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_HW_TITAN1_PCI_REVISION 1
33 #define VXGE_HW_TITAN1A_PCI_REVISION 2
35 #define VXGE_USE_DEFAULT 0xffffffff
36 #define VXGE_HW_VPATH_MSIX_ACTIVE 4
37 #define VXGE_ALARM_MSIX_ID 2
38 #define VXGE_HW_RXSYNC_FREQ_CNT 4
39 #define VXGE_LL_WATCH_DOG_TIMEOUT (15 * HZ)
40 #define VXGE_LL_RX_COPY_THRESHOLD 256
41 #define VXGE_DEF_FIFO_LENGTH 84
44 #define PORT_STEERING 0x1
45 #define RTH_STEERING 0x2
46 #define RX_TOS_STEERING 0x3
47 #define RX_VLAN_STEERING 0x4
48 #define RTH_BUCKET_SIZE 4
50 #define TX_PRIORITY_STEERING 1
51 #define TX_VLAN_STEERING 2
52 #define TX_PORT_STEERING 3
53 #define TX_MULTIQ_STEERING 4
55 #define VXGE_HW_MAC_ADDR_LEARN_DEFAULT VXGE_HW_RTS_MAC_DISABLE
57 #define VXGE_TTI_BTIMER_VAL 250000
59 #define VXGE_TTI_LTIMER_VAL 1000
60 #define VXGE_T1A_TTI_LTIMER_VAL 80
61 #define VXGE_TTI_RTIMER_VAL 0
62 #define VXGE_TTI_RTIMER_ADAPT_VAL 10
63 #define VXGE_T1A_TTI_RTIMER_VAL 400
64 #define VXGE_RTI_BTIMER_VAL 250
65 #define VXGE_RTI_LTIMER_VAL 100
66 #define VXGE_RTI_RTIMER_VAL 0
67 #define VXGE_RTI_RTIMER_ADAPT_VAL 15
68 #define VXGE_FIFO_INDICATE_MAX_PKTS VXGE_DEF_FIFO_LENGTH
69 #define VXGE_ISR_POLLING_CNT 8
70 #define VXGE_MAX_CONFIG_DEV 0xFF
71 #define VXGE_EXEC_MODE_DISABLE 0
72 #define VXGE_EXEC_MODE_ENABLE 1
73 #define VXGE_MAX_CONFIG_PORT 1
74 #define VXGE_ALL_VID_DISABLE 0
75 #define VXGE_ALL_VID_ENABLE 1
76 #define VXGE_PAUSE_CTRL_DISABLE 0
77 #define VXGE_PAUSE_CTRL_ENABLE 1
79 #define TTI_TX_URANGE_A 5
80 #define TTI_TX_URANGE_B 15
81 #define TTI_TX_URANGE_C 40
82 #define TTI_TX_UFC_A 5
83 #define TTI_TX_UFC_B 40
84 #define TTI_TX_UFC_C 60
85 #define TTI_TX_UFC_D 100
86 #define TTI_T1A_TX_UFC_A 30
87 #define TTI_T1A_TX_UFC_B 80
88 /* Slope - (max_mtu - min_mtu)/(max_mtu_ufc - min_mtu_ufc) */
90 /* 60 - 9k Mtu, 140 - 1.5k mtu */
91 #define TTI_T1A_TX_UFC_C(mtu) (60 + ((VXGE_HW_MAX_MTU - mtu) / 93))
94 /* 100 - 9k Mtu, 300 - 1.5k mtu */
95 #define TTI_T1A_TX_UFC_D(mtu) (100 + ((VXGE_HW_MAX_MTU - mtu) / 37))
98 #define RTI_RX_URANGE_A 5
99 #define RTI_RX_URANGE_B 15
100 #define RTI_RX_URANGE_C 40
101 #define RTI_T1A_RX_URANGE_A 1
102 #define RTI_T1A_RX_URANGE_B 20
103 #define RTI_T1A_RX_URANGE_C 50
104 #define RTI_RX_UFC_A 1
105 #define RTI_RX_UFC_B 5
106 #define RTI_RX_UFC_C 10
107 #define RTI_RX_UFC_D 15
108 #define RTI_T1A_RX_UFC_B 20
109 #define RTI_T1A_RX_UFC_C 50
110 #define RTI_T1A_RX_UFC_D 60
113 * The interrupt rate is maintained at 3k per second with the moderation
114 * parameters for most traffic but not all. This is the maximum interrupt
115 * count allowed per function with INTA or per vector in the case of
116 * MSI-X in a 10 millisecond time period. Enabled only for Titan 1A.
118 #define VXGE_T1A_MAX_INTERRUPT_COUNT 100
119 #define VXGE_T1A_MAX_TX_INTERRUPT_COUNT 200
121 /* Milli secs timer period */
122 #define VXGE_TIMER_DELAY 10000
124 #define VXGE_LL_MAX_FRAME_SIZE(dev) ((dev)->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE)
126 #define is_sriov(function_mode) \
127 ((function_mode == VXGE_HW_FUNCTION_MODE_SRIOV) || \
128 (function_mode == VXGE_HW_FUNCTION_MODE_SRIOV_8) || \
129 (function_mode == VXGE_HW_FUNCTION_MODE_SRIOV_4))
131 enum vxge_reset_event
{
133 VXGE_LL_VPATH_RESET
= 0,
134 VXGE_LL_DEVICE_RESET
= 1,
135 VXGE_LL_FULL_RESET
= 2,
136 VXGE_LL_START_RESET
= 3,
137 VXGE_LL_COMPL_RESET
= 4
139 /* These flags represent the devices temporary state */
140 enum vxge_device_state_t
{
141 __VXGE_STATE_RESET_CARD
= 0,
145 enum vxge_mac_addr_state
{
146 /* mac address states */
147 VXGE_LL_MAC_ADDR_IN_LIST
= 0,
148 VXGE_LL_MAC_ADDR_IN_DA_TABLE
= 1
151 struct vxge_drv_config
{
155 unsigned int vpath_per_dev
;
159 unsigned char macaddr
[ETH_ALEN
];
160 unsigned char macmask
[ETH_ALEN
];
161 unsigned int vpath_no
;
162 enum vxge_mac_addr_state state
;
169 #define NEW_NAPI_WEIGHT 64
180 rth_hash_type_tcpipv4
:1,
181 rth_hash_type_ipv4
:1,
182 rth_hash_type_tcpipv6
:1,
183 rth_hash_type_ipv6
:1,
184 rth_hash_type_tcpipv6ex
:1,
185 rth_hash_type_ipv6ex
:1,
187 int rth_jhash_golden_ratio
;
188 int tx_steering_type
;
189 int fifo_indicate_max_pkts
;
190 struct vxge_hw_device_hw_info device_hw_info
;
193 struct vxge_msix_entry
{
194 /* Mimicing the msix_entry struct of Kernel. */
201 /* Software Statistics */
203 struct vxge_sw_stats
{
204 /* Network Stats (interface stats) */
230 struct vxge_mac_addrs
{
231 struct list_head item
;
234 enum vxge_mac_addr_state state
;
239 struct vxge_fifo_stats
{
249 struct net_device
*ndev
;
250 struct pci_dev
*pdev
;
251 struct __vxge_hw_fifo
*handle
;
252 struct netdev_queue
*txq
;
254 int tx_steering_type
;
255 int indicate_max_pkts
;
257 /* Adaptive interrupt moderation parameters used in T1A */
258 unsigned long interrupt_count
;
259 unsigned long jiffies
;
263 struct vxge_fifo_stats stats
;
264 } ____cacheline_aligned
;
266 struct vxge_ring_stats
{
278 struct net_device
*ndev
;
279 struct pci_dev
*pdev
;
280 struct __vxge_hw_ring
*handle
;
281 /* The vpath id maintained in the driver -
282 * 0 to 'maximum_vpaths_in_function - 1'
286 /* Adaptive interrupt moderation parameters used in T1A */
287 unsigned long interrupt_count
;
288 unsigned long jiffies
;
290 /* copy of the flag indicating whether rx_hwts is to be used */
296 struct napi_struct napi
;
297 struct napi_struct
*napi_p
;
299 #define VXGE_MAX_MAC_ADDR_COUNT 30
302 struct vlan_group
*vlgrp
;
304 enum vxge_hw_status last_status
;
307 struct vxge_ring_stats stats
;
308 } ____cacheline_aligned
;
311 struct vxge_fifo fifo
;
312 struct vxge_ring ring
;
314 struct __vxge_hw_vpath_handle
*handle
;
316 /* Actual vpath id for this vpath in the device - 0 to 16 */
318 int max_mac_addr_cnt
;
321 struct vxgedev
*vdev
;
322 u8 macaddr
[ETH_ALEN
];
323 u8 macmask
[ETH_ALEN
];
325 #define VXGE_MAX_LEARN_MAC_ADDR_CNT 2048
326 /* mac addresses currently programmed into NIC */
329 struct list_head mac_addr_list
;
334 #define VXGE_COPY_DEBUG_INFO_TO_LL(vdev, err, trace) { \
335 for (i = 0; i < vdev->no_of_vpath; i++) { \
336 vdev->vpaths[i].level_err = err; \
337 vdev->vpaths[i].level_trace = trace; \
339 vdev->level_err = err; \
340 vdev->level_trace = trace; \
344 struct net_device
*ndev
;
345 struct pci_dev
*pdev
;
346 struct __vxge_hw_device
*devh
;
347 struct vlan_group
*vlgrp
;
349 struct vxge_config config
;
352 /* Indicates which vpath to reset */
353 unsigned long vp_reset
;
355 /* Timer used for polling vpath resets */
356 struct timer_list vp_reset_timer
;
358 /* Timer used for polling vpath lockup */
359 struct timer_list vp_lockup_timer
;
362 * Flags to track whether device is in All Multicast
363 * or in promiscuous mode.
367 /* A flag indicating whether rx_hwts is to be used or not. */
371 struct vxge_msix_entry
*vxge_entries
;
372 struct msix_entry
*entries
;
374 * 4 for each vpath * 17;
377 #define VXGE_MAX_REQUESTED_MSIX 68
378 #define VXGE_INTR_STRLEN 80
379 char desc
[VXGE_MAX_REQUESTED_MSIX
][VXGE_INTR_STRLEN
];
381 enum vxge_hw_event cric_err_event
;
383 int max_vpath_supported
;
386 struct napi_struct napi
;
387 /* A debug option, when enabled and if error condition occurs,
388 * the driver will do following steps:
389 * - mask all interrupts
390 * - Not clear the source of the alarm
391 * - gracefully stop all I/O
392 * A diagnostic dump of register and stats at this point
393 * reveals very useful information.
397 struct vxge_vpath
*vpaths
;
399 struct __vxge_hw_vpath_handle
*vp_handles
[VXGE_HW_MAX_VIRTUAL_PATHS
];
401 struct vxge_sw_stats stats
;
403 /* Below variables are used for vpath selection to transmit a packet */
404 u8 vpath_selector
[VXGE_HW_MAX_VIRTUAL_PATHS
];
410 char fw_version
[VXGE_HW_FW_STRLEN
];
411 struct work_struct reset_task
;
414 struct vxge_rx_priv
{
416 unsigned char *skb_data
;
418 dma_addr_t data_size
;
421 struct vxge_tx_priv
{
423 dma_addr_t dma_buffers
[MAX_SKB_FRAGS
+1];
426 #define VXGE_MODULE_PARAM_INT(p, val) \
427 static int p = val; \
428 module_param(p, int, 0)
430 #define vxge_os_timer(timer, handle, arg, exp) do { \
431 init_timer(&timer); \
432 timer.function = handle; \
433 timer.data = (unsigned long) arg; \
434 mod_timer(&timer, (jiffies + exp)); \
437 void vxge_initialize_ethtool_ops(struct net_device
*ndev
);
438 enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
);
439 int vxge_fw_upgrade(struct vxgedev
*vdev
, char *fw_name
, int override
);
442 * #define VXGE_DEBUG_INIT: debug for initialization functions
443 * #define VXGE_DEBUG_TX : debug transmit related functions
444 * #define VXGE_DEBUG_RX : debug recevice related functions
445 * #define VXGE_DEBUG_MEM : debug memory module
446 * #define VXGE_DEBUG_LOCK: debug locks
447 * #define VXGE_DEBUG_SEM : debug semaphore
448 * #define VXGE_DEBUG_ENTRYEXIT: debug functions by adding entry exit statements
450 #define VXGE_DEBUG_INIT 0x00000001
451 #define VXGE_DEBUG_TX 0x00000002
452 #define VXGE_DEBUG_RX 0x00000004
453 #define VXGE_DEBUG_MEM 0x00000008
454 #define VXGE_DEBUG_LOCK 0x00000010
455 #define VXGE_DEBUG_SEM 0x00000020
456 #define VXGE_DEBUG_ENTRYEXIT 0x00000040
457 #define VXGE_DEBUG_INTR 0x00000080
458 #define VXGE_DEBUG_LL_CONFIG 0x00000100
460 /* Debug tracing for VXGE driver */
461 #ifndef VXGE_DEBUG_MASK
462 #define VXGE_DEBUG_MASK 0x0
465 #if (VXGE_DEBUG_LL_CONFIG & VXGE_DEBUG_MASK)
466 #define vxge_debug_ll_config(level, fmt, ...) \
467 vxge_debug_ll(level, VXGE_DEBUG_LL_CONFIG, fmt, __VA_ARGS__)
469 #define vxge_debug_ll_config(level, fmt, ...)
472 #if (VXGE_DEBUG_INIT & VXGE_DEBUG_MASK)
473 #define vxge_debug_init(level, fmt, ...) \
474 vxge_debug_ll(level, VXGE_DEBUG_INIT, fmt, __VA_ARGS__)
476 #define vxge_debug_init(level, fmt, ...)
479 #if (VXGE_DEBUG_TX & VXGE_DEBUG_MASK)
480 #define vxge_debug_tx(level, fmt, ...) \
481 vxge_debug_ll(level, VXGE_DEBUG_TX, fmt, __VA_ARGS__)
483 #define vxge_debug_tx(level, fmt, ...)
486 #if (VXGE_DEBUG_RX & VXGE_DEBUG_MASK)
487 #define vxge_debug_rx(level, fmt, ...) \
488 vxge_debug_ll(level, VXGE_DEBUG_RX, fmt, __VA_ARGS__)
490 #define vxge_debug_rx(level, fmt, ...)
493 #if (VXGE_DEBUG_MEM & VXGE_DEBUG_MASK)
494 #define vxge_debug_mem(level, fmt, ...) \
495 vxge_debug_ll(level, VXGE_DEBUG_MEM, fmt, __VA_ARGS__)
497 #define vxge_debug_mem(level, fmt, ...)
500 #if (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK)
501 #define vxge_debug_entryexit(level, fmt, ...) \
502 vxge_debug_ll(level, VXGE_DEBUG_ENTRYEXIT, fmt, __VA_ARGS__)
504 #define vxge_debug_entryexit(level, fmt, ...)
507 #if (VXGE_DEBUG_INTR & VXGE_DEBUG_MASK)
508 #define vxge_debug_intr(level, fmt, ...) \
509 vxge_debug_ll(level, VXGE_DEBUG_INTR, fmt, __VA_ARGS__)
511 #define vxge_debug_intr(level, fmt, ...)
514 #define VXGE_DEVICE_DEBUG_LEVEL_SET(level, mask, vdev) {\
515 vxge_hw_device_debug_set((struct __vxge_hw_device *)vdev->devh, \
517 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, \
518 vxge_hw_device_error_level_get((struct __vxge_hw_device *) \
520 vxge_hw_device_trace_level_get((struct __vxge_hw_device *) \
525 #define vxge_tcp_mss(skb) (skb_shinfo(skb)->gso_size)
526 #define vxge_udp_mss(skb) (skb_shinfo(skb)->gso_size)
527 #define vxge_offload_type(skb) (skb_shinfo(skb)->gso_type)