1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
31 #include <linux/types.h>
32 #include <linux/bitops.h>
33 #include <linux/timer.h>
35 #include <linux/netdevice.h>
36 #include <linux/if_vlan.h>
37 #include <linux/u64_stats_sync.h>
41 /* wrapper around a pointer to a socket buffer,
42 * so a DMA handle can be stored along with the buffer */
43 struct ixgbevf_tx_buffer
{
46 unsigned long time_stamp
;
52 struct ixgbevf_rx_buffer
{
58 struct ixgbevf_ring
*next
;
59 struct ixgbevf_adapter
*adapter
; /* backlink */
60 void *desc
; /* descriptor ring memory */
61 dma_addr_t dma
; /* phys. address of descriptor ring */
62 unsigned int size
; /* length in bytes */
63 unsigned int count
; /* amount of descriptors */
64 unsigned int next_to_use
;
65 unsigned int next_to_clean
;
67 int queue_index
; /* needed for multiqueue queue management */
69 struct ixgbevf_tx_buffer
*tx_buffer_info
;
70 struct ixgbevf_rx_buffer
*rx_buffer_info
;
75 struct u64_stats_sync syncp
;
80 u16 reg_idx
; /* holds the special value that gets the hardware register
81 * offset associated with this ring, which is different
82 * for DCB and RSS modes */
87 /* How many Rx Buffers do we bundle into one write to the hardware ? */
88 #define IXGBEVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
90 #define MAX_RX_QUEUES 1
91 #define MAX_TX_QUEUES 1
93 #define IXGBEVF_DEFAULT_TXD 1024
94 #define IXGBEVF_DEFAULT_RXD 512
95 #define IXGBEVF_MAX_TXD 4096
96 #define IXGBEVF_MIN_TXD 64
97 #define IXGBEVF_MAX_RXD 4096
98 #define IXGBEVF_MIN_RXD 64
100 /* Supported Rx Buffer Sizes */
101 #define IXGBEVF_RXBUFFER_256 256 /* Used for packet split */
102 #define IXGBEVF_RXBUFFER_2048 2048
103 #define IXGBEVF_MAX_RXBUFFER 16384 /* largest size for single descriptor */
105 #define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256
107 #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
109 #define IXGBE_TX_FLAGS_CSUM (u32)(1)
110 #define IXGBE_TX_FLAGS_VLAN (u32)(1 << 1)
111 #define IXGBE_TX_FLAGS_TSO (u32)(1 << 2)
112 #define IXGBE_TX_FLAGS_IPV4 (u32)(1 << 3)
113 #define IXGBE_TX_FLAGS_FCOE (u32)(1 << 4)
114 #define IXGBE_TX_FLAGS_FSO (u32)(1 << 5)
115 #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000
116 #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000
117 #define IXGBE_TX_FLAGS_VLAN_SHIFT 16
119 struct ixgbevf_ring_container
{
120 struct ixgbevf_ring
*ring
; /* pointer to linked list of rings */
121 u8 count
; /* total number of rings in vector */
122 u8 itr
; /* current ITR setting for ring */
125 /* iterator for handling rings in ring container */
126 #define ixgbevf_for_each_ring(pos, head) \
127 for (pos = (head).ring; pos != NULL; pos = pos->next)
129 /* MAX_MSIX_Q_VECTORS of these are allocated,
130 * but we only use one per queue-specific vector.
132 struct ixgbevf_q_vector
{
133 struct ixgbevf_adapter
*adapter
;
134 struct napi_struct napi
;
135 struct ixgbevf_ring_container rx
, tx
;
137 int v_idx
; /* vector index in list */
138 char name
[IFNAMSIZ
+ 9];
141 /* Helper macros to switch between ints/sec and what the register uses.
142 * And yes, it's the same math going both ways. The lowest value
143 * supported by all of the ixgbe hardware is 8.
145 #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
146 ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
147 #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
149 #define IXGBE_DESC_UNUSED(R) \
150 ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
151 (R)->next_to_clean - (R)->next_to_use - 1)
153 #define IXGBE_RX_DESC_ADV(R, i) \
154 (&(((union ixgbe_adv_rx_desc *)((R).desc))[i]))
155 #define IXGBE_TX_DESC_ADV(R, i) \
156 (&(((union ixgbe_adv_tx_desc *)((R).desc))[i]))
157 #define IXGBE_TX_CTXTDESC_ADV(R, i) \
158 (&(((struct ixgbe_adv_tx_context_desc *)((R).desc))[i]))
160 #define IXGBE_MAX_JUMBO_FRAME_SIZE 16128
162 #define OTHER_VECTOR 1
163 #define NON_Q_VECTORS (OTHER_VECTOR)
165 #define MAX_MSIX_Q_VECTORS 2
167 #define MIN_MSIX_Q_VECTORS 1
168 #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
170 /* board specific private data structure */
171 struct ixgbevf_adapter
{
172 struct timer_list watchdog_timer
;
173 unsigned long active_vlans
[BITS_TO_LONGS(VLAN_N_VID
)];
175 struct work_struct reset_task
;
176 struct ixgbevf_q_vector
*q_vector
[MAX_MSIX_Q_VECTORS
];
178 /* Interrupt Throttle Rate */
182 struct ixgbevf_ring
*tx_ring
; /* One per active queue */
190 u32 tx_timeout_count
;
193 struct ixgbevf_ring
*rx_ring
; /* One per active queue */
196 u64 hw_csum_rx_error
;
197 u64 hw_rx_no_dma_resources
;
200 int num_msix_vectors
;
201 struct msix_entry
*msix_entries
;
203 u32 alloc_rx_page_failed
;
204 u32 alloc_rx_buff_failed
;
206 /* Some features need tri-state capability,
207 * thus the additional *_CAPABLE flags.
210 #define IXGBE_FLAG_IN_WATCHDOG_TASK (u32)(1)
212 /* OS defined structs */
213 struct net_device
*netdev
;
214 struct pci_dev
*pdev
;
216 /* structs defined in ixgbe_vf.h */
219 struct ixgbevf_hw_stats stats
;
221 /* Interrupt Throttle Rate */
226 unsigned int tx_ring_count
;
227 unsigned int rx_ring_count
;
232 struct work_struct watchdog_task
;
235 enum ixbgevf_state_t
{
241 enum ixgbevf_boards
{
246 extern const struct ixgbevf_info ixgbevf_82599_vf_info
;
247 extern const struct ixgbevf_info ixgbevf_X540_vf_info
;
248 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops
;
250 /* needed by ethtool.c */
251 extern const char ixgbevf_driver_name
[];
252 extern const char ixgbevf_driver_version
[];
254 extern void ixgbevf_up(struct ixgbevf_adapter
*adapter
);
255 extern void ixgbevf_down(struct ixgbevf_adapter
*adapter
);
256 extern void ixgbevf_reinit_locked(struct ixgbevf_adapter
*adapter
);
257 extern void ixgbevf_reset(struct ixgbevf_adapter
*adapter
);
258 extern void ixgbevf_set_ethtool_ops(struct net_device
*netdev
);
259 extern int ixgbevf_setup_rx_resources(struct ixgbevf_adapter
*,
260 struct ixgbevf_ring
*);
261 extern int ixgbevf_setup_tx_resources(struct ixgbevf_adapter
*,
262 struct ixgbevf_ring
*);
263 extern void ixgbevf_free_rx_resources(struct ixgbevf_adapter
*,
264 struct ixgbevf_ring
*);
265 extern void ixgbevf_free_tx_resources(struct ixgbevf_adapter
*,
266 struct ixgbevf_ring
*);
267 extern void ixgbevf_update_stats(struct ixgbevf_adapter
*adapter
);
269 extern int ethtool_ioctl(struct ifreq
*ifr
);
271 extern void ixgbe_napi_add_all(struct ixgbevf_adapter
*adapter
);
272 extern void ixgbe_napi_del_all(struct ixgbevf_adapter
*adapter
);
275 extern char *ixgbevf_get_hw_dev_name(struct ixgbe_hw
*hw
);
276 #define hw_dbg(hw, format, arg...) \
277 printk(KERN_DEBUG "%s: " format, ixgbevf_get_hw_dev_name(hw), ##arg)
279 #define hw_dbg(hw, format, arg...) do {} while (0)
282 #endif /* _IXGBEVF_H_ */