bnad.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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-2010 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #ifndef __BNAD_H__
  19. #define __BNAD_H__
  20. #include <linux/rtnetlink.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/ipv6.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/mutex.h>
  25. #include <linux/firmware.h>
  26. #include <linux/if_vlan.h>
  27. /* Fix for IA64 */
  28. #include <asm/checksum.h>
  29. #include <net/ip6_checksum.h>
  30. #include <net/ip.h>
  31. #include <net/tcp.h>
  32. #include "bna.h"
  33. #define BNAD_TXQ_DEPTH 2048
  34. #define BNAD_RXQ_DEPTH 2048
  35. #define BNAD_MAX_TX 1
  36. #define BNAD_MAX_TXQ_PER_TX 8 /* 8 priority queues */
  37. #define BNAD_TXQ_NUM 1
  38. #define BNAD_MAX_RX 1
  39. #define BNAD_MAX_RXP_PER_RX 16
  40. #define BNAD_MAX_RXQ_PER_RXP 2
  41. /*
  42. * Control structure pointed to ccb->ctrl, which
  43. * determines the NAPI / LRO behavior CCB
  44. * There is 1:1 corres. between ccb & ctrl
  45. */
  46. struct bnad_rx_ctrl {
  47. struct bna_ccb *ccb;
  48. struct bnad *bnad;
  49. unsigned long flags;
  50. struct napi_struct napi;
  51. u64 rx_intr_ctr;
  52. u64 rx_poll_ctr;
  53. u64 rx_schedule;
  54. u64 rx_keep_poll;
  55. u64 rx_complete;
  56. };
  57. #define BNAD_RXMODE_PROMISC_DEFAULT BNA_RXMODE_PROMISC
  58. /*
  59. * GLOBAL #defines (CONSTANTS)
  60. */
  61. #define BNAD_NAME "bna"
  62. #define BNAD_NAME_LEN 64
  63. #define BNAD_VERSION "3.0.2.2"
  64. #define BNAD_MAILBOX_MSIX_INDEX 0
  65. #define BNAD_MAILBOX_MSIX_VECTORS 1
  66. #define BNAD_INTX_TX_IB_BITMASK 0x1
  67. #define BNAD_INTX_RX_IB_BITMASK 0x2
  68. #define BNAD_STATS_TIMER_FREQ 1000 /* in msecs */
  69. #define BNAD_DIM_TIMER_FREQ 1000 /* in msecs */
  70. #define BNAD_IOCETH_TIMEOUT 10000
  71. #define BNAD_MAX_Q_DEPTH 0x10000
  72. #define BNAD_MIN_Q_DEPTH 0x200
  73. #define BNAD_MAX_RXQ_DEPTH (BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq)
  74. /* keeping MAX TX and RX Q depth equal */
  75. #define BNAD_MAX_TXQ_DEPTH BNAD_MAX_RXQ_DEPTH
  76. #define BNAD_JUMBO_MTU 9000
  77. #define BNAD_NETIF_WAKE_THRESHOLD 8
  78. #define BNAD_RXQ_REFILL_THRESHOLD_SHIFT 3
  79. /* Bit positions for tcb->flags */
  80. #define BNAD_TXQ_FREE_SENT 0
  81. #define BNAD_TXQ_TX_STARTED 1
  82. /* Bit positions for rcb->flags */
  83. #define BNAD_RXQ_REFILL 0
  84. #define BNAD_RXQ_STARTED 1
  85. #define BNAD_RXQ_POST_OK 2
  86. /* Resource limits */
  87. #define BNAD_NUM_TXQ (bnad->num_tx * bnad->num_txq_per_tx)
  88. #define BNAD_NUM_RXP (bnad->num_rx * bnad->num_rxp_per_rx)
  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_completion {
  102. struct completion ioc_comp;
  103. struct completion ucast_comp;
  104. struct completion mcast_comp;
  105. struct completion tx_comp;
  106. struct completion rx_comp;
  107. struct completion stats_comp;
  108. struct completion enet_comp;
  109. struct completion mtu_comp;
  110. u8 ioc_comp_status;
  111. u8 ucast_comp_status;
  112. u8 mcast_comp_status;
  113. u8 tx_comp_status;
  114. u8 rx_comp_status;
  115. u8 stats_comp_status;
  116. u8 port_comp_status;
  117. u8 mtu_comp_status;
  118. };
  119. /* Tx Rx Control Stats */
  120. struct bnad_drv_stats {
  121. u64 netif_queue_stop;
  122. u64 netif_queue_wakeup;
  123. u64 netif_queue_stopped;
  124. u64 tso4;
  125. u64 tso6;
  126. u64 tso_err;
  127. u64 tcpcsum_offload;
  128. u64 udpcsum_offload;
  129. u64 csum_help;
  130. u64 tx_skb_too_short;
  131. u64 tx_skb_stopping;
  132. u64 tx_skb_max_vectors;
  133. u64 tx_skb_mss_too_long;
  134. u64 tx_skb_tso_too_short;
  135. u64 tx_skb_tso_prepare;
  136. u64 tx_skb_non_tso_too_long;
  137. u64 tx_skb_tcp_hdr;
  138. u64 tx_skb_udp_hdr;
  139. u64 tx_skb_csum_err;
  140. u64 tx_skb_headlen_too_long;
  141. u64 tx_skb_headlen_zero;
  142. u64 tx_skb_frag_zero;
  143. u64 tx_skb_len_mismatch;
  144. u64 hw_stats_updates;
  145. u64 netif_rx_dropped;
  146. u64 link_toggle;
  147. u64 cee_toggle;
  148. u64 rxp_info_alloc_failed;
  149. u64 mbox_intr_disabled;
  150. u64 mbox_intr_enabled;
  151. u64 tx_unmap_q_alloc_failed;
  152. u64 rx_unmap_q_alloc_failed;
  153. u64 rxbuf_alloc_failed;
  154. };
  155. /* Complete driver stats */
  156. struct bnad_stats {
  157. struct bnad_drv_stats drv_stats;
  158. struct bna_stats *bna_stats;
  159. };
  160. /* Tx / Rx Resources */
  161. struct bnad_tx_res_info {
  162. struct bna_res_info res_info[BNA_TX_RES_T_MAX];
  163. };
  164. struct bnad_rx_res_info {
  165. struct bna_res_info res_info[BNA_RX_RES_T_MAX];
  166. };
  167. struct bnad_tx_info {
  168. struct bna_tx *tx; /* 1:1 between tx_info & tx */
  169. struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
  170. u32 tx_id;
  171. } ____cacheline_aligned;
  172. struct bnad_rx_info {
  173. struct bna_rx *rx; /* 1:1 between rx_info & rx */
  174. struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXP_PER_RX];
  175. u32 rx_id;
  176. } ____cacheline_aligned;
  177. /* Unmap queues for Tx / Rx cleanup */
  178. struct bnad_skb_unmap {
  179. struct sk_buff *skb;
  180. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  181. };
  182. struct bnad_unmap_q {
  183. u32 producer_index;
  184. u32 consumer_index;
  185. u32 q_depth;
  186. /* This should be the last one */
  187. struct bnad_skb_unmap unmap_array[1];
  188. };
  189. /* Bit mask values for bnad->cfg_flags */
  190. #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
  191. #define BNAD_CF_PROMISC 0x02
  192. #define BNAD_CF_ALLMULTI 0x04
  193. #define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
  194. /* Defines for run_flags bit-mask */
  195. /* Set, tested & cleared using xxx_bit() functions */
  196. /* Values indicated bit positions */
  197. #define BNAD_RF_CEE_RUNNING 0
  198. #define BNAD_RF_MTU_SET 1
  199. #define BNAD_RF_MBOX_IRQ_DISABLED 2
  200. #define BNAD_RF_NETDEV_REGISTERED 3
  201. #define BNAD_RF_DIM_TIMER_RUNNING 4
  202. #define BNAD_RF_STATS_TIMER_RUNNING 5
  203. #define BNAD_RF_TX_PRIO_SET 6
  204. /* Define for Fast Path flags */
  205. /* Defined as bit positions */
  206. #define BNAD_FP_IN_RX_PATH 0
  207. struct bnad {
  208. struct net_device *netdev;
  209. /* Data path */
  210. struct bnad_tx_info tx_info[BNAD_MAX_TX];
  211. struct bnad_rx_info rx_info[BNAD_MAX_RX];
  212. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  213. /*
  214. * These q numbers are global only because
  215. * they are used to calculate MSIx vectors.
  216. * Actually the exact # of queues are per Tx/Rx
  217. * object.
  218. */
  219. u32 num_tx;
  220. u32 num_rx;
  221. u32 num_txq_per_tx;
  222. u32 num_rxp_per_rx;
  223. u32 txq_depth;
  224. u32 rxq_depth;
  225. u8 tx_coalescing_timeo;
  226. u8 rx_coalescing_timeo;
  227. struct bna_rx_config rx_config[BNAD_MAX_RX];
  228. struct bna_tx_config tx_config[BNAD_MAX_TX];
  229. void __iomem *bar0; /* BAR0 address */
  230. struct bna bna;
  231. u32 cfg_flags;
  232. unsigned long run_flags;
  233. struct pci_dev *pcidev;
  234. u64 mmio_start;
  235. u64 mmio_len;
  236. u32 msix_num;
  237. struct msix_entry *msix_table;
  238. struct mutex conf_mutex;
  239. spinlock_t bna_lock ____cacheline_aligned;
  240. /* Timers */
  241. struct timer_list ioc_timer;
  242. struct timer_list dim_timer;
  243. struct timer_list stats_timer;
  244. /* Control path resources, memory & irq */
  245. struct bna_res_info res_info[BNA_RES_T_MAX];
  246. struct bna_res_info mod_res_info[BNA_MOD_RES_T_MAX];
  247. struct bnad_tx_res_info tx_res_info[BNAD_MAX_TX];
  248. struct bnad_rx_res_info rx_res_info[BNAD_MAX_RX];
  249. struct bnad_completion bnad_completions;
  250. /* Burnt in MAC address */
  251. mac_t perm_addr;
  252. struct tasklet_struct tx_free_tasklet;
  253. /* Statistics */
  254. struct bnad_stats stats;
  255. struct bnad_diag *diag;
  256. char adapter_name[BNAD_NAME_LEN];
  257. char port_name[BNAD_NAME_LEN];
  258. char mbox_irq_name[BNAD_NAME_LEN];
  259. };
  260. /*
  261. * EXTERN VARIABLES
  262. */
  263. extern struct firmware *bfi_fw;
  264. extern u32 bnad_rxqs_per_cq;
  265. /*
  266. * EXTERN PROTOTYPES
  267. */
  268. extern u32 *cna_get_firmware_buf(struct pci_dev *pdev);
  269. /* Netdev entry point prototypes */
  270. extern void bnad_set_rx_mode(struct net_device *netdev);
  271. extern struct net_device_stats *bnad_get_netdev_stats(
  272. struct net_device *netdev);
  273. extern int bnad_mac_addr_set_locked(struct bnad *bnad, u8 *mac_addr);
  274. extern int bnad_enable_default_bcast(struct bnad *bnad);
  275. extern void bnad_restore_vlans(struct bnad *bnad, u32 rx_id);
  276. extern void bnad_set_ethtool_ops(struct net_device *netdev);
  277. /* Configuration & setup */
  278. extern void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
  279. extern void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
  280. extern int bnad_setup_rx(struct bnad *bnad, u32 rx_id);
  281. extern int bnad_setup_tx(struct bnad *bnad, u32 tx_id);
  282. extern void bnad_cleanup_tx(struct bnad *bnad, u32 tx_id);
  283. extern void bnad_cleanup_rx(struct bnad *bnad, u32 rx_id);
  284. /* Timer start/stop protos */
  285. extern void bnad_dim_timer_start(struct bnad *bnad);
  286. /* Statistics */
  287. extern void bnad_netdev_qstats_fill(struct bnad *bnad,
  288. struct rtnl_link_stats64 *stats);
  289. extern void bnad_netdev_hwstats_fill(struct bnad *bnad,
  290. struct rtnl_link_stats64 *stats);
  291. /**
  292. * MACROS
  293. */
  294. /* To set & get the stats counters */
  295. #define BNAD_UPDATE_CTR(_bnad, _ctr) \
  296. (((_bnad)->stats.drv_stats._ctr)++)
  297. #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
  298. #define bnad_enable_rx_irq_unsafe(_ccb) \
  299. { \
  300. if (likely(test_bit(BNAD_RXQ_STARTED, &(_ccb)->rcb[0]->flags))) {\
  301. bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
  302. (_ccb)->rx_coalescing_timeo); \
  303. bna_ib_ack((_ccb)->i_dbell, 0); \
  304. } \
  305. }
  306. #endif /* __BNAD_H__ */