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.
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 ******************************************************************************/
17 #include "vxge-traffic.h"
18 #include "vxge-config.h"
19 #include "vxge-version.h"
20 #include <linux/list.h>
22 #define VXGE_DRIVER_NAME "vxge"
23 #define VXGE_DRIVER_VENDOR "Neterion, Inc"
24 #define VXGE_DRIVER_FW_VERSION_MAJOR 1
26 #define DRV_VERSION VXGE_VERSION_MAJOR"."VXGE_VERSION_MINOR"."\
27 VXGE_VERSION_FIX"."VXGE_VERSION_BUILD"-"\
30 #define PCI_DEVICE_ID_TITAN_WIN 0x5733
31 #define PCI_DEVICE_ID_TITAN_UNI 0x5833
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
41 #define PORT_STEERING 0x1
42 #define RTH_STEERING 0x2
43 #define RX_TOS_STEERING 0x3
44 #define RX_VLAN_STEERING 0x4
45 #define RTH_BUCKET_SIZE 4
47 #define TX_PRIORITY_STEERING 1
48 #define TX_VLAN_STEERING 2
49 #define TX_PORT_STEERING 3
50 #define TX_MULTIQ_STEERING 4
52 #define VXGE_HW_MAC_ADDR_LEARN_DEFAULT VXGE_HW_RTS_MAC_DISABLE
54 #define VXGE_TTI_BTIMER_VAL 250000
56 #define VXGE_TTI_LTIMER_VAL 1000
57 #define VXGE_TTI_RTIMER_VAL 0
58 #define VXGE_RTI_BTIMER_VAL 250
59 #define VXGE_RTI_LTIMER_VAL 100
60 #define VXGE_RTI_RTIMER_VAL 0
61 #define VXGE_FIFO_INDICATE_MAX_PKTS VXGE_DEF_FIFO_LENGTH
62 #define VXGE_ISR_POLLING_CNT 8
63 #define VXGE_MAX_CONFIG_DEV 0xFF
64 #define VXGE_EXEC_MODE_DISABLE 0
65 #define VXGE_EXEC_MODE_ENABLE 1
66 #define VXGE_MAX_CONFIG_PORT 1
67 #define VXGE_ALL_VID_DISABLE 0
68 #define VXGE_ALL_VID_ENABLE 1
69 #define VXGE_PAUSE_CTRL_DISABLE 0
70 #define VXGE_PAUSE_CTRL_ENABLE 1
72 #define TTI_TX_URANGE_A 5
73 #define TTI_TX_URANGE_B 15
74 #define TTI_TX_URANGE_C 40
75 #define TTI_TX_UFC_A 5
76 #define TTI_TX_UFC_B 40
77 #define TTI_TX_UFC_C 60
78 #define TTI_TX_UFC_D 100
80 #define RTI_RX_URANGE_A 5
81 #define RTI_RX_URANGE_B 15
82 #define RTI_RX_URANGE_C 40
83 #define RTI_RX_UFC_A 1
84 #define RTI_RX_UFC_B 5
85 #define RTI_RX_UFC_C 10
86 #define RTI_RX_UFC_D 15
88 /* Milli secs timer period */
89 #define VXGE_TIMER_DELAY 10000
91 #define VXGE_LL_MAX_FRAME_SIZE(dev) ((dev)->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE)
93 #define is_sriov(function_mode) \
94 ((function_mode == VXGE_HW_FUNCTION_MODE_SRIOV) || \
95 (function_mode == VXGE_HW_FUNCTION_MODE_SRIOV_8) || \
96 (function_mode == VXGE_HW_FUNCTION_MODE_SRIOV_4))
98 enum vxge_reset_event
{
100 VXGE_LL_VPATH_RESET
= 0,
101 VXGE_LL_DEVICE_RESET
= 1,
102 VXGE_LL_FULL_RESET
= 2,
103 VXGE_LL_START_RESET
= 3,
104 VXGE_LL_COMPL_RESET
= 4
106 /* These flags represent the devices temporary state */
107 enum vxge_device_state_t
{
108 __VXGE_STATE_RESET_CARD
= 0,
112 enum vxge_mac_addr_state
{
113 /* mac address states */
114 VXGE_LL_MAC_ADDR_IN_LIST
= 0,
115 VXGE_LL_MAC_ADDR_IN_DA_TABLE
= 1
118 struct vxge_drv_config
{
122 unsigned int vpath_per_dev
;
126 unsigned char macaddr
[ETH_ALEN
];
127 unsigned char macmask
[ETH_ALEN
];
128 unsigned int vpath_no
;
129 enum vxge_mac_addr_state state
;
136 #define NEW_NAPI_WEIGHT 64
138 #define VXGE_GRO_DONOT_AGGREGATE 0
139 #define VXGE_GRO_ALWAYS_AGGREGATE 1
150 int rth_hash_type_tcpipv4
;
151 int rth_hash_type_ipv4
;
152 int rth_hash_type_tcpipv6
;
153 int rth_hash_type_ipv6
;
154 int rth_hash_type_tcpipv6ex
;
155 int rth_hash_type_ipv6ex
;
157 int rth_jhash_golden_ratio
;
158 int tx_steering_type
;
159 int fifo_indicate_max_pkts
;
160 struct vxge_hw_device_hw_info device_hw_info
;
163 struct vxge_msix_entry
{
164 /* Mimicing the msix_entry struct of Kernel. */
171 /* Software Statistics */
173 struct vxge_sw_stats
{
174 /* Network Stats (interface stats) */
175 struct net_device_stats net_stats
;
201 struct vxge_mac_addrs
{
202 struct list_head item
;
205 enum vxge_mac_addr_state state
;
210 struct vxge_fifo_stats
{
220 struct net_device
*ndev
;
221 struct pci_dev
*pdev
;
222 struct __vxge_hw_fifo
*handle
;
223 struct netdev_queue
*txq
;
225 int tx_steering_type
;
226 int indicate_max_pkts
;
229 struct vxge_fifo_stats stats
;
230 } ____cacheline_aligned
;
232 struct vxge_ring_stats
{
244 struct net_device
*ndev
;
245 struct pci_dev
*pdev
;
246 struct __vxge_hw_ring
*handle
;
247 /* The vpath id maintained in the driver -
248 * 0 to 'maximum_vpaths_in_function - 1'
252 /* copy of the flag indicating whether rx_csum is to be used */
259 struct napi_struct napi
;
260 struct napi_struct
*napi_p
;
262 #define VXGE_MAX_MAC_ADDR_COUNT 30
265 struct vlan_group
*vlgrp
;
267 enum vxge_hw_status last_status
;
270 struct vxge_ring_stats stats
;
271 } ____cacheline_aligned
;
274 struct vxge_fifo fifo
;
275 struct vxge_ring ring
;
277 struct __vxge_hw_vpath_handle
*handle
;
279 /* Actual vpath id for this vpath in the device - 0 to 16 */
281 int max_mac_addr_cnt
;
284 struct vxgedev
*vdev
;
285 u8 (macaddr
)[ETH_ALEN
];
286 u8 (macmask
)[ETH_ALEN
];
288 #define VXGE_MAX_LEARN_MAC_ADDR_CNT 2048
289 /* mac addresses currently programmed into NIC */
292 struct list_head mac_addr_list
;
297 #define VXGE_COPY_DEBUG_INFO_TO_LL(vdev, err, trace) { \
298 for (i = 0; i < vdev->no_of_vpath; i++) { \
299 vdev->vpaths[i].level_err = err; \
300 vdev->vpaths[i].level_trace = trace; \
302 vdev->level_err = err; \
303 vdev->level_trace = trace; \
307 struct net_device
*ndev
;
308 struct pci_dev
*pdev
;
309 struct __vxge_hw_device
*devh
;
310 struct vlan_group
*vlgrp
;
312 struct vxge_config config
;
315 /* Indicates which vpath to reset */
316 unsigned long vp_reset
;
318 /* Timer used for polling vpath resets */
319 struct timer_list vp_reset_timer
;
321 /* Timer used for polling vpath lockup */
322 struct timer_list vp_lockup_timer
;
325 * Flags to track whether device is in All Multicast
326 * or in promiscuous mode.
330 /* A flag indicating whether rx_csum is to be used or not. */
333 struct vxge_msix_entry
*vxge_entries
;
334 struct msix_entry
*entries
;
336 * 4 for each vpath * 17;
339 #define VXGE_MAX_REQUESTED_MSIX 68
340 #define VXGE_INTR_STRLEN 80
341 char desc
[VXGE_MAX_REQUESTED_MSIX
][VXGE_INTR_STRLEN
];
343 enum vxge_hw_event cric_err_event
;
345 int max_vpath_supported
;
348 struct napi_struct napi
;
349 /* A debug option, when enabled and if error condition occurs,
350 * the driver will do following steps:
351 * - mask all interrupts
352 * - Not clear the source of the alarm
353 * - gracefully stop all I/O
354 * A diagnostic dump of register and stats at this point
355 * reveals very useful information.
359 struct vxge_vpath
*vpaths
;
361 struct __vxge_hw_vpath_handle
*vp_handles
[VXGE_HW_MAX_VIRTUAL_PATHS
];
363 struct vxge_sw_stats stats
;
365 /* Below variables are used for vpath selection to transmit a packet */
366 u8 vpath_selector
[VXGE_HW_MAX_VIRTUAL_PATHS
];
372 char fw_version
[VXGE_HW_FW_STRLEN
];
375 struct vxge_rx_priv
{
377 unsigned char *skb_data
;
379 dma_addr_t data_size
;
382 struct vxge_tx_priv
{
384 dma_addr_t dma_buffers
[MAX_SKB_FRAGS
+1];
387 #define VXGE_MODULE_PARAM_INT(p, val) \
388 static int p = val; \
389 module_param(p, int, 0)
391 #define vxge_os_bug(fmt...) { printk(fmt); BUG(); }
393 #define vxge_os_timer(timer, handle, arg, exp) do { \
394 init_timer(&timer); \
395 timer.function = handle; \
396 timer.data = (unsigned long) arg; \
397 mod_timer(&timer, (jiffies + exp)); \
400 int __devinit
vxge_device_register(struct __vxge_hw_device
*devh
,
401 struct vxge_config
*config
,
402 int high_dma
, int no_of_vpath
,
403 struct vxgedev
**vdev
);
405 void vxge_device_unregister(struct __vxge_hw_device
*devh
);
407 void vxge_vpath_intr_enable(struct vxgedev
*vdev
, int vp_id
);
409 void vxge_vpath_intr_disable(struct vxgedev
*vdev
, int vp_id
);
411 void vxge_callback_link_up(struct __vxge_hw_device
*devh
);
413 void vxge_callback_link_down(struct __vxge_hw_device
*devh
);
415 enum vxge_hw_status
vxge_add_mac_addr(struct vxgedev
*vdev
,
416 struct macInfo
*mac
);
418 int vxge_mac_list_del(struct vxge_vpath
*vpath
, struct macInfo
*mac
);
420 int vxge_reset(struct vxgedev
*vdev
);
423 vxge_rx_1b_compl(struct __vxge_hw_ring
*ringh
, void *dtr
,
424 u8 t_code
, void *userdata
);
427 vxge_xmit_compl(struct __vxge_hw_fifo
*fifo_hw
, void *dtr
,
428 enum vxge_hw_fifo_tcode t_code
, void *userdata
,
429 struct sk_buff
***skb_ptr
, int nr_skbs
, int *more
);
431 int vxge_close(struct net_device
*dev
);
433 int vxge_open(struct net_device
*dev
);
435 void vxge_close_vpaths(struct vxgedev
*vdev
, int index
);
437 int vxge_open_vpaths(struct vxgedev
*vdev
);
439 enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
);
441 enum vxge_hw_status
vxge_add_mac_addr(struct vxgedev
*vdev
,
442 struct macInfo
*mac
);
444 enum vxge_hw_status
vxge_del_mac_addr(struct vxgedev
*vdev
,
445 struct macInfo
*mac
);
447 int vxge_mac_list_add(struct vxge_vpath
*vpath
,
448 struct macInfo
*mac
);
450 void vxge_free_mac_add_list(struct vxge_vpath
*vpath
);
452 enum vxge_hw_status
vxge_restore_vpath_mac_addr(struct vxge_vpath
*vpath
);
454 enum vxge_hw_status
vxge_restore_vpath_vid_table(struct vxge_vpath
*vpath
);
456 int do_vxge_close(struct net_device
*dev
, int do_io
);
457 extern void initialize_ethtool_ops(struct net_device
*ndev
);
459 * #define VXGE_DEBUG_INIT: debug for initialization functions
460 * #define VXGE_DEBUG_TX : debug transmit related functions
461 * #define VXGE_DEBUG_RX : debug recevice related functions
462 * #define VXGE_DEBUG_MEM : debug memory module
463 * #define VXGE_DEBUG_LOCK: debug locks
464 * #define VXGE_DEBUG_SEM : debug semaphore
465 * #define VXGE_DEBUG_ENTRYEXIT: debug functions by adding entry exit statements
467 #define VXGE_DEBUG_INIT 0x00000001
468 #define VXGE_DEBUG_TX 0x00000002
469 #define VXGE_DEBUG_RX 0x00000004
470 #define VXGE_DEBUG_MEM 0x00000008
471 #define VXGE_DEBUG_LOCK 0x00000010
472 #define VXGE_DEBUG_SEM 0x00000020
473 #define VXGE_DEBUG_ENTRYEXIT 0x00000040
474 #define VXGE_DEBUG_INTR 0x00000080
475 #define VXGE_DEBUG_LL_CONFIG 0x00000100
477 /* Debug tracing for VXGE driver */
478 #ifndef VXGE_DEBUG_MASK
479 #define VXGE_DEBUG_MASK 0x0
482 #if (VXGE_DEBUG_LL_CONFIG & VXGE_DEBUG_MASK)
483 #define vxge_debug_ll_config(level, fmt, ...) \
484 vxge_debug_ll(level, VXGE_DEBUG_LL_CONFIG, fmt, __VA_ARGS__)
486 #define vxge_debug_ll_config(level, fmt, ...)
489 #if (VXGE_DEBUG_INIT & VXGE_DEBUG_MASK)
490 #define vxge_debug_init(level, fmt, ...) \
491 vxge_debug_ll(level, VXGE_DEBUG_INIT, fmt, __VA_ARGS__)
493 #define vxge_debug_init(level, fmt, ...)
496 #if (VXGE_DEBUG_TX & VXGE_DEBUG_MASK)
497 #define vxge_debug_tx(level, fmt, ...) \
498 vxge_debug_ll(level, VXGE_DEBUG_TX, fmt, __VA_ARGS__)
500 #define vxge_debug_tx(level, fmt, ...)
503 #if (VXGE_DEBUG_RX & VXGE_DEBUG_MASK)
504 #define vxge_debug_rx(level, fmt, ...) \
505 vxge_debug_ll(level, VXGE_DEBUG_RX, fmt, __VA_ARGS__)
507 #define vxge_debug_rx(level, fmt, ...)
510 #if (VXGE_DEBUG_MEM & VXGE_DEBUG_MASK)
511 #define vxge_debug_mem(level, fmt, ...) \
512 vxge_debug_ll(level, VXGE_DEBUG_MEM, fmt, __VA_ARGS__)
514 #define vxge_debug_mem(level, fmt, ...)
517 #if (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)
518 #define vxge_debug_entryexit(level, fmt, ...) \
519 vxge_debug_ll(level, VXGE_DEBUG_ENTRYEXIT, fmt, __VA_ARGS__)
521 #define vxge_debug_entryexit(level, fmt, ...)
524 #if (VXGE_DEBUG_INTR & VXGE_DEBUG_MASK)
525 #define vxge_debug_intr(level, fmt, ...) \
526 vxge_debug_ll(level, VXGE_DEBUG_INTR, fmt, __VA_ARGS__)
528 #define vxge_debug_intr(level, fmt, ...)
531 #define VXGE_DEVICE_DEBUG_LEVEL_SET(level, mask, vdev) {\
532 vxge_hw_device_debug_set((struct __vxge_hw_device *)vdev->devh, \
534 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, \
535 vxge_hw_device_error_level_get((struct __vxge_hw_device *) \
537 vxge_hw_device_trace_level_get((struct __vxge_hw_device *) \
542 #define vxge_tcp_mss(skb) (skb_shinfo(skb)->gso_size)
543 #define vxge_udp_mss(skb) (skb_shinfo(skb)->gso_size)
544 #define vxge_offload_type(skb) (skb_shinfo(skb)->gso_type)