bnad.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Linux network driver for QLogic BR-series Converged Network Adapter.
  4. */
  5. /*
  6. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  7. * Copyright (c) 2014-2015 QLogic Corporation
  8. * All rights reserved
  9. * www.qlogic.com
  10. */
  11. #ifndef __BNAD_H__
  12. #define __BNAD_H__
  13. #include <linux/rtnetlink.h>
  14. #include <linux/workqueue.h>
  15. #include <linux/ipv6.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/mutex.h>
  18. #include <linux/firmware.h>
  19. #include <linux/if_vlan.h>
  20. /* Fix for IA64 */
  21. #include <asm/checksum.h>
  22. #include <net/ip6_checksum.h>
  23. #include <net/ip.h>
  24. #include <net/tcp.h>
  25. #include "bna.h"
  26. #define BNAD_TXQ_DEPTH 2048
  27. #define BNAD_RXQ_DEPTH 2048
  28. #define BNAD_MAX_TX 1
  29. #define BNAD_MAX_TXQ_PER_TX 8 /* 8 priority queues */
  30. #define BNAD_TXQ_NUM 1
  31. #define BNAD_MAX_RX 1
  32. #define BNAD_MAX_RXP_PER_RX 16
  33. #define BNAD_MAX_RXQ_PER_RXP 2
  34. /*
  35. * Control structure pointed to ccb->ctrl, which
  36. * determines the NAPI / LRO behavior CCB
  37. * There is 1:1 corres. between ccb & ctrl
  38. */
  39. struct bnad_rx_ctrl {
  40. struct bna_ccb *ccb;
  41. struct bnad *bnad;
  42. unsigned long flags;
  43. struct napi_struct napi;
  44. u64 rx_intr_ctr;
  45. u64 rx_poll_ctr;
  46. u64 rx_schedule;
  47. u64 rx_keep_poll;
  48. u64 rx_complete;
  49. };
  50. #define BNAD_RXMODE_PROMISC_DEFAULT BNA_RXMODE_PROMISC
  51. /*
  52. * GLOBAL #defines (CONSTANTS)
  53. */
  54. #define BNAD_NAME "bna"
  55. #define BNAD_NAME_LEN 64
  56. #define BNAD_MAILBOX_MSIX_INDEX 0
  57. #define BNAD_MAILBOX_MSIX_VECTORS 1
  58. #define BNAD_INTX_TX_IB_BITMASK 0x1
  59. #define BNAD_INTX_RX_IB_BITMASK 0x2
  60. #define BNAD_STATS_TIMER_FREQ 1000 /* in msecs */
  61. #define BNAD_DIM_TIMER_FREQ 1000 /* in msecs */
  62. #define BNAD_IOCETH_TIMEOUT 10000
  63. #define BNAD_MIN_Q_DEPTH 512
  64. #define BNAD_MAX_RXQ_DEPTH 16384
  65. #define BNAD_MAX_TXQ_DEPTH 2048
  66. #define BNAD_JUMBO_MTU 9000
  67. #define BNAD_NETIF_WAKE_THRESHOLD 8
  68. #define BNAD_RXQ_REFILL_THRESHOLD_SHIFT 3
  69. /* Bit positions for tcb->flags */
  70. #define BNAD_TXQ_FREE_SENT 0
  71. #define BNAD_TXQ_TX_STARTED 1
  72. /* Bit positions for rcb->flags */
  73. #define BNAD_RXQ_STARTED 0
  74. #define BNAD_RXQ_POST_OK 1
  75. /* Resource limits */
  76. #define BNAD_NUM_TXQ (bnad->num_tx * bnad->num_txq_per_tx)
  77. #define BNAD_NUM_RXP (bnad->num_rx * bnad->num_rxp_per_rx)
  78. #define BNAD_FRAME_SIZE(_mtu) \
  79. (ETH_HLEN + VLAN_HLEN + (_mtu) + ETH_FCS_LEN)
  80. /*
  81. * DATA STRUCTURES
  82. */
  83. /* enums */
  84. enum bnad_intr_source {
  85. BNAD_INTR_TX = 1,
  86. BNAD_INTR_RX = 2
  87. };
  88. enum bnad_link_state {
  89. BNAD_LS_DOWN = 0,
  90. BNAD_LS_UP = 1
  91. };
  92. struct bnad_iocmd_comp {
  93. struct bnad *bnad;
  94. struct completion comp;
  95. int comp_status;
  96. };
  97. struct bnad_completion {
  98. struct completion ioc_comp;
  99. struct completion ucast_comp;
  100. struct completion mcast_comp;
  101. struct completion tx_comp;
  102. struct completion rx_comp;
  103. struct completion stats_comp;
  104. struct completion enet_comp;
  105. struct completion mtu_comp;
  106. u8 ioc_comp_status;
  107. u8 ucast_comp_status;
  108. u8 mcast_comp_status;
  109. u8 tx_comp_status;
  110. u8 rx_comp_status;
  111. u8 stats_comp_status;
  112. u8 port_comp_status;
  113. u8 mtu_comp_status;
  114. };
  115. /* Tx Rx Control Stats */
  116. struct bnad_drv_stats {
  117. u64 netif_queue_stop;
  118. u64 netif_queue_wakeup;
  119. u64 netif_queue_stopped;
  120. u64 tso4;
  121. u64 tso6;
  122. u64 tso_err;
  123. u64 tcpcsum_offload;
  124. u64 udpcsum_offload;
  125. u64 csum_help;
  126. u64 tx_skb_too_short;
  127. u64 tx_skb_stopping;
  128. u64 tx_skb_max_vectors;
  129. u64 tx_skb_mss_too_long;
  130. u64 tx_skb_tso_too_short;
  131. u64 tx_skb_tso_prepare;
  132. u64 tx_skb_non_tso_too_long;
  133. u64 tx_skb_tcp_hdr;
  134. u64 tx_skb_udp_hdr;
  135. u64 tx_skb_csum_err;
  136. u64 tx_skb_headlen_too_long;
  137. u64 tx_skb_headlen_zero;
  138. u64 tx_skb_frag_zero;
  139. u64 tx_skb_len_mismatch;
  140. u64 tx_skb_map_failed;
  141. u64 hw_stats_updates;
  142. u64 netif_rx_dropped;
  143. u64 link_toggle;
  144. u64 cee_toggle;
  145. u64 rxp_info_alloc_failed;
  146. u64 mbox_intr_disabled;
  147. u64 mbox_intr_enabled;
  148. u64 tx_unmap_q_alloc_failed;
  149. u64 rx_unmap_q_alloc_failed;
  150. u64 rxbuf_alloc_failed;
  151. u64 rxbuf_map_failed;
  152. };
  153. /* Complete driver stats */
  154. struct bnad_stats {
  155. struct bnad_drv_stats drv_stats;
  156. struct bna_stats *bna_stats;
  157. };
  158. /* Tx / Rx Resources */
  159. struct bnad_tx_res_info {
  160. struct bna_res_info res_info[BNA_TX_RES_T_MAX];
  161. };
  162. struct bnad_rx_res_info {
  163. struct bna_res_info res_info[BNA_RX_RES_T_MAX];
  164. };
  165. struct bnad_tx_info {
  166. struct bna_tx *tx; /* 1:1 between tx_info & tx */
  167. struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
  168. u32 tx_id;
  169. struct delayed_work tx_cleanup_work;
  170. } ____cacheline_aligned;
  171. struct bnad_rx_info {
  172. struct bna_rx *rx; /* 1:1 between rx_info & rx */
  173. struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXP_PER_RX];
  174. u32 rx_id;
  175. struct work_struct rx_cleanup_work;
  176. } ____cacheline_aligned;
  177. struct bnad_tx_vector {
  178. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  179. DEFINE_DMA_UNMAP_LEN(dma_len);
  180. };
  181. struct bnad_tx_unmap {
  182. struct sk_buff *skb;
  183. u32 nvecs;
  184. struct bnad_tx_vector vectors[BFI_TX_MAX_VECTORS_PER_WI];
  185. };
  186. struct bnad_rx_vector {
  187. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  188. u32 len;
  189. };
  190. struct bnad_rx_unmap {
  191. struct page *page;
  192. struct sk_buff *skb;
  193. struct bnad_rx_vector vector;
  194. u32 page_offset;
  195. };
  196. enum bnad_rxbuf_type {
  197. BNAD_RXBUF_NONE = 0,
  198. BNAD_RXBUF_SK_BUFF = 1,
  199. BNAD_RXBUF_PAGE = 2,
  200. BNAD_RXBUF_MULTI_BUFF = 3
  201. };
  202. #define BNAD_RXBUF_IS_SK_BUFF(_type) ((_type) == BNAD_RXBUF_SK_BUFF)
  203. #define BNAD_RXBUF_IS_MULTI_BUFF(_type) ((_type) == BNAD_RXBUF_MULTI_BUFF)
  204. struct bnad_rx_unmap_q {
  205. int reuse_pi;
  206. int alloc_order;
  207. u32 map_size;
  208. enum bnad_rxbuf_type type;
  209. struct bnad_rx_unmap unmap[] ____cacheline_aligned;
  210. };
  211. #define BNAD_PCI_DEV_IS_CAT2(_bnad) \
  212. ((_bnad)->pcidev->device == BFA_PCI_DEVICE_ID_CT2)
  213. /* Bit mask values for bnad->cfg_flags */
  214. #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
  215. #define BNAD_CF_PROMISC 0x02
  216. #define BNAD_CF_ALLMULTI 0x04
  217. #define BNAD_CF_DEFAULT 0x08
  218. #define BNAD_CF_MSIX 0x10 /* If in MSIx mode */
  219. /* Defines for run_flags bit-mask */
  220. /* Set, tested & cleared using xxx_bit() functions */
  221. /* Values indicated bit positions */
  222. #define BNAD_RF_CEE_RUNNING 0
  223. #define BNAD_RF_MTU_SET 1
  224. #define BNAD_RF_MBOX_IRQ_DISABLED 2
  225. #define BNAD_RF_NETDEV_REGISTERED 3
  226. #define BNAD_RF_DIM_TIMER_RUNNING 4
  227. #define BNAD_RF_STATS_TIMER_RUNNING 5
  228. #define BNAD_RF_TX_PRIO_SET 6
  229. struct bnad {
  230. struct net_device *netdev;
  231. u32 id;
  232. /* Data path */
  233. struct bnad_tx_info tx_info[BNAD_MAX_TX];
  234. struct bnad_rx_info rx_info[BNAD_MAX_RX];
  235. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  236. /*
  237. * These q numbers are global only because
  238. * they are used to calculate MSIx vectors.
  239. * Actually the exact # of queues are per Tx/Rx
  240. * object.
  241. */
  242. u32 num_tx;
  243. u32 num_rx;
  244. u32 num_txq_per_tx;
  245. u32 num_rxp_per_rx;
  246. u32 txq_depth;
  247. u32 rxq_depth;
  248. u8 tx_coalescing_timeo;
  249. u8 rx_coalescing_timeo;
  250. struct bna_rx_config rx_config[BNAD_MAX_RX] ____cacheline_aligned;
  251. struct bna_tx_config tx_config[BNAD_MAX_TX] ____cacheline_aligned;
  252. void __iomem *bar0; /* BAR0 address */
  253. struct bna bna;
  254. u32 cfg_flags;
  255. unsigned long run_flags;
  256. struct pci_dev *pcidev;
  257. u64 mmio_start;
  258. u64 mmio_len;
  259. u32 msix_num;
  260. struct msix_entry *msix_table;
  261. struct mutex conf_mutex;
  262. spinlock_t bna_lock ____cacheline_aligned;
  263. /* Timers */
  264. struct timer_list ioc_timer;
  265. struct timer_list dim_timer;
  266. struct timer_list stats_timer;
  267. /* Control path resources, memory & irq */
  268. struct bna_res_info res_info[BNA_RES_T_MAX];
  269. struct bna_res_info mod_res_info[BNA_MOD_RES_T_MAX];
  270. struct bnad_tx_res_info tx_res_info[BNAD_MAX_TX];
  271. struct bnad_rx_res_info rx_res_info[BNAD_MAX_RX];
  272. struct bnad_completion bnad_completions;
  273. /* Burnt in MAC address */
  274. u8 perm_addr[ETH_ALEN];
  275. struct workqueue_struct *work_q;
  276. /* Statistics */
  277. struct bnad_stats stats;
  278. struct bnad_diag *diag;
  279. char adapter_name[BNAD_NAME_LEN];
  280. char port_name[BNAD_NAME_LEN];
  281. char mbox_irq_name[BNAD_NAME_LEN];
  282. char wq_name[BNAD_NAME_LEN];
  283. /* debugfs specific data */
  284. char *regdata;
  285. u32 reglen;
  286. struct dentry *bnad_dentry_files[5];
  287. struct dentry *port_debugfs_root;
  288. };
  289. struct bnad_drvinfo {
  290. struct bfa_ioc_attr ioc_attr;
  291. struct bfa_cee_attr cee_attr;
  292. struct bfa_flash_attr flash_attr;
  293. u32 cee_status;
  294. u32 flash_status;
  295. };
  296. /*
  297. * EXTERN VARIABLES
  298. */
  299. extern const struct firmware *bfi_fw;
  300. /*
  301. * EXTERN PROTOTYPES
  302. */
  303. u32 *cna_get_firmware_buf(struct pci_dev *pdev);
  304. /* Netdev entry point prototypes */
  305. void bnad_set_rx_mode(struct net_device *netdev);
  306. struct net_device_stats *bnad_get_netdev_stats(struct net_device *netdev);
  307. int bnad_mac_addr_set_locked(struct bnad *bnad, const u8 *mac_addr);
  308. int bnad_enable_default_bcast(struct bnad *bnad);
  309. void bnad_restore_vlans(struct bnad *bnad, u32 rx_id);
  310. void bnad_set_ethtool_ops(struct net_device *netdev);
  311. void bnad_cb_completion(void *arg, enum bfa_status status);
  312. /* Configuration & setup */
  313. void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
  314. void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
  315. int bnad_setup_rx(struct bnad *bnad, u32 rx_id);
  316. int bnad_setup_tx(struct bnad *bnad, u32 tx_id);
  317. void bnad_destroy_tx(struct bnad *bnad, u32 tx_id);
  318. void bnad_destroy_rx(struct bnad *bnad, u32 rx_id);
  319. /* Timer start/stop protos */
  320. void bnad_dim_timer_start(struct bnad *bnad);
  321. /* Statistics */
  322. void bnad_netdev_qstats_fill(struct bnad *bnad,
  323. struct rtnl_link_stats64 *stats);
  324. void bnad_netdev_hwstats_fill(struct bnad *bnad,
  325. struct rtnl_link_stats64 *stats);
  326. /* Debugfs */
  327. void bnad_debugfs_init(struct bnad *bnad);
  328. void bnad_debugfs_uninit(struct bnad *bnad);
  329. /* MACROS */
  330. /* To set & get the stats counters */
  331. #define BNAD_UPDATE_CTR(_bnad, _ctr) \
  332. (((_bnad)->stats.drv_stats._ctr)++)
  333. #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
  334. #define bnad_enable_rx_irq_unsafe(_ccb) \
  335. { \
  336. if (likely(test_bit(BNAD_RXQ_STARTED, &(_ccb)->rcb[0]->flags))) {\
  337. bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
  338. (_ccb)->rx_coalescing_timeo); \
  339. bna_ib_ack((_ccb)->i_dbell, 0); \
  340. } \
  341. }
  342. #endif /* __BNAD_H__ */