snic_fwint.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright 2014 Cisco Systems, Inc. All rights reserved. */
  3. #ifndef __SNIC_FWINT_H
  4. #define __SNIC_FWINT_H
  5. #define SNIC_CDB_LEN 32 /* SCSI CDB size 32, can be used for 16 bytes */
  6. #define LUN_ADDR_LEN 8
  7. /*
  8. * Command entry type
  9. */
  10. enum snic_io_type {
  11. /*
  12. * Initiator request types
  13. */
  14. SNIC_REQ_REPORT_TGTS = 0x2, /* Report Targets */
  15. SNIC_REQ_ICMND, /* Initiator command for SCSI IO */
  16. SNIC_REQ_ITMF, /* Initiator command for Task Mgmt */
  17. SNIC_REQ_HBA_RESET, /* SNIC Reset */
  18. SNIC_REQ_EXCH_VER, /* Exchange Version Information */
  19. SNIC_REQ_TGT_INFO, /* Backend/Target Information */
  20. SNIC_REQ_BOOT_LUNS,
  21. /*
  22. * Response type
  23. */
  24. SNIC_RSP_REPORT_TGTS_CMPL = 0x12,/* Report Targets Completion */
  25. SNIC_RSP_ICMND_CMPL, /* SCSI IO Completion */
  26. SNIC_RSP_ITMF_CMPL, /* Task Management Completion */
  27. SNIC_RSP_HBA_RESET_CMPL, /* SNIC Reset Completion */
  28. SNIC_RSP_EXCH_VER_CMPL, /* Exchange Version Completion*/
  29. SNIC_RSP_BOOT_LUNS_CMPL,
  30. /*
  31. * Misc Request types
  32. */
  33. SNIC_MSG_ACK = 0x80, /* Ack: snic_notify_msg */
  34. SNIC_MSG_ASYNC_EVNOTIFY, /* Asynchronous Event Notification */
  35. }; /* end of enum snic_io_type */
  36. /*
  37. * Header status codes from firmware
  38. */
  39. enum snic_io_status {
  40. SNIC_STAT_IO_SUCCESS = 0, /* request was successful */
  41. /*
  42. * If a request to the fw is rejected, the original request header
  43. * will be returned with the status set to one of the following:
  44. */
  45. SNIC_STAT_INVALID_HDR, /* header contains invalid data */
  46. SNIC_STAT_OUT_OF_RES, /* out of resources to complete request */
  47. SNIC_STAT_INVALID_PARM, /* some parameter in request is not valid */
  48. SNIC_STAT_REQ_NOT_SUP, /* req type is not supported */
  49. SNIC_STAT_IO_NOT_FOUND, /* requested IO was not found */
  50. /*
  51. * Once a request is processed, the fw will usually return
  52. * a cmpl message type. In cases where errors occurred,
  53. * the header status would be filled in with one of the following:
  54. */
  55. SNIC_STAT_ABORTED, /* req was aborted */
  56. SNIC_STAT_TIMEOUT, /* req was timed out */
  57. SNIC_STAT_SGL_INVALID, /* req was aborted due to sgl error */
  58. SNIC_STAT_DATA_CNT_MISMATCH, /*recv/sent more/less data than expec */
  59. SNIC_STAT_FW_ERR, /* req was terminated due to fw error */
  60. SNIC_STAT_ITMF_REJECT, /* itmf req was rejected by target */
  61. SNIC_STAT_ITMF_FAIL, /* itmf req was failed */
  62. SNIC_STAT_ITMF_INCORRECT_LUN, /* itmf req has incorrect LUN id*/
  63. SNIC_STAT_CMND_REJECT, /* req was invalid and rejected */
  64. SNIC_STAT_DEV_OFFLINE, /* req sent to offline device */
  65. SNIC_STAT_NO_BOOTLUN,
  66. SNIC_STAT_SCSI_ERR, /* SCSI error returned by Target. */
  67. SNIC_STAT_NOT_READY, /* sNIC Subsystem is not ready */
  68. SNIC_STAT_FATAL_ERROR, /* sNIC is in unrecoverable state */
  69. }; /* end of enum snic_io_status */
  70. /*
  71. * snic_io_hdr : host <--> firmware
  72. *
  73. * for any other message that will be queued to firmware should
  74. * have the following request header
  75. */
  76. struct snic_io_hdr {
  77. __le32 hid;
  78. __le32 cmnd_id; /* tag here */
  79. ulong init_ctx; /* initiator context */
  80. u8 type; /* request/response type */
  81. u8 status; /* header status entry */
  82. u8 protocol; /* Protocol specific, may needed for RoCE*/
  83. u8 flags;
  84. __le16 sg_cnt;
  85. u16 resvd;
  86. };
  87. /* auxillary funciton for encoding the snic_io_hdr */
  88. static inline void
  89. snic_io_hdr_enc(struct snic_io_hdr *hdr, u8 typ, u8 status, u32 id, u32 hid,
  90. u16 sg_cnt, ulong ctx)
  91. {
  92. hdr->type = typ;
  93. hdr->status = status;
  94. hdr->protocol = 0;
  95. hdr->hid = cpu_to_le32(hid);
  96. hdr->cmnd_id = cpu_to_le32(id);
  97. hdr->sg_cnt = cpu_to_le16(sg_cnt);
  98. hdr->init_ctx = ctx;
  99. hdr->flags = 0;
  100. }
  101. /* auxillary funciton for decoding the snic_io_hdr */
  102. static inline void
  103. snic_io_hdr_dec(struct snic_io_hdr *hdr, u8 *typ, u8 *stat, u32 *cmnd_id,
  104. u32 *hid, ulong *ctx)
  105. {
  106. *typ = hdr->type;
  107. *stat = hdr->status;
  108. *hid = le32_to_cpu(hdr->hid);
  109. *cmnd_id = le32_to_cpu(hdr->cmnd_id);
  110. *ctx = hdr->init_ctx;
  111. }
  112. /*
  113. * snic_host_info: host -> firmware
  114. *
  115. * Used for sending host information to firmware, and request fw version
  116. */
  117. struct snic_exch_ver_req {
  118. __le32 drvr_ver; /* for debugging, when fw dump captured */
  119. __le32 os_type; /* for OS specific features */
  120. };
  121. /*
  122. * os_type flags
  123. * Bit 0-7 : OS information
  124. * Bit 8-31: Feature/Capability Information
  125. */
  126. #define SNIC_OS_LINUX 0x1
  127. #define SNIC_OS_WIN 0x2
  128. #define SNIC_OS_ESX 0x3
  129. /*
  130. * HBA Capabilities
  131. * Bit 1: Reserved.
  132. * Bit 2: Dynamic Discovery of LUNs.
  133. * Bit 3: Async event notifications on tgt online/offline events.
  134. * Bit 4: IO timeout support in FW.
  135. * Bit 5-31: Reserved.
  136. */
  137. #define SNIC_HBA_CAP_DDL 0x02 /* Supports Dynamic Discovery of LUNs */
  138. #define SNIC_HBA_CAP_AEN 0x04 /* Supports Async Event Noitifcation */
  139. #define SNIC_HBA_CAP_TMO 0x08 /* Supports IO timeout in FW */
  140. /*
  141. * snic_exch_ver_rsp : firmware -> host
  142. *
  143. * Used by firmware to send response to version request
  144. */
  145. struct snic_exch_ver_rsp {
  146. __le32 version;
  147. __le32 hid;
  148. __le32 max_concur_ios; /* max concurrent ios */
  149. __le32 max_sgs_per_cmd; /* max sgls per IO */
  150. __le32 max_io_sz; /* max io size supported */
  151. __le32 hba_cap; /* hba capabilities */
  152. __le32 max_tgts; /* max tgts supported */
  153. __le16 io_timeout; /* FW extended timeout */
  154. u16 rsvd;
  155. };
  156. /*
  157. * snic_report_tgts : host -> firmware request
  158. *
  159. * Used by the host to request list of targets
  160. */
  161. struct snic_report_tgts {
  162. __le16 sg_cnt;
  163. __le16 flags; /* specific flags from fw */
  164. u8 _resvd[4];
  165. __le64 sg_addr; /* Points to SGL */
  166. __le64 sense_addr;
  167. };
  168. enum snic_type {
  169. SNIC_NONE = 0x0,
  170. SNIC_DAS,
  171. SNIC_SAN,
  172. };
  173. /* Report Target Response */
  174. enum snic_tgt_type {
  175. SNIC_TGT_NONE = 0x0,
  176. SNIC_TGT_DAS, /* DAS Target */
  177. SNIC_TGT_SAN, /* SAN Target */
  178. };
  179. /* target id format */
  180. struct snic_tgt_id {
  181. __le32 tgt_id; /* target id */
  182. __le16 tgt_type; /* tgt type */
  183. __le16 vnic_id; /* corresponding vnic id */
  184. };
  185. /*
  186. * snic_report_tgts_cmpl : firmware -> host response
  187. *
  188. * Used by firmware to send response to Report Targets request
  189. */
  190. struct snic_report_tgts_cmpl {
  191. __le32 tgt_cnt; /* Number of Targets accessible */
  192. u32 _resvd;
  193. };
  194. /*
  195. * Command flags
  196. *
  197. * Bit 0: Read flags
  198. * Bit 1: Write flag
  199. * Bit 2: ESGL - sg/esg array contains extended sg
  200. * ESGE - is a host buffer contains sg elements
  201. * Bit 3-4: Task Attributes
  202. * 00b - simple
  203. * 01b - head of queue
  204. * 10b - ordered
  205. * Bit 5-7: Priority - future use
  206. * Bit 8-15: Reserved
  207. */
  208. #define SNIC_ICMND_WR 0x01 /* write command */
  209. #define SNIC_ICMND_RD 0x02 /* read command */
  210. #define SNIC_ICMND_ESGL 0x04 /* SGE/ESGE array contains valid data*/
  211. /*
  212. * Priority/Task Attribute settings
  213. */
  214. #define SNIC_ICMND_TSK_SHIFT 2 /* task attr starts at bit 2 */
  215. #define SNIC_ICMND_TSK_MASK(x) ((x>>SNIC_ICMND_TSK_SHIFT) & ~(0xffff))
  216. #define SNIC_ICMND_TSK_SIMPLE 0 /* simple task attr */
  217. #define SNIC_ICMND_TSK_HEAD_OF_QUEUE 1 /* head of qeuue task attr */
  218. #define SNIC_ICMND_TSK_ORDERED 2 /* ordered task attr */
  219. #define SNIC_ICMND_PRI_SHIFT 5 /* prio val starts at bit 5 */
  220. /*
  221. * snic_icmnd : host-> firmware request
  222. *
  223. * used for sending out an initiator SCSI 16/32-byte command
  224. */
  225. struct snic_icmnd {
  226. __le16 sg_cnt; /* Number of SG Elements */
  227. __le16 flags; /* flags */
  228. __le32 sense_len; /* Sense buffer length */
  229. __le64 tgt_id; /* Destination Target ID */
  230. __le64 lun_id; /* Destination LUN ID */
  231. u8 cdb_len;
  232. u8 _resvd;
  233. __le16 time_out; /* ms time for Res allocations fw to handle io*/
  234. __le32 data_len; /* Total number of bytes to be transferred */
  235. u8 cdb[SNIC_CDB_LEN];
  236. __le64 sg_addr; /* Points to SG List */
  237. __le64 sense_addr; /* Sense buffer address */
  238. };
  239. /* Response flags */
  240. /* Bit 0: Under run
  241. * Bit 1: Over Run
  242. * Bit 2-7: Reserved
  243. */
  244. #define SNIC_ICMND_CMPL_UNDR_RUN 0x01 /* resid under and valid */
  245. #define SNIC_ICMND_CMPL_OVER_RUN 0x02 /* resid over and valid */
  246. /*
  247. * snic_icmnd_cmpl: firmware -> host response
  248. *
  249. * Used for sending the host a response to an icmnd (initiator command)
  250. */
  251. struct snic_icmnd_cmpl {
  252. u8 scsi_status; /* value as per SAM */
  253. u8 flags;
  254. __le16 sense_len; /* Sense Length */
  255. __le32 resid; /* Residue : # bytes under or over run */
  256. };
  257. /*
  258. * snic_itmf: host->firmware request
  259. *
  260. * used for requesting the firmware to abort a request and/or send out
  261. * a task management function
  262. *
  263. * the req_id field is valid in case of abort task and clear task
  264. */
  265. struct snic_itmf {
  266. u8 tm_type; /* SCSI Task Management request */
  267. u8 resvd;
  268. __le16 flags; /* flags */
  269. __le32 req_id; /* Command id of snic req to be aborted */
  270. __le64 tgt_id; /* Target ID */
  271. __le64 lun_id; /* Destination LUN ID */
  272. __le16 timeout; /* in sec */
  273. };
  274. /*
  275. * Task Management Request
  276. */
  277. enum snic_itmf_tm_type {
  278. SNIC_ITMF_ABTS_TASK = 0x01, /* Abort Task */
  279. SNIC_ITMF_ABTS_TASK_SET, /* Abort Task Set */
  280. SNIC_ITMF_CLR_TASK, /* Clear Task */
  281. SNIC_ITMF_CLR_TASKSET, /* Clear Task Set */
  282. SNIC_ITMF_LUN_RESET, /* Lun Reset */
  283. SNIC_ITMF_ABTS_TASK_TERM, /* Supported for SAN Targets */
  284. };
  285. /*
  286. * snic_itmf_cmpl: firmware -> host resposne
  287. *
  288. * used for sending the host a response for a itmf request
  289. */
  290. struct snic_itmf_cmpl {
  291. __le32 nterminated; /* # IOs terminated as a result of tmf */
  292. u8 flags; /* flags */
  293. u8 _resvd[3];
  294. };
  295. /*
  296. * itmfl_cmpl flags
  297. * Bit 0 : 1 - Num terminated field valid
  298. * Bit 1 - 7 : Reserved
  299. */
  300. #define SNIC_NUM_TERM_VALID 0x01 /* Number of IOs terminated */
  301. /*
  302. * snic_hba_reset: host -> firmware request
  303. *
  304. * used for requesting firmware to reset snic
  305. */
  306. struct snic_hba_reset {
  307. __le16 flags; /* flags */
  308. u8 _resvd[6];
  309. };
  310. /*
  311. * snic_hba_reset_cmpl: firmware -> host response
  312. *
  313. * Used by firmware to respond to the host's hba reset request
  314. */
  315. struct snic_hba_reset_cmpl {
  316. u8 flags; /* flags : more info needs to be added*/
  317. u8 _resvd[7];
  318. };
  319. /*
  320. * snic_notify_msg: firmware -> host response
  321. *
  322. * Used by firmware to notify host of the last work queue entry received
  323. */
  324. struct snic_notify_msg {
  325. __le32 wqe_num; /* wq entry number */
  326. u8 flags; /* flags, macros */
  327. u8 _resvd[4];
  328. };
  329. #define SNIC_EVDATA_LEN 24 /* in bytes */
  330. /* snic_async_evnotify: firmware -> host notification
  331. *
  332. * Used by firmware to notify the host about configuration/state changes
  333. */
  334. struct snic_async_evnotify {
  335. u8 FLS_EVENT_DESC;
  336. u8 vnic; /* vnic id */
  337. u8 _resvd[2];
  338. __le32 ev_id; /* Event ID */
  339. u8 ev_data[SNIC_EVDATA_LEN]; /* Event Data */
  340. u8 _resvd2[4];
  341. };
  342. /* async event flags */
  343. enum snic_ev_type {
  344. SNIC_EV_TGT_OFFLINE = 0x01, /* Target Offline, PL contains TGT ID */
  345. SNIC_EV_TGT_ONLINE, /* Target Online, PL contains TGT ID */
  346. SNIC_EV_LUN_OFFLINE, /* LUN Offline, PL contains LUN ID */
  347. SNIC_EV_LUN_ONLINE, /* LUN Online, PL contains LUN ID */
  348. SNIC_EV_CONF_CHG, /* Dev Config/Attr Change Event */
  349. SNIC_EV_TGT_ADDED, /* Target Added */
  350. SNIC_EV_TGT_DELTD, /* Target Del'd, PL contains TGT ID */
  351. SNIC_EV_LUN_ADDED, /* LUN Added */
  352. SNIC_EV_LUN_DELTD, /* LUN Del'd, PL cont. TGT & LUN ID */
  353. SNIC_EV_DISC_CMPL = 0x10, /* Discovery Completed Event */
  354. };
  355. #define SNIC_HOST_REQ_LEN 128 /*Exp length of host req, wq desc sz*/
  356. /* Payload 88 bytes = 128 - 24 - 16 */
  357. #define SNIC_HOST_REQ_PAYLOAD ((int)(SNIC_HOST_REQ_LEN - \
  358. sizeof(struct snic_io_hdr) - \
  359. (2 * sizeof(u64)) - sizeof(ulong)))
  360. /*
  361. * snic_host_req: host -> firmware request
  362. *
  363. * Basic structure for all snic requests that are sent from the host to
  364. * firmware. They are 128 bytes in size.
  365. */
  366. struct snic_host_req {
  367. u64 ctrl_data[2]; /*16 bytes - Control Data */
  368. struct snic_io_hdr hdr;
  369. union {
  370. /*
  371. * Entry specific space, last byte contains color
  372. */
  373. u8 buf[SNIC_HOST_REQ_PAYLOAD];
  374. /*
  375. * Exchange firmware version
  376. */
  377. struct snic_exch_ver_req exch_ver;
  378. /* report targets */
  379. struct snic_report_tgts rpt_tgts;
  380. /* io request */
  381. struct snic_icmnd icmnd;
  382. /* task management request */
  383. struct snic_itmf itmf;
  384. /* hba reset */
  385. struct snic_hba_reset reset;
  386. } u;
  387. ulong req_pa;
  388. }; /* end of snic_host_req structure */
  389. #define SNIC_FW_REQ_LEN 64 /* Expected length of fw req */
  390. struct snic_fw_req {
  391. struct snic_io_hdr hdr;
  392. union {
  393. /*
  394. * Entry specific space, last byte contains color
  395. */
  396. u8 buf[SNIC_FW_REQ_LEN - sizeof(struct snic_io_hdr)];
  397. /* Exchange Version Response */
  398. struct snic_exch_ver_rsp exch_ver_cmpl;
  399. /* Report Targets Response */
  400. struct snic_report_tgts_cmpl rpt_tgts_cmpl;
  401. /* scsi response */
  402. struct snic_icmnd_cmpl icmnd_cmpl;
  403. /* task management response */
  404. struct snic_itmf_cmpl itmf_cmpl;
  405. /* hba reset response */
  406. struct snic_hba_reset_cmpl reset_cmpl;
  407. /* notify message */
  408. struct snic_notify_msg ack;
  409. /* async notification event */
  410. struct snic_async_evnotify async_ev;
  411. } u;
  412. }; /* end of snic_fw_req structure */
  413. /*
  414. * Auxillary macro to verify specific snic req/cmpl structures
  415. * to ensure that it will be aligned to 64 bit, and not using
  416. * color bit field
  417. */
  418. #define VERIFY_REQ_SZ(x)
  419. #define VERIFY_CMPL_SZ(x)
  420. /*
  421. * Access routines to encode and decode the color bit, which is the most
  422. * significant bit of the structure.
  423. */
  424. static inline void
  425. snic_color_enc(struct snic_fw_req *req, u8 color)
  426. {
  427. u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;
  428. if (color)
  429. *c |= 0x80;
  430. else
  431. *c &= ~0x80;
  432. }
  433. static inline void
  434. snic_color_dec(struct snic_fw_req *req, u8 *color)
  435. {
  436. u8 *c = ((u8 *) req) + sizeof(struct snic_fw_req) - 1;
  437. *color = *c >> 7;
  438. /* Make sure color bit is read from desc *before* other fields
  439. * are read from desc. Hardware guarantees color bit is last
  440. * bit (byte) written. Adding the rmb() prevents the compiler
  441. * and/or CPU from reordering the reads which would potentially
  442. * result in reading stale values.
  443. */
  444. rmb();
  445. }
  446. #endif /* end of __SNIC_FWINT_H */