bnad.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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_TXS 1
  36. #define BNAD_MAX_TXQ_PER_TX 8 /* 8 priority queues */
  37. #define BNAD_TXQ_NUM 1
  38. #define BNAD_MAX_RXS 1
  39. #define BNAD_MAX_RXPS_PER_RX 16
  40. /*
  41. * Control structure pointed to ccb->ctrl, which
  42. * determines the NAPI / LRO behavior CCB
  43. * There is 1:1 corres. between ccb & ctrl
  44. */
  45. struct bnad_rx_ctrl {
  46. struct bna_ccb *ccb;
  47. unsigned long flags;
  48. struct napi_struct napi;
  49. };
  50. #define BNAD_RXMODE_PROMISC_DEFAULT BNA_RXMODE_PROMISC
  51. #define BNAD_GET_TX_ID(_skb) (0)
  52. /*
  53. * GLOBAL #defines (CONSTANTS)
  54. */
  55. #define BNAD_NAME "bna"
  56. #define BNAD_NAME_LEN 64
  57. #define BNAD_VERSION "2.3.2.3"
  58. #define BNAD_MAILBOX_MSIX_INDEX 0
  59. #define BNAD_MAILBOX_MSIX_VECTORS 1
  60. #define BNAD_INTX_TX_IB_BITMASK 0x1
  61. #define BNAD_INTX_RX_IB_BITMASK 0x2
  62. #define BNAD_STATS_TIMER_FREQ 1000 /* in msecs */
  63. #define BNAD_DIM_TIMER_FREQ 1000 /* in msecs */
  64. #define BNAD_MAX_Q_DEPTH 0x10000
  65. #define BNAD_MIN_Q_DEPTH 0x200
  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_REFILL 0
  74. #define BNAD_RXQ_STARTED 1
  75. /*
  76. * DATA STRUCTURES
  77. */
  78. /* enums */
  79. enum bnad_intr_source {
  80. BNAD_INTR_TX = 1,
  81. BNAD_INTR_RX = 2
  82. };
  83. enum bnad_link_state {
  84. BNAD_LS_DOWN = 0,
  85. BNAD_LS_UP = 1
  86. };
  87. struct bnad_completion {
  88. struct completion ioc_comp;
  89. struct completion ucast_comp;
  90. struct completion mcast_comp;
  91. struct completion tx_comp;
  92. struct completion rx_comp;
  93. struct completion stats_comp;
  94. struct completion port_comp;
  95. u8 ioc_comp_status;
  96. u8 ucast_comp_status;
  97. u8 mcast_comp_status;
  98. u8 tx_comp_status;
  99. u8 rx_comp_status;
  100. u8 stats_comp_status;
  101. u8 port_comp_status;
  102. };
  103. /* Tx Rx Control Stats */
  104. struct bnad_drv_stats {
  105. u64 netif_queue_stop;
  106. u64 netif_queue_wakeup;
  107. u64 netif_queue_stopped;
  108. u64 tso4;
  109. u64 tso6;
  110. u64 tso_err;
  111. u64 tcpcsum_offload;
  112. u64 udpcsum_offload;
  113. u64 csum_help;
  114. u64 csum_help_err;
  115. u64 hw_stats_updates;
  116. u64 netif_rx_schedule;
  117. u64 netif_rx_complete;
  118. u64 netif_rx_dropped;
  119. u64 link_toggle;
  120. u64 cee_up;
  121. u64 rxp_info_alloc_failed;
  122. u64 mbox_intr_disabled;
  123. u64 mbox_intr_enabled;
  124. u64 tx_unmap_q_alloc_failed;
  125. u64 rx_unmap_q_alloc_failed;
  126. u64 rxbuf_alloc_failed;
  127. };
  128. /* Complete driver stats */
  129. struct bnad_stats {
  130. struct bnad_drv_stats drv_stats;
  131. struct bna_stats *bna_stats;
  132. };
  133. /* Tx / Rx Resources */
  134. struct bnad_tx_res_info {
  135. struct bna_res_info res_info[BNA_TX_RES_T_MAX];
  136. };
  137. struct bnad_rx_res_info {
  138. struct bna_res_info res_info[BNA_RX_RES_T_MAX];
  139. };
  140. struct bnad_tx_info {
  141. struct bna_tx *tx; /* 1:1 between tx_info & tx */
  142. struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
  143. } ____cacheline_aligned;
  144. struct bnad_rx_info {
  145. struct bna_rx *rx; /* 1:1 between rx_info & rx */
  146. struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXPS_PER_RX];
  147. } ____cacheline_aligned;
  148. /* Unmap queues for Tx / Rx cleanup */
  149. struct bnad_skb_unmap {
  150. struct sk_buff *skb;
  151. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  152. };
  153. struct bnad_unmap_q {
  154. u32 producer_index;
  155. u32 consumer_index;
  156. u32 q_depth;
  157. /* This should be the last one */
  158. struct bnad_skb_unmap unmap_array[1];
  159. };
  160. /* Bit mask values for bnad->cfg_flags */
  161. #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
  162. #define BNAD_CF_PROMISC 0x02
  163. #define BNAD_CF_ALLMULTI 0x04
  164. #define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
  165. /* Defines for run_flags bit-mask */
  166. /* Set, tested & cleared using xxx_bit() functions */
  167. /* Values indicated bit positions */
  168. #define BNAD_RF_CEE_RUNNING 1
  169. #define BNAD_RF_MBOX_IRQ_DISABLED 2
  170. #define BNAD_RF_RX_STARTED 3
  171. #define BNAD_RF_DIM_TIMER_RUNNING 4
  172. #define BNAD_RF_STATS_TIMER_RUNNING 5
  173. #define BNAD_RF_TX_SHUTDOWN_DELAYED 6
  174. #define BNAD_RF_RX_SHUTDOWN_DELAYED 7
  175. struct bnad {
  176. struct net_device *netdev;
  177. /* Data path */
  178. struct bnad_tx_info tx_info[BNAD_MAX_TXS];
  179. struct bnad_rx_info rx_info[BNAD_MAX_RXS];
  180. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  181. /*
  182. * These q numbers are global only because
  183. * they are used to calculate MSIx vectors.
  184. * Actually the exact # of queues are per Tx/Rx
  185. * object.
  186. */
  187. u32 num_tx;
  188. u32 num_rx;
  189. u32 num_txq_per_tx;
  190. u32 num_rxp_per_rx;
  191. u32 txq_depth;
  192. u32 rxq_depth;
  193. u8 tx_coalescing_timeo;
  194. u8 rx_coalescing_timeo;
  195. struct bna_rx_config rx_config[BNAD_MAX_RXS];
  196. struct bna_tx_config tx_config[BNAD_MAX_TXS];
  197. void __iomem *bar0; /* BAR0 address */
  198. struct bna bna;
  199. u32 cfg_flags;
  200. unsigned long run_flags;
  201. struct pci_dev *pcidev;
  202. u64 mmio_start;
  203. u64 mmio_len;
  204. u32 msix_num;
  205. struct msix_entry *msix_table;
  206. struct mutex conf_mutex;
  207. spinlock_t bna_lock ____cacheline_aligned;
  208. /* Timers */
  209. struct timer_list ioc_timer;
  210. struct timer_list dim_timer;
  211. struct timer_list stats_timer;
  212. /* Control path resources, memory & irq */
  213. struct bna_res_info res_info[BNA_RES_T_MAX];
  214. struct bnad_tx_res_info tx_res_info[BNAD_MAX_TXS];
  215. struct bnad_rx_res_info rx_res_info[BNAD_MAX_RXS];
  216. struct bnad_completion bnad_completions;
  217. /* Burnt in MAC address */
  218. mac_t perm_addr;
  219. struct tasklet_struct tx_free_tasklet;
  220. /* Statistics */
  221. struct bnad_stats stats;
  222. struct bnad_diag *diag;
  223. char adapter_name[BNAD_NAME_LEN];
  224. char port_name[BNAD_NAME_LEN];
  225. char mbox_irq_name[BNAD_NAME_LEN];
  226. };
  227. /*
  228. * EXTERN VARIABLES
  229. */
  230. extern struct firmware *bfi_fw;
  231. extern u32 bnad_rxqs_per_cq;
  232. /*
  233. * EXTERN PROTOTYPES
  234. */
  235. extern u32 *cna_get_firmware_buf(struct pci_dev *pdev);
  236. /* Netdev entry point prototypes */
  237. extern void bnad_set_ethtool_ops(struct net_device *netdev);
  238. /* Configuration & setup */
  239. extern void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
  240. extern void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
  241. extern int bnad_setup_rx(struct bnad *bnad, uint rx_id);
  242. extern int bnad_setup_tx(struct bnad *bnad, uint tx_id);
  243. extern void bnad_cleanup_tx(struct bnad *bnad, uint tx_id);
  244. extern void bnad_cleanup_rx(struct bnad *bnad, uint rx_id);
  245. /* Timer start/stop protos */
  246. extern void bnad_dim_timer_start(struct bnad *bnad);
  247. /* Statistics */
  248. extern void bnad_netdev_qstats_fill(struct bnad *bnad,
  249. struct rtnl_link_stats64 *stats);
  250. extern void bnad_netdev_hwstats_fill(struct bnad *bnad,
  251. struct rtnl_link_stats64 *stats);
  252. /**
  253. * MACROS
  254. */
  255. /* To set & get the stats counters */
  256. #define BNAD_UPDATE_CTR(_bnad, _ctr) \
  257. (((_bnad)->stats.drv_stats._ctr)++)
  258. #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
  259. #define bnad_enable_rx_irq_unsafe(_ccb) \
  260. { \
  261. if (likely(test_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags))) {\
  262. bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
  263. (_ccb)->rx_coalescing_timeo); \
  264. bna_ib_ack((_ccb)->i_dbell, 0); \
  265. } \
  266. }
  267. #define bnad_dim_timer_running(_bnad) \
  268. (((_bnad)->cfg_flags & BNAD_CF_DIM_ENABLED) && \
  269. (test_bit(BNAD_RF_DIM_TIMER_RUNNING, &((_bnad)->run_flags))))
  270. #endif /* __BNAD_H__ */