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 struct ibmvscsis_cmd *abort_cmd;
171 /* Sense buffer that will be mapped into outgoing status */
172 unsigned char sense_buf[TRANSPORT_SENSE_BUFFER];
174 #define CMD_FAST_FAIL BIT(0)
175 #define DELAY_SEND BIT(1)
180 struct ibmvscsis_nexus {
181 struct se_session *se_sess;
184 struct ibmvscsis_tport {
185 /* SCSI protocol the tport is providing */
187 /* ASCII formatted WWPN for SRP Target port */
188 char tport_name[IBMVSCSIS_NAMELEN];
189 /* Returned by ibmvscsis_make_tport() */
190 struct se_wwn tport_wwn;
191 /* Returned by ibmvscsis_make_tpg() */
192 struct se_portal_group se_tpg;
193 /* ibmvscsis port target portal group tag for TCM */
195 /* Pointer to TCM session for I_T Nexus */
196 struct ibmvscsis_nexus *ibmv_nexus;
202 struct list_head list;
205 /* commands waiting for space on repsonse queue */
206 struct list_head waiting_rsp;
207 #define NO_QUEUE 0x00
208 #define WAIT_ENABLED 0X01
209 #define WAIT_CONNECTION 0x04
210 /* have established a connection */
211 #define CONNECTED 0x08
212 /* at least one port is processing SRP IU */
213 #define SRP_PROCESSING 0x10
214 /* remove request received */
215 #define UNCONFIGURING 0x20
216 /* disconnect by letting adapter go idle, no error */
217 #define WAIT_IDLE 0x40
218 /* disconnecting to clear an error */
219 #define ERR_DISCONNECT 0x80
220 /* disconnect to clear error state, then come back up */
221 #define ERR_DISCONNECT_RECONNECT 0x100
222 /* disconnected after clearing an error */
223 #define ERR_DISCONNECTED 0x200
224 /* A series of errors caused unexpected errors */
225 #define UNDEFINED 0x400
228 struct target_dds dds;
230 /* list of free commands */
231 struct list_head free_cmd;
232 /* command elements ready for scheduler */
233 struct list_head schedule_q;
234 /* commands sent to TCM */
235 struct list_head active_q;
237 /* ioba of map buffer */
239 /* allowable number of outstanding SRP requests */
243 /* outstanding transactions against credit limit */
246 /* allow only one outstanding mad request */
247 #define PROCESSING_MAD 0x00002
248 /* Waiting to go idle */
249 #define WAIT_FOR_IDLE 0x00004
250 /* H_REG_CRQ called */
251 #define CRQ_CLOSED 0x00010
252 /* detected that client has failed */
253 #define CLIENT_FAILED 0x00040
254 /* detected that transport event occurred */
255 #define TRANS_EVENT 0x00080
256 /* don't attempt to send anything to the client */
257 #define RESPONSE_Q_DOWN 0x00100
258 /* request made to schedule disconnect handler */
259 #define SCHEDULE_DISCONNECT 0x00400
260 /* disconnect handler is scheduled */
261 #define DISCONNECT_SCHEDULED 0x00800
262 /* remove function is sleeping */
263 #define CFG_SLEEPING 0x01000
266 spinlock_t intr_lock;
267 /* information needed to manage command queue */
268 struct cmd_queue cmd_q;
269 /* used in hcall to copy response back into srp buffer */
271 /* used in crq, to tag what iu the response is for */
274 /* control block for the response queue timer */
275 struct timer_cb rsp_q_timer;
276 /* keep last client to enable proper accounting */
277 struct client_info client_data;
278 /* what can this client do */
281 * The following two fields capture state and flag changes that
282 * can occur when the lock is given up. In the orginal design,
283 * the lock was held during calls into phyp;
284 * however, phyp did not meet PAPR architecture. This is
290 struct workqueue_struct *work_q;
291 struct completion wait_idle;
292 struct completion unconfig;
294 struct vio_dev *dma_dev;
295 struct srp_target target;
296 struct ibmvscsis_tport tport;
297 struct tasklet_struct work_task;
298 struct work_struct proc_work;
302 * Provide a constant that allows software to detect the adapter is
303 * disconnecting from the client from one of several states.
305 #define IS_DISCONNECTING (UNCONFIGURING | ERR_DISCONNECT_RECONNECT | \
309 * Provide a constant that can be used with interrupt handling that
310 * essentially lets the interrupt handler know that all requests should
313 #define DONT_PROCESS_STATE (IS_DISCONNECTING | UNDEFINED | \
314 ERR_DISCONNECTED | WAIT_IDLE)
317 * If any of these flag bits are set then do not allow the interrupt
318 * handler to schedule the off level handler.
320 #define BLOCK (DISCONNECT_SCHEDULED)
322 /* State and transition events that stop the interrupt handler */
323 #define TARGET_STOP(VSCSI) (long)(((VSCSI)->state & DONT_PROCESS_STATE) | \
324 ((VSCSI)->flags & BLOCK))
326 /* flag bit that are not reset during disconnect */
327 #define PRESERVE_FLAG_FIELDS 0
329 #define vio_iu(IUE) ((union viosrp_iu *)((IUE)->sbuf->buf))
331 #define READ_CMD(cdb) (((cdb)[0] & 0x1F) == 8)
332 #define WRITE_CMD(cdb) (((cdb)[0] & 0x1F) == 0xA)
334 #ifndef H_GET_PARTNER_INFO
335 #define H_GET_PARTNER_INFO 0x0000000000000008LL
338 #define h_copy_rdma(l, sa, sb, da, db) \
339 plpar_hcall_norets(H_COPY_RDMA, l, sa, sb, da, db)
340 #define h_vioctl(u, o, a, u1, u2, u3, u4) \
341 plpar_hcall_norets(H_VIOCTL, u, o, a, u1, u2)
342 #define h_reg_crq(ua, tok, sz) \
343 plpar_hcall_norets(H_REG_CRQ, ua, tok, sz)
344 #define h_free_crq(ua) \
345 plpar_hcall_norets(H_FREE_CRQ, ua)
346 #define h_send_crq(ua, d1, d2) \
347 plpar_hcall_norets(H_SEND_CRQ, ua, d1, d2)