35 #include <linux/module.h>
37 #include <linux/slab.h>
39 #include <linux/ctype.h>
41 #include <linux/string.h>
53 #define DRV_NAME "ib_srpt"
54 #define DRV_VERSION "2.0.0"
55 #define DRV_RELDATE "2011-02-14"
57 #define SRPT_ID_STRING "Linux SRP target"
60 #define pr_fmt(fmt) DRV_NAME " " fmt
71 static u64 srpt_service_guid;
78 "Maximum size of SRP request messages in bytes.");
83 "Shared receive queue (SRQ) size.");
92 "Using this value for ioc_guid, id_ext, and cm_listen_id"
93 " instead of using the node_guid of the first HCA.");
97 static void srpt_release_channel(
struct srpt_rdma_ch *ch);
98 static int srpt_queue_status(
struct se_cmd *
cmd);
118 static inline const char *srpt_sdev_name(
struct srpt_device *sdev)
120 return sdev->
device->name;
130 spin_unlock_irqrestore(&ch->
spinlock, flags);
143 spin_unlock_irqrestore(&ch->
spinlock, flags);
163 spin_unlock_irqrestore(&ch->
spinlock, flags);
186 srpt_sdev_name(sdev));
188 switch (event->
event) {
191 sport = &sdev->
port[
event->element.port_num - 1];
203 sport = &sdev->
port[
event->element.port_num - 1];
218 static void srpt_srq_event(
struct ib_event *event,
void *
ctx)
228 pr_debug(
"QP event %d on cm_id=%p sess_name=%s state=%d\n",
231 switch (event->
event) {
238 srpt_release_channel(ch);
240 pr_debug(
"%s: state %d - ignored LAST_WQE.\n",
266 tmp = c_list[
id] & 0xf;
267 c_list[
id] = (value << 4) | tmp;
269 tmp = c_list[
id] & 0xf0;
270 c_list[
id] = (value & 0xf) | tmp;
280 static void srpt_get_class_port_info(
struct ib_dm_mad *
mad)
285 memset(cif, 0,
sizeof *cif);
299 static void srpt_get_iou(
struct ib_dm_mad *mad)
311 for (i = 1, slot = 2; i < 16; i++, slot++)
324 static void srpt_get_ioc(
struct srpt_port *sport,
u32 slot,
332 if (!slot || slot > 16) {
344 memset(iocp, 0,
sizeof *iocp);
374 static void srpt_get_svc_entries(
u64 ioc_guid,
381 if (!slot || slot > 16) {
387 if (slot > 2 || lo > hi || hi > 1) {
394 memset(svc_entries, 0,
sizeof *svc_entries);
421 srpt_get_class_port_info(rsp_mad);
424 srpt_get_iou(rsp_mad);
428 srpt_get_ioc(sp, slot, rsp_mad);
432 hi = (
u8) ((slot >> 8) & 0xff);
433 lo = (
u8) (slot & 0xff);
434 slot = (
u16) ((slot >> 16) & 0xffff);
435 srpt_get_svc_entries(srpt_service_guid,
436 slot, hi, lo, rsp_mad);
448 static void srpt_mad_send_handler(
struct ib_mad_agent *mad_agent,
458 static void srpt_mad_recv_handler(
struct ib_mad_agent *mad_agent,
477 mad_wc->
wc->pkey_index, 0,
488 dm_mad->mad_hdr.status = 0;
490 switch (mad_wc->
recv_buf.mad->mad_hdr.method) {
492 srpt_mgmt_method_get(sport, mad_wc->
recv_buf.mad, dm_mad);
495 dm_mad->mad_hdr.status =
499 dm_mad->mad_hdr.status =
527 static int srpt_refresh_port(
struct srpt_port *sport)
534 memset(&port_modify, 0,
sizeof port_modify);
536 port_modify.clr_port_cap_mask = 0;
546 sport->
sm_lid = port_attr.sm_lid;
547 sport->
lid = port_attr.lid;
554 memset(®_req, 0,
sizeof reg_req);
564 srpt_mad_send_handler,
565 srpt_mad_recv_handler,
578 port_modify.set_port_cap_mask = 0;
592 static void srpt_unregister_mad_agent(
struct srpt_device *sdev)
600 for (i = 1; i <= sdev->
device->phys_port_cnt; i++) {
601 sport = &sdev->
port[i - 1];
616 int ioctx_size,
int dma_size,
629 ioctx->
dma = ib_dma_map_single(sdev->
device, ioctx->
buf, dma_size, dir);
630 if (ib_dma_mapping_error(sdev->
device, ioctx->
dma))
652 ib_dma_unmap_single(sdev->
device, ioctx->
dma, dma_size, dir);
679 ring[
i] = srpt_alloc_ioctx(sdev, ioctx_size, dma_size, dir);
688 srpt_free_ioctx(sdev, ring[i], dma_size, dir);
698 static void srpt_free_ioctx_ring(
struct srpt_ioctx **ioctx_ring,
705 srpt_free_ioctx(sdev, ioctx_ring[i], dma_size, dir);
720 state = ioctx->
state;
721 spin_unlock_irqrestore(&ioctx->
spinlock, flags);
740 previous = ioctx->
state;
743 spin_unlock_irqrestore(&ioctx->
spinlock, flags);
765 previous = ioctx->
state;
768 spin_unlock_irqrestore(&ioctx->
spinlock, flags);
769 return previous == old;
775 static int srpt_post_recv(
struct srpt_device *sdev,
785 list.length = srp_max_req_size;
786 list.lkey = sdev->
mr->lkey;
792 return ib_post_srq_recv(sdev->
srq, &
wr, &bad_wr);
816 ib_dma_sync_single_for_device(sdev->
device, ioctx->
ioctx.dma, len,
821 list.lkey = sdev->
mr->lkey;
830 ret = ib_post_send(ch->
qp, &
wr, &bad_wr);
860 unsigned add_cdb_offset;
886 else if (srp_cmd->
buf_fmt >> 4)
915 " type (%u out + %u in != %u / %zu)\n",
996 qp_attr.max_dest_rd_atomic = 4;
1026 qp_attr.max_rd_atomic = 4;
1048 static void srpt_unmap_sg_to_ib_sge(
struct srpt_rdma_ch *ch,
1067 dir = ioctx->
cmd.data_direction;
1069 ib_dma_unmap_sg(ch->
sport->sdev->device, sg, ioctx->
sg_cnt,
1070 opposite_dma_dir(dir));
1078 static int srpt_map_sg_to_ib_sge(
struct srpt_rdma_ch *ch,
1105 count = ib_dma_map_sg(ch->
sport->sdev->device, sg, sg_cnt,
1106 opposite_dma_dir(dir));
1139 j < count && i < ioctx->
n_rbuf && tsize > 0; ++
i, ++riu, ++db) {
1147 while (rsize > 0 && tsize > 0) {
1149 if (rsize >= dma_len) {
1172 kmalloc(riu->sge_cnt *
sizeof *riu->sge,
1185 riu->sge =
kmalloc(riu->sge_cnt *
sizeof *riu->sge,
1200 j < count && i < ioctx->
n_rbuf && tsize > 0; ++
i, ++riu, ++db) {
1205 while (rsize > 0 && tsize > 0) {
1209 if (rsize >= dma_len) {
1211 (tsize < dma_len) ? tsize : dma_len;
1224 sge->
length = (tsize < rsize) ? tsize : rsize;
1232 if (k == riu->sge_cnt && rsize > 0 && tsize > 0) {
1236 }
else if (rsize > 0 && tsize > 0)
1244 srpt_unmap_sg_to_ib_sge(ch, ioctx);
1255 unsigned long flags;
1266 spin_unlock_irqrestore(&ch->
spinlock, flags);
1272 kref_init(&ioctx->
kref);
1281 init_completion(&ioctx->
tx_done);
1299 unsigned long flags;
1307 srpt_unmap_sg_to_ib_sge(ioctx->
ch, ioctx);
1318 spin_unlock_irqrestore(&ch->
spinlock, flags);
1321 static void srpt_put_send_ioctx_kref(
struct kref *
kref)
1334 unsigned long flags;
1347 state = ioctx->
state;
1360 spin_unlock_irqrestore(&ioctx->
spinlock, flags);
1365 pr_debug(
"Aborting cmd with state %d and tag %lld\n", state,
1385 spin_unlock_irqrestore(&ioctx->
cmd.t_state_lock, flags);
1394 srpt_unmap_sg_to_ib_sge(ioctx->
ch, ioctx);
1397 spin_unlock_irqrestore(&ioctx->
cmd.t_state_lock, flags);
1398 kref_put(&ioctx->
kref, srpt_put_send_ioctx_kref);
1402 kref_put(&ioctx->
kref, srpt_put_send_ioctx_kref);
1405 WARN_ON(
"ERROR: unexpected command state");
1416 static void srpt_handle_send_err_comp(
struct srpt_rdma_ch *ch,
u64 wr_id)
1425 index = idx_from_wr_id(wr_id);
1427 state = srpt_get_cmd_state(ioctx);
1440 srpt_abort_cmd(ioctx);
1446 static void srpt_handle_send_comp(
struct srpt_rdma_ch *ch,
1461 kref_put(&ioctx->
kref, srpt_put_send_ioctx_kref);
1464 " wr_id = %u.\n", ioctx->
ioctx.index);
1475 static void srpt_handle_rdma_comp(
struct srpt_rdma_ch *ch,
1488 __LINE__, srpt_get_cmd_state(ioctx));
1492 WARN(
true,
"unexpected opcode %d\n", opcode);
1499 static void srpt_handle_rdma_err_comp(
struct srpt_rdma_ch *ch,
1505 unsigned long flags;
1508 state = srpt_get_cmd_state(ioctx);
1511 if (ioctx->
n_rdma <= 0) {
1513 " error completion with idx %d\n",
1514 ioctx->
ioctx.index);
1519 srpt_abort_cmd(ioctx);
1522 __func__, __LINE__, state);
1527 spin_unlock_irqrestore(&ioctx->
cmd.t_state_lock, flags);
1565 srp_rsp = ioctx->
ioctx.buf;
1569 sense_data_len = ioctx->
cmd.scsi_sense_length;
1572 memset(srp_rsp, 0,
sizeof *srp_rsp);
1579 if (sense_data_len) {
1582 if (sense_data_len > max_sense_len) {
1584 " bytes\n", sense_data_len, max_sense_len);
1585 sense_data_len = max_sense_len;
1590 memcpy(srp_rsp + 1, sense_data, sense_data_len);
1609 static int srpt_build_tskmgmt_rsp(
struct srpt_rdma_ch *ch,
1613 struct srp_rsp *srp_rsp;
1620 srp_rsp = ioctx->
ioctx.buf;
1622 memset(srp_rsp, 0,
sizeof *srp_rsp);
1638 #define NO_SUCH_LUN ((uint64_t)-1LL)
1661 int addressing_method;
1676 if (*((
__be16 *)&lun[2]) != 0)
1680 if (*((
__be32 *)&lun[2]) != 0)
1689 addressing_method = (*lun) >> 6;
1690 switch (addressing_method) {
1694 res = *(lun + 1) | (((*lun) & 0x3f) << 8);
1713 static int srpt_check_stop_free(
struct se_cmd *cmd)
1718 return kref_put(&ioctx->
kref, srpt_put_send_ioctx_kref);
1729 struct srp_cmd *srp_cmd;
1737 srp_cmd = recv_ioctx->
ioctx.buf;
1738 kref_get(&send_ioctx->
kref);
1739 cmd = &send_ioctx->
cmd;
1740 send_ioctx->
tag = srp_cmd->
tag;
1758 ret = srpt_get_desc_tbl(send_ioctx, srp_cmd, &dir, &data_len);
1760 printk(
KERN_ERR "0x%llx: parsing SRP descriptor table failed.\n",
1764 kref_put(&send_ioctx->
kref, srpt_put_send_ioctx_kref);
1770 unpacked_lun = srpt_unpack_lun((
uint8_t *)&srp_cmd->lun,
1771 sizeof(srp_cmd->lun));
1773 kref_put(&send_ioctx->
kref, srpt_put_send_ioctx_kref);
1778 kref_put(&send_ioctx->
kref, srpt_put_send_ioctx_kref);
1780 srpt_queue_status(cmd);
1819 sdev = ch->
sport->sdev;
1822 for (i = 0; i < ch->
rq_size; ++
i) {
1824 if (target->
cmd.se_lun == ioctx->
cmd.se_lun &&
1825 target->
tag == tag &&
1836 static int srp_tmr_to_tcm(
int fn)
1862 static void srpt_handle_tsk_mgmt(
struct srpt_rdma_ch *ch,
1874 srp_tsk = recv_ioctx->
ioctx.buf;
1875 cmd = &send_ioctx->
cmd;
1877 pr_debug(
"recv tsk_mgmt fn %d for task_tag %lld and cmd tag %lld"
1882 send_ioctx->
tag = srp_tsk->
tag;
1886 send_ioctx->
cmd.se_tmr_req->response =
1897 unpacked_lun = srpt_unpack_lun((
uint8_t *)&srp_tsk->lun,
1898 sizeof(srp_tsk->lun));
1901 pr_debug(
"rejecting TMR for LUN %lld\n", unpacked_lun);
1908 srpt_rx_mgmt_fn_tag(send_ioctx, srp_tsk->
task_tag);
1911 kref_get(&send_ioctx->
kref);
1925 static void srpt_handle_new_iu(
struct srpt_rdma_ch *ch,
1929 struct srp_cmd *srp_cmd;
1935 ib_dma_sync_single_for_cpu(ch->
sport->sdev->device,
1936 recv_ioctx->
ioctx.dma, srp_max_req_size,
1939 ch_state = srpt_get_ch_state(ch);
1948 srp_cmd = recv_ioctx->
ioctx.buf;
1951 send_ioctx = srpt_get_send_ioctx(ch);
1963 switch (srp_cmd->
opcode) {
1965 srpt_handle_cmd(ch, recv_ioctx, send_ioctx);
1968 srpt_handle_tsk_mgmt(ch, recv_ioctx, send_ioctx);
1974 pr_debug(
"received SRP_CRED_RSP\n");
1977 pr_debug(
"received SRP_AER_RSP\n");
1988 srpt_post_recv(ch->
sport->sdev, recv_ioctx);
1993 static void srpt_process_rcv_completion(
struct ib_cq *cq,
2001 index = idx_from_wr_id(wc->
wr_id);
2009 srpt_handle_new_iu(ch, ioctx,
NULL);
2031 static void srpt_process_send_completion(
struct ib_cq *cq,
2039 index = idx_from_wr_id(wc->
wr_id);
2040 opcode = opcode_from_wr_id(wc->
wr_id);
2044 srpt_handle_send_comp(ch, send_ioctx);
2048 srpt_handle_rdma_comp(ch, send_ioctx, opcode);
2053 " with status %d\n", index, wc->
status);
2054 srpt_handle_send_err_comp(ch, wc->
wr_id);
2057 " status %d", opcode, index, wc->
status);
2058 srpt_handle_rdma_err_comp(ch, send_ioctx, opcode);
2064 && srpt_get_ch_state(ch) ==
CH_LIVE
2065 && (send_ioctx = srpt_get_send_ioctx(ch)) !=
NULL)) {
2072 srpt_handle_new_iu(ch, recv_ioctx, send_ioctx);
2078 struct ib_wc *
const wc = ch->
wc;
2084 while ((n = ib_poll_cq(cq,
ARRAY_SIZE(ch->
wc), wc)) > 0) {
2085 for (i = 0; i <
n; i++) {
2086 if (opcode_from_wr_id(wc[i].wr_id) ==
SRPT_RECV)
2087 srpt_process_rcv_completion(cq, ch, &wc[i]);
2089 srpt_process_send_completion(cq, ch, &wc[i]);
2105 static void srpt_completion(
struct ib_cq *cq,
void *
ctx)
2112 static int srpt_compl_thread(
void *
arg)
2125 (srpt_process_completion(ch->
cq, ch),
2147 qp_init = kzalloc(
sizeof *qp_init,
GFP_KERNEL);
2152 ch->
rq_size + srp_sq_size, 0);
2153 if (IS_ERR(ch->
cq)) {
2154 ret = PTR_ERR(ch->
cq);
2156 ch->
rq_size + srp_sq_size, ret);
2165 qp_init->
srq = sdev->
srq;
2168 qp_init->
cap.max_send_wr = srp_sq_size;
2172 if (IS_ERR(ch->
qp)) {
2173 ret = PTR_ERR(ch->
qp);
2175 goto err_destroy_cq;
2180 pr_debug(
"%s: max_cqe= %d max_sge= %d sq_size = %d cm_id= %p\n",
2181 __func__, ch->
cq->cqe, qp_init->
cap.max_send_sge,
2182 qp_init->
cap.max_send_wr, ch->
cm_id);
2184 ret = srpt_init_ch_qp(ch, ch->
qp);
2186 goto err_destroy_qp;
2193 if (IS_ERR(ch->
thread)) {
2197 goto err_destroy_qp;
2211 static void srpt_destroy_ch_ib(
struct srpt_rdma_ch *ch)
2232 unsigned long flags;
2234 sdev = ch->
sport->sdev;
2237 prev_state = ch->
state;
2238 switch (prev_state) {
2246 spin_unlock_irqrestore(&ch->
spinlock, flags);
2248 switch (prev_state) {
2272 sdev = ch->
sport->sdev;
2274 __srpt_close_ch(ch);
2303 if (ch->
cm_id == cm_id) {
2304 do_reset = srpt_test_and_set_ch_state(ch,
2306 srpt_test_and_set_ch_state(ch,
2308 srpt_test_and_set_ch_state(ch,
2316 ret = srpt_ch_qp_err(ch);
2319 " failed: %d\n", ret);
2341 if (ch->
cm_id == cm_id) {
2348 return found ? ch :
NULL;
2359 static void srpt_release_channel(
struct srpt_rdma_ch *ch)
2364 static void srpt_release_channel_work(
struct work_struct *
w)
2370 pr_debug(
"ch = %p; ch->sess = %p; release_done = %p\n", ch, ch->
sess,
2373 sdev = ch->
sport->sdev;
2380 srpt_destroy_ch_ib(ch);
2406 if (
memcmp(nacl->i_port_id, i_port_id,
2407 sizeof(nacl->i_port_id)) == 0)
2418 spin_lock_irq(&sport->port_acl_lock);
2419 nacl = __srpt_lookup_acl(sport, i_port_id);
2420 spin_unlock_irq(&sport->port_acl_lock);
2431 static int srpt_cm_req_recv(
struct ib_cm_id *cm_id,
2449 if (
WARN_ON(!sdev || !private_data))
2456 printk(
KERN_INFO "Received SRP_LOGIN_REQ with i_port_id 0x%llx:0x%llx,"
2457 " t_port_id 0x%llx:0x%llx and it_iu_len %d on port %d"
2458 " (guid=0x%llx:0x%llx)\n",
2470 rep_param = kzalloc(
sizeof *rep_param,
GFP_KERNEL);
2472 if (!rsp || !rej || !rep_param) {
2477 if (it_iu_len > srp_max_req_size || it_iu_len < 64) {
2482 " length (%d bytes) is out of range (%d .. %d)\n",
2483 it_iu_len, 64, srp_max_req_size);
2492 " has not yet been enabled\n");
2509 ch_state = srpt_get_ch_state(ch);
2515 pr_debug(
"Found existing channel %s"
2516 " cm_id= %p state= %d\n",
2519 __srpt_close_ch(ch);
2538 " has an invalid target port identifier.\n");
2574 for (i = 0; i < ch->
rq_size; i++) {
2579 ret = srpt_create_ch_ib(ch);
2584 " a new RDMA channel failed.\n");
2588 ret = srpt_ch_qp_rtr(ch, ch->
qp);
2593 " RTR failed (error code = %d)\n", ret);
2605 nacl = srpt_lookup_acl(sport, ch->
i_port_id);
2608 " configured yet for initiator %s.\n", ch->
sess_name);
2615 if (IS_ERR(ch->
sess)) {
2618 pr_debug(
"Failed to create session\n");
2619 goto deregister_session;
2621 ch->
sess->se_node_acl = &nacl->
nacl;
2624 pr_debug(
"Establish connection sess=%p name=%s cm_id=%p\n", ch->
sess,
2640 rep_param->
qp_num = ch->
qp->qp_num;
2653 " (error code = %d)\n", ret);
2654 goto release_channel;
2672 srpt_destroy_ch_ib(ch);
2688 (
void *)rej,
sizeof *rej);
2698 static void srpt_cm_rej_recv(
struct ib_cm_id *cm_id)
2701 srpt_drain_channel(cm_id);
2710 static void srpt_cm_rtu_recv(
struct ib_cm_id *cm_id)
2715 ch = srpt_find_channel(cm_id->
context, cm_id);
2721 ret = srpt_ch_qp_rts(ch, ch->
qp);
2726 srpt_handle_new_iu(ch, ioctx,
NULL);
2733 static void srpt_cm_timewait_exit(
struct ib_cm_id *cm_id)
2736 srpt_drain_channel(cm_id);
2739 static void srpt_cm_rep_error(
struct ib_cm_id *cm_id)
2742 srpt_drain_channel(cm_id);
2748 static void srpt_cm_dreq_recv(
struct ib_cm_id *cm_id)
2751 unsigned long flags;
2752 bool send_drep =
false;
2754 ch = srpt_find_channel(cm_id->
context, cm_id);
2757 pr_debug(
"cm_id= %p ch->state= %d\n", cm_id, srpt_get_ch_state(ch));
2760 switch (ch->
state) {
2769 WARN(
true,
"unexpected channel state %d\n", ch->
state);
2772 spin_unlock_irqrestore(&ch->
spinlock, flags);
2785 static void srpt_cm_drep_recv(
struct ib_cm_id *cm_id)
2789 srpt_drain_channel(cm_id);
2807 switch (event->
event) {
2813 srpt_cm_rej_recv(cm_id);
2817 srpt_cm_rtu_recv(cm_id);
2820 srpt_cm_dreq_recv(cm_id);
2823 srpt_cm_drep_recv(cm_id);
2826 srpt_cm_timewait_exit(cm_id);
2829 srpt_cm_rep_error(cm_id);
2861 const int n_rdma = ioctx->
n_rdma;
2863 dir = ioctx->
cmd.data_direction;
2868 if (sq_wr_avail < 0) {
2880 for (i = 0; i < n_rdma; ++
i, ++riu) {
2883 wr.wr_id = encode_wr_id(i == n_rdma - 1 ?
2886 ioctx->
ioctx.index);
2889 wr.wr_id = encode_wr_id(i == n_rdma - 1 ?
2892 ioctx->
ioctx.index);
2895 wr.wr.rdma.remote_addr = riu->
raddr;
2896 wr.wr.rdma.rkey = riu->
rkey;
2898 wr.sg_list = riu->
sge;
2904 ret = ib_post_send(ch->
qp, &
wr, &bad_wr);
2911 __func__, __LINE__, ret, i, n_rdma);
2917 ib_post_send(ch->
qp, &
wr, &bad_wr) != 0) {
2919 ioctx->
ioctx.index);
2924 ioctx->
ioctx.index);
2942 ret = srpt_map_sg_to_ib_sge(ch, ioctx);
2948 ret = srpt_perform_rdmas(ch, ioctx);
2952 __func__, __LINE__, ret);
2955 __func__, __LINE__, ret);
2962 srpt_unmap_sg_to_ib_sge(ch, ioctx);
2966 static int srpt_write_pending_status(
struct se_cmd *
se_cmd)
2993 ch_state = srpt_get_ch_state(ch);
2996 WARN(
true,
"unexpected channel state %d\n", ch_state);
3004 pr_debug(
"cmd with tag %lld: channel disconnecting\n",
3010 ret = srpt_xfer_data(ch, ioctx);
3016 static u8 tcm_to_srp_tsk_mgmt_status(
const int tcm_mgmt_status)
3018 switch (tcm_mgmt_status) {
3033 static int srpt_queue_response(
struct se_cmd *cmd)
3038 unsigned long flags;
3051 state = ioctx->
state;
3061 WARN(
true,
"ch %p; cmd %d: unexpected command state %d\n",
3065 spin_unlock_irqrestore(&ioctx->
spinlock, flags);
3070 srpt_abort_cmd(ioctx);
3074 dir = ioctx->
cmd.data_direction;
3079 ret = srpt_xfer_data(ch, ioctx);
3088 resp_len = srpt_build_cmd_rsp(ch, ioctx, ioctx->
tag,
3092 = tcm_to_srp_tsk_mgmt_status(cmd->
se_tmr_req->response);
3093 resp_len = srpt_build_tskmgmt_rsp(ch, ioctx, srp_tm_status,
3096 ret = srpt_post_send(ch, ioctx, resp_len);
3100 srpt_unmap_sg_to_ib_sge(ch, ioctx);
3102 kref_put(&ioctx->
kref, srpt_put_send_ioctx_kref);
3109 static int srpt_queue_status(
struct se_cmd *cmd)
3119 return srpt_queue_response(cmd);
3126 srpt_refresh_port(sport);
3129 static int srpt_ch_list_empty(
struct srpt_device *sdev)
3143 static int srpt_release_sdev(
struct srpt_device *sdev)
3154 __srpt_close_ch(ch);
3158 srpt_ch_list_empty(sdev));
3178 sport = &sdev->
port[
i];
3188 static struct srpt_port *srpt_lookup_port(
const char *name)
3192 spin_lock(&srpt_dev_lock);
3193 sport = __srpt_lookup_port(name);
3194 spin_unlock(&srpt_dev_lock);
3209 pr_debug(
"device = %p, device->dma_ops = %p\n", device,
3225 if (IS_ERR(sdev->
pd))
3229 if (IS_ERR(sdev->
mr))
3234 srq_attr.event_handler = srpt_srq_event;
3235 srq_attr.srq_context = (
void *)sdev;
3236 srq_attr.attr.max_wr = sdev->
srq_size;
3237 srq_attr.attr.max_sge = 1;
3238 srq_attr.attr.srq_limit = 0;
3242 if (IS_ERR(sdev->
srq))
3245 pr_debug(
"%s: create SRQ #wr= %d max_allow=%d dev= %s\n",
3249 if (!srpt_service_guid)
3253 if (IS_ERR(sdev->
cm_id))
3257 pr_debug(
"Target login info: id_ext=%016llx,ioc_guid=%016llx,"
3258 "pkey=ffff,service_id=%016llx\n", srpt_service_guid,
3259 srpt_service_guid, srpt_service_guid);
3271 srpt_event_handler);
3276 srpt_alloc_ioctx_ring(sdev, sdev->
srq_size,
3287 for (i = 1; i <= sdev->
device->phys_port_cnt; i++) {
3288 sport = &sdev->
port[i - 1];
3298 if (srpt_refresh_port(sport)) {
3300 srpt_sdev_name(sdev), i);
3309 spin_lock(&srpt_dev_lock);
3311 spin_unlock(&srpt_dev_lock);
3343 static void srpt_remove_one(
struct ib_device *device)
3355 srpt_unregister_mad_agent(sdev);
3360 for (i = 0; i < sdev->
device->phys_port_cnt; i++)
3370 spin_lock(&srpt_dev_lock);
3372 spin_unlock(&srpt_dev_lock);
3373 srpt_release_sdev(sdev);
3387 .add = srpt_add_one,
3388 .remove = srpt_remove_one
3401 static char *srpt_get_fabric_name(
void)
3431 int *format_code,
unsigned char *
buf)
3437 tr_id = (
void *)buf;
3440 return sizeof(*tr_id);
3452 static char *srpt_parse_pr_out_transport_id(
struct se_portal_group *se_tpg,
3453 const char *
buf,
u32 *out_tid_len,
3454 char **port_nexus_ptr)
3458 *port_nexus_ptr =
NULL;
3460 tr_id = (
void *)buf;
3491 static void srpt_release_cmd(
struct se_cmd *se_cmd)
3498 static int srpt_shutdown_session(
struct se_session *se_sess)
3510 static void srpt_close_session(
struct se_session *se_sess)
3520 pr_debug(
"ch %p state %d\n", ch, srpt_get_ch_state(ch));
3522 sdev = ch->
sport->sdev;
3526 __srpt_close_ch(ch);
3546 static void srpt_set_default_node_attrs(
struct se_node_acl *nacl)
3550 static u32 srpt_get_task_tag(
struct se_cmd *se_cmd)
3559 static int srpt_get_tcm_cmd_state(
struct se_cmd *se_cmd)
3564 return srpt_get_cmd_state(ioctx);
3572 static int srpt_parse_i_port_id(
u8 i_port_id[16],
const char *name)
3575 unsigned len,
count, leading_zero_bytes;
3585 count =
min(len / 2, 16
U);
3586 leading_zero_bytes = 16 -
count;
3587 memset(i_port_id, 0, leading_zero_bytes);
3588 rc =
hex2bin(i_port_id + leading_zero_bytes, p, count);
3590 pr_debug(
"hex2bin failed for srpt_parse_i_port_id: %d\n", rc);
3608 u32 nexus_depth = 1;
3611 if (srpt_parse_i_port_id(i_port_id, name) < 0) {
3617 se_nacl_new = srpt_alloc_fabric_acl(tpg);
3628 if (IS_ERR(se_nacl)) {
3629 ret = PTR_ERR(se_nacl);
3643 return ERR_PTR(ret);
3650 static void srpt_drop_nodeacl(
struct se_node_acl *se_nacl)
3657 sport = nacl->
sport;
3663 srpt_release_fabric_acl(
NULL, se_nacl);
3666 static ssize_t srpt_tpg_attrib_show_srp_max_rdma_size(
3675 static ssize_t srpt_tpg_attrib_store_srp_max_rdma_size(
3686 pr_err(
"strict_strtoul() failed with ret: %d\n", ret);
3690 pr_err(
"val: %lu exceeds MAX_SRPT_RDMA_SIZE: %d\n", val,
3695 pr_err(
"val: %lu smaller than DEFAULT_MAX_RDMA_SIZE: %d\n",
3706 static ssize_t srpt_tpg_attrib_show_srp_max_rsp_size(
3715 static ssize_t srpt_tpg_attrib_store_srp_max_rsp_size(
3726 pr_err(
"strict_strtoul() failed with ret: %d\n", ret);
3730 pr_err(
"val: %lu exceeds MAX_SRPT_RSP_SIZE: %d\n", val,
3735 pr_err(
"val: %lu smaller than MIN_MAX_RSP_SIZE: %d\n", val,
3746 static ssize_t srpt_tpg_attrib_show_srp_sq_size(
3755 static ssize_t srpt_tpg_attrib_store_srp_sq_size(
3766 pr_err(
"strict_strtoul() failed with ret: %d\n", ret);
3770 pr_err(
"val: %lu exceeds MAX_SRPT_SRQ_SIZE: %d\n", val,
3775 pr_err(
"val: %lu smaller than MIN_SRPT_SRQ_SIZE: %d\n", val,
3787 &srpt_tpg_attrib_srp_max_rdma_size.attr,
3788 &srpt_tpg_attrib_srp_max_rsp_size.attr,
3789 &srpt_tpg_attrib_srp_sq_size.attr,
3793 static ssize_t srpt_tpg_show_enable(
3802 static ssize_t srpt_tpg_store_enable(
3817 if ((tmp != 0) && (tmp != 1)) {
3818 printk(
KERN_ERR "Illegal value for srpt_tpg_store_enable: %lu\n", tmp);
3832 &srpt_tpg_enable.attr,
3851 return ERR_PTR(res);
3880 sport = srpt_lookup_port(name);
3881 pr_debug(
"make_tport(%s)\n", name);
3889 return ERR_PTR(ret);
3896 static void srpt_drop_tport(
struct se_wwn *wwn)
3900 pr_debug(
"drop_tport(%s\n", config_item_name(&sport->
port_wwn.wwn_group.cg_item));
3912 &srpt_wwn_version.attr,
3917 .get_fabric_name = srpt_get_fabric_name,
3918 .get_fabric_proto_ident = srpt_get_fabric_proto_ident,
3919 .tpg_get_wwn = srpt_get_fabric_wwn,
3920 .tpg_get_tag = srpt_get_tag,
3921 .tpg_get_default_depth = srpt_get_default_depth,
3922 .tpg_get_pr_transport_id = srpt_get_pr_transport_id,
3923 .tpg_get_pr_transport_id_len = srpt_get_pr_transport_id_len,
3924 .tpg_parse_pr_out_transport_id = srpt_parse_pr_out_transport_id,
3925 .tpg_check_demo_mode = srpt_check_false,
3926 .tpg_check_demo_mode_cache = srpt_check_true,
3927 .tpg_check_demo_mode_write_protect = srpt_check_true,
3928 .tpg_check_prod_mode_write_protect = srpt_check_false,
3929 .tpg_alloc_fabric_acl = srpt_alloc_fabric_acl,
3930 .tpg_release_fabric_acl = srpt_release_fabric_acl,
3931 .tpg_get_inst_index = srpt_tpg_get_inst_index,
3932 .release_cmd = srpt_release_cmd,
3933 .check_stop_free = srpt_check_stop_free,
3934 .shutdown_session = srpt_shutdown_session,
3935 .close_session = srpt_close_session,
3936 .sess_get_index = srpt_sess_get_index,
3937 .sess_get_initiator_sid =
NULL,
3938 .write_pending = srpt_write_pending,
3939 .write_pending_status = srpt_write_pending_status,
3940 .set_default_node_attributes = srpt_set_default_node_attrs,
3941 .get_task_tag = srpt_get_task_tag,
3942 .get_cmd_state = srpt_get_tcm_cmd_state,
3943 .queue_data_in = srpt_queue_response,
3944 .queue_status = srpt_queue_status,
3945 .queue_tm_rsp = srpt_queue_response,
3950 .fabric_make_wwn = srpt_make_tport,
3951 .fabric_drop_wwn = srpt_drop_tport,
3952 .fabric_make_tpg = srpt_make_tpg,
3953 .fabric_drop_tpg = srpt_drop_tpg,
3954 .fabric_post_link =
NULL,
3955 .fabric_pre_unlink =
NULL,
3956 .fabric_make_np =
NULL,
3957 .fabric_drop_np =
NULL,
3958 .fabric_make_nodeacl = srpt_make_nodeacl,
3959 .fabric_drop_nodeacl = srpt_drop_nodeacl,
3970 static int __init srpt_init_module(
void)
3977 " srp_max_req_size -- must be at least %d.\n",
3985 " srpt_srq_size -- must be in the range [%d..%d].\n",
3991 if (IS_ERR(srpt_target)) {
3993 ret = PTR_ERR(srpt_target);
3997 srpt_target->
tf_ops = srpt_template;
4002 srpt_target->
tf_cit_tmpl.tfc_wwn_cit.ct_attrs = srpt_wwn_attrs;
4003 srpt_target->
tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = srpt_tpg_attrs;
4004 srpt_target->
tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = srpt_tpg_attrib_attrs;
4015 goto out_free_target;
4021 goto out_unregister_target;
4026 out_unregister_target:
4036 static void __exit srpt_cleanup_module(
void)