1*4c7070dbSScott Long /*- 2*4c7070dbSScott Long * Copyright (c) 2014-2015, Matthew Macy (mmacy@nextbsd.org) 3*4c7070dbSScott Long * All rights reserved. 4*4c7070dbSScott Long * 5*4c7070dbSScott Long * Redistribution and use in source and binary forms, with or without 6*4c7070dbSScott Long * modification, are permitted provided that the following conditions are met: 7*4c7070dbSScott Long * 8*4c7070dbSScott Long * 1. Redistributions of source code must retain the above copyright notice, 9*4c7070dbSScott Long * this list of conditions and the following disclaimer. 10*4c7070dbSScott Long * 11*4c7070dbSScott Long * 2. Neither the name of Matthew Macy nor the names of its 12*4c7070dbSScott Long * contributors may be used to endorse or promote products derived from 13*4c7070dbSScott Long * this software without specific prior written permission. 14*4c7070dbSScott Long * 15*4c7070dbSScott Long * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16*4c7070dbSScott Long * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*4c7070dbSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*4c7070dbSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19*4c7070dbSScott Long * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*4c7070dbSScott Long * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*4c7070dbSScott Long * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*4c7070dbSScott Long * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*4c7070dbSScott Long * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*4c7070dbSScott Long * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*4c7070dbSScott Long * POSSIBILITY OF SUCH DAMAGE. 26*4c7070dbSScott Long * 27*4c7070dbSScott Long * $FreeBSD$ 28*4c7070dbSScott Long */ 29*4c7070dbSScott Long #ifndef __IFLIB_H_ 30*4c7070dbSScott Long #define __IFLIB_H_ 31*4c7070dbSScott Long 32*4c7070dbSScott Long #include <sys/kobj.h> 33*4c7070dbSScott Long #include <sys/bus.h> 34*4c7070dbSScott Long #include <sys/cpuset.h> 35*4c7070dbSScott Long #include <machine/bus.h> 36*4c7070dbSScott Long #include <sys/bus_dma.h> 37*4c7070dbSScott Long #include <sys/nv.h> 38*4c7070dbSScott Long 39*4c7070dbSScott Long 40*4c7070dbSScott Long /* 41*4c7070dbSScott Long * Most cards can handle much larger TSO requests 42*4c7070dbSScott Long * but the FreeBSD TCP stack will break on larger 43*4c7070dbSScott Long * values 44*4c7070dbSScott Long */ 45*4c7070dbSScott Long #define FREEBSD_TSO_SIZE_MAX 65518 46*4c7070dbSScott Long 47*4c7070dbSScott Long 48*4c7070dbSScott Long struct iflib_ctx; 49*4c7070dbSScott Long typedef struct iflib_ctx *if_ctx_t; 50*4c7070dbSScott Long struct if_shared_ctx; 51*4c7070dbSScott Long typedef struct if_shared_ctx *if_shared_ctx_t; 52*4c7070dbSScott Long struct if_int_delay_info; 53*4c7070dbSScott Long typedef struct if_int_delay_info *if_int_delay_info_t; 54*4c7070dbSScott Long 55*4c7070dbSScott Long /* 56*4c7070dbSScott Long * File organization: 57*4c7070dbSScott Long * - public structures 58*4c7070dbSScott Long * - iflib accessors 59*4c7070dbSScott Long * - iflib utility functions 60*4c7070dbSScott Long * - iflib core functions 61*4c7070dbSScott Long */ 62*4c7070dbSScott Long 63*4c7070dbSScott Long typedef struct if_rxd_frag { 64*4c7070dbSScott Long uint8_t irf_flid; 65*4c7070dbSScott Long uint16_t irf_idx; 66*4c7070dbSScott Long } *if_rxd_frag_t; 67*4c7070dbSScott Long 68*4c7070dbSScott Long typedef struct if_rxd_info { 69*4c7070dbSScott Long /* set by iflib */ 70*4c7070dbSScott Long uint16_t iri_qsidx; /* qset index */ 71*4c7070dbSScott Long uint16_t iri_vtag; /* vlan tag - if flag set */ 72*4c7070dbSScott Long uint16_t iri_len; /* packet length */ 73*4c7070dbSScott Long uint16_t iri_cidx; /* consumer index of cq */ 74*4c7070dbSScott Long struct ifnet *iri_ifp; /* some drivers >1 interface per softc */ 75*4c7070dbSScott Long 76*4c7070dbSScott Long /* updated by driver */ 77*4c7070dbSScott Long uint16_t iri_flags; /* mbuf flags for packet */ 78*4c7070dbSScott Long uint32_t iri_flowid; /* RSS hash for packet */ 79*4c7070dbSScott Long uint32_t iri_csum_flags; /* m_pkthdr csum flags */ 80*4c7070dbSScott Long uint32_t iri_csum_data; /* m_pkthdr csum data */ 81*4c7070dbSScott Long uint8_t iri_nfrags; /* number of fragments in packet */ 82*4c7070dbSScott Long uint8_t iri_rsstype; /* RSS hash type */ 83*4c7070dbSScott Long uint8_t iri_pad; /* any padding in the received data */ 84*4c7070dbSScott Long if_rxd_frag_t iri_frags; 85*4c7070dbSScott Long } *if_rxd_info_t; 86*4c7070dbSScott Long 87*4c7070dbSScott Long #define IPI_TX_INTR 0x1 /* send an interrupt when this packet is sent */ 88*4c7070dbSScott Long #define IPI_TX_IPV4 0x2 /* ethertype IPv4 */ 89*4c7070dbSScott Long #define IPI_TX_IPV6 0x4 /* ethertype IPv6 */ 90*4c7070dbSScott Long 91*4c7070dbSScott Long typedef struct if_pkt_info { 92*4c7070dbSScott Long uint32_t ipi_len; /* packet length */ 93*4c7070dbSScott Long bus_dma_segment_t *ipi_segs; /* physical addresses */ 94*4c7070dbSScott Long uint16_t ipi_qsidx; /* queue set index */ 95*4c7070dbSScott Long uint16_t ipi_nsegs; /* number of segments */ 96*4c7070dbSScott Long uint16_t ipi_ndescs; /* number of descriptors used by encap */ 97*4c7070dbSScott Long uint16_t ipi_flags; /* iflib per-packet flags */ 98*4c7070dbSScott Long uint32_t ipi_pidx; /* start pidx for encap */ 99*4c7070dbSScott Long uint32_t ipi_new_pidx; /* next available pidx post-encap */ 100*4c7070dbSScott Long /* offload handling */ 101*4c7070dbSScott Long uint64_t ipi_csum_flags; /* packet checksum flags */ 102*4c7070dbSScott Long uint16_t ipi_tso_segsz; /* tso segment size */ 103*4c7070dbSScott Long uint16_t ipi_mflags; /* packet mbuf flags */ 104*4c7070dbSScott Long uint16_t ipi_vtag; /* VLAN tag */ 105*4c7070dbSScott Long uint16_t ipi_etype; /* ether header type */ 106*4c7070dbSScott Long uint8_t ipi_ehdrlen; /* ether header length */ 107*4c7070dbSScott Long uint8_t ipi_ip_hlen; /* ip header length */ 108*4c7070dbSScott Long uint8_t ipi_tcp_hlen; /* tcp header length */ 109*4c7070dbSScott Long uint8_t ipi_tcp_hflags; /* tcp header flags */ 110*4c7070dbSScott Long uint8_t ipi_ipproto; /* ip protocol */ 111*4c7070dbSScott Long /* implied padding */ 112*4c7070dbSScott Long uint32_t ipi_tcp_seq; /* tcp seqno */ 113*4c7070dbSScott Long uint32_t ipi_tcp_sum; /* tcp csum */ 114*4c7070dbSScott Long } *if_pkt_info_t; 115*4c7070dbSScott Long 116*4c7070dbSScott Long typedef struct if_irq { 117*4c7070dbSScott Long struct resource *ii_res; 118*4c7070dbSScott Long int ii_rid; 119*4c7070dbSScott Long void *ii_tag; 120*4c7070dbSScott Long } *if_irq_t; 121*4c7070dbSScott Long 122*4c7070dbSScott Long struct if_int_delay_info { 123*4c7070dbSScott Long if_ctx_t iidi_ctx; /* Back-pointer to the iflib ctx (softc) */ 124*4c7070dbSScott Long int iidi_offset; /* Register offset to read/write */ 125*4c7070dbSScott Long int iidi_value; /* Current value in usecs */ 126*4c7070dbSScott Long struct sysctl_oid *iidi_oidp; 127*4c7070dbSScott Long struct sysctl_req *iidi_req; 128*4c7070dbSScott Long }; 129*4c7070dbSScott Long 130*4c7070dbSScott Long typedef enum { 131*4c7070dbSScott Long IFLIB_INTR_LEGACY, 132*4c7070dbSScott Long IFLIB_INTR_MSI, 133*4c7070dbSScott Long IFLIB_INTR_MSIX 134*4c7070dbSScott Long } iflib_intr_mode_t; 135*4c7070dbSScott Long 136*4c7070dbSScott Long /* 137*4c7070dbSScott Long * This really belongs in pciio.h or some place more general 138*4c7070dbSScott Long * but this is the only consumer for now. 139*4c7070dbSScott Long */ 140*4c7070dbSScott Long typedef struct pci_vendor_info { 141*4c7070dbSScott Long uint32_t pvi_vendor_id; 142*4c7070dbSScott Long uint32_t pvi_device_id; 143*4c7070dbSScott Long uint32_t pvi_subvendor_id; 144*4c7070dbSScott Long uint32_t pvi_subdevice_id; 145*4c7070dbSScott Long uint32_t pvi_rev_id; 146*4c7070dbSScott Long uint32_t pvi_class_mask; 147*4c7070dbSScott Long caddr_t pvi_name; 148*4c7070dbSScott Long } pci_vendor_info_t; 149*4c7070dbSScott Long 150*4c7070dbSScott Long #define PVID(vendor, devid, name) {vendor, devid, 0, 0, 0, 0, name} 151*4c7070dbSScott Long #define PVID_OEM(vendor, devid, svid, sdevid, revid, name) {vendor, devid, svid, sdevid, revid, 0, name} 152*4c7070dbSScott Long #define PVID_END {0, 0, 0, 0, 0, 0, NULL} 153*4c7070dbSScott Long 154*4c7070dbSScott Long typedef struct if_txrx { 155*4c7070dbSScott Long int (*ift_txd_encap) (void *, if_pkt_info_t); 156*4c7070dbSScott Long void (*ift_txd_flush) (void *, uint16_t, uint32_t); 157*4c7070dbSScott Long int (*ift_txd_credits_update) (void *, uint16_t, uint32_t, bool); 158*4c7070dbSScott Long 159*4c7070dbSScott Long int (*ift_rxd_available) (void *, uint16_t qsidx, uint32_t pidx); 160*4c7070dbSScott Long int (*ift_rxd_pkt_get) (void *, if_rxd_info_t ri); 161*4c7070dbSScott Long void (*ift_rxd_refill) (void * , uint16_t qsidx, uint8_t flidx, uint32_t pidx, 162*4c7070dbSScott Long uint64_t *paddrs, caddr_t *vaddrs, uint16_t count); 163*4c7070dbSScott Long void (*ift_rxd_flush) (void *, uint16_t qsidx, uint8_t flidx, uint32_t pidx); 164*4c7070dbSScott Long int (*ift_legacy_intr) (void *); 165*4c7070dbSScott Long } *if_txrx_t; 166*4c7070dbSScott Long 167*4c7070dbSScott Long typedef struct if_softc_ctx { 168*4c7070dbSScott Long int isc_vectors; 169*4c7070dbSScott Long int isc_nrxqsets; 170*4c7070dbSScott Long int isc_ntxqsets; 171*4c7070dbSScott Long int isc_msix_bar; /* can be model specific - initialize in attach_pre */ 172*4c7070dbSScott Long int isc_tx_nsegments; /* can be model specific - initialize in attach_pre */ 173*4c7070dbSScott Long int isc_tx_tso_segments_max; 174*4c7070dbSScott Long int isc_tx_tso_size_max; 175*4c7070dbSScott Long int isc_tx_tso_segsize_max; 176*4c7070dbSScott Long int isc_rss_table_size; 177*4c7070dbSScott Long int isc_rss_table_mask; 178*4c7070dbSScott Long 179*4c7070dbSScott Long iflib_intr_mode_t isc_intr; 180*4c7070dbSScott Long uint16_t isc_max_frame_size; /* set at init time by driver */ 181*4c7070dbSScott Long pci_vendor_info_t isc_vendor_info; /* set by iflib prior to attach_pre */ 182*4c7070dbSScott Long } *if_softc_ctx_t; 183*4c7070dbSScott Long 184*4c7070dbSScott Long /* 185*4c7070dbSScott Long * Initialization values for device 186*4c7070dbSScott Long */ 187*4c7070dbSScott Long struct if_shared_ctx { 188*4c7070dbSScott Long int isc_magic; 189*4c7070dbSScott Long if_txrx_t isc_txrx; 190*4c7070dbSScott Long driver_t *isc_driver; 191*4c7070dbSScott Long int isc_ntxd; 192*4c7070dbSScott Long int isc_nrxd; 193*4c7070dbSScott Long int isc_nfl; 194*4c7070dbSScott Long int isc_flags; 195*4c7070dbSScott Long bus_size_t isc_q_align; 196*4c7070dbSScott Long bus_size_t isc_tx_maxsize; 197*4c7070dbSScott Long bus_size_t isc_tx_maxsegsize; 198*4c7070dbSScott Long bus_size_t isc_rx_maxsize; 199*4c7070dbSScott Long bus_size_t isc_rx_maxsegsize; 200*4c7070dbSScott Long int isc_rx_nsegments; 201*4c7070dbSScott Long int isc_rx_process_limit; 202*4c7070dbSScott Long 203*4c7070dbSScott Long 204*4c7070dbSScott Long uint32_t isc_txqsizes[8]; 205*4c7070dbSScott Long int isc_ntxqs; /* # of tx queues per tx qset - usually 1 */ 206*4c7070dbSScott Long uint32_t isc_rxqsizes[8]; 207*4c7070dbSScott Long int isc_nrxqs; /* # of rx queues per rx qset - intel 1, chelsio 2, broadcom 3 */ 208*4c7070dbSScott Long int isc_admin_intrcnt; /* # of admin/link interrupts */ 209*4c7070dbSScott Long 210*4c7070dbSScott Long int isc_tx_reclaim_thresh; 211*4c7070dbSScott Long 212*4c7070dbSScott Long /* fields necessary for probe */ 213*4c7070dbSScott Long pci_vendor_info_t *isc_vendor_info; 214*4c7070dbSScott Long char *isc_driver_version; 215*4c7070dbSScott Long /* optional function to transform the read values to match the table*/ 216*4c7070dbSScott Long void (*isc_parse_devinfo) (uint16_t *device_id, uint16_t *subvendor_id, 217*4c7070dbSScott Long uint16_t *subdevice_id, uint16_t *rev_id); 218*4c7070dbSScott Long }; 219*4c7070dbSScott Long 220*4c7070dbSScott Long typedef struct iflib_dma_info { 221*4c7070dbSScott Long bus_addr_t idi_paddr; 222*4c7070dbSScott Long caddr_t idi_vaddr; 223*4c7070dbSScott Long bus_dma_tag_t idi_tag; 224*4c7070dbSScott Long bus_dmamap_t idi_map; 225*4c7070dbSScott Long uint32_t idi_size; 226*4c7070dbSScott Long } *iflib_dma_info_t; 227*4c7070dbSScott Long 228*4c7070dbSScott Long #define IFLIB_MAGIC 0xCAFEF00D 229*4c7070dbSScott Long 230*4c7070dbSScott Long typedef enum { 231*4c7070dbSScott Long IFLIB_INTR_TX, 232*4c7070dbSScott Long IFLIB_INTR_RX, 233*4c7070dbSScott Long IFLIB_INTR_ADMIN, 234*4c7070dbSScott Long IFLIB_INTR_IOV, 235*4c7070dbSScott Long } iflib_intr_type_t; 236*4c7070dbSScott Long 237*4c7070dbSScott Long #ifndef ETH_ADDR_LEN 238*4c7070dbSScott Long #define ETH_ADDR_LEN 6 239*4c7070dbSScott Long #endif 240*4c7070dbSScott Long 241*4c7070dbSScott Long 242*4c7070dbSScott Long /* 243*4c7070dbSScott Long * Interface has a separate command queue 244*4c7070dbSScott Long */ 245*4c7070dbSScott Long #define IFLIB_HAS_CQ 0x1 246*4c7070dbSScott Long /* 247*4c7070dbSScott Long * Driver has already allocated vectors 248*4c7070dbSScott Long */ 249*4c7070dbSScott Long #define IFLIB_SKIP_MSIX 0x2 250*4c7070dbSScott Long 251*4c7070dbSScott Long /* 252*4c7070dbSScott Long * Interface is a virtual function 253*4c7070dbSScott Long */ 254*4c7070dbSScott Long #define IFLIB_IS_VF 0x4 255*4c7070dbSScott Long 256*4c7070dbSScott Long 257*4c7070dbSScott Long /* 258*4c7070dbSScott Long * field accessors 259*4c7070dbSScott Long */ 260*4c7070dbSScott Long void *iflib_get_softc(if_ctx_t ctx); 261*4c7070dbSScott Long 262*4c7070dbSScott Long device_t iflib_get_dev(if_ctx_t ctx); 263*4c7070dbSScott Long 264*4c7070dbSScott Long if_t iflib_get_ifp(if_ctx_t ctx); 265*4c7070dbSScott Long 266*4c7070dbSScott Long struct ifmedia *iflib_get_media(if_ctx_t ctx); 267*4c7070dbSScott Long 268*4c7070dbSScott Long if_softc_ctx_t iflib_get_softc_ctx(if_ctx_t ctx); 269*4c7070dbSScott Long if_shared_ctx_t iflib_get_sctx(if_ctx_t ctx); 270*4c7070dbSScott Long 271*4c7070dbSScott Long void iflib_set_mac(if_ctx_t ctx, uint8_t mac[ETHER_ADDR_LEN]); 272*4c7070dbSScott Long 273*4c7070dbSScott Long 274*4c7070dbSScott Long 275*4c7070dbSScott Long 276*4c7070dbSScott Long /* 277*4c7070dbSScott Long * If the driver can plug cleanly in to newbus use these 278*4c7070dbSScott Long */ 279*4c7070dbSScott Long int iflib_device_probe(device_t); 280*4c7070dbSScott Long int iflib_device_attach(device_t); 281*4c7070dbSScott Long int iflib_device_detach(device_t); 282*4c7070dbSScott Long int iflib_device_suspend(device_t); 283*4c7070dbSScott Long int iflib_device_resume(device_t); 284*4c7070dbSScott Long int iflib_device_shutdown(device_t); 285*4c7070dbSScott Long 286*4c7070dbSScott Long 287*4c7070dbSScott Long int iflib_device_iov_init(device_t, uint16_t, const nvlist_t *); 288*4c7070dbSScott Long void iflib_device_iov_uninit(device_t); 289*4c7070dbSScott Long int iflib_device_iov_add_vf(device_t, uint16_t, const nvlist_t *); 290*4c7070dbSScott Long 291*4c7070dbSScott Long /* 292*4c7070dbSScott Long * If the driver can't plug cleanly in to newbus 293*4c7070dbSScott Long * use these 294*4c7070dbSScott Long */ 295*4c7070dbSScott Long int iflib_device_register(device_t dev, void *softc, if_shared_ctx_t sctx, if_ctx_t *ctxp); 296*4c7070dbSScott Long int iflib_device_deregister(if_ctx_t); 297*4c7070dbSScott Long 298*4c7070dbSScott Long 299*4c7070dbSScott Long 300*4c7070dbSScott Long int iflib_irq_alloc(if_ctx_t, if_irq_t, int, driver_filter_t, void *filter_arg, driver_intr_t, void *arg, char *name); 301*4c7070dbSScott Long int iflib_irq_alloc_generic(if_ctx_t ctx, if_irq_t irq, int rid, 302*4c7070dbSScott Long iflib_intr_type_t type, driver_filter_t *filter, 303*4c7070dbSScott Long void *filter_arg, int qid, char *name); 304*4c7070dbSScott Long void iflib_softirq_alloc_generic(if_ctx_t ctx, int rid, iflib_intr_type_t type, void *arg, int qid, char *name); 305*4c7070dbSScott Long 306*4c7070dbSScott Long void iflib_irq_free(if_ctx_t ctx, if_irq_t irq); 307*4c7070dbSScott Long 308*4c7070dbSScott Long void iflib_io_tqg_attach(struct grouptask *gt, void *uniq, int cpu, char *name); 309*4c7070dbSScott Long 310*4c7070dbSScott Long void iflib_config_gtask_init(if_ctx_t ctx, struct grouptask *gtask, 311*4c7070dbSScott Long task_fn_t *fn, char *name); 312*4c7070dbSScott Long 313*4c7070dbSScott Long 314*4c7070dbSScott Long void iflib_tx_intr_deferred(if_ctx_t ctx, int txqid); 315*4c7070dbSScott Long void iflib_rx_intr_deferred(if_ctx_t ctx, int rxqid); 316*4c7070dbSScott Long void iflib_admin_intr_deferred(if_ctx_t ctx); 317*4c7070dbSScott Long void iflib_iov_intr_deferred(if_ctx_t ctx); 318*4c7070dbSScott Long 319*4c7070dbSScott Long 320*4c7070dbSScott Long void iflib_link_state_change(if_ctx_t ctx, int linkstate); 321*4c7070dbSScott Long 322*4c7070dbSScott Long int iflib_dma_alloc(if_ctx_t ctx, int size, iflib_dma_info_t dma, int mapflags); 323*4c7070dbSScott Long void iflib_dma_free(iflib_dma_info_t dma); 324*4c7070dbSScott Long 325*4c7070dbSScott Long int iflib_dma_alloc_multi(if_ctx_t ctx, int *sizes, iflib_dma_info_t *dmalist, int mapflags, int count); 326*4c7070dbSScott Long 327*4c7070dbSScott Long void iflib_dma_free_multi(iflib_dma_info_t *dmalist, int count); 328*4c7070dbSScott Long 329*4c7070dbSScott Long 330*4c7070dbSScott Long struct mtx *iflib_ctx_lock_get(if_ctx_t); 331*4c7070dbSScott Long struct mtx *iflib_qset_lock_get(if_ctx_t, uint16_t); 332*4c7070dbSScott Long 333*4c7070dbSScott Long void iflib_led_create(if_ctx_t ctx); 334*4c7070dbSScott Long 335*4c7070dbSScott Long void iflib_add_int_delay_sysctl(if_ctx_t, const char *, const char *, 336*4c7070dbSScott Long if_int_delay_info_t, int, int); 337*4c7070dbSScott Long 338*4c7070dbSScott Long #endif /* __IFLIB_H_ */ 339