bnad.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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_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 hw_stats_updates;
  150. u64 netif_rx_dropped;
  151. u64 link_toggle;
  152. u64 cee_toggle;
  153. u64 rxp_info_alloc_failed;
  154. u64 mbox_intr_disabled;
  155. u64 mbox_intr_enabled;
  156. u64 tx_unmap_q_alloc_failed;
  157. u64 rx_unmap_q_alloc_failed;
  158. u64 rxbuf_alloc_failed;
  159. };
  160. /* Complete driver stats */
  161. struct bnad_stats {
  162. struct bnad_drv_stats drv_stats;
  163. struct bna_stats *bna_stats;
  164. };
  165. /* Tx / Rx Resources */
  166. struct bnad_tx_res_info {
  167. struct bna_res_info res_info[BNA_TX_RES_T_MAX];
  168. };
  169. struct bnad_rx_res_info {
  170. struct bna_res_info res_info[BNA_RX_RES_T_MAX];
  171. };
  172. struct bnad_tx_info {
  173. struct bna_tx *tx; /* 1:1 between tx_info & tx */
  174. struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
  175. u32 tx_id;
  176. } ____cacheline_aligned;
  177. struct bnad_rx_info {
  178. struct bna_rx *rx; /* 1:1 between rx_info & rx */
  179. struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXP_PER_RX];
  180. u32 rx_id;
  181. } ____cacheline_aligned;
  182. /* Unmap queues for Tx / Rx cleanup */
  183. struct bnad_skb_unmap {
  184. struct sk_buff *skb;
  185. DEFINE_DMA_UNMAP_ADDR(dma_addr);
  186. };
  187. struct bnad_unmap_q {
  188. u32 producer_index;
  189. u32 consumer_index;
  190. u32 q_depth;
  191. /* This should be the last one */
  192. struct bnad_skb_unmap unmap_array[1];
  193. };
  194. /* Bit mask values for bnad->cfg_flags */
  195. #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
  196. #define BNAD_CF_PROMISC 0x02
  197. #define BNAD_CF_ALLMULTI 0x04
  198. #define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
  199. /* Defines for run_flags bit-mask */
  200. /* Set, tested & cleared using xxx_bit() functions */
  201. /* Values indicated bit positions */
  202. #define BNAD_RF_CEE_RUNNING 0
  203. #define BNAD_RF_MTU_SET 1
  204. #define BNAD_RF_MBOX_IRQ_DISABLED 2
  205. #define BNAD_RF_NETDEV_REGISTERED 3
  206. #define BNAD_RF_DIM_TIMER_RUNNING 4
  207. #define BNAD_RF_STATS_TIMER_RUNNING 5
  208. #define BNAD_RF_TX_PRIO_SET 6
  209. /* Define for Fast Path flags */
  210. /* Defined as bit positions */
  211. #define BNAD_FP_IN_RX_PATH 0
  212. struct bnad {
  213. struct net_device *netdev;
  214. u32 id;
  215. struct list_head list_entry;
  216. /* Data path */
  217. struct bnad_tx_info tx_info[BNAD_MAX_TX];
  218. struct bnad_rx_info rx_info[BNAD_MAX_RX];
  219. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  220. /*
  221. * These q numbers are global only because
  222. * they are used to calculate MSIx vectors.
  223. * Actually the exact # of queues are per Tx/Rx
  224. * object.
  225. */
  226. u32 num_tx;
  227. u32 num_rx;
  228. u32 num_txq_per_tx;
  229. u32 num_rxp_per_rx;
  230. u32 txq_depth;
  231. u32 rxq_depth;
  232. u8 tx_coalescing_timeo;
  233. u8 rx_coalescing_timeo;
  234. struct bna_rx_config rx_config[BNAD_MAX_RX];
  235. struct bna_tx_config tx_config[BNAD_MAX_TX];
  236. void __iomem *bar0; /* BAR0 address */
  237. struct bna bna;
  238. u32 cfg_flags;
  239. unsigned long run_flags;
  240. struct pci_dev *pcidev;
  241. u64 mmio_start;
  242. u64 mmio_len;
  243. u32 msix_num;
  244. struct msix_entry *msix_table;
  245. struct mutex conf_mutex;
  246. spinlock_t bna_lock ____cacheline_aligned;
  247. /* Timers */
  248. struct timer_list ioc_timer;
  249. struct timer_list dim_timer;
  250. struct timer_list stats_timer;
  251. /* Control path resources, memory & irq */
  252. struct bna_res_info res_info[BNA_RES_T_MAX];
  253. struct bna_res_info mod_res_info[BNA_MOD_RES_T_MAX];
  254. struct bnad_tx_res_info tx_res_info[BNAD_MAX_TX];
  255. struct bnad_rx_res_info rx_res_info[BNAD_MAX_RX];
  256. struct bnad_completion bnad_completions;
  257. /* Burnt in MAC address */
  258. mac_t perm_addr;
  259. struct tasklet_struct tx_free_tasklet;
  260. /* Statistics */
  261. struct bnad_stats stats;
  262. struct bnad_diag *diag;
  263. char adapter_name[BNAD_NAME_LEN];
  264. char port_name[BNAD_NAME_LEN];
  265. char mbox_irq_name[BNAD_NAME_LEN];
  266. /* debugfs specific data */
  267. char *regdata;
  268. u32 reglen;
  269. struct dentry *bnad_dentry_files[5];
  270. struct dentry *port_debugfs_root;
  271. };
  272. struct bnad_drvinfo {
  273. struct bfa_ioc_attr ioc_attr;
  274. struct bfa_cee_attr cee_attr;
  275. struct bfa_flash_attr flash_attr;
  276. u32 cee_status;
  277. u32 flash_status;
  278. };
  279. /*
  280. * EXTERN VARIABLES
  281. */
  282. extern const struct firmware *bfi_fw;
  283. extern u32 bnad_rxqs_per_cq;
  284. /*
  285. * EXTERN PROTOTYPES
  286. */
  287. extern u32 *cna_get_firmware_buf(struct pci_dev *pdev);
  288. /* Netdev entry point prototypes */
  289. extern void bnad_set_rx_mode(struct net_device *netdev);
  290. extern struct net_device_stats *bnad_get_netdev_stats(
  291. struct net_device *netdev);
  292. extern int bnad_mac_addr_set_locked(struct bnad *bnad, u8 *mac_addr);
  293. extern int bnad_enable_default_bcast(struct bnad *bnad);
  294. extern void bnad_restore_vlans(struct bnad *bnad, u32 rx_id);
  295. extern void bnad_set_ethtool_ops(struct net_device *netdev);
  296. extern void bnad_cb_completion(void *arg, enum bfa_status status);
  297. /* Configuration & setup */
  298. extern void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
  299. extern void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
  300. extern int bnad_setup_rx(struct bnad *bnad, u32 rx_id);
  301. extern int bnad_setup_tx(struct bnad *bnad, u32 tx_id);
  302. extern void bnad_cleanup_tx(struct bnad *bnad, u32 tx_id);
  303. extern void bnad_cleanup_rx(struct bnad *bnad, u32 rx_id);
  304. /* Timer start/stop protos */
  305. extern void bnad_dim_timer_start(struct bnad *bnad);
  306. /* Statistics */
  307. extern void bnad_netdev_qstats_fill(struct bnad *bnad,
  308. struct rtnl_link_stats64 *stats);
  309. extern void bnad_netdev_hwstats_fill(struct bnad *bnad,
  310. struct rtnl_link_stats64 *stats);
  311. /* Debugfs */
  312. void bnad_debugfs_init(struct bnad *bnad);
  313. void bnad_debugfs_uninit(struct bnad *bnad);
  314. /**
  315. * MACROS
  316. */
  317. /* To set & get the stats counters */
  318. #define BNAD_UPDATE_CTR(_bnad, _ctr) \
  319. (((_bnad)->stats.drv_stats._ctr)++)
  320. #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
  321. #define bnad_enable_rx_irq_unsafe(_ccb) \
  322. { \
  323. if (likely(test_bit(BNAD_RXQ_STARTED, &(_ccb)->rcb[0]->flags))) {\
  324. bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
  325. (_ccb)->rx_coalescing_timeo); \
  326. bna_ib_ack((_ccb)->i_dbell, 0); \
  327. } \
  328. }
  329. #endif /* __BNAD_H__ */