vxge-main.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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 Neterion Inc's X3100 Series 10GbE PCIe I/O
  11. * Virtualized Server Adapter.
  12. * Copyright(c) 2002-2009 Neterion Inc.
  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. #define VXGE_DRIVER_NAME "vxge"
  21. #define VXGE_DRIVER_VENDOR "Neterion, Inc"
  22. #define VXGE_DRIVER_FW_VERSION_MAJOR 1
  23. #define DRV_VERSION VXGE_VERSION_MAJOR"."VXGE_VERSION_MINOR"."\
  24. VXGE_VERSION_FIX"."VXGE_VERSION_BUILD"-"\
  25. VXGE_VERSION_FOR
  26. #define PCI_DEVICE_ID_TITAN_WIN 0x5733
  27. #define PCI_DEVICE_ID_TITAN_UNI 0x5833
  28. #define VXGE_USE_DEFAULT 0xffffffff
  29. #define VXGE_HW_VPATH_MSIX_ACTIVE 4
  30. #define VXGE_HW_RXSYNC_FREQ_CNT 4
  31. #define VXGE_LL_WATCH_DOG_TIMEOUT (15 * HZ)
  32. #define VXGE_LL_RX_COPY_THRESHOLD 256
  33. #define VXGE_DEF_FIFO_LENGTH 84
  34. #define NO_STEERING 0
  35. #define PORT_STEERING 0x1
  36. #define RTH_STEERING 0x2
  37. #define RX_TOS_STEERING 0x3
  38. #define RX_VLAN_STEERING 0x4
  39. #define RTH_BUCKET_SIZE 4
  40. #define TX_PRIORITY_STEERING 1
  41. #define TX_VLAN_STEERING 2
  42. #define TX_PORT_STEERING 3
  43. #define TX_MULTIQ_STEERING 4
  44. #define VXGE_HW_MAC_ADDR_LEARN_DEFAULT VXGE_HW_RTS_MAC_DISABLE
  45. #define VXGE_TTI_BTIMER_VAL 250000
  46. #define VXGE_TTI_LTIMER_VAL 1000
  47. #define VXGE_TTI_RTIMER_VAL 0
  48. #define VXGE_RTI_BTIMER_VAL 250
  49. #define VXGE_RTI_LTIMER_VAL 100
  50. #define VXGE_RTI_RTIMER_VAL 0
  51. #define VXGE_FIFO_INDICATE_MAX_PKTS VXGE_DEF_FIFO_LENGTH
  52. #define VXGE_ISR_POLLING_CNT 8
  53. #define VXGE_MAX_CONFIG_DEV 0xFF
  54. #define VXGE_EXEC_MODE_DISABLE 0
  55. #define VXGE_EXEC_MODE_ENABLE 1
  56. #define VXGE_MAX_CONFIG_PORT 1
  57. #define VXGE_ALL_VID_DISABLE 0
  58. #define VXGE_ALL_VID_ENABLE 1
  59. #define VXGE_PAUSE_CTRL_DISABLE 0
  60. #define VXGE_PAUSE_CTRL_ENABLE 1
  61. #define TTI_TX_URANGE_A 5
  62. #define TTI_TX_URANGE_B 15
  63. #define TTI_TX_URANGE_C 40
  64. #define TTI_TX_UFC_A 5
  65. #define TTI_TX_UFC_B 40
  66. #define TTI_TX_UFC_C 60
  67. #define TTI_TX_UFC_D 100
  68. #define RTI_RX_URANGE_A 5
  69. #define RTI_RX_URANGE_B 15
  70. #define RTI_RX_URANGE_C 40
  71. #define RTI_RX_UFC_A 1
  72. #define RTI_RX_UFC_B 5
  73. #define RTI_RX_UFC_C 10
  74. #define RTI_RX_UFC_D 15
  75. /* Milli secs timer period */
  76. #define VXGE_TIMER_DELAY 10000
  77. #define VXGE_LL_MAX_FRAME_SIZE(dev) ((dev)->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE)
  78. enum vxge_reset_event {
  79. /* reset events */
  80. VXGE_LL_VPATH_RESET = 0,
  81. VXGE_LL_DEVICE_RESET = 1,
  82. VXGE_LL_FULL_RESET = 2,
  83. VXGE_LL_START_RESET = 3,
  84. VXGE_LL_COMPL_RESET = 4
  85. };
  86. /* These flags represent the devices temporary state */
  87. enum vxge_device_state_t {
  88. __VXGE_STATE_RESET_CARD = 0,
  89. __VXGE_STATE_CARD_UP
  90. };
  91. enum vxge_mac_addr_state {
  92. /* mac address states */
  93. VXGE_LL_MAC_ADDR_IN_LIST = 0,
  94. VXGE_LL_MAC_ADDR_IN_DA_TABLE = 1
  95. };
  96. struct vxge_drv_config {
  97. int config_dev_cnt;
  98. int total_dev_cnt;
  99. unsigned long inta_dev_open;
  100. int g_no_cpus;
  101. unsigned int vpath_per_dev;
  102. };
  103. struct macInfo {
  104. unsigned char macaddr[ETH_ALEN];
  105. unsigned char macmask[ETH_ALEN];
  106. unsigned int vpath_no;
  107. enum vxge_mac_addr_state state;
  108. };
  109. struct vxge_config {
  110. int tx_pause_enable;
  111. int rx_pause_enable;
  112. #define NEW_NAPI_WEIGHT 64
  113. int napi_weight;
  114. #define VXGE_GRO_DONOT_AGGREGATE 0
  115. #define VXGE_GRO_ALWAYS_AGGREGATE 1
  116. int gro_enable;
  117. int intr_type;
  118. #define INTA 0
  119. #define MSI 1
  120. #define MSI_X 2
  121. int addr_learn_en;
  122. int rth_steering;
  123. int rth_algorithm;
  124. int rth_hash_type_tcpipv4;
  125. int rth_hash_type_ipv4;
  126. int rth_hash_type_tcpipv6;
  127. int rth_hash_type_ipv6;
  128. int rth_hash_type_tcpipv6ex;
  129. int rth_hash_type_ipv6ex;
  130. int rth_bkt_sz;
  131. int rth_jhash_golden_ratio;
  132. int tx_steering_type;
  133. int fifo_indicate_max_pkts;
  134. struct vxge_hw_device_hw_info device_hw_info;
  135. };
  136. struct vxge_msix_entry {
  137. /* Mimicing the msix_entry struct of Kernel. */
  138. u16 vector;
  139. u16 entry;
  140. u16 in_use;
  141. void *arg;
  142. };
  143. /* Software Statistics */
  144. struct vxge_sw_stats {
  145. /* Network Stats (interface stats) */
  146. struct net_device_stats net_stats;
  147. /* Tx */
  148. u64 tx_frms;
  149. u64 tx_errors;
  150. u64 tx_bytes;
  151. u64 txd_not_free;
  152. u64 txd_out_of_desc;
  153. /* Virtual Path */
  154. u64 vpaths_open;
  155. u64 vpath_open_fail;
  156. /* Rx */
  157. u64 rx_frms;
  158. u64 rx_errors;
  159. u64 rx_bytes;
  160. u64 rx_mcast;
  161. /* Misc. */
  162. u64 link_up;
  163. u64 link_down;
  164. u64 pci_map_fail;
  165. u64 skb_alloc_fail;
  166. };
  167. struct vxge_mac_addrs {
  168. struct list_head item;
  169. u64 macaddr;
  170. u64 macmask;
  171. enum vxge_mac_addr_state state;
  172. };
  173. struct vxgedev;
  174. struct vxge_fifo_stats {
  175. u64 tx_frms;
  176. u64 tx_errors;
  177. u64 tx_bytes;
  178. u64 txd_not_free;
  179. u64 txd_out_of_desc;
  180. u64 pci_map_fail;
  181. };
  182. struct vxge_fifo {
  183. struct net_device *ndev;
  184. struct pci_dev *pdev;
  185. struct __vxge_hw_fifo *handle;
  186. /* The vpath id maintained in the driver -
  187. * 0 to 'maximum_vpaths_in_function - 1'
  188. */
  189. int driver_id;
  190. int tx_steering_type;
  191. int indicate_max_pkts;
  192. spinlock_t tx_lock;
  193. /* flag used to maintain queue state when MULTIQ is not enabled */
  194. #define VPATH_QUEUE_START 0
  195. #define VPATH_QUEUE_STOP 1
  196. int queue_state;
  197. /* Tx stats */
  198. struct vxge_fifo_stats stats;
  199. } ____cacheline_aligned;
  200. struct vxge_ring_stats {
  201. u64 prev_rx_frms;
  202. u64 rx_frms;
  203. u64 rx_errors;
  204. u64 rx_dropped;
  205. u64 rx_bytes;
  206. u64 rx_mcast;
  207. u64 pci_map_fail;
  208. u64 skb_alloc_fail;
  209. };
  210. struct vxge_ring {
  211. struct net_device *ndev;
  212. struct pci_dev *pdev;
  213. struct __vxge_hw_ring *handle;
  214. /* The vpath id maintained in the driver -
  215. * 0 to 'maximum_vpaths_in_function - 1'
  216. */
  217. int driver_id;
  218. /* copy of the flag indicating whether rx_csum is to be used */
  219. u32 rx_csum;
  220. int pkts_processed;
  221. int budget;
  222. int gro_enable;
  223. struct napi_struct napi;
  224. struct napi_struct *napi_p;
  225. #define VXGE_MAX_MAC_ADDR_COUNT 30
  226. int vlan_tag_strip;
  227. struct vlan_group *vlgrp;
  228. int rx_vector_no;
  229. enum vxge_hw_status last_status;
  230. /* Rx stats */
  231. struct vxge_ring_stats stats;
  232. } ____cacheline_aligned;
  233. struct vxge_vpath {
  234. struct vxge_fifo fifo;
  235. struct vxge_ring ring;
  236. struct __vxge_hw_vpath_handle *handle;
  237. /* Actual vpath id for this vpath in the device - 0 to 16 */
  238. int device_id;
  239. int max_mac_addr_cnt;
  240. int is_configured;
  241. int is_open;
  242. struct vxgedev *vdev;
  243. u8 (macaddr)[ETH_ALEN];
  244. u8 (macmask)[ETH_ALEN];
  245. #define VXGE_MAX_LEARN_MAC_ADDR_CNT 2048
  246. /* mac addresses currently programmed into NIC */
  247. u16 mac_addr_cnt;
  248. u16 mcast_addr_cnt;
  249. struct list_head mac_addr_list;
  250. u32 level_err;
  251. u32 level_trace;
  252. };
  253. #define VXGE_COPY_DEBUG_INFO_TO_LL(vdev, err, trace) { \
  254. for (i = 0; i < vdev->no_of_vpath; i++) { \
  255. vdev->vpaths[i].level_err = err; \
  256. vdev->vpaths[i].level_trace = trace; \
  257. } \
  258. vdev->level_err = err; \
  259. vdev->level_trace = trace; \
  260. }
  261. struct vxgedev {
  262. struct net_device *ndev;
  263. struct pci_dev *pdev;
  264. struct __vxge_hw_device *devh;
  265. struct vlan_group *vlgrp;
  266. int vlan_tag_strip;
  267. struct vxge_config config;
  268. unsigned long state;
  269. /* Indicates which vpath to reset */
  270. unsigned long vp_reset;
  271. /* Timer used for polling vpath resets */
  272. struct timer_list vp_reset_timer;
  273. /* Timer used for polling vpath lockup */
  274. struct timer_list vp_lockup_timer;
  275. /*
  276. * Flags to track whether device is in All Multicast
  277. * or in promiscuous mode.
  278. */
  279. u16 all_multi_flg;
  280. /* A flag indicating whether rx_csum is to be used or not. */
  281. u32 rx_csum;
  282. struct vxge_msix_entry *vxge_entries;
  283. struct msix_entry *entries;
  284. /*
  285. * 4 for each vpath * 17;
  286. * total is 68
  287. */
  288. #define VXGE_MAX_REQUESTED_MSIX 68
  289. #define VXGE_INTR_STRLEN 80
  290. char desc[VXGE_MAX_REQUESTED_MSIX][VXGE_INTR_STRLEN];
  291. enum vxge_hw_event cric_err_event;
  292. int max_vpath_supported;
  293. int no_of_vpath;
  294. struct napi_struct napi;
  295. /* A debug option, when enabled and if error condition occurs,
  296. * the driver will do following steps:
  297. * - mask all interrupts
  298. * - Not clear the source of the alarm
  299. * - gracefully stop all I/O
  300. * A diagnostic dump of register and stats at this point
  301. * reveals very useful information.
  302. */
  303. int exec_mode;
  304. int max_config_port;
  305. struct vxge_vpath *vpaths;
  306. struct __vxge_hw_vpath_handle *vp_handles[VXGE_HW_MAX_VIRTUAL_PATHS];
  307. void __iomem *bar0;
  308. struct vxge_sw_stats stats;
  309. int mtu;
  310. /* Below variables are used for vpath selection to transmit a packet */
  311. u8 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS];
  312. u64 vpaths_deployed;
  313. u32 intr_cnt;
  314. u32 level_err;
  315. u32 level_trace;
  316. char fw_version[VXGE_HW_FW_STRLEN];
  317. };
  318. struct vxge_rx_priv {
  319. struct sk_buff *skb;
  320. unsigned char *skb_data;
  321. dma_addr_t data_dma;
  322. dma_addr_t data_size;
  323. };
  324. struct vxge_tx_priv {
  325. struct sk_buff *skb;
  326. dma_addr_t dma_buffers[MAX_SKB_FRAGS+1];
  327. };
  328. #define VXGE_MODULE_PARAM_INT(p, val) \
  329. static int p = val; \
  330. module_param(p, int, 0)
  331. #define vxge_os_bug(fmt...) { printk(fmt); BUG(); }
  332. #define vxge_os_timer(timer, handle, arg, exp) do { \
  333. init_timer(&timer); \
  334. timer.function = handle; \
  335. timer.data = (unsigned long) arg; \
  336. mod_timer(&timer, (jiffies + exp)); \
  337. } while (0);
  338. int __devinit vxge_device_register(struct __vxge_hw_device *devh,
  339. struct vxge_config *config,
  340. int high_dma, int no_of_vpath,
  341. struct vxgedev **vdev);
  342. void vxge_device_unregister(struct __vxge_hw_device *devh);
  343. void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id);
  344. void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id);
  345. void vxge_callback_link_up(struct __vxge_hw_device *devh);
  346. void vxge_callback_link_down(struct __vxge_hw_device *devh);
  347. enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
  348. struct macInfo *mac);
  349. int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac);
  350. int vxge_reset(struct vxgedev *vdev);
  351. enum vxge_hw_status
  352. vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
  353. u8 t_code, void *userdata);
  354. enum vxge_hw_status
  355. vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
  356. enum vxge_hw_fifo_tcode t_code, void *userdata,
  357. struct sk_buff ***skb_ptr, int nr_skbs, int *more);
  358. int vxge_close(struct net_device *dev);
  359. int vxge_open(struct net_device *dev);
  360. void vxge_close_vpaths(struct vxgedev *vdev, int index);
  361. int vxge_open_vpaths(struct vxgedev *vdev);
  362. enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev);
  363. void vxge_stop_all_tx_queue(struct vxgedev *vdev);
  364. void vxge_stop_tx_queue(struct vxge_fifo *fifo);
  365. void vxge_start_all_tx_queue(struct vxgedev *vdev);
  366. void vxge_wake_tx_queue(struct vxge_fifo *fifo, struct sk_buff *skb);
  367. enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
  368. struct macInfo *mac);
  369. enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev,
  370. struct macInfo *mac);
  371. int vxge_mac_list_add(struct vxge_vpath *vpath,
  372. struct macInfo *mac);
  373. void vxge_free_mac_add_list(struct vxge_vpath *vpath);
  374. enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath);
  375. enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath);
  376. int do_vxge_close(struct net_device *dev, int do_io);
  377. extern void initialize_ethtool_ops(struct net_device *ndev);
  378. /**
  379. * #define VXGE_DEBUG_INIT: debug for initialization functions
  380. * #define VXGE_DEBUG_TX : debug transmit related functions
  381. * #define VXGE_DEBUG_RX : debug recevice related functions
  382. * #define VXGE_DEBUG_MEM : debug memory module
  383. * #define VXGE_DEBUG_LOCK: debug locks
  384. * #define VXGE_DEBUG_SEM : debug semaphore
  385. * #define VXGE_DEBUG_ENTRYEXIT: debug functions by adding entry exit statements
  386. */
  387. #define VXGE_DEBUG_INIT 0x00000001
  388. #define VXGE_DEBUG_TX 0x00000002
  389. #define VXGE_DEBUG_RX 0x00000004
  390. #define VXGE_DEBUG_MEM 0x00000008
  391. #define VXGE_DEBUG_LOCK 0x00000010
  392. #define VXGE_DEBUG_SEM 0x00000020
  393. #define VXGE_DEBUG_ENTRYEXIT 0x00000040
  394. #define VXGE_DEBUG_INTR 0x00000080
  395. #define VXGE_DEBUG_LL_CONFIG 0x00000100
  396. /* Debug tracing for VXGE driver */
  397. #ifndef VXGE_DEBUG_MASK
  398. #define VXGE_DEBUG_MASK 0x0
  399. #endif
  400. #if (VXGE_DEBUG_LL_CONFIG & VXGE_DEBUG_MASK)
  401. #define vxge_debug_ll_config(level, fmt, ...) \
  402. vxge_debug_ll(level, VXGE_DEBUG_LL_CONFIG, fmt, __VA_ARGS__)
  403. #else
  404. #define vxge_debug_ll_config(level, fmt, ...)
  405. #endif
  406. #if (VXGE_DEBUG_INIT & VXGE_DEBUG_MASK)
  407. #define vxge_debug_init(level, fmt, ...) \
  408. vxge_debug_ll(level, VXGE_DEBUG_INIT, fmt, __VA_ARGS__)
  409. #else
  410. #define vxge_debug_init(level, fmt, ...)
  411. #endif
  412. #if (VXGE_DEBUG_TX & VXGE_DEBUG_MASK)
  413. #define vxge_debug_tx(level, fmt, ...) \
  414. vxge_debug_ll(level, VXGE_DEBUG_TX, fmt, __VA_ARGS__)
  415. #else
  416. #define vxge_debug_tx(level, fmt, ...)
  417. #endif
  418. #if (VXGE_DEBUG_RX & VXGE_DEBUG_MASK)
  419. #define vxge_debug_rx(level, fmt, ...) \
  420. vxge_debug_ll(level, VXGE_DEBUG_RX, fmt, __VA_ARGS__)
  421. #else
  422. #define vxge_debug_rx(level, fmt, ...)
  423. #endif
  424. #if (VXGE_DEBUG_MEM & VXGE_DEBUG_MASK)
  425. #define vxge_debug_mem(level, fmt, ...) \
  426. vxge_debug_ll(level, VXGE_DEBUG_MEM, fmt, __VA_ARGS__)
  427. #else
  428. #define vxge_debug_mem(level, fmt, ...)
  429. #endif
  430. #if (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)
  431. #define vxge_debug_entryexit(level, fmt, ...) \
  432. vxge_debug_ll(level, VXGE_DEBUG_ENTRYEXIT, fmt, __VA_ARGS__)
  433. #else
  434. #define vxge_debug_entryexit(level, fmt, ...)
  435. #endif
  436. #if (VXGE_DEBUG_INTR & VXGE_DEBUG_MASK)
  437. #define vxge_debug_intr(level, fmt, ...) \
  438. vxge_debug_ll(level, VXGE_DEBUG_INTR, fmt, __VA_ARGS__)
  439. #else
  440. #define vxge_debug_intr(level, fmt, ...)
  441. #endif
  442. #define VXGE_DEVICE_DEBUG_LEVEL_SET(level, mask, vdev) {\
  443. vxge_hw_device_debug_set((struct __vxge_hw_device *)vdev->devh, \
  444. level, mask);\
  445. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, \
  446. vxge_hw_device_error_level_get((struct __vxge_hw_device *) \
  447. vdev->devh), \
  448. vxge_hw_device_trace_level_get((struct __vxge_hw_device *) \
  449. vdev->devh));\
  450. }
  451. #ifdef NETIF_F_GSO
  452. #define vxge_tcp_mss(skb) (skb_shinfo(skb)->gso_size)
  453. #define vxge_udp_mss(skb) (skb_shinfo(skb)->gso_size)
  454. #define vxge_offload_type(skb) (skb_shinfo(skb)->gso_type)
  455. #endif
  456. #endif