bna.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * Linux network driver for QLogic BR-series 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-2014 Brocade Communications Systems, Inc.
  15. * Copyright (c) 2014-2015 QLogic Corporation
  16. * All rights reserved
  17. * www.qlogic.com
  18. */
  19. #ifndef __BNA_H__
  20. #define __BNA_H__
  21. #include "bfa_defs.h"
  22. #include "bfa_ioc.h"
  23. #include "bfi_enet.h"
  24. #include "bna_types.h"
  25. extern const u32 bna_napi_dim_vector[][BNA_BIAS_T_MAX];
  26. /* Macros and constants */
  27. #define bna_is_small_rxq(_id) ((_id) & 0x1)
  28. /*
  29. * input : _addr-> os dma addr in host endian format,
  30. * output : _bna_dma_addr-> pointer to hw dma addr
  31. */
  32. #define BNA_SET_DMA_ADDR(_addr, _bna_dma_addr) \
  33. do { \
  34. u64 tmp_addr = \
  35. cpu_to_be64((u64)(_addr)); \
  36. (_bna_dma_addr)->msb = ((struct bna_dma_addr *)&tmp_addr)->msb; \
  37. (_bna_dma_addr)->lsb = ((struct bna_dma_addr *)&tmp_addr)->lsb; \
  38. } while (0)
  39. /*
  40. * input : _bna_dma_addr-> pointer to hw dma addr
  41. * output : _addr-> os dma addr in host endian format
  42. */
  43. #define BNA_GET_DMA_ADDR(_bna_dma_addr, _addr) \
  44. do { \
  45. (_addr) = ((((u64)ntohl((_bna_dma_addr)->msb))) << 32) \
  46. | ((ntohl((_bna_dma_addr)->lsb) & 0xffffffff)); \
  47. } while (0)
  48. #define BNA_TXQ_WI_NEEDED(_vectors) (((_vectors) + 3) >> 2)
  49. #define BNA_QE_INDX_ADD(_qe_idx, _qe_num, _q_depth) \
  50. ((_qe_idx) = ((_qe_idx) + (_qe_num)) & ((_q_depth) - 1))
  51. #define BNA_QE_INDX_INC(_idx, _q_depth) BNA_QE_INDX_ADD(_idx, 1, _q_depth)
  52. #define BNA_Q_INDEX_CHANGE(_old_idx, _updated_idx, _q_depth) \
  53. (((_updated_idx) - (_old_idx)) & ((_q_depth) - 1))
  54. #define BNA_QE_FREE_CNT(_q_ptr, _q_depth) \
  55. (((_q_ptr)->consumer_index - (_q_ptr)->producer_index - 1) & \
  56. ((_q_depth) - 1))
  57. #define BNA_QE_IN_USE_CNT(_q_ptr, _q_depth) \
  58. ((((_q_ptr)->producer_index - (_q_ptr)->consumer_index)) & \
  59. (_q_depth - 1))
  60. #define BNA_LARGE_PKT_SIZE 1000
  61. #define BNA_UPDATE_PKT_CNT(_pkt, _len) \
  62. do { \
  63. if ((_len) > BNA_LARGE_PKT_SIZE) { \
  64. (_pkt)->large_pkt_cnt++; \
  65. } else { \
  66. (_pkt)->small_pkt_cnt++; \
  67. } \
  68. } while (0)
  69. #define call_rxf_stop_cbfn(rxf) \
  70. do { \
  71. if ((rxf)->stop_cbfn) { \
  72. void (*cbfn)(struct bna_rx *); \
  73. struct bna_rx *cbarg; \
  74. cbfn = (rxf)->stop_cbfn; \
  75. cbarg = (rxf)->stop_cbarg; \
  76. (rxf)->stop_cbfn = NULL; \
  77. (rxf)->stop_cbarg = NULL; \
  78. cbfn(cbarg); \
  79. } \
  80. } while (0)
  81. #define call_rxf_start_cbfn(rxf) \
  82. do { \
  83. if ((rxf)->start_cbfn) { \
  84. void (*cbfn)(struct bna_rx *); \
  85. struct bna_rx *cbarg; \
  86. cbfn = (rxf)->start_cbfn; \
  87. cbarg = (rxf)->start_cbarg; \
  88. (rxf)->start_cbfn = NULL; \
  89. (rxf)->start_cbarg = NULL; \
  90. cbfn(cbarg); \
  91. } \
  92. } while (0)
  93. #define call_rxf_cam_fltr_cbfn(rxf) \
  94. do { \
  95. if ((rxf)->cam_fltr_cbfn) { \
  96. void (*cbfn)(struct bnad *, struct bna_rx *); \
  97. struct bnad *cbarg; \
  98. cbfn = (rxf)->cam_fltr_cbfn; \
  99. cbarg = (rxf)->cam_fltr_cbarg; \
  100. (rxf)->cam_fltr_cbfn = NULL; \
  101. (rxf)->cam_fltr_cbarg = NULL; \
  102. cbfn(cbarg, rxf->rx); \
  103. } \
  104. } while (0)
  105. #define is_xxx_enable(mode, bitmask, xxx) ((bitmask & xxx) && (mode & xxx))
  106. #define is_xxx_disable(mode, bitmask, xxx) ((bitmask & xxx) && !(mode & xxx))
  107. #define xxx_enable(mode, bitmask, xxx) \
  108. do { \
  109. bitmask |= xxx; \
  110. mode |= xxx; \
  111. } while (0)
  112. #define xxx_disable(mode, bitmask, xxx) \
  113. do { \
  114. bitmask |= xxx; \
  115. mode &= ~xxx; \
  116. } while (0)
  117. #define xxx_inactive(mode, bitmask, xxx) \
  118. do { \
  119. bitmask &= ~xxx; \
  120. mode &= ~xxx; \
  121. } while (0)
  122. #define is_promisc_enable(mode, bitmask) \
  123. is_xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
  124. #define is_promisc_disable(mode, bitmask) \
  125. is_xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
  126. #define promisc_enable(mode, bitmask) \
  127. xxx_enable(mode, bitmask, BNA_RXMODE_PROMISC)
  128. #define promisc_disable(mode, bitmask) \
  129. xxx_disable(mode, bitmask, BNA_RXMODE_PROMISC)
  130. #define promisc_inactive(mode, bitmask) \
  131. xxx_inactive(mode, bitmask, BNA_RXMODE_PROMISC)
  132. #define is_default_enable(mode, bitmask) \
  133. is_xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
  134. #define is_default_disable(mode, bitmask) \
  135. is_xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
  136. #define default_enable(mode, bitmask) \
  137. xxx_enable(mode, bitmask, BNA_RXMODE_DEFAULT)
  138. #define default_disable(mode, bitmask) \
  139. xxx_disable(mode, bitmask, BNA_RXMODE_DEFAULT)
  140. #define default_inactive(mode, bitmask) \
  141. xxx_inactive(mode, bitmask, BNA_RXMODE_DEFAULT)
  142. #define is_allmulti_enable(mode, bitmask) \
  143. is_xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
  144. #define is_allmulti_disable(mode, bitmask) \
  145. is_xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
  146. #define allmulti_enable(mode, bitmask) \
  147. xxx_enable(mode, bitmask, BNA_RXMODE_ALLMULTI)
  148. #define allmulti_disable(mode, bitmask) \
  149. xxx_disable(mode, bitmask, BNA_RXMODE_ALLMULTI)
  150. #define allmulti_inactive(mode, bitmask) \
  151. xxx_inactive(mode, bitmask, BNA_RXMODE_ALLMULTI)
  152. #define GET_RXQS(rxp, q0, q1) do { \
  153. switch ((rxp)->type) { \
  154. case BNA_RXP_SINGLE: \
  155. (q0) = rxp->rxq.single.only; \
  156. (q1) = NULL; \
  157. break; \
  158. case BNA_RXP_SLR: \
  159. (q0) = rxp->rxq.slr.large; \
  160. (q1) = rxp->rxq.slr.small; \
  161. break; \
  162. case BNA_RXP_HDS: \
  163. (q0) = rxp->rxq.hds.data; \
  164. (q1) = rxp->rxq.hds.hdr; \
  165. break; \
  166. } \
  167. } while (0)
  168. #define bna_tx_rid_mask(_bna) ((_bna)->tx_mod.rid_mask)
  169. #define bna_rx_rid_mask(_bna) ((_bna)->rx_mod.rid_mask)
  170. #define bna_tx_from_rid(_bna, _rid, _tx) \
  171. do { \
  172. struct bna_tx_mod *__tx_mod = &(_bna)->tx_mod; \
  173. struct bna_tx *__tx; \
  174. _tx = NULL; \
  175. list_for_each_entry(__tx, &__tx_mod->tx_active_q, qe) { \
  176. if (__tx->rid == (_rid)) { \
  177. (_tx) = __tx; \
  178. break; \
  179. } \
  180. } \
  181. } while (0)
  182. #define bna_rx_from_rid(_bna, _rid, _rx) \
  183. do { \
  184. struct bna_rx_mod *__rx_mod = &(_bna)->rx_mod; \
  185. struct bna_rx *__rx; \
  186. _rx = NULL; \
  187. list_for_each_entry(__rx, &__rx_mod->rx_active_q, qe) { \
  188. if (__rx->rid == (_rid)) { \
  189. (_rx) = __rx; \
  190. break; \
  191. } \
  192. } \
  193. } while (0)
  194. #define bna_mcam_mod_free_q(_bna) (&(_bna)->mcam_mod.free_q)
  195. #define bna_mcam_mod_del_q(_bna) (&(_bna)->mcam_mod.del_q)
  196. #define bna_ucam_mod_free_q(_bna) (&(_bna)->ucam_mod.free_q)
  197. #define bna_ucam_mod_del_q(_bna) (&(_bna)->ucam_mod.del_q)
  198. /* Inline functions */
  199. static inline struct bna_mac *bna_mac_find(struct list_head *q, const u8 *addr)
  200. {
  201. struct bna_mac *mac;
  202. list_for_each_entry(mac, q, qe)
  203. if (ether_addr_equal(mac->addr, addr))
  204. return mac;
  205. return NULL;
  206. }
  207. #define bna_attr(_bna) (&(_bna)->ioceth.attr)
  208. /* Function prototypes */
  209. /* BNA */
  210. /* FW response handlers */
  211. void bna_bfi_stats_clr_rsp(struct bna *bna, struct bfi_msgq_mhdr *msghdr);
  212. /* APIs for BNAD */
  213. void bna_res_req(struct bna_res_info *res_info);
  214. void bna_mod_res_req(struct bna *bna, struct bna_res_info *res_info);
  215. void bna_init(struct bna *bna, struct bnad *bnad,
  216. struct bfa_pcidev *pcidev,
  217. struct bna_res_info *res_info);
  218. void bna_mod_init(struct bna *bna, struct bna_res_info *res_info);
  219. void bna_uninit(struct bna *bna);
  220. int bna_num_txq_set(struct bna *bna, int num_txq);
  221. int bna_num_rxp_set(struct bna *bna, int num_rxp);
  222. void bna_hw_stats_get(struct bna *bna);
  223. /* APIs for RxF */
  224. struct bna_mac *bna_cam_mod_mac_get(struct list_head *head);
  225. struct bna_mcam_handle *bna_mcam_mod_handle_get(struct bna_mcam_mod *mod);
  226. void bna_mcam_mod_handle_put(struct bna_mcam_mod *mcam_mod,
  227. struct bna_mcam_handle *handle);
  228. /* MBOX */
  229. /* API for BNAD */
  230. void bna_mbox_handler(struct bna *bna, u32 intr_status);
  231. /* ETHPORT */
  232. /* Callbacks for RX */
  233. void bna_ethport_cb_rx_started(struct bna_ethport *ethport);
  234. void bna_ethport_cb_rx_stopped(struct bna_ethport *ethport);
  235. /* TX MODULE AND TX */
  236. /* FW response handelrs */
  237. void bna_bfi_tx_enet_start_rsp(struct bna_tx *tx,
  238. struct bfi_msgq_mhdr *msghdr);
  239. void bna_bfi_tx_enet_stop_rsp(struct bna_tx *tx,
  240. struct bfi_msgq_mhdr *msghdr);
  241. void bna_bfi_bw_update_aen(struct bna_tx_mod *tx_mod);
  242. /* APIs for BNA */
  243. void bna_tx_mod_init(struct bna_tx_mod *tx_mod, struct bna *bna,
  244. struct bna_res_info *res_info);
  245. void bna_tx_mod_uninit(struct bna_tx_mod *tx_mod);
  246. /* APIs for ENET */
  247. void bna_tx_mod_start(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
  248. void bna_tx_mod_stop(struct bna_tx_mod *tx_mod, enum bna_tx_type type);
  249. void bna_tx_mod_fail(struct bna_tx_mod *tx_mod);
  250. /* APIs for BNAD */
  251. void bna_tx_res_req(int num_txq, int txq_depth,
  252. struct bna_res_info *res_info);
  253. struct bna_tx *bna_tx_create(struct bna *bna, struct bnad *bnad,
  254. struct bna_tx_config *tx_cfg,
  255. const struct bna_tx_event_cbfn *tx_cbfn,
  256. struct bna_res_info *res_info, void *priv);
  257. void bna_tx_destroy(struct bna_tx *tx);
  258. void bna_tx_enable(struct bna_tx *tx);
  259. void bna_tx_disable(struct bna_tx *tx, enum bna_cleanup_type type,
  260. void (*cbfn)(void *, struct bna_tx *));
  261. void bna_tx_cleanup_complete(struct bna_tx *tx);
  262. void bna_tx_coalescing_timeo_set(struct bna_tx *tx, int coalescing_timeo);
  263. /* RX MODULE, RX, RXF */
  264. /* FW response handlers */
  265. void bna_bfi_rx_enet_start_rsp(struct bna_rx *rx,
  266. struct bfi_msgq_mhdr *msghdr);
  267. void bna_bfi_rx_enet_stop_rsp(struct bna_rx *rx,
  268. struct bfi_msgq_mhdr *msghdr);
  269. void bna_bfi_rxf_cfg_rsp(struct bna_rxf *rxf, struct bfi_msgq_mhdr *msghdr);
  270. void bna_bfi_rxf_mcast_add_rsp(struct bna_rxf *rxf,
  271. struct bfi_msgq_mhdr *msghdr);
  272. void bna_bfi_rxf_ucast_set_rsp(struct bna_rxf *rxf,
  273. struct bfi_msgq_mhdr *msghdr);
  274. /* APIs for BNA */
  275. void bna_rx_mod_init(struct bna_rx_mod *rx_mod, struct bna *bna,
  276. struct bna_res_info *res_info);
  277. void bna_rx_mod_uninit(struct bna_rx_mod *rx_mod);
  278. /* APIs for ENET */
  279. void bna_rx_mod_start(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
  280. void bna_rx_mod_stop(struct bna_rx_mod *rx_mod, enum bna_rx_type type);
  281. void bna_rx_mod_fail(struct bna_rx_mod *rx_mod);
  282. /* APIs for BNAD */
  283. void bna_rx_res_req(struct bna_rx_config *rx_config,
  284. struct bna_res_info *res_info);
  285. struct bna_rx *bna_rx_create(struct bna *bna, struct bnad *bnad,
  286. struct bna_rx_config *rx_cfg,
  287. const struct bna_rx_event_cbfn *rx_cbfn,
  288. struct bna_res_info *res_info, void *priv);
  289. void bna_rx_destroy(struct bna_rx *rx);
  290. void bna_rx_enable(struct bna_rx *rx);
  291. void bna_rx_disable(struct bna_rx *rx, enum bna_cleanup_type type,
  292. void (*cbfn)(void *, struct bna_rx *));
  293. void bna_rx_cleanup_complete(struct bna_rx *rx);
  294. void bna_rx_coalescing_timeo_set(struct bna_rx *rx, int coalescing_timeo);
  295. void bna_rx_dim_reconfig(struct bna *bna, const u32 vector[][BNA_BIAS_T_MAX]);
  296. void bna_rx_dim_update(struct bna_ccb *ccb);
  297. enum bna_cb_status bna_rx_ucast_set(struct bna_rx *rx, const u8 *ucmac);
  298. enum bna_cb_status bna_rx_ucast_listset(struct bna_rx *rx, int count,
  299. const u8 *uclist);
  300. enum bna_cb_status bna_rx_mcast_add(struct bna_rx *rx, const u8 *mcmac,
  301. void (*cbfn)(struct bnad *,
  302. struct bna_rx *));
  303. enum bna_cb_status bna_rx_mcast_listset(struct bna_rx *rx, int count,
  304. const u8 *mcmac);
  305. void
  306. bna_rx_mcast_delall(struct bna_rx *rx);
  307. enum bna_cb_status
  308. bna_rx_mode_set(struct bna_rx *rx, enum bna_rxmode rxmode,
  309. enum bna_rxmode bitmask);
  310. void bna_rx_vlan_add(struct bna_rx *rx, int vlan_id);
  311. void bna_rx_vlan_del(struct bna_rx *rx, int vlan_id);
  312. void bna_rx_vlanfilter_enable(struct bna_rx *rx);
  313. void bna_rx_vlan_strip_enable(struct bna_rx *rx);
  314. void bna_rx_vlan_strip_disable(struct bna_rx *rx);
  315. /* ENET */
  316. /* API for RX */
  317. int bna_enet_mtu_get(struct bna_enet *enet);
  318. /* Callbacks for TX, RX */
  319. void bna_enet_cb_tx_stopped(struct bna_enet *enet);
  320. void bna_enet_cb_rx_stopped(struct bna_enet *enet);
  321. /* API for BNAD */
  322. void bna_enet_enable(struct bna_enet *enet);
  323. void bna_enet_disable(struct bna_enet *enet, enum bna_cleanup_type type,
  324. void (*cbfn)(void *));
  325. void bna_enet_pause_config(struct bna_enet *enet,
  326. struct bna_pause_config *pause_config);
  327. void bna_enet_mtu_set(struct bna_enet *enet, int mtu,
  328. void (*cbfn)(struct bnad *));
  329. void bna_enet_perm_mac_get(struct bna_enet *enet, u8 *mac);
  330. /* IOCETH */
  331. /* APIs for BNAD */
  332. void bna_ioceth_enable(struct bna_ioceth *ioceth);
  333. void bna_ioceth_disable(struct bna_ioceth *ioceth,
  334. enum bna_cleanup_type type);
  335. /* BNAD */
  336. /* Callbacks for ENET */
  337. void bnad_cb_ethport_link_status(struct bnad *bnad,
  338. enum bna_link_status status);
  339. /* Callbacks for IOCETH */
  340. void bnad_cb_ioceth_ready(struct bnad *bnad);
  341. void bnad_cb_ioceth_failed(struct bnad *bnad);
  342. void bnad_cb_ioceth_disabled(struct bnad *bnad);
  343. void bnad_cb_mbox_intr_enable(struct bnad *bnad);
  344. void bnad_cb_mbox_intr_disable(struct bnad *bnad);
  345. /* Callbacks for BNA */
  346. void bnad_cb_stats_get(struct bnad *bnad, enum bna_cb_status status,
  347. struct bna_stats *stats);
  348. #endif /* __BNA_H__ */