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 #ifdef CONFIG_NET_RX_BUSY_POLL
42 #include <net/busy_poll.h>
43 #define BP_EXTENDED_STATS
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 {
51 unsigned long time_stamp;
52 union ixgbe_adv_tx_desc *next_to_watch;
57 struct ixgbevf_rx_buffer {
63 struct ixgbevf_ring *next;
64 struct net_device *netdev;
66 void *desc; /* descriptor ring memory */
67 dma_addr_t dma; /* phys. address of descriptor ring */
68 unsigned int size; /* length in bytes */
69 unsigned int count; /* amount of descriptors */
70 unsigned int next_to_use;
71 unsigned int next_to_clean;
73 int queue_index; /* needed for multiqueue queue management */
75 struct ixgbevf_tx_buffer *tx_buffer_info;
76 struct ixgbevf_rx_buffer *rx_buffer_info;
81 struct u64_stats_sync syncp;
84 #ifdef BP_EXTENDED_STATS
91 u16 reg_idx; /* holds the special value that gets the hardware register
92 * offset associated with this ring, which is different
93 * for DCB and RSS modes */
98 /* How many Rx Buffers do we bundle into one write to the hardware ? */
99 #define IXGBEVF_RX_BUFFER_WRITE 16 /* Must be power of 2 */
101 #define MAX_RX_QUEUES IXGBE_VF_MAX_RX_QUEUES
102 #define MAX_TX_QUEUES IXGBE_VF_MAX_TX_QUEUES
104 #define IXGBEVF_DEFAULT_TXD 1024
105 #define IXGBEVF_DEFAULT_RXD 512
106 #define IXGBEVF_MAX_TXD 4096
107 #define IXGBEVF_MIN_TXD 64
108 #define IXGBEVF_MAX_RXD 4096
109 #define IXGBEVF_MIN_RXD 64
111 /* Supported Rx Buffer Sizes */
112 #define IXGBEVF_RXBUFFER_256 256 /* Used for packet split */
113 #define IXGBEVF_RXBUFFER_2K 2048
114 #define IXGBEVF_RXBUFFER_4K 4096
115 #define IXGBEVF_RXBUFFER_8K 8192
116 #define IXGBEVF_RXBUFFER_10K 10240
118 #define IXGBEVF_RX_HDR_SIZE IXGBEVF_RXBUFFER_256
120 #define MAXIMUM_ETHERNET_VLAN_SIZE (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
122 #define IXGBE_TX_FLAGS_CSUM (u32)(1)
123 #define IXGBE_TX_FLAGS_VLAN (u32)(1 << 1)
124 #define IXGBE_TX_FLAGS_TSO (u32)(1 << 2)
125 #define IXGBE_TX_FLAGS_IPV4 (u32)(1 << 3)
126 #define IXGBE_TX_FLAGS_FCOE (u32)(1 << 4)
127 #define IXGBE_TX_FLAGS_FSO (u32)(1 << 5)
128 #define IXGBE_TX_FLAGS_VLAN_MASK 0xffff0000
129 #define IXGBE_TX_FLAGS_VLAN_PRIO_MASK 0x0000e000
130 #define IXGBE_TX_FLAGS_VLAN_SHIFT 16
132 struct ixgbevf_ring_container {
133 struct ixgbevf_ring *ring; /* pointer to linked list of rings */
134 unsigned int total_bytes; /* total bytes processed this int */
135 unsigned int total_packets; /* total packets processed this int */
136 u8 count; /* total number of rings in vector */
137 u8 itr; /* current ITR setting for ring */
140 /* iterator for handling rings in ring container */
141 #define ixgbevf_for_each_ring(pos, head) \
142 for (pos = (head).ring; pos != NULL; pos = pos->next)
144 /* MAX_MSIX_Q_VECTORS of these are allocated,
145 * but we only use one per queue-specific vector.
147 struct ixgbevf_q_vector {
148 struct ixgbevf_adapter *adapter;
149 u16 v_idx; /* index of q_vector within array, also used for
150 * finding the bit in EICR and friends that
151 * represents the vector for this ring */
152 u16 itr; /* Interrupt throttle rate written to EITR */
153 struct napi_struct napi;
154 struct ixgbevf_ring_container rx, tx;
155 char name[IFNAMSIZ + 9];
156 #ifdef CONFIG_NET_RX_BUSY_POLL
158 #define IXGBEVF_QV_STATE_IDLE 0
159 #define IXGBEVF_QV_STATE_NAPI 1 /* NAPI owns this QV */
160 #define IXGBEVF_QV_STATE_POLL 2 /* poll owns this QV */
161 #define IXGBEVF_QV_STATE_DISABLED 4 /* QV is disabled */
162 #define IXGBEVF_QV_OWNED (IXGBEVF_QV_STATE_NAPI | IXGBEVF_QV_STATE_POLL)
163 #define IXGBEVF_QV_LOCKED (IXGBEVF_QV_OWNED | IXGBEVF_QV_STATE_DISABLED)
164 #define IXGBEVF_QV_STATE_NAPI_YIELD 8 /* NAPI yielded this QV */
165 #define IXGBEVF_QV_STATE_POLL_YIELD 16 /* poll yielded this QV */
166 #define IXGBEVF_QV_YIELD (IXGBEVF_QV_STATE_NAPI_YIELD | IXGBEVF_QV_STATE_POLL_YIELD)
167 #define IXGBEVF_QV_USER_PEND (IXGBEVF_QV_STATE_POLL | IXGBEVF_QV_STATE_POLL_YIELD)
169 #endif /* CONFIG_NET_RX_BUSY_POLL */
171 #ifdef CONFIG_NET_RX_BUSY_POLL
172 static inline void ixgbevf_qv_init_lock(struct ixgbevf_q_vector *q_vector)
175 spin_lock_init(&q_vector->lock);
176 q_vector->state = IXGBEVF_QV_STATE_IDLE;
179 /* called from the device poll routine to get ownership of a q_vector */
180 static inline bool ixgbevf_qv_lock_napi(struct ixgbevf_q_vector *q_vector)
183 spin_lock_bh(&q_vector->lock);
184 if (q_vector->state & IXGBEVF_QV_LOCKED) {
185 WARN_ON(q_vector->state & IXGBEVF_QV_STATE_NAPI);
186 q_vector->state |= IXGBEVF_QV_STATE_NAPI_YIELD;
188 #ifdef BP_EXTENDED_STATS
189 q_vector->tx.ring->bp_yields++;
192 /* we don't care if someone yielded */
193 q_vector->state = IXGBEVF_QV_STATE_NAPI;
195 spin_unlock_bh(&q_vector->lock);
199 /* returns true is someone tried to get the qv while napi had it */
200 static inline bool ixgbevf_qv_unlock_napi(struct ixgbevf_q_vector *q_vector)
203 spin_lock_bh(&q_vector->lock);
204 WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_POLL |
205 IXGBEVF_QV_STATE_NAPI_YIELD));
207 if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
209 /* reset state to idle, unless QV is disabled */
210 q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
211 spin_unlock_bh(&q_vector->lock);
215 /* called from ixgbevf_low_latency_poll() */
216 static inline bool ixgbevf_qv_lock_poll(struct ixgbevf_q_vector *q_vector)
219 spin_lock_bh(&q_vector->lock);
220 if ((q_vector->state & IXGBEVF_QV_LOCKED)) {
221 q_vector->state |= IXGBEVF_QV_STATE_POLL_YIELD;
223 #ifdef BP_EXTENDED_STATS
224 q_vector->rx.ring->bp_yields++;
227 /* preserve yield marks */
228 q_vector->state |= IXGBEVF_QV_STATE_POLL;
230 spin_unlock_bh(&q_vector->lock);
234 /* returns true if someone tried to get the qv while it was locked */
235 static inline bool ixgbevf_qv_unlock_poll(struct ixgbevf_q_vector *q_vector)
238 spin_lock_bh(&q_vector->lock);
239 WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_NAPI));
241 if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
243 /* reset state to idle, unless QV is disabled */
244 q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
245 spin_unlock_bh(&q_vector->lock);
249 /* true if a socket is polling, even if it did not get the lock */
250 static inline bool ixgbevf_qv_busy_polling(struct ixgbevf_q_vector *q_vector)
252 WARN_ON(!(q_vector->state & IXGBEVF_QV_OWNED));
253 return q_vector->state & IXGBEVF_QV_USER_PEND;
256 /* false if QV is currently owned */
257 static inline bool ixgbevf_qv_disable(struct ixgbevf_q_vector *q_vector)
260 spin_lock_bh(&q_vector->lock);
261 if (q_vector->state & IXGBEVF_QV_OWNED)
263 spin_unlock_bh(&q_vector->lock);
267 #endif /* CONFIG_NET_RX_BUSY_POLL */
270 * microsecond values for various ITR rates shifted by 2 to fit itr register
271 * with the first 3 bits reserved 0
273 #define IXGBE_MIN_RSC_ITR 24
274 #define IXGBE_100K_ITR 40
275 #define IXGBE_20K_ITR 200
276 #define IXGBE_10K_ITR 400
277 #define IXGBE_8K_ITR 500
279 /* Helper macros to switch between ints/sec and what the register uses.
280 * And yes, it's the same math going both ways. The lowest value
281 * supported by all of the ixgbe hardware is 8.
283 #define EITR_INTS_PER_SEC_TO_REG(_eitr) \
284 ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
285 #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
287 static inline u16 ixgbevf_desc_unused(struct ixgbevf_ring *ring)
289 u16 ntc = ring->next_to_clean;
290 u16 ntu = ring->next_to_use;
292 return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
295 #define IXGBEVF_RX_DESC(R, i) \
296 (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
297 #define IXGBEVF_TX_DESC(R, i) \
298 (&(((union ixgbe_adv_tx_desc *)((R)->desc))[i]))
299 #define IXGBEVF_TX_CTXTDESC(R, i) \
300 (&(((struct ixgbe_adv_tx_context_desc *)((R)->desc))[i]))
302 #define IXGBE_MAX_JUMBO_FRAME_SIZE 9728 /* Maximum Supported Size 9.5KB */
304 #define OTHER_VECTOR 1
305 #define NON_Q_VECTORS (OTHER_VECTOR)
307 #define MAX_MSIX_Q_VECTORS 2
309 #define MIN_MSIX_Q_VECTORS 1
310 #define MIN_MSIX_COUNT (MIN_MSIX_Q_VECTORS + NON_Q_VECTORS)
312 /* board specific private data structure */
313 struct ixgbevf_adapter {
314 struct timer_list watchdog_timer;
315 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
317 struct work_struct reset_task;
318 struct ixgbevf_q_vector *q_vector[MAX_MSIX_Q_VECTORS];
320 /* Interrupt Throttle Rate */
324 /* interrupt masks */
325 u32 eims_enable_mask;
329 struct ixgbevf_ring *tx_ring; /* One per active queue */
336 u32 tx_timeout_count;
339 struct ixgbevf_ring *rx_ring; /* One per active queue */
341 u64 hw_csum_rx_error;
342 u64 hw_rx_no_dma_resources;
345 int num_msix_vectors;
346 struct msix_entry *msix_entries;
348 u32 alloc_rx_page_failed;
349 u32 alloc_rx_buff_failed;
351 /* Some features need tri-state capability,
352 * thus the additional *_CAPABLE flags.
355 #define IXGBE_FLAG_IN_WATCHDOG_TASK (u32)(1)
356 #define IXGBE_FLAG_IN_NETPOLL (u32)(1 << 1)
357 #define IXGBEVF_FLAG_QUEUE_RESET_REQUESTED (u32)(1 << 2)
359 /* OS defined structs */
360 struct net_device *netdev;
361 struct pci_dev *pdev;
363 /* structs defined in ixgbe_vf.h */
366 struct ixgbevf_hw_stats stats;
367 /* Interrupt Throttle Rate */
372 unsigned int tx_ring_count;
373 unsigned int rx_ring_count;
375 #ifdef BP_EXTENDED_STATS
388 struct work_struct watchdog_task;
393 enum ixbgevf_state_t {
400 struct sk_buff *prev;
402 #define IXGBE_CB(skb) ((struct ixgbevf_cb *)(skb)->cb)
404 enum ixgbevf_boards {
409 extern const struct ixgbevf_info ixgbevf_82599_vf_info;
410 extern const struct ixgbevf_info ixgbevf_X540_vf_info;
411 extern const struct ixgbe_mbx_operations ixgbevf_mbx_ops;
413 /* needed by ethtool.c */
414 extern const char ixgbevf_driver_name[];
415 extern const char ixgbevf_driver_version[];
417 void ixgbevf_up(struct ixgbevf_adapter *adapter);
418 void ixgbevf_down(struct ixgbevf_adapter *adapter);
419 void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter);
420 void ixgbevf_reset(struct ixgbevf_adapter *adapter);
421 void ixgbevf_set_ethtool_ops(struct net_device *netdev);
422 int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *, struct ixgbevf_ring *);
423 int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *, struct ixgbevf_ring *);
424 void ixgbevf_free_rx_resources(struct ixgbevf_adapter *, struct ixgbevf_ring *);
425 void ixgbevf_free_tx_resources(struct ixgbevf_adapter *, struct ixgbevf_ring *);
426 void ixgbevf_update_stats(struct ixgbevf_adapter *adapter);
427 int ethtool_ioctl(struct ifreq *ifr);
429 extern void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector);
431 void ixgbe_napi_add_all(struct ixgbevf_adapter *adapter);
432 void ixgbe_napi_del_all(struct ixgbevf_adapter *adapter);
435 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw);
436 #define hw_dbg(hw, format, arg...) \
437 printk(KERN_DEBUG "%s: " format, ixgbevf_get_hw_dev_name(hw), ##arg)
439 #define hw_dbg(hw, format, arg...) do {} while (0)
442 #endif /* _IXGBEVF_H_ */