bfi.h 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #ifndef __BFI_H__
  18. #define __BFI_H__
  19. #include "bfa_defs.h"
  20. #include "bfa_defs_svc.h"
  21. #pragma pack(1)
  22. /* Per dma segment max size */
  23. #define BFI_MEM_DMA_SEG_SZ (131072)
  24. /* Get number of dma segments required */
  25. #define BFI_MEM_DMA_NSEGS(_num_reqs, _req_sz) \
  26. ((u16)(((((_num_reqs) * (_req_sz)) + BFI_MEM_DMA_SEG_SZ - 1) & \
  27. ~(BFI_MEM_DMA_SEG_SZ - 1)) / BFI_MEM_DMA_SEG_SZ))
  28. /* Get num dma reqs - that fit in a segment */
  29. #define BFI_MEM_NREQS_SEG(_rqsz) (BFI_MEM_DMA_SEG_SZ / (_rqsz))
  30. /* Get segment num from tag */
  31. #define BFI_MEM_SEG_FROM_TAG(_tag, _rqsz) ((_tag) / BFI_MEM_NREQS_SEG(_rqsz))
  32. /* Get dma req offset in a segment */
  33. #define BFI_MEM_SEG_REQ_OFFSET(_tag, _sz) \
  34. ((_tag) - (BFI_MEM_SEG_FROM_TAG(_tag, _sz) * BFI_MEM_NREQS_SEG(_sz)))
  35. /*
  36. * BFI FW image type
  37. */
  38. #define BFI_FLASH_CHUNK_SZ 256 /* Flash chunk size */
  39. #define BFI_FLASH_CHUNK_SZ_WORDS (BFI_FLASH_CHUNK_SZ/sizeof(u32))
  40. /*
  41. * Msg header common to all msgs
  42. */
  43. struct bfi_mhdr_s {
  44. u8 msg_class; /* @ref bfi_mclass_t */
  45. u8 msg_id; /* msg opcode with in the class */
  46. union {
  47. struct {
  48. u8 qid;
  49. u8 fn_lpu; /* msg destination */
  50. } h2i;
  51. u16 i2htok; /* token in msgs to host */
  52. } mtag;
  53. };
  54. #define bfi_fn_lpu(__fn, __lpu) ((__fn) << 1 | (__lpu))
  55. #define bfi_mhdr_2_fn(_mh) ((_mh)->mtag.h2i.fn_lpu >> 1)
  56. #define bfi_h2i_set(_mh, _mc, _op, _fn_lpu) do { \
  57. (_mh).msg_class = (_mc); \
  58. (_mh).msg_id = (_op); \
  59. (_mh).mtag.h2i.fn_lpu = (_fn_lpu); \
  60. } while (0)
  61. #define bfi_i2h_set(_mh, _mc, _op, _i2htok) do { \
  62. (_mh).msg_class = (_mc); \
  63. (_mh).msg_id = (_op); \
  64. (_mh).mtag.i2htok = (_i2htok); \
  65. } while (0)
  66. /*
  67. * Message opcodes: 0-127 to firmware, 128-255 to host
  68. */
  69. #define BFI_I2H_OPCODE_BASE 128
  70. #define BFA_I2HM(_x) ((_x) + BFI_I2H_OPCODE_BASE)
  71. /*
  72. ****************************************************************************
  73. *
  74. * Scatter Gather Element and Page definition
  75. *
  76. ****************************************************************************
  77. */
  78. #define BFI_SGE_INLINE 1
  79. #define BFI_SGE_INLINE_MAX (BFI_SGE_INLINE + 1)
  80. /*
  81. * SG Flags
  82. */
  83. enum {
  84. BFI_SGE_DATA = 0, /* data address, not last */
  85. BFI_SGE_DATA_CPL = 1, /* data addr, last in current page */
  86. BFI_SGE_DATA_LAST = 3, /* data address, last */
  87. BFI_SGE_LINK = 2, /* link address */
  88. BFI_SGE_PGDLEN = 2, /* cumulative data length for page */
  89. };
  90. /*
  91. * DMA addresses
  92. */
  93. union bfi_addr_u {
  94. struct {
  95. __be32 addr_lo;
  96. __be32 addr_hi;
  97. } a32;
  98. };
  99. /*
  100. * Scatter Gather Element used for fast-path IO requests
  101. */
  102. struct bfi_sge_s {
  103. #ifdef __BIG_ENDIAN
  104. u32 flags:2,
  105. rsvd:2,
  106. sg_len:28;
  107. #else
  108. u32 sg_len:28,
  109. rsvd:2,
  110. flags:2;
  111. #endif
  112. union bfi_addr_u sga;
  113. };
  114. /**
  115. * Generic DMA addr-len pair.
  116. */
  117. struct bfi_alen_s {
  118. union bfi_addr_u al_addr; /* DMA addr of buffer */
  119. u32 al_len; /* length of buffer */
  120. };
  121. /*
  122. * Scatter Gather Page
  123. */
  124. #define BFI_SGPG_DATA_SGES 7
  125. #define BFI_SGPG_SGES_MAX (BFI_SGPG_DATA_SGES + 1)
  126. #define BFI_SGPG_RSVD_WD_LEN 8
  127. struct bfi_sgpg_s {
  128. struct bfi_sge_s sges[BFI_SGPG_SGES_MAX];
  129. u32 rsvd[BFI_SGPG_RSVD_WD_LEN];
  130. };
  131. /* FCP module definitions */
  132. #define BFI_IO_MAX (2000)
  133. #define BFI_IOIM_SNSLEN (256)
  134. #define BFI_IOIM_SNSBUF_SEGS \
  135. BFI_MEM_DMA_NSEGS(BFI_IO_MAX, BFI_IOIM_SNSLEN)
  136. /*
  137. * Large Message structure - 128 Bytes size Msgs
  138. */
  139. #define BFI_LMSG_SZ 128
  140. #define BFI_LMSG_PL_WSZ \
  141. ((BFI_LMSG_SZ - sizeof(struct bfi_mhdr_s)) / 4)
  142. struct bfi_msg_s {
  143. struct bfi_mhdr_s mhdr;
  144. u32 pl[BFI_LMSG_PL_WSZ];
  145. };
  146. /*
  147. * Mailbox message structure
  148. */
  149. #define BFI_MBMSG_SZ 7
  150. struct bfi_mbmsg_s {
  151. struct bfi_mhdr_s mh;
  152. u32 pl[BFI_MBMSG_SZ];
  153. };
  154. /*
  155. * Supported PCI function class codes (personality)
  156. */
  157. enum bfi_pcifn_class {
  158. BFI_PCIFN_CLASS_FC = 0x0c04,
  159. BFI_PCIFN_CLASS_ETH = 0x0200,
  160. };
  161. /*
  162. * Message Classes
  163. */
  164. enum bfi_mclass {
  165. BFI_MC_IOC = 1, /* IO Controller (IOC) */
  166. BFI_MC_DIAG = 2, /* Diagnostic Msgs */
  167. BFI_MC_FLASH = 3, /* Flash message class */
  168. BFI_MC_CEE = 4, /* CEE */
  169. BFI_MC_FCPORT = 5, /* FC port */
  170. BFI_MC_IOCFC = 6, /* FC - IO Controller (IOC) */
  171. BFI_MC_ABLK = 7, /* ASIC block configuration */
  172. BFI_MC_UF = 8, /* Unsolicited frame receive */
  173. BFI_MC_FCXP = 9, /* FC Transport */
  174. BFI_MC_LPS = 10, /* lport fc login services */
  175. BFI_MC_RPORT = 11, /* Remote port */
  176. BFI_MC_ITN = 12, /* I-T nexus (Initiator mode) */
  177. BFI_MC_IOIM_READ = 13, /* read IO (Initiator mode) */
  178. BFI_MC_IOIM_WRITE = 14, /* write IO (Initiator mode) */
  179. BFI_MC_IOIM_IO = 15, /* IO (Initiator mode) */
  180. BFI_MC_IOIM = 16, /* IO (Initiator mode) */
  181. BFI_MC_IOIM_IOCOM = 17, /* good IO completion */
  182. BFI_MC_TSKIM = 18, /* Initiator Task management */
  183. BFI_MC_PORT = 21, /* Physical port */
  184. BFI_MC_SFP = 22, /* SFP module */
  185. BFI_MC_PHY = 25, /* External PHY message class */
  186. BFI_MC_MAX = 32
  187. };
  188. #define BFI_IOC_MAX_CQS 4
  189. #define BFI_IOC_MAX_CQS_ASIC 8
  190. #define BFI_IOC_MSGLEN_MAX 32 /* 32 bytes */
  191. /*
  192. *----------------------------------------------------------------------
  193. * IOC
  194. *----------------------------------------------------------------------
  195. */
  196. /*
  197. * Different asic generations
  198. */
  199. enum bfi_asic_gen {
  200. BFI_ASIC_GEN_CB = 1, /* crossbow 8G FC */
  201. BFI_ASIC_GEN_CT = 2, /* catapult 8G FC or 10G CNA */
  202. BFI_ASIC_GEN_CT2 = 3, /* catapult-2 16G FC or 10G CNA */
  203. };
  204. enum bfi_asic_mode {
  205. BFI_ASIC_MODE_FC = 1, /* FC upto 8G speed */
  206. BFI_ASIC_MODE_FC16 = 2, /* FC upto 16G speed */
  207. BFI_ASIC_MODE_ETH = 3, /* Ethernet ports */
  208. BFI_ASIC_MODE_COMBO = 4, /* FC 16G and Ethernet 10G port */
  209. };
  210. enum bfi_ioc_h2i_msgs {
  211. BFI_IOC_H2I_ENABLE_REQ = 1,
  212. BFI_IOC_H2I_DISABLE_REQ = 2,
  213. BFI_IOC_H2I_GETATTR_REQ = 3,
  214. BFI_IOC_H2I_DBG_SYNC = 4,
  215. BFI_IOC_H2I_DBG_DUMP = 5,
  216. };
  217. enum bfi_ioc_i2h_msgs {
  218. BFI_IOC_I2H_ENABLE_REPLY = BFA_I2HM(1),
  219. BFI_IOC_I2H_DISABLE_REPLY = BFA_I2HM(2),
  220. BFI_IOC_I2H_GETATTR_REPLY = BFA_I2HM(3),
  221. BFI_IOC_I2H_HBEAT = BFA_I2HM(4),
  222. BFI_IOC_I2H_ACQ_ADDR_REPLY = BFA_I2HM(5),
  223. };
  224. /*
  225. * BFI_IOC_H2I_GETATTR_REQ message
  226. */
  227. struct bfi_ioc_getattr_req_s {
  228. struct bfi_mhdr_s mh;
  229. union bfi_addr_u attr_addr;
  230. };
  231. struct bfi_ioc_attr_s {
  232. wwn_t mfg_pwwn; /* Mfg port wwn */
  233. wwn_t mfg_nwwn; /* Mfg node wwn */
  234. mac_t mfg_mac; /* Mfg mac */
  235. u8 port_mode; /* bfi_port_mode */
  236. u8 rsvd_a;
  237. wwn_t pwwn;
  238. wwn_t nwwn;
  239. mac_t mac; /* PBC or Mfg mac */
  240. u16 rsvd_b;
  241. mac_t fcoe_mac;
  242. u16 rsvd_c;
  243. char brcd_serialnum[STRSZ(BFA_MFG_SERIALNUM_SIZE)];
  244. u8 pcie_gen;
  245. u8 pcie_lanes_orig;
  246. u8 pcie_lanes;
  247. u8 rx_bbcredit; /* receive buffer credits */
  248. u32 adapter_prop; /* adapter properties */
  249. u16 maxfrsize; /* max receive frame size */
  250. char asic_rev;
  251. u8 rsvd_d;
  252. char fw_version[BFA_VERSION_LEN];
  253. char optrom_version[BFA_VERSION_LEN];
  254. struct bfa_mfg_vpd_s vpd;
  255. u32 card_type; /* card type */
  256. };
  257. /*
  258. * BFI_IOC_I2H_GETATTR_REPLY message
  259. */
  260. struct bfi_ioc_getattr_reply_s {
  261. struct bfi_mhdr_s mh; /* Common msg header */
  262. u8 status; /* cfg reply status */
  263. u8 rsvd[3];
  264. };
  265. /*
  266. * Firmware memory page offsets
  267. */
  268. #define BFI_IOC_SMEM_PG0_CB (0x40)
  269. #define BFI_IOC_SMEM_PG0_CT (0x180)
  270. /*
  271. * Firmware statistic offset
  272. */
  273. #define BFI_IOC_FWSTATS_OFF (0x6B40)
  274. #define BFI_IOC_FWSTATS_SZ (4096)
  275. /*
  276. * Firmware trace offset
  277. */
  278. #define BFI_IOC_TRC_OFF (0x4b00)
  279. #define BFI_IOC_TRC_ENTS 256
  280. #define BFI_IOC_FW_SIGNATURE (0xbfadbfad)
  281. #define BFI_IOC_MD5SUM_SZ 4
  282. struct bfi_ioc_image_hdr_s {
  283. u32 signature; /* constant signature */
  284. u8 asic_gen; /* asic generation */
  285. u8 asic_mode;
  286. u8 port0_mode; /* device mode for port 0 */
  287. u8 port1_mode; /* device mode for port 1 */
  288. u32 exec; /* exec vector */
  289. u32 bootenv; /* fimware boot env */
  290. u32 rsvd_b[4];
  291. u32 md5sum[BFI_IOC_MD5SUM_SZ];
  292. };
  293. #define BFI_FWBOOT_DEVMODE_OFF 4
  294. #define BFI_FWBOOT_TYPE_OFF 8
  295. #define BFI_FWBOOT_ENV_OFF 12
  296. #define BFI_FWBOOT_DEVMODE(__asic_gen, __asic_mode, __p0_mode, __p1_mode) \
  297. (((u32)(__asic_gen)) << 24 | \
  298. ((u32)(__asic_mode)) << 16 | \
  299. ((u32)(__p0_mode)) << 8 | \
  300. ((u32)(__p1_mode)))
  301. #define BFI_FWBOOT_TYPE_NORMAL 0
  302. #define BFI_FWBOOT_TYPE_MEMTEST 2
  303. #define BFI_FWBOOT_ENV_OS 0
  304. enum bfi_port_mode {
  305. BFI_PORT_MODE_FC = 1,
  306. BFI_PORT_MODE_ETH = 2,
  307. };
  308. struct bfi_ioc_hbeat_s {
  309. struct bfi_mhdr_s mh; /* common msg header */
  310. u32 hb_count; /* current heart beat count */
  311. };
  312. /*
  313. * IOC hardware/firmware state
  314. */
  315. enum bfi_ioc_state {
  316. BFI_IOC_UNINIT = 0, /* not initialized */
  317. BFI_IOC_INITING = 1, /* h/w is being initialized */
  318. BFI_IOC_HWINIT = 2, /* h/w is initialized */
  319. BFI_IOC_CFG = 3, /* IOC configuration in progress */
  320. BFI_IOC_OP = 4, /* IOC is operational */
  321. BFI_IOC_DISABLING = 5, /* IOC is being disabled */
  322. BFI_IOC_DISABLED = 6, /* IOC is disabled */
  323. BFI_IOC_CFG_DISABLED = 7, /* IOC is being disabled;transient */
  324. BFI_IOC_FAIL = 8, /* IOC heart-beat failure */
  325. BFI_IOC_MEMTEST = 9, /* IOC is doing memtest */
  326. };
  327. #define BFI_IOC_ENDIAN_SIG 0x12345678
  328. enum {
  329. BFI_ADAPTER_TYPE_FC = 0x01, /* FC adapters */
  330. BFI_ADAPTER_TYPE_MK = 0x0f0000, /* adapter type mask */
  331. BFI_ADAPTER_TYPE_SH = 16, /* adapter type shift */
  332. BFI_ADAPTER_NPORTS_MK = 0xff00, /* number of ports mask */
  333. BFI_ADAPTER_NPORTS_SH = 8, /* number of ports shift */
  334. BFI_ADAPTER_SPEED_MK = 0xff, /* adapter speed mask */
  335. BFI_ADAPTER_SPEED_SH = 0, /* adapter speed shift */
  336. BFI_ADAPTER_PROTO = 0x100000, /* prototype adapaters */
  337. BFI_ADAPTER_TTV = 0x200000, /* TTV debug capable */
  338. BFI_ADAPTER_UNSUPP = 0x400000, /* unknown adapter type */
  339. };
  340. #define BFI_ADAPTER_GETP(__prop, __adap_prop) \
  341. (((__adap_prop) & BFI_ADAPTER_ ## __prop ## _MK) >> \
  342. BFI_ADAPTER_ ## __prop ## _SH)
  343. #define BFI_ADAPTER_SETP(__prop, __val) \
  344. ((__val) << BFI_ADAPTER_ ## __prop ## _SH)
  345. #define BFI_ADAPTER_IS_PROTO(__adap_type) \
  346. ((__adap_type) & BFI_ADAPTER_PROTO)
  347. #define BFI_ADAPTER_IS_TTV(__adap_type) \
  348. ((__adap_type) & BFI_ADAPTER_TTV)
  349. #define BFI_ADAPTER_IS_UNSUPP(__adap_type) \
  350. ((__adap_type) & BFI_ADAPTER_UNSUPP)
  351. #define BFI_ADAPTER_IS_SPECIAL(__adap_type) \
  352. ((__adap_type) & (BFI_ADAPTER_TTV | BFI_ADAPTER_PROTO | \
  353. BFI_ADAPTER_UNSUPP))
  354. /*
  355. * BFI_IOC_H2I_ENABLE_REQ & BFI_IOC_H2I_DISABLE_REQ messages
  356. */
  357. struct bfi_ioc_ctrl_req_s {
  358. struct bfi_mhdr_s mh;
  359. u16 clscode;
  360. u16 rsvd;
  361. u32 tv_sec;
  362. };
  363. #define bfi_ioc_enable_req_t struct bfi_ioc_ctrl_req_s;
  364. #define bfi_ioc_disable_req_t struct bfi_ioc_ctrl_req_s;
  365. /*
  366. * BFI_IOC_I2H_ENABLE_REPLY & BFI_IOC_I2H_DISABLE_REPLY messages
  367. */
  368. struct bfi_ioc_ctrl_reply_s {
  369. struct bfi_mhdr_s mh; /* Common msg header */
  370. u8 status; /* enable/disable status */
  371. u8 port_mode; /* bfa_mode_s */
  372. u8 cap_bm; /* capability bit mask */
  373. u8 rsvd;
  374. };
  375. #define bfi_ioc_enable_reply_t struct bfi_ioc_ctrl_reply_s;
  376. #define bfi_ioc_disable_reply_t struct bfi_ioc_ctrl_reply_s;
  377. #define BFI_IOC_MSGSZ 8
  378. /*
  379. * H2I Messages
  380. */
  381. union bfi_ioc_h2i_msg_u {
  382. struct bfi_mhdr_s mh;
  383. struct bfi_ioc_ctrl_req_s enable_req;
  384. struct bfi_ioc_ctrl_req_s disable_req;
  385. struct bfi_ioc_getattr_req_s getattr_req;
  386. u32 mboxmsg[BFI_IOC_MSGSZ];
  387. };
  388. /*
  389. * I2H Messages
  390. */
  391. union bfi_ioc_i2h_msg_u {
  392. struct bfi_mhdr_s mh;
  393. struct bfi_ioc_ctrl_reply_s fw_event;
  394. u32 mboxmsg[BFI_IOC_MSGSZ];
  395. };
  396. /*
  397. *----------------------------------------------------------------------
  398. * PBC
  399. *----------------------------------------------------------------------
  400. */
  401. #define BFI_PBC_MAX_BLUNS 8
  402. #define BFI_PBC_MAX_VPORTS 16
  403. #define BFI_PBC_PORT_DISABLED 2
  404. /*
  405. * PBC boot lun configuration
  406. */
  407. struct bfi_pbc_blun_s {
  408. wwn_t tgt_pwwn;
  409. struct scsi_lun tgt_lun;
  410. };
  411. /*
  412. * PBC virtual port configuration
  413. */
  414. struct bfi_pbc_vport_s {
  415. wwn_t vp_pwwn;
  416. wwn_t vp_nwwn;
  417. };
  418. /*
  419. * BFI pre-boot configuration information
  420. */
  421. struct bfi_pbc_s {
  422. u8 port_enabled;
  423. u8 boot_enabled;
  424. u8 nbluns;
  425. u8 nvports;
  426. u8 port_speed;
  427. u8 rsvd_a;
  428. u16 hss;
  429. wwn_t pbc_pwwn;
  430. wwn_t pbc_nwwn;
  431. struct bfi_pbc_blun_s blun[BFI_PBC_MAX_BLUNS];
  432. struct bfi_pbc_vport_s vport[BFI_PBC_MAX_VPORTS];
  433. };
  434. /*
  435. *----------------------------------------------------------------------
  436. * MSGQ
  437. *----------------------------------------------------------------------
  438. */
  439. #define BFI_MSGQ_FULL(_q) (((_q->pi + 1) % _q->q_depth) == _q->ci)
  440. #define BFI_MSGQ_EMPTY(_q) (_q->pi == _q->ci)
  441. #define BFI_MSGQ_UPDATE_CI(_q) (_q->ci = (_q->ci + 1) % _q->q_depth)
  442. #define BFI_MSGQ_UPDATE_PI(_q) (_q->pi = (_q->pi + 1) % _q->q_depth)
  443. /* q_depth must be power of 2 */
  444. #define BFI_MSGQ_FREE_CNT(_q) ((_q->ci - _q->pi - 1) & (_q->q_depth - 1))
  445. enum bfi_msgq_h2i_msgs_e {
  446. BFI_MSGQ_H2I_INIT_REQ = 1,
  447. BFI_MSGQ_H2I_DOORBELL = 2,
  448. BFI_MSGQ_H2I_SHUTDOWN = 3,
  449. };
  450. enum bfi_msgq_i2h_msgs_e {
  451. BFI_MSGQ_I2H_INIT_RSP = 1,
  452. BFI_MSGQ_I2H_DOORBELL = 2,
  453. };
  454. /* Messages(commands/responsed/AENS will have the following header */
  455. struct bfi_msgq_mhdr_s {
  456. u8 msg_class;
  457. u8 msg_id;
  458. u16 msg_token;
  459. u16 num_entries;
  460. u8 enet_id;
  461. u8 rsvd[1];
  462. };
  463. #define bfi_msgq_mhdr_set(_mh, _mc, _mid, _tok, _enet_id) do { \
  464. (_mh).msg_class = (_mc); \
  465. (_mh).msg_id = (_mid); \
  466. (_mh).msg_token = (_tok); \
  467. (_mh).enet_id = (_enet_id); \
  468. } while (0)
  469. /*
  470. * Mailbox for messaging interface
  471. *
  472. */
  473. #define BFI_MSGQ_CMD_ENTRY_SIZE (64) /* TBD */
  474. #define BFI_MSGQ_RSP_ENTRY_SIZE (64) /* TBD */
  475. #define BFI_MSGQ_MSG_SIZE_MAX (2048) /* TBD */
  476. struct bfi_msgq_s {
  477. union bfi_addr_u addr;
  478. u16 q_depth; /* Total num of entries in the queue */
  479. u8 rsvd[2];
  480. };
  481. /* BFI_ENET_MSGQ_CFG_REQ TBD init or cfg? */
  482. struct bfi_msgq_cfg_req_s {
  483. struct bfi_mhdr_s mh;
  484. struct bfi_msgq_s cmdq;
  485. struct bfi_msgq_s rspq;
  486. };
  487. /* BFI_ENET_MSGQ_CFG_RSP */
  488. struct bfi_msgq_cfg_rsp_s {
  489. struct bfi_mhdr_s mh;
  490. u8 cmd_status;
  491. u8 rsvd[3];
  492. };
  493. /* BFI_MSGQ_H2I_DOORBELL */
  494. struct bfi_msgq_h2i_db_s {
  495. struct bfi_mhdr_s mh;
  496. u16 cmdq_pi;
  497. u16 rspq_ci;
  498. };
  499. /* BFI_MSGQ_I2H_DOORBELL */
  500. struct bfi_msgq_i2h_db_s {
  501. struct bfi_mhdr_s mh;
  502. u16 rspq_pi;
  503. u16 cmdq_ci;
  504. };
  505. #pragma pack()
  506. /* BFI port specific */
  507. #pragma pack(1)
  508. enum bfi_port_h2i {
  509. BFI_PORT_H2I_ENABLE_REQ = (1),
  510. BFI_PORT_H2I_DISABLE_REQ = (2),
  511. BFI_PORT_H2I_GET_STATS_REQ = (3),
  512. BFI_PORT_H2I_CLEAR_STATS_REQ = (4),
  513. };
  514. enum bfi_port_i2h {
  515. BFI_PORT_I2H_ENABLE_RSP = BFA_I2HM(1),
  516. BFI_PORT_I2H_DISABLE_RSP = BFA_I2HM(2),
  517. BFI_PORT_I2H_GET_STATS_RSP = BFA_I2HM(3),
  518. BFI_PORT_I2H_CLEAR_STATS_RSP = BFA_I2HM(4),
  519. };
  520. /*
  521. * Generic REQ type
  522. */
  523. struct bfi_port_generic_req_s {
  524. struct bfi_mhdr_s mh; /* msg header */
  525. u32 msgtag; /* msgtag for reply */
  526. u32 rsvd;
  527. };
  528. /*
  529. * Generic RSP type
  530. */
  531. struct bfi_port_generic_rsp_s {
  532. struct bfi_mhdr_s mh; /* common msg header */
  533. u8 status; /* port enable status */
  534. u8 rsvd[3];
  535. u32 msgtag; /* msgtag for reply */
  536. };
  537. /*
  538. * BFI_PORT_H2I_GET_STATS_REQ
  539. */
  540. struct bfi_port_get_stats_req_s {
  541. struct bfi_mhdr_s mh; /* common msg header */
  542. union bfi_addr_u dma_addr;
  543. };
  544. union bfi_port_h2i_msg_u {
  545. struct bfi_mhdr_s mh;
  546. struct bfi_port_generic_req_s enable_req;
  547. struct bfi_port_generic_req_s disable_req;
  548. struct bfi_port_get_stats_req_s getstats_req;
  549. struct bfi_port_generic_req_s clearstats_req;
  550. };
  551. union bfi_port_i2h_msg_u {
  552. struct bfi_mhdr_s mh;
  553. struct bfi_port_generic_rsp_s enable_rsp;
  554. struct bfi_port_generic_rsp_s disable_rsp;
  555. struct bfi_port_generic_rsp_s getstats_rsp;
  556. struct bfi_port_generic_rsp_s clearstats_rsp;
  557. };
  558. /*
  559. *----------------------------------------------------------------------
  560. * ABLK
  561. *----------------------------------------------------------------------
  562. */
  563. enum bfi_ablk_h2i_msgs_e {
  564. BFI_ABLK_H2I_QUERY = 1,
  565. BFI_ABLK_H2I_ADPT_CONFIG = 2,
  566. BFI_ABLK_H2I_PORT_CONFIG = 3,
  567. BFI_ABLK_H2I_PF_CREATE = 4,
  568. BFI_ABLK_H2I_PF_DELETE = 5,
  569. BFI_ABLK_H2I_PF_UPDATE = 6,
  570. BFI_ABLK_H2I_OPTROM_ENABLE = 7,
  571. BFI_ABLK_H2I_OPTROM_DISABLE = 8,
  572. };
  573. enum bfi_ablk_i2h_msgs_e {
  574. BFI_ABLK_I2H_QUERY = BFA_I2HM(BFI_ABLK_H2I_QUERY),
  575. BFI_ABLK_I2H_ADPT_CONFIG = BFA_I2HM(BFI_ABLK_H2I_ADPT_CONFIG),
  576. BFI_ABLK_I2H_PORT_CONFIG = BFA_I2HM(BFI_ABLK_H2I_PORT_CONFIG),
  577. BFI_ABLK_I2H_PF_CREATE = BFA_I2HM(BFI_ABLK_H2I_PF_CREATE),
  578. BFI_ABLK_I2H_PF_DELETE = BFA_I2HM(BFI_ABLK_H2I_PF_DELETE),
  579. BFI_ABLK_I2H_PF_UPDATE = BFA_I2HM(BFI_ABLK_H2I_PF_UPDATE),
  580. BFI_ABLK_I2H_OPTROM_ENABLE = BFA_I2HM(BFI_ABLK_H2I_OPTROM_ENABLE),
  581. BFI_ABLK_I2H_OPTROM_DISABLE = BFA_I2HM(BFI_ABLK_H2I_OPTROM_DISABLE),
  582. };
  583. /* BFI_ABLK_H2I_QUERY */
  584. struct bfi_ablk_h2i_query_s {
  585. struct bfi_mhdr_s mh;
  586. union bfi_addr_u addr;
  587. };
  588. /* BFI_ABL_H2I_ADPT_CONFIG, BFI_ABLK_H2I_PORT_CONFIG */
  589. struct bfi_ablk_h2i_cfg_req_s {
  590. struct bfi_mhdr_s mh;
  591. u8 mode;
  592. u8 port;
  593. u8 max_pf;
  594. u8 max_vf;
  595. };
  596. /*
  597. * BFI_ABLK_H2I_PF_CREATE, BFI_ABLK_H2I_PF_DELETE,
  598. */
  599. struct bfi_ablk_h2i_pf_req_s {
  600. struct bfi_mhdr_s mh;
  601. u8 pcifn;
  602. u8 port;
  603. u16 pers;
  604. u32 bw;
  605. };
  606. /* BFI_ABLK_H2I_OPTROM_ENABLE, BFI_ABLK_H2I_OPTROM_DISABLE */
  607. struct bfi_ablk_h2i_optrom_s {
  608. struct bfi_mhdr_s mh;
  609. };
  610. /*
  611. * BFI_ABLK_I2H_QUERY
  612. * BFI_ABLK_I2H_PORT_CONFIG
  613. * BFI_ABLK_I2H_PF_CREATE
  614. * BFI_ABLK_I2H_PF_DELETE
  615. * BFI_ABLK_I2H_PF_UPDATE
  616. * BFI_ABLK_I2H_OPTROM_ENABLE
  617. * BFI_ABLK_I2H_OPTROM_DISABLE
  618. */
  619. struct bfi_ablk_i2h_rsp_s {
  620. struct bfi_mhdr_s mh;
  621. u8 status;
  622. u8 pcifn;
  623. u8 port_mode;
  624. };
  625. /*
  626. * CEE module specific messages
  627. */
  628. /* Mailbox commands from host to firmware */
  629. enum bfi_cee_h2i_msgs_e {
  630. BFI_CEE_H2I_GET_CFG_REQ = 1,
  631. BFI_CEE_H2I_RESET_STATS = 2,
  632. BFI_CEE_H2I_GET_STATS_REQ = 3,
  633. };
  634. enum bfi_cee_i2h_msgs_e {
  635. BFI_CEE_I2H_GET_CFG_RSP = BFA_I2HM(1),
  636. BFI_CEE_I2H_RESET_STATS_RSP = BFA_I2HM(2),
  637. BFI_CEE_I2H_GET_STATS_RSP = BFA_I2HM(3),
  638. };
  639. /*
  640. * H2I command structure for resetting the stats
  641. */
  642. struct bfi_cee_reset_stats_s {
  643. struct bfi_mhdr_s mh;
  644. };
  645. /*
  646. * Get configuration command from host
  647. */
  648. struct bfi_cee_get_req_s {
  649. struct bfi_mhdr_s mh;
  650. union bfi_addr_u dma_addr;
  651. };
  652. /*
  653. * Reply message from firmware
  654. */
  655. struct bfi_cee_get_rsp_s {
  656. struct bfi_mhdr_s mh;
  657. u8 cmd_status;
  658. u8 rsvd[3];
  659. };
  660. /*
  661. * Reply message from firmware
  662. */
  663. struct bfi_cee_stats_rsp_s {
  664. struct bfi_mhdr_s mh;
  665. u8 cmd_status;
  666. u8 rsvd[3];
  667. };
  668. /* Mailbox message structures from firmware to host */
  669. union bfi_cee_i2h_msg_u {
  670. struct bfi_mhdr_s mh;
  671. struct bfi_cee_get_rsp_s get_rsp;
  672. struct bfi_cee_stats_rsp_s stats_rsp;
  673. };
  674. /*
  675. * SFP related
  676. */
  677. enum bfi_sfp_h2i_e {
  678. BFI_SFP_H2I_SHOW = 1,
  679. BFI_SFP_H2I_SCN = 2,
  680. };
  681. enum bfi_sfp_i2h_e {
  682. BFI_SFP_I2H_SHOW = BFA_I2HM(BFI_SFP_H2I_SHOW),
  683. BFI_SFP_I2H_SCN = BFA_I2HM(BFI_SFP_H2I_SCN),
  684. };
  685. /*
  686. * SFP state change notification
  687. */
  688. struct bfi_sfp_scn_s {
  689. struct bfi_mhdr_s mhr; /* host msg header */
  690. u8 event;
  691. u8 sfpid;
  692. u8 pomlvl; /* pom level: normal/warning/alarm */
  693. u8 is_elb; /* e-loopback */
  694. };
  695. /*
  696. * SFP state
  697. */
  698. enum bfa_sfp_stat_e {
  699. BFA_SFP_STATE_INIT = 0, /* SFP state is uninit */
  700. BFA_SFP_STATE_REMOVED = 1, /* SFP is removed */
  701. BFA_SFP_STATE_INSERTED = 2, /* SFP is inserted */
  702. BFA_SFP_STATE_VALID = 3, /* SFP is valid */
  703. BFA_SFP_STATE_UNSUPPORT = 4, /* SFP is unsupport */
  704. BFA_SFP_STATE_FAILED = 5, /* SFP i2c read fail */
  705. };
  706. /*
  707. * SFP memory access type
  708. */
  709. enum bfi_sfp_mem_e {
  710. BFI_SFP_MEM_ALL = 0x1, /* access all data field */
  711. BFI_SFP_MEM_DIAGEXT = 0x2, /* access diag ext data field only */
  712. };
  713. struct bfi_sfp_req_s {
  714. struct bfi_mhdr_s mh;
  715. u8 memtype;
  716. u8 rsvd[3];
  717. struct bfi_alen_s alen;
  718. };
  719. struct bfi_sfp_rsp_s {
  720. struct bfi_mhdr_s mh;
  721. u8 status;
  722. u8 state;
  723. u8 rsvd[2];
  724. };
  725. /*
  726. * FLASH module specific
  727. */
  728. enum bfi_flash_h2i_msgs {
  729. BFI_FLASH_H2I_QUERY_REQ = 1,
  730. BFI_FLASH_H2I_ERASE_REQ = 2,
  731. BFI_FLASH_H2I_WRITE_REQ = 3,
  732. BFI_FLASH_H2I_READ_REQ = 4,
  733. BFI_FLASH_H2I_BOOT_VER_REQ = 5,
  734. };
  735. enum bfi_flash_i2h_msgs {
  736. BFI_FLASH_I2H_QUERY_RSP = BFA_I2HM(1),
  737. BFI_FLASH_I2H_ERASE_RSP = BFA_I2HM(2),
  738. BFI_FLASH_I2H_WRITE_RSP = BFA_I2HM(3),
  739. BFI_FLASH_I2H_READ_RSP = BFA_I2HM(4),
  740. BFI_FLASH_I2H_BOOT_VER_RSP = BFA_I2HM(5),
  741. BFI_FLASH_I2H_EVENT = BFA_I2HM(127),
  742. };
  743. /*
  744. * Flash query request
  745. */
  746. struct bfi_flash_query_req_s {
  747. struct bfi_mhdr_s mh; /* Common msg header */
  748. struct bfi_alen_s alen;
  749. };
  750. /*
  751. * Flash erase request
  752. */
  753. struct bfi_flash_erase_req_s {
  754. struct bfi_mhdr_s mh; /* Common msg header */
  755. u32 type; /* partition type */
  756. u8 instance; /* partition instance */
  757. u8 rsv[3];
  758. };
  759. /*
  760. * Flash write request
  761. */
  762. struct bfi_flash_write_req_s {
  763. struct bfi_mhdr_s mh; /* Common msg header */
  764. struct bfi_alen_s alen;
  765. u32 type; /* partition type */
  766. u8 instance; /* partition instance */
  767. u8 last;
  768. u8 rsv[2];
  769. u32 offset;
  770. u32 length;
  771. };
  772. /*
  773. * Flash read request
  774. */
  775. struct bfi_flash_read_req_s {
  776. struct bfi_mhdr_s mh; /* Common msg header */
  777. u32 type; /* partition type */
  778. u8 instance; /* partition instance */
  779. u8 rsv[3];
  780. u32 offset;
  781. u32 length;
  782. struct bfi_alen_s alen;
  783. };
  784. /*
  785. * Flash query response
  786. */
  787. struct bfi_flash_query_rsp_s {
  788. struct bfi_mhdr_s mh; /* Common msg header */
  789. u32 status;
  790. };
  791. /*
  792. * Flash read response
  793. */
  794. struct bfi_flash_read_rsp_s {
  795. struct bfi_mhdr_s mh; /* Common msg header */
  796. u32 type; /* partition type */
  797. u8 instance; /* partition instance */
  798. u8 rsv[3];
  799. u32 status;
  800. u32 length;
  801. };
  802. /*
  803. * Flash write response
  804. */
  805. struct bfi_flash_write_rsp_s {
  806. struct bfi_mhdr_s mh; /* Common msg header */
  807. u32 type; /* partition type */
  808. u8 instance; /* partition instance */
  809. u8 rsv[3];
  810. u32 status;
  811. u32 length;
  812. };
  813. /*
  814. * Flash erase response
  815. */
  816. struct bfi_flash_erase_rsp_s {
  817. struct bfi_mhdr_s mh; /* Common msg header */
  818. u32 type; /* partition type */
  819. u8 instance; /* partition instance */
  820. u8 rsv[3];
  821. u32 status;
  822. };
  823. /*
  824. * Flash event notification
  825. */
  826. struct bfi_flash_event_s {
  827. struct bfi_mhdr_s mh; /* Common msg header */
  828. bfa_status_t status;
  829. u32 param;
  830. };
  831. /*
  832. *----------------------------------------------------------------------
  833. * DIAG
  834. *----------------------------------------------------------------------
  835. */
  836. enum bfi_diag_h2i {
  837. BFI_DIAG_H2I_PORTBEACON = 1,
  838. BFI_DIAG_H2I_LOOPBACK = 2,
  839. BFI_DIAG_H2I_FWPING = 3,
  840. BFI_DIAG_H2I_TEMPSENSOR = 4,
  841. BFI_DIAG_H2I_LEDTEST = 5,
  842. BFI_DIAG_H2I_QTEST = 6,
  843. };
  844. enum bfi_diag_i2h {
  845. BFI_DIAG_I2H_PORTBEACON = BFA_I2HM(BFI_DIAG_H2I_PORTBEACON),
  846. BFI_DIAG_I2H_LOOPBACK = BFA_I2HM(BFI_DIAG_H2I_LOOPBACK),
  847. BFI_DIAG_I2H_FWPING = BFA_I2HM(BFI_DIAG_H2I_FWPING),
  848. BFI_DIAG_I2H_TEMPSENSOR = BFA_I2HM(BFI_DIAG_H2I_TEMPSENSOR),
  849. BFI_DIAG_I2H_LEDTEST = BFA_I2HM(BFI_DIAG_H2I_LEDTEST),
  850. BFI_DIAG_I2H_QTEST = BFA_I2HM(BFI_DIAG_H2I_QTEST),
  851. };
  852. #define BFI_DIAG_MAX_SGES 2
  853. #define BFI_DIAG_DMA_BUF_SZ (2 * 1024)
  854. #define BFI_BOOT_MEMTEST_RES_ADDR 0x900
  855. #define BFI_BOOT_MEMTEST_RES_SIG 0xA0A1A2A3
  856. struct bfi_diag_lb_req_s {
  857. struct bfi_mhdr_s mh;
  858. u32 loopcnt;
  859. u32 pattern;
  860. u8 lb_mode; /*!< bfa_port_opmode_t */
  861. u8 speed; /*!< bfa_port_speed_t */
  862. u8 rsvd[2];
  863. };
  864. struct bfi_diag_lb_rsp_s {
  865. struct bfi_mhdr_s mh; /* 4 bytes */
  866. struct bfa_diag_loopback_result_s res; /* 16 bytes */
  867. };
  868. struct bfi_diag_fwping_req_s {
  869. struct bfi_mhdr_s mh; /* 4 bytes */
  870. struct bfi_alen_s alen; /* 12 bytes */
  871. u32 data; /* user input data pattern */
  872. u32 count; /* user input dma count */
  873. u8 qtag; /* track CPE vc */
  874. u8 rsv[3];
  875. };
  876. struct bfi_diag_fwping_rsp_s {
  877. struct bfi_mhdr_s mh; /* 4 bytes */
  878. u32 data; /* user input data pattern */
  879. u8 qtag; /* track CPE vc */
  880. u8 dma_status; /* dma status */
  881. u8 rsv[2];
  882. };
  883. /*
  884. * Temperature Sensor
  885. */
  886. struct bfi_diag_ts_req_s {
  887. struct bfi_mhdr_s mh; /* 4 bytes */
  888. u16 temp; /* 10-bit A/D value */
  889. u16 brd_temp; /* 9-bit board temp */
  890. u8 status;
  891. u8 ts_junc; /* show junction tempsensor */
  892. u8 ts_brd; /* show board tempsensor */
  893. u8 rsv;
  894. };
  895. #define bfi_diag_ts_rsp_t struct bfi_diag_ts_req_s
  896. struct bfi_diag_ledtest_req_s {
  897. struct bfi_mhdr_s mh; /* 4 bytes */
  898. u8 cmd;
  899. u8 color;
  900. u8 portid;
  901. u8 led; /* bitmap of LEDs to be tested */
  902. u16 freq; /* no. of blinks every 10 secs */
  903. u8 rsv[2];
  904. };
  905. /* notify host led operation is done */
  906. struct bfi_diag_ledtest_rsp_s {
  907. struct bfi_mhdr_s mh; /* 4 bytes */
  908. };
  909. struct bfi_diag_portbeacon_req_s {
  910. struct bfi_mhdr_s mh; /* 4 bytes */
  911. u32 period; /* beaconing period */
  912. u8 beacon; /* 1: beacon on */
  913. u8 rsvd[3];
  914. };
  915. /* notify host the beacon is off */
  916. struct bfi_diag_portbeacon_rsp_s {
  917. struct bfi_mhdr_s mh; /* 4 bytes */
  918. };
  919. struct bfi_diag_qtest_req_s {
  920. struct bfi_mhdr_s mh; /* 4 bytes */
  921. u32 data[BFI_LMSG_PL_WSZ]; /* fill up tcm prefetch area */
  922. };
  923. #define bfi_diag_qtest_rsp_t struct bfi_diag_qtest_req_s
  924. /*
  925. * PHY module specific
  926. */
  927. enum bfi_phy_h2i_msgs_e {
  928. BFI_PHY_H2I_QUERY_REQ = 1,
  929. BFI_PHY_H2I_STATS_REQ = 2,
  930. BFI_PHY_H2I_WRITE_REQ = 3,
  931. BFI_PHY_H2I_READ_REQ = 4,
  932. };
  933. enum bfi_phy_i2h_msgs_e {
  934. BFI_PHY_I2H_QUERY_RSP = BFA_I2HM(1),
  935. BFI_PHY_I2H_STATS_RSP = BFA_I2HM(2),
  936. BFI_PHY_I2H_WRITE_RSP = BFA_I2HM(3),
  937. BFI_PHY_I2H_READ_RSP = BFA_I2HM(4),
  938. };
  939. /*
  940. * External PHY query request
  941. */
  942. struct bfi_phy_query_req_s {
  943. struct bfi_mhdr_s mh; /* Common msg header */
  944. u8 instance;
  945. u8 rsv[3];
  946. struct bfi_alen_s alen;
  947. };
  948. /*
  949. * External PHY stats request
  950. */
  951. struct bfi_phy_stats_req_s {
  952. struct bfi_mhdr_s mh; /* Common msg header */
  953. u8 instance;
  954. u8 rsv[3];
  955. struct bfi_alen_s alen;
  956. };
  957. /*
  958. * External PHY write request
  959. */
  960. struct bfi_phy_write_req_s {
  961. struct bfi_mhdr_s mh; /* Common msg header */
  962. u8 instance;
  963. u8 last;
  964. u8 rsv[2];
  965. u32 offset;
  966. u32 length;
  967. struct bfi_alen_s alen;
  968. };
  969. /*
  970. * External PHY read request
  971. */
  972. struct bfi_phy_read_req_s {
  973. struct bfi_mhdr_s mh; /* Common msg header */
  974. u8 instance;
  975. u8 rsv[3];
  976. u32 offset;
  977. u32 length;
  978. struct bfi_alen_s alen;
  979. };
  980. /*
  981. * External PHY query response
  982. */
  983. struct bfi_phy_query_rsp_s {
  984. struct bfi_mhdr_s mh; /* Common msg header */
  985. u32 status;
  986. };
  987. /*
  988. * External PHY stats response
  989. */
  990. struct bfi_phy_stats_rsp_s {
  991. struct bfi_mhdr_s mh; /* Common msg header */
  992. u32 status;
  993. };
  994. /*
  995. * External PHY read response
  996. */
  997. struct bfi_phy_read_rsp_s {
  998. struct bfi_mhdr_s mh; /* Common msg header */
  999. u32 status;
  1000. u32 length;
  1001. };
  1002. /*
  1003. * External PHY write response
  1004. */
  1005. struct bfi_phy_write_rsp_s {
  1006. struct bfi_mhdr_s mh; /* Common msg header */
  1007. u32 status;
  1008. u32 length;
  1009. };
  1010. #pragma pack()
  1011. #endif /* __BFI_H__ */