Home | History | Annotate | Line # | Download | only in pci
if_ixl.c revision 1.65.2.2
      1  1.65.2.2  martin /*	$NetBSD: if_ixl.c,v 1.65.2.2 2020/04/08 14:08:09 martin Exp $	*/
      2  1.65.2.2  martin 
      3  1.65.2.2  martin /*
      4  1.65.2.2  martin  * Copyright (c) 2013-2015, Intel Corporation
      5  1.65.2.2  martin  * All rights reserved.
      6  1.65.2.2  martin 
      7  1.65.2.2  martin  * Redistribution and use in source and binary forms, with or without
      8  1.65.2.2  martin  * modification, are permitted provided that the following conditions are met:
      9  1.65.2.2  martin  *
     10  1.65.2.2  martin  *  1. Redistributions of source code must retain the above copyright notice,
     11  1.65.2.2  martin  *     this list of conditions and the following disclaimer.
     12  1.65.2.2  martin  *
     13  1.65.2.2  martin  *  2. Redistributions in binary form must reproduce the above copyright
     14  1.65.2.2  martin  *     notice, this list of conditions and the following disclaimer in the
     15  1.65.2.2  martin  *     documentation and/or other materials provided with the distribution.
     16  1.65.2.2  martin  *
     17  1.65.2.2  martin  *  3. Neither the name of the Intel Corporation nor the names of its
     18  1.65.2.2  martin  *     contributors may be used to endorse or promote products derived from
     19  1.65.2.2  martin  *     this software without specific prior written permission.
     20  1.65.2.2  martin  *
     21  1.65.2.2  martin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     22  1.65.2.2  martin  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.65.2.2  martin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.65.2.2  martin  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     25  1.65.2.2  martin  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  1.65.2.2  martin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  1.65.2.2  martin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  1.65.2.2  martin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  1.65.2.2  martin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  1.65.2.2  martin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  1.65.2.2  martin  * POSSIBILITY OF SUCH DAMAGE.
     32  1.65.2.2  martin  */
     33  1.65.2.2  martin 
     34  1.65.2.2  martin /*
     35  1.65.2.2  martin  * Copyright (c) 2016,2017 David Gwynne <dlg (at) openbsd.org>
     36  1.65.2.2  martin  *
     37  1.65.2.2  martin  * Permission to use, copy, modify, and distribute this software for any
     38  1.65.2.2  martin  * purpose with or without fee is hereby granted, provided that the above
     39  1.65.2.2  martin  * copyright notice and this permission notice appear in all copies.
     40  1.65.2.2  martin  *
     41  1.65.2.2  martin  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     42  1.65.2.2  martin  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     43  1.65.2.2  martin  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     44  1.65.2.2  martin  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     45  1.65.2.2  martin  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     46  1.65.2.2  martin  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     47  1.65.2.2  martin  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     48  1.65.2.2  martin  */
     49  1.65.2.2  martin 
     50  1.65.2.2  martin /*
     51  1.65.2.2  martin  * Copyright (c) 2019 Internet Initiative Japan, Inc.
     52  1.65.2.2  martin  * All rights reserved.
     53  1.65.2.2  martin  *
     54  1.65.2.2  martin  * Redistribution and use in source and binary forms, with or without
     55  1.65.2.2  martin  * modification, are permitted provided that the following conditions
     56  1.65.2.2  martin  * are met:
     57  1.65.2.2  martin  * 1. Redistributions of source code must retain the above copyright
     58  1.65.2.2  martin  *    notice, this list of conditions and the following disclaimer.
     59  1.65.2.2  martin  * 2. Redistributions in binary form must reproduce the above copyright
     60  1.65.2.2  martin  *    notice, this list of conditions and the following disclaimer in the
     61  1.65.2.2  martin  *    documentation and/or other materials provided with the distribution.
     62  1.65.2.2  martin  *
     63  1.65.2.2  martin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     64  1.65.2.2  martin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     65  1.65.2.2  martin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     66  1.65.2.2  martin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     67  1.65.2.2  martin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     68  1.65.2.2  martin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     69  1.65.2.2  martin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     70  1.65.2.2  martin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     71  1.65.2.2  martin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     72  1.65.2.2  martin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     73  1.65.2.2  martin  * POSSIBILITY OF SUCH DAMAGE.
     74  1.65.2.2  martin  */
     75  1.65.2.2  martin 
     76  1.65.2.2  martin #include <sys/cdefs.h>
     77  1.65.2.2  martin __KERNEL_RCSID(0, "$NetBSD: if_ixl.c,v 1.65.2.2 2020/04/08 14:08:09 martin Exp $");
     78  1.65.2.2  martin 
     79  1.65.2.2  martin #ifdef _KERNEL_OPT
     80  1.65.2.2  martin #include "opt_net_mpsafe.h"
     81  1.65.2.2  martin #include "opt_if_ixl.h"
     82  1.65.2.2  martin #endif
     83  1.65.2.2  martin 
     84  1.65.2.2  martin #include <sys/param.h>
     85  1.65.2.2  martin #include <sys/types.h>
     86  1.65.2.2  martin 
     87  1.65.2.2  martin #include <sys/cpu.h>
     88  1.65.2.2  martin #include <sys/device.h>
     89  1.65.2.2  martin #include <sys/evcnt.h>
     90  1.65.2.2  martin #include <sys/interrupt.h>
     91  1.65.2.2  martin #include <sys/kmem.h>
     92  1.65.2.2  martin #include <sys/module.h>
     93  1.65.2.2  martin #include <sys/mutex.h>
     94  1.65.2.2  martin #include <sys/pcq.h>
     95  1.65.2.2  martin #include <sys/syslog.h>
     96  1.65.2.2  martin #include <sys/workqueue.h>
     97  1.65.2.2  martin 
     98  1.65.2.2  martin #include <sys/bus.h>
     99  1.65.2.2  martin 
    100  1.65.2.2  martin #include <net/bpf.h>
    101  1.65.2.2  martin #include <net/if.h>
    102  1.65.2.2  martin #include <net/if_dl.h>
    103  1.65.2.2  martin #include <net/if_media.h>
    104  1.65.2.2  martin #include <net/if_ether.h>
    105  1.65.2.2  martin #include <net/rss_config.h>
    106  1.65.2.2  martin 
    107  1.65.2.2  martin #include <netinet/tcp.h>	/* for struct tcphdr */
    108  1.65.2.2  martin #include <netinet/udp.h>	/* for struct udphdr */
    109  1.65.2.2  martin 
    110  1.65.2.2  martin #include <dev/pci/pcivar.h>
    111  1.65.2.2  martin #include <dev/pci/pcidevs.h>
    112  1.65.2.2  martin 
    113  1.65.2.2  martin #include <dev/pci/if_ixlreg.h>
    114  1.65.2.2  martin #include <dev/pci/if_ixlvar.h>
    115  1.65.2.2  martin 
    116  1.65.2.2  martin #include <prop/proplib.h>
    117  1.65.2.2  martin 
    118  1.65.2.2  martin struct ixl_softc; /* defined */
    119  1.65.2.2  martin 
    120  1.65.2.2  martin #define I40E_PF_RESET_WAIT_COUNT	200
    121  1.65.2.2  martin #define I40E_AQ_LARGE_BUF		512
    122  1.65.2.2  martin 
    123  1.65.2.2  martin /* bitfields for Tx queue mapping in QTX_CTL */
    124  1.65.2.2  martin #define I40E_QTX_CTL_VF_QUEUE		0x0
    125  1.65.2.2  martin #define I40E_QTX_CTL_VM_QUEUE		0x1
    126  1.65.2.2  martin #define I40E_QTX_CTL_PF_QUEUE		0x2
    127  1.65.2.2  martin 
    128  1.65.2.2  martin #define I40E_QUEUE_TYPE_EOL		0x7ff
    129  1.65.2.2  martin #define I40E_INTR_NOTX_QUEUE		0
    130  1.65.2.2  martin 
    131  1.65.2.2  martin #define I40E_QUEUE_TYPE_RX		0x0
    132  1.65.2.2  martin #define I40E_QUEUE_TYPE_TX		0x1
    133  1.65.2.2  martin #define I40E_QUEUE_TYPE_PE_CEQ		0x2
    134  1.65.2.2  martin #define I40E_QUEUE_TYPE_UNKNOWN		0x3
    135  1.65.2.2  martin 
    136  1.65.2.2  martin #define I40E_ITR_INDEX_RX		0x0
    137  1.65.2.2  martin #define I40E_ITR_INDEX_TX		0x1
    138  1.65.2.2  martin #define I40E_ITR_INDEX_OTHER		0x2
    139  1.65.2.2  martin #define I40E_ITR_INDEX_NONE		0x3
    140  1.65.2.2  martin #define IXL_ITR_RX			0x7a /* 4K intrs/sec */
    141  1.65.2.2  martin #define IXL_ITR_TX			0x7a /* 4K intrs/sec */
    142  1.65.2.2  martin 
    143  1.65.2.2  martin #define I40E_INTR_NOTX_QUEUE		0
    144  1.65.2.2  martin #define I40E_INTR_NOTX_INTR		0
    145  1.65.2.2  martin #define I40E_INTR_NOTX_RX_QUEUE		0
    146  1.65.2.2  martin #define I40E_INTR_NOTX_TX_QUEUE		1
    147  1.65.2.2  martin #define I40E_INTR_NOTX_RX_MASK		I40E_PFINT_ICR0_QUEUE_0_MASK
    148  1.65.2.2  martin #define I40E_INTR_NOTX_TX_MASK		I40E_PFINT_ICR0_QUEUE_1_MASK
    149  1.65.2.2  martin 
    150  1.65.2.2  martin #define BIT_ULL(a)	(1ULL << (a))
    151  1.65.2.2  martin #define IXL_RSS_HENA_DEFAULT_BASE			\
    152  1.65.2.2  martin 	(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |	\
    153  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP) |	\
    154  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) |	\
    155  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |	\
    156  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4) |	\
    157  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |	\
    158  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP) |	\
    159  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) |	\
    160  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |	\
    161  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6) |	\
    162  1.65.2.2  martin 	 BIT_ULL(I40E_FILTER_PCTYPE_L2_PAYLOAD))
    163  1.65.2.2  martin #define IXL_RSS_HENA_DEFAULT_XL710	IXL_RSS_HENA_DEFAULT_BASE
    164  1.65.2.2  martin #define IXL_RSS_HENA_DEFAULT_X722	(IXL_RSS_HENA_DEFAULT_XL710 |	\
    165  1.65.2.2  martin 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |		\
    166  1.65.2.2  martin 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |		\
    167  1.65.2.2  martin 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |		\
    168  1.65.2.2  martin 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |		\
    169  1.65.2.2  martin 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK) |	\
    170  1.65.2.2  martin 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK))
    171  1.65.2.2  martin #define I40E_HASH_LUT_SIZE_128		0
    172  1.65.2.2  martin #define IXL_RSS_KEY_SIZE_REG		13
    173  1.65.2.2  martin 
    174  1.65.2.2  martin #define IXL_ICR0_CRIT_ERR_MASK			\
    175  1.65.2.2  martin 	(I40E_PFINT_ICR0_PCI_EXCEPTION_MASK |	\
    176  1.65.2.2  martin 	I40E_PFINT_ICR0_ECC_ERR_MASK |		\
    177  1.65.2.2  martin 	I40E_PFINT_ICR0_PE_CRITERR_MASK)
    178  1.65.2.2  martin 
    179  1.65.2.2  martin #define IXL_QUEUE_MAX_XL710		64
    180  1.65.2.2  martin #define IXL_QUEUE_MAX_X722		128
    181  1.65.2.2  martin 
    182  1.65.2.2  martin #define IXL_TX_PKT_DESCS		8
    183  1.65.2.2  martin #define IXL_TX_PKT_MAXSIZE		(MCLBYTES * IXL_TX_PKT_DESCS)
    184  1.65.2.2  martin #define IXL_TX_QUEUE_ALIGN		128
    185  1.65.2.2  martin #define IXL_RX_QUEUE_ALIGN		128
    186  1.65.2.2  martin 
    187  1.65.2.2  martin #define IXL_MCLBYTES			(MCLBYTES - ETHER_ALIGN)
    188  1.65.2.2  martin #define IXL_MTU_ETHERLEN		ETHER_HDR_LEN		\
    189  1.65.2.2  martin 					+ ETHER_CRC_LEN
    190  1.65.2.2  martin #if 0
    191  1.65.2.2  martin #define IXL_MAX_MTU			(9728 - IXL_MTU_ETHERLEN)
    192  1.65.2.2  martin #else
    193  1.65.2.2  martin /* (dbuff * 5) - ETHER_HDR_LEN - ETHER_CRC_LEN */
    194  1.65.2.2  martin #define IXL_MAX_MTU			(9600 - IXL_MTU_ETHERLEN)
    195  1.65.2.2  martin #endif
    196  1.65.2.2  martin #define IXL_MIN_MTU			(ETHER_MIN_LEN - ETHER_CRC_LEN)
    197  1.65.2.2  martin 
    198  1.65.2.2  martin #define IXL_PCIREG			PCI_MAPREG_START
    199  1.65.2.2  martin 
    200  1.65.2.2  martin #define IXL_ITR0			0x0
    201  1.65.2.2  martin #define IXL_ITR1			0x1
    202  1.65.2.2  martin #define IXL_ITR2			0x2
    203  1.65.2.2  martin #define IXL_NOITR			0x3
    204  1.65.2.2  martin 
    205  1.65.2.2  martin #define IXL_AQ_NUM			256
    206  1.65.2.2  martin #define IXL_AQ_MASK			(IXL_AQ_NUM - 1)
    207  1.65.2.2  martin #define IXL_AQ_ALIGN			64 /* lol */
    208  1.65.2.2  martin #define IXL_AQ_BUFLEN			4096
    209  1.65.2.2  martin 
    210  1.65.2.2  martin #define IXL_HMC_ROUNDUP			512
    211  1.65.2.2  martin #define IXL_HMC_PGSIZE			4096
    212  1.65.2.2  martin #define IXL_HMC_DVASZ			sizeof(uint64_t)
    213  1.65.2.2  martin #define IXL_HMC_PGS			(IXL_HMC_PGSIZE / IXL_HMC_DVASZ)
    214  1.65.2.2  martin #define IXL_HMC_L2SZ			(IXL_HMC_PGSIZE * IXL_HMC_PGS)
    215  1.65.2.2  martin #define IXL_HMC_PDVALID			1ULL
    216  1.65.2.2  martin 
    217  1.65.2.2  martin #define IXL_ATQ_EXEC_TIMEOUT		(10 * hz)
    218  1.65.2.2  martin 
    219  1.65.2.2  martin #define IXL_SRRD_SRCTL_ATTEMPTS		100000
    220  1.65.2.2  martin 
    221  1.65.2.2  martin struct ixl_aq_regs {
    222  1.65.2.2  martin 	bus_size_t		atq_tail;
    223  1.65.2.2  martin 	bus_size_t		atq_head;
    224  1.65.2.2  martin 	bus_size_t		atq_len;
    225  1.65.2.2  martin 	bus_size_t		atq_bal;
    226  1.65.2.2  martin 	bus_size_t		atq_bah;
    227  1.65.2.2  martin 
    228  1.65.2.2  martin 	bus_size_t		arq_tail;
    229  1.65.2.2  martin 	bus_size_t		arq_head;
    230  1.65.2.2  martin 	bus_size_t		arq_len;
    231  1.65.2.2  martin 	bus_size_t		arq_bal;
    232  1.65.2.2  martin 	bus_size_t		arq_bah;
    233  1.65.2.2  martin 
    234  1.65.2.2  martin 	uint32_t		atq_len_enable;
    235  1.65.2.2  martin 	uint32_t		atq_tail_mask;
    236  1.65.2.2  martin 	uint32_t		atq_head_mask;
    237  1.65.2.2  martin 
    238  1.65.2.2  martin 	uint32_t		arq_len_enable;
    239  1.65.2.2  martin 	uint32_t		arq_tail_mask;
    240  1.65.2.2  martin 	uint32_t		arq_head_mask;
    241  1.65.2.2  martin };
    242  1.65.2.2  martin 
    243  1.65.2.2  martin struct ixl_phy_type {
    244  1.65.2.2  martin 	uint64_t	phy_type;
    245  1.65.2.2  martin 	uint64_t	ifm_type;
    246  1.65.2.2  martin };
    247  1.65.2.2  martin 
    248  1.65.2.2  martin struct ixl_speed_type {
    249  1.65.2.2  martin 	uint8_t		dev_speed;
    250  1.65.2.2  martin 	uint64_t	net_speed;
    251  1.65.2.2  martin };
    252  1.65.2.2  martin 
    253  1.65.2.2  martin struct ixl_aq_buf {
    254  1.65.2.2  martin 	SIMPLEQ_ENTRY(ixl_aq_buf)
    255  1.65.2.2  martin 				 aqb_entry;
    256  1.65.2.2  martin 	void			*aqb_data;
    257  1.65.2.2  martin 	bus_dmamap_t		 aqb_map;
    258  1.65.2.2  martin 	bus_dma_segment_t	 aqb_seg;
    259  1.65.2.2  martin 	size_t			 aqb_size;
    260  1.65.2.2  martin 	int			 aqb_nsegs;
    261  1.65.2.2  martin };
    262  1.65.2.2  martin SIMPLEQ_HEAD(ixl_aq_bufs, ixl_aq_buf);
    263  1.65.2.2  martin 
    264  1.65.2.2  martin struct ixl_dmamem {
    265  1.65.2.2  martin 	bus_dmamap_t		 ixm_map;
    266  1.65.2.2  martin 	bus_dma_segment_t	 ixm_seg;
    267  1.65.2.2  martin 	int			 ixm_nsegs;
    268  1.65.2.2  martin 	size_t			 ixm_size;
    269  1.65.2.2  martin 	void			*ixm_kva;
    270  1.65.2.2  martin };
    271  1.65.2.2  martin 
    272  1.65.2.2  martin #define IXL_DMA_MAP(_ixm)	((_ixm)->ixm_map)
    273  1.65.2.2  martin #define IXL_DMA_DVA(_ixm)	((_ixm)->ixm_map->dm_segs[0].ds_addr)
    274  1.65.2.2  martin #define IXL_DMA_KVA(_ixm)	((void *)(_ixm)->ixm_kva)
    275  1.65.2.2  martin #define IXL_DMA_LEN(_ixm)	((_ixm)->ixm_size)
    276  1.65.2.2  martin 
    277  1.65.2.2  martin struct ixl_hmc_entry {
    278  1.65.2.2  martin 	uint64_t		 hmc_base;
    279  1.65.2.2  martin 	uint32_t		 hmc_count;
    280  1.65.2.2  martin 	uint64_t		 hmc_size;
    281  1.65.2.2  martin };
    282  1.65.2.2  martin 
    283  1.65.2.2  martin enum  ixl_hmc_types {
    284  1.65.2.2  martin 	IXL_HMC_LAN_TX = 0,
    285  1.65.2.2  martin 	IXL_HMC_LAN_RX,
    286  1.65.2.2  martin 	IXL_HMC_FCOE_CTX,
    287  1.65.2.2  martin 	IXL_HMC_FCOE_FILTER,
    288  1.65.2.2  martin 	IXL_HMC_COUNT
    289  1.65.2.2  martin };
    290  1.65.2.2  martin 
    291  1.65.2.2  martin struct ixl_hmc_pack {
    292  1.65.2.2  martin 	uint16_t		offset;
    293  1.65.2.2  martin 	uint16_t		width;
    294  1.65.2.2  martin 	uint16_t		lsb;
    295  1.65.2.2  martin };
    296  1.65.2.2  martin 
    297  1.65.2.2  martin /*
    298  1.65.2.2  martin  * these hmc objects have weird sizes and alignments, so these are abstract
    299  1.65.2.2  martin  * representations of them that are nice for c to populate.
    300  1.65.2.2  martin  *
    301  1.65.2.2  martin  * the packing code relies on little-endian values being stored in the fields,
    302  1.65.2.2  martin  * no high bits in the fields being set, and the fields must be packed in the
    303  1.65.2.2  martin  * same order as they are in the ctx structure.
    304  1.65.2.2  martin  */
    305  1.65.2.2  martin 
    306  1.65.2.2  martin struct ixl_hmc_rxq {
    307  1.65.2.2  martin 	uint16_t		 head;
    308  1.65.2.2  martin 	uint8_t			 cpuid;
    309  1.65.2.2  martin 	uint64_t		 base;
    310  1.65.2.2  martin #define IXL_HMC_RXQ_BASE_UNIT		128
    311  1.65.2.2  martin 	uint16_t		 qlen;
    312  1.65.2.2  martin 	uint16_t		 dbuff;
    313  1.65.2.2  martin #define IXL_HMC_RXQ_DBUFF_UNIT		128
    314  1.65.2.2  martin 	uint8_t			 hbuff;
    315  1.65.2.2  martin #define IXL_HMC_RXQ_HBUFF_UNIT		64
    316  1.65.2.2  martin 	uint8_t			 dtype;
    317  1.65.2.2  martin #define IXL_HMC_RXQ_DTYPE_NOSPLIT	0x0
    318  1.65.2.2  martin #define IXL_HMC_RXQ_DTYPE_HSPLIT	0x1
    319  1.65.2.2  martin #define IXL_HMC_RXQ_DTYPE_SPLIT_ALWAYS	0x2
    320  1.65.2.2  martin 	uint8_t			 dsize;
    321  1.65.2.2  martin #define IXL_HMC_RXQ_DSIZE_16		0
    322  1.65.2.2  martin #define IXL_HMC_RXQ_DSIZE_32		1
    323  1.65.2.2  martin 	uint8_t			 crcstrip;
    324  1.65.2.2  martin 	uint8_t			 fc_ena;
    325  1.65.2.2  martin 	uint8_t			 l2sel;
    326  1.65.2.2  martin 	uint8_t			 hsplit_0;
    327  1.65.2.2  martin 	uint8_t			 hsplit_1;
    328  1.65.2.2  martin 	uint8_t			 showiv;
    329  1.65.2.2  martin 	uint16_t		 rxmax;
    330  1.65.2.2  martin 	uint8_t			 tphrdesc_ena;
    331  1.65.2.2  martin 	uint8_t			 tphwdesc_ena;
    332  1.65.2.2  martin 	uint8_t			 tphdata_ena;
    333  1.65.2.2  martin 	uint8_t			 tphhead_ena;
    334  1.65.2.2  martin 	uint8_t			 lrxqthresh;
    335  1.65.2.2  martin 	uint8_t			 prefena;
    336  1.65.2.2  martin };
    337  1.65.2.2  martin 
    338  1.65.2.2  martin static const struct ixl_hmc_pack ixl_hmc_pack_rxq[] = {
    339  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, head),		13,	0 },
    340  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, cpuid),		8,	13 },
    341  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, base),		57,	32 },
    342  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, qlen),		13,	89 },
    343  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, dbuff),		7,	102 },
    344  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, hbuff),		5,	109 },
    345  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, dtype),		2,	114 },
    346  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, dsize),		1,	116 },
    347  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, crcstrip),	1,	117 },
    348  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, fc_ena),		1,	118 },
    349  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, l2sel),		1,	119 },
    350  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, hsplit_0),	4,	120 },
    351  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, hsplit_1),	2,	124 },
    352  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, showiv),		1,	127 },
    353  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, rxmax),		14,	174 },
    354  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, tphrdesc_ena),	1,	193 },
    355  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, tphwdesc_ena),	1,	194 },
    356  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, tphdata_ena),	1,	195 },
    357  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, tphhead_ena),	1,	196 },
    358  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, lrxqthresh),	3,	198 },
    359  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_rxq, prefena),	1,	201 },
    360  1.65.2.2  martin };
    361  1.65.2.2  martin 
    362  1.65.2.2  martin #define IXL_HMC_RXQ_MINSIZE (201 + 1)
    363  1.65.2.2  martin 
    364  1.65.2.2  martin struct ixl_hmc_txq {
    365  1.65.2.2  martin 	uint16_t		head;
    366  1.65.2.2  martin 	uint8_t			new_context;
    367  1.65.2.2  martin 	uint64_t		base;
    368  1.65.2.2  martin #define IXL_HMC_TXQ_BASE_UNIT		128
    369  1.65.2.2  martin 	uint8_t			fc_ena;
    370  1.65.2.2  martin 	uint8_t			timesync_ena;
    371  1.65.2.2  martin 	uint8_t			fd_ena;
    372  1.65.2.2  martin 	uint8_t			alt_vlan_ena;
    373  1.65.2.2  martin 	uint8_t			cpuid;
    374  1.65.2.2  martin 	uint16_t		thead_wb;
    375  1.65.2.2  martin 	uint8_t			head_wb_ena;
    376  1.65.2.2  martin #define IXL_HMC_TXQ_DESC_WB		0
    377  1.65.2.2  martin #define IXL_HMC_TXQ_HEAD_WB		1
    378  1.65.2.2  martin 	uint16_t		qlen;
    379  1.65.2.2  martin 	uint8_t			tphrdesc_ena;
    380  1.65.2.2  martin 	uint8_t			tphrpacket_ena;
    381  1.65.2.2  martin 	uint8_t			tphwdesc_ena;
    382  1.65.2.2  martin 	uint64_t		head_wb_addr;
    383  1.65.2.2  martin 	uint32_t		crc;
    384  1.65.2.2  martin 	uint16_t		rdylist;
    385  1.65.2.2  martin 	uint8_t			rdylist_act;
    386  1.65.2.2  martin };
    387  1.65.2.2  martin 
    388  1.65.2.2  martin static const struct ixl_hmc_pack ixl_hmc_pack_txq[] = {
    389  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, head),		13,	0 },
    390  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, new_context),	1,	30 },
    391  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, base),		57,	32 },
    392  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, fc_ena),		1,	89 },
    393  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, timesync_ena),	1,	90 },
    394  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, fd_ena),		1,	91 },
    395  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, alt_vlan_ena),	1,	92 },
    396  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, cpuid),		8,	96 },
    397  1.65.2.2  martin /* line 1 */
    398  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, thead_wb),	13,	0 + 128 },
    399  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, head_wb_ena),	1,	32 + 128 },
    400  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, qlen),		13,	33 + 128 },
    401  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, tphrdesc_ena),	1,	46 + 128 },
    402  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, tphrpacket_ena),	1,	47 + 128 },
    403  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, tphwdesc_ena),	1,	48 + 128 },
    404  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, head_wb_addr),	64,	64 + 128 },
    405  1.65.2.2  martin /* line 7 */
    406  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, crc),		32,	0 + (7*128) },
    407  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, rdylist),	10,	84 + (7*128) },
    408  1.65.2.2  martin 	{ offsetof(struct ixl_hmc_txq, rdylist_act),	1,	94 + (7*128) },
    409  1.65.2.2  martin };
    410  1.65.2.2  martin 
    411  1.65.2.2  martin #define IXL_HMC_TXQ_MINSIZE (94 + (7*128) + 1)
    412  1.65.2.2  martin 
    413  1.65.2.2  martin struct ixl_work {
    414  1.65.2.2  martin 	struct work	 ixw_cookie;
    415  1.65.2.2  martin 	void		(*ixw_func)(void *);
    416  1.65.2.2  martin 	void		*ixw_arg;
    417  1.65.2.2  martin 	unsigned int	 ixw_added;
    418  1.65.2.2  martin };
    419  1.65.2.2  martin #define IXL_WORKQUEUE_PRI	PRI_SOFTNET
    420  1.65.2.2  martin 
    421  1.65.2.2  martin struct ixl_tx_map {
    422  1.65.2.2  martin 	struct mbuf		*txm_m;
    423  1.65.2.2  martin 	bus_dmamap_t		 txm_map;
    424  1.65.2.2  martin 	unsigned int		 txm_eop;
    425  1.65.2.2  martin };
    426  1.65.2.2  martin 
    427  1.65.2.2  martin struct ixl_tx_ring {
    428  1.65.2.2  martin 	kmutex_t		 txr_lock;
    429  1.65.2.2  martin 	struct ixl_softc	*txr_sc;
    430  1.65.2.2  martin 
    431  1.65.2.2  martin 	unsigned int		 txr_prod;
    432  1.65.2.2  martin 	unsigned int		 txr_cons;
    433  1.65.2.2  martin 
    434  1.65.2.2  martin 	struct ixl_tx_map	*txr_maps;
    435  1.65.2.2  martin 	struct ixl_dmamem	 txr_mem;
    436  1.65.2.2  martin 
    437  1.65.2.2  martin 	bus_size_t		 txr_tail;
    438  1.65.2.2  martin 	unsigned int		 txr_qid;
    439  1.65.2.2  martin 	pcq_t			*txr_intrq;
    440  1.65.2.2  martin 	void			*txr_si;
    441  1.65.2.2  martin 
    442  1.65.2.2  martin 	struct evcnt		 txr_defragged;
    443  1.65.2.2  martin 	struct evcnt		 txr_defrag_failed;
    444  1.65.2.2  martin 	struct evcnt		 txr_pcqdrop;
    445  1.65.2.2  martin 	struct evcnt		 txr_transmitdef;
    446  1.65.2.2  martin 	struct evcnt		 txr_intr;
    447  1.65.2.2  martin 	struct evcnt		 txr_defer;
    448  1.65.2.2  martin };
    449  1.65.2.2  martin 
    450  1.65.2.2  martin struct ixl_rx_map {
    451  1.65.2.2  martin 	struct mbuf		*rxm_m;
    452  1.65.2.2  martin 	bus_dmamap_t		 rxm_map;
    453  1.65.2.2  martin };
    454  1.65.2.2  martin 
    455  1.65.2.2  martin struct ixl_rx_ring {
    456  1.65.2.2  martin 	kmutex_t		 rxr_lock;
    457  1.65.2.2  martin 
    458  1.65.2.2  martin 	unsigned int		 rxr_prod;
    459  1.65.2.2  martin 	unsigned int		 rxr_cons;
    460  1.65.2.2  martin 
    461  1.65.2.2  martin 	struct ixl_rx_map	*rxr_maps;
    462  1.65.2.2  martin 	struct ixl_dmamem	 rxr_mem;
    463  1.65.2.2  martin 
    464  1.65.2.2  martin 	struct mbuf		*rxr_m_head;
    465  1.65.2.2  martin 	struct mbuf		**rxr_m_tail;
    466  1.65.2.2  martin 
    467  1.65.2.2  martin 	bus_size_t		 rxr_tail;
    468  1.65.2.2  martin 	unsigned int		 rxr_qid;
    469  1.65.2.2  martin 
    470  1.65.2.2  martin 	struct evcnt		 rxr_mgethdr_failed;
    471  1.65.2.2  martin 	struct evcnt		 rxr_mgetcl_failed;
    472  1.65.2.2  martin 	struct evcnt		 rxr_mbuf_load_failed;
    473  1.65.2.2  martin 	struct evcnt		 rxr_intr;
    474  1.65.2.2  martin 	struct evcnt		 rxr_defer;
    475  1.65.2.2  martin };
    476  1.65.2.2  martin 
    477  1.65.2.2  martin struct ixl_queue_pair {
    478  1.65.2.2  martin 	struct ixl_softc	*qp_sc;
    479  1.65.2.2  martin 	struct ixl_tx_ring	*qp_txr;
    480  1.65.2.2  martin 	struct ixl_rx_ring	*qp_rxr;
    481  1.65.2.2  martin 
    482  1.65.2.2  martin 	char			 qp_name[16];
    483  1.65.2.2  martin 
    484  1.65.2.2  martin 	void			*qp_si;
    485  1.65.2.2  martin 	struct work		 qp_work;
    486  1.65.2.2  martin 	bool			 qp_workqueue;
    487  1.65.2.2  martin };
    488  1.65.2.2  martin 
    489  1.65.2.2  martin struct ixl_atq {
    490  1.65.2.2  martin 	struct ixl_aq_desc	 iatq_desc;
    491  1.65.2.2  martin 	void			(*iatq_fn)(struct ixl_softc *,
    492  1.65.2.2  martin 				    const struct ixl_aq_desc *);
    493  1.65.2.2  martin };
    494  1.65.2.2  martin SIMPLEQ_HEAD(ixl_atq_list, ixl_atq);
    495  1.65.2.2  martin 
    496  1.65.2.2  martin struct ixl_product {
    497  1.65.2.2  martin 	unsigned int	 vendor_id;
    498  1.65.2.2  martin 	unsigned int	 product_id;
    499  1.65.2.2  martin };
    500  1.65.2.2  martin 
    501  1.65.2.2  martin struct ixl_stats_counters {
    502  1.65.2.2  martin 	bool		 isc_has_offset;
    503  1.65.2.2  martin 	struct evcnt	 isc_crc_errors;
    504  1.65.2.2  martin 	uint64_t	 isc_crc_errors_offset;
    505  1.65.2.2  martin 	struct evcnt	 isc_illegal_bytes;
    506  1.65.2.2  martin 	uint64_t	 isc_illegal_bytes_offset;
    507  1.65.2.2  martin 	struct evcnt	 isc_rx_bytes;
    508  1.65.2.2  martin 	uint64_t	 isc_rx_bytes_offset;
    509  1.65.2.2  martin 	struct evcnt	 isc_rx_discards;
    510  1.65.2.2  martin 	uint64_t	 isc_rx_discards_offset;
    511  1.65.2.2  martin 	struct evcnt	 isc_rx_unicast;
    512  1.65.2.2  martin 	uint64_t	 isc_rx_unicast_offset;
    513  1.65.2.2  martin 	struct evcnt	 isc_rx_multicast;
    514  1.65.2.2  martin 	uint64_t	 isc_rx_multicast_offset;
    515  1.65.2.2  martin 	struct evcnt	 isc_rx_broadcast;
    516  1.65.2.2  martin 	uint64_t	 isc_rx_broadcast_offset;
    517  1.65.2.2  martin 	struct evcnt	 isc_rx_size_64;
    518  1.65.2.2  martin 	uint64_t	 isc_rx_size_64_offset;
    519  1.65.2.2  martin 	struct evcnt	 isc_rx_size_127;
    520  1.65.2.2  martin 	uint64_t	 isc_rx_size_127_offset;
    521  1.65.2.2  martin 	struct evcnt	 isc_rx_size_255;
    522  1.65.2.2  martin 	uint64_t	 isc_rx_size_255_offset;
    523  1.65.2.2  martin 	struct evcnt	 isc_rx_size_511;
    524  1.65.2.2  martin 	uint64_t	 isc_rx_size_511_offset;
    525  1.65.2.2  martin 	struct evcnt	 isc_rx_size_1023;
    526  1.65.2.2  martin 	uint64_t	 isc_rx_size_1023_offset;
    527  1.65.2.2  martin 	struct evcnt	 isc_rx_size_1522;
    528  1.65.2.2  martin 	uint64_t	 isc_rx_size_1522_offset;
    529  1.65.2.2  martin 	struct evcnt	 isc_rx_size_big;
    530  1.65.2.2  martin 	uint64_t	 isc_rx_size_big_offset;
    531  1.65.2.2  martin 	struct evcnt	 isc_rx_undersize;
    532  1.65.2.2  martin 	uint64_t	 isc_rx_undersize_offset;
    533  1.65.2.2  martin 	struct evcnt	 isc_rx_oversize;
    534  1.65.2.2  martin 	uint64_t	 isc_rx_oversize_offset;
    535  1.65.2.2  martin 	struct evcnt	 isc_rx_fragments;
    536  1.65.2.2  martin 	uint64_t	 isc_rx_fragments_offset;
    537  1.65.2.2  martin 	struct evcnt	 isc_rx_jabber;
    538  1.65.2.2  martin 	uint64_t	 isc_rx_jabber_offset;
    539  1.65.2.2  martin 	struct evcnt	 isc_tx_bytes;
    540  1.65.2.2  martin 	uint64_t	 isc_tx_bytes_offset;
    541  1.65.2.2  martin 	struct evcnt	 isc_tx_dropped_link_down;
    542  1.65.2.2  martin 	uint64_t	 isc_tx_dropped_link_down_offset;
    543  1.65.2.2  martin 	struct evcnt	 isc_tx_unicast;
    544  1.65.2.2  martin 	uint64_t	 isc_tx_unicast_offset;
    545  1.65.2.2  martin 	struct evcnt	 isc_tx_multicast;
    546  1.65.2.2  martin 	uint64_t	 isc_tx_multicast_offset;
    547  1.65.2.2  martin 	struct evcnt	 isc_tx_broadcast;
    548  1.65.2.2  martin 	uint64_t	 isc_tx_broadcast_offset;
    549  1.65.2.2  martin 	struct evcnt	 isc_tx_size_64;
    550  1.65.2.2  martin 	uint64_t	 isc_tx_size_64_offset;
    551  1.65.2.2  martin 	struct evcnt	 isc_tx_size_127;
    552  1.65.2.2  martin 	uint64_t	 isc_tx_size_127_offset;
    553  1.65.2.2  martin 	struct evcnt	 isc_tx_size_255;
    554  1.65.2.2  martin 	uint64_t	 isc_tx_size_255_offset;
    555  1.65.2.2  martin 	struct evcnt	 isc_tx_size_511;
    556  1.65.2.2  martin 	uint64_t	 isc_tx_size_511_offset;
    557  1.65.2.2  martin 	struct evcnt	 isc_tx_size_1023;
    558  1.65.2.2  martin 	uint64_t	 isc_tx_size_1023_offset;
    559  1.65.2.2  martin 	struct evcnt	 isc_tx_size_1522;
    560  1.65.2.2  martin 	uint64_t	 isc_tx_size_1522_offset;
    561  1.65.2.2  martin 	struct evcnt	 isc_tx_size_big;
    562  1.65.2.2  martin 	uint64_t	 isc_tx_size_big_offset;
    563  1.65.2.2  martin 	struct evcnt	 isc_mac_local_faults;
    564  1.65.2.2  martin 	uint64_t	 isc_mac_local_faults_offset;
    565  1.65.2.2  martin 	struct evcnt	 isc_mac_remote_faults;
    566  1.65.2.2  martin 	uint64_t	 isc_mac_remote_faults_offset;
    567  1.65.2.2  martin 	struct evcnt	 isc_link_xon_rx;
    568  1.65.2.2  martin 	uint64_t	 isc_link_xon_rx_offset;
    569  1.65.2.2  martin 	struct evcnt	 isc_link_xon_tx;
    570  1.65.2.2  martin 	uint64_t	 isc_link_xon_tx_offset;
    571  1.65.2.2  martin 	struct evcnt	 isc_link_xoff_rx;
    572  1.65.2.2  martin 	uint64_t	 isc_link_xoff_rx_offset;
    573  1.65.2.2  martin 	struct evcnt	 isc_link_xoff_tx;
    574  1.65.2.2  martin 	uint64_t	 isc_link_xoff_tx_offset;
    575  1.65.2.2  martin 	struct evcnt	 isc_vsi_rx_discards;
    576  1.65.2.2  martin 	uint64_t	 isc_vsi_rx_discards_offset;
    577  1.65.2.2  martin 	struct evcnt	 isc_vsi_rx_bytes;
    578  1.65.2.2  martin 	uint64_t	 isc_vsi_rx_bytes_offset;
    579  1.65.2.2  martin 	struct evcnt	 isc_vsi_rx_unicast;
    580  1.65.2.2  martin 	uint64_t	 isc_vsi_rx_unicast_offset;
    581  1.65.2.2  martin 	struct evcnt	 isc_vsi_rx_multicast;
    582  1.65.2.2  martin 	uint64_t	 isc_vsi_rx_multicast_offset;
    583  1.65.2.2  martin 	struct evcnt	 isc_vsi_rx_broadcast;
    584  1.65.2.2  martin 	uint64_t	 isc_vsi_rx_broadcast_offset;
    585  1.65.2.2  martin 	struct evcnt	 isc_vsi_tx_errors;
    586  1.65.2.2  martin 	uint64_t	 isc_vsi_tx_errors_offset;
    587  1.65.2.2  martin 	struct evcnt	 isc_vsi_tx_bytes;
    588  1.65.2.2  martin 	uint64_t	 isc_vsi_tx_bytes_offset;
    589  1.65.2.2  martin 	struct evcnt	 isc_vsi_tx_unicast;
    590  1.65.2.2  martin 	uint64_t	 isc_vsi_tx_unicast_offset;
    591  1.65.2.2  martin 	struct evcnt	 isc_vsi_tx_multicast;
    592  1.65.2.2  martin 	uint64_t	 isc_vsi_tx_multicast_offset;
    593  1.65.2.2  martin 	struct evcnt	 isc_vsi_tx_broadcast;
    594  1.65.2.2  martin 	uint64_t	 isc_vsi_tx_broadcast_offset;
    595  1.65.2.2  martin };
    596  1.65.2.2  martin 
    597  1.65.2.2  martin /*
    598  1.65.2.2  martin  * Locking notes:
    599  1.65.2.2  martin  * + a field in ixl_tx_ring is protected by txr_lock (a spin mutex), and
    600  1.65.2.2  martin  *   a field in ixl_rx_ring is protected by rxr_lock (a spin mutex).
    601  1.65.2.2  martin  *    - more than one lock of them cannot be held at once.
    602  1.65.2.2  martin  * + a field named sc_atq_* in ixl_softc is protected by sc_atq_lock
    603  1.65.2.2  martin  *   (a spin mutex).
    604  1.65.2.2  martin  *    - the lock cannot held with txr_lock or rxr_lock.
    605  1.65.2.2  martin  * + a field named sc_arq_* is not protected by any lock.
    606  1.65.2.2  martin  *    - operations for sc_arq_* is done in one context related to
    607  1.65.2.2  martin  *      sc_arq_task.
    608  1.65.2.2  martin  * + other fields in ixl_softc is protected by sc_cfg_lock
    609  1.65.2.2  martin  *   (an adaptive mutex)
    610  1.65.2.2  martin  *    - It must be held before another lock is held, and It can be
    611  1.65.2.2  martin  *      released after the other lock is released.
    612  1.65.2.2  martin  * */
    613  1.65.2.2  martin 
    614  1.65.2.2  martin struct ixl_softc {
    615  1.65.2.2  martin 	device_t		 sc_dev;
    616  1.65.2.2  martin 	struct ethercom		 sc_ec;
    617  1.65.2.2  martin 	bool			 sc_attached;
    618  1.65.2.2  martin 	bool			 sc_dead;
    619  1.65.2.2  martin 	uint32_t		 sc_port;
    620  1.65.2.2  martin 	struct sysctllog	*sc_sysctllog;
    621  1.65.2.2  martin 	struct workqueue	*sc_workq;
    622  1.65.2.2  martin 	struct workqueue	*sc_workq_txrx;
    623  1.65.2.2  martin 	int			 sc_stats_intval;
    624  1.65.2.2  martin 	callout_t		 sc_stats_callout;
    625  1.65.2.2  martin 	struct ixl_work		 sc_stats_task;
    626  1.65.2.2  martin 	struct ixl_stats_counters
    627  1.65.2.2  martin 				 sc_stats_counters;
    628  1.65.2.2  martin 	uint8_t			 sc_enaddr[ETHER_ADDR_LEN];
    629  1.65.2.2  martin 	struct ifmedia		 sc_media;
    630  1.65.2.2  martin 	uint64_t		 sc_media_status;
    631  1.65.2.2  martin 	uint64_t		 sc_media_active;
    632  1.65.2.2  martin 	uint64_t		 sc_phy_types;
    633  1.65.2.2  martin 	uint8_t			 sc_phy_abilities;
    634  1.65.2.2  martin 	uint8_t			 sc_phy_linkspeed;
    635  1.65.2.2  martin 	uint8_t			 sc_phy_fec_cfg;
    636  1.65.2.2  martin 	uint16_t		 sc_eee_cap;
    637  1.65.2.2  martin 	uint32_t		 sc_eeer_val;
    638  1.65.2.2  martin 	uint8_t			 sc_d3_lpan;
    639  1.65.2.2  martin 	kmutex_t		 sc_cfg_lock;
    640  1.65.2.2  martin 	enum i40e_mac_type	 sc_mac_type;
    641  1.65.2.2  martin 	uint32_t		 sc_rss_table_size;
    642  1.65.2.2  martin 	uint32_t		 sc_rss_table_entry_width;
    643  1.65.2.2  martin 	bool			 sc_txrx_workqueue;
    644  1.65.2.2  martin 	u_int			 sc_tx_process_limit;
    645  1.65.2.2  martin 	u_int			 sc_rx_process_limit;
    646  1.65.2.2  martin 	u_int			 sc_tx_intr_process_limit;
    647  1.65.2.2  martin 	u_int			 sc_rx_intr_process_limit;
    648  1.65.2.2  martin 
    649  1.65.2.2  martin 	int			 sc_cur_ec_capenable;
    650  1.65.2.2  martin 
    651  1.65.2.2  martin 	struct pci_attach_args	 sc_pa;
    652  1.65.2.2  martin 	pci_intr_handle_t	*sc_ihp;
    653  1.65.2.2  martin 	void			**sc_ihs;
    654  1.65.2.2  martin 	unsigned int		 sc_nintrs;
    655  1.65.2.2  martin 
    656  1.65.2.2  martin 	bus_dma_tag_t		 sc_dmat;
    657  1.65.2.2  martin 	bus_space_tag_t		 sc_memt;
    658  1.65.2.2  martin 	bus_space_handle_t	 sc_memh;
    659  1.65.2.2  martin 	bus_size_t		 sc_mems;
    660  1.65.2.2  martin 
    661  1.65.2.2  martin 	uint8_t			 sc_pf_id;
    662  1.65.2.2  martin 	uint16_t		 sc_uplink_seid;	/* le */
    663  1.65.2.2  martin 	uint16_t		 sc_downlink_seid;	/* le */
    664  1.65.2.2  martin 	uint16_t		 sc_vsi_number;
    665  1.65.2.2  martin 	uint16_t		 sc_vsi_stat_counter_idx;
    666  1.65.2.2  martin 	uint16_t		 sc_seid;
    667  1.65.2.2  martin 	unsigned int		 sc_base_queue;
    668  1.65.2.2  martin 
    669  1.65.2.2  martin 	pci_intr_type_t		 sc_intrtype;
    670  1.65.2.2  martin 	unsigned int		 sc_msix_vector_queue;
    671  1.65.2.2  martin 
    672  1.65.2.2  martin 	struct ixl_dmamem	 sc_scratch;
    673  1.65.2.2  martin 	struct ixl_dmamem	 sc_aqbuf;
    674  1.65.2.2  martin 
    675  1.65.2.2  martin 	const struct ixl_aq_regs *
    676  1.65.2.2  martin 				 sc_aq_regs;
    677  1.65.2.2  martin 	uint32_t		 sc_aq_flags;
    678  1.65.2.2  martin #define IXL_SC_AQ_FLAG_RXCTL	__BIT(0)
    679  1.65.2.2  martin #define IXL_SC_AQ_FLAG_NVMLOCK	__BIT(1)
    680  1.65.2.2  martin #define IXL_SC_AQ_FLAG_NVMREAD	__BIT(2)
    681  1.65.2.2  martin #define IXL_SC_AQ_FLAG_RSS	__BIT(3)
    682  1.65.2.2  martin 
    683  1.65.2.2  martin 	kmutex_t		 sc_atq_lock;
    684  1.65.2.2  martin 	kcondvar_t		 sc_atq_cv;
    685  1.65.2.2  martin 	struct ixl_dmamem	 sc_atq;
    686  1.65.2.2  martin 	unsigned int		 sc_atq_prod;
    687  1.65.2.2  martin 	unsigned int		 sc_atq_cons;
    688  1.65.2.2  martin 
    689  1.65.2.2  martin 	struct ixl_dmamem	 sc_arq;
    690  1.65.2.2  martin 	struct ixl_work		 sc_arq_task;
    691  1.65.2.2  martin 	struct ixl_aq_bufs	 sc_arq_idle;
    692  1.65.2.2  martin 	struct ixl_aq_buf	*sc_arq_live[IXL_AQ_NUM];
    693  1.65.2.2  martin 	unsigned int		 sc_arq_prod;
    694  1.65.2.2  martin 	unsigned int		 sc_arq_cons;
    695  1.65.2.2  martin 
    696  1.65.2.2  martin 	struct ixl_work		 sc_link_state_task;
    697  1.65.2.2  martin 	struct ixl_atq		 sc_link_state_atq;
    698  1.65.2.2  martin 
    699  1.65.2.2  martin 	struct ixl_dmamem	 sc_hmc_sd;
    700  1.65.2.2  martin 	struct ixl_dmamem	 sc_hmc_pd;
    701  1.65.2.2  martin 	struct ixl_hmc_entry	 sc_hmc_entries[IXL_HMC_COUNT];
    702  1.65.2.2  martin 
    703  1.65.2.2  martin 	unsigned int		 sc_tx_ring_ndescs;
    704  1.65.2.2  martin 	unsigned int		 sc_rx_ring_ndescs;
    705  1.65.2.2  martin 	unsigned int		 sc_nqueue_pairs;
    706  1.65.2.2  martin 	unsigned int		 sc_nqueue_pairs_max;
    707  1.65.2.2  martin 	unsigned int		 sc_nqueue_pairs_device;
    708  1.65.2.2  martin 	struct ixl_queue_pair	*sc_qps;
    709  1.65.2.2  martin 	uint32_t		 sc_itr_rx;
    710  1.65.2.2  martin 	uint32_t		 sc_itr_tx;
    711  1.65.2.2  martin 
    712  1.65.2.2  martin 	struct evcnt		 sc_event_atq;
    713  1.65.2.2  martin 	struct evcnt		 sc_event_link;
    714  1.65.2.2  martin 	struct evcnt		 sc_event_ecc_err;
    715  1.65.2.2  martin 	struct evcnt		 sc_event_pci_exception;
    716  1.65.2.2  martin 	struct evcnt		 sc_event_crit_err;
    717  1.65.2.2  martin };
    718  1.65.2.2  martin 
    719  1.65.2.2  martin #define IXL_TXRX_PROCESS_UNLIMIT	UINT_MAX
    720  1.65.2.2  martin #define IXL_TX_PROCESS_LIMIT		256
    721  1.65.2.2  martin #define IXL_RX_PROCESS_LIMIT		256
    722  1.65.2.2  martin #define IXL_TX_INTR_PROCESS_LIMIT	256
    723  1.65.2.2  martin #define IXL_RX_INTR_PROCESS_LIMIT	0U
    724  1.65.2.2  martin 
    725  1.65.2.2  martin #define IXL_IFCAP_RXCSUM	(IFCAP_CSUM_IPv4_Rx |	\
    726  1.65.2.2  martin 				 IFCAP_CSUM_TCPv4_Rx |	\
    727  1.65.2.2  martin 				 IFCAP_CSUM_UDPv4_Rx |	\
    728  1.65.2.2  martin 				 IFCAP_CSUM_TCPv6_Rx |	\
    729  1.65.2.2  martin 				 IFCAP_CSUM_UDPv6_Rx)
    730  1.65.2.2  martin #define IXL_IFCAP_TXCSUM	(IFCAP_CSUM_IPv4_Tx |	\
    731  1.65.2.2  martin 				 IFCAP_CSUM_TCPv4_Tx |	\
    732  1.65.2.2  martin 				 IFCAP_CSUM_UDPv4_Tx |	\
    733  1.65.2.2  martin 				 IFCAP_CSUM_TCPv6_Tx |	\
    734  1.65.2.2  martin 				 IFCAP_CSUM_UDPv6_Tx)
    735  1.65.2.2  martin #define IXL_CSUM_ALL_OFFLOAD	(M_CSUM_IPv4 |			\
    736  1.65.2.2  martin 				 M_CSUM_TCPv4 | M_CSUM_TCPv6 |	\
    737  1.65.2.2  martin 				 M_CSUM_UDPv4 | M_CSUM_UDPv6)
    738  1.65.2.2  martin 
    739  1.65.2.2  martin #define delaymsec(_x)	DELAY(1000 * (_x))
    740  1.65.2.2  martin #ifdef IXL_DEBUG
    741  1.65.2.2  martin #define DDPRINTF(sc, fmt, args...)			\
    742  1.65.2.2  martin do {							\
    743  1.65.2.2  martin 	if ((sc) != NULL) {				\
    744  1.65.2.2  martin 		device_printf(				\
    745  1.65.2.2  martin 		    ((struct ixl_softc *)(sc))->sc_dev,	\
    746  1.65.2.2  martin 		    "");				\
    747  1.65.2.2  martin 	}						\
    748  1.65.2.2  martin 	printf("%s:\t" fmt, __func__, ##args);		\
    749  1.65.2.2  martin } while (0)
    750  1.65.2.2  martin #else
    751  1.65.2.2  martin #define DDPRINTF(sc, fmt, args...)	__nothing
    752  1.65.2.2  martin #endif
    753  1.65.2.2  martin #ifndef IXL_STATS_INTERVAL_MSEC
    754  1.65.2.2  martin #define IXL_STATS_INTERVAL_MSEC	10000
    755  1.65.2.2  martin #endif
    756  1.65.2.2  martin #ifndef IXL_QUEUE_NUM
    757  1.65.2.2  martin #define IXL_QUEUE_NUM		0
    758  1.65.2.2  martin #endif
    759  1.65.2.2  martin 
    760  1.65.2.2  martin static bool		 ixl_param_nomsix = false;
    761  1.65.2.2  martin static int		 ixl_param_stats_interval = IXL_STATS_INTERVAL_MSEC;
    762  1.65.2.2  martin static int		 ixl_param_nqps_limit = IXL_QUEUE_NUM;
    763  1.65.2.2  martin static unsigned int	 ixl_param_tx_ndescs = 1024;
    764  1.65.2.2  martin static unsigned int	 ixl_param_rx_ndescs = 1024;
    765  1.65.2.2  martin 
    766  1.65.2.2  martin static enum i40e_mac_type
    767  1.65.2.2  martin     ixl_mactype(pci_product_id_t);
    768  1.65.2.2  martin static void	ixl_clear_hw(struct ixl_softc *);
    769  1.65.2.2  martin static int	ixl_pf_reset(struct ixl_softc *);
    770  1.65.2.2  martin 
    771  1.65.2.2  martin static int	ixl_dmamem_alloc(struct ixl_softc *, struct ixl_dmamem *,
    772  1.65.2.2  martin 		    bus_size_t, bus_size_t);
    773  1.65.2.2  martin static void	ixl_dmamem_free(struct ixl_softc *, struct ixl_dmamem *);
    774  1.65.2.2  martin 
    775  1.65.2.2  martin static int	ixl_arq_fill(struct ixl_softc *);
    776  1.65.2.2  martin static void	ixl_arq_unfill(struct ixl_softc *);
    777  1.65.2.2  martin 
    778  1.65.2.2  martin static int	ixl_atq_poll(struct ixl_softc *, struct ixl_aq_desc *,
    779  1.65.2.2  martin 		    unsigned int);
    780  1.65.2.2  martin static void	ixl_atq_set(struct ixl_atq *,
    781  1.65.2.2  martin 		    void (*)(struct ixl_softc *, const struct ixl_aq_desc *));
    782  1.65.2.2  martin static int	ixl_atq_post_locked(struct ixl_softc *, struct ixl_atq *);
    783  1.65.2.2  martin static void	ixl_atq_done(struct ixl_softc *);
    784  1.65.2.2  martin static int	ixl_atq_exec(struct ixl_softc *, struct ixl_atq *);
    785  1.65.2.2  martin static int	ixl_atq_exec_locked(struct ixl_softc *, struct ixl_atq *);
    786  1.65.2.2  martin static int	ixl_get_version(struct ixl_softc *);
    787  1.65.2.2  martin static int	ixl_get_nvm_version(struct ixl_softc *);
    788  1.65.2.2  martin static int	ixl_get_hw_capabilities(struct ixl_softc *);
    789  1.65.2.2  martin static int	ixl_pxe_clear(struct ixl_softc *);
    790  1.65.2.2  martin static int	ixl_lldp_shut(struct ixl_softc *);
    791  1.65.2.2  martin static int	ixl_get_mac(struct ixl_softc *);
    792  1.65.2.2  martin static int	ixl_get_switch_config(struct ixl_softc *);
    793  1.65.2.2  martin static int	ixl_phy_mask_ints(struct ixl_softc *);
    794  1.65.2.2  martin static int	ixl_get_phy_info(struct ixl_softc *);
    795  1.65.2.2  martin static int	ixl_set_phy_config(struct ixl_softc *, uint8_t, uint8_t, bool);
    796  1.65.2.2  martin static int	ixl_set_phy_autoselect(struct ixl_softc *);
    797  1.65.2.2  martin static int	ixl_restart_an(struct ixl_softc *);
    798  1.65.2.2  martin static int	ixl_hmc(struct ixl_softc *);
    799  1.65.2.2  martin static void	ixl_hmc_free(struct ixl_softc *);
    800  1.65.2.2  martin static int	ixl_get_vsi(struct ixl_softc *);
    801  1.65.2.2  martin static int	ixl_set_vsi(struct ixl_softc *);
    802  1.65.2.2  martin static void	ixl_set_filter_control(struct ixl_softc *);
    803  1.65.2.2  martin static void	ixl_get_link_status(void *);
    804  1.65.2.2  martin static int	ixl_get_link_status_poll(struct ixl_softc *, int *);
    805  1.65.2.2  martin static void	ixl_get_link_status_done(struct ixl_softc *,
    806  1.65.2.2  martin 		    const struct ixl_aq_desc *);
    807  1.65.2.2  martin static int	ixl_set_link_status_locked(struct ixl_softc *,
    808  1.65.2.2  martin 		    const struct ixl_aq_desc *);
    809  1.65.2.2  martin static uint64_t	ixl_search_link_speed(uint8_t);
    810  1.65.2.2  martin static uint8_t	ixl_search_baudrate(uint64_t);
    811  1.65.2.2  martin static void	ixl_config_rss(struct ixl_softc *);
    812  1.65.2.2  martin static int	ixl_add_macvlan(struct ixl_softc *, const uint8_t *,
    813  1.65.2.2  martin 		    uint16_t, uint16_t);
    814  1.65.2.2  martin static int	ixl_remove_macvlan(struct ixl_softc *, const uint8_t *,
    815  1.65.2.2  martin 		    uint16_t, uint16_t);
    816  1.65.2.2  martin static void	ixl_arq(void *);
    817  1.65.2.2  martin static void	ixl_hmc_pack(void *, const void *,
    818  1.65.2.2  martin 		    const struct ixl_hmc_pack *, unsigned int);
    819  1.65.2.2  martin static uint32_t	ixl_rd_rx_csr(struct ixl_softc *, uint32_t);
    820  1.65.2.2  martin static void	ixl_wr_rx_csr(struct ixl_softc *, uint32_t, uint32_t);
    821  1.65.2.2  martin static int	ixl_rd16_nvm(struct ixl_softc *, uint16_t, uint16_t *);
    822  1.65.2.2  martin 
    823  1.65.2.2  martin static int	ixl_match(device_t, cfdata_t, void *);
    824  1.65.2.2  martin static void	ixl_attach(device_t, device_t, void *);
    825  1.65.2.2  martin static int	ixl_detach(device_t, int);
    826  1.65.2.2  martin 
    827  1.65.2.2  martin static void	ixl_media_add(struct ixl_softc *);
    828  1.65.2.2  martin static int	ixl_media_change(struct ifnet *);
    829  1.65.2.2  martin static void	ixl_media_status(struct ifnet *, struct ifmediareq *);
    830  1.65.2.2  martin static void	ixl_watchdog(struct ifnet *);
    831  1.65.2.2  martin static int	ixl_ioctl(struct ifnet *, u_long, void *);
    832  1.65.2.2  martin static void	ixl_start(struct ifnet *);
    833  1.65.2.2  martin static int	ixl_transmit(struct ifnet *, struct mbuf *);
    834  1.65.2.2  martin static void	ixl_deferred_transmit(void *);
    835  1.65.2.2  martin static int	ixl_intr(void *);
    836  1.65.2.2  martin static int	ixl_queue_intr(void *);
    837  1.65.2.2  martin static int	ixl_other_intr(void *);
    838  1.65.2.2  martin static void	ixl_handle_queue(void *);
    839  1.65.2.2  martin static void	ixl_handle_queue_wk(struct work *, void *);
    840  1.65.2.2  martin static void	ixl_sched_handle_queue(struct ixl_softc *,
    841  1.65.2.2  martin 		    struct ixl_queue_pair *);
    842  1.65.2.2  martin static int	ixl_init(struct ifnet *);
    843  1.65.2.2  martin static int	ixl_init_locked(struct ixl_softc *);
    844  1.65.2.2  martin static void	ixl_stop(struct ifnet *, int);
    845  1.65.2.2  martin static void	ixl_stop_locked(struct ixl_softc *);
    846  1.65.2.2  martin static int	ixl_iff(struct ixl_softc *);
    847  1.65.2.2  martin static int	ixl_ifflags_cb(struct ethercom *);
    848  1.65.2.2  martin static int	ixl_setup_interrupts(struct ixl_softc *);
    849  1.65.2.2  martin static int	ixl_establish_intx(struct ixl_softc *);
    850  1.65.2.2  martin static int	ixl_establish_msix(struct ixl_softc *);
    851  1.65.2.2  martin static void	ixl_enable_queue_intr(struct ixl_softc *,
    852  1.65.2.2  martin 		    struct ixl_queue_pair *);
    853  1.65.2.2  martin static void	ixl_disable_queue_intr(struct ixl_softc *,
    854  1.65.2.2  martin 		    struct ixl_queue_pair *);
    855  1.65.2.2  martin static void	ixl_enable_other_intr(struct ixl_softc *);
    856  1.65.2.2  martin static void	ixl_disable_other_intr(struct ixl_softc *);
    857  1.65.2.2  martin static void	ixl_config_queue_intr(struct ixl_softc *);
    858  1.65.2.2  martin static void	ixl_config_other_intr(struct ixl_softc *);
    859  1.65.2.2  martin 
    860  1.65.2.2  martin static struct ixl_tx_ring *
    861  1.65.2.2  martin 		ixl_txr_alloc(struct ixl_softc *, unsigned int);
    862  1.65.2.2  martin static void	ixl_txr_qdis(struct ixl_softc *, struct ixl_tx_ring *, int);
    863  1.65.2.2  martin static void	ixl_txr_config(struct ixl_softc *, struct ixl_tx_ring *);
    864  1.65.2.2  martin static int	ixl_txr_enabled(struct ixl_softc *, struct ixl_tx_ring *);
    865  1.65.2.2  martin static int	ixl_txr_disabled(struct ixl_softc *, struct ixl_tx_ring *);
    866  1.65.2.2  martin static void	ixl_txr_unconfig(struct ixl_softc *, struct ixl_tx_ring *);
    867  1.65.2.2  martin static void	ixl_txr_clean(struct ixl_softc *, struct ixl_tx_ring *);
    868  1.65.2.2  martin static void	ixl_txr_free(struct ixl_softc *, struct ixl_tx_ring *);
    869  1.65.2.2  martin static int	ixl_txeof(struct ixl_softc *, struct ixl_tx_ring *, u_int);
    870  1.65.2.2  martin 
    871  1.65.2.2  martin static struct ixl_rx_ring *
    872  1.65.2.2  martin 		ixl_rxr_alloc(struct ixl_softc *, unsigned int);
    873  1.65.2.2  martin static void	ixl_rxr_config(struct ixl_softc *, struct ixl_rx_ring *);
    874  1.65.2.2  martin static int	ixl_rxr_enabled(struct ixl_softc *, struct ixl_rx_ring *);
    875  1.65.2.2  martin static int	ixl_rxr_disabled(struct ixl_softc *, struct ixl_rx_ring *);
    876  1.65.2.2  martin static void	ixl_rxr_unconfig(struct ixl_softc *, struct ixl_rx_ring *);
    877  1.65.2.2  martin static void	ixl_rxr_clean(struct ixl_softc *, struct ixl_rx_ring *);
    878  1.65.2.2  martin static void	ixl_rxr_free(struct ixl_softc *, struct ixl_rx_ring *);
    879  1.65.2.2  martin static int	ixl_rxeof(struct ixl_softc *, struct ixl_rx_ring *, u_int);
    880  1.65.2.2  martin static int	ixl_rxfill(struct ixl_softc *, struct ixl_rx_ring *);
    881  1.65.2.2  martin 
    882  1.65.2.2  martin static struct workqueue *
    883  1.65.2.2  martin     ixl_workq_create(const char *, pri_t, int, int);
    884  1.65.2.2  martin static void	ixl_workq_destroy(struct workqueue *);
    885  1.65.2.2  martin static int	ixl_workqs_teardown(device_t);
    886  1.65.2.2  martin static void	ixl_work_set(struct ixl_work *, void (*)(void *), void *);
    887  1.65.2.2  martin static void	ixl_work_add(struct workqueue *, struct ixl_work *);
    888  1.65.2.2  martin static void	ixl_work_wait(struct workqueue *, struct ixl_work *);
    889  1.65.2.2  martin static void	ixl_workq_work(struct work *, void *);
    890  1.65.2.2  martin static const struct ixl_product *
    891  1.65.2.2  martin 		ixl_lookup(const struct pci_attach_args *pa);
    892  1.65.2.2  martin static void	ixl_link_state_update(struct ixl_softc *,
    893  1.65.2.2  martin 		    const struct ixl_aq_desc *);
    894  1.65.2.2  martin static int	ixl_vlan_cb(struct ethercom *, uint16_t, bool);
    895  1.65.2.2  martin static int	ixl_setup_vlan_hwfilter(struct ixl_softc *);
    896  1.65.2.2  martin static void	ixl_teardown_vlan_hwfilter(struct ixl_softc *);
    897  1.65.2.2  martin static int	ixl_update_macvlan(struct ixl_softc *);
    898  1.65.2.2  martin static int	ixl_setup_interrupts(struct ixl_softc *);;
    899  1.65.2.2  martin static void	ixl_teardown_interrupts(struct ixl_softc *);
    900  1.65.2.2  martin static int	ixl_setup_stats(struct ixl_softc *);
    901  1.65.2.2  martin static void	ixl_teardown_stats(struct ixl_softc *);
    902  1.65.2.2  martin static void	ixl_stats_callout(void *);
    903  1.65.2.2  martin static void	ixl_stats_update(void *);
    904  1.65.2.2  martin static int	ixl_setup_sysctls(struct ixl_softc *);
    905  1.65.2.2  martin static void	ixl_teardown_sysctls(struct ixl_softc *);
    906  1.65.2.2  martin static int	ixl_queue_pairs_alloc(struct ixl_softc *);
    907  1.65.2.2  martin static void	ixl_queue_pairs_free(struct ixl_softc *);
    908  1.65.2.2  martin 
    909  1.65.2.2  martin static const struct ixl_phy_type ixl_phy_type_map[] = {
    910  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_SGMII,		IFM_1000_SGMII },
    911  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_1000BASE_KX,	IFM_1000_KX },
    912  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_KX4,	IFM_10G_KX4 },
    913  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_KR,	IFM_10G_KR },
    914  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_40GBASE_KR4,	IFM_40G_KR4 },
    915  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_XAUI |
    916  1.65.2.2  martin 	  1ULL << IXL_PHY_TYPE_XFI,		IFM_10G_CX4 },
    917  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_SFI,		IFM_10G_SFI },
    918  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_XLAUI |
    919  1.65.2.2  martin 	  1ULL << IXL_PHY_TYPE_XLPPI,		IFM_40G_XLPPI },
    920  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_40GBASE_CR4_CU |
    921  1.65.2.2  martin 	  1ULL << IXL_PHY_TYPE_40GBASE_CR4,	IFM_40G_CR4 },
    922  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_CR1_CU |
    923  1.65.2.2  martin 	  1ULL << IXL_PHY_TYPE_10GBASE_CR1,	IFM_10G_CR1 },
    924  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_AOC,	IFM_10G_AOC },
    925  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_40GBASE_AOC,	IFM_40G_AOC },
    926  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_100BASE_TX,	IFM_100_TX },
    927  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_1000BASE_T_OPTICAL |
    928  1.65.2.2  martin 	  1ULL << IXL_PHY_TYPE_1000BASE_T,	IFM_1000_T },
    929  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_T,	IFM_10G_T },
    930  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_SR,	IFM_10G_SR },
    931  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_LR,	IFM_10G_LR },
    932  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_10GBASE_SFPP_CU,	IFM_10G_TWINAX },
    933  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_40GBASE_SR4,	IFM_40G_SR4 },
    934  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_40GBASE_LR4,	IFM_40G_LR4 },
    935  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_1000BASE_SX,	IFM_1000_SX },
    936  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_1000BASE_LX,	IFM_1000_LX },
    937  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_20GBASE_KR2,	IFM_20G_KR2 },
    938  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_25GBASE_KR,	IFM_25G_KR },
    939  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_25GBASE_CR,	IFM_25G_CR },
    940  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_25GBASE_SR,	IFM_25G_SR },
    941  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_25GBASE_LR,	IFM_25G_LR },
    942  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_25GBASE_AOC,	IFM_25G_AOC },
    943  1.65.2.2  martin 	{ 1ULL << IXL_PHY_TYPE_25GBASE_ACC,	IFM_25G_ACC },
    944  1.65.2.2  martin };
    945  1.65.2.2  martin 
    946  1.65.2.2  martin static const struct ixl_speed_type ixl_speed_type_map[] = {
    947  1.65.2.2  martin 	{ IXL_AQ_LINK_SPEED_40GB,		IF_Gbps(40) },
    948  1.65.2.2  martin 	{ IXL_AQ_LINK_SPEED_25GB,		IF_Gbps(25) },
    949  1.65.2.2  martin 	{ IXL_AQ_LINK_SPEED_10GB,		IF_Gbps(10) },
    950  1.65.2.2  martin 	{ IXL_AQ_LINK_SPEED_1000MB,		IF_Mbps(1000) },
    951  1.65.2.2  martin 	{ IXL_AQ_LINK_SPEED_100MB,		IF_Mbps(100)},
    952  1.65.2.2  martin };
    953  1.65.2.2  martin 
    954  1.65.2.2  martin static const struct ixl_aq_regs ixl_pf_aq_regs = {
    955  1.65.2.2  martin 	.atq_tail	= I40E_PF_ATQT,
    956  1.65.2.2  martin 	.atq_tail_mask	= I40E_PF_ATQT_ATQT_MASK,
    957  1.65.2.2  martin 	.atq_head	= I40E_PF_ATQH,
    958  1.65.2.2  martin 	.atq_head_mask	= I40E_PF_ATQH_ATQH_MASK,
    959  1.65.2.2  martin 	.atq_len	= I40E_PF_ATQLEN,
    960  1.65.2.2  martin 	.atq_bal	= I40E_PF_ATQBAL,
    961  1.65.2.2  martin 	.atq_bah	= I40E_PF_ATQBAH,
    962  1.65.2.2  martin 	.atq_len_enable	= I40E_PF_ATQLEN_ATQENABLE_MASK,
    963  1.65.2.2  martin 
    964  1.65.2.2  martin 	.arq_tail	= I40E_PF_ARQT,
    965  1.65.2.2  martin 	.arq_tail_mask	= I40E_PF_ARQT_ARQT_MASK,
    966  1.65.2.2  martin 	.arq_head	= I40E_PF_ARQH,
    967  1.65.2.2  martin 	.arq_head_mask	= I40E_PF_ARQH_ARQH_MASK,
    968  1.65.2.2  martin 	.arq_len	= I40E_PF_ARQLEN,
    969  1.65.2.2  martin 	.arq_bal	= I40E_PF_ARQBAL,
    970  1.65.2.2  martin 	.arq_bah	= I40E_PF_ARQBAH,
    971  1.65.2.2  martin 	.arq_len_enable	= I40E_PF_ARQLEN_ARQENABLE_MASK,
    972  1.65.2.2  martin };
    973  1.65.2.2  martin 
    974  1.65.2.2  martin #define ixl_rd(_s, _r)			\
    975  1.65.2.2  martin 	bus_space_read_4((_s)->sc_memt, (_s)->sc_memh, (_r))
    976  1.65.2.2  martin #define ixl_wr(_s, _r, _v)		\
    977  1.65.2.2  martin 	bus_space_write_4((_s)->sc_memt, (_s)->sc_memh, (_r), (_v))
    978  1.65.2.2  martin #define ixl_barrier(_s, _r, _l, _o) \
    979  1.65.2.2  martin     bus_space_barrier((_s)->sc_memt, (_s)->sc_memh, (_r), (_l), (_o))
    980  1.65.2.2  martin #define ixl_flush(_s)	(void)ixl_rd((_s), I40E_GLGEN_STAT)
    981  1.65.2.2  martin #define ixl_nqueues(_sc)	(1 << ((_sc)->sc_nqueue_pairs - 1))
    982  1.65.2.2  martin 
    983  1.65.2.2  martin static inline uint32_t
    984  1.65.2.2  martin ixl_dmamem_hi(struct ixl_dmamem *ixm)
    985  1.65.2.2  martin {
    986  1.65.2.2  martin 	uint32_t retval;
    987  1.65.2.2  martin 	uint64_t val;
    988  1.65.2.2  martin 
    989  1.65.2.2  martin 	if (sizeof(IXL_DMA_DVA(ixm)) > 4) {
    990  1.65.2.2  martin 		val = (intptr_t)IXL_DMA_DVA(ixm);
    991  1.65.2.2  martin 		retval = (uint32_t)(val >> 32);
    992  1.65.2.2  martin 	} else {
    993  1.65.2.2  martin 		retval = 0;
    994  1.65.2.2  martin 	}
    995  1.65.2.2  martin 
    996  1.65.2.2  martin 	return retval;
    997  1.65.2.2  martin }
    998  1.65.2.2  martin 
    999  1.65.2.2  martin static inline uint32_t
   1000  1.65.2.2  martin ixl_dmamem_lo(struct ixl_dmamem *ixm)
   1001  1.65.2.2  martin {
   1002  1.65.2.2  martin 
   1003  1.65.2.2  martin 	return (uint32_t)IXL_DMA_DVA(ixm);
   1004  1.65.2.2  martin }
   1005  1.65.2.2  martin 
   1006  1.65.2.2  martin static inline void
   1007  1.65.2.2  martin ixl_aq_dva(struct ixl_aq_desc *iaq, bus_addr_t addr)
   1008  1.65.2.2  martin {
   1009  1.65.2.2  martin 	uint64_t val;
   1010  1.65.2.2  martin 
   1011  1.65.2.2  martin 	if (sizeof(addr) > 4) {
   1012  1.65.2.2  martin 		val = (intptr_t)addr;
   1013  1.65.2.2  martin 		iaq->iaq_param[2] = htole32(val >> 32);
   1014  1.65.2.2  martin 	} else {
   1015  1.65.2.2  martin 		iaq->iaq_param[2] = htole32(0);
   1016  1.65.2.2  martin 	}
   1017  1.65.2.2  martin 
   1018  1.65.2.2  martin 	iaq->iaq_param[3] = htole32(addr);
   1019  1.65.2.2  martin }
   1020  1.65.2.2  martin 
   1021  1.65.2.2  martin static inline unsigned int
   1022  1.65.2.2  martin ixl_rxr_unrefreshed(unsigned int prod, unsigned int cons, unsigned int ndescs)
   1023  1.65.2.2  martin {
   1024  1.65.2.2  martin 	unsigned int num;
   1025  1.65.2.2  martin 
   1026  1.65.2.2  martin 	if (prod  < cons)
   1027  1.65.2.2  martin 		num = cons - prod;
   1028  1.65.2.2  martin 	else
   1029  1.65.2.2  martin 		num  = (ndescs - prod) + cons;
   1030  1.65.2.2  martin 
   1031  1.65.2.2  martin 	if (__predict_true(num > 0)) {
   1032  1.65.2.2  martin 		/* device cannot receive packets if all descripter is filled */
   1033  1.65.2.2  martin 		num -= 1;
   1034  1.65.2.2  martin 	}
   1035  1.65.2.2  martin 
   1036  1.65.2.2  martin 	return num;
   1037  1.65.2.2  martin }
   1038  1.65.2.2  martin 
   1039  1.65.2.2  martin CFATTACH_DECL3_NEW(ixl, sizeof(struct ixl_softc),
   1040  1.65.2.2  martin     ixl_match, ixl_attach, ixl_detach, NULL, NULL, NULL,
   1041  1.65.2.2  martin     DVF_DETACH_SHUTDOWN);
   1042  1.65.2.2  martin 
   1043  1.65.2.2  martin static const struct ixl_product ixl_products[] = {
   1044  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_SFP },
   1045  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_KX_B },
   1046  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_KX_C },
   1047  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_QSFP_A },
   1048  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_QSFP_B },
   1049  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_QSFP_C },
   1050  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X710_10G_T },
   1051  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_20G_BP_1 },
   1052  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XL710_20G_BP_2 },
   1053  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X710_T4_10G },
   1054  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XXV710_25G_BP },
   1055  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_XXV710_25G_SFP28 },
   1056  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X722_KX },
   1057  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X722_QSFP },
   1058  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X722_SFP },
   1059  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X722_1G_BASET },
   1060  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X722_10G_BASET },
   1061  1.65.2.2  martin 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_X722_I_SFP },
   1062  1.65.2.2  martin 	/* required last entry */
   1063  1.65.2.2  martin 	{0, 0}
   1064  1.65.2.2  martin };
   1065  1.65.2.2  martin 
   1066  1.65.2.2  martin static const struct ixl_product *
   1067  1.65.2.2  martin ixl_lookup(const struct pci_attach_args *pa)
   1068  1.65.2.2  martin {
   1069  1.65.2.2  martin 	const struct ixl_product *ixlp;
   1070  1.65.2.2  martin 
   1071  1.65.2.2  martin 	for (ixlp = ixl_products; ixlp->vendor_id != 0; ixlp++) {
   1072  1.65.2.2  martin 		if (PCI_VENDOR(pa->pa_id) == ixlp->vendor_id &&
   1073  1.65.2.2  martin 		    PCI_PRODUCT(pa->pa_id) == ixlp->product_id)
   1074  1.65.2.2  martin 			return ixlp;
   1075  1.65.2.2  martin 	}
   1076  1.65.2.2  martin 
   1077  1.65.2.2  martin 	return NULL;
   1078  1.65.2.2  martin }
   1079  1.65.2.2  martin 
   1080  1.65.2.2  martin static int
   1081  1.65.2.2  martin ixl_match(device_t parent, cfdata_t match, void *aux)
   1082  1.65.2.2  martin {
   1083  1.65.2.2  martin 	const struct pci_attach_args *pa = aux;
   1084  1.65.2.2  martin 
   1085  1.65.2.2  martin 	return (ixl_lookup(pa) != NULL) ? 1 : 0;
   1086  1.65.2.2  martin }
   1087  1.65.2.2  martin 
   1088  1.65.2.2  martin static void
   1089  1.65.2.2  martin ixl_attach(device_t parent, device_t self, void *aux)
   1090  1.65.2.2  martin {
   1091  1.65.2.2  martin 	struct ixl_softc *sc;
   1092  1.65.2.2  martin 	struct pci_attach_args *pa = aux;
   1093  1.65.2.2  martin 	struct ifnet *ifp;
   1094  1.65.2.2  martin 	pcireg_t memtype;
   1095  1.65.2.2  martin 	uint32_t firstq, port, ari, func;
   1096  1.65.2.2  martin 	char xnamebuf[32];
   1097  1.65.2.2  martin 	int tries, rv, link;
   1098  1.65.2.2  martin 
   1099  1.65.2.2  martin 	sc = device_private(self);
   1100  1.65.2.2  martin 	sc->sc_dev = self;
   1101  1.65.2.2  martin 	ifp = &sc->sc_ec.ec_if;
   1102  1.65.2.2  martin 
   1103  1.65.2.2  martin 	sc->sc_pa = *pa;
   1104  1.65.2.2  martin 	sc->sc_dmat = (pci_dma64_available(pa)) ?
   1105  1.65.2.2  martin 	    pa->pa_dmat64 : pa->pa_dmat;
   1106  1.65.2.2  martin 	sc->sc_aq_regs = &ixl_pf_aq_regs;
   1107  1.65.2.2  martin 
   1108  1.65.2.2  martin 	sc->sc_mac_type = ixl_mactype(PCI_PRODUCT(pa->pa_id));
   1109  1.65.2.2  martin 
   1110  1.65.2.2  martin 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, IXL_PCIREG);
   1111  1.65.2.2  martin 	if (pci_mapreg_map(pa, IXL_PCIREG, memtype, 0,
   1112  1.65.2.2  martin 	    &sc->sc_memt, &sc->sc_memh, NULL, &sc->sc_mems)) {
   1113  1.65.2.2  martin 		aprint_error(": unable to map registers\n");
   1114  1.65.2.2  martin 		return;
   1115  1.65.2.2  martin 	}
   1116  1.65.2.2  martin 
   1117  1.65.2.2  martin 	mutex_init(&sc->sc_cfg_lock, MUTEX_DEFAULT, IPL_SOFTNET);
   1118  1.65.2.2  martin 
   1119  1.65.2.2  martin 	firstq = ixl_rd(sc, I40E_PFLAN_QALLOC);
   1120  1.65.2.2  martin 	firstq &= I40E_PFLAN_QALLOC_FIRSTQ_MASK;
   1121  1.65.2.2  martin 	firstq >>= I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
   1122  1.65.2.2  martin 	sc->sc_base_queue = firstq;
   1123  1.65.2.2  martin 
   1124  1.65.2.2  martin 	ixl_clear_hw(sc);
   1125  1.65.2.2  martin 	if (ixl_pf_reset(sc) == -1) {
   1126  1.65.2.2  martin 		/* error printed by ixl pf_reset */
   1127  1.65.2.2  martin 		goto unmap;
   1128  1.65.2.2  martin 	}
   1129  1.65.2.2  martin 
   1130  1.65.2.2  martin 	port = ixl_rd(sc, I40E_PFGEN_PORTNUM);
   1131  1.65.2.2  martin 	port &= I40E_PFGEN_PORTNUM_PORT_NUM_MASK;
   1132  1.65.2.2  martin 	port >>= I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
   1133  1.65.2.2  martin 	sc->sc_port = port;
   1134  1.65.2.2  martin 	aprint_normal(": port %u", sc->sc_port);
   1135  1.65.2.2  martin 
   1136  1.65.2.2  martin 	ari = ixl_rd(sc, I40E_GLPCI_CAPSUP);
   1137  1.65.2.2  martin 	ari &= I40E_GLPCI_CAPSUP_ARI_EN_MASK;
   1138  1.65.2.2  martin 	ari >>= I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
   1139  1.65.2.2  martin 
   1140  1.65.2.2  martin 	func = ixl_rd(sc, I40E_PF_FUNC_RID);
   1141  1.65.2.2  martin 	sc->sc_pf_id = func & (ari ? 0xff : 0x7);
   1142  1.65.2.2  martin 
   1143  1.65.2.2  martin 	/* initialise the adminq */
   1144  1.65.2.2  martin 
   1145  1.65.2.2  martin 	mutex_init(&sc->sc_atq_lock, MUTEX_DEFAULT, IPL_NET);
   1146  1.65.2.2  martin 
   1147  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &sc->sc_atq,
   1148  1.65.2.2  martin 	    sizeof(struct ixl_aq_desc) * IXL_AQ_NUM, IXL_AQ_ALIGN) != 0) {
   1149  1.65.2.2  martin 		aprint_error("\n" "%s: unable to allocate atq\n",
   1150  1.65.2.2  martin 		    device_xname(self));
   1151  1.65.2.2  martin 		goto unmap;
   1152  1.65.2.2  martin 	}
   1153  1.65.2.2  martin 
   1154  1.65.2.2  martin 	SIMPLEQ_INIT(&sc->sc_arq_idle);
   1155  1.65.2.2  martin 	ixl_work_set(&sc->sc_arq_task, ixl_arq, sc);
   1156  1.65.2.2  martin 	sc->sc_arq_cons = 0;
   1157  1.65.2.2  martin 	sc->sc_arq_prod = 0;
   1158  1.65.2.2  martin 
   1159  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &sc->sc_arq,
   1160  1.65.2.2  martin 	    sizeof(struct ixl_aq_desc) * IXL_AQ_NUM, IXL_AQ_ALIGN) != 0) {
   1161  1.65.2.2  martin 		aprint_error("\n" "%s: unable to allocate arq\n",
   1162  1.65.2.2  martin 		    device_xname(self));
   1163  1.65.2.2  martin 		goto free_atq;
   1164  1.65.2.2  martin 	}
   1165  1.65.2.2  martin 
   1166  1.65.2.2  martin 	if (!ixl_arq_fill(sc)) {
   1167  1.65.2.2  martin 		aprint_error("\n" "%s: unable to fill arq descriptors\n",
   1168  1.65.2.2  martin 		    device_xname(self));
   1169  1.65.2.2  martin 		goto free_arq;
   1170  1.65.2.2  martin 	}
   1171  1.65.2.2  martin 
   1172  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   1173  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq),
   1174  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1175  1.65.2.2  martin 
   1176  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_arq),
   1177  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_arq),
   1178  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1179  1.65.2.2  martin 
   1180  1.65.2.2  martin 	for (tries = 0; tries < 10; tries++) {
   1181  1.65.2.2  martin 		sc->sc_atq_cons = 0;
   1182  1.65.2.2  martin 		sc->sc_atq_prod = 0;
   1183  1.65.2.2  martin 
   1184  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->atq_head, 0);
   1185  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->arq_head, 0);
   1186  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->atq_tail, 0);
   1187  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->arq_tail, 0);
   1188  1.65.2.2  martin 
   1189  1.65.2.2  martin 		ixl_barrier(sc, 0, sc->sc_mems, BUS_SPACE_BARRIER_WRITE);
   1190  1.65.2.2  martin 
   1191  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->atq_bal,
   1192  1.65.2.2  martin 		    ixl_dmamem_lo(&sc->sc_atq));
   1193  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->atq_bah,
   1194  1.65.2.2  martin 		    ixl_dmamem_hi(&sc->sc_atq));
   1195  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->atq_len,
   1196  1.65.2.2  martin 		    sc->sc_aq_regs->atq_len_enable | IXL_AQ_NUM);
   1197  1.65.2.2  martin 
   1198  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->arq_bal,
   1199  1.65.2.2  martin 		    ixl_dmamem_lo(&sc->sc_arq));
   1200  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->arq_bah,
   1201  1.65.2.2  martin 		    ixl_dmamem_hi(&sc->sc_arq));
   1202  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->arq_len,
   1203  1.65.2.2  martin 		    sc->sc_aq_regs->arq_len_enable | IXL_AQ_NUM);
   1204  1.65.2.2  martin 
   1205  1.65.2.2  martin 		rv = ixl_get_version(sc);
   1206  1.65.2.2  martin 		if (rv == 0)
   1207  1.65.2.2  martin 			break;
   1208  1.65.2.2  martin 		if (rv != ETIMEDOUT) {
   1209  1.65.2.2  martin 			aprint_error(", unable to get firmware version\n");
   1210  1.65.2.2  martin 			goto shutdown;
   1211  1.65.2.2  martin 		}
   1212  1.65.2.2  martin 
   1213  1.65.2.2  martin 		delaymsec(100);
   1214  1.65.2.2  martin 	}
   1215  1.65.2.2  martin 
   1216  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_tail, sc->sc_arq_prod);
   1217  1.65.2.2  martin 
   1218  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &sc->sc_aqbuf, IXL_AQ_BUFLEN, 0) != 0) {
   1219  1.65.2.2  martin 		aprint_error_dev(self, ", unable to allocate nvm buffer\n");
   1220  1.65.2.2  martin 		goto shutdown;
   1221  1.65.2.2  martin 	}
   1222  1.65.2.2  martin 
   1223  1.65.2.2  martin 	ixl_get_nvm_version(sc);
   1224  1.65.2.2  martin 
   1225  1.65.2.2  martin 	if (sc->sc_mac_type == I40E_MAC_X722)
   1226  1.65.2.2  martin 		sc->sc_nqueue_pairs_device = IXL_QUEUE_MAX_X722;
   1227  1.65.2.2  martin 	else
   1228  1.65.2.2  martin 		sc->sc_nqueue_pairs_device = IXL_QUEUE_MAX_XL710;
   1229  1.65.2.2  martin 
   1230  1.65.2.2  martin 	rv = ixl_get_hw_capabilities(sc);
   1231  1.65.2.2  martin 	if (rv != 0) {
   1232  1.65.2.2  martin 		aprint_error(", GET HW CAPABILITIES %s\n",
   1233  1.65.2.2  martin 		    rv == ETIMEDOUT ? "timeout" : "error");
   1234  1.65.2.2  martin 		goto free_aqbuf;
   1235  1.65.2.2  martin 	}
   1236  1.65.2.2  martin 
   1237  1.65.2.2  martin 	sc->sc_nqueue_pairs_max = MIN((int)sc->sc_nqueue_pairs_device, ncpu);
   1238  1.65.2.2  martin 	if (ixl_param_nqps_limit > 0) {
   1239  1.65.2.2  martin 		sc->sc_nqueue_pairs_max = MIN((int)sc->sc_nqueue_pairs_max,
   1240  1.65.2.2  martin 		    ixl_param_nqps_limit);
   1241  1.65.2.2  martin 	}
   1242  1.65.2.2  martin 
   1243  1.65.2.2  martin 	sc->sc_nqueue_pairs = sc->sc_nqueue_pairs_max;
   1244  1.65.2.2  martin 	sc->sc_tx_ring_ndescs = ixl_param_tx_ndescs;
   1245  1.65.2.2  martin 	sc->sc_rx_ring_ndescs = ixl_param_rx_ndescs;
   1246  1.65.2.2  martin 
   1247  1.65.2.2  martin 	KASSERT(IXL_TXRX_PROCESS_UNLIMIT > sc->sc_rx_ring_ndescs);
   1248  1.65.2.2  martin 	KASSERT(IXL_TXRX_PROCESS_UNLIMIT > sc->sc_tx_ring_ndescs);
   1249  1.65.2.2  martin 
   1250  1.65.2.2  martin 	if (ixl_get_mac(sc) != 0) {
   1251  1.65.2.2  martin 		/* error printed by ixl_get_mac */
   1252  1.65.2.2  martin 		goto free_aqbuf;
   1253  1.65.2.2  martin 	}
   1254  1.65.2.2  martin 
   1255  1.65.2.2  martin 	aprint_normal("\n");
   1256  1.65.2.2  martin 	aprint_naive("\n");
   1257  1.65.2.2  martin 
   1258  1.65.2.2  martin 	aprint_normal_dev(self, "Ethernet address %s\n",
   1259  1.65.2.2  martin 	    ether_sprintf(sc->sc_enaddr));
   1260  1.65.2.2  martin 
   1261  1.65.2.2  martin 	rv = ixl_pxe_clear(sc);
   1262  1.65.2.2  martin 	if (rv != 0) {
   1263  1.65.2.2  martin 		aprint_debug_dev(self, "CLEAR PXE MODE %s\n",
   1264  1.65.2.2  martin 		    rv == ETIMEDOUT ? "timeout" : "error");
   1265  1.65.2.2  martin 	}
   1266  1.65.2.2  martin 
   1267  1.65.2.2  martin 	ixl_set_filter_control(sc);
   1268  1.65.2.2  martin 
   1269  1.65.2.2  martin 	if (ixl_hmc(sc) != 0) {
   1270  1.65.2.2  martin 		/* error printed by ixl_hmc */
   1271  1.65.2.2  martin 		goto free_aqbuf;
   1272  1.65.2.2  martin 	}
   1273  1.65.2.2  martin 
   1274  1.65.2.2  martin 	if (ixl_lldp_shut(sc) != 0) {
   1275  1.65.2.2  martin 		/* error printed by ixl_lldp_shut */
   1276  1.65.2.2  martin 		goto free_hmc;
   1277  1.65.2.2  martin 	}
   1278  1.65.2.2  martin 
   1279  1.65.2.2  martin 	if (ixl_phy_mask_ints(sc) != 0) {
   1280  1.65.2.2  martin 		/* error printed by ixl_phy_mask_ints */
   1281  1.65.2.2  martin 		goto free_hmc;
   1282  1.65.2.2  martin 	}
   1283  1.65.2.2  martin 
   1284  1.65.2.2  martin 	if (ixl_restart_an(sc) != 0) {
   1285  1.65.2.2  martin 		/* error printed by ixl_restart_an */
   1286  1.65.2.2  martin 		goto free_hmc;
   1287  1.65.2.2  martin 	}
   1288  1.65.2.2  martin 
   1289  1.65.2.2  martin 	if (ixl_get_switch_config(sc) != 0) {
   1290  1.65.2.2  martin 		/* error printed by ixl_get_switch_config */
   1291  1.65.2.2  martin 		goto free_hmc;
   1292  1.65.2.2  martin 	}
   1293  1.65.2.2  martin 
   1294  1.65.2.2  martin 	rv = ixl_get_link_status_poll(sc, NULL);
   1295  1.65.2.2  martin 	if (rv != 0) {
   1296  1.65.2.2  martin 		aprint_error_dev(self, "GET LINK STATUS %s\n",
   1297  1.65.2.2  martin 		    rv == ETIMEDOUT ? "timeout" : "error");
   1298  1.65.2.2  martin 		goto free_hmc;
   1299  1.65.2.2  martin 	}
   1300  1.65.2.2  martin 
   1301  1.65.2.2  martin 	/*
   1302  1.65.2.2  martin 	 * The FW often returns EIO in "Get PHY Abilities" command
   1303  1.65.2.2  martin 	 * if there is no delay
   1304  1.65.2.2  martin 	 */
   1305  1.65.2.2  martin 	DELAY(500);
   1306  1.65.2.2  martin 	if (ixl_get_phy_info(sc) != 0) {
   1307  1.65.2.2  martin 		/* error printed by ixl_get_phy_info */
   1308  1.65.2.2  martin 		goto free_hmc;
   1309  1.65.2.2  martin 	}
   1310  1.65.2.2  martin 
   1311  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &sc->sc_scratch,
   1312  1.65.2.2  martin 	    sizeof(struct ixl_aq_vsi_data), 8) != 0) {
   1313  1.65.2.2  martin 		aprint_error_dev(self, "unable to allocate scratch buffer\n");
   1314  1.65.2.2  martin 		goto free_hmc;
   1315  1.65.2.2  martin 	}
   1316  1.65.2.2  martin 
   1317  1.65.2.2  martin 	rv = ixl_get_vsi(sc);
   1318  1.65.2.2  martin 	if (rv != 0) {
   1319  1.65.2.2  martin 		aprint_error_dev(self, "GET VSI %s %d\n",
   1320  1.65.2.2  martin 		    rv == ETIMEDOUT ? "timeout" : "error", rv);
   1321  1.65.2.2  martin 		goto free_scratch;
   1322  1.65.2.2  martin 	}
   1323  1.65.2.2  martin 
   1324  1.65.2.2  martin 	rv = ixl_set_vsi(sc);
   1325  1.65.2.2  martin 	if (rv != 0) {
   1326  1.65.2.2  martin 		aprint_error_dev(self, "UPDATE VSI error %s %d\n",
   1327  1.65.2.2  martin 		    rv == ETIMEDOUT ? "timeout" : "error", rv);
   1328  1.65.2.2  martin 		goto free_scratch;
   1329  1.65.2.2  martin 	}
   1330  1.65.2.2  martin 
   1331  1.65.2.2  martin 	if (ixl_queue_pairs_alloc(sc) != 0) {
   1332  1.65.2.2  martin 		/* error printed by ixl_queue_pairs_alloc */
   1333  1.65.2.2  martin 		goto free_scratch;
   1334  1.65.2.2  martin 	}
   1335  1.65.2.2  martin 
   1336  1.65.2.2  martin 	if (ixl_setup_interrupts(sc) != 0) {
   1337  1.65.2.2  martin 		/* error printed by ixl_setup_interrupts */
   1338  1.65.2.2  martin 		goto free_queue_pairs;
   1339  1.65.2.2  martin 	}
   1340  1.65.2.2  martin 
   1341  1.65.2.2  martin 	if (ixl_setup_stats(sc) != 0) {
   1342  1.65.2.2  martin 		aprint_error_dev(self, "failed to setup event counters\n");
   1343  1.65.2.2  martin 		goto teardown_intrs;
   1344  1.65.2.2  martin 	}
   1345  1.65.2.2  martin 
   1346  1.65.2.2  martin 	if (ixl_setup_sysctls(sc) != 0) {
   1347  1.65.2.2  martin 		/* error printed by ixl_setup_sysctls */
   1348  1.65.2.2  martin 		goto teardown_stats;
   1349  1.65.2.2  martin 	}
   1350  1.65.2.2  martin 
   1351  1.65.2.2  martin 	snprintf(xnamebuf, sizeof(xnamebuf), "%s_wq_cfg", device_xname(self));
   1352  1.65.2.2  martin 	sc->sc_workq = ixl_workq_create(xnamebuf, IXL_WORKQUEUE_PRI,
   1353  1.65.2.2  martin 	    IPL_NET, WQ_MPSAFE);
   1354  1.65.2.2  martin 	if (sc->sc_workq == NULL)
   1355  1.65.2.2  martin 		goto teardown_sysctls;
   1356  1.65.2.2  martin 
   1357  1.65.2.2  martin 	snprintf(xnamebuf, sizeof(xnamebuf), "%s_wq_txrx", device_xname(self));
   1358  1.65.2.2  martin 	rv = workqueue_create(&sc->sc_workq_txrx, xnamebuf, ixl_handle_queue_wk,
   1359  1.65.2.2  martin 	    sc, IXL_WORKQUEUE_PRI, IPL_NET, WQ_PERCPU | WQ_MPSAFE);
   1360  1.65.2.2  martin 	if (rv != 0) {
   1361  1.65.2.2  martin 		sc->sc_workq_txrx = NULL;
   1362  1.65.2.2  martin 		goto teardown_wqs;
   1363  1.65.2.2  martin 	}
   1364  1.65.2.2  martin 
   1365  1.65.2.2  martin 	snprintf(xnamebuf, sizeof(xnamebuf), "%s_atq_cv", device_xname(self));
   1366  1.65.2.2  martin 	cv_init(&sc->sc_atq_cv, xnamebuf);
   1367  1.65.2.2  martin 
   1368  1.65.2.2  martin 	strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
   1369  1.65.2.2  martin 
   1370  1.65.2.2  martin 	ifp->if_softc = sc;
   1371  1.65.2.2  martin 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
   1372  1.65.2.2  martin 	ifp->if_extflags = IFEF_MPSAFE;
   1373  1.65.2.2  martin 	ifp->if_ioctl = ixl_ioctl;
   1374  1.65.2.2  martin 	ifp->if_start = ixl_start;
   1375  1.65.2.2  martin 	ifp->if_transmit = ixl_transmit;
   1376  1.65.2.2  martin 	ifp->if_watchdog = ixl_watchdog;
   1377  1.65.2.2  martin 	ifp->if_init = ixl_init;
   1378  1.65.2.2  martin 	ifp->if_stop = ixl_stop;
   1379  1.65.2.2  martin 	IFQ_SET_MAXLEN(&ifp->if_snd, sc->sc_tx_ring_ndescs);
   1380  1.65.2.2  martin 	IFQ_SET_READY(&ifp->if_snd);
   1381  1.65.2.2  martin 	ifp->if_capabilities |= IXL_IFCAP_RXCSUM;
   1382  1.65.2.2  martin 	ifp->if_capabilities |= IXL_IFCAP_TXCSUM;
   1383  1.65.2.2  martin #if 0
   1384  1.65.2.2  martin 	ifp->if_capabilities |= IFCAP_TSOv4 | IFCAP_TSOv6;
   1385  1.65.2.2  martin #endif
   1386  1.65.2.2  martin 	ether_set_vlan_cb(&sc->sc_ec, ixl_vlan_cb);
   1387  1.65.2.2  martin 	sc->sc_ec.ec_capabilities |= ETHERCAP_JUMBO_MTU;
   1388  1.65.2.2  martin 	sc->sc_ec.ec_capabilities |= ETHERCAP_VLAN_HWTAGGING;
   1389  1.65.2.2  martin 	sc->sc_ec.ec_capabilities |= ETHERCAP_VLAN_HWFILTER;
   1390  1.65.2.2  martin 
   1391  1.65.2.2  martin 	sc->sc_ec.ec_capenable = sc->sc_ec.ec_capabilities;
   1392  1.65.2.2  martin 	/* Disable VLAN_HWFILTER by default */
   1393  1.65.2.2  martin 	CLR(sc->sc_ec.ec_capenable, ETHERCAP_VLAN_HWFILTER);
   1394  1.65.2.2  martin 
   1395  1.65.2.2  martin 	sc->sc_cur_ec_capenable = sc->sc_ec.ec_capenable;
   1396  1.65.2.2  martin 
   1397  1.65.2.2  martin 	sc->sc_ec.ec_ifmedia = &sc->sc_media;
   1398  1.65.2.2  martin 	ifmedia_init_with_lock(&sc->sc_media, IFM_IMASK, ixl_media_change,
   1399  1.65.2.2  martin 	    ixl_media_status, &sc->sc_cfg_lock);
   1400  1.65.2.2  martin 
   1401  1.65.2.2  martin 	ixl_media_add(sc);
   1402  1.65.2.2  martin 	ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
   1403  1.65.2.2  martin 	if (ISSET(sc->sc_phy_abilities,
   1404  1.65.2.2  martin 	    (IXL_PHY_ABILITY_PAUSE_TX | IXL_PHY_ABILITY_PAUSE_RX))) {
   1405  1.65.2.2  martin 		ifmedia_add(&sc->sc_media,
   1406  1.65.2.2  martin 		    IFM_ETHER | IFM_AUTO | IFM_FLOW, 0, NULL);
   1407  1.65.2.2  martin 	}
   1408  1.65.2.2  martin 	ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_NONE, 0, NULL);
   1409  1.65.2.2  martin 	ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
   1410  1.65.2.2  martin 
   1411  1.65.2.2  martin 	if_attach(ifp);
   1412  1.65.2.2  martin 	if_deferred_start_init(ifp, NULL);
   1413  1.65.2.2  martin 	ether_ifattach(ifp, sc->sc_enaddr);
   1414  1.65.2.2  martin 	ether_set_ifflags_cb(&sc->sc_ec, ixl_ifflags_cb);
   1415  1.65.2.2  martin 
   1416  1.65.2.2  martin 	rv = ixl_get_link_status_poll(sc, &link);
   1417  1.65.2.2  martin 	if (rv != 0)
   1418  1.65.2.2  martin 		link = LINK_STATE_UNKNOWN;
   1419  1.65.2.2  martin 	if_link_state_change(ifp, link);
   1420  1.65.2.2  martin 
   1421  1.65.2.2  martin 	ixl_atq_set(&sc->sc_link_state_atq, ixl_get_link_status_done);
   1422  1.65.2.2  martin 	ixl_work_set(&sc->sc_link_state_task, ixl_get_link_status, sc);
   1423  1.65.2.2  martin 
   1424  1.65.2.2  martin 	ixl_config_other_intr(sc);
   1425  1.65.2.2  martin 	ixl_enable_other_intr(sc);
   1426  1.65.2.2  martin 
   1427  1.65.2.2  martin 	ixl_set_phy_autoselect(sc);
   1428  1.65.2.2  martin 
   1429  1.65.2.2  martin 	/* remove default mac filter and replace it so we can see vlans */
   1430  1.65.2.2  martin 	rv = ixl_remove_macvlan(sc, sc->sc_enaddr, 0, 0);
   1431  1.65.2.2  martin 	if (rv != ENOENT) {
   1432  1.65.2.2  martin 		aprint_debug_dev(self,
   1433  1.65.2.2  martin 		    "unable to remove macvlan %u\n", rv);
   1434  1.65.2.2  martin 	}
   1435  1.65.2.2  martin 	rv = ixl_remove_macvlan(sc, sc->sc_enaddr, 0,
   1436  1.65.2.2  martin 	    IXL_AQ_OP_REMOVE_MACVLAN_IGNORE_VLAN);
   1437  1.65.2.2  martin 	if (rv != ENOENT) {
   1438  1.65.2.2  martin 		aprint_debug_dev(self,
   1439  1.65.2.2  martin 		    "unable to remove macvlan, ignore vlan %u\n", rv);
   1440  1.65.2.2  martin 	}
   1441  1.65.2.2  martin 
   1442  1.65.2.2  martin 	if (ixl_update_macvlan(sc) != 0) {
   1443  1.65.2.2  martin 		aprint_debug_dev(self,
   1444  1.65.2.2  martin 		    "couldn't enable vlan hardware filter\n");
   1445  1.65.2.2  martin 		CLR(sc->sc_ec.ec_capenable, ETHERCAP_VLAN_HWFILTER);
   1446  1.65.2.2  martin 		CLR(sc->sc_cur_ec_capenable, ETHERCAP_VLAN_HWFILTER);
   1447  1.65.2.2  martin 	}
   1448  1.65.2.2  martin 
   1449  1.65.2.2  martin 	sc->sc_txrx_workqueue = true;
   1450  1.65.2.2  martin 	sc->sc_tx_process_limit = IXL_TX_PROCESS_LIMIT;
   1451  1.65.2.2  martin 	sc->sc_rx_process_limit = IXL_RX_PROCESS_LIMIT;
   1452  1.65.2.2  martin 	sc->sc_tx_intr_process_limit = IXL_TX_INTR_PROCESS_LIMIT;
   1453  1.65.2.2  martin 	sc->sc_rx_intr_process_limit = IXL_RX_INTR_PROCESS_LIMIT;
   1454  1.65.2.2  martin 
   1455  1.65.2.2  martin 	ixl_stats_update(sc);
   1456  1.65.2.2  martin 	sc->sc_stats_counters.isc_has_offset = true;
   1457  1.65.2.2  martin 
   1458  1.65.2.2  martin 	if (pmf_device_register(self, NULL, NULL) != true)
   1459  1.65.2.2  martin 		aprint_debug_dev(self, "couldn't establish power handler\n");
   1460  1.65.2.2  martin 	sc->sc_itr_rx = IXL_ITR_RX;
   1461  1.65.2.2  martin 	sc->sc_itr_tx = IXL_ITR_TX;
   1462  1.65.2.2  martin 	sc->sc_attached = true;
   1463  1.65.2.2  martin 	return;
   1464  1.65.2.2  martin 
   1465  1.65.2.2  martin teardown_wqs:
   1466  1.65.2.2  martin 	config_finalize_register(self, ixl_workqs_teardown);
   1467  1.65.2.2  martin teardown_sysctls:
   1468  1.65.2.2  martin 	ixl_teardown_sysctls(sc);
   1469  1.65.2.2  martin teardown_stats:
   1470  1.65.2.2  martin 	ixl_teardown_stats(sc);
   1471  1.65.2.2  martin teardown_intrs:
   1472  1.65.2.2  martin 	ixl_teardown_interrupts(sc);
   1473  1.65.2.2  martin free_queue_pairs:
   1474  1.65.2.2  martin 	ixl_queue_pairs_free(sc);
   1475  1.65.2.2  martin free_scratch:
   1476  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_scratch);
   1477  1.65.2.2  martin free_hmc:
   1478  1.65.2.2  martin 	ixl_hmc_free(sc);
   1479  1.65.2.2  martin free_aqbuf:
   1480  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_aqbuf);
   1481  1.65.2.2  martin shutdown:
   1482  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_head, 0);
   1483  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_head, 0);
   1484  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_tail, 0);
   1485  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_tail, 0);
   1486  1.65.2.2  martin 
   1487  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_bal, 0);
   1488  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_bah, 0);
   1489  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_len, 0);
   1490  1.65.2.2  martin 
   1491  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_bal, 0);
   1492  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_bah, 0);
   1493  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_len, 0);
   1494  1.65.2.2  martin 
   1495  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_arq),
   1496  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_arq),
   1497  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD);
   1498  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   1499  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq),
   1500  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1501  1.65.2.2  martin 
   1502  1.65.2.2  martin 	ixl_arq_unfill(sc);
   1503  1.65.2.2  martin free_arq:
   1504  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_arq);
   1505  1.65.2.2  martin free_atq:
   1506  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_atq);
   1507  1.65.2.2  martin unmap:
   1508  1.65.2.2  martin 	mutex_destroy(&sc->sc_atq_lock);
   1509  1.65.2.2  martin 	bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
   1510  1.65.2.2  martin 	mutex_destroy(&sc->sc_cfg_lock);
   1511  1.65.2.2  martin 	sc->sc_mems = 0;
   1512  1.65.2.2  martin 
   1513  1.65.2.2  martin 	sc->sc_attached = false;
   1514  1.65.2.2  martin }
   1515  1.65.2.2  martin 
   1516  1.65.2.2  martin static int
   1517  1.65.2.2  martin ixl_detach(device_t self, int flags)
   1518  1.65.2.2  martin {
   1519  1.65.2.2  martin 	struct ixl_softc *sc = device_private(self);
   1520  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   1521  1.65.2.2  martin 
   1522  1.65.2.2  martin 	if (!sc->sc_attached)
   1523  1.65.2.2  martin 		return 0;
   1524  1.65.2.2  martin 
   1525  1.65.2.2  martin 	ixl_stop(ifp, 1);
   1526  1.65.2.2  martin 
   1527  1.65.2.2  martin 	ixl_disable_other_intr(sc);
   1528  1.65.2.2  martin 
   1529  1.65.2.2  martin 	callout_halt(&sc->sc_stats_callout, NULL);
   1530  1.65.2.2  martin 	ixl_work_wait(sc->sc_workq, &sc->sc_stats_task);
   1531  1.65.2.2  martin 
   1532  1.65.2.2  martin 	/* wait for ATQ handler */
   1533  1.65.2.2  martin 	mutex_enter(&sc->sc_atq_lock);
   1534  1.65.2.2  martin 	mutex_exit(&sc->sc_atq_lock);
   1535  1.65.2.2  martin 
   1536  1.65.2.2  martin 	ixl_work_wait(sc->sc_workq, &sc->sc_arq_task);
   1537  1.65.2.2  martin 	ixl_work_wait(sc->sc_workq, &sc->sc_link_state_task);
   1538  1.65.2.2  martin 
   1539  1.65.2.2  martin 	if (sc->sc_workq != NULL) {
   1540  1.65.2.2  martin 		ixl_workq_destroy(sc->sc_workq);
   1541  1.65.2.2  martin 		sc->sc_workq = NULL;
   1542  1.65.2.2  martin 	}
   1543  1.65.2.2  martin 
   1544  1.65.2.2  martin 	if (sc->sc_workq_txrx != NULL) {
   1545  1.65.2.2  martin 		workqueue_destroy(sc->sc_workq_txrx);
   1546  1.65.2.2  martin 		sc->sc_workq_txrx = NULL;
   1547  1.65.2.2  martin 	}
   1548  1.65.2.2  martin 
   1549  1.65.2.2  martin 	ether_ifdetach(ifp);
   1550  1.65.2.2  martin 	if_detach(ifp);
   1551  1.65.2.2  martin 	ifmedia_fini(&sc->sc_media);
   1552  1.65.2.2  martin 
   1553  1.65.2.2  martin 	ixl_teardown_interrupts(sc);
   1554  1.65.2.2  martin 	ixl_teardown_stats(sc);
   1555  1.65.2.2  martin 	ixl_teardown_sysctls(sc);
   1556  1.65.2.2  martin 
   1557  1.65.2.2  martin 	ixl_queue_pairs_free(sc);
   1558  1.65.2.2  martin 
   1559  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_scratch);
   1560  1.65.2.2  martin 	ixl_hmc_free(sc);
   1561  1.65.2.2  martin 
   1562  1.65.2.2  martin 	/* shutdown */
   1563  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_head, 0);
   1564  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_head, 0);
   1565  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_tail, 0);
   1566  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_tail, 0);
   1567  1.65.2.2  martin 
   1568  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_bal, 0);
   1569  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_bah, 0);
   1570  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_len, 0);
   1571  1.65.2.2  martin 
   1572  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_bal, 0);
   1573  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_bah, 0);
   1574  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->arq_len, 0);
   1575  1.65.2.2  martin 
   1576  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_arq),
   1577  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_arq),
   1578  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD);
   1579  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   1580  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq),
   1581  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1582  1.65.2.2  martin 
   1583  1.65.2.2  martin 	ixl_arq_unfill(sc);
   1584  1.65.2.2  martin 
   1585  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_arq);
   1586  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_atq);
   1587  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_aqbuf);
   1588  1.65.2.2  martin 
   1589  1.65.2.2  martin 	cv_destroy(&sc->sc_atq_cv);
   1590  1.65.2.2  martin 	mutex_destroy(&sc->sc_atq_lock);
   1591  1.65.2.2  martin 
   1592  1.65.2.2  martin 	if (sc->sc_mems != 0) {
   1593  1.65.2.2  martin 		bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_mems);
   1594  1.65.2.2  martin 		sc->sc_mems = 0;
   1595  1.65.2.2  martin 	}
   1596  1.65.2.2  martin 
   1597  1.65.2.2  martin 	mutex_destroy(&sc->sc_cfg_lock);
   1598  1.65.2.2  martin 
   1599  1.65.2.2  martin 	return 0;
   1600  1.65.2.2  martin }
   1601  1.65.2.2  martin 
   1602  1.65.2.2  martin static int
   1603  1.65.2.2  martin ixl_workqs_teardown(device_t self)
   1604  1.65.2.2  martin {
   1605  1.65.2.2  martin 	struct ixl_softc *sc = device_private(self);
   1606  1.65.2.2  martin 
   1607  1.65.2.2  martin 	if (sc->sc_workq != NULL) {
   1608  1.65.2.2  martin 		ixl_workq_destroy(sc->sc_workq);
   1609  1.65.2.2  martin 		sc->sc_workq = NULL;
   1610  1.65.2.2  martin 	}
   1611  1.65.2.2  martin 
   1612  1.65.2.2  martin 	if (sc->sc_workq_txrx != NULL) {
   1613  1.65.2.2  martin 		workqueue_destroy(sc->sc_workq_txrx);
   1614  1.65.2.2  martin 		sc->sc_workq_txrx = NULL;
   1615  1.65.2.2  martin 	}
   1616  1.65.2.2  martin 
   1617  1.65.2.2  martin 	return 0;
   1618  1.65.2.2  martin }
   1619  1.65.2.2  martin 
   1620  1.65.2.2  martin static int
   1621  1.65.2.2  martin ixl_vlan_cb(struct ethercom *ec, uint16_t vid, bool set)
   1622  1.65.2.2  martin {
   1623  1.65.2.2  martin 	struct ifnet *ifp = &ec->ec_if;
   1624  1.65.2.2  martin 	struct ixl_softc *sc = ifp->if_softc;
   1625  1.65.2.2  martin 	int rv;
   1626  1.65.2.2  martin 
   1627  1.65.2.2  martin 	if (!ISSET(sc->sc_cur_ec_capenable, ETHERCAP_VLAN_HWFILTER)) {
   1628  1.65.2.2  martin 		return 0;
   1629  1.65.2.2  martin 	}
   1630  1.65.2.2  martin 
   1631  1.65.2.2  martin 	if (set) {
   1632  1.65.2.2  martin 		rv = ixl_add_macvlan(sc, sc->sc_enaddr, vid,
   1633  1.65.2.2  martin 		    IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH);
   1634  1.65.2.2  martin 		if (rv == 0) {
   1635  1.65.2.2  martin 			rv = ixl_add_macvlan(sc, etherbroadcastaddr,
   1636  1.65.2.2  martin 			    vid, IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH);
   1637  1.65.2.2  martin 		}
   1638  1.65.2.2  martin 	} else {
   1639  1.65.2.2  martin 		rv = ixl_remove_macvlan(sc, sc->sc_enaddr, vid,
   1640  1.65.2.2  martin 		    IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH);
   1641  1.65.2.2  martin 		(void)ixl_remove_macvlan(sc, etherbroadcastaddr, vid,
   1642  1.65.2.2  martin 		    IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH);
   1643  1.65.2.2  martin 	}
   1644  1.65.2.2  martin 
   1645  1.65.2.2  martin 	return rv;
   1646  1.65.2.2  martin }
   1647  1.65.2.2  martin 
   1648  1.65.2.2  martin static void
   1649  1.65.2.2  martin ixl_media_add(struct ixl_softc *sc)
   1650  1.65.2.2  martin {
   1651  1.65.2.2  martin 	struct ifmedia *ifm = &sc->sc_media;
   1652  1.65.2.2  martin 	const struct ixl_phy_type *itype;
   1653  1.65.2.2  martin 	unsigned int i;
   1654  1.65.2.2  martin 	bool flow;
   1655  1.65.2.2  martin 
   1656  1.65.2.2  martin 	if (ISSET(sc->sc_phy_abilities,
   1657  1.65.2.2  martin 	    (IXL_PHY_ABILITY_PAUSE_TX | IXL_PHY_ABILITY_PAUSE_RX))) {
   1658  1.65.2.2  martin 		flow = true;
   1659  1.65.2.2  martin 	} else {
   1660  1.65.2.2  martin 		flow = false;
   1661  1.65.2.2  martin 	}
   1662  1.65.2.2  martin 
   1663  1.65.2.2  martin 	for (i = 0; i < __arraycount(ixl_phy_type_map); i++) {
   1664  1.65.2.2  martin 		itype = &ixl_phy_type_map[i];
   1665  1.65.2.2  martin 
   1666  1.65.2.2  martin 		if (ISSET(sc->sc_phy_types, itype->phy_type)) {
   1667  1.65.2.2  martin 			ifmedia_add(ifm,
   1668  1.65.2.2  martin 			    IFM_ETHER | IFM_FDX | itype->ifm_type, 0, NULL);
   1669  1.65.2.2  martin 
   1670  1.65.2.2  martin 			if (flow) {
   1671  1.65.2.2  martin 				ifmedia_add(ifm,
   1672  1.65.2.2  martin 				    IFM_ETHER | IFM_FDX | IFM_FLOW |
   1673  1.65.2.2  martin 				    itype->ifm_type, 0, NULL);
   1674  1.65.2.2  martin 			}
   1675  1.65.2.2  martin 
   1676  1.65.2.2  martin 			if (itype->ifm_type != IFM_100_TX)
   1677  1.65.2.2  martin 				continue;
   1678  1.65.2.2  martin 
   1679  1.65.2.2  martin 			ifmedia_add(ifm, IFM_ETHER | itype->ifm_type,
   1680  1.65.2.2  martin 			    0, NULL);
   1681  1.65.2.2  martin 			if (flow) {
   1682  1.65.2.2  martin 				ifmedia_add(ifm,
   1683  1.65.2.2  martin 				    IFM_ETHER | IFM_FLOW | itype->ifm_type,
   1684  1.65.2.2  martin 				    0, NULL);
   1685  1.65.2.2  martin 			}
   1686  1.65.2.2  martin 		}
   1687  1.65.2.2  martin 	}
   1688  1.65.2.2  martin }
   1689  1.65.2.2  martin 
   1690  1.65.2.2  martin static void
   1691  1.65.2.2  martin ixl_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
   1692  1.65.2.2  martin {
   1693  1.65.2.2  martin 	struct ixl_softc *sc = ifp->if_softc;
   1694  1.65.2.2  martin 
   1695  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_cfg_lock));
   1696  1.65.2.2  martin 
   1697  1.65.2.2  martin 	ifmr->ifm_status = sc->sc_media_status;
   1698  1.65.2.2  martin 	ifmr->ifm_active = sc->sc_media_active;
   1699  1.65.2.2  martin }
   1700  1.65.2.2  martin 
   1701  1.65.2.2  martin static int
   1702  1.65.2.2  martin ixl_media_change(struct ifnet *ifp)
   1703  1.65.2.2  martin {
   1704  1.65.2.2  martin 	struct ixl_softc *sc = ifp->if_softc;
   1705  1.65.2.2  martin 	struct ifmedia *ifm = &sc->sc_media;
   1706  1.65.2.2  martin 	uint64_t ifm_active = sc->sc_media_active;
   1707  1.65.2.2  martin 	uint8_t link_speed, abilities;
   1708  1.65.2.2  martin 
   1709  1.65.2.2  martin 	switch (IFM_SUBTYPE(ifm_active)) {
   1710  1.65.2.2  martin 	case IFM_1000_SGMII:
   1711  1.65.2.2  martin 	case IFM_1000_KX:
   1712  1.65.2.2  martin 	case IFM_10G_KX4:
   1713  1.65.2.2  martin 	case IFM_10G_KR:
   1714  1.65.2.2  martin 	case IFM_40G_KR4:
   1715  1.65.2.2  martin 	case IFM_20G_KR2:
   1716  1.65.2.2  martin 	case IFM_25G_KR:
   1717  1.65.2.2  martin 		/* backplanes */
   1718  1.65.2.2  martin 		return EINVAL;
   1719  1.65.2.2  martin 	}
   1720  1.65.2.2  martin 
   1721  1.65.2.2  martin 	abilities = IXL_PHY_ABILITY_AUTONEGO | IXL_PHY_ABILITY_LINKUP;
   1722  1.65.2.2  martin 
   1723  1.65.2.2  martin 	switch (IFM_SUBTYPE(ifm->ifm_media)) {
   1724  1.65.2.2  martin 	case IFM_AUTO:
   1725  1.65.2.2  martin 		link_speed = sc->sc_phy_linkspeed;
   1726  1.65.2.2  martin 		break;
   1727  1.65.2.2  martin 	case IFM_NONE:
   1728  1.65.2.2  martin 		link_speed = 0;
   1729  1.65.2.2  martin 		CLR(abilities, IXL_PHY_ABILITY_LINKUP);
   1730  1.65.2.2  martin 		break;
   1731  1.65.2.2  martin 	default:
   1732  1.65.2.2  martin 		link_speed = ixl_search_baudrate(
   1733  1.65.2.2  martin 		    ifmedia_baudrate(ifm->ifm_media));
   1734  1.65.2.2  martin 	}
   1735  1.65.2.2  martin 
   1736  1.65.2.2  martin 	if (ISSET(abilities, IXL_PHY_ABILITY_LINKUP)) {
   1737  1.65.2.2  martin 		if (ISSET(link_speed, sc->sc_phy_linkspeed) == 0)
   1738  1.65.2.2  martin 			return EINVAL;
   1739  1.65.2.2  martin 	}
   1740  1.65.2.2  martin 
   1741  1.65.2.2  martin 	if (ifm->ifm_media & IFM_FLOW) {
   1742  1.65.2.2  martin 		abilities |= sc->sc_phy_abilities &
   1743  1.65.2.2  martin 		    (IXL_PHY_ABILITY_PAUSE_TX | IXL_PHY_ABILITY_PAUSE_RX);
   1744  1.65.2.2  martin 	}
   1745  1.65.2.2  martin 
   1746  1.65.2.2  martin 	return ixl_set_phy_config(sc, link_speed, abilities, false);
   1747  1.65.2.2  martin }
   1748  1.65.2.2  martin 
   1749  1.65.2.2  martin static void
   1750  1.65.2.2  martin ixl_watchdog(struct ifnet *ifp)
   1751  1.65.2.2  martin {
   1752  1.65.2.2  martin 
   1753  1.65.2.2  martin }
   1754  1.65.2.2  martin 
   1755  1.65.2.2  martin static void
   1756  1.65.2.2  martin ixl_del_all_multiaddr(struct ixl_softc *sc)
   1757  1.65.2.2  martin {
   1758  1.65.2.2  martin 	struct ethercom *ec = &sc->sc_ec;
   1759  1.65.2.2  martin 	struct ether_multi *enm;
   1760  1.65.2.2  martin 	struct ether_multistep step;
   1761  1.65.2.2  martin 
   1762  1.65.2.2  martin 	ETHER_LOCK(ec);
   1763  1.65.2.2  martin 	for (ETHER_FIRST_MULTI(step, ec, enm); enm != NULL;
   1764  1.65.2.2  martin 	    ETHER_NEXT_MULTI(step, enm)) {
   1765  1.65.2.2  martin 		ixl_remove_macvlan(sc, enm->enm_addrlo, 0,
   1766  1.65.2.2  martin 		    IXL_AQ_OP_REMOVE_MACVLAN_IGNORE_VLAN);
   1767  1.65.2.2  martin 	}
   1768  1.65.2.2  martin 	ETHER_UNLOCK(ec);
   1769  1.65.2.2  martin }
   1770  1.65.2.2  martin 
   1771  1.65.2.2  martin static int
   1772  1.65.2.2  martin ixl_add_multi(struct ixl_softc *sc, uint8_t *addrlo, uint8_t *addrhi)
   1773  1.65.2.2  martin {
   1774  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   1775  1.65.2.2  martin 	int rv;
   1776  1.65.2.2  martin 
   1777  1.65.2.2  martin 	if (ISSET(ifp->if_flags, IFF_ALLMULTI))
   1778  1.65.2.2  martin 		return 0;
   1779  1.65.2.2  martin 
   1780  1.65.2.2  martin 	if (memcmp(addrlo, addrhi, ETHER_ADDR_LEN) != 0) {
   1781  1.65.2.2  martin 		ixl_del_all_multiaddr(sc);
   1782  1.65.2.2  martin 		SET(ifp->if_flags, IFF_ALLMULTI);
   1783  1.65.2.2  martin 		return ENETRESET;
   1784  1.65.2.2  martin 	}
   1785  1.65.2.2  martin 
   1786  1.65.2.2  martin 	/* multicast address can not use VLAN HWFILTER */
   1787  1.65.2.2  martin 	rv = ixl_add_macvlan(sc, addrlo, 0,
   1788  1.65.2.2  martin 	    IXL_AQ_OP_ADD_MACVLAN_IGNORE_VLAN);
   1789  1.65.2.2  martin 
   1790  1.65.2.2  martin 	if (rv == ENOSPC) {
   1791  1.65.2.2  martin 		ixl_del_all_multiaddr(sc);
   1792  1.65.2.2  martin 		SET(ifp->if_flags, IFF_ALLMULTI);
   1793  1.65.2.2  martin 		return ENETRESET;
   1794  1.65.2.2  martin 	}
   1795  1.65.2.2  martin 
   1796  1.65.2.2  martin 	return rv;
   1797  1.65.2.2  martin }
   1798  1.65.2.2  martin 
   1799  1.65.2.2  martin static int
   1800  1.65.2.2  martin ixl_del_multi(struct ixl_softc *sc, uint8_t *addrlo, uint8_t *addrhi)
   1801  1.65.2.2  martin {
   1802  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   1803  1.65.2.2  martin 	struct ethercom *ec = &sc->sc_ec;
   1804  1.65.2.2  martin 	struct ether_multi *enm, *enm_last;
   1805  1.65.2.2  martin 	struct ether_multistep step;
   1806  1.65.2.2  martin 	int error, rv = 0;
   1807  1.65.2.2  martin 
   1808  1.65.2.2  martin 	if (!ISSET(ifp->if_flags, IFF_ALLMULTI)) {
   1809  1.65.2.2  martin 		ixl_remove_macvlan(sc, addrlo, 0,
   1810  1.65.2.2  martin 		    IXL_AQ_OP_REMOVE_MACVLAN_IGNORE_VLAN);
   1811  1.65.2.2  martin 		return 0;
   1812  1.65.2.2  martin 	}
   1813  1.65.2.2  martin 
   1814  1.65.2.2  martin 	ETHER_LOCK(ec);
   1815  1.65.2.2  martin 	for (ETHER_FIRST_MULTI(step, ec, enm); enm != NULL;
   1816  1.65.2.2  martin 	    ETHER_NEXT_MULTI(step, enm)) {
   1817  1.65.2.2  martin 		if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
   1818  1.65.2.2  martin 		    ETHER_ADDR_LEN) != 0) {
   1819  1.65.2.2  martin 			goto out;
   1820  1.65.2.2  martin 		}
   1821  1.65.2.2  martin 	}
   1822  1.65.2.2  martin 
   1823  1.65.2.2  martin 	for (ETHER_FIRST_MULTI(step, ec, enm); enm != NULL;
   1824  1.65.2.2  martin 	    ETHER_NEXT_MULTI(step, enm)) {
   1825  1.65.2.2  martin 		error = ixl_add_macvlan(sc, enm->enm_addrlo, 0,
   1826  1.65.2.2  martin 		    IXL_AQ_OP_ADD_MACVLAN_IGNORE_VLAN);
   1827  1.65.2.2  martin 		if (error != 0)
   1828  1.65.2.2  martin 			break;
   1829  1.65.2.2  martin 	}
   1830  1.65.2.2  martin 
   1831  1.65.2.2  martin 	if (enm != NULL) {
   1832  1.65.2.2  martin 		enm_last = enm;
   1833  1.65.2.2  martin 		for (ETHER_FIRST_MULTI(step, ec, enm); enm != NULL;
   1834  1.65.2.2  martin 		    ETHER_NEXT_MULTI(step, enm)) {
   1835  1.65.2.2  martin 			if (enm == enm_last)
   1836  1.65.2.2  martin 				break;
   1837  1.65.2.2  martin 
   1838  1.65.2.2  martin 			ixl_remove_macvlan(sc, enm->enm_addrlo, 0,
   1839  1.65.2.2  martin 			    IXL_AQ_OP_REMOVE_MACVLAN_IGNORE_VLAN);
   1840  1.65.2.2  martin 		}
   1841  1.65.2.2  martin 	} else {
   1842  1.65.2.2  martin 		CLR(ifp->if_flags, IFF_ALLMULTI);
   1843  1.65.2.2  martin 		rv = ENETRESET;
   1844  1.65.2.2  martin 	}
   1845  1.65.2.2  martin 
   1846  1.65.2.2  martin out:
   1847  1.65.2.2  martin 	ETHER_UNLOCK(ec);
   1848  1.65.2.2  martin 	return rv;
   1849  1.65.2.2  martin }
   1850  1.65.2.2  martin 
   1851  1.65.2.2  martin static int
   1852  1.65.2.2  martin ixl_ioctl(struct ifnet *ifp, u_long cmd, void *data)
   1853  1.65.2.2  martin {
   1854  1.65.2.2  martin 	struct ifreq *ifr = (struct ifreq *)data;
   1855  1.65.2.2  martin 	struct ixl_softc *sc = (struct ixl_softc *)ifp->if_softc;
   1856  1.65.2.2  martin 	const struct sockaddr *sa;
   1857  1.65.2.2  martin 	uint8_t addrhi[ETHER_ADDR_LEN], addrlo[ETHER_ADDR_LEN];
   1858  1.65.2.2  martin 	int s, error = 0;
   1859  1.65.2.2  martin 	unsigned int nmtu;
   1860  1.65.2.2  martin 
   1861  1.65.2.2  martin 	switch (cmd) {
   1862  1.65.2.2  martin 	case SIOCSIFMTU:
   1863  1.65.2.2  martin 		nmtu = ifr->ifr_mtu;
   1864  1.65.2.2  martin 
   1865  1.65.2.2  martin 		if (nmtu < IXL_MIN_MTU || nmtu > IXL_MAX_MTU) {
   1866  1.65.2.2  martin 			error = EINVAL;
   1867  1.65.2.2  martin 			break;
   1868  1.65.2.2  martin 		}
   1869  1.65.2.2  martin 		if (ifp->if_mtu != nmtu) {
   1870  1.65.2.2  martin 			s = splnet();
   1871  1.65.2.2  martin 			error = ether_ioctl(ifp, cmd, data);
   1872  1.65.2.2  martin 			splx(s);
   1873  1.65.2.2  martin 			if (error == ENETRESET)
   1874  1.65.2.2  martin 				error = ixl_init(ifp);
   1875  1.65.2.2  martin 		}
   1876  1.65.2.2  martin 		break;
   1877  1.65.2.2  martin 	case SIOCADDMULTI:
   1878  1.65.2.2  martin 		sa = ifreq_getaddr(SIOCADDMULTI, ifr);
   1879  1.65.2.2  martin 		if (ether_addmulti(sa, &sc->sc_ec) == ENETRESET) {
   1880  1.65.2.2  martin 			error = ether_multiaddr(sa, addrlo, addrhi);
   1881  1.65.2.2  martin 			if (error != 0)
   1882  1.65.2.2  martin 				return error;
   1883  1.65.2.2  martin 
   1884  1.65.2.2  martin 			error = ixl_add_multi(sc, addrlo, addrhi);
   1885  1.65.2.2  martin 			if (error != 0 && error != ENETRESET) {
   1886  1.65.2.2  martin 				ether_delmulti(sa, &sc->sc_ec);
   1887  1.65.2.2  martin 				error = EIO;
   1888  1.65.2.2  martin 			}
   1889  1.65.2.2  martin 		}
   1890  1.65.2.2  martin 		break;
   1891  1.65.2.2  martin 
   1892  1.65.2.2  martin 	case SIOCDELMULTI:
   1893  1.65.2.2  martin 		sa = ifreq_getaddr(SIOCDELMULTI, ifr);
   1894  1.65.2.2  martin 		if (ether_delmulti(sa, &sc->sc_ec) == ENETRESET) {
   1895  1.65.2.2  martin 			error = ether_multiaddr(sa, addrlo, addrhi);
   1896  1.65.2.2  martin 			if (error != 0)
   1897  1.65.2.2  martin 				return error;
   1898  1.65.2.2  martin 
   1899  1.65.2.2  martin 			error = ixl_del_multi(sc, addrlo, addrhi);
   1900  1.65.2.2  martin 		}
   1901  1.65.2.2  martin 		break;
   1902  1.65.2.2  martin 
   1903  1.65.2.2  martin 	default:
   1904  1.65.2.2  martin 		s = splnet();
   1905  1.65.2.2  martin 		error = ether_ioctl(ifp, cmd, data);
   1906  1.65.2.2  martin 		splx(s);
   1907  1.65.2.2  martin 	}
   1908  1.65.2.2  martin 
   1909  1.65.2.2  martin 	if (error == ENETRESET)
   1910  1.65.2.2  martin 		error = ixl_iff(sc);
   1911  1.65.2.2  martin 
   1912  1.65.2.2  martin 	return error;
   1913  1.65.2.2  martin }
   1914  1.65.2.2  martin 
   1915  1.65.2.2  martin static enum i40e_mac_type
   1916  1.65.2.2  martin ixl_mactype(pci_product_id_t id)
   1917  1.65.2.2  martin {
   1918  1.65.2.2  martin 
   1919  1.65.2.2  martin 	switch (id) {
   1920  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_SFP:
   1921  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_KX_B:
   1922  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_KX_C:
   1923  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_QSFP_A:
   1924  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_QSFP_B:
   1925  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_QSFP_C:
   1926  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X710_10G_T:
   1927  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_20G_BP_1:
   1928  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XL710_20G_BP_2:
   1929  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X710_T4_10G:
   1930  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XXV710_25G_BP:
   1931  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_XXV710_25G_SFP28:
   1932  1.65.2.2  martin 		return I40E_MAC_XL710;
   1933  1.65.2.2  martin 
   1934  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X722_KX:
   1935  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X722_QSFP:
   1936  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X722_SFP:
   1937  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X722_1G_BASET:
   1938  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X722_10G_BASET:
   1939  1.65.2.2  martin 	case PCI_PRODUCT_INTEL_X722_I_SFP:
   1940  1.65.2.2  martin 		return I40E_MAC_X722;
   1941  1.65.2.2  martin 	}
   1942  1.65.2.2  martin 
   1943  1.65.2.2  martin 	return I40E_MAC_GENERIC;
   1944  1.65.2.2  martin }
   1945  1.65.2.2  martin 
   1946  1.65.2.2  martin static inline void *
   1947  1.65.2.2  martin ixl_hmc_kva(struct ixl_softc *sc, enum ixl_hmc_types type, unsigned int i)
   1948  1.65.2.2  martin {
   1949  1.65.2.2  martin 	uint8_t *kva = IXL_DMA_KVA(&sc->sc_hmc_pd);
   1950  1.65.2.2  martin 	struct ixl_hmc_entry *e = &sc->sc_hmc_entries[type];
   1951  1.65.2.2  martin 
   1952  1.65.2.2  martin 	if (i >= e->hmc_count)
   1953  1.65.2.2  martin 		return NULL;
   1954  1.65.2.2  martin 
   1955  1.65.2.2  martin 	kva += e->hmc_base;
   1956  1.65.2.2  martin 	kva += i * e->hmc_size;
   1957  1.65.2.2  martin 
   1958  1.65.2.2  martin 	return kva;
   1959  1.65.2.2  martin }
   1960  1.65.2.2  martin 
   1961  1.65.2.2  martin static inline size_t
   1962  1.65.2.2  martin ixl_hmc_len(struct ixl_softc *sc, enum ixl_hmc_types type)
   1963  1.65.2.2  martin {
   1964  1.65.2.2  martin 	struct ixl_hmc_entry *e = &sc->sc_hmc_entries[type];
   1965  1.65.2.2  martin 
   1966  1.65.2.2  martin 	return e->hmc_size;
   1967  1.65.2.2  martin }
   1968  1.65.2.2  martin 
   1969  1.65.2.2  martin static void
   1970  1.65.2.2  martin ixl_enable_queue_intr(struct ixl_softc *sc, struct ixl_queue_pair *qp)
   1971  1.65.2.2  martin {
   1972  1.65.2.2  martin 	struct ixl_rx_ring *rxr = qp->qp_rxr;
   1973  1.65.2.2  martin 
   1974  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_DYN_CTLN(rxr->rxr_qid),
   1975  1.65.2.2  martin 	    I40E_PFINT_DYN_CTLN_INTENA_MASK |
   1976  1.65.2.2  martin 	    I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
   1977  1.65.2.2  martin 	    (IXL_NOITR << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT));
   1978  1.65.2.2  martin 	ixl_flush(sc);
   1979  1.65.2.2  martin }
   1980  1.65.2.2  martin 
   1981  1.65.2.2  martin static void
   1982  1.65.2.2  martin ixl_disable_queue_intr(struct ixl_softc *sc, struct ixl_queue_pair *qp)
   1983  1.65.2.2  martin {
   1984  1.65.2.2  martin 	struct ixl_rx_ring *rxr = qp->qp_rxr;
   1985  1.65.2.2  martin 
   1986  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_DYN_CTLN(rxr->rxr_qid),
   1987  1.65.2.2  martin 	    (IXL_NOITR << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT));
   1988  1.65.2.2  martin 	ixl_flush(sc);
   1989  1.65.2.2  martin }
   1990  1.65.2.2  martin 
   1991  1.65.2.2  martin static void
   1992  1.65.2.2  martin ixl_enable_other_intr(struct ixl_softc *sc)
   1993  1.65.2.2  martin {
   1994  1.65.2.2  martin 
   1995  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_DYN_CTL0,
   1996  1.65.2.2  martin 	    I40E_PFINT_DYN_CTL0_INTENA_MASK |
   1997  1.65.2.2  martin 	    I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
   1998  1.65.2.2  martin 	    (IXL_NOITR << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT));
   1999  1.65.2.2  martin 	ixl_flush(sc);
   2000  1.65.2.2  martin }
   2001  1.65.2.2  martin 
   2002  1.65.2.2  martin static void
   2003  1.65.2.2  martin ixl_disable_other_intr(struct ixl_softc *sc)
   2004  1.65.2.2  martin {
   2005  1.65.2.2  martin 
   2006  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_DYN_CTL0,
   2007  1.65.2.2  martin 	    (IXL_NOITR << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT));
   2008  1.65.2.2  martin 	ixl_flush(sc);
   2009  1.65.2.2  martin }
   2010  1.65.2.2  martin 
   2011  1.65.2.2  martin static int
   2012  1.65.2.2  martin ixl_reinit(struct ixl_softc *sc)
   2013  1.65.2.2  martin {
   2014  1.65.2.2  martin 	struct ixl_rx_ring *rxr;
   2015  1.65.2.2  martin 	struct ixl_tx_ring *txr;
   2016  1.65.2.2  martin 	unsigned int i;
   2017  1.65.2.2  martin 	uint32_t reg;
   2018  1.65.2.2  martin 
   2019  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_cfg_lock));
   2020  1.65.2.2  martin 
   2021  1.65.2.2  martin 	if (ixl_get_vsi(sc) != 0)
   2022  1.65.2.2  martin 		return EIO;
   2023  1.65.2.2  martin 
   2024  1.65.2.2  martin 	if (ixl_set_vsi(sc) != 0)
   2025  1.65.2.2  martin 		return EIO;
   2026  1.65.2.2  martin 
   2027  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2028  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   2029  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   2030  1.65.2.2  martin 
   2031  1.65.2.2  martin 		ixl_txr_config(sc, txr);
   2032  1.65.2.2  martin 		ixl_rxr_config(sc, rxr);
   2033  1.65.2.2  martin 	}
   2034  1.65.2.2  martin 
   2035  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_hmc_pd),
   2036  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_hmc_pd), BUS_DMASYNC_PREWRITE);
   2037  1.65.2.2  martin 
   2038  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2039  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   2040  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   2041  1.65.2.2  martin 
   2042  1.65.2.2  martin 		ixl_wr(sc, I40E_QTX_CTL(i), I40E_QTX_CTL_PF_QUEUE |
   2043  1.65.2.2  martin 		    (sc->sc_pf_id << I40E_QTX_CTL_PF_INDX_SHIFT));
   2044  1.65.2.2  martin 		ixl_flush(sc);
   2045  1.65.2.2  martin 
   2046  1.65.2.2  martin 		ixl_wr(sc, txr->txr_tail, txr->txr_prod);
   2047  1.65.2.2  martin 		ixl_wr(sc, rxr->rxr_tail, rxr->rxr_prod);
   2048  1.65.2.2  martin 
   2049  1.65.2.2  martin 		/* ixl_rxfill() needs lock held */
   2050  1.65.2.2  martin 		mutex_enter(&rxr->rxr_lock);
   2051  1.65.2.2  martin 		ixl_rxfill(sc, rxr);
   2052  1.65.2.2  martin 		mutex_exit(&rxr->rxr_lock);
   2053  1.65.2.2  martin 
   2054  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_QRX_ENA(i));
   2055  1.65.2.2  martin 		SET(reg, I40E_QRX_ENA_QENA_REQ_MASK);
   2056  1.65.2.2  martin 		ixl_wr(sc, I40E_QRX_ENA(i), reg);
   2057  1.65.2.2  martin 		if (ixl_rxr_enabled(sc, rxr) != 0)
   2058  1.65.2.2  martin 			goto stop;
   2059  1.65.2.2  martin 
   2060  1.65.2.2  martin 		ixl_txr_qdis(sc, txr, 1);
   2061  1.65.2.2  martin 
   2062  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_QTX_ENA(i));
   2063  1.65.2.2  martin 		SET(reg, I40E_QTX_ENA_QENA_REQ_MASK);
   2064  1.65.2.2  martin 		ixl_wr(sc, I40E_QTX_ENA(i), reg);
   2065  1.65.2.2  martin 
   2066  1.65.2.2  martin 		if (ixl_txr_enabled(sc, txr) != 0)
   2067  1.65.2.2  martin 			goto stop;
   2068  1.65.2.2  martin 	}
   2069  1.65.2.2  martin 
   2070  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_hmc_pd),
   2071  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_hmc_pd), BUS_DMASYNC_POSTWRITE);
   2072  1.65.2.2  martin 
   2073  1.65.2.2  martin 	return 0;
   2074  1.65.2.2  martin 
   2075  1.65.2.2  martin stop:
   2076  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_hmc_pd),
   2077  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_hmc_pd), BUS_DMASYNC_POSTWRITE);
   2078  1.65.2.2  martin 
   2079  1.65.2.2  martin 	return ETIMEDOUT;
   2080  1.65.2.2  martin }
   2081  1.65.2.2  martin 
   2082  1.65.2.2  martin static int
   2083  1.65.2.2  martin ixl_init_locked(struct ixl_softc *sc)
   2084  1.65.2.2  martin {
   2085  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   2086  1.65.2.2  martin 	unsigned int i;
   2087  1.65.2.2  martin 	int error, eccap_change;
   2088  1.65.2.2  martin 
   2089  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_cfg_lock));
   2090  1.65.2.2  martin 
   2091  1.65.2.2  martin 	if (ISSET(ifp->if_flags, IFF_RUNNING))
   2092  1.65.2.2  martin 		ixl_stop_locked(sc);
   2093  1.65.2.2  martin 
   2094  1.65.2.2  martin 	if (sc->sc_dead) {
   2095  1.65.2.2  martin 		return ENXIO;
   2096  1.65.2.2  martin 	}
   2097  1.65.2.2  martin 
   2098  1.65.2.2  martin 	eccap_change = sc->sc_ec.ec_capenable ^ sc->sc_cur_ec_capenable;
   2099  1.65.2.2  martin 	if (ISSET(eccap_change, ETHERCAP_VLAN_HWTAGGING))
   2100  1.65.2.2  martin 		sc->sc_cur_ec_capenable ^= ETHERCAP_VLAN_HWTAGGING;
   2101  1.65.2.2  martin 
   2102  1.65.2.2  martin 	if (ISSET(eccap_change, ETHERCAP_VLAN_HWFILTER)) {
   2103  1.65.2.2  martin 		if (ixl_update_macvlan(sc) == 0) {
   2104  1.65.2.2  martin 			sc->sc_cur_ec_capenable ^= ETHERCAP_VLAN_HWFILTER;
   2105  1.65.2.2  martin 		} else {
   2106  1.65.2.2  martin 			CLR(sc->sc_ec.ec_capenable, ETHERCAP_VLAN_HWFILTER);
   2107  1.65.2.2  martin 			CLR(sc->sc_cur_ec_capenable, ETHERCAP_VLAN_HWFILTER);
   2108  1.65.2.2  martin 		}
   2109  1.65.2.2  martin 	}
   2110  1.65.2.2  martin 
   2111  1.65.2.2  martin 	if (sc->sc_intrtype != PCI_INTR_TYPE_MSIX)
   2112  1.65.2.2  martin 		sc->sc_nqueue_pairs = 1;
   2113  1.65.2.2  martin 	else
   2114  1.65.2.2  martin 		sc->sc_nqueue_pairs = sc->sc_nqueue_pairs_max;
   2115  1.65.2.2  martin 
   2116  1.65.2.2  martin 	error = ixl_reinit(sc);
   2117  1.65.2.2  martin 	if (error) {
   2118  1.65.2.2  martin 		ixl_stop_locked(sc);
   2119  1.65.2.2  martin 		return error;
   2120  1.65.2.2  martin 	}
   2121  1.65.2.2  martin 
   2122  1.65.2.2  martin 	SET(ifp->if_flags, IFF_RUNNING);
   2123  1.65.2.2  martin 	CLR(ifp->if_flags, IFF_OACTIVE);
   2124  1.65.2.2  martin 
   2125  1.65.2.2  martin 	ixl_config_rss(sc);
   2126  1.65.2.2  martin 	ixl_config_queue_intr(sc);
   2127  1.65.2.2  martin 
   2128  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2129  1.65.2.2  martin 		ixl_enable_queue_intr(sc, &sc->sc_qps[i]);
   2130  1.65.2.2  martin 	}
   2131  1.65.2.2  martin 
   2132  1.65.2.2  martin 	error = ixl_iff(sc);
   2133  1.65.2.2  martin 	if (error) {
   2134  1.65.2.2  martin 		ixl_stop_locked(sc);
   2135  1.65.2.2  martin 		return error;
   2136  1.65.2.2  martin 	}
   2137  1.65.2.2  martin 
   2138  1.65.2.2  martin 	callout_schedule(&sc->sc_stats_callout, mstohz(sc->sc_stats_intval));
   2139  1.65.2.2  martin 
   2140  1.65.2.2  martin 	return 0;
   2141  1.65.2.2  martin }
   2142  1.65.2.2  martin 
   2143  1.65.2.2  martin static int
   2144  1.65.2.2  martin ixl_init(struct ifnet *ifp)
   2145  1.65.2.2  martin {
   2146  1.65.2.2  martin 	struct ixl_softc *sc = ifp->if_softc;
   2147  1.65.2.2  martin 	int error;
   2148  1.65.2.2  martin 
   2149  1.65.2.2  martin 	mutex_enter(&sc->sc_cfg_lock);
   2150  1.65.2.2  martin 	error = ixl_init_locked(sc);
   2151  1.65.2.2  martin 	mutex_exit(&sc->sc_cfg_lock);
   2152  1.65.2.2  martin 
   2153  1.65.2.2  martin 	if (error == 0)
   2154  1.65.2.2  martin 		(void)ixl_get_link_status(sc);
   2155  1.65.2.2  martin 
   2156  1.65.2.2  martin 	return error;
   2157  1.65.2.2  martin }
   2158  1.65.2.2  martin 
   2159  1.65.2.2  martin static int
   2160  1.65.2.2  martin ixl_iff(struct ixl_softc *sc)
   2161  1.65.2.2  martin {
   2162  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   2163  1.65.2.2  martin 	struct ixl_atq iatq;
   2164  1.65.2.2  martin 	struct ixl_aq_desc *iaq;
   2165  1.65.2.2  martin 	struct ixl_aq_vsi_promisc_param *param;
   2166  1.65.2.2  martin 	uint16_t flag_add, flag_del;
   2167  1.65.2.2  martin 	int error;
   2168  1.65.2.2  martin 
   2169  1.65.2.2  martin 	if (!ISSET(ifp->if_flags, IFF_RUNNING))
   2170  1.65.2.2  martin 		return 0;
   2171  1.65.2.2  martin 
   2172  1.65.2.2  martin 	memset(&iatq, 0, sizeof(iatq));
   2173  1.65.2.2  martin 
   2174  1.65.2.2  martin 	iaq = &iatq.iatq_desc;
   2175  1.65.2.2  martin 	iaq->iaq_opcode = htole16(IXL_AQ_OP_SET_VSI_PROMISC);
   2176  1.65.2.2  martin 
   2177  1.65.2.2  martin 	param = (struct ixl_aq_vsi_promisc_param *)&iaq->iaq_param;
   2178  1.65.2.2  martin 	param->flags = htole16(0);
   2179  1.65.2.2  martin 
   2180  1.65.2.2  martin 	if (!ISSET(sc->sc_cur_ec_capenable, ETHERCAP_VLAN_HWFILTER)
   2181  1.65.2.2  martin 	    || ISSET(ifp->if_flags, IFF_PROMISC)) {
   2182  1.65.2.2  martin 		param->flags |= htole16(IXL_AQ_VSI_PROMISC_FLAG_BCAST |
   2183  1.65.2.2  martin 		    IXL_AQ_VSI_PROMISC_FLAG_VLAN);
   2184  1.65.2.2  martin 	}
   2185  1.65.2.2  martin 
   2186  1.65.2.2  martin 	if (ISSET(ifp->if_flags, IFF_PROMISC)) {
   2187  1.65.2.2  martin 		param->flags |= htole16(IXL_AQ_VSI_PROMISC_FLAG_UCAST |
   2188  1.65.2.2  martin 		    IXL_AQ_VSI_PROMISC_FLAG_MCAST);
   2189  1.65.2.2  martin 	} else if (ISSET(ifp->if_flags, IFF_ALLMULTI)) {
   2190  1.65.2.2  martin 		param->flags |= htole16(IXL_AQ_VSI_PROMISC_FLAG_MCAST);
   2191  1.65.2.2  martin 	}
   2192  1.65.2.2  martin 	param->valid_flags = htole16(IXL_AQ_VSI_PROMISC_FLAG_UCAST |
   2193  1.65.2.2  martin 	    IXL_AQ_VSI_PROMISC_FLAG_MCAST | IXL_AQ_VSI_PROMISC_FLAG_BCAST |
   2194  1.65.2.2  martin 	    IXL_AQ_VSI_PROMISC_FLAG_VLAN);
   2195  1.65.2.2  martin 	param->seid = sc->sc_seid;
   2196  1.65.2.2  martin 
   2197  1.65.2.2  martin 	error = ixl_atq_exec(sc, &iatq);
   2198  1.65.2.2  martin 	if (error)
   2199  1.65.2.2  martin 		return error;
   2200  1.65.2.2  martin 
   2201  1.65.2.2  martin 	if (iaq->iaq_retval != htole16(IXL_AQ_RC_OK))
   2202  1.65.2.2  martin 		return EIO;
   2203  1.65.2.2  martin 
   2204  1.65.2.2  martin 	if (memcmp(sc->sc_enaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN) != 0) {
   2205  1.65.2.2  martin 		if (ISSET(sc->sc_cur_ec_capenable, ETHERCAP_VLAN_HWFILTER)) {
   2206  1.65.2.2  martin 			flag_add = IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH;
   2207  1.65.2.2  martin 			flag_del = IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH;
   2208  1.65.2.2  martin 		} else {
   2209  1.65.2.2  martin 			flag_add = IXL_AQ_OP_ADD_MACVLAN_IGNORE_VLAN;
   2210  1.65.2.2  martin 			flag_del = IXL_AQ_OP_REMOVE_MACVLAN_IGNORE_VLAN;
   2211  1.65.2.2  martin 		}
   2212  1.65.2.2  martin 
   2213  1.65.2.2  martin 		ixl_remove_macvlan(sc, sc->sc_enaddr, 0, flag_del);
   2214  1.65.2.2  martin 
   2215  1.65.2.2  martin 		memcpy(sc->sc_enaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
   2216  1.65.2.2  martin 		ixl_add_macvlan(sc, sc->sc_enaddr, 0, flag_add);
   2217  1.65.2.2  martin 	}
   2218  1.65.2.2  martin 	return 0;
   2219  1.65.2.2  martin }
   2220  1.65.2.2  martin 
   2221  1.65.2.2  martin static void
   2222  1.65.2.2  martin ixl_stop_rendezvous(struct ixl_softc *sc)
   2223  1.65.2.2  martin {
   2224  1.65.2.2  martin 	struct ixl_tx_ring *txr;
   2225  1.65.2.2  martin 	struct ixl_rx_ring *rxr;
   2226  1.65.2.2  martin 	unsigned int i;
   2227  1.65.2.2  martin 
   2228  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2229  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   2230  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   2231  1.65.2.2  martin 
   2232  1.65.2.2  martin 		mutex_enter(&txr->txr_lock);
   2233  1.65.2.2  martin 		mutex_exit(&txr->txr_lock);
   2234  1.65.2.2  martin 
   2235  1.65.2.2  martin 		mutex_enter(&rxr->rxr_lock);
   2236  1.65.2.2  martin 		mutex_exit(&rxr->rxr_lock);
   2237  1.65.2.2  martin 
   2238  1.65.2.2  martin 		sc->sc_qps[i].qp_workqueue = false;
   2239  1.65.2.2  martin 		workqueue_wait(sc->sc_workq_txrx,
   2240  1.65.2.2  martin 		    &sc->sc_qps[i].qp_work);
   2241  1.65.2.2  martin 	}
   2242  1.65.2.2  martin }
   2243  1.65.2.2  martin 
   2244  1.65.2.2  martin static void
   2245  1.65.2.2  martin ixl_stop_locked(struct ixl_softc *sc)
   2246  1.65.2.2  martin {
   2247  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   2248  1.65.2.2  martin 	struct ixl_rx_ring *rxr;
   2249  1.65.2.2  martin 	struct ixl_tx_ring *txr;
   2250  1.65.2.2  martin 	unsigned int i;
   2251  1.65.2.2  martin 	uint32_t reg;
   2252  1.65.2.2  martin 
   2253  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_cfg_lock));
   2254  1.65.2.2  martin 
   2255  1.65.2.2  martin 	CLR(ifp->if_flags, IFF_RUNNING | IFF_OACTIVE);
   2256  1.65.2.2  martin 	callout_stop(&sc->sc_stats_callout);
   2257  1.65.2.2  martin 
   2258  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2259  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   2260  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   2261  1.65.2.2  martin 
   2262  1.65.2.2  martin 		ixl_disable_queue_intr(sc, &sc->sc_qps[i]);
   2263  1.65.2.2  martin 
   2264  1.65.2.2  martin 		mutex_enter(&txr->txr_lock);
   2265  1.65.2.2  martin 		ixl_txr_qdis(sc, txr, 0);
   2266  1.65.2.2  martin 		mutex_exit(&txr->txr_lock);
   2267  1.65.2.2  martin 	}
   2268  1.65.2.2  martin 
   2269  1.65.2.2  martin 	/* XXX wait at least 400 usec for all tx queues in one go */
   2270  1.65.2.2  martin 	ixl_flush(sc);
   2271  1.65.2.2  martin 	DELAY(500);
   2272  1.65.2.2  martin 
   2273  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2274  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   2275  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   2276  1.65.2.2  martin 
   2277  1.65.2.2  martin 		mutex_enter(&txr->txr_lock);
   2278  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_QTX_ENA(i));
   2279  1.65.2.2  martin 		CLR(reg, I40E_QTX_ENA_QENA_REQ_MASK);
   2280  1.65.2.2  martin 		ixl_wr(sc, I40E_QTX_ENA(i), reg);
   2281  1.65.2.2  martin 		mutex_exit(&txr->txr_lock);
   2282  1.65.2.2  martin 
   2283  1.65.2.2  martin 		mutex_enter(&rxr->rxr_lock);
   2284  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_QRX_ENA(i));
   2285  1.65.2.2  martin 		CLR(reg, I40E_QRX_ENA_QENA_REQ_MASK);
   2286  1.65.2.2  martin 		ixl_wr(sc, I40E_QRX_ENA(i), reg);
   2287  1.65.2.2  martin 		mutex_exit(&rxr->rxr_lock);
   2288  1.65.2.2  martin 	}
   2289  1.65.2.2  martin 
   2290  1.65.2.2  martin 	/* XXX short wait for all queue disables to settle */
   2291  1.65.2.2  martin 	ixl_flush(sc);
   2292  1.65.2.2  martin 	DELAY(50);
   2293  1.65.2.2  martin 
   2294  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2295  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   2296  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   2297  1.65.2.2  martin 
   2298  1.65.2.2  martin 		mutex_enter(&txr->txr_lock);
   2299  1.65.2.2  martin 		if (ixl_txr_disabled(sc, txr) != 0) {
   2300  1.65.2.2  martin 			mutex_exit(&txr->txr_lock);
   2301  1.65.2.2  martin 			goto die;
   2302  1.65.2.2  martin 		}
   2303  1.65.2.2  martin 		mutex_exit(&txr->txr_lock);
   2304  1.65.2.2  martin 
   2305  1.65.2.2  martin 		mutex_enter(&rxr->rxr_lock);
   2306  1.65.2.2  martin 		if (ixl_rxr_disabled(sc, rxr) != 0) {
   2307  1.65.2.2  martin 			mutex_exit(&rxr->rxr_lock);
   2308  1.65.2.2  martin 			goto die;
   2309  1.65.2.2  martin 		}
   2310  1.65.2.2  martin 		mutex_exit(&rxr->rxr_lock);
   2311  1.65.2.2  martin 	}
   2312  1.65.2.2  martin 
   2313  1.65.2.2  martin 	ixl_stop_rendezvous(sc);
   2314  1.65.2.2  martin 
   2315  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   2316  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   2317  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   2318  1.65.2.2  martin 
   2319  1.65.2.2  martin 		mutex_enter(&txr->txr_lock);
   2320  1.65.2.2  martin 		ixl_txr_unconfig(sc, txr);
   2321  1.65.2.2  martin 		mutex_exit(&txr->txr_lock);
   2322  1.65.2.2  martin 
   2323  1.65.2.2  martin 		mutex_enter(&rxr->rxr_lock);
   2324  1.65.2.2  martin 		ixl_rxr_unconfig(sc, rxr);
   2325  1.65.2.2  martin 		mutex_exit(&rxr->rxr_lock);
   2326  1.65.2.2  martin 
   2327  1.65.2.2  martin 		ixl_txr_clean(sc, txr);
   2328  1.65.2.2  martin 		ixl_rxr_clean(sc, rxr);
   2329  1.65.2.2  martin 	}
   2330  1.65.2.2  martin 
   2331  1.65.2.2  martin 	return;
   2332  1.65.2.2  martin die:
   2333  1.65.2.2  martin 	sc->sc_dead = true;
   2334  1.65.2.2  martin 	log(LOG_CRIT, "%s: failed to shut down rings",
   2335  1.65.2.2  martin 	    device_xname(sc->sc_dev));
   2336  1.65.2.2  martin 	return;
   2337  1.65.2.2  martin }
   2338  1.65.2.2  martin 
   2339  1.65.2.2  martin static void
   2340  1.65.2.2  martin ixl_stop(struct ifnet *ifp, int disable)
   2341  1.65.2.2  martin {
   2342  1.65.2.2  martin 	struct ixl_softc *sc = ifp->if_softc;
   2343  1.65.2.2  martin 
   2344  1.65.2.2  martin 	mutex_enter(&sc->sc_cfg_lock);
   2345  1.65.2.2  martin 	ixl_stop_locked(sc);
   2346  1.65.2.2  martin 	mutex_exit(&sc->sc_cfg_lock);
   2347  1.65.2.2  martin }
   2348  1.65.2.2  martin 
   2349  1.65.2.2  martin static int
   2350  1.65.2.2  martin ixl_queue_pairs_alloc(struct ixl_softc *sc)
   2351  1.65.2.2  martin {
   2352  1.65.2.2  martin 	struct ixl_queue_pair *qp;
   2353  1.65.2.2  martin 	unsigned int i;
   2354  1.65.2.2  martin 	size_t sz;
   2355  1.65.2.2  martin 
   2356  1.65.2.2  martin 	sz = sizeof(sc->sc_qps[0]) * sc->sc_nqueue_pairs_max;
   2357  1.65.2.2  martin 	sc->sc_qps = kmem_zalloc(sz, KM_SLEEP);
   2358  1.65.2.2  martin 
   2359  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs_max; i++) {
   2360  1.65.2.2  martin 		qp = &sc->sc_qps[i];
   2361  1.65.2.2  martin 
   2362  1.65.2.2  martin 		qp->qp_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
   2363  1.65.2.2  martin 		    ixl_handle_queue, qp);
   2364  1.65.2.2  martin 		if (qp->qp_si == NULL)
   2365  1.65.2.2  martin 			goto free;
   2366  1.65.2.2  martin 
   2367  1.65.2.2  martin 		qp->qp_txr = ixl_txr_alloc(sc, i);
   2368  1.65.2.2  martin 		if (qp->qp_txr == NULL)
   2369  1.65.2.2  martin 			goto free;
   2370  1.65.2.2  martin 
   2371  1.65.2.2  martin 		qp->qp_rxr = ixl_rxr_alloc(sc, i);
   2372  1.65.2.2  martin 		if (qp->qp_rxr == NULL)
   2373  1.65.2.2  martin 			goto free;
   2374  1.65.2.2  martin 
   2375  1.65.2.2  martin 		qp->qp_sc = sc;
   2376  1.65.2.2  martin 		snprintf(qp->qp_name, sizeof(qp->qp_name),
   2377  1.65.2.2  martin 		    "%s-TXRX%d", device_xname(sc->sc_dev), i);
   2378  1.65.2.2  martin 	}
   2379  1.65.2.2  martin 
   2380  1.65.2.2  martin 	return 0;
   2381  1.65.2.2  martin free:
   2382  1.65.2.2  martin 	if (sc->sc_qps != NULL) {
   2383  1.65.2.2  martin 		for (i = 0; i < sc->sc_nqueue_pairs_max; i++) {
   2384  1.65.2.2  martin 			qp = &sc->sc_qps[i];
   2385  1.65.2.2  martin 
   2386  1.65.2.2  martin 			if (qp->qp_txr != NULL)
   2387  1.65.2.2  martin 				ixl_txr_free(sc, qp->qp_txr);
   2388  1.65.2.2  martin 			if (qp->qp_rxr != NULL)
   2389  1.65.2.2  martin 				ixl_rxr_free(sc, qp->qp_rxr);
   2390  1.65.2.2  martin 			if (qp->qp_si != NULL)
   2391  1.65.2.2  martin 				softint_disestablish(qp->qp_si);
   2392  1.65.2.2  martin 		}
   2393  1.65.2.2  martin 
   2394  1.65.2.2  martin 		sz = sizeof(sc->sc_qps[0]) * sc->sc_nqueue_pairs_max;
   2395  1.65.2.2  martin 		kmem_free(sc->sc_qps, sz);
   2396  1.65.2.2  martin 		sc->sc_qps = NULL;
   2397  1.65.2.2  martin 	}
   2398  1.65.2.2  martin 
   2399  1.65.2.2  martin 	return -1;
   2400  1.65.2.2  martin }
   2401  1.65.2.2  martin 
   2402  1.65.2.2  martin static void
   2403  1.65.2.2  martin ixl_queue_pairs_free(struct ixl_softc *sc)
   2404  1.65.2.2  martin {
   2405  1.65.2.2  martin 	struct ixl_queue_pair *qp;
   2406  1.65.2.2  martin 	unsigned int i;
   2407  1.65.2.2  martin 	size_t sz;
   2408  1.65.2.2  martin 
   2409  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs_max; i++) {
   2410  1.65.2.2  martin 		qp = &sc->sc_qps[i];
   2411  1.65.2.2  martin 		ixl_txr_free(sc, qp->qp_txr);
   2412  1.65.2.2  martin 		ixl_rxr_free(sc, qp->qp_rxr);
   2413  1.65.2.2  martin 		softint_disestablish(qp->qp_si);
   2414  1.65.2.2  martin 	}
   2415  1.65.2.2  martin 
   2416  1.65.2.2  martin 	sz = sizeof(sc->sc_qps[0]) * sc->sc_nqueue_pairs_max;
   2417  1.65.2.2  martin 	kmem_free(sc->sc_qps, sz);
   2418  1.65.2.2  martin 	sc->sc_qps = NULL;
   2419  1.65.2.2  martin }
   2420  1.65.2.2  martin 
   2421  1.65.2.2  martin static struct ixl_tx_ring *
   2422  1.65.2.2  martin ixl_txr_alloc(struct ixl_softc *sc, unsigned int qid)
   2423  1.65.2.2  martin {
   2424  1.65.2.2  martin 	struct ixl_tx_ring *txr = NULL;
   2425  1.65.2.2  martin 	struct ixl_tx_map *maps = NULL, *txm;
   2426  1.65.2.2  martin 	unsigned int i;
   2427  1.65.2.2  martin 
   2428  1.65.2.2  martin 	txr = kmem_zalloc(sizeof(*txr), KM_SLEEP);
   2429  1.65.2.2  martin 	maps = kmem_zalloc(sizeof(maps[0]) * sc->sc_tx_ring_ndescs,
   2430  1.65.2.2  martin 	    KM_SLEEP);
   2431  1.65.2.2  martin 
   2432  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &txr->txr_mem,
   2433  1.65.2.2  martin 	    sizeof(struct ixl_tx_desc) * sc->sc_tx_ring_ndescs,
   2434  1.65.2.2  martin 	    IXL_TX_QUEUE_ALIGN) != 0)
   2435  1.65.2.2  martin 	    goto free;
   2436  1.65.2.2  martin 
   2437  1.65.2.2  martin 	for (i = 0; i < sc->sc_tx_ring_ndescs; i++) {
   2438  1.65.2.2  martin 		txm = &maps[i];
   2439  1.65.2.2  martin 
   2440  1.65.2.2  martin 		if (bus_dmamap_create(sc->sc_dmat, IXL_TX_PKT_MAXSIZE,
   2441  1.65.2.2  martin 		    IXL_TX_PKT_DESCS, IXL_TX_PKT_MAXSIZE, 0,
   2442  1.65.2.2  martin 		    BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW, &txm->txm_map) != 0)
   2443  1.65.2.2  martin 			goto uncreate;
   2444  1.65.2.2  martin 
   2445  1.65.2.2  martin 		txm->txm_eop = -1;
   2446  1.65.2.2  martin 		txm->txm_m = NULL;
   2447  1.65.2.2  martin 	}
   2448  1.65.2.2  martin 
   2449  1.65.2.2  martin 	txr->txr_cons = txr->txr_prod = 0;
   2450  1.65.2.2  martin 	txr->txr_maps = maps;
   2451  1.65.2.2  martin 
   2452  1.65.2.2  martin 	txr->txr_intrq = pcq_create(sc->sc_tx_ring_ndescs, KM_NOSLEEP);
   2453  1.65.2.2  martin 	if (txr->txr_intrq == NULL)
   2454  1.65.2.2  martin 		goto uncreate;
   2455  1.65.2.2  martin 
   2456  1.65.2.2  martin 	txr->txr_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
   2457  1.65.2.2  martin 	    ixl_deferred_transmit, txr);
   2458  1.65.2.2  martin 	if (txr->txr_si == NULL)
   2459  1.65.2.2  martin 		goto destroy_pcq;
   2460  1.65.2.2  martin 
   2461  1.65.2.2  martin 	txr->txr_tail = I40E_QTX_TAIL(qid);
   2462  1.65.2.2  martin 	txr->txr_qid = qid;
   2463  1.65.2.2  martin 	txr->txr_sc = sc;
   2464  1.65.2.2  martin 	mutex_init(&txr->txr_lock, MUTEX_DEFAULT, IPL_NET);
   2465  1.65.2.2  martin 
   2466  1.65.2.2  martin 	return txr;
   2467  1.65.2.2  martin 
   2468  1.65.2.2  martin destroy_pcq:
   2469  1.65.2.2  martin 	pcq_destroy(txr->txr_intrq);
   2470  1.65.2.2  martin uncreate:
   2471  1.65.2.2  martin 	for (i = 0; i < sc->sc_tx_ring_ndescs; i++) {
   2472  1.65.2.2  martin 		txm = &maps[i];
   2473  1.65.2.2  martin 
   2474  1.65.2.2  martin 		if (txm->txm_map == NULL)
   2475  1.65.2.2  martin 			continue;
   2476  1.65.2.2  martin 
   2477  1.65.2.2  martin 		bus_dmamap_destroy(sc->sc_dmat, txm->txm_map);
   2478  1.65.2.2  martin 	}
   2479  1.65.2.2  martin 
   2480  1.65.2.2  martin 	ixl_dmamem_free(sc, &txr->txr_mem);
   2481  1.65.2.2  martin free:
   2482  1.65.2.2  martin 	kmem_free(maps, sizeof(maps[0]) * sc->sc_tx_ring_ndescs);
   2483  1.65.2.2  martin 	kmem_free(txr, sizeof(*txr));
   2484  1.65.2.2  martin 
   2485  1.65.2.2  martin 	return NULL;
   2486  1.65.2.2  martin }
   2487  1.65.2.2  martin 
   2488  1.65.2.2  martin static void
   2489  1.65.2.2  martin ixl_txr_qdis(struct ixl_softc *sc, struct ixl_tx_ring *txr, int enable)
   2490  1.65.2.2  martin {
   2491  1.65.2.2  martin 	unsigned int qid;
   2492  1.65.2.2  martin 	bus_size_t reg;
   2493  1.65.2.2  martin 	uint32_t r;
   2494  1.65.2.2  martin 
   2495  1.65.2.2  martin 	qid = txr->txr_qid + sc->sc_base_queue;
   2496  1.65.2.2  martin 	reg = I40E_GLLAN_TXPRE_QDIS(qid / 128);
   2497  1.65.2.2  martin 	qid %= 128;
   2498  1.65.2.2  martin 
   2499  1.65.2.2  martin 	r = ixl_rd(sc, reg);
   2500  1.65.2.2  martin 	CLR(r, I40E_GLLAN_TXPRE_QDIS_QINDX_MASK);
   2501  1.65.2.2  martin 	SET(r, qid << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
   2502  1.65.2.2  martin 	SET(r, enable ? I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK :
   2503  1.65.2.2  martin 	    I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK);
   2504  1.65.2.2  martin 	ixl_wr(sc, reg, r);
   2505  1.65.2.2  martin }
   2506  1.65.2.2  martin 
   2507  1.65.2.2  martin static void
   2508  1.65.2.2  martin ixl_txr_config(struct ixl_softc *sc, struct ixl_tx_ring *txr)
   2509  1.65.2.2  martin {
   2510  1.65.2.2  martin 	struct ixl_hmc_txq txq;
   2511  1.65.2.2  martin 	struct ixl_aq_vsi_data *data = IXL_DMA_KVA(&sc->sc_scratch);
   2512  1.65.2.2  martin 	void *hmc;
   2513  1.65.2.2  martin 
   2514  1.65.2.2  martin 	memset(&txq, 0, sizeof(txq));
   2515  1.65.2.2  martin 	txq.head = htole16(txr->txr_cons);
   2516  1.65.2.2  martin 	txq.new_context = 1;
   2517  1.65.2.2  martin 	txq.base = htole64(IXL_DMA_DVA(&txr->txr_mem) / IXL_HMC_TXQ_BASE_UNIT);
   2518  1.65.2.2  martin 	txq.head_wb_ena = IXL_HMC_TXQ_DESC_WB;
   2519  1.65.2.2  martin 	txq.qlen = htole16(sc->sc_tx_ring_ndescs);
   2520  1.65.2.2  martin 	txq.tphrdesc_ena = 0;
   2521  1.65.2.2  martin 	txq.tphrpacket_ena = 0;
   2522  1.65.2.2  martin 	txq.tphwdesc_ena = 0;
   2523  1.65.2.2  martin 	txq.rdylist = data->qs_handle[0];
   2524  1.65.2.2  martin 
   2525  1.65.2.2  martin 	hmc = ixl_hmc_kva(sc, IXL_HMC_LAN_TX, txr->txr_qid);
   2526  1.65.2.2  martin 	memset(hmc, 0, ixl_hmc_len(sc, IXL_HMC_LAN_TX));
   2527  1.65.2.2  martin 	ixl_hmc_pack(hmc, &txq, ixl_hmc_pack_txq,
   2528  1.65.2.2  martin 	    __arraycount(ixl_hmc_pack_txq));
   2529  1.65.2.2  martin }
   2530  1.65.2.2  martin 
   2531  1.65.2.2  martin static void
   2532  1.65.2.2  martin ixl_txr_unconfig(struct ixl_softc *sc, struct ixl_tx_ring *txr)
   2533  1.65.2.2  martin {
   2534  1.65.2.2  martin 	void *hmc;
   2535  1.65.2.2  martin 
   2536  1.65.2.2  martin 	hmc = ixl_hmc_kva(sc, IXL_HMC_LAN_TX, txr->txr_qid);
   2537  1.65.2.2  martin 	memset(hmc, 0, ixl_hmc_len(sc, IXL_HMC_LAN_TX));
   2538  1.65.2.2  martin 	txr->txr_cons = txr->txr_prod = 0;
   2539  1.65.2.2  martin }
   2540  1.65.2.2  martin 
   2541  1.65.2.2  martin static void
   2542  1.65.2.2  martin ixl_txr_clean(struct ixl_softc *sc, struct ixl_tx_ring *txr)
   2543  1.65.2.2  martin {
   2544  1.65.2.2  martin 	struct ixl_tx_map *maps, *txm;
   2545  1.65.2.2  martin 	bus_dmamap_t map;
   2546  1.65.2.2  martin 	unsigned int i;
   2547  1.65.2.2  martin 
   2548  1.65.2.2  martin 	maps = txr->txr_maps;
   2549  1.65.2.2  martin 	for (i = 0; i < sc->sc_tx_ring_ndescs; i++) {
   2550  1.65.2.2  martin 		txm = &maps[i];
   2551  1.65.2.2  martin 
   2552  1.65.2.2  martin 		if (txm->txm_m == NULL)
   2553  1.65.2.2  martin 			continue;
   2554  1.65.2.2  martin 
   2555  1.65.2.2  martin 		map = txm->txm_map;
   2556  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
   2557  1.65.2.2  martin 		    BUS_DMASYNC_POSTWRITE);
   2558  1.65.2.2  martin 		bus_dmamap_unload(sc->sc_dmat, map);
   2559  1.65.2.2  martin 
   2560  1.65.2.2  martin 		m_freem(txm->txm_m);
   2561  1.65.2.2  martin 		txm->txm_m = NULL;
   2562  1.65.2.2  martin 	}
   2563  1.65.2.2  martin }
   2564  1.65.2.2  martin 
   2565  1.65.2.2  martin static int
   2566  1.65.2.2  martin ixl_txr_enabled(struct ixl_softc *sc, struct ixl_tx_ring *txr)
   2567  1.65.2.2  martin {
   2568  1.65.2.2  martin 	bus_size_t ena = I40E_QTX_ENA(txr->txr_qid);
   2569  1.65.2.2  martin 	uint32_t reg;
   2570  1.65.2.2  martin 	int i;
   2571  1.65.2.2  martin 
   2572  1.65.2.2  martin 	for (i = 0; i < 10; i++) {
   2573  1.65.2.2  martin 		reg = ixl_rd(sc, ena);
   2574  1.65.2.2  martin 		if (ISSET(reg, I40E_QTX_ENA_QENA_STAT_MASK))
   2575  1.65.2.2  martin 			return 0;
   2576  1.65.2.2  martin 
   2577  1.65.2.2  martin 		delaymsec(10);
   2578  1.65.2.2  martin 	}
   2579  1.65.2.2  martin 
   2580  1.65.2.2  martin 	return ETIMEDOUT;
   2581  1.65.2.2  martin }
   2582  1.65.2.2  martin 
   2583  1.65.2.2  martin static int
   2584  1.65.2.2  martin ixl_txr_disabled(struct ixl_softc *sc, struct ixl_tx_ring *txr)
   2585  1.65.2.2  martin {
   2586  1.65.2.2  martin 	bus_size_t ena = I40E_QTX_ENA(txr->txr_qid);
   2587  1.65.2.2  martin 	uint32_t reg;
   2588  1.65.2.2  martin 	int i;
   2589  1.65.2.2  martin 
   2590  1.65.2.2  martin 	KASSERT(mutex_owned(&txr->txr_lock));
   2591  1.65.2.2  martin 
   2592  1.65.2.2  martin 	for (i = 0; i < 10; i++) {
   2593  1.65.2.2  martin 		reg = ixl_rd(sc, ena);
   2594  1.65.2.2  martin 		if (ISSET(reg, I40E_QTX_ENA_QENA_STAT_MASK) == 0)
   2595  1.65.2.2  martin 			return 0;
   2596  1.65.2.2  martin 
   2597  1.65.2.2  martin 		delaymsec(10);
   2598  1.65.2.2  martin 	}
   2599  1.65.2.2  martin 
   2600  1.65.2.2  martin 	return ETIMEDOUT;
   2601  1.65.2.2  martin }
   2602  1.65.2.2  martin 
   2603  1.65.2.2  martin static void
   2604  1.65.2.2  martin ixl_txr_free(struct ixl_softc *sc, struct ixl_tx_ring *txr)
   2605  1.65.2.2  martin {
   2606  1.65.2.2  martin 	struct ixl_tx_map *maps, *txm;
   2607  1.65.2.2  martin 	struct mbuf *m;
   2608  1.65.2.2  martin 	unsigned int i;
   2609  1.65.2.2  martin 
   2610  1.65.2.2  martin 	softint_disestablish(txr->txr_si);
   2611  1.65.2.2  martin 	while ((m = pcq_get(txr->txr_intrq)) != NULL)
   2612  1.65.2.2  martin 		m_freem(m);
   2613  1.65.2.2  martin 	pcq_destroy(txr->txr_intrq);
   2614  1.65.2.2  martin 
   2615  1.65.2.2  martin 	maps = txr->txr_maps;
   2616  1.65.2.2  martin 	for (i = 0; i < sc->sc_tx_ring_ndescs; i++) {
   2617  1.65.2.2  martin 		txm = &maps[i];
   2618  1.65.2.2  martin 
   2619  1.65.2.2  martin 		bus_dmamap_destroy(sc->sc_dmat, txm->txm_map);
   2620  1.65.2.2  martin 	}
   2621  1.65.2.2  martin 
   2622  1.65.2.2  martin 	ixl_dmamem_free(sc, &txr->txr_mem);
   2623  1.65.2.2  martin 	mutex_destroy(&txr->txr_lock);
   2624  1.65.2.2  martin 	kmem_free(maps, sizeof(maps[0]) * sc->sc_tx_ring_ndescs);
   2625  1.65.2.2  martin 	kmem_free(txr, sizeof(*txr));
   2626  1.65.2.2  martin }
   2627  1.65.2.2  martin 
   2628  1.65.2.2  martin static inline int
   2629  1.65.2.2  martin ixl_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, struct mbuf **m0,
   2630  1.65.2.2  martin     struct ixl_tx_ring *txr)
   2631  1.65.2.2  martin {
   2632  1.65.2.2  martin 	struct mbuf *m;
   2633  1.65.2.2  martin 	int error;
   2634  1.65.2.2  martin 
   2635  1.65.2.2  martin 	KASSERT(mutex_owned(&txr->txr_lock));
   2636  1.65.2.2  martin 
   2637  1.65.2.2  martin 	m = *m0;
   2638  1.65.2.2  martin 
   2639  1.65.2.2  martin 	error = bus_dmamap_load_mbuf(dmat, map, m,
   2640  1.65.2.2  martin 	    BUS_DMA_STREAMING | BUS_DMA_WRITE | BUS_DMA_NOWAIT);
   2641  1.65.2.2  martin 	if (error != EFBIG)
   2642  1.65.2.2  martin 		return error;
   2643  1.65.2.2  martin 
   2644  1.65.2.2  martin 	m = m_defrag(m, M_DONTWAIT);
   2645  1.65.2.2  martin 	if (m != NULL) {
   2646  1.65.2.2  martin 		*m0 = m;
   2647  1.65.2.2  martin 		txr->txr_defragged.ev_count++;
   2648  1.65.2.2  martin 
   2649  1.65.2.2  martin 		error = bus_dmamap_load_mbuf(dmat, map, m,
   2650  1.65.2.2  martin 		    BUS_DMA_STREAMING | BUS_DMA_WRITE | BUS_DMA_NOWAIT);
   2651  1.65.2.2  martin 	} else {
   2652  1.65.2.2  martin 		txr->txr_defrag_failed.ev_count++;
   2653  1.65.2.2  martin 		error = ENOBUFS;
   2654  1.65.2.2  martin 	}
   2655  1.65.2.2  martin 
   2656  1.65.2.2  martin 	return error;
   2657  1.65.2.2  martin }
   2658  1.65.2.2  martin 
   2659  1.65.2.2  martin static inline int
   2660  1.65.2.2  martin ixl_tx_setup_offloads(struct mbuf *m, uint64_t *cmd_txd)
   2661  1.65.2.2  martin {
   2662  1.65.2.2  martin 	struct ether_header *eh;
   2663  1.65.2.2  martin 	size_t len;
   2664  1.65.2.2  martin 	uint64_t cmd;
   2665  1.65.2.2  martin 
   2666  1.65.2.2  martin 	cmd = 0;
   2667  1.65.2.2  martin 
   2668  1.65.2.2  martin 	eh = mtod(m, struct ether_header *);
   2669  1.65.2.2  martin 	switch (htons(eh->ether_type)) {
   2670  1.65.2.2  martin 	case ETHERTYPE_IP:
   2671  1.65.2.2  martin 	case ETHERTYPE_IPV6:
   2672  1.65.2.2  martin 		len = ETHER_HDR_LEN;
   2673  1.65.2.2  martin 		break;
   2674  1.65.2.2  martin 	case ETHERTYPE_VLAN:
   2675  1.65.2.2  martin 		len = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
   2676  1.65.2.2  martin 		break;
   2677  1.65.2.2  martin 	default:
   2678  1.65.2.2  martin 		len = 0;
   2679  1.65.2.2  martin 	}
   2680  1.65.2.2  martin 	cmd |= ((len >> 1) << IXL_TX_DESC_MACLEN_SHIFT);
   2681  1.65.2.2  martin 
   2682  1.65.2.2  martin 	if (m->m_pkthdr.csum_flags &
   2683  1.65.2.2  martin 	    (M_CSUM_TSOv4 | M_CSUM_TCPv4 | M_CSUM_UDPv4)) {
   2684  1.65.2.2  martin 		cmd |= IXL_TX_DESC_CMD_IIPT_IPV4;
   2685  1.65.2.2  martin 	}
   2686  1.65.2.2  martin 	if (m->m_pkthdr.csum_flags & M_CSUM_IPv4) {
   2687  1.65.2.2  martin 		cmd |= IXL_TX_DESC_CMD_IIPT_IPV4_CSUM;
   2688  1.65.2.2  martin 	}
   2689  1.65.2.2  martin 
   2690  1.65.2.2  martin 	if (m->m_pkthdr.csum_flags &
   2691  1.65.2.2  martin 	    (M_CSUM_TSOv6 | M_CSUM_TCPv6 | M_CSUM_UDPv6)) {
   2692  1.65.2.2  martin 		cmd |= IXL_TX_DESC_CMD_IIPT_IPV6;
   2693  1.65.2.2  martin 	}
   2694  1.65.2.2  martin 
   2695  1.65.2.2  martin 	switch (cmd & IXL_TX_DESC_CMD_IIPT_MASK) {
   2696  1.65.2.2  martin 	case IXL_TX_DESC_CMD_IIPT_IPV4:
   2697  1.65.2.2  martin 	case IXL_TX_DESC_CMD_IIPT_IPV4_CSUM:
   2698  1.65.2.2  martin 		len = M_CSUM_DATA_IPv4_IPHL(m->m_pkthdr.csum_data);
   2699  1.65.2.2  martin 		break;
   2700  1.65.2.2  martin 	case IXL_TX_DESC_CMD_IIPT_IPV6:
   2701  1.65.2.2  martin 		len = M_CSUM_DATA_IPv6_IPHL(m->m_pkthdr.csum_data);
   2702  1.65.2.2  martin 		break;
   2703  1.65.2.2  martin 	default:
   2704  1.65.2.2  martin 		len = 0;
   2705  1.65.2.2  martin 	}
   2706  1.65.2.2  martin 	cmd |= ((len >> 2) << IXL_TX_DESC_IPLEN_SHIFT);
   2707  1.65.2.2  martin 
   2708  1.65.2.2  martin 	if (m->m_pkthdr.csum_flags &
   2709  1.65.2.2  martin 	    (M_CSUM_TSOv4 | M_CSUM_TSOv6 | M_CSUM_TCPv4 | M_CSUM_TCPv6)) {
   2710  1.65.2.2  martin 		len = sizeof(struct tcphdr);
   2711  1.65.2.2  martin 		cmd |= IXL_TX_DESC_CMD_L4T_EOFT_TCP;
   2712  1.65.2.2  martin 	} else if (m->m_pkthdr.csum_flags & (M_CSUM_UDPv4 | M_CSUM_UDPv6)) {
   2713  1.65.2.2  martin 		len = sizeof(struct udphdr);
   2714  1.65.2.2  martin 		cmd |= IXL_TX_DESC_CMD_L4T_EOFT_UDP;
   2715  1.65.2.2  martin 	} else {
   2716  1.65.2.2  martin 		len = 0;
   2717  1.65.2.2  martin 	}
   2718  1.65.2.2  martin 	cmd |= ((len >> 2) << IXL_TX_DESC_L4LEN_SHIFT);
   2719  1.65.2.2  martin 
   2720  1.65.2.2  martin 	*cmd_txd |= cmd;
   2721  1.65.2.2  martin 	return 0;
   2722  1.65.2.2  martin }
   2723  1.65.2.2  martin 
   2724  1.65.2.2  martin static void
   2725  1.65.2.2  martin ixl_tx_common_locked(struct ifnet *ifp, struct ixl_tx_ring *txr,
   2726  1.65.2.2  martin     bool is_transmit)
   2727  1.65.2.2  martin {
   2728  1.65.2.2  martin 	struct ixl_softc *sc = ifp->if_softc;
   2729  1.65.2.2  martin 	struct ixl_tx_desc *ring, *txd;
   2730  1.65.2.2  martin 	struct ixl_tx_map *txm;
   2731  1.65.2.2  martin 	bus_dmamap_t map;
   2732  1.65.2.2  martin 	struct mbuf *m;
   2733  1.65.2.2  martin 	uint64_t cmd, cmd_txd;
   2734  1.65.2.2  martin 	unsigned int prod, free, last, i;
   2735  1.65.2.2  martin 	unsigned int mask;
   2736  1.65.2.2  martin 	int post = 0;
   2737  1.65.2.2  martin 
   2738  1.65.2.2  martin 	KASSERT(mutex_owned(&txr->txr_lock));
   2739  1.65.2.2  martin 
   2740  1.65.2.2  martin 	if (!ISSET(ifp->if_flags, IFF_RUNNING)
   2741  1.65.2.2  martin 	    || (!is_transmit && ISSET(ifp->if_flags, IFF_OACTIVE))) {
   2742  1.65.2.2  martin 		if (!is_transmit)
   2743  1.65.2.2  martin 			IFQ_PURGE(&ifp->if_snd);
   2744  1.65.2.2  martin 		return;
   2745  1.65.2.2  martin 	}
   2746  1.65.2.2  martin 
   2747  1.65.2.2  martin 	prod = txr->txr_prod;
   2748  1.65.2.2  martin 	free = txr->txr_cons;
   2749  1.65.2.2  martin 	if (free <= prod)
   2750  1.65.2.2  martin 		free += sc->sc_tx_ring_ndescs;
   2751  1.65.2.2  martin 	free -= prod;
   2752  1.65.2.2  martin 
   2753  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&txr->txr_mem),
   2754  1.65.2.2  martin 	    0, IXL_DMA_LEN(&txr->txr_mem), BUS_DMASYNC_POSTWRITE);
   2755  1.65.2.2  martin 
   2756  1.65.2.2  martin 	ring = IXL_DMA_KVA(&txr->txr_mem);
   2757  1.65.2.2  martin 	mask = sc->sc_tx_ring_ndescs - 1;
   2758  1.65.2.2  martin 	last = prod;
   2759  1.65.2.2  martin 	cmd = 0;
   2760  1.65.2.2  martin 	txd = NULL;
   2761  1.65.2.2  martin 
   2762  1.65.2.2  martin 	for (;;) {
   2763  1.65.2.2  martin 		if (free <= IXL_TX_PKT_DESCS) {
   2764  1.65.2.2  martin 			if (!is_transmit)
   2765  1.65.2.2  martin 				SET(ifp->if_flags, IFF_OACTIVE);
   2766  1.65.2.2  martin 			break;
   2767  1.65.2.2  martin 		}
   2768  1.65.2.2  martin 
   2769  1.65.2.2  martin 		if (is_transmit)
   2770  1.65.2.2  martin 			m = pcq_get(txr->txr_intrq);
   2771  1.65.2.2  martin 		else
   2772  1.65.2.2  martin 			IFQ_DEQUEUE(&ifp->if_snd, m);
   2773  1.65.2.2  martin 
   2774  1.65.2.2  martin 		if (m == NULL)
   2775  1.65.2.2  martin 			break;
   2776  1.65.2.2  martin 
   2777  1.65.2.2  martin 		txm = &txr->txr_maps[prod];
   2778  1.65.2.2  martin 		map = txm->txm_map;
   2779  1.65.2.2  martin 
   2780  1.65.2.2  martin 		if (ixl_load_mbuf(sc->sc_dmat, map, &m, txr) != 0) {
   2781  1.65.2.2  martin 			if_statinc(ifp, if_oerrors);
   2782  1.65.2.2  martin 			m_freem(m);
   2783  1.65.2.2  martin 			continue;
   2784  1.65.2.2  martin 		}
   2785  1.65.2.2  martin 
   2786  1.65.2.2  martin 		cmd_txd = 0;
   2787  1.65.2.2  martin 		if (m->m_pkthdr.csum_flags & IXL_CSUM_ALL_OFFLOAD) {
   2788  1.65.2.2  martin 			ixl_tx_setup_offloads(m, &cmd_txd);
   2789  1.65.2.2  martin 		}
   2790  1.65.2.2  martin 
   2791  1.65.2.2  martin 		if (vlan_has_tag(m)) {
   2792  1.65.2.2  martin 			cmd_txd |= (uint64_t)vlan_get_tag(m) <<
   2793  1.65.2.2  martin 			    IXL_TX_DESC_L2TAG1_SHIFT;
   2794  1.65.2.2  martin 			cmd_txd |= IXL_TX_DESC_CMD_IL2TAG1;
   2795  1.65.2.2  martin 		}
   2796  1.65.2.2  martin 
   2797  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, map, 0,
   2798  1.65.2.2  martin 		    map->dm_mapsize, BUS_DMASYNC_PREWRITE);
   2799  1.65.2.2  martin 
   2800  1.65.2.2  martin 		for (i = 0; i < (unsigned int)map->dm_nsegs; i++) {
   2801  1.65.2.2  martin 			txd = &ring[prod];
   2802  1.65.2.2  martin 
   2803  1.65.2.2  martin 			cmd = (uint64_t)map->dm_segs[i].ds_len <<
   2804  1.65.2.2  martin 			    IXL_TX_DESC_BSIZE_SHIFT;
   2805  1.65.2.2  martin 			cmd |= IXL_TX_DESC_DTYPE_DATA | IXL_TX_DESC_CMD_ICRC;
   2806  1.65.2.2  martin 			cmd |= cmd_txd;
   2807  1.65.2.2  martin 
   2808  1.65.2.2  martin 			txd->addr = htole64(map->dm_segs[i].ds_addr);
   2809  1.65.2.2  martin 			txd->cmd = htole64(cmd);
   2810  1.65.2.2  martin 
   2811  1.65.2.2  martin 			last = prod;
   2812  1.65.2.2  martin 
   2813  1.65.2.2  martin 			prod++;
   2814  1.65.2.2  martin 			prod &= mask;
   2815  1.65.2.2  martin 		}
   2816  1.65.2.2  martin 		cmd |= IXL_TX_DESC_CMD_EOP | IXL_TX_DESC_CMD_RS;
   2817  1.65.2.2  martin 		txd->cmd = htole64(cmd);
   2818  1.65.2.2  martin 
   2819  1.65.2.2  martin 		txm->txm_m = m;
   2820  1.65.2.2  martin 		txm->txm_eop = last;
   2821  1.65.2.2  martin 
   2822  1.65.2.2  martin 		bpf_mtap(ifp, m, BPF_D_OUT);
   2823  1.65.2.2  martin 
   2824  1.65.2.2  martin 		free -= i;
   2825  1.65.2.2  martin 		post = 1;
   2826  1.65.2.2  martin 	}
   2827  1.65.2.2  martin 
   2828  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&txr->txr_mem),
   2829  1.65.2.2  martin 	    0, IXL_DMA_LEN(&txr->txr_mem), BUS_DMASYNC_PREWRITE);
   2830  1.65.2.2  martin 
   2831  1.65.2.2  martin 	if (post) {
   2832  1.65.2.2  martin 		txr->txr_prod = prod;
   2833  1.65.2.2  martin 		ixl_wr(sc, txr->txr_tail, prod);
   2834  1.65.2.2  martin 	}
   2835  1.65.2.2  martin }
   2836  1.65.2.2  martin 
   2837  1.65.2.2  martin static int
   2838  1.65.2.2  martin ixl_txeof(struct ixl_softc *sc, struct ixl_tx_ring *txr, u_int txlimit)
   2839  1.65.2.2  martin {
   2840  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   2841  1.65.2.2  martin 	struct ixl_tx_desc *ring, *txd;
   2842  1.65.2.2  martin 	struct ixl_tx_map *txm;
   2843  1.65.2.2  martin 	struct mbuf *m;
   2844  1.65.2.2  martin 	bus_dmamap_t map;
   2845  1.65.2.2  martin 	unsigned int cons, prod, last;
   2846  1.65.2.2  martin 	unsigned int mask;
   2847  1.65.2.2  martin 	uint64_t dtype;
   2848  1.65.2.2  martin 	int done = 0, more = 0;
   2849  1.65.2.2  martin 
   2850  1.65.2.2  martin 	KASSERT(mutex_owned(&txr->txr_lock));
   2851  1.65.2.2  martin 
   2852  1.65.2.2  martin 	prod = txr->txr_prod;
   2853  1.65.2.2  martin 	cons = txr->txr_cons;
   2854  1.65.2.2  martin 
   2855  1.65.2.2  martin 	if (cons == prod)
   2856  1.65.2.2  martin 		return 0;
   2857  1.65.2.2  martin 
   2858  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&txr->txr_mem),
   2859  1.65.2.2  martin 	    0, IXL_DMA_LEN(&txr->txr_mem), BUS_DMASYNC_POSTREAD);
   2860  1.65.2.2  martin 
   2861  1.65.2.2  martin 	ring = IXL_DMA_KVA(&txr->txr_mem);
   2862  1.65.2.2  martin 	mask = sc->sc_tx_ring_ndescs - 1;
   2863  1.65.2.2  martin 
   2864  1.65.2.2  martin 	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
   2865  1.65.2.2  martin 
   2866  1.65.2.2  martin 	do {
   2867  1.65.2.2  martin 		if (txlimit-- <= 0) {
   2868  1.65.2.2  martin 			more = 1;
   2869  1.65.2.2  martin 			break;
   2870  1.65.2.2  martin 		}
   2871  1.65.2.2  martin 
   2872  1.65.2.2  martin 		txm = &txr->txr_maps[cons];
   2873  1.65.2.2  martin 		last = txm->txm_eop;
   2874  1.65.2.2  martin 		txd = &ring[last];
   2875  1.65.2.2  martin 
   2876  1.65.2.2  martin 		dtype = txd->cmd & htole64(IXL_TX_DESC_DTYPE_MASK);
   2877  1.65.2.2  martin 		if (dtype != htole64(IXL_TX_DESC_DTYPE_DONE))
   2878  1.65.2.2  martin 			break;
   2879  1.65.2.2  martin 
   2880  1.65.2.2  martin 		map = txm->txm_map;
   2881  1.65.2.2  martin 
   2882  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
   2883  1.65.2.2  martin 		    BUS_DMASYNC_POSTWRITE);
   2884  1.65.2.2  martin 		bus_dmamap_unload(sc->sc_dmat, map);
   2885  1.65.2.2  martin 
   2886  1.65.2.2  martin 		m = txm->txm_m;
   2887  1.65.2.2  martin 		if (m != NULL) {
   2888  1.65.2.2  martin 			if_statinc_ref(nsr, if_opackets);
   2889  1.65.2.2  martin 			if_statadd_ref(nsr, if_obytes, m->m_pkthdr.len);
   2890  1.65.2.2  martin 			if (ISSET(m->m_flags, M_MCAST))
   2891  1.65.2.2  martin 				if_statinc_ref(nsr, if_omcasts);
   2892  1.65.2.2  martin 			m_freem(m);
   2893  1.65.2.2  martin 		}
   2894  1.65.2.2  martin 
   2895  1.65.2.2  martin 		txm->txm_m = NULL;
   2896  1.65.2.2  martin 		txm->txm_eop = -1;
   2897  1.65.2.2  martin 
   2898  1.65.2.2  martin 		cons = last + 1;
   2899  1.65.2.2  martin 		cons &= mask;
   2900  1.65.2.2  martin 		done = 1;
   2901  1.65.2.2  martin 	} while (cons != prod);
   2902  1.65.2.2  martin 
   2903  1.65.2.2  martin 	IF_STAT_PUTREF(ifp);
   2904  1.65.2.2  martin 
   2905  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&txr->txr_mem),
   2906  1.65.2.2  martin 	    0, IXL_DMA_LEN(&txr->txr_mem), BUS_DMASYNC_PREREAD);
   2907  1.65.2.2  martin 
   2908  1.65.2.2  martin 	txr->txr_cons = cons;
   2909  1.65.2.2  martin 
   2910  1.65.2.2  martin 	if (done) {
   2911  1.65.2.2  martin 		softint_schedule(txr->txr_si);
   2912  1.65.2.2  martin 		if (txr->txr_qid == 0) {
   2913  1.65.2.2  martin 			CLR(ifp->if_flags, IFF_OACTIVE);
   2914  1.65.2.2  martin 			if_schedule_deferred_start(ifp);
   2915  1.65.2.2  martin 		}
   2916  1.65.2.2  martin 	}
   2917  1.65.2.2  martin 
   2918  1.65.2.2  martin 	return more;
   2919  1.65.2.2  martin }
   2920  1.65.2.2  martin 
   2921  1.65.2.2  martin static void
   2922  1.65.2.2  martin ixl_start(struct ifnet *ifp)
   2923  1.65.2.2  martin {
   2924  1.65.2.2  martin 	struct ixl_softc	*sc;
   2925  1.65.2.2  martin 	struct ixl_tx_ring	*txr;
   2926  1.65.2.2  martin 
   2927  1.65.2.2  martin 	sc = ifp->if_softc;
   2928  1.65.2.2  martin 	txr = sc->sc_qps[0].qp_txr;
   2929  1.65.2.2  martin 
   2930  1.65.2.2  martin 	mutex_enter(&txr->txr_lock);
   2931  1.65.2.2  martin 	ixl_tx_common_locked(ifp, txr, false);
   2932  1.65.2.2  martin 	mutex_exit(&txr->txr_lock);
   2933  1.65.2.2  martin }
   2934  1.65.2.2  martin 
   2935  1.65.2.2  martin static inline unsigned int
   2936  1.65.2.2  martin ixl_select_txqueue(struct ixl_softc *sc, struct mbuf *m)
   2937  1.65.2.2  martin {
   2938  1.65.2.2  martin 	u_int cpuid;
   2939  1.65.2.2  martin 
   2940  1.65.2.2  martin 	cpuid = cpu_index(curcpu());
   2941  1.65.2.2  martin 
   2942  1.65.2.2  martin 	return (unsigned int)(cpuid % sc->sc_nqueue_pairs);
   2943  1.65.2.2  martin }
   2944  1.65.2.2  martin 
   2945  1.65.2.2  martin static int
   2946  1.65.2.2  martin ixl_transmit(struct ifnet *ifp, struct mbuf *m)
   2947  1.65.2.2  martin {
   2948  1.65.2.2  martin 	struct ixl_softc *sc;
   2949  1.65.2.2  martin 	struct ixl_tx_ring *txr;
   2950  1.65.2.2  martin 	unsigned int qid;
   2951  1.65.2.2  martin 
   2952  1.65.2.2  martin 	sc = ifp->if_softc;
   2953  1.65.2.2  martin 	qid = ixl_select_txqueue(sc, m);
   2954  1.65.2.2  martin 
   2955  1.65.2.2  martin 	txr = sc->sc_qps[qid].qp_txr;
   2956  1.65.2.2  martin 
   2957  1.65.2.2  martin 	if (__predict_false(!pcq_put(txr->txr_intrq, m))) {
   2958  1.65.2.2  martin 		mutex_enter(&txr->txr_lock);
   2959  1.65.2.2  martin 		txr->txr_pcqdrop.ev_count++;
   2960  1.65.2.2  martin 		mutex_exit(&txr->txr_lock);
   2961  1.65.2.2  martin 
   2962  1.65.2.2  martin 		m_freem(m);
   2963  1.65.2.2  martin 		return ENOBUFS;
   2964  1.65.2.2  martin 	}
   2965  1.65.2.2  martin 
   2966  1.65.2.2  martin 	if (mutex_tryenter(&txr->txr_lock)) {
   2967  1.65.2.2  martin 		ixl_tx_common_locked(ifp, txr, true);
   2968  1.65.2.2  martin 		mutex_exit(&txr->txr_lock);
   2969  1.65.2.2  martin 	} else {
   2970  1.65.2.2  martin 		kpreempt_disable();
   2971  1.65.2.2  martin 		softint_schedule(txr->txr_si);
   2972  1.65.2.2  martin 		kpreempt_enable();
   2973  1.65.2.2  martin 	}
   2974  1.65.2.2  martin 
   2975  1.65.2.2  martin 	return 0;
   2976  1.65.2.2  martin }
   2977  1.65.2.2  martin 
   2978  1.65.2.2  martin static void
   2979  1.65.2.2  martin ixl_deferred_transmit(void *xtxr)
   2980  1.65.2.2  martin {
   2981  1.65.2.2  martin 	struct ixl_tx_ring *txr = xtxr;
   2982  1.65.2.2  martin 	struct ixl_softc *sc = txr->txr_sc;
   2983  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   2984  1.65.2.2  martin 
   2985  1.65.2.2  martin 	mutex_enter(&txr->txr_lock);
   2986  1.65.2.2  martin 	txr->txr_transmitdef.ev_count++;
   2987  1.65.2.2  martin 	if (pcq_peek(txr->txr_intrq) != NULL)
   2988  1.65.2.2  martin 		ixl_tx_common_locked(ifp, txr, true);
   2989  1.65.2.2  martin 	mutex_exit(&txr->txr_lock);
   2990  1.65.2.2  martin }
   2991  1.65.2.2  martin 
   2992  1.65.2.2  martin static struct ixl_rx_ring *
   2993  1.65.2.2  martin ixl_rxr_alloc(struct ixl_softc *sc, unsigned int qid)
   2994  1.65.2.2  martin {
   2995  1.65.2.2  martin 	struct ixl_rx_ring *rxr = NULL;
   2996  1.65.2.2  martin 	struct ixl_rx_map *maps = NULL, *rxm;
   2997  1.65.2.2  martin 	unsigned int i;
   2998  1.65.2.2  martin 
   2999  1.65.2.2  martin 	rxr = kmem_zalloc(sizeof(*rxr), KM_SLEEP);
   3000  1.65.2.2  martin 	maps = kmem_zalloc(sizeof(maps[0]) * sc->sc_rx_ring_ndescs,
   3001  1.65.2.2  martin 	    KM_SLEEP);
   3002  1.65.2.2  martin 
   3003  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &rxr->rxr_mem,
   3004  1.65.2.2  martin 	    sizeof(struct ixl_rx_rd_desc_32) * sc->sc_rx_ring_ndescs,
   3005  1.65.2.2  martin 	    IXL_RX_QUEUE_ALIGN) != 0)
   3006  1.65.2.2  martin 		goto free;
   3007  1.65.2.2  martin 
   3008  1.65.2.2  martin 	for (i = 0; i < sc->sc_rx_ring_ndescs; i++) {
   3009  1.65.2.2  martin 		rxm = &maps[i];
   3010  1.65.2.2  martin 
   3011  1.65.2.2  martin 		if (bus_dmamap_create(sc->sc_dmat,
   3012  1.65.2.2  martin 		    IXL_MCLBYTES, 1, IXL_MCLBYTES, 0,
   3013  1.65.2.2  martin 		    BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW, &rxm->rxm_map) != 0)
   3014  1.65.2.2  martin 			goto uncreate;
   3015  1.65.2.2  martin 
   3016  1.65.2.2  martin 		rxm->rxm_m = NULL;
   3017  1.65.2.2  martin 	}
   3018  1.65.2.2  martin 
   3019  1.65.2.2  martin 	rxr->rxr_cons = rxr->rxr_prod = 0;
   3020  1.65.2.2  martin 	rxr->rxr_m_head = NULL;
   3021  1.65.2.2  martin 	rxr->rxr_m_tail = &rxr->rxr_m_head;
   3022  1.65.2.2  martin 	rxr->rxr_maps = maps;
   3023  1.65.2.2  martin 
   3024  1.65.2.2  martin 	rxr->rxr_tail = I40E_QRX_TAIL(qid);
   3025  1.65.2.2  martin 	rxr->rxr_qid = qid;
   3026  1.65.2.2  martin 	mutex_init(&rxr->rxr_lock, MUTEX_DEFAULT, IPL_NET);
   3027  1.65.2.2  martin 
   3028  1.65.2.2  martin 	return rxr;
   3029  1.65.2.2  martin 
   3030  1.65.2.2  martin uncreate:
   3031  1.65.2.2  martin 	for (i = 0; i < sc->sc_rx_ring_ndescs; i++) {
   3032  1.65.2.2  martin 		rxm = &maps[i];
   3033  1.65.2.2  martin 
   3034  1.65.2.2  martin 		if (rxm->rxm_map == NULL)
   3035  1.65.2.2  martin 			continue;
   3036  1.65.2.2  martin 
   3037  1.65.2.2  martin 		bus_dmamap_destroy(sc->sc_dmat, rxm->rxm_map);
   3038  1.65.2.2  martin 	}
   3039  1.65.2.2  martin 
   3040  1.65.2.2  martin 	ixl_dmamem_free(sc, &rxr->rxr_mem);
   3041  1.65.2.2  martin free:
   3042  1.65.2.2  martin 	kmem_free(maps, sizeof(maps[0]) * sc->sc_rx_ring_ndescs);
   3043  1.65.2.2  martin 	kmem_free(rxr, sizeof(*rxr));
   3044  1.65.2.2  martin 
   3045  1.65.2.2  martin 	return NULL;
   3046  1.65.2.2  martin }
   3047  1.65.2.2  martin 
   3048  1.65.2.2  martin static void
   3049  1.65.2.2  martin ixl_rxr_clean(struct ixl_softc *sc, struct ixl_rx_ring *rxr)
   3050  1.65.2.2  martin {
   3051  1.65.2.2  martin 	struct ixl_rx_map *maps, *rxm;
   3052  1.65.2.2  martin 	bus_dmamap_t map;
   3053  1.65.2.2  martin 	unsigned int i;
   3054  1.65.2.2  martin 
   3055  1.65.2.2  martin 	maps = rxr->rxr_maps;
   3056  1.65.2.2  martin 	for (i = 0; i < sc->sc_rx_ring_ndescs; i++) {
   3057  1.65.2.2  martin 		rxm = &maps[i];
   3058  1.65.2.2  martin 
   3059  1.65.2.2  martin 		if (rxm->rxm_m == NULL)
   3060  1.65.2.2  martin 			continue;
   3061  1.65.2.2  martin 
   3062  1.65.2.2  martin 		map = rxm->rxm_map;
   3063  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
   3064  1.65.2.2  martin 		    BUS_DMASYNC_POSTWRITE);
   3065  1.65.2.2  martin 		bus_dmamap_unload(sc->sc_dmat, map);
   3066  1.65.2.2  martin 
   3067  1.65.2.2  martin 		m_freem(rxm->rxm_m);
   3068  1.65.2.2  martin 		rxm->rxm_m = NULL;
   3069  1.65.2.2  martin 	}
   3070  1.65.2.2  martin 
   3071  1.65.2.2  martin 	m_freem(rxr->rxr_m_head);
   3072  1.65.2.2  martin 	rxr->rxr_m_head = NULL;
   3073  1.65.2.2  martin 	rxr->rxr_m_tail = &rxr->rxr_m_head;
   3074  1.65.2.2  martin 
   3075  1.65.2.2  martin 	rxr->rxr_prod = rxr->rxr_cons = 0;
   3076  1.65.2.2  martin }
   3077  1.65.2.2  martin 
   3078  1.65.2.2  martin static int
   3079  1.65.2.2  martin ixl_rxr_enabled(struct ixl_softc *sc, struct ixl_rx_ring *rxr)
   3080  1.65.2.2  martin {
   3081  1.65.2.2  martin 	bus_size_t ena = I40E_QRX_ENA(rxr->rxr_qid);
   3082  1.65.2.2  martin 	uint32_t reg;
   3083  1.65.2.2  martin 	int i;
   3084  1.65.2.2  martin 
   3085  1.65.2.2  martin 	for (i = 0; i < 10; i++) {
   3086  1.65.2.2  martin 		reg = ixl_rd(sc, ena);
   3087  1.65.2.2  martin 		if (ISSET(reg, I40E_QRX_ENA_QENA_STAT_MASK))
   3088  1.65.2.2  martin 			return 0;
   3089  1.65.2.2  martin 
   3090  1.65.2.2  martin 		delaymsec(10);
   3091  1.65.2.2  martin 	}
   3092  1.65.2.2  martin 
   3093  1.65.2.2  martin 	return ETIMEDOUT;
   3094  1.65.2.2  martin }
   3095  1.65.2.2  martin 
   3096  1.65.2.2  martin static int
   3097  1.65.2.2  martin ixl_rxr_disabled(struct ixl_softc *sc, struct ixl_rx_ring *rxr)
   3098  1.65.2.2  martin {
   3099  1.65.2.2  martin 	bus_size_t ena = I40E_QRX_ENA(rxr->rxr_qid);
   3100  1.65.2.2  martin 	uint32_t reg;
   3101  1.65.2.2  martin 	int i;
   3102  1.65.2.2  martin 
   3103  1.65.2.2  martin 	KASSERT(mutex_owned(&rxr->rxr_lock));
   3104  1.65.2.2  martin 
   3105  1.65.2.2  martin 	for (i = 0; i < 10; i++) {
   3106  1.65.2.2  martin 		reg = ixl_rd(sc, ena);
   3107  1.65.2.2  martin 		if (ISSET(reg, I40E_QRX_ENA_QENA_STAT_MASK) == 0)
   3108  1.65.2.2  martin 			return 0;
   3109  1.65.2.2  martin 
   3110  1.65.2.2  martin 		delaymsec(10);
   3111  1.65.2.2  martin 	}
   3112  1.65.2.2  martin 
   3113  1.65.2.2  martin 	return ETIMEDOUT;
   3114  1.65.2.2  martin }
   3115  1.65.2.2  martin 
   3116  1.65.2.2  martin static void
   3117  1.65.2.2  martin ixl_rxr_config(struct ixl_softc *sc, struct ixl_rx_ring *rxr)
   3118  1.65.2.2  martin {
   3119  1.65.2.2  martin 	struct ixl_hmc_rxq rxq;
   3120  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   3121  1.65.2.2  martin 	uint16_t rxmax;
   3122  1.65.2.2  martin 	void *hmc;
   3123  1.65.2.2  martin 
   3124  1.65.2.2  martin 	memset(&rxq, 0, sizeof(rxq));
   3125  1.65.2.2  martin 	rxmax = ifp->if_mtu + IXL_MTU_ETHERLEN;
   3126  1.65.2.2  martin 
   3127  1.65.2.2  martin 	rxq.head = htole16(rxr->rxr_cons);
   3128  1.65.2.2  martin 	rxq.base = htole64(IXL_DMA_DVA(&rxr->rxr_mem) / IXL_HMC_RXQ_BASE_UNIT);
   3129  1.65.2.2  martin 	rxq.qlen = htole16(sc->sc_rx_ring_ndescs);
   3130  1.65.2.2  martin 	rxq.dbuff = htole16(IXL_MCLBYTES / IXL_HMC_RXQ_DBUFF_UNIT);
   3131  1.65.2.2  martin 	rxq.hbuff = 0;
   3132  1.65.2.2  martin 	rxq.dtype = IXL_HMC_RXQ_DTYPE_NOSPLIT;
   3133  1.65.2.2  martin 	rxq.dsize = IXL_HMC_RXQ_DSIZE_32;
   3134  1.65.2.2  martin 	rxq.crcstrip = 1;
   3135  1.65.2.2  martin 	rxq.l2sel = 1;
   3136  1.65.2.2  martin 	rxq.showiv = 1;
   3137  1.65.2.2  martin 	rxq.rxmax = htole16(rxmax);
   3138  1.65.2.2  martin 	rxq.tphrdesc_ena = 0;
   3139  1.65.2.2  martin 	rxq.tphwdesc_ena = 0;
   3140  1.65.2.2  martin 	rxq.tphdata_ena = 0;
   3141  1.65.2.2  martin 	rxq.tphhead_ena = 0;
   3142  1.65.2.2  martin 	rxq.lrxqthresh = 0;
   3143  1.65.2.2  martin 	rxq.prefena = 1;
   3144  1.65.2.2  martin 
   3145  1.65.2.2  martin 	hmc = ixl_hmc_kva(sc, IXL_HMC_LAN_RX, rxr->rxr_qid);
   3146  1.65.2.2  martin 	memset(hmc, 0, ixl_hmc_len(sc, IXL_HMC_LAN_RX));
   3147  1.65.2.2  martin 	ixl_hmc_pack(hmc, &rxq, ixl_hmc_pack_rxq,
   3148  1.65.2.2  martin 	    __arraycount(ixl_hmc_pack_rxq));
   3149  1.65.2.2  martin }
   3150  1.65.2.2  martin 
   3151  1.65.2.2  martin static void
   3152  1.65.2.2  martin ixl_rxr_unconfig(struct ixl_softc *sc, struct ixl_rx_ring *rxr)
   3153  1.65.2.2  martin {
   3154  1.65.2.2  martin 	void *hmc;
   3155  1.65.2.2  martin 
   3156  1.65.2.2  martin 	hmc = ixl_hmc_kva(sc, IXL_HMC_LAN_RX, rxr->rxr_qid);
   3157  1.65.2.2  martin 	memset(hmc, 0, ixl_hmc_len(sc, IXL_HMC_LAN_RX));
   3158  1.65.2.2  martin 	rxr->rxr_cons = rxr->rxr_prod = 0;
   3159  1.65.2.2  martin }
   3160  1.65.2.2  martin 
   3161  1.65.2.2  martin static void
   3162  1.65.2.2  martin ixl_rxr_free(struct ixl_softc *sc, struct ixl_rx_ring *rxr)
   3163  1.65.2.2  martin {
   3164  1.65.2.2  martin 	struct ixl_rx_map *maps, *rxm;
   3165  1.65.2.2  martin 	unsigned int i;
   3166  1.65.2.2  martin 
   3167  1.65.2.2  martin 	maps = rxr->rxr_maps;
   3168  1.65.2.2  martin 	for (i = 0; i < sc->sc_rx_ring_ndescs; i++) {
   3169  1.65.2.2  martin 		rxm = &maps[i];
   3170  1.65.2.2  martin 
   3171  1.65.2.2  martin 		bus_dmamap_destroy(sc->sc_dmat, rxm->rxm_map);
   3172  1.65.2.2  martin 	}
   3173  1.65.2.2  martin 
   3174  1.65.2.2  martin 	ixl_dmamem_free(sc, &rxr->rxr_mem);
   3175  1.65.2.2  martin 	mutex_destroy(&rxr->rxr_lock);
   3176  1.65.2.2  martin 	kmem_free(maps, sizeof(maps[0]) * sc->sc_rx_ring_ndescs);
   3177  1.65.2.2  martin 	kmem_free(rxr, sizeof(*rxr));
   3178  1.65.2.2  martin }
   3179  1.65.2.2  martin 
   3180  1.65.2.2  martin static inline void
   3181  1.65.2.2  martin ixl_rx_csum(struct mbuf *m, uint64_t qword)
   3182  1.65.2.2  martin {
   3183  1.65.2.2  martin 	int flags_mask;
   3184  1.65.2.2  martin 
   3185  1.65.2.2  martin 	if (!ISSET(qword, IXL_RX_DESC_L3L4P)) {
   3186  1.65.2.2  martin 		/* No L3 or L4 checksum was calculated */
   3187  1.65.2.2  martin 		return;
   3188  1.65.2.2  martin 	}
   3189  1.65.2.2  martin 
   3190  1.65.2.2  martin 	switch (__SHIFTOUT(qword, IXL_RX_DESC_PTYPE_MASK)) {
   3191  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_IPV4FRAG:
   3192  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_IPV4:
   3193  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_SCTPV4:
   3194  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_ICMPV4:
   3195  1.65.2.2  martin 		flags_mask = M_CSUM_IPv4 | M_CSUM_IPv4_BAD;
   3196  1.65.2.2  martin 		break;
   3197  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_TCPV4:
   3198  1.65.2.2  martin 		flags_mask = M_CSUM_IPv4 | M_CSUM_IPv4_BAD;
   3199  1.65.2.2  martin 		flags_mask |= M_CSUM_TCPv4 | M_CSUM_TCP_UDP_BAD;
   3200  1.65.2.2  martin 		break;
   3201  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_UDPV4:
   3202  1.65.2.2  martin 		flags_mask = M_CSUM_IPv4 | M_CSUM_IPv4_BAD;
   3203  1.65.2.2  martin 		flags_mask |= M_CSUM_UDPv4 | M_CSUM_TCP_UDP_BAD;
   3204  1.65.2.2  martin 		break;
   3205  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_TCPV6:
   3206  1.65.2.2  martin 		flags_mask = M_CSUM_TCPv6 | M_CSUM_TCP_UDP_BAD;
   3207  1.65.2.2  martin 		break;
   3208  1.65.2.2  martin 	case IXL_RX_DESC_PTYPE_UDPV6:
   3209  1.65.2.2  martin 		flags_mask = M_CSUM_UDPv6 | M_CSUM_TCP_UDP_BAD;
   3210  1.65.2.2  martin 		break;
   3211  1.65.2.2  martin 	default:
   3212  1.65.2.2  martin 		flags_mask = 0;
   3213  1.65.2.2  martin 	}
   3214  1.65.2.2  martin 
   3215  1.65.2.2  martin 	m->m_pkthdr.csum_flags |= (flags_mask & (M_CSUM_IPv4 |
   3216  1.65.2.2  martin 	    M_CSUM_TCPv4 | M_CSUM_TCPv6 | M_CSUM_UDPv4 | M_CSUM_UDPv6));
   3217  1.65.2.2  martin 
   3218  1.65.2.2  martin 	if (ISSET(qword, IXL_RX_DESC_IPE)) {
   3219  1.65.2.2  martin 		m->m_pkthdr.csum_flags |= (flags_mask & M_CSUM_IPv4_BAD);
   3220  1.65.2.2  martin 	}
   3221  1.65.2.2  martin 
   3222  1.65.2.2  martin 	if (ISSET(qword, IXL_RX_DESC_L4E)) {
   3223  1.65.2.2  martin 		m->m_pkthdr.csum_flags |= (flags_mask & M_CSUM_TCP_UDP_BAD);
   3224  1.65.2.2  martin 	}
   3225  1.65.2.2  martin }
   3226  1.65.2.2  martin 
   3227  1.65.2.2  martin static int
   3228  1.65.2.2  martin ixl_rxeof(struct ixl_softc *sc, struct ixl_rx_ring *rxr, u_int rxlimit)
   3229  1.65.2.2  martin {
   3230  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   3231  1.65.2.2  martin 	struct ixl_rx_wb_desc_32 *ring, *rxd;
   3232  1.65.2.2  martin 	struct ixl_rx_map *rxm;
   3233  1.65.2.2  martin 	bus_dmamap_t map;
   3234  1.65.2.2  martin 	unsigned int cons, prod;
   3235  1.65.2.2  martin 	struct mbuf *m;
   3236  1.65.2.2  martin 	uint64_t word, word0;
   3237  1.65.2.2  martin 	unsigned int len;
   3238  1.65.2.2  martin 	unsigned int mask;
   3239  1.65.2.2  martin 	int done = 0, more = 0;
   3240  1.65.2.2  martin 
   3241  1.65.2.2  martin 	KASSERT(mutex_owned(&rxr->rxr_lock));
   3242  1.65.2.2  martin 
   3243  1.65.2.2  martin 	if (!ISSET(ifp->if_flags, IFF_RUNNING))
   3244  1.65.2.2  martin 		return 0;
   3245  1.65.2.2  martin 
   3246  1.65.2.2  martin 	prod = rxr->rxr_prod;
   3247  1.65.2.2  martin 	cons = rxr->rxr_cons;
   3248  1.65.2.2  martin 
   3249  1.65.2.2  martin 	if (cons == prod)
   3250  1.65.2.2  martin 		return 0;
   3251  1.65.2.2  martin 
   3252  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&rxr->rxr_mem),
   3253  1.65.2.2  martin 	    0, IXL_DMA_LEN(&rxr->rxr_mem),
   3254  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   3255  1.65.2.2  martin 
   3256  1.65.2.2  martin 	ring = IXL_DMA_KVA(&rxr->rxr_mem);
   3257  1.65.2.2  martin 	mask = sc->sc_rx_ring_ndescs - 1;
   3258  1.65.2.2  martin 
   3259  1.65.2.2  martin 	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
   3260  1.65.2.2  martin 
   3261  1.65.2.2  martin 	do {
   3262  1.65.2.2  martin 		if (rxlimit-- <= 0) {
   3263  1.65.2.2  martin 			more = 1;
   3264  1.65.2.2  martin 			break;
   3265  1.65.2.2  martin 		}
   3266  1.65.2.2  martin 
   3267  1.65.2.2  martin 		rxd = &ring[cons];
   3268  1.65.2.2  martin 
   3269  1.65.2.2  martin 		word = le64toh(rxd->qword1);
   3270  1.65.2.2  martin 
   3271  1.65.2.2  martin 		if (!ISSET(word, IXL_RX_DESC_DD))
   3272  1.65.2.2  martin 			break;
   3273  1.65.2.2  martin 
   3274  1.65.2.2  martin 		rxm = &rxr->rxr_maps[cons];
   3275  1.65.2.2  martin 
   3276  1.65.2.2  martin 		map = rxm->rxm_map;
   3277  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
   3278  1.65.2.2  martin 		    BUS_DMASYNC_POSTREAD);
   3279  1.65.2.2  martin 		bus_dmamap_unload(sc->sc_dmat, map);
   3280  1.65.2.2  martin 
   3281  1.65.2.2  martin 		m = rxm->rxm_m;
   3282  1.65.2.2  martin 		rxm->rxm_m = NULL;
   3283  1.65.2.2  martin 
   3284  1.65.2.2  martin 		KASSERT(m != NULL);
   3285  1.65.2.2  martin 
   3286  1.65.2.2  martin 		len = (word & IXL_RX_DESC_PLEN_MASK) >> IXL_RX_DESC_PLEN_SHIFT;
   3287  1.65.2.2  martin 		m->m_len = len;
   3288  1.65.2.2  martin 		m->m_pkthdr.len = 0;
   3289  1.65.2.2  martin 
   3290  1.65.2.2  martin 		m->m_next = NULL;
   3291  1.65.2.2  martin 		*rxr->rxr_m_tail = m;
   3292  1.65.2.2  martin 		rxr->rxr_m_tail = &m->m_next;
   3293  1.65.2.2  martin 
   3294  1.65.2.2  martin 		m = rxr->rxr_m_head;
   3295  1.65.2.2  martin 		m->m_pkthdr.len += len;
   3296  1.65.2.2  martin 
   3297  1.65.2.2  martin 		if (ISSET(word, IXL_RX_DESC_EOP)) {
   3298  1.65.2.2  martin 			word0 = le64toh(rxd->qword0);
   3299  1.65.2.2  martin 
   3300  1.65.2.2  martin 			if (ISSET(word, IXL_RX_DESC_L2TAG1P)) {
   3301  1.65.2.2  martin 				vlan_set_tag(m,
   3302  1.65.2.2  martin 				    __SHIFTOUT(word0, IXL_RX_DESC_L2TAG1_MASK));
   3303  1.65.2.2  martin 			}
   3304  1.65.2.2  martin 
   3305  1.65.2.2  martin 			if ((ifp->if_capenable & IXL_IFCAP_RXCSUM) != 0)
   3306  1.65.2.2  martin 				ixl_rx_csum(m, word);
   3307  1.65.2.2  martin 
   3308  1.65.2.2  martin 			if (!ISSET(word,
   3309  1.65.2.2  martin 			    IXL_RX_DESC_RXE | IXL_RX_DESC_OVERSIZE)) {
   3310  1.65.2.2  martin 				m_set_rcvif(m, ifp);
   3311  1.65.2.2  martin 				if_statinc_ref(nsr, if_ipackets);
   3312  1.65.2.2  martin 				if_statadd_ref(nsr, if_ibytes,
   3313  1.65.2.2  martin 				    m->m_pkthdr.len);
   3314  1.65.2.2  martin 				if_percpuq_enqueue(ifp->if_percpuq, m);
   3315  1.65.2.2  martin 			} else {
   3316  1.65.2.2  martin 				if_statinc_ref(nsr, if_ierrors);
   3317  1.65.2.2  martin 				m_freem(m);
   3318  1.65.2.2  martin 			}
   3319  1.65.2.2  martin 
   3320  1.65.2.2  martin 			rxr->rxr_m_head = NULL;
   3321  1.65.2.2  martin 			rxr->rxr_m_tail = &rxr->rxr_m_head;
   3322  1.65.2.2  martin 		}
   3323  1.65.2.2  martin 
   3324  1.65.2.2  martin 		cons++;
   3325  1.65.2.2  martin 		cons &= mask;
   3326  1.65.2.2  martin 
   3327  1.65.2.2  martin 		done = 1;
   3328  1.65.2.2  martin 	} while (cons != prod);
   3329  1.65.2.2  martin 
   3330  1.65.2.2  martin 	if (done) {
   3331  1.65.2.2  martin 		rxr->rxr_cons = cons;
   3332  1.65.2.2  martin 		if (ixl_rxfill(sc, rxr) == -1)
   3333  1.65.2.2  martin 			if_statinc_ref(nsr, if_iqdrops);
   3334  1.65.2.2  martin 	}
   3335  1.65.2.2  martin 
   3336  1.65.2.2  martin 	IF_STAT_PUTREF(ifp);
   3337  1.65.2.2  martin 
   3338  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&rxr->rxr_mem),
   3339  1.65.2.2  martin 	    0, IXL_DMA_LEN(&rxr->rxr_mem),
   3340  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   3341  1.65.2.2  martin 
   3342  1.65.2.2  martin 	return more;
   3343  1.65.2.2  martin }
   3344  1.65.2.2  martin 
   3345  1.65.2.2  martin static int
   3346  1.65.2.2  martin ixl_rxfill(struct ixl_softc *sc, struct ixl_rx_ring *rxr)
   3347  1.65.2.2  martin {
   3348  1.65.2.2  martin 	struct ixl_rx_rd_desc_32 *ring, *rxd;
   3349  1.65.2.2  martin 	struct ixl_rx_map *rxm;
   3350  1.65.2.2  martin 	bus_dmamap_t map;
   3351  1.65.2.2  martin 	struct mbuf *m;
   3352  1.65.2.2  martin 	unsigned int prod;
   3353  1.65.2.2  martin 	unsigned int slots;
   3354  1.65.2.2  martin 	unsigned int mask;
   3355  1.65.2.2  martin 	int post = 0, error = 0;
   3356  1.65.2.2  martin 
   3357  1.65.2.2  martin 	KASSERT(mutex_owned(&rxr->rxr_lock));
   3358  1.65.2.2  martin 
   3359  1.65.2.2  martin 	prod = rxr->rxr_prod;
   3360  1.65.2.2  martin 	slots = ixl_rxr_unrefreshed(rxr->rxr_prod, rxr->rxr_cons,
   3361  1.65.2.2  martin 	    sc->sc_rx_ring_ndescs);
   3362  1.65.2.2  martin 
   3363  1.65.2.2  martin 	ring = IXL_DMA_KVA(&rxr->rxr_mem);
   3364  1.65.2.2  martin 	mask = sc->sc_rx_ring_ndescs - 1;
   3365  1.65.2.2  martin 
   3366  1.65.2.2  martin 	if (__predict_false(slots <= 0))
   3367  1.65.2.2  martin 		return -1;
   3368  1.65.2.2  martin 
   3369  1.65.2.2  martin 	do {
   3370  1.65.2.2  martin 		rxm = &rxr->rxr_maps[prod];
   3371  1.65.2.2  martin 
   3372  1.65.2.2  martin 		MGETHDR(m, M_DONTWAIT, MT_DATA);
   3373  1.65.2.2  martin 		if (m == NULL) {
   3374  1.65.2.2  martin 			rxr->rxr_mgethdr_failed.ev_count++;
   3375  1.65.2.2  martin 			error = -1;
   3376  1.65.2.2  martin 			break;
   3377  1.65.2.2  martin 		}
   3378  1.65.2.2  martin 
   3379  1.65.2.2  martin 		MCLGET(m, M_DONTWAIT);
   3380  1.65.2.2  martin 		if (!ISSET(m->m_flags, M_EXT)) {
   3381  1.65.2.2  martin 			rxr->rxr_mgetcl_failed.ev_count++;
   3382  1.65.2.2  martin 			error = -1;
   3383  1.65.2.2  martin 			m_freem(m);
   3384  1.65.2.2  martin 			break;
   3385  1.65.2.2  martin 		}
   3386  1.65.2.2  martin 
   3387  1.65.2.2  martin 		m->m_len = m->m_pkthdr.len = MCLBYTES;
   3388  1.65.2.2  martin 		m_adj(m, ETHER_ALIGN);
   3389  1.65.2.2  martin 
   3390  1.65.2.2  martin 		map = rxm->rxm_map;
   3391  1.65.2.2  martin 
   3392  1.65.2.2  martin 		if (bus_dmamap_load_mbuf(sc->sc_dmat, map, m,
   3393  1.65.2.2  martin 		    BUS_DMA_READ | BUS_DMA_NOWAIT) != 0) {
   3394  1.65.2.2  martin 			rxr->rxr_mbuf_load_failed.ev_count++;
   3395  1.65.2.2  martin 			error = -1;
   3396  1.65.2.2  martin 			m_freem(m);
   3397  1.65.2.2  martin 			break;
   3398  1.65.2.2  martin 		}
   3399  1.65.2.2  martin 
   3400  1.65.2.2  martin 		rxm->rxm_m = m;
   3401  1.65.2.2  martin 
   3402  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
   3403  1.65.2.2  martin 		    BUS_DMASYNC_PREREAD);
   3404  1.65.2.2  martin 
   3405  1.65.2.2  martin 		rxd = &ring[prod];
   3406  1.65.2.2  martin 
   3407  1.65.2.2  martin 		rxd->paddr = htole64(map->dm_segs[0].ds_addr);
   3408  1.65.2.2  martin 		rxd->haddr = htole64(0);
   3409  1.65.2.2  martin 
   3410  1.65.2.2  martin 		prod++;
   3411  1.65.2.2  martin 		prod &= mask;
   3412  1.65.2.2  martin 
   3413  1.65.2.2  martin 		post = 1;
   3414  1.65.2.2  martin 
   3415  1.65.2.2  martin 	} while (--slots);
   3416  1.65.2.2  martin 
   3417  1.65.2.2  martin 	if (post) {
   3418  1.65.2.2  martin 		rxr->rxr_prod = prod;
   3419  1.65.2.2  martin 		ixl_wr(sc, rxr->rxr_tail, prod);
   3420  1.65.2.2  martin 	}
   3421  1.65.2.2  martin 
   3422  1.65.2.2  martin 	return error;
   3423  1.65.2.2  martin }
   3424  1.65.2.2  martin 
   3425  1.65.2.2  martin static inline int
   3426  1.65.2.2  martin ixl_handle_queue_common(struct ixl_softc *sc, struct ixl_queue_pair *qp,
   3427  1.65.2.2  martin     u_int txlimit, struct evcnt *txevcnt,
   3428  1.65.2.2  martin     u_int rxlimit, struct evcnt *rxevcnt)
   3429  1.65.2.2  martin {
   3430  1.65.2.2  martin 	struct ixl_tx_ring *txr = qp->qp_txr;
   3431  1.65.2.2  martin 	struct ixl_rx_ring *rxr = qp->qp_rxr;
   3432  1.65.2.2  martin 	int txmore, rxmore;
   3433  1.65.2.2  martin 	int rv;
   3434  1.65.2.2  martin 
   3435  1.65.2.2  martin 	mutex_enter(&txr->txr_lock);
   3436  1.65.2.2  martin 	txevcnt->ev_count++;
   3437  1.65.2.2  martin 	txmore = ixl_txeof(sc, txr, txlimit);
   3438  1.65.2.2  martin 	mutex_exit(&txr->txr_lock);
   3439  1.65.2.2  martin 
   3440  1.65.2.2  martin 	mutex_enter(&rxr->rxr_lock);
   3441  1.65.2.2  martin 	rxevcnt->ev_count++;
   3442  1.65.2.2  martin 	rxmore = ixl_rxeof(sc, rxr, rxlimit);
   3443  1.65.2.2  martin 	mutex_exit(&rxr->rxr_lock);
   3444  1.65.2.2  martin 
   3445  1.65.2.2  martin 	rv = txmore | (rxmore << 1);
   3446  1.65.2.2  martin 
   3447  1.65.2.2  martin 	return rv;
   3448  1.65.2.2  martin }
   3449  1.65.2.2  martin 
   3450  1.65.2.2  martin static void
   3451  1.65.2.2  martin ixl_sched_handle_queue(struct ixl_softc *sc, struct ixl_queue_pair *qp)
   3452  1.65.2.2  martin {
   3453  1.65.2.2  martin 
   3454  1.65.2.2  martin 	if (qp->qp_workqueue)
   3455  1.65.2.2  martin 		workqueue_enqueue(sc->sc_workq_txrx, &qp->qp_work, NULL);
   3456  1.65.2.2  martin 	else
   3457  1.65.2.2  martin 		softint_schedule(qp->qp_si);
   3458  1.65.2.2  martin }
   3459  1.65.2.2  martin 
   3460  1.65.2.2  martin static int
   3461  1.65.2.2  martin ixl_intr(void *xsc)
   3462  1.65.2.2  martin {
   3463  1.65.2.2  martin 	struct ixl_softc *sc = xsc;
   3464  1.65.2.2  martin 	struct ixl_tx_ring *txr;
   3465  1.65.2.2  martin 	struct ixl_rx_ring *rxr;
   3466  1.65.2.2  martin 	uint32_t icr, rxintr, txintr;
   3467  1.65.2.2  martin 	int rv = 0;
   3468  1.65.2.2  martin 	unsigned int i;
   3469  1.65.2.2  martin 
   3470  1.65.2.2  martin 	KASSERT(sc != NULL);
   3471  1.65.2.2  martin 
   3472  1.65.2.2  martin 	ixl_enable_other_intr(sc);
   3473  1.65.2.2  martin 	icr = ixl_rd(sc, I40E_PFINT_ICR0);
   3474  1.65.2.2  martin 
   3475  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_ADMINQ_MASK)) {
   3476  1.65.2.2  martin 		atomic_inc_64(&sc->sc_event_atq.ev_count);
   3477  1.65.2.2  martin 		ixl_atq_done(sc);
   3478  1.65.2.2  martin 		ixl_work_add(sc->sc_workq, &sc->sc_arq_task);
   3479  1.65.2.2  martin 		rv = 1;
   3480  1.65.2.2  martin 	}
   3481  1.65.2.2  martin 
   3482  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_LINK_STAT_CHANGE_MASK)) {
   3483  1.65.2.2  martin 		atomic_inc_64(&sc->sc_event_link.ev_count);
   3484  1.65.2.2  martin 		ixl_work_add(sc->sc_workq, &sc->sc_link_state_task);
   3485  1.65.2.2  martin 		rv = 1;
   3486  1.65.2.2  martin 	}
   3487  1.65.2.2  martin 
   3488  1.65.2.2  martin 	rxintr = icr & I40E_INTR_NOTX_RX_MASK;
   3489  1.65.2.2  martin 	txintr = icr & I40E_INTR_NOTX_TX_MASK;
   3490  1.65.2.2  martin 
   3491  1.65.2.2  martin 	if (txintr || rxintr) {
   3492  1.65.2.2  martin 		for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   3493  1.65.2.2  martin 			txr = sc->sc_qps[i].qp_txr;
   3494  1.65.2.2  martin 			rxr = sc->sc_qps[i].qp_rxr;
   3495  1.65.2.2  martin 
   3496  1.65.2.2  martin 			ixl_handle_queue_common(sc, &sc->sc_qps[i],
   3497  1.65.2.2  martin 			    IXL_TXRX_PROCESS_UNLIMIT, &txr->txr_intr,
   3498  1.65.2.2  martin 			    IXL_TXRX_PROCESS_UNLIMIT, &rxr->rxr_intr);
   3499  1.65.2.2  martin 		}
   3500  1.65.2.2  martin 		rv = 1;
   3501  1.65.2.2  martin 	}
   3502  1.65.2.2  martin 
   3503  1.65.2.2  martin 	return rv;
   3504  1.65.2.2  martin }
   3505  1.65.2.2  martin 
   3506  1.65.2.2  martin static int
   3507  1.65.2.2  martin ixl_queue_intr(void *xqp)
   3508  1.65.2.2  martin {
   3509  1.65.2.2  martin 	struct ixl_queue_pair *qp = xqp;
   3510  1.65.2.2  martin 	struct ixl_tx_ring *txr = qp->qp_txr;
   3511  1.65.2.2  martin 	struct ixl_rx_ring *rxr = qp->qp_rxr;
   3512  1.65.2.2  martin 	struct ixl_softc *sc = qp->qp_sc;
   3513  1.65.2.2  martin 	u_int txlimit, rxlimit;
   3514  1.65.2.2  martin 	int more;
   3515  1.65.2.2  martin 
   3516  1.65.2.2  martin 	txlimit = sc->sc_tx_intr_process_limit;
   3517  1.65.2.2  martin 	rxlimit = sc->sc_rx_intr_process_limit;
   3518  1.65.2.2  martin 	qp->qp_workqueue = sc->sc_txrx_workqueue;
   3519  1.65.2.2  martin 
   3520  1.65.2.2  martin 	more = ixl_handle_queue_common(sc, qp,
   3521  1.65.2.2  martin 	    txlimit, &txr->txr_intr, rxlimit, &rxr->rxr_intr);
   3522  1.65.2.2  martin 
   3523  1.65.2.2  martin 	if (more != 0) {
   3524  1.65.2.2  martin 		ixl_sched_handle_queue(sc, qp);
   3525  1.65.2.2  martin 	} else {
   3526  1.65.2.2  martin 		/* for ALTQ */
   3527  1.65.2.2  martin 		if (txr->txr_qid == 0)
   3528  1.65.2.2  martin 			if_schedule_deferred_start(&sc->sc_ec.ec_if);
   3529  1.65.2.2  martin 		softint_schedule(txr->txr_si);
   3530  1.65.2.2  martin 
   3531  1.65.2.2  martin 		ixl_enable_queue_intr(sc, qp);
   3532  1.65.2.2  martin 	}
   3533  1.65.2.2  martin 
   3534  1.65.2.2  martin 	return 1;
   3535  1.65.2.2  martin }
   3536  1.65.2.2  martin 
   3537  1.65.2.2  martin static void
   3538  1.65.2.2  martin ixl_handle_queue_wk(struct work *wk, void *xsc)
   3539  1.65.2.2  martin {
   3540  1.65.2.2  martin 	struct ixl_queue_pair *qp;
   3541  1.65.2.2  martin 
   3542  1.65.2.2  martin 	qp = container_of(wk, struct ixl_queue_pair, qp_work);
   3543  1.65.2.2  martin 	ixl_handle_queue(qp);
   3544  1.65.2.2  martin }
   3545  1.65.2.2  martin 
   3546  1.65.2.2  martin static void
   3547  1.65.2.2  martin ixl_handle_queue(void *xqp)
   3548  1.65.2.2  martin {
   3549  1.65.2.2  martin 	struct ixl_queue_pair *qp = xqp;
   3550  1.65.2.2  martin 	struct ixl_softc *sc = qp->qp_sc;
   3551  1.65.2.2  martin 	struct ixl_tx_ring *txr = qp->qp_txr;
   3552  1.65.2.2  martin 	struct ixl_rx_ring *rxr = qp->qp_rxr;
   3553  1.65.2.2  martin 	u_int txlimit, rxlimit;
   3554  1.65.2.2  martin 	int more;
   3555  1.65.2.2  martin 
   3556  1.65.2.2  martin 	txlimit = sc->sc_tx_process_limit;
   3557  1.65.2.2  martin 	rxlimit = sc->sc_rx_process_limit;
   3558  1.65.2.2  martin 
   3559  1.65.2.2  martin 	more = ixl_handle_queue_common(sc, qp,
   3560  1.65.2.2  martin 	    txlimit, &txr->txr_defer, rxlimit, &rxr->rxr_defer);
   3561  1.65.2.2  martin 
   3562  1.65.2.2  martin 	if (more != 0)
   3563  1.65.2.2  martin 		ixl_sched_handle_queue(sc, qp);
   3564  1.65.2.2  martin 	else
   3565  1.65.2.2  martin 		ixl_enable_queue_intr(sc, qp);
   3566  1.65.2.2  martin }
   3567  1.65.2.2  martin 
   3568  1.65.2.2  martin static inline void
   3569  1.65.2.2  martin ixl_print_hmc_error(struct ixl_softc *sc, uint32_t reg)
   3570  1.65.2.2  martin {
   3571  1.65.2.2  martin 	uint32_t hmc_idx, hmc_isvf;
   3572  1.65.2.2  martin 	uint32_t hmc_errtype, hmc_objtype, hmc_data;
   3573  1.65.2.2  martin 
   3574  1.65.2.2  martin 	hmc_idx = reg & I40E_PFHMC_ERRORINFO_PMF_INDEX_MASK;
   3575  1.65.2.2  martin 	hmc_idx = hmc_idx >> I40E_PFHMC_ERRORINFO_PMF_INDEX_SHIFT;
   3576  1.65.2.2  martin 	hmc_isvf = reg & I40E_PFHMC_ERRORINFO_PMF_ISVF_MASK;
   3577  1.65.2.2  martin 	hmc_isvf = hmc_isvf >> I40E_PFHMC_ERRORINFO_PMF_ISVF_SHIFT;
   3578  1.65.2.2  martin 	hmc_errtype = reg & I40E_PFHMC_ERRORINFO_HMC_ERROR_TYPE_MASK;
   3579  1.65.2.2  martin 	hmc_errtype = hmc_errtype >> I40E_PFHMC_ERRORINFO_HMC_ERROR_TYPE_SHIFT;
   3580  1.65.2.2  martin 	hmc_objtype = reg & I40E_PFHMC_ERRORINFO_HMC_OBJECT_TYPE_MASK;
   3581  1.65.2.2  martin 	hmc_objtype = hmc_objtype >> I40E_PFHMC_ERRORINFO_HMC_OBJECT_TYPE_SHIFT;
   3582  1.65.2.2  martin 	hmc_data = ixl_rd(sc, I40E_PFHMC_ERRORDATA);
   3583  1.65.2.2  martin 
   3584  1.65.2.2  martin 	device_printf(sc->sc_dev,
   3585  1.65.2.2  martin 	    "HMC Error (idx=0x%x, isvf=0x%x, err=0x%x, obj=0x%x, data=0x%x)\n",
   3586  1.65.2.2  martin 	    hmc_idx, hmc_isvf, hmc_errtype, hmc_objtype, hmc_data);
   3587  1.65.2.2  martin }
   3588  1.65.2.2  martin 
   3589  1.65.2.2  martin static int
   3590  1.65.2.2  martin ixl_other_intr(void *xsc)
   3591  1.65.2.2  martin {
   3592  1.65.2.2  martin 	struct ixl_softc *sc = xsc;
   3593  1.65.2.2  martin 	uint32_t icr, mask, reg;
   3594  1.65.2.2  martin 	int rv;
   3595  1.65.2.2  martin 
   3596  1.65.2.2  martin 	icr = ixl_rd(sc, I40E_PFINT_ICR0);
   3597  1.65.2.2  martin 	mask = ixl_rd(sc, I40E_PFINT_ICR0_ENA);
   3598  1.65.2.2  martin 
   3599  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_ADMINQ_MASK)) {
   3600  1.65.2.2  martin 		atomic_inc_64(&sc->sc_event_atq.ev_count);
   3601  1.65.2.2  martin 		ixl_atq_done(sc);
   3602  1.65.2.2  martin 		ixl_work_add(sc->sc_workq, &sc->sc_arq_task);
   3603  1.65.2.2  martin 		rv = 1;
   3604  1.65.2.2  martin 	}
   3605  1.65.2.2  martin 
   3606  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_LINK_STAT_CHANGE_MASK)) {
   3607  1.65.2.2  martin 		if (ISSET(sc->sc_ec.ec_if.if_flags, IFF_DEBUG))
   3608  1.65.2.2  martin 			device_printf(sc->sc_dev, "link stat changed\n");
   3609  1.65.2.2  martin 
   3610  1.65.2.2  martin 		atomic_inc_64(&sc->sc_event_link.ev_count);
   3611  1.65.2.2  martin 		ixl_work_add(sc->sc_workq, &sc->sc_link_state_task);
   3612  1.65.2.2  martin 		rv = 1;
   3613  1.65.2.2  martin 	}
   3614  1.65.2.2  martin 
   3615  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_GRST_MASK)) {
   3616  1.65.2.2  martin 		CLR(mask, I40E_PFINT_ICR0_ENA_GRST_MASK);
   3617  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_GLGEN_RSTAT);
   3618  1.65.2.2  martin 		reg = reg & I40E_GLGEN_RSTAT_RESET_TYPE_MASK;
   3619  1.65.2.2  martin 		reg = reg >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
   3620  1.65.2.2  martin 
   3621  1.65.2.2  martin 		device_printf(sc->sc_dev, "GRST: %s\n",
   3622  1.65.2.2  martin 		    reg == I40E_RESET_CORER ? "CORER" :
   3623  1.65.2.2  martin 		    reg == I40E_RESET_GLOBR ? "GLOBR" :
   3624  1.65.2.2  martin 		    reg == I40E_RESET_EMPR ? "EMPR" :
   3625  1.65.2.2  martin 		    "POR");
   3626  1.65.2.2  martin 	}
   3627  1.65.2.2  martin 
   3628  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_ECC_ERR_MASK))
   3629  1.65.2.2  martin 		atomic_inc_64(&sc->sc_event_ecc_err.ev_count);
   3630  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_PCI_EXCEPTION_MASK))
   3631  1.65.2.2  martin 		atomic_inc_64(&sc->sc_event_pci_exception.ev_count);
   3632  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_PE_CRITERR_MASK))
   3633  1.65.2.2  martin 		atomic_inc_64(&sc->sc_event_crit_err.ev_count);
   3634  1.65.2.2  martin 
   3635  1.65.2.2  martin 	if (ISSET(icr, IXL_ICR0_CRIT_ERR_MASK)) {
   3636  1.65.2.2  martin 		CLR(mask, IXL_ICR0_CRIT_ERR_MASK);
   3637  1.65.2.2  martin 		device_printf(sc->sc_dev, "critical error\n");
   3638  1.65.2.2  martin 	}
   3639  1.65.2.2  martin 
   3640  1.65.2.2  martin 	if (ISSET(icr, I40E_PFINT_ICR0_HMC_ERR_MASK)) {
   3641  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_PFHMC_ERRORINFO);
   3642  1.65.2.2  martin 		if (ISSET(reg, I40E_PFHMC_ERRORINFO_ERROR_DETECTED_MASK))
   3643  1.65.2.2  martin 			ixl_print_hmc_error(sc, reg);
   3644  1.65.2.2  martin 		ixl_wr(sc, I40E_PFHMC_ERRORINFO, 0);
   3645  1.65.2.2  martin 	}
   3646  1.65.2.2  martin 
   3647  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_ICR0_ENA, mask);
   3648  1.65.2.2  martin 	ixl_flush(sc);
   3649  1.65.2.2  martin 	ixl_enable_other_intr(sc);
   3650  1.65.2.2  martin 	return rv;
   3651  1.65.2.2  martin }
   3652  1.65.2.2  martin 
   3653  1.65.2.2  martin static void
   3654  1.65.2.2  martin ixl_get_link_status_done(struct ixl_softc *sc,
   3655  1.65.2.2  martin     const struct ixl_aq_desc *iaq)
   3656  1.65.2.2  martin {
   3657  1.65.2.2  martin 	struct ixl_aq_desc iaq_buf;
   3658  1.65.2.2  martin 
   3659  1.65.2.2  martin 	memcpy(&iaq_buf, iaq, sizeof(iaq_buf));
   3660  1.65.2.2  martin 
   3661  1.65.2.2  martin 	/*
   3662  1.65.2.2  martin 	 * The lock can be released here
   3663  1.65.2.2  martin 	 * because there is no post processing about ATQ
   3664  1.65.2.2  martin 	 */
   3665  1.65.2.2  martin 	mutex_exit(&sc->sc_atq_lock);
   3666  1.65.2.2  martin 	ixl_link_state_update(sc, &iaq_buf);
   3667  1.65.2.2  martin 	mutex_enter(&sc->sc_atq_lock);
   3668  1.65.2.2  martin }
   3669  1.65.2.2  martin 
   3670  1.65.2.2  martin static void
   3671  1.65.2.2  martin ixl_get_link_status(void *xsc)
   3672  1.65.2.2  martin {
   3673  1.65.2.2  martin 	struct ixl_softc *sc = xsc;
   3674  1.65.2.2  martin 	struct ixl_aq_desc *iaq;
   3675  1.65.2.2  martin 	struct ixl_aq_link_param *param;
   3676  1.65.2.2  martin 	int error;
   3677  1.65.2.2  martin 
   3678  1.65.2.2  martin 	mutex_enter(&sc->sc_atq_lock);
   3679  1.65.2.2  martin 
   3680  1.65.2.2  martin 	iaq = &sc->sc_link_state_atq.iatq_desc;
   3681  1.65.2.2  martin 	memset(iaq, 0, sizeof(*iaq));
   3682  1.65.2.2  martin 	iaq->iaq_opcode = htole16(IXL_AQ_OP_PHY_LINK_STATUS);
   3683  1.65.2.2  martin 	param = (struct ixl_aq_link_param *)iaq->iaq_param;
   3684  1.65.2.2  martin 	param->notify = IXL_AQ_LINK_NOTIFY;
   3685  1.65.2.2  martin 
   3686  1.65.2.2  martin 	error = ixl_atq_exec_locked(sc, &sc->sc_link_state_atq);
   3687  1.65.2.2  martin 	ixl_atq_set(&sc->sc_link_state_atq, ixl_get_link_status_done);
   3688  1.65.2.2  martin 
   3689  1.65.2.2  martin 	if (error == 0) {
   3690  1.65.2.2  martin 		ixl_get_link_status_done(sc, iaq);
   3691  1.65.2.2  martin 	}
   3692  1.65.2.2  martin 
   3693  1.65.2.2  martin 	mutex_exit(&sc->sc_atq_lock);
   3694  1.65.2.2  martin }
   3695  1.65.2.2  martin 
   3696  1.65.2.2  martin static void
   3697  1.65.2.2  martin ixl_link_state_update(struct ixl_softc *sc, const struct ixl_aq_desc *iaq)
   3698  1.65.2.2  martin {
   3699  1.65.2.2  martin 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   3700  1.65.2.2  martin 	int link_state;
   3701  1.65.2.2  martin 
   3702  1.65.2.2  martin 	mutex_enter(&sc->sc_cfg_lock);
   3703  1.65.2.2  martin 	link_state = ixl_set_link_status_locked(sc, iaq);
   3704  1.65.2.2  martin 	mutex_exit(&sc->sc_cfg_lock);
   3705  1.65.2.2  martin 
   3706  1.65.2.2  martin 	if (ifp->if_link_state != link_state)
   3707  1.65.2.2  martin 		if_link_state_change(ifp, link_state);
   3708  1.65.2.2  martin 
   3709  1.65.2.2  martin 	if (link_state != LINK_STATE_DOWN) {
   3710  1.65.2.2  martin 		kpreempt_disable();
   3711  1.65.2.2  martin 		if_schedule_deferred_start(ifp);
   3712  1.65.2.2  martin 		kpreempt_enable();
   3713  1.65.2.2  martin 	}
   3714  1.65.2.2  martin }
   3715  1.65.2.2  martin 
   3716  1.65.2.2  martin static void
   3717  1.65.2.2  martin ixl_aq_dump(const struct ixl_softc *sc, const struct ixl_aq_desc *iaq,
   3718  1.65.2.2  martin     const char *msg)
   3719  1.65.2.2  martin {
   3720  1.65.2.2  martin 	char	 buf[512];
   3721  1.65.2.2  martin 	size_t	 len;
   3722  1.65.2.2  martin 
   3723  1.65.2.2  martin 	len = sizeof(buf);
   3724  1.65.2.2  martin 	buf[--len] = '\0';
   3725  1.65.2.2  martin 
   3726  1.65.2.2  martin 	device_printf(sc->sc_dev, "%s\n", msg);
   3727  1.65.2.2  martin 	snprintb(buf, len, IXL_AQ_FLAGS_FMT, le16toh(iaq->iaq_flags));
   3728  1.65.2.2  martin 	device_printf(sc->sc_dev, "flags %s opcode %04x\n",
   3729  1.65.2.2  martin 	    buf, le16toh(iaq->iaq_opcode));
   3730  1.65.2.2  martin 	device_printf(sc->sc_dev, "datalen %u retval %u\n",
   3731  1.65.2.2  martin 	    le16toh(iaq->iaq_datalen), le16toh(iaq->iaq_retval));
   3732  1.65.2.2  martin 	device_printf(sc->sc_dev, "cookie %016" PRIx64 "\n", iaq->iaq_cookie);
   3733  1.65.2.2  martin 	device_printf(sc->sc_dev, "%08x %08x %08x %08x\n",
   3734  1.65.2.2  martin 	    le32toh(iaq->iaq_param[0]), le32toh(iaq->iaq_param[1]),
   3735  1.65.2.2  martin 	    le32toh(iaq->iaq_param[2]), le32toh(iaq->iaq_param[3]));
   3736  1.65.2.2  martin }
   3737  1.65.2.2  martin 
   3738  1.65.2.2  martin static void
   3739  1.65.2.2  martin ixl_arq(void *xsc)
   3740  1.65.2.2  martin {
   3741  1.65.2.2  martin 	struct ixl_softc *sc = xsc;
   3742  1.65.2.2  martin 	struct ixl_aq_desc *arq, *iaq;
   3743  1.65.2.2  martin 	struct ixl_aq_buf *aqb;
   3744  1.65.2.2  martin 	unsigned int cons = sc->sc_arq_cons;
   3745  1.65.2.2  martin 	unsigned int prod;
   3746  1.65.2.2  martin 	int done = 0;
   3747  1.65.2.2  martin 
   3748  1.65.2.2  martin 	prod = ixl_rd(sc, sc->sc_aq_regs->arq_head) &
   3749  1.65.2.2  martin 	    sc->sc_aq_regs->arq_head_mask;
   3750  1.65.2.2  martin 
   3751  1.65.2.2  martin 	if (cons == prod)
   3752  1.65.2.2  martin 		goto done;
   3753  1.65.2.2  martin 
   3754  1.65.2.2  martin 	arq = IXL_DMA_KVA(&sc->sc_arq);
   3755  1.65.2.2  martin 
   3756  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_arq),
   3757  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_arq),
   3758  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   3759  1.65.2.2  martin 
   3760  1.65.2.2  martin 	do {
   3761  1.65.2.2  martin 		iaq = &arq[cons];
   3762  1.65.2.2  martin 		aqb = sc->sc_arq_live[cons];
   3763  1.65.2.2  martin 
   3764  1.65.2.2  martin 		KASSERT(aqb != NULL);
   3765  1.65.2.2  martin 
   3766  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, aqb->aqb_map, 0, IXL_AQ_BUFLEN,
   3767  1.65.2.2  martin 		    BUS_DMASYNC_POSTREAD);
   3768  1.65.2.2  martin 
   3769  1.65.2.2  martin 		if (ISSET(sc->sc_ec.ec_if.if_flags, IFF_DEBUG))
   3770  1.65.2.2  martin 			ixl_aq_dump(sc, iaq, "arq event");
   3771  1.65.2.2  martin 
   3772  1.65.2.2  martin 		switch (iaq->iaq_opcode) {
   3773  1.65.2.2  martin 		case htole16(IXL_AQ_OP_PHY_LINK_STATUS):
   3774  1.65.2.2  martin 			ixl_link_state_update(sc, iaq);
   3775  1.65.2.2  martin 			break;
   3776  1.65.2.2  martin 		}
   3777  1.65.2.2  martin 
   3778  1.65.2.2  martin 		memset(iaq, 0, sizeof(*iaq));
   3779  1.65.2.2  martin 		sc->sc_arq_live[cons] = NULL;
   3780  1.65.2.2  martin 		SIMPLEQ_INSERT_TAIL(&sc->sc_arq_idle, aqb, aqb_entry);
   3781  1.65.2.2  martin 
   3782  1.65.2.2  martin 		cons++;
   3783  1.65.2.2  martin 		cons &= IXL_AQ_MASK;
   3784  1.65.2.2  martin 
   3785  1.65.2.2  martin 		done = 1;
   3786  1.65.2.2  martin 	} while (cons != prod);
   3787  1.65.2.2  martin 
   3788  1.65.2.2  martin 	if (done) {
   3789  1.65.2.2  martin 		sc->sc_arq_cons = cons;
   3790  1.65.2.2  martin 		ixl_arq_fill(sc);
   3791  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_arq),
   3792  1.65.2.2  martin 		    0, IXL_DMA_LEN(&sc->sc_arq),
   3793  1.65.2.2  martin 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   3794  1.65.2.2  martin 	}
   3795  1.65.2.2  martin 
   3796  1.65.2.2  martin done:
   3797  1.65.2.2  martin 	ixl_enable_other_intr(sc);
   3798  1.65.2.2  martin }
   3799  1.65.2.2  martin 
   3800  1.65.2.2  martin static void
   3801  1.65.2.2  martin ixl_atq_set(struct ixl_atq *iatq,
   3802  1.65.2.2  martin     void (*fn)(struct ixl_softc *, const struct ixl_aq_desc *))
   3803  1.65.2.2  martin {
   3804  1.65.2.2  martin 
   3805  1.65.2.2  martin 	iatq->iatq_fn = fn;
   3806  1.65.2.2  martin }
   3807  1.65.2.2  martin 
   3808  1.65.2.2  martin static int
   3809  1.65.2.2  martin ixl_atq_post_locked(struct ixl_softc *sc, struct ixl_atq *iatq)
   3810  1.65.2.2  martin {
   3811  1.65.2.2  martin 	struct ixl_aq_desc *atq, *slot;
   3812  1.65.2.2  martin 	unsigned int prod, cons, prod_next;
   3813  1.65.2.2  martin 
   3814  1.65.2.2  martin 	/* assert locked */
   3815  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_atq_lock));
   3816  1.65.2.2  martin 
   3817  1.65.2.2  martin 	atq = IXL_DMA_KVA(&sc->sc_atq);
   3818  1.65.2.2  martin 	prod = sc->sc_atq_prod;
   3819  1.65.2.2  martin 	cons = sc->sc_atq_cons;
   3820  1.65.2.2  martin 	prod_next = (prod +1) & IXL_AQ_MASK;
   3821  1.65.2.2  martin 
   3822  1.65.2.2  martin 	if (cons == prod_next)
   3823  1.65.2.2  martin 		return ENOMEM;
   3824  1.65.2.2  martin 
   3825  1.65.2.2  martin 	slot = &atq[prod];
   3826  1.65.2.2  martin 
   3827  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3828  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq), BUS_DMASYNC_POSTWRITE);
   3829  1.65.2.2  martin 
   3830  1.65.2.2  martin 	KASSERT(iatq->iatq_fn != NULL);
   3831  1.65.2.2  martin 	*slot = iatq->iatq_desc;
   3832  1.65.2.2  martin 	slot->iaq_cookie = (uint64_t)((intptr_t)iatq);
   3833  1.65.2.2  martin 
   3834  1.65.2.2  martin 	if (ISSET(sc->sc_ec.ec_if.if_flags, IFF_DEBUG))
   3835  1.65.2.2  martin 		ixl_aq_dump(sc, slot, "atq command");
   3836  1.65.2.2  martin 
   3837  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3838  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq), BUS_DMASYNC_PREWRITE);
   3839  1.65.2.2  martin 
   3840  1.65.2.2  martin 	sc->sc_atq_prod = prod_next;
   3841  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_tail, sc->sc_atq_prod);
   3842  1.65.2.2  martin 
   3843  1.65.2.2  martin 	return 0;
   3844  1.65.2.2  martin }
   3845  1.65.2.2  martin 
   3846  1.65.2.2  martin static void
   3847  1.65.2.2  martin ixl_atq_done_locked(struct ixl_softc *sc)
   3848  1.65.2.2  martin {
   3849  1.65.2.2  martin 	struct ixl_aq_desc *atq, *slot;
   3850  1.65.2.2  martin 	struct ixl_atq *iatq;
   3851  1.65.2.2  martin 	unsigned int cons;
   3852  1.65.2.2  martin 	unsigned int prod;
   3853  1.65.2.2  martin 
   3854  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_atq_lock));
   3855  1.65.2.2  martin 
   3856  1.65.2.2  martin 	prod = sc->sc_atq_prod;
   3857  1.65.2.2  martin 	cons = sc->sc_atq_cons;
   3858  1.65.2.2  martin 
   3859  1.65.2.2  martin 	if (prod == cons)
   3860  1.65.2.2  martin 		return;
   3861  1.65.2.2  martin 
   3862  1.65.2.2  martin 	atq = IXL_DMA_KVA(&sc->sc_atq);
   3863  1.65.2.2  martin 
   3864  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3865  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq),
   3866  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   3867  1.65.2.2  martin 
   3868  1.65.2.2  martin 	do {
   3869  1.65.2.2  martin 		slot = &atq[cons];
   3870  1.65.2.2  martin 		if (!ISSET(slot->iaq_flags, htole16(IXL_AQ_DD)))
   3871  1.65.2.2  martin 			break;
   3872  1.65.2.2  martin 
   3873  1.65.2.2  martin 		iatq = (struct ixl_atq *)((intptr_t)slot->iaq_cookie);
   3874  1.65.2.2  martin 		iatq->iatq_desc = *slot;
   3875  1.65.2.2  martin 
   3876  1.65.2.2  martin 		memset(slot, 0, sizeof(*slot));
   3877  1.65.2.2  martin 
   3878  1.65.2.2  martin 		if (ISSET(sc->sc_ec.ec_if.if_flags, IFF_DEBUG))
   3879  1.65.2.2  martin 			ixl_aq_dump(sc, &iatq->iatq_desc, "atq response");
   3880  1.65.2.2  martin 
   3881  1.65.2.2  martin 		(*iatq->iatq_fn)(sc, &iatq->iatq_desc);
   3882  1.65.2.2  martin 
   3883  1.65.2.2  martin 		cons++;
   3884  1.65.2.2  martin 		cons &= IXL_AQ_MASK;
   3885  1.65.2.2  martin 	} while (cons != prod);
   3886  1.65.2.2  martin 
   3887  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3888  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq),
   3889  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   3890  1.65.2.2  martin 
   3891  1.65.2.2  martin 	sc->sc_atq_cons = cons;
   3892  1.65.2.2  martin }
   3893  1.65.2.2  martin 
   3894  1.65.2.2  martin static void
   3895  1.65.2.2  martin ixl_atq_done(struct ixl_softc *sc)
   3896  1.65.2.2  martin {
   3897  1.65.2.2  martin 
   3898  1.65.2.2  martin 	mutex_enter(&sc->sc_atq_lock);
   3899  1.65.2.2  martin 	ixl_atq_done_locked(sc);
   3900  1.65.2.2  martin 	mutex_exit(&sc->sc_atq_lock);
   3901  1.65.2.2  martin }
   3902  1.65.2.2  martin 
   3903  1.65.2.2  martin static void
   3904  1.65.2.2  martin ixl_wakeup(struct ixl_softc *sc, const struct ixl_aq_desc *iaq)
   3905  1.65.2.2  martin {
   3906  1.65.2.2  martin 
   3907  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_atq_lock));
   3908  1.65.2.2  martin 
   3909  1.65.2.2  martin 	cv_signal(&sc->sc_atq_cv);
   3910  1.65.2.2  martin }
   3911  1.65.2.2  martin 
   3912  1.65.2.2  martin static int
   3913  1.65.2.2  martin ixl_atq_exec(struct ixl_softc *sc, struct ixl_atq *iatq)
   3914  1.65.2.2  martin {
   3915  1.65.2.2  martin 	int error;
   3916  1.65.2.2  martin 
   3917  1.65.2.2  martin 	mutex_enter(&sc->sc_atq_lock);
   3918  1.65.2.2  martin 	error = ixl_atq_exec_locked(sc, iatq);
   3919  1.65.2.2  martin 	mutex_exit(&sc->sc_atq_lock);
   3920  1.65.2.2  martin 
   3921  1.65.2.2  martin 	return error;
   3922  1.65.2.2  martin }
   3923  1.65.2.2  martin 
   3924  1.65.2.2  martin static int
   3925  1.65.2.2  martin ixl_atq_exec_locked(struct ixl_softc *sc, struct ixl_atq *iatq)
   3926  1.65.2.2  martin {
   3927  1.65.2.2  martin 	int error;
   3928  1.65.2.2  martin 
   3929  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_atq_lock));
   3930  1.65.2.2  martin 	KASSERT(iatq->iatq_desc.iaq_cookie == 0);
   3931  1.65.2.2  martin 
   3932  1.65.2.2  martin 	ixl_atq_set(iatq, ixl_wakeup);
   3933  1.65.2.2  martin 
   3934  1.65.2.2  martin 	error = ixl_atq_post_locked(sc, iatq);
   3935  1.65.2.2  martin 	if (error)
   3936  1.65.2.2  martin 		return error;
   3937  1.65.2.2  martin 
   3938  1.65.2.2  martin 	error = cv_timedwait(&sc->sc_atq_cv, &sc->sc_atq_lock,
   3939  1.65.2.2  martin 	    IXL_ATQ_EXEC_TIMEOUT);
   3940  1.65.2.2  martin 
   3941  1.65.2.2  martin 	return error;
   3942  1.65.2.2  martin }
   3943  1.65.2.2  martin 
   3944  1.65.2.2  martin static int
   3945  1.65.2.2  martin ixl_atq_poll(struct ixl_softc *sc, struct ixl_aq_desc *iaq, unsigned int tm)
   3946  1.65.2.2  martin {
   3947  1.65.2.2  martin 	struct ixl_aq_desc *atq, *slot;
   3948  1.65.2.2  martin 	unsigned int prod;
   3949  1.65.2.2  martin 	unsigned int t = 0;
   3950  1.65.2.2  martin 
   3951  1.65.2.2  martin 	mutex_enter(&sc->sc_atq_lock);
   3952  1.65.2.2  martin 
   3953  1.65.2.2  martin 	atq = IXL_DMA_KVA(&sc->sc_atq);
   3954  1.65.2.2  martin 	prod = sc->sc_atq_prod;
   3955  1.65.2.2  martin 	slot = atq + prod;
   3956  1.65.2.2  martin 
   3957  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3958  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq), BUS_DMASYNC_POSTWRITE);
   3959  1.65.2.2  martin 
   3960  1.65.2.2  martin 	*slot = *iaq;
   3961  1.65.2.2  martin 	slot->iaq_flags |= htole16(IXL_AQ_SI);
   3962  1.65.2.2  martin 
   3963  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3964  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq), BUS_DMASYNC_PREWRITE);
   3965  1.65.2.2  martin 
   3966  1.65.2.2  martin 	prod++;
   3967  1.65.2.2  martin 	prod &= IXL_AQ_MASK;
   3968  1.65.2.2  martin 	sc->sc_atq_prod = prod;
   3969  1.65.2.2  martin 	ixl_wr(sc, sc->sc_aq_regs->atq_tail, prod);
   3970  1.65.2.2  martin 
   3971  1.65.2.2  martin 	while (ixl_rd(sc, sc->sc_aq_regs->atq_head) != prod) {
   3972  1.65.2.2  martin 		delaymsec(1);
   3973  1.65.2.2  martin 
   3974  1.65.2.2  martin 		if (t++ > tm) {
   3975  1.65.2.2  martin 			mutex_exit(&sc->sc_atq_lock);
   3976  1.65.2.2  martin 			return ETIMEDOUT;
   3977  1.65.2.2  martin 		}
   3978  1.65.2.2  martin 	}
   3979  1.65.2.2  martin 
   3980  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3981  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq), BUS_DMASYNC_POSTREAD);
   3982  1.65.2.2  martin 	*iaq = *slot;
   3983  1.65.2.2  martin 	memset(slot, 0, sizeof(*slot));
   3984  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_atq),
   3985  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_atq), BUS_DMASYNC_PREREAD);
   3986  1.65.2.2  martin 
   3987  1.65.2.2  martin 	sc->sc_atq_cons = prod;
   3988  1.65.2.2  martin 
   3989  1.65.2.2  martin 	mutex_exit(&sc->sc_atq_lock);
   3990  1.65.2.2  martin 
   3991  1.65.2.2  martin 	return 0;
   3992  1.65.2.2  martin }
   3993  1.65.2.2  martin 
   3994  1.65.2.2  martin static int
   3995  1.65.2.2  martin ixl_get_version(struct ixl_softc *sc)
   3996  1.65.2.2  martin {
   3997  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   3998  1.65.2.2  martin 	uint32_t fwbuild, fwver, apiver;
   3999  1.65.2.2  martin 	uint16_t api_maj_ver, api_min_ver;
   4000  1.65.2.2  martin 
   4001  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4002  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_GET_VERSION);
   4003  1.65.2.2  martin 
   4004  1.65.2.2  martin 	iaq.iaq_retval = le16toh(23);
   4005  1.65.2.2  martin 
   4006  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 2000) != 0)
   4007  1.65.2.2  martin 		return ETIMEDOUT;
   4008  1.65.2.2  martin 	if (iaq.iaq_retval != htole16(IXL_AQ_RC_OK))
   4009  1.65.2.2  martin 		return EIO;
   4010  1.65.2.2  martin 
   4011  1.65.2.2  martin 	fwbuild = le32toh(iaq.iaq_param[1]);
   4012  1.65.2.2  martin 	fwver = le32toh(iaq.iaq_param[2]);
   4013  1.65.2.2  martin 	apiver = le32toh(iaq.iaq_param[3]);
   4014  1.65.2.2  martin 
   4015  1.65.2.2  martin 	api_maj_ver = (uint16_t)apiver;
   4016  1.65.2.2  martin 	api_min_ver = (uint16_t)(apiver >> 16);
   4017  1.65.2.2  martin 
   4018  1.65.2.2  martin 	aprint_normal(", FW %hu.%hu.%05u API %hu.%hu", (uint16_t)fwver,
   4019  1.65.2.2  martin 	    (uint16_t)(fwver >> 16), fwbuild, api_maj_ver, api_min_ver);
   4020  1.65.2.2  martin 
   4021  1.65.2.2  martin 	if (sc->sc_mac_type == I40E_MAC_X722) {
   4022  1.65.2.2  martin 		SET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_NVMLOCK |
   4023  1.65.2.2  martin 		    IXL_SC_AQ_FLAG_NVMREAD);
   4024  1.65.2.2  martin 		SET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_RXCTL);
   4025  1.65.2.2  martin 		SET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_RSS);
   4026  1.65.2.2  martin 	}
   4027  1.65.2.2  martin 
   4028  1.65.2.2  martin #define IXL_API_VER(maj, min)	(((uint32_t)(maj) << 16) | (min))
   4029  1.65.2.2  martin 	if (IXL_API_VER(api_maj_ver, api_min_ver) >= IXL_API_VER(1, 5)) {
   4030  1.65.2.2  martin 		SET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_RXCTL);
   4031  1.65.2.2  martin 		SET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_NVMLOCK);
   4032  1.65.2.2  martin 	}
   4033  1.65.2.2  martin #undef IXL_API_VER
   4034  1.65.2.2  martin 
   4035  1.65.2.2  martin 	return 0;
   4036  1.65.2.2  martin }
   4037  1.65.2.2  martin 
   4038  1.65.2.2  martin static int
   4039  1.65.2.2  martin ixl_get_nvm_version(struct ixl_softc *sc)
   4040  1.65.2.2  martin {
   4041  1.65.2.2  martin 	uint16_t nvmver, cfg_ptr, eetrack_hi, eetrack_lo, oem_hi, oem_lo;
   4042  1.65.2.2  martin 	uint32_t eetrack, oem;
   4043  1.65.2.2  martin 	uint16_t nvm_maj_ver, nvm_min_ver, oem_build;
   4044  1.65.2.2  martin 	uint8_t oem_ver, oem_patch;
   4045  1.65.2.2  martin 
   4046  1.65.2.2  martin 	nvmver = cfg_ptr = eetrack_hi = eetrack_lo = oem_hi = oem_lo = 0;
   4047  1.65.2.2  martin 	ixl_rd16_nvm(sc, I40E_SR_NVM_DEV_STARTER_VERSION, &nvmver);
   4048  1.65.2.2  martin 	ixl_rd16_nvm(sc, I40E_SR_NVM_EETRACK_HI, &eetrack_hi);
   4049  1.65.2.2  martin 	ixl_rd16_nvm(sc, I40E_SR_NVM_EETRACK_LO, &eetrack_lo);
   4050  1.65.2.2  martin 	ixl_rd16_nvm(sc, I40E_SR_BOOT_CONFIG_PTR, &cfg_ptr);
   4051  1.65.2.2  martin 	ixl_rd16_nvm(sc, cfg_ptr + I40E_NVM_OEM_VER_OFF, &oem_hi);
   4052  1.65.2.2  martin 	ixl_rd16_nvm(sc, cfg_ptr + I40E_NVM_OEM_VER_OFF + 1, &oem_lo);
   4053  1.65.2.2  martin 
   4054  1.65.2.2  martin 	nvm_maj_ver = (uint16_t)__SHIFTOUT(nvmver, IXL_NVM_VERSION_HI_MASK);
   4055  1.65.2.2  martin 	nvm_min_ver = (uint16_t)__SHIFTOUT(nvmver, IXL_NVM_VERSION_LO_MASK);
   4056  1.65.2.2  martin 	eetrack = ((uint32_t)eetrack_hi << 16) | eetrack_lo;
   4057  1.65.2.2  martin 	oem = ((uint32_t)oem_hi << 16) | oem_lo;
   4058  1.65.2.2  martin 	oem_ver = __SHIFTOUT(oem, IXL_NVM_OEMVERSION_MASK);
   4059  1.65.2.2  martin 	oem_build = __SHIFTOUT(oem, IXL_NVM_OEMBUILD_MASK);
   4060  1.65.2.2  martin 	oem_patch = __SHIFTOUT(oem, IXL_NVM_OEMPATCH_MASK);
   4061  1.65.2.2  martin 
   4062  1.65.2.2  martin 	aprint_normal(" nvm %x.%02x etid %08x oem %d.%d.%d",
   4063  1.65.2.2  martin 	    nvm_maj_ver, nvm_min_ver, eetrack,
   4064  1.65.2.2  martin 	    oem_ver, oem_build, oem_patch);
   4065  1.65.2.2  martin 
   4066  1.65.2.2  martin 	return 0;
   4067  1.65.2.2  martin }
   4068  1.65.2.2  martin 
   4069  1.65.2.2  martin static int
   4070  1.65.2.2  martin ixl_pxe_clear(struct ixl_softc *sc)
   4071  1.65.2.2  martin {
   4072  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4073  1.65.2.2  martin 	int rv;
   4074  1.65.2.2  martin 
   4075  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4076  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_CLEAR_PXE_MODE);
   4077  1.65.2.2  martin 	iaq.iaq_param[0] = htole32(0x2);
   4078  1.65.2.2  martin 
   4079  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   4080  1.65.2.2  martin 
   4081  1.65.2.2  martin 	ixl_wr(sc, I40E_GLLAN_RCTL_0, 0x1);
   4082  1.65.2.2  martin 
   4083  1.65.2.2  martin 	if (rv != 0)
   4084  1.65.2.2  martin 		return ETIMEDOUT;
   4085  1.65.2.2  martin 
   4086  1.65.2.2  martin 	switch (iaq.iaq_retval) {
   4087  1.65.2.2  martin 	case htole16(IXL_AQ_RC_OK):
   4088  1.65.2.2  martin 	case htole16(IXL_AQ_RC_EEXIST):
   4089  1.65.2.2  martin 		break;
   4090  1.65.2.2  martin 	default:
   4091  1.65.2.2  martin 		return EIO;
   4092  1.65.2.2  martin 	}
   4093  1.65.2.2  martin 
   4094  1.65.2.2  martin 	return 0;
   4095  1.65.2.2  martin }
   4096  1.65.2.2  martin 
   4097  1.65.2.2  martin static int
   4098  1.65.2.2  martin ixl_lldp_shut(struct ixl_softc *sc)
   4099  1.65.2.2  martin {
   4100  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4101  1.65.2.2  martin 
   4102  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4103  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_LLDP_STOP_AGENT);
   4104  1.65.2.2  martin 	iaq.iaq_param[0] = htole32(IXL_LLDP_SHUTDOWN);
   4105  1.65.2.2  martin 
   4106  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0) {
   4107  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "STOP LLDP AGENT timeout\n");
   4108  1.65.2.2  martin 		return -1;
   4109  1.65.2.2  martin 	}
   4110  1.65.2.2  martin 
   4111  1.65.2.2  martin 	switch (iaq.iaq_retval) {
   4112  1.65.2.2  martin 	case htole16(IXL_AQ_RC_EMODE):
   4113  1.65.2.2  martin 	case htole16(IXL_AQ_RC_EPERM):
   4114  1.65.2.2  martin 		/* ignore silently */
   4115  1.65.2.2  martin 	default:
   4116  1.65.2.2  martin 		break;
   4117  1.65.2.2  martin 	}
   4118  1.65.2.2  martin 
   4119  1.65.2.2  martin 	return 0;
   4120  1.65.2.2  martin }
   4121  1.65.2.2  martin 
   4122  1.65.2.2  martin static void
   4123  1.65.2.2  martin ixl_parse_hw_capability(struct ixl_softc *sc, struct ixl_aq_capability *cap)
   4124  1.65.2.2  martin {
   4125  1.65.2.2  martin 	uint16_t id;
   4126  1.65.2.2  martin 	uint32_t number, logical_id;
   4127  1.65.2.2  martin 
   4128  1.65.2.2  martin 	id = le16toh(cap->cap_id);
   4129  1.65.2.2  martin 	number = le32toh(cap->number);
   4130  1.65.2.2  martin 	logical_id = le32toh(cap->logical_id);
   4131  1.65.2.2  martin 
   4132  1.65.2.2  martin 	switch (id) {
   4133  1.65.2.2  martin 	case IXL_AQ_CAP_RSS:
   4134  1.65.2.2  martin 		sc->sc_rss_table_size = number;
   4135  1.65.2.2  martin 		sc->sc_rss_table_entry_width = logical_id;
   4136  1.65.2.2  martin 		break;
   4137  1.65.2.2  martin 	case IXL_AQ_CAP_RXQ:
   4138  1.65.2.2  martin 	case IXL_AQ_CAP_TXQ:
   4139  1.65.2.2  martin 		sc->sc_nqueue_pairs_device = MIN(number,
   4140  1.65.2.2  martin 		    sc->sc_nqueue_pairs_device);
   4141  1.65.2.2  martin 		break;
   4142  1.65.2.2  martin 	}
   4143  1.65.2.2  martin }
   4144  1.65.2.2  martin 
   4145  1.65.2.2  martin static int
   4146  1.65.2.2  martin ixl_get_hw_capabilities(struct ixl_softc *sc)
   4147  1.65.2.2  martin {
   4148  1.65.2.2  martin 	struct ixl_dmamem idm;
   4149  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4150  1.65.2.2  martin 	struct ixl_aq_capability *caps;
   4151  1.65.2.2  martin 	size_t i, ncaps;
   4152  1.65.2.2  martin 	bus_size_t caps_size;
   4153  1.65.2.2  martin 	uint16_t status;
   4154  1.65.2.2  martin 	int rv;
   4155  1.65.2.2  martin 
   4156  1.65.2.2  martin 	caps_size = sizeof(caps[0]) * 40;
   4157  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4158  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_LIST_FUNC_CAP);
   4159  1.65.2.2  martin 
   4160  1.65.2.2  martin 	do {
   4161  1.65.2.2  martin 		if (ixl_dmamem_alloc(sc, &idm, caps_size, 0) != 0) {
   4162  1.65.2.2  martin 			return -1;
   4163  1.65.2.2  martin 		}
   4164  1.65.2.2  martin 
   4165  1.65.2.2  martin 		iaq.iaq_flags = htole16(IXL_AQ_BUF |
   4166  1.65.2.2  martin 		    (caps_size > I40E_AQ_LARGE_BUF ? IXL_AQ_LB : 0));
   4167  1.65.2.2  martin 		iaq.iaq_datalen = htole16(caps_size);
   4168  1.65.2.2  martin 		ixl_aq_dva(&iaq, IXL_DMA_DVA(&idm));
   4169  1.65.2.2  martin 
   4170  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&idm), 0,
   4171  1.65.2.2  martin 		    IXL_DMA_LEN(&idm), BUS_DMASYNC_PREREAD);
   4172  1.65.2.2  martin 
   4173  1.65.2.2  martin 		rv = ixl_atq_poll(sc, &iaq, 250);
   4174  1.65.2.2  martin 
   4175  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&idm), 0,
   4176  1.65.2.2  martin 		    IXL_DMA_LEN(&idm), BUS_DMASYNC_POSTREAD);
   4177  1.65.2.2  martin 
   4178  1.65.2.2  martin 		if (rv != 0) {
   4179  1.65.2.2  martin 			aprint_error(", HW capabilities timeout\n");
   4180  1.65.2.2  martin 			goto done;
   4181  1.65.2.2  martin 		}
   4182  1.65.2.2  martin 
   4183  1.65.2.2  martin 		status = le16toh(iaq.iaq_retval);
   4184  1.65.2.2  martin 
   4185  1.65.2.2  martin 		if (status == IXL_AQ_RC_ENOMEM) {
   4186  1.65.2.2  martin 			caps_size = le16toh(iaq.iaq_datalen);
   4187  1.65.2.2  martin 			ixl_dmamem_free(sc, &idm);
   4188  1.65.2.2  martin 		}
   4189  1.65.2.2  martin 	} while (status == IXL_AQ_RC_ENOMEM);
   4190  1.65.2.2  martin 
   4191  1.65.2.2  martin 	if (status != IXL_AQ_RC_OK) {
   4192  1.65.2.2  martin 		aprint_error(", HW capabilities error\n");
   4193  1.65.2.2  martin 		goto done;
   4194  1.65.2.2  martin 	}
   4195  1.65.2.2  martin 
   4196  1.65.2.2  martin 	caps = IXL_DMA_KVA(&idm);
   4197  1.65.2.2  martin 	ncaps = le16toh(iaq.iaq_param[1]);
   4198  1.65.2.2  martin 
   4199  1.65.2.2  martin 	for (i = 0; i < ncaps; i++) {
   4200  1.65.2.2  martin 		ixl_parse_hw_capability(sc, &caps[i]);
   4201  1.65.2.2  martin 	}
   4202  1.65.2.2  martin 
   4203  1.65.2.2  martin done:
   4204  1.65.2.2  martin 	ixl_dmamem_free(sc, &idm);
   4205  1.65.2.2  martin 	return rv;
   4206  1.65.2.2  martin }
   4207  1.65.2.2  martin 
   4208  1.65.2.2  martin static int
   4209  1.65.2.2  martin ixl_get_mac(struct ixl_softc *sc)
   4210  1.65.2.2  martin {
   4211  1.65.2.2  martin 	struct ixl_dmamem idm;
   4212  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4213  1.65.2.2  martin 	struct ixl_aq_mac_addresses *addrs;
   4214  1.65.2.2  martin 	int rv;
   4215  1.65.2.2  martin 
   4216  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &idm, sizeof(*addrs), 0) != 0) {
   4217  1.65.2.2  martin 		aprint_error(", unable to allocate mac addresses\n");
   4218  1.65.2.2  martin 		return -1;
   4219  1.65.2.2  martin 	}
   4220  1.65.2.2  martin 
   4221  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4222  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF);
   4223  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_MAC_ADDRESS_READ);
   4224  1.65.2.2  martin 	iaq.iaq_datalen = htole16(sizeof(*addrs));
   4225  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(&idm));
   4226  1.65.2.2  martin 
   4227  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&idm), 0, IXL_DMA_LEN(&idm),
   4228  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD);
   4229  1.65.2.2  martin 
   4230  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   4231  1.65.2.2  martin 
   4232  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&idm), 0, IXL_DMA_LEN(&idm),
   4233  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD);
   4234  1.65.2.2  martin 
   4235  1.65.2.2  martin 	if (rv != 0) {
   4236  1.65.2.2  martin 		aprint_error(", MAC ADDRESS READ timeout\n");
   4237  1.65.2.2  martin 		rv = -1;
   4238  1.65.2.2  martin 		goto done;
   4239  1.65.2.2  martin 	}
   4240  1.65.2.2  martin 	if (iaq.iaq_retval != htole16(IXL_AQ_RC_OK)) {
   4241  1.65.2.2  martin 		aprint_error(", MAC ADDRESS READ error\n");
   4242  1.65.2.2  martin 		rv = -1;
   4243  1.65.2.2  martin 		goto done;
   4244  1.65.2.2  martin 	}
   4245  1.65.2.2  martin 
   4246  1.65.2.2  martin 	addrs = IXL_DMA_KVA(&idm);
   4247  1.65.2.2  martin 	if (!ISSET(iaq.iaq_param[0], htole32(IXL_AQ_MAC_PORT_VALID))) {
   4248  1.65.2.2  martin 		printf(", port address is not valid\n");
   4249  1.65.2.2  martin 		goto done;
   4250  1.65.2.2  martin 	}
   4251  1.65.2.2  martin 
   4252  1.65.2.2  martin 	memcpy(sc->sc_enaddr, addrs->port, ETHER_ADDR_LEN);
   4253  1.65.2.2  martin 	rv = 0;
   4254  1.65.2.2  martin 
   4255  1.65.2.2  martin done:
   4256  1.65.2.2  martin 	ixl_dmamem_free(sc, &idm);
   4257  1.65.2.2  martin 	return rv;
   4258  1.65.2.2  martin }
   4259  1.65.2.2  martin 
   4260  1.65.2.2  martin static int
   4261  1.65.2.2  martin ixl_get_switch_config(struct ixl_softc *sc)
   4262  1.65.2.2  martin {
   4263  1.65.2.2  martin 	struct ixl_dmamem idm;
   4264  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4265  1.65.2.2  martin 	struct ixl_aq_switch_config *hdr;
   4266  1.65.2.2  martin 	struct ixl_aq_switch_config_element *elms, *elm;
   4267  1.65.2.2  martin 	unsigned int nelm, i;
   4268  1.65.2.2  martin 	int rv;
   4269  1.65.2.2  martin 
   4270  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &idm, IXL_AQ_BUFLEN, 0) != 0) {
   4271  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   4272  1.65.2.2  martin 		    "unable to allocate switch config buffer\n");
   4273  1.65.2.2  martin 		return -1;
   4274  1.65.2.2  martin 	}
   4275  1.65.2.2  martin 
   4276  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4277  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF |
   4278  1.65.2.2  martin 	    (IXL_AQ_BUFLEN > I40E_AQ_LARGE_BUF ? IXL_AQ_LB : 0));
   4279  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_SWITCH_GET_CONFIG);
   4280  1.65.2.2  martin 	iaq.iaq_datalen = htole16(IXL_AQ_BUFLEN);
   4281  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(&idm));
   4282  1.65.2.2  martin 
   4283  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&idm), 0, IXL_DMA_LEN(&idm),
   4284  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD);
   4285  1.65.2.2  martin 
   4286  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   4287  1.65.2.2  martin 
   4288  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&idm), 0, IXL_DMA_LEN(&idm),
   4289  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD);
   4290  1.65.2.2  martin 
   4291  1.65.2.2  martin 	if (rv != 0) {
   4292  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "GET SWITCH CONFIG timeout\n");
   4293  1.65.2.2  martin 		rv = -1;
   4294  1.65.2.2  martin 		goto done;
   4295  1.65.2.2  martin 	}
   4296  1.65.2.2  martin 	if (iaq.iaq_retval != htole16(IXL_AQ_RC_OK)) {
   4297  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "GET SWITCH CONFIG error\n");
   4298  1.65.2.2  martin 		rv = -1;
   4299  1.65.2.2  martin 		goto done;
   4300  1.65.2.2  martin 	}
   4301  1.65.2.2  martin 
   4302  1.65.2.2  martin 	hdr = IXL_DMA_KVA(&idm);
   4303  1.65.2.2  martin 	elms = (struct ixl_aq_switch_config_element *)(hdr + 1);
   4304  1.65.2.2  martin 
   4305  1.65.2.2  martin 	nelm = le16toh(hdr->num_reported);
   4306  1.65.2.2  martin 	if (nelm < 1) {
   4307  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "no switch config available\n");
   4308  1.65.2.2  martin 		rv = -1;
   4309  1.65.2.2  martin 		goto done;
   4310  1.65.2.2  martin 	}
   4311  1.65.2.2  martin 
   4312  1.65.2.2  martin 	for (i = 0; i < nelm; i++) {
   4313  1.65.2.2  martin 		elm = &elms[i];
   4314  1.65.2.2  martin 
   4315  1.65.2.2  martin 		aprint_debug_dev(sc->sc_dev,
   4316  1.65.2.2  martin 		    "type %x revision %u seid %04x\n",
   4317  1.65.2.2  martin 		    elm->type, elm->revision, le16toh(elm->seid));
   4318  1.65.2.2  martin 		aprint_debug_dev(sc->sc_dev,
   4319  1.65.2.2  martin 		    "uplink %04x downlink %04x\n",
   4320  1.65.2.2  martin 		    le16toh(elm->uplink_seid),
   4321  1.65.2.2  martin 		    le16toh(elm->downlink_seid));
   4322  1.65.2.2  martin 		aprint_debug_dev(sc->sc_dev,
   4323  1.65.2.2  martin 		    "conntype %x scheduler %04x extra %04x\n",
   4324  1.65.2.2  martin 		    elm->connection_type,
   4325  1.65.2.2  martin 		    le16toh(elm->scheduler_id),
   4326  1.65.2.2  martin 		    le16toh(elm->element_info));
   4327  1.65.2.2  martin 	}
   4328  1.65.2.2  martin 
   4329  1.65.2.2  martin 	elm = &elms[0];
   4330  1.65.2.2  martin 
   4331  1.65.2.2  martin 	sc->sc_uplink_seid = elm->uplink_seid;
   4332  1.65.2.2  martin 	sc->sc_downlink_seid = elm->downlink_seid;
   4333  1.65.2.2  martin 	sc->sc_seid = elm->seid;
   4334  1.65.2.2  martin 
   4335  1.65.2.2  martin 	if ((sc->sc_uplink_seid == htole16(0)) !=
   4336  1.65.2.2  martin 	    (sc->sc_downlink_seid == htole16(0))) {
   4337  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "SEIDs are misconfigured\n");
   4338  1.65.2.2  martin 		rv = -1;
   4339  1.65.2.2  martin 		goto done;
   4340  1.65.2.2  martin 	}
   4341  1.65.2.2  martin 
   4342  1.65.2.2  martin done:
   4343  1.65.2.2  martin 	ixl_dmamem_free(sc, &idm);
   4344  1.65.2.2  martin 	return rv;
   4345  1.65.2.2  martin }
   4346  1.65.2.2  martin 
   4347  1.65.2.2  martin static int
   4348  1.65.2.2  martin ixl_phy_mask_ints(struct ixl_softc *sc)
   4349  1.65.2.2  martin {
   4350  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4351  1.65.2.2  martin 
   4352  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4353  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_PHY_SET_EVENT_MASK);
   4354  1.65.2.2  martin 	iaq.iaq_param[2] = htole32(IXL_AQ_PHY_EV_MASK &
   4355  1.65.2.2  martin 	    ~(IXL_AQ_PHY_EV_LINK_UPDOWN | IXL_AQ_PHY_EV_MODULE_QUAL_FAIL |
   4356  1.65.2.2  martin 	      IXL_AQ_PHY_EV_MEDIA_NA));
   4357  1.65.2.2  martin 
   4358  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0) {
   4359  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "SET PHY EVENT MASK timeout\n");
   4360  1.65.2.2  martin 		return -1;
   4361  1.65.2.2  martin 	}
   4362  1.65.2.2  martin 	if (iaq.iaq_retval != htole16(IXL_AQ_RC_OK)) {
   4363  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "SET PHY EVENT MASK error\n");
   4364  1.65.2.2  martin 		return -1;
   4365  1.65.2.2  martin 	}
   4366  1.65.2.2  martin 
   4367  1.65.2.2  martin 	return 0;
   4368  1.65.2.2  martin }
   4369  1.65.2.2  martin 
   4370  1.65.2.2  martin static int
   4371  1.65.2.2  martin ixl_get_phy_abilities(struct ixl_softc *sc,struct ixl_dmamem *idm)
   4372  1.65.2.2  martin {
   4373  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4374  1.65.2.2  martin 	int rv;
   4375  1.65.2.2  martin 
   4376  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4377  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF |
   4378  1.65.2.2  martin 	    (IXL_DMA_LEN(idm) > I40E_AQ_LARGE_BUF ? IXL_AQ_LB : 0));
   4379  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_PHY_GET_ABILITIES);
   4380  1.65.2.2  martin 	iaq.iaq_datalen = htole16(IXL_DMA_LEN(idm));
   4381  1.65.2.2  martin 	iaq.iaq_param[0] = htole32(IXL_AQ_PHY_REPORT_INIT);
   4382  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(idm));
   4383  1.65.2.2  martin 
   4384  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0, IXL_DMA_LEN(idm),
   4385  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD);
   4386  1.65.2.2  martin 
   4387  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   4388  1.65.2.2  martin 
   4389  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0, IXL_DMA_LEN(idm),
   4390  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD);
   4391  1.65.2.2  martin 
   4392  1.65.2.2  martin 	if (rv != 0)
   4393  1.65.2.2  martin 		return -1;
   4394  1.65.2.2  martin 
   4395  1.65.2.2  martin 	return le16toh(iaq.iaq_retval);
   4396  1.65.2.2  martin }
   4397  1.65.2.2  martin 
   4398  1.65.2.2  martin static int
   4399  1.65.2.2  martin ixl_get_phy_info(struct ixl_softc *sc)
   4400  1.65.2.2  martin {
   4401  1.65.2.2  martin 	struct ixl_dmamem idm;
   4402  1.65.2.2  martin 	struct ixl_aq_phy_abilities *phy;
   4403  1.65.2.2  martin 	int rv;
   4404  1.65.2.2  martin 
   4405  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &idm, IXL_AQ_BUFLEN, 0) != 0) {
   4406  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   4407  1.65.2.2  martin 		    "unable to allocate phy abilities buffer\n");
   4408  1.65.2.2  martin 		return -1;
   4409  1.65.2.2  martin 	}
   4410  1.65.2.2  martin 
   4411  1.65.2.2  martin 	rv = ixl_get_phy_abilities(sc, &idm);
   4412  1.65.2.2  martin 	switch (rv) {
   4413  1.65.2.2  martin 	case -1:
   4414  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "GET PHY ABILITIES timeout\n");
   4415  1.65.2.2  martin 		goto done;
   4416  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   4417  1.65.2.2  martin 		break;
   4418  1.65.2.2  martin 	case IXL_AQ_RC_EIO:
   4419  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,"unable to query phy types\n");
   4420  1.65.2.2  martin 		goto done;
   4421  1.65.2.2  martin 	default:
   4422  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   4423  1.65.2.2  martin 		    "GET PHY ABILITIIES error %u\n", rv);
   4424  1.65.2.2  martin 		goto done;
   4425  1.65.2.2  martin 	}
   4426  1.65.2.2  martin 
   4427  1.65.2.2  martin 	phy = IXL_DMA_KVA(&idm);
   4428  1.65.2.2  martin 
   4429  1.65.2.2  martin 	sc->sc_phy_types = le32toh(phy->phy_type);
   4430  1.65.2.2  martin 	sc->sc_phy_types |= (uint64_t)le32toh(phy->phy_type_ext) << 32;
   4431  1.65.2.2  martin 
   4432  1.65.2.2  martin 	sc->sc_phy_abilities = phy->abilities;
   4433  1.65.2.2  martin 	sc->sc_phy_linkspeed = phy->link_speed;
   4434  1.65.2.2  martin 	sc->sc_phy_fec_cfg = phy->fec_cfg_curr_mod_ext_info &
   4435  1.65.2.2  martin 	    (IXL_AQ_ENABLE_FEC_KR | IXL_AQ_ENABLE_FEC_RS |
   4436  1.65.2.2  martin 	    IXL_AQ_REQUEST_FEC_KR | IXL_AQ_REQUEST_FEC_RS);
   4437  1.65.2.2  martin 	sc->sc_eee_cap = phy->eee_capability;
   4438  1.65.2.2  martin 	sc->sc_eeer_val = phy->eeer_val;
   4439  1.65.2.2  martin 	sc->sc_d3_lpan = phy->d3_lpan;
   4440  1.65.2.2  martin 
   4441  1.65.2.2  martin 	rv = 0;
   4442  1.65.2.2  martin 
   4443  1.65.2.2  martin done:
   4444  1.65.2.2  martin 	ixl_dmamem_free(sc, &idm);
   4445  1.65.2.2  martin 	return rv;
   4446  1.65.2.2  martin }
   4447  1.65.2.2  martin 
   4448  1.65.2.2  martin static int
   4449  1.65.2.2  martin ixl_set_phy_config(struct ixl_softc *sc,
   4450  1.65.2.2  martin     uint8_t link_speed, uint8_t abilities, bool polling)
   4451  1.65.2.2  martin {
   4452  1.65.2.2  martin 	struct ixl_aq_phy_param *param;
   4453  1.65.2.2  martin 	struct ixl_atq iatq;
   4454  1.65.2.2  martin 	struct ixl_aq_desc *iaq;
   4455  1.65.2.2  martin 	int error;
   4456  1.65.2.2  martin 
   4457  1.65.2.2  martin 	memset(&iatq, 0, sizeof(iatq));
   4458  1.65.2.2  martin 
   4459  1.65.2.2  martin 	iaq = &iatq.iatq_desc;
   4460  1.65.2.2  martin 	iaq->iaq_opcode = htole16(IXL_AQ_OP_PHY_SET_CONFIG);
   4461  1.65.2.2  martin 	param = (struct ixl_aq_phy_param *)&iaq->iaq_param;
   4462  1.65.2.2  martin 	param->phy_types = htole32((uint32_t)sc->sc_phy_types);
   4463  1.65.2.2  martin 	param->phy_type_ext = (uint8_t)(sc->sc_phy_types >> 32);
   4464  1.65.2.2  martin 	param->link_speed = link_speed;
   4465  1.65.2.2  martin 	param->abilities = abilities | IXL_AQ_PHY_ABILITY_AUTO_LINK;
   4466  1.65.2.2  martin 	param->fec_cfg = sc->sc_phy_fec_cfg;
   4467  1.65.2.2  martin 	param->eee_capability = sc->sc_eee_cap;
   4468  1.65.2.2  martin 	param->eeer_val = sc->sc_eeer_val;
   4469  1.65.2.2  martin 	param->d3_lpan = sc->sc_d3_lpan;
   4470  1.65.2.2  martin 
   4471  1.65.2.2  martin 	if (polling)
   4472  1.65.2.2  martin 		error = ixl_atq_poll(sc, iaq, 250);
   4473  1.65.2.2  martin 	else
   4474  1.65.2.2  martin 		error = ixl_atq_exec(sc, &iatq);
   4475  1.65.2.2  martin 
   4476  1.65.2.2  martin 	if (error != 0)
   4477  1.65.2.2  martin 		return error;
   4478  1.65.2.2  martin 
   4479  1.65.2.2  martin 	switch (le16toh(iaq->iaq_retval)) {
   4480  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   4481  1.65.2.2  martin 		break;
   4482  1.65.2.2  martin 	case IXL_AQ_RC_EPERM:
   4483  1.65.2.2  martin 		return EPERM;
   4484  1.65.2.2  martin 	default:
   4485  1.65.2.2  martin 		return EIO;
   4486  1.65.2.2  martin 	}
   4487  1.65.2.2  martin 
   4488  1.65.2.2  martin 	return 0;
   4489  1.65.2.2  martin }
   4490  1.65.2.2  martin 
   4491  1.65.2.2  martin static int
   4492  1.65.2.2  martin ixl_set_phy_autoselect(struct ixl_softc *sc)
   4493  1.65.2.2  martin {
   4494  1.65.2.2  martin 	uint8_t link_speed, abilities;
   4495  1.65.2.2  martin 
   4496  1.65.2.2  martin 	link_speed = sc->sc_phy_linkspeed;
   4497  1.65.2.2  martin 	abilities = IXL_PHY_ABILITY_LINKUP | IXL_PHY_ABILITY_AUTONEGO;
   4498  1.65.2.2  martin 
   4499  1.65.2.2  martin 	return ixl_set_phy_config(sc, link_speed, abilities, true);
   4500  1.65.2.2  martin }
   4501  1.65.2.2  martin 
   4502  1.65.2.2  martin static int
   4503  1.65.2.2  martin ixl_get_link_status_poll(struct ixl_softc *sc, int *l)
   4504  1.65.2.2  martin {
   4505  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4506  1.65.2.2  martin 	struct ixl_aq_link_param *param;
   4507  1.65.2.2  martin 	int link;
   4508  1.65.2.2  martin 
   4509  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4510  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_PHY_LINK_STATUS);
   4511  1.65.2.2  martin 	param = (struct ixl_aq_link_param *)iaq.iaq_param;
   4512  1.65.2.2  martin 	param->notify = IXL_AQ_LINK_NOTIFY;
   4513  1.65.2.2  martin 
   4514  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0) {
   4515  1.65.2.2  martin 		return ETIMEDOUT;
   4516  1.65.2.2  martin 	}
   4517  1.65.2.2  martin 	if (iaq.iaq_retval != htole16(IXL_AQ_RC_OK)) {
   4518  1.65.2.2  martin 		return EIO;
   4519  1.65.2.2  martin 	}
   4520  1.65.2.2  martin 
   4521  1.65.2.2  martin 	/* It is unneccessary to hold lock */
   4522  1.65.2.2  martin 	link = ixl_set_link_status_locked(sc, &iaq);
   4523  1.65.2.2  martin 
   4524  1.65.2.2  martin 	if (l != NULL)
   4525  1.65.2.2  martin 		*l = link;
   4526  1.65.2.2  martin 
   4527  1.65.2.2  martin 	return 0;
   4528  1.65.2.2  martin }
   4529  1.65.2.2  martin 
   4530  1.65.2.2  martin static int
   4531  1.65.2.2  martin ixl_get_vsi(struct ixl_softc *sc)
   4532  1.65.2.2  martin {
   4533  1.65.2.2  martin 	struct ixl_dmamem *vsi = &sc->sc_scratch;
   4534  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4535  1.65.2.2  martin 	struct ixl_aq_vsi_param *param;
   4536  1.65.2.2  martin 	struct ixl_aq_vsi_reply *reply;
   4537  1.65.2.2  martin 	struct ixl_aq_vsi_data *data;
   4538  1.65.2.2  martin 	int rv;
   4539  1.65.2.2  martin 
   4540  1.65.2.2  martin 	/* grumble, vsi info isn't "known" at compile time */
   4541  1.65.2.2  martin 
   4542  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4543  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF |
   4544  1.65.2.2  martin 	    (IXL_DMA_LEN(vsi) > I40E_AQ_LARGE_BUF ? IXL_AQ_LB : 0));
   4545  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_GET_VSI_PARAMS);
   4546  1.65.2.2  martin 	iaq.iaq_datalen = htole16(IXL_DMA_LEN(vsi));
   4547  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(vsi));
   4548  1.65.2.2  martin 
   4549  1.65.2.2  martin 	param = (struct ixl_aq_vsi_param *)iaq.iaq_param;
   4550  1.65.2.2  martin 	param->uplink_seid = sc->sc_seid;
   4551  1.65.2.2  martin 
   4552  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(vsi), 0, IXL_DMA_LEN(vsi),
   4553  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD);
   4554  1.65.2.2  martin 
   4555  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   4556  1.65.2.2  martin 
   4557  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(vsi), 0, IXL_DMA_LEN(vsi),
   4558  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD);
   4559  1.65.2.2  martin 
   4560  1.65.2.2  martin 	if (rv != 0) {
   4561  1.65.2.2  martin 		return ETIMEDOUT;
   4562  1.65.2.2  martin 	}
   4563  1.65.2.2  martin 
   4564  1.65.2.2  martin 	switch (le16toh(iaq.iaq_retval)) {
   4565  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   4566  1.65.2.2  martin 		break;
   4567  1.65.2.2  martin 	case IXL_AQ_RC_ENOENT:
   4568  1.65.2.2  martin 		return ENOENT;
   4569  1.65.2.2  martin 	case IXL_AQ_RC_EACCES:
   4570  1.65.2.2  martin 		return EACCES;
   4571  1.65.2.2  martin 	default:
   4572  1.65.2.2  martin 		return EIO;
   4573  1.65.2.2  martin 	}
   4574  1.65.2.2  martin 
   4575  1.65.2.2  martin 	reply = (struct ixl_aq_vsi_reply *)iaq.iaq_param;
   4576  1.65.2.2  martin 	sc->sc_vsi_number = le16toh(reply->vsi_number);
   4577  1.65.2.2  martin 	data = IXL_DMA_KVA(vsi);
   4578  1.65.2.2  martin 	sc->sc_vsi_stat_counter_idx = le16toh(data->stat_counter_idx);
   4579  1.65.2.2  martin 
   4580  1.65.2.2  martin 	return 0;
   4581  1.65.2.2  martin }
   4582  1.65.2.2  martin 
   4583  1.65.2.2  martin static int
   4584  1.65.2.2  martin ixl_set_vsi(struct ixl_softc *sc)
   4585  1.65.2.2  martin {
   4586  1.65.2.2  martin 	struct ixl_dmamem *vsi = &sc->sc_scratch;
   4587  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4588  1.65.2.2  martin 	struct ixl_aq_vsi_param *param;
   4589  1.65.2.2  martin 	struct ixl_aq_vsi_data *data = IXL_DMA_KVA(vsi);
   4590  1.65.2.2  martin 	unsigned int qnum;
   4591  1.65.2.2  martin 	uint16_t val;
   4592  1.65.2.2  martin 	int rv;
   4593  1.65.2.2  martin 
   4594  1.65.2.2  martin 	qnum = sc->sc_nqueue_pairs - 1;
   4595  1.65.2.2  martin 
   4596  1.65.2.2  martin 	data->valid_sections = htole16(IXL_AQ_VSI_VALID_QUEUE_MAP |
   4597  1.65.2.2  martin 	    IXL_AQ_VSI_VALID_VLAN);
   4598  1.65.2.2  martin 
   4599  1.65.2.2  martin 	CLR(data->mapping_flags, htole16(IXL_AQ_VSI_QUE_MAP_MASK));
   4600  1.65.2.2  martin 	SET(data->mapping_flags, htole16(IXL_AQ_VSI_QUE_MAP_CONTIG));
   4601  1.65.2.2  martin 	data->queue_mapping[0] = htole16(0);
   4602  1.65.2.2  martin 	data->tc_mapping[0] = htole16((0 << IXL_AQ_VSI_TC_Q_OFFSET_SHIFT) |
   4603  1.65.2.2  martin 	    (qnum << IXL_AQ_VSI_TC_Q_NUMBER_SHIFT));
   4604  1.65.2.2  martin 
   4605  1.65.2.2  martin 	val = le16toh(data->port_vlan_flags);
   4606  1.65.2.2  martin 	CLR(val, IXL_AQ_VSI_PVLAN_MODE_MASK | IXL_AQ_VSI_PVLAN_EMOD_MASK);
   4607  1.65.2.2  martin 	SET(val, IXL_AQ_VSI_PVLAN_MODE_ALL);
   4608  1.65.2.2  martin 
   4609  1.65.2.2  martin 	if (ISSET(sc->sc_cur_ec_capenable, ETHERCAP_VLAN_HWTAGGING)) {
   4610  1.65.2.2  martin 		SET(val, IXL_AQ_VSI_PVLAN_EMOD_STR_BOTH);
   4611  1.65.2.2  martin 	} else {
   4612  1.65.2.2  martin 		SET(val, IXL_AQ_VSI_PVLAN_EMOD_NOTHING);
   4613  1.65.2.2  martin 	}
   4614  1.65.2.2  martin 
   4615  1.65.2.2  martin 	data->port_vlan_flags = htole16(val);
   4616  1.65.2.2  martin 
   4617  1.65.2.2  martin 	/* grumble, vsi info isn't "known" at compile time */
   4618  1.65.2.2  martin 
   4619  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4620  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF | IXL_AQ_RD |
   4621  1.65.2.2  martin 	    (IXL_DMA_LEN(vsi) > I40E_AQ_LARGE_BUF ? IXL_AQ_LB : 0));
   4622  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_UPD_VSI_PARAMS);
   4623  1.65.2.2  martin 	iaq.iaq_datalen = htole16(IXL_DMA_LEN(vsi));
   4624  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(vsi));
   4625  1.65.2.2  martin 
   4626  1.65.2.2  martin 	param = (struct ixl_aq_vsi_param *)iaq.iaq_param;
   4627  1.65.2.2  martin 	param->uplink_seid = sc->sc_seid;
   4628  1.65.2.2  martin 
   4629  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(vsi), 0, IXL_DMA_LEN(vsi),
   4630  1.65.2.2  martin 	    BUS_DMASYNC_PREWRITE);
   4631  1.65.2.2  martin 
   4632  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   4633  1.65.2.2  martin 
   4634  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(vsi), 0, IXL_DMA_LEN(vsi),
   4635  1.65.2.2  martin 	    BUS_DMASYNC_POSTWRITE);
   4636  1.65.2.2  martin 
   4637  1.65.2.2  martin 	if (rv != 0) {
   4638  1.65.2.2  martin 		return ETIMEDOUT;
   4639  1.65.2.2  martin 	}
   4640  1.65.2.2  martin 
   4641  1.65.2.2  martin 	switch (le16toh(iaq.iaq_retval)) {
   4642  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   4643  1.65.2.2  martin 		break;
   4644  1.65.2.2  martin 	case IXL_AQ_RC_ENOENT:
   4645  1.65.2.2  martin 		return ENOENT;
   4646  1.65.2.2  martin 	case IXL_AQ_RC_EACCES:
   4647  1.65.2.2  martin 		return EACCES;
   4648  1.65.2.2  martin 	default:
   4649  1.65.2.2  martin 		return EIO;
   4650  1.65.2.2  martin 	}
   4651  1.65.2.2  martin 
   4652  1.65.2.2  martin 	return 0;
   4653  1.65.2.2  martin }
   4654  1.65.2.2  martin 
   4655  1.65.2.2  martin static void
   4656  1.65.2.2  martin ixl_set_filter_control(struct ixl_softc *sc)
   4657  1.65.2.2  martin {
   4658  1.65.2.2  martin 	uint32_t reg;
   4659  1.65.2.2  martin 
   4660  1.65.2.2  martin 	reg = ixl_rd_rx_csr(sc, I40E_PFQF_CTL_0);
   4661  1.65.2.2  martin 
   4662  1.65.2.2  martin 	CLR(reg, I40E_PFQF_CTL_0_HASHLUTSIZE_MASK);
   4663  1.65.2.2  martin 	SET(reg, I40E_HASH_LUT_SIZE_128 << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT);
   4664  1.65.2.2  martin 
   4665  1.65.2.2  martin 	SET(reg, I40E_PFQF_CTL_0_FD_ENA_MASK);
   4666  1.65.2.2  martin 	SET(reg, I40E_PFQF_CTL_0_ETYPE_ENA_MASK);
   4667  1.65.2.2  martin 	SET(reg, I40E_PFQF_CTL_0_MACVLAN_ENA_MASK);
   4668  1.65.2.2  martin 
   4669  1.65.2.2  martin 	ixl_wr_rx_csr(sc, I40E_PFQF_CTL_0, reg);
   4670  1.65.2.2  martin }
   4671  1.65.2.2  martin 
   4672  1.65.2.2  martin static inline void
   4673  1.65.2.2  martin ixl_get_default_rss_key(uint32_t *buf, size_t len)
   4674  1.65.2.2  martin {
   4675  1.65.2.2  martin 	size_t cplen;
   4676  1.65.2.2  martin 	uint8_t rss_seed[RSS_KEYSIZE];
   4677  1.65.2.2  martin 
   4678  1.65.2.2  martin 	rss_getkey(rss_seed);
   4679  1.65.2.2  martin 	memset(buf, 0, len);
   4680  1.65.2.2  martin 
   4681  1.65.2.2  martin 	cplen = MIN(len, sizeof(rss_seed));
   4682  1.65.2.2  martin 	memcpy(buf, rss_seed, cplen);
   4683  1.65.2.2  martin }
   4684  1.65.2.2  martin 
   4685  1.65.2.2  martin static int
   4686  1.65.2.2  martin ixl_set_rss_key(struct ixl_softc *sc, uint8_t *key, size_t keylen)
   4687  1.65.2.2  martin {
   4688  1.65.2.2  martin 	struct ixl_dmamem *idm;
   4689  1.65.2.2  martin 	struct ixl_atq iatq;
   4690  1.65.2.2  martin 	struct ixl_aq_desc *iaq;
   4691  1.65.2.2  martin 	struct ixl_aq_rss_key_param *param;
   4692  1.65.2.2  martin 	struct ixl_aq_rss_key_data *data;
   4693  1.65.2.2  martin 	size_t len, datalen, stdlen, extlen;
   4694  1.65.2.2  martin 	uint16_t vsi_id;
   4695  1.65.2.2  martin 	int rv;
   4696  1.65.2.2  martin 
   4697  1.65.2.2  martin 	memset(&iatq, 0, sizeof(iatq));
   4698  1.65.2.2  martin 	iaq = &iatq.iatq_desc;
   4699  1.65.2.2  martin 	idm = &sc->sc_aqbuf;
   4700  1.65.2.2  martin 
   4701  1.65.2.2  martin 	datalen = sizeof(*data);
   4702  1.65.2.2  martin 
   4703  1.65.2.2  martin 	/*XXX The buf size has to be less than the size of the register */
   4704  1.65.2.2  martin 	datalen = MIN(IXL_RSS_KEY_SIZE_REG * sizeof(uint32_t), datalen);
   4705  1.65.2.2  martin 
   4706  1.65.2.2  martin 	iaq->iaq_flags = htole16(IXL_AQ_BUF | IXL_AQ_RD |
   4707  1.65.2.2  martin 	    (datalen > I40E_AQ_LARGE_BUF ? IXL_AQ_LB : 0));
   4708  1.65.2.2  martin 	iaq->iaq_opcode = htole16(IXL_AQ_OP_RSS_SET_KEY);
   4709  1.65.2.2  martin 	iaq->iaq_datalen = htole16(datalen);
   4710  1.65.2.2  martin 
   4711  1.65.2.2  martin 	param = (struct ixl_aq_rss_key_param *)iaq->iaq_param;
   4712  1.65.2.2  martin 	vsi_id = (sc->sc_vsi_number << IXL_AQ_RSSKEY_VSI_ID_SHIFT) |
   4713  1.65.2.2  martin 	    IXL_AQ_RSSKEY_VSI_VALID;
   4714  1.65.2.2  martin 	param->vsi_id = htole16(vsi_id);
   4715  1.65.2.2  martin 
   4716  1.65.2.2  martin 	memset(IXL_DMA_KVA(idm), 0, IXL_DMA_LEN(idm));
   4717  1.65.2.2  martin 	data = IXL_DMA_KVA(idm);
   4718  1.65.2.2  martin 
   4719  1.65.2.2  martin 	len = MIN(keylen, datalen);
   4720  1.65.2.2  martin 	stdlen = MIN(sizeof(data->standard_rss_key), len);
   4721  1.65.2.2  martin 	memcpy(data->standard_rss_key, key, stdlen);
   4722  1.65.2.2  martin 	len = (len > stdlen) ? (len - stdlen) : 0;
   4723  1.65.2.2  martin 
   4724  1.65.2.2  martin 	extlen = MIN(sizeof(data->extended_hash_key), len);
   4725  1.65.2.2  martin 	extlen = (stdlen < keylen) ? 0 : keylen - stdlen;
   4726  1.65.2.2  martin 	memcpy(data->extended_hash_key, key + stdlen, extlen);
   4727  1.65.2.2  martin 
   4728  1.65.2.2  martin 	ixl_aq_dva(iaq, IXL_DMA_DVA(idm));
   4729  1.65.2.2  martin 
   4730  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0,
   4731  1.65.2.2  martin 	    IXL_DMA_LEN(idm), BUS_DMASYNC_PREWRITE);
   4732  1.65.2.2  martin 
   4733  1.65.2.2  martin 	rv = ixl_atq_exec(sc, &iatq);
   4734  1.65.2.2  martin 
   4735  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0,
   4736  1.65.2.2  martin 	    IXL_DMA_LEN(idm), BUS_DMASYNC_POSTWRITE);
   4737  1.65.2.2  martin 
   4738  1.65.2.2  martin 	if (rv != 0) {
   4739  1.65.2.2  martin 		return ETIMEDOUT;
   4740  1.65.2.2  martin 	}
   4741  1.65.2.2  martin 
   4742  1.65.2.2  martin 	if (iaq->iaq_retval != htole16(IXL_AQ_RC_OK)) {
   4743  1.65.2.2  martin 		return EIO;
   4744  1.65.2.2  martin 	}
   4745  1.65.2.2  martin 
   4746  1.65.2.2  martin 	return 0;
   4747  1.65.2.2  martin }
   4748  1.65.2.2  martin 
   4749  1.65.2.2  martin static int
   4750  1.65.2.2  martin ixl_set_rss_lut(struct ixl_softc *sc, uint8_t *lut, size_t lutlen)
   4751  1.65.2.2  martin {
   4752  1.65.2.2  martin 	struct ixl_dmamem *idm;
   4753  1.65.2.2  martin 	struct ixl_atq iatq;
   4754  1.65.2.2  martin 	struct ixl_aq_desc *iaq;
   4755  1.65.2.2  martin 	struct ixl_aq_rss_lut_param *param;
   4756  1.65.2.2  martin 	uint16_t vsi_id;
   4757  1.65.2.2  martin 	uint8_t *data;
   4758  1.65.2.2  martin 	size_t dmalen;
   4759  1.65.2.2  martin 	int rv;
   4760  1.65.2.2  martin 
   4761  1.65.2.2  martin 	memset(&iatq, 0, sizeof(iatq));
   4762  1.65.2.2  martin 	iaq = &iatq.iatq_desc;
   4763  1.65.2.2  martin 	idm = &sc->sc_aqbuf;
   4764  1.65.2.2  martin 
   4765  1.65.2.2  martin 	dmalen = MIN(lutlen, IXL_DMA_LEN(idm));
   4766  1.65.2.2  martin 
   4767  1.65.2.2  martin 	iaq->iaq_flags = htole16(IXL_AQ_BUF | IXL_AQ_RD |
   4768  1.65.2.2  martin 	    (dmalen > I40E_AQ_LARGE_BUF ? IXL_AQ_LB : 0));
   4769  1.65.2.2  martin 	iaq->iaq_opcode = htole16(IXL_AQ_OP_RSS_SET_LUT);
   4770  1.65.2.2  martin 	iaq->iaq_datalen = htole16(dmalen);
   4771  1.65.2.2  martin 
   4772  1.65.2.2  martin 	memset(IXL_DMA_KVA(idm), 0, IXL_DMA_LEN(idm));
   4773  1.65.2.2  martin 	data = IXL_DMA_KVA(idm);
   4774  1.65.2.2  martin 	memcpy(data, lut, dmalen);
   4775  1.65.2.2  martin 	ixl_aq_dva(iaq, IXL_DMA_DVA(idm));
   4776  1.65.2.2  martin 
   4777  1.65.2.2  martin 	param = (struct ixl_aq_rss_lut_param *)iaq->iaq_param;
   4778  1.65.2.2  martin 	vsi_id = (sc->sc_vsi_number << IXL_AQ_RSSLUT_VSI_ID_SHIFT) |
   4779  1.65.2.2  martin 	    IXL_AQ_RSSLUT_VSI_VALID;
   4780  1.65.2.2  martin 	param->vsi_id = htole16(vsi_id);
   4781  1.65.2.2  martin 	param->flags = htole16(IXL_AQ_RSSLUT_TABLE_TYPE_PF <<
   4782  1.65.2.2  martin 	    IXL_AQ_RSSLUT_TABLE_TYPE_SHIFT);
   4783  1.65.2.2  martin 
   4784  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0,
   4785  1.65.2.2  martin 	    IXL_DMA_LEN(idm), BUS_DMASYNC_PREWRITE);
   4786  1.65.2.2  martin 
   4787  1.65.2.2  martin 	rv = ixl_atq_exec(sc, &iatq);
   4788  1.65.2.2  martin 
   4789  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0,
   4790  1.65.2.2  martin 	    IXL_DMA_LEN(idm), BUS_DMASYNC_POSTWRITE);
   4791  1.65.2.2  martin 
   4792  1.65.2.2  martin 	if (rv != 0) {
   4793  1.65.2.2  martin 		return ETIMEDOUT;
   4794  1.65.2.2  martin 	}
   4795  1.65.2.2  martin 
   4796  1.65.2.2  martin 	if (iaq->iaq_retval != htole16(IXL_AQ_RC_OK)) {
   4797  1.65.2.2  martin 		return EIO;
   4798  1.65.2.2  martin 	}
   4799  1.65.2.2  martin 
   4800  1.65.2.2  martin 	return 0;
   4801  1.65.2.2  martin }
   4802  1.65.2.2  martin 
   4803  1.65.2.2  martin static int
   4804  1.65.2.2  martin ixl_register_rss_key(struct ixl_softc *sc)
   4805  1.65.2.2  martin {
   4806  1.65.2.2  martin 	uint32_t rss_seed[IXL_RSS_KEY_SIZE_REG];
   4807  1.65.2.2  martin 	int rv;
   4808  1.65.2.2  martin 	size_t i;
   4809  1.65.2.2  martin 
   4810  1.65.2.2  martin 	ixl_get_default_rss_key(rss_seed, sizeof(rss_seed));
   4811  1.65.2.2  martin 
   4812  1.65.2.2  martin 	if (ISSET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_RSS)){
   4813  1.65.2.2  martin 		rv = ixl_set_rss_key(sc, (uint8_t*)rss_seed,
   4814  1.65.2.2  martin 		    sizeof(rss_seed));
   4815  1.65.2.2  martin 	} else {
   4816  1.65.2.2  martin 		rv = 0;
   4817  1.65.2.2  martin 		for (i = 0; i < IXL_RSS_KEY_SIZE_REG; i++) {
   4818  1.65.2.2  martin 			ixl_wr_rx_csr(sc, I40E_PFQF_HKEY(i), rss_seed[i]);
   4819  1.65.2.2  martin 		}
   4820  1.65.2.2  martin 	}
   4821  1.65.2.2  martin 
   4822  1.65.2.2  martin 	return rv;
   4823  1.65.2.2  martin }
   4824  1.65.2.2  martin 
   4825  1.65.2.2  martin static void
   4826  1.65.2.2  martin ixl_register_rss_pctype(struct ixl_softc *sc)
   4827  1.65.2.2  martin {
   4828  1.65.2.2  martin 	uint64_t set_hena = 0;
   4829  1.65.2.2  martin 	uint32_t hena0, hena1;
   4830  1.65.2.2  martin 
   4831  1.65.2.2  martin 	/*
   4832  1.65.2.2  martin 	 * We use TCP/UDP with IPv4/IPv6 by default.
   4833  1.65.2.2  martin 	 * Note: the device can not use just IP header in each
   4834  1.65.2.2  martin 	 * TCP/UDP packets for the RSS hash calculation.
   4835  1.65.2.2  martin 	 */
   4836  1.65.2.2  martin 	if (sc->sc_mac_type == I40E_MAC_X722)
   4837  1.65.2.2  martin 		set_hena = IXL_RSS_HENA_DEFAULT_X722;
   4838  1.65.2.2  martin 	else
   4839  1.65.2.2  martin 		set_hena = IXL_RSS_HENA_DEFAULT_XL710;
   4840  1.65.2.2  martin 
   4841  1.65.2.2  martin 	hena0 = ixl_rd_rx_csr(sc, I40E_PFQF_HENA(0));
   4842  1.65.2.2  martin 	hena1 = ixl_rd_rx_csr(sc, I40E_PFQF_HENA(1));
   4843  1.65.2.2  martin 
   4844  1.65.2.2  martin 	SET(hena0, set_hena);
   4845  1.65.2.2  martin 	SET(hena1, set_hena >> 32);
   4846  1.65.2.2  martin 
   4847  1.65.2.2  martin 	ixl_wr_rx_csr(sc, I40E_PFQF_HENA(0), hena0);
   4848  1.65.2.2  martin 	ixl_wr_rx_csr(sc, I40E_PFQF_HENA(1), hena1);
   4849  1.65.2.2  martin }
   4850  1.65.2.2  martin 
   4851  1.65.2.2  martin static int
   4852  1.65.2.2  martin ixl_register_rss_hlut(struct ixl_softc *sc)
   4853  1.65.2.2  martin {
   4854  1.65.2.2  martin 	unsigned int qid;
   4855  1.65.2.2  martin 	uint8_t hlut_buf[512], lut_mask;
   4856  1.65.2.2  martin 	uint32_t *hluts;
   4857  1.65.2.2  martin 	size_t i, hluts_num;
   4858  1.65.2.2  martin 	int rv;
   4859  1.65.2.2  martin 
   4860  1.65.2.2  martin 	lut_mask = (0x01 << sc->sc_rss_table_entry_width) - 1;
   4861  1.65.2.2  martin 
   4862  1.65.2.2  martin 	for (i = 0; i < sc->sc_rss_table_size; i++) {
   4863  1.65.2.2  martin 		qid = i % sc->sc_nqueue_pairs;
   4864  1.65.2.2  martin 		hlut_buf[i] = qid & lut_mask;
   4865  1.65.2.2  martin 	}
   4866  1.65.2.2  martin 
   4867  1.65.2.2  martin 	if (ISSET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_RSS)) {
   4868  1.65.2.2  martin 		rv = ixl_set_rss_lut(sc, hlut_buf, sizeof(hlut_buf));
   4869  1.65.2.2  martin 	} else {
   4870  1.65.2.2  martin 		rv = 0;
   4871  1.65.2.2  martin 		hluts = (uint32_t *)hlut_buf;
   4872  1.65.2.2  martin 		hluts_num = sc->sc_rss_table_size >> 2;
   4873  1.65.2.2  martin 		for (i = 0; i < hluts_num; i++) {
   4874  1.65.2.2  martin 			ixl_wr(sc, I40E_PFQF_HLUT(i), hluts[i]);
   4875  1.65.2.2  martin 		}
   4876  1.65.2.2  martin 		ixl_flush(sc);
   4877  1.65.2.2  martin 	}
   4878  1.65.2.2  martin 
   4879  1.65.2.2  martin 	return rv;
   4880  1.65.2.2  martin }
   4881  1.65.2.2  martin 
   4882  1.65.2.2  martin static void
   4883  1.65.2.2  martin ixl_config_rss(struct ixl_softc *sc)
   4884  1.65.2.2  martin {
   4885  1.65.2.2  martin 
   4886  1.65.2.2  martin 	KASSERT(mutex_owned(&sc->sc_cfg_lock));
   4887  1.65.2.2  martin 
   4888  1.65.2.2  martin 	ixl_register_rss_key(sc);
   4889  1.65.2.2  martin 	ixl_register_rss_pctype(sc);
   4890  1.65.2.2  martin 	ixl_register_rss_hlut(sc);
   4891  1.65.2.2  martin }
   4892  1.65.2.2  martin 
   4893  1.65.2.2  martin static const struct ixl_phy_type *
   4894  1.65.2.2  martin ixl_search_phy_type(uint8_t phy_type)
   4895  1.65.2.2  martin {
   4896  1.65.2.2  martin 	const struct ixl_phy_type *itype;
   4897  1.65.2.2  martin 	uint64_t mask;
   4898  1.65.2.2  martin 	unsigned int i;
   4899  1.65.2.2  martin 
   4900  1.65.2.2  martin 	if (phy_type >= 64)
   4901  1.65.2.2  martin 		return NULL;
   4902  1.65.2.2  martin 
   4903  1.65.2.2  martin 	mask = 1ULL << phy_type;
   4904  1.65.2.2  martin 
   4905  1.65.2.2  martin 	for (i = 0; i < __arraycount(ixl_phy_type_map); i++) {
   4906  1.65.2.2  martin 		itype = &ixl_phy_type_map[i];
   4907  1.65.2.2  martin 
   4908  1.65.2.2  martin 		if (ISSET(itype->phy_type, mask))
   4909  1.65.2.2  martin 			return itype;
   4910  1.65.2.2  martin 	}
   4911  1.65.2.2  martin 
   4912  1.65.2.2  martin 	return NULL;
   4913  1.65.2.2  martin }
   4914  1.65.2.2  martin 
   4915  1.65.2.2  martin static uint64_t
   4916  1.65.2.2  martin ixl_search_link_speed(uint8_t link_speed)
   4917  1.65.2.2  martin {
   4918  1.65.2.2  martin 	const struct ixl_speed_type *type;
   4919  1.65.2.2  martin 	unsigned int i;
   4920  1.65.2.2  martin 
   4921  1.65.2.2  martin 	for (i = 0; i < __arraycount(ixl_speed_type_map); i++) {
   4922  1.65.2.2  martin 		type = &ixl_speed_type_map[i];
   4923  1.65.2.2  martin 
   4924  1.65.2.2  martin 		if (ISSET(type->dev_speed, link_speed))
   4925  1.65.2.2  martin 			return type->net_speed;
   4926  1.65.2.2  martin 	}
   4927  1.65.2.2  martin 
   4928  1.65.2.2  martin 	return 0;
   4929  1.65.2.2  martin }
   4930  1.65.2.2  martin 
   4931  1.65.2.2  martin static uint8_t
   4932  1.65.2.2  martin ixl_search_baudrate(uint64_t baudrate)
   4933  1.65.2.2  martin {
   4934  1.65.2.2  martin 	const struct ixl_speed_type *type;
   4935  1.65.2.2  martin 	unsigned int i;
   4936  1.65.2.2  martin 
   4937  1.65.2.2  martin 	for (i = 0; i < __arraycount(ixl_speed_type_map); i++) {
   4938  1.65.2.2  martin 		type = &ixl_speed_type_map[i];
   4939  1.65.2.2  martin 
   4940  1.65.2.2  martin 		if (type->net_speed == baudrate) {
   4941  1.65.2.2  martin 			return type->dev_speed;
   4942  1.65.2.2  martin 		}
   4943  1.65.2.2  martin 	}
   4944  1.65.2.2  martin 
   4945  1.65.2.2  martin 	return 0;
   4946  1.65.2.2  martin }
   4947  1.65.2.2  martin 
   4948  1.65.2.2  martin static int
   4949  1.65.2.2  martin ixl_restart_an(struct ixl_softc *sc)
   4950  1.65.2.2  martin {
   4951  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4952  1.65.2.2  martin 
   4953  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4954  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_PHY_RESTART_AN);
   4955  1.65.2.2  martin 	iaq.iaq_param[0] =
   4956  1.65.2.2  martin 	    htole32(IXL_AQ_PHY_RESTART_AN | IXL_AQ_PHY_LINK_ENABLE);
   4957  1.65.2.2  martin 
   4958  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0) {
   4959  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "RESTART AN timeout\n");
   4960  1.65.2.2  martin 		return -1;
   4961  1.65.2.2  martin 	}
   4962  1.65.2.2  martin 	if (iaq.iaq_retval != htole16(IXL_AQ_RC_OK)) {
   4963  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev, "RESTART AN error\n");
   4964  1.65.2.2  martin 		return -1;
   4965  1.65.2.2  martin 	}
   4966  1.65.2.2  martin 
   4967  1.65.2.2  martin 	return 0;
   4968  1.65.2.2  martin }
   4969  1.65.2.2  martin 
   4970  1.65.2.2  martin static int
   4971  1.65.2.2  martin ixl_add_macvlan(struct ixl_softc *sc, const uint8_t *macaddr,
   4972  1.65.2.2  martin     uint16_t vlan, uint16_t flags)
   4973  1.65.2.2  martin {
   4974  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   4975  1.65.2.2  martin 	struct ixl_aq_add_macvlan *param;
   4976  1.65.2.2  martin 	struct ixl_aq_add_macvlan_elem *elem;
   4977  1.65.2.2  martin 
   4978  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   4979  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF | IXL_AQ_RD);
   4980  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_ADD_MACVLAN);
   4981  1.65.2.2  martin 	iaq.iaq_datalen = htole16(sizeof(*elem));
   4982  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(&sc->sc_scratch));
   4983  1.65.2.2  martin 
   4984  1.65.2.2  martin 	param = (struct ixl_aq_add_macvlan *)&iaq.iaq_param;
   4985  1.65.2.2  martin 	param->num_addrs = htole16(1);
   4986  1.65.2.2  martin 	param->seid0 = htole16(0x8000) | sc->sc_seid;
   4987  1.65.2.2  martin 	param->seid1 = 0;
   4988  1.65.2.2  martin 	param->seid2 = 0;
   4989  1.65.2.2  martin 
   4990  1.65.2.2  martin 	elem = IXL_DMA_KVA(&sc->sc_scratch);
   4991  1.65.2.2  martin 	memset(elem, 0, sizeof(*elem));
   4992  1.65.2.2  martin 	memcpy(elem->macaddr, macaddr, ETHER_ADDR_LEN);
   4993  1.65.2.2  martin 	elem->flags = htole16(IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH | flags);
   4994  1.65.2.2  martin 	elem->vlan = htole16(vlan);
   4995  1.65.2.2  martin 
   4996  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0) {
   4997  1.65.2.2  martin 		return IXL_AQ_RC_EINVAL;
   4998  1.65.2.2  martin 	}
   4999  1.65.2.2  martin 
   5000  1.65.2.2  martin 	switch (le16toh(iaq.iaq_retval)) {
   5001  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   5002  1.65.2.2  martin 		break;
   5003  1.65.2.2  martin 	case IXL_AQ_RC_ENOSPC:
   5004  1.65.2.2  martin 		return ENOSPC;
   5005  1.65.2.2  martin 	case IXL_AQ_RC_ENOENT:
   5006  1.65.2.2  martin 		return ENOENT;
   5007  1.65.2.2  martin 	case IXL_AQ_RC_EACCES:
   5008  1.65.2.2  martin 		return EACCES;
   5009  1.65.2.2  martin 	case IXL_AQ_RC_EEXIST:
   5010  1.65.2.2  martin 		return EEXIST;
   5011  1.65.2.2  martin 	case IXL_AQ_RC_EINVAL:
   5012  1.65.2.2  martin 		return EINVAL;
   5013  1.65.2.2  martin 	default:
   5014  1.65.2.2  martin 		return EIO;
   5015  1.65.2.2  martin 	}
   5016  1.65.2.2  martin 
   5017  1.65.2.2  martin 	return 0;
   5018  1.65.2.2  martin }
   5019  1.65.2.2  martin 
   5020  1.65.2.2  martin static int
   5021  1.65.2.2  martin ixl_remove_macvlan(struct ixl_softc *sc, const uint8_t *macaddr,
   5022  1.65.2.2  martin     uint16_t vlan, uint16_t flags)
   5023  1.65.2.2  martin {
   5024  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   5025  1.65.2.2  martin 	struct ixl_aq_remove_macvlan *param;
   5026  1.65.2.2  martin 	struct ixl_aq_remove_macvlan_elem *elem;
   5027  1.65.2.2  martin 
   5028  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   5029  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF | IXL_AQ_RD);
   5030  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_REMOVE_MACVLAN);
   5031  1.65.2.2  martin 	iaq.iaq_datalen = htole16(sizeof(*elem));
   5032  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(&sc->sc_scratch));
   5033  1.65.2.2  martin 
   5034  1.65.2.2  martin 	param = (struct ixl_aq_remove_macvlan *)&iaq.iaq_param;
   5035  1.65.2.2  martin 	param->num_addrs = htole16(1);
   5036  1.65.2.2  martin 	param->seid0 = htole16(0x8000) | sc->sc_seid;
   5037  1.65.2.2  martin 	param->seid1 = 0;
   5038  1.65.2.2  martin 	param->seid2 = 0;
   5039  1.65.2.2  martin 
   5040  1.65.2.2  martin 	elem = IXL_DMA_KVA(&sc->sc_scratch);
   5041  1.65.2.2  martin 	memset(elem, 0, sizeof(*elem));
   5042  1.65.2.2  martin 	memcpy(elem->macaddr, macaddr, ETHER_ADDR_LEN);
   5043  1.65.2.2  martin 	elem->flags = htole16(IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH | flags);
   5044  1.65.2.2  martin 	elem->vlan = htole16(vlan);
   5045  1.65.2.2  martin 
   5046  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0) {
   5047  1.65.2.2  martin 		return EINVAL;
   5048  1.65.2.2  martin 	}
   5049  1.65.2.2  martin 
   5050  1.65.2.2  martin 	switch (le16toh(iaq.iaq_retval)) {
   5051  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   5052  1.65.2.2  martin 		break;
   5053  1.65.2.2  martin 	case IXL_AQ_RC_ENOENT:
   5054  1.65.2.2  martin 		return ENOENT;
   5055  1.65.2.2  martin 	case IXL_AQ_RC_EACCES:
   5056  1.65.2.2  martin 		return EACCES;
   5057  1.65.2.2  martin 	case IXL_AQ_RC_EINVAL:
   5058  1.65.2.2  martin 		return EINVAL;
   5059  1.65.2.2  martin 	default:
   5060  1.65.2.2  martin 		return EIO;
   5061  1.65.2.2  martin 	}
   5062  1.65.2.2  martin 
   5063  1.65.2.2  martin 	return 0;
   5064  1.65.2.2  martin }
   5065  1.65.2.2  martin 
   5066  1.65.2.2  martin static int
   5067  1.65.2.2  martin ixl_hmc(struct ixl_softc *sc)
   5068  1.65.2.2  martin {
   5069  1.65.2.2  martin 	struct {
   5070  1.65.2.2  martin 		uint32_t   count;
   5071  1.65.2.2  martin 		uint32_t   minsize;
   5072  1.65.2.2  martin 		bus_size_t objsiz;
   5073  1.65.2.2  martin 		bus_size_t setoff;
   5074  1.65.2.2  martin 		bus_size_t setcnt;
   5075  1.65.2.2  martin 	} regs[] = {
   5076  1.65.2.2  martin 		{
   5077  1.65.2.2  martin 			0,
   5078  1.65.2.2  martin 			IXL_HMC_TXQ_MINSIZE,
   5079  1.65.2.2  martin 			I40E_GLHMC_LANTXOBJSZ,
   5080  1.65.2.2  martin 			I40E_GLHMC_LANTXBASE(sc->sc_pf_id),
   5081  1.65.2.2  martin 			I40E_GLHMC_LANTXCNT(sc->sc_pf_id),
   5082  1.65.2.2  martin 		},
   5083  1.65.2.2  martin 		{
   5084  1.65.2.2  martin 			0,
   5085  1.65.2.2  martin 			IXL_HMC_RXQ_MINSIZE,
   5086  1.65.2.2  martin 			I40E_GLHMC_LANRXOBJSZ,
   5087  1.65.2.2  martin 			I40E_GLHMC_LANRXBASE(sc->sc_pf_id),
   5088  1.65.2.2  martin 			I40E_GLHMC_LANRXCNT(sc->sc_pf_id),
   5089  1.65.2.2  martin 		},
   5090  1.65.2.2  martin 		{
   5091  1.65.2.2  martin 			0,
   5092  1.65.2.2  martin 			0,
   5093  1.65.2.2  martin 			I40E_GLHMC_FCOEDDPOBJSZ,
   5094  1.65.2.2  martin 			I40E_GLHMC_FCOEDDPBASE(sc->sc_pf_id),
   5095  1.65.2.2  martin 			I40E_GLHMC_FCOEDDPCNT(sc->sc_pf_id),
   5096  1.65.2.2  martin 		},
   5097  1.65.2.2  martin 		{
   5098  1.65.2.2  martin 			0,
   5099  1.65.2.2  martin 			0,
   5100  1.65.2.2  martin 			I40E_GLHMC_FCOEFOBJSZ,
   5101  1.65.2.2  martin 			I40E_GLHMC_FCOEFBASE(sc->sc_pf_id),
   5102  1.65.2.2  martin 			I40E_GLHMC_FCOEFCNT(sc->sc_pf_id),
   5103  1.65.2.2  martin 		},
   5104  1.65.2.2  martin 	};
   5105  1.65.2.2  martin 	struct ixl_hmc_entry *e;
   5106  1.65.2.2  martin 	uint64_t size, dva;
   5107  1.65.2.2  martin 	uint8_t *kva;
   5108  1.65.2.2  martin 	uint64_t *sdpage;
   5109  1.65.2.2  martin 	unsigned int i;
   5110  1.65.2.2  martin 	int npages, tables;
   5111  1.65.2.2  martin 	uint32_t reg;
   5112  1.65.2.2  martin 
   5113  1.65.2.2  martin 	CTASSERT(__arraycount(regs) <= __arraycount(sc->sc_hmc_entries));
   5114  1.65.2.2  martin 
   5115  1.65.2.2  martin 	regs[IXL_HMC_LAN_TX].count = regs[IXL_HMC_LAN_RX].count =
   5116  1.65.2.2  martin 	    ixl_rd(sc, I40E_GLHMC_LANQMAX);
   5117  1.65.2.2  martin 
   5118  1.65.2.2  martin 	size = 0;
   5119  1.65.2.2  martin 	for (i = 0; i < __arraycount(regs); i++) {
   5120  1.65.2.2  martin 		e = &sc->sc_hmc_entries[i];
   5121  1.65.2.2  martin 
   5122  1.65.2.2  martin 		e->hmc_count = regs[i].count;
   5123  1.65.2.2  martin 		reg = ixl_rd(sc, regs[i].objsiz);
   5124  1.65.2.2  martin 		e->hmc_size = BIT_ULL(0x3F & reg);
   5125  1.65.2.2  martin 		e->hmc_base = size;
   5126  1.65.2.2  martin 
   5127  1.65.2.2  martin 		if ((e->hmc_size * 8) < regs[i].minsize) {
   5128  1.65.2.2  martin 			aprint_error_dev(sc->sc_dev,
   5129  1.65.2.2  martin 			    "kernel hmc entry is too big\n");
   5130  1.65.2.2  martin 			return -1;
   5131  1.65.2.2  martin 		}
   5132  1.65.2.2  martin 
   5133  1.65.2.2  martin 		size += roundup(e->hmc_size * e->hmc_count, IXL_HMC_ROUNDUP);
   5134  1.65.2.2  martin 	}
   5135  1.65.2.2  martin 	size = roundup(size, IXL_HMC_PGSIZE);
   5136  1.65.2.2  martin 	npages = size / IXL_HMC_PGSIZE;
   5137  1.65.2.2  martin 
   5138  1.65.2.2  martin 	tables = roundup(size, IXL_HMC_L2SZ) / IXL_HMC_L2SZ;
   5139  1.65.2.2  martin 
   5140  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &sc->sc_hmc_pd, size, IXL_HMC_PGSIZE) != 0) {
   5141  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   5142  1.65.2.2  martin 		    "unable to allocate hmc pd memory\n");
   5143  1.65.2.2  martin 		return -1;
   5144  1.65.2.2  martin 	}
   5145  1.65.2.2  martin 
   5146  1.65.2.2  martin 	if (ixl_dmamem_alloc(sc, &sc->sc_hmc_sd, tables * IXL_HMC_PGSIZE,
   5147  1.65.2.2  martin 	    IXL_HMC_PGSIZE) != 0) {
   5148  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   5149  1.65.2.2  martin 		    "unable to allocate hmc sd memory\n");
   5150  1.65.2.2  martin 		ixl_dmamem_free(sc, &sc->sc_hmc_pd);
   5151  1.65.2.2  martin 		return -1;
   5152  1.65.2.2  martin 	}
   5153  1.65.2.2  martin 
   5154  1.65.2.2  martin 	kva = IXL_DMA_KVA(&sc->sc_hmc_pd);
   5155  1.65.2.2  martin 	memset(kva, 0, IXL_DMA_LEN(&sc->sc_hmc_pd));
   5156  1.65.2.2  martin 
   5157  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_hmc_pd),
   5158  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_hmc_pd),
   5159  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   5160  1.65.2.2  martin 
   5161  1.65.2.2  martin 	dva = IXL_DMA_DVA(&sc->sc_hmc_pd);
   5162  1.65.2.2  martin 	sdpage = IXL_DMA_KVA(&sc->sc_hmc_sd);
   5163  1.65.2.2  martin 	memset(sdpage, 0, IXL_DMA_LEN(&sc->sc_hmc_sd));
   5164  1.65.2.2  martin 
   5165  1.65.2.2  martin 	for (i = 0; (int)i < npages; i++) {
   5166  1.65.2.2  martin 		*sdpage = htole64(dva | IXL_HMC_PDVALID);
   5167  1.65.2.2  martin 		sdpage++;
   5168  1.65.2.2  martin 
   5169  1.65.2.2  martin 		dva += IXL_HMC_PGSIZE;
   5170  1.65.2.2  martin 	}
   5171  1.65.2.2  martin 
   5172  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(&sc->sc_hmc_sd),
   5173  1.65.2.2  martin 	    0, IXL_DMA_LEN(&sc->sc_hmc_sd),
   5174  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   5175  1.65.2.2  martin 
   5176  1.65.2.2  martin 	dva = IXL_DMA_DVA(&sc->sc_hmc_sd);
   5177  1.65.2.2  martin 	for (i = 0; (int)i < tables; i++) {
   5178  1.65.2.2  martin 		uint32_t count;
   5179  1.65.2.2  martin 
   5180  1.65.2.2  martin 		KASSERT(npages >= 0);
   5181  1.65.2.2  martin 
   5182  1.65.2.2  martin 		count = ((unsigned int)npages > IXL_HMC_PGS) ?
   5183  1.65.2.2  martin 		    IXL_HMC_PGS : (unsigned int)npages;
   5184  1.65.2.2  martin 
   5185  1.65.2.2  martin 		ixl_wr(sc, I40E_PFHMC_SDDATAHIGH, dva >> 32);
   5186  1.65.2.2  martin 		ixl_wr(sc, I40E_PFHMC_SDDATALOW, dva |
   5187  1.65.2.2  martin 		    (count << I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) |
   5188  1.65.2.2  martin 		    (1U << I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT));
   5189  1.65.2.2  martin 		ixl_barrier(sc, 0, sc->sc_mems, BUS_SPACE_BARRIER_WRITE);
   5190  1.65.2.2  martin 		ixl_wr(sc, I40E_PFHMC_SDCMD,
   5191  1.65.2.2  martin 		    (1U << I40E_PFHMC_SDCMD_PMSDWR_SHIFT) | i);
   5192  1.65.2.2  martin 
   5193  1.65.2.2  martin 		npages -= IXL_HMC_PGS;
   5194  1.65.2.2  martin 		dva += IXL_HMC_PGSIZE;
   5195  1.65.2.2  martin 	}
   5196  1.65.2.2  martin 
   5197  1.65.2.2  martin 	for (i = 0; i < __arraycount(regs); i++) {
   5198  1.65.2.2  martin 		e = &sc->sc_hmc_entries[i];
   5199  1.65.2.2  martin 
   5200  1.65.2.2  martin 		ixl_wr(sc, regs[i].setoff, e->hmc_base / IXL_HMC_ROUNDUP);
   5201  1.65.2.2  martin 		ixl_wr(sc, regs[i].setcnt, e->hmc_count);
   5202  1.65.2.2  martin 	}
   5203  1.65.2.2  martin 
   5204  1.65.2.2  martin 	return 0;
   5205  1.65.2.2  martin }
   5206  1.65.2.2  martin 
   5207  1.65.2.2  martin static void
   5208  1.65.2.2  martin ixl_hmc_free(struct ixl_softc *sc)
   5209  1.65.2.2  martin {
   5210  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_hmc_sd);
   5211  1.65.2.2  martin 	ixl_dmamem_free(sc, &sc->sc_hmc_pd);
   5212  1.65.2.2  martin }
   5213  1.65.2.2  martin 
   5214  1.65.2.2  martin static void
   5215  1.65.2.2  martin ixl_hmc_pack(void *d, const void *s, const struct ixl_hmc_pack *packing,
   5216  1.65.2.2  martin     unsigned int npacking)
   5217  1.65.2.2  martin {
   5218  1.65.2.2  martin 	uint8_t *dst = d;
   5219  1.65.2.2  martin 	const uint8_t *src = s;
   5220  1.65.2.2  martin 	unsigned int i;
   5221  1.65.2.2  martin 
   5222  1.65.2.2  martin 	for (i = 0; i < npacking; i++) {
   5223  1.65.2.2  martin 		const struct ixl_hmc_pack *pack = &packing[i];
   5224  1.65.2.2  martin 		unsigned int offset = pack->lsb / 8;
   5225  1.65.2.2  martin 		unsigned int align = pack->lsb % 8;
   5226  1.65.2.2  martin 		const uint8_t *in = src + pack->offset;
   5227  1.65.2.2  martin 		uint8_t *out = dst + offset;
   5228  1.65.2.2  martin 		int width = pack->width;
   5229  1.65.2.2  martin 		unsigned int inbits = 0;
   5230  1.65.2.2  martin 
   5231  1.65.2.2  martin 		if (align) {
   5232  1.65.2.2  martin 			inbits = (*in++) << align;
   5233  1.65.2.2  martin 			*out++ |= (inbits & 0xff);
   5234  1.65.2.2  martin 			inbits >>= 8;
   5235  1.65.2.2  martin 
   5236  1.65.2.2  martin 			width -= 8 - align;
   5237  1.65.2.2  martin 		}
   5238  1.65.2.2  martin 
   5239  1.65.2.2  martin 		while (width >= 8) {
   5240  1.65.2.2  martin 			inbits |= (*in++) << align;
   5241  1.65.2.2  martin 			*out++ = (inbits & 0xff);
   5242  1.65.2.2  martin 			inbits >>= 8;
   5243  1.65.2.2  martin 
   5244  1.65.2.2  martin 			width -= 8;
   5245  1.65.2.2  martin 		}
   5246  1.65.2.2  martin 
   5247  1.65.2.2  martin 		if (width > 0) {
   5248  1.65.2.2  martin 			inbits |= (*in) << align;
   5249  1.65.2.2  martin 			*out |= (inbits & ((1 << width) - 1));
   5250  1.65.2.2  martin 		}
   5251  1.65.2.2  martin 	}
   5252  1.65.2.2  martin }
   5253  1.65.2.2  martin 
   5254  1.65.2.2  martin static struct ixl_aq_buf *
   5255  1.65.2.2  martin ixl_aqb_alloc(struct ixl_softc *sc)
   5256  1.65.2.2  martin {
   5257  1.65.2.2  martin 	struct ixl_aq_buf *aqb;
   5258  1.65.2.2  martin 
   5259  1.65.2.2  martin 	aqb = kmem_alloc(sizeof(*aqb), KM_SLEEP);
   5260  1.65.2.2  martin 
   5261  1.65.2.2  martin 	aqb->aqb_size = IXL_AQ_BUFLEN;
   5262  1.65.2.2  martin 
   5263  1.65.2.2  martin 	if (bus_dmamap_create(sc->sc_dmat, aqb->aqb_size, 1,
   5264  1.65.2.2  martin 	    aqb->aqb_size, 0,
   5265  1.65.2.2  martin 	    BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW, &aqb->aqb_map) != 0)
   5266  1.65.2.2  martin 		goto free;
   5267  1.65.2.2  martin 	if (bus_dmamem_alloc(sc->sc_dmat, aqb->aqb_size,
   5268  1.65.2.2  martin 	    IXL_AQ_ALIGN, 0, &aqb->aqb_seg, 1, &aqb->aqb_nsegs,
   5269  1.65.2.2  martin 	    BUS_DMA_WAITOK) != 0)
   5270  1.65.2.2  martin 		goto destroy;
   5271  1.65.2.2  martin 	if (bus_dmamem_map(sc->sc_dmat, &aqb->aqb_seg, aqb->aqb_nsegs,
   5272  1.65.2.2  martin 	    aqb->aqb_size, &aqb->aqb_data, BUS_DMA_WAITOK) != 0)
   5273  1.65.2.2  martin 		goto dma_free;
   5274  1.65.2.2  martin 	if (bus_dmamap_load(sc->sc_dmat, aqb->aqb_map, aqb->aqb_data,
   5275  1.65.2.2  martin 	    aqb->aqb_size, NULL, BUS_DMA_WAITOK) != 0)
   5276  1.65.2.2  martin 		goto unmap;
   5277  1.65.2.2  martin 
   5278  1.65.2.2  martin 	return aqb;
   5279  1.65.2.2  martin unmap:
   5280  1.65.2.2  martin 	bus_dmamem_unmap(sc->sc_dmat, aqb->aqb_data, aqb->aqb_size);
   5281  1.65.2.2  martin dma_free:
   5282  1.65.2.2  martin 	bus_dmamem_free(sc->sc_dmat, &aqb->aqb_seg, 1);
   5283  1.65.2.2  martin destroy:
   5284  1.65.2.2  martin 	bus_dmamap_destroy(sc->sc_dmat, aqb->aqb_map);
   5285  1.65.2.2  martin free:
   5286  1.65.2.2  martin 	kmem_free(aqb, sizeof(*aqb));
   5287  1.65.2.2  martin 
   5288  1.65.2.2  martin 	return NULL;
   5289  1.65.2.2  martin }
   5290  1.65.2.2  martin 
   5291  1.65.2.2  martin static void
   5292  1.65.2.2  martin ixl_aqb_free(struct ixl_softc *sc, struct ixl_aq_buf *aqb)
   5293  1.65.2.2  martin {
   5294  1.65.2.2  martin 
   5295  1.65.2.2  martin 	bus_dmamap_unload(sc->sc_dmat, aqb->aqb_map);
   5296  1.65.2.2  martin 	bus_dmamem_unmap(sc->sc_dmat, aqb->aqb_data, aqb->aqb_size);
   5297  1.65.2.2  martin 	bus_dmamem_free(sc->sc_dmat, &aqb->aqb_seg, 1);
   5298  1.65.2.2  martin 	bus_dmamap_destroy(sc->sc_dmat, aqb->aqb_map);
   5299  1.65.2.2  martin 	kmem_free(aqb, sizeof(*aqb));
   5300  1.65.2.2  martin }
   5301  1.65.2.2  martin 
   5302  1.65.2.2  martin static int
   5303  1.65.2.2  martin ixl_arq_fill(struct ixl_softc *sc)
   5304  1.65.2.2  martin {
   5305  1.65.2.2  martin 	struct ixl_aq_buf *aqb;
   5306  1.65.2.2  martin 	struct ixl_aq_desc *arq, *iaq;
   5307  1.65.2.2  martin 	unsigned int prod = sc->sc_arq_prod;
   5308  1.65.2.2  martin 	unsigned int n;
   5309  1.65.2.2  martin 	int post = 0;
   5310  1.65.2.2  martin 
   5311  1.65.2.2  martin 	n = ixl_rxr_unrefreshed(sc->sc_arq_prod, sc->sc_arq_cons,
   5312  1.65.2.2  martin 	    IXL_AQ_NUM);
   5313  1.65.2.2  martin 	arq = IXL_DMA_KVA(&sc->sc_arq);
   5314  1.65.2.2  martin 
   5315  1.65.2.2  martin 	if (__predict_false(n <= 0))
   5316  1.65.2.2  martin 		return 0;
   5317  1.65.2.2  martin 
   5318  1.65.2.2  martin 	do {
   5319  1.65.2.2  martin 		aqb = sc->sc_arq_live[prod];
   5320  1.65.2.2  martin 		iaq = &arq[prod];
   5321  1.65.2.2  martin 
   5322  1.65.2.2  martin 		if (aqb == NULL) {
   5323  1.65.2.2  martin 			aqb = SIMPLEQ_FIRST(&sc->sc_arq_idle);
   5324  1.65.2.2  martin 			if (aqb != NULL) {
   5325  1.65.2.2  martin 				SIMPLEQ_REMOVE(&sc->sc_arq_idle, aqb,
   5326  1.65.2.2  martin 				    ixl_aq_buf, aqb_entry);
   5327  1.65.2.2  martin 			} else if ((aqb = ixl_aqb_alloc(sc)) == NULL) {
   5328  1.65.2.2  martin 				break;
   5329  1.65.2.2  martin 			}
   5330  1.65.2.2  martin 
   5331  1.65.2.2  martin 			sc->sc_arq_live[prod] = aqb;
   5332  1.65.2.2  martin 			memset(aqb->aqb_data, 0, aqb->aqb_size);
   5333  1.65.2.2  martin 
   5334  1.65.2.2  martin 			bus_dmamap_sync(sc->sc_dmat, aqb->aqb_map, 0,
   5335  1.65.2.2  martin 			    aqb->aqb_size, BUS_DMASYNC_PREREAD);
   5336  1.65.2.2  martin 
   5337  1.65.2.2  martin 			iaq->iaq_flags = htole16(IXL_AQ_BUF |
   5338  1.65.2.2  martin 			    (IXL_AQ_BUFLEN > I40E_AQ_LARGE_BUF ?
   5339  1.65.2.2  martin 			    IXL_AQ_LB : 0));
   5340  1.65.2.2  martin 			iaq->iaq_opcode = 0;
   5341  1.65.2.2  martin 			iaq->iaq_datalen = htole16(aqb->aqb_size);
   5342  1.65.2.2  martin 			iaq->iaq_retval = 0;
   5343  1.65.2.2  martin 			iaq->iaq_cookie = 0;
   5344  1.65.2.2  martin 			iaq->iaq_param[0] = 0;
   5345  1.65.2.2  martin 			iaq->iaq_param[1] = 0;
   5346  1.65.2.2  martin 			ixl_aq_dva(iaq, aqb->aqb_map->dm_segs[0].ds_addr);
   5347  1.65.2.2  martin 		}
   5348  1.65.2.2  martin 
   5349  1.65.2.2  martin 		prod++;
   5350  1.65.2.2  martin 		prod &= IXL_AQ_MASK;
   5351  1.65.2.2  martin 
   5352  1.65.2.2  martin 		post = 1;
   5353  1.65.2.2  martin 
   5354  1.65.2.2  martin 	} while (--n);
   5355  1.65.2.2  martin 
   5356  1.65.2.2  martin 	if (post) {
   5357  1.65.2.2  martin 		sc->sc_arq_prod = prod;
   5358  1.65.2.2  martin 		ixl_wr(sc, sc->sc_aq_regs->arq_tail, sc->sc_arq_prod);
   5359  1.65.2.2  martin 	}
   5360  1.65.2.2  martin 
   5361  1.65.2.2  martin 	return post;
   5362  1.65.2.2  martin }
   5363  1.65.2.2  martin 
   5364  1.65.2.2  martin static void
   5365  1.65.2.2  martin ixl_arq_unfill(struct ixl_softc *sc)
   5366  1.65.2.2  martin {
   5367  1.65.2.2  martin 	struct ixl_aq_buf *aqb;
   5368  1.65.2.2  martin 	unsigned int i;
   5369  1.65.2.2  martin 
   5370  1.65.2.2  martin 	for (i = 0; i < __arraycount(sc->sc_arq_live); i++) {
   5371  1.65.2.2  martin 		aqb = sc->sc_arq_live[i];
   5372  1.65.2.2  martin 		if (aqb == NULL)
   5373  1.65.2.2  martin 			continue;
   5374  1.65.2.2  martin 
   5375  1.65.2.2  martin 		sc->sc_arq_live[i] = NULL;
   5376  1.65.2.2  martin 		bus_dmamap_sync(sc->sc_dmat, aqb->aqb_map, 0, aqb->aqb_size,
   5377  1.65.2.2  martin 		    BUS_DMASYNC_POSTREAD);
   5378  1.65.2.2  martin 		ixl_aqb_free(sc, aqb);
   5379  1.65.2.2  martin 	}
   5380  1.65.2.2  martin 
   5381  1.65.2.2  martin 	while ((aqb = SIMPLEQ_FIRST(&sc->sc_arq_idle)) != NULL) {
   5382  1.65.2.2  martin 		SIMPLEQ_REMOVE(&sc->sc_arq_idle, aqb,
   5383  1.65.2.2  martin 		    ixl_aq_buf, aqb_entry);
   5384  1.65.2.2  martin 		ixl_aqb_free(sc, aqb);
   5385  1.65.2.2  martin 	}
   5386  1.65.2.2  martin }
   5387  1.65.2.2  martin 
   5388  1.65.2.2  martin static void
   5389  1.65.2.2  martin ixl_clear_hw(struct ixl_softc *sc)
   5390  1.65.2.2  martin {
   5391  1.65.2.2  martin 	uint32_t num_queues, base_queue;
   5392  1.65.2.2  martin 	uint32_t num_pf_int;
   5393  1.65.2.2  martin 	uint32_t num_vf_int;
   5394  1.65.2.2  martin 	uint32_t num_vfs;
   5395  1.65.2.2  martin 	uint32_t i, j;
   5396  1.65.2.2  martin 	uint32_t val;
   5397  1.65.2.2  martin 	uint32_t eol = 0x7ff;
   5398  1.65.2.2  martin 
   5399  1.65.2.2  martin 	/* get number of interrupts, queues, and vfs */
   5400  1.65.2.2  martin 	val = ixl_rd(sc, I40E_GLPCI_CNF2);
   5401  1.65.2.2  martin 	num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
   5402  1.65.2.2  martin 	    I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
   5403  1.65.2.2  martin 	num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
   5404  1.65.2.2  martin 	    I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
   5405  1.65.2.2  martin 
   5406  1.65.2.2  martin 	val = ixl_rd(sc, I40E_PFLAN_QALLOC);
   5407  1.65.2.2  martin 	base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
   5408  1.65.2.2  martin 	    I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
   5409  1.65.2.2  martin 	j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
   5410  1.65.2.2  martin 	    I40E_PFLAN_QALLOC_LASTQ_SHIFT;
   5411  1.65.2.2  martin 	if (val & I40E_PFLAN_QALLOC_VALID_MASK)
   5412  1.65.2.2  martin 		num_queues = (j - base_queue) + 1;
   5413  1.65.2.2  martin 	else
   5414  1.65.2.2  martin 		num_queues = 0;
   5415  1.65.2.2  martin 
   5416  1.65.2.2  martin 	val = ixl_rd(sc, I40E_PF_VT_PFALLOC);
   5417  1.65.2.2  martin 	i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
   5418  1.65.2.2  martin 	    I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
   5419  1.65.2.2  martin 	j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
   5420  1.65.2.2  martin 	    I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
   5421  1.65.2.2  martin 	if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
   5422  1.65.2.2  martin 		num_vfs = (j - i) + 1;
   5423  1.65.2.2  martin 	else
   5424  1.65.2.2  martin 		num_vfs = 0;
   5425  1.65.2.2  martin 
   5426  1.65.2.2  martin 	/* stop all the interrupts */
   5427  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_ICR0_ENA, 0);
   5428  1.65.2.2  martin 	ixl_flush(sc);
   5429  1.65.2.2  martin 	val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
   5430  1.65.2.2  martin 	for (i = 0; i < num_pf_int - 2; i++)
   5431  1.65.2.2  martin 		ixl_wr(sc, I40E_PFINT_DYN_CTLN(i), val);
   5432  1.65.2.2  martin 	ixl_flush(sc);
   5433  1.65.2.2  martin 
   5434  1.65.2.2  martin 	/* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
   5435  1.65.2.2  martin 	val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
   5436  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_LNKLST0, val);
   5437  1.65.2.2  martin 	for (i = 0; i < num_pf_int - 2; i++)
   5438  1.65.2.2  martin 		ixl_wr(sc, I40E_PFINT_LNKLSTN(i), val);
   5439  1.65.2.2  martin 	val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
   5440  1.65.2.2  martin 	for (i = 0; i < num_vfs; i++)
   5441  1.65.2.2  martin 		ixl_wr(sc, I40E_VPINT_LNKLST0(i), val);
   5442  1.65.2.2  martin 	for (i = 0; i < num_vf_int - 2; i++)
   5443  1.65.2.2  martin 		ixl_wr(sc, I40E_VPINT_LNKLSTN(i), val);
   5444  1.65.2.2  martin 
   5445  1.65.2.2  martin 	/* warn the HW of the coming Tx disables */
   5446  1.65.2.2  martin 	for (i = 0; i < num_queues; i++) {
   5447  1.65.2.2  martin 		uint32_t abs_queue_idx = base_queue + i;
   5448  1.65.2.2  martin 		uint32_t reg_block = 0;
   5449  1.65.2.2  martin 
   5450  1.65.2.2  martin 		if (abs_queue_idx >= 128) {
   5451  1.65.2.2  martin 			reg_block = abs_queue_idx / 128;
   5452  1.65.2.2  martin 			abs_queue_idx %= 128;
   5453  1.65.2.2  martin 		}
   5454  1.65.2.2  martin 
   5455  1.65.2.2  martin 		val = ixl_rd(sc, I40E_GLLAN_TXPRE_QDIS(reg_block));
   5456  1.65.2.2  martin 		val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
   5457  1.65.2.2  martin 		val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
   5458  1.65.2.2  martin 		val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
   5459  1.65.2.2  martin 
   5460  1.65.2.2  martin 		ixl_wr(sc, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
   5461  1.65.2.2  martin 	}
   5462  1.65.2.2  martin 	delaymsec(400);
   5463  1.65.2.2  martin 
   5464  1.65.2.2  martin 	/* stop all the queues */
   5465  1.65.2.2  martin 	for (i = 0; i < num_queues; i++) {
   5466  1.65.2.2  martin 		ixl_wr(sc, I40E_QINT_TQCTL(i), 0);
   5467  1.65.2.2  martin 		ixl_wr(sc, I40E_QTX_ENA(i), 0);
   5468  1.65.2.2  martin 		ixl_wr(sc, I40E_QINT_RQCTL(i), 0);
   5469  1.65.2.2  martin 		ixl_wr(sc, I40E_QRX_ENA(i), 0);
   5470  1.65.2.2  martin 	}
   5471  1.65.2.2  martin 
   5472  1.65.2.2  martin 	/* short wait for all queue disables to settle */
   5473  1.65.2.2  martin 	delaymsec(50);
   5474  1.65.2.2  martin }
   5475  1.65.2.2  martin 
   5476  1.65.2.2  martin static int
   5477  1.65.2.2  martin ixl_pf_reset(struct ixl_softc *sc)
   5478  1.65.2.2  martin {
   5479  1.65.2.2  martin 	uint32_t cnt = 0;
   5480  1.65.2.2  martin 	uint32_t cnt1 = 0;
   5481  1.65.2.2  martin 	uint32_t reg = 0, reg0 = 0;
   5482  1.65.2.2  martin 	uint32_t grst_del;
   5483  1.65.2.2  martin 
   5484  1.65.2.2  martin 	/*
   5485  1.65.2.2  martin 	 * Poll for Global Reset steady state in case of recent GRST.
   5486  1.65.2.2  martin 	 * The grst delay value is in 100ms units, and we'll wait a
   5487  1.65.2.2  martin 	 * couple counts longer to be sure we don't just miss the end.
   5488  1.65.2.2  martin 	 */
   5489  1.65.2.2  martin 	grst_del = ixl_rd(sc, I40E_GLGEN_RSTCTL);
   5490  1.65.2.2  martin 	grst_del &= I40E_GLGEN_RSTCTL_GRSTDEL_MASK;
   5491  1.65.2.2  martin 	grst_del >>= I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
   5492  1.65.2.2  martin 
   5493  1.65.2.2  martin 	grst_del = grst_del * 20;
   5494  1.65.2.2  martin 
   5495  1.65.2.2  martin 	for (cnt = 0; cnt < grst_del; cnt++) {
   5496  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_GLGEN_RSTAT);
   5497  1.65.2.2  martin 		if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
   5498  1.65.2.2  martin 			break;
   5499  1.65.2.2  martin 		delaymsec(100);
   5500  1.65.2.2  martin 	}
   5501  1.65.2.2  martin 	if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
   5502  1.65.2.2  martin 		aprint_error(", Global reset polling failed to complete\n");
   5503  1.65.2.2  martin 		return -1;
   5504  1.65.2.2  martin 	}
   5505  1.65.2.2  martin 
   5506  1.65.2.2  martin 	/* Now Wait for the FW to be ready */
   5507  1.65.2.2  martin 	for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
   5508  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_GLNVM_ULD);
   5509  1.65.2.2  martin 		reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
   5510  1.65.2.2  martin 		    I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
   5511  1.65.2.2  martin 		if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
   5512  1.65.2.2  martin 		    I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))
   5513  1.65.2.2  martin 			break;
   5514  1.65.2.2  martin 
   5515  1.65.2.2  martin 		delaymsec(10);
   5516  1.65.2.2  martin 	}
   5517  1.65.2.2  martin 	if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
   5518  1.65.2.2  martin 	    I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
   5519  1.65.2.2  martin 		aprint_error(", wait for FW Reset complete timed out "
   5520  1.65.2.2  martin 		    "(I40E_GLNVM_ULD = 0x%x)\n", reg);
   5521  1.65.2.2  martin 		return -1;
   5522  1.65.2.2  martin 	}
   5523  1.65.2.2  martin 
   5524  1.65.2.2  martin 	/*
   5525  1.65.2.2  martin 	 * If there was a Global Reset in progress when we got here,
   5526  1.65.2.2  martin 	 * we don't need to do the PF Reset
   5527  1.65.2.2  martin 	 */
   5528  1.65.2.2  martin 	if (cnt == 0) {
   5529  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_PFGEN_CTRL);
   5530  1.65.2.2  martin 		ixl_wr(sc, I40E_PFGEN_CTRL, reg | I40E_PFGEN_CTRL_PFSWR_MASK);
   5531  1.65.2.2  martin 		for (cnt = 0; cnt < I40E_PF_RESET_WAIT_COUNT; cnt++) {
   5532  1.65.2.2  martin 			reg = ixl_rd(sc, I40E_PFGEN_CTRL);
   5533  1.65.2.2  martin 			if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
   5534  1.65.2.2  martin 				break;
   5535  1.65.2.2  martin 			delaymsec(1);
   5536  1.65.2.2  martin 
   5537  1.65.2.2  martin 			reg0 = ixl_rd(sc, I40E_GLGEN_RSTAT);
   5538  1.65.2.2  martin 			if (reg0 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
   5539  1.65.2.2  martin 				aprint_error(", Core reset upcoming."
   5540  1.65.2.2  martin 				    " Skipping PF reset reset request\n");
   5541  1.65.2.2  martin 				return -1;
   5542  1.65.2.2  martin 			}
   5543  1.65.2.2  martin 		}
   5544  1.65.2.2  martin 		if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
   5545  1.65.2.2  martin 			aprint_error(", PF reset polling failed to complete"
   5546  1.65.2.2  martin 			    "(I40E_PFGEN_CTRL= 0x%x)\n", reg);
   5547  1.65.2.2  martin 			return -1;
   5548  1.65.2.2  martin 		}
   5549  1.65.2.2  martin 	}
   5550  1.65.2.2  martin 
   5551  1.65.2.2  martin 	return 0;
   5552  1.65.2.2  martin }
   5553  1.65.2.2  martin 
   5554  1.65.2.2  martin static int
   5555  1.65.2.2  martin ixl_dmamem_alloc(struct ixl_softc *sc, struct ixl_dmamem *ixm,
   5556  1.65.2.2  martin     bus_size_t size, bus_size_t align)
   5557  1.65.2.2  martin {
   5558  1.65.2.2  martin 	ixm->ixm_size = size;
   5559  1.65.2.2  martin 
   5560  1.65.2.2  martin 	if (bus_dmamap_create(sc->sc_dmat, ixm->ixm_size, 1,
   5561  1.65.2.2  martin 	    ixm->ixm_size, 0,
   5562  1.65.2.2  martin 	    BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW,
   5563  1.65.2.2  martin 	    &ixm->ixm_map) != 0)
   5564  1.65.2.2  martin 		return 1;
   5565  1.65.2.2  martin 	if (bus_dmamem_alloc(sc->sc_dmat, ixm->ixm_size,
   5566  1.65.2.2  martin 	    align, 0, &ixm->ixm_seg, 1, &ixm->ixm_nsegs,
   5567  1.65.2.2  martin 	    BUS_DMA_WAITOK) != 0)
   5568  1.65.2.2  martin 		goto destroy;
   5569  1.65.2.2  martin 	if (bus_dmamem_map(sc->sc_dmat, &ixm->ixm_seg, ixm->ixm_nsegs,
   5570  1.65.2.2  martin 	    ixm->ixm_size, &ixm->ixm_kva, BUS_DMA_WAITOK) != 0)
   5571  1.65.2.2  martin 		goto free;
   5572  1.65.2.2  martin 	if (bus_dmamap_load(sc->sc_dmat, ixm->ixm_map, ixm->ixm_kva,
   5573  1.65.2.2  martin 	    ixm->ixm_size, NULL, BUS_DMA_WAITOK) != 0)
   5574  1.65.2.2  martin 		goto unmap;
   5575  1.65.2.2  martin 
   5576  1.65.2.2  martin 	memset(ixm->ixm_kva, 0, ixm->ixm_size);
   5577  1.65.2.2  martin 
   5578  1.65.2.2  martin 	return 0;
   5579  1.65.2.2  martin unmap:
   5580  1.65.2.2  martin 	bus_dmamem_unmap(sc->sc_dmat, ixm->ixm_kva, ixm->ixm_size);
   5581  1.65.2.2  martin free:
   5582  1.65.2.2  martin 	bus_dmamem_free(sc->sc_dmat, &ixm->ixm_seg, 1);
   5583  1.65.2.2  martin destroy:
   5584  1.65.2.2  martin 	bus_dmamap_destroy(sc->sc_dmat, ixm->ixm_map);
   5585  1.65.2.2  martin 	return 1;
   5586  1.65.2.2  martin }
   5587  1.65.2.2  martin 
   5588  1.65.2.2  martin static void
   5589  1.65.2.2  martin ixl_dmamem_free(struct ixl_softc *sc, struct ixl_dmamem *ixm)
   5590  1.65.2.2  martin {
   5591  1.65.2.2  martin 	bus_dmamap_unload(sc->sc_dmat, ixm->ixm_map);
   5592  1.65.2.2  martin 	bus_dmamem_unmap(sc->sc_dmat, ixm->ixm_kva, ixm->ixm_size);
   5593  1.65.2.2  martin 	bus_dmamem_free(sc->sc_dmat, &ixm->ixm_seg, 1);
   5594  1.65.2.2  martin 	bus_dmamap_destroy(sc->sc_dmat, ixm->ixm_map);
   5595  1.65.2.2  martin }
   5596  1.65.2.2  martin 
   5597  1.65.2.2  martin static int
   5598  1.65.2.2  martin ixl_setup_vlan_hwfilter(struct ixl_softc *sc)
   5599  1.65.2.2  martin {
   5600  1.65.2.2  martin 	struct ethercom *ec = &sc->sc_ec;
   5601  1.65.2.2  martin 	struct vlanid_list *vlanidp;
   5602  1.65.2.2  martin 	int rv;
   5603  1.65.2.2  martin 
   5604  1.65.2.2  martin 	ixl_remove_macvlan(sc, sc->sc_enaddr, 0,
   5605  1.65.2.2  martin 	    IXL_AQ_OP_REMOVE_MACVLAN_IGNORE_VLAN);
   5606  1.65.2.2  martin 	ixl_remove_macvlan(sc, etherbroadcastaddr, 0,
   5607  1.65.2.2  martin 	    IXL_AQ_OP_REMOVE_MACVLAN_IGNORE_VLAN);
   5608  1.65.2.2  martin 
   5609  1.65.2.2  martin 	rv = ixl_add_macvlan(sc, sc->sc_enaddr, 0,
   5610  1.65.2.2  martin 	    IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH);
   5611  1.65.2.2  martin 	if (rv != 0)
   5612  1.65.2.2  martin 		return rv;
   5613  1.65.2.2  martin 	rv = ixl_add_macvlan(sc, etherbroadcastaddr, 0,
   5614  1.65.2.2  martin 	    IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH);
   5615  1.65.2.2  martin 	if (rv != 0)
   5616  1.65.2.2  martin 		return rv;
   5617  1.65.2.2  martin 
   5618  1.65.2.2  martin 	ETHER_LOCK(ec);
   5619  1.65.2.2  martin 	SIMPLEQ_FOREACH(vlanidp, &ec->ec_vids, vid_list) {
   5620  1.65.2.2  martin 		rv = ixl_add_macvlan(sc, sc->sc_enaddr,
   5621  1.65.2.2  martin 		    vlanidp->vid, IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH);
   5622  1.65.2.2  martin 		if (rv != 0)
   5623  1.65.2.2  martin 			break;
   5624  1.65.2.2  martin 		rv = ixl_add_macvlan(sc, etherbroadcastaddr,
   5625  1.65.2.2  martin 		    vlanidp->vid, IXL_AQ_OP_ADD_MACVLAN_PERFECT_MATCH);
   5626  1.65.2.2  martin 		if (rv != 0)
   5627  1.65.2.2  martin 			break;
   5628  1.65.2.2  martin 	}
   5629  1.65.2.2  martin 	ETHER_UNLOCK(ec);
   5630  1.65.2.2  martin 
   5631  1.65.2.2  martin 	return rv;
   5632  1.65.2.2  martin }
   5633  1.65.2.2  martin 
   5634  1.65.2.2  martin static void
   5635  1.65.2.2  martin ixl_teardown_vlan_hwfilter(struct ixl_softc *sc)
   5636  1.65.2.2  martin {
   5637  1.65.2.2  martin 	struct vlanid_list *vlanidp;
   5638  1.65.2.2  martin 	struct ethercom *ec = &sc->sc_ec;
   5639  1.65.2.2  martin 
   5640  1.65.2.2  martin 	ixl_remove_macvlan(sc, sc->sc_enaddr, 0,
   5641  1.65.2.2  martin 	    IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH);
   5642  1.65.2.2  martin 	ixl_remove_macvlan(sc, etherbroadcastaddr, 0,
   5643  1.65.2.2  martin 	    IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH);
   5644  1.65.2.2  martin 
   5645  1.65.2.2  martin 	ETHER_LOCK(ec);
   5646  1.65.2.2  martin 	SIMPLEQ_FOREACH(vlanidp, &ec->ec_vids, vid_list) {
   5647  1.65.2.2  martin 		ixl_remove_macvlan(sc, sc->sc_enaddr,
   5648  1.65.2.2  martin 		    vlanidp->vid, IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH);
   5649  1.65.2.2  martin 		ixl_remove_macvlan(sc, etherbroadcastaddr,
   5650  1.65.2.2  martin 		    vlanidp->vid, IXL_AQ_OP_REMOVE_MACVLAN_PERFECT_MATCH);
   5651  1.65.2.2  martin 	}
   5652  1.65.2.2  martin 	ETHER_UNLOCK(ec);
   5653  1.65.2.2  martin 
   5654  1.65.2.2  martin 	ixl_add_macvlan(sc, sc->sc_enaddr, 0,
   5655  1.65.2.2  martin 	    IXL_AQ_OP_ADD_MACVLAN_IGNORE_VLAN);
   5656  1.65.2.2  martin 	ixl_add_macvlan(sc, etherbroadcastaddr, 0,
   5657  1.65.2.2  martin 	    IXL_AQ_OP_ADD_MACVLAN_IGNORE_VLAN);
   5658  1.65.2.2  martin }
   5659  1.65.2.2  martin 
   5660  1.65.2.2  martin static int
   5661  1.65.2.2  martin ixl_update_macvlan(struct ixl_softc *sc)
   5662  1.65.2.2  martin {
   5663  1.65.2.2  martin 	int rv = 0;
   5664  1.65.2.2  martin 	int next_ec_capenable = sc->sc_ec.ec_capenable;
   5665  1.65.2.2  martin 
   5666  1.65.2.2  martin 	if (ISSET(next_ec_capenable, ETHERCAP_VLAN_HWFILTER)) {
   5667  1.65.2.2  martin 		rv = ixl_setup_vlan_hwfilter(sc);
   5668  1.65.2.2  martin 		if (rv != 0)
   5669  1.65.2.2  martin 			ixl_teardown_vlan_hwfilter(sc);
   5670  1.65.2.2  martin 	} else {
   5671  1.65.2.2  martin 		ixl_teardown_vlan_hwfilter(sc);
   5672  1.65.2.2  martin 	}
   5673  1.65.2.2  martin 
   5674  1.65.2.2  martin 	return rv;
   5675  1.65.2.2  martin }
   5676  1.65.2.2  martin 
   5677  1.65.2.2  martin static int
   5678  1.65.2.2  martin ixl_ifflags_cb(struct ethercom *ec)
   5679  1.65.2.2  martin {
   5680  1.65.2.2  martin 	struct ifnet *ifp = &ec->ec_if;
   5681  1.65.2.2  martin 	struct ixl_softc *sc = ifp->if_softc;
   5682  1.65.2.2  martin 	int rv, change;
   5683  1.65.2.2  martin 
   5684  1.65.2.2  martin 	mutex_enter(&sc->sc_cfg_lock);
   5685  1.65.2.2  martin 
   5686  1.65.2.2  martin 	change = ec->ec_capenable ^ sc->sc_cur_ec_capenable;
   5687  1.65.2.2  martin 
   5688  1.65.2.2  martin 	if (ISSET(change, ETHERCAP_VLAN_HWTAGGING)) {
   5689  1.65.2.2  martin 		sc->sc_cur_ec_capenable ^= ETHERCAP_VLAN_HWTAGGING;
   5690  1.65.2.2  martin 		rv = ENETRESET;
   5691  1.65.2.2  martin 		goto out;
   5692  1.65.2.2  martin 	}
   5693  1.65.2.2  martin 
   5694  1.65.2.2  martin 	if (ISSET(change, ETHERCAP_VLAN_HWFILTER)) {
   5695  1.65.2.2  martin 		rv = ixl_update_macvlan(sc);
   5696  1.65.2.2  martin 		if (rv == 0) {
   5697  1.65.2.2  martin 			sc->sc_cur_ec_capenable ^= ETHERCAP_VLAN_HWFILTER;
   5698  1.65.2.2  martin 		} else {
   5699  1.65.2.2  martin 			CLR(ec->ec_capenable, ETHERCAP_VLAN_HWFILTER);
   5700  1.65.2.2  martin 			CLR(sc->sc_cur_ec_capenable, ETHERCAP_VLAN_HWFILTER);
   5701  1.65.2.2  martin 		}
   5702  1.65.2.2  martin 	}
   5703  1.65.2.2  martin 
   5704  1.65.2.2  martin 	rv = ixl_iff(sc);
   5705  1.65.2.2  martin out:
   5706  1.65.2.2  martin 	mutex_exit(&sc->sc_cfg_lock);
   5707  1.65.2.2  martin 
   5708  1.65.2.2  martin 	return rv;
   5709  1.65.2.2  martin }
   5710  1.65.2.2  martin 
   5711  1.65.2.2  martin static int
   5712  1.65.2.2  martin ixl_set_link_status_locked(struct ixl_softc *sc, const struct ixl_aq_desc *iaq)
   5713  1.65.2.2  martin {
   5714  1.65.2.2  martin 	const struct ixl_aq_link_status *status;
   5715  1.65.2.2  martin 	const struct ixl_phy_type *itype;
   5716  1.65.2.2  martin 
   5717  1.65.2.2  martin 	uint64_t ifm_active = IFM_ETHER;
   5718  1.65.2.2  martin 	uint64_t ifm_status = IFM_AVALID;
   5719  1.65.2.2  martin 	int link_state = LINK_STATE_DOWN;
   5720  1.65.2.2  martin 	uint64_t baudrate = 0;
   5721  1.65.2.2  martin 
   5722  1.65.2.2  martin 	status = (const struct ixl_aq_link_status *)iaq->iaq_param;
   5723  1.65.2.2  martin 	if (!ISSET(status->link_info, IXL_AQ_LINK_UP_FUNCTION)) {
   5724  1.65.2.2  martin 		ifm_active |= IFM_NONE;
   5725  1.65.2.2  martin 		goto done;
   5726  1.65.2.2  martin 	}
   5727  1.65.2.2  martin 
   5728  1.65.2.2  martin 	ifm_active |= IFM_FDX;
   5729  1.65.2.2  martin 	ifm_status |= IFM_ACTIVE;
   5730  1.65.2.2  martin 	link_state = LINK_STATE_UP;
   5731  1.65.2.2  martin 
   5732  1.65.2.2  martin 	itype = ixl_search_phy_type(status->phy_type);
   5733  1.65.2.2  martin 	if (itype != NULL)
   5734  1.65.2.2  martin 		ifm_active |= itype->ifm_type;
   5735  1.65.2.2  martin 
   5736  1.65.2.2  martin 	if (ISSET(status->an_info, IXL_AQ_LINK_PAUSE_TX))
   5737  1.65.2.2  martin 		ifm_active |= IFM_ETH_TXPAUSE;
   5738  1.65.2.2  martin 	if (ISSET(status->an_info, IXL_AQ_LINK_PAUSE_RX))
   5739  1.65.2.2  martin 		ifm_active |= IFM_ETH_RXPAUSE;
   5740  1.65.2.2  martin 
   5741  1.65.2.2  martin 	baudrate = ixl_search_link_speed(status->link_speed);
   5742  1.65.2.2  martin 
   5743  1.65.2.2  martin done:
   5744  1.65.2.2  martin 	/* sc->sc_cfg_lock held expect during attach */
   5745  1.65.2.2  martin 	sc->sc_media_active = ifm_active;
   5746  1.65.2.2  martin 	sc->sc_media_status = ifm_status;
   5747  1.65.2.2  martin 
   5748  1.65.2.2  martin 	sc->sc_ec.ec_if.if_baudrate = baudrate;
   5749  1.65.2.2  martin 
   5750  1.65.2.2  martin 	return link_state;
   5751  1.65.2.2  martin }
   5752  1.65.2.2  martin 
   5753  1.65.2.2  martin static int
   5754  1.65.2.2  martin ixl_establish_intx(struct ixl_softc *sc)
   5755  1.65.2.2  martin {
   5756  1.65.2.2  martin 	pci_chipset_tag_t pc = sc->sc_pa.pa_pc;
   5757  1.65.2.2  martin 	pci_intr_handle_t *intr;
   5758  1.65.2.2  martin 	char xnamebuf[32];
   5759  1.65.2.2  martin 	char intrbuf[PCI_INTRSTR_LEN];
   5760  1.65.2.2  martin 	char const *intrstr;
   5761  1.65.2.2  martin 
   5762  1.65.2.2  martin 	KASSERT(sc->sc_nintrs == 1);
   5763  1.65.2.2  martin 
   5764  1.65.2.2  martin 	intr = &sc->sc_ihp[0];
   5765  1.65.2.2  martin 
   5766  1.65.2.2  martin 	intrstr = pci_intr_string(pc, *intr, intrbuf, sizeof(intrbuf));
   5767  1.65.2.2  martin 	snprintf(xnamebuf, sizeof(xnamebuf), "%s:legacy",
   5768  1.65.2.2  martin 	    device_xname(sc->sc_dev));
   5769  1.65.2.2  martin 
   5770  1.65.2.2  martin 	sc->sc_ihs[0] = pci_intr_establish_xname(pc, *intr, IPL_NET, ixl_intr,
   5771  1.65.2.2  martin 	    sc, xnamebuf);
   5772  1.65.2.2  martin 
   5773  1.65.2.2  martin 	if (sc->sc_ihs[0] == NULL) {
   5774  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   5775  1.65.2.2  martin 		    "unable to establish interrupt at %s\n", intrstr);
   5776  1.65.2.2  martin 		return -1;
   5777  1.65.2.2  martin 	}
   5778  1.65.2.2  martin 
   5779  1.65.2.2  martin 	aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
   5780  1.65.2.2  martin 	return 0;
   5781  1.65.2.2  martin }
   5782  1.65.2.2  martin 
   5783  1.65.2.2  martin static int
   5784  1.65.2.2  martin ixl_establish_msix(struct ixl_softc *sc)
   5785  1.65.2.2  martin {
   5786  1.65.2.2  martin 	pci_chipset_tag_t pc = sc->sc_pa.pa_pc;
   5787  1.65.2.2  martin 	kcpuset_t *affinity;
   5788  1.65.2.2  martin 	unsigned int vector = 0;
   5789  1.65.2.2  martin 	unsigned int i;
   5790  1.65.2.2  martin 	int affinity_to, r;
   5791  1.65.2.2  martin 	char xnamebuf[32];
   5792  1.65.2.2  martin 	char intrbuf[PCI_INTRSTR_LEN];
   5793  1.65.2.2  martin 	char const *intrstr;
   5794  1.65.2.2  martin 
   5795  1.65.2.2  martin 	kcpuset_create(&affinity, false);
   5796  1.65.2.2  martin 
   5797  1.65.2.2  martin 	/* the "other" intr is mapped to vector 0 */
   5798  1.65.2.2  martin 	vector = 0;
   5799  1.65.2.2  martin 	intrstr = pci_intr_string(pc, sc->sc_ihp[vector],
   5800  1.65.2.2  martin 	    intrbuf, sizeof(intrbuf));
   5801  1.65.2.2  martin 	snprintf(xnamebuf, sizeof(xnamebuf), "%s others",
   5802  1.65.2.2  martin 	    device_xname(sc->sc_dev));
   5803  1.65.2.2  martin 	sc->sc_ihs[vector] = pci_intr_establish_xname(pc,
   5804  1.65.2.2  martin 	    sc->sc_ihp[vector], IPL_NET, ixl_other_intr,
   5805  1.65.2.2  martin 	    sc, xnamebuf);
   5806  1.65.2.2  martin 	if (sc->sc_ihs[vector] == NULL) {
   5807  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   5808  1.65.2.2  martin 		    "unable to establish interrupt at %s\n", intrstr);
   5809  1.65.2.2  martin 		goto fail;
   5810  1.65.2.2  martin 	}
   5811  1.65.2.2  martin 
   5812  1.65.2.2  martin 	aprint_normal_dev(sc->sc_dev, "other interrupt at %s", intrstr);
   5813  1.65.2.2  martin 
   5814  1.65.2.2  martin 	affinity_to = ncpu > (int)sc->sc_nqueue_pairs_max ? 1 : 0;
   5815  1.65.2.2  martin 	affinity_to = (affinity_to + sc->sc_nqueue_pairs_max) % ncpu;
   5816  1.65.2.2  martin 
   5817  1.65.2.2  martin 	kcpuset_zero(affinity);
   5818  1.65.2.2  martin 	kcpuset_set(affinity, affinity_to);
   5819  1.65.2.2  martin 	r = interrupt_distribute(sc->sc_ihs[vector], affinity, NULL);
   5820  1.65.2.2  martin 	if (r == 0) {
   5821  1.65.2.2  martin 		aprint_normal(", affinity to %u", affinity_to);
   5822  1.65.2.2  martin 	}
   5823  1.65.2.2  martin 	aprint_normal("\n");
   5824  1.65.2.2  martin 	vector++;
   5825  1.65.2.2  martin 
   5826  1.65.2.2  martin 	sc->sc_msix_vector_queue = vector;
   5827  1.65.2.2  martin 	affinity_to = ncpu > (int)sc->sc_nqueue_pairs_max ? 1 : 0;
   5828  1.65.2.2  martin 
   5829  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs_max; i++) {
   5830  1.65.2.2  martin 		intrstr = pci_intr_string(pc, sc->sc_ihp[vector],
   5831  1.65.2.2  martin 		    intrbuf, sizeof(intrbuf));
   5832  1.65.2.2  martin 		snprintf(xnamebuf, sizeof(xnamebuf), "%s TXRX%d",
   5833  1.65.2.2  martin 		    device_xname(sc->sc_dev), i);
   5834  1.65.2.2  martin 
   5835  1.65.2.2  martin 		sc->sc_ihs[vector] = pci_intr_establish_xname(pc,
   5836  1.65.2.2  martin 		    sc->sc_ihp[vector], IPL_NET, ixl_queue_intr,
   5837  1.65.2.2  martin 		    (void *)&sc->sc_qps[i], xnamebuf);
   5838  1.65.2.2  martin 
   5839  1.65.2.2  martin 		if (sc->sc_ihs[vector] == NULL) {
   5840  1.65.2.2  martin 			aprint_error_dev(sc->sc_dev,
   5841  1.65.2.2  martin 			    "unable to establish interrupt at %s\n", intrstr);
   5842  1.65.2.2  martin 			goto fail;
   5843  1.65.2.2  martin 		}
   5844  1.65.2.2  martin 
   5845  1.65.2.2  martin 		aprint_normal_dev(sc->sc_dev,
   5846  1.65.2.2  martin 		    "for TXRX%d interrupt at %s",i , intrstr);
   5847  1.65.2.2  martin 
   5848  1.65.2.2  martin 		kcpuset_zero(affinity);
   5849  1.65.2.2  martin 		kcpuset_set(affinity, affinity_to);
   5850  1.65.2.2  martin 		r = interrupt_distribute(sc->sc_ihs[vector], affinity, NULL);
   5851  1.65.2.2  martin 		if (r == 0) {
   5852  1.65.2.2  martin 			aprint_normal(", affinity to %u", affinity_to);
   5853  1.65.2.2  martin 			affinity_to = (affinity_to + 1) % ncpu;
   5854  1.65.2.2  martin 		}
   5855  1.65.2.2  martin 		aprint_normal("\n");
   5856  1.65.2.2  martin 		vector++;
   5857  1.65.2.2  martin 	}
   5858  1.65.2.2  martin 
   5859  1.65.2.2  martin 	kcpuset_destroy(affinity);
   5860  1.65.2.2  martin 
   5861  1.65.2.2  martin 	return 0;
   5862  1.65.2.2  martin fail:
   5863  1.65.2.2  martin 	for (i = 0; i < vector; i++) {
   5864  1.65.2.2  martin 		pci_intr_disestablish(pc, sc->sc_ihs[i]);
   5865  1.65.2.2  martin 	}
   5866  1.65.2.2  martin 
   5867  1.65.2.2  martin 	sc->sc_msix_vector_queue = 0;
   5868  1.65.2.2  martin 	sc->sc_msix_vector_queue = 0;
   5869  1.65.2.2  martin 	kcpuset_destroy(affinity);
   5870  1.65.2.2  martin 
   5871  1.65.2.2  martin 	return -1;
   5872  1.65.2.2  martin }
   5873  1.65.2.2  martin 
   5874  1.65.2.2  martin static void
   5875  1.65.2.2  martin ixl_config_queue_intr(struct ixl_softc *sc)
   5876  1.65.2.2  martin {
   5877  1.65.2.2  martin 	unsigned int i, vector;
   5878  1.65.2.2  martin 
   5879  1.65.2.2  martin 	if (sc->sc_intrtype == PCI_INTR_TYPE_MSIX) {
   5880  1.65.2.2  martin 		vector = sc->sc_msix_vector_queue;
   5881  1.65.2.2  martin 	} else {
   5882  1.65.2.2  martin 		vector = I40E_INTR_NOTX_INTR;
   5883  1.65.2.2  martin 
   5884  1.65.2.2  martin 		ixl_wr(sc, I40E_PFINT_LNKLST0,
   5885  1.65.2.2  martin 		    (I40E_INTR_NOTX_QUEUE <<
   5886  1.65.2.2  martin 		     I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
   5887  1.65.2.2  martin 		    (I40E_QUEUE_TYPE_RX <<
   5888  1.65.2.2  martin 		     I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
   5889  1.65.2.2  martin 	}
   5890  1.65.2.2  martin 
   5891  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs; i++) {
   5892  1.65.2.2  martin 		ixl_wr(sc, I40E_PFINT_DYN_CTLN(i), 0);
   5893  1.65.2.2  martin 		ixl_flush(sc);
   5894  1.65.2.2  martin 
   5895  1.65.2.2  martin 		ixl_wr(sc, I40E_PFINT_LNKLSTN(i),
   5896  1.65.2.2  martin 		    ((i) << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
   5897  1.65.2.2  martin 		    (I40E_QUEUE_TYPE_RX <<
   5898  1.65.2.2  martin 		     I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
   5899  1.65.2.2  martin 
   5900  1.65.2.2  martin 		ixl_wr(sc, I40E_QINT_RQCTL(i),
   5901  1.65.2.2  martin 		    (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
   5902  1.65.2.2  martin 		    (I40E_ITR_INDEX_RX <<
   5903  1.65.2.2  martin 		     I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
   5904  1.65.2.2  martin 		    (I40E_INTR_NOTX_RX_QUEUE <<
   5905  1.65.2.2  martin 		     I40E_QINT_RQCTL_MSIX0_INDX_SHIFT) |
   5906  1.65.2.2  martin 		    (i << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
   5907  1.65.2.2  martin 		    (I40E_QUEUE_TYPE_TX <<
   5908  1.65.2.2  martin 		     I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
   5909  1.65.2.2  martin 		    I40E_QINT_RQCTL_CAUSE_ENA_MASK);
   5910  1.65.2.2  martin 
   5911  1.65.2.2  martin 		ixl_wr(sc, I40E_QINT_TQCTL(i),
   5912  1.65.2.2  martin 		    (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
   5913  1.65.2.2  martin 		    (I40E_ITR_INDEX_TX <<
   5914  1.65.2.2  martin 		     I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
   5915  1.65.2.2  martin 		    (I40E_INTR_NOTX_TX_QUEUE <<
   5916  1.65.2.2  martin 		     I40E_QINT_TQCTL_MSIX0_INDX_SHIFT) |
   5917  1.65.2.2  martin 		    (I40E_QUEUE_TYPE_EOL <<
   5918  1.65.2.2  martin 		     I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
   5919  1.65.2.2  martin 		    (I40E_QUEUE_TYPE_RX <<
   5920  1.65.2.2  martin 		     I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT) |
   5921  1.65.2.2  martin 		     I40E_QINT_TQCTL_CAUSE_ENA_MASK);
   5922  1.65.2.2  martin 
   5923  1.65.2.2  martin 		if (sc->sc_intrtype == PCI_INTR_TYPE_MSIX) {
   5924  1.65.2.2  martin 			ixl_wr(sc, I40E_PFINT_ITRN(I40E_ITR_INDEX_RX, i),
   5925  1.65.2.2  martin 			    sc->sc_itr_rx);
   5926  1.65.2.2  martin 			ixl_wr(sc, I40E_PFINT_ITRN(I40E_ITR_INDEX_TX, i),
   5927  1.65.2.2  martin 			    sc->sc_itr_tx);
   5928  1.65.2.2  martin 			vector++;
   5929  1.65.2.2  martin 		}
   5930  1.65.2.2  martin 	}
   5931  1.65.2.2  martin 	ixl_flush(sc);
   5932  1.65.2.2  martin 
   5933  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_ITR0(I40E_ITR_INDEX_RX), sc->sc_itr_rx);
   5934  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_ITR0(I40E_ITR_INDEX_TX), sc->sc_itr_tx);
   5935  1.65.2.2  martin 	ixl_flush(sc);
   5936  1.65.2.2  martin }
   5937  1.65.2.2  martin 
   5938  1.65.2.2  martin static void
   5939  1.65.2.2  martin ixl_config_other_intr(struct ixl_softc *sc)
   5940  1.65.2.2  martin {
   5941  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_ICR0_ENA, 0);
   5942  1.65.2.2  martin 	(void)ixl_rd(sc, I40E_PFINT_ICR0);
   5943  1.65.2.2  martin 
   5944  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_ICR0_ENA,
   5945  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
   5946  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_GRST_MASK |
   5947  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_ADMINQ_MASK |
   5948  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
   5949  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
   5950  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_VFLR_MASK |
   5951  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK |
   5952  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
   5953  1.65.2.2  martin 	    I40E_PFINT_ICR0_ENA_LINK_STAT_CHANGE_MASK);
   5954  1.65.2.2  martin 
   5955  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_LNKLST0, 0x7FF);
   5956  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_ITR0(I40E_ITR_INDEX_OTHER), 0);
   5957  1.65.2.2  martin 	ixl_wr(sc, I40E_PFINT_STAT_CTL0,
   5958  1.65.2.2  martin 	    (I40E_ITR_INDEX_OTHER <<
   5959  1.65.2.2  martin 	     I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_SHIFT));
   5960  1.65.2.2  martin 	ixl_flush(sc);
   5961  1.65.2.2  martin }
   5962  1.65.2.2  martin 
   5963  1.65.2.2  martin static int
   5964  1.65.2.2  martin ixl_setup_interrupts(struct ixl_softc *sc)
   5965  1.65.2.2  martin {
   5966  1.65.2.2  martin 	struct pci_attach_args *pa = &sc->sc_pa;
   5967  1.65.2.2  martin 	pci_intr_type_t max_type, intr_type;
   5968  1.65.2.2  martin 	int counts[PCI_INTR_TYPE_SIZE];
   5969  1.65.2.2  martin 	int error;
   5970  1.65.2.2  martin 	unsigned int i;
   5971  1.65.2.2  martin 	bool retry;
   5972  1.65.2.2  martin 
   5973  1.65.2.2  martin 	memset(counts, 0, sizeof(counts));
   5974  1.65.2.2  martin 	max_type = PCI_INTR_TYPE_MSIX;
   5975  1.65.2.2  martin 	/* QPs + other interrupt */
   5976  1.65.2.2  martin 	counts[PCI_INTR_TYPE_MSIX] = sc->sc_nqueue_pairs_max + 1;
   5977  1.65.2.2  martin 	counts[PCI_INTR_TYPE_INTX] = 1;
   5978  1.65.2.2  martin 
   5979  1.65.2.2  martin 	if (ixl_param_nomsix)
   5980  1.65.2.2  martin 		counts[PCI_INTR_TYPE_MSIX] = 0;
   5981  1.65.2.2  martin 
   5982  1.65.2.2  martin 	do {
   5983  1.65.2.2  martin 		retry = false;
   5984  1.65.2.2  martin 		error = pci_intr_alloc(pa, &sc->sc_ihp, counts, max_type);
   5985  1.65.2.2  martin 		if (error != 0) {
   5986  1.65.2.2  martin 			aprint_error_dev(sc->sc_dev,
   5987  1.65.2.2  martin 			    "couldn't map interrupt\n");
   5988  1.65.2.2  martin 			break;
   5989  1.65.2.2  martin 		}
   5990  1.65.2.2  martin 
   5991  1.65.2.2  martin 		intr_type = pci_intr_type(pa->pa_pc, sc->sc_ihp[0]);
   5992  1.65.2.2  martin 		sc->sc_nintrs = counts[intr_type];
   5993  1.65.2.2  martin 		KASSERT(sc->sc_nintrs > 0);
   5994  1.65.2.2  martin 
   5995  1.65.2.2  martin 		for (i = 0; i < sc->sc_nintrs; i++) {
   5996  1.65.2.2  martin 			pci_intr_setattr(pa->pa_pc, &sc->sc_ihp[i],
   5997  1.65.2.2  martin 			    PCI_INTR_MPSAFE, true);
   5998  1.65.2.2  martin 		}
   5999  1.65.2.2  martin 
   6000  1.65.2.2  martin 		sc->sc_ihs = kmem_alloc(sizeof(sc->sc_ihs[0]) * sc->sc_nintrs,
   6001  1.65.2.2  martin 		    KM_SLEEP);
   6002  1.65.2.2  martin 
   6003  1.65.2.2  martin 		if (intr_type == PCI_INTR_TYPE_MSIX) {
   6004  1.65.2.2  martin 			error = ixl_establish_msix(sc);
   6005  1.65.2.2  martin 			if (error) {
   6006  1.65.2.2  martin 				counts[PCI_INTR_TYPE_MSIX] = 0;
   6007  1.65.2.2  martin 				retry = true;
   6008  1.65.2.2  martin 			}
   6009  1.65.2.2  martin 		} else if (intr_type == PCI_INTR_TYPE_INTX) {
   6010  1.65.2.2  martin 			error = ixl_establish_intx(sc);
   6011  1.65.2.2  martin 		} else {
   6012  1.65.2.2  martin 			error = -1;
   6013  1.65.2.2  martin 		}
   6014  1.65.2.2  martin 
   6015  1.65.2.2  martin 		if (error) {
   6016  1.65.2.2  martin 			kmem_free(sc->sc_ihs,
   6017  1.65.2.2  martin 			    sizeof(sc->sc_ihs[0]) * sc->sc_nintrs);
   6018  1.65.2.2  martin 			pci_intr_release(pa->pa_pc, sc->sc_ihp, sc->sc_nintrs);
   6019  1.65.2.2  martin 		} else {
   6020  1.65.2.2  martin 			sc->sc_intrtype = intr_type;
   6021  1.65.2.2  martin 		}
   6022  1.65.2.2  martin 	} while (retry);
   6023  1.65.2.2  martin 
   6024  1.65.2.2  martin 	return error;
   6025  1.65.2.2  martin }
   6026  1.65.2.2  martin 
   6027  1.65.2.2  martin static void
   6028  1.65.2.2  martin ixl_teardown_interrupts(struct ixl_softc *sc)
   6029  1.65.2.2  martin {
   6030  1.65.2.2  martin 	struct pci_attach_args *pa = &sc->sc_pa;
   6031  1.65.2.2  martin 	unsigned int i;
   6032  1.65.2.2  martin 
   6033  1.65.2.2  martin 	for (i = 0; i < sc->sc_nintrs; i++) {
   6034  1.65.2.2  martin 		pci_intr_disestablish(pa->pa_pc, sc->sc_ihs[i]);
   6035  1.65.2.2  martin 	}
   6036  1.65.2.2  martin 
   6037  1.65.2.2  martin 	pci_intr_release(pa->pa_pc, sc->sc_ihp, sc->sc_nintrs);
   6038  1.65.2.2  martin 
   6039  1.65.2.2  martin 	kmem_free(sc->sc_ihs, sizeof(sc->sc_ihs[0]) * sc->sc_nintrs);
   6040  1.65.2.2  martin 	sc->sc_ihs = NULL;
   6041  1.65.2.2  martin 	sc->sc_nintrs = 0;
   6042  1.65.2.2  martin }
   6043  1.65.2.2  martin 
   6044  1.65.2.2  martin static int
   6045  1.65.2.2  martin ixl_setup_stats(struct ixl_softc *sc)
   6046  1.65.2.2  martin {
   6047  1.65.2.2  martin 	struct ixl_queue_pair *qp;
   6048  1.65.2.2  martin 	struct ixl_tx_ring *txr;
   6049  1.65.2.2  martin 	struct ixl_rx_ring *rxr;
   6050  1.65.2.2  martin 	struct ixl_stats_counters *isc;
   6051  1.65.2.2  martin 	unsigned int i;
   6052  1.65.2.2  martin 
   6053  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs_max; i++) {
   6054  1.65.2.2  martin 		qp = &sc->sc_qps[i];
   6055  1.65.2.2  martin 		txr = qp->qp_txr;
   6056  1.65.2.2  martin 		rxr = qp->qp_rxr;
   6057  1.65.2.2  martin 
   6058  1.65.2.2  martin 		evcnt_attach_dynamic(&txr->txr_defragged, EVCNT_TYPE_MISC,
   6059  1.65.2.2  martin 		    NULL, qp->qp_name, "m_defrag successed");
   6060  1.65.2.2  martin 		evcnt_attach_dynamic(&txr->txr_defrag_failed, EVCNT_TYPE_MISC,
   6061  1.65.2.2  martin 		    NULL, qp->qp_name, "m_defrag_failed");
   6062  1.65.2.2  martin 		evcnt_attach_dynamic(&txr->txr_pcqdrop, EVCNT_TYPE_MISC,
   6063  1.65.2.2  martin 		    NULL, qp->qp_name, "Dropped in pcq");
   6064  1.65.2.2  martin 		evcnt_attach_dynamic(&txr->txr_transmitdef, EVCNT_TYPE_MISC,
   6065  1.65.2.2  martin 		    NULL, qp->qp_name, "Deferred transmit");
   6066  1.65.2.2  martin 		evcnt_attach_dynamic(&txr->txr_intr, EVCNT_TYPE_INTR,
   6067  1.65.2.2  martin 		    NULL, qp->qp_name, "Interrupt on queue");
   6068  1.65.2.2  martin 		evcnt_attach_dynamic(&txr->txr_defer, EVCNT_TYPE_MISC,
   6069  1.65.2.2  martin 		    NULL, qp->qp_name, "Handled queue in softint/workqueue");
   6070  1.65.2.2  martin 
   6071  1.65.2.2  martin 		evcnt_attach_dynamic(&rxr->rxr_mgethdr_failed, EVCNT_TYPE_MISC,
   6072  1.65.2.2  martin 		    NULL, qp->qp_name, "MGETHDR failed");
   6073  1.65.2.2  martin 		evcnt_attach_dynamic(&rxr->rxr_mgetcl_failed, EVCNT_TYPE_MISC,
   6074  1.65.2.2  martin 		    NULL, qp->qp_name, "MCLGET failed");
   6075  1.65.2.2  martin 		evcnt_attach_dynamic(&rxr->rxr_mbuf_load_failed,
   6076  1.65.2.2  martin 		    EVCNT_TYPE_MISC, NULL, qp->qp_name,
   6077  1.65.2.2  martin 		    "bus_dmamap_load_mbuf failed");
   6078  1.65.2.2  martin 		evcnt_attach_dynamic(&rxr->rxr_intr, EVCNT_TYPE_INTR,
   6079  1.65.2.2  martin 		    NULL, qp->qp_name, "Interrupt on queue");
   6080  1.65.2.2  martin 		evcnt_attach_dynamic(&rxr->rxr_defer, EVCNT_TYPE_MISC,
   6081  1.65.2.2  martin 		    NULL, qp->qp_name, "Handled queue in softint/workqueue");
   6082  1.65.2.2  martin 	}
   6083  1.65.2.2  martin 
   6084  1.65.2.2  martin 	evcnt_attach_dynamic(&sc->sc_event_atq, EVCNT_TYPE_INTR,
   6085  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Interrupt for other events");
   6086  1.65.2.2  martin 	evcnt_attach_dynamic(&sc->sc_event_link, EVCNT_TYPE_MISC,
   6087  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Link status event");
   6088  1.65.2.2  martin 	evcnt_attach_dynamic(&sc->sc_event_ecc_err, EVCNT_TYPE_MISC,
   6089  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "ECC error");
   6090  1.65.2.2  martin 	evcnt_attach_dynamic(&sc->sc_event_pci_exception, EVCNT_TYPE_MISC,
   6091  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "PCI exception");
   6092  1.65.2.2  martin 	evcnt_attach_dynamic(&sc->sc_event_crit_err, EVCNT_TYPE_MISC,
   6093  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Critical error");
   6094  1.65.2.2  martin 
   6095  1.65.2.2  martin 	isc = &sc->sc_stats_counters;
   6096  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_crc_errors, EVCNT_TYPE_MISC,
   6097  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "CRC errors");
   6098  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_illegal_bytes, EVCNT_TYPE_MISC,
   6099  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Illegal bytes");
   6100  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_mac_local_faults, EVCNT_TYPE_MISC,
   6101  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Mac local faults");
   6102  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_mac_remote_faults, EVCNT_TYPE_MISC,
   6103  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Mac remote faults");
   6104  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_link_xon_rx, EVCNT_TYPE_MISC,
   6105  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx xon");
   6106  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_link_xon_tx, EVCNT_TYPE_MISC,
   6107  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx xon");
   6108  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_link_xoff_rx, EVCNT_TYPE_MISC,
   6109  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx xoff");
   6110  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_link_xoff_tx, EVCNT_TYPE_MISC,
   6111  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx xoff");
   6112  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_fragments, EVCNT_TYPE_MISC,
   6113  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx fragments");
   6114  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_jabber, EVCNT_TYPE_MISC,
   6115  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx jabber");
   6116  1.65.2.2  martin 
   6117  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_size_64, EVCNT_TYPE_MISC,
   6118  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx size 64");
   6119  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_size_127, EVCNT_TYPE_MISC,
   6120  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx size 127");
   6121  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_size_255, EVCNT_TYPE_MISC,
   6122  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx size 255");
   6123  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_size_511, EVCNT_TYPE_MISC,
   6124  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx size 511");
   6125  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_size_1023, EVCNT_TYPE_MISC,
   6126  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx size 1023");
   6127  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_size_1522, EVCNT_TYPE_MISC,
   6128  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx size 1522");
   6129  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_size_big, EVCNT_TYPE_MISC,
   6130  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx jumbo packets");
   6131  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_undersize, EVCNT_TYPE_MISC,
   6132  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx under size");
   6133  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_oversize, EVCNT_TYPE_MISC,
   6134  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx over size");
   6135  1.65.2.2  martin 
   6136  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_bytes, EVCNT_TYPE_MISC,
   6137  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx bytes / port");
   6138  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_discards, EVCNT_TYPE_MISC,
   6139  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx discards / port");
   6140  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_unicast, EVCNT_TYPE_MISC,
   6141  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx unicast / port");
   6142  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_multicast, EVCNT_TYPE_MISC,
   6143  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx multicast / port");
   6144  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_rx_broadcast, EVCNT_TYPE_MISC,
   6145  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx broadcast / port");
   6146  1.65.2.2  martin 
   6147  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_rx_bytes, EVCNT_TYPE_MISC,
   6148  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx bytes / vsi");
   6149  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_rx_discards, EVCNT_TYPE_MISC,
   6150  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx discard / vsi");
   6151  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_rx_unicast, EVCNT_TYPE_MISC,
   6152  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx unicast / vsi");
   6153  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_rx_multicast, EVCNT_TYPE_MISC,
   6154  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx multicast / vsi");
   6155  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_rx_broadcast, EVCNT_TYPE_MISC,
   6156  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Rx broadcast / vsi");
   6157  1.65.2.2  martin 
   6158  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_size_64, EVCNT_TYPE_MISC,
   6159  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx size 64");
   6160  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_size_127, EVCNT_TYPE_MISC,
   6161  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx size 127");
   6162  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_size_255, EVCNT_TYPE_MISC,
   6163  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx size 255");
   6164  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_size_511, EVCNT_TYPE_MISC,
   6165  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx size 511");
   6166  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_size_1023, EVCNT_TYPE_MISC,
   6167  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx size 1023");
   6168  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_size_1522, EVCNT_TYPE_MISC,
   6169  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx size 1522");
   6170  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_size_big, EVCNT_TYPE_MISC,
   6171  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx jumbo packets");
   6172  1.65.2.2  martin 
   6173  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_bytes, EVCNT_TYPE_MISC,
   6174  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx bytes / port");
   6175  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_dropped_link_down, EVCNT_TYPE_MISC,
   6176  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev),
   6177  1.65.2.2  martin 	    "Tx dropped due to link down / port");
   6178  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_unicast, EVCNT_TYPE_MISC,
   6179  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx unicast / port");
   6180  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_multicast, EVCNT_TYPE_MISC,
   6181  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx multicast / port");
   6182  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_tx_broadcast, EVCNT_TYPE_MISC,
   6183  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx broadcast / port");
   6184  1.65.2.2  martin 
   6185  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_tx_bytes, EVCNT_TYPE_MISC,
   6186  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx bytes / vsi");
   6187  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_tx_errors, EVCNT_TYPE_MISC,
   6188  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx errors / vsi");
   6189  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_tx_unicast, EVCNT_TYPE_MISC,
   6190  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx unicast / vsi");
   6191  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_tx_multicast, EVCNT_TYPE_MISC,
   6192  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx multicast / vsi");
   6193  1.65.2.2  martin 	evcnt_attach_dynamic(&isc->isc_vsi_tx_broadcast, EVCNT_TYPE_MISC,
   6194  1.65.2.2  martin 	    NULL, device_xname(sc->sc_dev), "Tx broadcast / vsi");
   6195  1.65.2.2  martin 
   6196  1.65.2.2  martin 	sc->sc_stats_intval = ixl_param_stats_interval;
   6197  1.65.2.2  martin 	callout_init(&sc->sc_stats_callout, CALLOUT_MPSAFE);
   6198  1.65.2.2  martin 	callout_setfunc(&sc->sc_stats_callout, ixl_stats_callout, sc);
   6199  1.65.2.2  martin 	ixl_work_set(&sc->sc_stats_task, ixl_stats_update, sc);
   6200  1.65.2.2  martin 
   6201  1.65.2.2  martin 	return 0;
   6202  1.65.2.2  martin }
   6203  1.65.2.2  martin 
   6204  1.65.2.2  martin static void
   6205  1.65.2.2  martin ixl_teardown_stats(struct ixl_softc *sc)
   6206  1.65.2.2  martin {
   6207  1.65.2.2  martin 	struct ixl_tx_ring *txr;
   6208  1.65.2.2  martin 	struct ixl_rx_ring *rxr;
   6209  1.65.2.2  martin 	struct ixl_stats_counters *isc;
   6210  1.65.2.2  martin 	unsigned int i;
   6211  1.65.2.2  martin 
   6212  1.65.2.2  martin 	for (i = 0; i < sc->sc_nqueue_pairs_max; i++) {
   6213  1.65.2.2  martin 		txr = sc->sc_qps[i].qp_txr;
   6214  1.65.2.2  martin 		rxr = sc->sc_qps[i].qp_rxr;
   6215  1.65.2.2  martin 
   6216  1.65.2.2  martin 		evcnt_detach(&txr->txr_defragged);
   6217  1.65.2.2  martin 		evcnt_detach(&txr->txr_defrag_failed);
   6218  1.65.2.2  martin 		evcnt_detach(&txr->txr_pcqdrop);
   6219  1.65.2.2  martin 		evcnt_detach(&txr->txr_transmitdef);
   6220  1.65.2.2  martin 		evcnt_detach(&txr->txr_intr);
   6221  1.65.2.2  martin 		evcnt_detach(&txr->txr_defer);
   6222  1.65.2.2  martin 
   6223  1.65.2.2  martin 		evcnt_detach(&rxr->rxr_mgethdr_failed);
   6224  1.65.2.2  martin 		evcnt_detach(&rxr->rxr_mgetcl_failed);
   6225  1.65.2.2  martin 		evcnt_detach(&rxr->rxr_mbuf_load_failed);
   6226  1.65.2.2  martin 		evcnt_detach(&rxr->rxr_intr);
   6227  1.65.2.2  martin 		evcnt_detach(&rxr->rxr_defer);
   6228  1.65.2.2  martin 	}
   6229  1.65.2.2  martin 
   6230  1.65.2.2  martin 	isc = &sc->sc_stats_counters;
   6231  1.65.2.2  martin 	evcnt_detach(&isc->isc_crc_errors);
   6232  1.65.2.2  martin 	evcnt_detach(&isc->isc_illegal_bytes);
   6233  1.65.2.2  martin 	evcnt_detach(&isc->isc_mac_local_faults);
   6234  1.65.2.2  martin 	evcnt_detach(&isc->isc_mac_remote_faults);
   6235  1.65.2.2  martin 	evcnt_detach(&isc->isc_link_xon_rx);
   6236  1.65.2.2  martin 	evcnt_detach(&isc->isc_link_xon_tx);
   6237  1.65.2.2  martin 	evcnt_detach(&isc->isc_link_xoff_rx);
   6238  1.65.2.2  martin 	evcnt_detach(&isc->isc_link_xoff_tx);
   6239  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_fragments);
   6240  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_jabber);
   6241  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_bytes);
   6242  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_discards);
   6243  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_unicast);
   6244  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_multicast);
   6245  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_broadcast);
   6246  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_size_64);
   6247  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_size_127);
   6248  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_size_255);
   6249  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_size_511);
   6250  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_size_1023);
   6251  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_size_1522);
   6252  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_size_big);
   6253  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_undersize);
   6254  1.65.2.2  martin 	evcnt_detach(&isc->isc_rx_oversize);
   6255  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_bytes);
   6256  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_dropped_link_down);
   6257  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_unicast);
   6258  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_multicast);
   6259  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_broadcast);
   6260  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_size_64);
   6261  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_size_127);
   6262  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_size_255);
   6263  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_size_511);
   6264  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_size_1023);
   6265  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_size_1522);
   6266  1.65.2.2  martin 	evcnt_detach(&isc->isc_tx_size_big);
   6267  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_rx_discards);
   6268  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_rx_bytes);
   6269  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_rx_unicast);
   6270  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_rx_multicast);
   6271  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_rx_broadcast);
   6272  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_tx_errors);
   6273  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_tx_bytes);
   6274  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_tx_unicast);
   6275  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_tx_multicast);
   6276  1.65.2.2  martin 	evcnt_detach(&isc->isc_vsi_tx_broadcast);
   6277  1.65.2.2  martin 
   6278  1.65.2.2  martin 	evcnt_detach(&sc->sc_event_atq);
   6279  1.65.2.2  martin 	evcnt_detach(&sc->sc_event_link);
   6280  1.65.2.2  martin 	evcnt_detach(&sc->sc_event_ecc_err);
   6281  1.65.2.2  martin 	evcnt_detach(&sc->sc_event_pci_exception);
   6282  1.65.2.2  martin 	evcnt_detach(&sc->sc_event_crit_err);
   6283  1.65.2.2  martin 
   6284  1.65.2.2  martin 	callout_destroy(&sc->sc_stats_callout);
   6285  1.65.2.2  martin }
   6286  1.65.2.2  martin 
   6287  1.65.2.2  martin static void
   6288  1.65.2.2  martin ixl_stats_callout(void *xsc)
   6289  1.65.2.2  martin {
   6290  1.65.2.2  martin 	struct ixl_softc *sc = xsc;
   6291  1.65.2.2  martin 
   6292  1.65.2.2  martin 	ixl_work_add(sc->sc_workq, &sc->sc_stats_task);
   6293  1.65.2.2  martin 	callout_schedule(&sc->sc_stats_callout, mstohz(sc->sc_stats_intval));
   6294  1.65.2.2  martin }
   6295  1.65.2.2  martin 
   6296  1.65.2.2  martin static uint64_t
   6297  1.65.2.2  martin ixl_stat_delta(struct ixl_softc *sc, uint32_t reg_hi, uint32_t reg_lo,
   6298  1.65.2.2  martin     uint64_t *offset, bool has_offset)
   6299  1.65.2.2  martin {
   6300  1.65.2.2  martin 	uint64_t value, delta;
   6301  1.65.2.2  martin 	int bitwidth;
   6302  1.65.2.2  martin 
   6303  1.65.2.2  martin 	bitwidth = reg_hi == 0 ? 32 : 48;
   6304  1.65.2.2  martin 
   6305  1.65.2.2  martin 	value = ixl_rd(sc, reg_lo);
   6306  1.65.2.2  martin 
   6307  1.65.2.2  martin 	if (bitwidth > 32) {
   6308  1.65.2.2  martin 		value |= ((uint64_t)ixl_rd(sc, reg_hi) << 32);
   6309  1.65.2.2  martin 	}
   6310  1.65.2.2  martin 
   6311  1.65.2.2  martin 	if (__predict_true(has_offset)) {
   6312  1.65.2.2  martin 		delta = value;
   6313  1.65.2.2  martin 		if (value < *offset)
   6314  1.65.2.2  martin 			delta += ((uint64_t)1 << bitwidth);
   6315  1.65.2.2  martin 		delta -= *offset;
   6316  1.65.2.2  martin 	} else {
   6317  1.65.2.2  martin 		delta = 0;
   6318  1.65.2.2  martin 	}
   6319  1.65.2.2  martin 	atomic_swap_64(offset, value);
   6320  1.65.2.2  martin 
   6321  1.65.2.2  martin 	return delta;
   6322  1.65.2.2  martin }
   6323  1.65.2.2  martin 
   6324  1.65.2.2  martin static void
   6325  1.65.2.2  martin ixl_stats_update(void *xsc)
   6326  1.65.2.2  martin {
   6327  1.65.2.2  martin 	struct ixl_softc *sc = xsc;
   6328  1.65.2.2  martin 	struct ixl_stats_counters *isc;
   6329  1.65.2.2  martin 	uint64_t delta;
   6330  1.65.2.2  martin 
   6331  1.65.2.2  martin 	isc = &sc->sc_stats_counters;
   6332  1.65.2.2  martin 
   6333  1.65.2.2  martin 	/* errors */
   6334  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6335  1.65.2.2  martin 	    0, I40E_GLPRT_CRCERRS(sc->sc_port),
   6336  1.65.2.2  martin 	    &isc->isc_crc_errors_offset, isc->isc_has_offset);
   6337  1.65.2.2  martin 	atomic_add_64(&isc->isc_crc_errors.ev_count, delta);
   6338  1.65.2.2  martin 
   6339  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6340  1.65.2.2  martin 	    0, I40E_GLPRT_ILLERRC(sc->sc_port),
   6341  1.65.2.2  martin 	    &isc->isc_illegal_bytes_offset, isc->isc_has_offset);
   6342  1.65.2.2  martin 	atomic_add_64(&isc->isc_illegal_bytes.ev_count, delta);
   6343  1.65.2.2  martin 
   6344  1.65.2.2  martin 	/* rx */
   6345  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6346  1.65.2.2  martin 	    I40E_GLPRT_GORCH(sc->sc_port), I40E_GLPRT_GORCL(sc->sc_port),
   6347  1.65.2.2  martin 	    &isc->isc_rx_bytes_offset, isc->isc_has_offset);
   6348  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_bytes.ev_count, delta);
   6349  1.65.2.2  martin 
   6350  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6351  1.65.2.2  martin 	    0, I40E_GLPRT_RDPC(sc->sc_port),
   6352  1.65.2.2  martin 	    &isc->isc_rx_discards_offset, isc->isc_has_offset);
   6353  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_discards.ev_count, delta);
   6354  1.65.2.2  martin 
   6355  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6356  1.65.2.2  martin 	    I40E_GLPRT_UPRCH(sc->sc_port), I40E_GLPRT_UPRCL(sc->sc_port),
   6357  1.65.2.2  martin 	    &isc->isc_rx_unicast_offset, isc->isc_has_offset);
   6358  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_unicast.ev_count, delta);
   6359  1.65.2.2  martin 
   6360  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6361  1.65.2.2  martin 	    I40E_GLPRT_MPRCH(sc->sc_port), I40E_GLPRT_MPRCL(sc->sc_port),
   6362  1.65.2.2  martin 	    &isc->isc_rx_multicast_offset, isc->isc_has_offset);
   6363  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_multicast.ev_count, delta);
   6364  1.65.2.2  martin 
   6365  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6366  1.65.2.2  martin 	    I40E_GLPRT_BPRCH(sc->sc_port), I40E_GLPRT_BPRCL(sc->sc_port),
   6367  1.65.2.2  martin 	    &isc->isc_rx_broadcast_offset, isc->isc_has_offset);
   6368  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_broadcast.ev_count, delta);
   6369  1.65.2.2  martin 
   6370  1.65.2.2  martin 	/* Packet size stats rx */
   6371  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6372  1.65.2.2  martin 	    I40E_GLPRT_PRC64H(sc->sc_port), I40E_GLPRT_PRC64L(sc->sc_port),
   6373  1.65.2.2  martin 	    &isc->isc_rx_size_64_offset, isc->isc_has_offset);
   6374  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_size_64.ev_count, delta);
   6375  1.65.2.2  martin 
   6376  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6377  1.65.2.2  martin 	    I40E_GLPRT_PRC127H(sc->sc_port), I40E_GLPRT_PRC127L(sc->sc_port),
   6378  1.65.2.2  martin 	    &isc->isc_rx_size_127_offset, isc->isc_has_offset);
   6379  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_size_127.ev_count, delta);
   6380  1.65.2.2  martin 
   6381  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6382  1.65.2.2  martin 	    I40E_GLPRT_PRC255H(sc->sc_port), I40E_GLPRT_PRC255L(sc->sc_port),
   6383  1.65.2.2  martin 	    &isc->isc_rx_size_255_offset, isc->isc_has_offset);
   6384  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_size_255.ev_count, delta);
   6385  1.65.2.2  martin 
   6386  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6387  1.65.2.2  martin 	    I40E_GLPRT_PRC511H(sc->sc_port), I40E_GLPRT_PRC511L(sc->sc_port),
   6388  1.65.2.2  martin 	    &isc->isc_rx_size_511_offset, isc->isc_has_offset);
   6389  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_size_511.ev_count, delta);
   6390  1.65.2.2  martin 
   6391  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6392  1.65.2.2  martin 	    I40E_GLPRT_PRC1023H(sc->sc_port), I40E_GLPRT_PRC1023L(sc->sc_port),
   6393  1.65.2.2  martin 	    &isc->isc_rx_size_1023_offset, isc->isc_has_offset);
   6394  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_size_1023.ev_count, delta);
   6395  1.65.2.2  martin 
   6396  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6397  1.65.2.2  martin 	    I40E_GLPRT_PRC1522H(sc->sc_port), I40E_GLPRT_PRC1522L(sc->sc_port),
   6398  1.65.2.2  martin 	    &isc->isc_rx_size_1522_offset, isc->isc_has_offset);
   6399  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_size_1522.ev_count, delta);
   6400  1.65.2.2  martin 
   6401  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6402  1.65.2.2  martin 	    I40E_GLPRT_PRC9522H(sc->sc_port), I40E_GLPRT_PRC9522L(sc->sc_port),
   6403  1.65.2.2  martin 	    &isc->isc_rx_size_big_offset, isc->isc_has_offset);
   6404  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_size_big.ev_count, delta);
   6405  1.65.2.2  martin 
   6406  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6407  1.65.2.2  martin 	    0, I40E_GLPRT_RUC(sc->sc_port),
   6408  1.65.2.2  martin 	    &isc->isc_rx_undersize_offset, isc->isc_has_offset);
   6409  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_undersize.ev_count, delta);
   6410  1.65.2.2  martin 
   6411  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6412  1.65.2.2  martin 	    0, I40E_GLPRT_ROC(sc->sc_port),
   6413  1.65.2.2  martin 	    &isc->isc_rx_oversize_offset, isc->isc_has_offset);
   6414  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_oversize.ev_count, delta);
   6415  1.65.2.2  martin 
   6416  1.65.2.2  martin 	/* tx */
   6417  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6418  1.65.2.2  martin 	    I40E_GLPRT_GOTCH(sc->sc_port), I40E_GLPRT_GOTCL(sc->sc_port),
   6419  1.65.2.2  martin 	    &isc->isc_tx_bytes_offset, isc->isc_has_offset);
   6420  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_bytes.ev_count, delta);
   6421  1.65.2.2  martin 
   6422  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6423  1.65.2.2  martin 	    0, I40E_GLPRT_TDOLD(sc->sc_port),
   6424  1.65.2.2  martin 	    &isc->isc_tx_dropped_link_down_offset, isc->isc_has_offset);
   6425  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_dropped_link_down.ev_count, delta);
   6426  1.65.2.2  martin 
   6427  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6428  1.65.2.2  martin 	    I40E_GLPRT_UPTCH(sc->sc_port), I40E_GLPRT_UPTCL(sc->sc_port),
   6429  1.65.2.2  martin 	    &isc->isc_tx_unicast_offset, isc->isc_has_offset);
   6430  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_unicast.ev_count, delta);
   6431  1.65.2.2  martin 
   6432  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6433  1.65.2.2  martin 	    I40E_GLPRT_MPTCH(sc->sc_port), I40E_GLPRT_MPTCL(sc->sc_port),
   6434  1.65.2.2  martin 	    &isc->isc_tx_multicast_offset, isc->isc_has_offset);
   6435  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_multicast.ev_count, delta);
   6436  1.65.2.2  martin 
   6437  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6438  1.65.2.2  martin 	    I40E_GLPRT_BPTCH(sc->sc_port), I40E_GLPRT_BPTCL(sc->sc_port),
   6439  1.65.2.2  martin 	    &isc->isc_tx_broadcast_offset, isc->isc_has_offset);
   6440  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_broadcast.ev_count, delta);
   6441  1.65.2.2  martin 
   6442  1.65.2.2  martin 	/* Packet size stats tx */
   6443  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6444  1.65.2.2  martin 	    I40E_GLPRT_PTC64L(sc->sc_port), I40E_GLPRT_PTC64L(sc->sc_port),
   6445  1.65.2.2  martin 	    &isc->isc_tx_size_64_offset, isc->isc_has_offset);
   6446  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_size_64.ev_count, delta);
   6447  1.65.2.2  martin 
   6448  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6449  1.65.2.2  martin 	    I40E_GLPRT_PTC127H(sc->sc_port), I40E_GLPRT_PTC127L(sc->sc_port),
   6450  1.65.2.2  martin 	    &isc->isc_tx_size_127_offset, isc->isc_has_offset);
   6451  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_size_127.ev_count, delta);
   6452  1.65.2.2  martin 
   6453  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6454  1.65.2.2  martin 	    I40E_GLPRT_PTC255H(sc->sc_port), I40E_GLPRT_PTC255L(sc->sc_port),
   6455  1.65.2.2  martin 	    &isc->isc_tx_size_255_offset, isc->isc_has_offset);
   6456  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_size_255.ev_count, delta);
   6457  1.65.2.2  martin 
   6458  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6459  1.65.2.2  martin 	    I40E_GLPRT_PTC511H(sc->sc_port), I40E_GLPRT_PTC511L(sc->sc_port),
   6460  1.65.2.2  martin 	    &isc->isc_tx_size_511_offset, isc->isc_has_offset);
   6461  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_size_511.ev_count, delta);
   6462  1.65.2.2  martin 
   6463  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6464  1.65.2.2  martin 	    I40E_GLPRT_PTC1023H(sc->sc_port), I40E_GLPRT_PTC1023L(sc->sc_port),
   6465  1.65.2.2  martin 	    &isc->isc_tx_size_1023_offset, isc->isc_has_offset);
   6466  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_size_1023.ev_count, delta);
   6467  1.65.2.2  martin 
   6468  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6469  1.65.2.2  martin 	    I40E_GLPRT_PTC1522H(sc->sc_port), I40E_GLPRT_PTC1522L(sc->sc_port),
   6470  1.65.2.2  martin 	    &isc->isc_tx_size_1522_offset, isc->isc_has_offset);
   6471  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_size_1522.ev_count, delta);
   6472  1.65.2.2  martin 
   6473  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6474  1.65.2.2  martin 	    I40E_GLPRT_PTC9522H(sc->sc_port), I40E_GLPRT_PTC9522L(sc->sc_port),
   6475  1.65.2.2  martin 	    &isc->isc_tx_size_big_offset, isc->isc_has_offset);
   6476  1.65.2.2  martin 	atomic_add_64(&isc->isc_tx_size_big.ev_count, delta);
   6477  1.65.2.2  martin 
   6478  1.65.2.2  martin 	/* mac faults */
   6479  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6480  1.65.2.2  martin 	    0, I40E_GLPRT_MLFC(sc->sc_port),
   6481  1.65.2.2  martin 	    &isc->isc_mac_local_faults_offset, isc->isc_has_offset);
   6482  1.65.2.2  martin 	atomic_add_64(&isc->isc_mac_local_faults.ev_count, delta);
   6483  1.65.2.2  martin 
   6484  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6485  1.65.2.2  martin 	    0, I40E_GLPRT_MRFC(sc->sc_port),
   6486  1.65.2.2  martin 	    &isc->isc_mac_remote_faults_offset, isc->isc_has_offset);
   6487  1.65.2.2  martin 	atomic_add_64(&isc->isc_mac_remote_faults.ev_count, delta);
   6488  1.65.2.2  martin 
   6489  1.65.2.2  martin 	/* Flow control (LFC) stats */
   6490  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6491  1.65.2.2  martin 	    0, I40E_GLPRT_LXONRXC(sc->sc_port),
   6492  1.65.2.2  martin 	    &isc->isc_link_xon_rx_offset, isc->isc_has_offset);
   6493  1.65.2.2  martin 	atomic_add_64(&isc->isc_link_xon_rx.ev_count, delta);
   6494  1.65.2.2  martin 
   6495  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6496  1.65.2.2  martin 	    0, I40E_GLPRT_LXONTXC(sc->sc_port),
   6497  1.65.2.2  martin 	    &isc->isc_link_xon_tx_offset, isc->isc_has_offset);
   6498  1.65.2.2  martin 	atomic_add_64(&isc->isc_link_xon_tx.ev_count, delta);
   6499  1.65.2.2  martin 
   6500  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6501  1.65.2.2  martin 	    0, I40E_GLPRT_LXOFFRXC(sc->sc_port),
   6502  1.65.2.2  martin 	    &isc->isc_link_xoff_rx_offset, isc->isc_has_offset);
   6503  1.65.2.2  martin 	atomic_add_64(&isc->isc_link_xoff_rx.ev_count, delta);
   6504  1.65.2.2  martin 
   6505  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6506  1.65.2.2  martin 	    0, I40E_GLPRT_LXOFFTXC(sc->sc_port),
   6507  1.65.2.2  martin 	    &isc->isc_link_xoff_tx_offset, isc->isc_has_offset);
   6508  1.65.2.2  martin 	atomic_add_64(&isc->isc_link_xoff_tx.ev_count, delta);
   6509  1.65.2.2  martin 
   6510  1.65.2.2  martin 	/* fragments */
   6511  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6512  1.65.2.2  martin 	    0, I40E_GLPRT_RFC(sc->sc_port),
   6513  1.65.2.2  martin 	    &isc->isc_rx_fragments_offset, isc->isc_has_offset);
   6514  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_fragments.ev_count, delta);
   6515  1.65.2.2  martin 
   6516  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6517  1.65.2.2  martin 	    0, I40E_GLPRT_RJC(sc->sc_port),
   6518  1.65.2.2  martin 	    &isc->isc_rx_jabber_offset, isc->isc_has_offset);
   6519  1.65.2.2  martin 	atomic_add_64(&isc->isc_rx_jabber.ev_count, delta);
   6520  1.65.2.2  martin 
   6521  1.65.2.2  martin 	/* VSI rx counters */
   6522  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6523  1.65.2.2  martin 	    0, I40E_GLV_RDPC(sc->sc_vsi_stat_counter_idx),
   6524  1.65.2.2  martin 	    &isc->isc_vsi_rx_discards_offset, isc->isc_has_offset);
   6525  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_rx_discards.ev_count, delta);
   6526  1.65.2.2  martin 
   6527  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6528  1.65.2.2  martin 	    I40E_GLV_GORCH(sc->sc_vsi_stat_counter_idx),
   6529  1.65.2.2  martin 	    I40E_GLV_GORCL(sc->sc_vsi_stat_counter_idx),
   6530  1.65.2.2  martin 	    &isc->isc_vsi_rx_bytes_offset, isc->isc_has_offset);
   6531  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_rx_bytes.ev_count, delta);
   6532  1.65.2.2  martin 
   6533  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6534  1.65.2.2  martin 	    I40E_GLV_UPRCH(sc->sc_vsi_stat_counter_idx),
   6535  1.65.2.2  martin 	    I40E_GLV_UPRCL(sc->sc_vsi_stat_counter_idx),
   6536  1.65.2.2  martin 	    &isc->isc_vsi_rx_unicast_offset, isc->isc_has_offset);
   6537  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_rx_unicast.ev_count, delta);
   6538  1.65.2.2  martin 
   6539  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6540  1.65.2.2  martin 	    I40E_GLV_MPRCH(sc->sc_vsi_stat_counter_idx),
   6541  1.65.2.2  martin 	    I40E_GLV_MPRCL(sc->sc_vsi_stat_counter_idx),
   6542  1.65.2.2  martin 	    &isc->isc_vsi_rx_multicast_offset, isc->isc_has_offset);
   6543  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_rx_multicast.ev_count, delta);
   6544  1.65.2.2  martin 
   6545  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6546  1.65.2.2  martin 	    I40E_GLV_BPRCH(sc->sc_vsi_stat_counter_idx),
   6547  1.65.2.2  martin 	    I40E_GLV_BPRCL(sc->sc_vsi_stat_counter_idx),
   6548  1.65.2.2  martin 	    &isc->isc_vsi_rx_broadcast_offset, isc->isc_has_offset);
   6549  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_rx_broadcast.ev_count, delta);
   6550  1.65.2.2  martin 
   6551  1.65.2.2  martin 	/* VSI tx counters */
   6552  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6553  1.65.2.2  martin 	    0, I40E_GLV_TEPC(sc->sc_vsi_stat_counter_idx),
   6554  1.65.2.2  martin 	    &isc->isc_vsi_tx_errors_offset, isc->isc_has_offset);
   6555  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_tx_errors.ev_count, delta);
   6556  1.65.2.2  martin 
   6557  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6558  1.65.2.2  martin 	    I40E_GLV_GOTCH(sc->sc_vsi_stat_counter_idx),
   6559  1.65.2.2  martin 	    I40E_GLV_GOTCL(sc->sc_vsi_stat_counter_idx),
   6560  1.65.2.2  martin 	    &isc->isc_vsi_tx_bytes_offset, isc->isc_has_offset);
   6561  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_tx_bytes.ev_count, delta);
   6562  1.65.2.2  martin 
   6563  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6564  1.65.2.2  martin 	    I40E_GLV_UPTCH(sc->sc_vsi_stat_counter_idx),
   6565  1.65.2.2  martin 	    I40E_GLV_UPTCL(sc->sc_vsi_stat_counter_idx),
   6566  1.65.2.2  martin 	    &isc->isc_vsi_tx_unicast_offset, isc->isc_has_offset);
   6567  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_tx_unicast.ev_count, delta);
   6568  1.65.2.2  martin 
   6569  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6570  1.65.2.2  martin 	    I40E_GLV_MPTCH(sc->sc_vsi_stat_counter_idx),
   6571  1.65.2.2  martin 	    I40E_GLV_MPTCL(sc->sc_vsi_stat_counter_idx),
   6572  1.65.2.2  martin 	    &isc->isc_vsi_tx_multicast_offset, isc->isc_has_offset);
   6573  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_tx_multicast.ev_count, delta);
   6574  1.65.2.2  martin 
   6575  1.65.2.2  martin 	delta = ixl_stat_delta(sc,
   6576  1.65.2.2  martin 	    I40E_GLV_BPTCH(sc->sc_vsi_stat_counter_idx),
   6577  1.65.2.2  martin 	    I40E_GLV_BPTCL(sc->sc_vsi_stat_counter_idx),
   6578  1.65.2.2  martin 	    &isc->isc_vsi_tx_broadcast_offset, isc->isc_has_offset);
   6579  1.65.2.2  martin 	atomic_add_64(&isc->isc_vsi_tx_broadcast.ev_count, delta);
   6580  1.65.2.2  martin }
   6581  1.65.2.2  martin 
   6582  1.65.2.2  martin static int
   6583  1.65.2.2  martin ixl_setup_sysctls(struct ixl_softc *sc)
   6584  1.65.2.2  martin {
   6585  1.65.2.2  martin 	const char *devname;
   6586  1.65.2.2  martin 	struct sysctllog **log;
   6587  1.65.2.2  martin 	const struct sysctlnode *rnode, *rxnode, *txnode;
   6588  1.65.2.2  martin 	int error;
   6589  1.65.2.2  martin 
   6590  1.65.2.2  martin 	log = &sc->sc_sysctllog;
   6591  1.65.2.2  martin 	devname = device_xname(sc->sc_dev);
   6592  1.65.2.2  martin 
   6593  1.65.2.2  martin 	error = sysctl_createv(log, 0, NULL, &rnode,
   6594  1.65.2.2  martin 	    0, CTLTYPE_NODE, devname,
   6595  1.65.2.2  martin 	    SYSCTL_DESCR("ixl information and settings"),
   6596  1.65.2.2  martin 	    NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
   6597  1.65.2.2  martin 	if (error)
   6598  1.65.2.2  martin 		goto out;
   6599  1.65.2.2  martin 
   6600  1.65.2.2  martin 	error = sysctl_createv(log, 0, &rnode, NULL,
   6601  1.65.2.2  martin 	    CTLFLAG_READWRITE, CTLTYPE_BOOL, "txrx_workqueue",
   6602  1.65.2.2  martin 	    SYSCTL_DESCR("Use workqueue for packet processing"),
   6603  1.65.2.2  martin 	    NULL, 0, &sc->sc_txrx_workqueue, 0, CTL_CREATE, CTL_EOL);
   6604  1.65.2.2  martin 	if (error)
   6605  1.65.2.2  martin 		goto out;
   6606  1.65.2.2  martin 
   6607  1.65.2.2  martin 	error = sysctl_createv(log, 0, &rnode, NULL,
   6608  1.65.2.2  martin 	    CTLFLAG_READONLY, CTLTYPE_INT, "stats_interval",
   6609  1.65.2.2  martin 	    SYSCTL_DESCR("Statistics collection interval in milliseconds"),
   6610  1.65.2.2  martin 	    NULL, 0, &sc->sc_stats_intval, 0, CTL_CREATE, CTL_EOL);
   6611  1.65.2.2  martin 
   6612  1.65.2.2  martin 	error = sysctl_createv(log, 0, &rnode, &rxnode,
   6613  1.65.2.2  martin 	    0, CTLTYPE_NODE, "rx",
   6614  1.65.2.2  martin 	    SYSCTL_DESCR("ixl information and settings for Rx"),
   6615  1.65.2.2  martin 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
   6616  1.65.2.2  martin 	if (error)
   6617  1.65.2.2  martin 		goto out;
   6618  1.65.2.2  martin 
   6619  1.65.2.2  martin 	error = sysctl_createv(log, 0, &rxnode, NULL,
   6620  1.65.2.2  martin 	    CTLFLAG_READWRITE, CTLTYPE_INT, "intr_process_limit",
   6621  1.65.2.2  martin 	    SYSCTL_DESCR("max number of Rx packets"
   6622  1.65.2.2  martin 	    " to process for interrupt processing"),
   6623  1.65.2.2  martin 	    NULL, 0, &sc->sc_rx_intr_process_limit, 0, CTL_CREATE, CTL_EOL);
   6624  1.65.2.2  martin 	if (error)
   6625  1.65.2.2  martin 		goto out;
   6626  1.65.2.2  martin 
   6627  1.65.2.2  martin 	error = sysctl_createv(log, 0, &rxnode, NULL,
   6628  1.65.2.2  martin 	    CTLFLAG_READWRITE, CTLTYPE_INT, "process_limit",
   6629  1.65.2.2  martin 	    SYSCTL_DESCR("max number of Rx packets"
   6630  1.65.2.2  martin 	    " to process for deferred processing"),
   6631  1.65.2.2  martin 	    NULL, 0, &sc->sc_rx_process_limit, 0, CTL_CREATE, CTL_EOL);
   6632  1.65.2.2  martin 	if (error)
   6633  1.65.2.2  martin 		goto out;
   6634  1.65.2.2  martin 
   6635  1.65.2.2  martin 	error = sysctl_createv(log, 0, &rnode, &txnode,
   6636  1.65.2.2  martin 	    0, CTLTYPE_NODE, "tx",
   6637  1.65.2.2  martin 	    SYSCTL_DESCR("ixl information and settings for Tx"),
   6638  1.65.2.2  martin 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
   6639  1.65.2.2  martin 	if (error)
   6640  1.65.2.2  martin 		goto out;
   6641  1.65.2.2  martin 
   6642  1.65.2.2  martin 	error = sysctl_createv(log, 0, &txnode, NULL,
   6643  1.65.2.2  martin 	    CTLFLAG_READWRITE, CTLTYPE_INT, "intr_process_limit",
   6644  1.65.2.2  martin 	    SYSCTL_DESCR("max number of Tx packets"
   6645  1.65.2.2  martin 	    " to process for interrupt processing"),
   6646  1.65.2.2  martin 	    NULL, 0, &sc->sc_tx_intr_process_limit, 0, CTL_CREATE, CTL_EOL);
   6647  1.65.2.2  martin 	if (error)
   6648  1.65.2.2  martin 		goto out;
   6649  1.65.2.2  martin 
   6650  1.65.2.2  martin 	error = sysctl_createv(log, 0, &txnode, NULL,
   6651  1.65.2.2  martin 	    CTLFLAG_READWRITE, CTLTYPE_INT, "process_limit",
   6652  1.65.2.2  martin 	    SYSCTL_DESCR("max number of Tx packets"
   6653  1.65.2.2  martin 	    " to process for deferred processing"),
   6654  1.65.2.2  martin 	    NULL, 0, &sc->sc_tx_process_limit, 0, CTL_CREATE, CTL_EOL);
   6655  1.65.2.2  martin 	if (error)
   6656  1.65.2.2  martin 		goto out;
   6657  1.65.2.2  martin 
   6658  1.65.2.2  martin out:
   6659  1.65.2.2  martin 	if (error) {
   6660  1.65.2.2  martin 		aprint_error_dev(sc->sc_dev,
   6661  1.65.2.2  martin 		    "unable to create sysctl node\n");
   6662  1.65.2.2  martin 		sysctl_teardown(log);
   6663  1.65.2.2  martin 	}
   6664  1.65.2.2  martin 
   6665  1.65.2.2  martin 	return error;
   6666  1.65.2.2  martin }
   6667  1.65.2.2  martin 
   6668  1.65.2.2  martin static void
   6669  1.65.2.2  martin ixl_teardown_sysctls(struct ixl_softc *sc)
   6670  1.65.2.2  martin {
   6671  1.65.2.2  martin 
   6672  1.65.2.2  martin 	sysctl_teardown(&sc->sc_sysctllog);
   6673  1.65.2.2  martin }
   6674  1.65.2.2  martin 
   6675  1.65.2.2  martin static struct workqueue *
   6676  1.65.2.2  martin ixl_workq_create(const char *name, pri_t prio, int ipl, int flags)
   6677  1.65.2.2  martin {
   6678  1.65.2.2  martin 	struct workqueue *wq;
   6679  1.65.2.2  martin 	int error;
   6680  1.65.2.2  martin 
   6681  1.65.2.2  martin 	error = workqueue_create(&wq, name, ixl_workq_work, NULL,
   6682  1.65.2.2  martin 	    prio, ipl, flags);
   6683  1.65.2.2  martin 
   6684  1.65.2.2  martin 	if (error)
   6685  1.65.2.2  martin 		return NULL;
   6686  1.65.2.2  martin 
   6687  1.65.2.2  martin 	return wq;
   6688  1.65.2.2  martin }
   6689  1.65.2.2  martin 
   6690  1.65.2.2  martin static void
   6691  1.65.2.2  martin ixl_workq_destroy(struct workqueue *wq)
   6692  1.65.2.2  martin {
   6693  1.65.2.2  martin 
   6694  1.65.2.2  martin 	workqueue_destroy(wq);
   6695  1.65.2.2  martin }
   6696  1.65.2.2  martin 
   6697  1.65.2.2  martin static void
   6698  1.65.2.2  martin ixl_work_set(struct ixl_work *work, void (*func)(void *), void *arg)
   6699  1.65.2.2  martin {
   6700  1.65.2.2  martin 
   6701  1.65.2.2  martin 	memset(work, 0, sizeof(*work));
   6702  1.65.2.2  martin 	work->ixw_func = func;
   6703  1.65.2.2  martin 	work->ixw_arg = arg;
   6704  1.65.2.2  martin }
   6705  1.65.2.2  martin 
   6706  1.65.2.2  martin static void
   6707  1.65.2.2  martin ixl_work_add(struct workqueue *wq, struct ixl_work *work)
   6708  1.65.2.2  martin {
   6709  1.65.2.2  martin 	if (atomic_cas_uint(&work->ixw_added, 0, 1) != 0)
   6710  1.65.2.2  martin 		return;
   6711  1.65.2.2  martin 
   6712  1.65.2.2  martin 	kpreempt_disable();
   6713  1.65.2.2  martin 	workqueue_enqueue(wq, &work->ixw_cookie, NULL);
   6714  1.65.2.2  martin 	kpreempt_enable();
   6715  1.65.2.2  martin }
   6716  1.65.2.2  martin 
   6717  1.65.2.2  martin static void
   6718  1.65.2.2  martin ixl_work_wait(struct workqueue *wq, struct ixl_work *work)
   6719  1.65.2.2  martin {
   6720  1.65.2.2  martin 
   6721  1.65.2.2  martin 	workqueue_wait(wq, &work->ixw_cookie);
   6722  1.65.2.2  martin }
   6723  1.65.2.2  martin 
   6724  1.65.2.2  martin static void
   6725  1.65.2.2  martin ixl_workq_work(struct work *wk, void *context)
   6726  1.65.2.2  martin {
   6727  1.65.2.2  martin 	struct ixl_work *work;
   6728  1.65.2.2  martin 
   6729  1.65.2.2  martin 	work = container_of(wk, struct ixl_work, ixw_cookie);
   6730  1.65.2.2  martin 
   6731  1.65.2.2  martin 	atomic_swap_uint(&work->ixw_added, 0);
   6732  1.65.2.2  martin 	work->ixw_func(work->ixw_arg);
   6733  1.65.2.2  martin }
   6734  1.65.2.2  martin 
   6735  1.65.2.2  martin static int
   6736  1.65.2.2  martin ixl_rx_ctl_read(struct ixl_softc *sc, uint32_t reg, uint32_t *rv)
   6737  1.65.2.2  martin {
   6738  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   6739  1.65.2.2  martin 
   6740  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   6741  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_RX_CTL_REG_READ);
   6742  1.65.2.2  martin 	iaq.iaq_param[1] = htole32(reg);
   6743  1.65.2.2  martin 
   6744  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0)
   6745  1.65.2.2  martin 		return ETIMEDOUT;
   6746  1.65.2.2  martin 
   6747  1.65.2.2  martin 	switch (htole16(iaq.iaq_retval)) {
   6748  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   6749  1.65.2.2  martin 		/* success */
   6750  1.65.2.2  martin 		break;
   6751  1.65.2.2  martin 	case IXL_AQ_RC_EACCES:
   6752  1.65.2.2  martin 		return EPERM;
   6753  1.65.2.2  martin 	case IXL_AQ_RC_EAGAIN:
   6754  1.65.2.2  martin 		return EAGAIN;
   6755  1.65.2.2  martin 	default:
   6756  1.65.2.2  martin 		return EIO;
   6757  1.65.2.2  martin 	}
   6758  1.65.2.2  martin 
   6759  1.65.2.2  martin 	*rv = htole32(iaq.iaq_param[3]);
   6760  1.65.2.2  martin 	return 0;
   6761  1.65.2.2  martin }
   6762  1.65.2.2  martin 
   6763  1.65.2.2  martin static uint32_t
   6764  1.65.2.2  martin ixl_rd_rx_csr(struct ixl_softc *sc, uint32_t reg)
   6765  1.65.2.2  martin {
   6766  1.65.2.2  martin 	uint32_t val;
   6767  1.65.2.2  martin 	int rv, retry, retry_limit;
   6768  1.65.2.2  martin 
   6769  1.65.2.2  martin 	if (ISSET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_RXCTL)) {
   6770  1.65.2.2  martin 		retry_limit = 5;
   6771  1.65.2.2  martin 	} else {
   6772  1.65.2.2  martin 		retry_limit = 0;
   6773  1.65.2.2  martin 	}
   6774  1.65.2.2  martin 
   6775  1.65.2.2  martin 	for (retry = 0; retry < retry_limit; retry++) {
   6776  1.65.2.2  martin 		rv = ixl_rx_ctl_read(sc, reg, &val);
   6777  1.65.2.2  martin 		if (rv == 0)
   6778  1.65.2.2  martin 			return val;
   6779  1.65.2.2  martin 		else if (rv == EAGAIN)
   6780  1.65.2.2  martin 			delaymsec(1);
   6781  1.65.2.2  martin 		else
   6782  1.65.2.2  martin 			break;
   6783  1.65.2.2  martin 	}
   6784  1.65.2.2  martin 
   6785  1.65.2.2  martin 	val = ixl_rd(sc, reg);
   6786  1.65.2.2  martin 
   6787  1.65.2.2  martin 	return val;
   6788  1.65.2.2  martin }
   6789  1.65.2.2  martin 
   6790  1.65.2.2  martin static int
   6791  1.65.2.2  martin ixl_rx_ctl_write(struct ixl_softc *sc, uint32_t reg, uint32_t value)
   6792  1.65.2.2  martin {
   6793  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   6794  1.65.2.2  martin 
   6795  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   6796  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_RX_CTL_REG_WRITE);
   6797  1.65.2.2  martin 	iaq.iaq_param[1] = htole32(reg);
   6798  1.65.2.2  martin 	iaq.iaq_param[3] = htole32(value);
   6799  1.65.2.2  martin 
   6800  1.65.2.2  martin 	if (ixl_atq_poll(sc, &iaq, 250) != 0)
   6801  1.65.2.2  martin 		return ETIMEDOUT;
   6802  1.65.2.2  martin 
   6803  1.65.2.2  martin 	switch (htole16(iaq.iaq_retval)) {
   6804  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   6805  1.65.2.2  martin 		/* success */
   6806  1.65.2.2  martin 		break;
   6807  1.65.2.2  martin 	case IXL_AQ_RC_EACCES:
   6808  1.65.2.2  martin 		return EPERM;
   6809  1.65.2.2  martin 	case IXL_AQ_RC_EAGAIN:
   6810  1.65.2.2  martin 		return EAGAIN;
   6811  1.65.2.2  martin 	default:
   6812  1.65.2.2  martin 		return EIO;
   6813  1.65.2.2  martin 	}
   6814  1.65.2.2  martin 
   6815  1.65.2.2  martin 	return 0;
   6816  1.65.2.2  martin }
   6817  1.65.2.2  martin 
   6818  1.65.2.2  martin static void
   6819  1.65.2.2  martin ixl_wr_rx_csr(struct ixl_softc *sc, uint32_t reg, uint32_t value)
   6820  1.65.2.2  martin {
   6821  1.65.2.2  martin 	int rv, retry, retry_limit;
   6822  1.65.2.2  martin 
   6823  1.65.2.2  martin 	if (ISSET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_RXCTL)) {
   6824  1.65.2.2  martin 		retry_limit = 5;
   6825  1.65.2.2  martin 	} else {
   6826  1.65.2.2  martin 		retry_limit = 0;
   6827  1.65.2.2  martin 	}
   6828  1.65.2.2  martin 
   6829  1.65.2.2  martin 	for (retry = 0; retry < retry_limit; retry++) {
   6830  1.65.2.2  martin 		rv = ixl_rx_ctl_write(sc, reg, value);
   6831  1.65.2.2  martin 		if (rv == 0)
   6832  1.65.2.2  martin 			return;
   6833  1.65.2.2  martin 		else if (rv == EAGAIN)
   6834  1.65.2.2  martin 			delaymsec(1);
   6835  1.65.2.2  martin 		else
   6836  1.65.2.2  martin 			break;
   6837  1.65.2.2  martin 	}
   6838  1.65.2.2  martin 
   6839  1.65.2.2  martin 	ixl_wr(sc, reg, value);
   6840  1.65.2.2  martin }
   6841  1.65.2.2  martin 
   6842  1.65.2.2  martin static int
   6843  1.65.2.2  martin ixl_nvm_lock(struct ixl_softc *sc, char rw)
   6844  1.65.2.2  martin {
   6845  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   6846  1.65.2.2  martin 	struct ixl_aq_req_resource_param *param;
   6847  1.65.2.2  martin 	int rv;
   6848  1.65.2.2  martin 
   6849  1.65.2.2  martin 	if (!ISSET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_NVMLOCK))
   6850  1.65.2.2  martin 		return 0;
   6851  1.65.2.2  martin 
   6852  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   6853  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_REQUEST_RESOURCE);
   6854  1.65.2.2  martin 
   6855  1.65.2.2  martin 	param = (struct ixl_aq_req_resource_param *)&iaq.iaq_param;
   6856  1.65.2.2  martin 	param->resource_id = htole16(IXL_AQ_RESOURCE_ID_NVM);
   6857  1.65.2.2  martin 	if (rw == 'R') {
   6858  1.65.2.2  martin 		param->access_type = htole16(IXL_AQ_RESOURCE_ACCES_READ);
   6859  1.65.2.2  martin 	} else {
   6860  1.65.2.2  martin 		param->access_type = htole16(IXL_AQ_RESOURCE_ACCES_WRITE);
   6861  1.65.2.2  martin 	}
   6862  1.65.2.2  martin 
   6863  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   6864  1.65.2.2  martin 
   6865  1.65.2.2  martin 	if (rv != 0)
   6866  1.65.2.2  martin 		return ETIMEDOUT;
   6867  1.65.2.2  martin 
   6868  1.65.2.2  martin 	switch (le16toh(iaq.iaq_retval)) {
   6869  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   6870  1.65.2.2  martin 		break;
   6871  1.65.2.2  martin 	case IXL_AQ_RC_EACCES:
   6872  1.65.2.2  martin 		return EACCES;
   6873  1.65.2.2  martin 	case IXL_AQ_RC_EBUSY:
   6874  1.65.2.2  martin 		return EBUSY;
   6875  1.65.2.2  martin 	case IXL_AQ_RC_EPERM:
   6876  1.65.2.2  martin 		return EPERM;
   6877  1.65.2.2  martin 	}
   6878  1.65.2.2  martin 
   6879  1.65.2.2  martin 	return 0;
   6880  1.65.2.2  martin }
   6881  1.65.2.2  martin 
   6882  1.65.2.2  martin static int
   6883  1.65.2.2  martin ixl_nvm_unlock(struct ixl_softc *sc)
   6884  1.65.2.2  martin {
   6885  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   6886  1.65.2.2  martin 	struct ixl_aq_rel_resource_param *param;
   6887  1.65.2.2  martin 	int rv;
   6888  1.65.2.2  martin 
   6889  1.65.2.2  martin 	if (!ISSET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_NVMLOCK))
   6890  1.65.2.2  martin 		return 0;
   6891  1.65.2.2  martin 
   6892  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   6893  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_RELEASE_RESOURCE);
   6894  1.65.2.2  martin 
   6895  1.65.2.2  martin 	param = (struct ixl_aq_rel_resource_param *)&iaq.iaq_param;
   6896  1.65.2.2  martin 	param->resource_id = htole16(IXL_AQ_RESOURCE_ID_NVM);
   6897  1.65.2.2  martin 
   6898  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   6899  1.65.2.2  martin 
   6900  1.65.2.2  martin 	if (rv != 0)
   6901  1.65.2.2  martin 		return ETIMEDOUT;
   6902  1.65.2.2  martin 
   6903  1.65.2.2  martin 	switch (le16toh(iaq.iaq_retval)) {
   6904  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   6905  1.65.2.2  martin 		break;
   6906  1.65.2.2  martin 	default:
   6907  1.65.2.2  martin 		return EIO;
   6908  1.65.2.2  martin 	}
   6909  1.65.2.2  martin 	return 0;
   6910  1.65.2.2  martin }
   6911  1.65.2.2  martin 
   6912  1.65.2.2  martin static int
   6913  1.65.2.2  martin ixl_srdone_poll(struct ixl_softc *sc)
   6914  1.65.2.2  martin {
   6915  1.65.2.2  martin 	int wait_count;
   6916  1.65.2.2  martin 	uint32_t reg;
   6917  1.65.2.2  martin 
   6918  1.65.2.2  martin 	for (wait_count = 0; wait_count < IXL_SRRD_SRCTL_ATTEMPTS;
   6919  1.65.2.2  martin 	    wait_count++) {
   6920  1.65.2.2  martin 		reg = ixl_rd(sc, I40E_GLNVM_SRCTL);
   6921  1.65.2.2  martin 		if (ISSET(reg, I40E_GLNVM_SRCTL_DONE_MASK))
   6922  1.65.2.2  martin 			break;
   6923  1.65.2.2  martin 
   6924  1.65.2.2  martin 		delaymsec(5);
   6925  1.65.2.2  martin 	}
   6926  1.65.2.2  martin 
   6927  1.65.2.2  martin 	if (wait_count == IXL_SRRD_SRCTL_ATTEMPTS)
   6928  1.65.2.2  martin 		return -1;
   6929  1.65.2.2  martin 
   6930  1.65.2.2  martin 	return 0;
   6931  1.65.2.2  martin }
   6932  1.65.2.2  martin 
   6933  1.65.2.2  martin static int
   6934  1.65.2.2  martin ixl_nvm_read_srctl(struct ixl_softc *sc, uint16_t offset, uint16_t *data)
   6935  1.65.2.2  martin {
   6936  1.65.2.2  martin 	uint32_t reg;
   6937  1.65.2.2  martin 
   6938  1.65.2.2  martin 	if (ixl_srdone_poll(sc) != 0)
   6939  1.65.2.2  martin 		return ETIMEDOUT;
   6940  1.65.2.2  martin 
   6941  1.65.2.2  martin 	reg = ((uint32_t)offset << I40E_GLNVM_SRCTL_ADDR_SHIFT) |
   6942  1.65.2.2  martin 	    __BIT(I40E_GLNVM_SRCTL_START_SHIFT);
   6943  1.65.2.2  martin 	ixl_wr(sc, I40E_GLNVM_SRCTL, reg);
   6944  1.65.2.2  martin 
   6945  1.65.2.2  martin 	if (ixl_srdone_poll(sc) != 0) {
   6946  1.65.2.2  martin 		aprint_debug("NVM read error: couldn't access "
   6947  1.65.2.2  martin 		    "Shadow RAM address: 0x%x\n", offset);
   6948  1.65.2.2  martin 		return ETIMEDOUT;
   6949  1.65.2.2  martin 	}
   6950  1.65.2.2  martin 
   6951  1.65.2.2  martin 	reg = ixl_rd(sc, I40E_GLNVM_SRDATA);
   6952  1.65.2.2  martin 	*data = (uint16_t)__SHIFTOUT(reg, I40E_GLNVM_SRDATA_RDDATA_MASK);
   6953  1.65.2.2  martin 
   6954  1.65.2.2  martin 	return 0;
   6955  1.65.2.2  martin }
   6956  1.65.2.2  martin 
   6957  1.65.2.2  martin static int
   6958  1.65.2.2  martin ixl_nvm_read_aq(struct ixl_softc *sc, uint16_t offset_word,
   6959  1.65.2.2  martin     void *data, size_t len)
   6960  1.65.2.2  martin {
   6961  1.65.2.2  martin 	struct ixl_dmamem *idm;
   6962  1.65.2.2  martin 	struct ixl_aq_desc iaq;
   6963  1.65.2.2  martin 	struct ixl_aq_nvm_param *param;
   6964  1.65.2.2  martin 	uint32_t offset_bytes;
   6965  1.65.2.2  martin 	int rv;
   6966  1.65.2.2  martin 
   6967  1.65.2.2  martin 	idm = &sc->sc_aqbuf;
   6968  1.65.2.2  martin 	if (len > IXL_DMA_LEN(idm))
   6969  1.65.2.2  martin 		return ENOMEM;
   6970  1.65.2.2  martin 
   6971  1.65.2.2  martin 	memset(IXL_DMA_KVA(idm), 0, IXL_DMA_LEN(idm));
   6972  1.65.2.2  martin 	memset(&iaq, 0, sizeof(iaq));
   6973  1.65.2.2  martin 	iaq.iaq_opcode = htole16(IXL_AQ_OP_NVM_READ);
   6974  1.65.2.2  martin 	iaq.iaq_flags = htole16(IXL_AQ_BUF |
   6975  1.65.2.2  martin 	    ((len > I40E_AQ_LARGE_BUF) ? IXL_AQ_LB : 0));
   6976  1.65.2.2  martin 	iaq.iaq_datalen = htole16(len);
   6977  1.65.2.2  martin 	ixl_aq_dva(&iaq, IXL_DMA_DVA(idm));
   6978  1.65.2.2  martin 
   6979  1.65.2.2  martin 	param = (struct ixl_aq_nvm_param *)iaq.iaq_param;
   6980  1.65.2.2  martin 	param->command_flags = IXL_AQ_NVM_LAST_CMD;
   6981  1.65.2.2  martin 	param->module_pointer = 0;
   6982  1.65.2.2  martin 	param->length = htole16(len);
   6983  1.65.2.2  martin 	offset_bytes = (uint32_t)offset_word * 2;
   6984  1.65.2.2  martin 	offset_bytes &= 0x00FFFFFF;
   6985  1.65.2.2  martin 	param->offset = htole32(offset_bytes);
   6986  1.65.2.2  martin 
   6987  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0, IXL_DMA_LEN(idm),
   6988  1.65.2.2  martin 	    BUS_DMASYNC_PREREAD);
   6989  1.65.2.2  martin 
   6990  1.65.2.2  martin 	rv = ixl_atq_poll(sc, &iaq, 250);
   6991  1.65.2.2  martin 
   6992  1.65.2.2  martin 	bus_dmamap_sync(sc->sc_dmat, IXL_DMA_MAP(idm), 0, IXL_DMA_LEN(idm),
   6993  1.65.2.2  martin 	    BUS_DMASYNC_POSTREAD);
   6994  1.65.2.2  martin 
   6995  1.65.2.2  martin 	if (rv != 0) {
   6996  1.65.2.2  martin 		return ETIMEDOUT;
   6997  1.65.2.2  martin 	}
   6998  1.65.2.2  martin 
   6999  1.65.2.2  martin 	switch (le16toh(iaq.iaq_retval)) {
   7000  1.65.2.2  martin 	case IXL_AQ_RC_OK:
   7001  1.65.2.2  martin 		break;
   7002  1.65.2.2  martin 	case IXL_AQ_RC_EPERM:
   7003  1.65.2.2  martin 		return EPERM;
   7004  1.65.2.2  martin 	case IXL_AQ_RC_EINVAL:
   7005  1.65.2.2  martin 		return EINVAL;
   7006  1.65.2.2  martin 	case IXL_AQ_RC_EBUSY:
   7007  1.65.2.2  martin 		return EBUSY;
   7008  1.65.2.2  martin 	case IXL_AQ_RC_EIO:
   7009  1.65.2.2  martin 	default:
   7010  1.65.2.2  martin 		return EIO;
   7011  1.65.2.2  martin 	}
   7012  1.65.2.2  martin 
   7013  1.65.2.2  martin 	memcpy(data, IXL_DMA_KVA(idm), len);
   7014  1.65.2.2  martin 
   7015  1.65.2.2  martin 	return 0;
   7016  1.65.2.2  martin }
   7017  1.65.2.2  martin 
   7018  1.65.2.2  martin static int
   7019  1.65.2.2  martin ixl_rd16_nvm(struct ixl_softc *sc, uint16_t offset, uint16_t *data)
   7020  1.65.2.2  martin {
   7021  1.65.2.2  martin 	int error;
   7022  1.65.2.2  martin 	uint16_t buf;
   7023  1.65.2.2  martin 
   7024  1.65.2.2  martin 	error = ixl_nvm_lock(sc, 'R');
   7025  1.65.2.2  martin 	if (error)
   7026  1.65.2.2  martin 		return error;
   7027  1.65.2.2  martin 
   7028  1.65.2.2  martin 	if (ISSET(sc->sc_aq_flags, IXL_SC_AQ_FLAG_NVMREAD)) {
   7029  1.65.2.2  martin 		error = ixl_nvm_read_aq(sc, offset,
   7030  1.65.2.2  martin 		    &buf, sizeof(buf));
   7031  1.65.2.2  martin 		if (error == 0)
   7032  1.65.2.2  martin 			*data = le16toh(buf);
   7033  1.65.2.2  martin 	} else {
   7034  1.65.2.2  martin 		error = ixl_nvm_read_srctl(sc, offset, &buf);
   7035  1.65.2.2  martin 		if (error == 0)
   7036  1.65.2.2  martin 			*data = buf;
   7037  1.65.2.2  martin 	}
   7038  1.65.2.2  martin 
   7039  1.65.2.2  martin 	ixl_nvm_unlock(sc);
   7040  1.65.2.2  martin 
   7041  1.65.2.2  martin 	return error;
   7042  1.65.2.2  martin }
   7043  1.65.2.2  martin 
   7044  1.65.2.2  martin MODULE(MODULE_CLASS_DRIVER, if_ixl, "pci");
   7045  1.65.2.2  martin 
   7046  1.65.2.2  martin #ifdef _MODULE
   7047  1.65.2.2  martin #include "ioconf.c"
   7048  1.65.2.2  martin #endif
   7049  1.65.2.2  martin 
   7050  1.65.2.2  martin #ifdef _MODULE
   7051  1.65.2.2  martin static void
   7052  1.65.2.2  martin ixl_parse_modprop(prop_dictionary_t dict)
   7053  1.65.2.2  martin {
   7054  1.65.2.2  martin 	prop_object_t obj;
   7055  1.65.2.2  martin 	int64_t val;
   7056  1.65.2.2  martin 	uint64_t uval;
   7057  1.65.2.2  martin 
   7058  1.65.2.2  martin 	if (dict == NULL)
   7059  1.65.2.2  martin 		return;
   7060  1.65.2.2  martin 
   7061  1.65.2.2  martin 	obj = prop_dictionary_get(dict, "nomsix");
   7062  1.65.2.2  martin 	if (obj != NULL && prop_object_type(obj) == PROP_TYPE_BOOL) {
   7063  1.65.2.2  martin 		ixl_param_nomsix = prop_bool_true((prop_bool_t)obj);
   7064  1.65.2.2  martin 	}
   7065  1.65.2.2  martin 
   7066  1.65.2.2  martin 	obj = prop_dictionary_get(dict, "stats_interval");
   7067  1.65.2.2  martin 	if (obj != NULL && prop_object_type(obj) == PROP_TYPE_NUMBER) {
   7068  1.65.2.2  martin 		val = prop_number_integer_value((prop_number_t)obj);
   7069  1.65.2.2  martin 
   7070  1.65.2.2  martin 		/* the range has no reason */
   7071  1.65.2.2  martin 		if (100 < val && val < 180000) {
   7072  1.65.2.2  martin 			ixl_param_stats_interval = val;
   7073  1.65.2.2  martin 		}
   7074  1.65.2.2  martin 	}
   7075  1.65.2.2  martin 
   7076  1.65.2.2  martin 	obj = prop_dictionary_get(dict, "nqps_limit");
   7077  1.65.2.2  martin 	if (obj != NULL && prop_object_type(obj) == PROP_TYPE_NUMBER) {
   7078  1.65.2.2  martin 		val = prop_number_integer_value((prop_number_t)obj);
   7079  1.65.2.2  martin 
   7080  1.65.2.2  martin 		if (val <= INT32_MAX)
   7081  1.65.2.2  martin 			ixl_param_nqps_limit = val;
   7082  1.65.2.2  martin 	}
   7083  1.65.2.2  martin 
   7084  1.65.2.2  martin 	obj = prop_dictionary_get(dict, "rx_ndescs");
   7085  1.65.2.2  martin 	if (obj != NULL && prop_object_type(obj) == PROP_TYPE_NUMBER) {
   7086  1.65.2.2  martin 		uval = prop_number_unsigned_integer_value((prop_number_t)obj);
   7087  1.65.2.2  martin 
   7088  1.65.2.2  martin 		if (uval > 8)
   7089  1.65.2.2  martin 			ixl_param_rx_ndescs = uval;
   7090  1.65.2.2  martin 	}
   7091  1.65.2.2  martin 
   7092  1.65.2.2  martin 	obj = prop_dictionary_get(dict, "tx_ndescs");
   7093  1.65.2.2  martin 	if (obj != NULL && prop_object_type(obj) == PROP_TYPE_NUMBER) {
   7094  1.65.2.2  martin 		uval = prop_number_unsigned_integer_value((prop_number_t)obj);
   7095  1.65.2.2  martin 
   7096  1.65.2.2  martin 		if (uval > IXL_TX_PKT_DESCS)
   7097  1.65.2.2  martin 			ixl_param_tx_ndescs = uval;
   7098  1.65.2.2  martin 	}
   7099  1.65.2.2  martin 
   7100  1.65.2.2  martin }
   7101  1.65.2.2  martin #endif
   7102  1.65.2.2  martin 
   7103  1.65.2.2  martin static int
   7104  1.65.2.2  martin if_ixl_modcmd(modcmd_t cmd, void *opaque)
   7105  1.65.2.2  martin {
   7106  1.65.2.2  martin 	int error = 0;
   7107  1.65.2.2  martin 
   7108  1.65.2.2  martin #ifdef _MODULE
   7109  1.65.2.2  martin 	switch (cmd) {
   7110  1.65.2.2  martin 	case MODULE_CMD_INIT:
   7111  1.65.2.2  martin 		ixl_parse_modprop((prop_dictionary_t)opaque);
   7112  1.65.2.2  martin 		error = config_init_component(cfdriver_ioconf_if_ixl,
   7113  1.65.2.2  martin 		    cfattach_ioconf_if_ixl, cfdata_ioconf_if_ixl);
   7114  1.65.2.2  martin 		break;
   7115  1.65.2.2  martin 	case MODULE_CMD_FINI:
   7116  1.65.2.2  martin 		error = config_fini_component(cfdriver_ioconf_if_ixl,
   7117  1.65.2.2  martin 		    cfattach_ioconf_if_ixl, cfdata_ioconf_if_ixl);
   7118  1.65.2.2  martin 		break;
   7119  1.65.2.2  martin 	default:
   7120  1.65.2.2  martin 		error = ENOTTY;
   7121  1.65.2.2  martin 		break;
   7122  1.65.2.2  martin 	}
   7123  1.65.2.2  martin #endif
   7124  1.65.2.2  martin 
   7125  1.65.2.2  martin 	return error;
   7126  1.65.2.2  martin }
   7127