bna_hw_defs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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-2011 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. /**
  19. * File for interrupt macros and functions
  20. */
  21. #ifndef __BNA_HW_DEFS_H__
  22. #define __BNA_HW_DEFS_H__
  23. #include "bfi_reg.h"
  24. /**
  25. *
  26. * SW imposed limits
  27. *
  28. */
  29. #define BFI_ENET_DEF_TXQ 1
  30. #define BFI_ENET_DEF_RXP 1
  31. #define BFI_ENET_DEF_UCAM 1
  32. #define BFI_ENET_DEF_RITSZ 1
  33. #define BFI_ENET_MAX_MCAM 256
  34. #define BFI_INVALID_RID -1
  35. #define BFI_IBIDX_SIZE 4
  36. #define BFI_VLAN_WORD_SHIFT 5 /* 32 bits */
  37. #define BFI_VLAN_WORD_MASK 0x1F
  38. #define BFI_VLAN_BLOCK_SHIFT 9 /* 512 bits */
  39. #define BFI_VLAN_BMASK_ALL 0xFF
  40. #define BFI_COALESCING_TIMER_UNIT 5 /* 5us */
  41. #define BFI_MAX_COALESCING_TIMEO 0xFF /* in 5us units */
  42. #define BFI_MAX_INTERPKT_COUNT 0xFF
  43. #define BFI_MAX_INTERPKT_TIMEO 0xF /* in 0.5us units */
  44. #define BFI_TX_COALESCING_TIMEO 20 /* 20 * 5 = 100us */
  45. #define BFI_TX_INTERPKT_COUNT 32
  46. #define BFI_RX_COALESCING_TIMEO 12 /* 12 * 5 = 60us */
  47. #define BFI_RX_INTERPKT_COUNT 6 /* Pkt Cnt = 6 */
  48. #define BFI_RX_INTERPKT_TIMEO 3 /* 3 * 0.5 = 1.5us */
  49. #define BFI_TXQ_WI_SIZE 64 /* bytes */
  50. #define BFI_RXQ_WI_SIZE 8 /* bytes */
  51. #define BFI_CQ_WI_SIZE 16 /* bytes */
  52. #define BFI_TX_MAX_WRR_QUOTA 0xFFF
  53. #define BFI_TX_MAX_VECTORS_PER_WI 4
  54. #define BFI_TX_MAX_VECTORS_PER_PKT 0xFF
  55. #define BFI_TX_MAX_DATA_PER_VECTOR 0xFFFF
  56. #define BFI_TX_MAX_DATA_PER_PKT 0xFFFFFF
  57. /* Small Q buffer size */
  58. #define BFI_SMALL_RXBUF_SIZE 128
  59. #define BFI_TX_MAX_PRIO 8
  60. #define BFI_TX_PRIO_MAP_ALL 0xFF
  61. /*
  62. *
  63. * Register definitions and macros
  64. *
  65. */
  66. #define BNA_PCI_REG_CT_ADDRSZ (0x40000)
  67. #define ct_reg_addr_init(_bna, _pcidev) \
  68. { \
  69. struct bna_reg_offset reg_offset[] = \
  70. {{HOSTFN0_INT_STATUS, HOSTFN0_INT_MSK}, \
  71. {HOSTFN1_INT_STATUS, HOSTFN1_INT_MSK}, \
  72. {HOSTFN2_INT_STATUS, HOSTFN2_INT_MSK}, \
  73. {HOSTFN3_INT_STATUS, HOSTFN3_INT_MSK} }; \
  74. \
  75. (_bna)->regs.fn_int_status = (_pcidev)->pci_bar_kva + \
  76. reg_offset[(_pcidev)->pci_func].fn_int_status;\
  77. (_bna)->regs.fn_int_mask = (_pcidev)->pci_bar_kva + \
  78. reg_offset[(_pcidev)->pci_func].fn_int_mask;\
  79. }
  80. #define ct_bit_defn_init(_bna, _pcidev) \
  81. { \
  82. (_bna)->bits.mbox_status_bits = (__HFN_INT_MBOX_LPU0 | \
  83. __HFN_INT_MBOX_LPU1); \
  84. (_bna)->bits.mbox_mask_bits = (__HFN_INT_MBOX_LPU0 | \
  85. __HFN_INT_MBOX_LPU1); \
  86. (_bna)->bits.error_status_bits = (__HFN_INT_ERR_MASK); \
  87. (_bna)->bits.error_mask_bits = (__HFN_INT_ERR_MASK); \
  88. (_bna)->bits.halt_status_bits = __HFN_INT_LL_HALT; \
  89. (_bna)->bits.halt_mask_bits = __HFN_INT_LL_HALT; \
  90. }
  91. #define ct2_reg_addr_init(_bna, _pcidev) \
  92. { \
  93. (_bna)->regs.fn_int_status = (_pcidev)->pci_bar_kva + \
  94. CT2_HOSTFN_INT_STATUS; \
  95. (_bna)->regs.fn_int_mask = (_pcidev)->pci_bar_kva + \
  96. CT2_HOSTFN_INTR_MASK; \
  97. }
  98. #define ct2_bit_defn_init(_bna, _pcidev) \
  99. { \
  100. (_bna)->bits.mbox_status_bits = (__HFN_INT_MBOX_LPU0_CT2 | \
  101. __HFN_INT_MBOX_LPU1_CT2); \
  102. (_bna)->bits.mbox_mask_bits = (__HFN_INT_MBOX_LPU0_CT2 | \
  103. __HFN_INT_MBOX_LPU1_CT2); \
  104. (_bna)->bits.error_status_bits = (__HFN_INT_ERR_MASK_CT2); \
  105. (_bna)->bits.error_mask_bits = (__HFN_INT_ERR_MASK_CT2); \
  106. (_bna)->bits.halt_status_bits = __HFN_INT_CPQ_HALT_CT2; \
  107. (_bna)->bits.halt_mask_bits = __HFN_INT_CPQ_HALT_CT2; \
  108. }
  109. #define bna_reg_addr_init(_bna, _pcidev) \
  110. { \
  111. switch ((_pcidev)->device_id) { \
  112. case PCI_DEVICE_ID_BROCADE_CT: \
  113. ct_reg_addr_init((_bna), (_pcidev)); \
  114. ct_bit_defn_init((_bna), (_pcidev)); \
  115. break; \
  116. case BFA_PCI_DEVICE_ID_CT2: \
  117. ct2_reg_addr_init((_bna), (_pcidev)); \
  118. ct2_bit_defn_init((_bna), (_pcidev)); \
  119. break; \
  120. } \
  121. }
  122. #define bna_port_id_get(_bna) ((_bna)->ioceth.ioc.port_id)
  123. /**
  124. *
  125. * Interrupt related bits, flags and macros
  126. *
  127. */
  128. #define IB_STATUS_BITS 0x0000ffff
  129. #define BNA_IS_MBOX_INTR(_bna, _intr_status) \
  130. ((_intr_status) & (_bna)->bits.mbox_status_bits)
  131. #define BNA_IS_HALT_INTR(_bna, _intr_status) \
  132. ((_intr_status) & (_bna)->bits.halt_status_bits)
  133. #define BNA_IS_ERR_INTR(_bna, _intr_status) \
  134. ((_intr_status) & (_bna)->bits.error_status_bits)
  135. #define BNA_IS_MBOX_ERR_INTR(_bna, _intr_status) \
  136. (BNA_IS_MBOX_INTR(_bna, _intr_status) | \
  137. BNA_IS_ERR_INTR(_bna, _intr_status))
  138. #define BNA_IS_INTX_DATA_INTR(_intr_status) \
  139. ((_intr_status) & IB_STATUS_BITS)
  140. #define bna_halt_clear(_bna) \
  141. do { \
  142. u32 init_halt; \
  143. init_halt = readl((_bna)->ioceth.ioc.ioc_regs.ll_halt); \
  144. init_halt &= ~__FW_INIT_HALT_P; \
  145. writel(init_halt, (_bna)->ioceth.ioc.ioc_regs.ll_halt); \
  146. init_halt = readl((_bna)->ioceth.ioc.ioc_regs.ll_halt); \
  147. } while (0)
  148. #define bna_intx_disable(_bna, _cur_mask) \
  149. { \
  150. (_cur_mask) = readl((_bna)->regs.fn_int_mask); \
  151. writel(0xffffffff, (_bna)->regs.fn_int_mask); \
  152. }
  153. #define bna_intx_enable(bna, new_mask) \
  154. writel((new_mask), (bna)->regs.fn_int_mask)
  155. #define bna_mbox_intr_disable(bna) \
  156. do { \
  157. u32 mask; \
  158. mask = readl((bna)->regs.fn_int_mask); \
  159. writel((mask | (bna)->bits.mbox_mask_bits | \
  160. (bna)->bits.error_mask_bits), (bna)->regs.fn_int_mask); \
  161. mask = readl((bna)->regs.fn_int_mask); \
  162. } while (0)
  163. #define bna_mbox_intr_enable(bna) \
  164. do { \
  165. u32 mask; \
  166. mask = readl((bna)->regs.fn_int_mask); \
  167. writel((mask & ~((bna)->bits.mbox_mask_bits | \
  168. (bna)->bits.error_mask_bits)), (bna)->regs.fn_int_mask);\
  169. mask = readl((bna)->regs.fn_int_mask); \
  170. } while (0)
  171. #define bna_intr_status_get(_bna, _status) \
  172. { \
  173. (_status) = readl((_bna)->regs.fn_int_status); \
  174. if (_status) { \
  175. writel(((_status) & ~(_bna)->bits.mbox_status_bits), \
  176. (_bna)->regs.fn_int_status); \
  177. } \
  178. }
  179. /*
  180. * MAX ACK EVENTS : No. of acks that can be accumulated in driver,
  181. * before acking to h/w. The no. of bits is 16 in the doorbell register,
  182. * however we keep this limited to 15 bits.
  183. * This is because around the edge of 64K boundary (16 bits), one
  184. * single poll can make the accumulated ACK counter cross the 64K boundary,
  185. * causing problems, when we try to ack with a value greater than 64K.
  186. * 15 bits (32K) should be large enough to accumulate, anyways, and the max.
  187. * acked events to h/w can be (32K + max poll weight) (currently 64).
  188. */
  189. #define BNA_IB_MAX_ACK_EVENTS (1 << 15)
  190. /* These macros build the data portion of the TxQ/RxQ doorbell */
  191. #define BNA_DOORBELL_Q_PRD_IDX(_pi) (0x80000000 | (_pi))
  192. #define BNA_DOORBELL_Q_STOP (0x40000000)
  193. /* These macros build the data portion of the IB doorbell */
  194. #define BNA_DOORBELL_IB_INT_ACK(_timeout, _events) \
  195. (0x80000000 | ((_timeout) << 16) | (_events))
  196. #define BNA_DOORBELL_IB_INT_DISABLE (0x40000000)
  197. /* Set the coalescing timer for the given ib */
  198. #define bna_ib_coalescing_timer_set(_i_dbell, _cls_timer) \
  199. ((_i_dbell)->doorbell_ack = BNA_DOORBELL_IB_INT_ACK((_cls_timer), 0));
  200. /* Acks 'events' # of events for a given ib while disabling interrupts */
  201. #define bna_ib_ack_disable_irq(_i_dbell, _events) \
  202. (writel(BNA_DOORBELL_IB_INT_ACK(0, (_events)), \
  203. (_i_dbell)->doorbell_addr));
  204. /* Acks 'events' # of events for a given ib */
  205. #define bna_ib_ack(_i_dbell, _events) \
  206. (writel(((_i_dbell)->doorbell_ack | (_events)), \
  207. (_i_dbell)->doorbell_addr));
  208. #define bna_ib_start(_bna, _ib, _is_regular) \
  209. { \
  210. u32 intx_mask; \
  211. struct bna_ib *ib = _ib; \
  212. if ((ib->intr_type == BNA_INTR_T_INTX)) { \
  213. bna_intx_disable((_bna), intx_mask); \
  214. intx_mask &= ~(ib->intr_vector); \
  215. bna_intx_enable((_bna), intx_mask); \
  216. } \
  217. bna_ib_coalescing_timer_set(&ib->door_bell, \
  218. ib->coalescing_timeo); \
  219. if (_is_regular) \
  220. bna_ib_ack(&ib->door_bell, 0); \
  221. }
  222. #define bna_ib_stop(_bna, _ib) \
  223. { \
  224. u32 intx_mask; \
  225. struct bna_ib *ib = _ib; \
  226. writel(BNA_DOORBELL_IB_INT_DISABLE, \
  227. ib->door_bell.doorbell_addr); \
  228. if (ib->intr_type == BNA_INTR_T_INTX) { \
  229. bna_intx_disable((_bna), intx_mask); \
  230. intx_mask |= ib->intr_vector; \
  231. bna_intx_enable((_bna), intx_mask); \
  232. } \
  233. }
  234. #define bna_txq_prod_indx_doorbell(_tcb) \
  235. (writel(BNA_DOORBELL_Q_PRD_IDX((_tcb)->producer_index), \
  236. (_tcb)->q_dbell));
  237. #define bna_rxq_prod_indx_doorbell(_rcb) \
  238. (writel(BNA_DOORBELL_Q_PRD_IDX((_rcb)->producer_index), \
  239. (_rcb)->q_dbell));
  240. /**
  241. *
  242. * TxQ, RxQ, CQ related bits, offsets, macros
  243. *
  244. */
  245. /* TxQ Entry Opcodes */
  246. #define BNA_TXQ_WI_SEND (0x402) /* Single Frame Transmission */
  247. #define BNA_TXQ_WI_SEND_LSO (0x403) /* Multi-Frame Transmission */
  248. #define BNA_TXQ_WI_EXTENSION (0x104) /* Extension WI */
  249. /* TxQ Entry Control Flags */
  250. #define BNA_TXQ_WI_CF_FCOE_CRC (1 << 8)
  251. #define BNA_TXQ_WI_CF_IPID_MODE (1 << 5)
  252. #define BNA_TXQ_WI_CF_INS_PRIO (1 << 4)
  253. #define BNA_TXQ_WI_CF_INS_VLAN (1 << 3)
  254. #define BNA_TXQ_WI_CF_UDP_CKSUM (1 << 2)
  255. #define BNA_TXQ_WI_CF_TCP_CKSUM (1 << 1)
  256. #define BNA_TXQ_WI_CF_IP_CKSUM (1 << 0)
  257. #define BNA_TXQ_WI_L4_HDR_N_OFFSET(_hdr_size, _offset) \
  258. (((_hdr_size) << 10) | ((_offset) & 0x3FF))
  259. /*
  260. * Completion Q defines
  261. */
  262. /* CQ Entry Flags */
  263. #define BNA_CQ_EF_MAC_ERROR (1 << 0)
  264. #define BNA_CQ_EF_FCS_ERROR (1 << 1)
  265. #define BNA_CQ_EF_TOO_LONG (1 << 2)
  266. #define BNA_CQ_EF_FC_CRC_OK (1 << 3)
  267. #define BNA_CQ_EF_RSVD1 (1 << 4)
  268. #define BNA_CQ_EF_L4_CKSUM_OK (1 << 5)
  269. #define BNA_CQ_EF_L3_CKSUM_OK (1 << 6)
  270. #define BNA_CQ_EF_HDS_HEADER (1 << 7)
  271. #define BNA_CQ_EF_UDP (1 << 8)
  272. #define BNA_CQ_EF_TCP (1 << 9)
  273. #define BNA_CQ_EF_IP_OPTIONS (1 << 10)
  274. #define BNA_CQ_EF_IPV6 (1 << 11)
  275. #define BNA_CQ_EF_IPV4 (1 << 12)
  276. #define BNA_CQ_EF_VLAN (1 << 13)
  277. #define BNA_CQ_EF_RSS (1 << 14)
  278. #define BNA_CQ_EF_RSVD2 (1 << 15)
  279. #define BNA_CQ_EF_MCAST_MATCH (1 << 16)
  280. #define BNA_CQ_EF_MCAST (1 << 17)
  281. #define BNA_CQ_EF_BCAST (1 << 18)
  282. #define BNA_CQ_EF_REMOTE (1 << 19)
  283. #define BNA_CQ_EF_LOCAL (1 << 20)
  284. /**
  285. *
  286. * Data structures
  287. *
  288. */
  289. struct bna_reg_offset {
  290. u32 fn_int_status;
  291. u32 fn_int_mask;
  292. };
  293. struct bna_bit_defn {
  294. u32 mbox_status_bits;
  295. u32 mbox_mask_bits;
  296. u32 error_status_bits;
  297. u32 error_mask_bits;
  298. u32 halt_status_bits;
  299. u32 halt_mask_bits;
  300. };
  301. struct bna_reg {
  302. void __iomem *fn_int_status;
  303. void __iomem *fn_int_mask;
  304. };
  305. /* TxQ Vector (a.k.a. Tx-Buffer Descriptor) */
  306. struct bna_dma_addr {
  307. u32 msb;
  308. u32 lsb;
  309. };
  310. struct bna_txq_wi_vector {
  311. u16 reserved;
  312. u16 length; /* Only 14 LSB are valid */
  313. struct bna_dma_addr host_addr; /* Tx-Buf DMA addr */
  314. };
  315. /**
  316. * TxQ Entry Structure
  317. *
  318. * BEWARE: Load values into this structure with correct endianess.
  319. */
  320. struct bna_txq_entry {
  321. union {
  322. struct {
  323. u8 reserved;
  324. u8 num_vectors; /* number of vectors present */
  325. u16 opcode; /* Either */
  326. /* BNA_TXQ_WI_SEND or */
  327. /* BNA_TXQ_WI_SEND_LSO */
  328. u16 flags; /* OR of all the flags */
  329. u16 l4_hdr_size_n_offset;
  330. u16 vlan_tag;
  331. u16 lso_mss; /* Only 14 LSB are valid */
  332. u32 frame_length; /* Only 24 LSB are valid */
  333. } wi;
  334. struct {
  335. u16 reserved;
  336. u16 opcode; /* Must be */
  337. /* BNA_TXQ_WI_EXTENSION */
  338. u32 reserved2[3]; /* Place holder for */
  339. /* removed vector (12 bytes) */
  340. } wi_ext;
  341. } hdr;
  342. struct bna_txq_wi_vector vector[4];
  343. };
  344. /* RxQ Entry Structure */
  345. struct bna_rxq_entry { /* Rx-Buffer */
  346. struct bna_dma_addr host_addr; /* Rx-Buffer DMA address */
  347. };
  348. /* CQ Entry Structure */
  349. struct bna_cq_entry {
  350. u32 flags;
  351. u16 vlan_tag;
  352. u16 length;
  353. u32 rss_hash;
  354. u8 valid;
  355. u8 reserved1;
  356. u8 reserved2;
  357. u8 rxq_id;
  358. };
  359. #endif /* __BNA_HW_DEFS_H__ */