1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 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/rtnetlink.h>
27 #include <linux/if_vlan.h>
28 #include <linux/pci.h>
33 #define FM10K_MAX_JUMBO_FRAME_SIZE 15358 /* Maximum supported size 15K */
35 #define MAX_QUEUES FM10K_MAX_QUEUES_PF
37 #define FM10K_MIN_RXD 128
38 #define FM10K_MAX_RXD 4096
39 #define FM10K_DEFAULT_RXD 256
41 #define FM10K_MIN_TXD 128
42 #define FM10K_MAX_TXD 4096
43 #define FM10K_DEFAULT_TXD 256
44 #define FM10K_DEFAULT_TX_WORK 256
46 #define FM10K_RXBUFFER_256 256
47 #define FM10K_RXBUFFER_16384 16384
48 #define FM10K_RX_HDR_LEN FM10K_RXBUFFER_256
49 #if PAGE_SIZE <= FM10K_RXBUFFER_16384
50 #define FM10K_RX_BUFSZ (PAGE_SIZE / 2)
52 #define FM10K_RX_BUFSZ FM10K_RXBUFFER_16384
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
,
72 #define check_for_tx_hang(ring) \
73 test_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
74 #define set_check_for_tx_hang(ring) \
75 set_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
76 #define clear_check_for_tx_hang(ring) \
77 clear_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
79 struct fm10k_tx_buffer
{
80 struct fm10k_tx_desc
*next_to_watch
;
82 unsigned int bytecount
;
85 DEFINE_DMA_UNMAP_ADDR(dma
);
86 DEFINE_DMA_UNMAP_LEN(len
);
89 struct fm10k_rx_buffer
{
95 struct fm10k_queue_stats
{
100 struct fm10k_tx_queue_stats
{
107 struct fm10k_rx_queue_stats
{
114 struct fm10k_q_vector
*q_vector
;/* backpointer to host q_vector */
115 struct net_device
*netdev
; /* netdev ring belongs to */
116 struct device
*dev
; /* device for DMA mapping */
117 struct fm10k_l2_accel __rcu
*l2_accel
; /* L2 acceleration list */
118 void *desc
; /* descriptor ring memory */
120 struct fm10k_tx_buffer
*tx_buffer
;
121 struct fm10k_rx_buffer
*rx_buffer
;
125 dma_addr_t dma
; /* phys. address of descriptor ring */
126 unsigned int size
; /* length in bytes */
128 u8 queue_index
; /* needed for queue management */
129 u8 reg_idx
; /* holds the special value that gets
130 * the hardware register offset
131 * associated with this ring, which is
132 * different for DCB and RSS modes
134 u8 qos_pc
; /* priority class of queue */
135 u16 vid
; /* default vlan ID of queue */
136 u16 count
; /* amount of descriptors */
142 struct fm10k_queue_stats stats
;
143 struct u64_stats_sync syncp
;
146 struct fm10k_tx_queue_stats tx_stats
;
149 struct fm10k_rx_queue_stats rx_stats
;
153 } ____cacheline_internodealigned_in_smp
;
155 struct fm10k_ring_container
{
156 struct fm10k_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 u16 work_limit
; /* total work allowed per interrupt */
160 u16 itr
; /* interrupt throttle rate value */
161 u8 count
; /* total number of rings in vector */
164 #define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */
165 #define FM10K_ITR_10K 100 /* 100us */
166 #define FM10K_ITR_20K 50 /* 50us */
167 #define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */
169 #define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR)
171 static inline struct netdev_queue
*txring_txq(const struct fm10k_ring
*ring
)
173 return &ring
->netdev
->_tx
[ring
->queue_index
];
176 /* iterator for handling rings in ring container */
177 #define fm10k_for_each_ring(pos, head) \
178 for (pos = &(head).ring[(head).count]; (--pos) >= (head).ring;)
180 #define MAX_Q_VECTORS 256
181 #define MIN_Q_VECTORS 1
182 enum fm10k_non_q_vectors
{
184 #define NON_Q_VECTORS_VF NON_Q_VECTORS_PF
188 #define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \
191 #define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw))
193 struct fm10k_q_vector
{
194 struct fm10k_intfc
*interface
;
195 u32 __iomem
*itr
; /* pointer to ITR register for this vector */
196 u16 v_idx
; /* index of q_vector within interface array */
197 struct fm10k_ring_container rx
, tx
;
199 struct napi_struct napi
;
200 char name
[IFNAMSIZ
+ 9];
202 struct rcu_head rcu
; /* to avoid race with update stats on free */
204 /* for dynamic allocation of rings associated with this q_vector */
205 struct fm10k_ring ring
[0] ____cacheline_internodealigned_in_smp
;
208 enum fm10k_ring_f_enum
{
211 RING_F_ARRAY_SIZE
/* must be last in enum set */
214 struct fm10k_ring_feature
{
215 u16 limit
; /* upper limit on feature indices */
216 u16 indices
; /* current value of indices */
217 u16 mask
; /* Mask used for feature to ring mapping */
218 u16 offset
; /* offset to start of feature */
221 #define fm10k_vxlan_port_for_each(vp, intfc) \
222 list_for_each_entry(vp, &(intfc)->vxlan_port, list)
223 struct fm10k_vxlan_port
{
224 struct list_head list
;
225 sa_family_t sa_family
;
230 unsigned long active_vlans
[BITS_TO_LONGS(VLAN_N_VID
)];
231 struct net_device
*netdev
;
232 struct fm10k_l2_accel
*l2_accel
; /* pointer to L2 acceleration list */
233 struct pci_dev
*pdev
;
237 #define FM10K_FLAG_RESET_REQUESTED (u32)(1 << 0)
238 #define FM10K_FLAG_RSS_FIELD_IPV4_UDP (u32)(1 << 1)
239 #define FM10K_FLAG_RSS_FIELD_IPV6_UDP (u32)(1 << 2)
240 #define FM10K_FLAG_RX_TS_ENABLED (u32)(1 << 3)
241 #define FM10K_FLAG_SWPRI_CONFIG (u32)(1 << 4)
244 /* Tx fast path data */
248 /* Rx fast path data */
253 struct fm10k_ring
*tx_ring
[MAX_QUEUES
] ____cacheline_aligned_in_smp
;
269 u32 tx_timeout_count
;
272 struct fm10k_ring
*rx_ring
[MAX_QUEUES
];
274 /* Queueing vectors */
275 struct fm10k_q_vector
*q_vector
[MAX_Q_VECTORS
];
276 struct msix_entry
*msix_entries
;
277 int num_q_vectors
; /* current number of q_vectors for device */
278 struct fm10k_ring_feature ring_feature
[RING_F_ARRAY_SIZE
];
280 struct fm10k_hw_stats stats
;
282 u32 __iomem
*uc_addr
;
286 struct timer_list service_timer
;
287 struct work_struct service_task
;
288 unsigned long next_stats_update
;
289 unsigned long next_tx_hang_check
;
290 unsigned long last_reset
;
291 unsigned long link_down_event
;
294 u32 reta
[FM10K_RETA_SIZE
];
295 u32 rssrk
[FM10K_RSSRK_SIZE
];
297 /* VXLAN port tracking information */
298 struct list_head vxlan_port
;
300 #if defined(HAVE_DCBNL_IEEE) && defined(CONFIG_DCB)
305 /* GLORT resources in use by PF */
309 /* VLAN ID for updating multicast/unicast lists */
316 __FM10K_SERVICE_SCHED
,
317 __FM10K_SERVICE_DISABLE
,
322 static inline void fm10k_mbx_lock(struct fm10k_intfc
*interface
)
324 /* busy loop if we cannot obtain the lock as some calls
325 * such as ndo_set_rx_mode may be made in atomic context
327 while (test_and_set_bit(__FM10K_MBX_LOCK
, &interface
->state
))
331 static inline void fm10k_mbx_unlock(struct fm10k_intfc
*interface
)
333 /* flush memory to make sure state is correct */
334 smp_mb__before_atomic();
335 clear_bit(__FM10K_MBX_LOCK
, &interface
->state
);
338 static inline int fm10k_mbx_trylock(struct fm10k_intfc
*interface
)
340 return !test_and_set_bit(__FM10K_MBX_LOCK
, &interface
->state
);
343 /* fm10k_test_staterr - test bits in Rx descriptor status and error fields */
344 static inline __le32
fm10k_test_staterr(union fm10k_rx_desc
*rx_desc
,
345 const u32 stat_err_bits
)
347 return rx_desc
->d
.staterr
& cpu_to_le32(stat_err_bits
);
350 /* fm10k_desc_unused - calculate if we have unused descriptors */
351 static inline u16
fm10k_desc_unused(struct fm10k_ring
*ring
)
353 s16 unused
= ring
->next_to_clean
- ring
->next_to_use
- 1;
355 return likely(unused
< 0) ? unused
+ ring
->count
: unused
;
358 #define FM10K_TX_DESC(R, i) \
359 (&(((struct fm10k_tx_desc *)((R)->desc))[i]))
360 #define FM10K_RX_DESC(R, i) \
361 (&(((union fm10k_rx_desc *)((R)->desc))[i]))
363 #define FM10K_MAX_TXD_PWR 14
364 #define FM10K_MAX_DATA_PER_TXD (1 << FM10K_MAX_TXD_PWR)
366 /* Tx Descriptors needed, worst case */
367 #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), FM10K_MAX_DATA_PER_TXD)
368 #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
370 enum fm10k_tx_flags
{
371 /* Tx offload flags */
372 FM10K_TX_FLAGS_CSUM
= 0x01,
375 /* This structure is stored as little endian values as that is the native
376 * format of the Rx descriptor. The ordering of these fields is reversed
377 * from the actual ftag header to allow for a single bswap to take care
378 * of placing all of the values in network order
380 union fm10k_ftag_info
{
383 /* dglort and sglort combined into a single 32bit desc read */
385 /* upper 16 bits of vlan are reserved 0 for swpri_type_user */
392 __le16 swpri_type_user
;
397 union fm10k_ftag_info fi
;
400 #define FM10K_CB(skb) ((struct fm10k_cb *)(skb)->cb)
403 extern char fm10k_driver_name
[];
404 extern const char fm10k_driver_version
[];
405 int fm10k_init_queueing_scheme(struct fm10k_intfc
*interface
);
406 void fm10k_clear_queueing_scheme(struct fm10k_intfc
*interface
);
407 netdev_tx_t
fm10k_xmit_frame_ring(struct sk_buff
*skb
,
408 struct fm10k_ring
*tx_ring
);
409 void fm10k_tx_timeout_reset(struct fm10k_intfc
*interface
);
410 bool fm10k_check_tx_hang(struct fm10k_ring
*tx_ring
);
411 void fm10k_alloc_rx_buffers(struct fm10k_ring
*rx_ring
, u16 cleaned_count
);
414 void fm10k_mbx_free_irq(struct fm10k_intfc
*);
415 int fm10k_mbx_request_irq(struct fm10k_intfc
*);
416 void fm10k_qv_free_irq(struct fm10k_intfc
*interface
);
417 int fm10k_qv_request_irq(struct fm10k_intfc
*interface
);
418 int fm10k_register_pci_driver(void);
419 void fm10k_unregister_pci_driver(void);
420 void fm10k_up(struct fm10k_intfc
*interface
);
421 void fm10k_down(struct fm10k_intfc
*interface
);
422 void fm10k_update_stats(struct fm10k_intfc
*interface
);
423 void fm10k_service_event_schedule(struct fm10k_intfc
*interface
);
424 void fm10k_update_rx_drop_en(struct fm10k_intfc
*interface
);
427 struct net_device
*fm10k_alloc_netdev(void);
428 int fm10k_setup_rx_resources(struct fm10k_ring
*);
429 int fm10k_setup_tx_resources(struct fm10k_ring
*);
430 void fm10k_free_rx_resources(struct fm10k_ring
*);
431 void fm10k_free_tx_resources(struct fm10k_ring
*);
432 void fm10k_clean_all_rx_rings(struct fm10k_intfc
*);
433 void fm10k_clean_all_tx_rings(struct fm10k_intfc
*);
434 void fm10k_unmap_and_free_tx_resource(struct fm10k_ring
*,
435 struct fm10k_tx_buffer
*);
436 void fm10k_restore_rx_state(struct fm10k_intfc
*);
437 void fm10k_reset_rx_state(struct fm10k_intfc
*);
438 int fm10k_setup_tc(struct net_device
*dev
, u8 tc
);
439 int fm10k_open(struct net_device
*netdev
);
440 int fm10k_close(struct net_device
*netdev
);
443 void fm10k_set_ethtool_ops(struct net_device
*dev
);
444 #endif /* _FM10K_H_ */