Lines Matching refs: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);
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
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()
207 info->transport_status = SMBD_CONNECTED; in smbd_conn_upcall()
208 wake_up_interruptible(&info->conn_wait); 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
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()
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()
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()
442 smbd_post_send_empty(info); in smbd_post_send_credits()
453 struct smbd_connection *info = response->info; in recv_done() local
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()
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()
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
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()
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()
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()
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()
1270 info->keep_alive_requested); in idle_connection_timer()
1271 smbd_disconnect_rdma_connection(info); 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()
1300 if (info->transport_status != SMBD_DISCONNECTED) { in smbd_destroy()
1304 info->disconn_wait, in smbd_destroy()
1305 info->transport_status == SMBD_DISCONNECTED); in smbd_destroy()
1309 ib_drain_qp(info->id->qp); in smbd_destroy()
1310 rdma_destroy_qp(info->id); in smbd_destroy()
1313 cancel_delayed_work_sync(&info->idle_timer_work); in smbd_destroy()
1316 wait_event(info->wait_send_pending, in smbd_destroy()
1317 atomic_read(&info->send_pending) == 0); 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()
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()
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()
1373 kfree(info); in smbd_destroy()
1410 static void destroy_caches_and_workqueue(struct smbd_connection *info) in destroy_caches_and_workqueue() argument
1412 destroy_receive_buffers(info); in destroy_caches_and_workqueue()
1413 destroy_workqueue(info->workqueue); in destroy_caches_and_workqueue()
1414 mempool_destroy(info->response_mempool); in destroy_caches_and_workqueue()
1415 kmem_cache_destroy(info->response_cache); in destroy_caches_and_workqueue()
1416 mempool_destroy(info->request_mempool); in destroy_caches_and_workqueue()
1417 kmem_cache_destroy(info->request_cache); in destroy_caches_and_workqueue()
1421 static int allocate_caches_and_workqueue(struct smbd_connection *info) in allocate_caches_and_workqueue() argument
1426 scnprintf(name, MAX_NAME_LEN, "smbd_request_%p", info); in allocate_caches_and_workqueue()
1427 info->request_cache = in allocate_caches_and_workqueue()
1433 if (!info->request_cache) in allocate_caches_and_workqueue()
1436 info->request_mempool = in allocate_caches_and_workqueue()
1437 mempool_create(info->send_credit_target, mempool_alloc_slab, in allocate_caches_and_workqueue()
1438 mempool_free_slab, info->request_cache); in allocate_caches_and_workqueue()
1439 if (!info->request_mempool) in allocate_caches_and_workqueue()
1442 scnprintf(name, MAX_NAME_LEN, "smbd_response_%p", info); in allocate_caches_and_workqueue()
1443 info->response_cache = in allocate_caches_and_workqueue()
1447 info->max_receive_size, in allocate_caches_and_workqueue()
1449 if (!info->response_cache) in allocate_caches_and_workqueue()
1452 info->response_mempool = in allocate_caches_and_workqueue()
1453 mempool_create(info->receive_credit_max, mempool_alloc_slab, in allocate_caches_and_workqueue()
1454 mempool_free_slab, info->response_cache); in allocate_caches_and_workqueue()
1455 if (!info->response_mempool) in allocate_caches_and_workqueue()
1458 scnprintf(name, MAX_NAME_LEN, "smbd_%p", info); in allocate_caches_and_workqueue()
1459 info->workqueue = create_workqueue(name); in allocate_caches_and_workqueue()
1460 if (!info->workqueue) in allocate_caches_and_workqueue()
1463 rc = allocate_receive_buffers(info, info->receive_credit_max); in allocate_caches_and_workqueue()
1472 destroy_workqueue(info->workqueue); in allocate_caches_and_workqueue()
1474 mempool_destroy(info->response_mempool); in allocate_caches_and_workqueue()
1476 kmem_cache_destroy(info->response_cache); in allocate_caches_and_workqueue()
1478 mempool_destroy(info->request_mempool); in allocate_caches_and_workqueue()
1480 kmem_cache_destroy(info->request_cache); in allocate_caches_and_workqueue()
1489 struct smbd_connection *info; in _smbd_get_connection() local
1496 info = kzalloc(sizeof(struct smbd_connection), GFP_KERNEL); in _smbd_get_connection()
1497 if (!info) in _smbd_get_connection()
1500 info->transport_status = SMBD_CONNECTING; in _smbd_get_connection()
1501 rc = smbd_ia_open(info, dstaddr, port); in _smbd_get_connection()
1507 if (smbd_send_credit_target > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1508 smbd_send_credit_target > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1511 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1512 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1516 if (smbd_receive_credit_max > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1517 smbd_receive_credit_max > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1520 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1521 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1525 info->receive_credit_max = smbd_receive_credit_max; in _smbd_get_connection()
1526 info->send_credit_target = smbd_send_credit_target; in _smbd_get_connection()
1527 info->max_send_size = smbd_max_send_size; in _smbd_get_connection()
1528 info->max_fragmented_recv_size = smbd_max_fragmented_recv_size; in _smbd_get_connection()
1529 info->max_receive_size = smbd_max_receive_size; in _smbd_get_connection()
1530 info->keep_alive_interval = smbd_keep_alive_interval; in _smbd_get_connection()
1532 if (info->id->device->attrs.max_send_sge < SMBDIRECT_MAX_SEND_SGE || in _smbd_get_connection()
1533 info->id->device->attrs.max_recv_sge < SMBDIRECT_MAX_RECV_SGE) { in _smbd_get_connection()
1537 info->id->device->name, in _smbd_get_connection()
1538 info->id->device->attrs.max_send_sge, in _smbd_get_connection()
1539 info->id->device->attrs.max_recv_sge); in _smbd_get_connection()
1543 info->send_cq = NULL; in _smbd_get_connection()
1544 info->recv_cq = NULL; in _smbd_get_connection()
1545 info->send_cq = in _smbd_get_connection()
1546 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1547 info->send_credit_target, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1548 if (IS_ERR(info->send_cq)) { in _smbd_get_connection()
1549 info->send_cq = NULL; in _smbd_get_connection()
1553 info->recv_cq = in _smbd_get_connection()
1554 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1555 info->receive_credit_max, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1556 if (IS_ERR(info->recv_cq)) { in _smbd_get_connection()
1557 info->recv_cq = NULL; in _smbd_get_connection()
1563 qp_attr.qp_context = info; in _smbd_get_connection()
1564 qp_attr.cap.max_send_wr = info->send_credit_target; in _smbd_get_connection()
1565 qp_attr.cap.max_recv_wr = info->receive_credit_max; in _smbd_get_connection()
1571 qp_attr.send_cq = info->send_cq; in _smbd_get_connection()
1572 qp_attr.recv_cq = info->recv_cq; in _smbd_get_connection()
1575 rc = rdma_create_qp(info->id, info->pd, &qp_attr); in _smbd_get_connection()
1585 info->id->device->attrs.max_qp_rd_atom in _smbd_get_connection()
1587 info->id->device->attrs.max_qp_rd_atom : in _smbd_get_connection()
1589 info->responder_resources = conn_param.responder_resources; in _smbd_get_connection()
1591 info->responder_resources); in _smbd_get_connection()
1594 info->id->device->ops.get_port_immutable( in _smbd_get_connection()
1595 info->id->device, info->id->port_num, &port_immutable); in _smbd_get_connection()
1597 ird_ord_hdr[0] = info->responder_resources; in _smbd_get_connection()
1613 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1614 init_waitqueue_head(&info->disconn_wait); in _smbd_get_connection()
1615 init_waitqueue_head(&info->wait_reassembly_queue); in _smbd_get_connection()
1616 rc = rdma_connect(info->id, &conn_param); in _smbd_get_connection()
1623 info->conn_wait, info->transport_status != SMBD_CONNECTING); in _smbd_get_connection()
1625 if (info->transport_status != SMBD_CONNECTED) { in _smbd_get_connection()
1632 rc = allocate_caches_and_workqueue(info); in _smbd_get_connection()
1638 init_waitqueue_head(&info->wait_send_queue); in _smbd_get_connection()
1639 INIT_DELAYED_WORK(&info->idle_timer_work, idle_connection_timer); in _smbd_get_connection()
1640 queue_delayed_work(info->workqueue, &info->idle_timer_work, in _smbd_get_connection()
1641 info->keep_alive_interval*HZ); in _smbd_get_connection()
1643 init_waitqueue_head(&info->wait_send_pending); in _smbd_get_connection()
1644 atomic_set(&info->send_pending, 0); in _smbd_get_connection()
1646 init_waitqueue_head(&info->wait_post_send); in _smbd_get_connection()
1648 INIT_WORK(&info->disconnect_work, smbd_disconnect_rdma_work); in _smbd_get_connection()
1649 INIT_WORK(&info->post_send_credits_work, smbd_post_send_credits); in _smbd_get_connection()
1650 info->new_credits_offered = 0; in _smbd_get_connection()
1651 spin_lock_init(&info->lock_new_credits_offered); in _smbd_get_connection()
1653 rc = smbd_negotiate(info); in _smbd_get_connection()
1659 rc = allocate_mr_list(info); in _smbd_get_connection()
1665 return info; in _smbd_get_connection()
1669 server->smbd_conn = info; in _smbd_get_connection()
1674 cancel_delayed_work_sync(&info->idle_timer_work); in _smbd_get_connection()
1675 destroy_caches_and_workqueue(info); in _smbd_get_connection()
1676 info->transport_status = SMBD_NEGOTIATE_FAILED; in _smbd_get_connection()
1677 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1678 rdma_disconnect(info->id); in _smbd_get_connection()
1679 wait_event(info->conn_wait, in _smbd_get_connection()
1680 info->transport_status == SMBD_DISCONNECTED); in _smbd_get_connection()
1684 rdma_destroy_qp(info->id); in _smbd_get_connection()
1688 if (info->send_cq) in _smbd_get_connection()
1689 ib_free_cq(info->send_cq); in _smbd_get_connection()
1690 if (info->recv_cq) in _smbd_get_connection()
1691 ib_free_cq(info->recv_cq); in _smbd_get_connection()
1694 ib_dealloc_pd(info->pd); in _smbd_get_connection()
1695 rdma_destroy_id(info->id); in _smbd_get_connection()
1698 kfree(info); in _smbd_get_connection()
1732 static int smbd_recv_buf(struct smbd_connection *info, char *buf, in smbd_recv_buf() argument
1748 info->reassembly_data_length); in smbd_recv_buf()
1749 if (info->reassembly_data_length >= size) { in smbd_recv_buf()
1761 queue_length = info->reassembly_queue_length; in smbd_recv_buf()
1764 offset = info->first_entry_offset; in smbd_recv_buf()
1766 response = _get_first_reassembly(info); in smbd_recv_buf()
1810 &info->reassembly_queue_lock); in smbd_recv_buf()
1813 &info->reassembly_queue_lock); in smbd_recv_buf()
1816 info->count_reassembly_queue--; in smbd_recv_buf()
1817 info->count_dequeue_reassembly_queue++; in smbd_recv_buf()
1818 put_receive_buffer(info, response); in smbd_recv_buf()
1832 spin_lock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1833 info->reassembly_data_length -= data_read; in smbd_recv_buf()
1834 info->reassembly_queue_length -= queue_removed; in smbd_recv_buf()
1835 spin_unlock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1837 info->first_entry_offset = offset; in smbd_recv_buf()
1839 data_read, info->reassembly_data_length, in smbd_recv_buf()
1840 info->first_entry_offset); in smbd_recv_buf()
1847 info->wait_reassembly_queue, in smbd_recv_buf()
1848 info->reassembly_data_length >= size || in smbd_recv_buf()
1849 info->transport_status != SMBD_CONNECTED); in smbd_recv_buf()
1854 if (info->transport_status != SMBD_CONNECTED) { in smbd_recv_buf()
1868 static int smbd_recv_page(struct smbd_connection *info, in smbd_recv_page() argument
1878 info->wait_reassembly_queue, in smbd_recv_page()
1879 info->reassembly_data_length >= to_read || in smbd_recv_page()
1880 info->transport_status != SMBD_CONNECTED); in smbd_recv_page()
1891 ret = smbd_recv_buf(info, to_address, to_read); in smbd_recv_page()
1902 int smbd_recv(struct smbd_connection *info, struct msghdr *msg) in smbd_recv() argument
1921 rc = smbd_recv_buf(info, buf, to_read); in smbd_recv()
1928 rc = smbd_recv_page(info, page, page_offset, to_read); in smbd_recv()
1954 struct smbd_connection *info = server->smbd_conn; in smbd_send() local
1960 if (info->transport_status != SMBD_CONNECTED) in smbd_send()
1972 if (unlikely(remaining_data_length > info->max_fragmented_send_size)) { in smbd_send()
1975 remaining_data_length, info->max_fragmented_send_size); in smbd_send()
2001 rc = smbd_post_send_iter(info, &iter, &remaining_data_length); in smbd_send()
2007 rc = smbd_post_send_iter(info, &rqst->rq_iter, in smbd_send()
2022 wait_event(info->wait_send_pending, in smbd_send()
2023 atomic_read(&info->send_pending) == 0); in smbd_send()
2052 struct smbd_connection *info = in smbd_mr_recovery_work() local
2057 list_for_each_entry(smbdirect_mr, &info->mr_list, list) { in smbd_mr_recovery_work()
2066 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2071 info->pd, info->mr_type, in smbd_mr_recovery_work()
2072 info->max_frmr_depth); in smbd_mr_recovery_work()
2075 info->mr_type, in smbd_mr_recovery_work()
2076 info->max_frmr_depth); in smbd_mr_recovery_work()
2077 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2093 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_mr_recovery_work()
2094 wake_up_interruptible(&info->wait_mr); in smbd_mr_recovery_work()
2098 static void destroy_mr_list(struct smbd_connection *info) in destroy_mr_list() argument
2102 cancel_work_sync(&info->mr_recovery_work); in destroy_mr_list()
2103 list_for_each_entry_safe(mr, tmp, &info->mr_list, list) { in destroy_mr_list()
2105 ib_dma_unmap_sg(info->id->device, mr->sgt.sgl, in destroy_mr_list()
2120 static int allocate_mr_list(struct smbd_connection *info) in allocate_mr_list() argument
2125 INIT_LIST_HEAD(&info->mr_list); in allocate_mr_list()
2126 init_waitqueue_head(&info->wait_mr); in allocate_mr_list()
2127 spin_lock_init(&info->mr_list_lock); in allocate_mr_list()
2128 atomic_set(&info->mr_ready_count, 0); in allocate_mr_list()
2129 atomic_set(&info->mr_used_count, 0); in allocate_mr_list()
2130 init_waitqueue_head(&info->wait_for_mr_cleanup); in allocate_mr_list()
2131 INIT_WORK(&info->mr_recovery_work, smbd_mr_recovery_work); in allocate_mr_list()
2133 for (i = 0; i < info->responder_resources * 2; i++) { in allocate_mr_list()
2137 smbdirect_mr->mr = ib_alloc_mr(info->pd, info->mr_type, in allocate_mr_list()
2138 info->max_frmr_depth); in allocate_mr_list()
2141 info->mr_type, info->max_frmr_depth); in allocate_mr_list()
2144 smbdirect_mr->sgt.sgl = kcalloc(info->max_frmr_depth, in allocate_mr_list()
2153 smbdirect_mr->conn = info; in allocate_mr_list()
2155 list_add_tail(&smbdirect_mr->list, &info->mr_list); in allocate_mr_list()
2156 atomic_inc(&info->mr_ready_count); in allocate_mr_list()
2163 list_for_each_entry_safe(smbdirect_mr, tmp, &info->mr_list, list) { in allocate_mr_list()
2180 static struct smbd_mr *get_mr(struct smbd_connection *info) in get_mr() argument
2185 rc = wait_event_interruptible(info->wait_mr, in get_mr()
2186 atomic_read(&info->mr_ready_count) || in get_mr()
2187 info->transport_status != SMBD_CONNECTED); in get_mr()
2193 if (info->transport_status != SMBD_CONNECTED) { in get_mr()
2195 info->transport_status); in get_mr()
2199 spin_lock(&info->mr_list_lock); in get_mr()
2200 list_for_each_entry(ret, &info->mr_list, list) { in get_mr()
2203 spin_unlock(&info->mr_list_lock); in get_mr()
2204 atomic_dec(&info->mr_ready_count); in get_mr()
2205 atomic_inc(&info->mr_used_count); in get_mr()
2210 spin_unlock(&info->mr_list_lock); in get_mr()
2221 static int smbd_iter_to_mr(struct smbd_connection *info, in smbd_iter_to_mr() argument
2244 struct smbd_mr *smbd_register_mr(struct smbd_connection *info, in smbd_register_mr() argument
2253 num_pages = iov_iter_npages(iter, info->max_frmr_depth + 1); in smbd_register_mr()
2254 if (num_pages > info->max_frmr_depth) { in smbd_register_mr()
2256 num_pages, info->max_frmr_depth); in smbd_register_mr()
2261 smbdirect_mr = get_mr(info); in smbd_register_mr()
2274 num_pages, iov_iter_count(iter), info->max_frmr_depth); in smbd_register_mr()
2275 smbd_iter_to_mr(info, iter, &smbdirect_mr->sgt, info->max_frmr_depth); in smbd_register_mr()
2277 rc = ib_dma_map_sg(info->id->device, smbdirect_mr->sgt.sgl, in smbd_register_mr()
2313 rc = ib_post_send(info->id->qp, &reg_wr->wr, NULL); in smbd_register_mr()
2322 ib_dma_unmap_sg(info->id->device, smbdirect_mr->sgt.sgl, in smbd_register_mr()
2327 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_register_mr()
2328 wake_up(&info->wait_for_mr_cleanup); in smbd_register_mr()
2330 smbd_disconnect_rdma_connection(info); in smbd_register_mr()
2359 struct smbd_connection *info = smbdirect_mr->conn; in smbd_deregister_mr() local
2373 rc = ib_post_send(info->id->qp, wr, NULL); in smbd_deregister_mr()
2376 smbd_disconnect_rdma_connection(info); in smbd_deregister_mr()
2390 info->id->device, smbdirect_mr->sgt.sgl, in smbd_deregister_mr()
2394 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_deregister_mr()
2395 wake_up_interruptible(&info->wait_mr); in smbd_deregister_mr()
2401 queue_work(info->workqueue, &info->mr_recovery_work); in smbd_deregister_mr()
2404 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_deregister_mr()
2405 wake_up(&info->wait_for_mr_cleanup); in smbd_deregister_mr()