Lines Matching full:info
15 struct smbd_connection *info);
17 struct smbd_connection *info);
19 struct smbd_connection *info,
21 static int allocate_receive_buffers(struct smbd_connection *info, int num_buf);
22 static void destroy_receive_buffers(struct smbd_connection *info);
25 struct smbd_connection *info, struct smbd_response *response);
27 struct smbd_connection *info,
30 struct smbd_connection *info);
33 struct smbd_connection *info,
36 static int smbd_post_send_empty(struct smbd_connection *info);
38 static void destroy_mr_list(struct smbd_connection *info);
39 static int allocate_mr_list(struct smbd_connection *info);
134 #define INFO 0x1 macro
138 "Logging level for SMBD transport, 0 (default): error, 1: info");
165 struct smbd_connection *info = in smbd_disconnect_rdma_work() local
168 if (info->transport_status == SMBD_CONNECTED) { in smbd_disconnect_rdma_work()
169 info->transport_status = SMBD_DISCONNECTING; in smbd_disconnect_rdma_work()
170 rdma_disconnect(info->id); in smbd_disconnect_rdma_work()
174 static void smbd_disconnect_rdma_connection(struct smbd_connection *info) in smbd_disconnect_rdma_connection() argument
176 queue_work(info->workqueue, &info->disconnect_work); in smbd_disconnect_rdma_connection()
183 struct smbd_connection *info = id->context; in smbd_conn_upcall() local
185 log_rdma_event(INFO, "event=%d status=%d\n", in smbd_conn_upcall()
191 info->ri_rc = 0; in smbd_conn_upcall()
192 complete(&info->ri_done); in smbd_conn_upcall()
196 info->ri_rc = -EHOSTUNREACH; in smbd_conn_upcall()
197 complete(&info->ri_done); in smbd_conn_upcall()
201 info->ri_rc = -ENETUNREACH; in smbd_conn_upcall()
202 complete(&info->ri_done); in smbd_conn_upcall()
206 log_rdma_event(INFO, "connected event=%d\n", event->event); in smbd_conn_upcall()
207 info->transport_status = SMBD_CONNECTED; in smbd_conn_upcall()
208 wake_up_interruptible(&info->conn_wait); in smbd_conn_upcall()
214 log_rdma_event(INFO, "connecting failed event=%d\n", event->event); in smbd_conn_upcall()
215 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
216 wake_up_interruptible(&info->conn_wait); in smbd_conn_upcall()
222 if (info->transport_status == SMBD_NEGOTIATE_FAILED) { in smbd_conn_upcall()
223 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
224 wake_up(&info->conn_wait); in smbd_conn_upcall()
228 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
229 wake_up_interruptible(&info->disconn_wait); in smbd_conn_upcall()
230 wake_up_interruptible(&info->wait_reassembly_queue); in smbd_conn_upcall()
231 wake_up_interruptible_all(&info->wait_send_queue); in smbd_conn_upcall()
245 struct smbd_connection *info = context; in smbd_qp_async_error_upcall() local
247 log_rdma_event(ERR, "%s on device %s info %p\n", in smbd_qp_async_error_upcall()
248 ib_event_msg(event->event), event->device->name, info); in smbd_qp_async_error_upcall()
253 smbd_disconnect_rdma_connection(info); in smbd_qp_async_error_upcall()
278 log_rdma_send(INFO, "smbd_request 0x%p completed wc->status=%d\n", in send_done()
284 smbd_disconnect_rdma_connection(request->info); in send_done()
288 ib_dma_unmap_single(request->info->id->device, in send_done()
293 if (atomic_dec_and_test(&request->info->send_pending)) in send_done()
294 wake_up(&request->info->wait_send_pending); in send_done()
296 wake_up(&request->info->wait_post_send); in send_done()
298 mempool_free(request, request->info->request_mempool); in send_done()
303 …log_rdma_event(INFO, "resp message min_version %u max_version %u negotiated_version %u credits_req… in dump_smbd_negotiate_resp()
319 struct smbd_connection *info = response->info; in process_negotiation_response() local
333 info->protocol = le16_to_cpu(packet->negotiated_version); in process_negotiation_response()
339 info->receive_credit_target = le16_to_cpu(packet->credits_requested); in process_negotiation_response()
345 atomic_set(&info->send_credits, le16_to_cpu(packet->credits_granted)); in process_negotiation_response()
347 atomic_set(&info->receive_credits, 0); in process_negotiation_response()
349 if (le32_to_cpu(packet->preferred_send_size) > info->max_receive_size) { in process_negotiation_response()
354 info->max_receive_size = le32_to_cpu(packet->preferred_send_size); in process_negotiation_response()
361 info->max_send_size = min_t(int, info->max_send_size, in process_negotiation_response()
370 info->max_fragmented_send_size = in process_negotiation_response()
372 info->rdma_readwrite_threshold = in process_negotiation_response()
373 rdma_readwrite_threshold > info->max_fragmented_send_size ? in process_negotiation_response()
374 info->max_fragmented_send_size : in process_negotiation_response()
378 info->max_readwrite_size = min_t(u32, in process_negotiation_response()
380 info->max_frmr_depth * PAGE_SIZE); in process_negotiation_response()
381 info->max_frmr_depth = info->max_readwrite_size / PAGE_SIZE; in process_negotiation_response()
392 struct smbd_connection *info = in smbd_post_send_credits() local
396 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_credits()
397 wake_up(&info->wait_receive_queues); in smbd_post_send_credits()
401 if (info->receive_credit_target > in smbd_post_send_credits()
402 atomic_read(&info->receive_credits)) { in smbd_post_send_credits()
405 response = get_receive_buffer(info); in smbd_post_send_credits()
407 response = get_empty_queue_buffer(info); in smbd_post_send_credits()
419 rc = smbd_post_recv(info, response); in smbd_post_send_credits()
423 put_receive_buffer(info, response); in smbd_post_send_credits()
431 spin_lock(&info->lock_new_credits_offered); in smbd_post_send_credits()
432 info->new_credits_offered += ret; in smbd_post_send_credits()
433 spin_unlock(&info->lock_new_credits_offered); in smbd_post_send_credits()
436 info->send_immediate = true; in smbd_post_send_credits()
437 if (atomic_read(&info->receive_credits) < in smbd_post_send_credits()
438 info->receive_credit_target - 1) { in smbd_post_send_credits()
439 if (info->keep_alive_requested == KEEP_ALIVE_PENDING || in smbd_post_send_credits()
440 info->send_immediate) { in smbd_post_send_credits()
441 log_keep_alive(INFO, "send an empty message\n"); in smbd_post_send_credits()
442 smbd_post_send_empty(info); in smbd_post_send_credits()
453 struct smbd_connection *info = response->info; in recv_done() local
456 log_rdma_recv(INFO, "response=0x%p type=%d wc status=%d wc opcode %d byte_len=%d pkey_index=%u\n", in recv_done()
461 log_rdma_recv(INFO, "wc->status=%d opcode=%d\n", in recv_done()
463 smbd_disconnect_rdma_connection(info); in recv_done()
477 info->full_packet_received = true; in recv_done()
478 info->negotiate_done = in recv_done()
480 complete(&info->negotiate_completion); in recv_done()
493 if (info->full_packet_received) in recv_done()
497 info->full_packet_received = false; in recv_done()
499 info->full_packet_received = true; in recv_done()
502 info, in recv_done()
506 put_empty_packet(info, response); in recv_done()
509 wake_up_interruptible(&info->wait_reassembly_queue); in recv_done()
511 atomic_dec(&info->receive_credits); in recv_done()
512 info->receive_credit_target = in recv_done()
516 &info->send_credits); in recv_done()
521 wake_up_interruptible(&info->wait_send_queue); in recv_done()
524 log_incoming(INFO, "data flags %d data_offset %d data_length %d remaining_data_length %d\n", in recv_done()
531 info->keep_alive_requested = KEEP_ALIVE_NONE; in recv_done()
534 info->keep_alive_requested = KEEP_ALIVE_PENDING; in recv_done()
545 put_receive_buffer(info, response); in recv_done()
549 struct smbd_connection *info, in smbd_create_id() argument
556 id = rdma_create_id(&init_net, smbd_conn_upcall, info, in smbd_create_id()
571 init_completion(&info->ri_done); in smbd_create_id()
572 info->ri_rc = -ETIMEDOUT; in smbd_create_id()
581 &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT)); in smbd_create_id()
587 rc = info->ri_rc; in smbd_create_id()
593 info->ri_rc = -ETIMEDOUT; in smbd_create_id()
600 &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT)); in smbd_create_id()
606 rc = info->ri_rc; in smbd_create_id()
634 struct smbd_connection *info, in smbd_ia_open() argument
639 info->id = smbd_create_id(info, dstaddr, port); in smbd_ia_open()
640 if (IS_ERR(info->id)) { in smbd_ia_open()
641 rc = PTR_ERR(info->id); in smbd_ia_open()
645 if (!frwr_is_supported(&info->id->device->attrs)) { in smbd_ia_open()
648 info->id->device->attrs.device_cap_flags, in smbd_ia_open()
649 info->id->device->attrs.max_fast_reg_page_list_len); in smbd_ia_open()
653 info->max_frmr_depth = min_t(int, in smbd_ia_open()
655 info->id->device->attrs.max_fast_reg_page_list_len); in smbd_ia_open()
656 info->mr_type = IB_MR_TYPE_MEM_REG; in smbd_ia_open()
657 if (info->id->device->attrs.kernel_cap_flags & IBK_SG_GAPS_REG) in smbd_ia_open()
658 info->mr_type = IB_MR_TYPE_SG_GAPS; in smbd_ia_open()
660 info->pd = ib_alloc_pd(info->id->device, 0); in smbd_ia_open()
661 if (IS_ERR(info->pd)) { in smbd_ia_open()
662 rc = PTR_ERR(info->pd); in smbd_ia_open()
670 rdma_destroy_id(info->id); in smbd_ia_open()
671 info->id = NULL; in smbd_ia_open()
683 static int smbd_post_send_negotiate_req(struct smbd_connection *info) in smbd_post_send_negotiate_req() argument
690 request = mempool_alloc(info->request_mempool, GFP_KERNEL); in smbd_post_send_negotiate_req()
694 request->info = info; in smbd_post_send_negotiate_req()
700 packet->credits_requested = cpu_to_le16(info->send_credit_target); in smbd_post_send_negotiate_req()
701 packet->preferred_send_size = cpu_to_le32(info->max_send_size); in smbd_post_send_negotiate_req()
702 packet->max_receive_size = cpu_to_le32(info->max_receive_size); in smbd_post_send_negotiate_req()
704 cpu_to_le32(info->max_fragmented_recv_size); in smbd_post_send_negotiate_req()
708 info->id->device, (void *)packet, in smbd_post_send_negotiate_req()
710 if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) { in smbd_post_send_negotiate_req()
716 request->sge[0].lkey = info->pd->local_dma_lkey; in smbd_post_send_negotiate_req()
719 info->id->device, request->sge[0].addr, in smbd_post_send_negotiate_req()
731 log_rdma_send(INFO, "sge addr=0x%llx length=%u lkey=0x%x\n", in smbd_post_send_negotiate_req()
735 atomic_inc(&info->send_pending); in smbd_post_send_negotiate_req()
736 rc = ib_post_send(info->id->qp, &send_wr, NULL); in smbd_post_send_negotiate_req()
742 atomic_dec(&info->send_pending); in smbd_post_send_negotiate_req()
743 ib_dma_unmap_single(info->id->device, request->sge[0].addr, in smbd_post_send_negotiate_req()
746 smbd_disconnect_rdma_connection(info); in smbd_post_send_negotiate_req()
749 mempool_free(request, info->request_mempool); in smbd_post_send_negotiate_req()
761 static int manage_credits_prior_sending(struct smbd_connection *info) in manage_credits_prior_sending() argument
765 spin_lock(&info->lock_new_credits_offered); in manage_credits_prior_sending()
766 new_credits = info->new_credits_offered; in manage_credits_prior_sending()
767 info->new_credits_offered = 0; in manage_credits_prior_sending()
768 spin_unlock(&info->lock_new_credits_offered); in manage_credits_prior_sending()
782 static int manage_keep_alive_before_sending(struct smbd_connection *info) in manage_keep_alive_before_sending() argument
784 if (info->keep_alive_requested == KEEP_ALIVE_PENDING) { in manage_keep_alive_before_sending()
785 info->keep_alive_requested = KEEP_ALIVE_SENT; in manage_keep_alive_before_sending()
792 static int smbd_post_send(struct smbd_connection *info, in smbd_post_send() argument
799 log_rdma_send(INFO, in smbd_post_send()
803 info->id->device, in smbd_post_send()
818 rc = ib_post_send(info->id->qp, &send_wr, NULL); in smbd_post_send()
821 smbd_disconnect_rdma_connection(info); in smbd_post_send()
825 mod_delayed_work(info->workqueue, &info->idle_timer_work, in smbd_post_send()
826 info->keep_alive_interval*HZ); in smbd_post_send()
831 static int smbd_post_send_iter(struct smbd_connection *info, in smbd_post_send_iter() argument
844 rc = wait_event_interruptible(info->wait_send_queue, in smbd_post_send_iter()
845 atomic_read(&info->send_credits) > 0 || in smbd_post_send_iter()
846 info->transport_status != SMBD_CONNECTED); in smbd_post_send_iter()
850 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_iter()
855 if (unlikely(atomic_dec_return(&info->send_credits) < 0)) { in smbd_post_send_iter()
856 atomic_inc(&info->send_credits); in smbd_post_send_iter()
861 wait_event(info->wait_post_send, in smbd_post_send_iter()
862 atomic_read(&info->send_pending) < info->send_credit_target || in smbd_post_send_iter()
863 info->transport_status != SMBD_CONNECTED); in smbd_post_send_iter()
865 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_iter()
871 if (unlikely(atomic_inc_return(&info->send_pending) > in smbd_post_send_iter()
872 info->send_credit_target)) { in smbd_post_send_iter()
873 atomic_dec(&info->send_pending); in smbd_post_send_iter()
877 request = mempool_alloc(info->request_mempool, GFP_KERNEL); in smbd_post_send_iter()
883 request->info = info; in smbd_post_send_iter()
892 .device = info->id->device, in smbd_post_send_iter()
893 .local_dma_lkey = info->pd->local_dma_lkey, in smbd_post_send_iter()
911 packet->credits_requested = cpu_to_le16(info->send_credit_target); in smbd_post_send_iter()
913 new_credits = manage_credits_prior_sending(info); in smbd_post_send_iter()
914 atomic_add(new_credits, &info->receive_credits); in smbd_post_send_iter()
917 info->send_immediate = false; in smbd_post_send_iter()
920 if (manage_keep_alive_before_sending(info)) in smbd_post_send_iter()
932 …log_outgoing(INFO, "credits_requested=%d credits_granted=%d data_offset=%d data_length=%d remainin… in smbd_post_send_iter()
945 request->sge[0].addr = ib_dma_map_single(info->id->device, in smbd_post_send_iter()
949 if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) { in smbd_post_send_iter()
956 request->sge[0].lkey = info->pd->local_dma_lkey; in smbd_post_send_iter()
958 rc = smbd_post_send(info, request); in smbd_post_send_iter()
965 ib_dma_unmap_single(info->id->device, in smbd_post_send_iter()
969 mempool_free(request, info->request_mempool); in smbd_post_send_iter()
972 spin_lock(&info->lock_new_credits_offered); in smbd_post_send_iter()
973 info->new_credits_offered += new_credits; in smbd_post_send_iter()
974 spin_unlock(&info->lock_new_credits_offered); in smbd_post_send_iter()
975 atomic_sub(new_credits, &info->receive_credits); in smbd_post_send_iter()
978 if (atomic_dec_and_test(&info->send_pending)) in smbd_post_send_iter()
979 wake_up(&info->wait_send_pending); in smbd_post_send_iter()
983 atomic_inc(&info->send_credits); in smbd_post_send_iter()
994 static int smbd_post_send_empty(struct smbd_connection *info) in smbd_post_send_empty() argument
998 info->count_send_empty++; in smbd_post_send_empty()
999 return smbd_post_send_iter(info, NULL, &remaining_data_length); in smbd_post_send_empty()
1008 struct smbd_connection *info, struct smbd_response *response) in smbd_post_recv() argument
1014 info->id->device, response->packet, in smbd_post_recv()
1015 info->max_receive_size, DMA_FROM_DEVICE); in smbd_post_recv()
1016 if (ib_dma_mapping_error(info->id->device, response->sge.addr)) in smbd_post_recv()
1019 response->sge.length = info->max_receive_size; in smbd_post_recv()
1020 response->sge.lkey = info->pd->local_dma_lkey; in smbd_post_recv()
1029 rc = ib_post_recv(info->id->qp, &recv_wr, NULL); in smbd_post_recv()
1031 ib_dma_unmap_single(info->id->device, response->sge.addr, in smbd_post_recv()
1033 smbd_disconnect_rdma_connection(info); in smbd_post_recv()
1041 static int smbd_negotiate(struct smbd_connection *info) in smbd_negotiate() argument
1044 struct smbd_response *response = get_receive_buffer(info); in smbd_negotiate()
1047 rc = smbd_post_recv(info, response); in smbd_negotiate()
1048 log_rdma_event(INFO, "smbd_post_recv rc=%d iov.addr=0x%llx iov.length=%u iov.lkey=0x%x\n", in smbd_negotiate()
1054 init_completion(&info->negotiate_completion); in smbd_negotiate()
1055 info->negotiate_done = false; in smbd_negotiate()
1056 rc = smbd_post_send_negotiate_req(info); in smbd_negotiate()
1061 &info->negotiate_completion, SMBD_NEGOTIATE_TIMEOUT * HZ); in smbd_negotiate()
1062 log_rdma_event(INFO, "wait_for_completion_timeout rc=%d\n", rc); in smbd_negotiate()
1064 if (info->negotiate_done) in smbd_negotiate()
1078 struct smbd_connection *info, struct smbd_response *response) in put_empty_packet() argument
1080 spin_lock(&info->empty_packet_queue_lock); in put_empty_packet()
1081 list_add_tail(&response->list, &info->empty_packet_queue); in put_empty_packet()
1082 info->count_empty_packet_queue++; in put_empty_packet()
1083 spin_unlock(&info->empty_packet_queue_lock); in put_empty_packet()
1085 queue_work(info->workqueue, &info->post_send_credits_work); in put_empty_packet()
1099 struct smbd_connection *info, in enqueue_reassembly() argument
1103 spin_lock(&info->reassembly_queue_lock); in enqueue_reassembly()
1104 list_add_tail(&response->list, &info->reassembly_queue); in enqueue_reassembly()
1105 info->reassembly_queue_length++; in enqueue_reassembly()
1113 info->reassembly_data_length += data_length; in enqueue_reassembly()
1114 spin_unlock(&info->reassembly_queue_lock); in enqueue_reassembly()
1115 info->count_reassembly_queue++; in enqueue_reassembly()
1116 info->count_enqueue_reassembly_queue++; in enqueue_reassembly()
1124 static struct smbd_response *_get_first_reassembly(struct smbd_connection *info) in _get_first_reassembly() argument
1128 if (!list_empty(&info->reassembly_queue)) { in _get_first_reassembly()
1130 &info->reassembly_queue, in _get_first_reassembly()
1137 struct smbd_connection *info) in get_empty_queue_buffer() argument
1142 spin_lock_irqsave(&info->empty_packet_queue_lock, flags); in get_empty_queue_buffer()
1143 if (!list_empty(&info->empty_packet_queue)) { in get_empty_queue_buffer()
1145 &info->empty_packet_queue, in get_empty_queue_buffer()
1148 info->count_empty_packet_queue--; in get_empty_queue_buffer()
1150 spin_unlock_irqrestore(&info->empty_packet_queue_lock, flags); in get_empty_queue_buffer()
1161 static struct smbd_response *get_receive_buffer(struct smbd_connection *info) in get_receive_buffer() argument
1166 spin_lock_irqsave(&info->receive_queue_lock, flags); in get_receive_buffer()
1167 if (!list_empty(&info->receive_queue)) { in get_receive_buffer()
1169 &info->receive_queue, in get_receive_buffer()
1172 info->count_receive_queue--; in get_receive_buffer()
1173 info->count_get_receive_buffer++; in get_receive_buffer()
1175 spin_unlock_irqrestore(&info->receive_queue_lock, flags); in get_receive_buffer()
1187 struct smbd_connection *info, struct smbd_response *response) in put_receive_buffer() argument
1191 ib_dma_unmap_single(info->id->device, response->sge.addr, in put_receive_buffer()
1194 spin_lock_irqsave(&info->receive_queue_lock, flags); in put_receive_buffer()
1195 list_add_tail(&response->list, &info->receive_queue); in put_receive_buffer()
1196 info->count_receive_queue++; in put_receive_buffer()
1197 info->count_put_receive_buffer++; in put_receive_buffer()
1198 spin_unlock_irqrestore(&info->receive_queue_lock, flags); in put_receive_buffer()
1200 queue_work(info->workqueue, &info->post_send_credits_work); in put_receive_buffer()
1204 static int allocate_receive_buffers(struct smbd_connection *info, int num_buf) in allocate_receive_buffers() argument
1209 INIT_LIST_HEAD(&info->reassembly_queue); in allocate_receive_buffers()
1210 spin_lock_init(&info->reassembly_queue_lock); in allocate_receive_buffers()
1211 info->reassembly_data_length = 0; in allocate_receive_buffers()
1212 info->reassembly_queue_length = 0; in allocate_receive_buffers()
1214 INIT_LIST_HEAD(&info->receive_queue); in allocate_receive_buffers()
1215 spin_lock_init(&info->receive_queue_lock); in allocate_receive_buffers()
1216 info->count_receive_queue = 0; in allocate_receive_buffers()
1218 INIT_LIST_HEAD(&info->empty_packet_queue); in allocate_receive_buffers()
1219 spin_lock_init(&info->empty_packet_queue_lock); in allocate_receive_buffers()
1220 info->count_empty_packet_queue = 0; in allocate_receive_buffers()
1222 init_waitqueue_head(&info->wait_receive_queues); in allocate_receive_buffers()
1225 response = mempool_alloc(info->response_mempool, GFP_KERNEL); in allocate_receive_buffers()
1229 response->info = info; in allocate_receive_buffers()
1230 list_add_tail(&response->list, &info->receive_queue); in allocate_receive_buffers()
1231 info->count_receive_queue++; in allocate_receive_buffers()
1237 while (!list_empty(&info->receive_queue)) { in allocate_receive_buffers()
1239 &info->receive_queue, in allocate_receive_buffers()
1242 info->count_receive_queue--; in allocate_receive_buffers()
1244 mempool_free(response, info->response_mempool); in allocate_receive_buffers()
1249 static void destroy_receive_buffers(struct smbd_connection *info) in destroy_receive_buffers() argument
1253 while ((response = get_receive_buffer(info))) in destroy_receive_buffers()
1254 mempool_free(response, info->response_mempool); in destroy_receive_buffers()
1256 while ((response = get_empty_queue_buffer(info))) in destroy_receive_buffers()
1257 mempool_free(response, info->response_mempool); in destroy_receive_buffers()
1263 struct smbd_connection *info = container_of( in idle_connection_timer() local
1267 if (info->keep_alive_requested != KEEP_ALIVE_NONE) { in idle_connection_timer()
1269 "error status info->keep_alive_requested=%d\n", in idle_connection_timer()
1270 info->keep_alive_requested); in idle_connection_timer()
1271 smbd_disconnect_rdma_connection(info); in idle_connection_timer()
1275 log_keep_alive(INFO, "about to send an empty idle message\n"); in idle_connection_timer()
1276 smbd_post_send_empty(info); in idle_connection_timer()
1279 queue_delayed_work(info->workqueue, &info->idle_timer_work, in idle_connection_timer()
1280 info->keep_alive_interval*HZ); in idle_connection_timer()
1290 struct smbd_connection *info = server->smbd_conn; in smbd_destroy() local
1294 if (!info) { in smbd_destroy()
1295 log_rdma_event(INFO, "rdma session already destroyed\n"); in smbd_destroy()
1299 log_rdma_event(INFO, "destroying rdma session\n"); in smbd_destroy()
1300 if (info->transport_status != SMBD_DISCONNECTED) { in smbd_destroy()
1302 log_rdma_event(INFO, "wait for transport being disconnected\n"); in smbd_destroy()
1304 info->disconn_wait, in smbd_destroy()
1305 info->transport_status == SMBD_DISCONNECTED); in smbd_destroy()
1308 log_rdma_event(INFO, "destroying qp\n"); in smbd_destroy()
1309 ib_drain_qp(info->id->qp); in smbd_destroy()
1310 rdma_destroy_qp(info->id); in smbd_destroy()
1312 log_rdma_event(INFO, "cancelling idle timer\n"); in smbd_destroy()
1313 cancel_delayed_work_sync(&info->idle_timer_work); in smbd_destroy()
1315 log_rdma_event(INFO, "wait for all send posted to IB to finish\n"); in smbd_destroy()
1316 wait_event(info->wait_send_pending, in smbd_destroy()
1317 atomic_read(&info->send_pending) == 0); in smbd_destroy()
1320 log_rdma_event(INFO, "drain the reassembly queue\n"); in smbd_destroy()
1322 spin_lock_irqsave(&info->reassembly_queue_lock, flags); in smbd_destroy()
1323 response = _get_first_reassembly(info); in smbd_destroy()
1327 &info->reassembly_queue_lock, flags); in smbd_destroy()
1328 put_receive_buffer(info, response); in smbd_destroy()
1331 &info->reassembly_queue_lock, flags); in smbd_destroy()
1333 info->reassembly_data_length = 0; in smbd_destroy()
1335 log_rdma_event(INFO, "free receive buffers\n"); in smbd_destroy()
1336 wait_event(info->wait_receive_queues, in smbd_destroy()
1337 info->count_receive_queue + info->count_empty_packet_queue in smbd_destroy()
1338 == info->receive_credit_max); in smbd_destroy()
1339 destroy_receive_buffers(info); in smbd_destroy()
1348 log_rdma_event(INFO, "freeing mr list\n"); in smbd_destroy()
1349 wake_up_interruptible_all(&info->wait_mr); in smbd_destroy()
1350 while (atomic_read(&info->mr_used_count)) { in smbd_destroy()
1355 destroy_mr_list(info); in smbd_destroy()
1357 ib_free_cq(info->send_cq); in smbd_destroy()
1358 ib_free_cq(info->recv_cq); in smbd_destroy()
1359 ib_dealloc_pd(info->pd); in smbd_destroy()
1360 rdma_destroy_id(info->id); in smbd_destroy()
1363 mempool_destroy(info->request_mempool); in smbd_destroy()
1364 kmem_cache_destroy(info->request_cache); in smbd_destroy()
1366 mempool_destroy(info->response_mempool); in smbd_destroy()
1367 kmem_cache_destroy(info->response_cache); in smbd_destroy()
1369 info->transport_status = SMBD_DESTROYED; in smbd_destroy()
1371 destroy_workqueue(info->workqueue); in smbd_destroy()
1372 log_rdma_event(INFO, "rdma session destroyed\n"); in smbd_destroy()
1373 kfree(info); in smbd_destroy()
1383 log_rdma_event(INFO, "reconnecting rdma session\n"); in smbd_reconnect()
1386 log_rdma_event(INFO, "rdma session already destroyed\n"); in smbd_reconnect()
1395 log_rdma_event(INFO, "disconnecting transport\n"); in smbd_reconnect()
1400 log_rdma_event(INFO, "creating rdma session\n"); in smbd_reconnect()
1413 static void destroy_caches_and_workqueue(struct smbd_connection *info) in destroy_caches_and_workqueue() argument
1415 destroy_receive_buffers(info); in destroy_caches_and_workqueue()
1416 destroy_workqueue(info->workqueue); in destroy_caches_and_workqueue()
1417 mempool_destroy(info->response_mempool); in destroy_caches_and_workqueue()
1418 kmem_cache_destroy(info->response_cache); in destroy_caches_and_workqueue()
1419 mempool_destroy(info->request_mempool); in destroy_caches_and_workqueue()
1420 kmem_cache_destroy(info->request_cache); in destroy_caches_and_workqueue()
1424 static int allocate_caches_and_workqueue(struct smbd_connection *info) in allocate_caches_and_workqueue() argument
1429 scnprintf(name, MAX_NAME_LEN, "smbd_request_%p", info); in allocate_caches_and_workqueue()
1430 info->request_cache = in allocate_caches_and_workqueue()
1436 if (!info->request_cache) in allocate_caches_and_workqueue()
1439 info->request_mempool = in allocate_caches_and_workqueue()
1440 mempool_create(info->send_credit_target, mempool_alloc_slab, in allocate_caches_and_workqueue()
1441 mempool_free_slab, info->request_cache); in allocate_caches_and_workqueue()
1442 if (!info->request_mempool) in allocate_caches_and_workqueue()
1445 scnprintf(name, MAX_NAME_LEN, "smbd_response_%p", info); in allocate_caches_and_workqueue()
1446 info->response_cache = in allocate_caches_and_workqueue()
1450 info->max_receive_size, in allocate_caches_and_workqueue()
1452 if (!info->response_cache) in allocate_caches_and_workqueue()
1455 info->response_mempool = in allocate_caches_and_workqueue()
1456 mempool_create(info->receive_credit_max, mempool_alloc_slab, in allocate_caches_and_workqueue()
1457 mempool_free_slab, info->response_cache); in allocate_caches_and_workqueue()
1458 if (!info->response_mempool) in allocate_caches_and_workqueue()
1461 scnprintf(name, MAX_NAME_LEN, "smbd_%p", info); in allocate_caches_and_workqueue()
1462 info->workqueue = create_workqueue(name); in allocate_caches_and_workqueue()
1463 if (!info->workqueue) in allocate_caches_and_workqueue()
1466 rc = allocate_receive_buffers(info, info->receive_credit_max); in allocate_caches_and_workqueue()
1475 destroy_workqueue(info->workqueue); in allocate_caches_and_workqueue()
1477 mempool_destroy(info->response_mempool); in allocate_caches_and_workqueue()
1479 kmem_cache_destroy(info->response_cache); in allocate_caches_and_workqueue()
1481 mempool_destroy(info->request_mempool); in allocate_caches_and_workqueue()
1483 kmem_cache_destroy(info->request_cache); in allocate_caches_and_workqueue()
1492 struct smbd_connection *info; in _smbd_get_connection() local
1499 info = kzalloc(sizeof(struct smbd_connection), GFP_KERNEL); in _smbd_get_connection()
1500 if (!info) in _smbd_get_connection()
1503 info->transport_status = SMBD_CONNECTING; in _smbd_get_connection()
1504 rc = smbd_ia_open(info, dstaddr, port); in _smbd_get_connection()
1506 log_rdma_event(INFO, "smbd_ia_open rc=%d\n", rc); in _smbd_get_connection()
1510 if (smbd_send_credit_target > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1511 smbd_send_credit_target > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1514 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1515 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1519 if (smbd_receive_credit_max > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1520 smbd_receive_credit_max > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1523 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1524 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1528 info->receive_credit_max = smbd_receive_credit_max; in _smbd_get_connection()
1529 info->send_credit_target = smbd_send_credit_target; in _smbd_get_connection()
1530 info->max_send_size = smbd_max_send_size; in _smbd_get_connection()
1531 info->max_fragmented_recv_size = smbd_max_fragmented_recv_size; in _smbd_get_connection()
1532 info->max_receive_size = smbd_max_receive_size; in _smbd_get_connection()
1533 info->keep_alive_interval = smbd_keep_alive_interval; in _smbd_get_connection()
1535 if (info->id->device->attrs.max_send_sge < SMBDIRECT_MAX_SEND_SGE || in _smbd_get_connection()
1536 info->id->device->attrs.max_recv_sge < SMBDIRECT_MAX_RECV_SGE) { in _smbd_get_connection()
1540 info->id->device->name, in _smbd_get_connection()
1541 info->id->device->attrs.max_send_sge, in _smbd_get_connection()
1542 info->id->device->attrs.max_recv_sge); in _smbd_get_connection()
1546 info->send_cq = NULL; in _smbd_get_connection()
1547 info->recv_cq = NULL; in _smbd_get_connection()
1548 info->send_cq = in _smbd_get_connection()
1549 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1550 info->send_credit_target, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1551 if (IS_ERR(info->send_cq)) { in _smbd_get_connection()
1552 info->send_cq = NULL; in _smbd_get_connection()
1556 info->recv_cq = in _smbd_get_connection()
1557 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1558 info->receive_credit_max, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1559 if (IS_ERR(info->recv_cq)) { in _smbd_get_connection()
1560 info->recv_cq = NULL; in _smbd_get_connection()
1566 qp_attr.qp_context = info; in _smbd_get_connection()
1567 qp_attr.cap.max_send_wr = info->send_credit_target; in _smbd_get_connection()
1568 qp_attr.cap.max_recv_wr = info->receive_credit_max; in _smbd_get_connection()
1574 qp_attr.send_cq = info->send_cq; in _smbd_get_connection()
1575 qp_attr.recv_cq = info->recv_cq; in _smbd_get_connection()
1578 rc = rdma_create_qp(info->id, info->pd, &qp_attr); in _smbd_get_connection()
1588 info->id->device->attrs.max_qp_rd_atom in _smbd_get_connection()
1590 info->id->device->attrs.max_qp_rd_atom : in _smbd_get_connection()
1592 info->responder_resources = conn_param.responder_resources; in _smbd_get_connection()
1593 log_rdma_mr(INFO, "responder_resources=%d\n", in _smbd_get_connection()
1594 info->responder_resources); in _smbd_get_connection()
1597 info->id->device->ops.get_port_immutable( in _smbd_get_connection()
1598 info->id->device, info->id->port_num, &port_immutable); in _smbd_get_connection()
1600 ird_ord_hdr[0] = info->responder_resources; in _smbd_get_connection()
1613 log_rdma_event(INFO, "connecting to IP %pI4 port %d\n", in _smbd_get_connection()
1616 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1617 init_waitqueue_head(&info->disconn_wait); in _smbd_get_connection()
1618 init_waitqueue_head(&info->wait_reassembly_queue); in _smbd_get_connection()
1619 rc = rdma_connect(info->id, &conn_param); in _smbd_get_connection()
1626 info->conn_wait, info->transport_status != SMBD_CONNECTING); in _smbd_get_connection()
1628 if (info->transport_status != SMBD_CONNECTED) { in _smbd_get_connection()
1633 log_rdma_event(INFO, "rdma_connect connected\n"); in _smbd_get_connection()
1635 rc = allocate_caches_and_workqueue(info); in _smbd_get_connection()
1641 init_waitqueue_head(&info->wait_send_queue); in _smbd_get_connection()
1642 INIT_DELAYED_WORK(&info->idle_timer_work, idle_connection_timer); in _smbd_get_connection()
1643 queue_delayed_work(info->workqueue, &info->idle_timer_work, in _smbd_get_connection()
1644 info->keep_alive_interval*HZ); in _smbd_get_connection()
1646 init_waitqueue_head(&info->wait_send_pending); in _smbd_get_connection()
1647 atomic_set(&info->send_pending, 0); in _smbd_get_connection()
1649 init_waitqueue_head(&info->wait_post_send); in _smbd_get_connection()
1651 INIT_WORK(&info->disconnect_work, smbd_disconnect_rdma_work); in _smbd_get_connection()
1652 INIT_WORK(&info->post_send_credits_work, smbd_post_send_credits); in _smbd_get_connection()
1653 info->new_credits_offered = 0; in _smbd_get_connection()
1654 spin_lock_init(&info->lock_new_credits_offered); in _smbd_get_connection()
1656 rc = smbd_negotiate(info); in _smbd_get_connection()
1662 rc = allocate_mr_list(info); in _smbd_get_connection()
1668 return info; in _smbd_get_connection()
1672 server->smbd_conn = info; in _smbd_get_connection()
1677 cancel_delayed_work_sync(&info->idle_timer_work); in _smbd_get_connection()
1678 destroy_caches_and_workqueue(info); in _smbd_get_connection()
1679 info->transport_status = SMBD_NEGOTIATE_FAILED; in _smbd_get_connection()
1680 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1681 rdma_disconnect(info->id); in _smbd_get_connection()
1682 wait_event(info->conn_wait, in _smbd_get_connection()
1683 info->transport_status == SMBD_DISCONNECTED); in _smbd_get_connection()
1687 rdma_destroy_qp(info->id); in _smbd_get_connection()
1691 if (info->send_cq) in _smbd_get_connection()
1692 ib_free_cq(info->send_cq); in _smbd_get_connection()
1693 if (info->recv_cq) in _smbd_get_connection()
1694 ib_free_cq(info->recv_cq); in _smbd_get_connection()
1697 ib_dealloc_pd(info->pd); in _smbd_get_connection()
1698 rdma_destroy_id(info->id); in _smbd_get_connection()
1701 kfree(info); in _smbd_get_connection()
1735 static int smbd_recv_buf(struct smbd_connection *info, char *buf, in smbd_recv_buf() argument
1750 log_read(INFO, "size=%d info->reassembly_data_length=%d\n", size, in smbd_recv_buf()
1751 info->reassembly_data_length); in smbd_recv_buf()
1752 if (info->reassembly_data_length >= size) { in smbd_recv_buf()
1764 queue_length = info->reassembly_queue_length; in smbd_recv_buf()
1767 offset = info->first_entry_offset; in smbd_recv_buf()
1769 response = _get_first_reassembly(info); in smbd_recv_buf()
1791 log_read(INFO, "returning rfc1002 length %d\n", in smbd_recv_buf()
1813 &info->reassembly_queue_lock); in smbd_recv_buf()
1816 &info->reassembly_queue_lock); in smbd_recv_buf()
1819 info->count_reassembly_queue--; in smbd_recv_buf()
1820 info->count_dequeue_reassembly_queue++; in smbd_recv_buf()
1821 put_receive_buffer(info, response); in smbd_recv_buf()
1823 log_read(INFO, "put_receive_buffer offset=0\n"); in smbd_recv_buf()
1830 …log_read(INFO, "_get_first_reassembly memcpy %d bytes data_transfer_length-offset=%d after that to… in smbd_recv_buf()
1835 spin_lock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1836 info->reassembly_data_length -= data_read; in smbd_recv_buf()
1837 info->reassembly_queue_length -= queue_removed; in smbd_recv_buf()
1838 spin_unlock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1840 info->first_entry_offset = offset; in smbd_recv_buf()
1841 …log_read(INFO, "returning to thread data_read=%d reassembly_data_length=%d first_entry_offset=%d\n… in smbd_recv_buf()
1842 data_read, info->reassembly_data_length, in smbd_recv_buf()
1843 info->first_entry_offset); in smbd_recv_buf()
1848 log_read(INFO, "wait_event on more data\n"); in smbd_recv_buf()
1850 info->wait_reassembly_queue, in smbd_recv_buf()
1851 info->reassembly_data_length >= size || in smbd_recv_buf()
1852 info->transport_status != SMBD_CONNECTED); in smbd_recv_buf()
1857 if (info->transport_status != SMBD_CONNECTED) { in smbd_recv_buf()
1871 static int smbd_recv_page(struct smbd_connection *info, in smbd_recv_page() argument
1881 info->wait_reassembly_queue, in smbd_recv_page()
1882 info->reassembly_data_length >= to_read || in smbd_recv_page()
1883 info->transport_status != SMBD_CONNECTED); in smbd_recv_page()
1891 log_read(INFO, "reading from page=%p address=%p to_read=%d\n", in smbd_recv_page()
1894 ret = smbd_recv_buf(info, to_address, to_read); in smbd_recv_page()
1905 int smbd_recv(struct smbd_connection *info, struct msghdr *msg) in smbd_recv() argument
1924 rc = smbd_recv_buf(info, buf, to_read); in smbd_recv()
1931 rc = smbd_recv_page(info, page, page_offset, to_read); in smbd_recv()
1957 struct smbd_connection *info = server->smbd_conn; in smbd_send() local
1963 if (info->transport_status != SMBD_CONNECTED) in smbd_send()
1975 if (unlikely(remaining_data_length > info->max_fragmented_send_size)) { in smbd_send()
1978 remaining_data_length, info->max_fragmented_send_size); in smbd_send()
1982 log_write(INFO, "num_rqst=%d total length=%u\n", in smbd_send()
1994 log_write(INFO, "RDMA-WR[%u] nvec=%d len=%u iter=%zu rqlen=%lu\n", in smbd_send()
2004 rc = smbd_post_send_iter(info, &iter, &remaining_data_length); in smbd_send()
2010 rc = smbd_post_send_iter(info, &rqst->rq_iter, in smbd_send()
2025 wait_event(info->wait_send_pending, in smbd_send()
2026 atomic_read(&info->send_pending) == 0); in smbd_send()
2055 struct smbd_connection *info = in smbd_mr_recovery_work() local
2060 list_for_each_entry(smbdirect_mr, &info->mr_list, list) { in smbd_mr_recovery_work()
2069 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2074 info->pd, info->mr_type, in smbd_mr_recovery_work()
2075 info->max_frmr_depth); in smbd_mr_recovery_work()
2078 info->mr_type, in smbd_mr_recovery_work()
2079 info->max_frmr_depth); in smbd_mr_recovery_work()
2080 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2096 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_mr_recovery_work()
2097 wake_up_interruptible(&info->wait_mr); in smbd_mr_recovery_work()
2101 static void destroy_mr_list(struct smbd_connection *info) in destroy_mr_list() argument
2105 cancel_work_sync(&info->mr_recovery_work); in destroy_mr_list()
2106 list_for_each_entry_safe(mr, tmp, &info->mr_list, list) { in destroy_mr_list()
2108 ib_dma_unmap_sg(info->id->device, mr->sgt.sgl, in destroy_mr_list()
2123 static int allocate_mr_list(struct smbd_connection *info) in allocate_mr_list() argument
2128 INIT_LIST_HEAD(&info->mr_list); in allocate_mr_list()
2129 init_waitqueue_head(&info->wait_mr); in allocate_mr_list()
2130 spin_lock_init(&info->mr_list_lock); in allocate_mr_list()
2131 atomic_set(&info->mr_ready_count, 0); in allocate_mr_list()
2132 atomic_set(&info->mr_used_count, 0); in allocate_mr_list()
2133 init_waitqueue_head(&info->wait_for_mr_cleanup); in allocate_mr_list()
2134 INIT_WORK(&info->mr_recovery_work, smbd_mr_recovery_work); in allocate_mr_list()
2136 for (i = 0; i < info->responder_resources * 2; i++) { in allocate_mr_list()
2140 smbdirect_mr->mr = ib_alloc_mr(info->pd, info->mr_type, in allocate_mr_list()
2141 info->max_frmr_depth); in allocate_mr_list()
2144 info->mr_type, info->max_frmr_depth); in allocate_mr_list()
2147 smbdirect_mr->sgt.sgl = kcalloc(info->max_frmr_depth, in allocate_mr_list()
2156 smbdirect_mr->conn = info; in allocate_mr_list()
2158 list_add_tail(&smbdirect_mr->list, &info->mr_list); in allocate_mr_list()
2159 atomic_inc(&info->mr_ready_count); in allocate_mr_list()
2166 list_for_each_entry_safe(smbdirect_mr, tmp, &info->mr_list, list) { in allocate_mr_list()
2183 static struct smbd_mr *get_mr(struct smbd_connection *info) in get_mr() argument
2188 rc = wait_event_interruptible(info->wait_mr, in get_mr()
2189 atomic_read(&info->mr_ready_count) || in get_mr()
2190 info->transport_status != SMBD_CONNECTED); in get_mr()
2196 if (info->transport_status != SMBD_CONNECTED) { in get_mr()
2197 log_rdma_mr(ERR, "info->transport_status=%x\n", in get_mr()
2198 info->transport_status); in get_mr()
2202 spin_lock(&info->mr_list_lock); in get_mr()
2203 list_for_each_entry(ret, &info->mr_list, list) { in get_mr()
2206 spin_unlock(&info->mr_list_lock); in get_mr()
2207 atomic_dec(&info->mr_ready_count); in get_mr()
2208 atomic_inc(&info->mr_used_count); in get_mr()
2213 spin_unlock(&info->mr_list_lock); in get_mr()
2224 static int smbd_iter_to_mr(struct smbd_connection *info, in smbd_iter_to_mr() argument
2247 struct smbd_mr *smbd_register_mr(struct smbd_connection *info, in smbd_register_mr() argument
2256 num_pages = iov_iter_npages(iter, info->max_frmr_depth + 1); in smbd_register_mr()
2257 if (num_pages > info->max_frmr_depth) { in smbd_register_mr()
2259 num_pages, info->max_frmr_depth); in smbd_register_mr()
2264 smbdirect_mr = get_mr(info); in smbd_register_mr()
2276 log_rdma_mr(INFO, "num_pages=0x%x count=0x%zx depth=%u\n", in smbd_register_mr()
2277 num_pages, iov_iter_count(iter), info->max_frmr_depth); in smbd_register_mr()
2278 smbd_iter_to_mr(info, iter, &smbdirect_mr->sgt, info->max_frmr_depth); in smbd_register_mr()
2280 rc = ib_dma_map_sg(info->id->device, smbdirect_mr->sgt.sgl, in smbd_register_mr()
2316 rc = ib_post_send(info->id->qp, ®_wr->wr, NULL); in smbd_register_mr()
2325 ib_dma_unmap_sg(info->id->device, smbdirect_mr->sgt.sgl, in smbd_register_mr()
2330 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_register_mr()
2331 wake_up(&info->wait_for_mr_cleanup); in smbd_register_mr()
2333 smbd_disconnect_rdma_connection(info); in smbd_register_mr()
2362 struct smbd_connection *info = smbdirect_mr->conn; in smbd_deregister_mr() local
2376 rc = ib_post_send(info->id->qp, wr, NULL); in smbd_deregister_mr()
2379 smbd_disconnect_rdma_connection(info); in smbd_deregister_mr()
2393 info->id->device, smbdirect_mr->sgt.sgl, in smbd_deregister_mr()
2397 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_deregister_mr()
2398 wake_up_interruptible(&info->wait_mr); in smbd_deregister_mr()
2404 queue_work(info->workqueue, &info->mr_recovery_work); in smbd_deregister_mr()
2407 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_deregister_mr()
2408 wake_up(&info->wait_for_mr_cleanup); in smbd_deregister_mr()