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>
32 #define FM10K_MAX_JUMBO_FRAME_SIZE 15358 /* Maximum supported size 15K */
34 #define MAX_QUEUES FM10K_MAX_QUEUES_PF
36 #define FM10K_MIN_RXD 128
37 #define FM10K_MAX_RXD 4096
38 #define FM10K_DEFAULT_RXD 256
40 #define FM10K_MIN_TXD 128
41 #define FM10K_MAX_TXD 4096
42 #define FM10K_DEFAULT_TXD 256
43 #define FM10K_DEFAULT_TX_WORK 256
45 #define FM10K_RXBUFFER_256 256
46 #define FM10K_RXBUFFER_16384 16384
47 #define FM10K_RX_HDR_LEN FM10K_RXBUFFER_256
48 #if PAGE_SIZE <= FM10K_RXBUFFER_16384
49 #define FM10K_RX_BUFSZ (PAGE_SIZE / 2)
51 #define FM10K_RX_BUFSZ FM10K_RXBUFFER_16384
54 /* How many Rx Buffers do we bundle into one write to the hardware ? */
55 #define FM10K_RX_BUFFER_WRITE 16 /* Must be power of 2 */
57 enum fm10k_ring_state_t
{
58 __FM10K_TX_DETECT_HANG
,
59 __FM10K_HANG_CHECK_ARMED
,
62 #define check_for_tx_hang(ring) \
63 test_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
64 #define set_check_for_tx_hang(ring) \
65 set_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
66 #define clear_check_for_tx_hang(ring) \
67 clear_bit(__FM10K_TX_DETECT_HANG, &(ring)->state)
69 struct fm10k_tx_buffer
{
70 struct fm10k_tx_desc
*next_to_watch
;
72 unsigned int bytecount
;
75 DEFINE_DMA_UNMAP_ADDR(dma
);
76 DEFINE_DMA_UNMAP_LEN(len
);
79 struct fm10k_rx_buffer
{
85 struct fm10k_queue_stats
{
90 struct fm10k_tx_queue_stats
{
97 struct fm10k_rx_queue_stats
{
104 struct fm10k_q_vector
*q_vector
;/* backpointer to host q_vector */
105 struct net_device
*netdev
; /* netdev ring belongs to */
106 struct device
*dev
; /* device for DMA mapping */
107 void *desc
; /* descriptor ring memory */
109 struct fm10k_tx_buffer
*tx_buffer
;
110 struct fm10k_rx_buffer
*rx_buffer
;
114 dma_addr_t dma
; /* phys. address of descriptor ring */
115 unsigned int size
; /* length in bytes */
117 u8 queue_index
; /* needed for queue management */
118 u8 reg_idx
; /* holds the special value that gets
119 * the hardware register offset
120 * associated with this ring, which is
121 * different for DCB and RSS modes
123 u8 qos_pc
; /* priority class of queue */
124 u16 vid
; /* default vlan ID of queue */
125 u16 count
; /* amount of descriptors */
131 struct fm10k_queue_stats stats
;
132 struct u64_stats_sync syncp
;
135 struct fm10k_tx_queue_stats tx_stats
;
138 struct fm10k_rx_queue_stats rx_stats
;
142 } ____cacheline_internodealigned_in_smp
;
144 struct fm10k_ring_container
{
145 struct fm10k_ring
*ring
; /* pointer to linked list of rings */
146 unsigned int total_bytes
; /* total bytes processed this int */
147 unsigned int total_packets
; /* total packets processed this int */
148 u16 work_limit
; /* total work allowed per interrupt */
149 u16 itr
; /* interrupt throttle rate value */
150 u8 count
; /* total number of rings in vector */
153 #define FM10K_ITR_MAX 0x0FFF /* maximum value for ITR */
154 #define FM10K_ITR_10K 100 /* 100us */
155 #define FM10K_ITR_20K 50 /* 50us */
156 #define FM10K_ITR_ADAPTIVE 0x8000 /* adaptive interrupt moderation flag */
158 #define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR)
160 static inline struct netdev_queue
*txring_txq(const struct fm10k_ring
*ring
)
162 return &ring
->netdev
->_tx
[ring
->queue_index
];
165 /* iterator for handling rings in ring container */
166 #define fm10k_for_each_ring(pos, head) \
167 for (pos = &(head).ring[(head).count]; (--pos) >= (head).ring;)
169 #define MAX_Q_VECTORS 256
170 #define MIN_Q_VECTORS 1
171 enum fm10k_non_q_vectors
{
176 #define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \
179 #define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw))
181 struct fm10k_q_vector
{
182 struct fm10k_intfc
*interface
;
183 u32 __iomem
*itr
; /* pointer to ITR register for this vector */
184 u16 v_idx
; /* index of q_vector within interface array */
185 struct fm10k_ring_container rx
, tx
;
187 struct napi_struct napi
;
188 char name
[IFNAMSIZ
+ 9];
190 struct rcu_head rcu
; /* to avoid race with update stats on free */
192 /* for dynamic allocation of rings associated with this q_vector */
193 struct fm10k_ring ring
[0] ____cacheline_internodealigned_in_smp
;
196 enum fm10k_ring_f_enum
{
199 RING_F_ARRAY_SIZE
/* must be last in enum set */
202 struct fm10k_ring_feature
{
203 u16 limit
; /* upper limit on feature indices */
204 u16 indices
; /* current value of indices */
205 u16 mask
; /* Mask used for feature to ring mapping */
206 u16 offset
; /* offset to start of feature */
209 #define fm10k_vxlan_port_for_each(vp, intfc) \
210 list_for_each_entry(vp, &(intfc)->vxlan_port, list)
211 struct fm10k_vxlan_port
{
212 struct list_head list
;
213 sa_family_t sa_family
;
218 unsigned long active_vlans
[BITS_TO_LONGS(VLAN_N_VID
)];
219 struct net_device
*netdev
;
220 struct pci_dev
*pdev
;
224 #define FM10K_FLAG_RESET_REQUESTED (u32)(1 << 0)
225 #define FM10K_FLAG_RSS_FIELD_IPV4_UDP (u32)(1 << 1)
226 #define FM10K_FLAG_RSS_FIELD_IPV6_UDP (u32)(1 << 2)
227 #define FM10K_FLAG_RX_TS_ENABLED (u32)(1 << 3)
228 #define FM10K_FLAG_SWPRI_CONFIG (u32)(1 << 4)
231 /* Tx fast path data */
235 /* Rx fast path data */
240 struct fm10k_ring
*tx_ring
[MAX_QUEUES
] ____cacheline_aligned_in_smp
;
256 u32 tx_timeout_count
;
259 struct fm10k_ring
*rx_ring
[MAX_QUEUES
];
261 /* Queueing vectors */
262 struct fm10k_q_vector
*q_vector
[MAX_Q_VECTORS
];
263 struct msix_entry
*msix_entries
;
264 int num_q_vectors
; /* current number of q_vectors for device */
265 struct fm10k_ring_feature ring_feature
[RING_F_ARRAY_SIZE
];
267 struct fm10k_hw_stats stats
;
269 u32 __iomem
*uc_addr
;
273 struct timer_list service_timer
;
274 struct work_struct service_task
;
275 unsigned long next_stats_update
;
276 unsigned long next_tx_hang_check
;
277 unsigned long last_reset
;
278 unsigned long link_down_event
;
281 u32 reta
[FM10K_RETA_SIZE
];
282 u32 rssrk
[FM10K_RSSRK_SIZE
];
284 /* VXLAN port tracking information */
285 struct list_head vxlan_port
;
287 #if defined(HAVE_DCBNL_IEEE) && defined(CONFIG_DCB)
292 /* GLORT resources in use by PF */
296 /* VLAN ID for updating multicast/unicast lists */
303 __FM10K_SERVICE_SCHED
,
304 __FM10K_SERVICE_DISABLE
,
309 static inline void fm10k_mbx_lock(struct fm10k_intfc
*interface
)
311 /* busy loop if we cannot obtain the lock as some calls
312 * such as ndo_set_rx_mode may be made in atomic context
314 while (test_and_set_bit(__FM10K_MBX_LOCK
, &interface
->state
))
318 static inline void fm10k_mbx_unlock(struct fm10k_intfc
*interface
)
320 /* flush memory to make sure state is correct */
321 smp_mb__before_atomic();
322 clear_bit(__FM10K_MBX_LOCK
, &interface
->state
);
325 static inline int fm10k_mbx_trylock(struct fm10k_intfc
*interface
)
327 return !test_and_set_bit(__FM10K_MBX_LOCK
, &interface
->state
);
330 /* fm10k_test_staterr - test bits in Rx descriptor status and error fields */
331 static inline __le32
fm10k_test_staterr(union fm10k_rx_desc
*rx_desc
,
332 const u32 stat_err_bits
)
334 return rx_desc
->d
.staterr
& cpu_to_le32(stat_err_bits
);
337 /* fm10k_desc_unused - calculate if we have unused descriptors */
338 static inline u16
fm10k_desc_unused(struct fm10k_ring
*ring
)
340 s16 unused
= ring
->next_to_clean
- ring
->next_to_use
- 1;
342 return likely(unused
< 0) ? unused
+ ring
->count
: unused
;
345 #define FM10K_TX_DESC(R, i) \
346 (&(((struct fm10k_tx_desc *)((R)->desc))[i]))
347 #define FM10K_RX_DESC(R, i) \
348 (&(((union fm10k_rx_desc *)((R)->desc))[i]))
350 #define FM10K_MAX_TXD_PWR 14
351 #define FM10K_MAX_DATA_PER_TXD (1 << FM10K_MAX_TXD_PWR)
353 /* Tx Descriptors needed, worst case */
354 #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), FM10K_MAX_DATA_PER_TXD)
355 #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
357 enum fm10k_tx_flags
{
358 /* Tx offload flags */
359 FM10K_TX_FLAGS_CSUM
= 0x01,
362 /* This structure is stored as little endian values as that is the native
363 * format of the Rx descriptor. The ordering of these fields is reversed
364 * from the actual ftag header to allow for a single bswap to take care
365 * of placing all of the values in network order
367 union fm10k_ftag_info
{
370 /* dglort and sglort combined into a single 32bit desc read */
372 /* upper 16 bits of vlan are reserved 0 for swpri_type_user */
379 __le16 swpri_type_user
;
384 union fm10k_ftag_info fi
;
387 #define FM10K_CB(skb) ((struct fm10k_cb *)(skb)->cb)
390 extern char fm10k_driver_name
[];
391 extern const char fm10k_driver_version
[];
392 int fm10k_init_queueing_scheme(struct fm10k_intfc
*interface
);
393 void fm10k_clear_queueing_scheme(struct fm10k_intfc
*interface
);
396 void fm10k_mbx_free_irq(struct fm10k_intfc
*);
397 int fm10k_mbx_request_irq(struct fm10k_intfc
*);
398 void fm10k_qv_free_irq(struct fm10k_intfc
*interface
);
399 int fm10k_qv_request_irq(struct fm10k_intfc
*interface
);
400 int fm10k_register_pci_driver(void);
401 void fm10k_unregister_pci_driver(void);
402 void fm10k_up(struct fm10k_intfc
*interface
);
403 void fm10k_down(struct fm10k_intfc
*interface
);
404 void fm10k_update_stats(struct fm10k_intfc
*interface
);
405 void fm10k_service_event_schedule(struct fm10k_intfc
*interface
);
406 void fm10k_update_rx_drop_en(struct fm10k_intfc
*interface
);
409 struct net_device
*fm10k_alloc_netdev(void);
410 void fm10k_restore_rx_state(struct fm10k_intfc
*);
411 void fm10k_reset_rx_state(struct fm10k_intfc
*);
412 int fm10k_open(struct net_device
*netdev
);
413 int fm10k_close(struct net_device
*netdev
);
414 #endif /* _FM10K_H_ */