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 struct smbd_connection *info,
40 static int smbd_post_send_page(struct smbd_connection *info,
44 static void destroy_mr_list(struct smbd_connection *info);
45 static int allocate_mr_list(struct smbd_connection *info);
160 struct smbd_connection *info = in smbd_disconnect_rdma_work() local
163 if (info->transport_status == SMBD_CONNECTED) { in smbd_disconnect_rdma_work()
164 info->transport_status = SMBD_DISCONNECTING; in smbd_disconnect_rdma_work()
165 rdma_disconnect(info->id); in smbd_disconnect_rdma_work()
169 static void smbd_disconnect_rdma_connection(struct smbd_connection *info) in smbd_disconnect_rdma_connection() argument
171 queue_work(info->workqueue, &info->disconnect_work); in smbd_disconnect_rdma_connection()
178 struct smbd_connection *info = id->context; in smbd_conn_upcall() local
186 info->ri_rc = 0; in smbd_conn_upcall()
187 complete(&info->ri_done); in smbd_conn_upcall()
191 info->ri_rc = -EHOSTUNREACH; in smbd_conn_upcall()
192 complete(&info->ri_done); in smbd_conn_upcall()
196 info->ri_rc = -ENETUNREACH; in smbd_conn_upcall()
197 complete(&info->ri_done); in smbd_conn_upcall()
202 info->transport_status = SMBD_CONNECTED; in smbd_conn_upcall()
203 wake_up_interruptible(&info->conn_wait); in smbd_conn_upcall()
210 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
211 wake_up_interruptible(&info->conn_wait); in smbd_conn_upcall()
217 if (info->transport_status == SMBD_NEGOTIATE_FAILED) { in smbd_conn_upcall()
218 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
219 wake_up(&info->conn_wait); in smbd_conn_upcall()
223 info->transport_status = SMBD_DISCONNECTED; in smbd_conn_upcall()
224 wake_up_interruptible(&info->disconn_wait); in smbd_conn_upcall()
225 wake_up_interruptible(&info->wait_reassembly_queue); in smbd_conn_upcall()
226 wake_up_interruptible_all(&info->wait_send_queue); in smbd_conn_upcall()
240 struct smbd_connection *info = context; in smbd_qp_async_error_upcall() local
243 ib_event_msg(event->event), event->device->name, info); in smbd_qp_async_error_upcall()
248 smbd_disconnect_rdma_connection(info); in smbd_qp_async_error_upcall()
278 smbd_disconnect_rdma_connection(request->info); in send_done()
282 ib_dma_unmap_single(request->info->id->device, in send_done()
287 if (atomic_dec_and_test(&request->info->send_pending)) in send_done()
288 wake_up(&request->info->wait_send_pending); in send_done()
290 wake_up(&request->info->wait_post_send); in send_done()
292 mempool_free(request, request->info->request_mempool); in send_done()
313 struct smbd_connection *info = response->info; in process_negotiation_response() local
327 info->protocol = le16_to_cpu(packet->negotiated_version); in process_negotiation_response()
333 info->receive_credit_target = le16_to_cpu(packet->credits_requested); in process_negotiation_response()
339 atomic_set(&info->send_credits, le16_to_cpu(packet->credits_granted)); in process_negotiation_response()
341 atomic_set(&info->receive_credits, 0); in process_negotiation_response()
343 if (le32_to_cpu(packet->preferred_send_size) > info->max_receive_size) { in process_negotiation_response()
348 info->max_receive_size = le32_to_cpu(packet->preferred_send_size); in process_negotiation_response()
355 info->max_send_size = min_t(int, info->max_send_size, in process_negotiation_response()
364 info->max_fragmented_send_size = in process_negotiation_response()
366 info->rdma_readwrite_threshold = in process_negotiation_response()
367 rdma_readwrite_threshold > info->max_fragmented_send_size ? in process_negotiation_response()
368 info->max_fragmented_send_size : in process_negotiation_response()
372 info->max_readwrite_size = min_t(u32, in process_negotiation_response()
374 info->max_frmr_depth * PAGE_SIZE); in process_negotiation_response()
375 info->max_frmr_depth = info->max_readwrite_size / PAGE_SIZE; in process_negotiation_response()
386 struct smbd_connection *info = in smbd_post_send_credits() local
390 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_credits()
391 wake_up(&info->wait_receive_queues); in smbd_post_send_credits()
395 if (info->receive_credit_target > in smbd_post_send_credits()
396 atomic_read(&info->receive_credits)) { in smbd_post_send_credits()
399 response = get_receive_buffer(info); in smbd_post_send_credits()
401 response = get_empty_queue_buffer(info); in smbd_post_send_credits()
413 rc = smbd_post_recv(info, response); in smbd_post_send_credits()
417 put_receive_buffer(info, response); in smbd_post_send_credits()
425 spin_lock(&info->lock_new_credits_offered); in smbd_post_send_credits()
426 info->new_credits_offered += ret; in smbd_post_send_credits()
427 spin_unlock(&info->lock_new_credits_offered); in smbd_post_send_credits()
430 info->send_immediate = true; in smbd_post_send_credits()
431 if (atomic_read(&info->receive_credits) < in smbd_post_send_credits()
432 info->receive_credit_target - 1) { in smbd_post_send_credits()
433 if (info->keep_alive_requested == KEEP_ALIVE_PENDING || in smbd_post_send_credits()
434 info->send_immediate) { in smbd_post_send_credits()
436 smbd_post_send_empty(info); in smbd_post_send_credits()
447 struct smbd_connection *info = response->info; in recv_done() local
457 smbd_disconnect_rdma_connection(info); in recv_done()
471 info->full_packet_received = true; in recv_done()
472 info->negotiate_done = in recv_done()
474 complete(&info->negotiate_completion); in recv_done()
487 if (info->full_packet_received) in recv_done()
491 info->full_packet_received = false; in recv_done()
493 info->full_packet_received = true; in recv_done()
496 info, in recv_done()
500 put_empty_packet(info, response); in recv_done()
503 wake_up_interruptible(&info->wait_reassembly_queue); in recv_done()
505 atomic_dec(&info->receive_credits); in recv_done()
506 info->receive_credit_target = in recv_done()
510 &info->send_credits); in recv_done()
515 wake_up_interruptible(&info->wait_send_queue); in recv_done()
525 info->keep_alive_requested = KEEP_ALIVE_NONE; in recv_done()
528 info->keep_alive_requested = KEEP_ALIVE_PENDING; in recv_done()
539 put_receive_buffer(info, response); in recv_done()
543 struct smbd_connection *info, in smbd_create_id() argument
550 id = rdma_create_id(&init_net, smbd_conn_upcall, info, in smbd_create_id()
565 init_completion(&info->ri_done); in smbd_create_id()
566 info->ri_rc = -ETIMEDOUT; in smbd_create_id()
575 &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT)); in smbd_create_id()
576 rc = info->ri_rc; in smbd_create_id()
582 info->ri_rc = -ETIMEDOUT; in smbd_create_id()
589 &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT)); in smbd_create_id()
590 rc = info->ri_rc; in smbd_create_id()
618 struct smbd_connection *info, in smbd_ia_open() argument
623 info->id = smbd_create_id(info, dstaddr, port); in smbd_ia_open()
624 if (IS_ERR(info->id)) { in smbd_ia_open()
625 rc = PTR_ERR(info->id); in smbd_ia_open()
629 if (!frwr_is_supported(&info->id->device->attrs)) { in smbd_ia_open()
632 info->id->device->attrs.device_cap_flags, in smbd_ia_open()
633 info->id->device->attrs.max_fast_reg_page_list_len); in smbd_ia_open()
637 info->max_frmr_depth = min_t(int, in smbd_ia_open()
639 info->id->device->attrs.max_fast_reg_page_list_len); in smbd_ia_open()
640 info->mr_type = IB_MR_TYPE_MEM_REG; in smbd_ia_open()
641 if (info->id->device->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG) in smbd_ia_open()
642 info->mr_type = IB_MR_TYPE_SG_GAPS; in smbd_ia_open()
644 info->pd = ib_alloc_pd(info->id->device, 0); in smbd_ia_open()
645 if (IS_ERR(info->pd)) { in smbd_ia_open()
646 rc = PTR_ERR(info->pd); in smbd_ia_open()
654 rdma_destroy_id(info->id); in smbd_ia_open()
655 info->id = NULL; in smbd_ia_open()
667 static int smbd_post_send_negotiate_req(struct smbd_connection *info) in smbd_post_send_negotiate_req() argument
674 request = mempool_alloc(info->request_mempool, GFP_KERNEL); in smbd_post_send_negotiate_req()
678 request->info = info; in smbd_post_send_negotiate_req()
684 packet->credits_requested = cpu_to_le16(info->send_credit_target); in smbd_post_send_negotiate_req()
685 packet->preferred_send_size = cpu_to_le32(info->max_send_size); in smbd_post_send_negotiate_req()
686 packet->max_receive_size = cpu_to_le32(info->max_receive_size); in smbd_post_send_negotiate_req()
688 cpu_to_le32(info->max_fragmented_recv_size); in smbd_post_send_negotiate_req()
692 info->id->device, (void *)packet, in smbd_post_send_negotiate_req()
694 if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) { in smbd_post_send_negotiate_req()
700 request->sge[0].lkey = info->pd->local_dma_lkey; in smbd_post_send_negotiate_req()
703 info->id->device, request->sge[0].addr, in smbd_post_send_negotiate_req()
719 atomic_inc(&info->send_pending); in smbd_post_send_negotiate_req()
720 rc = ib_post_send(info->id->qp, &send_wr, NULL); in smbd_post_send_negotiate_req()
726 atomic_dec(&info->send_pending); in smbd_post_send_negotiate_req()
727 ib_dma_unmap_single(info->id->device, request->sge[0].addr, in smbd_post_send_negotiate_req()
730 smbd_disconnect_rdma_connection(info); in smbd_post_send_negotiate_req()
733 mempool_free(request, info->request_mempool); in smbd_post_send_negotiate_req()
745 static int manage_credits_prior_sending(struct smbd_connection *info) in manage_credits_prior_sending() argument
749 spin_lock(&info->lock_new_credits_offered); in manage_credits_prior_sending()
750 new_credits = info->new_credits_offered; in manage_credits_prior_sending()
751 info->new_credits_offered = 0; in manage_credits_prior_sending()
752 spin_unlock(&info->lock_new_credits_offered); in manage_credits_prior_sending()
766 static int manage_keep_alive_before_sending(struct smbd_connection *info) in manage_keep_alive_before_sending() argument
768 if (info->keep_alive_requested == KEEP_ALIVE_PENDING) { in manage_keep_alive_before_sending()
769 info->keep_alive_requested = KEEP_ALIVE_SENT; in manage_keep_alive_before_sending()
776 static int smbd_post_send(struct smbd_connection *info, in smbd_post_send() argument
787 info->id->device, in smbd_post_send()
802 rc = ib_post_send(info->id->qp, &send_wr, NULL); in smbd_post_send()
805 smbd_disconnect_rdma_connection(info); in smbd_post_send()
809 mod_delayed_work(info->workqueue, &info->idle_timer_work, in smbd_post_send()
810 info->keep_alive_interval*HZ); in smbd_post_send()
815 static int smbd_post_send_sgl(struct smbd_connection *info, in smbd_post_send_sgl() argument
828 rc = wait_event_interruptible(info->wait_send_queue, in smbd_post_send_sgl()
829 atomic_read(&info->send_credits) > 0 || in smbd_post_send_sgl()
830 info->transport_status != SMBD_CONNECTED); in smbd_post_send_sgl()
834 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_sgl()
839 if (unlikely(atomic_dec_return(&info->send_credits) < 0)) { in smbd_post_send_sgl()
840 atomic_inc(&info->send_credits); in smbd_post_send_sgl()
845 wait_event(info->wait_post_send, in smbd_post_send_sgl()
846 atomic_read(&info->send_pending) < info->send_credit_target || in smbd_post_send_sgl()
847 info->transport_status != SMBD_CONNECTED); in smbd_post_send_sgl()
849 if (info->transport_status != SMBD_CONNECTED) { in smbd_post_send_sgl()
855 if (unlikely(atomic_inc_return(&info->send_pending) > in smbd_post_send_sgl()
856 info->send_credit_target)) { in smbd_post_send_sgl()
857 atomic_dec(&info->send_pending); in smbd_post_send_sgl()
861 request = mempool_alloc(info->request_mempool, GFP_KERNEL); in smbd_post_send_sgl()
867 request->info = info; in smbd_post_send_sgl()
871 packet->credits_requested = cpu_to_le16(info->send_credit_target); in smbd_post_send_sgl()
873 new_credits = manage_credits_prior_sending(info); in smbd_post_send_sgl()
874 atomic_add(new_credits, &info->receive_credits); in smbd_post_send_sgl()
877 info->send_immediate = false; in smbd_post_send_sgl()
880 if (manage_keep_alive_before_sending(info)) in smbd_post_send_sgl()
906 request->sge[0].addr = ib_dma_map_single(info->id->device, in smbd_post_send_sgl()
910 if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) { in smbd_post_send_sgl()
917 request->sge[0].lkey = info->pd->local_dma_lkey; in smbd_post_send_sgl()
923 ib_dma_map_page(info->id->device, sg_page(sg), in smbd_post_send_sgl()
926 info->id->device, request->sge[i+1].addr)) { in smbd_post_send_sgl()
932 request->sge[i+1].lkey = info->pd->local_dma_lkey; in smbd_post_send_sgl()
936 rc = smbd_post_send(info, request); in smbd_post_send_sgl()
943 ib_dma_unmap_single(info->id->device, in smbd_post_send_sgl()
947 mempool_free(request, info->request_mempool); in smbd_post_send_sgl()
950 spin_lock(&info->lock_new_credits_offered); in smbd_post_send_sgl()
951 info->new_credits_offered += new_credits; in smbd_post_send_sgl()
952 spin_unlock(&info->lock_new_credits_offered); in smbd_post_send_sgl()
953 atomic_sub(new_credits, &info->receive_credits); in smbd_post_send_sgl()
956 if (atomic_dec_and_test(&info->send_pending)) in smbd_post_send_sgl()
957 wake_up(&info->wait_send_pending); in smbd_post_send_sgl()
961 atomic_inc(&info->send_credits); in smbd_post_send_sgl()
974 static int smbd_post_send_page(struct smbd_connection *info, struct page *page, in smbd_post_send_page() argument
982 return smbd_post_send_sgl(info, &sgl, size, remaining_data_length); in smbd_post_send_page()
990 static int smbd_post_send_empty(struct smbd_connection *info) in smbd_post_send_empty() argument
992 info->count_send_empty++; in smbd_post_send_empty()
993 return smbd_post_send_sgl(info, NULL, 0, 0); in smbd_post_send_empty()
1004 struct smbd_connection *info, struct kvec *iov, int n_vec, in smbd_post_send_data() argument
1022 return smbd_post_send_sgl(info, sgl, data_length, remaining_data_length); in smbd_post_send_data()
1031 struct smbd_connection *info, struct smbd_response *response) in smbd_post_recv() argument
1037 info->id->device, response->packet, in smbd_post_recv()
1038 info->max_receive_size, DMA_FROM_DEVICE); in smbd_post_recv()
1039 if (ib_dma_mapping_error(info->id->device, response->sge.addr)) in smbd_post_recv()
1042 response->sge.length = info->max_receive_size; in smbd_post_recv()
1043 response->sge.lkey = info->pd->local_dma_lkey; in smbd_post_recv()
1052 rc = ib_post_recv(info->id->qp, &recv_wr, NULL); in smbd_post_recv()
1054 ib_dma_unmap_single(info->id->device, response->sge.addr, in smbd_post_recv()
1056 smbd_disconnect_rdma_connection(info); in smbd_post_recv()
1064 static int smbd_negotiate(struct smbd_connection *info) in smbd_negotiate() argument
1067 struct smbd_response *response = get_receive_buffer(info); in smbd_negotiate()
1070 rc = smbd_post_recv(info, response); in smbd_negotiate()
1077 init_completion(&info->negotiate_completion); in smbd_negotiate()
1078 info->negotiate_done = false; in smbd_negotiate()
1079 rc = smbd_post_send_negotiate_req(info); in smbd_negotiate()
1084 &info->negotiate_completion, SMBD_NEGOTIATE_TIMEOUT * HZ); in smbd_negotiate()
1087 if (info->negotiate_done) in smbd_negotiate()
1101 struct smbd_connection *info, struct smbd_response *response) in put_empty_packet() argument
1103 spin_lock(&info->empty_packet_queue_lock); in put_empty_packet()
1104 list_add_tail(&response->list, &info->empty_packet_queue); in put_empty_packet()
1105 info->count_empty_packet_queue++; in put_empty_packet()
1106 spin_unlock(&info->empty_packet_queue_lock); in put_empty_packet()
1108 queue_work(info->workqueue, &info->post_send_credits_work); in put_empty_packet()
1122 struct smbd_connection *info, in enqueue_reassembly() argument
1126 spin_lock(&info->reassembly_queue_lock); in enqueue_reassembly()
1127 list_add_tail(&response->list, &info->reassembly_queue); in enqueue_reassembly()
1128 info->reassembly_queue_length++; in enqueue_reassembly()
1136 info->reassembly_data_length += data_length; in enqueue_reassembly()
1137 spin_unlock(&info->reassembly_queue_lock); in enqueue_reassembly()
1138 info->count_reassembly_queue++; in enqueue_reassembly()
1139 info->count_enqueue_reassembly_queue++; in enqueue_reassembly()
1147 static struct smbd_response *_get_first_reassembly(struct smbd_connection *info) in _get_first_reassembly() argument
1151 if (!list_empty(&info->reassembly_queue)) { in _get_first_reassembly()
1153 &info->reassembly_queue, in _get_first_reassembly()
1160 struct smbd_connection *info) in get_empty_queue_buffer() argument
1165 spin_lock_irqsave(&info->empty_packet_queue_lock, flags); in get_empty_queue_buffer()
1166 if (!list_empty(&info->empty_packet_queue)) { in get_empty_queue_buffer()
1168 &info->empty_packet_queue, in get_empty_queue_buffer()
1171 info->count_empty_packet_queue--; in get_empty_queue_buffer()
1173 spin_unlock_irqrestore(&info->empty_packet_queue_lock, flags); in get_empty_queue_buffer()
1184 static struct smbd_response *get_receive_buffer(struct smbd_connection *info) in get_receive_buffer() argument
1189 spin_lock_irqsave(&info->receive_queue_lock, flags); in get_receive_buffer()
1190 if (!list_empty(&info->receive_queue)) { in get_receive_buffer()
1192 &info->receive_queue, in get_receive_buffer()
1195 info->count_receive_queue--; in get_receive_buffer()
1196 info->count_get_receive_buffer++; in get_receive_buffer()
1198 spin_unlock_irqrestore(&info->receive_queue_lock, flags); in get_receive_buffer()
1210 struct smbd_connection *info, struct smbd_response *response) in put_receive_buffer() argument
1214 ib_dma_unmap_single(info->id->device, response->sge.addr, in put_receive_buffer()
1217 spin_lock_irqsave(&info->receive_queue_lock, flags); in put_receive_buffer()
1218 list_add_tail(&response->list, &info->receive_queue); in put_receive_buffer()
1219 info->count_receive_queue++; in put_receive_buffer()
1220 info->count_put_receive_buffer++; in put_receive_buffer()
1221 spin_unlock_irqrestore(&info->receive_queue_lock, flags); in put_receive_buffer()
1223 queue_work(info->workqueue, &info->post_send_credits_work); in put_receive_buffer()
1227 static int allocate_receive_buffers(struct smbd_connection *info, int num_buf) in allocate_receive_buffers() argument
1232 INIT_LIST_HEAD(&info->reassembly_queue); in allocate_receive_buffers()
1233 spin_lock_init(&info->reassembly_queue_lock); in allocate_receive_buffers()
1234 info->reassembly_data_length = 0; in allocate_receive_buffers()
1235 info->reassembly_queue_length = 0; in allocate_receive_buffers()
1237 INIT_LIST_HEAD(&info->receive_queue); in allocate_receive_buffers()
1238 spin_lock_init(&info->receive_queue_lock); in allocate_receive_buffers()
1239 info->count_receive_queue = 0; in allocate_receive_buffers()
1241 INIT_LIST_HEAD(&info->empty_packet_queue); in allocate_receive_buffers()
1242 spin_lock_init(&info->empty_packet_queue_lock); in allocate_receive_buffers()
1243 info->count_empty_packet_queue = 0; in allocate_receive_buffers()
1245 init_waitqueue_head(&info->wait_receive_queues); in allocate_receive_buffers()
1248 response = mempool_alloc(info->response_mempool, GFP_KERNEL); in allocate_receive_buffers()
1252 response->info = info; in allocate_receive_buffers()
1253 list_add_tail(&response->list, &info->receive_queue); in allocate_receive_buffers()
1254 info->count_receive_queue++; in allocate_receive_buffers()
1260 while (!list_empty(&info->receive_queue)) { in allocate_receive_buffers()
1262 &info->receive_queue, in allocate_receive_buffers()
1265 info->count_receive_queue--; in allocate_receive_buffers()
1267 mempool_free(response, info->response_mempool); in allocate_receive_buffers()
1272 static void destroy_receive_buffers(struct smbd_connection *info) in destroy_receive_buffers() argument
1276 while ((response = get_receive_buffer(info))) in destroy_receive_buffers()
1277 mempool_free(response, info->response_mempool); in destroy_receive_buffers()
1279 while ((response = get_empty_queue_buffer(info))) in destroy_receive_buffers()
1280 mempool_free(response, info->response_mempool); in destroy_receive_buffers()
1286 struct smbd_connection *info = container_of( in idle_connection_timer() local
1290 if (info->keep_alive_requested != KEEP_ALIVE_NONE) { in idle_connection_timer()
1293 info->keep_alive_requested); in idle_connection_timer()
1294 smbd_disconnect_rdma_connection(info); in idle_connection_timer()
1299 smbd_post_send_empty(info); in idle_connection_timer()
1302 queue_delayed_work(info->workqueue, &info->idle_timer_work, in idle_connection_timer()
1303 info->keep_alive_interval*HZ); in idle_connection_timer()
1313 struct smbd_connection *info = server->smbd_conn; in smbd_destroy() local
1317 if (!info) { in smbd_destroy()
1323 if (info->transport_status != SMBD_DISCONNECTED) { in smbd_destroy()
1327 info->disconn_wait, in smbd_destroy()
1328 info->transport_status == SMBD_DISCONNECTED); in smbd_destroy()
1332 ib_drain_qp(info->id->qp); in smbd_destroy()
1333 rdma_destroy_qp(info->id); in smbd_destroy()
1336 cancel_delayed_work_sync(&info->idle_timer_work); in smbd_destroy()
1339 wait_event(info->wait_send_pending, in smbd_destroy()
1340 atomic_read(&info->send_pending) == 0); in smbd_destroy()
1345 spin_lock_irqsave(&info->reassembly_queue_lock, flags); in smbd_destroy()
1346 response = _get_first_reassembly(info); in smbd_destroy()
1350 &info->reassembly_queue_lock, flags); in smbd_destroy()
1351 put_receive_buffer(info, response); in smbd_destroy()
1354 &info->reassembly_queue_lock, flags); in smbd_destroy()
1356 info->reassembly_data_length = 0; in smbd_destroy()
1359 wait_event(info->wait_receive_queues, in smbd_destroy()
1360 info->count_receive_queue + info->count_empty_packet_queue in smbd_destroy()
1361 == info->receive_credit_max); in smbd_destroy()
1362 destroy_receive_buffers(info); in smbd_destroy()
1372 wake_up_interruptible_all(&info->wait_mr); in smbd_destroy()
1373 while (atomic_read(&info->mr_used_count)) { in smbd_destroy()
1378 destroy_mr_list(info); in smbd_destroy()
1380 ib_free_cq(info->send_cq); in smbd_destroy()
1381 ib_free_cq(info->recv_cq); in smbd_destroy()
1382 ib_dealloc_pd(info->pd); in smbd_destroy()
1383 rdma_destroy_id(info->id); in smbd_destroy()
1386 mempool_destroy(info->request_mempool); in smbd_destroy()
1387 kmem_cache_destroy(info->request_cache); in smbd_destroy()
1389 mempool_destroy(info->response_mempool); in smbd_destroy()
1390 kmem_cache_destroy(info->response_cache); in smbd_destroy()
1392 info->transport_status = SMBD_DESTROYED; in smbd_destroy()
1394 destroy_workqueue(info->workqueue); in smbd_destroy()
1396 kfree(info); in smbd_destroy()
1432 static void destroy_caches_and_workqueue(struct smbd_connection *info) in destroy_caches_and_workqueue() argument
1434 destroy_receive_buffers(info); in destroy_caches_and_workqueue()
1435 destroy_workqueue(info->workqueue); in destroy_caches_and_workqueue()
1436 mempool_destroy(info->response_mempool); in destroy_caches_and_workqueue()
1437 kmem_cache_destroy(info->response_cache); in destroy_caches_and_workqueue()
1438 mempool_destroy(info->request_mempool); in destroy_caches_and_workqueue()
1439 kmem_cache_destroy(info->request_cache); in destroy_caches_and_workqueue()
1443 static int allocate_caches_and_workqueue(struct smbd_connection *info) in allocate_caches_and_workqueue() argument
1448 scnprintf(name, MAX_NAME_LEN, "smbd_request_%p", info); in allocate_caches_and_workqueue()
1449 info->request_cache = in allocate_caches_and_workqueue()
1455 if (!info->request_cache) in allocate_caches_and_workqueue()
1458 info->request_mempool = in allocate_caches_and_workqueue()
1459 mempool_create(info->send_credit_target, mempool_alloc_slab, in allocate_caches_and_workqueue()
1460 mempool_free_slab, info->request_cache); in allocate_caches_and_workqueue()
1461 if (!info->request_mempool) in allocate_caches_and_workqueue()
1464 scnprintf(name, MAX_NAME_LEN, "smbd_response_%p", info); in allocate_caches_and_workqueue()
1465 info->response_cache = in allocate_caches_and_workqueue()
1469 info->max_receive_size, in allocate_caches_and_workqueue()
1471 if (!info->response_cache) in allocate_caches_and_workqueue()
1474 info->response_mempool = in allocate_caches_and_workqueue()
1475 mempool_create(info->receive_credit_max, mempool_alloc_slab, in allocate_caches_and_workqueue()
1476 mempool_free_slab, info->response_cache); in allocate_caches_and_workqueue()
1477 if (!info->response_mempool) in allocate_caches_and_workqueue()
1480 scnprintf(name, MAX_NAME_LEN, "smbd_%p", info); in allocate_caches_and_workqueue()
1481 info->workqueue = create_workqueue(name); in allocate_caches_and_workqueue()
1482 if (!info->workqueue) in allocate_caches_and_workqueue()
1485 rc = allocate_receive_buffers(info, info->receive_credit_max); in allocate_caches_and_workqueue()
1494 destroy_workqueue(info->workqueue); in allocate_caches_and_workqueue()
1496 mempool_destroy(info->response_mempool); in allocate_caches_and_workqueue()
1498 kmem_cache_destroy(info->response_cache); in allocate_caches_and_workqueue()
1500 mempool_destroy(info->request_mempool); in allocate_caches_and_workqueue()
1502 kmem_cache_destroy(info->request_cache); in allocate_caches_and_workqueue()
1511 struct smbd_connection *info; in _smbd_get_connection() local
1518 info = kzalloc(sizeof(struct smbd_connection), GFP_KERNEL); in _smbd_get_connection()
1519 if (!info) in _smbd_get_connection()
1522 info->transport_status = SMBD_CONNECTING; in _smbd_get_connection()
1523 rc = smbd_ia_open(info, dstaddr, port); in _smbd_get_connection()
1529 if (smbd_send_credit_target > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1530 smbd_send_credit_target > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1533 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1534 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1538 if (smbd_receive_credit_max > info->id->device->attrs.max_cqe || in _smbd_get_connection()
1539 smbd_receive_credit_max > info->id->device->attrs.max_qp_wr) { in _smbd_get_connection()
1542 info->id->device->attrs.max_cqe, in _smbd_get_connection()
1543 info->id->device->attrs.max_qp_wr); in _smbd_get_connection()
1547 info->receive_credit_max = smbd_receive_credit_max; in _smbd_get_connection()
1548 info->send_credit_target = smbd_send_credit_target; in _smbd_get_connection()
1549 info->max_send_size = smbd_max_send_size; in _smbd_get_connection()
1550 info->max_fragmented_recv_size = smbd_max_fragmented_recv_size; in _smbd_get_connection()
1551 info->max_receive_size = smbd_max_receive_size; in _smbd_get_connection()
1552 info->keep_alive_interval = smbd_keep_alive_interval; in _smbd_get_connection()
1554 if (info->id->device->attrs.max_send_sge < SMBDIRECT_MAX_SGE) { in _smbd_get_connection()
1557 info->id->device->attrs.max_send_sge); in _smbd_get_connection()
1560 if (info->id->device->attrs.max_recv_sge < SMBDIRECT_MAX_SGE) { in _smbd_get_connection()
1563 info->id->device->attrs.max_recv_sge); in _smbd_get_connection()
1567 info->send_cq = NULL; in _smbd_get_connection()
1568 info->recv_cq = NULL; in _smbd_get_connection()
1569 info->send_cq = in _smbd_get_connection()
1570 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1571 info->send_credit_target, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1572 if (IS_ERR(info->send_cq)) { in _smbd_get_connection()
1573 info->send_cq = NULL; in _smbd_get_connection()
1577 info->recv_cq = in _smbd_get_connection()
1578 ib_alloc_cq_any(info->id->device, info, in _smbd_get_connection()
1579 info->receive_credit_max, IB_POLL_SOFTIRQ); in _smbd_get_connection()
1580 if (IS_ERR(info->recv_cq)) { in _smbd_get_connection()
1581 info->recv_cq = NULL; in _smbd_get_connection()
1587 qp_attr.qp_context = info; in _smbd_get_connection()
1588 qp_attr.cap.max_send_wr = info->send_credit_target; in _smbd_get_connection()
1589 qp_attr.cap.max_recv_wr = info->receive_credit_max; in _smbd_get_connection()
1595 qp_attr.send_cq = info->send_cq; in _smbd_get_connection()
1596 qp_attr.recv_cq = info->recv_cq; in _smbd_get_connection()
1599 rc = rdma_create_qp(info->id, info->pd, &qp_attr); in _smbd_get_connection()
1609 info->id->device->attrs.max_qp_rd_atom in _smbd_get_connection()
1611 info->id->device->attrs.max_qp_rd_atom : in _smbd_get_connection()
1613 info->responder_resources = conn_param.responder_resources; in _smbd_get_connection()
1615 info->responder_resources); in _smbd_get_connection()
1618 info->id->device->ops.get_port_immutable( in _smbd_get_connection()
1619 info->id->device, info->id->port_num, &port_immutable); in _smbd_get_connection()
1621 ird_ord_hdr[0] = info->responder_resources; in _smbd_get_connection()
1637 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1638 init_waitqueue_head(&info->disconn_wait); in _smbd_get_connection()
1639 init_waitqueue_head(&info->wait_reassembly_queue); in _smbd_get_connection()
1640 rc = rdma_connect(info->id, &conn_param); in _smbd_get_connection()
1647 info->conn_wait, info->transport_status != SMBD_CONNECTING); in _smbd_get_connection()
1649 if (info->transport_status != SMBD_CONNECTED) { in _smbd_get_connection()
1656 rc = allocate_caches_and_workqueue(info); in _smbd_get_connection()
1662 init_waitqueue_head(&info->wait_send_queue); in _smbd_get_connection()
1663 INIT_DELAYED_WORK(&info->idle_timer_work, idle_connection_timer); in _smbd_get_connection()
1664 queue_delayed_work(info->workqueue, &info->idle_timer_work, in _smbd_get_connection()
1665 info->keep_alive_interval*HZ); in _smbd_get_connection()
1667 init_waitqueue_head(&info->wait_send_pending); in _smbd_get_connection()
1668 atomic_set(&info->send_pending, 0); in _smbd_get_connection()
1670 init_waitqueue_head(&info->wait_post_send); in _smbd_get_connection()
1672 INIT_WORK(&info->disconnect_work, smbd_disconnect_rdma_work); in _smbd_get_connection()
1673 INIT_WORK(&info->post_send_credits_work, smbd_post_send_credits); in _smbd_get_connection()
1674 info->new_credits_offered = 0; in _smbd_get_connection()
1675 spin_lock_init(&info->lock_new_credits_offered); in _smbd_get_connection()
1677 rc = smbd_negotiate(info); in _smbd_get_connection()
1683 rc = allocate_mr_list(info); in _smbd_get_connection()
1689 return info; in _smbd_get_connection()
1697 cancel_delayed_work_sync(&info->idle_timer_work); in _smbd_get_connection()
1698 destroy_caches_and_workqueue(info); in _smbd_get_connection()
1699 info->transport_status = SMBD_NEGOTIATE_FAILED; in _smbd_get_connection()
1700 init_waitqueue_head(&info->conn_wait); in _smbd_get_connection()
1701 rdma_disconnect(info->id); in _smbd_get_connection()
1702 wait_event(info->conn_wait, in _smbd_get_connection()
1703 info->transport_status == SMBD_DISCONNECTED); in _smbd_get_connection()
1707 rdma_destroy_qp(info->id); in _smbd_get_connection()
1711 if (info->send_cq) in _smbd_get_connection()
1712 ib_free_cq(info->send_cq); in _smbd_get_connection()
1713 if (info->recv_cq) in _smbd_get_connection()
1714 ib_free_cq(info->recv_cq); in _smbd_get_connection()
1717 ib_dealloc_pd(info->pd); in _smbd_get_connection()
1718 rdma_destroy_id(info->id); in _smbd_get_connection()
1721 kfree(info); in _smbd_get_connection()
1755 static int smbd_recv_buf(struct smbd_connection *info, char *buf, in smbd_recv_buf() argument
1771 info->reassembly_data_length); in smbd_recv_buf()
1772 if (info->reassembly_data_length >= size) { in smbd_recv_buf()
1784 queue_length = info->reassembly_queue_length; in smbd_recv_buf()
1787 offset = info->first_entry_offset; in smbd_recv_buf()
1789 response = _get_first_reassembly(info); in smbd_recv_buf()
1833 &info->reassembly_queue_lock); in smbd_recv_buf()
1836 &info->reassembly_queue_lock); in smbd_recv_buf()
1839 info->count_reassembly_queue--; in smbd_recv_buf()
1840 info->count_dequeue_reassembly_queue++; in smbd_recv_buf()
1841 put_receive_buffer(info, response); in smbd_recv_buf()
1855 spin_lock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1856 info->reassembly_data_length -= data_read; in smbd_recv_buf()
1857 info->reassembly_queue_length -= queue_removed; in smbd_recv_buf()
1858 spin_unlock_irq(&info->reassembly_queue_lock); in smbd_recv_buf()
1860 info->first_entry_offset = offset; in smbd_recv_buf()
1862 data_read, info->reassembly_data_length, in smbd_recv_buf()
1863 info->first_entry_offset); in smbd_recv_buf()
1870 info->wait_reassembly_queue, in smbd_recv_buf()
1871 info->reassembly_data_length >= size || in smbd_recv_buf()
1872 info->transport_status != SMBD_CONNECTED); in smbd_recv_buf()
1877 if (info->transport_status != SMBD_CONNECTED) { in smbd_recv_buf()
1891 static int smbd_recv_page(struct smbd_connection *info, in smbd_recv_page() argument
1901 info->wait_reassembly_queue, in smbd_recv_page()
1902 info->reassembly_data_length >= to_read || in smbd_recv_page()
1903 info->transport_status != SMBD_CONNECTED); in smbd_recv_page()
1914 ret = smbd_recv_buf(info, to_address, to_read); in smbd_recv_page()
1925 int smbd_recv(struct smbd_connection *info, struct msghdr *msg) in smbd_recv() argument
1944 rc = smbd_recv_buf(info, buf, to_read); in smbd_recv()
1951 rc = smbd_recv_page(info, page, page_offset, to_read); in smbd_recv()
1977 struct smbd_connection *info = server->smbd_conn; in smbd_send() local
1984 info->max_send_size - sizeof(struct smbd_data_transfer); in smbd_send()
1990 if (info->transport_status != SMBD_CONNECTED) { in smbd_send()
2004 if (remaining_data_length > info->max_fragmented_send_size) { in smbd_send()
2006 remaining_data_length, info->max_fragmented_send_size); in smbd_send()
2041 info, &iov[start], i-start, in smbd_send()
2066 info, &vec, 1, in smbd_send()
2085 rc = smbd_post_send_data(info, &iov[start], in smbd_send()
2112 info, rqst->rq_pages[i], in smbd_send()
2132 wait_event(info->wait_send_pending, in smbd_send()
2133 atomic_read(&info->send_pending) == 0); in smbd_send()
2162 struct smbd_connection *info = in smbd_mr_recovery_work() local
2167 list_for_each_entry(smbdirect_mr, &info->mr_list, list) { in smbd_mr_recovery_work()
2176 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2181 info->pd, info->mr_type, in smbd_mr_recovery_work()
2182 info->max_frmr_depth); in smbd_mr_recovery_work()
2185 info->mr_type, in smbd_mr_recovery_work()
2186 info->max_frmr_depth); in smbd_mr_recovery_work()
2187 smbd_disconnect_rdma_connection(info); in smbd_mr_recovery_work()
2203 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_mr_recovery_work()
2204 wake_up_interruptible(&info->wait_mr); in smbd_mr_recovery_work()
2208 static void destroy_mr_list(struct smbd_connection *info) in destroy_mr_list() argument
2212 cancel_work_sync(&info->mr_recovery_work); in destroy_mr_list()
2213 list_for_each_entry_safe(mr, tmp, &info->mr_list, list) { in destroy_mr_list()
2215 ib_dma_unmap_sg(info->id->device, mr->sgl, in destroy_mr_list()
2230 static int allocate_mr_list(struct smbd_connection *info) in allocate_mr_list() argument
2235 INIT_LIST_HEAD(&info->mr_list); in allocate_mr_list()
2236 init_waitqueue_head(&info->wait_mr); in allocate_mr_list()
2237 spin_lock_init(&info->mr_list_lock); in allocate_mr_list()
2238 atomic_set(&info->mr_ready_count, 0); in allocate_mr_list()
2239 atomic_set(&info->mr_used_count, 0); in allocate_mr_list()
2240 init_waitqueue_head(&info->wait_for_mr_cleanup); in allocate_mr_list()
2242 for (i = 0; i < info->responder_resources * 2; i++) { in allocate_mr_list()
2246 smbdirect_mr->mr = ib_alloc_mr(info->pd, info->mr_type, in allocate_mr_list()
2247 info->max_frmr_depth); in allocate_mr_list()
2250 info->mr_type, info->max_frmr_depth); in allocate_mr_list()
2254 info->max_frmr_depth, in allocate_mr_list()
2263 smbdirect_mr->conn = info; in allocate_mr_list()
2265 list_add_tail(&smbdirect_mr->list, &info->mr_list); in allocate_mr_list()
2266 atomic_inc(&info->mr_ready_count); in allocate_mr_list()
2268 INIT_WORK(&info->mr_recovery_work, smbd_mr_recovery_work); in allocate_mr_list()
2274 list_for_each_entry_safe(smbdirect_mr, tmp, &info->mr_list, list) { in allocate_mr_list()
2290 static struct smbd_mr *get_mr(struct smbd_connection *info) in get_mr() argument
2295 rc = wait_event_interruptible(info->wait_mr, in get_mr()
2296 atomic_read(&info->mr_ready_count) || in get_mr()
2297 info->transport_status != SMBD_CONNECTED); in get_mr()
2303 if (info->transport_status != SMBD_CONNECTED) { in get_mr()
2305 info->transport_status); in get_mr()
2309 spin_lock(&info->mr_list_lock); in get_mr()
2310 list_for_each_entry(ret, &info->mr_list, list) { in get_mr()
2313 spin_unlock(&info->mr_list_lock); in get_mr()
2314 atomic_dec(&info->mr_ready_count); in get_mr()
2315 atomic_inc(&info->mr_used_count); in get_mr()
2320 spin_unlock(&info->mr_list_lock); in get_mr()
2338 struct smbd_connection *info, struct page *pages[], int num_pages, in smbd_register_mr() argument
2346 if (num_pages > info->max_frmr_depth) { in smbd_register_mr()
2348 num_pages, info->max_frmr_depth); in smbd_register_mr()
2352 smbdirect_mr = get_mr(info); in smbd_register_mr()
2383 rc = ib_dma_map_sg(info->id->device, smbdirect_mr->sgl, num_pages, dir); in smbd_register_mr()
2418 rc = ib_post_send(info->id->qp, ®_wr->wr, NULL); in smbd_register_mr()
2427 ib_dma_unmap_sg(info->id->device, smbdirect_mr->sgl, in smbd_register_mr()
2432 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_register_mr()
2433 wake_up(&info->wait_for_mr_cleanup); in smbd_register_mr()
2435 smbd_disconnect_rdma_connection(info); in smbd_register_mr()
2464 struct smbd_connection *info = smbdirect_mr->conn; in smbd_deregister_mr() local
2478 rc = ib_post_send(info->id->qp, wr, NULL); in smbd_deregister_mr()
2481 smbd_disconnect_rdma_connection(info); in smbd_deregister_mr()
2495 info->id->device, smbdirect_mr->sgl, in smbd_deregister_mr()
2499 if (atomic_inc_return(&info->mr_ready_count) == 1) in smbd_deregister_mr()
2500 wake_up_interruptible(&info->wait_mr); in smbd_deregister_mr()
2506 queue_work(info->workqueue, &info->mr_recovery_work); in smbd_deregister_mr()
2509 if (atomic_dec_and_test(&info->mr_used_count)) in smbd_deregister_mr()
2510 wake_up(&info->wait_for_mr_cleanup); in smbd_deregister_mr()