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