xref: /freebsd/sys/net/iflib.h (revision 3ad01642fe9e241124553f2f18fd365ffea5d20b)
14c7070dbSScott Long /*-
296fc97c8SStephen Hurd  * Copyright (c) 2014-2017, Matthew Macy (mmacy@mattmacy.io)
34c7070dbSScott Long  * All rights reserved.
44c7070dbSScott Long  *
54c7070dbSScott Long  * Redistribution and use in source and binary forms, with or without
64c7070dbSScott Long  * modification, are permitted provided that the following conditions are met:
74c7070dbSScott Long  *
84c7070dbSScott Long  *  1. Redistributions of source code must retain the above copyright notice,
94c7070dbSScott Long  *     this list of conditions and the following disclaimer.
104c7070dbSScott Long  *
114c7070dbSScott Long  *  2. Neither the name of Matthew Macy nor the names of its
124c7070dbSScott Long  *     contributors may be used to endorse or promote products derived from
134c7070dbSScott Long  *     this software without specific prior written permission.
144c7070dbSScott Long  *
154c7070dbSScott Long  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
164c7070dbSScott Long  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
174c7070dbSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
184c7070dbSScott Long  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
194c7070dbSScott Long  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
204c7070dbSScott Long  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
214c7070dbSScott Long  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
224c7070dbSScott Long  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
234c7070dbSScott Long  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
244c7070dbSScott Long  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
254c7070dbSScott Long  * POSSIBILITY OF SUCH DAMAGE.
264c7070dbSScott Long  */
274c7070dbSScott Long #ifndef __IFLIB_H_
284c7070dbSScott Long #define __IFLIB_H_
294c7070dbSScott Long 
304c7070dbSScott Long #include <sys/kobj.h>
314c7070dbSScott Long #include <sys/bus.h>
324c7070dbSScott Long #include <sys/cpuset.h>
334c7070dbSScott Long #include <machine/bus.h>
344c7070dbSScott Long #include <sys/nv.h>
3523ac9029SStephen Hurd #include <sys/gtaskqueue.h>
364c7070dbSScott Long 
3795246abbSSean Bruno /*
3895246abbSSean Bruno  * The value type for indexing, limits max descriptors
3995246abbSSean Bruno  * to 65535 can be conditionally redefined to uint32_t
4095246abbSSean Bruno  * in the future if the need arises.
4195246abbSSean Bruno  */
4295246abbSSean Bruno typedef uint16_t qidx_t;
4395246abbSSean Bruno #define QIDX_INVALID 0xFFFF
444c7070dbSScott Long 
454c7070dbSScott Long struct iflib_ctx;
464c7070dbSScott Long typedef struct iflib_ctx *if_ctx_t;
474c7070dbSScott Long struct if_shared_ctx;
48ffe3def9SMark Johnston typedef const struct if_shared_ctx *if_shared_ctx_t;
494c7070dbSScott Long struct if_int_delay_info;
504c7070dbSScott Long typedef struct if_int_delay_info  *if_int_delay_info_t;
514c7070dbSScott Long 
524c7070dbSScott Long /*
534c7070dbSScott Long  * File organization:
544c7070dbSScott Long  *  - public structures
554c7070dbSScott Long  *  - iflib accessors
564c7070dbSScott Long  *  - iflib utility functions
574c7070dbSScott Long  *  - iflib core functions
584c7070dbSScott Long  */
594c7070dbSScott Long 
604c7070dbSScott Long typedef struct if_rxd_frag {
614c7070dbSScott Long 	uint8_t irf_flid;
6295246abbSSean Bruno 	qidx_t irf_idx;
6323ac9029SStephen Hurd 	uint16_t irf_len;
644c7070dbSScott Long } *if_rxd_frag_t;
654c7070dbSScott Long 
668f82136aSPatrick Kelsey /* bnxt supports 64 with hardware LRO enabled */
678f82136aSPatrick Kelsey #define IFLIB_MAX_RX_SEGS		64
688f82136aSPatrick Kelsey 
694c7070dbSScott Long typedef struct if_rxd_info {
704c7070dbSScott Long 	/* set by iflib */
714c7070dbSScott Long 	uint16_t iri_qsidx;		/* qset index */
724c7070dbSScott Long 	uint16_t iri_vtag;		/* vlan tag - if flag set */
7323ac9029SStephen Hurd 	/* XXX redundant with the new irf_len field */
744c7070dbSScott Long 	uint16_t iri_len;		/* packet length */
7595246abbSSean Bruno 	qidx_t iri_cidx;		/* consumer index of cq */
761722eeacSMarius Strobl 	if_t iri_ifp;			/* driver may have >1 iface per softc */
774c7070dbSScott Long 
784c7070dbSScott Long 	/* updated by driver */
7995246abbSSean Bruno 	if_rxd_frag_t iri_frags;
804c7070dbSScott Long 	uint32_t iri_flowid;		/* RSS hash for packet */
814c7070dbSScott Long 	uint32_t iri_csum_flags;	/* m_pkthdr csum flags */
8295246abbSSean Bruno 
834c7070dbSScott Long 	uint32_t iri_csum_data;		/* m_pkthdr csum data */
8495246abbSSean Bruno 	uint8_t iri_flags;		/* mbuf flags for packet */
854c7070dbSScott Long 	uint8_t	 iri_nfrags;		/* number of fragments in packet */
864c7070dbSScott Long 	uint8_t	 iri_rsstype;		/* RSS hash type */
874c7070dbSScott Long 	uint8_t	 iri_pad;		/* any padding in the received data */
884c7070dbSScott Long } *if_rxd_info_t;
894c7070dbSScott Long 
9095246abbSSean Bruno typedef struct if_rxd_update {
9195246abbSSean Bruno 	uint64_t	*iru_paddrs;
9295246abbSSean Bruno 	qidx_t		*iru_idxs;
9395246abbSSean Bruno 	qidx_t		iru_pidx;
9495246abbSSean Bruno 	uint16_t	iru_qsidx;
9595246abbSSean Bruno 	uint16_t	iru_count;
9695246abbSSean Bruno 	uint16_t	iru_buf_size;
9795246abbSSean Bruno 	uint8_t		iru_flidx;
9895246abbSSean Bruno } *if_rxd_update_t;
9995246abbSSean Bruno 
1004c7070dbSScott Long #define IPI_TX_INTR	0x1		/* send an interrupt when this packet is sent */
1014c7070dbSScott Long #define IPI_TX_IPV4	0x2		/* ethertype IPv4 */
1024c7070dbSScott Long #define IPI_TX_IPV6	0x4		/* ethertype IPv6 */
1034c7070dbSScott Long 
1044c7070dbSScott Long typedef struct if_pkt_info {
1054c7070dbSScott Long 	bus_dma_segment_t	*ipi_segs;	/* physical addresses */
10695246abbSSean Bruno 	uint32_t		ipi_len;	/* packet length */
1074c7070dbSScott Long 	uint16_t		ipi_qsidx;	/* queue set index */
10895246abbSSean Bruno 	qidx_t			ipi_nsegs;	/* number of segments */
10995246abbSSean Bruno 
11095246abbSSean Bruno 	qidx_t			ipi_ndescs;	/* number of descriptors used by encap */
1114c7070dbSScott Long 	uint16_t		ipi_flags;	/* iflib per-packet flags */
11295246abbSSean Bruno 	qidx_t			ipi_pidx;	/* start pidx for encap */
11395246abbSSean Bruno 	qidx_t			ipi_new_pidx;	/* next available pidx post-encap */
1144c7070dbSScott Long 	/* offload handling */
1154c7070dbSScott Long 	uint8_t			ipi_ehdrlen;	/* ether header length */
1164c7070dbSScott Long 	uint8_t			ipi_ip_hlen;	/* ip header length */
1174c7070dbSScott Long 	uint8_t			ipi_tcp_hlen;	/* tcp header length */
1184c7070dbSScott Long 	uint8_t			ipi_ipproto;	/* ip protocol */
11995246abbSSean Bruno 
12095246abbSSean Bruno 	uint32_t		ipi_csum_flags;	/* packet checksum flags */
12195246abbSSean Bruno 	uint16_t		ipi_tso_segsz;	/* tso segment size */
12295246abbSSean Bruno 	uint16_t		ipi_vtag;	/* VLAN tag */
12395246abbSSean Bruno 	uint16_t		ipi_etype;	/* ether header type */
1240fc7bdc9SRichard Scheffenegger 	uint16_t		ipi_tcp_hflags;	/* tcp header flags */
12595246abbSSean Bruno 
1264c7070dbSScott Long 	uint32_t		ipi_tcp_seq;	/* tcp seqno */
1279c950139SEric Joyner 	uint8_t			ipi_ip_tos;	/* IP ToS field data */
1280fc7bdc9SRichard Scheffenegger 	uint8_t			ipi_mflags;	/* packet mbuf flags */
1299c950139SEric Joyner 	uint8_t			__spare0__;
1300fc7bdc9SRichard Scheffenegger 	uint8_t		__spare1__;
1314c7070dbSScott Long } *if_pkt_info_t;
1324c7070dbSScott Long 
1334c7070dbSScott Long typedef struct if_irq {
1344c7070dbSScott Long 	struct resource  *ii_res;
135d49e83eaSMarius Strobl 	int               __spare0__;
1364c7070dbSScott Long 	void             *ii_tag;
1374c7070dbSScott Long } *if_irq_t;
1384c7070dbSScott Long 
1394c7070dbSScott Long struct if_int_delay_info {
1404c7070dbSScott Long 	if_ctx_t iidi_ctx;	/* Back-pointer to the iflib ctx (softc) */
1414c7070dbSScott Long 	int iidi_offset;			/* Register offset to read/write */
1424c7070dbSScott Long 	int iidi_value;			/* Current value in usecs */
1434c7070dbSScott Long 	struct sysctl_oid *iidi_oidp;
1444c7070dbSScott Long 	struct sysctl_req *iidi_req;
1454c7070dbSScott Long };
1464c7070dbSScott Long 
1474c7070dbSScott Long typedef enum {
1484c7070dbSScott Long 	IFLIB_INTR_LEGACY,
1494c7070dbSScott Long 	IFLIB_INTR_MSI,
1504c7070dbSScott Long 	IFLIB_INTR_MSIX
1514c7070dbSScott Long } iflib_intr_mode_t;
1524c7070dbSScott Long 
1534c7070dbSScott Long /*
1544c7070dbSScott Long  * This really belongs in pciio.h or some place more general
1554c7070dbSScott Long  * but this is the only consumer for now.
1564c7070dbSScott Long  */
1574c7070dbSScott Long typedef struct pci_vendor_info {
1584c7070dbSScott Long 	uint32_t	pvi_vendor_id;
1594c7070dbSScott Long 	uint32_t	pvi_device_id;
1604c7070dbSScott Long 	uint32_t	pvi_subvendor_id;
1614c7070dbSScott Long 	uint32_t	pvi_subdevice_id;
1624c7070dbSScott Long 	uint32_t	pvi_rev_id;
1634c7070dbSScott Long 	uint32_t	pvi_class_mask;
164d49e83eaSMarius Strobl 	const char	*pvi_name;
1654c7070dbSScott Long } pci_vendor_info_t;
1664c7070dbSScott Long #define PVID(vendor, devid, name) {vendor, devid, 0, 0, 0, 0, name}
1674c7070dbSScott Long #define PVID_OEM(vendor, devid, svid, sdevid, revid, name) {vendor, devid, svid, sdevid, revid, 0, name}
1684c7070dbSScott Long #define PVID_END {0, 0, 0, 0, 0, 0, NULL}
1694c7070dbSScott Long 
170704101ddSConrad Meyer /* No drivers in tree currently match on anything except vendor:device. */
171704101ddSConrad Meyer #define IFLIB_PNP_DESCR "U32:vendor;U32:device;U32:#;U32:#;" \
172704101ddSConrad Meyer     "U32:#;U32:#;D:#"
173916616c4SConrad Meyer #define IFLIB_PNP_INFO(b, u, t) \
174329e817fSWarner Losh     MODULE_PNP_INFO(IFLIB_PNP_DESCR, b, u, t, nitems(t) - 1)
175916616c4SConrad Meyer 
1764c7070dbSScott Long typedef struct if_txrx {
1774c7070dbSScott Long 	int (*ift_txd_encap) (void *, if_pkt_info_t);
17895246abbSSean Bruno 	void (*ift_txd_flush) (void *, uint16_t, qidx_t pidx);
17995246abbSSean Bruno 	int (*ift_txd_credits_update) (void *, uint16_t qsidx, bool clear);
1804c7070dbSScott Long 
18195246abbSSean Bruno 	int (*ift_rxd_available) (void *, uint16_t qsidx, qidx_t pidx, qidx_t budget);
1824c7070dbSScott Long 	int (*ift_rxd_pkt_get) (void *, if_rxd_info_t ri);
18395246abbSSean Bruno 	void (*ift_rxd_refill) (void * , if_rxd_update_t iru);
18495246abbSSean Bruno 	void (*ift_rxd_flush) (void *, uint16_t qsidx, uint8_t flidx, qidx_t pidx);
1854c7070dbSScott Long 	int (*ift_legacy_intr) (void *);
186213e9139SEric Joyner 	qidx_t (*ift_txq_select) (void *, struct mbuf *);
1879c950139SEric Joyner 	qidx_t (*ift_txq_select_v2) (void *, struct mbuf *, if_pkt_info_t);
1884c7070dbSScott Long } *if_txrx_t;
1894c7070dbSScott Long 
1904c7070dbSScott Long typedef struct if_softc_ctx {
1914c7070dbSScott Long 	int isc_vectors;
1924c7070dbSScott Long 	int isc_nrxqsets;
1934c7070dbSScott Long 	int isc_ntxqsets;
194d49e83eaSMarius Strobl 	uint16_t __spare0__;
195d49e83eaSMarius Strobl 	uint32_t __spare1__;
1964c7070dbSScott Long 	int isc_msix_bar;		/* can be model specific - initialize in attach_pre */
1974c7070dbSScott Long 	int isc_tx_nsegments;		/* can be model specific - initialize in attach_pre */
19823ac9029SStephen Hurd 	int isc_ntxd[8];
19923ac9029SStephen Hurd 	int isc_nrxd[8];
20023ac9029SStephen Hurd 
20123ac9029SStephen Hurd 	uint32_t isc_txqsizes[8];
20223ac9029SStephen Hurd 	uint32_t isc_rxqsizes[8];
20395246abbSSean Bruno 	/* is there such thing as a descriptor that is more than 248 bytes ? */
20495246abbSSean Bruno 	uint8_t isc_txd_size[8];
20595246abbSSean Bruno 	uint8_t isc_rxd_size[8];
20695246abbSSean Bruno 
2074c7070dbSScott Long 	int isc_tx_tso_segments_max;
2084c7070dbSScott Long 	int isc_tx_tso_size_max;
2094c7070dbSScott Long 	int isc_tx_tso_segsize_max;
2101248952aSSean Bruno 	int isc_tx_csum_flags;
2117f87c040SMarius Strobl 	int isc_capabilities;
2121248952aSSean Bruno 	int isc_capenable;
2134c7070dbSScott Long 	int isc_rss_table_size;
2144c7070dbSScott Long 	int isc_rss_table_mask;
21523ac9029SStephen Hurd 	int isc_nrxqsets_max;
21623ac9029SStephen Hurd 	int isc_ntxqsets_max;
217d49e83eaSMarius Strobl 	uint32_t __spare2__;
2184c7070dbSScott Long 
2194c7070dbSScott Long 	iflib_intr_mode_t isc_intr;
220b3813609SPatrick Kelsey 	uint16_t isc_rxd_buf_size[8]; /* set at init time by driver, 0
221b3813609SPatrick Kelsey 				         means use iflib-calculated size
222b3813609SPatrick Kelsey 				         based on isc_max_frame_size */
2234c7070dbSScott Long 	uint16_t isc_max_frame_size; /* set at init time by driver */
224d14c853bSStephen Hurd 	uint16_t isc_min_frame_size; /* set at init time by driver, only used if
225d14c853bSStephen Hurd 					IFLIB_NEED_ETHER_PAD is set. */
22660596476SSean Bruno 	uint32_t isc_pause_frames;   /* set by driver for iflib_timer to detect */
227d49e83eaSMarius Strobl 	uint32_t __spare3__;
228d49e83eaSMarius Strobl 	uint32_t __spare4__;
229d49e83eaSMarius Strobl 	uint32_t __spare5__;
230d49e83eaSMarius Strobl 	uint32_t __spare6__;
231d49e83eaSMarius Strobl 	uint32_t __spare7__;
232d49e83eaSMarius Strobl 	uint32_t __spare8__;
233d49e83eaSMarius Strobl 	caddr_t __spare9__;
234ea351d3fSSean Bruno 	int isc_disable_msix;
2351248952aSSean Bruno 	if_txrx_t isc_txrx;
236e2621d96SMatt Macy 	struct ifmedia *isc_media;
2376dd69f00SMarcin Wojtas 	bus_size_t isc_dma_width;	/* device dma width in bits, 0 means
2386dd69f00SMarcin Wojtas 					   use BUS_SPACE_MAXADDR instead */
2394c7070dbSScott Long } *if_softc_ctx_t;
2404c7070dbSScott Long 
2414c7070dbSScott Long /*
2424c7070dbSScott Long  * Initialization values for device
2434c7070dbSScott Long  */
2444c7070dbSScott Long struct if_shared_ctx {
24581ad57b1SStephen Hurd 	unsigned isc_magic;
2464c7070dbSScott Long 	driver_t *isc_driver;
2474c7070dbSScott Long 	bus_size_t isc_q_align;
2484c7070dbSScott Long 	bus_size_t isc_tx_maxsize;
2494c7070dbSScott Long 	bus_size_t isc_tx_maxsegsize;
2507f87c040SMarius Strobl 	bus_size_t isc_tso_maxsize;
2517f87c040SMarius Strobl 	bus_size_t isc_tso_maxsegsize;
2524c7070dbSScott Long 	bus_size_t isc_rx_maxsize;
2534c7070dbSScott Long 	bus_size_t isc_rx_maxsegsize;
2544c7070dbSScott Long 	int isc_rx_nsegments;
2554c7070dbSScott Long 	int isc_admin_intrcnt;		/* # of admin/link interrupts */
2564c7070dbSScott Long 
2574c7070dbSScott Long 	/* fields necessary for probe */
258d49e83eaSMarius Strobl 	const pci_vendor_info_t *isc_vendor_info;
25910a1e981SEric Joyner 	const char *isc_driver_version;
2604c7070dbSScott Long 	/* optional function to transform the read values to match the table*/
2614c7070dbSScott Long 	void (*isc_parse_devinfo) (uint16_t *device_id, uint16_t *subvendor_id,
2624c7070dbSScott Long 				   uint16_t *subdevice_id, uint16_t *rev_id);
26323ac9029SStephen Hurd 	int isc_nrxd_min[8];
26423ac9029SStephen Hurd 	int isc_nrxd_default[8];
26523ac9029SStephen Hurd 	int isc_nrxd_max[8];
26623ac9029SStephen Hurd 	int isc_ntxd_min[8];
26723ac9029SStephen Hurd 	int isc_ntxd_default[8];
26823ac9029SStephen Hurd 	int isc_ntxd_max[8];
26995246abbSSean Bruno 
27095246abbSSean Bruno 	/* actively used during operation */
27195246abbSSean Bruno 	int isc_nfl __aligned(CACHE_LINE_SIZE);
27295246abbSSean Bruno 	int isc_ntxqs;			/* # of tx queues per tx qset - usually 1 */
27395246abbSSean Bruno 	int isc_nrxqs;			/* # of rx queues per rx qset - intel 1, chelsio 2, broadcom 3 */
274d49e83eaSMarius Strobl 	int __spare0__;
27595246abbSSean Bruno 	int isc_tx_reclaim_thresh;
27695246abbSSean Bruno 	int isc_flags;
2774c7070dbSScott Long };
2784c7070dbSScott Long 
2794c7070dbSScott Long typedef struct iflib_dma_info {
2804c7070dbSScott Long 	bus_addr_t		idi_paddr;
2814c7070dbSScott Long 	caddr_t			idi_vaddr;
2824c7070dbSScott Long 	bus_dma_tag_t		idi_tag;
2834c7070dbSScott Long 	bus_dmamap_t		idi_map;
2844c7070dbSScott Long 	uint32_t		idi_size;
2854c7070dbSScott Long } *iflib_dma_info_t;
2864c7070dbSScott Long 
2874c7070dbSScott Long #define IFLIB_MAGIC 0xCAFEF00D
2884c7070dbSScott Long 
2894c7070dbSScott Long typedef enum {
29081be6552SMatt Macy 	/* Interrupt or softirq handles only receive */
2914c7070dbSScott Long 	IFLIB_INTR_RX,
29281be6552SMatt Macy 
29381be6552SMatt Macy 	/* Interrupt or softirq handles only transmit */
29495246abbSSean Bruno 	IFLIB_INTR_TX,
29581be6552SMatt Macy 
29681be6552SMatt Macy 	/*
29781be6552SMatt Macy 	 * Interrupt will check for both pending receive
29881be6552SMatt Macy 	 * and available tx credits and dispatch a task
29981be6552SMatt Macy 	 * for one or both depending on the disposition
30081be6552SMatt Macy 	 * of the respective queues.
30181be6552SMatt Macy 	 */
30295246abbSSean Bruno 	IFLIB_INTR_RXTX,
30381be6552SMatt Macy 
30481be6552SMatt Macy 	/*
30581be6552SMatt Macy 	 * Other interrupt - typically link status and
30681be6552SMatt Macy 	 * or error conditions.
30781be6552SMatt Macy 	 */
3084c7070dbSScott Long 	IFLIB_INTR_ADMIN,
30981be6552SMatt Macy 
31081be6552SMatt Macy 	/* Softirq (task) for iov handling */
3114c7070dbSScott Long 	IFLIB_INTR_IOV,
3124c7070dbSScott Long } iflib_intr_type_t;
3134c7070dbSScott Long 
3144c7070dbSScott Long /*
3156d84e76aSVincenzo Maffione  * Interface has a separate completion queue for RX
3164c7070dbSScott Long  */
3171248952aSSean Bruno #define IFLIB_HAS_RXCQ		0x01
3184c7070dbSScott Long /*
3194c7070dbSScott Long  * Driver has already allocated vectors
3204c7070dbSScott Long  */
3211248952aSSean Bruno #define IFLIB_SKIP_MSIX		0x02
3224c7070dbSScott Long /*
3234c7070dbSScott Long  * Interface is a virtual function
3244c7070dbSScott Long  */
3251248952aSSean Bruno #define IFLIB_IS_VF		0x04
32623ac9029SStephen Hurd /*
3276d84e76aSVincenzo Maffione  * Interface has a separate completion queue for TX
32823ac9029SStephen Hurd  */
3291248952aSSean Bruno #define IFLIB_HAS_TXCQ		0x08
3301248952aSSean Bruno /*
331ab2e3f79SStephen Hurd  * Interface does checksum in place
3321248952aSSean Bruno  */
333ab2e3f79SStephen Hurd #define IFLIB_NEED_SCRATCH	0x10
3341248952aSSean Bruno /*
3351248952aSSean Bruno  * Interface doesn't expect in_pseudo for th_sum
3361248952aSSean Bruno  */
3371248952aSSean Bruno #define IFLIB_TSO_INIT_IP	0x20
33895246abbSSean Bruno /*
33995246abbSSean Bruno  * Interface doesn't align IP header
34095246abbSSean Bruno  */
34195246abbSSean Bruno #define IFLIB_DO_RX_FIXUP	0x40
342c5cf2172SStephen Hurd /*
343c5cf2172SStephen Hurd  * Driver needs csum zeroed for offloading
344c5cf2172SStephen Hurd  */
345c5cf2172SStephen Hurd #define IFLIB_NEED_ZERO_CSUM	0x80
346d14c853bSStephen Hurd /*
347d14c853bSStephen Hurd  * Driver needs frames padded to some minimum length
348d14c853bSStephen Hurd  */
349d14c853bSStephen Hurd #define IFLIB_NEED_ETHER_PAD	0x100
3507ff9ae90SMarius Strobl #define	IFLIB_SPARE7		0x200
3517ff9ae90SMarius Strobl #define	IFLIB_SPARE6		0x400
3527ff9ae90SMarius Strobl #define	IFLIB_SPARE5		0x800
3537ff9ae90SMarius Strobl #define	IFLIB_SPARE4		0x1000
3547ff9ae90SMarius Strobl #define	IFLIB_SPARE3		0x2000
3557ff9ae90SMarius Strobl #define	IFLIB_SPARE2		0x4000
3567ff9ae90SMarius Strobl #define	IFLIB_SPARE1		0x8000
3571d7ef186SEric Joyner /*
3581d7ef186SEric Joyner  * Interface needs admin task to ignore interface up/down status
3591d7ef186SEric Joyner  */
3601d7ef186SEric Joyner #define IFLIB_ADMIN_ALWAYS_RUN	0x10000
361e2621d96SMatt Macy /*
362e2621d96SMatt Macy  * Driver will pass the media
363e2621d96SMatt Macy  */
364e2621d96SMatt Macy #define IFLIB_DRIVER_MEDIA	0x20000
36541669133SMark Johnston /*
36641669133SMark Johnston  * When using a single hardware interrupt for the interface, only process RX
36741669133SMark Johnston  * interrupts instead of doing combined RX/TX processing.
36841669133SMark Johnston  */
36941669133SMark Johnston #define	IFLIB_SINGLE_IRQ_RX_ONLY	0x40000
3707ff9ae90SMarius Strobl #define	IFLIB_SPARE0		0x80000
3714c7070dbSScott Long /*
37209c3f04fSMarcin Wojtas  * Interface has an admin completion queue
37309c3f04fSMarcin Wojtas  */
37409c3f04fSMarcin Wojtas #define IFLIB_HAS_ADMINCQ	0x100000
37558632fa7SMarcin Wojtas /*
37658632fa7SMarcin Wojtas  * Interface needs to preserve TX ring indices across restarts.
37758632fa7SMarcin Wojtas  */
37858632fa7SMarcin Wojtas #define IFLIB_PRESERVE_TX_INDICES	0x200000
37909c3f04fSMarcin Wojtas 
380213e9139SEric Joyner /* The following IFLIB_FEATURE_* defines are for driver modules to determine
381213e9139SEric Joyner  * what features this version of iflib supports. They shall be defined to the
382213e9139SEric Joyner  * first __FreeBSD_version that introduced the feature.
383213e9139SEric Joyner  */
384213e9139SEric Joyner /*
385213e9139SEric Joyner  * Driver can set its own TX queue selection function
386213e9139SEric Joyner  * as ift_txq_select in struct if_txrx
387213e9139SEric Joyner  */
388213e9139SEric Joyner #define IFLIB_FEATURE_QUEUE_SELECT	1400050
3899c950139SEric Joyner /*
3909c950139SEric Joyner  * Driver can set its own TX queue selection function
3919c950139SEric Joyner  * as ift_txq_select_v2 in struct if_txrx. This includes
3929c950139SEric Joyner  * having iflib send L3+ extra header information to the
3939c950139SEric Joyner  * function.
3949c950139SEric Joyner  */
3959c950139SEric Joyner #define IFLIB_FEATURE_QUEUE_SELECT_V2	1400073
396ed34a6b6SEric Joyner /*
397ed34a6b6SEric Joyner  * Driver can create subinterfaces with their own Tx/Rx queues
398ed34a6b6SEric Joyner  * that all share a single device (or commonly, port)
399ed34a6b6SEric Joyner  */
400ed34a6b6SEric Joyner #define IFLIB_FEATURE_SUB_INTERFACES	1500014
401213e9139SEric Joyner 
40209c3f04fSMarcin Wojtas /*
40345818bf1SEric Joyner  * These enum values are used in iflib_needs_restart to indicate to iflib
40445818bf1SEric Joyner  * functions whether or not the interface needs restarting when certain events
40545818bf1SEric Joyner  * happen.
40645818bf1SEric Joyner  */
40745818bf1SEric Joyner enum iflib_restart_event {
40845818bf1SEric Joyner 	IFLIB_RESTART_VLAN_CONFIG,
40945818bf1SEric Joyner };
41045818bf1SEric Joyner 
41145818bf1SEric Joyner /*
4124c7070dbSScott Long  * field accessors
4134c7070dbSScott Long  */
4144c7070dbSScott Long void *iflib_get_softc(if_ctx_t ctx);
4154c7070dbSScott Long 
4164c7070dbSScott Long device_t iflib_get_dev(if_ctx_t ctx);
4174c7070dbSScott Long 
4184c7070dbSScott Long if_t iflib_get_ifp(if_ctx_t ctx);
4194c7070dbSScott Long 
4204c7070dbSScott Long struct ifmedia *iflib_get_media(if_ctx_t ctx);
4214c7070dbSScott Long 
4224c7070dbSScott Long if_softc_ctx_t iflib_get_softc_ctx(if_ctx_t ctx);
4234c7070dbSScott Long if_shared_ctx_t iflib_get_sctx(if_ctx_t ctx);
4244c7070dbSScott Long 
4254c7070dbSScott Long void iflib_set_mac(if_ctx_t ctx, uint8_t mac[ETHER_ADDR_LEN]);
42677c1fcecSEric Joyner void iflib_request_reset(if_ctx_t ctx);
42777c1fcecSEric Joyner uint8_t iflib_in_detach(if_ctx_t ctx);
4284c7070dbSScott Long 
4291b9d9394SEric Joyner uint32_t iflib_get_rx_mbuf_sz(if_ctx_t ctx);
4301b9d9394SEric Joyner 
4314c7070dbSScott Long /*
4324c7070dbSScott Long  * If the driver can plug cleanly in to newbus use these
4334c7070dbSScott Long  */
4344c7070dbSScott Long int iflib_device_probe(device_t);
4354c7070dbSScott Long int iflib_device_attach(device_t);
4364c7070dbSScott Long int iflib_device_detach(device_t);
4374c7070dbSScott Long int iflib_device_suspend(device_t);
4384c7070dbSScott Long int iflib_device_resume(device_t);
4394c7070dbSScott Long int iflib_device_shutdown(device_t);
4404c7070dbSScott Long 
441668d6dbbSEric Joyner /*
442668d6dbbSEric Joyner  * Use this instead of iflib_device_probe if the driver should report
443668d6dbbSEric Joyner  * BUS_PROBE_VENDOR instead of BUS_PROBE_DEFAULT. (For example, an out-of-tree
444668d6dbbSEric Joyner  * driver based on iflib).
445668d6dbbSEric Joyner  */
446668d6dbbSEric Joyner int iflib_device_probe_vendor(device_t);
447668d6dbbSEric Joyner 
4484c7070dbSScott Long int iflib_device_iov_init(device_t, uint16_t, const nvlist_t *);
4494c7070dbSScott Long void iflib_device_iov_uninit(device_t);
4504c7070dbSScott Long int iflib_device_iov_add_vf(device_t, uint16_t, const nvlist_t *);
4514c7070dbSScott Long 
4524c7070dbSScott Long /*
4534c7070dbSScott Long  * If the driver can't plug cleanly in to newbus
4544c7070dbSScott Long  * use these
4554c7070dbSScott Long  */
4564c7070dbSScott Long int iflib_device_register(device_t dev, void *softc, if_shared_ctx_t sctx, if_ctx_t *ctxp);
4574c7070dbSScott Long int iflib_device_deregister(if_ctx_t);
4584c7070dbSScott Long 
4597f527d48SEric Joyner int iflib_irq_alloc(if_ctx_t, if_irq_t, int, driver_filter_t, void *filter_arg,
4607f527d48SEric Joyner 		    driver_intr_t, void *arg, const char *name);
4614c7070dbSScott Long int iflib_irq_alloc_generic(if_ctx_t ctx, if_irq_t irq, int rid,
4624c7070dbSScott Long 			    iflib_intr_type_t type, driver_filter_t *filter,
4633e0e6330SStephen Hurd 			    void *filter_arg, int qid, const char *name);
4647f527d48SEric Joyner void iflib_softirq_alloc_generic(if_ctx_t ctx, if_irq_t irq,
4657f527d48SEric Joyner 				 iflib_intr_type_t type,  void *arg, int qid,
4667f527d48SEric Joyner 				 const char *name);
4674c7070dbSScott Long 
4684c7070dbSScott Long void iflib_irq_free(if_ctx_t ctx, if_irq_t irq);
4694c7070dbSScott Long 
470d49e83eaSMarius Strobl void iflib_io_tqg_attach(struct grouptask *gt, void *uniq, int cpu,
471d49e83eaSMarius Strobl     const char *name);
4724c7070dbSScott Long 
473*3ad01642SKrzysztof Galazka void iflib_config_task_init(if_ctx_t ctx, struct task *config_task,
474*3ad01642SKrzysztof Galazka     task_fn_t *fn);
475*3ad01642SKrzysztof Galazka void iflib_config_task_enqueue(if_ctx_t ctx, struct task *config_task);
47623ac9029SStephen Hurd 
4774c7070dbSScott Long void iflib_tx_intr_deferred(if_ctx_t ctx, int txqid);
4784c7070dbSScott Long void iflib_rx_intr_deferred(if_ctx_t ctx, int rxqid);
4794c7070dbSScott Long void iflib_admin_intr_deferred(if_ctx_t ctx);
4804c7070dbSScott Long void iflib_iov_intr_deferred(if_ctx_t ctx);
4814c7070dbSScott Long 
48223ac9029SStephen Hurd void iflib_link_state_change(if_ctx_t ctx, int linkstate, uint64_t baudrate);
4834c7070dbSScott Long 
4844c7070dbSScott Long int iflib_dma_alloc(if_ctx_t ctx, int size, iflib_dma_info_t dma, int mapflags);
4858f82136aSPatrick Kelsey int iflib_dma_alloc_align(if_ctx_t ctx, int size, int align, iflib_dma_info_t dma, int mapflags);
4864c7070dbSScott Long void iflib_dma_free(iflib_dma_info_t dma);
4874c7070dbSScott Long int iflib_dma_alloc_multi(if_ctx_t ctx, int *sizes, iflib_dma_info_t *dmalist, int mapflags, int count);
4884c7070dbSScott Long 
4894c7070dbSScott Long void iflib_dma_free_multi(iflib_dma_info_t *dmalist, int count);
4904c7070dbSScott Long 
491aa8a24d3SStephen Hurd struct sx *iflib_ctx_lock_get(if_ctx_t);
4924c7070dbSScott Long 
4934c7070dbSScott Long void iflib_led_create(if_ctx_t ctx);
4944c7070dbSScott Long 
4954c7070dbSScott Long void iflib_add_int_delay_sysctl(if_ctx_t, const char *, const char *,
4964c7070dbSScott Long 								if_int_delay_info_t, int, int);
4973c7da27aSEric Joyner uint16_t iflib_get_extra_msix_vectors_sysctl(if_ctx_t ctx);
4984c7070dbSScott Long 
499ed34a6b6SEric Joyner /*
500ed34a6b6SEric Joyner  * Sub-interface support
501ed34a6b6SEric Joyner  */
502ed34a6b6SEric Joyner int iflib_irq_alloc_generic_subctx(if_ctx_t ctx, if_ctx_t subctx, if_irq_t irq,
503ed34a6b6SEric Joyner 				   int rid, iflib_intr_type_t type,
504ed34a6b6SEric Joyner 				   driver_filter_t *filter, void *filter_arg,
505ed34a6b6SEric Joyner 				   int qid, const char *name);
5064c7070dbSScott Long #endif /*  __IFLIB_H_ */
507