ixv.c revision 1.12 1 1.1 dyoung /******************************************************************************
2 1.1 dyoung
3 1.8 msaitoh Copyright (c) 2001-2013, Intel Corporation
4 1.1 dyoung All rights reserved.
5 1.1 dyoung
6 1.1 dyoung Redistribution and use in source and binary forms, with or without
7 1.1 dyoung modification, are permitted provided that the following conditions are met:
8 1.1 dyoung
9 1.1 dyoung 1. Redistributions of source code must retain the above copyright notice,
10 1.1 dyoung this list of conditions and the following disclaimer.
11 1.1 dyoung
12 1.1 dyoung 2. Redistributions in binary form must reproduce the above copyright
13 1.1 dyoung notice, this list of conditions and the following disclaimer in the
14 1.1 dyoung documentation and/or other materials provided with the distribution.
15 1.1 dyoung
16 1.1 dyoung 3. Neither the name of the Intel Corporation nor the names of its
17 1.1 dyoung contributors may be used to endorse or promote products derived from
18 1.1 dyoung this software without specific prior written permission.
19 1.1 dyoung
20 1.1 dyoung THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 1.1 dyoung AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.1 dyoung IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.1 dyoung ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 1.1 dyoung LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 dyoung CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 dyoung SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 dyoung INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 dyoung CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 dyoung ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 dyoung POSSIBILITY OF SUCH DAMAGE.
31 1.1 dyoung
32 1.1 dyoung ******************************************************************************/
33 1.10 msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixv.c 275358 2014-12-01 11:45:24Z hselasky $*/
34 1.12 msaitoh /*$NetBSD: ixv.c,v 1.12 2015/08/13 10:03:38 msaitoh Exp $*/
35 1.1 dyoung
36 1.1 dyoung #include "opt_inet.h"
37 1.4 msaitoh #include "opt_inet6.h"
38 1.1 dyoung
39 1.1 dyoung #include "ixv.h"
40 1.1 dyoung
41 1.1 dyoung /*********************************************************************
42 1.1 dyoung * Driver version
43 1.1 dyoung *********************************************************************/
44 1.6 msaitoh char ixv_driver_version[] = "1.1.4";
45 1.1 dyoung
46 1.1 dyoung /*********************************************************************
47 1.1 dyoung * PCI Device ID Table
48 1.1 dyoung *
49 1.1 dyoung * Used by probe to select devices to load on
50 1.1 dyoung * Last field stores an index into ixv_strings
51 1.1 dyoung * Last entry must be all 0s
52 1.1 dyoung *
53 1.1 dyoung * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
54 1.1 dyoung *********************************************************************/
55 1.1 dyoung
56 1.1 dyoung static ixv_vendor_info_t ixv_vendor_info_array[] =
57 1.1 dyoung {
58 1.1 dyoung {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF, 0, 0, 0},
59 1.5 msaitoh {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF, 0, 0, 0},
60 1.1 dyoung /* required last entry */
61 1.1 dyoung {0, 0, 0, 0, 0}
62 1.1 dyoung };
63 1.1 dyoung
64 1.1 dyoung /*********************************************************************
65 1.1 dyoung * Table of branding strings
66 1.1 dyoung *********************************************************************/
67 1.1 dyoung
68 1.3 msaitoh static const char *ixv_strings[] = {
69 1.1 dyoung "Intel(R) PRO/10GbE Virtual Function Network Driver"
70 1.1 dyoung };
71 1.1 dyoung
72 1.1 dyoung /*********************************************************************
73 1.1 dyoung * Function prototypes
74 1.1 dyoung *********************************************************************/
75 1.3 msaitoh static int ixv_probe(device_t, cfdata_t, void *);
76 1.3 msaitoh static void ixv_attach(device_t, device_t, void *);
77 1.3 msaitoh static int ixv_detach(device_t, int);
78 1.3 msaitoh #if 0
79 1.1 dyoung static int ixv_shutdown(device_t);
80 1.3 msaitoh #endif
81 1.1 dyoung #if __FreeBSD_version < 800000
82 1.1 dyoung static void ixv_start(struct ifnet *);
83 1.1 dyoung static void ixv_start_locked(struct tx_ring *, struct ifnet *);
84 1.1 dyoung #else
85 1.1 dyoung static int ixv_mq_start(struct ifnet *, struct mbuf *);
86 1.1 dyoung static int ixv_mq_start_locked(struct ifnet *,
87 1.1 dyoung struct tx_ring *, struct mbuf *);
88 1.1 dyoung static void ixv_qflush(struct ifnet *);
89 1.1 dyoung #endif
90 1.3 msaitoh static int ixv_ioctl(struct ifnet *, u_long, void *);
91 1.3 msaitoh static int ixv_init(struct ifnet *);
92 1.1 dyoung static void ixv_init_locked(struct adapter *);
93 1.1 dyoung static void ixv_stop(void *);
94 1.1 dyoung static void ixv_media_status(struct ifnet *, struct ifmediareq *);
95 1.1 dyoung static int ixv_media_change(struct ifnet *);
96 1.1 dyoung static void ixv_identify_hardware(struct adapter *);
97 1.3 msaitoh static int ixv_allocate_pci_resources(struct adapter *,
98 1.3 msaitoh const struct pci_attach_args *);
99 1.11 msaitoh static int ixv_allocate_msix(struct adapter *,
100 1.11 msaitoh const struct pci_attach_args *);
101 1.1 dyoung static int ixv_allocate_queues(struct adapter *);
102 1.1 dyoung static int ixv_setup_msix(struct adapter *);
103 1.1 dyoung static void ixv_free_pci_resources(struct adapter *);
104 1.1 dyoung static void ixv_local_timer(void *);
105 1.1 dyoung static void ixv_setup_interface(device_t, struct adapter *);
106 1.1 dyoung static void ixv_config_link(struct adapter *);
107 1.1 dyoung
108 1.1 dyoung static int ixv_allocate_transmit_buffers(struct tx_ring *);
109 1.1 dyoung static int ixv_setup_transmit_structures(struct adapter *);
110 1.1 dyoung static void ixv_setup_transmit_ring(struct tx_ring *);
111 1.1 dyoung static void ixv_initialize_transmit_units(struct adapter *);
112 1.1 dyoung static void ixv_free_transmit_structures(struct adapter *);
113 1.1 dyoung static void ixv_free_transmit_buffers(struct tx_ring *);
114 1.1 dyoung
115 1.1 dyoung static int ixv_allocate_receive_buffers(struct rx_ring *);
116 1.1 dyoung static int ixv_setup_receive_structures(struct adapter *);
117 1.1 dyoung static int ixv_setup_receive_ring(struct rx_ring *);
118 1.1 dyoung static void ixv_initialize_receive_units(struct adapter *);
119 1.1 dyoung static void ixv_free_receive_structures(struct adapter *);
120 1.1 dyoung static void ixv_free_receive_buffers(struct rx_ring *);
121 1.1 dyoung
122 1.1 dyoung static void ixv_enable_intr(struct adapter *);
123 1.1 dyoung static void ixv_disable_intr(struct adapter *);
124 1.1 dyoung static bool ixv_txeof(struct tx_ring *);
125 1.1 dyoung static bool ixv_rxeof(struct ix_queue *, int);
126 1.3 msaitoh static void ixv_rx_checksum(u32, struct mbuf *, u32,
127 1.3 msaitoh struct ixgbevf_hw_stats *);
128 1.1 dyoung static void ixv_set_multi(struct adapter *);
129 1.1 dyoung static void ixv_update_link_status(struct adapter *);
130 1.1 dyoung static void ixv_refresh_mbufs(struct rx_ring *, int);
131 1.3 msaitoh static int ixv_xmit(struct tx_ring *, struct mbuf *);
132 1.3 msaitoh static int ixv_sysctl_stats(SYSCTLFN_PROTO);
133 1.3 msaitoh static int ixv_sysctl_debug(SYSCTLFN_PROTO);
134 1.3 msaitoh static int ixv_set_flowcntl(SYSCTLFN_PROTO);
135 1.1 dyoung static int ixv_dma_malloc(struct adapter *, bus_size_t,
136 1.1 dyoung struct ixv_dma_alloc *, int);
137 1.1 dyoung static void ixv_dma_free(struct adapter *, struct ixv_dma_alloc *);
138 1.1 dyoung static void ixv_add_rx_process_limit(struct adapter *, const char *,
139 1.1 dyoung const char *, int *, int);
140 1.3 msaitoh static u32 ixv_tx_ctx_setup(struct tx_ring *, struct mbuf *);
141 1.1 dyoung static bool ixv_tso_setup(struct tx_ring *, struct mbuf *, u32 *);
142 1.1 dyoung static void ixv_set_ivar(struct adapter *, u8, u8, s8);
143 1.1 dyoung static void ixv_configure_ivars(struct adapter *);
144 1.1 dyoung static u8 * ixv_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
145 1.1 dyoung
146 1.1 dyoung static void ixv_setup_vlan_support(struct adapter *);
147 1.3 msaitoh #if 0
148 1.1 dyoung static void ixv_register_vlan(void *, struct ifnet *, u16);
149 1.1 dyoung static void ixv_unregister_vlan(void *, struct ifnet *, u16);
150 1.3 msaitoh #endif
151 1.1 dyoung
152 1.1 dyoung static void ixv_save_stats(struct adapter *);
153 1.1 dyoung static void ixv_init_stats(struct adapter *);
154 1.1 dyoung static void ixv_update_stats(struct adapter *);
155 1.1 dyoung
156 1.1 dyoung static __inline void ixv_rx_discard(struct rx_ring *, int);
157 1.1 dyoung static __inline void ixv_rx_input(struct rx_ring *, struct ifnet *,
158 1.1 dyoung struct mbuf *, u32);
159 1.1 dyoung
160 1.1 dyoung /* The MSI/X Interrupt handlers */
161 1.11 msaitoh static int ixv_msix_que(void *);
162 1.11 msaitoh static int ixv_msix_mbx(void *);
163 1.1 dyoung
164 1.1 dyoung /* Deferred interrupt tasklets */
165 1.3 msaitoh static void ixv_handle_que(void *);
166 1.3 msaitoh static void ixv_handle_mbx(void *);
167 1.3 msaitoh
168 1.3 msaitoh const struct sysctlnode *ixv_sysctl_instance(struct adapter *);
169 1.3 msaitoh static ixv_vendor_info_t *ixv_lookup(const struct pci_attach_args *);
170 1.1 dyoung
171 1.1 dyoung /*********************************************************************
172 1.1 dyoung * FreeBSD Device Interface Entry Points
173 1.1 dyoung *********************************************************************/
174 1.1 dyoung
175 1.3 msaitoh CFATTACH_DECL3_NEW(ixv, sizeof(struct adapter),
176 1.3 msaitoh ixv_probe, ixv_attach, ixv_detach, NULL, NULL, NULL,
177 1.3 msaitoh DVF_DETACH_SHUTDOWN);
178 1.3 msaitoh
179 1.3 msaitoh # if 0
180 1.1 dyoung static device_method_t ixv_methods[] = {
181 1.1 dyoung /* Device interface */
182 1.1 dyoung DEVMETHOD(device_probe, ixv_probe),
183 1.1 dyoung DEVMETHOD(device_attach, ixv_attach),
184 1.1 dyoung DEVMETHOD(device_detach, ixv_detach),
185 1.1 dyoung DEVMETHOD(device_shutdown, ixv_shutdown),
186 1.8 msaitoh DEVMETHOD_END
187 1.1 dyoung };
188 1.3 msaitoh #endif
189 1.1 dyoung
190 1.1 dyoung #if 0
191 1.1 dyoung static driver_t ixv_driver = {
192 1.1 dyoung "ix", ixv_methods, sizeof(struct adapter),
193 1.1 dyoung };
194 1.1 dyoung
195 1.1 dyoung extern devclass_t ixgbe_devclass;
196 1.1 dyoung DRIVER_MODULE(ixv, pci, ixv_driver, ixgbe_devclass, 0, 0);
197 1.1 dyoung MODULE_DEPEND(ixv, pci, 1, 1, 1);
198 1.1 dyoung MODULE_DEPEND(ixv, ether, 1, 1, 1);
199 1.1 dyoung #endif
200 1.1 dyoung
201 1.1 dyoung /*
202 1.1 dyoung ** TUNEABLE PARAMETERS:
203 1.1 dyoung */
204 1.1 dyoung
205 1.1 dyoung /*
206 1.1 dyoung ** AIM: Adaptive Interrupt Moderation
207 1.1 dyoung ** which means that the interrupt rate
208 1.1 dyoung ** is varied over time based on the
209 1.1 dyoung ** traffic for that interrupt vector
210 1.1 dyoung */
211 1.1 dyoung static int ixv_enable_aim = FALSE;
212 1.1 dyoung #define TUNABLE_INT(__x, __y)
213 1.1 dyoung TUNABLE_INT("hw.ixv.enable_aim", &ixv_enable_aim);
214 1.1 dyoung
215 1.1 dyoung /* How many packets rxeof tries to clean at a time */
216 1.1 dyoung static int ixv_rx_process_limit = 128;
217 1.1 dyoung TUNABLE_INT("hw.ixv.rx_process_limit", &ixv_rx_process_limit);
218 1.1 dyoung
219 1.1 dyoung /* Flow control setting, default to full */
220 1.1 dyoung static int ixv_flow_control = ixgbe_fc_full;
221 1.1 dyoung TUNABLE_INT("hw.ixv.flow_control", &ixv_flow_control);
222 1.1 dyoung
223 1.1 dyoung /*
224 1.1 dyoung * Header split: this causes the hardware to DMA
225 1.1 dyoung * the header into a seperate mbuf from the payload,
226 1.1 dyoung * it can be a performance win in some workloads, but
227 1.1 dyoung * in others it actually hurts, its off by default.
228 1.1 dyoung */
229 1.4 msaitoh static int ixv_header_split = FALSE;
230 1.1 dyoung TUNABLE_INT("hw.ixv.hdr_split", &ixv_header_split);
231 1.1 dyoung
232 1.1 dyoung /*
233 1.1 dyoung ** Number of TX descriptors per ring,
234 1.1 dyoung ** setting higher than RX as this seems
235 1.1 dyoung ** the better performing choice.
236 1.1 dyoung */
237 1.1 dyoung static int ixv_txd = DEFAULT_TXD;
238 1.1 dyoung TUNABLE_INT("hw.ixv.txd", &ixv_txd);
239 1.1 dyoung
240 1.1 dyoung /* Number of RX descriptors per ring */
241 1.1 dyoung static int ixv_rxd = DEFAULT_RXD;
242 1.1 dyoung TUNABLE_INT("hw.ixv.rxd", &ixv_rxd);
243 1.1 dyoung
244 1.1 dyoung /*
245 1.1 dyoung ** Shadow VFTA table, this is needed because
246 1.1 dyoung ** the real filter table gets cleared during
247 1.1 dyoung ** a soft reset and we need to repopulate it.
248 1.1 dyoung */
249 1.1 dyoung static u32 ixv_shadow_vfta[VFTA_SIZE];
250 1.1 dyoung
251 1.3 msaitoh /* Keep running tab on them for sanity check */
252 1.3 msaitoh static int ixv_total_ports;
253 1.3 msaitoh
254 1.1 dyoung /*********************************************************************
255 1.1 dyoung * Device identification routine
256 1.1 dyoung *
257 1.1 dyoung * ixv_probe determines if the driver should be loaded on
258 1.1 dyoung * adapter based on PCI vendor/device id of the adapter.
259 1.1 dyoung *
260 1.4 msaitoh * return 1 on success, 0 on failure
261 1.1 dyoung *********************************************************************/
262 1.1 dyoung
263 1.1 dyoung static int
264 1.3 msaitoh ixv_probe(device_t dev, cfdata_t cf, void *aux)
265 1.3 msaitoh {
266 1.3 msaitoh const struct pci_attach_args *pa = aux;
267 1.3 msaitoh
268 1.3 msaitoh return (ixv_lookup(pa) != NULL) ? 1 : 0;
269 1.3 msaitoh }
270 1.3 msaitoh
271 1.3 msaitoh static ixv_vendor_info_t *
272 1.3 msaitoh ixv_lookup(const struct pci_attach_args *pa)
273 1.1 dyoung {
274 1.3 msaitoh pcireg_t subid;
275 1.1 dyoung ixv_vendor_info_t *ent;
276 1.1 dyoung
277 1.3 msaitoh INIT_DEBUGOUT("ixv_probe: begin");
278 1.1 dyoung
279 1.3 msaitoh if (PCI_VENDOR(pa->pa_id) != IXGBE_INTEL_VENDOR_ID)
280 1.3 msaitoh return NULL;
281 1.1 dyoung
282 1.3 msaitoh subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
283 1.1 dyoung
284 1.3 msaitoh for (ent = ixv_vendor_info_array; ent->vendor_id != 0; ent++) {
285 1.3 msaitoh if ((PCI_VENDOR(pa->pa_id) == ent->vendor_id) &&
286 1.3 msaitoh (PCI_PRODUCT(pa->pa_id) == ent->device_id) &&
287 1.1 dyoung
288 1.3 msaitoh ((PCI_SUBSYS_VENDOR(subid) == ent->subvendor_id) ||
289 1.1 dyoung (ent->subvendor_id == 0)) &&
290 1.1 dyoung
291 1.3 msaitoh ((PCI_SUBSYS_ID(subid) == ent->subdevice_id) ||
292 1.1 dyoung (ent->subdevice_id == 0))) {
293 1.3 msaitoh ++ixv_total_ports;
294 1.3 msaitoh return ent;
295 1.1 dyoung }
296 1.1 dyoung }
297 1.3 msaitoh return NULL;
298 1.3 msaitoh }
299 1.3 msaitoh
300 1.3 msaitoh
301 1.3 msaitoh static void
302 1.3 msaitoh ixv_sysctl_attach(struct adapter *adapter)
303 1.3 msaitoh {
304 1.3 msaitoh struct sysctllog **log;
305 1.3 msaitoh const struct sysctlnode *rnode, *cnode;
306 1.3 msaitoh device_t dev;
307 1.3 msaitoh
308 1.3 msaitoh dev = adapter->dev;
309 1.3 msaitoh log = &adapter->sysctllog;
310 1.3 msaitoh
311 1.3 msaitoh if ((rnode = ixv_sysctl_instance(adapter)) == NULL) {
312 1.3 msaitoh aprint_error_dev(dev, "could not create sysctl root\n");
313 1.3 msaitoh return;
314 1.3 msaitoh }
315 1.3 msaitoh
316 1.3 msaitoh if (sysctl_createv(log, 0, &rnode, &cnode,
317 1.3 msaitoh CTLFLAG_READWRITE, CTLTYPE_INT,
318 1.3 msaitoh "stats", SYSCTL_DESCR("Statistics"),
319 1.3 msaitoh ixv_sysctl_stats, 0, (void *)adapter, 0, CTL_CREATE, CTL_EOL) != 0)
320 1.3 msaitoh aprint_error_dev(dev, "could not create sysctl\n");
321 1.3 msaitoh
322 1.3 msaitoh if (sysctl_createv(log, 0, &rnode, &cnode,
323 1.3 msaitoh CTLFLAG_READWRITE, CTLTYPE_INT,
324 1.3 msaitoh "debug", SYSCTL_DESCR("Debug Info"),
325 1.3 msaitoh ixv_sysctl_debug, 0, (void *)adapter, 0, CTL_CREATE, CTL_EOL) != 0)
326 1.3 msaitoh aprint_error_dev(dev, "could not create sysctl\n");
327 1.3 msaitoh
328 1.3 msaitoh if (sysctl_createv(log, 0, &rnode, &cnode,
329 1.3 msaitoh CTLFLAG_READWRITE, CTLTYPE_INT,
330 1.3 msaitoh "flow_control", SYSCTL_DESCR("Flow Control"),
331 1.3 msaitoh ixv_set_flowcntl, 0, (void *)adapter, 0, CTL_CREATE, CTL_EOL) != 0)
332 1.3 msaitoh aprint_error_dev(dev, "could not create sysctl\n");
333 1.3 msaitoh
334 1.3 msaitoh /* XXX This is an *instance* sysctl controlling a *global* variable.
335 1.3 msaitoh * XXX It's that way in the FreeBSD driver that this derives from.
336 1.3 msaitoh */
337 1.3 msaitoh if (sysctl_createv(log, 0, &rnode, &cnode,
338 1.3 msaitoh CTLFLAG_READWRITE, CTLTYPE_INT,
339 1.3 msaitoh "enable_aim", SYSCTL_DESCR("Interrupt Moderation"),
340 1.3 msaitoh NULL, 0, &ixv_enable_aim, 0, CTL_CREATE, CTL_EOL) != 0)
341 1.3 msaitoh aprint_error_dev(dev, "could not create sysctl\n");
342 1.1 dyoung }
343 1.1 dyoung
344 1.1 dyoung /*********************************************************************
345 1.1 dyoung * Device initialization routine
346 1.1 dyoung *
347 1.1 dyoung * The attach entry point is called when the driver is being loaded.
348 1.1 dyoung * This routine identifies the type of hardware, allocates all resources
349 1.1 dyoung * and initializes the hardware.
350 1.1 dyoung *
351 1.1 dyoung * return 0 on success, positive on failure
352 1.1 dyoung *********************************************************************/
353 1.1 dyoung
354 1.3 msaitoh static void
355 1.3 msaitoh ixv_attach(device_t parent, device_t dev, void *aux)
356 1.1 dyoung {
357 1.1 dyoung struct adapter *adapter;
358 1.1 dyoung struct ixgbe_hw *hw;
359 1.1 dyoung int error = 0;
360 1.3 msaitoh ixv_vendor_info_t *ent;
361 1.3 msaitoh const struct pci_attach_args *pa = aux;
362 1.1 dyoung
363 1.1 dyoung INIT_DEBUGOUT("ixv_attach: begin");
364 1.1 dyoung
365 1.1 dyoung /* Allocate, clear, and link in our adapter structure */
366 1.3 msaitoh adapter = device_private(dev);
367 1.1 dyoung adapter->dev = adapter->osdep.dev = dev;
368 1.1 dyoung hw = &adapter->hw;
369 1.1 dyoung
370 1.3 msaitoh ent = ixv_lookup(pa);
371 1.3 msaitoh
372 1.3 msaitoh KASSERT(ent != NULL);
373 1.3 msaitoh
374 1.3 msaitoh aprint_normal(": %s, Version - %s\n",
375 1.3 msaitoh ixv_strings[ent->index], ixv_driver_version);
376 1.3 msaitoh
377 1.1 dyoung /* Core Lock Init*/
378 1.3 msaitoh IXV_CORE_LOCK_INIT(adapter, device_xname(dev));
379 1.1 dyoung
380 1.1 dyoung /* SYSCTL APIs */
381 1.3 msaitoh ixv_sysctl_attach(adapter);
382 1.1 dyoung
383 1.1 dyoung /* Set up the timer callout */
384 1.3 msaitoh callout_init(&adapter->timer, 0);
385 1.1 dyoung
386 1.1 dyoung /* Determine hardware revision */
387 1.1 dyoung ixv_identify_hardware(adapter);
388 1.1 dyoung
389 1.1 dyoung /* Do base PCI setup - map BAR0 */
390 1.3 msaitoh if (ixv_allocate_pci_resources(adapter, pa)) {
391 1.3 msaitoh aprint_error_dev(dev, "Allocation of PCI resources failed\n");
392 1.1 dyoung error = ENXIO;
393 1.1 dyoung goto err_out;
394 1.1 dyoung }
395 1.1 dyoung
396 1.1 dyoung /* Do descriptor calc and sanity checks */
397 1.1 dyoung if (((ixv_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
398 1.1 dyoung ixv_txd < MIN_TXD || ixv_txd > MAX_TXD) {
399 1.3 msaitoh aprint_error_dev(dev, "TXD config issue, using default!\n");
400 1.1 dyoung adapter->num_tx_desc = DEFAULT_TXD;
401 1.1 dyoung } else
402 1.1 dyoung adapter->num_tx_desc = ixv_txd;
403 1.1 dyoung
404 1.1 dyoung if (((ixv_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
405 1.10 msaitoh ixv_rxd < MIN_RXD || ixv_rxd > MAX_RXD) {
406 1.3 msaitoh aprint_error_dev(dev, "RXD config issue, using default!\n");
407 1.1 dyoung adapter->num_rx_desc = DEFAULT_RXD;
408 1.1 dyoung } else
409 1.1 dyoung adapter->num_rx_desc = ixv_rxd;
410 1.1 dyoung
411 1.1 dyoung /* Allocate our TX/RX Queues */
412 1.1 dyoung if (ixv_allocate_queues(adapter)) {
413 1.1 dyoung error = ENOMEM;
414 1.1 dyoung goto err_out;
415 1.1 dyoung }
416 1.1 dyoung
417 1.1 dyoung /*
418 1.1 dyoung ** Initialize the shared code: its
419 1.1 dyoung ** at this point the mac type is set.
420 1.1 dyoung */
421 1.1 dyoung error = ixgbe_init_shared_code(hw);
422 1.1 dyoung if (error) {
423 1.3 msaitoh aprint_error_dev(dev,"Shared Code Initialization Failure\n");
424 1.1 dyoung error = EIO;
425 1.1 dyoung goto err_late;
426 1.1 dyoung }
427 1.1 dyoung
428 1.1 dyoung /* Setup the mailbox */
429 1.1 dyoung ixgbe_init_mbx_params_vf(hw);
430 1.1 dyoung
431 1.1 dyoung ixgbe_reset_hw(hw);
432 1.1 dyoung
433 1.1 dyoung /* Get Hardware Flow Control setting */
434 1.1 dyoung hw->fc.requested_mode = ixgbe_fc_full;
435 1.1 dyoung hw->fc.pause_time = IXV_FC_PAUSE;
436 1.6 msaitoh hw->fc.low_water[0] = IXV_FC_LO;
437 1.5 msaitoh hw->fc.high_water[0] = IXV_FC_HI;
438 1.1 dyoung hw->fc.send_xon = TRUE;
439 1.1 dyoung
440 1.1 dyoung error = ixgbe_init_hw(hw);
441 1.1 dyoung if (error) {
442 1.3 msaitoh aprint_error_dev(dev,"Hardware Initialization Failure\n");
443 1.1 dyoung error = EIO;
444 1.1 dyoung goto err_late;
445 1.1 dyoung }
446 1.1 dyoung
447 1.11 msaitoh error = ixv_allocate_msix(adapter, pa);
448 1.1 dyoung if (error)
449 1.1 dyoung goto err_late;
450 1.1 dyoung
451 1.1 dyoung /* Setup OS specific network interface */
452 1.1 dyoung ixv_setup_interface(dev, adapter);
453 1.1 dyoung
454 1.1 dyoung /* Sysctl for limiting the amount of work done in the taskqueue */
455 1.1 dyoung ixv_add_rx_process_limit(adapter, "rx_processing_limit",
456 1.1 dyoung "max number of rx packets to process", &adapter->rx_process_limit,
457 1.1 dyoung ixv_rx_process_limit);
458 1.1 dyoung
459 1.1 dyoung /* Do the stats setup */
460 1.1 dyoung ixv_save_stats(adapter);
461 1.1 dyoung ixv_init_stats(adapter);
462 1.1 dyoung
463 1.1 dyoung /* Register for VLAN events */
464 1.12 msaitoh #if 0 /* XXX delete after write? */
465 1.1 dyoung adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
466 1.1 dyoung ixv_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
467 1.1 dyoung adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
468 1.1 dyoung ixv_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
469 1.3 msaitoh #endif
470 1.1 dyoung
471 1.1 dyoung INIT_DEBUGOUT("ixv_attach: end");
472 1.3 msaitoh return;
473 1.1 dyoung
474 1.1 dyoung err_late:
475 1.1 dyoung ixv_free_transmit_structures(adapter);
476 1.1 dyoung ixv_free_receive_structures(adapter);
477 1.1 dyoung err_out:
478 1.1 dyoung ixv_free_pci_resources(adapter);
479 1.3 msaitoh return;
480 1.1 dyoung
481 1.1 dyoung }
482 1.1 dyoung
483 1.1 dyoung /*********************************************************************
484 1.1 dyoung * Device removal routine
485 1.1 dyoung *
486 1.1 dyoung * The detach entry point is called when the driver is being removed.
487 1.1 dyoung * This routine stops the adapter and deallocates all the resources
488 1.1 dyoung * that were allocated for driver operation.
489 1.1 dyoung *
490 1.1 dyoung * return 0 on success, positive on failure
491 1.1 dyoung *********************************************************************/
492 1.1 dyoung
493 1.1 dyoung static int
494 1.3 msaitoh ixv_detach(device_t dev, int flags)
495 1.1 dyoung {
496 1.3 msaitoh struct adapter *adapter = device_private(dev);
497 1.1 dyoung struct ix_queue *que = adapter->queues;
498 1.1 dyoung
499 1.1 dyoung INIT_DEBUGOUT("ixv_detach: begin");
500 1.1 dyoung
501 1.1 dyoung /* Make sure VLANS are not using driver */
502 1.3 msaitoh if (!VLAN_ATTACHED(&adapter->osdep.ec))
503 1.3 msaitoh ; /* nothing to do: no VLANs */
504 1.3 msaitoh else if ((flags & (DETACH_SHUTDOWN|DETACH_FORCE)) != 0)
505 1.3 msaitoh vlan_ifdetach(adapter->ifp);
506 1.3 msaitoh else {
507 1.3 msaitoh aprint_error_dev(dev, "VLANs in use\n");
508 1.3 msaitoh return EBUSY;
509 1.1 dyoung }
510 1.1 dyoung
511 1.1 dyoung IXV_CORE_LOCK(adapter);
512 1.1 dyoung ixv_stop(adapter);
513 1.1 dyoung IXV_CORE_UNLOCK(adapter);
514 1.1 dyoung
515 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, que++) {
516 1.3 msaitoh softint_disestablish(que->que_si);
517 1.1 dyoung }
518 1.1 dyoung
519 1.1 dyoung /* Drain the Link queue */
520 1.3 msaitoh softint_disestablish(adapter->mbx_si);
521 1.1 dyoung
522 1.1 dyoung /* Unregister VLAN events */
523 1.3 msaitoh #if 0 /* XXX msaitoh delete after write? */
524 1.1 dyoung if (adapter->vlan_attach != NULL)
525 1.1 dyoung EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
526 1.1 dyoung if (adapter->vlan_detach != NULL)
527 1.1 dyoung EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
528 1.3 msaitoh #endif
529 1.1 dyoung
530 1.1 dyoung ether_ifdetach(adapter->ifp);
531 1.3 msaitoh callout_halt(&adapter->timer, NULL);
532 1.1 dyoung ixv_free_pci_resources(adapter);
533 1.3 msaitoh #if 0 /* XXX the NetBSD port is probably missing something here */
534 1.1 dyoung bus_generic_detach(dev);
535 1.3 msaitoh #endif
536 1.3 msaitoh if_detach(adapter->ifp);
537 1.1 dyoung
538 1.1 dyoung ixv_free_transmit_structures(adapter);
539 1.1 dyoung ixv_free_receive_structures(adapter);
540 1.1 dyoung
541 1.1 dyoung IXV_CORE_LOCK_DESTROY(adapter);
542 1.1 dyoung return (0);
543 1.1 dyoung }
544 1.1 dyoung
545 1.1 dyoung /*********************************************************************
546 1.1 dyoung *
547 1.1 dyoung * Shutdown entry point
548 1.1 dyoung *
549 1.1 dyoung **********************************************************************/
550 1.3 msaitoh #if 0 /* XXX NetBSD ought to register something like this through pmf(9) */
551 1.1 dyoung static int
552 1.1 dyoung ixv_shutdown(device_t dev)
553 1.1 dyoung {
554 1.3 msaitoh struct adapter *adapter = device_private(dev);
555 1.1 dyoung IXV_CORE_LOCK(adapter);
556 1.1 dyoung ixv_stop(adapter);
557 1.1 dyoung IXV_CORE_UNLOCK(adapter);
558 1.1 dyoung return (0);
559 1.1 dyoung }
560 1.3 msaitoh #endif
561 1.1 dyoung
562 1.1 dyoung #if __FreeBSD_version < 800000
563 1.1 dyoung /*********************************************************************
564 1.1 dyoung * Transmit entry point
565 1.1 dyoung *
566 1.1 dyoung * ixv_start is called by the stack to initiate a transmit.
567 1.1 dyoung * The driver will remain in this routine as long as there are
568 1.1 dyoung * packets to transmit and transmit resources are available.
569 1.1 dyoung * In case resources are not available stack is notified and
570 1.1 dyoung * the packet is requeued.
571 1.1 dyoung **********************************************************************/
572 1.1 dyoung static void
573 1.1 dyoung ixv_start_locked(struct tx_ring *txr, struct ifnet * ifp)
574 1.1 dyoung {
575 1.3 msaitoh int rc;
576 1.1 dyoung struct mbuf *m_head;
577 1.1 dyoung struct adapter *adapter = txr->adapter;
578 1.1 dyoung
579 1.1 dyoung IXV_TX_LOCK_ASSERT(txr);
580 1.1 dyoung
581 1.3 msaitoh if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) !=
582 1.3 msaitoh IFF_RUNNING)
583 1.1 dyoung return;
584 1.1 dyoung if (!adapter->link_active)
585 1.1 dyoung return;
586 1.1 dyoung
587 1.3 msaitoh while (!IFQ_IS_EMPTY(&ifp->if_snd)) {
588 1.1 dyoung
589 1.3 msaitoh IFQ_POLL(&ifp->if_snd, m_head);
590 1.1 dyoung if (m_head == NULL)
591 1.1 dyoung break;
592 1.1 dyoung
593 1.11 msaitoh if ((rc = ixv_xmit(txr, m_head)) == EAGAIN) {
594 1.3 msaitoh ifp->if_flags |= IFF_OACTIVE;
595 1.1 dyoung break;
596 1.1 dyoung }
597 1.3 msaitoh IFQ_DEQUEUE(&ifp->if_snd, m_head);
598 1.3 msaitoh if (rc == EFBIG) {
599 1.3 msaitoh struct mbuf *mtmp;
600 1.3 msaitoh
601 1.8 msaitoh if ((mtmp = m_defrag(m_head, M_NOWAIT)) != NULL) {
602 1.3 msaitoh m_head = mtmp;
603 1.3 msaitoh rc = ixv_xmit(txr, m_head);
604 1.3 msaitoh if (rc != 0)
605 1.3 msaitoh adapter->efbig2_tx_dma_setup.ev_count++;
606 1.3 msaitoh } else
607 1.3 msaitoh adapter->m_defrag_failed.ev_count++;
608 1.3 msaitoh }
609 1.3 msaitoh if (rc != 0) {
610 1.3 msaitoh m_freem(m_head);
611 1.3 msaitoh continue;
612 1.3 msaitoh }
613 1.1 dyoung /* Send a copy of the frame to the BPF listener */
614 1.3 msaitoh bpf_mtap(ifp, m_head);
615 1.1 dyoung
616 1.1 dyoung /* Set watchdog on */
617 1.1 dyoung txr->watchdog_check = TRUE;
618 1.3 msaitoh getmicrotime(&txr->watchdog_time);
619 1.1 dyoung }
620 1.1 dyoung return;
621 1.1 dyoung }
622 1.1 dyoung
623 1.1 dyoung /*
624 1.1 dyoung * Legacy TX start - called by the stack, this
625 1.1 dyoung * always uses the first tx ring, and should
626 1.1 dyoung * not be used with multiqueue tx enabled.
627 1.1 dyoung */
628 1.1 dyoung static void
629 1.1 dyoung ixv_start(struct ifnet *ifp)
630 1.1 dyoung {
631 1.1 dyoung struct adapter *adapter = ifp->if_softc;
632 1.1 dyoung struct tx_ring *txr = adapter->tx_rings;
633 1.1 dyoung
634 1.3 msaitoh if (ifp->if_flags & IFF_RUNNING) {
635 1.1 dyoung IXV_TX_LOCK(txr);
636 1.1 dyoung ixv_start_locked(txr, ifp);
637 1.1 dyoung IXV_TX_UNLOCK(txr);
638 1.1 dyoung }
639 1.1 dyoung return;
640 1.1 dyoung }
641 1.1 dyoung
642 1.1 dyoung #else
643 1.1 dyoung
644 1.1 dyoung /*
645 1.1 dyoung ** Multiqueue Transmit driver
646 1.1 dyoung **
647 1.1 dyoung */
648 1.1 dyoung static int
649 1.1 dyoung ixv_mq_start(struct ifnet *ifp, struct mbuf *m)
650 1.1 dyoung {
651 1.1 dyoung struct adapter *adapter = ifp->if_softc;
652 1.1 dyoung struct ix_queue *que;
653 1.1 dyoung struct tx_ring *txr;
654 1.1 dyoung int i = 0, err = 0;
655 1.1 dyoung
656 1.1 dyoung /* Which queue to use */
657 1.1 dyoung if ((m->m_flags & M_FLOWID) != 0)
658 1.1 dyoung i = m->m_pkthdr.flowid % adapter->num_queues;
659 1.1 dyoung
660 1.1 dyoung txr = &adapter->tx_rings[i];
661 1.1 dyoung que = &adapter->queues[i];
662 1.1 dyoung
663 1.1 dyoung if (IXV_TX_TRYLOCK(txr)) {
664 1.1 dyoung err = ixv_mq_start_locked(ifp, txr, m);
665 1.1 dyoung IXV_TX_UNLOCK(txr);
666 1.1 dyoung } else {
667 1.1 dyoung err = drbr_enqueue(ifp, txr->br, m);
668 1.3 msaitoh softint_schedule(que->que_si);
669 1.1 dyoung }
670 1.1 dyoung
671 1.1 dyoung return (err);
672 1.1 dyoung }
673 1.1 dyoung
674 1.1 dyoung static int
675 1.1 dyoung ixv_mq_start_locked(struct ifnet *ifp, struct tx_ring *txr, struct mbuf *m)
676 1.1 dyoung {
677 1.1 dyoung struct adapter *adapter = txr->adapter;
678 1.1 dyoung struct mbuf *next;
679 1.1 dyoung int enqueued, err = 0;
680 1.1 dyoung
681 1.3 msaitoh if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) !=
682 1.3 msaitoh IFF_RUNNING || adapter->link_active == 0) {
683 1.1 dyoung if (m != NULL)
684 1.1 dyoung err = drbr_enqueue(ifp, txr->br, m);
685 1.1 dyoung return (err);
686 1.1 dyoung }
687 1.1 dyoung
688 1.1 dyoung /* Do a clean if descriptors are low */
689 1.1 dyoung if (txr->tx_avail <= IXV_TX_CLEANUP_THRESHOLD)
690 1.1 dyoung ixv_txeof(txr);
691 1.1 dyoung
692 1.1 dyoung enqueued = 0;
693 1.12 msaitoh if (m != NULL) {
694 1.8 msaitoh err = drbr_dequeue(ifp, txr->br, m);
695 1.8 msaitoh if (err) {
696 1.12 msaitoh return (err);
697 1.8 msaitoh }
698 1.8 msaitoh }
699 1.1 dyoung /* Process the queue */
700 1.8 msaitoh while ((next = drbr_peek(ifp, txr->br)) != NULL) {
701 1.3 msaitoh if ((err = ixv_xmit(txr, next)) != 0) {
702 1.8 msaitoh if (next != NULL) {
703 1.8 msaitoh drbr_advance(ifp, txr->br);
704 1.8 msaitoh } else {
705 1.8 msaitoh drbr_putback(ifp, txr->br, next);
706 1.8 msaitoh }
707 1.1 dyoung break;
708 1.1 dyoung }
709 1.8 msaitoh drbr_advance(ifp, txr->br);
710 1.1 dyoung enqueued++;
711 1.7 msaitoh ifp->if_obytes += next->m_pkthdr.len;
712 1.7 msaitoh if (next->m_flags & M_MCAST)
713 1.7 msaitoh ifp->if_omcasts++;
714 1.1 dyoung /* Send a copy of the frame to the BPF listener */
715 1.1 dyoung ETHER_BPF_MTAP(ifp, next);
716 1.3 msaitoh if ((ifp->if_flags & IFF_RUNNING) == 0)
717 1.1 dyoung break;
718 1.1 dyoung if (txr->tx_avail <= IXV_TX_OP_THRESHOLD) {
719 1.3 msaitoh ifp->if_flags |= IFF_OACTIVE;
720 1.1 dyoung break;
721 1.1 dyoung }
722 1.1 dyoung }
723 1.1 dyoung
724 1.1 dyoung if (enqueued > 0) {
725 1.1 dyoung /* Set watchdog on */
726 1.1 dyoung txr->watchdog_check = TRUE;
727 1.3 msaitoh getmicrotime(&txr->watchdog_time);
728 1.1 dyoung }
729 1.1 dyoung
730 1.1 dyoung return (err);
731 1.1 dyoung }
732 1.1 dyoung
733 1.1 dyoung /*
734 1.1 dyoung ** Flush all ring buffers
735 1.1 dyoung */
736 1.1 dyoung static void
737 1.1 dyoung ixv_qflush(struct ifnet *ifp)
738 1.1 dyoung {
739 1.1 dyoung struct adapter *adapter = ifp->if_softc;
740 1.1 dyoung struct tx_ring *txr = adapter->tx_rings;
741 1.1 dyoung struct mbuf *m;
742 1.1 dyoung
743 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, txr++) {
744 1.1 dyoung IXV_TX_LOCK(txr);
745 1.1 dyoung while ((m = buf_ring_dequeue_sc(txr->br)) != NULL)
746 1.1 dyoung m_freem(m);
747 1.1 dyoung IXV_TX_UNLOCK(txr);
748 1.1 dyoung }
749 1.1 dyoung if_qflush(ifp);
750 1.1 dyoung }
751 1.1 dyoung
752 1.1 dyoung #endif
753 1.1 dyoung
754 1.3 msaitoh static int
755 1.3 msaitoh ixv_ifflags_cb(struct ethercom *ec)
756 1.3 msaitoh {
757 1.3 msaitoh struct ifnet *ifp = &ec->ec_if;
758 1.3 msaitoh struct adapter *adapter = ifp->if_softc;
759 1.3 msaitoh int change = ifp->if_flags ^ adapter->if_flags, rc = 0;
760 1.3 msaitoh
761 1.3 msaitoh IXV_CORE_LOCK(adapter);
762 1.3 msaitoh
763 1.3 msaitoh if (change != 0)
764 1.3 msaitoh adapter->if_flags = ifp->if_flags;
765 1.3 msaitoh
766 1.3 msaitoh if ((change & ~(IFF_CANTCHANGE|IFF_DEBUG)) != 0)
767 1.3 msaitoh rc = ENETRESET;
768 1.3 msaitoh
769 1.3 msaitoh IXV_CORE_UNLOCK(adapter);
770 1.3 msaitoh
771 1.3 msaitoh return rc;
772 1.3 msaitoh }
773 1.3 msaitoh
774 1.1 dyoung /*********************************************************************
775 1.1 dyoung * Ioctl entry point
776 1.1 dyoung *
777 1.1 dyoung * ixv_ioctl is called when the user wants to configure the
778 1.1 dyoung * interface.
779 1.1 dyoung *
780 1.1 dyoung * return 0 on success, positive on failure
781 1.1 dyoung **********************************************************************/
782 1.1 dyoung
783 1.1 dyoung static int
784 1.3 msaitoh ixv_ioctl(struct ifnet * ifp, u_long command, void *data)
785 1.1 dyoung {
786 1.1 dyoung struct adapter *adapter = ifp->if_softc;
787 1.3 msaitoh struct ifcapreq *ifcr = data;
788 1.1 dyoung struct ifreq *ifr = (struct ifreq *) data;
789 1.1 dyoung int error = 0;
790 1.3 msaitoh int l4csum_en;
791 1.3 msaitoh const int l4csum = IFCAP_CSUM_TCPv4_Rx|IFCAP_CSUM_UDPv4_Rx|
792 1.3 msaitoh IFCAP_CSUM_TCPv6_Rx|IFCAP_CSUM_UDPv6_Rx;
793 1.1 dyoung
794 1.1 dyoung switch (command) {
795 1.1 dyoung case SIOCSIFFLAGS:
796 1.1 dyoung IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
797 1.1 dyoung break;
798 1.1 dyoung case SIOCADDMULTI:
799 1.1 dyoung case SIOCDELMULTI:
800 1.1 dyoung IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
801 1.1 dyoung break;
802 1.1 dyoung case SIOCSIFMEDIA:
803 1.1 dyoung case SIOCGIFMEDIA:
804 1.1 dyoung IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
805 1.1 dyoung break;
806 1.1 dyoung case SIOCSIFCAP:
807 1.1 dyoung IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
808 1.1 dyoung break;
809 1.3 msaitoh case SIOCSIFMTU:
810 1.3 msaitoh IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
811 1.3 msaitoh break;
812 1.1 dyoung default:
813 1.1 dyoung IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
814 1.1 dyoung break;
815 1.1 dyoung }
816 1.1 dyoung
817 1.3 msaitoh switch (command) {
818 1.3 msaitoh case SIOCSIFMEDIA:
819 1.3 msaitoh case SIOCGIFMEDIA:
820 1.3 msaitoh return ifmedia_ioctl(ifp, ifr, &adapter->media, command);
821 1.3 msaitoh case SIOCSIFCAP:
822 1.3 msaitoh /* Layer-4 Rx checksum offload has to be turned on and
823 1.3 msaitoh * off as a unit.
824 1.3 msaitoh */
825 1.3 msaitoh l4csum_en = ifcr->ifcr_capenable & l4csum;
826 1.3 msaitoh if (l4csum_en != l4csum && l4csum_en != 0)
827 1.3 msaitoh return EINVAL;
828 1.3 msaitoh /*FALLTHROUGH*/
829 1.3 msaitoh case SIOCADDMULTI:
830 1.3 msaitoh case SIOCDELMULTI:
831 1.3 msaitoh case SIOCSIFFLAGS:
832 1.3 msaitoh case SIOCSIFMTU:
833 1.3 msaitoh default:
834 1.3 msaitoh if ((error = ether_ioctl(ifp, command, data)) != ENETRESET)
835 1.3 msaitoh return error;
836 1.3 msaitoh if ((ifp->if_flags & IFF_RUNNING) == 0)
837 1.3 msaitoh ;
838 1.3 msaitoh else if (command == SIOCSIFCAP || command == SIOCSIFMTU) {
839 1.3 msaitoh IXV_CORE_LOCK(adapter);
840 1.3 msaitoh ixv_init_locked(adapter);
841 1.3 msaitoh IXV_CORE_UNLOCK(adapter);
842 1.3 msaitoh } else if (command == SIOCADDMULTI || command == SIOCDELMULTI) {
843 1.3 msaitoh /*
844 1.3 msaitoh * Multicast list has changed; set the hardware filter
845 1.3 msaitoh * accordingly.
846 1.3 msaitoh */
847 1.3 msaitoh IXV_CORE_LOCK(adapter);
848 1.3 msaitoh ixv_disable_intr(adapter);
849 1.3 msaitoh ixv_set_multi(adapter);
850 1.3 msaitoh ixv_enable_intr(adapter);
851 1.3 msaitoh IXV_CORE_UNLOCK(adapter);
852 1.3 msaitoh }
853 1.3 msaitoh return 0;
854 1.3 msaitoh }
855 1.1 dyoung }
856 1.1 dyoung
857 1.1 dyoung /*********************************************************************
858 1.1 dyoung * Init entry point
859 1.1 dyoung *
860 1.1 dyoung * This routine is used in two ways. It is used by the stack as
861 1.1 dyoung * init entry point in network interface structure. It is also used
862 1.1 dyoung * by the driver as a hw/sw initialization routine to get to a
863 1.1 dyoung * consistent state.
864 1.1 dyoung *
865 1.1 dyoung * return 0 on success, positive on failure
866 1.1 dyoung **********************************************************************/
867 1.1 dyoung #define IXGBE_MHADD_MFS_SHIFT 16
868 1.1 dyoung
869 1.1 dyoung static void
870 1.1 dyoung ixv_init_locked(struct adapter *adapter)
871 1.1 dyoung {
872 1.1 dyoung struct ifnet *ifp = adapter->ifp;
873 1.1 dyoung device_t dev = adapter->dev;
874 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
875 1.1 dyoung u32 mhadd, gpie;
876 1.1 dyoung
877 1.1 dyoung INIT_DEBUGOUT("ixv_init: begin");
878 1.3 msaitoh KASSERT(mutex_owned(&adapter->core_mtx));
879 1.1 dyoung hw->adapter_stopped = FALSE;
880 1.1 dyoung ixgbe_stop_adapter(hw);
881 1.1 dyoung callout_stop(&adapter->timer);
882 1.1 dyoung
883 1.1 dyoung /* reprogram the RAR[0] in case user changed it. */
884 1.1 dyoung ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
885 1.1 dyoung
886 1.1 dyoung /* Get the latest mac address, User can use a LAA */
887 1.3 msaitoh memcpy(hw->mac.addr, CLLADDR(adapter->ifp->if_sadl),
888 1.1 dyoung IXGBE_ETH_LENGTH_OF_ADDRESS);
889 1.1 dyoung ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
890 1.1 dyoung hw->addr_ctrl.rar_used_count = 1;
891 1.1 dyoung
892 1.1 dyoung /* Prepare transmit descriptors and buffers */
893 1.1 dyoung if (ixv_setup_transmit_structures(adapter)) {
894 1.3 msaitoh aprint_error_dev(dev,"Could not setup transmit structures\n");
895 1.1 dyoung ixv_stop(adapter);
896 1.1 dyoung return;
897 1.1 dyoung }
898 1.1 dyoung
899 1.1 dyoung ixgbe_reset_hw(hw);
900 1.1 dyoung ixv_initialize_transmit_units(adapter);
901 1.1 dyoung
902 1.1 dyoung /* Setup Multicast table */
903 1.1 dyoung ixv_set_multi(adapter);
904 1.1 dyoung
905 1.1 dyoung /*
906 1.1 dyoung ** Determine the correct mbuf pool
907 1.1 dyoung ** for doing jumbo/headersplit
908 1.1 dyoung */
909 1.1 dyoung if (ifp->if_mtu > ETHERMTU)
910 1.1 dyoung adapter->rx_mbuf_sz = MJUMPAGESIZE;
911 1.1 dyoung else
912 1.1 dyoung adapter->rx_mbuf_sz = MCLBYTES;
913 1.1 dyoung
914 1.1 dyoung /* Prepare receive descriptors and buffers */
915 1.1 dyoung if (ixv_setup_receive_structures(adapter)) {
916 1.1 dyoung device_printf(dev,"Could not setup receive structures\n");
917 1.1 dyoung ixv_stop(adapter);
918 1.1 dyoung return;
919 1.1 dyoung }
920 1.1 dyoung
921 1.1 dyoung /* Configure RX settings */
922 1.1 dyoung ixv_initialize_receive_units(adapter);
923 1.1 dyoung
924 1.1 dyoung /* Enable Enhanced MSIX mode */
925 1.1 dyoung gpie = IXGBE_READ_REG(&adapter->hw, IXGBE_GPIE);
926 1.1 dyoung gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME;
927 1.1 dyoung gpie |= IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD;
928 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
929 1.1 dyoung
930 1.3 msaitoh #if 0 /* XXX isn't it required? -- msaitoh */
931 1.1 dyoung /* Set the various hardware offload abilities */
932 1.1 dyoung ifp->if_hwassist = 0;
933 1.1 dyoung if (ifp->if_capenable & IFCAP_TSO4)
934 1.1 dyoung ifp->if_hwassist |= CSUM_TSO;
935 1.1 dyoung if (ifp->if_capenable & IFCAP_TXCSUM) {
936 1.1 dyoung ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
937 1.1 dyoung #if __FreeBSD_version >= 800000
938 1.1 dyoung ifp->if_hwassist |= CSUM_SCTP;
939 1.1 dyoung #endif
940 1.1 dyoung }
941 1.3 msaitoh #endif
942 1.1 dyoung
943 1.1 dyoung /* Set MTU size */
944 1.1 dyoung if (ifp->if_mtu > ETHERMTU) {
945 1.1 dyoung mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
946 1.1 dyoung mhadd &= ~IXGBE_MHADD_MFS_MASK;
947 1.1 dyoung mhadd |= adapter->max_frame_size << IXGBE_MHADD_MFS_SHIFT;
948 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
949 1.1 dyoung }
950 1.1 dyoung
951 1.1 dyoung /* Set up VLAN offload and filter */
952 1.1 dyoung ixv_setup_vlan_support(adapter);
953 1.1 dyoung
954 1.1 dyoung callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
955 1.1 dyoung
956 1.1 dyoung /* Set up MSI/X routing */
957 1.1 dyoung ixv_configure_ivars(adapter);
958 1.1 dyoung
959 1.1 dyoung /* Set up auto-mask */
960 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_EICS_RTX_QUEUE);
961 1.1 dyoung
962 1.1 dyoung /* Set moderation on the Link interrupt */
963 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEITR(adapter->mbxvec), IXV_LINK_ITR);
964 1.1 dyoung
965 1.1 dyoung /* Stats init */
966 1.1 dyoung ixv_init_stats(adapter);
967 1.1 dyoung
968 1.1 dyoung /* Config/Enable Link */
969 1.1 dyoung ixv_config_link(adapter);
970 1.1 dyoung
971 1.1 dyoung /* And now turn on interrupts */
972 1.1 dyoung ixv_enable_intr(adapter);
973 1.1 dyoung
974 1.1 dyoung /* Now inform the stack we're ready */
975 1.3 msaitoh ifp->if_flags |= IFF_RUNNING;
976 1.3 msaitoh ifp->if_flags &= ~IFF_OACTIVE;
977 1.1 dyoung
978 1.1 dyoung return;
979 1.1 dyoung }
980 1.1 dyoung
981 1.3 msaitoh static int
982 1.3 msaitoh ixv_init(struct ifnet *ifp)
983 1.1 dyoung {
984 1.3 msaitoh struct adapter *adapter = ifp->if_softc;
985 1.1 dyoung
986 1.1 dyoung IXV_CORE_LOCK(adapter);
987 1.1 dyoung ixv_init_locked(adapter);
988 1.1 dyoung IXV_CORE_UNLOCK(adapter);
989 1.3 msaitoh return 0;
990 1.1 dyoung }
991 1.1 dyoung
992 1.1 dyoung
993 1.1 dyoung /*
994 1.1 dyoung **
995 1.1 dyoung ** MSIX Interrupt Handlers and Tasklets
996 1.1 dyoung **
997 1.1 dyoung */
998 1.1 dyoung
999 1.1 dyoung static inline void
1000 1.1 dyoung ixv_enable_queue(struct adapter *adapter, u32 vector)
1001 1.1 dyoung {
1002 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
1003 1.1 dyoung u32 queue = 1 << vector;
1004 1.1 dyoung u32 mask;
1005 1.1 dyoung
1006 1.1 dyoung mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1007 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
1008 1.1 dyoung }
1009 1.1 dyoung
1010 1.1 dyoung static inline void
1011 1.1 dyoung ixv_disable_queue(struct adapter *adapter, u32 vector)
1012 1.1 dyoung {
1013 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
1014 1.1 dyoung u64 queue = (u64)(1 << vector);
1015 1.1 dyoung u32 mask;
1016 1.1 dyoung
1017 1.1 dyoung mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1018 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, mask);
1019 1.1 dyoung }
1020 1.1 dyoung
1021 1.1 dyoung static inline void
1022 1.1 dyoung ixv_rearm_queues(struct adapter *adapter, u64 queues)
1023 1.1 dyoung {
1024 1.1 dyoung u32 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
1025 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEICS, mask);
1026 1.1 dyoung }
1027 1.1 dyoung
1028 1.1 dyoung
1029 1.1 dyoung static void
1030 1.1 dyoung ixv_handle_que(void *context)
1031 1.1 dyoung {
1032 1.1 dyoung struct ix_queue *que = context;
1033 1.1 dyoung struct adapter *adapter = que->adapter;
1034 1.1 dyoung struct tx_ring *txr = que->txr;
1035 1.1 dyoung struct ifnet *ifp = adapter->ifp;
1036 1.1 dyoung bool more;
1037 1.1 dyoung
1038 1.3 msaitoh if (ifp->if_flags & IFF_RUNNING) {
1039 1.1 dyoung more = ixv_rxeof(que, adapter->rx_process_limit);
1040 1.1 dyoung IXV_TX_LOCK(txr);
1041 1.1 dyoung ixv_txeof(txr);
1042 1.1 dyoung #if __FreeBSD_version >= 800000
1043 1.1 dyoung if (!drbr_empty(ifp, txr->br))
1044 1.1 dyoung ixv_mq_start_locked(ifp, txr, NULL);
1045 1.1 dyoung #else
1046 1.3 msaitoh if (!IFQ_IS_EMPTY(&ifp->if_snd))
1047 1.1 dyoung ixv_start_locked(txr, ifp);
1048 1.1 dyoung #endif
1049 1.1 dyoung IXV_TX_UNLOCK(txr);
1050 1.1 dyoung if (more) {
1051 1.3 msaitoh adapter->req.ev_count++;
1052 1.3 msaitoh softint_schedule(que->que_si);
1053 1.1 dyoung return;
1054 1.1 dyoung }
1055 1.1 dyoung }
1056 1.1 dyoung
1057 1.1 dyoung /* Reenable this interrupt */
1058 1.1 dyoung ixv_enable_queue(adapter, que->msix);
1059 1.1 dyoung return;
1060 1.1 dyoung }
1061 1.1 dyoung
1062 1.1 dyoung /*********************************************************************
1063 1.1 dyoung *
1064 1.1 dyoung * MSI Queue Interrupt Service routine
1065 1.1 dyoung *
1066 1.1 dyoung **********************************************************************/
1067 1.11 msaitoh int
1068 1.1 dyoung ixv_msix_que(void *arg)
1069 1.1 dyoung {
1070 1.1 dyoung struct ix_queue *que = arg;
1071 1.1 dyoung struct adapter *adapter = que->adapter;
1072 1.1 dyoung struct tx_ring *txr = que->txr;
1073 1.1 dyoung struct rx_ring *rxr = que->rxr;
1074 1.1 dyoung bool more_tx, more_rx;
1075 1.1 dyoung u32 newitr = 0;
1076 1.1 dyoung
1077 1.1 dyoung ixv_disable_queue(adapter, que->msix);
1078 1.1 dyoung ++que->irqs;
1079 1.1 dyoung
1080 1.1 dyoung more_rx = ixv_rxeof(que, adapter->rx_process_limit);
1081 1.1 dyoung
1082 1.1 dyoung IXV_TX_LOCK(txr);
1083 1.1 dyoung more_tx = ixv_txeof(txr);
1084 1.5 msaitoh /*
1085 1.5 msaitoh ** Make certain that if the stack
1086 1.5 msaitoh ** has anything queued the task gets
1087 1.5 msaitoh ** scheduled to handle it.
1088 1.5 msaitoh */
1089 1.5 msaitoh #if __FreeBSD_version < 800000
1090 1.5 msaitoh if (!IFQ_IS_EMPTY(&adapter->ifp->if_snd))
1091 1.5 msaitoh #else
1092 1.5 msaitoh if (!drbr_empty(adapter->ifp, txr->br))
1093 1.5 msaitoh #endif
1094 1.5 msaitoh more_tx = 1;
1095 1.1 dyoung IXV_TX_UNLOCK(txr);
1096 1.1 dyoung
1097 1.1 dyoung more_rx = ixv_rxeof(que, adapter->rx_process_limit);
1098 1.1 dyoung
1099 1.1 dyoung /* Do AIM now? */
1100 1.1 dyoung
1101 1.1 dyoung if (ixv_enable_aim == FALSE)
1102 1.1 dyoung goto no_calc;
1103 1.1 dyoung /*
1104 1.1 dyoung ** Do Adaptive Interrupt Moderation:
1105 1.1 dyoung ** - Write out last calculated setting
1106 1.1 dyoung ** - Calculate based on average size over
1107 1.1 dyoung ** the last interval.
1108 1.1 dyoung */
1109 1.1 dyoung if (que->eitr_setting)
1110 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw,
1111 1.1 dyoung IXGBE_VTEITR(que->msix),
1112 1.1 dyoung que->eitr_setting);
1113 1.1 dyoung
1114 1.1 dyoung que->eitr_setting = 0;
1115 1.1 dyoung
1116 1.1 dyoung /* Idle, do nothing */
1117 1.1 dyoung if ((txr->bytes == 0) && (rxr->bytes == 0))
1118 1.1 dyoung goto no_calc;
1119 1.1 dyoung
1120 1.1 dyoung if ((txr->bytes) && (txr->packets))
1121 1.1 dyoung newitr = txr->bytes/txr->packets;
1122 1.1 dyoung if ((rxr->bytes) && (rxr->packets))
1123 1.1 dyoung newitr = max(newitr,
1124 1.1 dyoung (rxr->bytes / rxr->packets));
1125 1.1 dyoung newitr += 24; /* account for hardware frame, crc */
1126 1.1 dyoung
1127 1.1 dyoung /* set an upper boundary */
1128 1.1 dyoung newitr = min(newitr, 3000);
1129 1.1 dyoung
1130 1.1 dyoung /* Be nice to the mid range */
1131 1.1 dyoung if ((newitr > 300) && (newitr < 1200))
1132 1.1 dyoung newitr = (newitr / 3);
1133 1.1 dyoung else
1134 1.1 dyoung newitr = (newitr / 2);
1135 1.1 dyoung
1136 1.1 dyoung newitr |= newitr << 16;
1137 1.1 dyoung
1138 1.1 dyoung /* save for next interrupt */
1139 1.1 dyoung que->eitr_setting = newitr;
1140 1.1 dyoung
1141 1.1 dyoung /* Reset state */
1142 1.1 dyoung txr->bytes = 0;
1143 1.1 dyoung txr->packets = 0;
1144 1.1 dyoung rxr->bytes = 0;
1145 1.1 dyoung rxr->packets = 0;
1146 1.1 dyoung
1147 1.1 dyoung no_calc:
1148 1.1 dyoung if (more_tx || more_rx)
1149 1.3 msaitoh softint_schedule(que->que_si);
1150 1.1 dyoung else /* Reenable this interrupt */
1151 1.1 dyoung ixv_enable_queue(adapter, que->msix);
1152 1.11 msaitoh return 1;
1153 1.1 dyoung }
1154 1.1 dyoung
1155 1.11 msaitoh static int
1156 1.1 dyoung ixv_msix_mbx(void *arg)
1157 1.1 dyoung {
1158 1.1 dyoung struct adapter *adapter = arg;
1159 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
1160 1.1 dyoung u32 reg;
1161 1.1 dyoung
1162 1.3 msaitoh ++adapter->mbx_irq.ev_count;
1163 1.1 dyoung
1164 1.1 dyoung /* First get the cause */
1165 1.1 dyoung reg = IXGBE_READ_REG(hw, IXGBE_VTEICS);
1166 1.1 dyoung /* Clear interrupt with write */
1167 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEICR, reg);
1168 1.1 dyoung
1169 1.1 dyoung /* Link status change */
1170 1.1 dyoung if (reg & IXGBE_EICR_LSC)
1171 1.3 msaitoh softint_schedule(adapter->mbx_si);
1172 1.1 dyoung
1173 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_EIMS_OTHER);
1174 1.11 msaitoh return 1;
1175 1.1 dyoung }
1176 1.1 dyoung
1177 1.1 dyoung /*********************************************************************
1178 1.1 dyoung *
1179 1.1 dyoung * Media Ioctl callback
1180 1.1 dyoung *
1181 1.1 dyoung * This routine is called whenever the user queries the status of
1182 1.1 dyoung * the interface using ifconfig.
1183 1.1 dyoung *
1184 1.1 dyoung **********************************************************************/
1185 1.1 dyoung static void
1186 1.1 dyoung ixv_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
1187 1.1 dyoung {
1188 1.1 dyoung struct adapter *adapter = ifp->if_softc;
1189 1.1 dyoung
1190 1.1 dyoung INIT_DEBUGOUT("ixv_media_status: begin");
1191 1.1 dyoung IXV_CORE_LOCK(adapter);
1192 1.1 dyoung ixv_update_link_status(adapter);
1193 1.1 dyoung
1194 1.1 dyoung ifmr->ifm_status = IFM_AVALID;
1195 1.1 dyoung ifmr->ifm_active = IFM_ETHER;
1196 1.1 dyoung
1197 1.1 dyoung if (!adapter->link_active) {
1198 1.1 dyoung IXV_CORE_UNLOCK(adapter);
1199 1.1 dyoung return;
1200 1.1 dyoung }
1201 1.1 dyoung
1202 1.1 dyoung ifmr->ifm_status |= IFM_ACTIVE;
1203 1.1 dyoung
1204 1.1 dyoung switch (adapter->link_speed) {
1205 1.1 dyoung case IXGBE_LINK_SPEED_1GB_FULL:
1206 1.1 dyoung ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
1207 1.1 dyoung break;
1208 1.1 dyoung case IXGBE_LINK_SPEED_10GB_FULL:
1209 1.1 dyoung ifmr->ifm_active |= IFM_FDX;
1210 1.1 dyoung break;
1211 1.1 dyoung }
1212 1.1 dyoung
1213 1.1 dyoung IXV_CORE_UNLOCK(adapter);
1214 1.1 dyoung
1215 1.1 dyoung return;
1216 1.1 dyoung }
1217 1.1 dyoung
1218 1.1 dyoung /*********************************************************************
1219 1.1 dyoung *
1220 1.1 dyoung * Media Ioctl callback
1221 1.1 dyoung *
1222 1.1 dyoung * This routine is called when the user changes speed/duplex using
1223 1.1 dyoung * media/mediopt option with ifconfig.
1224 1.1 dyoung *
1225 1.1 dyoung **********************************************************************/
1226 1.1 dyoung static int
1227 1.1 dyoung ixv_media_change(struct ifnet * ifp)
1228 1.1 dyoung {
1229 1.1 dyoung struct adapter *adapter = ifp->if_softc;
1230 1.1 dyoung struct ifmedia *ifm = &adapter->media;
1231 1.1 dyoung
1232 1.1 dyoung INIT_DEBUGOUT("ixv_media_change: begin");
1233 1.1 dyoung
1234 1.1 dyoung if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1235 1.1 dyoung return (EINVAL);
1236 1.1 dyoung
1237 1.1 dyoung switch (IFM_SUBTYPE(ifm->ifm_media)) {
1238 1.1 dyoung case IFM_AUTO:
1239 1.1 dyoung break;
1240 1.1 dyoung default:
1241 1.1 dyoung device_printf(adapter->dev, "Only auto media type\n");
1242 1.1 dyoung return (EINVAL);
1243 1.1 dyoung }
1244 1.1 dyoung
1245 1.1 dyoung return (0);
1246 1.1 dyoung }
1247 1.1 dyoung
1248 1.1 dyoung /*********************************************************************
1249 1.1 dyoung *
1250 1.1 dyoung * This routine maps the mbufs to tx descriptors, allowing the
1251 1.1 dyoung * TX engine to transmit the packets.
1252 1.1 dyoung * - return 0 on success, positive on failure
1253 1.1 dyoung *
1254 1.1 dyoung **********************************************************************/
1255 1.1 dyoung
1256 1.1 dyoung static int
1257 1.3 msaitoh ixv_xmit(struct tx_ring *txr, struct mbuf *m_head)
1258 1.1 dyoung {
1259 1.3 msaitoh struct m_tag *mtag;
1260 1.1 dyoung struct adapter *adapter = txr->adapter;
1261 1.3 msaitoh struct ethercom *ec = &adapter->osdep.ec;
1262 1.1 dyoung u32 olinfo_status = 0, cmd_type_len;
1263 1.1 dyoung u32 paylen = 0;
1264 1.11 msaitoh int i, j, error;
1265 1.1 dyoung int first, last = 0;
1266 1.1 dyoung bus_dmamap_t map;
1267 1.3 msaitoh struct ixv_tx_buf *txbuf;
1268 1.1 dyoung union ixgbe_adv_tx_desc *txd = NULL;
1269 1.1 dyoung
1270 1.1 dyoung /* Basic descriptor defines */
1271 1.1 dyoung cmd_type_len = (IXGBE_ADVTXD_DTYP_DATA |
1272 1.1 dyoung IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT);
1273 1.1 dyoung
1274 1.3 msaitoh if ((mtag = VLAN_OUTPUT_TAG(ec, m_head)) != NULL)
1275 1.1 dyoung cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
1276 1.1 dyoung
1277 1.1 dyoung /*
1278 1.1 dyoung * Important to capture the first descriptor
1279 1.1 dyoung * used because it will contain the index of
1280 1.1 dyoung * the one we tell the hardware to report back
1281 1.1 dyoung */
1282 1.1 dyoung first = txr->next_avail_desc;
1283 1.1 dyoung txbuf = &txr->tx_buffers[first];
1284 1.1 dyoung map = txbuf->map;
1285 1.1 dyoung
1286 1.1 dyoung /*
1287 1.1 dyoung * Map the packet for DMA.
1288 1.1 dyoung */
1289 1.3 msaitoh error = bus_dmamap_load_mbuf(txr->txtag->dt_dmat, map,
1290 1.3 msaitoh m_head, BUS_DMA_NOWAIT);
1291 1.1 dyoung
1292 1.3 msaitoh switch (error) {
1293 1.3 msaitoh case EAGAIN:
1294 1.3 msaitoh adapter->eagain_tx_dma_setup.ev_count++;
1295 1.3 msaitoh return EAGAIN;
1296 1.3 msaitoh case ENOMEM:
1297 1.3 msaitoh adapter->enomem_tx_dma_setup.ev_count++;
1298 1.3 msaitoh return EAGAIN;
1299 1.3 msaitoh case EFBIG:
1300 1.3 msaitoh adapter->efbig_tx_dma_setup.ev_count++;
1301 1.3 msaitoh return error;
1302 1.3 msaitoh case EINVAL:
1303 1.3 msaitoh adapter->einval_tx_dma_setup.ev_count++;
1304 1.3 msaitoh return error;
1305 1.3 msaitoh default:
1306 1.3 msaitoh adapter->other_tx_dma_setup.ev_count++;
1307 1.3 msaitoh return error;
1308 1.3 msaitoh case 0:
1309 1.3 msaitoh break;
1310 1.1 dyoung }
1311 1.1 dyoung
1312 1.1 dyoung /* Make certain there are enough descriptors */
1313 1.11 msaitoh if (map->dm_nsegs > txr->tx_avail - 2) {
1314 1.3 msaitoh txr->no_desc_avail.ev_count++;
1315 1.3 msaitoh /* XXX s/ixgbe/ixv/ */
1316 1.3 msaitoh ixgbe_dmamap_unload(txr->txtag, txbuf->map);
1317 1.3 msaitoh return EAGAIN;
1318 1.1 dyoung }
1319 1.1 dyoung
1320 1.1 dyoung /*
1321 1.1 dyoung ** Set up the appropriate offload context
1322 1.1 dyoung ** this becomes the first descriptor of
1323 1.1 dyoung ** a packet.
1324 1.1 dyoung */
1325 1.3 msaitoh if (m_head->m_pkthdr.csum_flags & (M_CSUM_TSOv4|M_CSUM_TSOv6)) {
1326 1.1 dyoung if (ixv_tso_setup(txr, m_head, &paylen)) {
1327 1.1 dyoung cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
1328 1.1 dyoung olinfo_status |= IXGBE_TXD_POPTS_IXSM << 8;
1329 1.1 dyoung olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
1330 1.1 dyoung olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
1331 1.3 msaitoh ++adapter->tso_tx.ev_count;
1332 1.3 msaitoh } else {
1333 1.3 msaitoh ++adapter->tso_err.ev_count;
1334 1.3 msaitoh /* XXX unload DMA map! --dyoung -> easy? --msaitoh */
1335 1.1 dyoung return (ENXIO);
1336 1.3 msaitoh }
1337 1.3 msaitoh } else
1338 1.3 msaitoh olinfo_status |= ixv_tx_ctx_setup(txr, m_head);
1339 1.1 dyoung
1340 1.1 dyoung /* Record payload length */
1341 1.1 dyoung if (paylen == 0)
1342 1.1 dyoung olinfo_status |= m_head->m_pkthdr.len <<
1343 1.1 dyoung IXGBE_ADVTXD_PAYLEN_SHIFT;
1344 1.1 dyoung
1345 1.1 dyoung i = txr->next_avail_desc;
1346 1.3 msaitoh for (j = 0; j < map->dm_nsegs; j++) {
1347 1.1 dyoung bus_size_t seglen;
1348 1.1 dyoung bus_addr_t segaddr;
1349 1.1 dyoung
1350 1.1 dyoung txbuf = &txr->tx_buffers[i];
1351 1.1 dyoung txd = &txr->tx_base[i];
1352 1.3 msaitoh seglen = map->dm_segs[j].ds_len;
1353 1.3 msaitoh segaddr = htole64(map->dm_segs[j].ds_addr);
1354 1.1 dyoung
1355 1.1 dyoung txd->read.buffer_addr = segaddr;
1356 1.1 dyoung txd->read.cmd_type_len = htole32(txr->txd_cmd |
1357 1.1 dyoung cmd_type_len |seglen);
1358 1.1 dyoung txd->read.olinfo_status = htole32(olinfo_status);
1359 1.1 dyoung last = i; /* descriptor that will get completion IRQ */
1360 1.1 dyoung
1361 1.1 dyoung if (++i == adapter->num_tx_desc)
1362 1.1 dyoung i = 0;
1363 1.1 dyoung
1364 1.1 dyoung txbuf->m_head = NULL;
1365 1.1 dyoung txbuf->eop_index = -1;
1366 1.1 dyoung }
1367 1.1 dyoung
1368 1.1 dyoung txd->read.cmd_type_len |=
1369 1.1 dyoung htole32(IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS);
1370 1.3 msaitoh txr->tx_avail -= map->dm_nsegs;
1371 1.1 dyoung txr->next_avail_desc = i;
1372 1.1 dyoung
1373 1.1 dyoung txbuf->m_head = m_head;
1374 1.4 msaitoh /* Swap the dma map between the first and last descriptor */
1375 1.4 msaitoh txr->tx_buffers[first].map = txbuf->map;
1376 1.1 dyoung txbuf->map = map;
1377 1.3 msaitoh bus_dmamap_sync(txr->txtag->dt_dmat, map, 0, m_head->m_pkthdr.len,
1378 1.3 msaitoh BUS_DMASYNC_PREWRITE);
1379 1.1 dyoung
1380 1.1 dyoung /* Set the index of the descriptor that will be marked done */
1381 1.1 dyoung txbuf = &txr->tx_buffers[first];
1382 1.1 dyoung txbuf->eop_index = last;
1383 1.1 dyoung
1384 1.3 msaitoh /* XXX s/ixgbe/ixg/ */
1385 1.3 msaitoh ixgbe_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
1386 1.1 dyoung BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1387 1.1 dyoung /*
1388 1.1 dyoung * Advance the Transmit Descriptor Tail (Tdt), this tells the
1389 1.1 dyoung * hardware that this frame is available to transmit.
1390 1.1 dyoung */
1391 1.3 msaitoh ++txr->total_packets.ev_count;
1392 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDT(txr->me), i);
1393 1.1 dyoung
1394 1.3 msaitoh return 0;
1395 1.1 dyoung }
1396 1.1 dyoung
1397 1.1 dyoung
1398 1.1 dyoung /*********************************************************************
1399 1.1 dyoung * Multicast Update
1400 1.1 dyoung *
1401 1.1 dyoung * This routine is called whenever multicast address list is updated.
1402 1.1 dyoung *
1403 1.1 dyoung **********************************************************************/
1404 1.1 dyoung #define IXGBE_RAR_ENTRIES 16
1405 1.1 dyoung
1406 1.1 dyoung static void
1407 1.1 dyoung ixv_set_multi(struct adapter *adapter)
1408 1.1 dyoung {
1409 1.3 msaitoh struct ether_multi *enm;
1410 1.3 msaitoh struct ether_multistep step;
1411 1.1 dyoung u8 mta[MAX_NUM_MULTICAST_ADDRESSES * IXGBE_ETH_LENGTH_OF_ADDRESS];
1412 1.1 dyoung u8 *update_ptr;
1413 1.1 dyoung int mcnt = 0;
1414 1.3 msaitoh struct ethercom *ec = &adapter->osdep.ec;
1415 1.1 dyoung
1416 1.1 dyoung IOCTL_DEBUGOUT("ixv_set_multi: begin");
1417 1.1 dyoung
1418 1.3 msaitoh ETHER_FIRST_MULTI(step, ec, enm);
1419 1.3 msaitoh while (enm != NULL) {
1420 1.3 msaitoh bcopy(enm->enm_addrlo,
1421 1.1 dyoung &mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
1422 1.1 dyoung IXGBE_ETH_LENGTH_OF_ADDRESS);
1423 1.1 dyoung mcnt++;
1424 1.3 msaitoh /* XXX This might be required --msaitoh */
1425 1.3 msaitoh if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES)
1426 1.3 msaitoh break;
1427 1.3 msaitoh ETHER_NEXT_MULTI(step, enm);
1428 1.1 dyoung }
1429 1.1 dyoung
1430 1.1 dyoung update_ptr = mta;
1431 1.1 dyoung
1432 1.1 dyoung ixgbe_update_mc_addr_list(&adapter->hw,
1433 1.5 msaitoh update_ptr, mcnt, ixv_mc_array_itr, TRUE);
1434 1.1 dyoung
1435 1.1 dyoung return;
1436 1.1 dyoung }
1437 1.1 dyoung
1438 1.1 dyoung /*
1439 1.1 dyoung * This is an iterator function now needed by the multicast
1440 1.1 dyoung * shared code. It simply feeds the shared code routine the
1441 1.1 dyoung * addresses in the array of ixv_set_multi() one by one.
1442 1.1 dyoung */
1443 1.1 dyoung static u8 *
1444 1.1 dyoung ixv_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
1445 1.1 dyoung {
1446 1.1 dyoung u8 *addr = *update_ptr;
1447 1.1 dyoung u8 *newptr;
1448 1.1 dyoung *vmdq = 0;
1449 1.1 dyoung
1450 1.1 dyoung newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
1451 1.1 dyoung *update_ptr = newptr;
1452 1.1 dyoung return addr;
1453 1.1 dyoung }
1454 1.1 dyoung
1455 1.1 dyoung /*********************************************************************
1456 1.1 dyoung * Timer routine
1457 1.1 dyoung *
1458 1.1 dyoung * This routine checks for link status,updates statistics,
1459 1.1 dyoung * and runs the watchdog check.
1460 1.1 dyoung *
1461 1.1 dyoung **********************************************************************/
1462 1.1 dyoung
1463 1.1 dyoung static void
1464 1.3 msaitoh ixv_local_timer1(void *arg)
1465 1.1 dyoung {
1466 1.1 dyoung struct adapter *adapter = arg;
1467 1.1 dyoung device_t dev = adapter->dev;
1468 1.1 dyoung struct tx_ring *txr = adapter->tx_rings;
1469 1.1 dyoung int i;
1470 1.3 msaitoh struct timeval now, elapsed;
1471 1.1 dyoung
1472 1.3 msaitoh KASSERT(mutex_owned(&adapter->core_mtx));
1473 1.1 dyoung
1474 1.1 dyoung ixv_update_link_status(adapter);
1475 1.1 dyoung
1476 1.1 dyoung /* Stats Update */
1477 1.1 dyoung ixv_update_stats(adapter);
1478 1.1 dyoung
1479 1.1 dyoung /*
1480 1.1 dyoung * If the interface has been paused
1481 1.1 dyoung * then don't do the watchdog check
1482 1.1 dyoung */
1483 1.1 dyoung if (IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)
1484 1.1 dyoung goto out;
1485 1.1 dyoung /*
1486 1.1 dyoung ** Check for time since any descriptor was cleaned
1487 1.1 dyoung */
1488 1.1 dyoung for (i = 0; i < adapter->num_queues; i++, txr++) {
1489 1.1 dyoung IXV_TX_LOCK(txr);
1490 1.1 dyoung if (txr->watchdog_check == FALSE) {
1491 1.1 dyoung IXV_TX_UNLOCK(txr);
1492 1.1 dyoung continue;
1493 1.1 dyoung }
1494 1.3 msaitoh getmicrotime(&now);
1495 1.3 msaitoh timersub(&now, &txr->watchdog_time, &elapsed);
1496 1.3 msaitoh if (tvtohz(&elapsed) > IXV_WATCHDOG)
1497 1.1 dyoung goto hung;
1498 1.1 dyoung IXV_TX_UNLOCK(txr);
1499 1.1 dyoung }
1500 1.1 dyoung out:
1501 1.1 dyoung ixv_rearm_queues(adapter, adapter->que_mask);
1502 1.1 dyoung callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
1503 1.1 dyoung return;
1504 1.1 dyoung
1505 1.1 dyoung hung:
1506 1.1 dyoung device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
1507 1.1 dyoung device_printf(dev,"Queue(%d) tdh = %d, hw tdt = %d\n", txr->me,
1508 1.1 dyoung IXGBE_READ_REG(&adapter->hw, IXGBE_VFTDH(i)),
1509 1.1 dyoung IXGBE_READ_REG(&adapter->hw, IXGBE_VFTDT(i)));
1510 1.1 dyoung device_printf(dev,"TX(%d) desc avail = %d,"
1511 1.1 dyoung "Next TX to Clean = %d\n",
1512 1.1 dyoung txr->me, txr->tx_avail, txr->next_to_clean);
1513 1.3 msaitoh adapter->ifp->if_flags &= ~IFF_RUNNING;
1514 1.3 msaitoh adapter->watchdog_events.ev_count++;
1515 1.1 dyoung IXV_TX_UNLOCK(txr);
1516 1.1 dyoung ixv_init_locked(adapter);
1517 1.1 dyoung }
1518 1.1 dyoung
1519 1.3 msaitoh static void
1520 1.3 msaitoh ixv_local_timer(void *arg)
1521 1.3 msaitoh {
1522 1.3 msaitoh struct adapter *adapter = arg;
1523 1.3 msaitoh
1524 1.3 msaitoh IXV_CORE_LOCK(adapter);
1525 1.3 msaitoh ixv_local_timer1(adapter);
1526 1.3 msaitoh IXV_CORE_UNLOCK(adapter);
1527 1.3 msaitoh }
1528 1.3 msaitoh
1529 1.1 dyoung /*
1530 1.1 dyoung ** Note: this routine updates the OS on the link state
1531 1.1 dyoung ** the real check of the hardware only happens with
1532 1.1 dyoung ** a link interrupt.
1533 1.1 dyoung */
1534 1.1 dyoung static void
1535 1.1 dyoung ixv_update_link_status(struct adapter *adapter)
1536 1.1 dyoung {
1537 1.1 dyoung struct ifnet *ifp = adapter->ifp;
1538 1.1 dyoung struct tx_ring *txr = adapter->tx_rings;
1539 1.1 dyoung device_t dev = adapter->dev;
1540 1.1 dyoung
1541 1.1 dyoung
1542 1.1 dyoung if (adapter->link_up){
1543 1.1 dyoung if (adapter->link_active == FALSE) {
1544 1.1 dyoung if (bootverbose)
1545 1.1 dyoung device_printf(dev,"Link is up %d Gbps %s \n",
1546 1.1 dyoung ((adapter->link_speed == 128)? 10:1),
1547 1.1 dyoung "Full Duplex");
1548 1.1 dyoung adapter->link_active = TRUE;
1549 1.1 dyoung if_link_state_change(ifp, LINK_STATE_UP);
1550 1.1 dyoung }
1551 1.1 dyoung } else { /* Link down */
1552 1.1 dyoung if (adapter->link_active == TRUE) {
1553 1.1 dyoung if (bootverbose)
1554 1.1 dyoung device_printf(dev,"Link is Down\n");
1555 1.1 dyoung if_link_state_change(ifp, LINK_STATE_DOWN);
1556 1.1 dyoung adapter->link_active = FALSE;
1557 1.1 dyoung for (int i = 0; i < adapter->num_queues;
1558 1.1 dyoung i++, txr++)
1559 1.1 dyoung txr->watchdog_check = FALSE;
1560 1.1 dyoung }
1561 1.1 dyoung }
1562 1.1 dyoung
1563 1.1 dyoung return;
1564 1.1 dyoung }
1565 1.1 dyoung
1566 1.1 dyoung
1567 1.3 msaitoh static void
1568 1.3 msaitoh ixv_ifstop(struct ifnet *ifp, int disable)
1569 1.3 msaitoh {
1570 1.3 msaitoh struct adapter *adapter = ifp->if_softc;
1571 1.3 msaitoh
1572 1.3 msaitoh IXV_CORE_LOCK(adapter);
1573 1.3 msaitoh ixv_stop(adapter);
1574 1.3 msaitoh IXV_CORE_UNLOCK(adapter);
1575 1.3 msaitoh }
1576 1.3 msaitoh
1577 1.1 dyoung /*********************************************************************
1578 1.1 dyoung *
1579 1.1 dyoung * This routine disables all traffic on the adapter by issuing a
1580 1.1 dyoung * global reset on the MAC and deallocates TX/RX buffers.
1581 1.1 dyoung *
1582 1.1 dyoung **********************************************************************/
1583 1.1 dyoung
1584 1.1 dyoung static void
1585 1.1 dyoung ixv_stop(void *arg)
1586 1.1 dyoung {
1587 1.1 dyoung struct ifnet *ifp;
1588 1.1 dyoung struct adapter *adapter = arg;
1589 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
1590 1.1 dyoung ifp = adapter->ifp;
1591 1.1 dyoung
1592 1.3 msaitoh KASSERT(mutex_owned(&adapter->core_mtx));
1593 1.1 dyoung
1594 1.1 dyoung INIT_DEBUGOUT("ixv_stop: begin\n");
1595 1.1 dyoung ixv_disable_intr(adapter);
1596 1.1 dyoung
1597 1.1 dyoung /* Tell the stack that the interface is no longer active */
1598 1.3 msaitoh ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1599 1.1 dyoung
1600 1.1 dyoung ixgbe_reset_hw(hw);
1601 1.1 dyoung adapter->hw.adapter_stopped = FALSE;
1602 1.1 dyoung ixgbe_stop_adapter(hw);
1603 1.1 dyoung callout_stop(&adapter->timer);
1604 1.1 dyoung
1605 1.1 dyoung /* reprogram the RAR[0] in case user changed it. */
1606 1.1 dyoung ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
1607 1.1 dyoung
1608 1.1 dyoung return;
1609 1.1 dyoung }
1610 1.1 dyoung
1611 1.1 dyoung
1612 1.1 dyoung /*********************************************************************
1613 1.1 dyoung *
1614 1.1 dyoung * Determine hardware revision.
1615 1.1 dyoung *
1616 1.1 dyoung **********************************************************************/
1617 1.1 dyoung static void
1618 1.1 dyoung ixv_identify_hardware(struct adapter *adapter)
1619 1.1 dyoung {
1620 1.1 dyoung u16 pci_cmd_word;
1621 1.3 msaitoh pcitag_t tag;
1622 1.3 msaitoh pci_chipset_tag_t pc;
1623 1.3 msaitoh pcireg_t subid, id;
1624 1.3 msaitoh struct ixgbe_hw *hw = &adapter->hw;
1625 1.3 msaitoh
1626 1.3 msaitoh pc = adapter->osdep.pc;
1627 1.3 msaitoh tag = adapter->osdep.tag;
1628 1.1 dyoung
1629 1.1 dyoung /*
1630 1.1 dyoung ** Make sure BUSMASTER is set, on a VM under
1631 1.1 dyoung ** KVM it may not be and will break things.
1632 1.1 dyoung */
1633 1.3 msaitoh pci_cmd_word = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
1634 1.10 msaitoh if (!(pci_cmd_word & PCI_COMMAND_MASTER_ENABLE)) {
1635 1.10 msaitoh INIT_DEBUGOUT("Bus Master bit was not set!\n");
1636 1.10 msaitoh pci_cmd_word |= PCI_COMMAND_MASTER_ENABLE;
1637 1.3 msaitoh pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, pci_cmd_word);
1638 1.1 dyoung }
1639 1.1 dyoung
1640 1.3 msaitoh id = pci_conf_read(pc, tag, PCI_ID_REG);
1641 1.3 msaitoh subid = pci_conf_read(pc, tag, PCI_SUBSYS_ID_REG);
1642 1.3 msaitoh
1643 1.1 dyoung /* Save off the information about this board */
1644 1.3 msaitoh hw->vendor_id = PCI_VENDOR(id);
1645 1.3 msaitoh hw->device_id = PCI_PRODUCT(id);
1646 1.3 msaitoh hw->revision_id = PCI_REVISION(pci_conf_read(pc, tag, PCI_CLASS_REG));
1647 1.3 msaitoh hw->subsystem_vendor_id = PCI_SUBSYS_VENDOR(subid);
1648 1.3 msaitoh hw->subsystem_device_id = PCI_SUBSYS_ID(subid);
1649 1.1 dyoung
1650 1.1 dyoung return;
1651 1.1 dyoung }
1652 1.1 dyoung
1653 1.1 dyoung /*********************************************************************
1654 1.1 dyoung *
1655 1.1 dyoung * Setup MSIX Interrupt resources and handlers
1656 1.1 dyoung *
1657 1.1 dyoung **********************************************************************/
1658 1.1 dyoung static int
1659 1.11 msaitoh ixv_allocate_msix(struct adapter *adapter, const struct pci_attach_args *pa)
1660 1.1 dyoung {
1661 1.3 msaitoh #if !defined(NETBSD_MSI_OR_MSIX)
1662 1.3 msaitoh return 0;
1663 1.3 msaitoh #else
1664 1.1 dyoung device_t dev = adapter->dev;
1665 1.11 msaitoh struct ix_queue *que = adapter->queues;
1666 1.1 dyoung int error, rid, vector = 0;
1667 1.3 msaitoh pci_chipset_tag_t pc;
1668 1.11 msaitoh pcitag_t tag;
1669 1.11 msaitoh char intrbuf[PCI_INTRSTR_LEN];
1670 1.11 msaitoh const char *intrstr = NULL;
1671 1.11 msaitoh kcpuset_t *affinity;
1672 1.11 msaitoh int cpu_id = 0;
1673 1.3 msaitoh
1674 1.3 msaitoh pc = adapter->osdep.pc;
1675 1.3 msaitoh tag = adapter->osdep.tag;
1676 1.1 dyoung
1677 1.11 msaitoh if (pci_msix_alloc_exact(pa,
1678 1.11 msaitoh &adapter->osdep.intrs, IXG_MSIX_NINTR) != 0)
1679 1.11 msaitoh return (ENXIO);
1680 1.11 msaitoh
1681 1.11 msaitoh kcpuset_create(&affinity, false);
1682 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, vector++, que++) {
1683 1.11 msaitoh intrstr = pci_intr_string(pc, adapter->osdep.intrs[i], intrbuf,
1684 1.11 msaitoh sizeof(intrbuf));
1685 1.11 msaitoh #ifdef IXV_MPSAFE
1686 1.11 msaitoh pci_intr_setattr(pc, adapter->osdep.intrs[i], PCI_INTR_MPSAFE,
1687 1.11 msaitoh true);
1688 1.11 msaitoh #endif
1689 1.1 dyoung /* Set the handler function */
1690 1.11 msaitoh adapter->osdep.ihs[i] = pci_intr_establish(pc,
1691 1.11 msaitoh adapter->osdep.intrs[i], IPL_NET, ixv_msix_que, que);
1692 1.11 msaitoh if (adapter->osdep.ihs[i] == NULL) {
1693 1.1 dyoung que->res = NULL;
1694 1.3 msaitoh aprint_error_dev(dev,
1695 1.3 msaitoh "Failed to register QUE handler");
1696 1.11 msaitoh kcpuset_destroy(affinity);
1697 1.11 msaitoh return (ENXIO);
1698 1.1 dyoung }
1699 1.1 dyoung que->msix = vector;
1700 1.1 dyoung adapter->que_mask |= (u64)(1 << que->msix);
1701 1.1 dyoung
1702 1.11 msaitoh cpu_id = i;
1703 1.11 msaitoh /* Round-robin affinity */
1704 1.11 msaitoh kcpuset_zero(affinity);
1705 1.11 msaitoh kcpuset_set(affinity, cpu_id % ncpu);
1706 1.11 msaitoh error = pci_intr_distribute(adapter->osdep.ihs[i], affinity,
1707 1.11 msaitoh NULL);
1708 1.11 msaitoh aprint_normal_dev(dev, "for TX/RX, interrupting at %s",
1709 1.11 msaitoh intrstr);
1710 1.11 msaitoh if (error == 0)
1711 1.11 msaitoh aprint_normal(", bound queue %d to cpu %d\n",
1712 1.11 msaitoh i, cpu_id);
1713 1.11 msaitoh else
1714 1.11 msaitoh aprint_normal("\n");
1715 1.11 msaitoh
1716 1.3 msaitoh que->que_si = softint_establish(SOFTINT_NET, ixv_handle_que,
1717 1.3 msaitoh que);
1718 1.11 msaitoh if (que->que_si == NULL) {
1719 1.11 msaitoh aprint_error_dev(dev,
1720 1.11 msaitoh "could not establish software interrupt\n");
1721 1.11 msaitoh }
1722 1.1 dyoung }
1723 1.1 dyoung
1724 1.1 dyoung /* and Mailbox */
1725 1.11 msaitoh cpu_id++;
1726 1.11 msaitoh intrstr = pci_intr_string(pc, adapter->osdep.intrs[vector], intrbuf,
1727 1.11 msaitoh sizeof(intrbuf));
1728 1.11 msaitoh #ifdef IXG_MPSAFE
1729 1.11 msaitoh pci_intr_setattr(pc, &adapter->osdep.intrs[vector], PCI_INTR_MPSAFE, true);
1730 1.11 msaitoh #endif
1731 1.11 msaitoh /* Set the mbx handler function */
1732 1.11 msaitoh adapter->osdep.ihs[vector] = pci_intr_establish(pc,
1733 1.11 msaitoh adapter->osdep.intrs[vector], IPL_NET, ixv_msix_mbx, adapter);
1734 1.11 msaitoh if (adapter->osdep.ihs[vector] == NULL) {
1735 1.11 msaitoh adapter->res = NULL;
1736 1.11 msaitoh aprint_error_dev(dev, "Failed to register LINK handler\n");
1737 1.11 msaitoh kcpuset_destroy(affinity);
1738 1.1 dyoung return (ENXIO);
1739 1.1 dyoung }
1740 1.11 msaitoh /* Round-robin affinity */
1741 1.11 msaitoh kcpuset_zero(affinity);
1742 1.11 msaitoh kcpuset_set(affinity, cpu_id % ncpu);
1743 1.11 msaitoh error = pci_intr_distribute(adapter->osdep.ihs[vector], affinity,NULL);
1744 1.11 msaitoh
1745 1.11 msaitoh aprint_normal_dev(dev,
1746 1.11 msaitoh "for link, interrupting at %s, ", intrstr);
1747 1.11 msaitoh if (error == 0) {
1748 1.11 msaitoh aprint_normal("affinity to cpu %d\n", cpu_id);
1749 1.1 dyoung }
1750 1.1 dyoung adapter->mbxvec = vector;
1751 1.1 dyoung /* Tasklets for Mailbox */
1752 1.3 msaitoh adapter->mbx_si = softint_establish(SOFTINT_NET, ixv_handle_mbx,
1753 1.3 msaitoh adapter);
1754 1.1 dyoung /*
1755 1.1 dyoung ** Due to a broken design QEMU will fail to properly
1756 1.1 dyoung ** enable the guest for MSIX unless the vectors in
1757 1.1 dyoung ** the table are all set up, so we must rewrite the
1758 1.1 dyoung ** ENABLE in the MSIX control register again at this
1759 1.1 dyoung ** point to cause it to successfully initialize us.
1760 1.1 dyoung */
1761 1.1 dyoung if (adapter->hw.mac.type == ixgbe_mac_82599_vf) {
1762 1.1 dyoung int msix_ctrl;
1763 1.10 msaitoh pci_get_capability(pc, tag, PCI_CAP_MSIX, &rid, NULL);
1764 1.3 msaitoh rid += PCI_MSIX_CTL;
1765 1.11 msaitoh msix_ctrl = pci_conf_read(pc, tag, rid);
1766 1.3 msaitoh msix_ctrl |= PCI_MSIX_CTL_ENABLE;
1767 1.11 msaitoh pci_conf_write(pc, tag, rid, msix_ctrl);
1768 1.1 dyoung }
1769 1.1 dyoung
1770 1.1 dyoung return (0);
1771 1.3 msaitoh #endif
1772 1.1 dyoung }
1773 1.1 dyoung
1774 1.1 dyoung /*
1775 1.1 dyoung * Setup MSIX resources, note that the VF
1776 1.1 dyoung * device MUST use MSIX, there is no fallback.
1777 1.1 dyoung */
1778 1.1 dyoung static int
1779 1.1 dyoung ixv_setup_msix(struct adapter *adapter)
1780 1.1 dyoung {
1781 1.3 msaitoh #if !defined(NETBSD_MSI_OR_MSIX)
1782 1.3 msaitoh return 0;
1783 1.3 msaitoh #else
1784 1.1 dyoung device_t dev = adapter->dev;
1785 1.11 msaitoh int want, msgs;
1786 1.1 dyoung
1787 1.1 dyoung
1788 1.1 dyoung /*
1789 1.1 dyoung ** Want two vectors: one for a queue,
1790 1.1 dyoung ** plus an additional for mailbox.
1791 1.1 dyoung */
1792 1.11 msaitoh msgs = pci_msix_count(adapter->osdep.pc, adapter->osdep.tag);
1793 1.11 msaitoh if (msgs < IXG_MSIX_NINTR) {
1794 1.11 msaitoh aprint_error_dev(dev,"MSIX config error\n");
1795 1.11 msaitoh return (ENXIO);
1796 1.1 dyoung }
1797 1.11 msaitoh
1798 1.11 msaitoh adapter->msix_mem = (void *)1; /* XXX */
1799 1.11 msaitoh aprint_normal_dev(dev,
1800 1.11 msaitoh "Using MSIX interrupts with %d vectors\n", msgs);
1801 1.11 msaitoh return (want);
1802 1.3 msaitoh #endif
1803 1.1 dyoung }
1804 1.1 dyoung
1805 1.1 dyoung
1806 1.1 dyoung static int
1807 1.3 msaitoh ixv_allocate_pci_resources(struct adapter *adapter,
1808 1.3 msaitoh const struct pci_attach_args *pa)
1809 1.1 dyoung {
1810 1.3 msaitoh pcireg_t memtype;
1811 1.1 dyoung device_t dev = adapter->dev;
1812 1.3 msaitoh bus_addr_t addr;
1813 1.3 msaitoh int flags;
1814 1.1 dyoung
1815 1.3 msaitoh memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, PCI_BAR(0));
1816 1.1 dyoung
1817 1.3 msaitoh switch (memtype) {
1818 1.3 msaitoh case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
1819 1.3 msaitoh case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
1820 1.3 msaitoh adapter->osdep.mem_bus_space_tag = pa->pa_memt;
1821 1.3 msaitoh if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, PCI_BAR(0),
1822 1.3 msaitoh memtype, &addr, &adapter->osdep.mem_size, &flags) != 0)
1823 1.3 msaitoh goto map_err;
1824 1.3 msaitoh if ((flags & BUS_SPACE_MAP_PREFETCHABLE) != 0) {
1825 1.3 msaitoh aprint_normal_dev(dev, "clearing prefetchable bit\n");
1826 1.3 msaitoh flags &= ~BUS_SPACE_MAP_PREFETCHABLE;
1827 1.3 msaitoh }
1828 1.3 msaitoh if (bus_space_map(adapter->osdep.mem_bus_space_tag, addr,
1829 1.3 msaitoh adapter->osdep.mem_size, flags,
1830 1.3 msaitoh &adapter->osdep.mem_bus_space_handle) != 0) {
1831 1.3 msaitoh map_err:
1832 1.3 msaitoh adapter->osdep.mem_size = 0;
1833 1.3 msaitoh aprint_error_dev(dev, "unable to map BAR0\n");
1834 1.3 msaitoh return ENXIO;
1835 1.3 msaitoh }
1836 1.3 msaitoh break;
1837 1.3 msaitoh default:
1838 1.3 msaitoh aprint_error_dev(dev, "unexpected type on BAR0\n");
1839 1.3 msaitoh return ENXIO;
1840 1.1 dyoung }
1841 1.1 dyoung
1842 1.1 dyoung adapter->num_queues = 1;
1843 1.1 dyoung adapter->hw.back = &adapter->osdep;
1844 1.1 dyoung
1845 1.1 dyoung /*
1846 1.1 dyoung ** Now setup MSI/X, should
1847 1.1 dyoung ** return us the number of
1848 1.1 dyoung ** configured vectors.
1849 1.1 dyoung */
1850 1.1 dyoung adapter->msix = ixv_setup_msix(adapter);
1851 1.1 dyoung if (adapter->msix == ENXIO)
1852 1.1 dyoung return (ENXIO);
1853 1.1 dyoung else
1854 1.1 dyoung return (0);
1855 1.1 dyoung }
1856 1.1 dyoung
1857 1.1 dyoung static void
1858 1.1 dyoung ixv_free_pci_resources(struct adapter * adapter)
1859 1.1 dyoung {
1860 1.11 msaitoh #if !defined(NETBSD_MSI_OR_MSIX)
1861 1.11 msaitoh #else
1862 1.1 dyoung struct ix_queue *que = adapter->queues;
1863 1.11 msaitoh int rid;
1864 1.1 dyoung
1865 1.1 dyoung /*
1866 1.1 dyoung ** Release all msix queue resources:
1867 1.1 dyoung */
1868 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, que++) {
1869 1.1 dyoung rid = que->msix + 1;
1870 1.1 dyoung if (que->res != NULL)
1871 1.11 msaitoh pci_intr_disestablish(adapter->osdep.pc,
1872 1.11 msaitoh adapter->osdep.ihs[i]);
1873 1.1 dyoung }
1874 1.1 dyoung
1875 1.12 msaitoh
1876 1.1 dyoung /* Clean the Legacy or Link interrupt last */
1877 1.1 dyoung if (adapter->mbxvec) /* we are doing MSIX */
1878 1.1 dyoung rid = adapter->mbxvec + 1;
1879 1.1 dyoung else
1880 1.1 dyoung (adapter->msix != 0) ? (rid = 1):(rid = 0);
1881 1.1 dyoung
1882 1.11 msaitoh if (adapter->osdep.ihs[rid] != NULL)
1883 1.11 msaitoh pci_intr_disestablish(adapter->osdep.pc,
1884 1.11 msaitoh adapter->osdep.ihs[rid]);
1885 1.11 msaitoh adapter->osdep.ihs[rid] = NULL;
1886 1.11 msaitoh
1887 1.11 msaitoh #if defined(NETBSD_MSI_OR_MSIX)
1888 1.11 msaitoh pci_intr_release(adapter->osdep.pc, adapter->osdep.intrs,
1889 1.11 msaitoh adapter->osdep.nintrs);
1890 1.11 msaitoh #endif
1891 1.11 msaitoh
1892 1.11 msaitoh if (adapter->osdep.mem_size != 0) {
1893 1.11 msaitoh bus_space_unmap(adapter->osdep.mem_bus_space_tag,
1894 1.11 msaitoh adapter->osdep.mem_bus_space_handle,
1895 1.11 msaitoh adapter->osdep.mem_size);
1896 1.11 msaitoh }
1897 1.1 dyoung
1898 1.3 msaitoh #endif
1899 1.1 dyoung return;
1900 1.1 dyoung }
1901 1.1 dyoung
1902 1.1 dyoung /*********************************************************************
1903 1.1 dyoung *
1904 1.1 dyoung * Setup networking device structure and register an interface.
1905 1.1 dyoung *
1906 1.1 dyoung **********************************************************************/
1907 1.1 dyoung static void
1908 1.1 dyoung ixv_setup_interface(device_t dev, struct adapter *adapter)
1909 1.1 dyoung {
1910 1.3 msaitoh struct ethercom *ec = &adapter->osdep.ec;
1911 1.1 dyoung struct ifnet *ifp;
1912 1.1 dyoung
1913 1.1 dyoung INIT_DEBUGOUT("ixv_setup_interface: begin");
1914 1.1 dyoung
1915 1.3 msaitoh ifp = adapter->ifp = &ec->ec_if;
1916 1.3 msaitoh strlcpy(ifp->if_xname, device_xname(dev), IFNAMSIZ);
1917 1.1 dyoung ifp->if_baudrate = 1000000000;
1918 1.1 dyoung ifp->if_init = ixv_init;
1919 1.3 msaitoh ifp->if_stop = ixv_ifstop;
1920 1.1 dyoung ifp->if_softc = adapter;
1921 1.1 dyoung ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1922 1.1 dyoung ifp->if_ioctl = ixv_ioctl;
1923 1.1 dyoung #if __FreeBSD_version >= 800000
1924 1.1 dyoung ifp->if_transmit = ixv_mq_start;
1925 1.1 dyoung ifp->if_qflush = ixv_qflush;
1926 1.1 dyoung #else
1927 1.1 dyoung ifp->if_start = ixv_start;
1928 1.1 dyoung #endif
1929 1.1 dyoung ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 2;
1930 1.1 dyoung
1931 1.3 msaitoh if_attach(ifp);
1932 1.1 dyoung ether_ifattach(ifp, adapter->hw.mac.addr);
1933 1.3 msaitoh ether_set_ifflags_cb(ec, ixv_ifflags_cb);
1934 1.1 dyoung
1935 1.1 dyoung adapter->max_frame_size =
1936 1.1 dyoung ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
1937 1.1 dyoung
1938 1.1 dyoung /*
1939 1.1 dyoung * Tell the upper layer(s) we support long frames.
1940 1.1 dyoung */
1941 1.3 msaitoh ifp->if_hdrlen = sizeof(struct ether_vlan_header);
1942 1.3 msaitoh
1943 1.3 msaitoh ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_TSOv4;
1944 1.3 msaitoh ifp->if_capenable = 0;
1945 1.1 dyoung
1946 1.3 msaitoh ec->ec_capabilities |= ETHERCAP_VLAN_HWCSUM;
1947 1.3 msaitoh ec->ec_capabilities |= ETHERCAP_JUMBO_MTU;
1948 1.4 msaitoh ec->ec_capabilities |= ETHERCAP_VLAN_HWTAGGING
1949 1.4 msaitoh | ETHERCAP_VLAN_MTU;
1950 1.3 msaitoh ec->ec_capenable = ec->ec_capabilities;
1951 1.1 dyoung
1952 1.3 msaitoh /* Don't enable LRO by default */
1953 1.3 msaitoh ifp->if_capabilities |= IFCAP_LRO;
1954 1.3 msaitoh
1955 1.3 msaitoh /*
1956 1.3 msaitoh ** Dont turn this on by default, if vlans are
1957 1.3 msaitoh ** created on another pseudo device (eg. lagg)
1958 1.3 msaitoh ** then vlan events are not passed thru, breaking
1959 1.3 msaitoh ** operation, but with HW FILTER off it works. If
1960 1.3 msaitoh ** using vlans directly on the em driver you can
1961 1.3 msaitoh ** enable this and get full hardware tag filtering.
1962 1.3 msaitoh */
1963 1.3 msaitoh ec->ec_capabilities |= ETHERCAP_VLAN_HWFILTER;
1964 1.1 dyoung
1965 1.1 dyoung /*
1966 1.1 dyoung * Specify the media types supported by this adapter and register
1967 1.1 dyoung * callbacks to update media and link information
1968 1.1 dyoung */
1969 1.1 dyoung ifmedia_init(&adapter->media, IFM_IMASK, ixv_media_change,
1970 1.1 dyoung ixv_media_status);
1971 1.1 dyoung ifmedia_add(&adapter->media, IFM_ETHER | IFM_FDX, 0, NULL);
1972 1.1 dyoung ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1973 1.1 dyoung ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
1974 1.1 dyoung
1975 1.1 dyoung return;
1976 1.1 dyoung }
1977 1.1 dyoung
1978 1.1 dyoung static void
1979 1.1 dyoung ixv_config_link(struct adapter *adapter)
1980 1.1 dyoung {
1981 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
1982 1.1 dyoung u32 autoneg, err = 0;
1983 1.1 dyoung
1984 1.1 dyoung if (hw->mac.ops.check_link)
1985 1.1 dyoung err = hw->mac.ops.check_link(hw, &autoneg,
1986 1.1 dyoung &adapter->link_up, FALSE);
1987 1.1 dyoung if (err)
1988 1.1 dyoung goto out;
1989 1.1 dyoung
1990 1.1 dyoung if (hw->mac.ops.setup_link)
1991 1.8 msaitoh err = hw->mac.ops.setup_link(hw,
1992 1.8 msaitoh autoneg, adapter->link_up);
1993 1.1 dyoung out:
1994 1.1 dyoung return;
1995 1.1 dyoung }
1996 1.1 dyoung
1997 1.1 dyoung /********************************************************************
1998 1.1 dyoung * Manage DMA'able memory.
1999 1.1 dyoung *******************************************************************/
2000 1.1 dyoung
2001 1.1 dyoung static int
2002 1.1 dyoung ixv_dma_malloc(struct adapter *adapter, bus_size_t size,
2003 1.1 dyoung struct ixv_dma_alloc *dma, int mapflags)
2004 1.1 dyoung {
2005 1.1 dyoung device_t dev = adapter->dev;
2006 1.3 msaitoh int r, rsegs;
2007 1.1 dyoung
2008 1.3 msaitoh r = ixgbe_dma_tag_create(adapter->osdep.dmat, /* parent */
2009 1.1 dyoung DBA_ALIGN, 0, /* alignment, bounds */
2010 1.1 dyoung size, /* maxsize */
2011 1.1 dyoung 1, /* nsegments */
2012 1.1 dyoung size, /* maxsegsize */
2013 1.1 dyoung BUS_DMA_ALLOCNOW, /* flags */
2014 1.1 dyoung &dma->dma_tag);
2015 1.1 dyoung if (r != 0) {
2016 1.3 msaitoh aprint_error_dev(dev,
2017 1.3 msaitoh "ixv_dma_malloc: bus_dma_tag_create failed; error %u\n", r);
2018 1.1 dyoung goto fail_0;
2019 1.1 dyoung }
2020 1.3 msaitoh r = bus_dmamem_alloc(dma->dma_tag->dt_dmat,
2021 1.3 msaitoh size,
2022 1.3 msaitoh dma->dma_tag->dt_alignment,
2023 1.3 msaitoh dma->dma_tag->dt_boundary,
2024 1.3 msaitoh &dma->dma_seg, 1, &rsegs, BUS_DMA_NOWAIT);
2025 1.1 dyoung if (r != 0) {
2026 1.3 msaitoh aprint_error_dev(dev,
2027 1.3 msaitoh "%s: bus_dmamem_alloc failed; error %u\n", __func__, r);
2028 1.1 dyoung goto fail_1;
2029 1.1 dyoung }
2030 1.3 msaitoh
2031 1.3 msaitoh r = bus_dmamem_map(dma->dma_tag->dt_dmat, &dma->dma_seg, rsegs,
2032 1.3 msaitoh size, &dma->dma_vaddr, BUS_DMA_NOWAIT);
2033 1.3 msaitoh if (r != 0) {
2034 1.3 msaitoh aprint_error_dev(dev, "%s: bus_dmamem_map failed; error %d\n",
2035 1.3 msaitoh __func__, r);
2036 1.3 msaitoh goto fail_2;
2037 1.3 msaitoh }
2038 1.3 msaitoh
2039 1.3 msaitoh r = ixgbe_dmamap_create(dma->dma_tag, 0, &dma->dma_map);
2040 1.3 msaitoh if (r != 0) {
2041 1.3 msaitoh aprint_error_dev(dev, "%s: bus_dmamem_map failed; error %d\n",
2042 1.3 msaitoh __func__, r);
2043 1.3 msaitoh goto fail_3;
2044 1.3 msaitoh }
2045 1.3 msaitoh
2046 1.3 msaitoh r = bus_dmamap_load(dma->dma_tag->dt_dmat, dma->dma_map, dma->dma_vaddr,
2047 1.1 dyoung size,
2048 1.3 msaitoh NULL,
2049 1.1 dyoung mapflags | BUS_DMA_NOWAIT);
2050 1.1 dyoung if (r != 0) {
2051 1.3 msaitoh aprint_error_dev(dev,"%s: bus_dmamap_load failed; error %u\n",
2052 1.3 msaitoh __func__, r);
2053 1.3 msaitoh goto fail_4;
2054 1.1 dyoung }
2055 1.3 msaitoh dma->dma_paddr = dma->dma_map->dm_segs[0].ds_addr;
2056 1.1 dyoung dma->dma_size = size;
2057 1.3 msaitoh return 0;
2058 1.3 msaitoh fail_4:
2059 1.3 msaitoh ixgbe_dmamap_destroy(dma->dma_tag, dma->dma_map);
2060 1.3 msaitoh fail_3:
2061 1.3 msaitoh bus_dmamem_unmap(dma->dma_tag->dt_dmat, dma->dma_vaddr, size);
2062 1.1 dyoung fail_2:
2063 1.3 msaitoh bus_dmamem_free(dma->dma_tag->dt_dmat, &dma->dma_seg, rsegs);
2064 1.1 dyoung fail_1:
2065 1.3 msaitoh ixgbe_dma_tag_destroy(dma->dma_tag);
2066 1.1 dyoung fail_0:
2067 1.1 dyoung dma->dma_tag = NULL;
2068 1.1 dyoung return (r);
2069 1.1 dyoung }
2070 1.1 dyoung
2071 1.1 dyoung static void
2072 1.1 dyoung ixv_dma_free(struct adapter *adapter, struct ixv_dma_alloc *dma)
2073 1.1 dyoung {
2074 1.3 msaitoh bus_dmamap_sync(dma->dma_tag->dt_dmat, dma->dma_map, 0, dma->dma_size,
2075 1.1 dyoung BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2076 1.3 msaitoh ixgbe_dmamap_unload(dma->dma_tag, dma->dma_map);
2077 1.3 msaitoh bus_dmamem_free(dma->dma_tag->dt_dmat, &dma->dma_seg, 1);
2078 1.3 msaitoh ixgbe_dma_tag_destroy(dma->dma_tag);
2079 1.1 dyoung }
2080 1.1 dyoung
2081 1.1 dyoung
2082 1.1 dyoung /*********************************************************************
2083 1.1 dyoung *
2084 1.1 dyoung * Allocate memory for the transmit and receive rings, and then
2085 1.1 dyoung * the descriptors associated with each, called only once at attach.
2086 1.1 dyoung *
2087 1.1 dyoung **********************************************************************/
2088 1.1 dyoung static int
2089 1.1 dyoung ixv_allocate_queues(struct adapter *adapter)
2090 1.1 dyoung {
2091 1.1 dyoung device_t dev = adapter->dev;
2092 1.1 dyoung struct ix_queue *que;
2093 1.1 dyoung struct tx_ring *txr;
2094 1.1 dyoung struct rx_ring *rxr;
2095 1.1 dyoung int rsize, tsize, error = 0;
2096 1.1 dyoung int txconf = 0, rxconf = 0;
2097 1.1 dyoung
2098 1.1 dyoung /* First allocate the top level queue structs */
2099 1.1 dyoung if (!(adapter->queues =
2100 1.1 dyoung (struct ix_queue *) malloc(sizeof(struct ix_queue) *
2101 1.1 dyoung adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2102 1.3 msaitoh aprint_error_dev(dev, "Unable to allocate queue memory\n");
2103 1.1 dyoung error = ENOMEM;
2104 1.1 dyoung goto fail;
2105 1.1 dyoung }
2106 1.1 dyoung
2107 1.1 dyoung /* First allocate the TX ring struct memory */
2108 1.1 dyoung if (!(adapter->tx_rings =
2109 1.1 dyoung (struct tx_ring *) malloc(sizeof(struct tx_ring) *
2110 1.1 dyoung adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2111 1.3 msaitoh aprint_error_dev(dev, "Unable to allocate TX ring memory\n");
2112 1.1 dyoung error = ENOMEM;
2113 1.1 dyoung goto tx_fail;
2114 1.1 dyoung }
2115 1.1 dyoung
2116 1.1 dyoung /* Next allocate the RX */
2117 1.1 dyoung if (!(adapter->rx_rings =
2118 1.1 dyoung (struct rx_ring *) malloc(sizeof(struct rx_ring) *
2119 1.1 dyoung adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2120 1.3 msaitoh aprint_error_dev(dev, "Unable to allocate RX ring memory\n");
2121 1.1 dyoung error = ENOMEM;
2122 1.1 dyoung goto rx_fail;
2123 1.1 dyoung }
2124 1.1 dyoung
2125 1.1 dyoung /* For the ring itself */
2126 1.1 dyoung tsize = roundup2(adapter->num_tx_desc *
2127 1.1 dyoung sizeof(union ixgbe_adv_tx_desc), DBA_ALIGN);
2128 1.1 dyoung
2129 1.1 dyoung /*
2130 1.1 dyoung * Now set up the TX queues, txconf is needed to handle the
2131 1.1 dyoung * possibility that things fail midcourse and we need to
2132 1.1 dyoung * undo memory gracefully
2133 1.1 dyoung */
2134 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, txconf++) {
2135 1.1 dyoung /* Set up some basics */
2136 1.1 dyoung txr = &adapter->tx_rings[i];
2137 1.1 dyoung txr->adapter = adapter;
2138 1.1 dyoung txr->me = i;
2139 1.1 dyoung
2140 1.1 dyoung /* Initialize the TX side lock */
2141 1.1 dyoung snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)",
2142 1.3 msaitoh device_xname(dev), txr->me);
2143 1.3 msaitoh mutex_init(&txr->tx_mtx, MUTEX_DEFAULT, IPL_NET);
2144 1.1 dyoung
2145 1.1 dyoung if (ixv_dma_malloc(adapter, tsize,
2146 1.1 dyoung &txr->txdma, BUS_DMA_NOWAIT)) {
2147 1.3 msaitoh aprint_error_dev(dev,
2148 1.1 dyoung "Unable to allocate TX Descriptor memory\n");
2149 1.1 dyoung error = ENOMEM;
2150 1.1 dyoung goto err_tx_desc;
2151 1.1 dyoung }
2152 1.1 dyoung txr->tx_base = (union ixgbe_adv_tx_desc *)txr->txdma.dma_vaddr;
2153 1.1 dyoung bzero((void *)txr->tx_base, tsize);
2154 1.1 dyoung
2155 1.1 dyoung /* Now allocate transmit buffers for the ring */
2156 1.1 dyoung if (ixv_allocate_transmit_buffers(txr)) {
2157 1.3 msaitoh aprint_error_dev(dev,
2158 1.1 dyoung "Critical Failure setting up transmit buffers\n");
2159 1.1 dyoung error = ENOMEM;
2160 1.1 dyoung goto err_tx_desc;
2161 1.1 dyoung }
2162 1.1 dyoung #if __FreeBSD_version >= 800000
2163 1.1 dyoung /* Allocate a buf ring */
2164 1.1 dyoung txr->br = buf_ring_alloc(IXV_BR_SIZE, M_DEVBUF,
2165 1.1 dyoung M_WAITOK, &txr->tx_mtx);
2166 1.1 dyoung if (txr->br == NULL) {
2167 1.3 msaitoh aprint_error_dev(dev,
2168 1.1 dyoung "Critical Failure setting up buf ring\n");
2169 1.1 dyoung error = ENOMEM;
2170 1.1 dyoung goto err_tx_desc;
2171 1.1 dyoung }
2172 1.1 dyoung #endif
2173 1.1 dyoung }
2174 1.1 dyoung
2175 1.1 dyoung /*
2176 1.1 dyoung * Next the RX queues...
2177 1.1 dyoung */
2178 1.1 dyoung rsize = roundup2(adapter->num_rx_desc *
2179 1.1 dyoung sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
2180 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, rxconf++) {
2181 1.1 dyoung rxr = &adapter->rx_rings[i];
2182 1.1 dyoung /* Set up some basics */
2183 1.1 dyoung rxr->adapter = adapter;
2184 1.1 dyoung rxr->me = i;
2185 1.1 dyoung
2186 1.1 dyoung /* Initialize the RX side lock */
2187 1.1 dyoung snprintf(rxr->mtx_name, sizeof(rxr->mtx_name), "%s:rx(%d)",
2188 1.3 msaitoh device_xname(dev), rxr->me);
2189 1.3 msaitoh mutex_init(&rxr->rx_mtx, MUTEX_DEFAULT, IPL_NET);
2190 1.1 dyoung
2191 1.1 dyoung if (ixv_dma_malloc(adapter, rsize,
2192 1.1 dyoung &rxr->rxdma, BUS_DMA_NOWAIT)) {
2193 1.3 msaitoh aprint_error_dev(dev,
2194 1.1 dyoung "Unable to allocate RxDescriptor memory\n");
2195 1.1 dyoung error = ENOMEM;
2196 1.1 dyoung goto err_rx_desc;
2197 1.1 dyoung }
2198 1.1 dyoung rxr->rx_base = (union ixgbe_adv_rx_desc *)rxr->rxdma.dma_vaddr;
2199 1.1 dyoung bzero((void *)rxr->rx_base, rsize);
2200 1.1 dyoung
2201 1.1 dyoung /* Allocate receive buffers for the ring*/
2202 1.1 dyoung if (ixv_allocate_receive_buffers(rxr)) {
2203 1.3 msaitoh aprint_error_dev(dev,
2204 1.1 dyoung "Critical Failure setting up receive buffers\n");
2205 1.1 dyoung error = ENOMEM;
2206 1.1 dyoung goto err_rx_desc;
2207 1.1 dyoung }
2208 1.1 dyoung }
2209 1.1 dyoung
2210 1.1 dyoung /*
2211 1.1 dyoung ** Finally set up the queue holding structs
2212 1.1 dyoung */
2213 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++) {
2214 1.1 dyoung que = &adapter->queues[i];
2215 1.1 dyoung que->adapter = adapter;
2216 1.1 dyoung que->txr = &adapter->tx_rings[i];
2217 1.1 dyoung que->rxr = &adapter->rx_rings[i];
2218 1.1 dyoung }
2219 1.1 dyoung
2220 1.1 dyoung return (0);
2221 1.1 dyoung
2222 1.1 dyoung err_rx_desc:
2223 1.1 dyoung for (rxr = adapter->rx_rings; rxconf > 0; rxr++, rxconf--)
2224 1.1 dyoung ixv_dma_free(adapter, &rxr->rxdma);
2225 1.1 dyoung err_tx_desc:
2226 1.1 dyoung for (txr = adapter->tx_rings; txconf > 0; txr++, txconf--)
2227 1.1 dyoung ixv_dma_free(adapter, &txr->txdma);
2228 1.1 dyoung free(adapter->rx_rings, M_DEVBUF);
2229 1.1 dyoung rx_fail:
2230 1.1 dyoung free(adapter->tx_rings, M_DEVBUF);
2231 1.1 dyoung tx_fail:
2232 1.1 dyoung free(adapter->queues, M_DEVBUF);
2233 1.1 dyoung fail:
2234 1.1 dyoung return (error);
2235 1.1 dyoung }
2236 1.1 dyoung
2237 1.1 dyoung
2238 1.1 dyoung /*********************************************************************
2239 1.1 dyoung *
2240 1.1 dyoung * Allocate memory for tx_buffer structures. The tx_buffer stores all
2241 1.1 dyoung * the information needed to transmit a packet on the wire. This is
2242 1.1 dyoung * called only once at attach, setup is done every reset.
2243 1.1 dyoung *
2244 1.1 dyoung **********************************************************************/
2245 1.1 dyoung static int
2246 1.1 dyoung ixv_allocate_transmit_buffers(struct tx_ring *txr)
2247 1.1 dyoung {
2248 1.1 dyoung struct adapter *adapter = txr->adapter;
2249 1.1 dyoung device_t dev = adapter->dev;
2250 1.1 dyoung struct ixv_tx_buf *txbuf;
2251 1.1 dyoung int error, i;
2252 1.1 dyoung
2253 1.1 dyoung /*
2254 1.1 dyoung * Setup DMA descriptor areas.
2255 1.1 dyoung */
2256 1.3 msaitoh if ((error = ixgbe_dma_tag_create(adapter->osdep.dmat, /* parent */
2257 1.1 dyoung 1, 0, /* alignment, bounds */
2258 1.1 dyoung IXV_TSO_SIZE, /* maxsize */
2259 1.1 dyoung 32, /* nsegments */
2260 1.1 dyoung PAGE_SIZE, /* maxsegsize */
2261 1.1 dyoung 0, /* flags */
2262 1.1 dyoung &txr->txtag))) {
2263 1.3 msaitoh aprint_error_dev(dev,"Unable to allocate TX DMA tag\n");
2264 1.1 dyoung goto fail;
2265 1.1 dyoung }
2266 1.1 dyoung
2267 1.1 dyoung if (!(txr->tx_buffers =
2268 1.1 dyoung (struct ixv_tx_buf *) malloc(sizeof(struct ixv_tx_buf) *
2269 1.1 dyoung adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2270 1.3 msaitoh aprint_error_dev(dev, "Unable to allocate tx_buffer memory\n");
2271 1.1 dyoung error = ENOMEM;
2272 1.1 dyoung goto fail;
2273 1.1 dyoung }
2274 1.1 dyoung
2275 1.1 dyoung /* Create the descriptor buffer dma maps */
2276 1.1 dyoung txbuf = txr->tx_buffers;
2277 1.1 dyoung for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2278 1.3 msaitoh error = ixgbe_dmamap_create(txr->txtag, 0, &txbuf->map);
2279 1.1 dyoung if (error != 0) {
2280 1.3 msaitoh aprint_error_dev(dev, "Unable to create TX DMA map\n");
2281 1.1 dyoung goto fail;
2282 1.1 dyoung }
2283 1.1 dyoung }
2284 1.1 dyoung
2285 1.1 dyoung return 0;
2286 1.1 dyoung fail:
2287 1.1 dyoung /* We free all, it handles case where we are in the middle */
2288 1.1 dyoung ixv_free_transmit_structures(adapter);
2289 1.1 dyoung return (error);
2290 1.1 dyoung }
2291 1.1 dyoung
2292 1.1 dyoung /*********************************************************************
2293 1.1 dyoung *
2294 1.1 dyoung * Initialize a transmit ring.
2295 1.1 dyoung *
2296 1.1 dyoung **********************************************************************/
2297 1.1 dyoung static void
2298 1.1 dyoung ixv_setup_transmit_ring(struct tx_ring *txr)
2299 1.1 dyoung {
2300 1.1 dyoung struct adapter *adapter = txr->adapter;
2301 1.1 dyoung struct ixv_tx_buf *txbuf;
2302 1.1 dyoung int i;
2303 1.1 dyoung
2304 1.1 dyoung /* Clear the old ring contents */
2305 1.1 dyoung IXV_TX_LOCK(txr);
2306 1.1 dyoung bzero((void *)txr->tx_base,
2307 1.1 dyoung (sizeof(union ixgbe_adv_tx_desc)) * adapter->num_tx_desc);
2308 1.1 dyoung /* Reset indices */
2309 1.1 dyoung txr->next_avail_desc = 0;
2310 1.1 dyoung txr->next_to_clean = 0;
2311 1.1 dyoung
2312 1.1 dyoung /* Free any existing tx buffers. */
2313 1.1 dyoung txbuf = txr->tx_buffers;
2314 1.1 dyoung for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2315 1.1 dyoung if (txbuf->m_head != NULL) {
2316 1.3 msaitoh bus_dmamap_sync(txr->txtag->dt_dmat, txbuf->map,
2317 1.3 msaitoh 0, txbuf->m_head->m_pkthdr.len,
2318 1.1 dyoung BUS_DMASYNC_POSTWRITE);
2319 1.3 msaitoh ixgbe_dmamap_unload(txr->txtag, txbuf->map);
2320 1.1 dyoung m_freem(txbuf->m_head);
2321 1.1 dyoung txbuf->m_head = NULL;
2322 1.1 dyoung }
2323 1.1 dyoung /* Clear the EOP index */
2324 1.1 dyoung txbuf->eop_index = -1;
2325 1.1 dyoung }
2326 1.1 dyoung
2327 1.1 dyoung /* Set number of descriptors available */
2328 1.1 dyoung txr->tx_avail = adapter->num_tx_desc;
2329 1.1 dyoung
2330 1.3 msaitoh ixgbe_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
2331 1.1 dyoung BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2332 1.1 dyoung IXV_TX_UNLOCK(txr);
2333 1.1 dyoung }
2334 1.1 dyoung
2335 1.1 dyoung /*********************************************************************
2336 1.1 dyoung *
2337 1.1 dyoung * Initialize all transmit rings.
2338 1.1 dyoung *
2339 1.1 dyoung **********************************************************************/
2340 1.1 dyoung static int
2341 1.1 dyoung ixv_setup_transmit_structures(struct adapter *adapter)
2342 1.1 dyoung {
2343 1.1 dyoung struct tx_ring *txr = adapter->tx_rings;
2344 1.1 dyoung
2345 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, txr++)
2346 1.1 dyoung ixv_setup_transmit_ring(txr);
2347 1.1 dyoung
2348 1.1 dyoung return (0);
2349 1.1 dyoung }
2350 1.1 dyoung
2351 1.1 dyoung /*********************************************************************
2352 1.1 dyoung *
2353 1.1 dyoung * Enable transmit unit.
2354 1.1 dyoung *
2355 1.1 dyoung **********************************************************************/
2356 1.1 dyoung static void
2357 1.1 dyoung ixv_initialize_transmit_units(struct adapter *adapter)
2358 1.1 dyoung {
2359 1.1 dyoung struct tx_ring *txr = adapter->tx_rings;
2360 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
2361 1.1 dyoung
2362 1.1 dyoung
2363 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, txr++) {
2364 1.1 dyoung u64 tdba = txr->txdma.dma_paddr;
2365 1.1 dyoung u32 txctrl, txdctl;
2366 1.1 dyoung
2367 1.1 dyoung /* Set WTHRESH to 8, burst writeback */
2368 1.1 dyoung txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
2369 1.1 dyoung txdctl |= (8 << 16);
2370 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
2371 1.1 dyoung /* Now enable */
2372 1.1 dyoung txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
2373 1.1 dyoung txdctl |= IXGBE_TXDCTL_ENABLE;
2374 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), txdctl);
2375 1.1 dyoung
2376 1.1 dyoung /* Set the HW Tx Head and Tail indices */
2377 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDH(i), 0);
2378 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDT(i), 0);
2379 1.1 dyoung
2380 1.1 dyoung /* Setup Transmit Descriptor Cmd Settings */
2381 1.1 dyoung txr->txd_cmd = IXGBE_TXD_CMD_IFCS;
2382 1.1 dyoung txr->watchdog_check = FALSE;
2383 1.1 dyoung
2384 1.1 dyoung /* Set Ring parameters */
2385 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(i),
2386 1.1 dyoung (tdba & 0x00000000ffffffffULL));
2387 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(i), (tdba >> 32));
2388 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(i),
2389 1.1 dyoung adapter->num_tx_desc *
2390 1.1 dyoung sizeof(struct ixgbe_legacy_tx_desc));
2391 1.1 dyoung txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(i));
2392 1.6 msaitoh txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
2393 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i), txctrl);
2394 1.1 dyoung break;
2395 1.1 dyoung }
2396 1.1 dyoung
2397 1.1 dyoung return;
2398 1.1 dyoung }
2399 1.1 dyoung
2400 1.1 dyoung /*********************************************************************
2401 1.1 dyoung *
2402 1.1 dyoung * Free all transmit rings.
2403 1.1 dyoung *
2404 1.1 dyoung **********************************************************************/
2405 1.1 dyoung static void
2406 1.1 dyoung ixv_free_transmit_structures(struct adapter *adapter)
2407 1.1 dyoung {
2408 1.1 dyoung struct tx_ring *txr = adapter->tx_rings;
2409 1.1 dyoung
2410 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, txr++) {
2411 1.1 dyoung ixv_free_transmit_buffers(txr);
2412 1.1 dyoung ixv_dma_free(adapter, &txr->txdma);
2413 1.1 dyoung IXV_TX_LOCK_DESTROY(txr);
2414 1.1 dyoung }
2415 1.1 dyoung free(adapter->tx_rings, M_DEVBUF);
2416 1.1 dyoung }
2417 1.1 dyoung
2418 1.1 dyoung /*********************************************************************
2419 1.1 dyoung *
2420 1.1 dyoung * Free transmit ring related data structures.
2421 1.1 dyoung *
2422 1.1 dyoung **********************************************************************/
2423 1.1 dyoung static void
2424 1.1 dyoung ixv_free_transmit_buffers(struct tx_ring *txr)
2425 1.1 dyoung {
2426 1.1 dyoung struct adapter *adapter = txr->adapter;
2427 1.1 dyoung struct ixv_tx_buf *tx_buffer;
2428 1.1 dyoung int i;
2429 1.1 dyoung
2430 1.1 dyoung INIT_DEBUGOUT("free_transmit_ring: begin");
2431 1.1 dyoung
2432 1.1 dyoung if (txr->tx_buffers == NULL)
2433 1.1 dyoung return;
2434 1.1 dyoung
2435 1.1 dyoung tx_buffer = txr->tx_buffers;
2436 1.1 dyoung for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
2437 1.1 dyoung if (tx_buffer->m_head != NULL) {
2438 1.3 msaitoh bus_dmamap_sync(txr->txtag->dt_dmat, tx_buffer->map,
2439 1.3 msaitoh 0, tx_buffer->m_head->m_pkthdr.len,
2440 1.1 dyoung BUS_DMASYNC_POSTWRITE);
2441 1.3 msaitoh ixgbe_dmamap_unload(txr->txtag, tx_buffer->map);
2442 1.1 dyoung m_freem(tx_buffer->m_head);
2443 1.1 dyoung tx_buffer->m_head = NULL;
2444 1.1 dyoung if (tx_buffer->map != NULL) {
2445 1.3 msaitoh ixgbe_dmamap_destroy(txr->txtag,
2446 1.1 dyoung tx_buffer->map);
2447 1.1 dyoung tx_buffer->map = NULL;
2448 1.1 dyoung }
2449 1.1 dyoung } else if (tx_buffer->map != NULL) {
2450 1.3 msaitoh ixgbe_dmamap_unload(txr->txtag, tx_buffer->map);
2451 1.3 msaitoh ixgbe_dmamap_destroy(txr->txtag, tx_buffer->map);
2452 1.1 dyoung tx_buffer->map = NULL;
2453 1.1 dyoung }
2454 1.1 dyoung }
2455 1.1 dyoung #if __FreeBSD_version >= 800000
2456 1.1 dyoung if (txr->br != NULL)
2457 1.1 dyoung buf_ring_free(txr->br, M_DEVBUF);
2458 1.1 dyoung #endif
2459 1.1 dyoung if (txr->tx_buffers != NULL) {
2460 1.1 dyoung free(txr->tx_buffers, M_DEVBUF);
2461 1.1 dyoung txr->tx_buffers = NULL;
2462 1.1 dyoung }
2463 1.1 dyoung if (txr->txtag != NULL) {
2464 1.3 msaitoh ixgbe_dma_tag_destroy(txr->txtag);
2465 1.1 dyoung txr->txtag = NULL;
2466 1.1 dyoung }
2467 1.1 dyoung return;
2468 1.1 dyoung }
2469 1.1 dyoung
2470 1.1 dyoung /*********************************************************************
2471 1.1 dyoung *
2472 1.12 msaitoh * Advanced Context Descriptor setup for VLAN or CSUM
2473 1.1 dyoung *
2474 1.1 dyoung **********************************************************************/
2475 1.1 dyoung
2476 1.3 msaitoh static u32
2477 1.1 dyoung ixv_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp)
2478 1.1 dyoung {
2479 1.3 msaitoh struct m_tag *mtag;
2480 1.1 dyoung struct adapter *adapter = txr->adapter;
2481 1.3 msaitoh struct ethercom *ec = &adapter->osdep.ec;
2482 1.1 dyoung struct ixgbe_adv_tx_context_desc *TXD;
2483 1.1 dyoung struct ixv_tx_buf *tx_buffer;
2484 1.3 msaitoh u32 olinfo = 0, vlan_macip_lens = 0, type_tucmd_mlhl = 0;
2485 1.1 dyoung struct ether_vlan_header *eh;
2486 1.3 msaitoh struct ip ip;
2487 1.3 msaitoh struct ip6_hdr ip6;
2488 1.1 dyoung int ehdrlen, ip_hlen = 0;
2489 1.1 dyoung u16 etype;
2490 1.1 dyoung u8 ipproto = 0;
2491 1.3 msaitoh bool offload;
2492 1.1 dyoung int ctxd = txr->next_avail_desc;
2493 1.1 dyoung u16 vtag = 0;
2494 1.1 dyoung
2495 1.1 dyoung
2496 1.3 msaitoh offload = ((mp->m_pkthdr.csum_flags & M_CSUM_OFFLOAD) != 0);
2497 1.1 dyoung
2498 1.1 dyoung tx_buffer = &txr->tx_buffers[ctxd];
2499 1.1 dyoung TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
2500 1.1 dyoung
2501 1.1 dyoung /*
2502 1.1 dyoung ** In advanced descriptors the vlan tag must
2503 1.1 dyoung ** be placed into the descriptor itself.
2504 1.1 dyoung */
2505 1.3 msaitoh if ((mtag = VLAN_OUTPUT_TAG(ec, mp)) != NULL) {
2506 1.3 msaitoh vtag = htole16(VLAN_TAG_VALUE(mtag) & 0xffff);
2507 1.1 dyoung vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
2508 1.3 msaitoh } else if (!offload)
2509 1.3 msaitoh return 0;
2510 1.1 dyoung
2511 1.1 dyoung /*
2512 1.1 dyoung * Determine where frame payload starts.
2513 1.1 dyoung * Jump over vlan headers if already present,
2514 1.1 dyoung * helpful for QinQ too.
2515 1.1 dyoung */
2516 1.3 msaitoh KASSERT(mp->m_len >= offsetof(struct ether_vlan_header, evl_tag));
2517 1.1 dyoung eh = mtod(mp, struct ether_vlan_header *);
2518 1.1 dyoung if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
2519 1.3 msaitoh KASSERT(mp->m_len >= sizeof(struct ether_vlan_header));
2520 1.1 dyoung etype = ntohs(eh->evl_proto);
2521 1.1 dyoung ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
2522 1.1 dyoung } else {
2523 1.1 dyoung etype = ntohs(eh->evl_encap_proto);
2524 1.1 dyoung ehdrlen = ETHER_HDR_LEN;
2525 1.1 dyoung }
2526 1.1 dyoung
2527 1.1 dyoung /* Set the ether header length */
2528 1.1 dyoung vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
2529 1.1 dyoung
2530 1.1 dyoung switch (etype) {
2531 1.3 msaitoh case ETHERTYPE_IP:
2532 1.3 msaitoh m_copydata(mp, ehdrlen, sizeof(ip), &ip);
2533 1.3 msaitoh ip_hlen = ip.ip_hl << 2;
2534 1.3 msaitoh ipproto = ip.ip_p;
2535 1.3 msaitoh #if 0
2536 1.3 msaitoh ip.ip_sum = 0;
2537 1.3 msaitoh m_copyback(mp, ehdrlen, sizeof(ip), &ip);
2538 1.3 msaitoh #else
2539 1.3 msaitoh KASSERT((mp->m_pkthdr.csum_flags & M_CSUM_IPv4) == 0 ||
2540 1.3 msaitoh ip.ip_sum == 0);
2541 1.3 msaitoh #endif
2542 1.3 msaitoh type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
2543 1.3 msaitoh break;
2544 1.3 msaitoh case ETHERTYPE_IPV6:
2545 1.3 msaitoh m_copydata(mp, ehdrlen, sizeof(ip6), &ip6);
2546 1.3 msaitoh ip_hlen = sizeof(ip6);
2547 1.3 msaitoh ipproto = ip6.ip6_nxt;
2548 1.3 msaitoh type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
2549 1.3 msaitoh break;
2550 1.3 msaitoh default:
2551 1.3 msaitoh break;
2552 1.1 dyoung }
2553 1.1 dyoung
2554 1.3 msaitoh if ((mp->m_pkthdr.csum_flags & M_CSUM_IPv4) != 0)
2555 1.3 msaitoh olinfo |= IXGBE_TXD_POPTS_IXSM << 8;
2556 1.3 msaitoh
2557 1.1 dyoung vlan_macip_lens |= ip_hlen;
2558 1.1 dyoung type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
2559 1.1 dyoung
2560 1.3 msaitoh if (mp->m_pkthdr.csum_flags & (M_CSUM_TCPv4|M_CSUM_TCPv6)) {
2561 1.3 msaitoh type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
2562 1.3 msaitoh olinfo |= IXGBE_TXD_POPTS_TXSM << 8;
2563 1.3 msaitoh KASSERT(ipproto == IPPROTO_TCP);
2564 1.3 msaitoh } else if (mp->m_pkthdr.csum_flags & (M_CSUM_UDPv4|M_CSUM_UDPv6)) {
2565 1.3 msaitoh type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_UDP;
2566 1.3 msaitoh olinfo |= IXGBE_TXD_POPTS_TXSM << 8;
2567 1.3 msaitoh KASSERT(ipproto == IPPROTO_UDP);
2568 1.1 dyoung }
2569 1.1 dyoung
2570 1.1 dyoung /* Now copy bits into descriptor */
2571 1.1 dyoung TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
2572 1.1 dyoung TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
2573 1.1 dyoung TXD->seqnum_seed = htole32(0);
2574 1.1 dyoung TXD->mss_l4len_idx = htole32(0);
2575 1.1 dyoung
2576 1.1 dyoung tx_buffer->m_head = NULL;
2577 1.1 dyoung tx_buffer->eop_index = -1;
2578 1.1 dyoung
2579 1.1 dyoung /* We've consumed the first desc, adjust counters */
2580 1.1 dyoung if (++ctxd == adapter->num_tx_desc)
2581 1.1 dyoung ctxd = 0;
2582 1.1 dyoung txr->next_avail_desc = ctxd;
2583 1.1 dyoung --txr->tx_avail;
2584 1.1 dyoung
2585 1.3 msaitoh return olinfo;
2586 1.1 dyoung }
2587 1.1 dyoung
2588 1.1 dyoung /**********************************************************************
2589 1.1 dyoung *
2590 1.1 dyoung * Setup work for hardware segmentation offload (TSO) on
2591 1.1 dyoung * adapters using advanced tx descriptors
2592 1.1 dyoung *
2593 1.1 dyoung **********************************************************************/
2594 1.3 msaitoh static bool
2595 1.1 dyoung ixv_tso_setup(struct tx_ring *txr, struct mbuf *mp, u32 *paylen)
2596 1.1 dyoung {
2597 1.3 msaitoh struct m_tag *mtag;
2598 1.1 dyoung struct adapter *adapter = txr->adapter;
2599 1.3 msaitoh struct ethercom *ec = &adapter->osdep.ec;
2600 1.1 dyoung struct ixgbe_adv_tx_context_desc *TXD;
2601 1.1 dyoung struct ixv_tx_buf *tx_buffer;
2602 1.1 dyoung u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
2603 1.1 dyoung u32 mss_l4len_idx = 0;
2604 1.1 dyoung u16 vtag = 0;
2605 1.1 dyoung int ctxd, ehdrlen, hdrlen, ip_hlen, tcp_hlen;
2606 1.1 dyoung struct ether_vlan_header *eh;
2607 1.1 dyoung struct ip *ip;
2608 1.1 dyoung struct tcphdr *th;
2609 1.1 dyoung
2610 1.1 dyoung
2611 1.1 dyoung /*
2612 1.1 dyoung * Determine where frame payload starts.
2613 1.1 dyoung * Jump over vlan headers if already present
2614 1.1 dyoung */
2615 1.1 dyoung eh = mtod(mp, struct ether_vlan_header *);
2616 1.1 dyoung if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN))
2617 1.1 dyoung ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
2618 1.1 dyoung else
2619 1.1 dyoung ehdrlen = ETHER_HDR_LEN;
2620 1.1 dyoung
2621 1.1 dyoung /* Ensure we have at least the IP+TCP header in the first mbuf. */
2622 1.1 dyoung if (mp->m_len < ehdrlen + sizeof(struct ip) + sizeof(struct tcphdr))
2623 1.1 dyoung return FALSE;
2624 1.1 dyoung
2625 1.1 dyoung ctxd = txr->next_avail_desc;
2626 1.1 dyoung tx_buffer = &txr->tx_buffers[ctxd];
2627 1.1 dyoung TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
2628 1.1 dyoung
2629 1.1 dyoung ip = (struct ip *)(mp->m_data + ehdrlen);
2630 1.1 dyoung if (ip->ip_p != IPPROTO_TCP)
2631 1.1 dyoung return FALSE; /* 0 */
2632 1.1 dyoung ip->ip_sum = 0;
2633 1.1 dyoung ip_hlen = ip->ip_hl << 2;
2634 1.3 msaitoh th = (struct tcphdr *)((char *)ip + ip_hlen);
2635 1.3 msaitoh /* XXX Educated guess: FreeBSD's in_pseudo == NetBSD's in_cksum_phdr */
2636 1.3 msaitoh th->th_sum = in_cksum_phdr(ip->ip_src.s_addr,
2637 1.1 dyoung ip->ip_dst.s_addr, htons(IPPROTO_TCP));
2638 1.1 dyoung tcp_hlen = th->th_off << 2;
2639 1.1 dyoung hdrlen = ehdrlen + ip_hlen + tcp_hlen;
2640 1.1 dyoung
2641 1.1 dyoung /* This is used in the transmit desc in encap */
2642 1.1 dyoung *paylen = mp->m_pkthdr.len - hdrlen;
2643 1.1 dyoung
2644 1.1 dyoung /* VLAN MACLEN IPLEN */
2645 1.3 msaitoh if ((mtag = VLAN_OUTPUT_TAG(ec, mp)) != NULL) {
2646 1.3 msaitoh vtag = htole16(VLAN_TAG_VALUE(mtag) & 0xffff);
2647 1.1 dyoung vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
2648 1.1 dyoung }
2649 1.1 dyoung
2650 1.1 dyoung vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
2651 1.1 dyoung vlan_macip_lens |= ip_hlen;
2652 1.1 dyoung TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
2653 1.1 dyoung
2654 1.1 dyoung /* ADV DTYPE TUCMD */
2655 1.1 dyoung type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
2656 1.1 dyoung type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
2657 1.1 dyoung type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
2658 1.1 dyoung TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
2659 1.1 dyoung
2660 1.1 dyoung
2661 1.1 dyoung /* MSS L4LEN IDX */
2662 1.3 msaitoh mss_l4len_idx |= (mp->m_pkthdr.segsz << IXGBE_ADVTXD_MSS_SHIFT);
2663 1.1 dyoung mss_l4len_idx |= (tcp_hlen << IXGBE_ADVTXD_L4LEN_SHIFT);
2664 1.1 dyoung TXD->mss_l4len_idx = htole32(mss_l4len_idx);
2665 1.1 dyoung
2666 1.1 dyoung TXD->seqnum_seed = htole32(0);
2667 1.1 dyoung tx_buffer->m_head = NULL;
2668 1.1 dyoung tx_buffer->eop_index = -1;
2669 1.1 dyoung
2670 1.1 dyoung if (++ctxd == adapter->num_tx_desc)
2671 1.1 dyoung ctxd = 0;
2672 1.1 dyoung
2673 1.1 dyoung txr->tx_avail--;
2674 1.1 dyoung txr->next_avail_desc = ctxd;
2675 1.1 dyoung return TRUE;
2676 1.1 dyoung }
2677 1.1 dyoung
2678 1.1 dyoung
2679 1.1 dyoung /**********************************************************************
2680 1.1 dyoung *
2681 1.1 dyoung * Examine each tx_buffer in the used queue. If the hardware is done
2682 1.1 dyoung * processing the packet then free associated resources. The
2683 1.1 dyoung * tx_buffer is put back on the free queue.
2684 1.1 dyoung *
2685 1.1 dyoung **********************************************************************/
2686 1.3 msaitoh static bool
2687 1.1 dyoung ixv_txeof(struct tx_ring *txr)
2688 1.1 dyoung {
2689 1.1 dyoung struct adapter *adapter = txr->adapter;
2690 1.1 dyoung struct ifnet *ifp = adapter->ifp;
2691 1.1 dyoung u32 first, last, done;
2692 1.1 dyoung struct ixv_tx_buf *tx_buffer;
2693 1.1 dyoung struct ixgbe_legacy_tx_desc *tx_desc, *eop_desc;
2694 1.1 dyoung
2695 1.3 msaitoh KASSERT(mutex_owned(&txr->tx_mtx));
2696 1.1 dyoung
2697 1.1 dyoung if (txr->tx_avail == adapter->num_tx_desc)
2698 1.3 msaitoh return false;
2699 1.1 dyoung
2700 1.1 dyoung first = txr->next_to_clean;
2701 1.1 dyoung tx_buffer = &txr->tx_buffers[first];
2702 1.1 dyoung /* For cleanup we just use legacy struct */
2703 1.1 dyoung tx_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
2704 1.1 dyoung last = tx_buffer->eop_index;
2705 1.1 dyoung if (last == -1)
2706 1.3 msaitoh return false;
2707 1.1 dyoung eop_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
2708 1.1 dyoung
2709 1.1 dyoung /*
2710 1.1 dyoung ** Get the index of the first descriptor
2711 1.1 dyoung ** BEYOND the EOP and call that 'done'.
2712 1.1 dyoung ** I do this so the comparison in the
2713 1.1 dyoung ** inner while loop below can be simple
2714 1.1 dyoung */
2715 1.1 dyoung if (++last == adapter->num_tx_desc) last = 0;
2716 1.1 dyoung done = last;
2717 1.1 dyoung
2718 1.3 msaitoh ixgbe_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
2719 1.1 dyoung BUS_DMASYNC_POSTREAD);
2720 1.1 dyoung /*
2721 1.1 dyoung ** Only the EOP descriptor of a packet now has the DD
2722 1.1 dyoung ** bit set, this is what we look for...
2723 1.1 dyoung */
2724 1.1 dyoung while (eop_desc->upper.fields.status & IXGBE_TXD_STAT_DD) {
2725 1.1 dyoung /* We clean the range of the packet */
2726 1.1 dyoung while (first != done) {
2727 1.1 dyoung tx_desc->upper.data = 0;
2728 1.1 dyoung tx_desc->lower.data = 0;
2729 1.1 dyoung tx_desc->buffer_addr = 0;
2730 1.1 dyoung ++txr->tx_avail;
2731 1.1 dyoung
2732 1.1 dyoung if (tx_buffer->m_head) {
2733 1.3 msaitoh bus_dmamap_sync(txr->txtag->dt_dmat,
2734 1.1 dyoung tx_buffer->map,
2735 1.3 msaitoh 0, tx_buffer->m_head->m_pkthdr.len,
2736 1.1 dyoung BUS_DMASYNC_POSTWRITE);
2737 1.3 msaitoh ixgbe_dmamap_unload(txr->txtag, tx_buffer->map);
2738 1.1 dyoung m_freem(tx_buffer->m_head);
2739 1.1 dyoung tx_buffer->m_head = NULL;
2740 1.1 dyoung tx_buffer->map = NULL;
2741 1.1 dyoung }
2742 1.1 dyoung tx_buffer->eop_index = -1;
2743 1.3 msaitoh getmicrotime(&txr->watchdog_time);
2744 1.1 dyoung
2745 1.1 dyoung if (++first == adapter->num_tx_desc)
2746 1.1 dyoung first = 0;
2747 1.1 dyoung
2748 1.1 dyoung tx_buffer = &txr->tx_buffers[first];
2749 1.1 dyoung tx_desc =
2750 1.1 dyoung (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
2751 1.1 dyoung }
2752 1.1 dyoung ++ifp->if_opackets;
2753 1.1 dyoung /* See if there is more work now */
2754 1.1 dyoung last = tx_buffer->eop_index;
2755 1.1 dyoung if (last != -1) {
2756 1.1 dyoung eop_desc =
2757 1.1 dyoung (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
2758 1.1 dyoung /* Get next done point */
2759 1.1 dyoung if (++last == adapter->num_tx_desc) last = 0;
2760 1.1 dyoung done = last;
2761 1.1 dyoung } else
2762 1.1 dyoung break;
2763 1.1 dyoung }
2764 1.3 msaitoh ixgbe_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
2765 1.1 dyoung BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2766 1.1 dyoung
2767 1.1 dyoung txr->next_to_clean = first;
2768 1.1 dyoung
2769 1.1 dyoung /*
2770 1.3 msaitoh * If we have enough room, clear IFF_OACTIVE to tell the stack that
2771 1.1 dyoung * it is OK to send packets. If there are no pending descriptors,
2772 1.1 dyoung * clear the timeout. Otherwise, if some descriptors have been freed,
2773 1.1 dyoung * restart the timeout.
2774 1.1 dyoung */
2775 1.1 dyoung if (txr->tx_avail > IXV_TX_CLEANUP_THRESHOLD) {
2776 1.3 msaitoh ifp->if_flags &= ~IFF_OACTIVE;
2777 1.1 dyoung if (txr->tx_avail == adapter->num_tx_desc) {
2778 1.1 dyoung txr->watchdog_check = FALSE;
2779 1.3 msaitoh return false;
2780 1.1 dyoung }
2781 1.1 dyoung }
2782 1.1 dyoung
2783 1.3 msaitoh return true;
2784 1.1 dyoung }
2785 1.1 dyoung
2786 1.1 dyoung /*********************************************************************
2787 1.1 dyoung *
2788 1.1 dyoung * Refresh mbuf buffers for RX descriptor rings
2789 1.1 dyoung * - now keeps its own state so discards due to resource
2790 1.1 dyoung * exhaustion are unnecessary, if an mbuf cannot be obtained
2791 1.1 dyoung * it just returns, keeping its placeholder, thus it can simply
2792 1.1 dyoung * be recalled to try again.
2793 1.1 dyoung *
2794 1.1 dyoung **********************************************************************/
2795 1.1 dyoung static void
2796 1.1 dyoung ixv_refresh_mbufs(struct rx_ring *rxr, int limit)
2797 1.1 dyoung {
2798 1.1 dyoung struct adapter *adapter = rxr->adapter;
2799 1.1 dyoung struct ixv_rx_buf *rxbuf;
2800 1.1 dyoung struct mbuf *mh, *mp;
2801 1.3 msaitoh int i, j, error;
2802 1.3 msaitoh bool refreshed = false;
2803 1.1 dyoung
2804 1.3 msaitoh i = j = rxr->next_to_refresh;
2805 1.5 msaitoh /* Get the control variable, one beyond refresh point */
2806 1.3 msaitoh if (++j == adapter->num_rx_desc)
2807 1.3 msaitoh j = 0;
2808 1.3 msaitoh while (j != limit) {
2809 1.1 dyoung rxbuf = &rxr->rx_buffers[i];
2810 1.1 dyoung if ((rxbuf->m_head == NULL) && (rxr->hdr_split)) {
2811 1.8 msaitoh mh = m_gethdr(M_NOWAIT, MT_DATA);
2812 1.1 dyoung if (mh == NULL)
2813 1.1 dyoung goto update;
2814 1.1 dyoung mh->m_pkthdr.len = mh->m_len = MHLEN;
2815 1.1 dyoung mh->m_flags |= M_PKTHDR;
2816 1.1 dyoung m_adj(mh, ETHER_ALIGN);
2817 1.1 dyoung /* Get the memory mapping */
2818 1.3 msaitoh error = bus_dmamap_load_mbuf(rxr->htag->dt_dmat,
2819 1.3 msaitoh rxbuf->hmap, mh, BUS_DMA_NOWAIT);
2820 1.1 dyoung if (error != 0) {
2821 1.1 dyoung printf("GET BUF: dmamap load"
2822 1.1 dyoung " failure - %d\n", error);
2823 1.1 dyoung m_free(mh);
2824 1.1 dyoung goto update;
2825 1.1 dyoung }
2826 1.1 dyoung rxbuf->m_head = mh;
2827 1.3 msaitoh ixgbe_dmamap_sync(rxr->htag, rxbuf->hmap,
2828 1.1 dyoung BUS_DMASYNC_PREREAD);
2829 1.1 dyoung rxr->rx_base[i].read.hdr_addr =
2830 1.3 msaitoh htole64(rxbuf->hmap->dm_segs[0].ds_addr);
2831 1.1 dyoung }
2832 1.1 dyoung
2833 1.1 dyoung if (rxbuf->m_pack == NULL) {
2834 1.8 msaitoh mp = ixgbe_getjcl(&adapter->jcl_head, M_NOWAIT,
2835 1.3 msaitoh MT_DATA, M_PKTHDR, adapter->rx_mbuf_sz);
2836 1.3 msaitoh if (mp == NULL) {
2837 1.3 msaitoh rxr->no_jmbuf.ev_count++;
2838 1.1 dyoung goto update;
2839 1.5 msaitoh } else
2840 1.5 msaitoh mp = rxbuf->m_pack;
2841 1.5 msaitoh
2842 1.1 dyoung mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
2843 1.1 dyoung /* Get the memory mapping */
2844 1.3 msaitoh error = bus_dmamap_load_mbuf(rxr->ptag->dt_dmat,
2845 1.3 msaitoh rxbuf->pmap, mp, BUS_DMA_NOWAIT);
2846 1.1 dyoung if (error != 0) {
2847 1.1 dyoung printf("GET BUF: dmamap load"
2848 1.1 dyoung " failure - %d\n", error);
2849 1.1 dyoung m_free(mp);
2850 1.5 msaitoh rxbuf->m_pack = NULL;
2851 1.1 dyoung goto update;
2852 1.1 dyoung }
2853 1.1 dyoung rxbuf->m_pack = mp;
2854 1.3 msaitoh bus_dmamap_sync(rxr->ptag->dt_dmat, rxbuf->pmap,
2855 1.3 msaitoh 0, mp->m_pkthdr.len, BUS_DMASYNC_PREREAD);
2856 1.1 dyoung rxr->rx_base[i].read.pkt_addr =
2857 1.3 msaitoh htole64(rxbuf->pmap->dm_segs[0].ds_addr);
2858 1.1 dyoung }
2859 1.1 dyoung
2860 1.3 msaitoh refreshed = true;
2861 1.3 msaitoh rxr->next_to_refresh = i = j;
2862 1.1 dyoung /* Calculate next index */
2863 1.3 msaitoh if (++j == adapter->num_rx_desc)
2864 1.3 msaitoh j = 0;
2865 1.1 dyoung }
2866 1.1 dyoung update:
2867 1.5 msaitoh if (refreshed) /* update tail index */
2868 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw,
2869 1.3 msaitoh IXGBE_VFRDT(rxr->me), rxr->next_to_refresh);
2870 1.1 dyoung return;
2871 1.1 dyoung }
2872 1.1 dyoung
2873 1.1 dyoung /*********************************************************************
2874 1.1 dyoung *
2875 1.1 dyoung * Allocate memory for rx_buffer structures. Since we use one
2876 1.1 dyoung * rx_buffer per received packet, the maximum number of rx_buffer's
2877 1.1 dyoung * that we'll need is equal to the number of receive descriptors
2878 1.1 dyoung * that we've allocated.
2879 1.1 dyoung *
2880 1.1 dyoung **********************************************************************/
2881 1.1 dyoung static int
2882 1.1 dyoung ixv_allocate_receive_buffers(struct rx_ring *rxr)
2883 1.1 dyoung {
2884 1.1 dyoung struct adapter *adapter = rxr->adapter;
2885 1.1 dyoung device_t dev = adapter->dev;
2886 1.1 dyoung struct ixv_rx_buf *rxbuf;
2887 1.1 dyoung int i, bsize, error;
2888 1.1 dyoung
2889 1.1 dyoung bsize = sizeof(struct ixv_rx_buf) * adapter->num_rx_desc;
2890 1.1 dyoung if (!(rxr->rx_buffers =
2891 1.1 dyoung (struct ixv_rx_buf *) malloc(bsize,
2892 1.1 dyoung M_DEVBUF, M_NOWAIT | M_ZERO))) {
2893 1.3 msaitoh aprint_error_dev(dev, "Unable to allocate rx_buffer memory\n");
2894 1.1 dyoung error = ENOMEM;
2895 1.1 dyoung goto fail;
2896 1.1 dyoung }
2897 1.1 dyoung
2898 1.3 msaitoh if ((error = ixgbe_dma_tag_create(adapter->osdep.dmat, /* parent */
2899 1.1 dyoung 1, 0, /* alignment, bounds */
2900 1.1 dyoung MSIZE, /* maxsize */
2901 1.1 dyoung 1, /* nsegments */
2902 1.1 dyoung MSIZE, /* maxsegsize */
2903 1.1 dyoung 0, /* flags */
2904 1.1 dyoung &rxr->htag))) {
2905 1.3 msaitoh aprint_error_dev(dev, "Unable to create RX DMA tag\n");
2906 1.1 dyoung goto fail;
2907 1.1 dyoung }
2908 1.1 dyoung
2909 1.3 msaitoh if ((error = ixgbe_dma_tag_create(adapter->osdep.dmat, /* parent */
2910 1.1 dyoung 1, 0, /* alignment, bounds */
2911 1.1 dyoung MJUMPAGESIZE, /* maxsize */
2912 1.1 dyoung 1, /* nsegments */
2913 1.1 dyoung MJUMPAGESIZE, /* maxsegsize */
2914 1.1 dyoung 0, /* flags */
2915 1.1 dyoung &rxr->ptag))) {
2916 1.3 msaitoh aprint_error_dev(dev, "Unable to create RX DMA tag\n");
2917 1.1 dyoung goto fail;
2918 1.1 dyoung }
2919 1.1 dyoung
2920 1.1 dyoung for (i = 0; i < adapter->num_rx_desc; i++, rxbuf++) {
2921 1.1 dyoung rxbuf = &rxr->rx_buffers[i];
2922 1.3 msaitoh error = ixgbe_dmamap_create(rxr->htag,
2923 1.1 dyoung BUS_DMA_NOWAIT, &rxbuf->hmap);
2924 1.1 dyoung if (error) {
2925 1.3 msaitoh aprint_error_dev(dev, "Unable to create RX head map\n");
2926 1.1 dyoung goto fail;
2927 1.1 dyoung }
2928 1.3 msaitoh error = ixgbe_dmamap_create(rxr->ptag,
2929 1.1 dyoung BUS_DMA_NOWAIT, &rxbuf->pmap);
2930 1.1 dyoung if (error) {
2931 1.3 msaitoh aprint_error_dev(dev, "Unable to create RX pkt map\n");
2932 1.1 dyoung goto fail;
2933 1.1 dyoung }
2934 1.1 dyoung }
2935 1.1 dyoung
2936 1.1 dyoung return (0);
2937 1.1 dyoung
2938 1.1 dyoung fail:
2939 1.1 dyoung /* Frees all, but can handle partial completion */
2940 1.1 dyoung ixv_free_receive_structures(adapter);
2941 1.1 dyoung return (error);
2942 1.1 dyoung }
2943 1.1 dyoung
2944 1.1 dyoung static void
2945 1.1 dyoung ixv_free_receive_ring(struct rx_ring *rxr)
2946 1.1 dyoung {
2947 1.1 dyoung struct adapter *adapter;
2948 1.1 dyoung struct ixv_rx_buf *rxbuf;
2949 1.1 dyoung int i;
2950 1.1 dyoung
2951 1.1 dyoung adapter = rxr->adapter;
2952 1.1 dyoung for (i = 0; i < adapter->num_rx_desc; i++) {
2953 1.1 dyoung rxbuf = &rxr->rx_buffers[i];
2954 1.1 dyoung if (rxbuf->m_head != NULL) {
2955 1.3 msaitoh ixgbe_dmamap_sync(rxr->htag, rxbuf->hmap,
2956 1.1 dyoung BUS_DMASYNC_POSTREAD);
2957 1.3 msaitoh ixgbe_dmamap_unload(rxr->htag, rxbuf->hmap);
2958 1.1 dyoung rxbuf->m_head->m_flags |= M_PKTHDR;
2959 1.1 dyoung m_freem(rxbuf->m_head);
2960 1.1 dyoung }
2961 1.1 dyoung if (rxbuf->m_pack != NULL) {
2962 1.3 msaitoh /* XXX not ixgbe_ ? */
2963 1.3 msaitoh bus_dmamap_sync(rxr->ptag->dt_dmat, rxbuf->pmap,
2964 1.3 msaitoh 0, rxbuf->m_pack->m_pkthdr.len,
2965 1.1 dyoung BUS_DMASYNC_POSTREAD);
2966 1.3 msaitoh ixgbe_dmamap_unload(rxr->ptag, rxbuf->pmap);
2967 1.1 dyoung rxbuf->m_pack->m_flags |= M_PKTHDR;
2968 1.1 dyoung m_freem(rxbuf->m_pack);
2969 1.1 dyoung }
2970 1.1 dyoung rxbuf->m_head = NULL;
2971 1.1 dyoung rxbuf->m_pack = NULL;
2972 1.1 dyoung }
2973 1.1 dyoung }
2974 1.1 dyoung
2975 1.1 dyoung
2976 1.1 dyoung /*********************************************************************
2977 1.1 dyoung *
2978 1.1 dyoung * Initialize a receive ring and its buffers.
2979 1.1 dyoung *
2980 1.1 dyoung **********************************************************************/
2981 1.1 dyoung static int
2982 1.1 dyoung ixv_setup_receive_ring(struct rx_ring *rxr)
2983 1.1 dyoung {
2984 1.1 dyoung struct adapter *adapter;
2985 1.3 msaitoh struct ixv_rx_buf *rxbuf;
2986 1.3 msaitoh #ifdef LRO
2987 1.1 dyoung struct ifnet *ifp;
2988 1.1 dyoung struct lro_ctrl *lro = &rxr->lro;
2989 1.3 msaitoh #endif /* LRO */
2990 1.3 msaitoh int rsize, error = 0;
2991 1.1 dyoung
2992 1.1 dyoung adapter = rxr->adapter;
2993 1.3 msaitoh #ifdef LRO
2994 1.1 dyoung ifp = adapter->ifp;
2995 1.3 msaitoh #endif /* LRO */
2996 1.1 dyoung
2997 1.1 dyoung /* Clear the ring contents */
2998 1.1 dyoung IXV_RX_LOCK(rxr);
2999 1.1 dyoung rsize = roundup2(adapter->num_rx_desc *
3000 1.1 dyoung sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
3001 1.1 dyoung bzero((void *)rxr->rx_base, rsize);
3002 1.1 dyoung
3003 1.1 dyoung /* Free current RX buffer structs and their mbufs */
3004 1.1 dyoung ixv_free_receive_ring(rxr);
3005 1.1 dyoung
3006 1.3 msaitoh IXV_RX_UNLOCK(rxr);
3007 1.3 msaitoh
3008 1.3 msaitoh /* Now reinitialize our supply of jumbo mbufs. The number
3009 1.3 msaitoh * or size of jumbo mbufs may have changed.
3010 1.3 msaitoh */
3011 1.3 msaitoh ixgbe_jcl_reinit(&adapter->jcl_head, rxr->ptag->dt_dmat,
3012 1.3 msaitoh 2 * adapter->num_rx_desc, adapter->rx_mbuf_sz);
3013 1.3 msaitoh
3014 1.3 msaitoh IXV_RX_LOCK(rxr);
3015 1.3 msaitoh
3016 1.1 dyoung /* Configure header split? */
3017 1.1 dyoung if (ixv_header_split)
3018 1.1 dyoung rxr->hdr_split = TRUE;
3019 1.1 dyoung
3020 1.1 dyoung /* Now replenish the mbufs */
3021 1.1 dyoung for (int j = 0; j != adapter->num_rx_desc; ++j) {
3022 1.1 dyoung struct mbuf *mh, *mp;
3023 1.1 dyoung
3024 1.1 dyoung rxbuf = &rxr->rx_buffers[j];
3025 1.1 dyoung /*
3026 1.1 dyoung ** Dont allocate mbufs if not
3027 1.1 dyoung ** doing header split, its wasteful
3028 1.1 dyoung */
3029 1.1 dyoung if (rxr->hdr_split == FALSE)
3030 1.1 dyoung goto skip_head;
3031 1.1 dyoung
3032 1.1 dyoung /* First the header */
3033 1.3 msaitoh rxbuf->m_head = m_gethdr(M_DONTWAIT, MT_DATA);
3034 1.1 dyoung if (rxbuf->m_head == NULL) {
3035 1.1 dyoung error = ENOBUFS;
3036 1.1 dyoung goto fail;
3037 1.1 dyoung }
3038 1.1 dyoung m_adj(rxbuf->m_head, ETHER_ALIGN);
3039 1.1 dyoung mh = rxbuf->m_head;
3040 1.1 dyoung mh->m_len = mh->m_pkthdr.len = MHLEN;
3041 1.1 dyoung mh->m_flags |= M_PKTHDR;
3042 1.1 dyoung /* Get the memory mapping */
3043 1.3 msaitoh error = bus_dmamap_load_mbuf(rxr->htag->dt_dmat,
3044 1.3 msaitoh rxbuf->hmap, rxbuf->m_head, BUS_DMA_NOWAIT);
3045 1.1 dyoung if (error != 0) /* Nothing elegant to do here */
3046 1.1 dyoung goto fail;
3047 1.3 msaitoh bus_dmamap_sync(rxr->htag->dt_dmat, rxbuf->hmap,
3048 1.3 msaitoh 0, mh->m_pkthdr.len, BUS_DMASYNC_PREREAD);
3049 1.1 dyoung /* Update descriptor */
3050 1.3 msaitoh rxr->rx_base[j].read.hdr_addr =
3051 1.3 msaitoh htole64(rxbuf->hmap->dm_segs[0].ds_addr);
3052 1.1 dyoung
3053 1.1 dyoung skip_head:
3054 1.1 dyoung /* Now the payload cluster */
3055 1.3 msaitoh rxbuf->m_pack = ixgbe_getjcl(&adapter->jcl_head, M_DONTWAIT,
3056 1.3 msaitoh MT_DATA, M_PKTHDR, adapter->rx_mbuf_sz);
3057 1.1 dyoung if (rxbuf->m_pack == NULL) {
3058 1.1 dyoung error = ENOBUFS;
3059 1.1 dyoung goto fail;
3060 1.1 dyoung }
3061 1.1 dyoung mp = rxbuf->m_pack;
3062 1.1 dyoung mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
3063 1.1 dyoung /* Get the memory mapping */
3064 1.3 msaitoh error = bus_dmamap_load_mbuf(rxr->ptag->dt_dmat,
3065 1.3 msaitoh rxbuf->pmap, mp, BUS_DMA_NOWAIT);
3066 1.1 dyoung if (error != 0)
3067 1.1 dyoung goto fail;
3068 1.3 msaitoh bus_dmamap_sync(rxr->ptag->dt_dmat, rxbuf->pmap,
3069 1.3 msaitoh 0, adapter->rx_mbuf_sz, BUS_DMASYNC_PREREAD);
3070 1.1 dyoung /* Update descriptor */
3071 1.3 msaitoh rxr->rx_base[j].read.pkt_addr =
3072 1.3 msaitoh htole64(rxbuf->pmap->dm_segs[0].ds_addr);
3073 1.1 dyoung }
3074 1.1 dyoung
3075 1.1 dyoung
3076 1.1 dyoung /* Setup our descriptor indices */
3077 1.1 dyoung rxr->next_to_check = 0;
3078 1.1 dyoung rxr->next_to_refresh = 0;
3079 1.1 dyoung rxr->lro_enabled = FALSE;
3080 1.3 msaitoh rxr->rx_split_packets.ev_count = 0;
3081 1.3 msaitoh rxr->rx_bytes.ev_count = 0;
3082 1.5 msaitoh rxr->discard = FALSE;
3083 1.1 dyoung
3084 1.3 msaitoh ixgbe_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
3085 1.1 dyoung BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3086 1.1 dyoung
3087 1.3 msaitoh #ifdef LRO
3088 1.1 dyoung /*
3089 1.1 dyoung ** Now set up the LRO interface:
3090 1.1 dyoung */
3091 1.1 dyoung if (ifp->if_capenable & IFCAP_LRO) {
3092 1.3 msaitoh device_t dev = adapter->dev;
3093 1.1 dyoung int err = tcp_lro_init(lro);
3094 1.1 dyoung if (err) {
3095 1.1 dyoung device_printf(dev, "LRO Initialization failed!\n");
3096 1.1 dyoung goto fail;
3097 1.1 dyoung }
3098 1.1 dyoung INIT_DEBUGOUT("RX Soft LRO Initialized\n");
3099 1.1 dyoung rxr->lro_enabled = TRUE;
3100 1.1 dyoung lro->ifp = adapter->ifp;
3101 1.1 dyoung }
3102 1.3 msaitoh #endif /* LRO */
3103 1.1 dyoung
3104 1.1 dyoung IXV_RX_UNLOCK(rxr);
3105 1.1 dyoung return (0);
3106 1.1 dyoung
3107 1.1 dyoung fail:
3108 1.1 dyoung ixv_free_receive_ring(rxr);
3109 1.1 dyoung IXV_RX_UNLOCK(rxr);
3110 1.1 dyoung return (error);
3111 1.1 dyoung }
3112 1.1 dyoung
3113 1.1 dyoung /*********************************************************************
3114 1.1 dyoung *
3115 1.1 dyoung * Initialize all receive rings.
3116 1.1 dyoung *
3117 1.1 dyoung **********************************************************************/
3118 1.1 dyoung static int
3119 1.1 dyoung ixv_setup_receive_structures(struct adapter *adapter)
3120 1.1 dyoung {
3121 1.1 dyoung struct rx_ring *rxr = adapter->rx_rings;
3122 1.1 dyoung int j;
3123 1.1 dyoung
3124 1.1 dyoung for (j = 0; j < adapter->num_queues; j++, rxr++)
3125 1.1 dyoung if (ixv_setup_receive_ring(rxr))
3126 1.1 dyoung goto fail;
3127 1.1 dyoung
3128 1.1 dyoung return (0);
3129 1.1 dyoung fail:
3130 1.1 dyoung /*
3131 1.1 dyoung * Free RX buffers allocated so far, we will only handle
3132 1.1 dyoung * the rings that completed, the failing case will have
3133 1.1 dyoung * cleaned up for itself. 'j' failed, so its the terminus.
3134 1.1 dyoung */
3135 1.1 dyoung for (int i = 0; i < j; ++i) {
3136 1.1 dyoung rxr = &adapter->rx_rings[i];
3137 1.1 dyoung ixv_free_receive_ring(rxr);
3138 1.1 dyoung }
3139 1.1 dyoung
3140 1.1 dyoung return (ENOBUFS);
3141 1.1 dyoung }
3142 1.1 dyoung
3143 1.1 dyoung /*********************************************************************
3144 1.1 dyoung *
3145 1.1 dyoung * Setup receive registers and features.
3146 1.1 dyoung *
3147 1.1 dyoung **********************************************************************/
3148 1.1 dyoung #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
3149 1.1 dyoung
3150 1.1 dyoung static void
3151 1.1 dyoung ixv_initialize_receive_units(struct adapter *adapter)
3152 1.1 dyoung {
3153 1.3 msaitoh int i;
3154 1.1 dyoung struct rx_ring *rxr = adapter->rx_rings;
3155 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
3156 1.1 dyoung struct ifnet *ifp = adapter->ifp;
3157 1.1 dyoung u32 bufsz, fctrl, rxcsum, hlreg;
3158 1.1 dyoung
3159 1.1 dyoung
3160 1.1 dyoung /* Enable broadcasts */
3161 1.1 dyoung fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3162 1.1 dyoung fctrl |= IXGBE_FCTRL_BAM;
3163 1.1 dyoung fctrl |= IXGBE_FCTRL_DPF;
3164 1.1 dyoung fctrl |= IXGBE_FCTRL_PMCF;
3165 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3166 1.1 dyoung
3167 1.1 dyoung /* Set for Jumbo Frames? */
3168 1.1 dyoung hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3169 1.1 dyoung if (ifp->if_mtu > ETHERMTU) {
3170 1.1 dyoung hlreg |= IXGBE_HLREG0_JUMBOEN;
3171 1.1 dyoung bufsz = 4096 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3172 1.1 dyoung } else {
3173 1.1 dyoung hlreg &= ~IXGBE_HLREG0_JUMBOEN;
3174 1.1 dyoung bufsz = 2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3175 1.1 dyoung }
3176 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
3177 1.1 dyoung
3178 1.3 msaitoh for (i = 0; i < adapter->num_queues; i++, rxr++) {
3179 1.1 dyoung u64 rdba = rxr->rxdma.dma_paddr;
3180 1.1 dyoung u32 reg, rxdctl;
3181 1.1 dyoung
3182 1.1 dyoung /* Do the queue enabling first */
3183 1.1 dyoung rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
3184 1.1 dyoung rxdctl |= IXGBE_RXDCTL_ENABLE;
3185 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), rxdctl);
3186 1.1 dyoung for (int k = 0; k < 10; k++) {
3187 1.1 dyoung if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)) &
3188 1.1 dyoung IXGBE_RXDCTL_ENABLE)
3189 1.1 dyoung break;
3190 1.1 dyoung else
3191 1.1 dyoung msec_delay(1);
3192 1.1 dyoung }
3193 1.1 dyoung wmb();
3194 1.1 dyoung
3195 1.1 dyoung /* Setup the Base and Length of the Rx Descriptor Ring */
3196 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(i),
3197 1.1 dyoung (rdba & 0x00000000ffffffffULL));
3198 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(i),
3199 1.1 dyoung (rdba >> 32));
3200 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(i),
3201 1.1 dyoung adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
3202 1.1 dyoung
3203 1.1 dyoung /* Set up the SRRCTL register */
3204 1.1 dyoung reg = IXGBE_READ_REG(hw, IXGBE_VFSRRCTL(i));
3205 1.1 dyoung reg &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
3206 1.1 dyoung reg &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
3207 1.1 dyoung reg |= bufsz;
3208 1.1 dyoung if (rxr->hdr_split) {
3209 1.1 dyoung /* Use a standard mbuf for the header */
3210 1.1 dyoung reg |= ((IXV_RX_HDR <<
3211 1.1 dyoung IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT)
3212 1.1 dyoung & IXGBE_SRRCTL_BSIZEHDR_MASK);
3213 1.1 dyoung reg |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
3214 1.1 dyoung } else
3215 1.1 dyoung reg |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
3216 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(i), reg);
3217 1.1 dyoung
3218 1.1 dyoung /* Setup the HW Rx Head and Tail Descriptor Pointers */
3219 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFRDH(rxr->me), 0);
3220 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me),
3221 1.1 dyoung adapter->num_rx_desc - 1);
3222 1.1 dyoung }
3223 1.1 dyoung
3224 1.1 dyoung rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3225 1.1 dyoung
3226 1.1 dyoung if (ifp->if_capenable & IFCAP_RXCSUM)
3227 1.1 dyoung rxcsum |= IXGBE_RXCSUM_PCSD;
3228 1.1 dyoung
3229 1.1 dyoung if (!(rxcsum & IXGBE_RXCSUM_PCSD))
3230 1.1 dyoung rxcsum |= IXGBE_RXCSUM_IPPCSE;
3231 1.1 dyoung
3232 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3233 1.1 dyoung
3234 1.1 dyoung return;
3235 1.1 dyoung }
3236 1.1 dyoung
3237 1.1 dyoung /*********************************************************************
3238 1.1 dyoung *
3239 1.1 dyoung * Free all receive rings.
3240 1.1 dyoung *
3241 1.1 dyoung **********************************************************************/
3242 1.1 dyoung static void
3243 1.1 dyoung ixv_free_receive_structures(struct adapter *adapter)
3244 1.1 dyoung {
3245 1.1 dyoung struct rx_ring *rxr = adapter->rx_rings;
3246 1.1 dyoung
3247 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, rxr++) {
3248 1.3 msaitoh #ifdef LRO
3249 1.1 dyoung struct lro_ctrl *lro = &rxr->lro;
3250 1.3 msaitoh #endif /* LRO */
3251 1.1 dyoung ixv_free_receive_buffers(rxr);
3252 1.3 msaitoh #ifdef LRO
3253 1.1 dyoung /* Free LRO memory */
3254 1.1 dyoung tcp_lro_free(lro);
3255 1.3 msaitoh #endif /* LRO */
3256 1.1 dyoung /* Free the ring memory as well */
3257 1.1 dyoung ixv_dma_free(adapter, &rxr->rxdma);
3258 1.3 msaitoh IXV_RX_LOCK_DESTROY(rxr);
3259 1.1 dyoung }
3260 1.1 dyoung
3261 1.1 dyoung free(adapter->rx_rings, M_DEVBUF);
3262 1.1 dyoung }
3263 1.1 dyoung
3264 1.1 dyoung
3265 1.1 dyoung /*********************************************************************
3266 1.1 dyoung *
3267 1.1 dyoung * Free receive ring data structures
3268 1.1 dyoung *
3269 1.1 dyoung **********************************************************************/
3270 1.1 dyoung static void
3271 1.1 dyoung ixv_free_receive_buffers(struct rx_ring *rxr)
3272 1.1 dyoung {
3273 1.1 dyoung struct adapter *adapter = rxr->adapter;
3274 1.1 dyoung struct ixv_rx_buf *rxbuf;
3275 1.1 dyoung
3276 1.1 dyoung INIT_DEBUGOUT("free_receive_structures: begin");
3277 1.1 dyoung
3278 1.1 dyoung /* Cleanup any existing buffers */
3279 1.1 dyoung if (rxr->rx_buffers != NULL) {
3280 1.1 dyoung for (int i = 0; i < adapter->num_rx_desc; i++) {
3281 1.1 dyoung rxbuf = &rxr->rx_buffers[i];
3282 1.1 dyoung if (rxbuf->m_head != NULL) {
3283 1.3 msaitoh ixgbe_dmamap_sync(rxr->htag, rxbuf->hmap,
3284 1.1 dyoung BUS_DMASYNC_POSTREAD);
3285 1.3 msaitoh ixgbe_dmamap_unload(rxr->htag, rxbuf->hmap);
3286 1.1 dyoung rxbuf->m_head->m_flags |= M_PKTHDR;
3287 1.1 dyoung m_freem(rxbuf->m_head);
3288 1.1 dyoung }
3289 1.1 dyoung if (rxbuf->m_pack != NULL) {
3290 1.3 msaitoh /* XXX not ixgbe_* ? */
3291 1.3 msaitoh bus_dmamap_sync(rxr->ptag->dt_dmat, rxbuf->pmap,
3292 1.3 msaitoh 0, rxbuf->m_pack->m_pkthdr.len,
3293 1.1 dyoung BUS_DMASYNC_POSTREAD);
3294 1.3 msaitoh ixgbe_dmamap_unload(rxr->ptag, rxbuf->pmap);
3295 1.1 dyoung rxbuf->m_pack->m_flags |= M_PKTHDR;
3296 1.1 dyoung m_freem(rxbuf->m_pack);
3297 1.1 dyoung }
3298 1.1 dyoung rxbuf->m_head = NULL;
3299 1.1 dyoung rxbuf->m_pack = NULL;
3300 1.1 dyoung if (rxbuf->hmap != NULL) {
3301 1.3 msaitoh ixgbe_dmamap_destroy(rxr->htag, rxbuf->hmap);
3302 1.1 dyoung rxbuf->hmap = NULL;
3303 1.1 dyoung }
3304 1.1 dyoung if (rxbuf->pmap != NULL) {
3305 1.3 msaitoh ixgbe_dmamap_destroy(rxr->ptag, rxbuf->pmap);
3306 1.1 dyoung rxbuf->pmap = NULL;
3307 1.1 dyoung }
3308 1.1 dyoung }
3309 1.1 dyoung if (rxr->rx_buffers != NULL) {
3310 1.1 dyoung free(rxr->rx_buffers, M_DEVBUF);
3311 1.1 dyoung rxr->rx_buffers = NULL;
3312 1.1 dyoung }
3313 1.1 dyoung }
3314 1.1 dyoung
3315 1.1 dyoung if (rxr->htag != NULL) {
3316 1.3 msaitoh ixgbe_dma_tag_destroy(rxr->htag);
3317 1.1 dyoung rxr->htag = NULL;
3318 1.1 dyoung }
3319 1.1 dyoung if (rxr->ptag != NULL) {
3320 1.3 msaitoh ixgbe_dma_tag_destroy(rxr->ptag);
3321 1.1 dyoung rxr->ptag = NULL;
3322 1.1 dyoung }
3323 1.1 dyoung
3324 1.1 dyoung return;
3325 1.1 dyoung }
3326 1.1 dyoung
3327 1.1 dyoung static __inline void
3328 1.1 dyoung ixv_rx_input(struct rx_ring *rxr, struct ifnet *ifp, struct mbuf *m, u32 ptype)
3329 1.1 dyoung {
3330 1.3 msaitoh int s;
3331 1.1 dyoung
3332 1.3 msaitoh #ifdef LRO
3333 1.3 msaitoh struct adapter *adapter = ifp->if_softc;
3334 1.3 msaitoh struct ethercom *ec = &adapter->osdep.ec;
3335 1.3 msaitoh
3336 1.1 dyoung /*
3337 1.1 dyoung * ATM LRO is only for IPv4/TCP packets and TCP checksum of the packet
3338 1.1 dyoung * should be computed by hardware. Also it should not have VLAN tag in
3339 1.1 dyoung * ethernet header.
3340 1.1 dyoung */
3341 1.1 dyoung if (rxr->lro_enabled &&
3342 1.3 msaitoh (ec->ec_capenable & ETHERCAP_VLAN_HWTAGGING) != 0 &&
3343 1.1 dyoung (ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
3344 1.1 dyoung (ptype & (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
3345 1.1 dyoung (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP) &&
3346 1.1 dyoung (m->m_pkthdr.csum_flags & (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) ==
3347 1.1 dyoung (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) {
3348 1.1 dyoung /*
3349 1.1 dyoung * Send to the stack if:
3350 1.1 dyoung ** - LRO not enabled, or
3351 1.1 dyoung ** - no LRO resources, or
3352 1.1 dyoung ** - lro enqueue fails
3353 1.1 dyoung */
3354 1.1 dyoung if (rxr->lro.lro_cnt != 0)
3355 1.1 dyoung if (tcp_lro_rx(&rxr->lro, m, 0) == 0)
3356 1.1 dyoung return;
3357 1.1 dyoung }
3358 1.3 msaitoh #endif /* LRO */
3359 1.3 msaitoh
3360 1.3 msaitoh IXV_RX_UNLOCK(rxr);
3361 1.3 msaitoh
3362 1.3 msaitoh s = splnet();
3363 1.3 msaitoh /* Pass this up to any BPF listeners. */
3364 1.3 msaitoh bpf_mtap(ifp, m);
3365 1.1 dyoung (*ifp->if_input)(ifp, m);
3366 1.3 msaitoh splx(s);
3367 1.3 msaitoh
3368 1.3 msaitoh IXV_RX_LOCK(rxr);
3369 1.1 dyoung }
3370 1.1 dyoung
3371 1.1 dyoung static __inline void
3372 1.1 dyoung ixv_rx_discard(struct rx_ring *rxr, int i)
3373 1.1 dyoung {
3374 1.1 dyoung struct ixv_rx_buf *rbuf;
3375 1.1 dyoung
3376 1.1 dyoung rbuf = &rxr->rx_buffers[i];
3377 1.5 msaitoh if (rbuf->fmp != NULL) {/* Partial chain ? */
3378 1.5 msaitoh rbuf->fmp->m_flags |= M_PKTHDR;
3379 1.5 msaitoh m_freem(rbuf->fmp);
3380 1.5 msaitoh rbuf->fmp = NULL;
3381 1.5 msaitoh }
3382 1.1 dyoung
3383 1.5 msaitoh /*
3384 1.5 msaitoh ** With advanced descriptors the writeback
3385 1.5 msaitoh ** clobbers the buffer addrs, so its easier
3386 1.5 msaitoh ** to just free the existing mbufs and take
3387 1.5 msaitoh ** the normal refresh path to get new buffers
3388 1.5 msaitoh ** and mapping.
3389 1.5 msaitoh */
3390 1.5 msaitoh if (rbuf->m_head) {
3391 1.5 msaitoh m_free(rbuf->m_head);
3392 1.5 msaitoh rbuf->m_head = NULL;
3393 1.5 msaitoh }
3394 1.5 msaitoh
3395 1.5 msaitoh if (rbuf->m_pack) {
3396 1.5 msaitoh m_free(rbuf->m_pack);
3397 1.5 msaitoh rbuf->m_pack = NULL;
3398 1.5 msaitoh }
3399 1.1 dyoung
3400 1.1 dyoung return;
3401 1.1 dyoung }
3402 1.1 dyoung
3403 1.1 dyoung
3404 1.1 dyoung /*********************************************************************
3405 1.1 dyoung *
3406 1.1 dyoung * This routine executes in interrupt context. It replenishes
3407 1.1 dyoung * the mbufs in the descriptor and sends data which has been
3408 1.1 dyoung * dma'ed into host memory to upper layer.
3409 1.1 dyoung *
3410 1.1 dyoung * We loop at most count times if count is > 0, or until done if
3411 1.1 dyoung * count < 0.
3412 1.1 dyoung *
3413 1.1 dyoung * Return TRUE for more work, FALSE for all clean.
3414 1.1 dyoung *********************************************************************/
3415 1.1 dyoung static bool
3416 1.1 dyoung ixv_rxeof(struct ix_queue *que, int count)
3417 1.1 dyoung {
3418 1.1 dyoung struct adapter *adapter = que->adapter;
3419 1.1 dyoung struct rx_ring *rxr = que->rxr;
3420 1.1 dyoung struct ifnet *ifp = adapter->ifp;
3421 1.3 msaitoh #ifdef LRO
3422 1.1 dyoung struct lro_ctrl *lro = &rxr->lro;
3423 1.1 dyoung struct lro_entry *queued;
3424 1.3 msaitoh #endif /* LRO */
3425 1.1 dyoung int i, nextp, processed = 0;
3426 1.1 dyoung u32 staterr = 0;
3427 1.1 dyoung union ixgbe_adv_rx_desc *cur;
3428 1.1 dyoung struct ixv_rx_buf *rbuf, *nbuf;
3429 1.1 dyoung
3430 1.1 dyoung IXV_RX_LOCK(rxr);
3431 1.1 dyoung
3432 1.1 dyoung for (i = rxr->next_to_check; count != 0;) {
3433 1.1 dyoung struct mbuf *sendmp, *mh, *mp;
3434 1.3 msaitoh u32 ptype;
3435 1.1 dyoung u16 hlen, plen, hdr, vtag;
3436 1.1 dyoung bool eop;
3437 1.1 dyoung
3438 1.1 dyoung /* Sync the ring. */
3439 1.3 msaitoh ixgbe_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
3440 1.1 dyoung BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
3441 1.1 dyoung
3442 1.1 dyoung cur = &rxr->rx_base[i];
3443 1.1 dyoung staterr = le32toh(cur->wb.upper.status_error);
3444 1.1 dyoung
3445 1.1 dyoung if ((staterr & IXGBE_RXD_STAT_DD) == 0)
3446 1.1 dyoung break;
3447 1.3 msaitoh if ((ifp->if_flags & IFF_RUNNING) == 0)
3448 1.1 dyoung break;
3449 1.1 dyoung
3450 1.1 dyoung count--;
3451 1.1 dyoung sendmp = NULL;
3452 1.1 dyoung nbuf = NULL;
3453 1.1 dyoung cur->wb.upper.status_error = 0;
3454 1.1 dyoung rbuf = &rxr->rx_buffers[i];
3455 1.1 dyoung mh = rbuf->m_head;
3456 1.1 dyoung mp = rbuf->m_pack;
3457 1.1 dyoung
3458 1.1 dyoung plen = le16toh(cur->wb.upper.length);
3459 1.1 dyoung ptype = le32toh(cur->wb.lower.lo_dword.data) &
3460 1.1 dyoung IXGBE_RXDADV_PKTTYPE_MASK;
3461 1.1 dyoung hdr = le16toh(cur->wb.lower.lo_dword.hs_rss.hdr_info);
3462 1.1 dyoung vtag = le16toh(cur->wb.upper.vlan);
3463 1.1 dyoung eop = ((staterr & IXGBE_RXD_STAT_EOP) != 0);
3464 1.1 dyoung
3465 1.1 dyoung /* Make sure all parts of a bad packet are discarded */
3466 1.1 dyoung if (((staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) != 0) ||
3467 1.1 dyoung (rxr->discard)) {
3468 1.1 dyoung ifp->if_ierrors++;
3469 1.3 msaitoh rxr->rx_discarded.ev_count++;
3470 1.1 dyoung if (!eop)
3471 1.1 dyoung rxr->discard = TRUE;
3472 1.1 dyoung else
3473 1.1 dyoung rxr->discard = FALSE;
3474 1.1 dyoung ixv_rx_discard(rxr, i);
3475 1.1 dyoung goto next_desc;
3476 1.1 dyoung }
3477 1.1 dyoung
3478 1.1 dyoung if (!eop) {
3479 1.1 dyoung nextp = i + 1;
3480 1.1 dyoung if (nextp == adapter->num_rx_desc)
3481 1.1 dyoung nextp = 0;
3482 1.1 dyoung nbuf = &rxr->rx_buffers[nextp];
3483 1.1 dyoung prefetch(nbuf);
3484 1.1 dyoung }
3485 1.1 dyoung /*
3486 1.1 dyoung ** The header mbuf is ONLY used when header
3487 1.1 dyoung ** split is enabled, otherwise we get normal
3488 1.1 dyoung ** behavior, ie, both header and payload
3489 1.1 dyoung ** are DMA'd into the payload buffer.
3490 1.1 dyoung **
3491 1.1 dyoung ** Rather than using the fmp/lmp global pointers
3492 1.1 dyoung ** we now keep the head of a packet chain in the
3493 1.1 dyoung ** buffer struct and pass this along from one
3494 1.1 dyoung ** descriptor to the next, until we get EOP.
3495 1.1 dyoung */
3496 1.1 dyoung if (rxr->hdr_split && (rbuf->fmp == NULL)) {
3497 1.1 dyoung /* This must be an initial descriptor */
3498 1.1 dyoung hlen = (hdr & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
3499 1.1 dyoung IXGBE_RXDADV_HDRBUFLEN_SHIFT;
3500 1.1 dyoung if (hlen > IXV_RX_HDR)
3501 1.1 dyoung hlen = IXV_RX_HDR;
3502 1.1 dyoung mh->m_len = hlen;
3503 1.1 dyoung mh->m_flags |= M_PKTHDR;
3504 1.1 dyoung mh->m_next = NULL;
3505 1.1 dyoung mh->m_pkthdr.len = mh->m_len;
3506 1.1 dyoung /* Null buf pointer so it is refreshed */
3507 1.1 dyoung rbuf->m_head = NULL;
3508 1.1 dyoung /*
3509 1.1 dyoung ** Check the payload length, this
3510 1.1 dyoung ** could be zero if its a small
3511 1.1 dyoung ** packet.
3512 1.1 dyoung */
3513 1.1 dyoung if (plen > 0) {
3514 1.1 dyoung mp->m_len = plen;
3515 1.1 dyoung mp->m_next = NULL;
3516 1.1 dyoung mp->m_flags &= ~M_PKTHDR;
3517 1.1 dyoung mh->m_next = mp;
3518 1.1 dyoung mh->m_pkthdr.len += mp->m_len;
3519 1.1 dyoung /* Null buf pointer so it is refreshed */
3520 1.1 dyoung rbuf->m_pack = NULL;
3521 1.3 msaitoh rxr->rx_split_packets.ev_count++;
3522 1.1 dyoung }
3523 1.1 dyoung /*
3524 1.1 dyoung ** Now create the forward
3525 1.1 dyoung ** chain so when complete
3526 1.1 dyoung ** we wont have to.
3527 1.1 dyoung */
3528 1.1 dyoung if (eop == 0) {
3529 1.1 dyoung /* stash the chain head */
3530 1.1 dyoung nbuf->fmp = mh;
3531 1.1 dyoung /* Make forward chain */
3532 1.1 dyoung if (plen)
3533 1.1 dyoung mp->m_next = nbuf->m_pack;
3534 1.1 dyoung else
3535 1.1 dyoung mh->m_next = nbuf->m_pack;
3536 1.1 dyoung } else {
3537 1.1 dyoung /* Singlet, prepare to send */
3538 1.1 dyoung sendmp = mh;
3539 1.3 msaitoh if (VLAN_ATTACHED(&adapter->osdep.ec) &&
3540 1.3 msaitoh (staterr & IXGBE_RXD_STAT_VP)) {
3541 1.3 msaitoh VLAN_INPUT_TAG(ifp, sendmp, vtag,
3542 1.3 msaitoh printf("%s: could not apply VLAN "
3543 1.3 msaitoh "tag", __func__));
3544 1.1 dyoung }
3545 1.1 dyoung }
3546 1.1 dyoung } else {
3547 1.1 dyoung /*
3548 1.1 dyoung ** Either no header split, or a
3549 1.1 dyoung ** secondary piece of a fragmented
3550 1.1 dyoung ** split packet.
3551 1.1 dyoung */
3552 1.1 dyoung mp->m_len = plen;
3553 1.1 dyoung /*
3554 1.1 dyoung ** See if there is a stored head
3555 1.1 dyoung ** that determines what we are
3556 1.1 dyoung */
3557 1.1 dyoung sendmp = rbuf->fmp;
3558 1.1 dyoung rbuf->m_pack = rbuf->fmp = NULL;
3559 1.1 dyoung
3560 1.1 dyoung if (sendmp != NULL) /* secondary frag */
3561 1.1 dyoung sendmp->m_pkthdr.len += mp->m_len;
3562 1.1 dyoung else {
3563 1.1 dyoung /* first desc of a non-ps chain */
3564 1.1 dyoung sendmp = mp;
3565 1.1 dyoung sendmp->m_flags |= M_PKTHDR;
3566 1.1 dyoung sendmp->m_pkthdr.len = mp->m_len;
3567 1.1 dyoung if (staterr & IXGBE_RXD_STAT_VP) {
3568 1.3 msaitoh /* XXX Do something reasonable on
3569 1.3 msaitoh * error.
3570 1.3 msaitoh */
3571 1.3 msaitoh VLAN_INPUT_TAG(ifp, sendmp, vtag,
3572 1.3 msaitoh printf("%s: could not apply VLAN "
3573 1.3 msaitoh "tag", __func__));
3574 1.1 dyoung }
3575 1.1 dyoung }
3576 1.1 dyoung /* Pass the head pointer on */
3577 1.1 dyoung if (eop == 0) {
3578 1.1 dyoung nbuf->fmp = sendmp;
3579 1.1 dyoung sendmp = NULL;
3580 1.1 dyoung mp->m_next = nbuf->m_pack;
3581 1.1 dyoung }
3582 1.1 dyoung }
3583 1.1 dyoung ++processed;
3584 1.1 dyoung /* Sending this frame? */
3585 1.1 dyoung if (eop) {
3586 1.1 dyoung sendmp->m_pkthdr.rcvif = ifp;
3587 1.1 dyoung ifp->if_ipackets++;
3588 1.3 msaitoh rxr->rx_packets.ev_count++;
3589 1.1 dyoung /* capture data for AIM */
3590 1.1 dyoung rxr->bytes += sendmp->m_pkthdr.len;
3591 1.3 msaitoh rxr->rx_bytes.ev_count += sendmp->m_pkthdr.len;
3592 1.3 msaitoh if ((ifp->if_capenable & IFCAP_RXCSUM) != 0) {
3593 1.3 msaitoh ixv_rx_checksum(staterr, sendmp, ptype,
3594 1.3 msaitoh &adapter->stats);
3595 1.3 msaitoh }
3596 1.1 dyoung #if __FreeBSD_version >= 800000
3597 1.1 dyoung sendmp->m_pkthdr.flowid = que->msix;
3598 1.1 dyoung sendmp->m_flags |= M_FLOWID;
3599 1.1 dyoung #endif
3600 1.1 dyoung }
3601 1.1 dyoung next_desc:
3602 1.3 msaitoh ixgbe_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
3603 1.1 dyoung BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3604 1.1 dyoung
3605 1.1 dyoung /* Advance our pointers to the next descriptor. */
3606 1.1 dyoung if (++i == adapter->num_rx_desc)
3607 1.1 dyoung i = 0;
3608 1.1 dyoung
3609 1.1 dyoung /* Now send to the stack or do LRO */
3610 1.1 dyoung if (sendmp != NULL)
3611 1.1 dyoung ixv_rx_input(rxr, ifp, sendmp, ptype);
3612 1.1 dyoung
3613 1.1 dyoung /* Every 8 descriptors we go to refresh mbufs */
3614 1.1 dyoung if (processed == 8) {
3615 1.1 dyoung ixv_refresh_mbufs(rxr, i);
3616 1.1 dyoung processed = 0;
3617 1.1 dyoung }
3618 1.1 dyoung }
3619 1.1 dyoung
3620 1.1 dyoung /* Refresh any remaining buf structs */
3621 1.5 msaitoh if (ixv_rx_unrefreshed(rxr))
3622 1.1 dyoung ixv_refresh_mbufs(rxr, i);
3623 1.1 dyoung
3624 1.1 dyoung rxr->next_to_check = i;
3625 1.1 dyoung
3626 1.3 msaitoh #ifdef LRO
3627 1.1 dyoung /*
3628 1.1 dyoung * Flush any outstanding LRO work
3629 1.1 dyoung */
3630 1.1 dyoung while ((queued = SLIST_FIRST(&lro->lro_active)) != NULL) {
3631 1.1 dyoung SLIST_REMOVE_HEAD(&lro->lro_active, next);
3632 1.1 dyoung tcp_lro_flush(lro, queued);
3633 1.1 dyoung }
3634 1.3 msaitoh #endif /* LRO */
3635 1.1 dyoung
3636 1.1 dyoung IXV_RX_UNLOCK(rxr);
3637 1.1 dyoung
3638 1.1 dyoung /*
3639 1.1 dyoung ** We still have cleaning to do?
3640 1.1 dyoung ** Schedule another interrupt if so.
3641 1.1 dyoung */
3642 1.1 dyoung if ((staterr & IXGBE_RXD_STAT_DD) != 0) {
3643 1.3 msaitoh ixv_rearm_queues(adapter, (u64)(1ULL << que->msix));
3644 1.3 msaitoh return true;
3645 1.1 dyoung }
3646 1.1 dyoung
3647 1.3 msaitoh return false;
3648 1.1 dyoung }
3649 1.1 dyoung
3650 1.1 dyoung
3651 1.1 dyoung /*********************************************************************
3652 1.1 dyoung *
3653 1.1 dyoung * Verify that the hardware indicated that the checksum is valid.
3654 1.1 dyoung * Inform the stack about the status of checksum so that stack
3655 1.1 dyoung * doesn't spend time verifying the checksum.
3656 1.1 dyoung *
3657 1.1 dyoung *********************************************************************/
3658 1.1 dyoung static void
3659 1.3 msaitoh ixv_rx_checksum(u32 staterr, struct mbuf * mp, u32 ptype,
3660 1.3 msaitoh struct ixgbevf_hw_stats *stats)
3661 1.1 dyoung {
3662 1.1 dyoung u16 status = (u16) staterr;
3663 1.1 dyoung u8 errors = (u8) (staterr >> 24);
3664 1.3 msaitoh #if 0
3665 1.1 dyoung bool sctp = FALSE;
3666 1.12 msaitoh
3667 1.1 dyoung if ((ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
3668 1.1 dyoung (ptype & IXGBE_RXDADV_PKTTYPE_SCTP) != 0)
3669 1.1 dyoung sctp = TRUE;
3670 1.3 msaitoh #endif
3671 1.1 dyoung if (status & IXGBE_RXD_STAT_IPCS) {
3672 1.3 msaitoh stats->ipcs.ev_count++;
3673 1.1 dyoung if (!(errors & IXGBE_RXD_ERR_IPE)) {
3674 1.1 dyoung /* IP Checksum Good */
3675 1.3 msaitoh mp->m_pkthdr.csum_flags |= M_CSUM_IPv4;
3676 1.1 dyoung
3677 1.3 msaitoh } else {
3678 1.3 msaitoh stats->ipcs_bad.ev_count++;
3679 1.3 msaitoh mp->m_pkthdr.csum_flags = M_CSUM_IPv4|M_CSUM_IPv4_BAD;
3680 1.3 msaitoh }
3681 1.1 dyoung }
3682 1.1 dyoung if (status & IXGBE_RXD_STAT_L4CS) {
3683 1.3 msaitoh stats->l4cs.ev_count++;
3684 1.10 msaitoh int type = M_CSUM_TCPv4|M_CSUM_TCPv6|M_CSUM_UDPv4|M_CSUM_UDPv6;
3685 1.1 dyoung if (!(errors & IXGBE_RXD_ERR_TCPE)) {
3686 1.1 dyoung mp->m_pkthdr.csum_flags |= type;
3687 1.3 msaitoh } else {
3688 1.3 msaitoh stats->l4cs_bad.ev_count++;
3689 1.3 msaitoh mp->m_pkthdr.csum_flags |= type | M_CSUM_TCP_UDP_BAD;
3690 1.1 dyoung }
3691 1.1 dyoung }
3692 1.1 dyoung return;
3693 1.1 dyoung }
3694 1.1 dyoung
3695 1.1 dyoung static void
3696 1.1 dyoung ixv_setup_vlan_support(struct adapter *adapter)
3697 1.1 dyoung {
3698 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
3699 1.1 dyoung u32 ctrl, vid, vfta, retry;
3700 1.1 dyoung
3701 1.1 dyoung
3702 1.1 dyoung /*
3703 1.1 dyoung ** We get here thru init_locked, meaning
3704 1.1 dyoung ** a soft reset, this has already cleared
3705 1.1 dyoung ** the VFTA and other state, so if there
3706 1.1 dyoung ** have been no vlan's registered do nothing.
3707 1.1 dyoung */
3708 1.1 dyoung if (adapter->num_vlans == 0)
3709 1.1 dyoung return;
3710 1.1 dyoung
3711 1.1 dyoung /* Enable the queues */
3712 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++) {
3713 1.1 dyoung ctrl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
3714 1.1 dyoung ctrl |= IXGBE_RXDCTL_VME;
3715 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), ctrl);
3716 1.1 dyoung }
3717 1.1 dyoung
3718 1.1 dyoung /*
3719 1.1 dyoung ** A soft reset zero's out the VFTA, so
3720 1.1 dyoung ** we need to repopulate it now.
3721 1.1 dyoung */
3722 1.1 dyoung for (int i = 0; i < VFTA_SIZE; i++) {
3723 1.1 dyoung if (ixv_shadow_vfta[i] == 0)
3724 1.1 dyoung continue;
3725 1.1 dyoung vfta = ixv_shadow_vfta[i];
3726 1.1 dyoung /*
3727 1.1 dyoung ** Reconstruct the vlan id's
3728 1.1 dyoung ** based on the bits set in each
3729 1.1 dyoung ** of the array ints.
3730 1.1 dyoung */
3731 1.1 dyoung for ( int j = 0; j < 32; j++) {
3732 1.1 dyoung retry = 0;
3733 1.1 dyoung if ((vfta & (1 << j)) == 0)
3734 1.1 dyoung continue;
3735 1.1 dyoung vid = (i * 32) + j;
3736 1.1 dyoung /* Call the shared code mailbox routine */
3737 1.1 dyoung while (ixgbe_set_vfta(hw, vid, 0, TRUE)) {
3738 1.1 dyoung if (++retry > 5)
3739 1.1 dyoung break;
3740 1.1 dyoung }
3741 1.1 dyoung }
3742 1.1 dyoung }
3743 1.1 dyoung }
3744 1.1 dyoung
3745 1.3 msaitoh #if 0 /* XXX Badly need to overhaul vlan(4) on NetBSD. */
3746 1.1 dyoung /*
3747 1.1 dyoung ** This routine is run via an vlan config EVENT,
3748 1.1 dyoung ** it enables us to use the HW Filter table since
3749 1.1 dyoung ** we can get the vlan id. This just creates the
3750 1.1 dyoung ** entry in the soft version of the VFTA, init will
3751 1.1 dyoung ** repopulate the real table.
3752 1.1 dyoung */
3753 1.1 dyoung static void
3754 1.1 dyoung ixv_register_vlan(void *arg, struct ifnet *ifp, u16 vtag)
3755 1.1 dyoung {
3756 1.1 dyoung struct adapter *adapter = ifp->if_softc;
3757 1.1 dyoung u16 index, bit;
3758 1.1 dyoung
3759 1.1 dyoung if (ifp->if_softc != arg) /* Not our event */
3760 1.1 dyoung return;
3761 1.1 dyoung
3762 1.1 dyoung if ((vtag == 0) || (vtag > 4095)) /* Invalid */
3763 1.1 dyoung return;
3764 1.1 dyoung
3765 1.5 msaitoh IXV_CORE_LOCK(adapter);
3766 1.1 dyoung index = (vtag >> 5) & 0x7F;
3767 1.1 dyoung bit = vtag & 0x1F;
3768 1.1 dyoung ixv_shadow_vfta[index] |= (1 << bit);
3769 1.1 dyoung /* Re-init to load the changes */
3770 1.5 msaitoh ixv_init_locked(adapter);
3771 1.5 msaitoh IXV_CORE_UNLOCK(adapter);
3772 1.1 dyoung }
3773 1.1 dyoung
3774 1.1 dyoung /*
3775 1.1 dyoung ** This routine is run via an vlan
3776 1.1 dyoung ** unconfig EVENT, remove our entry
3777 1.1 dyoung ** in the soft vfta.
3778 1.1 dyoung */
3779 1.1 dyoung static void
3780 1.1 dyoung ixv_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag)
3781 1.1 dyoung {
3782 1.1 dyoung struct adapter *adapter = ifp->if_softc;
3783 1.1 dyoung u16 index, bit;
3784 1.1 dyoung
3785 1.1 dyoung if (ifp->if_softc != arg)
3786 1.1 dyoung return;
3787 1.1 dyoung
3788 1.1 dyoung if ((vtag == 0) || (vtag > 4095)) /* Invalid */
3789 1.1 dyoung return;
3790 1.1 dyoung
3791 1.5 msaitoh IXV_CORE_LOCK(adapter);
3792 1.1 dyoung index = (vtag >> 5) & 0x7F;
3793 1.1 dyoung bit = vtag & 0x1F;
3794 1.1 dyoung ixv_shadow_vfta[index] &= ~(1 << bit);
3795 1.1 dyoung /* Re-init to load the changes */
3796 1.5 msaitoh ixv_init_locked(adapter);
3797 1.5 msaitoh IXV_CORE_UNLOCK(adapter);
3798 1.1 dyoung }
3799 1.3 msaitoh #endif
3800 1.1 dyoung
3801 1.1 dyoung static void
3802 1.1 dyoung ixv_enable_intr(struct adapter *adapter)
3803 1.1 dyoung {
3804 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
3805 1.1 dyoung struct ix_queue *que = adapter->queues;
3806 1.1 dyoung u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
3807 1.1 dyoung
3808 1.1 dyoung
3809 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
3810 1.1 dyoung
3811 1.1 dyoung mask = IXGBE_EIMS_ENABLE_MASK;
3812 1.1 dyoung mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
3813 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, mask);
3814 1.1 dyoung
3815 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, que++)
3816 1.1 dyoung ixv_enable_queue(adapter, que->msix);
3817 1.1 dyoung
3818 1.1 dyoung IXGBE_WRITE_FLUSH(hw);
3819 1.1 dyoung
3820 1.1 dyoung return;
3821 1.1 dyoung }
3822 1.1 dyoung
3823 1.1 dyoung static void
3824 1.1 dyoung ixv_disable_intr(struct adapter *adapter)
3825 1.1 dyoung {
3826 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIAC, 0);
3827 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIMC, ~0);
3828 1.1 dyoung IXGBE_WRITE_FLUSH(&adapter->hw);
3829 1.1 dyoung return;
3830 1.1 dyoung }
3831 1.1 dyoung
3832 1.1 dyoung /*
3833 1.1 dyoung ** Setup the correct IVAR register for a particular MSIX interrupt
3834 1.1 dyoung ** - entry is the register array entry
3835 1.1 dyoung ** - vector is the MSIX vector for this queue
3836 1.1 dyoung ** - type is RX/TX/MISC
3837 1.1 dyoung */
3838 1.1 dyoung static void
3839 1.1 dyoung ixv_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
3840 1.1 dyoung {
3841 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
3842 1.1 dyoung u32 ivar, index;
3843 1.1 dyoung
3844 1.1 dyoung vector |= IXGBE_IVAR_ALLOC_VAL;
3845 1.1 dyoung
3846 1.1 dyoung if (type == -1) { /* MISC IVAR */
3847 1.1 dyoung ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
3848 1.1 dyoung ivar &= ~0xFF;
3849 1.1 dyoung ivar |= vector;
3850 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
3851 1.1 dyoung } else { /* RX/TX IVARS */
3852 1.1 dyoung index = (16 * (entry & 1)) + (8 * type);
3853 1.1 dyoung ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(entry >> 1));
3854 1.1 dyoung ivar &= ~(0xFF << index);
3855 1.1 dyoung ivar |= (vector << index);
3856 1.1 dyoung IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(entry >> 1), ivar);
3857 1.1 dyoung }
3858 1.1 dyoung }
3859 1.1 dyoung
3860 1.1 dyoung static void
3861 1.1 dyoung ixv_configure_ivars(struct adapter *adapter)
3862 1.1 dyoung {
3863 1.1 dyoung struct ix_queue *que = adapter->queues;
3864 1.1 dyoung
3865 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, que++) {
3866 1.1 dyoung /* First the RX queue entry */
3867 1.1 dyoung ixv_set_ivar(adapter, i, que->msix, 0);
3868 1.1 dyoung /* ... and the TX */
3869 1.1 dyoung ixv_set_ivar(adapter, i, que->msix, 1);
3870 1.1 dyoung /* Set an initial value in EITR */
3871 1.1 dyoung IXGBE_WRITE_REG(&adapter->hw,
3872 1.1 dyoung IXGBE_VTEITR(que->msix), IXV_EITR_DEFAULT);
3873 1.1 dyoung }
3874 1.1 dyoung
3875 1.1 dyoung /* For the Link interrupt */
3876 1.1 dyoung ixv_set_ivar(adapter, 1, adapter->mbxvec, -1);
3877 1.1 dyoung }
3878 1.1 dyoung
3879 1.1 dyoung
3880 1.1 dyoung /*
3881 1.1 dyoung ** Tasklet handler for MSIX MBX interrupts
3882 1.1 dyoung ** - do outside interrupt since it might sleep
3883 1.1 dyoung */
3884 1.1 dyoung static void
3885 1.1 dyoung ixv_handle_mbx(void *context)
3886 1.1 dyoung {
3887 1.1 dyoung struct adapter *adapter = context;
3888 1.1 dyoung
3889 1.1 dyoung ixgbe_check_link(&adapter->hw,
3890 1.1 dyoung &adapter->link_speed, &adapter->link_up, 0);
3891 1.1 dyoung ixv_update_link_status(adapter);
3892 1.1 dyoung }
3893 1.1 dyoung
3894 1.1 dyoung /*
3895 1.1 dyoung ** The VF stats registers never have a truely virgin
3896 1.1 dyoung ** starting point, so this routine tries to make an
3897 1.1 dyoung ** artificial one, marking ground zero on attach as
3898 1.1 dyoung ** it were.
3899 1.1 dyoung */
3900 1.1 dyoung static void
3901 1.1 dyoung ixv_save_stats(struct adapter *adapter)
3902 1.1 dyoung {
3903 1.1 dyoung if (adapter->stats.vfgprc || adapter->stats.vfgptc) {
3904 1.1 dyoung adapter->stats.saved_reset_vfgprc +=
3905 1.1 dyoung adapter->stats.vfgprc - adapter->stats.base_vfgprc;
3906 1.1 dyoung adapter->stats.saved_reset_vfgptc +=
3907 1.1 dyoung adapter->stats.vfgptc - adapter->stats.base_vfgptc;
3908 1.1 dyoung adapter->stats.saved_reset_vfgorc +=
3909 1.1 dyoung adapter->stats.vfgorc - adapter->stats.base_vfgorc;
3910 1.1 dyoung adapter->stats.saved_reset_vfgotc +=
3911 1.1 dyoung adapter->stats.vfgotc - adapter->stats.base_vfgotc;
3912 1.1 dyoung adapter->stats.saved_reset_vfmprc +=
3913 1.1 dyoung adapter->stats.vfmprc - adapter->stats.base_vfmprc;
3914 1.1 dyoung }
3915 1.1 dyoung }
3916 1.1 dyoung
3917 1.1 dyoung static void
3918 1.1 dyoung ixv_init_stats(struct adapter *adapter)
3919 1.1 dyoung {
3920 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
3921 1.1 dyoung
3922 1.1 dyoung adapter->stats.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
3923 1.1 dyoung adapter->stats.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
3924 1.1 dyoung adapter->stats.last_vfgorc |=
3925 1.1 dyoung (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
3926 1.1 dyoung
3927 1.1 dyoung adapter->stats.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
3928 1.1 dyoung adapter->stats.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
3929 1.1 dyoung adapter->stats.last_vfgotc |=
3930 1.1 dyoung (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
3931 1.1 dyoung
3932 1.1 dyoung adapter->stats.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
3933 1.1 dyoung
3934 1.1 dyoung adapter->stats.base_vfgprc = adapter->stats.last_vfgprc;
3935 1.1 dyoung adapter->stats.base_vfgorc = adapter->stats.last_vfgorc;
3936 1.1 dyoung adapter->stats.base_vfgptc = adapter->stats.last_vfgptc;
3937 1.1 dyoung adapter->stats.base_vfgotc = adapter->stats.last_vfgotc;
3938 1.1 dyoung adapter->stats.base_vfmprc = adapter->stats.last_vfmprc;
3939 1.1 dyoung }
3940 1.1 dyoung
3941 1.1 dyoung #define UPDATE_STAT_32(reg, last, count) \
3942 1.1 dyoung { \
3943 1.1 dyoung u32 current = IXGBE_READ_REG(hw, reg); \
3944 1.1 dyoung if (current < last) \
3945 1.1 dyoung count += 0x100000000LL; \
3946 1.1 dyoung last = current; \
3947 1.1 dyoung count &= 0xFFFFFFFF00000000LL; \
3948 1.1 dyoung count |= current; \
3949 1.1 dyoung }
3950 1.1 dyoung
3951 1.1 dyoung #define UPDATE_STAT_36(lsb, msb, last, count) \
3952 1.1 dyoung { \
3953 1.1 dyoung u64 cur_lsb = IXGBE_READ_REG(hw, lsb); \
3954 1.1 dyoung u64 cur_msb = IXGBE_READ_REG(hw, msb); \
3955 1.1 dyoung u64 current = ((cur_msb << 32) | cur_lsb); \
3956 1.1 dyoung if (current < last) \
3957 1.1 dyoung count += 0x1000000000LL; \
3958 1.1 dyoung last = current; \
3959 1.1 dyoung count &= 0xFFFFFFF000000000LL; \
3960 1.1 dyoung count |= current; \
3961 1.1 dyoung }
3962 1.1 dyoung
3963 1.1 dyoung /*
3964 1.1 dyoung ** ixv_update_stats - Update the board statistics counters.
3965 1.1 dyoung */
3966 1.1 dyoung void
3967 1.1 dyoung ixv_update_stats(struct adapter *adapter)
3968 1.1 dyoung {
3969 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
3970 1.1 dyoung
3971 1.1 dyoung UPDATE_STAT_32(IXGBE_VFGPRC, adapter->stats.last_vfgprc,
3972 1.1 dyoung adapter->stats.vfgprc);
3973 1.1 dyoung UPDATE_STAT_32(IXGBE_VFGPTC, adapter->stats.last_vfgptc,
3974 1.1 dyoung adapter->stats.vfgptc);
3975 1.1 dyoung UPDATE_STAT_36(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
3976 1.1 dyoung adapter->stats.last_vfgorc, adapter->stats.vfgorc);
3977 1.1 dyoung UPDATE_STAT_36(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
3978 1.1 dyoung adapter->stats.last_vfgotc, adapter->stats.vfgotc);
3979 1.1 dyoung UPDATE_STAT_32(IXGBE_VFMPRC, adapter->stats.last_vfmprc,
3980 1.1 dyoung adapter->stats.vfmprc);
3981 1.1 dyoung }
3982 1.1 dyoung
3983 1.1 dyoung /**********************************************************************
3984 1.1 dyoung *
3985 1.1 dyoung * This routine is called only when ixgbe_display_debug_stats is enabled.
3986 1.1 dyoung * This routine provides a way to take a look at important statistics
3987 1.1 dyoung * maintained by the driver and hardware.
3988 1.1 dyoung *
3989 1.1 dyoung **********************************************************************/
3990 1.1 dyoung static void
3991 1.1 dyoung ixv_print_hw_stats(struct adapter * adapter)
3992 1.1 dyoung {
3993 1.1 dyoung device_t dev = adapter->dev;
3994 1.1 dyoung
3995 1.11 msaitoh device_printf(dev,"Std Mbuf Failed = %"PRIu64"\n",
3996 1.3 msaitoh adapter->mbuf_defrag_failed.ev_count);
3997 1.11 msaitoh device_printf(dev,"Driver dropped packets = %"PRIu64"\n",
3998 1.3 msaitoh adapter->dropped_pkts.ev_count);
3999 1.11 msaitoh device_printf(dev, "watchdog timeouts = %"PRIu64"\n",
4000 1.3 msaitoh adapter->watchdog_events.ev_count);
4001 1.1 dyoung
4002 1.11 msaitoh device_printf(dev,"Good Packets Rcvd = %lld\n",
4003 1.1 dyoung (long long)adapter->stats.vfgprc);
4004 1.11 msaitoh device_printf(dev,"Good Packets Xmtd = %lld\n",
4005 1.1 dyoung (long long)adapter->stats.vfgptc);
4006 1.11 msaitoh device_printf(dev,"TSO Transmissions = %"PRIu64"\n",
4007 1.3 msaitoh adapter->tso_tx.ev_count);
4008 1.1 dyoung
4009 1.1 dyoung }
4010 1.1 dyoung
4011 1.1 dyoung /**********************************************************************
4012 1.1 dyoung *
4013 1.1 dyoung * This routine is called only when em_display_debug_stats is enabled.
4014 1.1 dyoung * This routine provides a way to take a look at important statistics
4015 1.1 dyoung * maintained by the driver and hardware.
4016 1.1 dyoung *
4017 1.1 dyoung **********************************************************************/
4018 1.1 dyoung static void
4019 1.1 dyoung ixv_print_debug_info(struct adapter *adapter)
4020 1.1 dyoung {
4021 1.1 dyoung device_t dev = adapter->dev;
4022 1.1 dyoung struct ixgbe_hw *hw = &adapter->hw;
4023 1.1 dyoung struct ix_queue *que = adapter->queues;
4024 1.1 dyoung struct rx_ring *rxr;
4025 1.1 dyoung struct tx_ring *txr;
4026 1.3 msaitoh #ifdef LRO
4027 1.1 dyoung struct lro_ctrl *lro;
4028 1.3 msaitoh #endif /* LRO */
4029 1.1 dyoung
4030 1.1 dyoung device_printf(dev,"Error Byte Count = %u \n",
4031 1.1 dyoung IXGBE_READ_REG(hw, IXGBE_ERRBC));
4032 1.1 dyoung
4033 1.1 dyoung for (int i = 0; i < adapter->num_queues; i++, que++) {
4034 1.1 dyoung txr = que->txr;
4035 1.1 dyoung rxr = que->rxr;
4036 1.3 msaitoh #ifdef LRO
4037 1.1 dyoung lro = &rxr->lro;
4038 1.3 msaitoh #endif /* LRO */
4039 1.1 dyoung device_printf(dev,"QUE(%d) IRQs Handled: %lu\n",
4040 1.1 dyoung que->msix, (long)que->irqs);
4041 1.1 dyoung device_printf(dev,"RX(%d) Packets Received: %lld\n",
4042 1.3 msaitoh rxr->me, (long long)rxr->rx_packets.ev_count);
4043 1.1 dyoung device_printf(dev,"RX(%d) Split RX Packets: %lld\n",
4044 1.3 msaitoh rxr->me, (long long)rxr->rx_split_packets.ev_count);
4045 1.1 dyoung device_printf(dev,"RX(%d) Bytes Received: %lu\n",
4046 1.3 msaitoh rxr->me, (long)rxr->rx_bytes.ev_count);
4047 1.3 msaitoh #ifdef LRO
4048 1.1 dyoung device_printf(dev,"RX(%d) LRO Queued= %d\n",
4049 1.1 dyoung rxr->me, lro->lro_queued);
4050 1.1 dyoung device_printf(dev,"RX(%d) LRO Flushed= %d\n",
4051 1.1 dyoung rxr->me, lro->lro_flushed);
4052 1.3 msaitoh #endif /* LRO */
4053 1.1 dyoung device_printf(dev,"TX(%d) Packets Sent: %lu\n",
4054 1.3 msaitoh txr->me, (long)txr->total_packets.ev_count);
4055 1.1 dyoung device_printf(dev,"TX(%d) NO Desc Avail: %lu\n",
4056 1.3 msaitoh txr->me, (long)txr->no_desc_avail.ev_count);
4057 1.1 dyoung }
4058 1.1 dyoung
4059 1.1 dyoung device_printf(dev,"MBX IRQ Handled: %lu\n",
4060 1.3 msaitoh (long)adapter->mbx_irq.ev_count);
4061 1.1 dyoung return;
4062 1.1 dyoung }
4063 1.1 dyoung
4064 1.1 dyoung static int
4065 1.3 msaitoh ixv_sysctl_stats(SYSCTLFN_ARGS)
4066 1.1 dyoung {
4067 1.3 msaitoh struct sysctlnode node;
4068 1.1 dyoung int error;
4069 1.3 msaitoh int result;
4070 1.1 dyoung struct adapter *adapter;
4071 1.1 dyoung
4072 1.3 msaitoh node = *rnode;
4073 1.3 msaitoh adapter = (struct adapter *)node.sysctl_data;
4074 1.3 msaitoh node.sysctl_data = &result;
4075 1.3 msaitoh error = sysctl_lookup(SYSCTLFN_CALL(&node));
4076 1.3 msaitoh if (error != 0)
4077 1.3 msaitoh return error;
4078 1.1 dyoung
4079 1.3 msaitoh if (result == 1)
4080 1.3 msaitoh ixv_print_hw_stats(adapter);
4081 1.1 dyoung
4082 1.3 msaitoh return 0;
4083 1.1 dyoung }
4084 1.1 dyoung
4085 1.1 dyoung static int
4086 1.3 msaitoh ixv_sysctl_debug(SYSCTLFN_ARGS)
4087 1.1 dyoung {
4088 1.3 msaitoh struct sysctlnode node;
4089 1.1 dyoung int error, result;
4090 1.1 dyoung struct adapter *adapter;
4091 1.1 dyoung
4092 1.3 msaitoh node = *rnode;
4093 1.3 msaitoh adapter = (struct adapter *)node.sysctl_data;
4094 1.3 msaitoh node.sysctl_data = &result;
4095 1.3 msaitoh error = sysctl_lookup(SYSCTLFN_CALL(&node));
4096 1.1 dyoung
4097 1.3 msaitoh if (error)
4098 1.3 msaitoh return error;
4099 1.1 dyoung
4100 1.3 msaitoh if (result == 1)
4101 1.1 dyoung ixv_print_debug_info(adapter);
4102 1.3 msaitoh
4103 1.3 msaitoh return 0;
4104 1.1 dyoung }
4105 1.1 dyoung
4106 1.1 dyoung /*
4107 1.1 dyoung ** Set flow control using sysctl:
4108 1.1 dyoung ** Flow control values:
4109 1.1 dyoung ** 0 - off
4110 1.1 dyoung ** 1 - rx pause
4111 1.1 dyoung ** 2 - tx pause
4112 1.1 dyoung ** 3 - full
4113 1.1 dyoung */
4114 1.1 dyoung static int
4115 1.3 msaitoh ixv_set_flowcntl(SYSCTLFN_ARGS)
4116 1.1 dyoung {
4117 1.3 msaitoh struct sysctlnode node;
4118 1.1 dyoung int error;
4119 1.1 dyoung struct adapter *adapter;
4120 1.1 dyoung
4121 1.3 msaitoh node = *rnode;
4122 1.3 msaitoh adapter = (struct adapter *)node.sysctl_data;
4123 1.3 msaitoh node.sysctl_data = &ixv_flow_control;
4124 1.3 msaitoh error = sysctl_lookup(SYSCTLFN_CALL(&node));
4125 1.1 dyoung
4126 1.1 dyoung if (error)
4127 1.1 dyoung return (error);
4128 1.1 dyoung
4129 1.1 dyoung switch (ixv_flow_control) {
4130 1.1 dyoung case ixgbe_fc_rx_pause:
4131 1.1 dyoung case ixgbe_fc_tx_pause:
4132 1.1 dyoung case ixgbe_fc_full:
4133 1.1 dyoung adapter->hw.fc.requested_mode = ixv_flow_control;
4134 1.1 dyoung break;
4135 1.1 dyoung case ixgbe_fc_none:
4136 1.1 dyoung default:
4137 1.1 dyoung adapter->hw.fc.requested_mode = ixgbe_fc_none;
4138 1.1 dyoung }
4139 1.1 dyoung
4140 1.6 msaitoh ixgbe_fc_enable(&adapter->hw);
4141 1.1 dyoung return error;
4142 1.1 dyoung }
4143 1.1 dyoung
4144 1.3 msaitoh const struct sysctlnode *
4145 1.3 msaitoh ixv_sysctl_instance(struct adapter *adapter)
4146 1.3 msaitoh {
4147 1.3 msaitoh const char *dvname;
4148 1.3 msaitoh struct sysctllog **log;
4149 1.3 msaitoh int rc;
4150 1.3 msaitoh const struct sysctlnode *rnode;
4151 1.3 msaitoh
4152 1.3 msaitoh log = &adapter->sysctllog;
4153 1.3 msaitoh dvname = device_xname(adapter->dev);
4154 1.3 msaitoh
4155 1.3 msaitoh if ((rc = sysctl_createv(log, 0, NULL, &rnode,
4156 1.3 msaitoh 0, CTLTYPE_NODE, dvname,
4157 1.3 msaitoh SYSCTL_DESCR("ixv information and settings"),
4158 1.3 msaitoh NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0)
4159 1.3 msaitoh goto err;
4160 1.3 msaitoh
4161 1.3 msaitoh return rnode;
4162 1.3 msaitoh err:
4163 1.3 msaitoh printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
4164 1.3 msaitoh return NULL;
4165 1.3 msaitoh }
4166 1.3 msaitoh
4167 1.1 dyoung static void
4168 1.1 dyoung ixv_add_rx_process_limit(struct adapter *adapter, const char *name,
4169 1.1 dyoung const char *description, int *limit, int value)
4170 1.1 dyoung {
4171 1.3 msaitoh const struct sysctlnode *rnode, *cnode;
4172 1.3 msaitoh struct sysctllog **log = &adapter->sysctllog;
4173 1.3 msaitoh
4174 1.1 dyoung *limit = value;
4175 1.3 msaitoh
4176 1.3 msaitoh if ((rnode = ixv_sysctl_instance(adapter)) == NULL)
4177 1.3 msaitoh aprint_error_dev(adapter->dev,
4178 1.3 msaitoh "could not create sysctl root\n");
4179 1.3 msaitoh else if (sysctl_createv(log, 0, &rnode, &cnode,
4180 1.3 msaitoh CTLFLAG_READWRITE,
4181 1.3 msaitoh CTLTYPE_INT,
4182 1.3 msaitoh name, SYSCTL_DESCR(description),
4183 1.3 msaitoh NULL, 0, limit, 0,
4184 1.3 msaitoh CTL_CREATE, CTL_EOL) != 0) {
4185 1.3 msaitoh aprint_error_dev(adapter->dev, "%s: could not create sysctl",
4186 1.3 msaitoh __func__);
4187 1.3 msaitoh }
4188 1.1 dyoung }
4189 1.1 dyoung
4190