fm10k: Add support for VF
[deliverable/linux.git] / drivers / net / ethernet / intel / fm10k / fm10k.h
1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 Intel Corporation.
3 *
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.
7 *
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
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
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
19 */
20
21 #ifndef _FM10K_H_
22 #define _FM10K_H_
23
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>
29
30 #include "fm10k_pf.h"
31 #include "fm10k_vf.h"
32
33 #define FM10K_MAX_JUMBO_FRAME_SIZE 15358 /* Maximum supported size 15K */
34
35 #define MAX_QUEUES FM10K_MAX_QUEUES_PF
36
37 #define FM10K_MIN_RXD 128
38 #define FM10K_MAX_RXD 4096
39 #define FM10K_DEFAULT_RXD 256
40
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
45
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)
51 #else
52 #define FM10K_RX_BUFSZ FM10K_RXBUFFER_16384
53 #endif
54
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 */
57
58 #define FM10K_MAX_STATIONS 63
59 struct fm10k_l2_accel {
60 int size;
61 u16 count;
62 u16 dglort;
63 struct rcu_head rcu;
64 struct net_device *macvlan[0];
65 };
66
67 enum fm10k_ring_state_t {
68 __FM10K_TX_DETECT_HANG,
69 __FM10K_HANG_CHECK_ARMED,
70 };
71
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)
78
79 struct fm10k_tx_buffer {
80 struct fm10k_tx_desc *next_to_watch;
81 struct sk_buff *skb;
82 unsigned int bytecount;
83 u16 gso_segs;
84 u16 tx_flags;
85 DEFINE_DMA_UNMAP_ADDR(dma);
86 DEFINE_DMA_UNMAP_LEN(len);
87 };
88
89 struct fm10k_rx_buffer {
90 dma_addr_t dma;
91 struct page *page;
92 u32 page_offset;
93 };
94
95 struct fm10k_queue_stats {
96 u64 packets;
97 u64 bytes;
98 };
99
100 struct fm10k_tx_queue_stats {
101 u64 restart_queue;
102 u64 csum_err;
103 u64 tx_busy;
104 u64 tx_done_old;
105 };
106
107 struct fm10k_rx_queue_stats {
108 u64 alloc_failed;
109 u64 csum_err;
110 u64 errors;
111 };
112
113 struct fm10k_ring {
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 */
119 union {
120 struct fm10k_tx_buffer *tx_buffer;
121 struct fm10k_rx_buffer *rx_buffer;
122 };
123 u32 __iomem *tail;
124 unsigned long state;
125 dma_addr_t dma; /* phys. address of descriptor ring */
126 unsigned int size; /* length in bytes */
127
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
133 */
134 u8 qos_pc; /* priority class of queue */
135 u16 vid; /* default vlan ID of queue */
136 u16 count; /* amount of descriptors */
137
138 u16 next_to_alloc;
139 u16 next_to_use;
140 u16 next_to_clean;
141
142 struct fm10k_queue_stats stats;
143 struct u64_stats_sync syncp;
144 union {
145 /* Tx */
146 struct fm10k_tx_queue_stats tx_stats;
147 /* Rx */
148 struct {
149 struct fm10k_rx_queue_stats rx_stats;
150 struct sk_buff *skb;
151 };
152 };
153 } ____cacheline_internodealigned_in_smp;
154
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 */
162 };
163
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 */
168
169 #define FM10K_ITR_ENABLE (FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR)
170
171 static inline struct netdev_queue *txring_txq(const struct fm10k_ring *ring)
172 {
173 return &ring->netdev->_tx[ring->queue_index];
174 }
175
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;)
179
180 #define MAX_Q_VECTORS 256
181 #define MIN_Q_VECTORS 1
182 enum fm10k_non_q_vectors {
183 FM10K_MBX_VECTOR,
184 #define NON_Q_VECTORS_VF NON_Q_VECTORS_PF
185 NON_Q_VECTORS_PF
186 };
187
188 #define NON_Q_VECTORS(hw) (((hw)->mac.type == fm10k_mac_pf) ? \
189 NON_Q_VECTORS_PF : \
190 NON_Q_VECTORS_VF)
191 #define MIN_MSIX_COUNT(hw) (MIN_Q_VECTORS + NON_Q_VECTORS(hw))
192
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;
198
199 struct napi_struct napi;
200 char name[IFNAMSIZ + 9];
201
202 struct rcu_head rcu; /* to avoid race with update stats on free */
203
204 /* for dynamic allocation of rings associated with this q_vector */
205 struct fm10k_ring ring[0] ____cacheline_internodealigned_in_smp;
206 };
207
208 enum fm10k_ring_f_enum {
209 RING_F_RSS,
210 RING_F_QOS,
211 RING_F_ARRAY_SIZE /* must be last in enum set */
212 };
213
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 */
219 };
220
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;
226 __be16 port;
227 };
228
229 struct fm10k_intfc {
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;
234 unsigned long state;
235
236 u32 flags;
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)
242 int xcast_mode;
243
244 /* Tx fast path data */
245 int num_tx_queues;
246 u16 tx_itr;
247
248 /* Rx fast path data */
249 int num_rx_queues;
250 u16 rx_itr;
251
252 /* TX */
253 struct fm10k_ring *tx_ring[MAX_QUEUES] ____cacheline_aligned_in_smp;
254
255 u64 restart_queue;
256 u64 tx_busy;
257 u64 tx_csum_errors;
258 u64 alloc_failed;
259 u64 rx_csum_errors;
260 u64 rx_errors;
261
262 u64 tx_bytes_nic;
263 u64 tx_packets_nic;
264 u64 rx_bytes_nic;
265 u64 rx_packets_nic;
266 u64 rx_drops_nic;
267 u64 rx_overrun_pf;
268 u64 rx_overrun_vf;
269 u32 tx_timeout_count;
270
271 /* RX */
272 struct fm10k_ring *rx_ring[MAX_QUEUES];
273
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];
279
280 struct fm10k_hw_stats stats;
281 struct fm10k_hw hw;
282 u32 __iomem *uc_addr;
283 u16 msg_enable;
284 u16 tx_ring_count;
285 u16 rx_ring_count;
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;
292 bool host_ready;
293
294 u32 reta[FM10K_RETA_SIZE];
295 u32 rssrk[FM10K_RSSRK_SIZE];
296
297 /* VXLAN port tracking information */
298 struct list_head vxlan_port;
299
300 #if defined(HAVE_DCBNL_IEEE) && defined(CONFIG_DCB)
301 u8 pfc_en;
302 #endif
303 u8 rx_pause;
304
305 /* GLORT resources in use by PF */
306 u16 glort;
307 u16 glort_count;
308
309 /* VLAN ID for updating multicast/unicast lists */
310 u16 vid;
311 };
312
313 enum fm10k_state_t {
314 __FM10K_RESETTING,
315 __FM10K_DOWN,
316 __FM10K_SERVICE_SCHED,
317 __FM10K_SERVICE_DISABLE,
318 __FM10K_MBX_LOCK,
319 __FM10K_LINK_DOWN,
320 };
321
322 static inline void fm10k_mbx_lock(struct fm10k_intfc *interface)
323 {
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
326 */
327 while (test_and_set_bit(__FM10K_MBX_LOCK, &interface->state))
328 udelay(20);
329 }
330
331 static inline void fm10k_mbx_unlock(struct fm10k_intfc *interface)
332 {
333 /* flush memory to make sure state is correct */
334 smp_mb__before_atomic();
335 clear_bit(__FM10K_MBX_LOCK, &interface->state);
336 }
337
338 static inline int fm10k_mbx_trylock(struct fm10k_intfc *interface)
339 {
340 return !test_and_set_bit(__FM10K_MBX_LOCK, &interface->state);
341 }
342
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)
346 {
347 return rx_desc->d.staterr & cpu_to_le32(stat_err_bits);
348 }
349
350 /* fm10k_desc_unused - calculate if we have unused descriptors */
351 static inline u16 fm10k_desc_unused(struct fm10k_ring *ring)
352 {
353 s16 unused = ring->next_to_clean - ring->next_to_use - 1;
354
355 return likely(unused < 0) ? unused + ring->count : unused;
356 }
357
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]))
362
363 #define FM10K_MAX_TXD_PWR 14
364 #define FM10K_MAX_DATA_PER_TXD (1 << FM10K_MAX_TXD_PWR)
365
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)
369
370 enum fm10k_tx_flags {
371 /* Tx offload flags */
372 FM10K_TX_FLAGS_CSUM = 0x01,
373 };
374
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
379 */
380 union fm10k_ftag_info {
381 __le64 ftag;
382 struct {
383 /* dglort and sglort combined into a single 32bit desc read */
384 __le32 glort;
385 /* upper 16 bits of vlan are reserved 0 for swpri_type_user */
386 __le32 vlan;
387 } d;
388 struct {
389 __le16 dglort;
390 __le16 sglort;
391 __le16 vlan;
392 __le16 swpri_type_user;
393 } w;
394 };
395
396 struct fm10k_cb {
397 union fm10k_ftag_info fi;
398 };
399
400 #define FM10K_CB(skb) ((struct fm10k_cb *)(skb)->cb)
401
402 /* main */
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);
412
413 /* PCI */
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);
425
426 /* Netdev */
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);
441
442 /* Ethtool */
443 void fm10k_set_ethtool_ops(struct net_device *dev);
444 #endif /* _FM10K_H_ */
This page took 0.054884 seconds and 5 git commands to generate.