1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2014 Cisco Systems, Inc. All rights reserved. */
7 #define SNIC_CDB_LEN 32 /* SCSI CDB size 32, can be used for 16 bytes */
15 * Initiator request types
17 SNIC_REQ_REPORT_TGTS
= 0x2, /* Report Targets */
18 SNIC_REQ_ICMND
, /* Initiator command for SCSI IO */
19 SNIC_REQ_ITMF
, /* Initiator command for Task Mgmt */
20 SNIC_REQ_HBA_RESET
, /* SNIC Reset */
21 SNIC_REQ_EXCH_VER
, /* Exchange Version Information */
22 SNIC_REQ_TGT_INFO
, /* Backend/Target Information */
28 SNIC_RSP_REPORT_TGTS_CMPL
= 0x12,/* Report Targets Completion */
29 SNIC_RSP_ICMND_CMPL
, /* SCSI IO Completion */
30 SNIC_RSP_ITMF_CMPL
, /* Task Management Completion */
31 SNIC_RSP_HBA_RESET_CMPL
, /* SNIC Reset Completion */
32 SNIC_RSP_EXCH_VER_CMPL
, /* Exchange Version Completion*/
33 SNIC_RSP_BOOT_LUNS_CMPL
,
38 SNIC_MSG_ACK
= 0x80, /* Ack: snic_notify_msg */
39 SNIC_MSG_ASYNC_EVNOTIFY
, /* Asynchronous Event Notification */
40 }; /* end of enum snic_io_type */
44 * Header status codes from firmware
47 SNIC_STAT_IO_SUCCESS
= 0, /* request was successful */
50 * If a request to the fw is rejected, the original request header
51 * will be returned with the status set to one of the following:
53 SNIC_STAT_INVALID_HDR
, /* header contains invalid data */
54 SNIC_STAT_OUT_OF_RES
, /* out of resources to complete request */
55 SNIC_STAT_INVALID_PARM
, /* some parameter in request is not valid */
56 SNIC_STAT_REQ_NOT_SUP
, /* req type is not supported */
57 SNIC_STAT_IO_NOT_FOUND
, /* requested IO was not found */
60 * Once a request is processed, the fw will usually return
61 * a cmpl message type. In cases where errors occurred,
62 * the header status would be filled in with one of the following:
64 SNIC_STAT_ABORTED
, /* req was aborted */
65 SNIC_STAT_TIMEOUT
, /* req was timed out */
66 SNIC_STAT_SGL_INVALID
, /* req was aborted due to sgl error */
67 SNIC_STAT_DATA_CNT_MISMATCH
, /*recv/sent more/less data than expec */
68 SNIC_STAT_FW_ERR
, /* req was terminated due to fw error */
69 SNIC_STAT_ITMF_REJECT
, /* itmf req was rejected by target */
70 SNIC_STAT_ITMF_FAIL
, /* itmf req was failed */
71 SNIC_STAT_ITMF_INCORRECT_LUN
, /* itmf req has incorrect LUN id*/
72 SNIC_STAT_CMND_REJECT
, /* req was invalid and rejected */
73 SNIC_STAT_DEV_OFFLINE
, /* req sent to offline device */
75 SNIC_STAT_SCSI_ERR
, /* SCSI error returned by Target. */
76 SNIC_STAT_NOT_READY
, /* sNIC Subsystem is not ready */
77 SNIC_STAT_FATAL_ERROR
, /* sNIC is in unrecoverable state */
78 }; /* end of enum snic_io_status */
81 * snic_io_hdr : host <--> firmware
83 * for any other message that will be queued to firmware should
84 * have the following request header
88 __le32 cmnd_id
; /* tag here */
89 ulong init_ctx
; /* initiator context */
90 u8 type
; /* request/response type */
91 u8 status
; /* header status entry */
92 u8 protocol
; /* Protocol specific, may needed for RoCE*/
98 /* auxillary funciton for encoding the snic_io_hdr */
100 snic_io_hdr_enc(struct snic_io_hdr
*hdr
, u8 typ
, u8 status
, u32 id
, u32 hid
,
101 u16 sg_cnt
, ulong ctx
)
104 hdr
->status
= status
;
106 hdr
->hid
= cpu_to_le32(hid
);
107 hdr
->cmnd_id
= cpu_to_le32(id
);
108 hdr
->sg_cnt
= cpu_to_le16(sg_cnt
);
113 /* auxillary funciton for decoding the snic_io_hdr */
115 snic_io_hdr_dec(struct snic_io_hdr
*hdr
, u8
*typ
, u8
*stat
, u32
*cmnd_id
,
116 u32
*hid
, ulong
*ctx
)
120 *hid
= le32_to_cpu(hdr
->hid
);
121 *cmnd_id
= le32_to_cpu(hdr
->cmnd_id
);
122 *ctx
= hdr
->init_ctx
;
126 * snic_host_info: host -> firmware
128 * Used for sending host information to firmware, and request fw version
130 struct snic_exch_ver_req
{
131 __le32 drvr_ver
; /* for debugging, when fw dump captured */
132 __le32 os_type
; /* for OS specific features */
137 * Bit 0-7 : OS information
138 * Bit 8-31: Feature/Capability Information
140 #define SNIC_OS_LINUX 0x1
141 #define SNIC_OS_WIN 0x2
142 #define SNIC_OS_ESX 0x3
147 * Bit 2: Dynamic Discovery of LUNs.
148 * Bit 3: Async event notifications on tgt online/offline events.
149 * Bit 4: IO timeout support in FW.
150 * Bit 5-31: Reserved.
152 #define SNIC_HBA_CAP_DDL 0x02 /* Supports Dynamic Discovery of LUNs */
153 #define SNIC_HBA_CAP_AEN 0x04 /* Supports Async Event Noitifcation */
154 #define SNIC_HBA_CAP_TMO 0x08 /* Supports IO timeout in FW */
157 * snic_exch_ver_rsp : firmware -> host
159 * Used by firmware to send response to version request
161 struct snic_exch_ver_rsp
{
164 __le32 max_concur_ios
; /* max concurrent ios */
165 __le32 max_sgs_per_cmd
; /* max sgls per IO */
166 __le32 max_io_sz
; /* max io size supported */
167 __le32 hba_cap
; /* hba capabilities */
168 __le32 max_tgts
; /* max tgts supported */
169 __le16 io_timeout
; /* FW extended timeout */
175 * snic_report_tgts : host -> firmware request
177 * Used by the host to request list of targets
179 struct snic_report_tgts
{
181 __le16 flags
; /* specific flags from fw */
183 __le64 sg_addr
; /* Points to SGL */
194 /* Report Target Response */
197 SNIC_TGT_DAS
, /* DAS Target */
198 SNIC_TGT_SAN
, /* SAN Target */
201 /* target id format */
203 __le32 tgt_id
; /* target id */
204 __le16 tgt_type
; /* tgt type */
205 __le16 vnic_id
; /* corresponding vnic id */
209 * snic_report_tgts_cmpl : firmware -> host response
211 * Used by firmware to send response to Report Targets request
213 struct snic_report_tgts_cmpl
{
214 __le32 tgt_cnt
; /* Number of Targets accessible */
223 * Bit 2: ESGL - sg/esg array contains extended sg
224 * ESGE - is a host buffer contains sg elements
225 * Bit 3-4: Task Attributes
227 * 01b - head of queue
229 * Bit 5-7: Priority - future use
233 #define SNIC_ICMND_WR 0x01 /* write command */
234 #define SNIC_ICMND_RD 0x02 /* read command */
235 #define SNIC_ICMND_ESGL 0x04 /* SGE/ESGE array contains valid data*/
238 * Priority/Task Attribute settings
240 #define SNIC_ICMND_TSK_SHIFT 2 /* task attr starts at bit 2 */
241 #define SNIC_ICMND_TSK_MASK(x) ((x>>SNIC_ICMND_TSK_SHIFT) & ~(0xffff))
242 #define SNIC_ICMND_TSK_SIMPLE 0 /* simple task attr */
243 #define SNIC_ICMND_TSK_HEAD_OF_QUEUE 1 /* head of qeuue task attr */
244 #define SNIC_ICMND_TSK_ORDERED 2 /* ordered task attr */
246 #define SNIC_ICMND_PRI_SHIFT 5 /* prio val starts at bit 5 */
249 * snic_icmnd : host-> firmware request
251 * used for sending out an initiator SCSI 16/32-byte command
254 __le16 sg_cnt
; /* Number of SG Elements */
255 __le16 flags
; /* flags */
256 __le32 sense_len
; /* Sense buffer length */
257 __le64 tgt_id
; /* Destination Target ID */
258 __le64 lun_id
; /* Destination LUN ID */
261 __le16 time_out
; /* ms time for Res allocations fw to handle io*/
262 __le32 data_len
; /* Total number of bytes to be transferred */
263 u8 cdb
[SNIC_CDB_LEN
];
264 __le64 sg_addr
; /* Points to SG List */
265 __le64 sense_addr
; /* Sense buffer address */
274 #define SNIC_ICMND_CMPL_UNDR_RUN 0x01 /* resid under and valid */
275 #define SNIC_ICMND_CMPL_OVER_RUN 0x02 /* resid over and valid */
278 * snic_icmnd_cmpl: firmware -> host response
280 * Used for sending the host a response to an icmnd (initiator command)
282 struct snic_icmnd_cmpl
{
283 u8 scsi_status
; /* value as per SAM */
285 __le16 sense_len
; /* Sense Length */
286 __le32 resid
; /* Residue : # bytes under or over run */
290 * snic_itmf: host->firmware request
292 * used for requesting the firmware to abort a request and/or send out
293 * a task management function
295 * the req_id field is valid in case of abort task and clear task
298 u8 tm_type
; /* SCSI Task Management request */
300 __le16 flags
; /* flags */
301 __le32 req_id
; /* Command id of snic req to be aborted */
302 __le64 tgt_id
; /* Target ID */
303 __le64 lun_id
; /* Destination LUN ID */
304 __le16 timeout
; /* in sec */
308 * Task Management Request
310 enum snic_itmf_tm_type
{
311 SNIC_ITMF_ABTS_TASK
= 0x01, /* Abort Task */
312 SNIC_ITMF_ABTS_TASK_SET
, /* Abort Task Set */
313 SNIC_ITMF_CLR_TASK
, /* Clear Task */
314 SNIC_ITMF_CLR_TASKSET
, /* Clear Task Set */
315 SNIC_ITMF_LUN_RESET
, /* Lun Reset */
316 SNIC_ITMF_ABTS_TASK_TERM
, /* Supported for SAN Targets */
320 * snic_itmf_cmpl: firmware -> host resposne
322 * used for sending the host a response for a itmf request
324 struct snic_itmf_cmpl
{
325 __le32 nterminated
; /* # IOs terminated as a result of tmf */
326 u8 flags
; /* flags */
332 * Bit 0 : 1 - Num terminated field valid
333 * Bit 1 - 7 : Reserved
335 #define SNIC_NUM_TERM_VALID 0x01 /* Number of IOs terminated */
338 * snic_hba_reset: host -> firmware request
340 * used for requesting firmware to reset snic
342 struct snic_hba_reset
{
343 __le16 flags
; /* flags */
348 * snic_hba_reset_cmpl: firmware -> host response
350 * Used by firmware to respond to the host's hba reset request
352 struct snic_hba_reset_cmpl
{
353 u8 flags
; /* flags : more info needs to be added*/
358 * snic_notify_msg: firmware -> host response
360 * Used by firmware to notify host of the last work queue entry received
362 struct snic_notify_msg
{
363 __le32 wqe_num
; /* wq entry number */
364 u8 flags
; /* flags, macros */
369 #define SNIC_EVDATA_LEN 24 /* in bytes */
370 /* snic_async_evnotify: firmware -> host notification
372 * Used by firmware to notify the host about configuration/state changes
374 struct snic_async_evnotify
{
376 u8 vnic
; /* vnic id */
378 __le32 ev_id
; /* Event ID */
379 u8 ev_data
[SNIC_EVDATA_LEN
]; /* Event Data */
383 /* async event flags */
385 SNIC_EV_TGT_OFFLINE
= 0x01, /* Target Offline, PL contains TGT ID */
386 SNIC_EV_TGT_ONLINE
, /* Target Online, PL contains TGT ID */
387 SNIC_EV_LUN_OFFLINE
, /* LUN Offline, PL contains LUN ID */
388 SNIC_EV_LUN_ONLINE
, /* LUN Online, PL contains LUN ID */
389 SNIC_EV_CONF_CHG
, /* Dev Config/Attr Change Event */
390 SNIC_EV_TGT_ADDED
, /* Target Added */
391 SNIC_EV_TGT_DELTD
, /* Target Del'd, PL contains TGT ID */
392 SNIC_EV_LUN_ADDED
, /* LUN Added */
393 SNIC_EV_LUN_DELTD
, /* LUN Del'd, PL cont. TGT & LUN ID */
395 SNIC_EV_DISC_CMPL
= 0x10, /* Discovery Completed Event */
399 #define SNIC_HOST_REQ_LEN 128 /*Exp length of host req, wq desc sz*/
400 /* Payload 88 bytes = 128 - 24 - 16 */
401 #define SNIC_HOST_REQ_PAYLOAD ((int)(SNIC_HOST_REQ_LEN - \
402 sizeof(struct snic_io_hdr) - \
403 (2 * sizeof(u64)) - sizeof(ulong)))
406 * snic_host_req: host -> firmware request
408 * Basic structure for all snic requests that are sent from the host to
409 * firmware. They are 128 bytes in size.
411 struct snic_host_req
{
412 u64 ctrl_data
[2]; /*16 bytes - Control Data */
413 struct snic_io_hdr hdr
;
416 * Entry specific space, last byte contains color
418 u8 buf
[SNIC_HOST_REQ_PAYLOAD
];
421 * Exchange firmware version
423 struct snic_exch_ver_req exch_ver
;
426 struct snic_report_tgts rpt_tgts
;
429 struct snic_icmnd icmnd
;
431 /* task management request */
432 struct snic_itmf itmf
;
435 struct snic_hba_reset reset
;
439 }; /* end of snic_host_req structure */
442 #define SNIC_FW_REQ_LEN 64 /* Expected length of fw req */
444 struct snic_io_hdr hdr
;
447 * Entry specific space, last byte contains color
449 u8 buf
[SNIC_FW_REQ_LEN
- sizeof(struct snic_io_hdr
)];
451 /* Exchange Version Response */
452 struct snic_exch_ver_rsp exch_ver_cmpl
;
454 /* Report Targets Response */
455 struct snic_report_tgts_cmpl rpt_tgts_cmpl
;
458 struct snic_icmnd_cmpl icmnd_cmpl
;
460 /* task management response */
461 struct snic_itmf_cmpl itmf_cmpl
;
463 /* hba reset response */
464 struct snic_hba_reset_cmpl reset_cmpl
;
467 struct snic_notify_msg ack
;
469 /* async notification event */
470 struct snic_async_evnotify async_ev
;
473 }; /* end of snic_fw_req structure */
476 * Auxillary macro to verify specific snic req/cmpl structures
477 * to ensure that it will be aligned to 64 bit, and not using
480 #define VERIFY_REQ_SZ(x)
481 #define VERIFY_CMPL_SZ(x)
484 * Access routines to encode and decode the color bit, which is the most
485 * significant bit of the structure.
488 snic_color_enc(struct snic_fw_req
*req
, u8 color
)
490 u8
*c
= ((u8
*) req
) + sizeof(struct snic_fw_req
) - 1;
499 snic_color_dec(struct snic_fw_req
*req
, u8
*color
)
501 u8
*c
= ((u8
*) req
) + sizeof(struct snic_fw_req
) - 1;
505 /* Make sure color bit is read from desc *before* other fields
506 * are read from desc. Hardware guarantees color bit is last
507 * bit (byte) written. Adding the rmb() prevents the compiler
508 * and/or CPU from reordering the reads which would potentially
509 * result in reading stale values.
513 #endif /* end of __SNIC_FWINT_H */