bnad.h 7.7 KB

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