bnad.h 10 KB

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