Lines Matching refs:info

16 		struct smbd_connection *info);
18 struct smbd_connection *info);
20 struct smbd_connection *info,
22 static int allocate_receive_buffers(struct smbd_connection *info, int num_buf);
23 static void destroy_receive_buffers(struct smbd_connection *info);
26 struct smbd_connection *info, struct smbd_response *response);
28 struct smbd_connection *info,
31 struct smbd_connection *info);
34 struct smbd_connection *info,
37 static int smbd_post_send_empty(struct smbd_connection *info);
39 static void destroy_mr_list(struct smbd_connection *info);
40 static int allocate_mr_list(struct smbd_connection *info);
166 struct smbd_connection *info = in smbd_disconnect_rdma_work() local
169 if (info->transport_status == SMBD_CONNECTED) { in smbd_disconnect_rdma_work()
170 info->transport_status = SMBD_DISCONNECTING; in smbd_disconnect_rdma_work()
171 rdma_disconnect(info->id); in smbd_disconnect_rdma_work()
175 static void smbd_disconnect_rdma_connection(struct smbd_connection *info) in smbd_disconnect_rdma_connection() argument
177 queue_work(info->workqueue, &info->disconnect_work); in smbd_disconnect_rdma_connection()
184 struct smbd_connection *info = id->context; in smbd_conn_upcall() local
192 info->ri_rc = 0; in smbd_conn_upcall()
193 complete(&info->ri_done); in smbd_conn_upcall()
197 info->ri_rc = -EHOSTUNREACH; in smbd_conn_upcall()
198 complete(&info->ri_done); in smbd_conn_upcall()
202 info->ri_rc = -ENETUNREACH; in smbd_conn_upcall()
203 complete(&info->ri_done); in smbd_conn_upcall()
208 info->transport_status = SMBD_CONNECTED; in smbd_conn_upcall()
209 wake_up_interruptible(&info->conn_wait); in smbd_conn_upcall()
216 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
217 wake_up_interruptible(&info->conn_wait); in smbd_conn_upcall()
223 if (info->transport_status == SMBD_NEGOTIATE_FAILED) { in smbd_conn_upcall()
224 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
225 wake_up(&info->conn_wait); in smbd_conn_upcall()
229 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
230 wake_up_interruptible(&info->disconn_wait); in smbd_conn_upcall()
231 wake_up_interruptible(&info->wait_reassembly_queue); in smbd_conn_upcall()
232 wake_up_interruptible_all(&info->wait_send_queue); in smbd_conn_upcall()
246 struct smbd_connection *info = context; in smbd_qp_async_error_upcall() local
249 ib_event_msg(event->event), event->device->name, info); in smbd_qp_async_error_upcall()
254 smbd_disconnect_rdma_connection(info); in smbd_qp_async_error_upcall()
285 smbd_disconnect_rdma_connection(request->info); in send_done()
289 ib_dma_unmap_single(request->info->id->device, in send_done()
294 if (atomic_dec_and_test(&request->info->send_pending)) in send_done()
295 wake_up(&request->info->wait_send_pending); in send_done()
297 wake_up(&request->info->wait_post_send); in send_done()
299 mempool_free(request, request->info->request_mempool); in send_done()
320 struct smbd_connection *info = response->info; in process_negotiation_response() local
334 info->protocol = le16_to_cpu(packet->negotiated_version); in process_negotiation_response()
340 info->receive_credit_target = le16_to_cpu(packet->credits_requested); in process_negotiation_response()
346 atomic_set(&info->send_credits, le16_to_cpu(packet->credits_granted)); in process_negotiation_response()
348 atomic_set(&info->receive_credits, 0); in process_negotiation_response()
350 if (le32_to_cpu(packet->preferred_send_size) > info->max_receive_size) { in process_negotiation_response()
355 info->max_receive_size = le32_to_cpu(packet->preferred_send_size); in process_negotiation_response()
362 info->max_send_size = min_t(int, info->max_send_size, in process_negotiation_response()
371 info->max_fragmented_send_size = in process_negotiation_response()
373 info->rdma_readwrite_threshold = in process_negotiation_response()
374 rdma_readwrite_threshold > info->max_fragmented_send_size ? in process_negotiation_response()
375 info->max_fragmented_send_size : in process_negotiation_response()
379 info->max_readwrite_size = min_t(u32, in process_negotiation_response()
381 info->max_frmr_depth * PAGE_SIZE); in process_negotiation_response()
382 info->max_frmr_depth = info->max_readwrite_size / PAGE_SIZE; in process_negotiation_response()
393 struct smbd_connection *info = in smbd_post_send_credits() local
397 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_credits()
398 wake_up(&info->wait_receive_queues); in smbd_post_send_credits()
402 if (info->receive_credit_target > in smbd_post_send_credits()
403 atomic_read(&info->receive_credits)) { in smbd_post_send_credits()
406 response = get_receive_buffer(info); in smbd_post_send_credits()
408 response = get_empty_queue_buffer(info); in smbd_post_send_credits()
420 rc = smbd_post_recv(info, response); in smbd_post_send_credits()
424 put_receive_buffer(info, response); in smbd_post_send_credits()
432 spin_lock(&info->lock_new_credits_offered); in smbd_post_send_credits()
433 info->new_credits_offered += ret; in smbd_post_send_credits()
434 spin_unlock(&info->lock_new_credits_offered); in smbd_post_send_credits()
437 info->send_immediate = true; in smbd_post_send_credits()
438 if (atomic_read(&info->receive_credits) < in smbd_post_send_credits()
439 info->receive_credit_target - 1) { in smbd_post_send_credits()
440 if (info->keep_alive_requested == KEEP_ALIVE_PENDING || in smbd_post_send_credits()
441 info->send_immediate) { in smbd_post_send_credits()
443 smbd_post_send_empty(info); in smbd_post_send_credits()
454 struct smbd_connection *info = response->info; in recv_done() local
464 smbd_disconnect_rdma_connection(info); in recv_done()
478 info->full_packet_received = true; in recv_done()
479 info->negotiate_done = in recv_done()
481 complete(&info->negotiate_completion); in recv_done()
494 if (info->full_packet_received) in recv_done()
498 info->full_packet_received = false; in recv_done()
500 info->full_packet_received = true; in recv_done()
503 info, in recv_done()
507 put_empty_packet(info, response); in recv_done()
510 wake_up_interruptible(&info->wait_reassembly_queue); in recv_done()
512 atomic_dec(&info->receive_credits); in recv_done()
513 info->receive_credit_target = in recv_done()
517 &info->send_credits); in recv_done()
522 wake_up_interruptible(&info->wait_send_queue); in recv_done()
532 info->keep_alive_requested = KEEP_ALIVE_NONE; in recv_done()
535 info->keep_alive_requested = KEEP_ALIVE_PENDING; in recv_done()
546 put_receive_buffer(info, response); in recv_done()
550 struct smbd_connection *info, in smbd_create_id() argument
557 id = rdma_create_id(&init_net, smbd_conn_upcall, info, in smbd_create_id()
572 init_completion(&info->ri_done); in smbd_create_id()
573 info->ri_rc = -ETIMEDOUT; in smbd_create_id()
582 &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT)); in smbd_create_id()
588 rc = info->ri_rc; in smbd_create_id()
594 info->ri_rc = -ETIMEDOUT; in smbd_create_id()
601 &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT)); in smbd_create_id()
607 rc = info->ri_rc; in smbd_create_id()
635 struct smbd_connection *info, in smbd_ia_open() argument
640 info->id = smbd_create_id(info, dstaddr, port); in smbd_ia_open()
641 if (IS_ERR(info->id)) { in smbd_ia_open()
642 rc = PTR_ERR(info->id); in smbd_ia_open()
646 if (!frwr_is_supported(&info->id->device->attrs)) { in smbd_ia_open()
649 info->id->device->attrs.device_cap_flags, in smbd_ia_open()
650 info->id->device->attrs.max_fast_reg_page_list_len); in smbd_ia_open()
654 info->max_frmr_depth = min_t(int, in smbd_ia_open()
656 info->id->device->attrs.max_fast_reg_page_list_len); in smbd_ia_open()
657 info->mr_type = IB_MR_TYPE_MEM_REG; in smbd_ia_open()
658 if (info->id->device->attrs.kernel_cap_flags & IBK_SG_GAPS_REG) in smbd_ia_open()
659 info->mr_type = IB_MR_TYPE_SG_GAPS; in smbd_ia_open()
661 info->pd = ib_alloc_pd(info->id->device, 0); in smbd_ia_open()
662 if (IS_ERR(info->pd)) { in smbd_ia_open()
663 rc = PTR_ERR(info->pd); in smbd_ia_open()
671 rdma_destroy_id(info->id); in smbd_ia_open()
672 info->id = NULL; in smbd_ia_open()
684 static int smbd_post_send_negotiate_req(struct smbd_connection *info) in smbd_post_send_negotiate_req() argument
691 request = mempool_alloc(info->request_mempool, GFP_KERNEL); in smbd_post_send_negotiate_req()
695 request->info = info; in smbd_post_send_negotiate_req()
701 packet->credits_requested = cpu_to_le16(info->send_credit_target); in smbd_post_send_negotiate_req()
702 packet->preferred_send_size = cpu_to_le32(info->max_send_size); in smbd_post_send_negotiate_req()
703 packet->max_receive_size = cpu_to_le32(info->max_receive_size); in smbd_post_send_negotiate_req()
705 cpu_to_le32(info->max_fragmented_recv_size); in smbd_post_send_negotiate_req()
709 info->id->device, (void *)packet, in smbd_post_send_negotiate_req()
711 if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) { in smbd_post_send_negotiate_req()
717 request->sge[0].lkey = info->pd->local_dma_lkey; in smbd_post_send_negotiate_req()
720 info->id->device, request->sge[0].addr, in smbd_post_send_negotiate_req()
736 atomic_inc(&info->send_pending); in smbd_post_send_negotiate_req()
737 rc = ib_post_send(info->id->qp, &send_wr, NULL); in smbd_post_send_negotiate_req()
743 atomic_dec(&info->send_pending); in smbd_post_send_negotiate_req()
744 ib_dma_unmap_single(info->id->device, request->sge[0].addr, in smbd_post_send_negotiate_req()
747 smbd_disconnect_rdma_connection(info); in smbd_post_send_negotiate_req()
750 mempool_free(request, info->request_mempool); in smbd_post_send_negotiate_req()
762 static int manage_credits_prior_sending(struct smbd_connection *info) in manage_credits_prior_sending() argument
766 spin_lock(&info->lock_new_credits_offered); in manage_credits_prior_sending()
767 new_credits = info->new_credits_offered; in manage_credits_prior_sending()
768 info->new_credits_offered = 0; in manage_credits_prior_sending()
769 spin_unlock(&info->lock_new_credits_offered); in manage_credits_prior_sending()
783 static int manage_keep_alive_before_sending(struct smbd_connection *info) in manage_keep_alive_before_sending() argument
785 if (info->keep_alive_requested == KEEP_ALIVE_PENDING) { in manage_keep_alive_before_sending()
786 info->keep_alive_requested = KEEP_ALIVE_SENT; in manage_keep_alive_before_sending()
793 static int smbd_post_send(struct smbd_connection *info, in smbd_post_send() argument
804 info->id->device, in smbd_post_send()
819 rc = ib_post_send(info->id->qp, &send_wr, NULL); in smbd_post_send()
822 smbd_disconnect_rdma_connection(info); in smbd_post_send()
826 mod_delayed_work(info->workqueue, &info->idle_timer_work, in smbd_post_send()
827 info->keep_alive_interval*HZ); in smbd_post_send()
832 static int smbd_post_send_iter(struct smbd_connection *info, in smbd_post_send_iter() argument
845 rc = wait_event_interruptible(info->wait_send_queue, in smbd_post_send_iter()
846 atomic_read(&info->send_credits) > 0 || in smbd_post_send_iter()
847 info->transport_status != SMBD_CONNECTED); in smbd_post_send_iter()
851 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_iter()
856 if (unlikely(atomic_dec_return(&info->send_credits) < 0)) { in smbd_post_send_iter()
857 atomic_inc(&info->send_credits); in smbd_post_send_iter()
862 wait_event(info->wait_post_send, in smbd_post_send_iter()
863 atomic_read(&info->send_pending) < info->send_credit_target || in smbd_post_send_iter()
864 info->transport_status != SMBD_CONNECTED); in smbd_post_send_iter()
866 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_iter()
872 if (unlikely(atomic_inc_return(&info->send_pending) > in smbd_post_send_iter()
873 info->send_credit_target)) { in smbd_post_send_iter()
874 atomic_dec(&info->send_pending); in smbd_post_send_iter()
878 request = mempool_alloc(info->request_mempool, GFP_KERNEL); in smbd_post_send_iter()
884 request->info = info; in smbd_post_send_iter()
893 .device = info->id->device, in smbd_post_send_iter()
894 .local_dma_lkey = info->pd->local_dma_lkey, in smbd_post_send_iter()
912 packet->credits_requested = cpu_to_le16(info->send_credit_target); in smbd_post_send_iter()
914 new_credits = manage_credits_prior_sending(info); in smbd_post_send_iter()
915 atomic_add(new_credits, &info->receive_credits); in smbd_post_send_iter()
918 info->send_immediate = false; in smbd_post_send_iter()
921 if (manage_keep_alive_before_sending(info)) in smbd_post_send_iter()
946 request->sge[0].addr = ib_dma_map_single(info->id->device, in smbd_post_send_iter()
950 if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) { in smbd_post_send_iter()
957 request->sge[0].lkey = info->pd->local_dma_lkey; in smbd_post_send_iter()
959 rc = smbd_post_send(info, request); in smbd_post_send_iter()
966 ib_dma_unmap_single(info->id->device, in smbd_post_send_iter()
970 mempool_free(request, info->request_mempool); in smbd_post_send_iter()
973 spin_lock(&info->lock_new_credits_offered); in smbd_post_send_iter()
974 info->new_credits_offered += new_credits; in smbd_post_send_iter()
975 spin_unlock(&info->lock_new_credits_offered); in smbd_post_send_iter()
976 atomic_sub(new_credits, &info->receive_credits); in smbd_post_send_iter()
979 if (atomic_dec_and_test(&info->send_pending)) in smbd_post_send_iter()
980 wake_up(&info->wait_send_pending); in smbd_post_send_iter()
984 atomic_inc(&info->send_credits); in smbd_post_send_iter()
995 static int smbd_post_send_empty(struct smbd_connection *info) in smbd_post_send_empty() argument
999 info->count_send_empty++; in smbd_post_send_empty()
1000 return smbd_post_send_iter(info, NULL, &remaining_data_length); in smbd_post_send_empty()
1009 struct smbd_connection *info, struct smbd_response *response) in smbd_post_recv() argument
1015 info->id->device, response->packet, in smbd_post_recv()
1016 info->max_receive_size, DMA_FROM_DEVICE); in smbd_post_recv()
1017 if (ib_dma_mapping_error(info->id->device, response->sge.addr)) in smbd_post_recv()
1020 response->sge.length = info->max_receive_size; in smbd_post_recv()
1021 response->sge.lkey = info->pd->local_dma_lkey; in smbd_post_recv()
1030 rc = ib_post_recv(info->id->qp, &recv_wr, NULL); in smbd_post_recv()
1032 ib_dma_unmap_single(info->id->device, response->sge.addr, in smbd_post_recv()
1034 smbd_disconnect_rdma_connection(info); in smbd_post_recv()
1042 static int smbd_negotiate(struct smbd_connection *info) in smbd_negotiate() argument
1045 struct smbd_response *response = get_receive_buffer(info); in smbd_negotiate()
1048 rc = smbd_post_recv(info, response); in smbd_negotiate()
1055 init_completion(&info->negotiate_completion); in smbd_negotiate()
1056 info->negotiate_done = false; in smbd_negotiate()
1057 rc = smbd_post_send_negotiate_req(info); in smbd_negotiate()
1062 &info->negotiate_completion, SMBD_NEGOTIATE_TIMEOUT * HZ); in smbd_negotiate()
1065 if (info->negotiate_done) in smbd_negotiate()
1079 struct smbd_connection *info, struct smbd_response *response) in put_empty_packet() argument
1081 spin_lock(&info->empty_packet_queue_lock); in put_empty_packet()
1082 list_add_tail(&response->list, &info->empty_packet_queue); in put_empty_packet()
1083 info->count_empty_packet_queue++; in put_empty_packet()
1084 spin_unlock(&info->empty_packet_queue_lock); in put_empty_packet()
1086 queue_work(info->workqueue, &info->post_send_credits_work); in put_empty_packet()
1100 struct smbd_connection *info, in enqueue_reassembly() argument
1104 spin_lock(&info->reassembly_queue_lock); in enqueue_reassembly()
1105 list_add_tail(&response->list, &info->reassembly_queue); in enqueue_reassembly()
1106 info->reassembly_queue_length++; in enqueue_reassembly()
1114 info->reassembly_data_length += data_length; in enqueue_reassembly()
1115 spin_unlock(&info->reassembly_queue_lock); in enqueue_reassembly()
1116 info->count_reassembly_queue++; in enqueue_reassembly()
1117 info->count_enqueue_reassembly_queue++; in enqueue_reassembly()
1125 static struct smbd_response *_get_first_reassembly(struct smbd_connection *info) in _get_first_reassembly() argument
1129 if (!list_empty(&info->reassembly_queue)) { in _get_first_reassembly()
1131 &info->reassembly_queue, in _get_first_reassembly()
1138 struct smbd_connection *info) in get_empty_queue_buffer() argument
1143 spin_lock_irqsave(&info->empty_packet_queue_lock, flags); in get_empty_queue_buffer()
1144 if (!list_empty(&info->empty_packet_queue)) { in get_empty_queue_buffer()
1146 &info->empty_packet_queue, in get_empty_queue_buffer()
1149 info->count_empty_packet_queue--; in get_empty_queue_buffer()
1151 spin_unlock_irqrestore(&info->empty_packet_queue_lock, flags); in get_empty_queue_buffer()
1162 static struct smbd_response *get_receive_buffer(struct smbd_connection *info) in get_receive_buffer() argument
1167 spin_lock_irqsave(&info->receive_queue_lock, flags); in get_receive_buffer()
1168 if (!list_empty(&info->receive_queue)) { in get_receive_buffer()
1170 &info->receive_queue, in get_receive_buffer()
1173 info->count_receive_queue--; in get_receive_buffer()
1174 info->count_get_receive_buffer++; in get_receive_buffer()
1176 spin_unlock_irqrestore(&info->receive_queue_lock, flags); in get_receive_buffer()
1188 struct smbd_connection *info, struct smbd_response *response) in put_receive_buffer() argument
1192 ib_dma_unmap_single(info->id->device, response->sge.addr, in put_receive_buffer()
1195 spin_lock_irqsave(&info->receive_queue_lock, flags); in put_receive_buffer()
1196 list_add_tail(&response->list, &info->receive_queue); in put_receive_buffer()
1197 info->count_receive_queue++; in put_receive_buffer()
1198 info->count_put_receive_buffer++; in put_receive_buffer()
1199 spin_unlock_irqrestore(&info->receive_queue_lock, flags); in put_receive_buffer()
1201 queue_work(info->workqueue, &info->post_send_credits_work); in put_receive_buffer()
1205 static int allocate_receive_buffers(struct smbd_connection *info, int num_buf) in allocate_receive_buffers() argument
1210 INIT_LIST_HEAD(&info->reassembly_queue); in allocate_receive_buffers()
1211 spin_lock_init(&info->reassembly_queue_lock); in allocate_receive_buffers()
1212 info->reassembly_data_length = 0; in allocate_receive_buffers()
1213 info->reassembly_queue_length = 0; in allocate_receive_buffers()
1215 INIT_LIST_HEAD(&info->receive_queue); in allocate_receive_buffers()
1216 spin_lock_init(&info->receive_queue_lock); in allocate_receive_buffers()
1217 info->count_receive_queue = 0; in allocate_receive_buffers()
1219 INIT_LIST_HEAD(&info->empty_packet_queue); in allocate_receive_buffers()
1220 spin_lock_init(&info->empty_packet_queue_lock); in allocate_receive_buffers()
1221 info->count_empty_packet_queue = 0; in allocate_receive_buffers()
1223 init_waitqueue_head(&info->wait_receive_queues); in allocate_receive_buffers()
1226 response = mempool_alloc(info->response_mempool, GFP_KERNEL); in allocate_receive_buffers()
1230 response->info = info; in allocate_receive_buffers()
1231 list_add_tail(&response->list, &info->receive_queue); in allocate_receive_buffers()
1232 info->count_receive_queue++; in allocate_receive_buffers()
1238 while (!list_empty(&info->receive_queue)) { in allocate_receive_buffers()
1240 &info->receive_queue, in allocate_receive_buffers()
1243 info->count_receive_queue--; in allocate_receive_buffers()
1245 mempool_free(response, info->response_mempool); in allocate_receive_buffers()
1250 static void destroy_receive_buffers(struct smbd_connection *info) in destroy_receive_buffers() argument
1254 while ((response = get_receive_buffer(info))) in destroy_receive_buffers()
1255 mempool_free(response, info->response_mempool); in destroy_receive_buffers()
1257 while ((response = get_empty_queue_buffer(info))) in destroy_receive_buffers()
1258 mempool_free(response, info->response_mempool); in destroy_receive_buffers()
1264 struct smbd_connection *info = container_of( in idle_connection_timer() local
1268 if (info->keep_alive_requested != KEEP_ALIVE_NONE) { in idle_connection_timer()
1271 info->keep_alive_requested); in idle_connection_timer()
1272 smbd_disconnect_rdma_connection(info); in idle_connection_timer()
1277 smbd_post_send_empty(info); in idle_connection_timer()
1280 queue_delayed_work(info->workqueue, &info->idle_timer_work, in idle_connection_timer()
1281 info->keep_alive_interval*HZ); in idle_connection_timer()
1291 struct smbd_connection *info = server->smbd_conn; in smbd_destroy() local
1295 if (!info) { in smbd_destroy()
1301 if (info->transport_status != SMBD_DISCONNECTED) { in smbd_destroy()
1305 info->disconn_wait, in smbd_destroy()
1306 info->transport_status == SMBD_DISCONNECTED); in smbd_destroy()
1310 ib_drain_qp(info->id->qp); in smbd_destroy()
1311 rdma_destroy_qp(info->id); in smbd_destroy()
1314 cancel_delayed_work_sync(&info->idle_timer_work); in smbd_destroy()
1317 wait_event(info->wait_send_pending, in smbd_destroy()
1318 atomic_read(&info->send_pending) == 0); in smbd_destroy()
1323 spin_lock_irqsave(&info->reassembly_queue_lock, flags); in smbd_destroy()
1324 response = _get_first_reassembly(info); in smbd_destroy()
1328 &info->reassembly_queue_lock, flags); in smbd_destroy()
1329 put_receive_buffer(info, response); in smbd_destroy()
1332 &info->reassembly_queue_lock, flags); in smbd_destroy()
1334 info->reassembly_data_length = 0; in smbd_destroy()
1337 wait_event(info->wait_receive_queues, in smbd_destroy()
1338 info->count_receive_queue + info->count_empty_packet_queue in smbd_destroy()
1339 == info->receive_credit_max); in smbd_destroy()
1340 destroy_receive_buffers(info); in smbd_destroy()
1350 wake_up_interruptible_all(&info->wait_mr); in smbd_destroy()
1351 while (atomic_read(&info->mr_used_count)) { in smbd_destroy()
1356 destroy_mr_list(info); in smbd_destroy()
1358 ib_free_cq(info->send_cq); in smbd_destroy()
1359 ib_free_cq(info->recv_cq); in smbd_destroy()
1360 ib_dealloc_pd(info->pd); in smbd_destroy()
1361 rdma_destroy_id(info->id); in smbd_destroy()
1364 mempool_destroy(info->request_mempool); in smbd_destroy()
1365 kmem_cache_destroy(info->request_cache); in smbd_destroy()
1367 mempool_destroy(info->response_mempool); in smbd_destroy()
1368 kmem_cache_destroy(info->response_cache); in smbd_destroy()
1370 info->transport_status = SMBD_DESTROYED; in smbd_destroy()
1372 destroy_workqueue(info->workqueue); in smbd_destroy()
1374 kfree(info); in smbd_destroy()
1414 static void destroy_caches_and_workqueue(struct smbd_connection *info) in destroy_caches_and_workqueue() argument
1416 destroy_receive_buffers(info); in destroy_caches_and_workqueue()
1417 destroy_workqueue(info->workqueue); in destroy_caches_and_workqueue()
1418 mempool_destroy(info->response_mempool); in destroy_caches_and_workqueue()
1419 kmem_cache_destroy(info->response_cache); in destroy_caches_and_workqueue()
1420 mempool_destroy(info->request_mempool); in destroy_caches_and_workqueue()
1421 kmem_cache_destroy(info->request_cache); in destroy_caches_and_workqueue()
1425 static int allocate_caches_and_workqueue(struct smbd_connection *info) in allocate_caches_and_workqueue() argument
1430 scnprintf(name, MAX_NAME_LEN, "smbd_request_%p", info); in allocate_caches_and_workqueue()
1431 info->request_cache = in allocate_caches_and_workqueue()
1437 if (!info->request_cache) in allocate_caches_and_workqueue()
1440 info->request_mempool = in allocate_caches_and_workqueue()
1441 mempool_create(info->send_credit_target, mempool_alloc_slab, in allocate_caches_and_workqueue()
1442 mempool_free_slab, info->request_cache); in allocate_caches_and_workqueue()
1443 if (!info->request_mempool) in allocate_caches_and_workqueue()
1446 scnprintf(name, MAX_NAME_LEN, "smbd_response_%p", info); in allocate_caches_and_workqueue()
1447 info->response_cache = in allocate_caches_and_workqueue()
1451 info->max_receive_size, in allocate_caches_and_workqueue()
1453 if (!info->response_cache) in allocate_caches_and_workqueue()
1456 info->response_mempool = in allocate_caches_and_workqueue()
1457 mempool_create(info->receive_credit_max, mempool_alloc_slab, in allocate_caches_and_workqueue()
1458 mempool_free_slab, info->response_cache); in allocate_caches_and_workqueue()
1459 if (!info->response_mempool) in allocate_caches_and_workqueue()
1462 scnprintf(name, MAX_NAME_LEN, "smbd_%p", info); in allocate_caches_and_workqueue()
1463 info->workqueue = create_workqueue(name); in allocate_caches_and_workqueue()
1464 if (!info->workqueue) in allocate_caches_and_workqueue()
1467 rc = allocate_receive_buffers(info, info->receive_credit_max); in allocate_caches_and_workqueue()
1476 destroy_workqueue(info->workqueue); in allocate_caches_and_workqueue()
1478 mempool_destroy(info->response_mempool); in allocate_caches_and_workqueue()
1480 kmem_cache_destroy(info->response_cache); in allocate_caches_and_workqueue()
1482 mempool_destroy(info->request_mempool); in allocate_caches_and_workqueue()
1484 kmem_cache_destroy(info->request_cache); in allocate_caches_and_workqueue()
1493 struct smbd_connection *info; in _smbd_get_connection() local
1500 info = kzalloc(sizeof(struct smbd_connection), GFP_KERNEL); in _smbd_get_connection()
1501 if (!info) in _smbd_get_connection()
1504 info->transport_status = SMBD_CONNECTING; in _smbd_get_connection()
1505 rc = smbd_ia_open(info, dstaddr, port); in _smbd_get_connection()
1511 if (smbd_send_credit_target > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1512 smbd_send_credit_target > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1515 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1516 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1520 if (smbd_receive_credit_max > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1521 smbd_receive_credit_max > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1524 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1525 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1529 info->receive_credit_max = smbd_receive_credit_max; in _smbd_get_connection()
1530 info->send_credit_target = smbd_send_credit_target; in _smbd_get_connection()
1531 info->max_send_size = smbd_max_send_size; in _smbd_get_connection()
1532 info->max_fragmented_recv_size = smbd_max_fragmented_recv_size; in _smbd_get_connection()
1533 info->max_receive_size = smbd_max_receive_size; in _smbd_get_connection()
1534 info->keep_alive_interval = smbd_keep_alive_interval; in _smbd_get_connection()
1536 if (info->id->device->attrs.max_send_sge < SMBDIRECT_MAX_SEND_SGE || in _smbd_get_connection()
1537 info->id->device->attrs.max_recv_sge < SMBDIRECT_MAX_RECV_SGE) { in _smbd_get_connection()
1541 info->id->device->name, in _smbd_get_connection()
1542 info->id->device->attrs.max_send_sge, in _smbd_get_connection()
1543 info->id->device->attrs.max_recv_sge); in _smbd_get_connection()
1547 info->send_cq = NULL; in _smbd_get_connection()
1548 info->recv_cq = NULL; in _smbd_get_connection()
1549 info->send_cq = in _smbd_get_connection()
1550 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1551 info->send_credit_target, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1552 if (IS_ERR(info->send_cq)) { in _smbd_get_connection()
1553 info->send_cq = NULL; in _smbd_get_connection()
1557 info->recv_cq = in _smbd_get_connection()
1558 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1559 info->receive_credit_max, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1560 if (IS_ERR(info->recv_cq)) { in _smbd_get_connection()
1561 info->recv_cq = NULL; in _smbd_get_connection()
1567 qp_attr.qp_context = info; in _smbd_get_connection()
1568 qp_attr.cap.max_send_wr = info->send_credit_target; in _smbd_get_connection()
1569 qp_attr.cap.max_recv_wr = info->receive_credit_max; in _smbd_get_connection()
1575 qp_attr.send_cq = info->send_cq; in _smbd_get_connection()
1576 qp_attr.recv_cq = info->recv_cq; in _smbd_get_connection()
1579 rc = rdma_create_qp(info->id, info->pd, &qp_attr); in _smbd_get_connection()
1589 min(info->id->device->attrs.max_qp_rd_atom, in _smbd_get_connection()
1591 info->responder_resources = conn_param.responder_resources; in _smbd_get_connection()
1593 info->responder_resources); in _smbd_get_connection()
1596 info->id->device->ops.get_port_immutable( in _smbd_get_connection()
1597 info->id->device, info->id->port_num, &port_immutable); in _smbd_get_connection()
1599 ird_ord_hdr[0] = info->responder_resources; in _smbd_get_connection()
1615 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1616 init_waitqueue_head(&info->disconn_wait); in _smbd_get_connection()
1617 init_waitqueue_head(&info->wait_reassembly_queue); in _smbd_get_connection()
1618 rc = rdma_connect(info->id, &conn_param); in _smbd_get_connection()
1625 info->conn_wait, info->transport_status != SMBD_CONNECTING); in _smbd_get_connection()
1627 if (info->transport_status != SMBD_CONNECTED) { in _smbd_get_connection()
1634 rc = allocate_caches_and_workqueue(info); in _smbd_get_connection()
1640 init_waitqueue_head(&info->wait_send_queue); in _smbd_get_connection()
1641 INIT_DELAYED_WORK(&info->idle_timer_work, idle_connection_timer); in _smbd_get_connection()
1642 queue_delayed_work(info->workqueue, &info->idle_timer_work, in _smbd_get_connection()
1643 info->keep_alive_interval*HZ); in _smbd_get_connection()
1645 init_waitqueue_head(&info->wait_send_pending); in _smbd_get_connection()
1646 atomic_set(&info->send_pending, 0); in _smbd_get_connection()
1648 init_waitqueue_head(&info->wait_post_send); in _smbd_get_connection()
1650 INIT_WORK(&info->disconnect_work, smbd_disconnect_rdma_work); in _smbd_get_connection()
1651 INIT_WORK(&info->post_send_credits_work, smbd_post_send_credits); in _smbd_get_connection()
1652 info->new_credits_offered = 0; in _smbd_get_connection()
1653 spin_lock_init(&info->lock_new_credits_offered); in _smbd_get_connection()
1655 rc = smbd_negotiate(info); in _smbd_get_connection()
1661 rc = allocate_mr_list(info); in _smbd_get_connection()
1667 return info; in _smbd_get_connection()
1671 server->smbd_conn = info; in _smbd_get_connection()
1676 cancel_delayed_work_sync(&info->idle_timer_work); in _smbd_get_connection()
1677 destroy_caches_and_workqueue(info); in _smbd_get_connection()
1678 info->transport_status = SMBD_NEGOTIATE_FAILED; in _smbd_get_connection()
1679 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1680 rdma_disconnect(info->id); in _smbd_get_connection()
1681 wait_event(info->conn_wait, in _smbd_get_connection()
1682 info->transport_status == SMBD_DISCONNECTED); in _smbd_get_connection()
1686 rdma_destroy_qp(info->id); in _smbd_get_connection()
1690 if (info->send_cq) in _smbd_get_connection()
1691 ib_free_cq(info->send_cq); in _smbd_get_connection()
1692 if (info->recv_cq) in _smbd_get_connection()
1693 ib_free_cq(info->recv_cq); in _smbd_get_connection()
1696 ib_dealloc_pd(info->pd); in _smbd_get_connection()
1697 rdma_destroy_id(info->id); in _smbd_get_connection()
1700 kfree(info); in _smbd_get_connection()
1734 static int smbd_recv_buf(struct smbd_connection *info, char *buf, in smbd_recv_buf() argument
1750 info->reassembly_data_length); in smbd_recv_buf()
1751 if (info->reassembly_data_length >= size) { in smbd_recv_buf()
1763 queue_length = info->reassembly_queue_length; in smbd_recv_buf()
1766 offset = info->first_entry_offset; in smbd_recv_buf()
1768 response = _get_first_reassembly(info); in smbd_recv_buf()
1812 &info->reassembly_queue_lock); in smbd_recv_buf()
1815 &info->reassembly_queue_lock); in smbd_recv_buf()
1818 info->count_reassembly_queue--; in smbd_recv_buf()
1819 info->count_dequeue_reassembly_queue++; in smbd_recv_buf()
1820 put_receive_buffer(info, response); in smbd_recv_buf()
1834 spin_lock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1835 info->reassembly_data_length -= data_read; in smbd_recv_buf()
1836 info->reassembly_queue_length -= queue_removed; in smbd_recv_buf()
1837 spin_unlock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1839 info->first_entry_offset = offset; in smbd_recv_buf()
1841 data_read, info->reassembly_data_length, in smbd_recv_buf()
1842 info->first_entry_offset); in smbd_recv_buf()
1849 info->wait_reassembly_queue, in smbd_recv_buf()
1850 info->reassembly_data_length >= size || in smbd_recv_buf()
1851 info->transport_status != SMBD_CONNECTED); in smbd_recv_buf()
1856 if (info->transport_status != SMBD_CONNECTED) { in smbd_recv_buf()
1870 static int smbd_recv_page(struct smbd_connection *info, in smbd_recv_page() argument
1880 info->wait_reassembly_queue, in smbd_recv_page()
1881 info->reassembly_data_length >= to_read || in smbd_recv_page()
1882 info->transport_status != SMBD_CONNECTED); in smbd_recv_page()
1893 ret = smbd_recv_buf(info, to_address, to_read); in smbd_recv_page()
1904 int smbd_recv(struct smbd_connection *info, struct msghdr *msg) in smbd_recv() argument
1923 rc = smbd_recv_buf(info, buf, to_read); in smbd_recv()
1930 rc = smbd_recv_page(info, page, page_offset, to_read); in smbd_recv()
1956 struct smbd_connection *info = server->smbd_conn; in smbd_send() local
1962 if (info->transport_status != SMBD_CONNECTED) in smbd_send()
1974 if (unlikely(remaining_data_length > info->max_fragmented_send_size)) { in smbd_send()
1977 remaining_data_length, info->max_fragmented_send_size); in smbd_send()
2003 rc = smbd_post_send_iter(info, &iter, &remaining_data_length); in smbd_send()
2009 rc = smbd_post_send_iter(info, &rqst->rq_iter, in smbd_send()
2024 wait_event(info->wait_send_pending, in smbd_send()
2025 atomic_read(&info->send_pending) == 0); in smbd_send()
2054 struct smbd_connection *info = in smbd_mr_recovery_work() local
2059 list_for_each_entry(smbdirect_mr, &info->mr_list, list) { in smbd_mr_recovery_work()
2068 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2073 info->pd, info->mr_type, in smbd_mr_recovery_work()
2074 info->max_frmr_depth); in smbd_mr_recovery_work()
2077 info->mr_type, in smbd_mr_recovery_work()
2078 info->max_frmr_depth); in smbd_mr_recovery_work()
2079 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2095 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_mr_recovery_work()
2096 wake_up_interruptible(&info->wait_mr); in smbd_mr_recovery_work()
2100 static void destroy_mr_list(struct smbd_connection *info) in destroy_mr_list() argument
2104 cancel_work_sync(&info->mr_recovery_work); in destroy_mr_list()
2105 list_for_each_entry_safe(mr, tmp, &info->mr_list, list) { in destroy_mr_list()
2107 ib_dma_unmap_sg(info->id->device, mr->sgt.sgl, in destroy_mr_list()
2122 static int allocate_mr_list(struct smbd_connection *info) in allocate_mr_list() argument
2127 INIT_LIST_HEAD(&info->mr_list); in allocate_mr_list()
2128 init_waitqueue_head(&info->wait_mr); in allocate_mr_list()
2129 spin_lock_init(&info->mr_list_lock); in allocate_mr_list()
2130 atomic_set(&info->mr_ready_count, 0); in allocate_mr_list()
2131 atomic_set(&info->mr_used_count, 0); in allocate_mr_list()
2132 init_waitqueue_head(&info->wait_for_mr_cleanup); in allocate_mr_list()
2133 INIT_WORK(&info->mr_recovery_work, smbd_mr_recovery_work); in allocate_mr_list()
2135 for (i = 0; i < info->responder_resources * 2; i++) { in allocate_mr_list()
2139 smbdirect_mr->mr = ib_alloc_mr(info->pd, info->mr_type, in allocate_mr_list()
2140 info->max_frmr_depth); in allocate_mr_list()
2143 info->mr_type, info->max_frmr_depth); in allocate_mr_list()
2146 smbdirect_mr->sgt.sgl = kcalloc(info->max_frmr_depth, in allocate_mr_list()
2155 smbdirect_mr->conn = info; in allocate_mr_list()
2157 list_add_tail(&smbdirect_mr->list, &info->mr_list); in allocate_mr_list()
2158 atomic_inc(&info->mr_ready_count); in allocate_mr_list()
2165 list_for_each_entry_safe(smbdirect_mr, tmp, &info->mr_list, list) { in allocate_mr_list()
2182 static struct smbd_mr *get_mr(struct smbd_connection *info) in get_mr() argument
2187 rc = wait_event_interruptible(info->wait_mr, in get_mr()
2188 atomic_read(&info->mr_ready_count) || in get_mr()
2189 info->transport_status != SMBD_CONNECTED); in get_mr()
2195 if (info->transport_status != SMBD_CONNECTED) { in get_mr()
2197 info->transport_status); in get_mr()
2201 spin_lock(&info->mr_list_lock); in get_mr()
2202 list_for_each_entry(ret, &info->mr_list, list) { in get_mr()
2205 spin_unlock(&info->mr_list_lock); in get_mr()
2206 atomic_dec(&info->mr_ready_count); in get_mr()
2207 atomic_inc(&info->mr_used_count); in get_mr()
2212 spin_unlock(&info->mr_list_lock); in get_mr()
2223 static int smbd_iter_to_mr(struct smbd_connection *info, in smbd_iter_to_mr() argument
2246 struct smbd_mr *smbd_register_mr(struct smbd_connection *info, in smbd_register_mr() argument
2255 num_pages = iov_iter_npages(iter, info->max_frmr_depth + 1); in smbd_register_mr()
2256 if (num_pages > info->max_frmr_depth) { in smbd_register_mr()
2258 num_pages, info->max_frmr_depth); in smbd_register_mr()
2263 smbdirect_mr = get_mr(info); in smbd_register_mr()
2276 num_pages, iov_iter_count(iter), info->max_frmr_depth); in smbd_register_mr()
2277 smbd_iter_to_mr(info, iter, &smbdirect_mr->sgt, info->max_frmr_depth); in smbd_register_mr()
2279 rc = ib_dma_map_sg(info->id->device, smbdirect_mr->sgt.sgl, in smbd_register_mr()
2315 rc = ib_post_send(info->id->qp, &reg_wr->wr, NULL); in smbd_register_mr()
2324 ib_dma_unmap_sg(info->id->device, smbdirect_mr->sgt.sgl, in smbd_register_mr()
2329 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_register_mr()
2330 wake_up(&info->wait_for_mr_cleanup); in smbd_register_mr()
2332 smbd_disconnect_rdma_connection(info); in smbd_register_mr()
2361 struct smbd_connection *info = smbdirect_mr->conn; in smbd_deregister_mr() local
2375 rc = ib_post_send(info->id->qp, wr, NULL); in smbd_deregister_mr()
2378 smbd_disconnect_rdma_connection(info); in smbd_deregister_mr()
2392 info->id->device, smbdirect_mr->sgt.sgl, in smbd_deregister_mr()
2396 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_deregister_mr()
2397 wake_up_interruptible(&info->wait_mr); in smbd_deregister_mr()
2403 queue_work(info->workqueue, &info->mr_recovery_work); in smbd_deregister_mr()
2406 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_deregister_mr()
2407 wake_up(&info->wait_for_mr_cleanup); in smbd_deregister_mr()