vxge-main.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /******************************************************************************
  2. * This software may be used and distributed according to the terms of
  3. * the GNU General Public License (GPL), incorporated herein by reference.
  4. * Drivers based on or derived from this code fall under the GPL and must
  5. * retain the authorship, copyright and license notice. This file is not
  6. * a complete program and may only be used when the entire operating
  7. * system is licensed under the GPL.
  8. * See the file COPYING in this distribution for more information.
  9. *
  10. * vxge-main.h: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
  11. * Virtualized Server Adapter.
  12. * Copyright(c) 2002-2010 Exar Corp.
  13. ******************************************************************************/
  14. #ifndef VXGE_MAIN_H
  15. #define VXGE_MAIN_H
  16. #include "vxge-traffic.h"
  17. #include "vxge-config.h"
  18. #include "vxge-version.h"
  19. #include <linux/list.h>
  20. #include <linux/bitops.h>
  21. #include <linux/if_vlan.h>
  22. #define VXGE_DRIVER_NAME "vxge"
  23. #define VXGE_DRIVER_VENDOR "Neterion, Inc"
  24. #define VXGE_DRIVER_FW_VERSION_MAJOR 1
  25. #define DRV_VERSION VXGE_VERSION_MAJOR"."VXGE_VERSION_MINOR"."\
  26. VXGE_VERSION_FIX"."VXGE_VERSION_BUILD"-"\
  27. VXGE_VERSION_FOR
  28. #define PCI_DEVICE_ID_TITAN_WIN 0x5733
  29. #define PCI_DEVICE_ID_TITAN_UNI 0x5833
  30. #define VXGE_HW_TITAN1_PCI_REVISION 1
  31. #define VXGE_HW_TITAN1A_PCI_REVISION 2
  32. #define VXGE_USE_DEFAULT 0xffffffff
  33. #define VXGE_HW_VPATH_MSIX_ACTIVE 4
  34. #define VXGE_ALARM_MSIX_ID 2
  35. #define VXGE_HW_RXSYNC_FREQ_CNT 4
  36. #define VXGE_LL_WATCH_DOG_TIMEOUT (15 * HZ)
  37. #define VXGE_LL_RX_COPY_THRESHOLD 256
  38. #define VXGE_DEF_FIFO_LENGTH 84
  39. #define NO_STEERING 0
  40. #define PORT_STEERING 0x1
  41. #define RTH_STEERING 0x2
  42. #define RX_TOS_STEERING 0x3
  43. #define RX_VLAN_STEERING 0x4
  44. #define RTH_BUCKET_SIZE 4
  45. #define TX_PRIORITY_STEERING 1
  46. #define TX_VLAN_STEERING 2
  47. #define TX_PORT_STEERING 3
  48. #define TX_MULTIQ_STEERING 4
  49. #define VXGE_HW_MAC_ADDR_LEARN_DEFAULT VXGE_HW_RTS_MAC_DISABLE
  50. #define VXGE_TTI_BTIMER_VAL 250000
  51. #define VXGE_TTI_LTIMER_VAL 1000
  52. #define VXGE_T1A_TTI_LTIMER_VAL 80
  53. #define VXGE_TTI_RTIMER_VAL 0
  54. #define VXGE_TTI_RTIMER_ADAPT_VAL 10
  55. #define VXGE_T1A_TTI_RTIMER_VAL 400
  56. #define VXGE_RTI_BTIMER_VAL 250
  57. #define VXGE_RTI_LTIMER_VAL 100
  58. #define VXGE_RTI_RTIMER_VAL 0
  59. #define VXGE_RTI_RTIMER_ADAPT_VAL 15
  60. #define VXGE_FIFO_INDICATE_MAX_PKTS VXGE_DEF_FIFO_LENGTH
  61. #define VXGE_ISR_POLLING_CNT 8
  62. #define VXGE_MAX_CONFIG_DEV 0xFF
  63. #define VXGE_EXEC_MODE_DISABLE 0
  64. #define VXGE_EXEC_MODE_ENABLE 1
  65. #define VXGE_MAX_CONFIG_PORT 1
  66. #define VXGE_ALL_VID_DISABLE 0
  67. #define VXGE_ALL_VID_ENABLE 1
  68. #define VXGE_PAUSE_CTRL_DISABLE 0
  69. #define VXGE_PAUSE_CTRL_ENABLE 1
  70. #define TTI_TX_URANGE_A 5
  71. #define TTI_TX_URANGE_B 15
  72. #define TTI_TX_URANGE_C 40
  73. #define TTI_TX_UFC_A 5
  74. #define TTI_TX_UFC_B 40
  75. #define TTI_TX_UFC_C 60
  76. #define TTI_TX_UFC_D 100
  77. #define TTI_T1A_TX_UFC_A 30
  78. #define TTI_T1A_TX_UFC_B 80
  79. /* Slope - (max_mtu - min_mtu)/(max_mtu_ufc - min_mtu_ufc) */
  80. /* Slope - 93 */
  81. /* 60 - 9k Mtu, 140 - 1.5k mtu */
  82. #define TTI_T1A_TX_UFC_C(mtu) (60 + ((VXGE_HW_MAX_MTU - mtu) / 93))
  83. /* Slope - 37 */
  84. /* 100 - 9k Mtu, 300 - 1.5k mtu */
  85. #define TTI_T1A_TX_UFC_D(mtu) (100 + ((VXGE_HW_MAX_MTU - mtu) / 37))
  86. #define RTI_RX_URANGE_A 5
  87. #define RTI_RX_URANGE_B 15
  88. #define RTI_RX_URANGE_C 40
  89. #define RTI_T1A_RX_URANGE_A 1
  90. #define RTI_T1A_RX_URANGE_B 20
  91. #define RTI_T1A_RX_URANGE_C 50
  92. #define RTI_RX_UFC_A 1
  93. #define RTI_RX_UFC_B 5
  94. #define RTI_RX_UFC_C 10
  95. #define RTI_RX_UFC_D 15
  96. #define RTI_T1A_RX_UFC_B 20
  97. #define RTI_T1A_RX_UFC_C 50
  98. #define RTI_T1A_RX_UFC_D 60
  99. /*
  100. * The interrupt rate is maintained at 3k per second with the moderation
  101. * parameters for most traffic but not all. This is the maximum interrupt
  102. * count allowed per function with INTA or per vector in the case of
  103. * MSI-X in a 10 millisecond time period. Enabled only for Titan 1A.
  104. */
  105. #define VXGE_T1A_MAX_INTERRUPT_COUNT 100
  106. #define VXGE_T1A_MAX_TX_INTERRUPT_COUNT 200
  107. /* Milli secs timer period */
  108. #define VXGE_TIMER_DELAY 10000
  109. #define VXGE_LL_MAX_FRAME_SIZE(dev) ((dev)->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE)
  110. #define is_sriov(function_mode) \
  111. ((function_mode == VXGE_HW_FUNCTION_MODE_SRIOV) || \
  112. (function_mode == VXGE_HW_FUNCTION_MODE_SRIOV_8) || \
  113. (function_mode == VXGE_HW_FUNCTION_MODE_SRIOV_4))
  114. enum vxge_reset_event {
  115. /* reset events */
  116. VXGE_LL_VPATH_RESET = 0,
  117. VXGE_LL_DEVICE_RESET = 1,
  118. VXGE_LL_FULL_RESET = 2,
  119. VXGE_LL_START_RESET = 3,
  120. VXGE_LL_COMPL_RESET = 4
  121. };
  122. /* These flags represent the devices temporary state */
  123. enum vxge_device_state_t {
  124. __VXGE_STATE_RESET_CARD = 0,
  125. __VXGE_STATE_CARD_UP
  126. };
  127. enum vxge_mac_addr_state {
  128. /* mac address states */
  129. VXGE_LL_MAC_ADDR_IN_LIST = 0,
  130. VXGE_LL_MAC_ADDR_IN_DA_TABLE = 1
  131. };
  132. struct vxge_drv_config {
  133. int config_dev_cnt;
  134. int total_dev_cnt;
  135. int g_no_cpus;
  136. unsigned int vpath_per_dev;
  137. };
  138. struct macInfo {
  139. unsigned char macaddr[ETH_ALEN];
  140. unsigned char macmask[ETH_ALEN];
  141. unsigned int vpath_no;
  142. enum vxge_mac_addr_state state;
  143. };
  144. struct vxge_config {
  145. int tx_pause_enable;
  146. int rx_pause_enable;
  147. #define NEW_NAPI_WEIGHT 64
  148. int napi_weight;
  149. int intr_type;
  150. #define INTA 0
  151. #define MSI 1
  152. #define MSI_X 2
  153. int addr_learn_en;
  154. u32 rth_steering:2,
  155. rth_algorithm:2,
  156. rth_hash_type_tcpipv4:1,
  157. rth_hash_type_ipv4:1,
  158. rth_hash_type_tcpipv6:1,
  159. rth_hash_type_ipv6:1,
  160. rth_hash_type_tcpipv6ex:1,
  161. rth_hash_type_ipv6ex:1,
  162. rth_bkt_sz:8;
  163. int rth_jhash_golden_ratio;
  164. int tx_steering_type;
  165. int fifo_indicate_max_pkts;
  166. struct vxge_hw_device_hw_info device_hw_info;
  167. };
  168. struct vxge_msix_entry {
  169. /* Mimicing the msix_entry struct of Kernel. */
  170. u16 vector;
  171. u16 entry;
  172. u16 in_use;
  173. void *arg;
  174. };
  175. /* Software Statistics */
  176. struct vxge_sw_stats {
  177. /* Virtual Path */
  178. unsigned long vpaths_open;
  179. unsigned long vpath_open_fail;
  180. /* Misc. */
  181. unsigned long link_up;
  182. unsigned long link_down;
  183. };
  184. struct vxge_mac_addrs {
  185. struct list_head item;
  186. u64 macaddr;
  187. u64 macmask;
  188. enum vxge_mac_addr_state state;
  189. };
  190. struct vxgedev;
  191. struct vxge_fifo_stats {
  192. struct u64_stats_sync syncp;
  193. u64 tx_frms;
  194. u64 tx_bytes;
  195. unsigned long tx_errors;
  196. unsigned long txd_not_free;
  197. unsigned long txd_out_of_desc;
  198. unsigned long pci_map_fail;
  199. };
  200. struct vxge_fifo {
  201. struct net_device *ndev;
  202. struct pci_dev *pdev;
  203. struct __vxge_hw_fifo *handle;
  204. struct netdev_queue *txq;
  205. int tx_steering_type;
  206. int indicate_max_pkts;
  207. /* Adaptive interrupt moderation parameters used in T1A */
  208. unsigned long interrupt_count;
  209. unsigned long jiffies;
  210. u32 tx_vector_no;
  211. /* Tx stats */
  212. struct vxge_fifo_stats stats;
  213. } ____cacheline_aligned;
  214. struct vxge_ring_stats {
  215. struct u64_stats_sync syncp;
  216. u64 rx_frms;
  217. u64 rx_mcast;
  218. u64 rx_bytes;
  219. unsigned long rx_errors;
  220. unsigned long rx_dropped;
  221. unsigned long prev_rx_frms;
  222. unsigned long pci_map_fail;
  223. unsigned long skb_alloc_fail;
  224. };
  225. struct vxge_ring {
  226. struct net_device *ndev;
  227. struct pci_dev *pdev;
  228. struct __vxge_hw_ring *handle;
  229. /* The vpath id maintained in the driver -
  230. * 0 to 'maximum_vpaths_in_function - 1'
  231. */
  232. int driver_id;
  233. /* Adaptive interrupt moderation parameters used in T1A */
  234. unsigned long interrupt_count;
  235. unsigned long jiffies;
  236. /* copy of the flag indicating whether rx_hwts is to be used */
  237. u32 rx_hwts:1;
  238. int pkts_processed;
  239. int budget;
  240. struct napi_struct napi;
  241. struct napi_struct *napi_p;
  242. #define VXGE_MAX_MAC_ADDR_COUNT 30
  243. int vlan_tag_strip;
  244. u32 rx_vector_no;
  245. enum vxge_hw_status last_status;
  246. /* Rx stats */
  247. struct vxge_ring_stats stats;
  248. } ____cacheline_aligned;
  249. struct vxge_vpath {
  250. struct vxge_fifo fifo;
  251. struct vxge_ring ring;
  252. struct __vxge_hw_vpath_handle *handle;
  253. /* Actual vpath id for this vpath in the device - 0 to 16 */
  254. int device_id;
  255. int max_mac_addr_cnt;
  256. int is_configured;
  257. int is_open;
  258. struct vxgedev *vdev;
  259. u8 macaddr[ETH_ALEN];
  260. u8 macmask[ETH_ALEN];
  261. #define VXGE_MAX_LEARN_MAC_ADDR_CNT 2048
  262. /* mac addresses currently programmed into NIC */
  263. u16 mac_addr_cnt;
  264. u16 mcast_addr_cnt;
  265. struct list_head mac_addr_list;
  266. u32 level_err;
  267. u32 level_trace;
  268. };
  269. #define VXGE_COPY_DEBUG_INFO_TO_LL(vdev, err, trace) { \
  270. for (i = 0; i < vdev->no_of_vpath; i++) { \
  271. vdev->vpaths[i].level_err = err; \
  272. vdev->vpaths[i].level_trace = trace; \
  273. } \
  274. vdev->level_err = err; \
  275. vdev->level_trace = trace; \
  276. }
  277. struct vxgedev {
  278. struct net_device *ndev;
  279. struct pci_dev *pdev;
  280. struct __vxge_hw_device *devh;
  281. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  282. int vlan_tag_strip;
  283. struct vxge_config config;
  284. unsigned long state;
  285. /* Indicates which vpath to reset */
  286. unsigned long vp_reset;
  287. /* Timer used for polling vpath resets */
  288. struct timer_list vp_reset_timer;
  289. /* Timer used for polling vpath lockup */
  290. struct timer_list vp_lockup_timer;
  291. /*
  292. * Flags to track whether device is in All Multicast
  293. * or in promiscuous mode.
  294. */
  295. u16 all_multi_flg;
  296. /* A flag indicating whether rx_hwts is to be used or not. */
  297. u32 rx_hwts:1,
  298. titan1:1;
  299. struct vxge_msix_entry *vxge_entries;
  300. struct msix_entry *entries;
  301. /*
  302. * 4 for each vpath * 17;
  303. * total is 68
  304. */
  305. #define VXGE_MAX_REQUESTED_MSIX 68
  306. #define VXGE_INTR_STRLEN 80
  307. char desc[VXGE_MAX_REQUESTED_MSIX][VXGE_INTR_STRLEN];
  308. enum vxge_hw_event cric_err_event;
  309. int max_vpath_supported;
  310. int no_of_vpath;
  311. struct napi_struct napi;
  312. /* A debug option, when enabled and if error condition occurs,
  313. * the driver will do following steps:
  314. * - mask all interrupts
  315. * - Not clear the source of the alarm
  316. * - gracefully stop all I/O
  317. * A diagnostic dump of register and stats at this point
  318. * reveals very useful information.
  319. */
  320. int exec_mode;
  321. int max_config_port;
  322. struct vxge_vpath *vpaths;
  323. struct __vxge_hw_vpath_handle *vp_handles[VXGE_HW_MAX_VIRTUAL_PATHS];
  324. void __iomem *bar0;
  325. struct vxge_sw_stats stats;
  326. int mtu;
  327. /* Below variables are used for vpath selection to transmit a packet */
  328. u8 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS];
  329. u64 vpaths_deployed;
  330. u32 intr_cnt;
  331. u32 level_err;
  332. u32 level_trace;
  333. char fw_version[VXGE_HW_FW_STRLEN];
  334. struct work_struct reset_task;
  335. };
  336. struct vxge_rx_priv {
  337. struct sk_buff *skb;
  338. unsigned char *skb_data;
  339. dma_addr_t data_dma;
  340. dma_addr_t data_size;
  341. };
  342. struct vxge_tx_priv {
  343. struct sk_buff *skb;
  344. dma_addr_t dma_buffers[MAX_SKB_FRAGS+1];
  345. };
  346. #define VXGE_MODULE_PARAM_INT(p, val) \
  347. static int p = val; \
  348. module_param(p, int, 0)
  349. static inline
  350. void vxge_os_timer(struct timer_list *timer, void (*func)(struct timer_list *),
  351. unsigned long timeout)
  352. {
  353. timer_setup(timer, func, 0);
  354. mod_timer(timer, jiffies + timeout);
  355. }
  356. void vxge_initialize_ethtool_ops(struct net_device *ndev);
  357. int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override);
  358. /* #define VXGE_DEBUG_INIT: debug for initialization functions
  359. * #define VXGE_DEBUG_TX : debug transmit related functions
  360. * #define VXGE_DEBUG_RX : debug recevice related functions
  361. * #define VXGE_DEBUG_MEM : debug memory module
  362. * #define VXGE_DEBUG_LOCK: debug locks
  363. * #define VXGE_DEBUG_SEM : debug semaphore
  364. * #define VXGE_DEBUG_ENTRYEXIT: debug functions by adding entry exit statements
  365. */
  366. #define VXGE_DEBUG_INIT 0x00000001
  367. #define VXGE_DEBUG_TX 0x00000002
  368. #define VXGE_DEBUG_RX 0x00000004
  369. #define VXGE_DEBUG_MEM 0x00000008
  370. #define VXGE_DEBUG_LOCK 0x00000010
  371. #define VXGE_DEBUG_SEM 0x00000020
  372. #define VXGE_DEBUG_ENTRYEXIT 0x00000040
  373. #define VXGE_DEBUG_INTR 0x00000080
  374. #define VXGE_DEBUG_LL_CONFIG 0x00000100
  375. /* Debug tracing for VXGE driver */
  376. #ifndef VXGE_DEBUG_MASK
  377. #define VXGE_DEBUG_MASK 0x0
  378. #endif
  379. #if (VXGE_DEBUG_LL_CONFIG & VXGE_DEBUG_MASK)
  380. #define vxge_debug_ll_config(level, fmt, ...) \
  381. vxge_debug_ll(level, VXGE_DEBUG_LL_CONFIG, fmt, __VA_ARGS__)
  382. #else
  383. #define vxge_debug_ll_config(level, fmt, ...)
  384. #endif
  385. #if (VXGE_DEBUG_INIT & VXGE_DEBUG_MASK)
  386. #define vxge_debug_init(level, fmt, ...) \
  387. vxge_debug_ll(level, VXGE_DEBUG_INIT, fmt, __VA_ARGS__)
  388. #else
  389. #define vxge_debug_init(level, fmt, ...)
  390. #endif
  391. #if (VXGE_DEBUG_TX & VXGE_DEBUG_MASK)
  392. #define vxge_debug_tx(level, fmt, ...) \
  393. vxge_debug_ll(level, VXGE_DEBUG_TX, fmt, __VA_ARGS__)
  394. #else
  395. #define vxge_debug_tx(level, fmt, ...)
  396. #endif
  397. #if (VXGE_DEBUG_RX & VXGE_DEBUG_MASK)
  398. #define vxge_debug_rx(level, fmt, ...) \
  399. vxge_debug_ll(level, VXGE_DEBUG_RX, fmt, __VA_ARGS__)
  400. #else
  401. #define vxge_debug_rx(level, fmt, ...)
  402. #endif
  403. #if (VXGE_DEBUG_MEM & VXGE_DEBUG_MASK)
  404. #define vxge_debug_mem(level, fmt, ...) \
  405. vxge_debug_ll(level, VXGE_DEBUG_MEM, fmt, __VA_ARGS__)
  406. #else
  407. #define vxge_debug_mem(level, fmt, ...)
  408. #endif
  409. #if (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)
  410. #define vxge_debug_entryexit(level, fmt, ...) \
  411. vxge_debug_ll(level, VXGE_DEBUG_ENTRYEXIT, fmt, __VA_ARGS__)
  412. #else
  413. #define vxge_debug_entryexit(level, fmt, ...)
  414. #endif
  415. #if (VXGE_DEBUG_INTR & VXGE_DEBUG_MASK)
  416. #define vxge_debug_intr(level, fmt, ...) \
  417. vxge_debug_ll(level, VXGE_DEBUG_INTR, fmt, __VA_ARGS__)
  418. #else
  419. #define vxge_debug_intr(level, fmt, ...)
  420. #endif
  421. #define VXGE_DEVICE_DEBUG_LEVEL_SET(level, mask, vdev) {\
  422. vxge_hw_device_debug_set((struct __vxge_hw_device *)vdev->devh, \
  423. level, mask);\
  424. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, \
  425. vxge_hw_device_error_level_get((struct __vxge_hw_device *) \
  426. vdev->devh), \
  427. vxge_hw_device_trace_level_get((struct __vxge_hw_device *) \
  428. vdev->devh));\
  429. }
  430. #ifdef NETIF_F_GSO
  431. #define vxge_tcp_mss(skb) (skb_shinfo(skb)->gso_size)
  432. #define vxge_udp_mss(skb) (skb_shinfo(skb)->gso_size)
  433. #define vxge_offload_type(skb) (skb_shinfo(skb)->gso_type)
  434. #endif
  435. #endif