Deleted Added
full compact
if_ixv.c (302408) if_ixv.c (320897)
1/******************************************************************************
2
1/******************************************************************************
2
3 Copyright (c) 2001-2015, Intel Corporation
3 Copyright (c) 2001-2017, Intel Corporation
4 All rights reserved.
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
7 modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
8
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
10 this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
11
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
14 documentation and/or other materials provided with the distribution.
15
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
15
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
18 this software without specific prior written permission.
19
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32******************************************************************************/
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32******************************************************************************/
33/*$FreeBSD: stable/11/sys/dev/ixgbe/if_ixv.c 302384 2016-07-07 03:39:18Z sbruno $*/
33/*$FreeBSD: stable/11/sys/dev/ixgbe/if_ixv.c 320897 2017-07-11 21:25:07Z erj $*/
34
35
36#ifndef IXGBE_STANDALONE_BUILD
37#include "opt_inet.h"
38#include "opt_inet6.h"
39#endif
40
41#include "ixgbe.h"
42
34
35
36#ifndef IXGBE_STANDALONE_BUILD
37#include "opt_inet.h"
38#include "opt_inet6.h"
39#endif
40
41#include "ixgbe.h"
42
43/*********************************************************************
44 * Driver version
45 *********************************************************************/
46char ixv_driver_version[] = "1.4.6-k";
43/************************************************************************
44 * Driver version
45 ************************************************************************/
46char ixv_driver_version[] = "1.5.13-k";
47
47
48/*********************************************************************
49 * PCI Device ID Table
48/************************************************************************
49 * PCI Device ID Table
50 *
50 *
51 * Used by probe to select devices to load on
52 * Last field stores an index into ixv_strings
53 * Last entry must be all 0s
51 * Used by probe to select devices to load on
52 * Last field stores an index into ixv_strings
53 * Last entry must be all 0s
54 *
54 *
55 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
56 *********************************************************************/
57
55 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
56 ************************************************************************/
58static ixgbe_vendor_info_t ixv_vendor_info_array[] =
59{
60 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF, 0, 0, 0},
61 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF, 0, 0, 0},
62 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF, 0, 0, 0},
63 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF, 0, 0, 0},
57static ixgbe_vendor_info_t ixv_vendor_info_array[] =
58{
59 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF, 0, 0, 0},
60 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF, 0, 0, 0},
61 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF, 0, 0, 0},
62 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF, 0, 0, 0},
63 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF, 0, 0, 0},
64 /* required last entry */
65 {0, 0, 0, 0, 0}
66};
67
64 /* required last entry */
65 {0, 0, 0, 0, 0}
66};
67
68/*********************************************************************
69 * Table of branding strings
70 *********************************************************************/
71
72static char *ixv_strings[] = {
68/************************************************************************
69 * Table of branding strings
70 ************************************************************************/
71static char *ixv_strings[] = {
73 "Intel(R) PRO/10GbE Virtual Function Network Driver"
74};
75
72 "Intel(R) PRO/10GbE Virtual Function Network Driver"
73};
74
76/*********************************************************************
77 * Function prototypes
78 *********************************************************************/
75/************************************************************************
76 * Function prototypes
77 ************************************************************************/
79static int ixv_probe(device_t);
80static int ixv_attach(device_t);
81static int ixv_detach(device_t);
82static int ixv_shutdown(device_t);
83static int ixv_ioctl(struct ifnet *, u_long, caddr_t);
78static int ixv_probe(device_t);
79static int ixv_attach(device_t);
80static int ixv_detach(device_t);
81static int ixv_shutdown(device_t);
82static int ixv_ioctl(struct ifnet *, u_long, caddr_t);
84static void ixv_init(void *);
85static void ixv_init_locked(struct adapter *);
83static void ixv_init(void *);
84static void ixv_init_locked(struct adapter *);
86static void ixv_stop(void *);
85static void ixv_stop(void *);
86static uint64_t ixv_get_counter(struct ifnet *, ift_counter);
87static void ixv_init_device_features(struct adapter *);
87static void ixv_media_status(struct ifnet *, struct ifmediareq *);
88static int ixv_media_change(struct ifnet *);
88static void ixv_media_status(struct ifnet *, struct ifmediareq *);
89static int ixv_media_change(struct ifnet *);
89static void ixv_identify_hardware(struct adapter *);
90static int ixv_allocate_pci_resources(struct adapter *);
91static int ixv_allocate_msix(struct adapter *);
90static int ixv_allocate_pci_resources(struct adapter *);
91static int ixv_allocate_msix(struct adapter *);
92static int ixv_setup_msix(struct adapter *);
93static void ixv_free_pci_resources(struct adapter *);
92static int ixv_configure_interrupts(struct adapter *);
93static void ixv_free_pci_resources(struct adapter *);
94static void ixv_local_timer(void *);
95static void ixv_setup_interface(device_t, struct adapter *);
94static void ixv_local_timer(void *);
95static void ixv_setup_interface(device_t, struct adapter *);
96static void ixv_config_link(struct adapter *);
97
98static void ixv_initialize_transmit_units(struct adapter *);
99static void ixv_initialize_receive_units(struct adapter *);
96
97static void ixv_initialize_transmit_units(struct adapter *);
98static void ixv_initialize_receive_units(struct adapter *);
99static void ixv_initialize_rss_mapping(struct adapter *);
100static void ixv_check_link(struct adapter *);
100
101static void ixv_enable_intr(struct adapter *);
102static void ixv_disable_intr(struct adapter *);
103static void ixv_set_multi(struct adapter *);
104static void ixv_update_link_status(struct adapter *);
101
102static void ixv_enable_intr(struct adapter *);
103static void ixv_disable_intr(struct adapter *);
104static void ixv_set_multi(struct adapter *);
105static void ixv_update_link_status(struct adapter *);
105static int ixv_sysctl_debug(SYSCTL_HANDLER_ARGS);
106static void ixv_set_ivar(struct adapter *, u8, u8, s8);
107static void ixv_configure_ivars(struct adapter *);
108static u8 * ixv_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
106static int ixv_sysctl_debug(SYSCTL_HANDLER_ARGS);
107static void ixv_set_ivar(struct adapter *, u8, u8, s8);
108static void ixv_configure_ivars(struct adapter *);
109static u8 *ixv_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
109
110
110static void ixv_setup_vlan_support(struct adapter *);
111static void ixv_register_vlan(void *, struct ifnet *, u16);
112static void ixv_unregister_vlan(void *, struct ifnet *, u16);
111static void ixv_setup_vlan_support(struct adapter *);
112static void ixv_register_vlan(void *, struct ifnet *, u16);
113static void ixv_unregister_vlan(void *, struct ifnet *, u16);
113
114
114static void ixv_save_stats(struct adapter *);
115static void ixv_init_stats(struct adapter *);
116static void ixv_update_stats(struct adapter *);
117static void ixv_add_stats_sysctls(struct adapter *);
118static void ixv_set_sysctl_value(struct adapter *, const char *,
119 const char *, int *, int);
115static void ixv_save_stats(struct adapter *);
116static void ixv_init_stats(struct adapter *);
117static void ixv_update_stats(struct adapter *);
118static void ixv_add_stats_sysctls(struct adapter *);
119static void ixv_set_sysctl_value(struct adapter *, const char *,
120 const char *, int *, int);
120
121
121/* The MSI/X Interrupt handlers */
122static void ixv_msix_que(void *);
123static void ixv_msix_mbx(void *);
122/* The MSI-X Interrupt handlers */
123static void ixv_msix_que(void *);
124static void ixv_msix_mbx(void *);
124
125/* Deferred interrupt tasklets */
125
126/* Deferred interrupt tasklets */
126static void ixv_handle_que(void *, int);
127static void ixv_handle_mbx(void *, int);
127static void ixv_handle_que(void *, int);
128static void ixv_handle_link(void *, int);
128
129
129#ifdef DEV_NETMAP
130/*
131 * This is defined in <dev/netmap/ixgbe_netmap.h>, which is included by
132 * if_ix.c.
133 */
134extern void ixgbe_netmap_attach(struct adapter *adapter);
135
136#include <net/netmap.h>
137#include <sys/selinfo.h>
138#include <dev/netmap/netmap_kern.h>
139#endif /* DEV_NETMAP */
140
141/*********************************************************************
142 * FreeBSD Device Interface Entry Points
143 *********************************************************************/
144
130/************************************************************************
131 * FreeBSD Device Interface Entry Points
132 ************************************************************************/
145static device_method_t ixv_methods[] = {
146 /* Device interface */
147 DEVMETHOD(device_probe, ixv_probe),
148 DEVMETHOD(device_attach, ixv_attach),
149 DEVMETHOD(device_detach, ixv_detach),
150 DEVMETHOD(device_shutdown, ixv_shutdown),
151 DEVMETHOD_END
152};
153
154static driver_t ixv_driver = {
155 "ixv", ixv_methods, sizeof(struct adapter),
156};
157
158devclass_t ixv_devclass;
159DRIVER_MODULE(ixv, pci, ixv_driver, ixv_devclass, 0, 0);
160MODULE_DEPEND(ixv, pci, 1, 1, 1);
161MODULE_DEPEND(ixv, ether, 1, 1, 1);
133static device_method_t ixv_methods[] = {
134 /* Device interface */
135 DEVMETHOD(device_probe, ixv_probe),
136 DEVMETHOD(device_attach, ixv_attach),
137 DEVMETHOD(device_detach, ixv_detach),
138 DEVMETHOD(device_shutdown, ixv_shutdown),
139 DEVMETHOD_END
140};
141
142static driver_t ixv_driver = {
143 "ixv", ixv_methods, sizeof(struct adapter),
144};
145
146devclass_t ixv_devclass;
147DRIVER_MODULE(ixv, pci, ixv_driver, ixv_devclass, 0, 0);
148MODULE_DEPEND(ixv, pci, 1, 1, 1);
149MODULE_DEPEND(ixv, ether, 1, 1, 1);
162#ifdef DEV_NETMAP
163MODULE_DEPEND(ix, netmap, 1, 1, 1);
164#endif /* DEV_NETMAP */
165/* XXX depend on 'ix' ? */
150MODULE_DEPEND(ixv, netmap, 1, 1, 1);
166
167/*
151
152/*
168** TUNEABLE PARAMETERS:
169*/
153 * TUNEABLE PARAMETERS:
154 */
170
155
171/* Number of Queues - do not exceed MSIX vectors - 1 */
156/* Number of Queues - do not exceed MSI-X vectors - 1 */
172static int ixv_num_queues = 1;
173TUNABLE_INT("hw.ixv.num_queues", &ixv_num_queues);
174
175/*
157static int ixv_num_queues = 1;
158TUNABLE_INT("hw.ixv.num_queues", &ixv_num_queues);
159
160/*
176** AIM: Adaptive Interrupt Moderation
177** which means that the interrupt rate
178** is varied over time based on the
179** traffic for that interrupt vector
180*/
161 * AIM: Adaptive Interrupt Moderation
162 * which means that the interrupt rate
163 * is varied over time based on the
164 * traffic for that interrupt vector
165 */
181static int ixv_enable_aim = FALSE;
182TUNABLE_INT("hw.ixv.enable_aim", &ixv_enable_aim);
183
184/* How many packets rxeof tries to clean at a time */
185static int ixv_rx_process_limit = 256;
186TUNABLE_INT("hw.ixv.rx_process_limit", &ixv_rx_process_limit);
187
188/* How many packets txeof tries to clean at a time */

--- 9 unchanged lines hidden (view full) ---

198 * the header into a separate mbuf from the payload,
199 * it can be a performance win in some workloads, but
200 * in others it actually hurts, its off by default.
201 */
202static int ixv_header_split = FALSE;
203TUNABLE_INT("hw.ixv.hdr_split", &ixv_header_split);
204
205/*
166static int ixv_enable_aim = FALSE;
167TUNABLE_INT("hw.ixv.enable_aim", &ixv_enable_aim);
168
169/* How many packets rxeof tries to clean at a time */
170static int ixv_rx_process_limit = 256;
171TUNABLE_INT("hw.ixv.rx_process_limit", &ixv_rx_process_limit);
172
173/* How many packets txeof tries to clean at a time */

--- 9 unchanged lines hidden (view full) ---

183 * the header into a separate mbuf from the payload,
184 * it can be a performance win in some workloads, but
185 * in others it actually hurts, its off by default.
186 */
187static int ixv_header_split = FALSE;
188TUNABLE_INT("hw.ixv.hdr_split", &ixv_header_split);
189
190/*
206** Number of TX descriptors per ring,
207** setting higher than RX as this seems
208** the better performing choice.
209*/
191 * Number of TX descriptors per ring,
192 * setting higher than RX as this seems
193 * the better performing choice.
194 */
210static int ixv_txd = DEFAULT_TXD;
211TUNABLE_INT("hw.ixv.txd", &ixv_txd);
212
213/* Number of RX descriptors per ring */
214static int ixv_rxd = DEFAULT_RXD;
215TUNABLE_INT("hw.ixv.rxd", &ixv_rxd);
216
195static int ixv_txd = DEFAULT_TXD;
196TUNABLE_INT("hw.ixv.txd", &ixv_txd);
197
198/* Number of RX descriptors per ring */
199static int ixv_rxd = DEFAULT_RXD;
200TUNABLE_INT("hw.ixv.rxd", &ixv_rxd);
201
202/* Legacy Transmit (single queue) */
203static int ixv_enable_legacy_tx = 0;
204TUNABLE_INT("hw.ixv.enable_legacy_tx", &ixv_enable_legacy_tx);
205
217/*
206/*
218** Shadow VFTA table, this is needed because
219** the real filter table gets cleared during
220** a soft reset and we need to repopulate it.
221*/
207 * Shadow VFTA table, this is needed because
208 * the real filter table gets cleared during
209 * a soft reset and we need to repopulate it.
210 */
222static u32 ixv_shadow_vfta[IXGBE_VFTA_SIZE];
223
211static u32 ixv_shadow_vfta[IXGBE_VFTA_SIZE];
212
224/*********************************************************************
225 * Device identification routine
213static int (*ixv_start_locked)(struct ifnet *, struct tx_ring *);
214static int (*ixv_ring_empty)(struct ifnet *, struct buf_ring *);
215
216/************************************************************************
217 * ixv_probe - Device identification routine
226 *
218 *
227 * ixv_probe determines if the driver should be loaded on
228 * adapter based on PCI vendor/device id of the adapter.
219 * Determines if the driver should be loaded on
220 * adapter based on its PCI vendor/device ID.
229 *
221 *
230 * return BUS_PROBE_DEFAULT on success, positive on failure
231 *********************************************************************/
232
222 * return BUS_PROBE_DEFAULT on success, positive on failure
223 ************************************************************************/
233static int
234ixv_probe(device_t dev)
235{
236 ixgbe_vendor_info_t *ent;
224static int
225ixv_probe(device_t dev)
226{
227 ixgbe_vendor_info_t *ent;
228 u16 pci_vendor_id = 0;
229 u16 pci_device_id = 0;
230 u16 pci_subvendor_id = 0;
231 u16 pci_subdevice_id = 0;
232 char adapter_name[256];
237
233
238 u16 pci_vendor_id = 0;
239 u16 pci_device_id = 0;
240 u16 pci_subvendor_id = 0;
241 u16 pci_subdevice_id = 0;
242 char adapter_name[256];
243
234
244
245 pci_vendor_id = pci_get_vendor(dev);
246 if (pci_vendor_id != IXGBE_INTEL_VENDOR_ID)
247 return (ENXIO);
248
249 pci_device_id = pci_get_device(dev);
250 pci_subvendor_id = pci_get_subvendor(dev);
251 pci_subdevice_id = pci_get_subdevice(dev);
252
253 ent = ixv_vendor_info_array;
254 while (ent->vendor_id != 0) {
255 if ((pci_vendor_id == ent->vendor_id) &&
256 (pci_device_id == ent->device_id) &&
235 pci_vendor_id = pci_get_vendor(dev);
236 if (pci_vendor_id != IXGBE_INTEL_VENDOR_ID)
237 return (ENXIO);
238
239 pci_device_id = pci_get_device(dev);
240 pci_subvendor_id = pci_get_subvendor(dev);
241 pci_subdevice_id = pci_get_subdevice(dev);
242
243 ent = ixv_vendor_info_array;
244 while (ent->vendor_id != 0) {
245 if ((pci_vendor_id == ent->vendor_id) &&
246 (pci_device_id == ent->device_id) &&
257
258 ((pci_subvendor_id == ent->subvendor_id) ||
259 (ent->subvendor_id == 0)) &&
247 ((pci_subvendor_id == ent->subvendor_id) ||
248 (ent->subvendor_id == 0)) &&
260
261 ((pci_subdevice_id == ent->subdevice_id) ||
262 (ent->subdevice_id == 0))) {
263 sprintf(adapter_name, "%s, Version - %s",
249 ((pci_subdevice_id == ent->subdevice_id) ||
250 (ent->subdevice_id == 0))) {
251 sprintf(adapter_name, "%s, Version - %s",
264 ixv_strings[ent->index],
265 ixv_driver_version);
252 ixv_strings[ent->index], ixv_driver_version);
266 device_set_desc_copy(dev, adapter_name);
267 return (BUS_PROBE_DEFAULT);
268 }
269 ent++;
270 }
253 device_set_desc_copy(dev, adapter_name);
254 return (BUS_PROBE_DEFAULT);
255 }
256 ent++;
257 }
258
271 return (ENXIO);
259 return (ENXIO);
272}
260} /* ixv_probe */
273
261
274/*********************************************************************
275 * Device initialization routine
262/************************************************************************
263 * ixv_attach - Device initialization routine
276 *
264 *
277 * The attach entry point is called when the driver is being loaded.
278 * This routine identifies the type of hardware, allocates all resources
279 * and initializes the hardware.
265 * Called when the driver is being loaded.
266 * Identifies the type of hardware, allocates all resources
267 * and initializes the hardware.
280 *
268 *
281 * return 0 on success, positive on failure
282 *********************************************************************/
283
269 * return 0 on success, positive on failure
270 ************************************************************************/
284static int
285ixv_attach(device_t dev)
286{
271static int
272ixv_attach(device_t dev)
273{
287 struct adapter *adapter;
274 struct adapter *adapter;
288 struct ixgbe_hw *hw;
289 int error = 0;
290
291 INIT_DEBUGOUT("ixv_attach: begin");
292
275 struct ixgbe_hw *hw;
276 int error = 0;
277
278 INIT_DEBUGOUT("ixv_attach: begin");
279
280 /*
281 * Make sure BUSMASTER is set, on a VM under
282 * KVM it may not be and will break things.
283 */
284 pci_enable_busmaster(dev);
285
293 /* Allocate, clear, and link in our adapter structure */
294 adapter = device_get_softc(dev);
295 adapter->dev = dev;
286 /* Allocate, clear, and link in our adapter structure */
287 adapter = device_get_softc(dev);
288 adapter->dev = dev;
289 adapter->hw.back = adapter;
296 hw = &adapter->hw;
297
290 hw = &adapter->hw;
291
298#ifdef DEV_NETMAP
299 adapter->init_locked = ixv_init_locked;
300 adapter->stop_locked = ixv_stop;
292 adapter->init_locked = ixv_init_locked;
293 adapter->stop_locked = ixv_stop;
301#endif
302
303 /* Core Lock Init*/
304 IXGBE_CORE_LOCK_INIT(adapter, device_get_nameunit(dev));
305
294
295 /* Core Lock Init*/
296 IXGBE_CORE_LOCK_INIT(adapter, device_get_nameunit(dev));
297
298 /* Do base PCI setup - map BAR0 */
299 if (ixv_allocate_pci_resources(adapter)) {
300 device_printf(dev, "ixv_allocate_pci_resources() failed!\n");
301 error = ENXIO;
302 goto err_out;
303 }
304
306 /* SYSCTL APIs */
307 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
305 /* SYSCTL APIs */
306 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
308 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
309 OID_AUTO, "debug", CTLTYPE_INT | CTLFLAG_RW,
310 adapter, 0, ixv_sysctl_debug, "I", "Debug Info");
307 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "debug",
308 CTLTYPE_INT | CTLFLAG_RW, adapter, 0, ixv_sysctl_debug, "I",
309 "Debug Info");
311
312 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
310
311 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
313 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
314 OID_AUTO, "enable_aim", CTLFLAG_RW,
315 &ixv_enable_aim, 1, "Interrupt Moderation");
312 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
313 "enable_aim", CTLFLAG_RW, &ixv_enable_aim, 1,
314 "Interrupt Moderation");
316
317 /* Set up the timer callout */
318 callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
319
315
316 /* Set up the timer callout */
317 callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
318
320 /* Determine hardware revision */
321 ixv_identify_hardware(adapter);
319 /* Save off the information about this board */
320 hw->vendor_id = pci_get_vendor(dev);
321 hw->device_id = pci_get_device(dev);
322 hw->revision_id = pci_get_revid(dev);
323 hw->subsystem_vendor_id = pci_get_subvendor(dev);
324 hw->subsystem_device_id = pci_get_subdevice(dev);
322
325
323 /* Do base PCI setup - map BAR0 */
324 if (ixv_allocate_pci_resources(adapter)) {
325 device_printf(dev, "ixv_allocate_pci_resources() failed!\n");
326 /* A subset of set_mac_type */
327 switch (hw->device_id) {
328 case IXGBE_DEV_ID_82599_VF:
329 hw->mac.type = ixgbe_mac_82599_vf;
330 break;
331 case IXGBE_DEV_ID_X540_VF:
332 hw->mac.type = ixgbe_mac_X540_vf;
333 break;
334 case IXGBE_DEV_ID_X550_VF:
335 hw->mac.type = ixgbe_mac_X550_vf;
336 break;
337 case IXGBE_DEV_ID_X550EM_X_VF:
338 hw->mac.type = ixgbe_mac_X550EM_x_vf;
339 break;
340 case IXGBE_DEV_ID_X550EM_A_VF:
341 hw->mac.type = ixgbe_mac_X550EM_a_vf;
342 break;
343 default:
344 /* Shouldn't get here since probe succeeded */
345 device_printf(dev, "Unknown device ID!\n");
326 error = ENXIO;
327 goto err_out;
346 error = ENXIO;
347 goto err_out;
348 break;
328 }
329
349 }
350
351 ixv_init_device_features(adapter);
352
353 /* Initialize the shared code */
354 error = ixgbe_init_ops_vf(hw);
355 if (error) {
356 device_printf(dev, "ixgbe_init_ops_vf() failed!\n");
357 error = EIO;
358 goto err_out;
359 }
360
361 /* Setup the mailbox */
362 ixgbe_init_mbx_params_vf(hw);
363
364 /* Set the right number of segments */
365 adapter->num_segs = IXGBE_82599_SCATTER;
366
367 error = hw->mac.ops.reset_hw(hw);
368 if (error == IXGBE_ERR_RESET_FAILED)
369 device_printf(dev, "...reset_hw() failure: Reset Failed!\n");
370 else if (error)
371 device_printf(dev, "...reset_hw() failed with error %d\n",
372 error);
373 if (error) {
374 error = EIO;
375 goto err_out;
376 }
377
378 error = hw->mac.ops.init_hw(hw);
379 if (error) {
380 device_printf(dev, "...init_hw() failed with error %d\n",
381 error);
382 error = EIO;
383 goto err_out;
384 }
385
386 /* Negotiate mailbox API version */
387 error = ixgbevf_negotiate_api_version(hw, ixgbe_mbox_api_12);
388 if (error) {
389 device_printf(dev, "MBX API 1.2 negotiation failed! Error %d\n",
390 error);
391 error = EIO;
392 goto err_out;
393 }
394
395 /* If no mac address was assigned, make a random one */
396 if (!ixv_check_ether_addr(hw->mac.addr)) {
397 u8 addr[ETHER_ADDR_LEN];
398 arc4rand(&addr, sizeof(addr), 0);
399 addr[0] &= 0xFE;
400 addr[0] |= 0x02;
401 bcopy(addr, hw->mac.addr, sizeof(addr));
402 bcopy(addr, hw->mac.perm_addr, sizeof(addr));
403 }
404
405 /* Register for VLAN events */
406 adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
407 ixv_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
408 adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
409 ixv_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
410
330 /* Sysctls for limiting the amount of work done in the taskqueues */
331 ixv_set_sysctl_value(adapter, "rx_processing_limit",
332 "max number of rx packets to process",
333 &adapter->rx_process_limit, ixv_rx_process_limit);
334
335 ixv_set_sysctl_value(adapter, "tx_processing_limit",
336 "max number of tx packets to process",
337 &adapter->tx_process_limit, ixv_tx_process_limit);

--- 8 unchanged lines hidden (view full) ---

346
347 if (((ixv_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
348 ixv_rxd < MIN_RXD || ixv_rxd > MAX_RXD) {
349 device_printf(dev, "RXD config issue, using default!\n");
350 adapter->num_rx_desc = DEFAULT_RXD;
351 } else
352 adapter->num_rx_desc = ixv_rxd;
353
411 /* Sysctls for limiting the amount of work done in the taskqueues */
412 ixv_set_sysctl_value(adapter, "rx_processing_limit",
413 "max number of rx packets to process",
414 &adapter->rx_process_limit, ixv_rx_process_limit);
415
416 ixv_set_sysctl_value(adapter, "tx_processing_limit",
417 "max number of tx packets to process",
418 &adapter->tx_process_limit, ixv_tx_process_limit);

--- 8 unchanged lines hidden (view full) ---

427
428 if (((ixv_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
429 ixv_rxd < MIN_RXD || ixv_rxd > MAX_RXD) {
430 device_printf(dev, "RXD config issue, using default!\n");
431 adapter->num_rx_desc = DEFAULT_RXD;
432 } else
433 adapter->num_rx_desc = ixv_rxd;
434
435 /* Setup MSI-X */
436 error = ixv_configure_interrupts(adapter);
437 if (error)
438 goto err_out;
439
354 /* Allocate our TX/RX Queues */
355 if (ixgbe_allocate_queues(adapter)) {
356 device_printf(dev, "ixgbe_allocate_queues() failed!\n");
357 error = ENOMEM;
358 goto err_out;
359 }
360
440 /* Allocate our TX/RX Queues */
441 if (ixgbe_allocate_queues(adapter)) {
442 device_printf(dev, "ixgbe_allocate_queues() failed!\n");
443 error = ENOMEM;
444 goto err_out;
445 }
446
361 /*
362 ** Initialize the shared code: its
363 ** at this point the mac type is set.
364 */
365 error = ixgbe_init_shared_code(hw);
366 if (error) {
367 device_printf(dev, "ixgbe_init_shared_code() failed!\n");
368 error = EIO;
369 goto err_late;
370 }
447 /* Setup OS specific network interface */
448 ixv_setup_interface(dev, adapter);
371
449
372 /* Setup the mailbox */
373 ixgbe_init_mbx_params_vf(hw);
374
375 /* Reset mbox api to 1.0 */
376 error = ixgbe_reset_hw(hw);
377 if (error == IXGBE_ERR_RESET_FAILED)
378 device_printf(dev, "ixgbe_reset_hw() failure: Reset Failed!\n");
379 else if (error)
380 device_printf(dev, "ixgbe_reset_hw() failed with error %d\n", error);
450 error = ixv_allocate_msix(adapter);
381 if (error) {
451 if (error) {
382 error = EIO;
383 goto err_late;
384 }
385
386 /* Negotiate mailbox API version */
387 error = ixgbevf_negotiate_api_version(hw, ixgbe_mbox_api_11);
388 if (error) {
389 device_printf(dev, "MBX API 1.1 negotiation failed! Error %d\n", error);
390 error = EIO;
391 goto err_late;
392 }
393
394 error = ixgbe_init_hw(hw);
395 if (error) {
396 device_printf(dev, "ixgbe_init_hw() failed!\n");
397 error = EIO;
398 goto err_late;
399 }
400
401 error = ixv_allocate_msix(adapter);
402 if (error) {
403 device_printf(dev, "ixv_allocate_msix() failed!\n");
404 goto err_late;
405 }
406
452 device_printf(dev, "ixv_allocate_msix() failed!\n");
453 goto err_late;
454 }
455
407 /* If no mac address was assigned, make a random one */
408 if (!ixv_check_ether_addr(hw->mac.addr)) {
409 u8 addr[ETHER_ADDR_LEN];
410 arc4rand(&addr, sizeof(addr), 0);
411 addr[0] &= 0xFE;
412 addr[0] |= 0x02;
413 bcopy(addr, hw->mac.addr, sizeof(addr));
414 }
415
416 /* Setup OS specific network interface */
417 ixv_setup_interface(dev, adapter);
418
419 /* Do the stats setup */
420 ixv_save_stats(adapter);
421 ixv_init_stats(adapter);
422 ixv_add_stats_sysctls(adapter);
423
456 /* Do the stats setup */
457 ixv_save_stats(adapter);
458 ixv_init_stats(adapter);
459 ixv_add_stats_sysctls(adapter);
460
424 /* Register for VLAN events */
425 adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
426 ixv_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
427 adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
428 ixv_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
461 if (adapter->feat_en & IXGBE_FEATURE_NETMAP)
462 ixgbe_netmap_attach(adapter);
429
463
430#ifdef DEV_NETMAP
431 ixgbe_netmap_attach(adapter);
432#endif /* DEV_NETMAP */
433 INIT_DEBUGOUT("ixv_attach: end");
464 INIT_DEBUGOUT("ixv_attach: end");
465
434 return (0);
435
436err_late:
437 ixgbe_free_transmit_structures(adapter);
438 ixgbe_free_receive_structures(adapter);
466 return (0);
467
468err_late:
469 ixgbe_free_transmit_structures(adapter);
470 ixgbe_free_receive_structures(adapter);
471 free(adapter->queues, M_DEVBUF);
439err_out:
440 ixv_free_pci_resources(adapter);
472err_out:
473 ixv_free_pci_resources(adapter);
474 IXGBE_CORE_LOCK_DESTROY(adapter);
475
441 return (error);
476 return (error);
477} /* ixv_attach */
442
478
443}
444
445/*********************************************************************
446 * Device removal routine
479/************************************************************************
480 * ixv_detach - Device removal routine
447 *
481 *
448 * The detach entry point is called when the driver is being removed.
449 * This routine stops the adapter and deallocates all the resources
450 * that were allocated for driver operation.
482 * Called when the driver is being removed.
483 * Stops the adapter and deallocates all the resources
484 * that were allocated for driver operation.
451 *
485 *
452 * return 0 on success, positive on failure
453 *********************************************************************/
454
486 * return 0 on success, positive on failure
487 ************************************************************************/
455static int
456ixv_detach(device_t dev)
457{
488static int
489ixv_detach(device_t dev)
490{
458 struct adapter *adapter = device_get_softc(dev);
491 struct adapter *adapter = device_get_softc(dev);
459 struct ix_queue *que = adapter->queues;
460
461 INIT_DEBUGOUT("ixv_detach: begin");
462
463 /* Make sure VLANS are not using driver */
464 if (adapter->ifp->if_vlantrunk != NULL) {
465 device_printf(dev, "Vlan in use, detach first\n");
466 return (EBUSY);
467 }
468
492 struct ix_queue *que = adapter->queues;
493
494 INIT_DEBUGOUT("ixv_detach: begin");
495
496 /* Make sure VLANS are not using driver */
497 if (adapter->ifp->if_vlantrunk != NULL) {
498 device_printf(dev, "Vlan in use, detach first\n");
499 return (EBUSY);
500 }
501
502 ether_ifdetach(adapter->ifp);
469 IXGBE_CORE_LOCK(adapter);
470 ixv_stop(adapter);
471 IXGBE_CORE_UNLOCK(adapter);
472
473 for (int i = 0; i < adapter->num_queues; i++, que++) {
474 if (que->tq) {
475 struct tx_ring *txr = que->txr;
476 taskqueue_drain(que->tq, &txr->txq_task);

--- 9 unchanged lines hidden (view full) ---

486 }
487
488 /* Unregister VLAN events */
489 if (adapter->vlan_attach != NULL)
490 EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
491 if (adapter->vlan_detach != NULL)
492 EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
493
503 IXGBE_CORE_LOCK(adapter);
504 ixv_stop(adapter);
505 IXGBE_CORE_UNLOCK(adapter);
506
507 for (int i = 0; i < adapter->num_queues; i++, que++) {
508 if (que->tq) {
509 struct tx_ring *txr = que->txr;
510 taskqueue_drain(que->tq, &txr->txq_task);

--- 9 unchanged lines hidden (view full) ---

520 }
521
522 /* Unregister VLAN events */
523 if (adapter->vlan_attach != NULL)
524 EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
525 if (adapter->vlan_detach != NULL)
526 EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
527
494 ether_ifdetach(adapter->ifp);
495 callout_drain(&adapter->timer);
528 callout_drain(&adapter->timer);
496#ifdef DEV_NETMAP
497 netmap_detach(adapter->ifp);
498#endif /* DEV_NETMAP */
529
530 if (adapter->feat_en & IXGBE_FEATURE_NETMAP)
531 netmap_detach(adapter->ifp);
532
499 ixv_free_pci_resources(adapter);
500 bus_generic_detach(dev);
501 if_free(adapter->ifp);
502
503 ixgbe_free_transmit_structures(adapter);
504 ixgbe_free_receive_structures(adapter);
533 ixv_free_pci_resources(adapter);
534 bus_generic_detach(dev);
535 if_free(adapter->ifp);
536
537 ixgbe_free_transmit_structures(adapter);
538 ixgbe_free_receive_structures(adapter);
539 free(adapter->queues, M_DEVBUF);
505
506 IXGBE_CORE_LOCK_DESTROY(adapter);
540
541 IXGBE_CORE_LOCK_DESTROY(adapter);
507 return (0);
508}
509
542
510/*********************************************************************
511 *
512 * Shutdown entry point
513 *
514 **********************************************************************/
515static int
516ixv_shutdown(device_t dev)
517{
518 struct adapter *adapter = device_get_softc(dev);
519 IXGBE_CORE_LOCK(adapter);
520 ixv_stop(adapter);
521 IXGBE_CORE_UNLOCK(adapter);
522 return (0);
543 return (0);
523}
544} /* ixv_detach */
524
545
525
526/*********************************************************************
527 * Ioctl entry point
546/************************************************************************
547 * ixv_init_locked - Init entry point
528 *
548 *
529 * ixv_ioctl is called when the user wants to configure the
530 * interface.
549 * Used in two ways: It is used by the stack as an init entry
550 * point in network interface structure. It is also used
551 * by the driver as a hw/sw initialization routine to get
552 * to a consistent state.
531 *
553 *
532 * return 0 on success, positive on failure
533 **********************************************************************/
534
535static int
536ixv_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
537{
538 struct adapter *adapter = ifp->if_softc;
539 struct ifreq *ifr = (struct ifreq *) data;
540#if defined(INET) || defined(INET6)
541 struct ifaddr *ifa = (struct ifaddr *) data;
542 bool avoid_reset = FALSE;
543#endif
544 int error = 0;
545
546 switch (command) {
547
548 case SIOCSIFADDR:
549#ifdef INET
550 if (ifa->ifa_addr->sa_family == AF_INET)
551 avoid_reset = TRUE;
552#endif
553#ifdef INET6
554 if (ifa->ifa_addr->sa_family == AF_INET6)
555 avoid_reset = TRUE;
556#endif
557#if defined(INET) || defined(INET6)
558 /*
559 ** Calling init results in link renegotiation,
560 ** so we avoid doing it when possible.
561 */
562 if (avoid_reset) {
563 ifp->if_flags |= IFF_UP;
564 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
565 ixv_init(adapter);
566 if (!(ifp->if_flags & IFF_NOARP))
567 arp_ifinit(ifp, ifa);
568 } else
569 error = ether_ioctl(ifp, command, data);
570 break;
571#endif
572 case SIOCSIFMTU:
573 IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
574 if (ifr->ifr_mtu > IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR) {
575 error = EINVAL;
576 } else {
577 IXGBE_CORE_LOCK(adapter);
578 ifp->if_mtu = ifr->ifr_mtu;
579 adapter->max_frame_size =
580 ifp->if_mtu + IXGBE_MTU_HDR;
581 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
582 ixv_init_locked(adapter);
583 IXGBE_CORE_UNLOCK(adapter);
584 }
585 break;
586 case SIOCSIFFLAGS:
587 IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
588 IXGBE_CORE_LOCK(adapter);
589 if (ifp->if_flags & IFF_UP) {
590 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
591 ixv_init_locked(adapter);
592 } else
593 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
594 ixv_stop(adapter);
595 adapter->if_flags = ifp->if_flags;
596 IXGBE_CORE_UNLOCK(adapter);
597 break;
598 case SIOCADDMULTI:
599 case SIOCDELMULTI:
600 IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
601 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
602 IXGBE_CORE_LOCK(adapter);
603 ixv_disable_intr(adapter);
604 ixv_set_multi(adapter);
605 ixv_enable_intr(adapter);
606 IXGBE_CORE_UNLOCK(adapter);
607 }
608 break;
609 case SIOCSIFMEDIA:
610 case SIOCGIFMEDIA:
611 IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
612 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
613 break;
614 case SIOCSIFCAP:
615 {
616 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
617 IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
618 if (mask & IFCAP_HWCSUM)
619 ifp->if_capenable ^= IFCAP_HWCSUM;
620 if (mask & IFCAP_TSO4)
621 ifp->if_capenable ^= IFCAP_TSO4;
622 if (mask & IFCAP_LRO)
623 ifp->if_capenable ^= IFCAP_LRO;
624 if (mask & IFCAP_VLAN_HWTAGGING)
625 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
626 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
627 IXGBE_CORE_LOCK(adapter);
628 ixv_init_locked(adapter);
629 IXGBE_CORE_UNLOCK(adapter);
630 }
631 VLAN_CAPABILITIES(ifp);
632 break;
633 }
634
635 default:
636 IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
637 error = ether_ioctl(ifp, command, data);
638 break;
639 }
640
641 return (error);
642}
643
644/*********************************************************************
645 * Init entry point
646 *
647 * This routine is used in two ways. It is used by the stack as
648 * init entry point in network interface structure. It is also used
649 * by the driver as a hw/sw initialization routine to get to a
650 * consistent state.
651 *
652 * return 0 on success, positive on failure
653 **********************************************************************/
654#define IXGBE_MHADD_MFS_SHIFT 16
655
656static void
554 * return 0 on success, positive on failure
555 ************************************************************************/
556void
657ixv_init_locked(struct adapter *adapter)
658{
557ixv_init_locked(struct adapter *adapter)
558{
659 struct ifnet *ifp = adapter->ifp;
660 device_t dev = adapter->dev;
559 struct ifnet *ifp = adapter->ifp;
560 device_t dev = adapter->dev;
661 struct ixgbe_hw *hw = &adapter->hw;
561 struct ixgbe_hw *hw = &adapter->hw;
662 int error = 0;
562 int error = 0;
663
664 INIT_DEBUGOUT("ixv_init_locked: begin");
665 mtx_assert(&adapter->core_mtx, MA_OWNED);
666 hw->adapter_stopped = FALSE;
563
564 INIT_DEBUGOUT("ixv_init_locked: begin");
565 mtx_assert(&adapter->core_mtx, MA_OWNED);
566 hw->adapter_stopped = FALSE;
667 ixgbe_stop_adapter(hw);
668 callout_stop(&adapter->timer);
567 hw->mac.ops.stop_adapter(hw);
568 callout_stop(&adapter->timer);
669
569
670 /* reprogram the RAR[0] in case user changed it. */
671 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
570 /* reprogram the RAR[0] in case user changed it. */
571 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
672
673 /* Get the latest mac address, User can use a LAA */
674 bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
572
573 /* Get the latest mac address, User can use a LAA */
574 bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
675 IXGBE_ETH_LENGTH_OF_ADDRESS);
676 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
677 hw->addr_ctrl.rar_used_count = 1;
575 IXGBE_ETH_LENGTH_OF_ADDRESS);
576 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, 1);
678
679 /* Prepare transmit descriptors and buffers */
680 if (ixgbe_setup_transmit_structures(adapter)) {
681 device_printf(dev, "Could not setup transmit structures\n");
682 ixv_stop(adapter);
683 return;
684 }
685
686 /* Reset VF and renegotiate mailbox API version */
577
578 /* Prepare transmit descriptors and buffers */
579 if (ixgbe_setup_transmit_structures(adapter)) {
580 device_printf(dev, "Could not setup transmit structures\n");
581 ixv_stop(adapter);
582 return;
583 }
584
585 /* Reset VF and renegotiate mailbox API version */
687 ixgbe_reset_hw(hw);
688 error = ixgbevf_negotiate_api_version(hw, ixgbe_mbox_api_11);
586 hw->mac.ops.reset_hw(hw);
587 error = ixgbevf_negotiate_api_version(hw, ixgbe_mbox_api_12);
689 if (error)
588 if (error)
690 device_printf(dev, "MBX API 1.1 negotiation failed! Error %d\n", error);
589 device_printf(dev, "MBX API 1.2 negotiation failed! Error %d\n",
590 error);
691
692 ixv_initialize_transmit_units(adapter);
693
694 /* Setup Multicast table */
695 ixv_set_multi(adapter);
696
697 /*
591
592 ixv_initialize_transmit_units(adapter);
593
594 /* Setup Multicast table */
595 ixv_set_multi(adapter);
596
597 /*
698 ** Determine the correct mbuf pool
699 ** for doing jumbo/headersplit
700 */
598 * Determine the correct mbuf pool
599 * for doing jumbo/headersplit
600 */
701 if (ifp->if_mtu > ETHERMTU)
702 adapter->rx_mbuf_sz = MJUMPAGESIZE;
703 else
704 adapter->rx_mbuf_sz = MCLBYTES;
705
706 /* Prepare receive descriptors and buffers */
707 if (ixgbe_setup_receive_structures(adapter)) {
708 device_printf(dev, "Could not setup receive structures\n");

--- 9 unchanged lines hidden (view full) ---

718 if (ifp->if_capenable & IFCAP_TSO4)
719 ifp->if_hwassist |= CSUM_TSO;
720 if (ifp->if_capenable & IFCAP_TXCSUM) {
721 ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
722#if __FreeBSD_version >= 800000
723 ifp->if_hwassist |= CSUM_SCTP;
724#endif
725 }
601 if (ifp->if_mtu > ETHERMTU)
602 adapter->rx_mbuf_sz = MJUMPAGESIZE;
603 else
604 adapter->rx_mbuf_sz = MCLBYTES;
605
606 /* Prepare receive descriptors and buffers */
607 if (ixgbe_setup_receive_structures(adapter)) {
608 device_printf(dev, "Could not setup receive structures\n");

--- 9 unchanged lines hidden (view full) ---

618 if (ifp->if_capenable & IFCAP_TSO4)
619 ifp->if_hwassist |= CSUM_TSO;
620 if (ifp->if_capenable & IFCAP_TXCSUM) {
621 ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
622#if __FreeBSD_version >= 800000
623 ifp->if_hwassist |= CSUM_SCTP;
624#endif
625 }
726
626
727 /* Set up VLAN offload and filter */
728 ixv_setup_vlan_support(adapter);
729
627 /* Set up VLAN offload and filter */
628 ixv_setup_vlan_support(adapter);
629
730 /* Set up MSI/X routing */
630 /* Set up MSI-X routing */
731 ixv_configure_ivars(adapter);
732
733 /* Set up auto-mask */
734 IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_EICS_RTX_QUEUE);
735
631 ixv_configure_ivars(adapter);
632
633 /* Set up auto-mask */
634 IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_EICS_RTX_QUEUE);
635
736 /* Set moderation on the Link interrupt */
737 IXGBE_WRITE_REG(hw, IXGBE_VTEITR(adapter->vector), IXGBE_LINK_ITR);
636 /* Set moderation on the Link interrupt */
637 IXGBE_WRITE_REG(hw, IXGBE_VTEITR(adapter->vector), IXGBE_LINK_ITR);
738
739 /* Stats init */
740 ixv_init_stats(adapter);
741
742 /* Config/Enable Link */
638
639 /* Stats init */
640 ixv_init_stats(adapter);
641
642 /* Config/Enable Link */
743 ixv_config_link(adapter);
643 hw->mac.ops.check_link(hw, &adapter->link_speed, &adapter->link_up,
644 FALSE);
744
745 /* Start watchdog */
746 callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
747
748 /* And now turn on interrupts */
749 ixv_enable_intr(adapter);
750
751 /* Now inform the stack we're ready */
752 ifp->if_drv_flags |= IFF_DRV_RUNNING;
753 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
754
755 return;
645
646 /* Start watchdog */
647 callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
648
649 /* And now turn on interrupts */
650 ixv_enable_intr(adapter);
651
652 /* Now inform the stack we're ready */
653 ifp->if_drv_flags |= IFF_DRV_RUNNING;
654 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
655
656 return;
756}
657} /* ixv_init_locked */
757
658
758static void
759ixv_init(void *arg)
760{
761 struct adapter *adapter = arg;
762
763 IXGBE_CORE_LOCK(adapter);
764 ixv_init_locked(adapter);
765 IXGBE_CORE_UNLOCK(adapter);
766 return;
767}
768
769
770/*
659/*
771**
772** MSIX Interrupt Handlers and Tasklets
773**
774*/
660 * MSI-X Interrupt Handlers and Tasklets
661 */
775
776static inline void
777ixv_enable_queue(struct adapter *adapter, u32 vector)
778{
779 struct ixgbe_hw *hw = &adapter->hw;
662
663static inline void
664ixv_enable_queue(struct adapter *adapter, u32 vector)
665{
666 struct ixgbe_hw *hw = &adapter->hw;
780 u32 queue = 1 << vector;
781 u32 mask;
667 u32 queue = 1 << vector;
668 u32 mask;
782
783 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
784 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
669
670 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
671 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
785}
672} /* ixv_enable_queue */
786
787static inline void
788ixv_disable_queue(struct adapter *adapter, u32 vector)
789{
790 struct ixgbe_hw *hw = &adapter->hw;
673
674static inline void
675ixv_disable_queue(struct adapter *adapter, u32 vector)
676{
677 struct ixgbe_hw *hw = &adapter->hw;
791 u64 queue = (u64)(1 << vector);
792 u32 mask;
678 u64 queue = (u64)(1 << vector);
679 u32 mask;
793
794 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
795 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, mask);
680
681 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
682 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, mask);
796}
683} /* ixv_disable_queue */
797
798static inline void
799ixv_rearm_queues(struct adapter *adapter, u64 queues)
800{
801 u32 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
802 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEICS, mask);
684
685static inline void
686ixv_rearm_queues(struct adapter *adapter, u64 queues)
687{
688 u32 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
689 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEICS, mask);
803}
690} /* ixv_rearm_queues */
804
805
691
692
806static void
807ixv_handle_que(void *context, int pending)
808{
809 struct ix_queue *que = context;
810 struct adapter *adapter = que->adapter;
811 struct tx_ring *txr = que->txr;
812 struct ifnet *ifp = adapter->ifp;
813 bool more;
814
815 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
816 more = ixgbe_rxeof(que);
817 IXGBE_TX_LOCK(txr);
818 ixgbe_txeof(txr);
819#if __FreeBSD_version >= 800000
820 if (!drbr_empty(ifp, txr->br))
821 ixgbe_mq_start_locked(ifp, txr);
822#else
823 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
824 ixgbe_start_locked(txr, ifp);
825#endif
826 IXGBE_TX_UNLOCK(txr);
827 if (more) {
828 taskqueue_enqueue(que->tq, &que->que_task);
829 return;
830 }
831 }
832
833 /* Reenable this interrupt */
834 ixv_enable_queue(adapter, que->msix);
835 return;
836}
837
838/*********************************************************************
839 *
840 * MSI Queue Interrupt Service routine
841 *
842 **********************************************************************/
693/************************************************************************
694 * ixv_msix_que - MSI Queue Interrupt Service routine
695 ************************************************************************/
843void
844ixv_msix_que(void *arg)
845{
696void
697ixv_msix_que(void *arg)
698{
846 struct ix_queue *que = arg;
699 struct ix_queue *que = arg;
847 struct adapter *adapter = que->adapter;
848 struct ifnet *ifp = adapter->ifp;
700 struct adapter *adapter = que->adapter;
701 struct ifnet *ifp = adapter->ifp;
849 struct tx_ring *txr = que->txr;
850 struct rx_ring *rxr = que->rxr;
851 bool more;
852 u32 newitr = 0;
702 struct tx_ring *txr = que->txr;
703 struct rx_ring *rxr = que->rxr;
704 bool more;
705 u32 newitr = 0;
853
854 ixv_disable_queue(adapter, que->msix);
855 ++que->irqs;
856
857 more = ixgbe_rxeof(que);
858
859 IXGBE_TX_LOCK(txr);
860 ixgbe_txeof(txr);
861 /*
706
707 ixv_disable_queue(adapter, que->msix);
708 ++que->irqs;
709
710 more = ixgbe_rxeof(que);
711
712 IXGBE_TX_LOCK(txr);
713 ixgbe_txeof(txr);
714 /*
862 ** Make certain that if the stack
863 ** has anything queued the task gets
864 ** scheduled to handle it.
865 */
866#ifdef IXGBE_LEGACY_TX
867 if (!IFQ_DRV_IS_EMPTY(&adapter->ifp->if_snd))
868 ixgbe_start_locked(txr, ifp);
869#else
870 if (!drbr_empty(adapter->ifp, txr->br))
871 ixgbe_mq_start_locked(ifp, txr);
872#endif
715 * Make certain that if the stack
716 * has anything queued the task gets
717 * scheduled to handle it.
718 */
719 if (!ixv_ring_empty(adapter->ifp, txr->br))
720 ixv_start_locked(ifp, txr);
873 IXGBE_TX_UNLOCK(txr);
874
875 /* Do AIM now? */
876
877 if (ixv_enable_aim == FALSE)
878 goto no_calc;
879 /*
721 IXGBE_TX_UNLOCK(txr);
722
723 /* Do AIM now? */
724
725 if (ixv_enable_aim == FALSE)
726 goto no_calc;
727 /*
880 ** Do Adaptive Interrupt Moderation:
881 ** - Write out last calculated setting
882 ** - Calculate based on average size over
883 ** the last interval.
884 */
885 if (que->eitr_setting)
886 IXGBE_WRITE_REG(&adapter->hw,
887 IXGBE_VTEITR(que->msix),
728 * Do Adaptive Interrupt Moderation:
729 * - Write out last calculated setting
730 * - Calculate based on average size over
731 * the last interval.
732 */
733 if (que->eitr_setting)
734 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEITR(que->msix),
888 que->eitr_setting);
735 que->eitr_setting);
889
890 que->eitr_setting = 0;
891
736
892 /* Idle, do nothing */
893 if ((txr->bytes == 0) && (rxr->bytes == 0))
894 goto no_calc;
895
737 que->eitr_setting = 0;
738
739 /* Idle, do nothing */
740 if ((txr->bytes == 0) && (rxr->bytes == 0))
741 goto no_calc;
742
896 if ((txr->bytes) && (txr->packets))
743 if ((txr->bytes) && (txr->packets))
897 newitr = txr->bytes/txr->packets;
744 newitr = txr->bytes/txr->packets;
898 if ((rxr->bytes) && (rxr->packets))
745 if ((rxr->bytes) && (rxr->packets))
899 newitr = max(newitr,
900 (rxr->bytes / rxr->packets));
746 newitr = max(newitr, (rxr->bytes / rxr->packets));
901 newitr += 24; /* account for hardware frame, crc */
902
903 /* set an upper boundary */
904 newitr = min(newitr, 3000);
905
906 /* Be nice to the mid range */
907 if ((newitr > 300) && (newitr < 1200))
908 newitr = (newitr / 3);
909 else
910 newitr = (newitr / 2);
911
912 newitr |= newitr << 16;
747 newitr += 24; /* account for hardware frame, crc */
748
749 /* set an upper boundary */
750 newitr = min(newitr, 3000);
751
752 /* Be nice to the mid range */
753 if ((newitr > 300) && (newitr < 1200))
754 newitr = (newitr / 3);
755 else
756 newitr = (newitr / 2);
757
758 newitr |= newitr << 16;
913
914 /* save for next interrupt */
915 que->eitr_setting = newitr;
916
759
917 /* Reset state */
918 txr->bytes = 0;
919 txr->packets = 0;
920 rxr->bytes = 0;
921 rxr->packets = 0;
760 /* save for next interrupt */
761 que->eitr_setting = newitr;
922
762
763 /* Reset state */
764 txr->bytes = 0;
765 txr->packets = 0;
766 rxr->bytes = 0;
767 rxr->packets = 0;
768
923no_calc:
924 if (more)
925 taskqueue_enqueue(que->tq, &que->que_task);
769no_calc:
770 if (more)
771 taskqueue_enqueue(que->tq, &que->que_task);
926 else /* Reenable this interrupt */
772 else /* Re-enable this interrupt */
927 ixv_enable_queue(adapter, que->msix);
773 ixv_enable_queue(adapter, que->msix);
774
928 return;
775 return;
929}
776} /* ixv_msix_que */
930
777
778/************************************************************************
779 * ixv_msix_mbx
780 ************************************************************************/
931static void
932ixv_msix_mbx(void *arg)
933{
781static void
782ixv_msix_mbx(void *arg)
783{
934 struct adapter *adapter = arg;
784 struct adapter *adapter = arg;
935 struct ixgbe_hw *hw = &adapter->hw;
785 struct ixgbe_hw *hw = &adapter->hw;
936 u32 reg;
786 u32 reg;
937
938 ++adapter->link_irq;
939
940 /* First get the cause */
941 reg = IXGBE_READ_REG(hw, IXGBE_VTEICS);
942 /* Clear interrupt with write */
943 IXGBE_WRITE_REG(hw, IXGBE_VTEICR, reg);
944
945 /* Link status change */
946 if (reg & IXGBE_EICR_LSC)
947 taskqueue_enqueue(adapter->tq, &adapter->link_task);
948
949 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_EIMS_OTHER);
787
788 ++adapter->link_irq;
789
790 /* First get the cause */
791 reg = IXGBE_READ_REG(hw, IXGBE_VTEICS);
792 /* Clear interrupt with write */
793 IXGBE_WRITE_REG(hw, IXGBE_VTEICR, reg);
794
795 /* Link status change */
796 if (reg & IXGBE_EICR_LSC)
797 taskqueue_enqueue(adapter->tq, &adapter->link_task);
798
799 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_EIMS_OTHER);
800
950 return;
801 return;
951}
802} /* ixv_msix_mbx */
952
803
953/*********************************************************************
804/************************************************************************
805 * ixv_media_status - Media Ioctl callback
954 *
806 *
955 * Media Ioctl callback
956 *
957 * This routine is called whenever the user queries the status of
958 * the interface using ifconfig.
959 *
960 **********************************************************************/
807 * Called whenever the user queries the status of
808 * the interface using ifconfig.
809 ************************************************************************/
961static void
810static void
962ixv_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
811ixv_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
963{
964 struct adapter *adapter = ifp->if_softc;
965
966 INIT_DEBUGOUT("ixv_media_status: begin");
967 IXGBE_CORE_LOCK(adapter);
968 ixv_update_link_status(adapter);
969
970 ifmr->ifm_status = IFM_AVALID;

--- 6 unchanged lines hidden (view full) ---

977
978 ifmr->ifm_status |= IFM_ACTIVE;
979
980 switch (adapter->link_speed) {
981 case IXGBE_LINK_SPEED_1GB_FULL:
982 ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
983 break;
984 case IXGBE_LINK_SPEED_10GB_FULL:
812{
813 struct adapter *adapter = ifp->if_softc;
814
815 INIT_DEBUGOUT("ixv_media_status: begin");
816 IXGBE_CORE_LOCK(adapter);
817 ixv_update_link_status(adapter);
818
819 ifmr->ifm_status = IFM_AVALID;

--- 6 unchanged lines hidden (view full) ---

826
827 ifmr->ifm_status |= IFM_ACTIVE;
828
829 switch (adapter->link_speed) {
830 case IXGBE_LINK_SPEED_1GB_FULL:
831 ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
832 break;
833 case IXGBE_LINK_SPEED_10GB_FULL:
985 ifmr->ifm_active |= IFM_FDX;
834 ifmr->ifm_active |= IFM_10G_T | IFM_FDX;
986 break;
835 break;
836 case IXGBE_LINK_SPEED_100_FULL:
837 ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
838 break;
839 case IXGBE_LINK_SPEED_10_FULL:
840 ifmr->ifm_active |= IFM_10_T | IFM_FDX;
841 break;
987 }
988
989 IXGBE_CORE_UNLOCK(adapter);
990
991 return;
842 }
843
844 IXGBE_CORE_UNLOCK(adapter);
845
846 return;
992}
847} /* ixv_media_status */
993
848
994/*********************************************************************
849/************************************************************************
850 * ixv_media_change - Media Ioctl callback
995 *
851 *
996 * Media Ioctl callback
997 *
998 * This routine is called when the user changes speed/duplex using
999 * media/mediopt option with ifconfig.
1000 *
1001 **********************************************************************/
852 * Called when the user changes speed/duplex using
853 * media/mediopt option with ifconfig.
854 ************************************************************************/
1002static int
855static int
1003ixv_media_change(struct ifnet * ifp)
856ixv_media_change(struct ifnet *ifp)
1004{
1005 struct adapter *adapter = ifp->if_softc;
1006 struct ifmedia *ifm = &adapter->media;
1007
1008 INIT_DEBUGOUT("ixv_media_change: begin");
1009
1010 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1011 return (EINVAL);
1012
857{
858 struct adapter *adapter = ifp->if_softc;
859 struct ifmedia *ifm = &adapter->media;
860
861 INIT_DEBUGOUT("ixv_media_change: begin");
862
863 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
864 return (EINVAL);
865
1013 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1014 case IFM_AUTO:
1015 break;
1016 default:
1017 device_printf(adapter->dev, "Only auto media type\n");
866 switch (IFM_SUBTYPE(ifm->ifm_media)) {
867 case IFM_AUTO:
868 break;
869 default:
870 device_printf(adapter->dev, "Only auto media type\n");
1018 return (EINVAL);
871 return (EINVAL);
1019 }
872 }
1020
1021 return (0);
873
874 return (0);
1022}
875} /* ixv_media_change */
1023
1024
876
877
1025/*********************************************************************
1026 * Multicast Update
878/************************************************************************
879 * ixv_set_multi - Multicast Update
1027 *
880 *
1028 * This routine is called whenever multicast address list is updated.
1029 *
1030 **********************************************************************/
1031#define IXGBE_RAR_ENTRIES 16
1032
881 * Called whenever multicast address list is updated.
882 ************************************************************************/
1033static void
1034ixv_set_multi(struct adapter *adapter)
1035{
883static void
884ixv_set_multi(struct adapter *adapter)
885{
1036 u8 mta[MAX_NUM_MULTICAST_ADDRESSES * IXGBE_ETH_LENGTH_OF_ADDRESS];
1037 u8 *update_ptr;
1038 struct ifmultiaddr *ifma;
1039 int mcnt = 0;
1040 struct ifnet *ifp = adapter->ifp;
886 u8 mta[MAX_NUM_MULTICAST_ADDRESSES * IXGBE_ETH_LENGTH_OF_ADDRESS];
887 u8 *update_ptr;
888 struct ifmultiaddr *ifma;
889 struct ifnet *ifp = adapter->ifp;
890 int mcnt = 0;
1041
1042 IOCTL_DEBUGOUT("ixv_set_multi: begin");
1043
1044#if __FreeBSD_version < 800000
1045 IF_ADDR_LOCK(ifp);
1046#else
1047 if_maddr_rlock(ifp);
1048#endif
1049 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1050 if (ifma->ifma_addr->sa_family != AF_LINK)
1051 continue;
891
892 IOCTL_DEBUGOUT("ixv_set_multi: begin");
893
894#if __FreeBSD_version < 800000
895 IF_ADDR_LOCK(ifp);
896#else
897 if_maddr_rlock(ifp);
898#endif
899 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
900 if (ifma->ifma_addr->sa_family != AF_LINK)
901 continue;
1052 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
902 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
1053 &mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
1054 IXGBE_ETH_LENGTH_OF_ADDRESS);
1055 mcnt++;
1056 }
1057#if __FreeBSD_version < 800000
1058 IF_ADDR_UNLOCK(ifp);
1059#else
1060 if_maddr_runlock(ifp);
1061#endif
1062
1063 update_ptr = mta;
1064
903 &mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
904 IXGBE_ETH_LENGTH_OF_ADDRESS);
905 mcnt++;
906 }
907#if __FreeBSD_version < 800000
908 IF_ADDR_UNLOCK(ifp);
909#else
910 if_maddr_runlock(ifp);
911#endif
912
913 update_ptr = mta;
914
1065 ixgbe_update_mc_addr_list(&adapter->hw,
1066 update_ptr, mcnt, ixv_mc_array_itr, TRUE);
915 adapter->hw.mac.ops.update_mc_addr_list(&adapter->hw, update_ptr, mcnt,
916 ixv_mc_array_itr, TRUE);
1067
1068 return;
917
918 return;
1069}
919} /* ixv_set_multi */
1070
920
1071/*
1072 * This is an iterator function now needed by the multicast
1073 * shared code. It simply feeds the shared code routine the
1074 * addresses in the array of ixv_set_multi() one by one.
1075 */
921/************************************************************************
922 * ixv_mc_array_itr
923 *
924 * An iterator function needed by the multicast shared code.
925 * It feeds the shared code routine the addresses in the
926 * array of ixv_set_multi() one by one.
927 ************************************************************************/
1076static u8 *
1077ixv_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
1078{
1079 u8 *addr = *update_ptr;
1080 u8 *newptr;
1081 *vmdq = 0;
1082
1083 newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
1084 *update_ptr = newptr;
928static u8 *
929ixv_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
930{
931 u8 *addr = *update_ptr;
932 u8 *newptr;
933 *vmdq = 0;
934
935 newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
936 *update_ptr = newptr;
937
1085 return addr;
938 return addr;
1086}
939} /* ixv_mc_array_itr */
1087
940
1088/*********************************************************************
1089 * Timer routine
941/************************************************************************
942 * ixv_local_timer - Timer routine
1090 *
943 *
1091 * This routine checks for link status,updates statistics,
1092 * and runs the watchdog check.
1093 *
1094 **********************************************************************/
1095
944 * Checks for link status, updates statistics,
945 * and runs the watchdog check.
946 ************************************************************************/
1096static void
1097ixv_local_timer(void *arg)
1098{
947static void
948ixv_local_timer(void *arg)
949{
1099 struct adapter *adapter = arg;
1100 device_t dev = adapter->dev;
1101 struct ix_queue *que = adapter->queues;
1102 u64 queues = 0;
1103 int hung = 0;
950 struct adapter *adapter = arg;
951 device_t dev = adapter->dev;
952 struct ix_queue *que = adapter->queues;
953 u64 queues = 0;
954 int hung = 0;
1104
1105 mtx_assert(&adapter->core_mtx, MA_OWNED);
1106
955
956 mtx_assert(&adapter->core_mtx, MA_OWNED);
957
1107 ixv_update_link_status(adapter);
958 ixv_check_link(adapter);
1108
1109 /* Stats Update */
1110 ixv_update_stats(adapter);
1111
1112 /*
959
960 /* Stats Update */
961 ixv_update_stats(adapter);
962
963 /*
1113 ** Check the TX queues status
1114 ** - mark hung queues so we don't schedule on them
1115 ** - watchdog only if all queues show hung
1116 */
964 * Check the TX queues status
965 * - mark hung queues so we don't schedule on them
966 * - watchdog only if all queues show hung
967 */
1117 for (int i = 0; i < adapter->num_queues; i++, que++) {
1118 /* Keep track of queues with work for soft irq */
1119 if (que->txr->busy)
1120 queues |= ((u64)1 << que->me);
1121 /*
968 for (int i = 0; i < adapter->num_queues; i++, que++) {
969 /* Keep track of queues with work for soft irq */
970 if (que->txr->busy)
971 queues |= ((u64)1 << que->me);
972 /*
1122 ** Each time txeof runs without cleaning, but there
1123 ** are uncleaned descriptors it increments busy. If
1124 ** we get to the MAX we declare it hung.
1125 */
973 * Each time txeof runs without cleaning, but there
974 * are uncleaned descriptors it increments busy. If
975 * we get to the MAX we declare it hung.
976 */
1126 if (que->busy == IXGBE_QUEUE_HUNG) {
1127 ++hung;
1128 /* Mark the queue as inactive */
1129 adapter->active_queues &= ~((u64)1 << que->me);
1130 continue;
1131 } else {
1132 /* Check if we've come back from hung */
1133 if ((adapter->active_queues & ((u64)1 << que->me)) == 0)
977 if (que->busy == IXGBE_QUEUE_HUNG) {
978 ++hung;
979 /* Mark the queue as inactive */
980 adapter->active_queues &= ~((u64)1 << que->me);
981 continue;
982 } else {
983 /* Check if we've come back from hung */
984 if ((adapter->active_queues & ((u64)1 << que->me)) == 0)
1134 adapter->active_queues |= ((u64)1 << que->me);
985 adapter->active_queues |= ((u64)1 << que->me);
1135 }
1136 if (que->busy >= IXGBE_MAX_TX_BUSY) {
986 }
987 if (que->busy >= IXGBE_MAX_TX_BUSY) {
1137 device_printf(dev,"Warning queue %d "
1138 "appears to be hung!\n", i);
988 device_printf(dev,
989 "Warning queue %d appears to be hung!\n", i);
1139 que->txr->busy = IXGBE_QUEUE_HUNG;
1140 ++hung;
1141 }
1142
1143 }
1144
1145 /* Only truly watchdog if all queues show hung */
1146 if (hung == adapter->num_queues)
1147 goto watchdog;
1148 else if (queues != 0) { /* Force an IRQ on queues with work */
1149 ixv_rearm_queues(adapter, queues);
1150 }
1151
1152 callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
990 que->txr->busy = IXGBE_QUEUE_HUNG;
991 ++hung;
992 }
993
994 }
995
996 /* Only truly watchdog if all queues show hung */
997 if (hung == adapter->num_queues)
998 goto watchdog;
999 else if (queues != 0) { /* Force an IRQ on queues with work */
1000 ixv_rearm_queues(adapter, queues);
1001 }
1002
1003 callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
1004
1153 return;
1154
1155watchdog:
1005 return;
1006
1007watchdog:
1008
1156 device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
1157 adapter->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1158 adapter->watchdog_events++;
1159 ixv_init_locked(adapter);
1009 device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
1010 adapter->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1011 adapter->watchdog_events++;
1012 ixv_init_locked(adapter);
1160}
1013} /* ixv_local_timer */
1161
1014
1162/*
1163** Note: this routine updates the OS on the link state
1164** the real check of the hardware only happens with
1165** a link interrupt.
1166*/
1015/************************************************************************
1016 * ixv_update_link_status - Update OS on link state
1017 *
1018 * Note: Only updates the OS on the cached link state.
1019 * The real check of the hardware only happens with
1020 * a link interrupt.
1021 ************************************************************************/
1167static void
1168ixv_update_link_status(struct adapter *adapter)
1169{
1022static void
1023ixv_update_link_status(struct adapter *adapter)
1024{
1170 struct ifnet *ifp = adapter->ifp;
1171 device_t dev = adapter->dev;
1025 struct ifnet *ifp = adapter->ifp;
1026 device_t dev = adapter->dev;
1172
1027
1173 if (adapter->link_up){
1028 if (adapter->link_up) {
1174 if (adapter->link_active == FALSE) {
1175 if (bootverbose)
1176 device_printf(dev,"Link is up %d Gbps %s \n",
1029 if (adapter->link_active == FALSE) {
1030 if (bootverbose)
1031 device_printf(dev,"Link is up %d Gbps %s \n",
1177 ((adapter->link_speed == 128)? 10:1),
1032 ((adapter->link_speed == 128) ? 10 : 1),
1178 "Full Duplex");
1179 adapter->link_active = TRUE;
1180 if_link_state_change(ifp, LINK_STATE_UP);
1181 }
1182 } else { /* Link down */
1183 if (adapter->link_active == TRUE) {
1184 if (bootverbose)
1185 device_printf(dev,"Link is Down\n");
1186 if_link_state_change(ifp, LINK_STATE_DOWN);
1187 adapter->link_active = FALSE;
1188 }
1189 }
1190
1191 return;
1033 "Full Duplex");
1034 adapter->link_active = TRUE;
1035 if_link_state_change(ifp, LINK_STATE_UP);
1036 }
1037 } else { /* Link down */
1038 if (adapter->link_active == TRUE) {
1039 if (bootverbose)
1040 device_printf(dev,"Link is Down\n");
1041 if_link_state_change(ifp, LINK_STATE_DOWN);
1042 adapter->link_active = FALSE;
1043 }
1044 }
1045
1046 return;
1192}
1047} /* ixv_update_link_status */
1193
1194
1048
1049
1195/*********************************************************************
1050/************************************************************************
1051 * ixv_stop - Stop the hardware
1196 *
1052 *
1197 * This routine disables all traffic on the adapter by issuing a
1198 * global reset on the MAC and deallocates TX/RX buffers.
1199 *
1200 **********************************************************************/
1201
1053 * Disables all traffic on the adapter by issuing a
1054 * global reset on the MAC and deallocates TX/RX buffers.
1055 ************************************************************************/
1202static void
1203ixv_stop(void *arg)
1204{
1056static void
1057ixv_stop(void *arg)
1058{
1205 struct ifnet *ifp;
1206 struct adapter *adapter = arg;
1059 struct ifnet *ifp;
1060 struct adapter *adapter = arg;
1207 struct ixgbe_hw *hw = &adapter->hw;
1061 struct ixgbe_hw *hw = &adapter->hw;
1062
1208 ifp = adapter->ifp;
1209
1210 mtx_assert(&adapter->core_mtx, MA_OWNED);
1211
1212 INIT_DEBUGOUT("ixv_stop: begin\n");
1213 ixv_disable_intr(adapter);
1214
1215 /* Tell the stack that the interface is no longer active */
1216 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1217
1063 ifp = adapter->ifp;
1064
1065 mtx_assert(&adapter->core_mtx, MA_OWNED);
1066
1067 INIT_DEBUGOUT("ixv_stop: begin\n");
1068 ixv_disable_intr(adapter);
1069
1070 /* Tell the stack that the interface is no longer active */
1071 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1072
1218 ixgbe_reset_hw(hw);
1073 hw->mac.ops.reset_hw(hw);
1219 adapter->hw.adapter_stopped = FALSE;
1074 adapter->hw.adapter_stopped = FALSE;
1220 ixgbe_stop_adapter(hw);
1075 hw->mac.ops.stop_adapter(hw);
1221 callout_stop(&adapter->timer);
1222
1223 /* reprogram the RAR[0] in case user changed it. */
1076 callout_stop(&adapter->timer);
1077
1078 /* reprogram the RAR[0] in case user changed it. */
1224 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
1079 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
1225
1226 return;
1080
1081 return;
1227}
1082} /* ixv_stop */
1228
1229
1083
1084
1230/*********************************************************************
1231 *
1232 * Determine hardware revision.
1233 *
1234 **********************************************************************/
1235static void
1236ixv_identify_hardware(struct adapter *adapter)
1237{
1238 device_t dev = adapter->dev;
1239 struct ixgbe_hw *hw = &adapter->hw;
1240
1241 /*
1242 ** Make sure BUSMASTER is set, on a VM under
1243 ** KVM it may not be and will break things.
1244 */
1245 pci_enable_busmaster(dev);
1246
1247 /* Save off the information about this board */
1248 hw->vendor_id = pci_get_vendor(dev);
1249 hw->device_id = pci_get_device(dev);
1250 hw->revision_id = pci_read_config(dev, PCIR_REVID, 1);
1251 hw->subsystem_vendor_id =
1252 pci_read_config(dev, PCIR_SUBVEND_0, 2);
1253 hw->subsystem_device_id =
1254 pci_read_config(dev, PCIR_SUBDEV_0, 2);
1255
1256 /* We need this to determine device-specific things */
1257 ixgbe_set_mac_type(hw);
1258
1259 /* Set the right number of segments */
1260 adapter->num_segs = IXGBE_82599_SCATTER;
1261
1262 return;
1263}
1264
1265/*********************************************************************
1266 *
1267 * Setup MSIX Interrupt resources and handlers
1268 *
1269 **********************************************************************/
1085/************************************************************************
1086 * ixv_allocate_pci_resources
1087 ************************************************************************/
1270static int
1088static int
1271ixv_allocate_msix(struct adapter *adapter)
1089ixv_allocate_pci_resources(struct adapter *adapter)
1272{
1090{
1273 device_t dev = adapter->dev;
1274 struct ix_queue *que = adapter->queues;
1275 struct tx_ring *txr = adapter->tx_rings;
1276 int error, rid, vector = 0;
1277
1278 for (int i = 0; i < adapter->num_queues; i++, vector++, que++, txr++) {
1279 rid = vector + 1;
1280 que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
1281 RF_SHAREABLE | RF_ACTIVE);
1282 if (que->res == NULL) {
1283 device_printf(dev,"Unable to allocate"
1284 " bus resource: que interrupt [%d]\n", vector);
1285 return (ENXIO);
1286 }
1287 /* Set the handler function */
1288 error = bus_setup_intr(dev, que->res,
1289 INTR_TYPE_NET | INTR_MPSAFE, NULL,
1290 ixv_msix_que, que, &que->tag);
1291 if (error) {
1292 que->res = NULL;
1293 device_printf(dev, "Failed to register QUE handler");
1294 return (error);
1295 }
1296#if __FreeBSD_version >= 800504
1297 bus_describe_intr(dev, que->res, que->tag, "que %d", i);
1298#endif
1299 que->msix = vector;
1300 adapter->active_queues |= (u64)(1 << que->msix);
1301 /*
1302 ** Bind the msix vector, and thus the
1303 ** ring to the corresponding cpu.
1304 */
1305 if (adapter->num_queues > 1)
1306 bus_bind_intr(dev, que->res, i);
1307 TASK_INIT(&txr->txq_task, 0, ixgbe_deferred_mq_start, txr);
1308 TASK_INIT(&que->que_task, 0, ixv_handle_que, que);
1309 que->tq = taskqueue_create_fast("ixv_que", M_NOWAIT,
1310 taskqueue_thread_enqueue, &que->tq);
1311 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que",
1312 device_get_nameunit(adapter->dev));
1313 }
1314
1315 /* and Mailbox */
1316 rid = vector + 1;
1317 adapter->res = bus_alloc_resource_any(dev,
1318 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
1319 if (!adapter->res) {
1320 device_printf(dev,"Unable to allocate"
1321 " bus resource: MBX interrupt [%d]\n", rid);
1322 return (ENXIO);
1323 }
1324 /* Set the mbx handler function */
1325 error = bus_setup_intr(dev, adapter->res,
1326 INTR_TYPE_NET | INTR_MPSAFE, NULL,
1327 ixv_msix_mbx, adapter, &adapter->tag);
1328 if (error) {
1329 adapter->res = NULL;
1330 device_printf(dev, "Failed to register LINK handler");
1331 return (error);
1332 }
1333#if __FreeBSD_version >= 800504
1334 bus_describe_intr(dev, adapter->res, adapter->tag, "mbx");
1335#endif
1336 adapter->vector = vector;
1337 /* Tasklets for Mailbox */
1338 TASK_INIT(&adapter->link_task, 0, ixv_handle_mbx, adapter);
1339 adapter->tq = taskqueue_create_fast("ixv_mbx", M_NOWAIT,
1340 taskqueue_thread_enqueue, &adapter->tq);
1341 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s mbxq",
1342 device_get_nameunit(adapter->dev));
1343 /*
1344 ** Due to a broken design QEMU will fail to properly
1345 ** enable the guest for MSIX unless the vectors in
1346 ** the table are all set up, so we must rewrite the
1347 ** ENABLE in the MSIX control register again at this
1348 ** point to cause it to successfully initialize us.
1349 */
1350 if (adapter->hw.mac.type == ixgbe_mac_82599_vf) {
1351 int msix_ctrl;
1352 pci_find_cap(dev, PCIY_MSIX, &rid);
1353 rid += PCIR_MSIX_CTRL;
1354 msix_ctrl = pci_read_config(dev, rid, 2);
1355 msix_ctrl |= PCIM_MSIXCTRL_MSIX_ENABLE;
1356 pci_write_config(dev, rid, msix_ctrl, 2);
1357 }
1358
1359 return (0);
1360}
1361
1362/*
1363 * Setup MSIX resources, note that the VF
1364 * device MUST use MSIX, there is no fallback.
1365 */
1366static int
1367ixv_setup_msix(struct adapter *adapter)
1368{
1369 device_t dev = adapter->dev;
1091 device_t dev = adapter->dev;
1370 int rid, want, msgs;
1092 int rid;
1371
1093
1372
1373 /* Must have at least 2 MSIX vectors */
1374 msgs = pci_msix_count(dev);
1375 if (msgs < 2)
1376 goto out;
1377 rid = PCIR_BAR(3);
1378 adapter->msix_mem = bus_alloc_resource_any(dev,
1379 SYS_RES_MEMORY, &rid, RF_ACTIVE);
1380 if (adapter->msix_mem == NULL) {
1381 device_printf(adapter->dev,
1382 "Unable to map MSIX table \n");
1383 goto out;
1384 }
1385
1386 /*
1387 ** Want vectors for the queues,
1388 ** plus an additional for mailbox.
1389 */
1390 want = adapter->num_queues + 1;
1391 if (want > msgs) {
1392 want = msgs;
1393 adapter->num_queues = msgs - 1;
1394 } else
1395 msgs = want;
1396 if ((pci_alloc_msix(dev, &msgs) == 0) && (msgs == want)) {
1397 device_printf(adapter->dev,
1398 "Using MSIX interrupts with %d vectors\n", want);
1399 return (want);
1400 }
1401 /* Release in case alloc was insufficient */
1402 pci_release_msi(dev);
1403out:
1404 if (adapter->msix_mem != NULL) {
1405 bus_release_resource(dev, SYS_RES_MEMORY,
1406 rid, adapter->msix_mem);
1407 adapter->msix_mem = NULL;
1408 }
1409 device_printf(adapter->dev,"MSIX config error\n");
1410 return (ENXIO);
1411}
1412
1413
1414static int
1415ixv_allocate_pci_resources(struct adapter *adapter)
1416{
1417 int rid;
1418 device_t dev = adapter->dev;
1419
1420 rid = PCIR_BAR(0);
1094 rid = PCIR_BAR(0);
1421 adapter->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1422 &rid, RF_ACTIVE);
1095 adapter->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
1096 RF_ACTIVE);
1423
1424 if (!(adapter->pci_mem)) {
1425 device_printf(dev, "Unable to allocate bus resource: memory\n");
1426 return (ENXIO);
1427 }
1428
1097
1098 if (!(adapter->pci_mem)) {
1099 device_printf(dev, "Unable to allocate bus resource: memory\n");
1100 return (ENXIO);
1101 }
1102
1429 adapter->osdep.mem_bus_space_tag =
1430 rman_get_bustag(adapter->pci_mem);
1103 adapter->osdep.mem_bus_space_tag = rman_get_bustag(adapter->pci_mem);
1431 adapter->osdep.mem_bus_space_handle =
1104 adapter->osdep.mem_bus_space_handle =
1432 rman_get_bushandle(adapter->pci_mem);
1105 rman_get_bushandle(adapter->pci_mem);
1433 adapter->hw.hw_addr = (u8 *)&adapter->osdep.mem_bus_space_handle;
1434
1435 /* Pick up the tuneable queues */
1436 adapter->num_queues = ixv_num_queues;
1106 adapter->hw.hw_addr = (u8 *)&adapter->osdep.mem_bus_space_handle;
1107
1108 /* Pick up the tuneable queues */
1109 adapter->num_queues = ixv_num_queues;
1437 adapter->hw.back = adapter;
1438
1110
1439 /*
1440 ** Now setup MSI/X, should
1441 ** return us the number of
1442 ** configured vectors.
1443 */
1444 adapter->msix = ixv_setup_msix(adapter);
1445 if (adapter->msix == ENXIO)
1446 return (ENXIO);
1447 else
1448 return (0);
1449}
1111 return (0);
1112} /* ixv_allocate_pci_resources */
1450
1113
1114/************************************************************************
1115 * ixv_free_pci_resources
1116 ************************************************************************/
1451static void
1452ixv_free_pci_resources(struct adapter * adapter)
1453{
1117static void
1118ixv_free_pci_resources(struct adapter * adapter)
1119{
1454 struct ix_queue *que = adapter->queues;
1455 device_t dev = adapter->dev;
1456 int rid, memrid;
1120 struct ix_queue *que = adapter->queues;
1121 device_t dev = adapter->dev;
1122 int rid, memrid;
1457
1458 memrid = PCIR_BAR(MSIX_82598_BAR);
1459
1460 /*
1123
1124 memrid = PCIR_BAR(MSIX_82598_BAR);
1125
1126 /*
1461 ** There is a slight possibility of a failure mode
1462 ** in attach that will result in entering this function
1463 ** before interrupt resources have been initialized, and
1464 ** in that case we do not want to execute the loops below
1465 ** We can detect this reliably by the state of the adapter
1466 ** res pointer.
1467 */
1127 * There is a slight possibility of a failure mode
1128 * in attach that will result in entering this function
1129 * before interrupt resources have been initialized, and
1130 * in that case we do not want to execute the loops below
1131 * We can detect this reliably by the state of the adapter
1132 * res pointer.
1133 */
1468 if (adapter->res == NULL)
1469 goto mem;
1470
1471 /*
1134 if (adapter->res == NULL)
1135 goto mem;
1136
1137 /*
1472 ** Release all msix queue resources:
1473 */
1138 * Release all msix queue resources:
1139 */
1474 for (int i = 0; i < adapter->num_queues; i++, que++) {
1475 rid = que->msix + 1;
1476 if (que->tag != NULL) {
1477 bus_teardown_intr(dev, que->res, que->tag);
1478 que->tag = NULL;
1479 }
1480 if (que->res != NULL)
1481 bus_release_resource(dev, SYS_RES_IRQ, rid, que->res);
1482 }
1483
1484
1140 for (int i = 0; i < adapter->num_queues; i++, que++) {
1141 rid = que->msix + 1;
1142 if (que->tag != NULL) {
1143 bus_teardown_intr(dev, que->res, que->tag);
1144 que->tag = NULL;
1145 }
1146 if (que->res != NULL)
1147 bus_release_resource(dev, SYS_RES_IRQ, rid, que->res);
1148 }
1149
1150
1485 /* Clean the Legacy or Link interrupt last */
1486 if (adapter->vector) /* we are doing MSIX */
1487 rid = adapter->vector + 1;
1488 else
1489 (adapter->msix != 0) ? (rid = 1):(rid = 0);
1151 /* Clean the Mailbox interrupt last */
1152 rid = adapter->vector + 1;
1490
1491 if (adapter->tag != NULL) {
1492 bus_teardown_intr(dev, adapter->res, adapter->tag);
1493 adapter->tag = NULL;
1494 }
1495 if (adapter->res != NULL)
1496 bus_release_resource(dev, SYS_RES_IRQ, rid, adapter->res);
1497
1498mem:
1153
1154 if (adapter->tag != NULL) {
1155 bus_teardown_intr(dev, adapter->res, adapter->tag);
1156 adapter->tag = NULL;
1157 }
1158 if (adapter->res != NULL)
1159 bus_release_resource(dev, SYS_RES_IRQ, rid, adapter->res);
1160
1161mem:
1499 if (adapter->msix)
1500 pci_release_msi(dev);
1162 pci_release_msi(dev);
1501
1502 if (adapter->msix_mem != NULL)
1163
1164 if (adapter->msix_mem != NULL)
1503 bus_release_resource(dev, SYS_RES_MEMORY,
1504 memrid, adapter->msix_mem);
1165 bus_release_resource(dev, SYS_RES_MEMORY, memrid,
1166 adapter->msix_mem);
1505
1506 if (adapter->pci_mem != NULL)
1167
1168 if (adapter->pci_mem != NULL)
1507 bus_release_resource(dev, SYS_RES_MEMORY,
1508 PCIR_BAR(0), adapter->pci_mem);
1169 bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
1170 adapter->pci_mem);
1509
1510 return;
1171
1172 return;
1511}
1173} /* ixv_free_pci_resources */
1512
1174
1513/*********************************************************************
1175/************************************************************************
1176 * ixv_setup_interface
1514 *
1177 *
1515 * Setup networking device structure and register an interface.
1516 *
1517 **********************************************************************/
1178 * Setup networking device structure and register an interface.
1179 ************************************************************************/
1518static void
1519ixv_setup_interface(device_t dev, struct adapter *adapter)
1520{
1180static void
1181ixv_setup_interface(device_t dev, struct adapter *adapter)
1182{
1521 struct ifnet *ifp;
1183 struct ifnet *ifp;
1522
1523 INIT_DEBUGOUT("ixv_setup_interface: begin");
1524
1525 ifp = adapter->ifp = if_alloc(IFT_ETHER);
1526 if (ifp == NULL)
1527 panic("%s: can not if_alloc()\n", device_get_nameunit(dev));
1528 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1529 ifp->if_baudrate = 1000000000;
1530 ifp->if_init = ixv_init;
1531 ifp->if_softc = adapter;
1532 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1533 ifp->if_ioctl = ixv_ioctl;
1184
1185 INIT_DEBUGOUT("ixv_setup_interface: begin");
1186
1187 ifp = adapter->ifp = if_alloc(IFT_ETHER);
1188 if (ifp == NULL)
1189 panic("%s: can not if_alloc()\n", device_get_nameunit(dev));
1190 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1191 ifp->if_baudrate = 1000000000;
1192 ifp->if_init = ixv_init;
1193 ifp->if_softc = adapter;
1194 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1195 ifp->if_ioctl = ixv_ioctl;
1534#if __FreeBSD_version >= 800000
1535 ifp->if_transmit = ixgbe_mq_start;
1536 ifp->if_qflush = ixgbe_qflush;
1537#else
1538 ifp->if_start = ixgbe_start;
1539#endif
1540 ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 2;
1196 if_setgetcounterfn(ifp, ixv_get_counter);
1197 /* TSO parameters */
1198 ifp->if_hw_tsomax = 65518;
1199 ifp->if_hw_tsomaxsegcount = IXGBE_82599_SCATTER;
1200 ifp->if_hw_tsomaxsegsize = 2048;
1201 if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) {
1202 ifp->if_start = ixgbe_legacy_start;
1203 ixv_start_locked = ixgbe_legacy_start_locked;
1204 ixv_ring_empty = ixgbe_legacy_ring_empty;
1205 } else {
1206 ifp->if_transmit = ixgbe_mq_start;
1207 ifp->if_qflush = ixgbe_qflush;
1208 ixv_start_locked = ixgbe_mq_start_locked;
1209 ixv_ring_empty = drbr_empty;
1210 }
1211 IFQ_SET_MAXLEN(&ifp->if_snd, adapter->num_tx_desc - 2);
1541
1542 ether_ifattach(ifp, adapter->hw.mac.addr);
1543
1212
1213 ether_ifattach(ifp, adapter->hw.mac.addr);
1214
1544 adapter->max_frame_size =
1545 ifp->if_mtu + IXGBE_MTU_HDR_VLAN;
1215 adapter->max_frame_size = ifp->if_mtu + IXGBE_MTU_HDR;
1546
1547 /*
1548 * Tell the upper layer(s) we support long frames.
1549 */
1550 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
1551
1216
1217 /*
1218 * Tell the upper layer(s) we support long frames.
1219 */
1220 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
1221
1552 ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_TSO4 | IFCAP_VLAN_HWCSUM;
1553 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
1554 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING
1555 | IFCAP_VLAN_HWTSO
1556 | IFCAP_VLAN_MTU;
1557 ifp->if_capabilities |= IFCAP_LRO;
1222 /* Set capability flags */
1223 ifp->if_capabilities |= IFCAP_HWCSUM
1224 | IFCAP_HWCSUM_IPV6
1225 | IFCAP_TSO
1226 | IFCAP_LRO
1227 | IFCAP_VLAN_HWTAGGING
1228 | IFCAP_VLAN_HWTSO
1229 | IFCAP_VLAN_HWCSUM
1230 | IFCAP_JUMBO_MTU
1231 | IFCAP_VLAN_MTU;
1232
1233 /* Enable the above capabilities by default */
1558 ifp->if_capenable = ifp->if_capabilities;
1559
1560 /*
1561 * Specify the media types supported by this adapter and register
1562 * callbacks to update media and link information
1563 */
1564 ifmedia_init(&adapter->media, IFM_IMASK, ixv_media_change,
1234 ifp->if_capenable = ifp->if_capabilities;
1235
1236 /*
1237 * Specify the media types supported by this adapter and register
1238 * callbacks to update media and link information
1239 */
1240 ifmedia_init(&adapter->media, IFM_IMASK, ixv_media_change,
1565 ixv_media_status);
1241 ixv_media_status);
1566 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1567 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
1568
1569 return;
1242 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1243 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
1244
1245 return;
1570}
1571
1572static void
1573ixv_config_link(struct adapter *adapter)
1574{
1575 struct ixgbe_hw *hw = &adapter->hw;
1576 u32 autoneg;
1246} /* ixv_setup_interface */
1577
1247
1578 if (hw->mac.ops.check_link)
1579 hw->mac.ops.check_link(hw, &autoneg,
1580 &adapter->link_up, FALSE);
1581}
1582
1248
1583
1584/*********************************************************************
1585 *
1586 * Enable transmit unit.
1587 *
1588 **********************************************************************/
1249/************************************************************************
1250 * ixv_initialize_transmit_units - Enable transmit unit.
1251 ************************************************************************/
1589static void
1590ixv_initialize_transmit_units(struct adapter *adapter)
1591{
1252static void
1253ixv_initialize_transmit_units(struct adapter *adapter)
1254{
1592 struct tx_ring *txr = adapter->tx_rings;
1593 struct ixgbe_hw *hw = &adapter->hw;
1255 struct tx_ring *txr = adapter->tx_rings;
1256 struct ixgbe_hw *hw = &adapter->hw;
1594
1595
1596 for (int i = 0; i < adapter->num_queues; i++, txr++) {
1257
1258
1259 for (int i = 0; i < adapter->num_queues; i++, txr++) {
1597 u64 tdba = txr->txdma.dma_paddr;
1598 u32 txctrl, txdctl;
1260 u64 tdba = txr->txdma.dma_paddr;
1261 u32 txctrl, txdctl;
1599
1600 /* Set WTHRESH to 8, burst writeback */
1601 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
1602 txdctl |= (8 << 16);
1603 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
1604
1605 /* Set the HW Tx Head and Tail indices */
1262
1263 /* Set WTHRESH to 8, burst writeback */
1264 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
1265 txdctl |= (8 << 16);
1266 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
1267
1268 /* Set the HW Tx Head and Tail indices */
1606 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDH(i), 0);
1607 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDT(i), 0);
1269 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDH(i), 0);
1270 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDT(i), 0);
1608
1609 /* Set Tx Tail register */
1610 txr->tail = IXGBE_VFTDT(i);
1611
1612 /* Set Ring parameters */
1613 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(i),
1271
1272 /* Set Tx Tail register */
1273 txr->tail = IXGBE_VFTDT(i);
1274
1275 /* Set Ring parameters */
1276 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(i),
1614 (tdba & 0x00000000ffffffffULL));
1277 (tdba & 0x00000000ffffffffULL));
1615 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(i), (tdba >> 32));
1616 IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(i),
1278 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(i), (tdba >> 32));
1279 IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(i),
1617 adapter->num_tx_desc *
1618 sizeof(struct ixgbe_legacy_tx_desc));
1280 adapter->num_tx_desc * sizeof(struct ixgbe_legacy_tx_desc));
1619 txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(i));
1620 txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
1621 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i), txctrl);
1622
1623 /* Now enable */
1624 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
1625 txdctl |= IXGBE_TXDCTL_ENABLE;
1626 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
1627 }
1628
1629 return;
1281 txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(i));
1282 txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
1283 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i), txctrl);
1284
1285 /* Now enable */
1286 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
1287 txdctl |= IXGBE_TXDCTL_ENABLE;
1288 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
1289 }
1290
1291 return;
1630}
1292} /* ixv_initialize_transmit_units */
1631
1632
1293
1294
1633/*********************************************************************
1634 *
1635 * Setup receive registers and features.
1636 *
1637 **********************************************************************/
1638#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1295/************************************************************************
1296 * ixv_initialize_rss_mapping
1297 ************************************************************************/
1298static void
1299ixv_initialize_rss_mapping(struct adapter *adapter)
1300{
1301 struct ixgbe_hw *hw = &adapter->hw;
1302 u32 reta = 0, mrqc, rss_key[10];
1303 int queue_id;
1304 int i, j;
1305 u32 rss_hash_config;
1639
1306
1307 if (adapter->feat_en & IXGBE_FEATURE_RSS) {
1308 /* Fetch the configured RSS key */
1309 rss_getkey((uint8_t *)&rss_key);
1310 } else {
1311 /* set up random bits */
1312 arc4rand(&rss_key, sizeof(rss_key), 0);
1313 }
1314
1315 /* Now fill out hash function seeds */
1316 for (i = 0; i < 10; i++)
1317 IXGBE_WRITE_REG(hw, IXGBE_VFRSSRK(i), rss_key[i]);
1318
1319 /* Set up the redirection table */
1320 for (i = 0, j = 0; i < 64; i++, j++) {
1321 if (j == adapter->num_queues)
1322 j = 0;
1323
1324 if (adapter->feat_en & IXGBE_FEATURE_RSS) {
1325 /*
1326 * Fetch the RSS bucket id for the given indirection
1327 * entry. Cap it at the number of configured buckets
1328 * (which is num_queues.)
1329 */
1330 queue_id = rss_get_indirection_to_bucket(i);
1331 queue_id = queue_id % adapter->num_queues;
1332 } else
1333 queue_id = j;
1334
1335 /*
1336 * The low 8 bits are for hash value (n+0);
1337 * The next 8 bits are for hash value (n+1), etc.
1338 */
1339 reta >>= 8;
1340 reta |= ((uint32_t)queue_id) << 24;
1341 if ((i & 3) == 3) {
1342 IXGBE_WRITE_REG(hw, IXGBE_VFRETA(i >> 2), reta);
1343 reta = 0;
1344 }
1345 }
1346
1347 /* Perform hash on these packet types */
1348 if (adapter->feat_en & IXGBE_FEATURE_RSS)
1349 rss_hash_config = rss_gethashconfig();
1350 else {
1351 /*
1352 * Disable UDP - IP fragments aren't currently being handled
1353 * and so we end up with a mix of 2-tuple and 4-tuple
1354 * traffic.
1355 */
1356 rss_hash_config = RSS_HASHTYPE_RSS_IPV4
1357 | RSS_HASHTYPE_RSS_TCP_IPV4
1358 | RSS_HASHTYPE_RSS_IPV6
1359 | RSS_HASHTYPE_RSS_TCP_IPV6;
1360 }
1361
1362 mrqc = IXGBE_MRQC_RSSEN;
1363 if (rss_hash_config & RSS_HASHTYPE_RSS_IPV4)
1364 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4;
1365 if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV4)
1366 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_TCP;
1367 if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6)
1368 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6;
1369 if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6)
1370 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
1371 if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6_EX)
1372 device_printf(adapter->dev, "%s: RSS_HASHTYPE_RSS_IPV6_EX defined, but not supported\n",
1373 __func__);
1374 if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6_EX)
1375 device_printf(adapter->dev, "%s: RSS_HASHTYPE_RSS_TCP_IPV6_EX defined, but not supported\n",
1376 __func__);
1377 if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV4)
1378 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
1379 if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV4_EX)
1380 device_printf(adapter->dev, "%s: RSS_HASHTYPE_RSS_UDP_IPV4_EX defined, but not supported\n",
1381 __func__);
1382 if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV6)
1383 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
1384 if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV6_EX)
1385 device_printf(adapter->dev, "%s: RSS_HASHTYPE_RSS_UDP_IPV6_EX defined, but not supported\n",
1386 __func__);
1387 IXGBE_WRITE_REG(hw, IXGBE_VFMRQC, mrqc);
1388} /* ixv_initialize_rss_mapping */
1389
1390
1391/************************************************************************
1392 * ixv_initialize_receive_units - Setup receive registers and features.
1393 ************************************************************************/
1640static void
1641ixv_initialize_receive_units(struct adapter *adapter)
1642{
1394static void
1395ixv_initialize_receive_units(struct adapter *adapter)
1396{
1643 struct rx_ring *rxr = adapter->rx_rings;
1644 struct ixgbe_hw *hw = &adapter->hw;
1645 struct ifnet *ifp = adapter->ifp;
1646 u32 bufsz, rxcsum, psrtype;
1397 struct rx_ring *rxr = adapter->rx_rings;
1398 struct ixgbe_hw *hw = &adapter->hw;
1399 struct ifnet *ifp = adapter->ifp;
1400 u32 bufsz, rxcsum, psrtype;
1647
1648 if (ifp->if_mtu > ETHERMTU)
1649 bufsz = 4096 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1650 else
1651 bufsz = 2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1652
1401
1402 if (ifp->if_mtu > ETHERMTU)
1403 bufsz = 4096 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1404 else
1405 bufsz = 2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1406
1653 psrtype = IXGBE_PSRTYPE_TCPHDR | IXGBE_PSRTYPE_UDPHDR |
1654 IXGBE_PSRTYPE_IPV4HDR | IXGBE_PSRTYPE_IPV6HDR |
1655 IXGBE_PSRTYPE_L2HDR;
1407 psrtype = IXGBE_PSRTYPE_TCPHDR
1408 | IXGBE_PSRTYPE_UDPHDR
1409 | IXGBE_PSRTYPE_IPV4HDR
1410 | IXGBE_PSRTYPE_IPV6HDR
1411 | IXGBE_PSRTYPE_L2HDR;
1656
1412
1413 if (adapter->num_queues > 1)
1414 psrtype |= 1 << 29;
1415
1657 IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
1658
1659 /* Tell PF our max_frame size */
1416 IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
1417
1418 /* Tell PF our max_frame size */
1660 ixgbevf_rlpml_set_vf(hw, adapter->max_frame_size);
1419 if (ixgbevf_rlpml_set_vf(hw, adapter->max_frame_size) != 0) {
1420 device_printf(adapter->dev, "There is a problem with the PF setup. It is likely the receive unit for this VF will not function correctly.\n");
1421 }
1661
1662 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
1663 u64 rdba = rxr->rxdma.dma_paddr;
1664 u32 reg, rxdctl;
1665
1666 /* Disable the queue */
1667 rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
1668 rxdctl &= ~IXGBE_RXDCTL_ENABLE;

--- 4 unchanged lines hidden (view full) ---

1673 msec_delay(1);
1674 else
1675 break;
1676 }
1677 wmb();
1678 /* Setup the Base and Length of the Rx Descriptor Ring */
1679 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(i),
1680 (rdba & 0x00000000ffffffffULL));
1422
1423 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
1424 u64 rdba = rxr->rxdma.dma_paddr;
1425 u32 reg, rxdctl;
1426
1427 /* Disable the queue */
1428 rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
1429 rxdctl &= ~IXGBE_RXDCTL_ENABLE;

--- 4 unchanged lines hidden (view full) ---

1434 msec_delay(1);
1435 else
1436 break;
1437 }
1438 wmb();
1439 /* Setup the Base and Length of the Rx Descriptor Ring */
1440 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(i),
1441 (rdba & 0x00000000ffffffffULL));
1681 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(i),
1682 (rdba >> 32));
1442 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(i), (rdba >> 32));
1683 IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(i),
1684 adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
1685
1686 /* Reset the ring indices */
1687 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(rxr->me), 0);
1688 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me), 0);
1689
1690 /* Set up the SRRCTL register */

--- 9 unchanged lines hidden (view full) ---

1700
1701 /* Do the queue enabling last */
1702 rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME;
1703 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl);
1704 for (int k = 0; k < 10; k++) {
1705 if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)) &
1706 IXGBE_RXDCTL_ENABLE)
1707 break;
1443 IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(i),
1444 adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
1445
1446 /* Reset the ring indices */
1447 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(rxr->me), 0);
1448 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me), 0);
1449
1450 /* Set up the SRRCTL register */

--- 9 unchanged lines hidden (view full) ---

1460
1461 /* Do the queue enabling last */
1462 rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME;
1463 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl);
1464 for (int k = 0; k < 10; k++) {
1465 if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)) &
1466 IXGBE_RXDCTL_ENABLE)
1467 break;
1708 else
1709 msec_delay(1);
1468 msec_delay(1);
1710 }
1711 wmb();
1712
1713 /* Set the Tail Pointer */
1469 }
1470 wmb();
1471
1472 /* Set the Tail Pointer */
1714#ifdef DEV_NETMAP
1715 /*
1716 * In netmap mode, we must preserve the buffers made
1717 * available to userspace before the if_init()
1718 * (this is true by default on the TX side, because
1719 * init makes all buffers available to userspace).
1720 *
1721 * netmap_reset() and the device specific routines
1722 * (e.g. ixgbe_setup_receive_rings()) map these
1723 * buffers at the end of the NIC ring, so here we
1724 * must set the RDT (tail) register to make sure
1725 * they are not overwritten.
1726 *
1727 * In this driver the NIC ring starts at RDH = 0,
1728 * RDT points to the last slot available for reception (?),
1729 * so RDT = num_rx_desc - 1 means the whole ring is available.
1730 */
1473 /*
1474 * In netmap mode, we must preserve the buffers made
1475 * available to userspace before the if_init()
1476 * (this is true by default on the TX side, because
1477 * init makes all buffers available to userspace).
1478 *
1479 * netmap_reset() and the device specific routines
1480 * (e.g. ixgbe_setup_receive_rings()) map these
1481 * buffers at the end of the NIC ring, so here we
1482 * must set the RDT (tail) register to make sure
1483 * they are not overwritten.
1484 *
1485 * In this driver the NIC ring starts at RDH = 0,
1486 * RDT points to the last slot available for reception (?),
1487 * so RDT = num_rx_desc - 1 means the whole ring is available.
1488 */
1731 if (ifp->if_capenable & IFCAP_NETMAP) {
1489#ifdef DEV_NETMAP
1490 if ((adapter->feat_en & IXGBE_FEATURE_NETMAP) &&
1491 (ifp->if_capenable & IFCAP_NETMAP)) {
1732 struct netmap_adapter *na = NA(adapter->ifp);
1733 struct netmap_kring *kring = &na->rx_rings[i];
1734 int t = na->num_rx_desc - 1 - nm_kr_rxspace(kring);
1735
1736 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me), t);
1737 } else
1738#endif /* DEV_NETMAP */
1739 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me),
1740 adapter->num_rx_desc - 1);
1741 }
1742
1743 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1744
1492 struct netmap_adapter *na = NA(adapter->ifp);
1493 struct netmap_kring *kring = &na->rx_rings[i];
1494 int t = na->num_rx_desc - 1 - nm_kr_rxspace(kring);
1495
1496 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me), t);
1497 } else
1498#endif /* DEV_NETMAP */
1499 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me),
1500 adapter->num_rx_desc - 1);
1501 }
1502
1503 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1504
1505 ixv_initialize_rss_mapping(adapter);
1506
1507 if (adapter->num_queues > 1) {
1508 /* RSS and RX IPP Checksum are mutually exclusive */
1509 rxcsum |= IXGBE_RXCSUM_PCSD;
1510 }
1511
1745 if (ifp->if_capenable & IFCAP_RXCSUM)
1746 rxcsum |= IXGBE_RXCSUM_PCSD;
1747
1748 if (!(rxcsum & IXGBE_RXCSUM_PCSD))
1749 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1750
1751 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
1752
1753 return;
1512 if (ifp->if_capenable & IFCAP_RXCSUM)
1513 rxcsum |= IXGBE_RXCSUM_PCSD;
1514
1515 if (!(rxcsum & IXGBE_RXCSUM_PCSD))
1516 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1517
1518 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
1519
1520 return;
1754}
1521} /* ixv_initialize_receive_units */
1755
1522
1523/************************************************************************
1524 * ixv_setup_vlan_support
1525 ************************************************************************/
1756static void
1757ixv_setup_vlan_support(struct adapter *adapter)
1758{
1759 struct ixgbe_hw *hw = &adapter->hw;
1526static void
1527ixv_setup_vlan_support(struct adapter *adapter)
1528{
1529 struct ixgbe_hw *hw = &adapter->hw;
1760 u32 ctrl, vid, vfta, retry;
1761 struct rx_ring *rxr;
1530 u32 ctrl, vid, vfta, retry;
1762
1763 /*
1531
1532 /*
1764 ** We get here thru init_locked, meaning
1765 ** a soft reset, this has already cleared
1766 ** the VFTA and other state, so if there
1767 ** have been no vlan's registered do nothing.
1768 */
1533 * We get here thru init_locked, meaning
1534 * a soft reset, this has already cleared
1535 * the VFTA and other state, so if there
1536 * have been no vlan's registered do nothing.
1537 */
1769 if (adapter->num_vlans == 0)
1770 return;
1771
1772 /* Enable the queues */
1773 for (int i = 0; i < adapter->num_queues; i++) {
1774 ctrl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
1775 ctrl |= IXGBE_RXDCTL_VME;
1776 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), ctrl);
1777 /*
1778 * Let Rx path know that it needs to store VLAN tag
1779 * as part of extra mbuf info.
1780 */
1538 if (adapter->num_vlans == 0)
1539 return;
1540
1541 /* Enable the queues */
1542 for (int i = 0; i < adapter->num_queues; i++) {
1543 ctrl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
1544 ctrl |= IXGBE_RXDCTL_VME;
1545 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), ctrl);
1546 /*
1547 * Let Rx path know that it needs to store VLAN tag
1548 * as part of extra mbuf info.
1549 */
1781 rxr = &adapter->rx_rings[i];
1782 rxr->vtag_strip = TRUE;
1550 adapter->rx_rings[i].vtag_strip = TRUE;
1783 }
1784
1785 /*
1551 }
1552
1553 /*
1786 ** A soft reset zero's out the VFTA, so
1787 ** we need to repopulate it now.
1788 */
1554 * A soft reset zero's out the VFTA, so
1555 * we need to repopulate it now.
1556 */
1789 for (int i = 0; i < IXGBE_VFTA_SIZE; i++) {
1790 if (ixv_shadow_vfta[i] == 0)
1791 continue;
1792 vfta = ixv_shadow_vfta[i];
1793 /*
1557 for (int i = 0; i < IXGBE_VFTA_SIZE; i++) {
1558 if (ixv_shadow_vfta[i] == 0)
1559 continue;
1560 vfta = ixv_shadow_vfta[i];
1561 /*
1794 ** Reconstruct the vlan id's
1795 ** based on the bits set in each
1796 ** of the array ints.
1797 */
1562 * Reconstruct the vlan id's
1563 * based on the bits set in each
1564 * of the array ints.
1565 */
1798 for (int j = 0; j < 32; j++) {
1799 retry = 0;
1800 if ((vfta & (1 << j)) == 0)
1801 continue;
1802 vid = (i * 32) + j;
1803 /* Call the shared code mailbox routine */
1566 for (int j = 0; j < 32; j++) {
1567 retry = 0;
1568 if ((vfta & (1 << j)) == 0)
1569 continue;
1570 vid = (i * 32) + j;
1571 /* Call the shared code mailbox routine */
1804 while (ixgbe_set_vfta(hw, vid, 0, TRUE)) {
1572 while (hw->mac.ops.set_vfta(hw, vid, 0, TRUE, FALSE)) {
1805 if (++retry > 5)
1806 break;
1807 }
1808 }
1809 }
1573 if (++retry > 5)
1574 break;
1575 }
1576 }
1577 }
1810}
1578} /* ixv_setup_vlan_support */
1811
1579
1812/*
1813** This routine is run via an vlan config EVENT,
1814** it enables us to use the HW Filter table since
1815** we can get the vlan id. This just creates the
1816** entry in the soft version of the VFTA, init will
1817** repopulate the real table.
1818*/
1580/************************************************************************
1581 * ixv_register_vlan
1582 *
1583 * Run via a vlan config EVENT, it enables us to use the
1584 * HW Filter table since we can get the vlan id. This just
1585 * creates the entry in the soft version of the VFTA, init
1586 * will repopulate the real table.
1587 ************************************************************************/
1819static void
1820ixv_register_vlan(void *arg, struct ifnet *ifp, u16 vtag)
1821{
1588static void
1589ixv_register_vlan(void *arg, struct ifnet *ifp, u16 vtag)
1590{
1822 struct adapter *adapter = ifp->if_softc;
1823 u16 index, bit;
1591 struct adapter *adapter = ifp->if_softc;
1592 u16 index, bit;
1824
1825 if (ifp->if_softc != arg) /* Not our event */
1826 return;
1827
1828 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
1829 return;
1830
1831 IXGBE_CORE_LOCK(adapter);
1832 index = (vtag >> 5) & 0x7F;
1833 bit = vtag & 0x1F;
1834 ixv_shadow_vfta[index] |= (1 << bit);
1835 ++adapter->num_vlans;
1836 /* Re-init to load the changes */
1837 ixv_init_locked(adapter);
1838 IXGBE_CORE_UNLOCK(adapter);
1593
1594 if (ifp->if_softc != arg) /* Not our event */
1595 return;
1596
1597 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
1598 return;
1599
1600 IXGBE_CORE_LOCK(adapter);
1601 index = (vtag >> 5) & 0x7F;
1602 bit = vtag & 0x1F;
1603 ixv_shadow_vfta[index] |= (1 << bit);
1604 ++adapter->num_vlans;
1605 /* Re-init to load the changes */
1606 ixv_init_locked(adapter);
1607 IXGBE_CORE_UNLOCK(adapter);
1839}
1608} /* ixv_register_vlan */
1840
1609
1841/*
1842** This routine is run via an vlan
1843** unconfig EVENT, remove our entry
1844** in the soft vfta.
1845*/
1610/************************************************************************
1611 * ixv_unregister_vlan
1612 *
1613 * Run via a vlan unconfig EVENT, remove our entry
1614 * in the soft vfta.
1615 ************************************************************************/
1846static void
1847ixv_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag)
1848{
1616static void
1617ixv_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag)
1618{
1849 struct adapter *adapter = ifp->if_softc;
1850 u16 index, bit;
1619 struct adapter *adapter = ifp->if_softc;
1620 u16 index, bit;
1851
1852 if (ifp->if_softc != arg)
1853 return;
1854
1621
1622 if (ifp->if_softc != arg)
1623 return;
1624
1855 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
1625 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
1856 return;
1857
1858 IXGBE_CORE_LOCK(adapter);
1859 index = (vtag >> 5) & 0x7F;
1860 bit = vtag & 0x1F;
1861 ixv_shadow_vfta[index] &= ~(1 << bit);
1862 --adapter->num_vlans;
1863 /* Re-init to load the changes */
1864 ixv_init_locked(adapter);
1865 IXGBE_CORE_UNLOCK(adapter);
1626 return;
1627
1628 IXGBE_CORE_LOCK(adapter);
1629 index = (vtag >> 5) & 0x7F;
1630 bit = vtag & 0x1F;
1631 ixv_shadow_vfta[index] &= ~(1 << bit);
1632 --adapter->num_vlans;
1633 /* Re-init to load the changes */
1634 ixv_init_locked(adapter);
1635 IXGBE_CORE_UNLOCK(adapter);
1866}
1636} /* ixv_unregister_vlan */
1867
1637
1638/************************************************************************
1639 * ixv_enable_intr
1640 ************************************************************************/
1868static void
1869ixv_enable_intr(struct adapter *adapter)
1870{
1871 struct ixgbe_hw *hw = &adapter->hw;
1872 struct ix_queue *que = adapter->queues;
1641static void
1642ixv_enable_intr(struct adapter *adapter)
1643{
1644 struct ixgbe_hw *hw = &adapter->hw;
1645 struct ix_queue *que = adapter->queues;
1873 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
1646 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
1874
1875
1876 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
1877
1878 mask = IXGBE_EIMS_ENABLE_MASK;
1879 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
1880 IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, mask);
1881
1647
1648
1649 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
1650
1651 mask = IXGBE_EIMS_ENABLE_MASK;
1652 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
1653 IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, mask);
1654
1882 for (int i = 0; i < adapter->num_queues; i++, que++)
1655 for (int i = 0; i < adapter->num_queues; i++, que++)
1883 ixv_enable_queue(adapter, que->msix);
1884
1885 IXGBE_WRITE_FLUSH(hw);
1886
1887 return;
1656 ixv_enable_queue(adapter, que->msix);
1657
1658 IXGBE_WRITE_FLUSH(hw);
1659
1660 return;
1888}
1661} /* ixv_enable_intr */
1889
1662
1663/************************************************************************
1664 * ixv_disable_intr
1665 ************************************************************************/
1890static void
1891ixv_disable_intr(struct adapter *adapter)
1892{
1893 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIAC, 0);
1894 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIMC, ~0);
1895 IXGBE_WRITE_FLUSH(&adapter->hw);
1666static void
1667ixv_disable_intr(struct adapter *adapter)
1668{
1669 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIAC, 0);
1670 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIMC, ~0);
1671 IXGBE_WRITE_FLUSH(&adapter->hw);
1672
1896 return;
1673 return;
1897}
1674} /* ixv_disable_intr */
1898
1675
1899/*
1900** Setup the correct IVAR register for a particular MSIX interrupt
1901** - entry is the register array entry
1902** - vector is the MSIX vector for this queue
1903** - type is RX/TX/MISC
1904*/
1676/************************************************************************
1677 * ixv_set_ivar
1678 *
1679 * Setup the correct IVAR register for a particular MSI-X interrupt
1680 * - entry is the register array entry
1681 * - vector is the MSI-X vector for this queue
1682 * - type is RX/TX/MISC
1683 ************************************************************************/
1905static void
1906ixv_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
1907{
1908 struct ixgbe_hw *hw = &adapter->hw;
1684static void
1685ixv_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
1686{
1687 struct ixgbe_hw *hw = &adapter->hw;
1909 u32 ivar, index;
1688 u32 ivar, index;
1910
1911 vector |= IXGBE_IVAR_ALLOC_VAL;
1912
1913 if (type == -1) { /* MISC IVAR */
1914 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
1915 ivar &= ~0xFF;
1916 ivar |= vector;
1917 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
1689
1690 vector |= IXGBE_IVAR_ALLOC_VAL;
1691
1692 if (type == -1) { /* MISC IVAR */
1693 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
1694 ivar &= ~0xFF;
1695 ivar |= vector;
1696 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
1918 } else { /* RX/TX IVARS */
1697 } else { /* RX/TX IVARS */
1919 index = (16 * (entry & 1)) + (8 * type);
1920 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(entry >> 1));
1921 ivar &= ~(0xFF << index);
1922 ivar |= (vector << index);
1923 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(entry >> 1), ivar);
1924 }
1698 index = (16 * (entry & 1)) + (8 * type);
1699 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(entry >> 1));
1700 ivar &= ~(0xFF << index);
1701 ivar |= (vector << index);
1702 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(entry >> 1), ivar);
1703 }
1925}
1704} /* ixv_set_ivar */
1926
1705
1706/************************************************************************
1707 * ixv_configure_ivars
1708 ************************************************************************/
1927static void
1928ixv_configure_ivars(struct adapter *adapter)
1929{
1709static void
1710ixv_configure_ivars(struct adapter *adapter)
1711{
1930 struct ix_queue *que = adapter->queues;
1712 struct ix_queue *que = adapter->queues;
1931
1713
1932 for (int i = 0; i < adapter->num_queues; i++, que++) {
1714 for (int i = 0; i < adapter->num_queues; i++, que++) {
1933 /* First the RX queue entry */
1715 /* First the RX queue entry */
1934 ixv_set_ivar(adapter, i, que->msix, 0);
1716 ixv_set_ivar(adapter, i, que->msix, 0);
1935 /* ... and the TX */
1936 ixv_set_ivar(adapter, i, que->msix, 1);
1937 /* Set an initial value in EITR */
1717 /* ... and the TX */
1718 ixv_set_ivar(adapter, i, que->msix, 1);
1719 /* Set an initial value in EITR */
1938 IXGBE_WRITE_REG(&adapter->hw,
1939 IXGBE_VTEITR(que->msix), IXV_EITR_DEFAULT);
1720 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEITR(que->msix),
1721 IXGBE_EITR_DEFAULT);
1940 }
1941
1942 /* For the mailbox interrupt */
1722 }
1723
1724 /* For the mailbox interrupt */
1943 ixv_set_ivar(adapter, 1, adapter->vector, -1);
1944}
1725 ixv_set_ivar(adapter, 1, adapter->vector, -1);
1726} /* ixv_configure_ivars */
1945
1946
1727
1728
1947/*
1948** Tasklet handler for MSIX MBX interrupts
1949** - do outside interrupt since it might sleep
1950*/
1951static void
1952ixv_handle_mbx(void *context, int pending)
1729/************************************************************************
1730 * ixv_get_counter
1731 ************************************************************************/
1732static uint64_t
1733ixv_get_counter(struct ifnet *ifp, ift_counter cnt)
1953{
1734{
1954 struct adapter *adapter = context;
1735 struct adapter *adapter;
1955
1736
1956 ixgbe_check_link(&adapter->hw,
1957 &adapter->link_speed, &adapter->link_up, 0);
1958 ixv_update_link_status(adapter);
1959}
1737 adapter = if_getsoftc(ifp);
1960
1738
1961/*
1962** The VF stats registers never have a truly virgin
1963** starting point, so this routine tries to make an
1964** artificial one, marking ground zero on attach as
1965** it were.
1966*/
1739 switch (cnt) {
1740 case IFCOUNTER_IPACKETS:
1741 return (adapter->ipackets);
1742 case IFCOUNTER_OPACKETS:
1743 return (adapter->opackets);
1744 case IFCOUNTER_IBYTES:
1745 return (adapter->ibytes);
1746 case IFCOUNTER_OBYTES:
1747 return (adapter->obytes);
1748 case IFCOUNTER_IMCASTS:
1749 return (adapter->imcasts);
1750 default:
1751 return (if_get_counter_default(ifp, cnt));
1752 }
1753} /* ixv_get_counter */
1754
1755/************************************************************************
1756 * ixv_save_stats
1757 *
1758 * The VF stats registers never have a truly virgin
1759 * starting point, so this routine tries to make an
1760 * artificial one, marking ground zero on attach as
1761 * it were.
1762 ************************************************************************/
1967static void
1968ixv_save_stats(struct adapter *adapter)
1969{
1970 if (adapter->stats.vf.vfgprc || adapter->stats.vf.vfgptc) {
1971 adapter->stats.vf.saved_reset_vfgprc +=
1972 adapter->stats.vf.vfgprc - adapter->stats.vf.base_vfgprc;
1973 adapter->stats.vf.saved_reset_vfgptc +=
1974 adapter->stats.vf.vfgptc - adapter->stats.vf.base_vfgptc;
1975 adapter->stats.vf.saved_reset_vfgorc +=
1976 adapter->stats.vf.vfgorc - adapter->stats.vf.base_vfgorc;
1977 adapter->stats.vf.saved_reset_vfgotc +=
1978 adapter->stats.vf.vfgotc - adapter->stats.vf.base_vfgotc;
1979 adapter->stats.vf.saved_reset_vfmprc +=
1980 adapter->stats.vf.vfmprc - adapter->stats.vf.base_vfmprc;
1981 }
1763static void
1764ixv_save_stats(struct adapter *adapter)
1765{
1766 if (adapter->stats.vf.vfgprc || adapter->stats.vf.vfgptc) {
1767 adapter->stats.vf.saved_reset_vfgprc +=
1768 adapter->stats.vf.vfgprc - adapter->stats.vf.base_vfgprc;
1769 adapter->stats.vf.saved_reset_vfgptc +=
1770 adapter->stats.vf.vfgptc - adapter->stats.vf.base_vfgptc;
1771 adapter->stats.vf.saved_reset_vfgorc +=
1772 adapter->stats.vf.vfgorc - adapter->stats.vf.base_vfgorc;
1773 adapter->stats.vf.saved_reset_vfgotc +=
1774 adapter->stats.vf.vfgotc - adapter->stats.vf.base_vfgotc;
1775 adapter->stats.vf.saved_reset_vfmprc +=
1776 adapter->stats.vf.vfmprc - adapter->stats.vf.base_vfmprc;
1777 }
1982}
1983
1778} /* ixv_save_stats */
1779
1780/************************************************************************
1781 * ixv_init_stats
1782 ************************************************************************/
1984static void
1985ixv_init_stats(struct adapter *adapter)
1986{
1987 struct ixgbe_hw *hw = &adapter->hw;
1783static void
1784ixv_init_stats(struct adapter *adapter)
1785{
1786 struct ixgbe_hw *hw = &adapter->hw;
1988
1787
1989 adapter->stats.vf.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
1990 adapter->stats.vf.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
1991 adapter->stats.vf.last_vfgorc |=
1992 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
1993
1994 adapter->stats.vf.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
1995 adapter->stats.vf.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
1996 adapter->stats.vf.last_vfgotc |=
1997 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
1998
1999 adapter->stats.vf.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
2000
2001 adapter->stats.vf.base_vfgprc = adapter->stats.vf.last_vfgprc;
2002 adapter->stats.vf.base_vfgorc = adapter->stats.vf.last_vfgorc;
2003 adapter->stats.vf.base_vfgptc = adapter->stats.vf.last_vfgptc;
2004 adapter->stats.vf.base_vfgotc = adapter->stats.vf.last_vfgotc;
2005 adapter->stats.vf.base_vfmprc = adapter->stats.vf.last_vfmprc;
1788 adapter->stats.vf.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
1789 adapter->stats.vf.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
1790 adapter->stats.vf.last_vfgorc |=
1791 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
1792
1793 adapter->stats.vf.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
1794 adapter->stats.vf.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
1795 adapter->stats.vf.last_vfgotc |=
1796 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
1797
1798 adapter->stats.vf.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
1799
1800 adapter->stats.vf.base_vfgprc = adapter->stats.vf.last_vfgprc;
1801 adapter->stats.vf.base_vfgorc = adapter->stats.vf.last_vfgorc;
1802 adapter->stats.vf.base_vfgptc = adapter->stats.vf.last_vfgptc;
1803 adapter->stats.vf.base_vfgotc = adapter->stats.vf.last_vfgotc;
1804 adapter->stats.vf.base_vfmprc = adapter->stats.vf.last_vfmprc;
2006}
1805} /* ixv_init_stats */
2007
1806
2008#define UPDATE_STAT_32(reg, last, count) \
2009{ \
2010 u32 current = IXGBE_READ_REG(hw, reg); \
2011 if (current < last) \
2012 count += 0x100000000LL; \
2013 last = current; \
2014 count &= 0xFFFFFFFF00000000LL; \
2015 count |= current; \
1807#define UPDATE_STAT_32(reg, last, count) \
1808{ \
1809 u32 current = IXGBE_READ_REG(hw, reg); \
1810 if (current < last) \
1811 count += 0x100000000LL; \
1812 last = current; \
1813 count &= 0xFFFFFFFF00000000LL; \
1814 count |= current; \
2016}
2017
1815}
1816
2018#define UPDATE_STAT_36(lsb, msb, last, count) \
2019{ \
2020 u64 cur_lsb = IXGBE_READ_REG(hw, lsb); \
2021 u64 cur_msb = IXGBE_READ_REG(hw, msb); \
2022 u64 current = ((cur_msb << 32) | cur_lsb); \
2023 if (current < last) \
2024 count += 0x1000000000LL; \
2025 last = current; \
2026 count &= 0xFFFFFFF000000000LL; \
2027 count |= current; \
1817#define UPDATE_STAT_36(lsb, msb, last, count) \
1818{ \
1819 u64 cur_lsb = IXGBE_READ_REG(hw, lsb); \
1820 u64 cur_msb = IXGBE_READ_REG(hw, msb); \
1821 u64 current = ((cur_msb << 32) | cur_lsb); \
1822 if (current < last) \
1823 count += 0x1000000000LL; \
1824 last = current; \
1825 count &= 0xFFFFFFF000000000LL; \
1826 count |= current; \
2028}
2029
1827}
1828
2030/*
2031** ixv_update_stats - Update the board statistics counters.
2032*/
1829/************************************************************************
1830 * ixv_update_stats - Update the board statistics counters.
1831 ************************************************************************/
2033void
2034ixv_update_stats(struct adapter *adapter)
2035{
1832void
1833ixv_update_stats(struct adapter *adapter)
1834{
2036 struct ixgbe_hw *hw = &adapter->hw;
1835 struct ixgbe_hw *hw = &adapter->hw;
1836 struct ixgbevf_hw_stats *stats = &adapter->stats.vf;
2037
2038 UPDATE_STAT_32(IXGBE_VFGPRC, adapter->stats.vf.last_vfgprc,
2039 adapter->stats.vf.vfgprc);
2040 UPDATE_STAT_32(IXGBE_VFGPTC, adapter->stats.vf.last_vfgptc,
2041 adapter->stats.vf.vfgptc);
2042 UPDATE_STAT_36(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
2043 adapter->stats.vf.last_vfgorc, adapter->stats.vf.vfgorc);
2044 UPDATE_STAT_36(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
2045 adapter->stats.vf.last_vfgotc, adapter->stats.vf.vfgotc);
2046 UPDATE_STAT_32(IXGBE_VFMPRC, adapter->stats.vf.last_vfmprc,
2047 adapter->stats.vf.vfmprc);
1837
1838 UPDATE_STAT_32(IXGBE_VFGPRC, adapter->stats.vf.last_vfgprc,
1839 adapter->stats.vf.vfgprc);
1840 UPDATE_STAT_32(IXGBE_VFGPTC, adapter->stats.vf.last_vfgptc,
1841 adapter->stats.vf.vfgptc);
1842 UPDATE_STAT_36(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
1843 adapter->stats.vf.last_vfgorc, adapter->stats.vf.vfgorc);
1844 UPDATE_STAT_36(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
1845 adapter->stats.vf.last_vfgotc, adapter->stats.vf.vfgotc);
1846 UPDATE_STAT_32(IXGBE_VFMPRC, adapter->stats.vf.last_vfmprc,
1847 adapter->stats.vf.vfmprc);
2048}
2049
1848
2050/*
2051 * Add statistic sysctls for the VF.
2052 */
1849 /* Fill out the OS statistics structure */
1850 IXGBE_SET_IPACKETS(adapter, stats->vfgprc);
1851 IXGBE_SET_OPACKETS(adapter, stats->vfgptc);
1852 IXGBE_SET_IBYTES(adapter, stats->vfgorc);
1853 IXGBE_SET_OBYTES(adapter, stats->vfgotc);
1854 IXGBE_SET_IMCASTS(adapter, stats->vfmprc);
1855} /* ixv_update_stats */
1856
1857/************************************************************************
1858 * ixv_add_stats_sysctls - Add statistic sysctls for the VF.
1859 ************************************************************************/
2053static void
2054ixv_add_stats_sysctls(struct adapter *adapter)
2055{
1860static void
1861ixv_add_stats_sysctls(struct adapter *adapter)
1862{
2056 device_t dev = adapter->dev;
2057 struct ix_queue *que = &adapter->queues[0];
2058 struct tx_ring *txr = que->txr;
2059 struct rx_ring *rxr = que->rxr;
2060
2061 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
2062 struct sysctl_oid *tree = device_get_sysctl_tree(dev);
2063 struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
1863 device_t dev = adapter->dev;
1864 struct tx_ring *txr = adapter->tx_rings;
1865 struct rx_ring *rxr = adapter->rx_rings;
1866 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
1867 struct sysctl_oid *tree = device_get_sysctl_tree(dev);
1868 struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
2064 struct ixgbevf_hw_stats *stats = &adapter->stats.vf;
1869 struct ixgbevf_hw_stats *stats = &adapter->stats.vf;
1870 struct sysctl_oid *stat_node, *queue_node;
1871 struct sysctl_oid_list *stat_list, *queue_list;
2065
1872
2066 struct sysctl_oid *stat_node, *queue_node;
2067 struct sysctl_oid_list *stat_list, *queue_list;
1873#define QUEUE_NAME_LEN 32
1874 char namebuf[QUEUE_NAME_LEN];
2068
2069 /* Driver Statistics */
2070 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped",
1875
1876 /* Driver Statistics */
1877 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped",
2071 CTLFLAG_RD, &adapter->dropped_pkts,
2072 "Driver dropped packets");
1878 CTLFLAG_RD, &adapter->dropped_pkts, "Driver dropped packets");
2073 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_defrag_failed",
1879 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_defrag_failed",
2074 CTLFLAG_RD, &adapter->mbuf_defrag_failed,
2075 "m_defrag() failed");
1880 CTLFLAG_RD, &adapter->mbuf_defrag_failed, "m_defrag() failed");
2076 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events",
1881 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events",
2077 CTLFLAG_RD, &adapter->watchdog_events,
2078 "Watchdog timeouts");
1882 CTLFLAG_RD, &adapter->watchdog_events, "Watchdog timeouts");
1883 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "link_irq",
1884 CTLFLAG_RD, &adapter->link_irq, "Link MSI-X IRQ Handled");
2079
1885
1886 for (int i = 0; i < adapter->num_queues; i++, txr++) {
1887 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
1888 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
1889 CTLFLAG_RD, NULL, "Queue Name");
1890 queue_list = SYSCTL_CHILDREN(queue_node);
1891
1892 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs",
1893 CTLFLAG_RD, &(adapter->queues[i].irqs), "IRQs on queue");
1894 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "no_tx_dma_setup",
1895 CTLFLAG_RD, &(txr->no_tx_dma_setup),
1896 "Driver Tx DMA failure in Tx");
1897 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_no_desc",
1898 CTLFLAG_RD, &(txr->no_desc_avail),
1899 "Not-enough-descriptors count: TX");
1900 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets",
1901 CTLFLAG_RD, &(txr->total_packets), "TX Packets");
1902 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "br_drops",
1903 CTLFLAG_RD, &(txr->br->br_drops),
1904 "Packets dropped in buf_ring");
1905 }
1906
1907 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
1908 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
1909 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
1910 CTLFLAG_RD, NULL, "Queue Name");
1911 queue_list = SYSCTL_CHILDREN(queue_node);
1912
1913 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets",
1914 CTLFLAG_RD, &(rxr->rx_packets), "RX packets");
1915 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes",
1916 CTLFLAG_RD, &(rxr->rx_bytes), "RX bytes");
1917 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_discarded",
1918 CTLFLAG_RD, &(rxr->rx_discarded), "Discarded RX packets");
1919 }
1920
2080 stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac",
1921 stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac",
2081 CTLFLAG_RD, NULL,
2082 "VF Statistics (read from HW registers)");
1922 CTLFLAG_RD, NULL, "VF Statistics (read from HW registers)");
2083 stat_list = SYSCTL_CHILDREN(stat_node);
2084
2085 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_rcvd",
1923 stat_list = SYSCTL_CHILDREN(stat_node);
1924
1925 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_rcvd",
2086 CTLFLAG_RD, &stats->vfgprc,
2087 "Good Packets Received");
1926 CTLFLAG_RD, &stats->vfgprc, "Good Packets Received");
2088 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_rcvd",
1927 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_rcvd",
2089 CTLFLAG_RD, &stats->vfgorc,
2090 "Good Octets Received");
1928 CTLFLAG_RD, &stats->vfgorc, "Good Octets Received");
2091 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_rcvd",
1929 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_rcvd",
2092 CTLFLAG_RD, &stats->vfmprc,
2093 "Multicast Packets Received");
1930 CTLFLAG_RD, &stats->vfmprc, "Multicast Packets Received");
2094 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd",
1931 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd",
2095 CTLFLAG_RD, &stats->vfgptc,
2096 "Good Packets Transmitted");
1932 CTLFLAG_RD, &stats->vfgptc, "Good Packets Transmitted");
2097 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_txd",
1933 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_txd",
2098 CTLFLAG_RD, &stats->vfgotc,
2099 "Good Octets Transmitted");
1934 CTLFLAG_RD, &stats->vfgotc, "Good Octets Transmitted");
1935} /* ixv_add_stats_sysctls */
2100
1936
2101 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "que",
2102 CTLFLAG_RD, NULL,
2103 "Queue Statistics (collected by SW)");
2104 queue_list = SYSCTL_CHILDREN(queue_node);
2105
2106 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs",
2107 CTLFLAG_RD, &(que->irqs),
2108 "IRQs on queue");
2109 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_irqs",
2110 CTLFLAG_RD, &(rxr->rx_irq),
2111 "RX irqs on queue");
2112 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets",
2113 CTLFLAG_RD, &(rxr->rx_packets),
2114 "RX packets");
2115 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes",
2116 CTLFLAG_RD, &(rxr->rx_bytes),
2117 "RX bytes");
2118 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_discarded",
2119 CTLFLAG_RD, &(rxr->rx_discarded),
2120 "Discarded RX packets");
2121
2122 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets",
2123 CTLFLAG_RD, &(txr->total_packets),
2124 "TX Packets");
2125
2126 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_no_desc",
2127 CTLFLAG_RD, &(txr->no_desc_avail),
2128 "# of times not enough descriptors were available during TX");
2129}
2130
1937/************************************************************************
1938 * ixv_set_sysctl_value
1939 ************************************************************************/
2131static void
2132ixv_set_sysctl_value(struct adapter *adapter, const char *name,
2133 const char *description, int *limit, int value)
2134{
2135 *limit = value;
2136 SYSCTL_ADD_INT(device_get_sysctl_ctx(adapter->dev),
2137 SYSCTL_CHILDREN(device_get_sysctl_tree(adapter->dev)),
2138 OID_AUTO, name, CTLFLAG_RW, limit, value, description);
1940static void
1941ixv_set_sysctl_value(struct adapter *adapter, const char *name,
1942 const char *description, int *limit, int value)
1943{
1944 *limit = value;
1945 SYSCTL_ADD_INT(device_get_sysctl_ctx(adapter->dev),
1946 SYSCTL_CHILDREN(device_get_sysctl_tree(adapter->dev)),
1947 OID_AUTO, name, CTLFLAG_RW, limit, value, description);
2139}
1948} /* ixv_set_sysctl_value */
2140
1949
2141/**********************************************************************
1950/************************************************************************
1951 * ixv_print_debug_info
2142 *
1952 *
2143 * This routine is called only when em_display_debug_stats is enabled.
2144 * This routine provides a way to take a look at important statistics
2145 * maintained by the driver and hardware.
2146 *
2147 **********************************************************************/
1953 * Called only when em_display_debug_stats is enabled.
1954 * Provides a way to take a look at important statistics
1955 * maintained by the driver and hardware.
1956 ************************************************************************/
2148static void
2149ixv_print_debug_info(struct adapter *adapter)
2150{
1957static void
1958ixv_print_debug_info(struct adapter *adapter)
1959{
2151 device_t dev = adapter->dev;
2152 struct ixgbe_hw *hw = &adapter->hw;
2153 struct ix_queue *que = adapter->queues;
2154 struct rx_ring *rxr;
2155 struct tx_ring *txr;
2156 struct lro_ctrl *lro;
1960 device_t dev = adapter->dev;
1961 struct ixgbe_hw *hw = &adapter->hw;
1962 struct ix_queue *que = adapter->queues;
1963 struct rx_ring *rxr;
1964 struct tx_ring *txr;
1965 struct lro_ctrl *lro;
2157
1966
2158 device_printf(dev,"Error Byte Count = %u \n",
2159 IXGBE_READ_REG(hw, IXGBE_ERRBC));
1967 device_printf(dev, "Error Byte Count = %u \n",
1968 IXGBE_READ_REG(hw, IXGBE_ERRBC));
2160
1969
2161 for (int i = 0; i < adapter->num_queues; i++, que++) {
2162 txr = que->txr;
2163 rxr = que->rxr;
2164 lro = &rxr->lro;
2165 device_printf(dev,"QUE(%d) IRQs Handled: %lu\n",
2166 que->msix, (long)que->irqs);
2167 device_printf(dev,"RX(%d) Packets Received: %lld\n",
2168 rxr->me, (long long)rxr->rx_packets);
2169 device_printf(dev,"RX(%d) Bytes Received: %lu\n",
2170 rxr->me, (long)rxr->rx_bytes);
2171 device_printf(dev,"RX(%d) LRO Queued= %lld\n",
2172 rxr->me, (long long)lro->lro_queued);
2173 device_printf(dev,"RX(%d) LRO Flushed= %lld\n",
2174 rxr->me, (long long)lro->lro_flushed);
2175 device_printf(dev,"TX(%d) Packets Sent: %lu\n",
2176 txr->me, (long)txr->total_packets);
2177 device_printf(dev,"TX(%d) NO Desc Avail: %lu\n",
2178 txr->me, (long)txr->no_desc_avail);
2179 }
1970 for (int i = 0; i < adapter->num_queues; i++, que++) {
1971 txr = que->txr;
1972 rxr = que->rxr;
1973 lro = &rxr->lro;
1974 device_printf(dev, "QUE(%d) IRQs Handled: %lu\n",
1975 que->msix, (long)que->irqs);
1976 device_printf(dev, "RX(%d) Packets Received: %lld\n",
1977 rxr->me, (long long)rxr->rx_packets);
1978 device_printf(dev, "RX(%d) Bytes Received: %lu\n",
1979 rxr->me, (long)rxr->rx_bytes);
1980 device_printf(dev, "RX(%d) LRO Queued= %lld\n",
1981 rxr->me, (long long)lro->lro_queued);
1982 device_printf(dev, "RX(%d) LRO Flushed= %lld\n",
1983 rxr->me, (long long)lro->lro_flushed);
1984 device_printf(dev, "TX(%d) Packets Sent: %lu\n",
1985 txr->me, (long)txr->total_packets);
1986 device_printf(dev, "TX(%d) NO Desc Avail: %lu\n",
1987 txr->me, (long)txr->no_desc_avail);
1988 }
2180
1989
2181 device_printf(dev,"MBX IRQ Handled: %lu\n",
2182 (long)adapter->link_irq);
2183 return;
2184}
1990 device_printf(dev, "MBX IRQ Handled: %lu\n", (long)adapter->link_irq);
1991} /* ixv_print_debug_info */
2185
1992
1993/************************************************************************
1994 * ixv_sysctl_debug
1995 ************************************************************************/
2186static int
2187ixv_sysctl_debug(SYSCTL_HANDLER_ARGS)
2188{
1996static int
1997ixv_sysctl_debug(SYSCTL_HANDLER_ARGS)
1998{
2189 int error, result;
2190 struct adapter *adapter;
1999 struct adapter *adapter;
2000 int error, result;
2191
2192 result = -1;
2193 error = sysctl_handle_int(oidp, &result, 0, req);
2194
2195 if (error || !req->newptr)
2196 return (error);
2197
2198 if (result == 1) {
2001
2002 result = -1;
2003 error = sysctl_handle_int(oidp, &result, 0, req);
2004
2005 if (error || !req->newptr)
2006 return (error);
2007
2008 if (result == 1) {
2199 adapter = (struct adapter *) arg1;
2009 adapter = (struct adapter *)arg1;
2200 ixv_print_debug_info(adapter);
2201 }
2010 ixv_print_debug_info(adapter);
2011 }
2012
2202 return error;
2013 return error;
2203}
2014} /* ixv_sysctl_debug */
2204
2015
2016/************************************************************************
2017 * ixv_init_device_features
2018 ************************************************************************/
2019static void
2020ixv_init_device_features(struct adapter *adapter)
2021{
2022 adapter->feat_cap = IXGBE_FEATURE_NETMAP
2023 | IXGBE_FEATURE_VF
2024 | IXGBE_FEATURE_RSS
2025 | IXGBE_FEATURE_LEGACY_TX;
2026
2027 /* A tad short on feature flags for VFs, atm. */
2028 switch (adapter->hw.mac.type) {
2029 case ixgbe_mac_82599_vf:
2030 break;
2031 case ixgbe_mac_X540_vf:
2032 break;
2033 case ixgbe_mac_X550_vf:
2034 case ixgbe_mac_X550EM_x_vf:
2035 case ixgbe_mac_X550EM_a_vf:
2036 adapter->feat_cap |= IXGBE_FEATURE_NEEDS_CTXD;
2037 break;
2038 default:
2039 break;
2040 }
2041
2042 /* Enabled by default... */
2043 /* Is a virtual function (VF) */
2044 if (adapter->feat_cap & IXGBE_FEATURE_VF)
2045 adapter->feat_en |= IXGBE_FEATURE_VF;
2046 /* Netmap */
2047 if (adapter->feat_cap & IXGBE_FEATURE_NETMAP)
2048 adapter->feat_en |= IXGBE_FEATURE_NETMAP;
2049 /* Receive-Side Scaling (RSS) */
2050 if (adapter->feat_cap & IXGBE_FEATURE_RSS)
2051 adapter->feat_en |= IXGBE_FEATURE_RSS;
2052 /* Needs advanced context descriptor regardless of offloads req'd */
2053 if (adapter->feat_cap & IXGBE_FEATURE_NEEDS_CTXD)
2054 adapter->feat_en |= IXGBE_FEATURE_NEEDS_CTXD;
2055
2056 /* Enabled via sysctl... */
2057 /* Legacy (single queue) transmit */
2058 if ((adapter->feat_cap & IXGBE_FEATURE_LEGACY_TX) &&
2059 ixv_enable_legacy_tx)
2060 adapter->feat_en |= IXGBE_FEATURE_LEGACY_TX;
2061} /* ixv_init_device_features */
2062
2063/************************************************************************
2064 * ixv_shutdown - Shutdown entry point
2065 ************************************************************************/
2066static int
2067ixv_shutdown(device_t dev)
2068{
2069 struct adapter *adapter = device_get_softc(dev);
2070 IXGBE_CORE_LOCK(adapter);
2071 ixv_stop(adapter);
2072 IXGBE_CORE_UNLOCK(adapter);
2073
2074 return (0);
2075} /* ixv_shutdown */
2076
2077
2078/************************************************************************
2079 * ixv_ioctl - Ioctl entry point
2080 *
2081 * Called when the user wants to configure the interface.
2082 *
2083 * return 0 on success, positive on failure
2084 ************************************************************************/
2085static int
2086ixv_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
2087{
2088 struct adapter *adapter = ifp->if_softc;
2089 struct ifreq *ifr = (struct ifreq *)data;
2090#if defined(INET) || defined(INET6)
2091 struct ifaddr *ifa = (struct ifaddr *)data;
2092 bool avoid_reset = FALSE;
2093#endif
2094 int error = 0;
2095
2096 switch (command) {
2097
2098 case SIOCSIFADDR:
2099#ifdef INET
2100 if (ifa->ifa_addr->sa_family == AF_INET)
2101 avoid_reset = TRUE;
2102#endif
2103#ifdef INET6
2104 if (ifa->ifa_addr->sa_family == AF_INET6)
2105 avoid_reset = TRUE;
2106#endif
2107#if defined(INET) || defined(INET6)
2108 /*
2109 * Calling init results in link renegotiation,
2110 * so we avoid doing it when possible.
2111 */
2112 if (avoid_reset) {
2113 ifp->if_flags |= IFF_UP;
2114 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
2115 ixv_init(adapter);
2116 if (!(ifp->if_flags & IFF_NOARP))
2117 arp_ifinit(ifp, ifa);
2118 } else
2119 error = ether_ioctl(ifp, command, data);
2120 break;
2121#endif
2122 case SIOCSIFMTU:
2123 IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
2124 if (ifr->ifr_mtu > IXGBE_MAX_MTU) {
2125 error = EINVAL;
2126 } else {
2127 IXGBE_CORE_LOCK(adapter);
2128 ifp->if_mtu = ifr->ifr_mtu;
2129 adapter->max_frame_size = ifp->if_mtu + IXGBE_MTU_HDR;
2130 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2131 ixv_init_locked(adapter);
2132 IXGBE_CORE_UNLOCK(adapter);
2133 }
2134 break;
2135 case SIOCSIFFLAGS:
2136 IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
2137 IXGBE_CORE_LOCK(adapter);
2138 if (ifp->if_flags & IFF_UP) {
2139 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
2140 ixv_init_locked(adapter);
2141 } else
2142 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2143 ixv_stop(adapter);
2144 adapter->if_flags = ifp->if_flags;
2145 IXGBE_CORE_UNLOCK(adapter);
2146 break;
2147 case SIOCADDMULTI:
2148 case SIOCDELMULTI:
2149 IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
2150 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2151 IXGBE_CORE_LOCK(adapter);
2152 ixv_disable_intr(adapter);
2153 ixv_set_multi(adapter);
2154 ixv_enable_intr(adapter);
2155 IXGBE_CORE_UNLOCK(adapter);
2156 }
2157 break;
2158 case SIOCSIFMEDIA:
2159 case SIOCGIFMEDIA:
2160 IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
2161 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
2162 break;
2163 case SIOCSIFCAP:
2164 {
2165 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
2166 IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
2167 if (mask & IFCAP_HWCSUM)
2168 ifp->if_capenable ^= IFCAP_HWCSUM;
2169 if (mask & IFCAP_TSO4)
2170 ifp->if_capenable ^= IFCAP_TSO4;
2171 if (mask & IFCAP_LRO)
2172 ifp->if_capenable ^= IFCAP_LRO;
2173 if (mask & IFCAP_VLAN_HWTAGGING)
2174 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
2175 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2176 IXGBE_CORE_LOCK(adapter);
2177 ixv_init_locked(adapter);
2178 IXGBE_CORE_UNLOCK(adapter);
2179 }
2180 VLAN_CAPABILITIES(ifp);
2181 break;
2182 }
2183
2184 default:
2185 IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
2186 error = ether_ioctl(ifp, command, data);
2187 break;
2188 }
2189
2190 return (error);
2191} /* ixv_ioctl */
2192
2193/************************************************************************
2194 * ixv_init
2195 ************************************************************************/
2196static void
2197ixv_init(void *arg)
2198{
2199 struct adapter *adapter = arg;
2200
2201 IXGBE_CORE_LOCK(adapter);
2202 ixv_init_locked(adapter);
2203 IXGBE_CORE_UNLOCK(adapter);
2204
2205 return;
2206} /* ixv_init */
2207
2208
2209/************************************************************************
2210 * ixv_handle_que
2211 ************************************************************************/
2212static void
2213ixv_handle_que(void *context, int pending)
2214{
2215 struct ix_queue *que = context;
2216 struct adapter *adapter = que->adapter;
2217 struct tx_ring *txr = que->txr;
2218 struct ifnet *ifp = adapter->ifp;
2219 bool more;
2220
2221 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2222 more = ixgbe_rxeof(que);
2223 IXGBE_TX_LOCK(txr);
2224 ixgbe_txeof(txr);
2225 if (!ixv_ring_empty(ifp, txr->br))
2226 ixv_start_locked(ifp, txr);
2227 IXGBE_TX_UNLOCK(txr);
2228 if (more) {
2229 taskqueue_enqueue(que->tq, &que->que_task);
2230 return;
2231 }
2232 }
2233
2234 /* Re-enable this interrupt */
2235 ixv_enable_queue(adapter, que->msix);
2236
2237 return;
2238} /* ixv_handle_que */
2239
2240/************************************************************************
2241 * ixv_allocate_msix - Setup MSI-X Interrupt resources and handlers
2242 ************************************************************************/
2243static int
2244ixv_allocate_msix(struct adapter *adapter)
2245{
2246 device_t dev = adapter->dev;
2247 struct ix_queue *que = adapter->queues;
2248 struct tx_ring *txr = adapter->tx_rings;
2249 int error, msix_ctrl, rid, vector = 0;
2250
2251 for (int i = 0; i < adapter->num_queues; i++, vector++, que++, txr++) {
2252 rid = vector + 1;
2253 que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2254 RF_SHAREABLE | RF_ACTIVE);
2255 if (que->res == NULL) {
2256 device_printf(dev, "Unable to allocate bus resource: que interrupt [%d]\n",
2257 vector);
2258 return (ENXIO);
2259 }
2260 /* Set the handler function */
2261 error = bus_setup_intr(dev, que->res,
2262 INTR_TYPE_NET | INTR_MPSAFE, NULL,
2263 ixv_msix_que, que, &que->tag);
2264 if (error) {
2265 que->res = NULL;
2266 device_printf(dev, "Failed to register QUE handler");
2267 return (error);
2268 }
2269#if __FreeBSD_version >= 800504
2270 bus_describe_intr(dev, que->res, que->tag, "que %d", i);
2271#endif
2272 que->msix = vector;
2273 adapter->active_queues |= (u64)(1 << que->msix);
2274 /*
2275 * Bind the MSI-X vector, and thus the
2276 * ring to the corresponding CPU.
2277 */
2278 if (adapter->num_queues > 1)
2279 bus_bind_intr(dev, que->res, i);
2280 TASK_INIT(&txr->txq_task, 0, ixgbe_deferred_mq_start, txr);
2281 TASK_INIT(&que->que_task, 0, ixv_handle_que, que);
2282 que->tq = taskqueue_create_fast("ixv_que", M_NOWAIT,
2283 taskqueue_thread_enqueue, &que->tq);
2284 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que",
2285 device_get_nameunit(adapter->dev));
2286 }
2287
2288 /* and Mailbox */
2289 rid = vector + 1;
2290 adapter->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2291 RF_SHAREABLE | RF_ACTIVE);
2292 if (!adapter->res) {
2293 device_printf(dev,
2294 "Unable to allocate bus resource: MBX interrupt [%d]\n",
2295 rid);
2296 return (ENXIO);
2297 }
2298 /* Set the mbx handler function */
2299 error = bus_setup_intr(dev, adapter->res, INTR_TYPE_NET | INTR_MPSAFE,
2300 NULL, ixv_msix_mbx, adapter, &adapter->tag);
2301 if (error) {
2302 adapter->res = NULL;
2303 device_printf(dev, "Failed to register LINK handler");
2304 return (error);
2305 }
2306#if __FreeBSD_version >= 800504
2307 bus_describe_intr(dev, adapter->res, adapter->tag, "mbx");
2308#endif
2309 adapter->vector = vector;
2310 /* Tasklets for Mailbox */
2311 TASK_INIT(&adapter->link_task, 0, ixv_handle_link, adapter);
2312 adapter->tq = taskqueue_create_fast("ixv_mbx", M_NOWAIT,
2313 taskqueue_thread_enqueue, &adapter->tq);
2314 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s mbxq",
2315 device_get_nameunit(adapter->dev));
2316 /*
2317 * Due to a broken design QEMU will fail to properly
2318 * enable the guest for MSI-X unless the vectors in
2319 * the table are all set up, so we must rewrite the
2320 * ENABLE in the MSI-X control register again at this
2321 * point to cause it to successfully initialize us.
2322 */
2323 if (adapter->hw.mac.type == ixgbe_mac_82599_vf) {
2324 pci_find_cap(dev, PCIY_MSIX, &rid);
2325 rid += PCIR_MSIX_CTRL;
2326 msix_ctrl = pci_read_config(dev, rid, 2);
2327 msix_ctrl |= PCIM_MSIXCTRL_MSIX_ENABLE;
2328 pci_write_config(dev, rid, msix_ctrl, 2);
2329 }
2330
2331 return (0);
2332} /* ixv_allocate_msix */
2333
2334/************************************************************************
2335 * ixv_configure_interrupts - Setup MSI-X resources
2336 *
2337 * Note: The VF device MUST use MSI-X, there is no fallback.
2338 ************************************************************************/
2339static int
2340ixv_configure_interrupts(struct adapter *adapter)
2341{
2342 device_t dev = adapter->dev;
2343 int rid, want, msgs;
2344
2345 /* Must have at least 2 MSI-X vectors */
2346 msgs = pci_msix_count(dev);
2347 if (msgs < 2)
2348 goto out;
2349 rid = PCIR_BAR(3);
2350 adapter->msix_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
2351 RF_ACTIVE);
2352 if (adapter->msix_mem == NULL) {
2353 device_printf(adapter->dev, "Unable to map MSI-X table \n");
2354 goto out;
2355 }
2356
2357 /*
2358 * Want vectors for the queues,
2359 * plus an additional for mailbox.
2360 */
2361 want = adapter->num_queues + 1;
2362 if (want > msgs) {
2363 want = msgs;
2364 adapter->num_queues = msgs - 1;
2365 } else
2366 msgs = want;
2367 if ((pci_alloc_msix(dev, &msgs) == 0) && (msgs == want)) {
2368 device_printf(adapter->dev,
2369 "Using MSI-X interrupts with %d vectors\n", want);
2370 /* reflect correct sysctl value */
2371 ixv_num_queues = adapter->num_queues;
2372
2373 return (0);
2374 }
2375 /* Release in case alloc was insufficient */
2376 pci_release_msi(dev);
2377out:
2378 if (adapter->msix_mem != NULL) {
2379 bus_release_resource(dev, SYS_RES_MEMORY, rid,
2380 adapter->msix_mem);
2381 adapter->msix_mem = NULL;
2382 }
2383 device_printf(adapter->dev, "MSI-X config error\n");
2384
2385 return (ENXIO);
2386} /* ixv_configure_interrupts */
2387
2388
2389/************************************************************************
2390 * ixv_handle_link - Tasklet handler for MSI-X MBX interrupts
2391 *
2392 * Done outside of interrupt context since the driver might sleep
2393 ************************************************************************/
2394static void
2395ixv_handle_link(void *context, int pending)
2396{
2397 struct adapter *adapter = context;
2398
2399 adapter->hw.mac.ops.check_link(&adapter->hw, &adapter->link_speed,
2400 &adapter->link_up, FALSE);
2401 ixv_update_link_status(adapter);
2402} /* ixv_handle_link */
2403
2404/************************************************************************
2405 * ixv_check_link - Used in the local timer to poll for link changes
2406 ************************************************************************/
2407static void
2408ixv_check_link(struct adapter *adapter)
2409{
2410 adapter->hw.mac.get_link_status = TRUE;
2411
2412 adapter->hw.mac.ops.check_link(&adapter->hw, &adapter->link_speed,
2413 &adapter->link_up, FALSE);
2414 ixv_update_link_status(adapter);
2415} /* ixv_check_link */
2416