ixgbevf: make the first tx_buffer a repository for most of the skb info
[deliverable/linux.git] / drivers / net / ethernet / intel / ixgbevf / ixgbevf.h
1 /*******************************************************************************
2
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
5
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>
32 #include <linux/bitops.h>
33 #include <linux/timer.h>
34 #include <linux/io.h>
35 #include <linux/netdevice.h>
36 #include <linux/if_vlan.h>
37 #include <linux/u64_stats_sync.h>
38
39 #include "vf.h"
40
41 #ifdef CONFIG_NET_RX_BUSY_POLL
42 #include <net/busy_poll.h>
43 #define BP_EXTENDED_STATS
44 #endif
45
46 /* wrapper around a pointer to a socket buffer,
47 * so a DMA handle can be stored along with the buffer */
48 struct ixgbevf_tx_buffer {
49 union ixgbe_adv_tx_desc *next_to_watch;
50 unsigned long time_stamp;
51 struct sk_buff *skb;
52 unsigned int bytecount;
53 unsigned short gso_segs;
54 __be16 protocol;
55 dma_addr_t dma;
56 u32 tx_flags;
57 u16 length;
58 };
59
60 struct ixgbevf_rx_buffer {
61 struct sk_buff *skb;
62 dma_addr_t dma;
63 };
64
65 struct ixgbevf_stats {
66 u64 packets;
67 u64 bytes;
68 #ifdef BP_EXTENDED_STATS
69 u64 yields;
70 u64 misses;
71 u64 cleaned;
72 #endif
73 };
74
75 struct ixgbevf_tx_queue_stats {
76 u64 restart_queue;
77 u64 tx_busy;
78 u64 tx_done_old;
79 };
80
81 struct ixgbevf_rx_queue_stats {
82 u64 non_eop_descs;
83 u64 alloc_rx_page_failed;
84 u64 alloc_rx_buff_failed;
85 u64 csum_err;
86 };
87
88 struct ixgbevf_ring {
89 struct ixgbevf_ring *next;
90 struct net_device *netdev;
91 struct device *dev;
92 void *desc; /* descriptor ring memory */
93 dma_addr_t dma; /* phys. address of descriptor ring */
94 unsigned int size; /* length in bytes */
95 unsigned int count; /* amount of descriptors */
96 unsigned int next_to_use;
97 unsigned int next_to_clean;
98
99 union {
100 struct ixgbevf_tx_buffer *tx_buffer_info;
101 struct ixgbevf_rx_buffer *rx_buffer_info;
102 };
103
104 struct ixgbevf_stats stats;
105 struct u64_stats_sync syncp;
106 union {
107 struct ixgbevf_tx_queue_stats tx_stats;
108 struct ixgbevf_rx_queue_stats rx_stats;
109 };
110
111 u64 hw_csum_rx_error;
112 u8 __iomem *tail;
113
114 u16 reg_idx; /* holds the special value that gets the hardware register
115 * offset associated with this ring, which is different
116 * for DCB and RSS modes */
117
118 u16 rx_buf_len;
119 int queue_index; /* needed for multiqueue queue management */
120 };
121
122 /* How many Rx Buffers do we bundle into one write to the hardware ? */
123 #define IXGBEVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
124
125 #define MAX_RX_QUEUES IXGBE_VF_MAX_RX_QUEUES
126 #define MAX_TX_QUEUES IXGBE_VF_MAX_TX_QUEUES
127
128 #define IXGBEVF_DEFAULT_TXD 1024
129 #define IXGBEVF_DEFAULT_RXD 512
130 #define IXGBEVF_MAX_TXD 4096
131 #define IXGBEVF_MIN_TXD 64
132 #define IXGBEVF_MAX_RXD 4096
133 #define IXGBEVF_MIN_RXD 64
134
135 /* Supported Rx Buffer Sizes */
136 #define IXGBEVF_RXBUFFER_256 256 /* Used for packet split */
137 #define IXGBEVF_RXBUFFER_2K 2048
138 #define IXGBEVF_RXBUFFER_4K 4096
139 #define IXGBEVF_RXBUFFER_8K 8192
140 #define IXGBEVF_RXBUFFER_10K 10240
141
142 #define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256
143
144 #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
145
146 #define IXGBE_TX_FLAGS_CSUM (u32)(1)
147 #define IXGBE_TX_FLAGS_VLAN (u32)(1 << 1)
148 #define IXGBE_TX_FLAGS_TSO (u32)(1 << 2)
149 #define IXGBE_TX_FLAGS_IPV4 (u32)(1 << 3)
150 #define IXGBE_TX_FLAGS_MAPPED_AS_PAGE (u32)(1 << 4)
151 #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000
152 #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000
153 #define IXGBE_TX_FLAGS_VLAN_SHIFT 16
154
155 struct ixgbevf_ring_container {
156 struct ixgbevf_ring *ring; /* pointer to linked list of rings */
157 unsigned int total_bytes; /* total bytes processed this int */
158 unsigned int total_packets; /* total packets processed this int */
159 u8 count; /* total number of rings in vector */
160 u8 itr; /* current ITR setting for ring */
161 };
162
163 /* iterator for handling rings in ring container */
164 #define ixgbevf_for_each_ring(pos, head) \
165 for (pos = (head).ring; pos != NULL; pos = pos->next)
166
167 /* MAX_MSIX_Q_VECTORS of these are allocated,
168 * but we only use one per queue-specific vector.
169 */
170 struct ixgbevf_q_vector {
171 struct ixgbevf_adapter *adapter;
172 u16 v_idx; /* index of q_vector within array, also used for
173 * finding the bit in EICR and friends that
174 * represents the vector for this ring */
175 u16 itr; /* Interrupt throttle rate written to EITR */
176 struct napi_struct napi;
177 struct ixgbevf_ring_container rx, tx;
178 char name[IFNAMSIZ + 9];
179 #ifdef CONFIG_NET_RX_BUSY_POLL
180 unsigned int state;
181 #define IXGBEVF_QV_STATE_IDLE 0
182 #define IXGBEVF_QV_STATE_NAPI 1 /* NAPI owns this QV */
183 #define IXGBEVF_QV_STATE_POLL 2 /* poll owns this QV */
184 #define IXGBEVF_QV_STATE_DISABLED 4 /* QV is disabled */
185 #define IXGBEVF_QV_OWNED (IXGBEVF_QV_STATE_NAPI | IXGBEVF_QV_STATE_POLL)
186 #define IXGBEVF_QV_LOCKED (IXGBEVF_QV_OWNED | IXGBEVF_QV_STATE_DISABLED)
187 #define IXGBEVF_QV_STATE_NAPI_YIELD 8 /* NAPI yielded this QV */
188 #define IXGBEVF_QV_STATE_POLL_YIELD 16 /* poll yielded this QV */
189 #define IXGBEVF_QV_YIELD (IXGBEVF_QV_STATE_NAPI_YIELD | IXGBEVF_QV_STATE_POLL_YIELD)
190 #define IXGBEVF_QV_USER_PEND (IXGBEVF_QV_STATE_POLL | IXGBEVF_QV_STATE_POLL_YIELD)
191 spinlock_t lock;
192 #endif /* CONFIG_NET_RX_BUSY_POLL */
193 };
194 #ifdef CONFIG_NET_RX_BUSY_POLL
195 static inline void ixgbevf_qv_init_lock(struct ixgbevf_q_vector *q_vector)
196 {
197
198 spin_lock_init(&q_vector->lock);
199 q_vector->state = IXGBEVF_QV_STATE_IDLE;
200 }
201
202 /* called from the device poll routine to get ownership of a q_vector */
203 static inline bool ixgbevf_qv_lock_napi(struct ixgbevf_q_vector *q_vector)
204 {
205 int rc = true;
206 spin_lock_bh(&q_vector->lock);
207 if (q_vector->state & IXGBEVF_QV_LOCKED) {
208 WARN_ON(q_vector->state & IXGBEVF_QV_STATE_NAPI);
209 q_vector->state |= IXGBEVF_QV_STATE_NAPI_YIELD;
210 rc = false;
211 #ifdef BP_EXTENDED_STATS
212 q_vector->tx.ring->stats.yields++;
213 #endif
214 } else {
215 /* we don't care if someone yielded */
216 q_vector->state = IXGBEVF_QV_STATE_NAPI;
217 }
218 spin_unlock_bh(&q_vector->lock);
219 return rc;
220 }
221
222 /* returns true is someone tried to get the qv while napi had it */
223 static inline bool ixgbevf_qv_unlock_napi(struct ixgbevf_q_vector *q_vector)
224 {
225 int rc = false;
226 spin_lock_bh(&q_vector->lock);
227 WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_POLL |
228 IXGBEVF_QV_STATE_NAPI_YIELD));
229
230 if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
231 rc = true;
232 /* reset state to idle, unless QV is disabled */
233 q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
234 spin_unlock_bh(&q_vector->lock);
235 return rc;
236 }
237
238 /* called from ixgbevf_low_latency_poll() */
239 static inline bool ixgbevf_qv_lock_poll(struct ixgbevf_q_vector *q_vector)
240 {
241 int rc = true;
242 spin_lock_bh(&q_vector->lock);
243 if ((q_vector->state & IXGBEVF_QV_LOCKED)) {
244 q_vector->state |= IXGBEVF_QV_STATE_POLL_YIELD;
245 rc = false;
246 #ifdef BP_EXTENDED_STATS
247 q_vector->rx.ring->stats.yields++;
248 #endif
249 } else {
250 /* preserve yield marks */
251 q_vector->state |= IXGBEVF_QV_STATE_POLL;
252 }
253 spin_unlock_bh(&q_vector->lock);
254 return rc;
255 }
256
257 /* returns true if someone tried to get the qv while it was locked */
258 static inline bool ixgbevf_qv_unlock_poll(struct ixgbevf_q_vector *q_vector)
259 {
260 int rc = false;
261 spin_lock_bh(&q_vector->lock);
262 WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_NAPI));
263
264 if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
265 rc = true;
266 /* reset state to idle, unless QV is disabled */
267 q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
268 spin_unlock_bh(&q_vector->lock);
269 return rc;
270 }
271
272 /* true if a socket is polling, even if it did not get the lock */
273 static inline bool ixgbevf_qv_busy_polling(struct ixgbevf_q_vector *q_vector)
274 {
275 WARN_ON(!(q_vector->state & IXGBEVF_QV_OWNED));
276 return q_vector->state & IXGBEVF_QV_USER_PEND;
277 }
278
279 /* false if QV is currently owned */
280 static inline bool ixgbevf_qv_disable(struct ixgbevf_q_vector *q_vector)
281 {
282 int rc = true;
283 spin_lock_bh(&q_vector->lock);
284 if (q_vector->state & IXGBEVF_QV_OWNED)
285 rc = false;
286 q_vector->state |= IXGBEVF_QV_STATE_DISABLED;
287 spin_unlock_bh(&q_vector->lock);
288 return rc;
289 }
290
291 #endif /* CONFIG_NET_RX_BUSY_POLL */
292
293 /*
294 * microsecond values for various ITR rates shifted by 2 to fit itr register
295 * with the first 3 bits reserved 0
296 */
297 #define IXGBE_MIN_RSC_ITR 24
298 #define IXGBE_100K_ITR 40
299 #define IXGBE_20K_ITR 200
300 #define IXGBE_10K_ITR 400
301 #define IXGBE_8K_ITR 500
302
303 /* Helper macros to switch between ints/sec and what the register uses.
304 * And yes, it's the same math going both ways. The lowest value
305 * supported by all of the ixgbe hardware is 8.
306 */
307 #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
308 ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
309 #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
310
311 static inline u16 ixgbevf_desc_unused(struct ixgbevf_ring *ring)
312 {
313 u16 ntc = ring->next_to_clean;
314 u16 ntu = ring->next_to_use;
315
316 return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
317 }
318
319 #define IXGBEVF_RX_DESC(R, i) \
320 (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
321 #define IXGBEVF_TX_DESC(R, i) \
322 (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i]))
323 #define IXGBEVF_TX_CTXTDESC(R, i) \
324 (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i]))
325
326 #define IXGBE_MAX_JUMBO_FRAME_SIZE 9728 /* Maximum Supported Size 9.5KB */
327
328 #define OTHER_VECTOR 1
329 #define NON_Q_VECTORS (OTHER_VECTOR)
330
331 #define MAX_MSIX_Q_VECTORS 2
332
333 #define MIN_MSIX_Q_VECTORS 1
334 #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
335
336 /* board specific private data structure */
337 struct ixgbevf_adapter {
338 struct timer_list watchdog_timer;
339 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
340 struct work_struct reset_task;
341 struct ixgbevf_q_vector *q_vector[MAX_MSIX_Q_VECTORS];
342
343 /* Interrupt Throttle Rate */
344 u16 rx_itr_setting;
345 u16 tx_itr_setting;
346
347 /* interrupt masks */
348 u32 eims_enable_mask;
349 u32 eims_other;
350
351 /* TX */
352 int num_tx_queues;
353 struct ixgbevf_ring *tx_ring[MAX_TX_QUEUES]; /* One per active queue */
354 u64 restart_queue;
355 u32 tx_timeout_count;
356
357 /* RX */
358 int num_rx_queues;
359 struct ixgbevf_ring *rx_ring[MAX_TX_QUEUES]; /* One per active queue */
360 u64 hw_csum_rx_error;
361 u64 hw_rx_no_dma_resources;
362 u64 non_eop_descs;
363 int num_msix_vectors;
364 u32 alloc_rx_page_failed;
365 u32 alloc_rx_buff_failed;
366
367 /* Some features need tri-state capability,
368 * thus the additional *_CAPABLE flags.
369 */
370 u32 flags;
371 #define IXGBE_FLAG_IN_WATCHDOG_TASK (u32)(1)
372 #define IXGBE_FLAG_IN_NETPOLL (u32)(1 << 1)
373 #define IXGBEVF_FLAG_QUEUE_RESET_REQUESTED (u32)(1 << 2)
374
375 struct msix_entry *msix_entries;
376
377 /* OS defined structs */
378 struct net_device *netdev;
379 struct pci_dev *pdev;
380
381 /* structs defined in ixgbe_vf.h */
382 struct ixgbe_hw hw;
383 u16 msg_enable;
384 u16 bd_number;
385 /* Interrupt Throttle Rate */
386 u32 eitr_param;
387
388 struct ixgbevf_hw_stats stats;
389
390 unsigned long state;
391 u64 tx_busy;
392 unsigned int tx_ring_count;
393 unsigned int rx_ring_count;
394
395 #ifdef BP_EXTENDED_STATS
396 u64 bp_rx_yields;
397 u64 bp_rx_cleaned;
398 u64 bp_rx_missed;
399
400 u64 bp_tx_yields;
401 u64 bp_tx_cleaned;
402 u64 bp_tx_missed;
403 #endif
404
405 u32 link_speed;
406 bool link_up;
407
408 spinlock_t mbx_lock;
409
410 struct work_struct watchdog_task;
411 };
412
413 enum ixbgevf_state_t {
414 __IXGBEVF_TESTING,
415 __IXGBEVF_RESETTING,
416 __IXGBEVF_DOWN
417 };
418
419 struct ixgbevf_cb {
420 struct sk_buff *prev;
421 };
422 #define IXGBE_CB(skb) ((struct ixgbevf_cb *)(skb)->cb)
423
424 enum ixgbevf_boards {
425 board_82599_vf,
426 board_X540_vf,
427 };
428
429 extern const struct ixgbevf_info ixgbevf_82599_vf_info;
430 extern const struct ixgbevf_info ixgbevf_X540_vf_info;
431 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
432
433 /* needed by ethtool.c */
434 extern const char ixgbevf_driver_name[];
435 extern const char ixgbevf_driver_version[];
436
437 void ixgbevf_up(struct ixgbevf_adapter *adapter);
438 void ixgbevf_down(struct ixgbevf_adapter *adapter);
439 void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter);
440 void ixgbevf_reset(struct ixgbevf_adapter *adapter);
441 void ixgbevf_set_ethtool_ops(struct net_device *netdev);
442 int ixgbevf_setup_rx_resources(struct ixgbevf_ring *);
443 int ixgbevf_setup_tx_resources(struct ixgbevf_ring *);
444 void ixgbevf_free_rx_resources(struct ixgbevf_ring *);
445 void ixgbevf_free_tx_resources(struct ixgbevf_ring *);
446 void ixgbevf_update_stats(struct ixgbevf_adapter *adapter);
447 int ethtool_ioctl(struct ifreq *ifr);
448
449 extern void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector);
450
451 void ixgbe_napi_add_all(struct ixgbevf_adapter *adapter);
452 void ixgbe_napi_del_all(struct ixgbevf_adapter *adapter);
453
454 #ifdef DEBUG
455 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw);
456 #define hw_dbg(hw, format, arg...) \
457 printk(KERN_DEBUG "%s: " format, ixgbevf_get_hw_dev_name(hw), ##arg)
458 #else
459 #define hw_dbg(hw, format, arg...) do {} while (0)
460 #endif
461
462 #endif /* _IXGBEVF_H_ */
This page took 0.045632 seconds and 5 git commands to generate.