snic_fwint.h 14 KB

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