]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ixl/ixl.h
Update libdialog to 1.3-20180621
[FreeBSD/FreeBSD.git] / sys / dev / ixl / ixl.h
1 /******************************************************************************
2
3   Copyright (c) 2013-2018, Intel Corporation
4   All rights reserved.
5   
6   Redistribution and use in source and binary forms, with or without 
7   modification, are permitted provided that the following conditions are met:
8   
9    1. Redistributions of source code must retain the above copyright notice, 
10       this list of conditions and the following disclaimer.
11   
12    2. Redistributions in binary form must reproduce the above copyright 
13       notice, this list of conditions and the following disclaimer in the 
14       documentation and/or other materials provided with the distribution.
15   
16    3. Neither the name of the Intel Corporation nor the names of its 
17       contributors may be used to endorse or promote products derived from 
18       this software without specific prior written permission.
19   
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31
32 ******************************************************************************/
33 /*$FreeBSD$*/
34
35 #ifndef _IXL_H_
36 #define _IXL_H_
37
38 #include "opt_inet.h"
39 #include "opt_inet6.h"
40 #include "opt_rss.h"
41 #include "opt_ixl.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/buf_ring.h>
46 #include <sys/mbuf.h>
47 #include <sys/protosw.h>
48 #include <sys/socket.h>
49 #include <sys/malloc.h>
50 #include <sys/kernel.h>
51 #include <sys/module.h>
52 #include <sys/sockio.h>
53 #include <sys/eventhandler.h>
54 #include <sys/syslog.h>
55
56 #include <net/if.h>
57 #include <net/if_var.h>
58 #include <net/if_arp.h>
59 #include <net/bpf.h>
60 #include <net/ethernet.h>
61 #include <net/if_dl.h>
62 #include <net/if_media.h>
63 #include <net/iflib.h>
64
65 #include <net/bpf.h>
66 #include <net/if_types.h>
67 #include <net/if_vlan_var.h>
68
69 #include <netinet/in_systm.h>
70 #include <netinet/in.h>
71 #include <netinet/if_ether.h>
72 #include <netinet/ip.h>
73 #include <netinet/ip6.h>
74 #include <netinet/tcp.h>
75 #include <netinet/tcp_lro.h>
76 #include <netinet/udp.h>
77 #include <netinet/sctp.h>
78
79 #include <machine/in_cksum.h>
80
81 #include <sys/bus.h>
82 #include <machine/bus.h>
83 #include <sys/rman.h>
84 #include <machine/resource.h>
85 #include <vm/vm.h>
86 #include <vm/pmap.h>
87 #include <machine/clock.h>
88 #include <dev/pci/pcivar.h>
89 #include <dev/pci/pcireg.h>
90 #include <sys/proc.h>
91 #include <sys/sysctl.h>
92 #include <sys/endian.h>
93 #include <sys/taskqueue.h>
94 #include <sys/pcpu.h>
95 #include <sys/smp.h>
96 #include <sys/sbuf.h>
97 #include <machine/smp.h>
98 #include <machine/stdarg.h>
99
100 #ifdef RSS
101 #include <net/rss_config.h>
102 #include <netinet/in_rss.h>
103 #endif
104
105 #include "ifdi_if.h"
106 #include "i40e_type.h"
107 #include "i40e_prototype.h"
108 #include "ixl_debug.h"
109
110 #define PVIDV(vendor, devid, name) \
111     PVID(vendor, devid, name " - " IXL_DRIVER_VERSION_STRING)
112
113 /* Tunables */
114
115 /*
116  * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the
117  * number of tx/rx descriptors allocated by the driver. Increasing this
118  * value allows the driver to queue more operations.
119  *
120  * Tx descriptors are always 16 bytes, but Rx descriptors can be 32 bytes.
121  * The driver currently always uses 32 byte Rx descriptors.
122  */
123 #define IXL_DEFAULT_RING        1024
124 #define IXL_MAX_RING            4096
125 #define IXL_MIN_RING            64
126 #define IXL_RING_INCREMENT      32
127
128 #define IXL_AQ_LEN              256
129 #define IXL_AQ_LEN_MAX          1024
130
131 /* Alignment for rings */
132 #define DBA_ALIGN               128
133
134 #define MAX_MULTICAST_ADDR      128
135
136 #define IXL_MSIX_BAR            3
137 #define IXL_ADM_LIMIT           2
138 #define IXL_TSO_SIZE            ((255*1024)-1)
139 #define IXL_TX_BUF_SZ           ((u32) 1514)
140 #define IXL_AQ_BUF_SZ           ((u32) 4096)
141 #define IXL_RX_ITR              0
142 #define IXL_TX_ITR              1
143 #define IXL_ITR_NONE            3
144 #define IXL_QUEUE_EOL           0x7FF
145 #define IXL_MIN_FRAME           17
146 #define IXL_MAX_FRAME           9728
147 #define IXL_MAX_TX_SEGS         8
148 #define IXL_MAX_RX_SEGS         5
149 #define IXL_MAX_TSO_SEGS        128
150 #define IXL_SPARSE_CHAIN        7
151 #define IXL_MIN_TSO_MSS         64
152 #define IXL_MAX_TSO_MSS         9668
153 #define IXL_MAX_DMA_SEG_SIZE    ((16 * 1024) - 1)
154
155 #define IXL_RSS_KEY_SIZE_REG            13
156 #define IXL_RSS_KEY_SIZE                (IXL_RSS_KEY_SIZE_REG * 4)
157 #define IXL_RSS_VSI_LUT_SIZE            64      /* X722 -> VSI, X710 -> VF */
158 #define IXL_RSS_VSI_LUT_ENTRY_MASK      0x3F
159 #define IXL_RSS_VF_LUT_ENTRY_MASK       0xF
160
161 #define IXL_VF_MAX_BUFFER       0x3F80
162 #define IXL_VF_MAX_HDR_BUFFER   0x840
163 #define IXL_VF_MAX_FRAME        0x3FFF
164
165 /* ERJ: hardware can support ~2k (SW5+) filters between all functions */
166 #define IXL_MAX_FILTERS         256
167
168 #define IXL_NVM_VERSION_LO_SHIFT        0
169 #define IXL_NVM_VERSION_LO_MASK         (0xff << IXL_NVM_VERSION_LO_SHIFT)
170 #define IXL_NVM_VERSION_HI_SHIFT        12
171 #define IXL_NVM_VERSION_HI_MASK         (0xf << IXL_NVM_VERSION_HI_SHIFT)
172
173 /*
174  * Interrupt Moderation parameters
175  * Multiply ITR values by 2 for real ITR value
176  */
177 #define IXL_MAX_ITR             0x0FF0
178 #define IXL_ITR_100K            0x0005
179 #define IXL_ITR_20K             0x0019
180 #define IXL_ITR_8K              0x003E
181 #define IXL_ITR_4K              0x007A
182 #define IXL_ITR_1K              0x01F4
183 #define IXL_ITR_DYNAMIC         0x8000
184 #define IXL_LOW_LATENCY         0
185 #define IXL_AVE_LATENCY         1
186 #define IXL_BULK_LATENCY        2
187
188 /* MacVlan Flags */
189 #define IXL_FILTER_USED         (u16)(1 << 0)
190 #define IXL_FILTER_VLAN         (u16)(1 << 1)
191 #define IXL_FILTER_ADD          (u16)(1 << 2)
192 #define IXL_FILTER_DEL          (u16)(1 << 3)
193 #define IXL_FILTER_MC           (u16)(1 << 4)
194
195 /* used in the vlan field of the filter when not a vlan */
196 #define IXL_VLAN_ANY            -1
197
198 #define CSUM_OFFLOAD_IPV4       (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
199 #define CSUM_OFFLOAD_IPV6       (CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6)
200 #define CSUM_OFFLOAD            (CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO)
201
202 #define IXL_VF_RESET_TIMEOUT    100
203
204 #define IXL_VSI_DATA_PORT       0x01
205
206 #define IAVF_MAX_QUEUES         16
207 #define IXL_MAX_VSI_QUEUES      (2 * (I40E_VSILAN_QTABLE_MAX_INDEX + 1))
208
209 #define IXL_RX_CTX_BASE_UNITS   128
210 #define IXL_TX_CTX_BASE_UNITS   128
211
212 #define IXL_PF_PCI_CIAA_VF_DEVICE_STATUS        0xAA
213
214 #define IXL_PF_PCI_CIAD_VF_TRANS_PENDING_MASK   0x20
215
216 #define IXL_GLGEN_VFLRSTAT_INDEX(glb_vf)        ((glb_vf) / 32)
217 #define IXL_GLGEN_VFLRSTAT_MASK(glb_vf) (1 << ((glb_vf) % 32))
218
219 #define IXL_MAX_ITR_IDX         3
220
221 #define IXL_END_OF_INTR_LNKLST  0x7FF
222
223 #define IXL_DEFAULT_RSS_HENA_BASE (\
224         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |     \
225         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP) |     \
226         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) |    \
227         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |   \
228         BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4) |         \
229         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |     \
230         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP) |     \
231         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) |    \
232         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |   \
233         BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6) |         \
234         BIT_ULL(I40E_FILTER_PCTYPE_L2_PAYLOAD))
235
236 #define IXL_DEFAULT_RSS_HENA_XL710      IXL_DEFAULT_RSS_HENA_BASE
237
238 #define IXL_DEFAULT_RSS_HENA_X722 (\
239         IXL_DEFAULT_RSS_HENA_BASE |                     \
240         BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | \
241         BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | \
242         BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \
243         BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | \
244         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK) | \
245         BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK))
246
247 #define IXL_CAPS \
248         (IFCAP_TSO4 | IFCAP_TSO6 | \
249          IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6 | \
250          IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | \
251          IFCAP_VLAN_HWFILTER | IFCAP_VLAN_HWTSO | \
252          IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWCSUM | \
253          IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU | IFCAP_LRO)
254
255 #define IXL_CSUM_TCP \
256         (CSUM_IP_TCP|CSUM_IP_TSO|CSUM_IP6_TSO|CSUM_IP6_TCP)
257 #define IXL_CSUM_UDP \
258         (CSUM_IP_UDP|CSUM_IP6_UDP)
259 #define IXL_CSUM_SCTP \
260         (CSUM_IP_SCTP|CSUM_IP6_SCTP)
261
262 /* Pre-11 counter(9) compatibility */
263 #if __FreeBSD_version >= 1100036
264 #define IXL_SET_IPACKETS(vsi, count)    (vsi)->ipackets = (count)
265 #define IXL_SET_IERRORS(vsi, count)     (vsi)->ierrors = (count)
266 #define IXL_SET_OPACKETS(vsi, count)    (vsi)->opackets = (count)
267 #define IXL_SET_OERRORS(vsi, count)     (vsi)->oerrors = (count)
268 #define IXL_SET_COLLISIONS(vsi, count)  /* Do nothing; collisions is always 0. */
269 #define IXL_SET_IBYTES(vsi, count)      (vsi)->ibytes = (count)
270 #define IXL_SET_OBYTES(vsi, count)      (vsi)->obytes = (count)
271 #define IXL_SET_IMCASTS(vsi, count)     (vsi)->imcasts = (count)
272 #define IXL_SET_OMCASTS(vsi, count)     (vsi)->omcasts = (count)
273 #define IXL_SET_IQDROPS(vsi, count)     (vsi)->iqdrops = (count)
274 #define IXL_SET_OQDROPS(vsi, count)     (vsi)->oqdrops = (count)
275 #define IXL_SET_NOPROTO(vsi, count)     (vsi)->noproto = (count)
276 #else
277 #define IXL_SET_IPACKETS(vsi, count)    (vsi)->ifp->if_ipackets = (count)
278 #define IXL_SET_IERRORS(vsi, count)     (vsi)->ifp->if_ierrors = (count)
279 #define IXL_SET_OPACKETS(vsi, count)    (vsi)->ifp->if_opackets = (count)
280 #define IXL_SET_OERRORS(vsi, count)     (vsi)->ifp->if_oerrors = (count)
281 #define IXL_SET_COLLISIONS(vsi, count)  (vsi)->ifp->if_collisions = (count)
282 #define IXL_SET_IBYTES(vsi, count)      (vsi)->ifp->if_ibytes = (count)
283 #define IXL_SET_OBYTES(vsi, count)      (vsi)->ifp->if_obytes = (count)
284 #define IXL_SET_IMCASTS(vsi, count)     (vsi)->ifp->if_imcasts = (count)
285 #define IXL_SET_OMCASTS(vsi, count)     (vsi)->ifp->if_omcasts = (count)
286 #define IXL_SET_IQDROPS(vsi, count)     (vsi)->ifp->if_iqdrops = (count)
287 #define IXL_SET_OQDROPS(vsi, odrops)    (vsi)->ifp->if_snd.ifq_drops = (odrops)
288 #define IXL_SET_NOPROTO(vsi, count)     (vsi)->noproto = (count)
289 #endif
290
291 /* For stats sysctl naming */
292 #define QUEUE_NAME_LEN 32
293
294 #define IXL_DEV_ERR(_dev, _format, ...) \
295         device_printf(_dev, "%s: " _format " (%s:%d)\n", __func__, ##__VA_ARGS__, __FILE__, __LINE__)
296
297 /*
298  *****************************************************************************
299  * vendor_info_array
300  * 
301  * This array contains the list of Subvendor/Subdevice IDs on which the driver
302  * should load.
303  * 
304  *****************************************************************************
305  */
306 typedef struct _ixl_vendor_info_t {
307         unsigned int    vendor_id;
308         unsigned int    device_id;
309         unsigned int    subvendor_id;
310         unsigned int    subdevice_id;
311         unsigned int    index;
312 } ixl_vendor_info_t;
313
314 /*
315 ** This struct has multiple uses, multicast
316 ** addresses, vlans, and mac filters all use it.
317 */
318 struct ixl_mac_filter {
319         SLIST_ENTRY(ixl_mac_filter) next;
320         u8      macaddr[ETHER_ADDR_LEN];
321         s16     vlan;
322         u16     flags;
323 };
324
325 /*
326  * The Transmit ring control struct
327  */
328 struct tx_ring {
329         struct ixl_tx_queue     *que;
330         u32                     tail;
331         struct i40e_tx_desc     *tx_base;
332         u64                     tx_paddr;
333         u32                     latency;
334         u32                     packets;
335         u32                     me;
336         /*
337          * For reporting completed packet status
338          * in descriptor writeback mode
339          */
340         qidx_t                  *tx_rsq;
341         qidx_t                  tx_rs_cidx;
342         qidx_t                  tx_rs_pidx;
343         qidx_t                  tx_cidx_processed;
344
345         /* Used for Dynamic ITR calculation */
346         u32                     itr;
347         u32                     bytes;
348
349         /* Soft Stats */
350         u64                     tx_bytes;
351         u64                     tx_packets;
352         u64                     mss_too_small;
353 };
354
355
356 /*
357  * The Receive ring control struct
358  */
359 struct rx_ring {
360         struct ixl_rx_queue     *que;
361         union i40e_rx_desc      *rx_base;
362         uint64_t                rx_paddr;
363         bool                    discard;
364         u32                     itr;
365         u32                     latency;
366         u32                     mbuf_sz;
367         u32                     tail;
368         u32                     me;
369
370         /* Used for Dynamic ITR calculation */
371         u32                     packets;
372         u32                     bytes;
373
374         /* Soft stats */
375         u64                     rx_packets;
376         u64                     rx_bytes;
377         u64                     desc_errs;
378 };
379
380 /*
381 ** Driver queue structs
382 */
383 struct ixl_tx_queue {
384         struct ixl_vsi          *vsi;
385         struct tx_ring          txr;
386         struct if_irq           que_irq;
387         u32                     msix;
388         /* Stats */
389         u64                     irqs;
390         u64                     tso;
391 };
392
393 struct ixl_rx_queue {
394         struct ixl_vsi          *vsi;
395         struct rx_ring          rxr;
396         struct if_irq           que_irq;
397         u32                     msix;           /* This queue's MSIX vector */
398         /* Stats */
399         u64                     irqs;
400 };
401
402 /*
403 ** Virtual Station Interface
404 */
405 SLIST_HEAD(ixl_ftl_head, ixl_mac_filter);
406 struct ixl_vsi {
407         if_ctx_t                ctx;
408         if_softc_ctx_t          shared;
409         struct ifnet            *ifp;
410         device_t                dev;
411         struct i40e_hw          *hw;
412         struct ifmedia          *media;
413
414         int                     num_rx_queues;
415         int                     num_tx_queues;
416
417         void                    *back;
418         enum i40e_vsi_type      type;
419         int                     id;
420         u32                     rx_itr_setting;
421         u32                     tx_itr_setting;
422         bool                    enable_head_writeback;
423
424         u16                     vsi_num;
425         bool                    link_active;
426         u16                     seid;
427         u16                     uplink_seid;
428         u16                     downlink_seid;
429
430         struct ixl_tx_queue     *tx_queues;     /* TX queue array */
431         struct ixl_rx_queue     *rx_queues;     /* RX queue array */
432         struct if_irq           irq;
433         u32                     link_speed;
434
435         /* MAC/VLAN Filter list */
436         struct ixl_ftl_head     ftl;
437         u16                     num_macs;
438
439         /* Contains readylist & stat counter id */
440         struct i40e_aqc_vsi_properties_data info;
441
442         u16                     num_vlans;
443
444         /* Per-VSI stats from hardware */
445         struct i40e_eth_stats   eth_stats;
446         struct i40e_eth_stats   eth_stats_offsets;
447         bool                    stat_offsets_loaded;
448         /* VSI stat counters */
449         u64                     ipackets;
450         u64                     ierrors;
451         u64                     opackets;
452         u64                     oerrors;
453         u64                     ibytes;
454         u64                     obytes;
455         u64                     imcasts;
456         u64                     omcasts;
457         u64                     iqdrops;
458         u64                     oqdrops;
459         u64                     noproto;
460
461         /* Driver statistics */
462         u64                     hw_filters_del;
463         u64                     hw_filters_add;
464
465         /* Misc. */
466         u64                     flags;
467         /* Stats sysctls for this VSI */
468         struct sysctl_oid       *vsi_node;
469 };
470
471 /*
472 ** Creates new filter with given MAC address and VLAN ID
473 */
474 static inline struct ixl_mac_filter *
475 ixl_new_filter(struct ixl_vsi *vsi, const u8 *macaddr, s16 vlan)
476 {
477         struct ixl_mac_filter  *f;
478
479         /* create a new empty filter */
480         f = malloc(sizeof(struct ixl_mac_filter),
481             M_DEVBUF, M_NOWAIT | M_ZERO);
482         if (f) {
483                 SLIST_INSERT_HEAD(&vsi->ftl, f, next);
484                 bcopy(macaddr, f->macaddr, ETHER_ADDR_LEN);
485                 f->vlan = vlan;
486                 f->flags |= (IXL_FILTER_ADD | IXL_FILTER_USED);
487         }
488
489         return (f);
490 }
491
492 /*
493 ** Compare two ethernet addresses
494 */
495 static inline bool
496 cmp_etheraddr(const u8 *ea1, const u8 *ea2)
497 {       
498         return (bcmp(ea1, ea2, 6) == 0);
499 }       
500
501 /*
502  * Return next largest power of 2, unsigned
503  *
504  * Public domain, from Bit Twiddling Hacks
505  */
506 static inline u32
507 next_power_of_two(u32 n)
508 {
509         n--;
510         n |= n >> 1;
511         n |= n >> 2;
512         n |= n >> 4;
513         n |= n >> 8;
514         n |= n >> 16;
515         n++;
516
517         /* Next power of two > 0 is 1 */
518         n += (n == 0);
519
520         return (n);
521 }
522
523 /*
524  * Info for stats sysctls
525  */
526 struct ixl_sysctl_info {
527         u64     *stat;
528         char    *name;
529         char    *description;
530 };
531
532 extern const uint8_t ixl_bcast_addr[ETHER_ADDR_LEN];
533
534 /* Common function prototypes between PF/VF driver */
535 void            ixl_debug_core(device_t dev, u32 enabled_mask, u32 mask, char *fmt, ...);
536 void             ixl_init_tx_ring(struct ixl_vsi *vsi, struct ixl_tx_queue *que);
537 void             ixl_get_default_rss_key(u32 *);
538 const char *    i40e_vc_stat_str(struct i40e_hw *hw,
539     enum virtchnl_status_code stat_err);
540 void            ixl_init_tx_rsqs(struct ixl_vsi *vsi);
541 void            ixl_init_tx_cidx(struct ixl_vsi *vsi);
542 u64             ixl_max_vc_speed_to_value(u8 link_speeds);
543 void            ixl_add_vsi_sysctls(device_t dev, struct ixl_vsi *vsi,
544                     struct sysctl_ctx_list *ctx, const char *sysctl_name);
545 void            ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *ctx,
546                     struct sysctl_oid_list *child,
547                     struct i40e_eth_stats *eth_stats);
548 void            ixl_add_queues_sysctls(device_t dev, struct ixl_vsi *vsi);
549 #endif /* _IXL_H_ */