1 /*******************************************************************************
2 * IBM Virtual SCSI Target Driver
3 * Copyright (C) 2003-2005 Dave Boutcher (boutcher@us.ibm.com) IBM Corp.
4 * Santiago Leon (santil@us.ibm.com) IBM Corp.
5 * Linda Xie (lxie@us.ibm.com) IBM Corp.
7 * Copyright (C) 2005-2011 FUJITA Tomonori <tomof@acm.org>
8 * Copyright (C) 2010 Nicholas A. Bellinger <nab@kernel.org>
9 * Copyright (C) 2016 Bryant G. Ly <bryantly@linux.vnet.ibm.com> IBM Corp.
11 * Authors: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
12 * Authors: Michael Cyr <mikecyr@linux.vnet.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 ****************************************************************************/
26 #ifndef __H_IBMVSCSI_TGT
27 #define __H_IBMVSCSI_TGT
31 #define SYS_ID_NAME_LEN 64
32 #define PARTITION_NAMELEN 96
33 #define IBMVSCSIS_NAMELEN 32
38 #define MAX_CMD_Q_PAGES 4
39 #define CRQ_PER_PAGE (PAGE_SIZE / sizeof(struct viosrp_crq))
40 /* in terms of number of elements */
41 #define DEFAULT_CMD_Q_SIZE CRQ_PER_PAGE
42 #define MAX_CMD_Q_SIZE (DEFAULT_CMD_Q_SIZE * MAX_CMD_Q_PAGES)
44 #define SRP_VIOLATION 0x102 /* general error code */
47 * SRP buffer formats defined as of 16.a supported by this driver.
49 #define SUPPORTED_FORMATS ((SRP_DATA_DESC_DIRECT << 1) | \
50 (SRP_DATA_DESC_INDIRECT << 1))
52 #define SCSI_LUN_ADDR_METHOD_FLAT 1
55 u32 liobn; /* Unique per vdevice */
56 u64 tce_base; /* Physical location of the TCE table */
57 u64 tce_size; /* Size of the TCE table in bytes */
61 u64 unit_id; /* 64 bit will force alignment */
62 #define NUM_DMA_WINDOWS 2
65 struct dma_window window[NUM_DMA_WINDOWS];
67 /* root node property "ibm,partition-no" */
69 char partition_name[PARTITION_NAMELEN];
72 #define MAX_NUM_PORTS 1
73 #define MAX_H_COPY_RDMA (128 * 1024)
78 #define ADAPT_SUCCESS 0L
79 /* choose error codes that do not conflict with PHYP */
88 #define SRP_VERSION "16.a"
90 /* root node property ibm,partition-name */
91 char partition_name[PARTITION_NAMELEN];
92 /* root node property ibm,partition-no */
100 * Changing this constant changes the number of seconds to wait before
101 * considering the client will never service its queue again.
103 #define SECONDS_TO_CONSIDER_FAILED 30
105 * These constants set the polling period used to determine if the client
106 * has freed at least one element in the response queue.
108 #define WAIT_SECONDS 1
109 #define WAIT_NANO_SECONDS 5000
110 #define MAX_TIMER_POPS ((1000000 / WAIT_NANO_SECONDS) * \
111 SECONDS_TO_CONSIDER_FAILED)
113 * general purpose timer control block
114 * which can be used for multiple functions
117 struct hrtimer timer;
119 * how long has it been since the client
120 * serviced the queue. The variable is incrmented
121 * in the service_wait_q routine and cleared
125 /* the timer is started */
131 struct viosrp_crq *base_addr;
132 dma_addr_t crq_token;
133 /* used to maintain index */
135 /* current element */
140 #define SCSOLNT_RESP_SHIFT 1
141 #define UCSOLNT_RESP_SHIFT 2
143 #define SCSOLNT BIT(SCSOLNT_RESP_SHIFT)
144 #define UCSOLNT BIT(UCSOLNT_RESP_SHIFT)
148 TASK_MANAGEMENT = 0x02,
149 /* MAD or addressed to port 0 */
158 /* tag is just to help client identify cmd, so don't translate be/le */
162 struct ibmvscsis_cmd {
163 struct list_head list;
164 /* Used for TCM Core operations */
165 struct se_cmd se_cmd;
166 struct iu_entry *iue;
168 struct work_struct work;
169 struct scsi_info *adapter;
170 /* Sense buffer that will be mapped into outgoing status */
171 unsigned char sense_buf[TRANSPORT_SENSE_BUFFER];
173 #define CMD_FAST_FAIL BIT(0)
178 struct ibmvscsis_nexus {
179 struct se_session *se_sess;
182 struct ibmvscsis_tport {
183 /* SCSI protocol the tport is providing */
185 /* ASCII formatted WWPN for SRP Target port */
186 char tport_name[IBMVSCSIS_NAMELEN];
187 /* Returned by ibmvscsis_make_tport() */
188 struct se_wwn tport_wwn;
189 /* Returned by ibmvscsis_make_tpg() */
190 struct se_portal_group se_tpg;
191 /* ibmvscsis port target portal group tag for TCM */
193 /* Pointer to TCM session for I_T Nexus */
194 struct ibmvscsis_nexus *ibmv_nexus;
200 struct list_head list;
203 /* commands waiting for space on repsonse queue */
204 struct list_head waiting_rsp;
205 #define NO_QUEUE 0x00
206 #define WAIT_ENABLED 0X01
207 #define WAIT_CONNECTION 0x04
208 /* have established a connection */
209 #define CONNECTED 0x08
210 /* at least one port is processing SRP IU */
211 #define SRP_PROCESSING 0x10
212 /* remove request received */
213 #define UNCONFIGURING 0x20
214 /* disconnect by letting adapter go idle, no error */
215 #define WAIT_IDLE 0x40
216 /* disconnecting to clear an error */
217 #define ERR_DISCONNECT 0x80
218 /* disconnect to clear error state, then come back up */
219 #define ERR_DISCONNECT_RECONNECT 0x100
220 /* disconnected after clearing an error */
221 #define ERR_DISCONNECTED 0x200
222 /* A series of errors caused unexpected errors */
223 #define UNDEFINED 0x400
226 struct target_dds dds;
228 /* list of free commands */
229 struct list_head free_cmd;
230 /* command elements ready for scheduler */
231 struct list_head schedule_q;
232 /* commands sent to TCM */
233 struct list_head active_q;
235 /* ioba of map buffer */
237 /* allowable number of outstanding SRP requests */
241 /* outstanding transactions against credit limit */
244 /* allow only one outstanding mad request */
245 #define PROCESSING_MAD 0x00002
246 /* Waiting to go idle */
247 #define WAIT_FOR_IDLE 0x00004
248 /* H_REG_CRQ called */
249 #define CRQ_CLOSED 0x00010
250 /* detected that client has failed */
251 #define CLIENT_FAILED 0x00040
252 /* detected that transport event occurred */
253 #define TRANS_EVENT 0x00080
254 /* don't attempt to send anything to the client */
255 #define RESPONSE_Q_DOWN 0x00100
256 /* request made to schedule disconnect handler */
257 #define SCHEDULE_DISCONNECT 0x00400
258 /* disconnect handler is scheduled */
259 #define DISCONNECT_SCHEDULED 0x00800
260 /* remove function is sleeping */
261 #define CFG_SLEEPING 0x01000
264 spinlock_t intr_lock;
265 /* information needed to manage command queue */
266 struct cmd_queue cmd_q;
267 /* used in hcall to copy response back into srp buffer */
269 /* used in crq, to tag what iu the response is for */
272 /* control block for the response queue timer */
273 struct timer_cb rsp_q_timer;
274 /* keep last client to enable proper accounting */
275 struct client_info client_data;
276 /* what can this client do */
279 * The following two fields capture state and flag changes that
280 * can occur when the lock is given up. In the orginal design,
281 * the lock was held during calls into phyp;
282 * however, phyp did not meet PAPR architecture. This is
288 struct workqueue_struct *work_q;
289 struct completion wait_idle;
290 struct completion unconfig;
292 struct vio_dev *dma_dev;
293 struct srp_target target;
294 struct ibmvscsis_tport tport;
295 struct tasklet_struct work_task;
296 struct work_struct proc_work;
300 * Provide a constant that allows software to detect the adapter is
301 * disconnecting from the client from one of several states.
303 #define IS_DISCONNECTING (UNCONFIGURING | ERR_DISCONNECT_RECONNECT | \
307 * Provide a constant that can be used with interrupt handling that
308 * essentially lets the interrupt handler know that all requests should
311 #define DONT_PROCESS_STATE (IS_DISCONNECTING | UNDEFINED | \
312 ERR_DISCONNECTED | WAIT_IDLE)
315 * If any of these flag bits are set then do not allow the interrupt
316 * handler to schedule the off level handler.
318 #define BLOCK (DISCONNECT_SCHEDULED)
320 /* State and transition events that stop the interrupt handler */
321 #define TARGET_STOP(VSCSI) (long)(((VSCSI)->state & DONT_PROCESS_STATE) | \
322 ((VSCSI)->flags & BLOCK))
324 /* flag bit that are not reset during disconnect */
325 #define PRESERVE_FLAG_FIELDS 0
327 #define vio_iu(IUE) ((union viosrp_iu *)((IUE)->sbuf->buf))
329 #define READ_CMD(cdb) (((cdb)[0] & 0x1F) == 8)
330 #define WRITE_CMD(cdb) (((cdb)[0] & 0x1F) == 0xA)
332 #ifndef H_GET_PARTNER_INFO
333 #define H_GET_PARTNER_INFO 0x0000000000000008LL
336 #define h_copy_rdma(l, sa, sb, da, db) \
337 plpar_hcall_norets(H_COPY_RDMA, l, sa, sb, da, db)
338 #define h_vioctl(u, o, a, u1, u2, u3, u4) \
339 plpar_hcall_norets(H_VIOCTL, u, o, a, u1, u2)
340 #define h_reg_crq(ua, tok, sz) \
341 plpar_hcall_norets(H_REG_CRQ, ua, tok, sz)
342 #define h_free_crq(ua) \
343 plpar_hcall_norets(H_FREE_CRQ, ua)
344 #define h_send_crq(ua, d1, d2) \
345 plpar_hcall_norets(H_SEND_CRQ, ua, d1, d2)