Lines Matching defs:ib_conn
154 static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
161 BUG_ON(ib_conn->device == NULL);
163 device = ib_conn->device;
165 ib_conn->login_buf = kmalloc(ISER_RX_LOGIN_SIZE, GFP_KERNEL);
166 if (!ib_conn->login_buf)
169 ib_conn->login_dma = ib_dma_map_single(ib_conn->device->ib_device,
170 (void *)ib_conn->login_buf, ISER_RX_LOGIN_SIZE,
173 ib_conn->page_vec = kmalloc(sizeof(struct iser_page_vec) +
176 if (!ib_conn->page_vec)
179 ib_conn->page_vec->pages = (u64 *) (ib_conn->page_vec + 1);
195 ib_conn->fmr_pool = ib_create_fmr_pool(device->pd, ¶ms);
196 if (IS_ERR(ib_conn->fmr_pool)) {
197 ret = PTR_ERR(ib_conn->fmr_pool);
198 ib_conn->fmr_pool = NULL;
205 init_attr.qp_context = (void *)ib_conn;
215 ret = rdma_create_qp(ib_conn->cma_id, device->pd, &init_attr);
219 ib_conn->qp = ib_conn->cma_id->qp;
221 ib_conn, ib_conn->cma_id,
222 ib_conn->fmr_pool, ib_conn->cma_id->qp);
234 static int iser_free_ib_conn_res(struct iser_conn *ib_conn, int can_destroy_id)
236 BUG_ON(ib_conn == NULL);
239 ib_conn, ib_conn->cma_id,
240 ib_conn->fmr_pool, ib_conn->qp);
243 if (ib_conn->fmr_pool != NULL)
244 ib_destroy_fmr_pool(ib_conn->fmr_pool);
246 if (ib_conn->qp != NULL)
247 rdma_destroy_qp(ib_conn->cma_id);
250 if (ib_conn->cma_id != NULL && can_destroy_id)
251 rdma_destroy_id(ib_conn->cma_id);
253 ib_conn->fmr_pool = NULL;
254 ib_conn->qp = NULL;
255 ib_conn->cma_id = NULL;
256 kfree(ib_conn->page_vec);
312 static int iser_conn_state_comp_exch(struct iser_conn *ib_conn,
318 spin_lock_bh(&ib_conn->lock);
319 if ((ret = (ib_conn->state == comp)))
320 ib_conn->state = exch;
321 spin_unlock_bh(&ib_conn->lock);
328 static void iser_conn_release(struct iser_conn *ib_conn, int can_destroy_id)
330 struct iser_device *device = ib_conn->device;
332 BUG_ON(ib_conn->state != ISER_CONN_DOWN);
335 list_del(&ib_conn->conn_list);
337 iser_free_rx_descriptors(ib_conn);
338 iser_free_ib_conn_res(ib_conn, can_destroy_id);
339 ib_conn->device = NULL;
343 iscsi_destroy_endpoint(ib_conn->ep);
346 void iser_conn_get(struct iser_conn *ib_conn)
348 atomic_inc(&ib_conn->refcount);
351 int iser_conn_put(struct iser_conn *ib_conn, int can_destroy_id)
353 if (atomic_dec_and_test(&ib_conn->refcount)) {
354 iser_conn_release(ib_conn, can_destroy_id);
363 void iser_conn_terminate(struct iser_conn *ib_conn)
372 iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP, ISER_CONN_TERMINATING);
373 err = rdma_disconnect(ib_conn->cma_id);
376 ib_conn,err);
378 wait_event_interruptible(ib_conn->wait,
379 ib_conn->state == ISER_CONN_DOWN);
381 iser_conn_put(ib_conn, 1); /* deref ib conn deallocate */
386 struct iser_conn *ib_conn;
387 ib_conn = (struct iser_conn *)cma_id->context;
389 ib_conn->state = ISER_CONN_DOWN;
390 wake_up_interruptible(&ib_conn->wait);
391 return iser_conn_put(ib_conn, 0); /* deref ib conn's cma id */
397 struct iser_conn *ib_conn;
406 ib_conn = (struct iser_conn *)cma_id->context;
407 ib_conn->device = device;
446 struct iser_conn *ib_conn;
448 ib_conn = (struct iser_conn *)cma_id->context;
449 ib_conn->state = ISER_CONN_UP;
450 wake_up_interruptible(&ib_conn->wait);
455 struct iser_conn *ib_conn;
458 ib_conn = (struct iser_conn *)cma_id->context;
462 if (iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP,
464 iscsi_conn_failure(ib_conn->iser_conn->iscsi_conn,
468 if (ib_conn->post_recv_buf_count == 0 &&
469 (atomic_read(&ib_conn->post_send_buf_count) == 0)) {
470 ib_conn->state = ISER_CONN_DOWN;
471 wake_up_interruptible(&ib_conn->wait);
474 ret = iser_conn_put(ib_conn, 0); /* deref ib conn's cma id */
514 void iser_conn_init(struct iser_conn *ib_conn)
516 ib_conn->state = ISER_CONN_INIT;
517 init_waitqueue_head(&ib_conn->wait);
518 ib_conn->post_recv_buf_count = 0;
519 atomic_set(&ib_conn->post_send_buf_count, 0);
520 atomic_set(&ib_conn->refcount, 1); /* ref ib conn allocation */
521 INIT_LIST_HEAD(&ib_conn->conn_list);
522 spin_lock_init(&ib_conn->lock);
529 int iser_connect(struct iser_conn *ib_conn,
537 sprintf(ib_conn->name, "%pI4:%d",
541 ib_conn->device = NULL;
546 ib_conn->state = ISER_CONN_PENDING;
548 iser_conn_get(ib_conn); /* ref ib conn's cma id */
549 ib_conn->cma_id = rdma_create_id(iser_cma_handler,
550 (void *)ib_conn,
552 if (IS_ERR(ib_conn->cma_id)) {
553 err = PTR_ERR(ib_conn->cma_id);
560 err = rdma_resolve_addr(ib_conn->cma_id, src, dst, 1000);
567 wait_event_interruptible(ib_conn->wait,
568 (ib_conn->state != ISER_CONN_PENDING));
570 if (ib_conn->state != ISER_CONN_UP) {
577 list_add(&ib_conn->conn_list, &ig.connlist);
582 ib_conn->cma_id = NULL;
584 ib_conn->state = ISER_CONN_DOWN;
586 iser_conn_release(ib_conn, 1);
595 int iser_reg_page_vec(struct iser_conn *ib_conn,
607 mem = ib_fmr_pool_map_phys(ib_conn->fmr_pool,
655 int iser_post_recvl(struct iser_conn *ib_conn)
661 sge.addr = ib_conn->login_dma;
663 sge.lkey = ib_conn->device->mr->lkey;
665 rx_wr.wr_id = (unsigned long)ib_conn->login_buf;
670 ib_conn->post_recv_buf_count++;
671 ib_ret = ib_post_recv(ib_conn->qp, &rx_wr, &rx_wr_failed);
674 ib_conn->post_recv_buf_count--;
679 int iser_post_recvm(struct iser_conn *ib_conn, int count)
683 unsigned int my_rx_head = ib_conn->rx_desc_head;
686 for (rx_wr = ib_conn->rx_wr, i = 0; i < count; i++, rx_wr++) {
687 rx_desc = &ib_conn->rx_descs[my_rx_head];
698 ib_conn->post_recv_buf_count += count;
699 ib_ret = ib_post_recv(ib_conn->qp, ib_conn->rx_wr, &rx_wr_failed);
702 ib_conn->post_recv_buf_count -= count;
704 ib_conn->rx_desc_head = my_rx_head;
714 int iser_post_send(struct iser_conn *ib_conn, struct iser_tx_desc *tx_desc)
719 ib_dma_sync_single_for_device(ib_conn->device->ib_device,
729 atomic_inc(&ib_conn->post_send_buf_count);
731 ib_ret = ib_post_send(ib_conn->qp, &send_wr, &send_wr_failed);
734 atomic_dec(&ib_conn->post_send_buf_count);
740 struct iser_conn *ib_conn)
745 if (ib_conn->post_recv_buf_count == 0 &&
746 atomic_read(&ib_conn->post_send_buf_count) == 0) {
750 if (iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP,
752 iscsi_conn_failure(ib_conn->iser_conn->iscsi_conn,
757 ib_conn->state = ISER_CONN_DOWN;
758 wake_up_interruptible(&ib_conn->wait);
767 struct iser_conn *ib_conn;
772 ib_conn = wc.qp->qp_context;
775 iser_snd_completion(tx_desc, ib_conn);
782 atomic_dec(&ib_conn->post_send_buf_count);
783 iser_handle_comp_error(tx_desc, ib_conn);
798 struct iser_conn *ib_conn;
805 ib_conn = wc.qp->qp_context;
809 iser_rcv_completion(desc, xfer_len, ib_conn);
817 ib_conn->post_recv_buf_count--;
818 iser_handle_comp_error(NULL, ib_conn);