1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*******************************************************************************
3 * IBM Virtual SCSI Target Driver
4 * Copyright (C) 2003-2005 Dave Boutcher (boutcher@us.ibm.com) IBM Corp.
5 * Santiago Leon (santil@us.ibm.com) IBM Corp.
6 * Linda Xie (lxie@us.ibm.com) IBM Corp.
8 * Copyright (C) 2005-2011 FUJITA Tomonori <tomof@acm.org>
9 * Copyright (C) 2010 Nicholas A. Bellinger <nab@kernel.org>
10 * Copyright (C) 2016 Bryant G. Ly <bryantly@linux.vnet.ibm.com> IBM Corp.
12 * Authors: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
13 * Authors: Michael Cyr <mikecyr@linux.vnet.ibm.com>
15 ****************************************************************************/
17 #ifndef __H_IBMVSCSI_TGT
18 #define __H_IBMVSCSI_TGT
20 #include <linux/interrupt.h>
23 #define SYS_ID_NAME_LEN 64
24 #define PARTITION_NAMELEN 96
25 #define IBMVSCSIS_NAMELEN 32
30 #define MAX_CMD_Q_PAGES 4
31 #define CRQ_PER_PAGE (PAGE_SIZE / sizeof(struct viosrp_crq))
32 /* in terms of number of elements */
33 #define DEFAULT_CMD_Q_SIZE CRQ_PER_PAGE
34 #define MAX_CMD_Q_SIZE (DEFAULT_CMD_Q_SIZE * MAX_CMD_Q_PAGES)
36 #define SRP_VIOLATION 0x102 /* general error code */
39 * SRP buffer formats defined as of 16.a supported by this driver.
41 #define SUPPORTED_FORMATS ((SRP_DATA_DESC_DIRECT << 1) | \
42 (SRP_DATA_DESC_INDIRECT << 1))
44 #define SCSI_LUN_ADDR_METHOD_FLAT 1
47 u32 liobn
; /* Unique per vdevice */
48 u64 tce_base
; /* Physical location of the TCE table */
49 u64 tce_size
; /* Size of the TCE table in bytes */
53 u64 unit_id
; /* 64 bit will force alignment */
54 #define NUM_DMA_WINDOWS 2
57 struct dma_window window
[NUM_DMA_WINDOWS
];
59 /* root node property "ibm,partition-no" */
61 char partition_name
[PARTITION_NAMELEN
];
64 #define MAX_NUM_PORTS 1
65 #define MAX_H_COPY_RDMA (128 * 1024)
70 #define ADAPT_SUCCESS 0L
71 /* choose error codes that do not conflict with PHYP */
80 #define SRP_VERSION "16.a"
82 /* root node property ibm,partition-name */
83 char partition_name
[PARTITION_NAMELEN
];
84 /* root node property ibm,partition-no */
92 * Changing this constant changes the number of seconds to wait before
93 * considering the client will never service its queue again.
95 #define SECONDS_TO_CONSIDER_FAILED 30
97 * These constants set the polling period used to determine if the client
98 * has freed at least one element in the response queue.
100 #define WAIT_SECONDS 1
101 #define WAIT_NANO_SECONDS 5000
102 #define MAX_TIMER_POPS ((1000000 / WAIT_NANO_SECONDS) * \
103 SECONDS_TO_CONSIDER_FAILED)
105 * general purpose timer control block
106 * which can be used for multiple functions
109 struct hrtimer timer
;
111 * how long has it been since the client
112 * serviced the queue. The variable is incrmented
113 * in the service_wait_q routine and cleared
117 /* the timer is started */
123 struct viosrp_crq
*base_addr
;
124 dma_addr_t crq_token
;
125 /* used to maintain index */
127 /* current element */
132 #define SCSOLNT_RESP_SHIFT 1
133 #define UCSOLNT_RESP_SHIFT 2
135 #define SCSOLNT BIT(SCSOLNT_RESP_SHIFT)
136 #define UCSOLNT BIT(UCSOLNT_RESP_SHIFT)
140 TASK_MANAGEMENT
= 0x02,
141 /* MAD or addressed to port 0 */
150 /* tag is just to help client identify cmd, so don't translate be/le */
154 struct ibmvscsis_cmd
{
155 struct list_head list
;
156 /* Used for TCM Core operations */
157 struct se_cmd se_cmd
;
158 struct iu_entry
*iue
;
160 struct work_struct work
;
161 struct scsi_info
*adapter
;
162 struct ibmvscsis_cmd
*abort_cmd
;
163 /* Sense buffer that will be mapped into outgoing status */
164 unsigned char sense_buf
[TRANSPORT_SENSE_BUFFER
];
166 #define CMD_FAST_FAIL BIT(0)
167 #define DELAY_SEND BIT(1)
172 struct ibmvscsis_nexus
{
173 struct se_session
*se_sess
;
176 struct ibmvscsis_tport
{
177 /* SCSI protocol the tport is providing */
179 /* ASCII formatted WWPN for SRP Target port */
180 char tport_name
[IBMVSCSIS_NAMELEN
];
181 /* Returned by ibmvscsis_make_tport() */
182 struct se_wwn tport_wwn
;
183 /* Returned by ibmvscsis_make_tpg() */
184 struct se_portal_group se_tpg
;
185 /* ibmvscsis port target portal group tag for TCM */
187 /* Pointer to TCM session for I_T Nexus */
188 struct ibmvscsis_nexus
*ibmv_nexus
;
194 struct list_head list
;
197 /* commands waiting for space on repsonse queue */
198 struct list_head waiting_rsp
;
199 #define NO_QUEUE 0x00
200 #define WAIT_ENABLED 0X01
201 #define WAIT_CONNECTION 0x04
202 /* have established a connection */
203 #define CONNECTED 0x08
204 /* at least one port is processing SRP IU */
205 #define SRP_PROCESSING 0x10
206 /* remove request received */
207 #define UNCONFIGURING 0x20
208 /* disconnect by letting adapter go idle, no error */
209 #define WAIT_IDLE 0x40
210 /* disconnecting to clear an error */
211 #define ERR_DISCONNECT 0x80
212 /* disconnect to clear error state, then come back up */
213 #define ERR_DISCONNECT_RECONNECT 0x100
214 /* disconnected after clearing an error */
215 #define ERR_DISCONNECTED 0x200
216 /* A series of errors caused unexpected errors */
217 #define UNDEFINED 0x400
220 struct target_dds dds
;
222 /* list of free commands */
223 struct list_head free_cmd
;
224 /* command elements ready for scheduler */
225 struct list_head schedule_q
;
226 /* commands sent to TCM */
227 struct list_head active_q
;
229 /* ioba of map buffer */
231 /* allowable number of outstanding SRP requests */
235 /* outstanding transactions against credit limit */
238 /* allow only one outstanding mad request */
239 #define PROCESSING_MAD 0x00002
240 /* Waiting to go idle */
241 #define WAIT_FOR_IDLE 0x00004
242 /* H_REG_CRQ called */
243 #define CRQ_CLOSED 0x00010
244 /* detected that client has failed */
245 #define CLIENT_FAILED 0x00040
246 /* detected that transport event occurred */
247 #define TRANS_EVENT 0x00080
248 /* don't attempt to send anything to the client */
249 #define RESPONSE_Q_DOWN 0x00100
250 /* request made to schedule disconnect handler */
251 #define SCHEDULE_DISCONNECT 0x00400
252 /* disconnect handler is scheduled */
253 #define DISCONNECT_SCHEDULED 0x00800
254 /* remove function is sleeping */
255 #define CFG_SLEEPING 0x01000
256 /* Register for Prepare for Suspend Transport Events */
257 #define PREP_FOR_SUSPEND_ENABLED 0x02000
258 /* Prepare for Suspend event sent */
259 #define PREP_FOR_SUSPEND_PENDING 0x04000
260 /* Resume from Suspend event sent */
261 #define PREP_FOR_SUSPEND_ABORTED 0x08000
262 /* Prepare for Suspend event overwrote another CRQ entry */
263 #define PREP_FOR_SUSPEND_OVERWRITE 0x10000
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 */
275 /* control block for the response queue timer */
276 struct timer_cb rsp_q_timer
;
277 /* keep last client to enable proper accounting */
278 struct client_info client_data
;
279 /* what can this client do */
282 * The following two fields capture state and flag changes that
283 * can occur when the lock is given up. In the orginal design,
284 * the lock was held during calls into phyp;
285 * however, phyp did not meet PAPR architecture. This is
291 struct workqueue_struct
*work_q
;
292 struct completion wait_idle
;
293 struct completion unconfig
;
295 struct vio_dev
*dma_dev
;
296 struct srp_target target
;
297 struct ibmvscsis_tport tport
;
298 struct tasklet_struct work_task
;
299 struct work_struct proc_work
;
303 * Provide a constant that allows software to detect the adapter is
304 * disconnecting from the client from one of several states.
306 #define IS_DISCONNECTING (UNCONFIGURING | ERR_DISCONNECT_RECONNECT | \
310 * Provide a constant that can be used with interrupt handling that
311 * essentially lets the interrupt handler know that all requests should
314 #define DONT_PROCESS_STATE (IS_DISCONNECTING | UNDEFINED | \
315 ERR_DISCONNECTED | WAIT_IDLE)
318 * If any of these flag bits are set then do not allow the interrupt
319 * handler to schedule the off level handler.
321 #define BLOCK (DISCONNECT_SCHEDULED)
323 /* State and transition events that stop the interrupt handler */
324 #define TARGET_STOP(VSCSI) (long)(((VSCSI)->state & DONT_PROCESS_STATE) | \
325 ((VSCSI)->flags & BLOCK))
327 #define PREP_FOR_SUSPEND_FLAGS (PREP_FOR_SUSPEND_ENABLED | \
328 PREP_FOR_SUSPEND_PENDING | \
329 PREP_FOR_SUSPEND_ABORTED | \
330 PREP_FOR_SUSPEND_OVERWRITE)
332 /* flag bit that are not reset during disconnect */
333 #define PRESERVE_FLAG_FIELDS (PREP_FOR_SUSPEND_FLAGS)
335 #define vio_iu(IUE) ((union viosrp_iu *)((IUE)->sbuf->buf))
337 #define READ_CMD(cdb) (((cdb)[0] & 0x1F) == 8)
338 #define WRITE_CMD(cdb) (((cdb)[0] & 0x1F) == 0xA)
340 #ifndef H_GET_PARTNER_INFO
341 #define H_GET_PARTNER_INFO 0x0000000000000008LL
343 #ifndef H_ENABLE_PREPARE_FOR_SUSPEND
344 #define H_ENABLE_PREPARE_FOR_SUSPEND 0x000000000000001DLL
346 #ifndef H_READY_FOR_SUSPEND
347 #define H_READY_FOR_SUSPEND 0x000000000000001ELL
351 #define h_copy_rdma(l, sa, sb, da, db) \
352 plpar_hcall_norets(H_COPY_RDMA, l, sa, sb, da, db)
353 #define h_vioctl(u, o, a, u1, u2, u3, u4) \
354 plpar_hcall_norets(H_VIOCTL, u, o, a, u1, u2)
355 #define h_reg_crq(ua, tok, sz) \
356 plpar_hcall_norets(H_REG_CRQ, ua, tok, sz)
357 #define h_free_crq(ua) \
358 plpar_hcall_norets(H_FREE_CRQ, ua)
359 #define h_send_crq(ua, d1, d2) \
360 plpar_hcall_norets(H_SEND_CRQ, ua, d1, d2)