blob: 1f1376515f707838d6e9eca72eb2235a702a1de9 [file] [log] [blame]
Greg Rose92915f72010-01-09 02:24:10 +00001/*******************************************************************************
2
3 Intel 82599 Virtual Function driver
Greg Rose5c47a2b2012-01-06 02:53:30 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Greg Rose92915f72010-01-09 02:24:10 +00005
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.
9
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
13 more details.
14
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.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#ifndef _IXGBEVF_H_
29#define _IXGBEVF_H_
30
31#include <linux/types.h>
Jiri Pirkodadcd652011-07-21 03:25:09 +000032#include <linux/bitops.h>
Greg Rose92915f72010-01-09 02:24:10 +000033#include <linux/timer.h>
34#include <linux/io.h>
35#include <linux/netdevice.h>
Jiri Pirkodadcd652011-07-21 03:25:09 +000036#include <linux/if_vlan.h>
Eric Dumazet4197aa72011-06-22 05:01:35 +000037#include <linux/u64_stats_sync.h>
Greg Rose92915f72010-01-09 02:24:10 +000038
39#include "vf.h"
40
41/* wrapper around a pointer to a socket buffer,
42 * so a DMA handle can be stored along with the buffer */
43struct ixgbevf_tx_buffer {
44 struct sk_buff *skb;
45 dma_addr_t dma;
46 unsigned long time_stamp;
47 u16 length;
48 u16 next_to_watch;
49 u16 mapped_as_page;
50};
51
52struct ixgbevf_rx_buffer {
53 struct sk_buff *skb;
54 dma_addr_t dma;
Greg Rose92915f72010-01-09 02:24:10 +000055};
56
57struct ixgbevf_ring {
Alexander Duyck6b43c442012-05-11 08:32:45 +000058 struct ixgbevf_ring *next;
Greg Rose92915f72010-01-09 02:24:10 +000059 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;
66
67 int queue_index; /* needed for multiqueue queue management */
68 union {
69 struct ixgbevf_tx_buffer *tx_buffer_info;
70 struct ixgbevf_rx_buffer *rx_buffer_info;
71 };
72
Eric Dumazet4197aa72011-06-22 05:01:35 +000073 u64 total_bytes;
74 u64 total_packets;
75 struct u64_stats_sync syncp;
76
Greg Rose92915f72010-01-09 02:24:10 +000077 u16 head;
78 u16 tail;
79
Greg Rose92915f72010-01-09 02:24:10 +000080 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 */
83
Greg Rose92915f72010-01-09 02:24:10 +000084 u16 rx_buf_len;
85};
86
Greg Rose92915f72010-01-09 02:24:10 +000087/* 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 */
89
90#define MAX_RX_QUEUES 1
91#define MAX_TX_QUEUES 1
92
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
99
100/* Supported Rx Buffer Sizes */
Greg Rose92915f72010-01-09 02:24:10 +0000101#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 */
104
105#define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256
106
107#define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
108
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
118
Alexander Duyck6b43c442012-05-11 08:32:45 +0000119struct ixgbevf_ring_container {
120 struct ixgbevf_ring *ring; /* pointer to linked list of rings */
Alexander Duyck5f3600e2012-05-11 08:32:55 +0000121 unsigned int total_bytes; /* total bytes processed this int */
122 unsigned int total_packets; /* total packets processed this int */
Alexander Duyck6b43c442012-05-11 08:32:45 +0000123 u8 count; /* total number of rings in vector */
124 u8 itr; /* current ITR setting for ring */
125};
126
127/* iterator for handling rings in ring container */
128#define ixgbevf_for_each_ring(pos, head) \
129 for (pos = (head).ring; pos != NULL; pos = pos->next)
130
Greg Rose92915f72010-01-09 02:24:10 +0000131/* MAX_MSIX_Q_VECTORS of these are allocated,
132 * but we only use one per queue-specific vector.
133 */
134struct ixgbevf_q_vector {
135 struct ixgbevf_adapter *adapter;
Alexander Duyck5f3600e2012-05-11 08:32:55 +0000136 u16 v_idx; /* index of q_vector within array, also used for
137 * finding the bit in EICR and friends that
138 * represents the vector for this ring */
139 u16 itr; /* Interrupt throttle rate written to EITR */
Greg Rose92915f72010-01-09 02:24:10 +0000140 struct napi_struct napi;
Alexander Duyck6b43c442012-05-11 08:32:45 +0000141 struct ixgbevf_ring_container rx, tx;
Alexander Duyckfa71ae22012-05-11 08:32:50 +0000142 char name[IFNAMSIZ + 9];
Greg Rose92915f72010-01-09 02:24:10 +0000143};
144
Alexander Duyck5f3600e2012-05-11 08:32:55 +0000145/*
146 * microsecond values for various ITR rates shifted by 2 to fit itr register
147 * with the first 3 bits reserved 0
148 */
149#define IXGBE_MIN_RSC_ITR 24
150#define IXGBE_100K_ITR 40
151#define IXGBE_20K_ITR 200
152#define IXGBE_10K_ITR 400
153#define IXGBE_8K_ITR 500
154
Greg Rose92915f72010-01-09 02:24:10 +0000155/* Helper macros to switch between ints/sec and what the register uses.
156 * And yes, it's the same math going both ways. The lowest value
157 * supported by all of the ixgbe hardware is 8.
158 */
159#define EITR_INTS_PER_SEC_TO_REG(_eitr) \
160 ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
161#define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
162
163#define IXGBE_DESC_UNUSED(R) \
164 ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
165 (R)->next_to_clean - (R)->next_to_use - 1)
166
Alexander Duyck908421f2012-05-11 08:33:00 +0000167#define IXGBEVF_RX_DESC(R, i) \
168 (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
169#define IXGBEVF_TX_DESC(R, i) \
170 (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i]))
171#define IXGBEVF_TX_CTXTDESC(R, i) \
172 (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i]))
Greg Rose92915f72010-01-09 02:24:10 +0000173
174#define IXGBE_MAX_JUMBO_FRAME_SIZE 16128
175
176#define OTHER_VECTOR 1
177#define NON_Q_VECTORS (OTHER_VECTOR)
178
179#define MAX_MSIX_Q_VECTORS 2
Greg Rose92915f72010-01-09 02:24:10 +0000180
Alexander Duyckfa71ae22012-05-11 08:32:50 +0000181#define MIN_MSIX_Q_VECTORS 1
Greg Rose92915f72010-01-09 02:24:10 +0000182#define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
183
184/* board specific private data structure */
185struct ixgbevf_adapter {
186 struct timer_list watchdog_timer;
Jiri Pirkodadcd652011-07-21 03:25:09 +0000187 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
Greg Rose92915f72010-01-09 02:24:10 +0000188 u16 bd_number;
189 struct work_struct reset_task;
190 struct ixgbevf_q_vector *q_vector[MAX_MSIX_Q_VECTORS];
Greg Rose92915f72010-01-09 02:24:10 +0000191
192 /* Interrupt Throttle Rate */
Alexander Duyck5f3600e2012-05-11 08:32:55 +0000193 u16 rx_itr_setting;
194 u16 tx_itr_setting;
195
196 /* interrupt masks */
197 u32 eims_enable_mask;
198 u32 eims_other;
Greg Rose92915f72010-01-09 02:24:10 +0000199
200 /* TX */
201 struct ixgbevf_ring *tx_ring; /* One per active queue */
202 int num_tx_queues;
203 u64 restart_queue;
204 u64 hw_csum_tx_good;
205 u64 lsc_int;
206 u64 hw_tso_ctxt;
207 u64 hw_tso6_ctxt;
208 u32 tx_timeout_count;
Greg Rose92915f72010-01-09 02:24:10 +0000209
210 /* RX */
211 struct ixgbevf_ring *rx_ring; /* One per active queue */
212 int num_rx_queues;
Greg Rose92915f72010-01-09 02:24:10 +0000213 u64 hw_csum_rx_error;
214 u64 hw_rx_no_dma_resources;
215 u64 hw_csum_rx_good;
216 u64 non_eop_descs;
217 int num_msix_vectors;
Greg Rose92915f72010-01-09 02:24:10 +0000218 struct msix_entry *msix_entries;
219
Greg Rose92915f72010-01-09 02:24:10 +0000220 u32 alloc_rx_page_failed;
221 u32 alloc_rx_buff_failed;
222
223 /* Some features need tri-state capability,
224 * thus the additional *_CAPABLE flags.
225 */
226 u32 flags;
Alexander Duyck525a9402012-05-11 08:32:29 +0000227#define IXGBE_FLAG_IN_WATCHDOG_TASK (u32)(1)
Alexander Duyck77d5dfc2012-05-11 08:32:19 +0000228
Greg Rose92915f72010-01-09 02:24:10 +0000229 /* OS defined structs */
230 struct net_device *netdev;
231 struct pci_dev *pdev;
Greg Rose92915f72010-01-09 02:24:10 +0000232
233 /* structs defined in ixgbe_vf.h */
234 struct ixgbe_hw hw;
235 u16 msg_enable;
236 struct ixgbevf_hw_stats stats;
237 u64 zero_base;
238 /* Interrupt Throttle Rate */
239 u32 eitr_param;
240
241 unsigned long state;
Greg Rose92915f72010-01-09 02:24:10 +0000242 u64 tx_busy;
243 unsigned int tx_ring_count;
244 unsigned int rx_ring_count;
245
246 u32 link_speed;
247 bool link_up;
Greg Rose92915f72010-01-09 02:24:10 +0000248
249 struct work_struct watchdog_task;
Greg Rose92915f72010-01-09 02:24:10 +0000250};
251
252enum ixbgevf_state_t {
253 __IXGBEVF_TESTING,
254 __IXGBEVF_RESETTING,
255 __IXGBEVF_DOWN
256};
257
258enum ixgbevf_boards {
259 board_82599_vf,
Greg Rose2316aa22010-12-02 07:12:26 +0000260 board_X540_vf,
Greg Rose92915f72010-01-09 02:24:10 +0000261};
262
Stephen Hemminger3d8fe982012-01-18 22:13:34 +0000263extern const struct ixgbevf_info ixgbevf_82599_vf_info;
264extern const struct ixgbevf_info ixgbevf_X540_vf_info;
Stephen Hemmingerb5417bf2012-01-18 22:13:33 +0000265extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
Greg Rose92915f72010-01-09 02:24:10 +0000266
267/* needed by ethtool.c */
Stephen Hemminger3d8fe982012-01-18 22:13:34 +0000268extern const char ixgbevf_driver_name[];
Greg Rose92915f72010-01-09 02:24:10 +0000269extern const char ixgbevf_driver_version[];
270
Greg Rose795180d2012-04-17 04:29:34 +0000271extern void ixgbevf_up(struct ixgbevf_adapter *adapter);
Greg Rose92915f72010-01-09 02:24:10 +0000272extern void ixgbevf_down(struct ixgbevf_adapter *adapter);
273extern void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter);
274extern void ixgbevf_reset(struct ixgbevf_adapter *adapter);
275extern void ixgbevf_set_ethtool_ops(struct net_device *netdev);
276extern int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *,
277 struct ixgbevf_ring *);
278extern int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *,
279 struct ixgbevf_ring *);
280extern void ixgbevf_free_rx_resources(struct ixgbevf_adapter *,
281 struct ixgbevf_ring *);
282extern void ixgbevf_free_tx_resources(struct ixgbevf_adapter *,
283 struct ixgbevf_ring *);
284extern void ixgbevf_update_stats(struct ixgbevf_adapter *adapter);
Alexander Duyck5f3600e2012-05-11 08:32:55 +0000285void ixgbevf_write_eitr(struct ixgbevf_q_vector *);
Greg Rose92915f72010-01-09 02:24:10 +0000286extern int ethtool_ioctl(struct ifreq *ifr);
287
Greg Rose92915f72010-01-09 02:24:10 +0000288extern void ixgbe_napi_add_all(struct ixgbevf_adapter *adapter);
289extern void ixgbe_napi_del_all(struct ixgbevf_adapter *adapter);
290
291#ifdef DEBUG
292extern char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw);
293#define hw_dbg(hw, format, arg...) \
294 printk(KERN_DEBUG "%s: " format, ixgbevf_get_hw_dev_name(hw), ##arg)
295#else
296#define hw_dbg(hw, format, arg...) do {} while (0)
297#endif
298
299#endif /* _IXGBEVF_H_ */