bfi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*
  2. * Linux network driver for Brocade Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #ifndef __BFI_H__
  19. #define __BFI_H__
  20. #include "bfa_defs.h"
  21. #pragma pack(1)
  22. /**
  23. * BFI FW image type
  24. */
  25. #define BFI_FLASH_CHUNK_SZ 256 /*!< Flash chunk size */
  26. #define BFI_FLASH_CHUNK_SZ_WORDS (BFI_FLASH_CHUNK_SZ/sizeof(u32))
  27. /**
  28. * Msg header common to all msgs
  29. */
  30. struct bfi_mhdr {
  31. u8 msg_class; /*!< @ref enum bfi_mclass */
  32. u8 msg_id; /*!< msg opcode with in the class */
  33. union {
  34. struct {
  35. u8 qid;
  36. u8 fn_lpu; /*!< msg destination */
  37. } h2i;
  38. u16 i2htok; /*!< token in msgs to host */
  39. } mtag;
  40. };
  41. #define bfi_fn_lpu(__fn, __lpu) ((__fn) << 1 | (__lpu))
  42. #define bfi_mhdr_2_fn(_mh) ((_mh)->mtag.h2i.fn_lpu >> 1)
  43. #define bfi_mhdr_2_qid(_mh) ((_mh)->mtag.h2i.qid)
  44. #define bfi_h2i_set(_mh, _mc, _op, _fn_lpu) do { \
  45. (_mh).msg_class = (_mc); \
  46. (_mh).msg_id = (_op); \
  47. (_mh).mtag.h2i.fn_lpu = (_fn_lpu); \
  48. } while (0)
  49. #define bfi_i2h_set(_mh, _mc, _op, _i2htok) do { \
  50. (_mh).msg_class = (_mc); \
  51. (_mh).msg_id = (_op); \
  52. (_mh).mtag.i2htok = (_i2htok); \
  53. } while (0)
  54. /*
  55. * Message opcodes: 0-127 to firmware, 128-255 to host
  56. */
  57. #define BFI_I2H_OPCODE_BASE 128
  58. #define BFA_I2HM(_x) ((_x) + BFI_I2H_OPCODE_BASE)
  59. /**
  60. ****************************************************************************
  61. *
  62. * Scatter Gather Element and Page definition
  63. *
  64. ****************************************************************************
  65. */
  66. #define BFI_SGE_INLINE 1
  67. #define BFI_SGE_INLINE_MAX (BFI_SGE_INLINE + 1)
  68. /**
  69. * SG Flags
  70. */
  71. enum {
  72. BFI_SGE_DATA = 0, /*!< data address, not last */
  73. BFI_SGE_DATA_CPL = 1, /*!< data addr, last in current page */
  74. BFI_SGE_DATA_LAST = 3, /*!< data address, last */
  75. BFI_SGE_LINK = 2, /*!< link address */
  76. BFI_SGE_PGDLEN = 2, /*!< cumulative data length for page */
  77. };
  78. /**
  79. * DMA addresses
  80. */
  81. union bfi_addr_u {
  82. struct {
  83. u32 addr_lo;
  84. u32 addr_hi;
  85. } a32;
  86. };
  87. /**
  88. * Scatter Gather Element
  89. */
  90. struct bfi_sge {
  91. #ifdef __BIGENDIAN
  92. u32 flags:2,
  93. rsvd:2,
  94. sg_len:28;
  95. #else
  96. u32 sg_len:28,
  97. rsvd:2,
  98. flags:2;
  99. #endif
  100. union bfi_addr_u sga;
  101. };
  102. /**
  103. * Scatter Gather Page
  104. */
  105. #define BFI_SGPG_DATA_SGES 7
  106. #define BFI_SGPG_SGES_MAX (BFI_SGPG_DATA_SGES + 1)
  107. #define BFI_SGPG_RSVD_WD_LEN 8
  108. struct bfi_sgpg {
  109. struct bfi_sge sges[BFI_SGPG_SGES_MAX];
  110. u32 rsvd[BFI_SGPG_RSVD_WD_LEN];
  111. };
  112. /*
  113. * Large Message structure - 128 Bytes size Msgs
  114. */
  115. #define BFI_LMSG_SZ 128
  116. #define BFI_LMSG_PL_WSZ \
  117. ((BFI_LMSG_SZ - sizeof(struct bfi_mhdr)) / 4)
  118. struct bfi_msg {
  119. struct bfi_mhdr mhdr;
  120. u32 pl[BFI_LMSG_PL_WSZ];
  121. };
  122. /**
  123. * Mailbox message structure
  124. */
  125. #define BFI_MBMSG_SZ 7
  126. struct bfi_mbmsg {
  127. struct bfi_mhdr mh;
  128. u32 pl[BFI_MBMSG_SZ];
  129. };
  130. /**
  131. * Supported PCI function class codes (personality)
  132. */
  133. enum bfi_pcifn_class {
  134. BFI_PCIFN_CLASS_FC = 0x0c04,
  135. BFI_PCIFN_CLASS_ETH = 0x0200,
  136. };
  137. /**
  138. * Message Classes
  139. */
  140. enum bfi_mclass {
  141. BFI_MC_IOC = 1, /*!< IO Controller (IOC) */
  142. BFI_MC_DIAG = 2, /*!< Diagnostic Msgs */
  143. BFI_MC_FLASH = 3, /*!< Flash message class */
  144. BFI_MC_CEE = 4, /*!< CEE */
  145. BFI_MC_FCPORT = 5, /*!< FC port */
  146. BFI_MC_IOCFC = 6, /*!< FC - IO Controller (IOC) */
  147. BFI_MC_LL = 7, /*!< Link Layer */
  148. BFI_MC_UF = 8, /*!< Unsolicited frame receive */
  149. BFI_MC_FCXP = 9, /*!< FC Transport */
  150. BFI_MC_LPS = 10, /*!< lport fc login services */
  151. BFI_MC_RPORT = 11, /*!< Remote port */
  152. BFI_MC_ITNIM = 12, /*!< I-T nexus (Initiator mode) */
  153. BFI_MC_IOIM_READ = 13, /*!< read IO (Initiator mode) */
  154. BFI_MC_IOIM_WRITE = 14, /*!< write IO (Initiator mode) */
  155. BFI_MC_IOIM_IO = 15, /*!< IO (Initiator mode) */
  156. BFI_MC_IOIM = 16, /*!< IO (Initiator mode) */
  157. BFI_MC_IOIM_IOCOM = 17, /*!< good IO completion */
  158. BFI_MC_TSKIM = 18, /*!< Initiator Task management */
  159. BFI_MC_SBOOT = 19, /*!< SAN boot services */
  160. BFI_MC_IPFC = 20, /*!< IP over FC Msgs */
  161. BFI_MC_PORT = 21, /*!< Physical port */
  162. BFI_MC_SFP = 22, /*!< SFP module */
  163. BFI_MC_MSGQ = 23, /*!< MSGQ */
  164. BFI_MC_ENET = 24, /*!< ENET commands/responses */
  165. BFI_MC_MAX = 32
  166. };
  167. #define BFI_IOC_MAX_CQS 4
  168. #define BFI_IOC_MAX_CQS_ASIC 8
  169. #define BFI_IOC_MSGLEN_MAX 32 /* 32 bytes */
  170. #define BFI_FWBOOT_ENV_OS 0
  171. #define BFI_BOOT_MEMTEST_RES_ADDR 0x900
  172. #define BFI_BOOT_MEMTEST_RES_SIG 0xA0A1A2A3
  173. /**
  174. *----------------------------------------------------------------------
  175. * IOC
  176. *----------------------------------------------------------------------
  177. */
  178. /**
  179. * Different asic generations
  180. */
  181. enum bfi_asic_gen {
  182. BFI_ASIC_GEN_CB = 1,
  183. BFI_ASIC_GEN_CT = 2,
  184. };
  185. enum bfi_asic_mode {
  186. BFI_ASIC_MODE_FC = 1, /* FC upto 8G speed */
  187. BFI_ASIC_MODE_FC16 = 2, /* FC upto 16G speed */
  188. BFI_ASIC_MODE_ETH = 3, /* Ethernet ports */
  189. BFI_ASIC_MODE_COMBO = 4, /* FC 16G and Ethernet 10G port */
  190. };
  191. enum bfi_ioc_h2i_msgs {
  192. BFI_IOC_H2I_ENABLE_REQ = 1,
  193. BFI_IOC_H2I_DISABLE_REQ = 2,
  194. BFI_IOC_H2I_GETATTR_REQ = 3,
  195. BFI_IOC_H2I_DBG_SYNC = 4,
  196. BFI_IOC_H2I_DBG_DUMP = 5,
  197. };
  198. enum bfi_ioc_i2h_msgs {
  199. BFI_IOC_I2H_ENABLE_REPLY = BFA_I2HM(1),
  200. BFI_IOC_I2H_DISABLE_REPLY = BFA_I2HM(2),
  201. BFI_IOC_I2H_GETATTR_REPLY = BFA_I2HM(3),
  202. BFI_IOC_I2H_HBEAT = BFA_I2HM(4),
  203. };
  204. /**
  205. * BFI_IOC_H2I_GETATTR_REQ message
  206. */
  207. struct bfi_ioc_getattr_req {
  208. struct bfi_mhdr mh;
  209. union bfi_addr_u attr_addr;
  210. };
  211. struct bfi_ioc_attr {
  212. u64 mfg_pwwn; /*!< Mfg port wwn */
  213. u64 mfg_nwwn; /*!< Mfg node wwn */
  214. mac_t mfg_mac; /*!< Mfg mac */
  215. u8 port_mode; /* enum bfi_port_mode */
  216. u8 rsvd_a;
  217. u64 pwwn;
  218. u64 nwwn;
  219. mac_t mac; /*!< PBC or Mfg mac */
  220. u16 rsvd_b;
  221. mac_t fcoe_mac;
  222. u16 rsvd_c;
  223. char brcd_serialnum[STRSZ(BFA_MFG_SERIALNUM_SIZE)];
  224. u8 pcie_gen;
  225. u8 pcie_lanes_orig;
  226. u8 pcie_lanes;
  227. u8 rx_bbcredit; /*!< receive buffer credits */
  228. u32 adapter_prop; /*!< adapter properties */
  229. u16 maxfrsize; /*!< max receive frame size */
  230. char asic_rev;
  231. u8 rsvd_d;
  232. char fw_version[BFA_VERSION_LEN];
  233. char optrom_version[BFA_VERSION_LEN];
  234. struct bfa_mfg_vpd vpd;
  235. u32 card_type; /*!< card type */
  236. };
  237. /**
  238. * BFI_IOC_I2H_GETATTR_REPLY message
  239. */
  240. struct bfi_ioc_getattr_reply {
  241. struct bfi_mhdr mh; /*!< Common msg header */
  242. u8 status; /*!< cfg reply status */
  243. u8 rsvd[3];
  244. };
  245. /**
  246. * Firmware memory page offsets
  247. */
  248. #define BFI_IOC_SMEM_PG0_CB (0x40)
  249. #define BFI_IOC_SMEM_PG0_CT (0x180)
  250. /**
  251. * Firmware statistic offset
  252. */
  253. #define BFI_IOC_FWSTATS_OFF (0x6B40)
  254. #define BFI_IOC_FWSTATS_SZ (4096)
  255. /**
  256. * Firmware trace offset
  257. */
  258. #define BFI_IOC_TRC_OFF (0x4b00)
  259. #define BFI_IOC_TRC_ENTS 256
  260. #define BFI_IOC_FW_SIGNATURE (0xbfadbfad)
  261. #define BFI_IOC_MD5SUM_SZ 4
  262. struct bfi_ioc_image_hdr {
  263. u32 signature; /*!< constant signature */
  264. u8 asic_gen; /*!< asic generation */
  265. u8 asic_mode;
  266. u8 port0_mode; /*!< device mode for port 0 */
  267. u8 port1_mode; /*!< device mode for port 1 */
  268. u32 exec; /*!< exec vector */
  269. u32 bootenv; /*!< firmware boot env */
  270. u32 rsvd_b[4];
  271. u32 md5sum[BFI_IOC_MD5SUM_SZ];
  272. };
  273. #define BFI_FWBOOT_DEVMODE_OFF 4
  274. #define BFI_FWBOOT_TYPE_OFF 8
  275. #define BFI_FWBOOT_ENV_OFF 12
  276. #define BFI_FWBOOT_DEVMODE(__asic_gen, __asic_mode, __p0_mode, __p1_mode) \
  277. (((u32)(__asic_gen)) << 24 | \
  278. ((u32)(__asic_mode)) << 16 | \
  279. ((u32)(__p0_mode)) << 8 | \
  280. ((u32)(__p1_mode)))
  281. enum bfi_fwboot_type {
  282. BFI_FWBOOT_TYPE_NORMAL = 0,
  283. BFI_FWBOOT_TYPE_FLASH = 1,
  284. BFI_FWBOOT_TYPE_MEMTEST = 2,
  285. };
  286. enum bfi_port_mode {
  287. BFI_PORT_MODE_FC = 1,
  288. BFI_PORT_MODE_ETH = 2,
  289. };
  290. /**
  291. * BFI_IOC_I2H_READY_EVENT message
  292. */
  293. struct bfi_ioc_hbeat {
  294. struct bfi_mhdr mh; /*!< common msg header */
  295. u32 hb_count; /*!< current heart beat count */
  296. };
  297. /**
  298. * IOC hardware/firmware state
  299. */
  300. enum bfi_ioc_state {
  301. BFI_IOC_UNINIT = 0, /*!< not initialized */
  302. BFI_IOC_INITING = 1, /*!< h/w is being initialized */
  303. BFI_IOC_HWINIT = 2, /*!< h/w is initialized */
  304. BFI_IOC_CFG = 3, /*!< IOC configuration in progress */
  305. BFI_IOC_OP = 4, /*!< IOC is operational */
  306. BFI_IOC_DISABLING = 5, /*!< IOC is being disabled */
  307. BFI_IOC_DISABLED = 6, /*!< IOC is disabled */
  308. BFI_IOC_CFG_DISABLED = 7, /*!< IOC is being disabled;transient */
  309. BFI_IOC_FAIL = 8, /*!< IOC heart-beat failure */
  310. BFI_IOC_MEMTEST = 9, /*!< IOC is doing memtest */
  311. };
  312. #define BFI_IOC_ENDIAN_SIG 0x12345678
  313. enum {
  314. BFI_ADAPTER_TYPE_FC = 0x01, /*!< FC adapters */
  315. BFI_ADAPTER_TYPE_MK = 0x0f0000, /*!< adapter type mask */
  316. BFI_ADAPTER_TYPE_SH = 16, /*!< adapter type shift */
  317. BFI_ADAPTER_NPORTS_MK = 0xff00, /*!< number of ports mask */
  318. BFI_ADAPTER_NPORTS_SH = 8, /*!< number of ports shift */
  319. BFI_ADAPTER_SPEED_MK = 0xff, /*!< adapter speed mask */
  320. BFI_ADAPTER_SPEED_SH = 0, /*!< adapter speed shift */
  321. BFI_ADAPTER_PROTO = 0x100000, /*!< prototype adapaters */
  322. BFI_ADAPTER_TTV = 0x200000, /*!< TTV debug capable */
  323. BFI_ADAPTER_UNSUPP = 0x400000, /*!< unknown adapter type */
  324. };
  325. #define BFI_ADAPTER_GETP(__prop, __adap_prop) \
  326. (((__adap_prop) & BFI_ADAPTER_ ## __prop ## _MK) >> \
  327. BFI_ADAPTER_ ## __prop ## _SH)
  328. #define BFI_ADAPTER_SETP(__prop, __val) \
  329. ((__val) << BFI_ADAPTER_ ## __prop ## _SH)
  330. #define BFI_ADAPTER_IS_PROTO(__adap_type) \
  331. ((__adap_type) & BFI_ADAPTER_PROTO)
  332. #define BFI_ADAPTER_IS_TTV(__adap_type) \
  333. ((__adap_type) & BFI_ADAPTER_TTV)
  334. #define BFI_ADAPTER_IS_UNSUPP(__adap_type) \
  335. ((__adap_type) & BFI_ADAPTER_UNSUPP)
  336. #define BFI_ADAPTER_IS_SPECIAL(__adap_type) \
  337. ((__adap_type) & (BFI_ADAPTER_TTV | BFI_ADAPTER_PROTO | \
  338. BFI_ADAPTER_UNSUPP))
  339. /**
  340. * BFI_IOC_H2I_ENABLE_REQ & BFI_IOC_H2I_DISABLE_REQ messages
  341. */
  342. struct bfi_ioc_ctrl_req {
  343. struct bfi_mhdr mh;
  344. u16 clscode;
  345. u16 rsvd;
  346. u32 tv_sec;
  347. };
  348. /**
  349. * BFI_IOC_I2H_ENABLE_REPLY & BFI_IOC_I2H_DISABLE_REPLY messages
  350. */
  351. struct bfi_ioc_ctrl_reply {
  352. struct bfi_mhdr mh; /*!< Common msg header */
  353. u8 status; /*!< enable/disable status */
  354. u8 port_mode; /*!< enum bfa_mode */
  355. u8 cap_bm; /*!< capability bit mask */
  356. u8 rsvd;
  357. };
  358. #define BFI_IOC_MSGSZ 8
  359. /**
  360. * H2I Messages
  361. */
  362. union bfi_ioc_h2i_msg_u {
  363. struct bfi_mhdr mh;
  364. struct bfi_ioc_ctrl_req enable_req;
  365. struct bfi_ioc_ctrl_req disable_req;
  366. struct bfi_ioc_getattr_req getattr_req;
  367. u32 mboxmsg[BFI_IOC_MSGSZ];
  368. };
  369. /**
  370. * I2H Messages
  371. */
  372. union bfi_ioc_i2h_msg_u {
  373. struct bfi_mhdr mh;
  374. struct bfi_ioc_ctrl_reply fw_event;
  375. u32 mboxmsg[BFI_IOC_MSGSZ];
  376. };
  377. /**
  378. *----------------------------------------------------------------------
  379. * MSGQ
  380. *----------------------------------------------------------------------
  381. */
  382. enum bfi_msgq_h2i_msgs {
  383. BFI_MSGQ_H2I_INIT_REQ = 1,
  384. BFI_MSGQ_H2I_DOORBELL_PI = 2,
  385. BFI_MSGQ_H2I_DOORBELL_CI = 3,
  386. BFI_MSGQ_H2I_CMDQ_COPY_RSP = 4,
  387. };
  388. enum bfi_msgq_i2h_msgs {
  389. BFI_MSGQ_I2H_INIT_RSP = BFA_I2HM(BFI_MSGQ_H2I_INIT_REQ),
  390. BFI_MSGQ_I2H_DOORBELL_PI = BFA_I2HM(BFI_MSGQ_H2I_DOORBELL_PI),
  391. BFI_MSGQ_I2H_DOORBELL_CI = BFA_I2HM(BFI_MSGQ_H2I_DOORBELL_CI),
  392. BFI_MSGQ_I2H_CMDQ_COPY_REQ = BFA_I2HM(BFI_MSGQ_H2I_CMDQ_COPY_RSP),
  393. };
  394. /* Messages(commands/responsed/AENS will have the following header */
  395. struct bfi_msgq_mhdr {
  396. u8 msg_class;
  397. u8 msg_id;
  398. u16 msg_token;
  399. u16 num_entries;
  400. u8 enet_id;
  401. u8 rsvd[1];
  402. };
  403. #define bfi_msgq_mhdr_set(_mh, _mc, _mid, _tok, _enet_id) do { \
  404. (_mh).msg_class = (_mc); \
  405. (_mh).msg_id = (_mid); \
  406. (_mh).msg_token = (_tok); \
  407. (_mh).enet_id = (_enet_id); \
  408. } while (0)
  409. /*
  410. * Mailbox for messaging interface
  411. */
  412. #define BFI_MSGQ_CMD_ENTRY_SIZE (64) /* TBD */
  413. #define BFI_MSGQ_RSP_ENTRY_SIZE (64) /* TBD */
  414. #define bfi_msgq_num_cmd_entries(_size) \
  415. (((_size) + BFI_MSGQ_CMD_ENTRY_SIZE - 1) / BFI_MSGQ_CMD_ENTRY_SIZE)
  416. struct bfi_msgq {
  417. union bfi_addr_u addr;
  418. u16 q_depth; /* Total num of entries in the queue */
  419. u8 rsvd[2];
  420. };
  421. /* BFI_ENET_MSGQ_CFG_REQ TBD init or cfg? */
  422. struct bfi_msgq_cfg_req {
  423. struct bfi_mhdr mh;
  424. struct bfi_msgq cmdq;
  425. struct bfi_msgq rspq;
  426. };
  427. /* BFI_ENET_MSGQ_CFG_RSP */
  428. struct bfi_msgq_cfg_rsp {
  429. struct bfi_mhdr mh;
  430. u8 cmd_status;
  431. u8 rsvd[3];
  432. };
  433. /* BFI_MSGQ_H2I_DOORBELL */
  434. struct bfi_msgq_h2i_db {
  435. struct bfi_mhdr mh;
  436. union {
  437. u16 cmdq_pi;
  438. u16 rspq_ci;
  439. } idx;
  440. };
  441. /* BFI_MSGQ_I2H_DOORBELL */
  442. struct bfi_msgq_i2h_db {
  443. struct bfi_mhdr mh;
  444. union {
  445. u16 rspq_pi;
  446. u16 cmdq_ci;
  447. } idx;
  448. };
  449. #define BFI_CMD_COPY_SZ 28
  450. /* BFI_MSGQ_H2I_CMD_COPY_RSP */
  451. struct bfi_msgq_h2i_cmdq_copy_rsp {
  452. struct bfi_mhdr mh;
  453. u8 data[BFI_CMD_COPY_SZ];
  454. };
  455. /* BFI_MSGQ_I2H_CMD_COPY_REQ */
  456. struct bfi_msgq_i2h_cmdq_copy_req {
  457. struct bfi_mhdr mh;
  458. u16 offset;
  459. u16 len;
  460. };
  461. #pragma pack()
  462. #endif /* __BFI_H__ */