Lines Matching refs:target

95 		 "Enable workarounds for Topspin/Cisco SRP target bugs if != 0");
142 "Number of RDMA channels to use for communication with an SRP target. Using more than one channel improves performance if the HCA supports multiple completion vectors. The default value is the minimum of four times the number of online CPU sockets and the number of completion vectors supported by the HCA.");
216 static int srp_target_is_topspin(struct srp_target_port *target)
222 (!memcmp(&target->ioc_guid, topspin_oui, sizeof topspin_oui) ||
223 !memcmp(&target->ioc_guid, cisco_oui, sizeof cisco_oui));
275 static int srp_init_ib_qp(struct srp_target_port *target,
285 ret = ib_find_cached_pkey(target->srp_host->srp_dev->dev,
286 target->srp_host->port,
287 be16_to_cpu(target->ib_cm.pkey),
295 attr->port_num = target->srp_host->port;
310 struct srp_target_port *target = ch->target;
313 new_cm_id = ib_create_cm_id(target->srp_host->srp_dev->dev,
321 if (rdma_cap_opa_ah(target->srp_host->srp_dev->dev,
322 target->srp_host->port))
326 ch->ib_cm.path.sgid = target->sgid;
327 ch->ib_cm.path.dgid = target->ib_cm.orig_dgid;
328 ch->ib_cm.path.pkey = target->ib_cm.pkey;
329 ch->ib_cm.path.service_id = target->ib_cm.service_id;
336 struct srp_target_port *target = ch->target;
340 new_cm_id = rdma_create_id(target->net, srp_rdma_cm_handler, ch,
349 ret = rdma_resolve_addr(new_cm_id, target->rdma_cm.src_specified ?
350 &target->rdma_cm.src.sa : NULL,
351 &target->rdma_cm.dst.sa,
355 &target->rdma_cm.src, &target->rdma_cm.dst, ret);
365 &target->rdma_cm.dst, ret);
380 struct srp_target_port *target = ch->target;
382 return target->using_rdma_cm ? srp_new_rdma_cm_id(ch) :
502 static struct srp_fr_pool *srp_alloc_fr_pool(struct srp_target_port *target)
504 struct srp_device *dev = target->srp_host->srp_dev;
506 return srp_create_fr_pool(dev->dev, dev->pd, target->mr_pool_size,
530 struct srp_target_port *target = ch->target;
531 struct srp_device *dev = target->srp_host->srp_dev;
537 const int m = 1 + dev->use_fast_reg * target->mr_per_cmd * 2;
545 recv_cq = ib_alloc_cq(dev->dev, ch, target->queue_size + 1,
552 send_cq = ib_alloc_cq(dev->dev, ch, m * target->queue_size,
560 init_attr->cap.max_send_wr = m * target->queue_size;
561 init_attr->cap.max_recv_wr = target->queue_size + 1;
571 if (target->using_rdma_cm) {
577 ret = srp_init_ib_qp(target, qp);
591 fr_pool = srp_alloc_fr_pool(target);
594 shost_printk(KERN_WARNING, target->scsi_host, PFX
621 if (target->using_rdma_cm)
641 static void srp_free_ch_ib(struct srp_target_port *target,
644 struct srp_device *dev = target->srp_host->srp_dev;
647 if (!ch->target)
650 if (target->using_rdma_cm) {
681 ch->target = NULL;
687 for (i = 0; i < target->queue_size; ++i)
688 srp_free_iu(target->srp_host, ch->rx_ring[i]);
693 for (i = 0; i < target->queue_size; ++i)
694 srp_free_iu(target->srp_host, ch->tx_ring[i]);
705 struct srp_target_port *target = ch->target;
709 shost_printk(KERN_ERR, target->scsi_host,
718 struct srp_target_port *target = ch->target;
726 target->srp_host->srp_dev->dev,
727 target->srp_host->port,
746 shost_printk(KERN_WARNING, target->scsi_host,
749 be16_to_cpu(target->ib_cm.pkey),
750 be64_to_cpu(target->ib_cm.service_id));
757 struct srp_target_port *target = ch->target;
769 shost_printk(KERN_WARNING, target->scsi_host,
777 struct srp_target_port *target = ch->target;
779 return target->using_rdma_cm ? srp_rdma_lookup_path(ch) :
803 struct srp_target_port *target = ch->target;
818 req->ib_param.retry_count = target->tl_retry_count;
840 if (target->using_rdma_cm) {
862 subnet_timeout = srp_get_subnet_timeout(target->srp_host);
866 req->ib_param.service_id = target->ib_cm.service_id;
889 if (target->io_class == SRP_REV10_IB_IO_CLASS) {
890 memcpy(ipi, &target->sgid.global.interface_id, 8);
891 memcpy(ipi + 8, &target->initiator_ext, 8);
892 memcpy(tpi, &target->ioc_guid, 8);
893 memcpy(tpi + 8, &target->id_ext, 8);
895 memcpy(ipi, &target->initiator_ext, 8);
896 memcpy(ipi + 8, &target->sgid.global.interface_id, 8);
897 memcpy(tpi, &target->id_ext, 8);
898 memcpy(tpi + 8, &target->ioc_guid, 8);
906 if (srp_target_is_topspin(target)) {
907 shost_printk(KERN_DEBUG, target->scsi_host,
909 "activated for target GUID %016llx\n",
910 be64_to_cpu(target->ioc_guid));
912 memcpy(ipi + 8, &target->srp_host->srp_dev->dev->node_guid, 8);
915 if (target->using_rdma_cm)
925 static bool srp_queue_remove_work(struct srp_target_port *target)
929 spin_lock_irq(&target->lock);
930 if (target->state != SRP_TARGET_REMOVED) {
931 target->state = SRP_TARGET_REMOVED;
934 spin_unlock_irq(&target->lock);
937 queue_work(srp_remove_wq, &target->remove_work);
942 static void srp_disconnect_target(struct srp_target_port *target)
949 for (i = 0; i < target->ch_count; i++) {
950 ch = &target->ch[i];
953 if (target->using_rdma_cm) {
962 shost_printk(KERN_DEBUG, target->scsi_host,
970 struct srp_target_port *target = host_to_target(shost);
971 struct srp_device *dev = target->srp_host->srp_dev;
978 target->indirect_size,
988 struct srp_target_port *target = host_to_target(shost);
989 struct srp_device *srp_dev = target->srp_host->srp_dev;
996 req->fr_list = kmalloc_array(target->mr_per_cmd, sizeof(void *),
1001 req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL);
1006 target->indirect_size,
1035 static void srp_remove_target(struct srp_target_port *target)
1040 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
1042 srp_del_scsi_host_attr(target->scsi_host);
1043 srp_rport_get(target->rport);
1044 srp_remove_host(target->scsi_host);
1045 scsi_remove_host(target->scsi_host);
1046 srp_stop_rport_timers(target->rport);
1047 srp_disconnect_target(target);
1048 kobj_ns_drop(KOBJ_NS_TYPE_NET, target->net);
1049 for (i = 0; i < target->ch_count; i++) {
1050 ch = &target->ch[i];
1051 srp_free_ch_ib(target, ch);
1053 cancel_work_sync(&target->tl_err_work);
1054 srp_rport_put(target->rport);
1055 kfree(target->ch);
1056 target->ch = NULL;
1058 spin_lock(&target->srp_host->target_lock);
1059 list_del(&target->list);
1060 spin_unlock(&target->srp_host->target_lock);
1062 scsi_host_put(target->scsi_host);
1067 struct srp_target_port *target =
1070 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
1072 srp_remove_target(target);
1077 struct srp_target_port *target = rport->lld_data;
1079 srp_queue_remove_work(target);
1084 * @target: SRP target port.
1086 static int srp_connected_ch(struct srp_target_port *target)
1090 for (i = 0; i < target->ch_count; i++)
1091 c += target->ch[i].connected;
1099 struct srp_target_port *target = ch->target;
1102 WARN_ON_ONCE(!multich && srp_connected_ch(target) > 0);
1139 shost_printk(KERN_ERR, target->scsi_host, PFX
1178 struct srp_target_port *target = ch->target;
1179 struct srp_device *dev = target->srp_host->srp_dev;
1194 shost_printk(KERN_ERR, target->scsi_host, PFX
1198 &target->tl_err_work);
1247 * @req_lim_delta: Amount to be added to @target->req_lim.
1282 struct srp_target_port *target = context->srp_target;
1284 struct srp_rdma_ch *ch = &target->ch[blk_mq_unique_tag_to_hwq(tag)];
1294 struct srp_target_port *target = rport->lld_data;
1295 struct srp_terminate_context context = { .srp_target = target,
1298 scsi_host_busy_iter(target->scsi_host, srp_terminate_cmd, &context);
1301 /* Calculate maximum initiator to target information unit length. */
1332 struct srp_target_port *target = rport->lld_data;
1334 uint32_t max_iu_len = srp_max_it_iu_len(target->cmd_sg_cnt,
1336 target->max_it_iu_size);
1340 srp_disconnect_target(target);
1342 if (target->state == SRP_TARGET_SCANNING)
1346 * Now get a new local CM ID so that we avoid confusing the target in
1350 for (i = 0; i < target->ch_count; i++) {
1351 ch = &target->ch[i];
1356 .srp_target = target, .scsi_result = DID_RESET << 16};
1358 scsi_host_busy_iter(target->scsi_host, srp_terminate_cmd,
1361 for (i = 0; i < target->ch_count; i++) {
1362 ch = &target->ch[i];
1371 for (j = 0; j < target->queue_size; ++j)
1375 target->qp_in_error = false;
1377 for (i = 0; i < target->ch_count; i++) {
1378 ch = &target->ch[i];
1386 shost_printk(KERN_INFO, target->scsi_host,
1424 struct srp_target_port *target = ch->target;
1425 struct srp_device *dev = target->srp_host->srp_dev;
1432 shost_printk(KERN_ERR, ch->target->scsi_host,
1434 ch->target->mr_per_cmd);
1440 if (sg_nents == 1 && target->global_rkey) {
1445 target->global_rkey);
1505 state->fr.end = req->fr_list + ch->target->mr_per_cmd;
1530 struct srp_target_port *target = ch->target;
1536 target->global_rkey);
1553 struct srp_target_port *target = ch->target;
1554 struct srp_device *dev = target->srp_host->srp_dev;
1592 struct srp_device *dev = ch->target->srp_host->srp_dev;
1622 struct srp_target_port *target = ch->target;
1642 shost_printk(KERN_WARNING, target->scsi_host,
1652 dev = target->srp_host->srp_dev;
1675 sge[i].lkey = target->lkey;
1685 if (count == 1 && target->global_rkey) {
1696 buf->key = cpu_to_be32(target->global_rkey);
1710 target->indirect_size, DMA_TO_DEVICE);
1731 * target is not using an external indirect table, we are
1747 if (unlikely(target->cmd_sg_cnt < state.ndesc &&
1748 !target->allow_ext_sg)) {
1749 shost_printk(KERN_ERR, target->scsi_host,
1755 count = min(state.ndesc, target->cmd_sg_cnt);
1767 if (!target->global_rkey) {
1774 idb_rkey = cpu_to_be32(target->global_rkey);
1800 if (ret == -ENOMEM && req->nmdesc >= target->mr_pool_size)
1830 * - SRP_IU_RSP: 1, since a conforming SRP target never sends more than
1836 struct srp_target_port *target = ch->target;
1847 /* Initiator responses to target requests do not consume credits */
1850 ++target->zero_req_lim;
1890 struct srp_target_port *target = ch->target;
1898 iu->sge[0].lkey = target->lkey;
1914 struct srp_target_port *target = ch->target;
1920 list.lkey = target->lkey;
1934 struct srp_target_port *target = ch->target;
1948 shost_printk(KERN_ERR, target->scsi_host,
1954 scmnd = scsi_host_find_tag(target->scsi_host, rsp->tag);
1960 shost_printk(KERN_ERR, target->scsi_host,
1962 rsp->tag, ch - target->ch, ch->qp->qp_num);
1994 struct srp_target_port *target = ch->target;
1995 struct ib_device *dev = target->srp_host->srp_dev->dev;
2006 shost_printk(KERN_ERR, target->scsi_host, PFX
2018 shost_printk(KERN_ERR, target->scsi_host, PFX
2036 shost_printk(KERN_ERR, ch->target->scsi_host, PFX
2043 struct srp_target_port *target = ch->target;
2050 shost_printk(KERN_ERR, target->scsi_host, PFX
2054 shost_printk(KERN_ERR, target->scsi_host, PFX
2062 struct srp_target_port *target = ch->target;
2063 struct ib_device *dev = target->srp_host->srp_dev->dev;
2078 shost_printk(KERN_ERR, target->scsi_host,
2098 /* XXX Handle target logout */
2099 shost_printk(KERN_WARNING, target->scsi_host,
2100 PFX "Got target logout request\n");
2104 shost_printk(KERN_WARNING, target->scsi_host,
2114 shost_printk(KERN_ERR, target->scsi_host,
2120 * @work: Work structure embedded in an SRP target port.
2123 * hence the target->rport test.
2127 struct srp_target_port *target;
2129 target = container_of(work, struct srp_target_port, tl_err_work);
2130 if (target->rport)
2131 srp_start_tl_fail_timers(target->rport);
2138 struct srp_target_port *target = ch->target;
2140 if (ch->connected && !target->qp_in_error) {
2141 shost_printk(KERN_ERR, target->scsi_host,
2145 queue_work(system_long_wq, &target->tl_err_work);
2147 target->qp_in_error = true;
2152 struct srp_target_port *target = host_to_target(shost);
2162 scmnd->result = srp_chkready(target->rport);
2168 ch = &target->ch[blk_mq_unique_tag_to_hwq(tag)];
2177 dev = target->srp_host->srp_dev->dev;
2200 shost_printk(KERN_ERR, target->scsi_host,
2217 shost_printk(KERN_ERR, target->scsi_host, PFX "Send failed\n");
2253 struct srp_target_port *target = ch->target;
2256 ch->rx_ring = kcalloc(target->queue_size, sizeof(*ch->rx_ring),
2260 ch->tx_ring = kcalloc(target->queue_size, sizeof(*ch->tx_ring),
2265 for (i = 0; i < target->queue_size; ++i) {
2266 ch->rx_ring[i] = srp_alloc_iu(target->srp_host,
2273 for (i = 0; i < target->queue_size; ++i) {
2274 ch->tx_ring[i] = srp_alloc_iu(target->srp_host,
2286 for (i = 0; i < target->queue_size; ++i) {
2287 srp_free_iu(target->srp_host, ch->rx_ring[i]);
2288 srp_free_iu(target->srp_host, ch->tx_ring[i]);
2315 * Set target->rq_tmo_jiffies to one second more than the largest time
2332 struct srp_target_port *target = ch->target;
2343 ch->max_it_iu_len = srp_max_it_iu_len(target->cmd_sg_cnt,
2345 target->max_it_iu_size);
2350 shost_printk(KERN_DEBUG, target->scsi_host,
2357 target->scsi_host->can_queue
2359 target->scsi_host->can_queue);
2360 target->scsi_host->cmd_per_lun
2361 = min_t(int, target->scsi_host->can_queue,
2362 target->scsi_host->cmd_per_lun);
2364 shost_printk(KERN_WARNING, target->scsi_host,
2376 for (i = 0; i < target->queue_size; i++) {
2384 if (!target->using_rdma_cm) {
2404 target->rq_tmo_jiffies = srp_compute_rq_tmo(qp_attr, attr_mask);
2424 struct srp_target_port *target = ch->target;
2425 struct Scsi_Host *shost = target->scsi_host;
2443 if (srp_target_is_topspin(target)) {
2454 PFX "Topspin/Cisco redirect to target port GID %016llx%016llx\n",
2484 target->sgid.raw,
2485 target->ib_cm.orig_dgid.raw,
2510 struct srp_target_port *target = ch->target;
2515 shost_printk(KERN_DEBUG, target->scsi_host,
2527 shost_printk(KERN_DEBUG, target->scsi_host, PFX "REJ received\n");
2534 shost_printk(KERN_WARNING, target->scsi_host,
2538 shost_printk(KERN_ERR, target->scsi_host,
2540 queue_work(system_long_wq, &target->tl_err_work);
2544 shost_printk(KERN_ERR, target->scsi_host,
2557 shost_printk(KERN_WARNING, target->scsi_host,
2571 struct srp_target_port *target = ch->target;
2572 struct Scsi_Host *shost = target->scsi_host;
2622 struct srp_target_port *target = ch->target;
2648 shost_printk(KERN_DEBUG, target->scsi_host,
2660 shost_printk(KERN_DEBUG, target->scsi_host, PFX "REJ received\n");
2668 shost_printk(KERN_WARNING, target->scsi_host,
2673 queue_work(system_long_wq, &target->tl_err_work);
2678 shost_printk(KERN_ERR, target->scsi_host,
2686 shost_printk(KERN_WARNING, target->scsi_host,
2715 struct srp_target_port *target = ch->target;
2716 struct srp_rport *rport = target->rport;
2717 struct ib_device *dev = target->srp_host->srp_dev->dev;
2722 if (!ch->connected || target->qp_in_error)
2780 struct srp_target_port *target = host_to_target(scmnd->device->host);
2786 shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n");
2790 if (WARN_ON_ONCE(ch_idx >= target->ch_count))
2792 ch = &target->ch[ch_idx];
2795 shost_printk(KERN_ERR, target->scsi_host,
2802 if (target->rport->state == SRP_RPORT_LOST)
2810 struct srp_target_port *target = host_to_target(scmnd->device->host);
2814 shost_printk(KERN_ERR, target->scsi_host, "SRP reset_device called\n");
2816 ch = &target->ch[0];
2828 struct srp_target_port *target = host_to_target(scmnd->device->host);
2830 shost_printk(KERN_ERR, target->scsi_host, PFX "SRP reset_host called\n");
2832 return srp_reconnect_rport(target->rport) == 0 ? SUCCESS : FAILED;
2838 struct srp_target_port *target = host_to_target(shost);
2840 if (target->target_can_queue)
2841 starget->can_queue = target->target_can_queue;
2848 struct srp_target_port *target = host_to_target(shost);
2853 timeout = max_t(unsigned, 30 * HZ, target->rq_tmo_jiffies);
2863 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2865 return sprintf(buf, "0x%016llx\n", be64_to_cpu(target->id_ext));
2871 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2873 return sprintf(buf, "0x%016llx\n", be64_to_cpu(target->ioc_guid));
2879 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2881 if (target->using_rdma_cm)
2884 be64_to_cpu(target->ib_cm.service_id));
2890 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2892 if (target->using_rdma_cm)
2894 return sprintf(buf, "0x%04x\n", be16_to_cpu(target->ib_cm.pkey));
2900 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2902 return sprintf(buf, "%pI6\n", target->sgid.raw);
2908 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2909 struct srp_rdma_ch *ch = &target->ch[0];
2911 if (target->using_rdma_cm)
2919 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2921 if (target->using_rdma_cm)
2923 return sprintf(buf, "%pI6\n", target->ib_cm.orig_dgid.raw);
2929 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2933 for (i = 0; i < target->ch_count; i++) {
2934 ch = &target->ch[i];
2943 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2945 return sprintf(buf, "%d\n", target->zero_req_lim);
2951 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2953 return sprintf(buf, "%d\n", target->srp_host->port);
2959 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2962 dev_name(&target->srp_host->srp_dev->dev->dev));
2968 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2970 return sprintf(buf, "%d\n", target->ch_count);
2976 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2978 return sprintf(buf, "%d\n", target->comp_vector);
2984 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2986 return sprintf(buf, "%d\n", target->tl_retry_count);
2992 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2994 return sprintf(buf, "%u\n", target->cmd_sg_cnt);
3000 struct srp_target_port *target = host_to_target(class_to_shost(dev));
3002 return sprintf(buf, "%s\n", target->allow_ext_sg ? "true" : "false");
3080 * < 0 upon failure. Caller is responsible for SRP target port cleanup.
3081 * 0 and target->state == SRP_TARGET_REMOVED if asynchronous target port
3083 * 0 and target->state != SRP_TARGET_REMOVED upon success.
3085 static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
3090 target->state = SRP_TARGET_SCANNING;
3091 sprintf(target->target_name, "SRP.T10:%016llX",
3092 be64_to_cpu(target->id_ext));
3094 if (scsi_add_host(target->scsi_host, host->srp_dev->dev->dev.parent))
3097 memcpy(ids.port_id, &target->id_ext, 8);
3098 memcpy(ids.port_id + 8, &target->ioc_guid, 8);
3100 rport = srp_rport_add(target->scsi_host, &ids);
3102 scsi_remove_host(target->scsi_host);
3106 rport->lld_data = target;
3107 target->rport = rport;
3110 list_add_tail(&target->list, &host->target_list);
3113 scsi_scan_target(&target->scsi_host->shost_gendev,
3114 0, target->scsi_id, SCAN_WILD_CARD, SCSI_SCAN_INITIAL);
3116 if (srp_connected_ch(target) < target->ch_count ||
3117 target->qp_in_error) {
3118 shost_printk(KERN_INFO, target->scsi_host,
3120 srp_queue_remove_work(target);
3125 dev_name(&target->scsi_host->shost_gendev),
3126 srp_sdev_count(target->scsi_host));
3128 spin_lock_irq(&target->lock);
3129 if (target->state == SRP_TARGET_SCANNING)
3130 target->state = SRP_TARGET_LIVE;
3131 spin_unlock_irq(&target->lock);
3151 * srp_conn_unique() - check whether the connection to a target is unique
3153 * @target: SRP target port.
3156 struct srp_target_port *target)
3161 if (target->state == SRP_TARGET_REMOVED)
3168 if (t != target &&
3169 target->id_ext == t->id_ext &&
3170 target->ioc_guid == t->ioc_guid &&
3171 target->initiator_ext == t->initiator_ext) {
3294 struct srp_target_port *target)
3331 target->id_ext = cpu_to_be64(ull);
3347 target->ioc_guid = cpu_to_be64(ull);
3363 ret = hex2bin(target->ib_cm.orig_dgid.raw, p, 16);
3375 target->ib_cm.pkey = cpu_to_be16(token);
3390 target->ib_cm.service_id = cpu_to_be64(ull);
3400 ret = srp_parse_in(net, &target->rdma_cm.src.ss, p,
3407 target->rdma_cm.src_specified = true;
3417 ret = srp_parse_in(net, &target->rdma_cm.dst.ss, p,
3426 target->using_rdma_cm = true;
3436 target->scsi_host->max_sectors = token;
3451 target->scsi_host->can_queue = token;
3452 target->queue_size = token + SRP_RSP_SQ_SIZE +
3455 target->scsi_host->cmd_per_lun = token;
3471 target->scsi_host->cmd_per_lun = token;
3487 target->target_can_queue = token;
3504 target->io_class = token;
3519 target->initiator_ext = cpu_to_be64(ull);
3536 target->cmd_sg_cnt = token;
3545 target->allow_ext_sg = !!token;
3561 target->sg_tablesize = token;
3576 target->comp_vector = token;
3592 target->tl_retry_count = token;
3603 pr_warn("bad maximum initiator to target IU size '%s'\n", p);
3607 target->max_it_iu_size = token;
3622 target->ch_count = token;
3626 pr_warn("unknown parameter or missing value '%s' in target creation request\n",
3640 pr_warn("target creation request is missing one or more parameters\n");
3642 if (target->scsi_host->cmd_per_lun > target->scsi_host->can_queue
3645 target->scsi_host->cmd_per_lun,
3646 target->scsi_host->can_queue);
3660 struct srp_target_port *target;
3684 target = host_to_target(target_host);
3686 target->net = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
3687 target->io_class = SRP_REV16A_IB_IO_CLASS;
3688 target->scsi_host = target_host;
3689 target->srp_host = host;
3690 target->lkey = host->srp_dev->pd->local_dma_lkey;
3691 target->global_rkey = host->srp_dev->global_rkey;
3692 target->cmd_sg_cnt = cmd_sg_entries;
3693 target->sg_tablesize = indirect_sg_entries ? : cmd_sg_entries;
3694 target->allow_ext_sg = allow_ext_sg;
3695 target->tl_retry_count = 7;
3696 target->queue_size = SRP_DEFAULT_QUEUE_SIZE;
3702 scsi_host_get(target->scsi_host);
3708 ret = srp_parse_options(target->net, buf, target);
3712 if (!srp_conn_unique(target->srp_host, target)) {
3713 if (target->using_rdma_cm) {
3714 shost_printk(KERN_INFO, target->scsi_host,
3715 PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;dest=%pIS\n",
3716 be64_to_cpu(target->id_ext),
3717 be64_to_cpu(target->ioc_guid),
3718 &target->rdma_cm.dst);
3720 shost_printk(KERN_INFO, target->scsi_host,
3721 PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;initiator_ext=%016llx\n",
3722 be64_to_cpu(target->id_ext),
3723 be64_to_cpu(target->ioc_guid),
3724 be64_to_cpu(target->initiator_ext));
3730 if (!srp_dev->has_fr && !target->allow_ext_sg &&
3731 target->cmd_sg_cnt < target->sg_tablesize) {
3733 target->sg_tablesize = target->cmd_sg_cnt;
3757 (target->scsi_host->max_sectors + 1 +
3761 (target->sg_tablesize +
3766 target->scsi_host->max_sectors, srp_dev->max_pages_per_mr, srp_dev->mr_page_size,
3770 target_host->sg_tablesize = target->sg_tablesize;
3771 target->mr_pool_size = target->scsi_host->can_queue * mr_per_cmd;
3772 target->mr_per_cmd = mr_per_cmd;
3773 target->indirect_size = target->sg_tablesize *
3775 max_iu_len = srp_max_it_iu_len(target->cmd_sg_cnt,
3777 target->max_it_iu_size);
3779 INIT_WORK(&target->tl_err_work, srp_tl_err_work);
3780 INIT_WORK(&target->remove_work, srp_remove_work);
3781 spin_lock_init(&target->lock);
3782 ret = rdma_query_gid(ibdev, host->port, 0, &target->sgid);
3787 if (target->ch_count == 0) {
3788 target->ch_count =
3795 target->ch = kcalloc(target->ch_count, sizeof(*target->ch),
3797 if (!target->ch)
3800 for (ch_idx = 0; ch_idx < target->ch_count; ++ch_idx) {
3801 ch = &target->ch[ch_idx];
3802 ch->target = target;
3818 if (target->using_rdma_cm)
3820 &target->rdma_cm.dst);
3823 target->ib_cm.orig_dgid.raw);
3824 shost_printk(KERN_ERR, target->scsi_host,
3827 target->ch_count, dst);
3831 srp_free_ch_ib(target, ch);
3832 target->ch_count = ch - target->ch;
3840 target->scsi_host->nr_hw_queues = target->ch_count;
3842 ret = srp_add_target(host, target);
3846 if (target->state != SRP_TARGET_REMOVED) {
3847 if (target->using_rdma_cm) {
3848 shost_printk(KERN_DEBUG, target->scsi_host, PFX
3849 "new target: id_ext %016llx ioc_guid %016llx sgid %pI6 dest %pIS\n",
3850 be64_to_cpu(target->id_ext),
3851 be64_to_cpu(target->ioc_guid),
3852 target->sgid.raw, &target->rdma_cm.dst);
3854 shost_printk(KERN_DEBUG, target->scsi_host, PFX
3855 "new target: id_ext %016llx ioc_guid %016llx pkey %04x service_id %016llx sgid %pI6 dgid %pI6\n",
3856 be64_to_cpu(target->id_ext),
3857 be64_to_cpu(target->ioc_guid),
3858 be16_to_cpu(target->ib_cm.pkey),
3859 be64_to_cpu(target->ib_cm.service_id),
3860 target->sgid.raw,
3861 target->ib_cm.orig_dgid.raw);
3871 scsi_host_put(target->scsi_host);
3878 if (target->state != SRP_TARGET_REMOVED)
3879 kobj_ns_drop(KOBJ_NS_TYPE_NET, target->net);
3880 scsi_host_put(target->scsi_host);
3886 srp_disconnect_target(target);
3889 for (i = 0; i < target->ch_count; i++) {
3890 ch = &target->ch[i];
3891 srp_free_ch_ib(target, ch);
3894 kfree(target->ch);
4057 struct srp_target_port *target;
4065 * target ports can be created.
4070 * Remove all target ports.
4073 list_for_each_entry(target, &host->target_list, list)
4074 srp_queue_remove_work(target);
4080 * target->tl_err_work so waiting for the remove works to