1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 #include <linux/types.h>
25 #include <linux/etherdevice.h>
26 #include <linux/cpumask.h>
27 #include <linux/rtnetlink.h>
28 #include <linux/if_vlan.h>
29 #include <linux/pci.h>
30 #include <linux/net_tstamp.h>
31 #include <linux/clocksource.h>
32 #include <linux/ptp_clock_kernel.h>
37 #define FM10K_MAX_JUMBO_FRAME_SIZE 15342 /* Maximum supported size 15K */
39 #define MAX_QUEUES FM10K_MAX_QUEUES_PF
41 #define FM10K_MIN_RXD 128
42 #define FM10K_MAX_RXD 4096
43 #define FM10K_DEFAULT_RXD 256
45 #define FM10K_MIN_TXD 128
46 #define FM10K_MAX_TXD 4096
47 #define FM10K_DEFAULT_TXD 256
48 #define FM10K_DEFAULT_TX_WORK 256
50 #define FM10K_RXBUFFER_256 256
51 #define FM10K_RX_HDR_LEN FM10K_RXBUFFER_256
52 #define FM10K_RXBUFFER_2048 2048
53 #define FM10K_RX_BUFSZ FM10K_RXBUFFER_2048
55 /* How many Rx Buffers do we bundle into one write to the hardware ? */
56 #define FM10K_RX_BUFFER_WRITE 16 /* Must be power of 2 */
58 #define FM10K_MAX_STATIONS 63
59 struct fm10k_l2_accel
{
64 struct net_device
*macvlan
[0];
67 enum fm10k_ring_state_t
{
68 __FM10K_TX_DETECT_HANG
,
69 __FM10K_HANG_CHECK_ARMED
,
70 __FM10K_TX_XPS_INIT_DONE
,
73 #define check_for_tx_hang(ring) \
74 test_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
75 #define set_check_for_tx_hang(ring) \
76 set_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
77 #define clear_check_for_tx_hang(ring) \
78 clear_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
80 struct fm10k_tx_buffer
{
81 struct fm10k_tx_desc
*next_to_watch
;
83 unsigned int bytecount
;
86 DEFINE_DMA_UNMAP_ADDR(dma
);
87 DEFINE_DMA_UNMAP_LEN(len
);
90 struct fm10k_rx_buffer
{
96 struct fm10k_queue_stats
{
101 struct fm10k_tx_queue_stats
{
109 struct fm10k_rx_queue_stats
{
122 struct fm10k_q_vector
*q_vector
;/* backpointer to host q_vector */
123 struct net_device
*netdev
; /* netdev ring belongs to */
124 struct device
*dev
; /* device for DMA mapping */
125 struct fm10k_l2_accel __rcu
*l2_accel
; /* L2 acceleration list */
126 void *desc
; /* descriptor ring memory */
128 struct fm10k_tx_buffer
*tx_buffer
;
129 struct fm10k_rx_buffer
*rx_buffer
;
133 dma_addr_t dma
; /* phys. address of descriptor ring */
134 unsigned int size
; /* length in bytes */
136 u8 queue_index
; /* needed for queue management */
137 u8 reg_idx
; /* holds the special value that gets
138 * the hardware register offset
139 * associated with this ring, which is
140 * different for DCB and RSS modes
142 u8 qos_pc
; /* priority class of queue */
143 u16 vid
; /* default VLAN ID of queue */
144 u16 count
; /* amount of descriptors */
150 struct fm10k_queue_stats stats
;
151 struct u64_stats_sync syncp
;
154 struct fm10k_tx_queue_stats tx_stats
;
157 struct fm10k_rx_queue_stats rx_stats
;
161 } ____cacheline_internodealigned_in_smp
;
163 struct fm10k_ring_container
{
164 struct fm10k_ring
*ring
; /* pointer to linked list of rings */
165 unsigned int total_bytes
; /* total bytes processed this int */
166 unsigned int total_packets
; /* total packets processed this int */
167 u16 work_limit
; /* total work allowed per interrupt */
168 u16 itr
; /* interrupt throttle rate value */
169 u8 itr_scale
; /* ITR adjustment based on PCI speed */
170 u8 count
; /* total number of rings in vector */
173 #define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */
174 #define FM10K_ITR_10K 100 /* 100us */
175 #define FM10K_ITR_20K 50 /* 50us */
176 #define FM10K_ITR_40K 25 /* 25us */
177 #define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */
179 #define ITR_IS_ADAPTIVE(itr) (!!(itr & FM10K_ITR_ADAPTIVE))
181 #define FM10K_TX_ITR_DEFAULT FM10K_ITR_40K
182 #define FM10K_RX_ITR_DEFAULT FM10K_ITR_20K
183 #define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR)
185 static inline struct netdev_queue
*txring_txq(const struct fm10k_ring
*ring
)
187 return &ring
->netdev
->_tx
[ring
->queue_index
];
190 /* iterator for handling rings in ring container */
191 #define fm10k_for_each_ring(pos, head) \
192 for (pos = &(head).ring[(head).count]; (--pos) >= (head).ring;)
194 #define MAX_Q_VECTORS 256
195 #define MIN_Q_VECTORS 1
196 enum fm10k_non_q_vectors
{
198 #define NON_Q_VECTORS_VF NON_Q_VECTORS_PF
202 #define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \
205 #define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw))
207 struct fm10k_q_vector
{
208 struct fm10k_intfc
*interface
;
209 u32 __iomem
*itr
; /* pointer to ITR register for this vector */
210 u16 v_idx
; /* index of q_vector within interface array */
211 struct fm10k_ring_container rx
, tx
;
213 struct napi_struct napi
;
214 cpumask_t affinity_mask
;
215 char name
[IFNAMSIZ
+ 9];
217 #ifdef CONFIG_DEBUG_FS
218 struct dentry
*dbg_q_vector
;
219 #endif /* CONFIG_DEBUG_FS */
220 struct rcu_head rcu
; /* to avoid race with update stats on free */
222 /* for dynamic allocation of rings associated with this q_vector */
223 struct fm10k_ring ring
[0] ____cacheline_internodealigned_in_smp
;
226 enum fm10k_ring_f_enum
{
229 RING_F_ARRAY_SIZE
/* must be last in enum set */
232 struct fm10k_ring_feature
{
233 u16 limit
; /* upper limit on feature indices */
234 u16 indices
; /* current value of indices */
235 u16 mask
; /* Mask used for feature to ring mapping */
236 u16 offset
; /* offset to start of feature */
239 struct fm10k_iov_data
{
240 unsigned int num_vfs
;
241 unsigned int next_vf_mbx
;
243 struct fm10k_vf_info vf_info
[0];
246 #define fm10k_vxlan_port_for_each(vp, intfc) \
247 list_for_each_entry(vp, &(intfc)->vxlan_port, list)
248 struct fm10k_vxlan_port
{
249 struct list_head list
;
250 sa_family_t sa_family
;
254 /* one work queue for entire driver */
255 extern struct workqueue_struct
*fm10k_workqueue
;
258 unsigned long active_vlans
[BITS_TO_LONGS(VLAN_N_VID
)];
259 struct net_device
*netdev
;
260 struct fm10k_l2_accel
*l2_accel
; /* pointer to L2 acceleration list */
261 struct pci_dev
*pdev
;
265 #define FM10K_FLAG_RESET_REQUESTED (u32)(1 << 0)
266 #define FM10K_FLAG_RSS_FIELD_IPV4_UDP (u32)(1 << 1)
267 #define FM10K_FLAG_RSS_FIELD_IPV6_UDP (u32)(1 << 2)
268 #define FM10K_FLAG_RX_TS_ENABLED (u32)(1 << 3)
269 #define FM10K_FLAG_SWPRI_CONFIG (u32)(1 << 4)
270 #define FM10K_FLAG_DEBUG_STATS (u32)(1 << 5)
273 /* Tx fast path data */
277 /* Rx fast path data */
282 struct fm10k_ring
*tx_ring
[MAX_QUEUES
] ____cacheline_aligned_in_smp
;
298 /* Debug Statistics */
302 u64 rx_switch_errors
;
306 u64 rx_length_errors
;
308 u32 tx_timeout_count
;
311 struct fm10k_ring
*rx_ring
[MAX_QUEUES
];
313 /* Queueing vectors */
314 struct fm10k_q_vector
*q_vector
[MAX_Q_VECTORS
];
315 struct msix_entry
*msix_entries
;
316 int num_q_vectors
; /* current number of q_vectors for device */
317 struct fm10k_ring_feature ring_feature
[RING_F_ARRAY_SIZE
];
319 /* SR-IOV information management structure */
320 struct fm10k_iov_data
*iov_data
;
322 struct fm10k_hw_stats stats
;
324 u32 __iomem
*uc_addr
;
325 u32 __iomem
*sw_addr
;
329 struct timer_list service_timer
;
330 struct work_struct service_task
;
331 unsigned long next_stats_update
;
332 unsigned long next_tx_hang_check
;
333 unsigned long last_reset
;
334 unsigned long link_down_event
;
337 u32 reta
[FM10K_RETA_SIZE
];
338 u32 rssrk
[FM10K_RSSRK_SIZE
];
340 /* VXLAN port tracking information */
341 struct list_head vxlan_port
;
343 #ifdef CONFIG_DEBUG_FS
344 struct dentry
*dbg_intfc
;
346 #endif /* CONFIG_DEBUG_FS */
347 struct ptp_clock_info ptp_caps
;
348 struct ptp_clock
*ptp_clock
;
350 struct sk_buff_head ts_tx_skb_queue
;
351 u32 tx_hwtstamp_timeouts
;
353 struct hwtstamp_config ts_config
;
354 /* We are unable to actually adjust the clock beyond the frequency
355 * value. Once the clock is started there is no resetting it. As
356 * such we maintain a separate offset from the actual hardware clock
357 * to allow for offset adjustment.
360 rwlock_t systime_lock
;
366 /* GLORT resources in use by PF */
370 /* VLAN ID for updating multicast/unicast lists */
377 __FM10K_SERVICE_SCHED
,
378 __FM10K_SERVICE_DISABLE
,
383 static inline void fm10k_mbx_lock(struct fm10k_intfc
*interface
)
385 /* busy loop if we cannot obtain the lock as some calls
386 * such as ndo_set_rx_mode may be made in atomic context
388 while (test_and_set_bit(__FM10K_MBX_LOCK
, &interface
->state
))
392 static inline void fm10k_mbx_unlock(struct fm10k_intfc
*interface
)
394 /* flush memory to make sure state is correct */
395 smp_mb__before_atomic();
396 clear_bit(__FM10K_MBX_LOCK
, &interface
->state
);
399 static inline int fm10k_mbx_trylock(struct fm10k_intfc
*interface
)
401 return !test_and_set_bit(__FM10K_MBX_LOCK
, &interface
->state
);
404 /* fm10k_test_staterr - test bits in Rx descriptor status and error fields */
405 static inline __le32
fm10k_test_staterr(union fm10k_rx_desc
*rx_desc
,
406 const u32 stat_err_bits
)
408 return rx_desc
->d
.staterr
& cpu_to_le32(stat_err_bits
);
411 /* fm10k_desc_unused - calculate if we have unused descriptors */
412 static inline u16
fm10k_desc_unused(struct fm10k_ring
*ring
)
414 s16 unused
= ring
->next_to_clean
- ring
->next_to_use
- 1;
416 return likely(unused
< 0) ? unused
+ ring
->count
: unused
;
419 #define FM10K_TX_DESC(R, i) \
420 (&(((struct fm10k_tx_desc *)((R)->desc))[i]))
421 #define FM10K_RX_DESC(R, i) \
422 (&(((union fm10k_rx_desc *)((R)->desc))[i]))
424 #define FM10K_MAX_TXD_PWR 14
425 #define FM10K_MAX_DATA_PER_TXD BIT(FM10K_MAX_TXD_PWR)
427 /* Tx Descriptors needed, worst case */
428 #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), FM10K_MAX_DATA_PER_TXD)
429 #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
431 enum fm10k_tx_flags
{
432 /* Tx offload flags */
433 FM10K_TX_FLAGS_CSUM
= 0x01,
436 /* This structure is stored as little endian values as that is the native
437 * format of the Rx descriptor. The ordering of these fields is reversed
438 * from the actual ftag header to allow for a single bswap to take care
439 * of placing all of the values in network order
441 union fm10k_ftag_info
{
444 /* dglort and sglort combined into a single 32bit desc read */
446 /* upper 16 bits of VLAN are reserved 0 for swpri_type_user */
453 __le16 swpri_type_user
;
460 unsigned long ts_tx_timeout
;
462 union fm10k_ftag_info fi
;
465 #define FM10K_CB(skb) ((struct fm10k_cb *)(skb)->cb)
468 extern char fm10k_driver_name
[];
469 extern const char fm10k_driver_version
[];
470 int fm10k_init_queueing_scheme(struct fm10k_intfc
*interface
);
471 void fm10k_clear_queueing_scheme(struct fm10k_intfc
*interface
);
472 __be16
fm10k_tx_encap_offload(struct sk_buff
*skb
);
473 netdev_tx_t
fm10k_xmit_frame_ring(struct sk_buff
*skb
,
474 struct fm10k_ring
*tx_ring
);
475 void fm10k_tx_timeout_reset(struct fm10k_intfc
*interface
);
476 bool fm10k_check_tx_hang(struct fm10k_ring
*tx_ring
);
477 void fm10k_alloc_rx_buffers(struct fm10k_ring
*rx_ring
, u16 cleaned_count
);
480 void fm10k_mbx_free_irq(struct fm10k_intfc
*);
481 int fm10k_mbx_request_irq(struct fm10k_intfc
*);
482 void fm10k_qv_free_irq(struct fm10k_intfc
*interface
);
483 int fm10k_qv_request_irq(struct fm10k_intfc
*interface
);
484 int fm10k_register_pci_driver(void);
485 void fm10k_unregister_pci_driver(void);
486 void fm10k_up(struct fm10k_intfc
*interface
);
487 void fm10k_down(struct fm10k_intfc
*interface
);
488 void fm10k_update_stats(struct fm10k_intfc
*interface
);
489 void fm10k_service_event_schedule(struct fm10k_intfc
*interface
);
490 void fm10k_update_rx_drop_en(struct fm10k_intfc
*interface
);
491 #ifdef CONFIG_NET_POLL_CONTROLLER
492 void fm10k_netpoll(struct net_device
*netdev
);
496 struct net_device
*fm10k_alloc_netdev(const struct fm10k_info
*info
);
497 int fm10k_setup_rx_resources(struct fm10k_ring
*);
498 int fm10k_setup_tx_resources(struct fm10k_ring
*);
499 void fm10k_free_rx_resources(struct fm10k_ring
*);
500 void fm10k_free_tx_resources(struct fm10k_ring
*);
501 void fm10k_clean_all_rx_rings(struct fm10k_intfc
*);
502 void fm10k_clean_all_tx_rings(struct fm10k_intfc
*);
503 void fm10k_unmap_and_free_tx_resource(struct fm10k_ring
*,
504 struct fm10k_tx_buffer
*);
505 void fm10k_restore_rx_state(struct fm10k_intfc
*);
506 void fm10k_reset_rx_state(struct fm10k_intfc
*);
507 int fm10k_setup_tc(struct net_device
*dev
, u8 tc
);
508 int fm10k_open(struct net_device
*netdev
);
509 int fm10k_close(struct net_device
*netdev
);
512 void fm10k_set_ethtool_ops(struct net_device
*dev
);
515 s32
fm10k_iov_event(struct fm10k_intfc
*interface
);
516 s32
fm10k_iov_mbx(struct fm10k_intfc
*interface
);
517 void fm10k_iov_suspend(struct pci_dev
*pdev
);
518 int fm10k_iov_resume(struct pci_dev
*pdev
);
519 void fm10k_iov_disable(struct pci_dev
*pdev
);
520 int fm10k_iov_configure(struct pci_dev
*pdev
, int num_vfs
);
521 s32
fm10k_iov_update_pvid(struct fm10k_intfc
*interface
, u16 glort
, u16 pvid
);
522 int fm10k_ndo_set_vf_mac(struct net_device
*netdev
, int vf_idx
, u8
*mac
);
523 int fm10k_ndo_set_vf_vlan(struct net_device
*netdev
,
524 int vf_idx
, u16 vid
, u8 qos
);
525 int fm10k_ndo_set_vf_bw(struct net_device
*netdev
, int vf_idx
, int rate
,
527 int fm10k_ndo_get_vf_config(struct net_device
*netdev
,
528 int vf_idx
, struct ifla_vf_info
*ivi
);
531 #ifdef CONFIG_DEBUG_FS
532 void fm10k_dbg_q_vector_init(struct fm10k_q_vector
*q_vector
);
533 void fm10k_dbg_q_vector_exit(struct fm10k_q_vector
*q_vector
);
534 void fm10k_dbg_intfc_init(struct fm10k_intfc
*interface
);
535 void fm10k_dbg_intfc_exit(struct fm10k_intfc
*interface
);
536 void fm10k_dbg_init(void);
537 void fm10k_dbg_exit(void);
539 static inline void fm10k_dbg_q_vector_init(struct fm10k_q_vector
*q_vector
) {}
540 static inline void fm10k_dbg_q_vector_exit(struct fm10k_q_vector
*q_vector
) {}
541 static inline void fm10k_dbg_intfc_init(struct fm10k_intfc
*interface
) {}
542 static inline void fm10k_dbg_intfc_exit(struct fm10k_intfc
*interface
) {}
543 static inline void fm10k_dbg_init(void) {}
544 static inline void fm10k_dbg_exit(void) {}
545 #endif /* CONFIG_DEBUG_FS */
548 void fm10k_systime_to_hwtstamp(struct fm10k_intfc
*interface
,
549 struct skb_shared_hwtstamps
*hwtstamp
,
551 void fm10k_ts_tx_enqueue(struct fm10k_intfc
*interface
, struct sk_buff
*skb
);
552 void fm10k_ts_tx_hwtstamp(struct fm10k_intfc
*interface
, __le16 dglort
,
554 void fm10k_ts_reset(struct fm10k_intfc
*interface
);
555 void fm10k_ts_init(struct fm10k_intfc
*interface
);
556 void fm10k_ts_tx_subtask(struct fm10k_intfc
*interface
);
557 void fm10k_ptp_register(struct fm10k_intfc
*interface
);
558 void fm10k_ptp_unregister(struct fm10k_intfc
*interface
);
559 int fm10k_get_ts_config(struct net_device
*netdev
, struct ifreq
*ifr
);
560 int fm10k_set_ts_config(struct net_device
*netdev
, struct ifreq
*ifr
);
564 void fm10k_dcbnl_set_ops(struct net_device
*dev
);
566 static inline void fm10k_dcbnl_set_ops(struct net_device
*dev
) {}
568 #endif /* _FM10K_H_ */