bnad.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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.0"
  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_JUMBO_MTU 9000
  74. #define BNAD_NETIF_WAKE_THRESHOLD 8
  75. #define BNAD_RXQ_REFILL_THRESHOLD_SHIFT 3
  76. /* Bit positions for tcb->flags */
  77. #define BNAD_TXQ_FREE_SENT 0
  78. #define BNAD_TXQ_TX_STARTED 1
  79. /* Bit positions for rcb->flags */
  80. #define BNAD_RXQ_REFILL 0
  81. #define BNAD_RXQ_STARTED 1
  82. /* Resource limits */
  83. #define BNAD_NUM_TXQ (bnad->num_tx * bnad->num_txq_per_tx)
  84. #define BNAD_NUM_RXP (bnad->num_rx * bnad->num_rxp_per_rx)
  85. /*
  86. * DATA STRUCTURES
  87. */
  88. /* enums */
  89. enum bnad_intr_source {
  90. BNAD_INTR_TX = 1,
  91. BNAD_INTR_RX = 2
  92. };
  93. enum bnad_link_state {
  94. BNAD_LS_DOWN = 0,
  95. BNAD_LS_UP = 1
  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 hw_stats_updates;
  141. u64 netif_rx_dropped;
  142. u64 link_toggle;
  143. u64 cee_toggle;
  144. u64 rxp_info_alloc_failed;
  145. u64 mbox_intr_disabled;
  146. u64 mbox_intr_enabled;
  147. u64 tx_unmap_q_alloc_failed;
  148. u64 rx_unmap_q_alloc_failed;
  149. u64 rxbuf_alloc_failed;
  150. };
  151. /* Complete driver stats */
  152. struct bnad_stats {
  153. struct bnad_drv_stats drv_stats;
  154. struct bna_stats *bna_stats;
  155. };
  156. /* Tx / Rx Resources */
  157. struct bnad_tx_res_info {
  158. struct bna_res_info res_info[BNA_TX_RES_T_MAX];
  159. };
  160. struct bnad_rx_res_info {
  161. struct bna_res_info res_info[BNA_RX_RES_T_MAX];
  162. };
  163. struct bnad_tx_info {
  164. struct bna_tx *tx; /* 1:1 between tx_info & tx */
  165. struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
  166. u32 tx_id;
  167. } ____cacheline_aligned;
  168. struct bnad_rx_info {
  169. struct bna_rx *rx; /* 1:1 between rx_info & rx */
  170. struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXP_PER_RX];
  171. u32 rx_id;
  172. } ____cacheline_aligned;
  173. /* Unmap queues for Tx / Rx cleanup */
  174. struct bnad_skb_unmap {
  175. struct sk_buff *skb;
  176. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  177. };
  178. struct bnad_unmap_q {
  179. u32 producer_index;
  180. u32 consumer_index;
  181. u32 q_depth;
  182. /* This should be the last one */
  183. struct bnad_skb_unmap unmap_array[1];
  184. };
  185. /* Bit mask values for bnad->cfg_flags */
  186. #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
  187. #define BNAD_CF_PROMISC 0x02
  188. #define BNAD_CF_ALLMULTI 0x04
  189. #define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
  190. /* Defines for run_flags bit-mask */
  191. /* Set, tested & cleared using xxx_bit() functions */
  192. /* Values indicated bit positions */
  193. #define BNAD_RF_CEE_RUNNING 0
  194. #define BNAD_RF_MTU_SET 1
  195. #define BNAD_RF_MBOX_IRQ_DISABLED 2
  196. #define BNAD_RF_NETDEV_REGISTERED 3
  197. #define BNAD_RF_DIM_TIMER_RUNNING 4
  198. #define BNAD_RF_STATS_TIMER_RUNNING 5
  199. #define BNAD_RF_TX_PRIO_SET 6
  200. /* Define for Fast Path flags */
  201. /* Defined as bit positions */
  202. #define BNAD_FP_IN_RX_PATH 0
  203. struct bnad {
  204. struct net_device *netdev;
  205. /* Data path */
  206. struct bnad_tx_info tx_info[BNAD_MAX_TX];
  207. struct bnad_rx_info rx_info[BNAD_MAX_RX];
  208. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  209. /*
  210. * These q numbers are global only because
  211. * they are used to calculate MSIx vectors.
  212. * Actually the exact # of queues are per Tx/Rx
  213. * object.
  214. */
  215. u32 num_tx;
  216. u32 num_rx;
  217. u32 num_txq_per_tx;
  218. u32 num_rxp_per_rx;
  219. u32 txq_depth;
  220. u32 rxq_depth;
  221. u8 tx_coalescing_timeo;
  222. u8 rx_coalescing_timeo;
  223. struct bna_rx_config rx_config[BNAD_MAX_RX];
  224. struct bna_tx_config tx_config[BNAD_MAX_TX];
  225. void __iomem *bar0; /* BAR0 address */
  226. struct bna bna;
  227. u32 cfg_flags;
  228. unsigned long run_flags;
  229. struct pci_dev *pcidev;
  230. u64 mmio_start;
  231. u64 mmio_len;
  232. u32 msix_num;
  233. struct msix_entry *msix_table;
  234. struct mutex conf_mutex;
  235. spinlock_t bna_lock ____cacheline_aligned;
  236. /* Timers */
  237. struct timer_list ioc_timer;
  238. struct timer_list dim_timer;
  239. struct timer_list stats_timer;
  240. /* Control path resources, memory & irq */
  241. struct bna_res_info res_info[BNA_RES_T_MAX];
  242. struct bna_res_info mod_res_info[BNA_MOD_RES_T_MAX];
  243. struct bnad_tx_res_info tx_res_info[BNAD_MAX_TX];
  244. struct bnad_rx_res_info rx_res_info[BNAD_MAX_RX];
  245. struct bnad_completion bnad_completions;
  246. /* Burnt in MAC address */
  247. mac_t perm_addr;
  248. struct tasklet_struct tx_free_tasklet;
  249. /* Statistics */
  250. struct bnad_stats stats;
  251. struct bnad_diag *diag;
  252. char adapter_name[BNAD_NAME_LEN];
  253. char port_name[BNAD_NAME_LEN];
  254. char mbox_irq_name[BNAD_NAME_LEN];
  255. };
  256. /*
  257. * EXTERN VARIABLES
  258. */
  259. extern struct firmware *bfi_fw;
  260. extern u32 bnad_rxqs_per_cq;
  261. /*
  262. * EXTERN PROTOTYPES
  263. */
  264. extern u32 *cna_get_firmware_buf(struct pci_dev *pdev);
  265. /* Netdev entry point prototypes */
  266. extern void bnad_set_ethtool_ops(struct net_device *netdev);
  267. /* Configuration & setup */
  268. extern void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
  269. extern void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
  270. extern int bnad_setup_rx(struct bnad *bnad, u32 rx_id);
  271. extern int bnad_setup_tx(struct bnad *bnad, u32 tx_id);
  272. extern void bnad_cleanup_tx(struct bnad *bnad, u32 tx_id);
  273. extern void bnad_cleanup_rx(struct bnad *bnad, u32 rx_id);
  274. /* Timer start/stop protos */
  275. extern void bnad_dim_timer_start(struct bnad *bnad);
  276. /* Statistics */
  277. extern void bnad_netdev_qstats_fill(struct bnad *bnad,
  278. struct rtnl_link_stats64 *stats);
  279. extern void bnad_netdev_hwstats_fill(struct bnad *bnad,
  280. struct rtnl_link_stats64 *stats);
  281. /**
  282. * MACROS
  283. */
  284. /* To set & get the stats counters */
  285. #define BNAD_UPDATE_CTR(_bnad, _ctr) \
  286. (((_bnad)->stats.drv_stats._ctr)++)
  287. #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
  288. #define bnad_enable_rx_irq_unsafe(_ccb) \
  289. { \
  290. if (likely(test_bit(BNAD_RXQ_STARTED, &(_ccb)->rcb[0]->flags))) {\
  291. bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
  292. (_ccb)->rx_coalescing_timeo); \
  293. bna_ib_ack((_ccb)->i_dbell, 0); \
  294. } \
  295. }
  296. #define bnad_dim_timer_running(_bnad) \
  297. (((_bnad)->cfg_flags & BNAD_CF_DIM_ENABLED) && \
  298. (test_bit(BNAD_RF_DIM_TIMER_RUNNING, &((_bnad)->run_flags))))
  299. #endif /* __BNAD_H__ */