2 * Copyright (c) 2006 - 2009 Mellanox Technology Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #include <linux/version.h>
38 #include <linux/types.h>
39 #include <linux/list.h>
40 #include <linux/mutex.h>
42 #include <rdma/ib_verbs.h>
43 #include <rdma/ib_sa.h>
44 #include <rdma/ib_cm.h>
50 #include "ib_dm_mad.h"
53 * The prefix the ServiceName field of the ServiceName/ServiceID pair in the
54 * device management ServiceEntries attribute pair must start with, as specified
55 * in the SRP r16a document.
57 #define SRP_SERVICE_NAME_PREFIX "SRP.T10:"
61 * SRP IOControllerProfile attributes for SRP target ports that have
62 * not been defined in <scsi/srp.h>. Source: section B.7, table B.7
63 * in the T10 SRP r16a document.
65 SRP_PROTOCOL = 0x0108,
66 SRP_PROTOCOL_VERSION = 0x0001,
67 SRP_IO_SUBCLASS = 0x609e,
68 SRP_SEND_TO_IOC = 0x01,
69 SRP_SEND_FROM_IOC = 0x02,
70 SRP_RDMA_READ_FROM_IOC = 0x08,
71 SRP_RDMA_WRITE_FROM_IOC = 0x20,
73 /* See also table 24 in the T10 r16a document. */
74 SRP_TSK_MGMT_SUCCESS = 0x00,
75 SRP_TSK_MGMT_FUNC_NOT_SUPP = 0x04,
76 SRP_TSK_MGMT_FAILED = 0x05,
78 /* See also table 21 in the T10 r16a document. */
79 SRP_CMD_SIMPLE_Q = 0x0,
80 SRP_CMD_HEAD_OF_Q = 0x1,
81 SRP_CMD_ORDERED_Q = 0x2,
84 SRP_LOGIN_RSP_MULTICHAN_NO_CHAN = 0x0,
85 SRP_LOGIN_RSP_MULTICHAN_TERMINATED = 0x1,
86 SRP_LOGIN_RSP_MULTICHAN_MAINTAINED = 0x2,
88 SRPT_DEF_SG_TABLESIZE = 128,
89 SRPT_DEF_SG_PER_WQE = 16,
91 SRPT_SQ_SIZE = 128 * SRPT_DEF_SG_PER_WQE,
95 MAX_MESSAGE_SIZE = 996,
98 #define SRPT_OP_RECV (1 << 31)
108 /* Command states. */
109 enum srpt_command_state {
110 /* New command arrived and is being processed. */
112 /* Processing a write or bidir command and waiting for data arrival. */
113 SRPT_STATE_NEED_DATA = 1,
114 /* Data for the write or bidir command arrived and is being processed.*/
115 SRPT_STATE_DATA_IN = 2,
116 /* Command processing finished. */
117 SRPT_STATE_PROCESSED = 3,
118 /* Command processing has been aborted. */
119 SRPT_STATE_ABORTED = 4,
122 /* SRPT I/O context: SRPT-private data associated with a struct scst_cmd. */
127 struct rdma_iu *rdma_ius;
128 struct srp_direct_buf *rbufs;
129 struct srp_direct_buf single_rbuf;
130 /* Node for insertion in srpt_rdma_ch::cmd_wait_list. */
131 struct list_head wait_list;
132 /* Node for insertion in srpt_rdma_ch::active_scmnd_list. */
133 struct list_head scmnd_list;
138 enum ib_wc_opcode op;
139 /* Node for insertion in the srpt_thread::thread_ioctx_list. */
140 struct list_head comp_list;
141 struct srpt_rdma_ch *ch;
142 struct scst_cmd *scmnd;
144 atomic_t state; /* enum srpt_command_state */
147 /* Additional context information for SCST management commands. */
148 struct srpt_mgmt_ioctx {
149 struct srpt_ioctx *ioctx;
150 struct srpt_rdma_ch *ch;
156 RDMA_CHANNEL_CONNECTING,
158 RDMA_CHANNEL_DISCONNECTING
161 struct srpt_rdma_ch {
162 struct ib_cm_id *cm_id;
165 struct srpt_port *sport;
166 /* 128-bit initiator port identifier copied from SRP_LOGIN_REQ. */
168 /* 128-bit target port identifier copied from SRP_LOGIN_REQ. */
170 atomic_t req_lim_delta;
172 enum rdma_ch_state state;
173 /* Node for insertion in the srpt_device::rch_list list. */
174 struct list_head list;
175 /* List of waiting SCST commands (containt struct srpt_ioctx elem's). */
176 struct list_head cmd_wait_list;
177 /* SCST commands being processed (contains struct srpt_ioctx elem's). */
178 struct list_head active_scmnd_list;
179 u32 active_scmnd_cnt;
181 struct scst_session *scst_sess;
186 struct srpt_device *sdev;
187 struct ib_mad_agent *mad_agent;
188 /* One-based port number. */
190 /* Cached values of the port's sm_lid, lid and gid. */
194 /* Work structure for refreshing the aforementioned cached values. */
195 struct work_struct work;
199 * Data stored by the ib_srpt kernel module per InfiniBand device
200 * (struct ib_device).
203 /* Backpointer to the struct ib_device managed by the IB core. */
204 struct ib_device *device;
205 /* Protection domain. */
207 /* L_Key (local key) with write access to all local memory. */
209 /* SRQ (shared receive queue). */
211 /* Connection identifier. */
212 struct ib_cm_id *cm_id;
214 * Attributes of the InfiniBand device as obtained during the
215 * ib_client::add() callback.
217 struct ib_device_attr dev_attr;
218 struct srpt_ioctx *ioctx_ring[SRPT_SRQ_SIZE];
220 * List node for insertion in the srpt_rdma_ch::list list.
221 * This list is protected by srpt_device::spinlock.
223 struct list_head rch_list;
225 struct srpt_port port[2];
226 struct ib_event_handler event_handler;
227 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
228 /* per-port srpt-<portname> device instance. */
229 struct class_device class_dev;
233 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
237 struct scst_tgt *scst_tgt;
240 /* sense code/qualifier pairs */
243 LUN_NOT_READY = 0x04,
245 INTERNAL_TARGET_FAILURE = 0x44
254 u8 cmd_info_bytes[4];
256 u8 addl_sense_code_qual;
262 #endif /* IB_SRPT_H */