2 * Copyright (c) 2001-2013, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include "opt_ifpoll.h"
35 #include <sys/param.h>
37 #include <sys/endian.h>
38 #include <sys/interrupt.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
44 #include <sys/serialize.h>
45 #include <sys/serialize2.h>
46 #include <sys/socket.h>
47 #include <sys/sockio.h>
48 #include <sys/sysctl.h>
49 #include <sys/systm.h>
52 #include <net/ethernet.h>
54 #include <net/if_arp.h>
55 #include <net/if_dl.h>
56 #include <net/if_media.h>
57 #include <net/ifq_var.h>
58 #include <net/if_ringmap.h>
59 #include <net/toeplitz.h>
60 #include <net/toeplitz2.h>
61 #include <net/vlan/if_vlan_var.h>
62 #include <net/vlan/if_vlan_ether.h>
63 #include <net/if_poll.h>
65 #include <netinet/in_systm.h>
66 #include <netinet/in.h>
67 #include <netinet/ip.h>
69 #include <bus/pci/pcivar.h>
70 #include <bus/pci/pcireg.h>
72 #include <dev/netif/ig_hal/e1000_api.h>
73 #include <dev/netif/ig_hal/e1000_82575.h>
74 #include <dev/netif/ig_hal/e1000_dragonfly.h>
75 #include <dev/netif/igb/if_igb.h>
78 #define IGB_RSS_DPRINTF(sc, lvl, fmt, ...) \
80 if (sc->rss_debug >= lvl) \
81 if_printf(&sc->arpcom.ac_if, fmt, __VA_ARGS__); \
83 #else /* !IGB_RSS_DEBUG */
84 #define IGB_RSS_DPRINTF(sc, lvl, fmt, ...) ((void)0)
85 #endif /* IGB_RSS_DEBUG */
87 #define IGB_NAME "Intel(R) PRO/1000 "
88 #define IGB_DEVICE(id) \
89 { IGB_VENDOR_ID, E1000_DEV_ID_##id, IGB_NAME #id }
90 #define IGB_DEVICE_NULL { 0, 0, NULL }
92 static struct igb_device {
97 IGB_DEVICE(82575EB_COPPER),
98 IGB_DEVICE(82575EB_FIBER_SERDES),
99 IGB_DEVICE(82575GB_QUAD_COPPER),
101 IGB_DEVICE(82576_NS),
102 IGB_DEVICE(82576_NS_SERDES),
103 IGB_DEVICE(82576_FIBER),
104 IGB_DEVICE(82576_SERDES),
105 IGB_DEVICE(82576_SERDES_QUAD),
106 IGB_DEVICE(82576_QUAD_COPPER),
107 IGB_DEVICE(82576_QUAD_COPPER_ET2),
108 IGB_DEVICE(82576_VF),
109 IGB_DEVICE(82580_COPPER),
110 IGB_DEVICE(82580_FIBER),
111 IGB_DEVICE(82580_SERDES),
112 IGB_DEVICE(82580_SGMII),
113 IGB_DEVICE(82580_COPPER_DUAL),
114 IGB_DEVICE(82580_QUAD_FIBER),
115 IGB_DEVICE(DH89XXCC_SERDES),
116 IGB_DEVICE(DH89XXCC_SGMII),
117 IGB_DEVICE(DH89XXCC_SFP),
118 IGB_DEVICE(DH89XXCC_BACKPLANE),
119 IGB_DEVICE(I350_COPPER),
120 IGB_DEVICE(I350_FIBER),
121 IGB_DEVICE(I350_SERDES),
122 IGB_DEVICE(I350_SGMII),
124 IGB_DEVICE(I210_COPPER),
125 IGB_DEVICE(I210_COPPER_IT),
126 IGB_DEVICE(I210_COPPER_OEM1),
127 IGB_DEVICE(I210_COPPER_FLASHLESS),
128 IGB_DEVICE(I210_SERDES_FLASHLESS),
129 IGB_DEVICE(I210_FIBER),
130 IGB_DEVICE(I210_SERDES),
131 IGB_DEVICE(I210_SGMII),
132 IGB_DEVICE(I211_COPPER),
133 IGB_DEVICE(I354_BACKPLANE_1GBPS),
134 IGB_DEVICE(I354_BACKPLANE_2_5GBPS),
135 IGB_DEVICE(I354_SGMII),
137 /* required last entry */
141 static int igb_probe(device_t);
142 static int igb_attach(device_t);
143 static int igb_detach(device_t);
144 static int igb_shutdown(device_t);
145 static int igb_suspend(device_t);
146 static int igb_resume(device_t);
148 static boolean_t igb_is_valid_ether_addr(const uint8_t *);
149 static void igb_setup_ifp(struct igb_softc *);
150 static boolean_t igb_txcsum_ctx(struct igb_tx_ring *, struct mbuf *);
151 static int igb_tso_pullup(struct igb_tx_ring *, struct mbuf **);
152 static void igb_tso_ctx(struct igb_tx_ring *, struct mbuf *, uint32_t *);
153 static void igb_add_sysctl(struct igb_softc *);
154 static void igb_add_intr_rate_sysctl(struct igb_softc *, int,
155 const char *, const char *);
156 static int igb_sysctl_intr_rate(SYSCTL_HANDLER_ARGS);
157 static int igb_sysctl_tx_intr_nsegs(SYSCTL_HANDLER_ARGS);
158 static int igb_sysctl_tx_wreg_nsegs(SYSCTL_HANDLER_ARGS);
159 static int igb_sysctl_rx_wreg_nsegs(SYSCTL_HANDLER_ARGS);
160 static void igb_set_ring_inuse(struct igb_softc *, boolean_t);
161 static int igb_get_rxring_inuse(const struct igb_softc *, boolean_t);
162 static int igb_get_txring_inuse(const struct igb_softc *, boolean_t);
163 static void igb_set_timer_cpuid(struct igb_softc *, boolean_t);
165 static void igb_vf_init_stats(struct igb_softc *);
166 static void igb_reset(struct igb_softc *, boolean_t);
167 static void igb_update_stats_counters(struct igb_softc *);
168 static void igb_update_vf_stats_counters(struct igb_softc *);
169 static void igb_update_link_status(struct igb_softc *);
170 static void igb_init_tx_unit(struct igb_softc *);
171 static void igb_init_rx_unit(struct igb_softc *, boolean_t);
172 static void igb_init_dmac(struct igb_softc *, uint32_t);
173 static void igb_reg_dump(struct igb_softc *);
174 static int igb_sysctl_reg_dump(SYSCTL_HANDLER_ARGS);
176 static void igb_set_vlan(struct igb_softc *);
177 static void igb_set_multi(struct igb_softc *);
178 static void igb_set_promisc(struct igb_softc *);
179 static void igb_disable_promisc(struct igb_softc *);
181 static int igb_get_ring_max(const struct igb_softc *);
182 static void igb_get_rxring_cnt(const struct igb_softc *, int *, int *);
183 static void igb_get_txring_cnt(const struct igb_softc *, int *, int *);
184 static int igb_alloc_rings(struct igb_softc *);
185 static void igb_free_rings(struct igb_softc *);
186 static int igb_create_tx_ring(struct igb_tx_ring *);
187 static int igb_create_rx_ring(struct igb_rx_ring *);
188 static void igb_free_tx_ring(struct igb_tx_ring *);
189 static void igb_free_rx_ring(struct igb_rx_ring *);
190 static void igb_destroy_tx_ring(struct igb_tx_ring *, int);
191 static void igb_destroy_rx_ring(struct igb_rx_ring *, int);
192 static void igb_init_tx_ring(struct igb_tx_ring *);
193 static int igb_init_rx_ring(struct igb_rx_ring *);
194 static int igb_newbuf(struct igb_rx_ring *, int, boolean_t);
195 static int igb_encap(struct igb_tx_ring *, struct mbuf **, int *, int *);
196 static void igb_rx_refresh(struct igb_rx_ring *, int);
197 static void igb_setup_serialize(struct igb_softc *);
199 static void igb_stop(struct igb_softc *);
200 static void igb_init(void *);
201 static int igb_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
202 static void igb_media_status(struct ifnet *, struct ifmediareq *);
203 static int igb_media_change(struct ifnet *);
204 static void igb_timer(void *);
205 static void igb_watchdog(struct ifaltq_subque *);
206 static void igb_start(struct ifnet *, struct ifaltq_subque *);
208 static void igb_npoll(struct ifnet *, struct ifpoll_info *);
209 static void igb_npoll_rx(struct ifnet *, void *, int);
210 static void igb_npoll_tx(struct ifnet *, void *, int);
211 static void igb_npoll_status(struct ifnet *);
213 static void igb_serialize(struct ifnet *, enum ifnet_serialize);
214 static void igb_deserialize(struct ifnet *, enum ifnet_serialize);
215 static int igb_tryserialize(struct ifnet *, enum ifnet_serialize);
217 static void igb_serialize_assert(struct ifnet *, enum ifnet_serialize,
221 static void igb_intr(void *);
222 static void igb_intr_shared(void *);
223 static void igb_rxeof(struct igb_rx_ring *, int);
224 static void igb_txeof(struct igb_tx_ring *, int);
225 static void igb_txgc(struct igb_tx_ring *);
226 static void igb_txgc_timer(void *);
227 static void igb_set_eitr(struct igb_softc *, int, int);
228 static void igb_enable_intr(struct igb_softc *);
229 static void igb_disable_intr(struct igb_softc *);
230 static void igb_init_unshared_intr(struct igb_softc *);
231 static void igb_init_intr(struct igb_softc *);
232 static int igb_setup_intr(struct igb_softc *);
233 static void igb_set_txintr_mask(struct igb_tx_ring *, int *, int);
234 static void igb_set_rxintr_mask(struct igb_rx_ring *, int *, int);
235 static void igb_set_intr_mask(struct igb_softc *);
236 static int igb_alloc_intr(struct igb_softc *);
237 static void igb_free_intr(struct igb_softc *);
238 static void igb_teardown_intr(struct igb_softc *, int);
239 static void igb_alloc_msix(struct igb_softc *);
240 static void igb_free_msix(struct igb_softc *, boolean_t);
241 static void igb_msix_rx(void *);
242 static void igb_msix_tx(void *);
243 static void igb_msix_status(void *);
244 static void igb_msix_rxtx(void *);
246 /* Management and WOL Support */
247 static void igb_get_mgmt(struct igb_softc *);
248 static void igb_rel_mgmt(struct igb_softc *);
249 static void igb_get_hw_control(struct igb_softc *);
250 static void igb_rel_hw_control(struct igb_softc *);
251 static void igb_enable_wol(struct igb_softc *);
252 static int igb_enable_phy_wol(struct igb_softc *);
254 static device_method_t igb_methods[] = {
255 /* Device interface */
256 DEVMETHOD(device_probe, igb_probe),
257 DEVMETHOD(device_attach, igb_attach),
258 DEVMETHOD(device_detach, igb_detach),
259 DEVMETHOD(device_shutdown, igb_shutdown),
260 DEVMETHOD(device_suspend, igb_suspend),
261 DEVMETHOD(device_resume, igb_resume),
265 static driver_t igb_driver = {
268 sizeof(struct igb_softc),
271 static devclass_t igb_devclass;
273 DECLARE_DUMMY_MODULE(if_igb);
274 MODULE_DEPEND(igb, ig_hal, 1, 1, 1);
275 DRIVER_MODULE(if_igb, pci, igb_driver, igb_devclass, NULL, NULL);
277 static int igb_rxd = IGB_DEFAULT_RXD;
278 static int igb_txd = IGB_DEFAULT_TXD;
279 static int igb_rxr = 0;
280 static int igb_txr = 0;
281 static int igb_msi_enable = 1;
282 static int igb_msix_enable = 1;
283 static int igb_eee_disabled = 1; /* Energy Efficient Ethernet */
285 static char igb_flowctrl[IFM_ETH_FC_STRLEN] = IFM_ETH_FC_NONE;
288 * DMA Coalescing, only for i350 - default to off,
289 * this feature is for power savings
291 static int igb_dma_coalesce = 0;
293 TUNABLE_INT("hw.igb.rxd", &igb_rxd);
294 TUNABLE_INT("hw.igb.txd", &igb_txd);
295 TUNABLE_INT("hw.igb.rxr", &igb_rxr);
296 TUNABLE_INT("hw.igb.txr", &igb_txr);
297 TUNABLE_INT("hw.igb.msi.enable", &igb_msi_enable);
298 TUNABLE_INT("hw.igb.msix.enable", &igb_msix_enable);
299 TUNABLE_STR("hw.igb.flow_ctrl", igb_flowctrl, sizeof(igb_flowctrl));
302 TUNABLE_INT("hw.igb.eee_disabled", &igb_eee_disabled);
303 TUNABLE_INT("hw.igb.dma_coalesce", &igb_dma_coalesce);
306 igb_tx_intr(struct igb_tx_ring *txr, int hdr)
310 if (!ifsq_is_empty(txr->ifsq))
311 ifsq_devstart(txr->ifsq);
315 igb_try_txgc(struct igb_tx_ring *txr, int16_t dec)
318 if (txr->tx_running > 0) {
319 txr->tx_running -= dec;
320 if (txr->tx_running <= 0 && txr->tx_nmbuf &&
321 txr->tx_avail < txr->num_tx_desc &&
322 txr->tx_avail + txr->intr_nsegs > txr->num_tx_desc)
328 igb_txgc_timer(void *xtxr)
330 struct igb_tx_ring *txr = xtxr;
331 struct ifnet *ifp = &txr->sc->arpcom.ac_if;
333 if ((ifp->if_flags & (IFF_RUNNING | IFF_UP | IFF_NPOLLING)) !=
334 (IFF_RUNNING | IFF_UP))
337 if (!lwkt_serialize_try(&txr->tx_serialize))
340 if ((ifp->if_flags & (IFF_RUNNING | IFF_UP | IFF_NPOLLING)) !=
341 (IFF_RUNNING | IFF_UP)) {
342 lwkt_serialize_exit(&txr->tx_serialize);
345 igb_try_txgc(txr, IGB_TX_RUNNING_DEC);
347 lwkt_serialize_exit(&txr->tx_serialize);
349 callout_reset(&txr->tx_gc_timer, 1, igb_txgc_timer, txr);
353 igb_free_txbuf(struct igb_tx_ring *txr, struct igb_tx_buf *txbuf)
356 KKASSERT(txbuf->m_head != NULL);
357 KKASSERT(txr->tx_nmbuf > 0);
360 bus_dmamap_unload(txr->tx_tag, txbuf->map);
361 m_freem(txbuf->m_head);
362 txbuf->m_head = NULL;
366 igb_rxcsum(uint32_t staterr, struct mbuf *mp)
368 /* Ignore Checksum bit is set */
369 if (staterr & E1000_RXD_STAT_IXSM)
372 if ((staterr & (E1000_RXD_STAT_IPCS | E1000_RXDEXT_STATERR_IPE)) ==
374 mp->m_pkthdr.csum_flags |= CSUM_IP_CHECKED | CSUM_IP_VALID;
376 if (staterr & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)) {
377 if ((staterr & E1000_RXDEXT_STATERR_TCPE) == 0) {
378 mp->m_pkthdr.csum_flags |= CSUM_DATA_VALID |
379 CSUM_PSEUDO_HDR | CSUM_FRAG_NOT_CHECKED;
380 mp->m_pkthdr.csum_data = htons(0xffff);
385 static __inline struct pktinfo *
386 igb_rssinfo(struct mbuf *m, struct pktinfo *pi,
387 uint32_t hash, uint32_t hashtype, uint32_t staterr)
390 case E1000_RXDADV_RSSTYPE_IPV4_TCP:
391 pi->pi_netisr = NETISR_IP;
393 pi->pi_l3proto = IPPROTO_TCP;
396 case E1000_RXDADV_RSSTYPE_IPV4:
397 if (staterr & E1000_RXD_STAT_IXSM)
401 (E1000_RXD_STAT_TCPCS | E1000_RXDEXT_STATERR_TCPE)) ==
402 E1000_RXD_STAT_TCPCS) {
403 pi->pi_netisr = NETISR_IP;
405 pi->pi_l3proto = IPPROTO_UDP;
413 m_sethash(m, toeplitz_hash(hash));
418 igb_get_ring_max(const struct igb_softc *sc)
421 switch (sc->hw.mac.type) {
423 return (IGB_MAX_RING_82575);
426 return (IGB_MAX_RING_82576);
429 return (IGB_MAX_RING_82580);
432 return (IGB_MAX_RING_I350);
435 return (IGB_MAX_RING_I354);
438 return (IGB_MAX_RING_I210);
441 return (IGB_MAX_RING_I211);
444 return (IGB_MIN_RING);
449 igb_get_rxring_cnt(const struct igb_softc *sc, int *ring_cnt, int *ring_max)
452 *ring_max = igb_get_ring_max(sc);
453 *ring_cnt = device_getenv_int(sc->dev, "rxr", igb_rxr);
457 igb_get_txring_cnt(const struct igb_softc *sc, int *ring_cnt, int *ring_max)
460 *ring_max = igb_get_ring_max(sc);
461 *ring_cnt = device_getenv_int(sc->dev, "txr", igb_txr);
465 igb_probe(device_t dev)
467 const struct igb_device *d;
470 vid = pci_get_vendor(dev);
471 did = pci_get_device(dev);
473 for (d = igb_devices; d->desc != NULL; ++d) {
474 if (vid == d->vid && did == d->did) {
475 device_set_desc(dev, d->desc);
483 igb_attach(device_t dev)
485 struct igb_softc *sc = device_get_softc(dev);
486 uint16_t eeprom_data;
487 int error = 0, ring_max, ring_cnt;
488 char flowctrl[IFM_ETH_FC_STRLEN];
492 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
493 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
494 OID_AUTO, "nvm", CTLTYPE_INT|CTLFLAG_RW, adapter, 0,
495 igb_sysctl_nvm_info, "I", "NVM Information");
498 ifmedia_init(&sc->media, IFM_IMASK | IFM_ETH_FCMASK,
499 igb_media_change, igb_media_status);
500 callout_init_mp(&sc->timer);
501 lwkt_serialize_init(&sc->main_serialize);
503 if_initname(&sc->arpcom.ac_if, device_get_name(dev),
504 device_get_unit(dev));
505 sc->dev = sc->osdep.dev = dev;
507 /* Enable bus mastering */
508 pci_enable_busmaster(dev);
511 * Determine hardware and mac type
513 sc->hw.vendor_id = pci_get_vendor(dev);
514 sc->hw.device_id = pci_get_device(dev);
515 sc->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1);
516 sc->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2);
517 sc->hw.subsystem_device_id = pci_read_config(dev, PCIR_SUBDEV_0, 2);
519 if (e1000_set_mac_type(&sc->hw))
522 /* Are we a VF device? */
523 if (sc->hw.mac.type == e1000_vfadapt ||
524 sc->hw.mac.type == e1000_vfadapt_i350)
530 * Configure total supported RX/TX ring count
532 igb_get_rxring_cnt(sc, &ring_cnt, &ring_max);
533 sc->rx_rmap = if_ringmap_alloc(dev, ring_cnt, ring_max);
534 igb_get_txring_cnt(sc, &ring_cnt, &ring_max);
535 sc->tx_rmap = if_ringmap_alloc(dev, ring_cnt, ring_max);
536 if_ringmap_match(dev, sc->rx_rmap, sc->tx_rmap);
538 sc->rx_ring_cnt = if_ringmap_count(sc->rx_rmap);
539 sc->rx_ring_inuse = sc->rx_ring_cnt;
540 sc->tx_ring_cnt = if_ringmap_count(sc->tx_rmap);
541 sc->tx_ring_inuse = sc->tx_ring_cnt;
543 /* Setup flow control. */
544 device_getenv_string(dev, "flow_ctrl", flowctrl, sizeof(flowctrl),
546 sc->ifm_flowctrl = ifmedia_str2ethfc(flowctrl);
551 sc->mem_rid = PCIR_BAR(0);
552 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
554 if (sc->mem_res == NULL) {
555 device_printf(dev, "Unable to allocate bus resource: memory\n");
559 sc->osdep.mem_bus_space_tag = rman_get_bustag(sc->mem_res);
560 sc->osdep.mem_bus_space_handle = rman_get_bushandle(sc->mem_res);
562 sc->hw.hw_addr = (uint8_t *)&sc->osdep.mem_bus_space_handle;
564 /* Save PCI command register for Shared Code */
565 sc->hw.bus.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
566 sc->hw.back = &sc->osdep;
568 /* Do Shared Code initialization */
569 if (e1000_setup_init_funcs(&sc->hw, TRUE)) {
570 device_printf(dev, "Setup of Shared code failed\n");
575 e1000_get_bus_info(&sc->hw);
577 sc->hw.mac.autoneg = DO_AUTO_NEG;
578 sc->hw.phy.autoneg_wait_to_complete = FALSE;
579 sc->hw.phy.autoneg_advertised = AUTONEG_ADV_DEFAULT;
582 if (sc->hw.phy.media_type == e1000_media_type_copper) {
583 sc->hw.phy.mdix = AUTO_ALL_MODES;
584 sc->hw.phy.disable_polarity_correction = FALSE;
585 sc->hw.phy.ms_type = IGB_MASTER_SLAVE;
588 /* Set the frame limits assuming standard ethernet sized frames. */
589 sc->max_frame_size = ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN;
591 /* Allocate RX/TX rings */
592 error = igb_alloc_rings(sc);
596 /* Allocate interrupt */
597 error = igb_alloc_intr(sc);
601 /* Setup serializes */
602 igb_setup_serialize(sc);
604 /* Allocate the appropriate stats memory */
606 sc->stats = kmalloc(sizeof(struct e1000_vf_stats), M_DEVBUF,
608 igb_vf_init_stats(sc);
610 sc->stats = kmalloc(sizeof(struct e1000_hw_stats), M_DEVBUF,
614 /* Allocate multicast array memory. */
615 sc->mta = kmalloc(ETHER_ADDR_LEN * MAX_NUM_MULTICAST_ADDRESSES,
618 /* Some adapter-specific advanced features */
619 if (sc->hw.mac.type >= e1000_i350) {
621 igb_set_sysctl_value(adapter, "dma_coalesce",
622 "configure dma coalesce",
623 &adapter->dma_coalesce, igb_dma_coalesce);
624 igb_set_sysctl_value(adapter, "eee_disabled",
625 "enable Energy Efficient Ethernet",
626 &adapter->hw.dev_spec._82575.eee_disable,
629 sc->dma_coalesce = igb_dma_coalesce;
630 sc->hw.dev_spec._82575.eee_disable = igb_eee_disabled;
632 if (sc->hw.phy.media_type == e1000_media_type_copper) {
633 if (sc->hw.mac.type == e1000_i354)
634 e1000_set_eee_i354(&sc->hw, TRUE, TRUE);
636 e1000_set_eee_i350(&sc->hw, TRUE, TRUE);
641 * Start from a known state, this is important in reading the nvm and
644 e1000_reset_hw(&sc->hw);
646 /* Make sure we have a good EEPROM before we read from it */
647 if (sc->hw.mac.type != e1000_i210 && sc->hw.mac.type != e1000_i211 &&
648 e1000_validate_nvm_checksum(&sc->hw) < 0) {
650 * Some PCI-E parts fail the first check due to
651 * the link being in sleep state, call it again,
652 * if it fails a second time its a real issue.
654 if (e1000_validate_nvm_checksum(&sc->hw) < 0) {
656 "The EEPROM Checksum Is Not Valid\n");
662 /* Copy the permanent MAC address out of the EEPROM */
663 if (e1000_read_mac_addr(&sc->hw) < 0) {
664 device_printf(dev, "EEPROM read error while reading MAC"
669 if (!igb_is_valid_ether_addr(sc->hw.mac.addr)) {
670 device_printf(dev, "Invalid MAC address\n");
675 /* Setup OS specific network interface */
678 /* Add sysctl tree, must after igb_setup_ifp() */
681 /* Now get a good starting state */
682 igb_reset(sc, FALSE);
684 /* Initialize statistics */
685 igb_update_stats_counters(sc);
687 sc->hw.mac.get_link_status = 1;
688 igb_update_link_status(sc);
690 /* Indicate SOL/IDER usage */
691 if (e1000_check_reset_block(&sc->hw)) {
693 "PHY reset is blocked due to SOL/IDER session.\n");
696 /* Determine if we have to control management hardware */
697 if (e1000_enable_mng_pass_thru(&sc->hw))
698 sc->flags |= IGB_FLAG_HAS_MGMT;
703 /* APME bit in EEPROM is mapped to WUC.APME */
704 eeprom_data = E1000_READ_REG(&sc->hw, E1000_WUC) & E1000_WUC_APME;
706 /* XXX E1000_WUFC_MC always be cleared from E1000_WUC. */
707 sc->wol = E1000_WUFC_MAG | E1000_WUFC_MC;
708 device_printf(dev, "has WOL\n");
712 /* Register for VLAN events */
713 adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
714 igb_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
715 adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
716 igb_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
720 igb_add_hw_stats(adapter);
724 * Disable interrupt to prevent spurious interrupts (line based
725 * interrupt, MSI or even MSI-X), which had been observed on
726 * several types of LOMs, from being handled.
728 igb_disable_intr(sc);
730 error = igb_setup_intr(sc);
732 ether_ifdetach(&sc->arpcom.ac_if);
743 igb_detach(device_t dev)
745 struct igb_softc *sc = device_get_softc(dev);
747 if (device_is_attached(dev)) {
748 struct ifnet *ifp = &sc->arpcom.ac_if;
750 ifnet_serialize_all(ifp);
754 e1000_phy_hw_reset(&sc->hw);
756 /* Give control back to firmware */
758 igb_rel_hw_control(sc);
761 igb_teardown_intr(sc, sc->intr_cnt);
763 ifnet_deserialize_all(ifp);
766 } else if (sc->mem_res != NULL) {
767 igb_rel_hw_control(sc);
770 ifmedia_removeall(&sc->media);
771 bus_generic_detach(dev);
775 if (sc->msix_mem_res != NULL) {
776 bus_release_resource(dev, SYS_RES_MEMORY, sc->msix_mem_rid,
779 if (sc->mem_res != NULL) {
780 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid,
787 kfree(sc->mta, M_DEVBUF);
788 if (sc->stats != NULL)
789 kfree(sc->stats, M_DEVBUF);
790 if (sc->serializes != NULL)
791 kfree(sc->serializes, M_DEVBUF);
792 if (sc->rx_rmap != NULL)
793 if_ringmap_free(sc->rx_rmap);
794 if (sc->rx_rmap_intr != NULL)
795 if_ringmap_free(sc->rx_rmap_intr);
796 if (sc->tx_rmap != NULL)
797 if_ringmap_free(sc->tx_rmap);
798 if (sc->tx_rmap_intr != NULL)
799 if_ringmap_free(sc->tx_rmap_intr);
805 igb_shutdown(device_t dev)
807 return igb_suspend(dev);
811 igb_suspend(device_t dev)
813 struct igb_softc *sc = device_get_softc(dev);
814 struct ifnet *ifp = &sc->arpcom.ac_if;
816 ifnet_serialize_all(ifp);
821 igb_rel_hw_control(sc);
824 ifnet_deserialize_all(ifp);
826 return bus_generic_suspend(dev);
830 igb_resume(device_t dev)
832 struct igb_softc *sc = device_get_softc(dev);
833 struct ifnet *ifp = &sc->arpcom.ac_if;
836 ifnet_serialize_all(ifp);
841 for (i = 0; i < sc->tx_ring_inuse; ++i)
842 ifsq_devstart_sched(sc->tx_rings[i].ifsq);
844 ifnet_deserialize_all(ifp);
846 return bus_generic_resume(dev);
850 igb_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
852 struct igb_softc *sc = ifp->if_softc;
853 struct ifreq *ifr = (struct ifreq *)data;
854 int max_frame_size, mask, reinit;
857 ASSERT_IFNET_SERIALIZED_ALL(ifp);
861 max_frame_size = 9234;
862 if (ifr->ifr_mtu > max_frame_size - ETHER_HDR_LEN -
868 ifp->if_mtu = ifr->ifr_mtu;
869 sc->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN +
872 if (ifp->if_flags & IFF_RUNNING)
877 if (ifp->if_flags & IFF_UP) {
878 if (ifp->if_flags & IFF_RUNNING) {
879 if ((ifp->if_flags ^ sc->if_flags) &
880 (IFF_PROMISC | IFF_ALLMULTI)) {
881 igb_disable_promisc(sc);
887 } else if (ifp->if_flags & IFF_RUNNING) {
890 sc->if_flags = ifp->if_flags;
895 if (ifp->if_flags & IFF_RUNNING) {
896 igb_disable_intr(sc);
899 if (!(ifp->if_flags & IFF_NPOLLING))
906 /* Check SOL/IDER usage */
907 if (e1000_check_reset_block(&sc->hw)) {
908 if_printf(ifp, "Media change is "
909 "blocked due to SOL/IDER session.\n");
915 error = ifmedia_ioctl(ifp, ifr, &sc->media, command);
920 mask = ifr->ifr_reqcap ^ ifp->if_capenable;
921 if (mask & IFCAP_RXCSUM) {
922 ifp->if_capenable ^= IFCAP_RXCSUM;
925 if (mask & IFCAP_VLAN_HWTAGGING) {
926 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
929 if (mask & IFCAP_TXCSUM) {
930 ifp->if_capenable ^= IFCAP_TXCSUM;
931 if (ifp->if_capenable & IFCAP_TXCSUM)
932 ifp->if_hwassist |= IGB_CSUM_FEATURES;
934 ifp->if_hwassist &= ~IGB_CSUM_FEATURES;
936 if (mask & IFCAP_TSO) {
937 ifp->if_capenable ^= IFCAP_TSO;
938 if (ifp->if_capenable & IFCAP_TSO)
939 ifp->if_hwassist |= CSUM_TSO;
941 ifp->if_hwassist &= ~CSUM_TSO;
943 if (mask & IFCAP_RSS)
944 ifp->if_capenable ^= IFCAP_RSS;
945 if (reinit && (ifp->if_flags & IFF_RUNNING))
950 error = ether_ioctl(ifp, command, data);
959 struct igb_softc *sc = xsc;
960 struct ifnet *ifp = &sc->arpcom.ac_if;
964 ASSERT_IFNET_SERIALIZED_ALL(ifp);
968 /* Get the latest mac address, User can use a LAA */
969 bcopy(IF_LLADDR(ifp), sc->hw.mac.addr, ETHER_ADDR_LEN);
971 /* Put the address into the Receive Address Array */
972 e1000_rar_set(&sc->hw, sc->hw.mac.addr, 0);
974 igb_reset(sc, FALSE);
975 igb_update_link_status(sc);
977 E1000_WRITE_REG(&sc->hw, E1000_VET, ETHERTYPE_VLAN);
979 /* Clear bad data from Rx FIFOs */
980 e1000_rx_fifo_flush_82575(&sc->hw);
982 /* Configure for OS presence */
987 if (ifp->if_flags & IFF_NPOLLING)
991 /* Configured used RX/TX rings */
992 igb_set_ring_inuse(sc, polling);
993 ifq_set_subq_divisor(&ifp->if_snd, sc->tx_ring_inuse);
995 /* Initialize interrupt */
998 /* Prepare transmit descriptors and buffers */
999 for (i = 0; i < sc->tx_ring_inuse; ++i)
1000 igb_init_tx_ring(&sc->tx_rings[i]);
1001 igb_init_tx_unit(sc);
1003 /* Setup Multicast table */
1008 * Figure out the desired mbuf pool
1009 * for doing jumbo/packetsplit
1011 if (adapter->max_frame_size <= 2048)
1012 adapter->rx_mbuf_sz = MCLBYTES;
1013 else if (adapter->max_frame_size <= 4096)
1014 adapter->rx_mbuf_sz = MJUMPAGESIZE;
1016 adapter->rx_mbuf_sz = MJUM9BYTES;
1019 /* Prepare receive descriptors and buffers */
1020 for (i = 0; i < sc->rx_ring_inuse; ++i) {
1023 error = igb_init_rx_ring(&sc->rx_rings[i]);
1025 if_printf(ifp, "Could not setup receive structures\n");
1030 igb_init_rx_unit(sc, polling);
1032 /* Enable VLAN support */
1033 if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
1036 /* Don't lose promiscuous settings */
1037 igb_set_promisc(sc);
1039 /* Clear counters */
1040 e1000_clear_hw_cntrs_base_generic(&sc->hw);
1042 /* This clears any pending interrupts */
1043 E1000_READ_REG(&sc->hw, E1000_ICR);
1046 * Only enable interrupts if we are not polling, make sure
1047 * they are off otherwise.
1050 igb_disable_intr(sc);
1052 igb_enable_intr(sc);
1053 E1000_WRITE_REG(&sc->hw, E1000_ICS, E1000_ICS_LSC);
1056 /* Set Energy Efficient Ethernet */
1057 if (sc->hw.phy.media_type == e1000_media_type_copper) {
1058 if (sc->hw.mac.type == e1000_i354)
1059 e1000_set_eee_i354(&sc->hw, TRUE, TRUE);
1061 e1000_set_eee_i350(&sc->hw, TRUE, TRUE);
1064 ifp->if_flags |= IFF_RUNNING;
1065 for (i = 0; i < sc->tx_ring_inuse; ++i) {
1066 struct igb_tx_ring *txr = &sc->tx_rings[i];
1068 ifsq_clr_oactive(txr->ifsq);
1069 ifsq_watchdog_start(&txr->tx_watchdog);
1072 callout_reset_bycpu(&txr->tx_gc_timer, 1,
1073 igb_txgc_timer, txr, txr->tx_intr_cpuid);
1077 igb_set_timer_cpuid(sc, polling);
1078 callout_reset_bycpu(&sc->timer, hz, igb_timer, sc, sc->timer_cpuid);
1082 igb_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
1084 struct igb_softc *sc = ifp->if_softc;
1086 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1088 if ((ifp->if_flags & IFF_RUNNING) == 0)
1089 sc->hw.mac.get_link_status = 1;
1090 igb_update_link_status(sc);
1092 ifmr->ifm_status = IFM_AVALID;
1093 ifmr->ifm_active = IFM_ETHER;
1095 if (!sc->link_active) {
1096 if (sc->hw.mac.autoneg)
1097 ifmr->ifm_active |= IFM_NONE;
1099 ifmr->ifm_active |= sc->media.ifm_media;
1103 ifmr->ifm_status |= IFM_ACTIVE;
1104 if (sc->ifm_flowctrl & IFM_ETH_FORCEPAUSE)
1105 ifmr->ifm_active |= sc->ifm_flowctrl;
1107 switch (sc->link_speed) {
1109 ifmr->ifm_active |= IFM_10_T;
1114 * Support for 100Mb SFP - these are Fiber
1115 * but the media type appears as serdes
1117 if (sc->hw.phy.media_type == e1000_media_type_fiber ||
1118 sc->hw.phy.media_type == e1000_media_type_internal_serdes)
1119 ifmr->ifm_active |= IFM_100_FX;
1121 ifmr->ifm_active |= IFM_100_TX;
1125 if (sc->hw.phy.media_type == e1000_media_type_fiber ||
1126 sc->hw.phy.media_type == e1000_media_type_internal_serdes)
1127 ifmr->ifm_active |= IFM_1000_SX;
1129 ifmr->ifm_active |= IFM_1000_T;
1133 ifmr->ifm_active |= IFM_2500_SX;
1137 if (sc->link_duplex == FULL_DUPLEX)
1138 ifmr->ifm_active |= IFM_FDX;
1140 ifmr->ifm_active |= IFM_HDX;
1142 if (sc->link_duplex == FULL_DUPLEX)
1143 ifmr->ifm_active |= e1000_fc2ifmedia(sc->hw.fc.current_mode);
1147 igb_media_change(struct ifnet *ifp)
1149 struct igb_softc *sc = ifp->if_softc;
1150 struct ifmedia *ifm = &sc->media;
1152 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1154 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1157 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1159 sc->hw.mac.autoneg = DO_AUTO_NEG;
1160 sc->hw.phy.autoneg_advertised = AUTONEG_ADV_DEFAULT;
1165 sc->hw.mac.autoneg = DO_AUTO_NEG;
1166 sc->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
1170 if (IFM_OPTIONS(ifm->ifm_media) & IFM_FDX) {
1171 sc->hw.mac.forced_speed_duplex = ADVERTISE_100_FULL;
1173 if (IFM_OPTIONS(ifm->ifm_media) &
1174 (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE)) {
1176 if_printf(ifp, "Flow control is not "
1177 "allowed for half-duplex\n");
1181 sc->hw.mac.forced_speed_duplex = ADVERTISE_100_HALF;
1183 sc->hw.mac.autoneg = FALSE;
1184 sc->hw.phy.autoneg_advertised = 0;
1188 if (IFM_OPTIONS(ifm->ifm_media) & IFM_FDX) {
1189 sc->hw.mac.forced_speed_duplex = ADVERTISE_10_FULL;
1191 if (IFM_OPTIONS(ifm->ifm_media) &
1192 (IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE)) {
1194 if_printf(ifp, "Flow control is not "
1195 "allowed for half-duplex\n");
1199 sc->hw.mac.forced_speed_duplex = ADVERTISE_10_HALF;
1201 sc->hw.mac.autoneg = FALSE;
1202 sc->hw.phy.autoneg_advertised = 0;
1207 if_printf(ifp, "Unsupported media type %d\n",
1208 IFM_SUBTYPE(ifm->ifm_media));
1212 sc->ifm_flowctrl = ifm->ifm_media & IFM_ETH_FCMASK;
1214 if (ifp->if_flags & IFF_RUNNING)
1221 igb_set_promisc(struct igb_softc *sc)
1223 struct ifnet *ifp = &sc->arpcom.ac_if;
1224 struct e1000_hw *hw = &sc->hw;
1228 e1000_promisc_set_vf(hw, e1000_promisc_enabled);
1232 reg = E1000_READ_REG(hw, E1000_RCTL);
1233 if (ifp->if_flags & IFF_PROMISC) {
1234 reg |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1235 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1236 } else if (ifp->if_flags & IFF_ALLMULTI) {
1237 reg |= E1000_RCTL_MPE;
1238 reg &= ~E1000_RCTL_UPE;
1239 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1244 igb_disable_promisc(struct igb_softc *sc)
1246 struct e1000_hw *hw = &sc->hw;
1247 struct ifnet *ifp = &sc->arpcom.ac_if;
1252 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
1255 reg = E1000_READ_REG(hw, E1000_RCTL);
1256 reg &= ~E1000_RCTL_UPE;
1257 if (ifp->if_flags & IFF_ALLMULTI) {
1258 mcnt = MAX_NUM_MULTICAST_ADDRESSES;
1260 struct ifmultiaddr *ifma;
1261 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1262 if (ifma->ifma_addr->sa_family != AF_LINK)
1264 if (mcnt == MAX_NUM_MULTICAST_ADDRESSES)
1269 /* Don't disable if in MAX groups */
1270 if (mcnt < MAX_NUM_MULTICAST_ADDRESSES)
1271 reg &= ~E1000_RCTL_MPE;
1272 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1276 igb_set_multi(struct igb_softc *sc)
1278 struct ifnet *ifp = &sc->arpcom.ac_if;
1279 struct ifmultiaddr *ifma;
1280 uint32_t reg_rctl = 0;
1285 bzero(mta, ETH_ADDR_LEN * MAX_NUM_MULTICAST_ADDRESSES);
1287 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1288 if (ifma->ifma_addr->sa_family != AF_LINK)
1291 if (mcnt == MAX_NUM_MULTICAST_ADDRESSES)
1294 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
1295 &mta[mcnt * ETH_ADDR_LEN], ETH_ADDR_LEN);
1299 if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES) {
1300 reg_rctl = E1000_READ_REG(&sc->hw, E1000_RCTL);
1301 reg_rctl |= E1000_RCTL_MPE;
1302 E1000_WRITE_REG(&sc->hw, E1000_RCTL, reg_rctl);
1304 e1000_update_mc_addr_list(&sc->hw, mta, mcnt);
1309 igb_timer(void *xsc)
1311 struct igb_softc *sc = xsc;
1313 lwkt_serialize_enter(&sc->main_serialize);
1315 igb_update_link_status(sc);
1316 igb_update_stats_counters(sc);
1318 callout_reset_bycpu(&sc->timer, hz, igb_timer, sc, sc->timer_cpuid);
1320 lwkt_serialize_exit(&sc->main_serialize);
1324 igb_update_link_status(struct igb_softc *sc)
1326 struct ifnet *ifp = &sc->arpcom.ac_if;
1327 struct e1000_hw *hw = &sc->hw;
1328 uint32_t link_check, thstat, ctrl;
1330 link_check = thstat = ctrl = 0;
1332 /* Get the cached link value or read for real */
1333 switch (hw->phy.media_type) {
1334 case e1000_media_type_copper:
1335 if (hw->mac.get_link_status) {
1336 /* Do the work to read phy */
1337 e1000_check_for_link(hw);
1338 link_check = !hw->mac.get_link_status;
1344 case e1000_media_type_fiber:
1345 e1000_check_for_link(hw);
1346 link_check = E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU;
1349 case e1000_media_type_internal_serdes:
1350 e1000_check_for_link(hw);
1351 link_check = hw->mac.serdes_has_link;
1354 /* VF device is type_unknown */
1355 case e1000_media_type_unknown:
1356 e1000_check_for_link(hw);
1357 link_check = !hw->mac.get_link_status;
1363 /* Check for thermal downshift or shutdown */
1364 if (hw->mac.type == e1000_i350) {
1365 thstat = E1000_READ_REG(hw, E1000_THSTAT);
1366 ctrl = E1000_READ_REG(hw, E1000_CTRL_EXT);
1369 /* Now we check if a transition has happened */
1370 if (link_check && sc->link_active == 0) {
1371 e1000_get_speed_and_duplex(hw,
1372 &sc->link_speed, &sc->link_duplex);
1374 char flowctrl[IFM_ETH_FC_STRLEN];
1376 /* Get the flow control for display */
1377 e1000_fc2str(hw->fc.current_mode, flowctrl,
1380 if_printf(ifp, "Link is up %d Mbps %s, "
1381 "Flow control: %s\n",
1383 sc->link_duplex == FULL_DUPLEX ?
1384 "Full Duplex" : "Half Duplex",
1387 if (sc->ifm_flowctrl & IFM_ETH_FORCEPAUSE)
1388 e1000_force_flowctrl(hw, sc->ifm_flowctrl);
1389 sc->link_active = 1;
1391 ifp->if_baudrate = sc->link_speed * 1000000;
1392 if ((ctrl & E1000_CTRL_EXT_LINK_MODE_GMII) &&
1393 (thstat & E1000_THSTAT_LINK_THROTTLE))
1394 if_printf(ifp, "Link: thermal downshift\n");
1395 /* Delay Link Up for Phy update */
1396 if ((hw->mac.type == e1000_i210 ||
1397 hw->mac.type == e1000_i211) &&
1398 hw->phy.id == I210_I_PHY_ID)
1399 msec_delay(IGB_I210_LINK_DELAY);
1401 * Reset if the media type changed.
1402 * Support AutoMediaDetect for Marvell M88 PHY in i354.
1404 if (hw->dev_spec._82575.media_changed) {
1405 hw->dev_spec._82575.media_changed = FALSE;
1406 igb_reset(sc, TRUE);
1408 /* This can sleep */
1409 ifp->if_link_state = LINK_STATE_UP;
1410 if_link_state_change(ifp);
1411 } else if (!link_check && sc->link_active == 1) {
1412 ifp->if_baudrate = sc->link_speed = 0;
1413 sc->link_duplex = 0;
1415 if_printf(ifp, "Link is Down\n");
1416 if ((ctrl & E1000_CTRL_EXT_LINK_MODE_GMII) &&
1417 (thstat & E1000_THSTAT_PWR_DOWN))
1418 if_printf(ifp, "Link: thermal shutdown\n");
1419 sc->link_active = 0;
1420 /* This can sleep */
1421 ifp->if_link_state = LINK_STATE_DOWN;
1422 if_link_state_change(ifp);
1427 igb_stop(struct igb_softc *sc)
1429 struct ifnet *ifp = &sc->arpcom.ac_if;
1432 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1434 igb_disable_intr(sc);
1436 callout_stop(&sc->timer);
1438 ifp->if_flags &= ~IFF_RUNNING;
1439 for (i = 0; i < sc->tx_ring_cnt; ++i) {
1440 struct igb_tx_ring *txr = &sc->tx_rings[i];
1442 ifsq_clr_oactive(txr->ifsq);
1443 ifsq_watchdog_stop(&txr->tx_watchdog);
1444 txr->tx_flags &= ~IGB_TXFLAG_ENABLED;
1446 txr->tx_running = 0;
1447 callout_stop(&txr->tx_gc_timer);
1450 e1000_reset_hw(&sc->hw);
1451 E1000_WRITE_REG(&sc->hw, E1000_WUC, 0);
1453 e1000_led_off(&sc->hw);
1454 e1000_cleanup_led(&sc->hw);
1456 for (i = 0; i < sc->tx_ring_cnt; ++i)
1457 igb_free_tx_ring(&sc->tx_rings[i]);
1458 for (i = 0; i < sc->rx_ring_cnt; ++i)
1459 igb_free_rx_ring(&sc->rx_rings[i]);
1463 igb_reset(struct igb_softc *sc, boolean_t media_reset)
1465 struct ifnet *ifp = &sc->arpcom.ac_if;
1466 struct e1000_hw *hw = &sc->hw;
1467 struct e1000_fc_info *fc = &hw->fc;
1471 /* Let the firmware know the OS is in control */
1472 igb_get_hw_control(sc);
1475 * Packet Buffer Allocation (PBA)
1476 * Writing PBA sets the receive portion of the buffer
1477 * the remainder is used for the transmit buffer.
1479 switch (hw->mac.type) {
1481 pba = E1000_PBA_32K;
1486 pba = E1000_READ_REG(hw, E1000_RXPBS);
1487 pba &= E1000_RXPBS_SIZE_MASK_82576;
1493 case e1000_vfadapt_i350:
1494 pba = E1000_READ_REG(hw, E1000_RXPBS);
1495 pba = e1000_rxpbs_adjust_82580(pba);
1500 pba = E1000_PBA_34K;
1507 /* Special needs in case of Jumbo frames */
1508 if (hw->mac.type == e1000_82575 && ifp->if_mtu > ETHERMTU) {
1509 uint32_t tx_space, min_tx, min_rx;
1511 pba = E1000_READ_REG(hw, E1000_PBA);
1512 tx_space = pba >> 16;
1515 min_tx = (sc->max_frame_size +
1516 sizeof(struct e1000_tx_desc) - ETHER_CRC_LEN) * 2;
1517 min_tx = roundup2(min_tx, 1024);
1519 min_rx = sc->max_frame_size;
1520 min_rx = roundup2(min_rx, 1024);
1522 if (tx_space < min_tx && (min_tx - tx_space) < pba) {
1523 pba = pba - (min_tx - tx_space);
1525 * if short on rx space, rx wins
1526 * and must trump tx adjustment
1531 E1000_WRITE_REG(hw, E1000_PBA, pba);
1535 * These parameters control the automatic generation (Tx) and
1536 * response (Rx) to Ethernet PAUSE frames.
1537 * - High water mark should allow for at least two frames to be
1538 * received after sending an XOFF.
1539 * - Low water mark works best when it is very near the high water mark.
1540 * This allows the receiver to restart by sending XON when it has
1543 hwm = min(((pba << 10) * 9 / 10),
1544 ((pba << 10) - 2 * sc->max_frame_size));
1546 if (hw->mac.type < e1000_82576) {
1547 fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
1548 fc->low_water = fc->high_water - 8;
1550 fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
1551 fc->low_water = fc->high_water - 16;
1553 fc->pause_time = IGB_FC_PAUSE_TIME;
1554 fc->send_xon = TRUE;
1555 fc->requested_mode = e1000_ifmedia2fc(sc->ifm_flowctrl);
1557 /* Issue a global reset */
1559 E1000_WRITE_REG(hw, E1000_WUC, 0);
1561 /* Reset for AutoMediaDetect */
1563 e1000_setup_init_funcs(hw, TRUE);
1564 e1000_get_bus_info(hw);
1567 if (e1000_init_hw(hw) < 0)
1568 if_printf(ifp, "Hardware Initialization Failed\n");
1570 /* Setup DMA Coalescing */
1571 igb_init_dmac(sc, pba);
1573 E1000_WRITE_REG(&sc->hw, E1000_VET, ETHERTYPE_VLAN);
1574 e1000_get_phy_info(hw);
1575 e1000_check_for_link(hw);
1579 igb_setup_ifp(struct igb_softc *sc)
1581 struct ifnet *ifp = &sc->arpcom.ac_if;
1585 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1586 ifp->if_init = igb_init;
1587 ifp->if_ioctl = igb_ioctl;
1588 ifp->if_start = igb_start;
1589 ifp->if_serialize = igb_serialize;
1590 ifp->if_deserialize = igb_deserialize;
1591 ifp->if_tryserialize = igb_tryserialize;
1593 ifp->if_serialize_assert = igb_serialize_assert;
1595 #ifdef IFPOLL_ENABLE
1596 ifp->if_npoll = igb_npoll;
1599 ifp->if_nmbclusters = sc->rx_ring_cnt * sc->rx_rings[0].num_rx_desc;
1601 ifq_set_maxlen(&ifp->if_snd, sc->tx_rings[0].num_tx_desc - 1);
1602 ifq_set_ready(&ifp->if_snd);
1603 ifq_set_subq_cnt(&ifp->if_snd, sc->tx_ring_cnt);
1605 ifp->if_mapsubq = ifq_mapsubq_modulo;
1606 ifq_set_subq_divisor(&ifp->if_snd, 1);
1608 ether_ifattach(ifp, sc->hw.mac.addr, NULL);
1610 ifp->if_capabilities =
1611 IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU | IFCAP_TSO;
1612 if (IGB_ENABLE_HWRSS(sc))
1613 ifp->if_capabilities |= IFCAP_RSS;
1614 ifp->if_capenable = ifp->if_capabilities;
1615 ifp->if_hwassist = IGB_CSUM_FEATURES | CSUM_TSO;
1618 * Tell the upper layer(s) we support long frames
1620 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
1622 /* Setup TX rings and subqueues */
1623 for (i = 0; i < sc->tx_ring_cnt; ++i) {
1624 struct ifaltq_subque *ifsq = ifq_get_subq(&ifp->if_snd, i);
1625 struct igb_tx_ring *txr = &sc->tx_rings[i];
1627 ifsq_set_cpuid(ifsq, txr->tx_intr_cpuid);
1628 ifsq_set_priv(ifsq, txr);
1629 ifsq_set_hw_serialize(ifsq, &txr->tx_serialize);
1632 ifsq_watchdog_init(&txr->tx_watchdog, ifsq, igb_watchdog, 0);
1636 * Specify the media types supported by this adapter and register
1637 * callbacks to update media and link information
1639 if (sc->hw.phy.media_type == e1000_media_type_fiber ||
1640 sc->hw.phy.media_type == e1000_media_type_internal_serdes) {
1641 ifmedia_add(&sc->media, IFM_ETHER | IFM_1000_SX | IFM_FDX,
1644 ifmedia_add(&sc->media, IFM_ETHER | IFM_10_T, 0, NULL);
1645 ifmedia_add(&sc->media, IFM_ETHER | IFM_10_T | IFM_FDX,
1647 ifmedia_add(&sc->media, IFM_ETHER | IFM_100_TX, 0, NULL);
1648 ifmedia_add(&sc->media, IFM_ETHER | IFM_100_TX | IFM_FDX,
1650 if (sc->hw.phy.type != e1000_phy_ife) {
1651 ifmedia_add(&sc->media,
1652 IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
1655 ifmedia_add(&sc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
1656 ifmedia_set(&sc->media, IFM_ETHER | IFM_AUTO | sc->ifm_flowctrl);
1660 igb_add_sysctl(struct igb_softc *sc)
1662 struct sysctl_ctx_list *ctx;
1663 struct sysctl_oid *tree;
1667 ctx = device_get_sysctl_ctx(sc->dev);
1668 tree = device_get_sysctl_tree(sc->dev);
1669 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree),
1670 OID_AUTO, "rxr", CTLFLAG_RD, &sc->rx_ring_cnt, 0, "# of RX rings");
1671 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree),
1672 OID_AUTO, "rxr_inuse", CTLFLAG_RD, &sc->rx_ring_inuse, 0,
1673 "# of RX rings used");
1674 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree),
1675 OID_AUTO, "txr", CTLFLAG_RD, &sc->tx_ring_cnt, 0, "# of TX rings");
1676 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree),
1677 OID_AUTO, "txr_inuse", CTLFLAG_RD, &sc->tx_ring_inuse, 0,
1678 "# of TX rings used");
1679 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree),
1680 OID_AUTO, "rxd", CTLFLAG_RD, &sc->rx_rings[0].num_rx_desc, 0,
1682 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree),
1683 OID_AUTO, "txd", CTLFLAG_RD, &sc->tx_rings[0].num_tx_desc, 0,
1686 #define IGB_ADD_INTR_RATE_SYSCTL(sc, use, name) \
1688 igb_add_intr_rate_sysctl(sc, IGB_INTR_USE_##use, #name "_intr_rate", \
1689 #use " interrupt rate"); \
1692 IGB_ADD_INTR_RATE_SYSCTL(sc, RXTX, rxtx);
1693 IGB_ADD_INTR_RATE_SYSCTL(sc, RX, rx);
1694 IGB_ADD_INTR_RATE_SYSCTL(sc, TX, tx);
1695 IGB_ADD_INTR_RATE_SYSCTL(sc, STATUS, sts);
1697 #undef IGB_ADD_INTR_RATE_SYSCTL
1699 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1700 OID_AUTO, "tx_intr_nsegs", CTLTYPE_INT | CTLFLAG_RW,
1701 sc, 0, igb_sysctl_tx_intr_nsegs, "I",
1702 "# of segments per TX interrupt");
1704 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1705 OID_AUTO, "tx_wreg_nsegs", CTLTYPE_INT | CTLFLAG_RW,
1706 sc, 0, igb_sysctl_tx_wreg_nsegs, "I",
1707 "# of segments sent before write to hardware register");
1709 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1710 OID_AUTO, "rx_wreg_nsegs", CTLTYPE_INT | CTLFLAG_RW,
1711 sc, 0, igb_sysctl_rx_wreg_nsegs, "I",
1712 "# of segments received before write to hardware register");
1714 if (sc->intr_type == PCI_INTR_TYPE_MSIX) {
1715 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1716 OID_AUTO, "tx_msix_cpumap", CTLTYPE_OPAQUE | CTLFLAG_RD,
1717 sc->tx_rmap_intr, 0, if_ringmap_cpumap_sysctl, "I",
1718 "TX MSI-X CPU map");
1719 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1720 OID_AUTO, "rx_msix_cpumap", CTLTYPE_OPAQUE | CTLFLAG_RD,
1721 sc->rx_rmap_intr, 0, if_ringmap_cpumap_sysctl, "I",
1722 "RX MSI-X CPU map");
1724 #ifdef IFPOLL_ENABLE
1725 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1726 OID_AUTO, "tx_poll_cpumap", CTLTYPE_OPAQUE | CTLFLAG_RD,
1727 sc->tx_rmap, 0, if_ringmap_cpumap_sysctl, "I",
1728 "TX polling CPU map");
1729 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1730 OID_AUTO, "rx_poll_cpumap", CTLTYPE_OPAQUE | CTLFLAG_RD,
1731 sc->rx_rmap, 0, if_ringmap_cpumap_sysctl, "I",
1732 "RX polling CPU map");
1735 #ifdef IGB_RSS_DEBUG
1736 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree),
1737 OID_AUTO, "rss_debug", CTLFLAG_RW, &sc->rss_debug, 0,
1739 for (i = 0; i < sc->rx_ring_cnt; ++i) {
1740 ksnprintf(node, sizeof(node), "rx%d_pkt", i);
1741 SYSCTL_ADD_ULONG(ctx,
1742 SYSCTL_CHILDREN(tree), OID_AUTO, node,
1743 CTLFLAG_RW, &sc->rx_rings[i].rx_packets, "RXed packets");
1746 for (i = 0; i < sc->tx_ring_cnt; ++i) {
1747 struct igb_tx_ring *txr = &sc->tx_rings[i];
1749 #ifdef IGB_TSS_DEBUG
1750 ksnprintf(node, sizeof(node), "tx%d_pkt", i);
1751 SYSCTL_ADD_ULONG(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, node,
1752 CTLFLAG_RW, &txr->tx_packets, "TXed packets");
1754 ksnprintf(node, sizeof(node), "tx%d_nmbuf", i);
1755 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, node,
1756 CTLFLAG_RD, &txr->tx_nmbuf, 0, "# of pending TX mbufs");
1758 ksnprintf(node, sizeof(node), "tx%d_gc", i);
1759 SYSCTL_ADD_ULONG(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, node,
1760 CTLFLAG_RW, &txr->tx_gc, "# of TX desc GC");
1763 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree),
1764 OID_AUTO, "dumpreg", CTLTYPE_INT | CTLFLAG_RW,
1765 sc, 0, igb_sysctl_reg_dump, "I", "dump registers");
1769 igb_alloc_rings(struct igb_softc *sc)
1774 * Create top level busdma tag
1776 error = bus_dma_tag_create(NULL, 1, 0,
1777 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL,
1778 BUS_SPACE_MAXSIZE_32BIT, 0, BUS_SPACE_MAXSIZE_32BIT, 0,
1781 device_printf(sc->dev, "could not create top level DMA tag\n");
1786 * Allocate TX descriptor rings and buffers
1788 sc->tx_rings = kmalloc(sizeof(struct igb_tx_ring) * sc->tx_ring_cnt,
1790 M_WAITOK | M_ZERO | M_CACHEALIGN);
1791 for (i = 0; i < sc->tx_ring_cnt; ++i) {
1792 struct igb_tx_ring *txr = &sc->tx_rings[i];
1794 /* Set up some basics */
1797 txr->tx_intr_cpuid = -1;
1798 lwkt_serialize_init(&txr->tx_serialize);
1799 callout_init_mp(&txr->tx_gc_timer);
1801 error = igb_create_tx_ring(txr);
1807 * Allocate RX descriptor rings and buffers
1809 sc->rx_rings = kmalloc(sizeof(struct igb_rx_ring) * sc->rx_ring_cnt,
1811 M_WAITOK | M_ZERO | M_CACHEALIGN);
1812 for (i = 0; i < sc->rx_ring_cnt; ++i) {
1813 struct igb_rx_ring *rxr = &sc->rx_rings[i];
1815 /* Set up some basics */
1818 lwkt_serialize_init(&rxr->rx_serialize);
1820 error = igb_create_rx_ring(rxr);
1829 igb_free_rings(struct igb_softc *sc)
1833 if (sc->tx_rings != NULL) {
1834 for (i = 0; i < sc->tx_ring_cnt; ++i) {
1835 struct igb_tx_ring *txr = &sc->tx_rings[i];
1837 igb_destroy_tx_ring(txr, txr->num_tx_desc);
1839 kfree(sc->tx_rings, M_DEVBUF);
1842 if (sc->rx_rings != NULL) {
1843 for (i = 0; i < sc->rx_ring_cnt; ++i) {
1844 struct igb_rx_ring *rxr = &sc->rx_rings[i];
1846 igb_destroy_rx_ring(rxr, rxr->num_rx_desc);
1848 kfree(sc->rx_rings, M_DEVBUF);
1853 igb_create_tx_ring(struct igb_tx_ring *txr)
1855 int tsize, error, i, ntxd;
1858 * Validate number of transmit descriptors. It must not exceed
1859 * hardware maximum, and must be multiple of IGB_DBA_ALIGN.
1861 ntxd = device_getenv_int(txr->sc->dev, "txd", igb_txd);
1862 if ((ntxd * sizeof(struct e1000_tx_desc)) % IGB_DBA_ALIGN != 0 ||
1863 ntxd > IGB_MAX_TXD || ntxd < IGB_MIN_TXD) {
1864 device_printf(txr->sc->dev,
1865 "Using %d TX descriptors instead of %d!\n",
1866 IGB_DEFAULT_TXD, ntxd);
1867 txr->num_tx_desc = IGB_DEFAULT_TXD;
1869 txr->num_tx_desc = ntxd;
1873 * Allocate TX descriptor ring
1875 tsize = roundup2(txr->num_tx_desc * sizeof(union e1000_adv_tx_desc),
1877 txr->txdma.dma_vaddr = bus_dmamem_coherent_any(txr->sc->parent_tag,
1878 IGB_DBA_ALIGN, tsize, BUS_DMA_WAITOK,
1879 &txr->txdma.dma_tag, &txr->txdma.dma_map, &txr->txdma.dma_paddr);
1880 if (txr->txdma.dma_vaddr == NULL) {
1881 device_printf(txr->sc->dev,
1882 "Unable to allocate TX Descriptor memory\n");
1885 txr->tx_base = txr->txdma.dma_vaddr;
1886 bzero(txr->tx_base, tsize);
1888 tsize = __VM_CACHELINE_ALIGN(
1889 sizeof(struct igb_tx_buf) * txr->num_tx_desc);
1890 txr->tx_buf = kmalloc(tsize, M_DEVBUF,
1891 M_WAITOK | M_ZERO | M_CACHEALIGN);
1894 * Allocate TX head write-back buffer
1896 txr->tx_hdr = bus_dmamem_coherent_any(txr->sc->parent_tag,
1897 __VM_CACHELINE_SIZE, __VM_CACHELINE_SIZE, BUS_DMA_WAITOK,
1898 &txr->tx_hdr_dtag, &txr->tx_hdr_dmap, &txr->tx_hdr_paddr);
1899 if (txr->tx_hdr == NULL) {
1900 device_printf(txr->sc->dev,
1901 "Unable to allocate TX head write-back buffer\n");
1906 * Create DMA tag for TX buffers
1908 error = bus_dma_tag_create(txr->sc->parent_tag,
1909 1, 0, /* alignment, bounds */
1910 BUS_SPACE_MAXADDR, /* lowaddr */
1911 BUS_SPACE_MAXADDR, /* highaddr */
1912 NULL, NULL, /* filter, filterarg */
1913 IGB_TSO_SIZE, /* maxsize */
1914 IGB_MAX_SCATTER, /* nsegments */
1915 PAGE_SIZE, /* maxsegsize */
1916 BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW |
1917 BUS_DMA_ONEBPAGE, /* flags */
1920 device_printf(txr->sc->dev, "Unable to allocate TX DMA tag\n");
1921 kfree(txr->tx_buf, M_DEVBUF);
1927 * Create DMA maps for TX buffers
1929 for (i = 0; i < txr->num_tx_desc; ++i) {
1930 struct igb_tx_buf *txbuf = &txr->tx_buf[i];
1932 error = bus_dmamap_create(txr->tx_tag,
1933 BUS_DMA_WAITOK | BUS_DMA_ONEBPAGE, &txbuf->map);
1935 device_printf(txr->sc->dev,
1936 "Unable to create TX DMA map\n");
1937 igb_destroy_tx_ring(txr, i);
1942 if (txr->sc->hw.mac.type == e1000_82575)
1943 txr->tx_flags |= IGB_TXFLAG_TSO_IPLEN0;
1946 * Initialize various watermark
1948 if (txr->sc->hw.mac.type == e1000_82575) {
1950 * There no ways to GC pending TX mbufs in 'header
1951 * write back' mode with reduced # of RS TX descs,
1952 * since TDH does _not_ move for 82575.
1954 txr->intr_nsegs = 1;
1956 txr->intr_nsegs = txr->num_tx_desc / 16;
1958 txr->wreg_nsegs = IGB_DEF_TXWREG_NSEGS;
1964 igb_free_tx_ring(struct igb_tx_ring *txr)
1968 for (i = 0; i < txr->num_tx_desc; ++i) {
1969 struct igb_tx_buf *txbuf = &txr->tx_buf[i];
1971 if (txbuf->m_head != NULL)
1972 igb_free_txbuf(txr, txbuf);
1977 igb_destroy_tx_ring(struct igb_tx_ring *txr, int ndesc)
1981 if (txr->txdma.dma_vaddr != NULL) {
1982 bus_dmamap_unload(txr->txdma.dma_tag, txr->txdma.dma_map);
1983 bus_dmamem_free(txr->txdma.dma_tag, txr->txdma.dma_vaddr,
1984 txr->txdma.dma_map);
1985 bus_dma_tag_destroy(txr->txdma.dma_tag);
1986 txr->txdma.dma_vaddr = NULL;
1989 if (txr->tx_hdr != NULL) {
1990 bus_dmamap_unload(txr->tx_hdr_dtag, txr->tx_hdr_dmap);
1991 bus_dmamem_free(txr->tx_hdr_dtag, txr->tx_hdr,
1993 bus_dma_tag_destroy(txr->tx_hdr_dtag);
1997 if (txr->tx_buf == NULL)
2000 for (i = 0; i < ndesc; ++i) {
2001 struct igb_tx_buf *txbuf = &txr->tx_buf[i];
2003 KKASSERT(txbuf->m_head == NULL);
2004 bus_dmamap_destroy(txr->tx_tag, txbuf->map);
2006 bus_dma_tag_destroy(txr->tx_tag);
2008 kfree(txr->tx_buf, M_DEVBUF);
2013 igb_init_tx_ring(struct igb_tx_ring *txr)
2015 /* Clear the old descriptor contents */
2017 sizeof(union e1000_adv_tx_desc) * txr->num_tx_desc);
2019 /* Clear TX head write-back buffer */
2023 txr->next_avail_desc = 0;
2024 txr->next_to_clean = 0;
2026 txr->tx_running = 0;
2029 /* Set number of descriptors available */
2030 txr->tx_avail = txr->num_tx_desc;
2032 /* Enable this TX ring */
2033 txr->tx_flags |= IGB_TXFLAG_ENABLED;
2037 igb_init_tx_unit(struct igb_softc *sc)
2039 struct e1000_hw *hw = &sc->hw;
2043 /* Setup the Tx Descriptor Rings */
2044 for (i = 0; i < sc->tx_ring_inuse; ++i) {
2045 struct igb_tx_ring *txr = &sc->tx_rings[i];
2046 uint64_t bus_addr = txr->txdma.dma_paddr;
2047 uint64_t hdr_paddr = txr->tx_hdr_paddr;
2048 uint32_t txdctl = 0;
2049 uint32_t dca_txctrl;
2051 E1000_WRITE_REG(hw, E1000_TDLEN(i),
2052 txr->num_tx_desc * sizeof(struct e1000_tx_desc));
2053 E1000_WRITE_REG(hw, E1000_TDBAH(i),
2054 (uint32_t)(bus_addr >> 32));
2055 E1000_WRITE_REG(hw, E1000_TDBAL(i),
2056 (uint32_t)bus_addr);
2058 /* Setup the HW Tx Head and Tail descriptor pointers */
2059 E1000_WRITE_REG(hw, E1000_TDT(i), 0);
2060 E1000_WRITE_REG(hw, E1000_TDH(i), 0);
2062 dca_txctrl = E1000_READ_REG(hw, E1000_DCA_TXCTRL(i));
2063 dca_txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
2064 E1000_WRITE_REG(hw, E1000_DCA_TXCTRL(i), dca_txctrl);
2067 * Don't set WB_on_EITR:
2068 * - 82575 does not have it
2069 * - It almost has no effect on 82576, see:
2070 * 82576 specification update errata #26
2071 * - It causes unnecessary bus traffic
2073 E1000_WRITE_REG(hw, E1000_TDWBAH(i),
2074 (uint32_t)(hdr_paddr >> 32));
2075 E1000_WRITE_REG(hw, E1000_TDWBAL(i),
2076 ((uint32_t)hdr_paddr) | E1000_TX_HEAD_WB_ENABLE);
2079 * WTHRESH is ignored by the hardware, since header
2080 * write back mode is used.
2082 txdctl |= IGB_TX_PTHRESH;
2083 txdctl |= IGB_TX_HTHRESH << 8;
2084 txdctl |= IGB_TX_WTHRESH << 16;
2085 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2086 E1000_WRITE_REG(hw, E1000_TXDCTL(i), txdctl);
2092 e1000_config_collision_dist(hw);
2094 /* Program the Transmit Control Register */
2095 tctl = E1000_READ_REG(hw, E1000_TCTL);
2096 tctl &= ~E1000_TCTL_CT;
2097 tctl |= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN |
2098 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT));
2100 /* This write will effectively turn on the transmit unit. */
2101 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2105 igb_txcsum_ctx(struct igb_tx_ring *txr, struct mbuf *mp)
2107 struct e1000_adv_tx_context_desc *TXD;
2108 uint32_t vlan_macip_lens, type_tucmd_mlhl, mss_l4len_idx;
2109 int ehdrlen, ctxd, ip_hlen = 0;
2110 boolean_t offload = TRUE;
2112 if ((mp->m_pkthdr.csum_flags & IGB_CSUM_FEATURES) == 0)
2115 vlan_macip_lens = type_tucmd_mlhl = mss_l4len_idx = 0;
2117 ctxd = txr->next_avail_desc;
2118 TXD = (struct e1000_adv_tx_context_desc *)&txr->tx_base[ctxd];
2121 * In advanced descriptors the vlan tag must
2122 * be placed into the context descriptor, thus
2123 * we need to be here just for that setup.
2125 if (mp->m_flags & M_VLANTAG) {
2128 vlantag = htole16(mp->m_pkthdr.ether_vlantag);
2129 vlan_macip_lens |= (vlantag << E1000_ADVTXD_VLAN_SHIFT);
2130 } else if (!offload) {
2134 ehdrlen = mp->m_pkthdr.csum_lhlen;
2135 KASSERT(ehdrlen > 0, ("invalid ether hlen"));
2137 /* Set the ether header length */
2138 vlan_macip_lens |= ehdrlen << E1000_ADVTXD_MACLEN_SHIFT;
2139 if (mp->m_pkthdr.csum_flags & CSUM_IP) {
2140 type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV4;
2141 ip_hlen = mp->m_pkthdr.csum_iphlen;
2142 KASSERT(ip_hlen > 0, ("invalid ip hlen"));
2144 vlan_macip_lens |= ip_hlen;
2146 type_tucmd_mlhl |= E1000_ADVTXD_DCMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
2147 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
2148 type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP;
2149 else if (mp->m_pkthdr.csum_flags & CSUM_UDP)
2150 type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP;
2153 * 82575 needs the TX context index added; the queue
2154 * index is used as TX context index here.
2156 if (txr->sc->hw.mac.type == e1000_82575)
2157 mss_l4len_idx = txr->me << 4;
2159 /* Now copy bits into descriptor */
2160 TXD->vlan_macip_lens = htole32(vlan_macip_lens);
2161 TXD->type_tucmd_mlhl = htole32(type_tucmd_mlhl);
2162 TXD->seqnum_seed = htole32(0);
2163 TXD->mss_l4len_idx = htole32(mss_l4len_idx);
2165 /* We've consumed the first desc, adjust counters */
2166 if (++ctxd == txr->num_tx_desc)
2168 txr->next_avail_desc = ctxd;
2175 igb_txeof(struct igb_tx_ring *txr, int hdr)
2179 if (txr->tx_avail == txr->num_tx_desc)
2182 first = txr->next_to_clean;
2186 avail = txr->tx_avail;
2187 while (first != hdr) {
2188 struct igb_tx_buf *txbuf = &txr->tx_buf[first];
2190 KKASSERT(avail < txr->num_tx_desc);
2194 igb_free_txbuf(txr, txbuf);
2196 if (++first == txr->num_tx_desc)
2199 txr->next_to_clean = first;
2200 txr->tx_avail = avail;
2203 * If we have a minimum free, clear OACTIVE
2204 * to tell the stack that it is OK to send packets.
2206 if (txr->tx_avail > IGB_MAX_SCATTER + IGB_TX_RESERVED) {
2207 ifsq_clr_oactive(txr->ifsq);
2210 * We have enough TX descriptors, turn off
2211 * the watchdog. We allow small amount of
2212 * packets (roughly intr_nsegs) pending on
2213 * the transmit ring.
2215 ifsq_watchdog_set_count(&txr->tx_watchdog, 0);
2217 txr->tx_running = IGB_TX_RUNNING;
2221 igb_txgc(struct igb_tx_ring *txr)
2228 if (txr->tx_avail == txr->num_tx_desc)
2231 hdr = E1000_READ_REG(&txr->sc->hw, E1000_TDH(txr->me)),
2232 first = txr->next_to_clean;
2238 avail = txr->tx_avail;
2240 while (first != hdr) {
2241 struct igb_tx_buf *txbuf = &txr->tx_buf[first];
2244 KKASSERT(avail < txr->num_tx_desc);
2248 igb_free_txbuf(txr, txbuf);
2250 if (++first == txr->num_tx_desc)
2255 txr->tx_running = IGB_TX_RUNNING;
2259 igb_create_rx_ring(struct igb_rx_ring *rxr)
2261 int rsize, i, error, nrxd;
2264 * Validate number of receive descriptors. It must not exceed
2265 * hardware maximum, and must be multiple of IGB_DBA_ALIGN.
2267 nrxd = device_getenv_int(rxr->sc->dev, "rxd", igb_rxd);
2268 if ((nrxd * sizeof(struct e1000_rx_desc)) % IGB_DBA_ALIGN != 0 ||
2269 nrxd > IGB_MAX_RXD || nrxd < IGB_MIN_RXD) {
2270 device_printf(rxr->sc->dev,
2271 "Using %d RX descriptors instead of %d!\n",
2272 IGB_DEFAULT_RXD, nrxd);
2273 rxr->num_rx_desc = IGB_DEFAULT_RXD;
2275 rxr->num_rx_desc = nrxd;
2279 * Allocate RX descriptor ring
2281 rsize = roundup2(rxr->num_rx_desc * sizeof(union e1000_adv_rx_desc),
2283 rxr->rxdma.dma_vaddr = bus_dmamem_coherent_any(rxr->sc->parent_tag,
2284 IGB_DBA_ALIGN, rsize, BUS_DMA_WAITOK,
2285 &rxr->rxdma.dma_tag, &rxr->rxdma.dma_map,
2286 &rxr->rxdma.dma_paddr);
2287 if (rxr->rxdma.dma_vaddr == NULL) {
2288 device_printf(rxr->sc->dev,
2289 "Unable to allocate RxDescriptor memory\n");
2292 rxr->rx_base = rxr->rxdma.dma_vaddr;
2293 bzero(rxr->rx_base, rsize);
2295 rsize = __VM_CACHELINE_ALIGN(
2296 sizeof(struct igb_rx_buf) * rxr->num_rx_desc);
2297 rxr->rx_buf = kmalloc(rsize, M_DEVBUF,
2298 M_WAITOK | M_ZERO | M_CACHEALIGN);
2301 * Create DMA tag for RX buffers
2303 error = bus_dma_tag_create(rxr->sc->parent_tag,
2304 1, 0, /* alignment, bounds */
2305 BUS_SPACE_MAXADDR, /* lowaddr */
2306 BUS_SPACE_MAXADDR, /* highaddr */
2307 NULL, NULL, /* filter, filterarg */
2308 MCLBYTES, /* maxsize */
2310 MCLBYTES, /* maxsegsize */
2311 BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW, /* flags */
2314 device_printf(rxr->sc->dev,
2315 "Unable to create RX payload DMA tag\n");
2316 kfree(rxr->rx_buf, M_DEVBUF);
2322 * Create spare DMA map for RX buffers
2324 error = bus_dmamap_create(rxr->rx_tag, BUS_DMA_WAITOK,
2327 device_printf(rxr->sc->dev,
2328 "Unable to create spare RX DMA maps\n");
2329 bus_dma_tag_destroy(rxr->rx_tag);
2330 kfree(rxr->rx_buf, M_DEVBUF);
2336 * Create DMA maps for RX buffers
2338 for (i = 0; i < rxr->num_rx_desc; i++) {
2339 struct igb_rx_buf *rxbuf = &rxr->rx_buf[i];
2341 error = bus_dmamap_create(rxr->rx_tag,
2342 BUS_DMA_WAITOK, &rxbuf->map);
2344 device_printf(rxr->sc->dev,
2345 "Unable to create RX DMA maps\n");
2346 igb_destroy_rx_ring(rxr, i);
2352 * Initialize various watermark
2354 rxr->wreg_nsegs = IGB_DEF_RXWREG_NSEGS;
2360 igb_free_rx_ring(struct igb_rx_ring *rxr)
2364 for (i = 0; i < rxr->num_rx_desc; ++i) {
2365 struct igb_rx_buf *rxbuf = &rxr->rx_buf[i];
2367 if (rxbuf->m_head != NULL) {
2368 bus_dmamap_unload(rxr->rx_tag, rxbuf->map);
2369 m_freem(rxbuf->m_head);
2370 rxbuf->m_head = NULL;
2374 if (rxr->fmp != NULL)
2381 igb_destroy_rx_ring(struct igb_rx_ring *rxr, int ndesc)
2385 if (rxr->rxdma.dma_vaddr != NULL) {
2386 bus_dmamap_unload(rxr->rxdma.dma_tag, rxr->rxdma.dma_map);
2387 bus_dmamem_free(rxr->rxdma.dma_tag, rxr->rxdma.dma_vaddr,
2388 rxr->rxdma.dma_map);
2389 bus_dma_tag_destroy(rxr->rxdma.dma_tag);
2390 rxr->rxdma.dma_vaddr = NULL;
2393 if (rxr->rx_buf == NULL)
2396 for (i = 0; i < ndesc; ++i) {
2397 struct igb_rx_buf *rxbuf = &rxr->rx_buf[i];
2399 KKASSERT(rxbuf->m_head == NULL);
2400 bus_dmamap_destroy(rxr->rx_tag, rxbuf->map);
2402 bus_dmamap_destroy(rxr->rx_tag, rxr->rx_sparemap);
2403 bus_dma_tag_destroy(rxr->rx_tag);
2405 kfree(rxr->rx_buf, M_DEVBUF);
2410 igb_setup_rxdesc(union e1000_adv_rx_desc *rxd, const struct igb_rx_buf *rxbuf)
2412 rxd->read.pkt_addr = htole64(rxbuf->paddr);
2413 rxd->wb.upper.status_error = 0;
2417 igb_newbuf(struct igb_rx_ring *rxr, int i, boolean_t wait)
2420 bus_dma_segment_t seg;
2422 struct igb_rx_buf *rxbuf;
2425 m = m_getcl(wait ? M_WAITOK : M_NOWAIT, MT_DATA, M_PKTHDR);
2428 if_printf(&rxr->sc->arpcom.ac_if,
2429 "Unable to allocate RX mbuf\n");
2433 m->m_len = m->m_pkthdr.len = MCLBYTES;
2435 if (rxr->sc->max_frame_size <= MCLBYTES - ETHER_ALIGN)
2436 m_adj(m, ETHER_ALIGN);
2438 error = bus_dmamap_load_mbuf_segment(rxr->rx_tag,
2439 rxr->rx_sparemap, m, &seg, 1, &nseg, BUS_DMA_NOWAIT);
2443 if_printf(&rxr->sc->arpcom.ac_if,
2444 "Unable to load RX mbuf\n");
2449 rxbuf = &rxr->rx_buf[i];
2450 if (rxbuf->m_head != NULL)
2451 bus_dmamap_unload(rxr->rx_tag, rxbuf->map);
2454 rxbuf->map = rxr->rx_sparemap;
2455 rxr->rx_sparemap = map;
2458 rxbuf->paddr = seg.ds_addr;
2460 igb_setup_rxdesc(&rxr->rx_base[i], rxbuf);
2465 igb_init_rx_ring(struct igb_rx_ring *rxr)
2469 /* Clear the ring contents */
2471 rxr->num_rx_desc * sizeof(union e1000_adv_rx_desc));
2473 /* Now replenish the ring mbufs */
2474 for (i = 0; i < rxr->num_rx_desc; ++i) {
2477 error = igb_newbuf(rxr, i, TRUE);
2482 /* Setup our descriptor indices */
2483 rxr->next_to_check = 0;
2487 rxr->discard = FALSE;
2493 igb_init_rx_unit(struct igb_softc *sc, boolean_t polling)
2495 struct ifnet *ifp = &sc->arpcom.ac_if;
2496 struct e1000_hw *hw = &sc->hw;
2497 uint32_t rctl, rxcsum, srrctl = 0;
2501 * Make sure receives are disabled while setting
2502 * up the descriptor ring
2504 rctl = E1000_READ_REG(hw, E1000_RCTL);
2505 E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
2509 ** Set up for header split
2511 if (igb_header_split) {
2512 /* Use a standard mbuf for the header */
2513 srrctl |= IGB_HDR_BUF << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
2514 srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
2517 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
2520 ** Set up for jumbo frames
2522 if (ifp->if_mtu > ETHERMTU) {
2523 rctl |= E1000_RCTL_LPE;
2525 if (adapter->rx_mbuf_sz == MJUMPAGESIZE) {
2526 srrctl |= 4096 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
2527 rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX;
2528 } else if (adapter->rx_mbuf_sz > MJUMPAGESIZE) {
2529 srrctl |= 8192 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
2530 rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX;
2532 /* Set maximum packet len */
2533 psize = adapter->max_frame_size;
2534 /* are we on a vlan? */
2535 if (adapter->ifp->if_vlantrunk != NULL)
2536 psize += VLAN_TAG_SIZE;
2537 E1000_WRITE_REG(&adapter->hw, E1000_RLPML, psize);
2539 srrctl |= 2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
2540 rctl |= E1000_RCTL_SZ_2048;
2543 rctl &= ~E1000_RCTL_LPE;
2544 srrctl |= 2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
2545 rctl |= E1000_RCTL_SZ_2048;
2549 * If TX flow control is disabled and more the 1 RX rings
2550 * are enabled, enable DROP.
2552 * This drops frames rather than hanging the RX MAC for all
2555 if (sc->rx_ring_inuse > 1 &&
2556 (sc->ifm_flowctrl & IFM_ETH_TXPAUSE) == 0) {
2557 srrctl |= E1000_SRRCTL_DROP_EN;
2559 if_printf(ifp, "enable RX drop\n");
2562 /* Setup the Base and Length of the Rx Descriptor Rings */
2563 for (i = 0; i < sc->rx_ring_inuse; ++i) {
2564 struct igb_rx_ring *rxr = &sc->rx_rings[i];
2565 uint64_t bus_addr = rxr->rxdma.dma_paddr;
2568 E1000_WRITE_REG(hw, E1000_RDLEN(i),
2569 rxr->num_rx_desc * sizeof(struct e1000_rx_desc));
2570 E1000_WRITE_REG(hw, E1000_RDBAH(i),
2571 (uint32_t)(bus_addr >> 32));
2572 E1000_WRITE_REG(hw, E1000_RDBAL(i),
2573 (uint32_t)bus_addr);
2574 E1000_WRITE_REG(hw, E1000_SRRCTL(i), srrctl);
2575 /* Enable this Queue */
2576 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i));
2577 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
2578 rxdctl &= 0xFFF00000;
2579 rxdctl |= IGB_RX_PTHRESH;
2580 rxdctl |= IGB_RX_HTHRESH << 8;
2582 * Don't set WTHRESH to a value above 1 on 82576, see:
2583 * 82576 specification update errata #26
2585 rxdctl |= IGB_RX_WTHRESH << 16;
2586 E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
2589 rxcsum = E1000_READ_REG(&sc->hw, E1000_RXCSUM);
2590 rxcsum &= ~(E1000_RXCSUM_PCSS_MASK | E1000_RXCSUM_IPPCSE);
2593 * Receive Checksum Offload for TCP and UDP
2595 * Checksum offloading is also enabled if multiple receive
2596 * queue is to be supported, since we need it to figure out
2599 if ((ifp->if_capenable & IFCAP_RXCSUM) || IGB_ENABLE_HWRSS(sc)) {
2602 * PCSD must be enabled to enable multiple
2605 rxcsum |= E1000_RXCSUM_IPOFL | E1000_RXCSUM_TUOFL |
2608 rxcsum &= ~(E1000_RXCSUM_IPOFL | E1000_RXCSUM_TUOFL |
2611 E1000_WRITE_REG(&sc->hw, E1000_RXCSUM, rxcsum);
2613 if (sc->rx_ring_inuse > 1) {
2614 uint8_t key[IGB_NRSSRK * IGB_RSSRK_SIZE];
2615 const struct if_ringmap *rm;
2616 uint32_t reta_shift;
2621 * When we reach here, RSS has already been disabled
2622 * in igb_stop(), so we could safely configure RSS key
2623 * and redirect table.
2629 toeplitz_get_key(key, sizeof(key));
2630 for (i = 0; i < IGB_NRSSRK; ++i) {
2633 rssrk = IGB_RSSRK_VAL(key, i);
2634 IGB_RSS_DPRINTF(sc, 1, "rssrk%d 0x%08x\n", i, rssrk);
2636 E1000_WRITE_REG(hw, E1000_RSSRK(i), rssrk);
2640 * Configure RSS redirect table
2645 rm = sc->rx_rmap_intr;
2646 if_ringmap_rdrtable(rm, sc->rdr_table, IGB_RDRTABLE_SIZE);
2648 reta_shift = IGB_RETA_SHIFT;
2649 if (hw->mac.type == e1000_82575)
2650 reta_shift = IGB_RETA_SHIFT_82575;
2653 for (j = 0; j < IGB_NRETA; ++j) {
2656 for (i = 0; i < IGB_RETA_SIZE; ++i) {
2659 q = sc->rdr_table[r] << reta_shift;
2660 reta |= q << (8 * i);
2663 IGB_RSS_DPRINTF(sc, 1, "reta 0x%08x\n", reta);
2664 E1000_WRITE_REG(hw, E1000_RETA(j), reta);
2668 * Enable multiple receive queues.
2669 * Enable IPv4 RSS standard hash functions.
2670 * Disable RSS interrupt on 82575
2672 E1000_WRITE_REG(&sc->hw, E1000_MRQC,
2673 E1000_MRQC_ENABLE_RSS_4Q |
2674 E1000_MRQC_RSS_FIELD_IPV4_TCP |
2675 E1000_MRQC_RSS_FIELD_IPV4);
2678 /* Setup the Receive Control Register */
2679 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2680 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
2681 E1000_RCTL_RDMTS_HALF |
2682 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
2683 /* Strip CRC bytes. */
2684 rctl |= E1000_RCTL_SECRC;
2685 /* Make sure VLAN Filters are off */
2686 rctl &= ~E1000_RCTL_VFE;
2687 /* Don't store bad packets */
2688 rctl &= ~E1000_RCTL_SBP;
2690 /* Enable Receives */
2691 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2694 * Setup the HW Rx Head and Tail Descriptor Pointers
2695 * - needs to be after enable
2697 for (i = 0; i < sc->rx_ring_inuse; ++i) {
2698 struct igb_rx_ring *rxr = &sc->rx_rings[i];
2700 E1000_WRITE_REG(hw, E1000_RDH(i), rxr->next_to_check);
2701 E1000_WRITE_REG(hw, E1000_RDT(i), rxr->num_rx_desc - 1);
2706 igb_rx_refresh(struct igb_rx_ring *rxr, int i)
2709 i = rxr->num_rx_desc - 1;
2710 E1000_WRITE_REG(&rxr->sc->hw, E1000_RDT(rxr->me), i);
2714 igb_rxeof(struct igb_rx_ring *rxr, int count)
2716 struct ifnet *ifp = &rxr->sc->arpcom.ac_if;
2717 union e1000_adv_rx_desc *cur;
2719 int i, ncoll = 0, cpuid = mycpuid;
2721 i = rxr->next_to_check;
2722 cur = &rxr->rx_base[i];
2723 staterr = le32toh(cur->wb.upper.status_error);
2725 if ((staterr & E1000_RXD_STAT_DD) == 0)
2728 while ((staterr & E1000_RXD_STAT_DD) && count != 0) {
2729 struct pktinfo *pi = NULL, pi0;
2730 struct igb_rx_buf *rxbuf = &rxr->rx_buf[i];
2731 struct mbuf *m = NULL;
2734 eop = (staterr & E1000_RXD_STAT_EOP) ? TRUE : FALSE;
2739 if ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) == 0 &&
2741 struct mbuf *mp = rxbuf->m_head;
2742 uint32_t hash, hashtype;
2746 len = le16toh(cur->wb.upper.length);
2747 if ((rxr->sc->hw.mac.type == e1000_i350 ||
2748 rxr->sc->hw.mac.type == e1000_i354) &&
2749 (staterr & E1000_RXDEXT_STATERR_LB))
2750 vlan = be16toh(cur->wb.upper.vlan);
2752 vlan = le16toh(cur->wb.upper.vlan);
2754 hash = le32toh(cur->wb.lower.hi_dword.rss);
2755 hashtype = le32toh(cur->wb.lower.lo_dword.data) &
2756 E1000_RXDADV_RSSTYPE_MASK;
2758 IGB_RSS_DPRINTF(rxr->sc, 10,
2759 "ring%d, hash 0x%08x, hashtype %u\n",
2760 rxr->me, hash, hashtype);
2762 bus_dmamap_sync(rxr->rx_tag, rxbuf->map,
2763 BUS_DMASYNC_POSTREAD);
2765 if (igb_newbuf(rxr, i, FALSE) != 0) {
2766 IFNET_STAT_INC(ifp, iqdrops, 1);
2771 if (rxr->fmp == NULL) {
2772 mp->m_pkthdr.len = len;
2776 rxr->lmp->m_next = mp;
2777 rxr->lmp = rxr->lmp->m_next;
2778 rxr->fmp->m_pkthdr.len += len;
2786 m->m_pkthdr.rcvif = ifp;
2787 IFNET_STAT_INC(ifp, ipackets, 1);
2789 if (ifp->if_capenable & IFCAP_RXCSUM)
2790 igb_rxcsum(staterr, m);
2792 if (staterr & E1000_RXD_STAT_VP) {
2793 m->m_pkthdr.ether_vlantag = vlan;
2794 m->m_flags |= M_VLANTAG;
2797 if (ifp->if_capenable & IFCAP_RSS) {
2798 pi = igb_rssinfo(m, &pi0,
2799 hash, hashtype, staterr);
2801 #ifdef IGB_RSS_DEBUG
2806 IFNET_STAT_INC(ifp, ierrors, 1);
2808 igb_setup_rxdesc(cur, rxbuf);
2810 rxr->discard = TRUE;
2812 rxr->discard = FALSE;
2813 if (rxr->fmp != NULL) {
2822 ifp->if_input(ifp, m, pi, cpuid);
2824 /* Advance our pointers to the next descriptor. */
2825 if (++i == rxr->num_rx_desc)
2828 if (ncoll >= rxr->wreg_nsegs) {
2829 igb_rx_refresh(rxr, i);
2833 cur = &rxr->rx_base[i];
2834 staterr = le32toh(cur->wb.upper.status_error);
2836 rxr->next_to_check = i;
2839 igb_rx_refresh(rxr, i);
2844 igb_set_vlan(struct igb_softc *sc)
2846 struct e1000_hw *hw = &sc->hw;
2849 struct ifnet *ifp = sc->arpcom.ac_if;
2853 e1000_rlpml_set_vf(hw, sc->max_frame_size + VLAN_TAG_SIZE);
2857 reg = E1000_READ_REG(hw, E1000_CTRL);
2858 reg |= E1000_CTRL_VME;
2859 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2862 /* Enable the Filter Table */
2863 if (ifp->if_capenable & IFCAP_VLAN_HWFILTER) {
2864 reg = E1000_READ_REG(hw, E1000_RCTL);
2865 reg &= ~E1000_RCTL_CFIEN;
2866 reg |= E1000_RCTL_VFE;
2867 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2871 /* Update the frame size */
2872 E1000_WRITE_REG(&sc->hw, E1000_RLPML,
2873 sc->max_frame_size + VLAN_TAG_SIZE);
2876 /* Don't bother with table if no vlans */
2877 if ((adapter->num_vlans == 0) ||
2878 ((ifp->if_capenable & IFCAP_VLAN_HWFILTER) == 0))
2881 ** A soft reset zero's out the VFTA, so
2882 ** we need to repopulate it now.
2884 for (int i = 0; i < IGB_VFTA_SIZE; i++)
2885 if (adapter->shadow_vfta[i] != 0) {
2886 if (adapter->vf_ifp)
2887 e1000_vfta_set_vf(hw,
2888 adapter->shadow_vfta[i], TRUE);
2890 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA,
2891 i, adapter->shadow_vfta[i]);
2897 igb_enable_intr(struct igb_softc *sc)
2901 for (i = 0; i < sc->intr_cnt; ++i)
2902 lwkt_serialize_handler_enable(sc->intr_data[i].intr_serialize);
2904 if ((sc->flags & IGB_FLAG_SHARED_INTR) == 0) {
2905 if (sc->intr_type == PCI_INTR_TYPE_MSIX)
2906 E1000_WRITE_REG(&sc->hw, E1000_EIAC, sc->intr_mask);
2908 E1000_WRITE_REG(&sc->hw, E1000_EIAC, 0);
2909 E1000_WRITE_REG(&sc->hw, E1000_EIAM, sc->intr_mask);
2910 E1000_WRITE_REG(&sc->hw, E1000_EIMS, sc->intr_mask);
2911 E1000_WRITE_REG(&sc->hw, E1000_IMS, E1000_IMS_LSC);
2913 E1000_WRITE_REG(&sc->hw, E1000_IMS, IMS_ENABLE_MASK);
2915 E1000_WRITE_FLUSH(&sc->hw);
2919 igb_disable_intr(struct igb_softc *sc)
2923 if ((sc->flags & IGB_FLAG_SHARED_INTR) == 0) {
2924 E1000_WRITE_REG(&sc->hw, E1000_EIMC, 0xffffffff);
2925 E1000_WRITE_REG(&sc->hw, E1000_EIAC, 0);
2927 E1000_WRITE_REG(&sc->hw, E1000_IMC, 0xffffffff);
2928 E1000_WRITE_FLUSH(&sc->hw);
2930 for (i = 0; i < sc->intr_cnt; ++i)
2931 lwkt_serialize_handler_disable(sc->intr_data[i].intr_serialize);
2935 * Bit of a misnomer, what this really means is
2936 * to enable OS management of the system... aka
2937 * to disable special hardware management features
2940 igb_get_mgmt(struct igb_softc *sc)
2942 if (sc->flags & IGB_FLAG_HAS_MGMT) {
2943 int manc2h = E1000_READ_REG(&sc->hw, E1000_MANC2H);
2944 int manc = E1000_READ_REG(&sc->hw, E1000_MANC);
2946 /* disable hardware interception of ARP */
2947 manc &= ~E1000_MANC_ARP_EN;
2949 /* enable receiving management packets to the host */
2950 manc |= E1000_MANC_EN_MNG2HOST;
2951 manc2h |= 1 << 5; /* Mng Port 623 */
2952 manc2h |= 1 << 6; /* Mng Port 664 */
2953 E1000_WRITE_REG(&sc->hw, E1000_MANC2H, manc2h);
2954 E1000_WRITE_REG(&sc->hw, E1000_MANC, manc);
2959 * Give control back to hardware management controller
2963 igb_rel_mgmt(struct igb_softc *sc)
2965 if (sc->flags & IGB_FLAG_HAS_MGMT) {
2966 int manc = E1000_READ_REG(&sc->hw, E1000_MANC);
2968 /* Re-enable hardware interception of ARP */
2969 manc |= E1000_MANC_ARP_EN;
2970 manc &= ~E1000_MANC_EN_MNG2HOST;
2972 E1000_WRITE_REG(&sc->hw, E1000_MANC, manc);
2977 * Sets CTRL_EXT:DRV_LOAD bit.
2979 * For ASF and Pass Through versions of f/w this means that
2980 * the driver is loaded.
2983 igb_get_hw_control(struct igb_softc *sc)
2990 /* Let firmware know the driver has taken over */
2991 ctrl_ext = E1000_READ_REG(&sc->hw, E1000_CTRL_EXT);
2992 E1000_WRITE_REG(&sc->hw, E1000_CTRL_EXT,
2993 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2997 * Resets CTRL_EXT:DRV_LOAD bit.
2999 * For ASF and Pass Through versions of f/w this means that the
3000 * driver is no longer loaded.
3003 igb_rel_hw_control(struct igb_softc *sc)
3010 /* Let firmware taken over control of h/w */
3011 ctrl_ext = E1000_READ_REG(&sc->hw, E1000_CTRL_EXT);
3012 E1000_WRITE_REG(&sc->hw, E1000_CTRL_EXT,
3013 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
3017 igb_is_valid_ether_addr(const uint8_t *addr)
3019 uint8_t zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 };
3021 if ((addr[0] & 1) || !bcmp(addr, zero_addr, ETHER_ADDR_LEN))
3027 * Enable PCI Wake On Lan capability
3030 igb_enable_wol(struct igb_softc *sc)
3032 device_t dev = sc->dev;
3037 if (pci_find_extcap(dev, PCIY_PMG, &pmc) != 0) {
3038 device_printf(dev, "no PMG\n");
3043 * Set the type of wakeup.
3045 sc->wol &= ~(E1000_WUFC_EX | E1000_WUFC_MC);
3046 if ((sc->wol & (E1000_WUFC_EX | E1000_WUFC_MAG | E1000_WUFC_MC)) == 0)
3050 * Advertise the wakeup capabilities.
3052 ctrl = E1000_READ_REG(&sc->hw, E1000_CTRL);
3053 ctrl |= (E1000_CTRL_SWDPIN2 | E1000_CTRL_SWDPIN3);
3054 E1000_WRITE_REG(&sc->hw, E1000_CTRL, ctrl);
3057 * Keep the laser running on Fiber adapters.
3059 if (sc->hw.phy.media_type == e1000_media_type_fiber ||
3060 sc->hw.phy.media_type == e1000_media_type_internal_serdes) {
3063 ctrl_ext = E1000_READ_REG(&sc->hw, E1000_CTRL_EXT);
3064 ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
3065 E1000_WRITE_REG(&sc->hw, E1000_CTRL_EXT, ctrl_ext);
3068 error = igb_enable_phy_wol(sc);
3072 /* XXX will this happen? ich/pch specific. */
3073 if (sc->hw.phy.type == e1000_phy_igp_3)
3074 e1000_igp3_phy_powerdown_workaround_ich8lan(&sc->hw);
3077 status = pci_read_config(dev, pmc + PCIR_POWER_STATUS, 2);
3078 status &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE);
3080 status |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE;
3081 pci_write_config(dev, pmc + PCIR_POWER_STATUS, status, 2);
3085 * WOL in the newer chipset interfaces (pchlan)
3086 * require thing to be copied into the phy
3089 igb_enable_phy_wol(struct igb_softc *sc)
3091 struct e1000_hw *hw = &sc->hw;
3096 /* Copy MAC RARs to PHY RARs */
3097 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
3099 /* Copy MAC MTA to PHY MTA */
3100 for (i = 0; i < hw->mac.mta_reg_count; i++) {
3101 mreg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
3102 e1000_write_phy_reg(hw, BM_MTA(i), (uint16_t)(mreg & 0xFFFF));
3103 e1000_write_phy_reg(hw, BM_MTA(i) + 1,
3104 (uint16_t)((mreg >> 16) & 0xFFFF));
3107 /* Configure PHY Rx Control register */
3108 e1000_read_phy_reg(hw, BM_RCTL, &preg);
3109 mreg = E1000_READ_REG(hw, E1000_RCTL);
3110 if (mreg & E1000_RCTL_UPE)
3111 preg |= BM_RCTL_UPE;
3112 if (mreg & E1000_RCTL_MPE)
3113 preg |= BM_RCTL_MPE;
3114 preg &= ~(BM_RCTL_MO_MASK);
3115 if (mreg & E1000_RCTL_MO_3) {
3116 preg |= (((mreg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
3117 << BM_RCTL_MO_SHIFT);
3119 if (mreg & E1000_RCTL_BAM)
3120 preg |= BM_RCTL_BAM;
3121 if (mreg & E1000_RCTL_PMCF)
3122 preg |= BM_RCTL_PMCF;
3123 mreg = E1000_READ_REG(hw, E1000_CTRL);
3124 if (mreg & E1000_CTRL_RFCE)
3125 preg |= BM_RCTL_RFCE;
3126 e1000_write_phy_reg(&sc->hw, BM_RCTL, preg);
3128 /* Enable PHY wakeup in MAC register. */
3129 E1000_WRITE_REG(hw, E1000_WUC,
3130 E1000_WUC_PHY_WAKE | E1000_WUC_PME_EN | E1000_WUC_APME);
3131 E1000_WRITE_REG(hw, E1000_WUFC, sc->wol);
3133 /* Configure and enable PHY wakeup in PHY registers */
3134 e1000_write_phy_reg(hw, BM_WUFC, sc->wol);
3135 e1000_write_phy_reg(hw, BM_WUC, E1000_WUC_PME_EN);
3136 /* Activate PHY wakeup */
3137 ret = hw->phy.ops.acquire(hw);
3139 if_printf(&sc->arpcom.ac_if, "Could not acquire PHY\n");
3142 e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
3143 (BM_WUC_ENABLE_PAGE << IGP_PAGE_SHIFT));
3144 ret = e1000_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, &preg);
3146 if_printf(&sc->arpcom.ac_if, "Could not read PHY page 769\n");
3149 preg |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
3150 ret = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, preg);
3152 if_printf(&sc->arpcom.ac_if,
3153 "Could not set PHY Host Wakeup bit\n");
3156 hw->phy.ops.release(hw);
3161 igb_update_stats_counters(struct igb_softc *sc)
3163 struct e1000_hw *hw = &sc->hw;
3164 struct e1000_hw_stats *stats;
3165 struct ifnet *ifp = &sc->arpcom.ac_if;
3168 * The virtual function adapter has only a
3169 * small controlled set of stats, do only
3173 igb_update_vf_stats_counters(sc);
3178 if (sc->hw.phy.media_type == e1000_media_type_copper ||
3179 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
3181 E1000_READ_REG(hw,E1000_SYMERRS);
3182 stats->sec += E1000_READ_REG(hw, E1000_SEC);
3185 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
3186 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
3187 stats->scc += E1000_READ_REG(hw, E1000_SCC);
3188 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
3190 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
3191 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
3192 stats->colc += E1000_READ_REG(hw, E1000_COLC);
3193 stats->dc += E1000_READ_REG(hw, E1000_DC);
3194 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
3195 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
3196 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
3199 * For watchdog management we need to know if we have been
3200 * paused during the last interval, so capture that here.
3202 sc->pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
3203 stats->xoffrxc += sc->pause_frames;
3204 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
3205 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
3206 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
3207 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
3208 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
3209 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
3210 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
3211 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
3212 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
3213 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
3214 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
3215 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
3217 /* For the 64-bit byte counters the low dword must be read first. */
3218 /* Both registers clear on the read of the high dword */
3220 stats->gorc += E1000_READ_REG(hw, E1000_GORCL) +
3221 ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
3222 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL) +
3223 ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
3225 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
3226 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
3227 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
3228 stats->roc += E1000_READ_REG(hw, E1000_ROC);
3229 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
3231 stats->mgprc += E1000_READ_REG(hw, E1000_MGTPRC);
3232 stats->mgpdc += E1000_READ_REG(hw, E1000_MGTPDC);
3233 stats->mgptc += E1000_READ_REG(hw, E1000_MGTPTC);
3235 stats->tor += E1000_READ_REG(hw, E1000_TORL) +
3236 ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
3237 stats->tot += E1000_READ_REG(hw, E1000_TOTL) +
3238 ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
3240 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
3241 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
3242 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
3243 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
3244 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
3245 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
3246 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
3247 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
3248 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
3249 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
3251 /* Interrupt Counts */
3253 stats->iac += E1000_READ_REG(hw, E1000_IAC);
3254 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
3255 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
3256 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
3257 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
3258 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
3259 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
3260 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
3261 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
3263 /* Host to Card Statistics */
3265 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
3266 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
3267 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
3268 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
3269 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
3270 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
3271 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
3272 stats->hgorc += (E1000_READ_REG(hw, E1000_HGORCL) +
3273 ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32));
3274 stats->hgotc += (E1000_READ_REG(hw, E1000_HGOTCL) +
3275 ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32));
3276 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
3277 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
3278 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
3280 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
3281 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
3282 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
3283 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
3284 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
3285 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
3287 IFNET_STAT_SET(ifp, collisions, stats->colc);
3290 IFNET_STAT_SET(ifp, ierrors,
3291 stats->rxerrc + stats->crcerrs + stats->algnerrc +
3292 stats->ruc + stats->roc + stats->mpc + stats->cexterr);
3295 IFNET_STAT_SET(ifp, oerrors,
3296 stats->ecol + stats->latecol + sc->watchdog_events);
3298 /* Driver specific counters */
3299 sc->device_control = E1000_READ_REG(hw, E1000_CTRL);
3300 sc->rx_control = E1000_READ_REG(hw, E1000_RCTL);
3301 sc->int_mask = E1000_READ_REG(hw, E1000_IMS);
3302 sc->eint_mask = E1000_READ_REG(hw, E1000_EIMS);
3303 sc->packet_buf_alloc_tx =
3304 ((E1000_READ_REG(hw, E1000_PBA) & 0xffff0000) >> 16);
3305 sc->packet_buf_alloc_rx =
3306 (E1000_READ_REG(hw, E1000_PBA) & 0xffff);
3310 igb_vf_init_stats(struct igb_softc *sc)
3312 struct e1000_hw *hw = &sc->hw;
3313 struct e1000_vf_stats *stats;
3316 stats->last_gprc = E1000_READ_REG(hw, E1000_VFGPRC);
3317 stats->last_gorc = E1000_READ_REG(hw, E1000_VFGORC);
3318 stats->last_gptc = E1000_READ_REG(hw, E1000_VFGPTC);
3319 stats->last_gotc = E1000_READ_REG(hw, E1000_VFGOTC);
3320 stats->last_mprc = E1000_READ_REG(hw, E1000_VFMPRC);
3324 igb_update_vf_stats_counters(struct igb_softc *sc)
3326 struct e1000_hw *hw = &sc->hw;
3327 struct e1000_vf_stats *stats;
3329 if (sc->link_speed == 0)
3333 UPDATE_VF_REG(E1000_VFGPRC, stats->last_gprc, stats->gprc);
3334 UPDATE_VF_REG(E1000_VFGORC, stats->last_gorc, stats->gorc);
3335 UPDATE_VF_REG(E1000_VFGPTC, stats->last_gptc, stats->gptc);
3336 UPDATE_VF_REG(E1000_VFGOTC, stats->last_gotc, stats->gotc);
3337 UPDATE_VF_REG(E1000_VFMPRC, stats->last_mprc, stats->mprc);
3340 #ifdef IFPOLL_ENABLE
3343 igb_npoll_status(struct ifnet *ifp)
3345 struct igb_softc *sc = ifp->if_softc;
3348 ASSERT_SERIALIZED(&sc->main_serialize);
3350 reg_icr = E1000_READ_REG(&sc->hw, E1000_ICR);
3351 if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3352 sc->hw.mac.get_link_status = 1;
3353 igb_update_link_status(sc);
3358 igb_npoll_tx(struct ifnet *ifp, void *arg, int cycle __unused)
3360 struct igb_tx_ring *txr = arg;
3362 ASSERT_SERIALIZED(&txr->tx_serialize);
3363 igb_tx_intr(txr, *(txr->tx_hdr));
3364 igb_try_txgc(txr, 1);
3368 igb_npoll_rx(struct ifnet *ifp __unused, void *arg, int cycle)
3370 struct igb_rx_ring *rxr = arg;
3372 ASSERT_SERIALIZED(&rxr->rx_serialize);
3374 igb_rxeof(rxr, cycle);
3378 igb_npoll(struct ifnet *ifp, struct ifpoll_info *info)
3380 struct igb_softc *sc = ifp->if_softc;
3381 int i, txr_cnt, rxr_cnt;
3383 ASSERT_IFNET_SERIALIZED_ALL(ifp);
3388 info->ifpi_status.status_func = igb_npoll_status;
3389 info->ifpi_status.serializer = &sc->main_serialize;
3391 txr_cnt = igb_get_txring_inuse(sc, TRUE);
3392 for (i = 0; i < txr_cnt; ++i) {
3393 struct igb_tx_ring *txr = &sc->tx_rings[i];
3395 cpu = if_ringmap_cpumap(sc->tx_rmap, i);
3396 KKASSERT(cpu < netisr_ncpus);
3397 info->ifpi_tx[cpu].poll_func = igb_npoll_tx;
3398 info->ifpi_tx[cpu].arg = txr;
3399 info->ifpi_tx[cpu].serializer = &txr->tx_serialize;
3400 ifsq_set_cpuid(txr->ifsq, cpu);
3403 rxr_cnt = igb_get_rxring_inuse(sc, TRUE);
3404 for (i = 0; i < rxr_cnt; ++i) {
3405 struct igb_rx_ring *rxr = &sc->rx_rings[i];
3407 cpu = if_ringmap_cpumap(sc->rx_rmap, i);
3408 KKASSERT(cpu < netisr_ncpus);
3409 info->ifpi_rx[cpu].poll_func = igb_npoll_rx;
3410 info->ifpi_rx[cpu].arg = rxr;
3411 info->ifpi_rx[cpu].serializer = &rxr->rx_serialize;
3414 for (i = 0; i < sc->tx_ring_cnt; ++i) {
3415 struct igb_tx_ring *txr = &sc->tx_rings[i];
3417 ifsq_set_cpuid(txr->ifsq, txr->tx_intr_cpuid);
3420 if (ifp->if_flags & IFF_RUNNING)
3424 #endif /* IFPOLL_ENABLE */
3429 struct igb_softc *sc = xsc;
3430 struct ifnet *ifp = &sc->arpcom.ac_if;
3433 ASSERT_SERIALIZED(&sc->main_serialize);
3435 eicr = E1000_READ_REG(&sc->hw, E1000_EICR);
3440 if (ifp->if_flags & IFF_RUNNING) {
3441 struct igb_tx_ring *txr = &sc->tx_rings[0];
3444 for (i = 0; i < sc->rx_ring_inuse; ++i) {
3445 struct igb_rx_ring *rxr = &sc->rx_rings[i];
3447 if (eicr & rxr->rx_intr_mask) {
3448 lwkt_serialize_enter(&rxr->rx_serialize);
3450 lwkt_serialize_exit(&rxr->rx_serialize);
3454 if (eicr & txr->tx_intr_mask) {
3455 lwkt_serialize_enter(&txr->tx_serialize);
3456 igb_tx_intr(txr, *(txr->tx_hdr));
3457 lwkt_serialize_exit(&txr->tx_serialize);
3461 if (eicr & E1000_EICR_OTHER) {
3462 uint32_t icr = E1000_READ_REG(&sc->hw, E1000_ICR);
3464 /* Link status change */
3465 if (icr & E1000_ICR_LSC) {
3466 sc->hw.mac.get_link_status = 1;
3467 igb_update_link_status(sc);
3472 * Reading EICR has the side effect to clear interrupt mask,
3473 * so all interrupts need to be enabled here.
3475 E1000_WRITE_REG(&sc->hw, E1000_EIMS, sc->intr_mask);
3479 igb_intr_shared(void *xsc)
3481 struct igb_softc *sc = xsc;
3482 struct ifnet *ifp = &sc->arpcom.ac_if;
3485 ASSERT_SERIALIZED(&sc->main_serialize);
3487 reg_icr = E1000_READ_REG(&sc->hw, E1000_ICR);
3490 if (reg_icr == 0xffffffff)
3493 /* Definitely not our interrupt. */
3497 if ((reg_icr & E1000_ICR_INT_ASSERTED) == 0)
3500 if (ifp->if_flags & IFF_RUNNING) {
3502 (E1000_ICR_RXT0 | E1000_ICR_RXDMT0 | E1000_ICR_RXO)) {
3505 for (i = 0; i < sc->rx_ring_inuse; ++i) {
3506 struct igb_rx_ring *rxr = &sc->rx_rings[i];
3508 lwkt_serialize_enter(&rxr->rx_serialize);
3510 lwkt_serialize_exit(&rxr->rx_serialize);
3514 if (reg_icr & E1000_ICR_TXDW) {
3515 struct igb_tx_ring *txr = &sc->tx_rings[0];
3517 lwkt_serialize_enter(&txr->tx_serialize);
3518 igb_tx_intr(txr, *(txr->tx_hdr));
3519 lwkt_serialize_exit(&txr->tx_serialize);
3523 /* Link status change */
3524 if (reg_icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3525 sc->hw.mac.get_link_status = 1;
3526 igb_update_link_status(sc);
3529 if (reg_icr & E1000_ICR_RXO)
3534 igb_encap(struct igb_tx_ring *txr, struct mbuf **m_headp,
3535 int *segs_used, int *idx)
3537 bus_dma_segment_t segs[IGB_MAX_SCATTER];
3539 struct igb_tx_buf *tx_buf, *tx_buf_mapped;
3540 union e1000_adv_tx_desc *txd = NULL;
3541 struct mbuf *m_head = *m_headp;
3542 uint32_t olinfo_status = 0, cmd_type_len = 0, cmd_rs = 0;
3543 int maxsegs, nsegs, i, j, error;
3544 uint32_t hdrlen = 0;
3546 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
3547 error = igb_tso_pullup(txr, m_headp);
3553 /* Set basic descriptor constants */
3554 cmd_type_len |= E1000_ADVTXD_DTYP_DATA;
3555 cmd_type_len |= E1000_ADVTXD_DCMD_IFCS | E1000_ADVTXD_DCMD_DEXT;
3556 if (m_head->m_flags & M_VLANTAG)
3557 cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
3560 * Map the packet for DMA.
3562 tx_buf = &txr->tx_buf[txr->next_avail_desc];
3563 tx_buf_mapped = tx_buf;
3566 maxsegs = txr->tx_avail - IGB_TX_RESERVED;
3567 if (maxsegs > IGB_MAX_SCATTER)
3568 maxsegs = IGB_MAX_SCATTER;
3570 error = bus_dmamap_load_mbuf_defrag(txr->tx_tag, map, m_headp,
3571 segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
3573 if (error == ENOBUFS)
3574 txr->sc->mbuf_defrag_failed++;
3576 txr->sc->no_tx_dma_setup++;
3582 bus_dmamap_sync(txr->tx_tag, map, BUS_DMASYNC_PREWRITE);
3587 * Set up the TX context descriptor, if any hardware offloading is
3588 * needed. This includes CSUM, VLAN, and TSO. It will consume one
3591 * Unlike these chips' predecessors (em/emx), TX context descriptor
3592 * will _not_ interfere TX data fetching pipelining.
3594 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
3595 igb_tso_ctx(txr, m_head, &hdrlen);
3596 cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
3597 olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
3598 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
3601 } else if (igb_txcsum_ctx(txr, m_head)) {
3602 if (m_head->m_pkthdr.csum_flags & CSUM_IP)
3603 olinfo_status |= (E1000_TXD_POPTS_IXSM << 8);
3604 if (m_head->m_pkthdr.csum_flags & (CSUM_UDP | CSUM_TCP))
3605 olinfo_status |= (E1000_TXD_POPTS_TXSM << 8);
3610 *segs_used += nsegs;
3611 txr->tx_nsegs += nsegs;
3612 if (txr->tx_nsegs >= txr->intr_nsegs) {
3614 * Report Status (RS) is turned on every intr_nsegs
3615 * descriptors (roughly).
3618 cmd_rs = E1000_ADVTXD_DCMD_RS;
3621 /* Calculate payload length */
3622 olinfo_status |= ((m_head->m_pkthdr.len - hdrlen)
3623 << E1000_ADVTXD_PAYLEN_SHIFT);
3626 * 82575 needs the TX context index added; the queue
3627 * index is used as TX context index here.
3629 if (txr->sc->hw.mac.type == e1000_82575)
3630 olinfo_status |= txr->me << 4;
3632 /* Set up our transmit descriptors */
3633 i = txr->next_avail_desc;
3634 for (j = 0; j < nsegs; j++) {
3636 bus_addr_t seg_addr;
3638 tx_buf = &txr->tx_buf[i];
3639 txd = (union e1000_adv_tx_desc *)&txr->tx_base[i];
3640 seg_addr = segs[j].ds_addr;
3641 seg_len = segs[j].ds_len;
3643 txd->read.buffer_addr = htole64(seg_addr);
3644 txd->read.cmd_type_len = htole32(cmd_type_len | seg_len);
3645 txd->read.olinfo_status = htole32(olinfo_status);
3646 if (++i == txr->num_tx_desc)
3648 tx_buf->m_head = NULL;
3651 KASSERT(txr->tx_avail > nsegs, ("invalid avail TX desc\n"));
3652 txr->next_avail_desc = i;
3653 txr->tx_avail -= nsegs;
3656 tx_buf->m_head = m_head;
3657 tx_buf_mapped->map = tx_buf->map;
3661 * Last Descriptor of Packet needs End Of Packet (EOP)
3663 txd->read.cmd_type_len |= htole32(E1000_ADVTXD_DCMD_EOP | cmd_rs);
3666 * Defer TDT updating, until enough descrptors are setup
3669 #ifdef IGB_TSS_DEBUG
3677 igb_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
3679 struct igb_softc *sc = ifp->if_softc;
3680 struct igb_tx_ring *txr = ifsq_get_priv(ifsq);
3681 struct mbuf *m_head;
3682 int idx = -1, nsegs = 0;
3684 KKASSERT(txr->ifsq == ifsq);
3685 ASSERT_SERIALIZED(&txr->tx_serialize);
3687 if ((ifp->if_flags & IFF_RUNNING) == 0 || ifsq_is_oactive(ifsq))
3690 if (!sc->link_active || (txr->tx_flags & IGB_TXFLAG_ENABLED) == 0) {
3695 while (!ifsq_is_empty(ifsq)) {
3696 if (txr->tx_avail <= IGB_MAX_SCATTER + IGB_TX_RESERVED) {
3697 ifsq_set_oactive(ifsq);
3698 /* Set watchdog on */
3699 ifsq_watchdog_set_count(&txr->tx_watchdog, 5);
3703 m_head = ifsq_dequeue(ifsq);
3707 if (igb_encap(txr, &m_head, &nsegs, &idx)) {
3708 IFNET_STAT_INC(ifp, oerrors, 1);
3713 * TX interrupt are aggressively aggregated, so increasing
3714 * opackets at TX interrupt time will make the opackets
3715 * statistics vastly inaccurate; we do the opackets increment
3718 IFNET_STAT_INC(ifp, opackets, 1);
3720 if (nsegs >= txr->wreg_nsegs) {
3721 E1000_WRITE_REG(&txr->sc->hw, E1000_TDT(txr->me), idx);
3726 /* Send a copy of the frame to the BPF listener */
3727 ETHER_BPF_MTAP(ifp, m_head);
3730 E1000_WRITE_REG(&txr->sc->hw, E1000_TDT(txr->me), idx);
3731 txr->tx_running = IGB_TX_RUNNING;
3735 igb_watchdog(struct ifaltq_subque *ifsq)
3737 struct igb_tx_ring *txr = ifsq_get_priv(ifsq);
3738 struct ifnet *ifp = ifsq_get_ifp(ifsq);
3739 struct igb_softc *sc = ifp->if_softc;
3742 KKASSERT(txr->ifsq == ifsq);
3743 ASSERT_IFNET_SERIALIZED_ALL(ifp);
3746 * If flow control has paused us since last checking
3747 * it invalidates the watchdog timing, so dont run it.
3749 if (sc->pause_frames) {
3750 sc->pause_frames = 0;
3751 ifsq_watchdog_set_count(&txr->tx_watchdog, 5);
3755 if_printf(ifp, "Watchdog timeout -- resetting\n");
3756 if_printf(ifp, "Queue(%d) tdh = %d, hw tdt = %d\n", txr->me,
3757 E1000_READ_REG(&sc->hw, E1000_TDH(txr->me)),
3758 E1000_READ_REG(&sc->hw, E1000_TDT(txr->me)));
3759 if_printf(ifp, "TX(%d) desc avail = %d, "
3760 "Next TX to Clean = %d\n",
3761 txr->me, txr->tx_avail, txr->next_to_clean);
3763 IFNET_STAT_INC(ifp, oerrors, 1);
3764 sc->watchdog_events++;
3767 for (i = 0; i < sc->tx_ring_inuse; ++i)
3768 ifsq_devstart_sched(sc->tx_rings[i].ifsq);
3772 igb_set_eitr(struct igb_softc *sc, int idx, int rate)
3777 if (sc->hw.mac.type == e1000_82575) {
3778 eitr = 1000000000 / 256 / rate;
3781 * Document is wrong on the 2 bits left shift
3784 eitr = 1000000 / rate;
3785 eitr <<= IGB_EITR_INTVL_SHIFT;
3789 /* Don't disable it */
3790 eitr = 1 << IGB_EITR_INTVL_SHIFT;
3791 } else if (eitr > IGB_EITR_INTVL_MASK) {
3792 /* Don't allow it to be too large */
3793 eitr = IGB_EITR_INTVL_MASK;
3796 if (sc->hw.mac.type == e1000_82575)
3799 eitr |= E1000_EITR_CNT_IGNR;
3800 E1000_WRITE_REG(&sc->hw, E1000_EITR(idx), eitr);
3804 igb_add_intr_rate_sysctl(struct igb_softc *sc, int use,
3805 const char *name, const char *desc)
3809 for (i = 0; i < sc->intr_cnt; ++i) {
3810 if (sc->intr_data[i].intr_use == use) {
3811 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
3812 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
3813 OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW,
3814 sc, use, igb_sysctl_intr_rate, "I", desc);
3821 igb_sysctl_intr_rate(SYSCTL_HANDLER_ARGS)
3823 struct igb_softc *sc = (void *)arg1;
3825 struct ifnet *ifp = &sc->arpcom.ac_if;
3827 struct igb_intr_data *intr;
3830 for (i = 0; i < sc->intr_cnt; ++i) {
3831 intr = &sc->intr_data[i];
3832 if (intr->intr_use == use) {
3833 rate = intr->intr_rate;
3838 error = sysctl_handle_int(oidp, &rate, 0, req);
3839 if (error || req->newptr == NULL)
3844 ifnet_serialize_all(ifp);
3846 for (i = 0; i < sc->intr_cnt; ++i) {
3847 intr = &sc->intr_data[i];
3848 if (intr->intr_use == use && intr->intr_rate != rate) {
3849 intr->intr_rate = rate;
3850 if (ifp->if_flags & IFF_RUNNING)
3851 igb_set_eitr(sc, i, rate);
3855 ifnet_deserialize_all(ifp);
3861 igb_sysctl_tx_intr_nsegs(SYSCTL_HANDLER_ARGS)
3863 struct igb_softc *sc = (void *)arg1;
3864 struct ifnet *ifp = &sc->arpcom.ac_if;
3865 struct igb_tx_ring *txr = &sc->tx_rings[0];
3868 nsegs = txr->intr_nsegs;
3869 error = sysctl_handle_int(oidp, &nsegs, 0, req);
3870 if (error || req->newptr == NULL)
3875 ifnet_serialize_all(ifp);
3877 if (nsegs >= txr->num_tx_desc - IGB_MAX_SCATTER - IGB_TX_RESERVED) {
3883 for (i = 0; i < sc->tx_ring_cnt; ++i)
3884 sc->tx_rings[i].intr_nsegs = nsegs;
3887 ifnet_deserialize_all(ifp);
3893 igb_sysctl_rx_wreg_nsegs(SYSCTL_HANDLER_ARGS)
3895 struct igb_softc *sc = (void *)arg1;
3896 struct ifnet *ifp = &sc->arpcom.ac_if;
3897 int error, nsegs, i;
3899 nsegs = sc->rx_rings[0].wreg_nsegs;
3900 error = sysctl_handle_int(oidp, &nsegs, 0, req);
3901 if (error || req->newptr == NULL)
3904 ifnet_serialize_all(ifp);
3905 for (i = 0; i < sc->rx_ring_cnt; ++i)
3906 sc->rx_rings[i].wreg_nsegs = nsegs;
3907 ifnet_deserialize_all(ifp);
3913 igb_sysctl_tx_wreg_nsegs(SYSCTL_HANDLER_ARGS)
3915 struct igb_softc *sc = (void *)arg1;
3916 struct ifnet *ifp = &sc->arpcom.ac_if;
3917 int error, nsegs, i;
3919 nsegs = sc->tx_rings[0].wreg_nsegs;
3920 error = sysctl_handle_int(oidp, &nsegs, 0, req);
3921 if (error || req->newptr == NULL)
3924 ifnet_serialize_all(ifp);
3925 for (i = 0; i < sc->tx_ring_cnt; ++i)
3926 sc->tx_rings[i].wreg_nsegs = nsegs;
3927 ifnet_deserialize_all(ifp);
3933 igb_init_intr(struct igb_softc *sc)
3937 igb_set_intr_mask(sc);
3939 if ((sc->flags & IGB_FLAG_SHARED_INTR) == 0)
3940 igb_init_unshared_intr(sc);
3942 for (i = 0; i < sc->intr_cnt; ++i)
3943 igb_set_eitr(sc, i, sc->intr_data[i].intr_rate);
3947 igb_init_unshared_intr(struct igb_softc *sc)
3949 struct e1000_hw *hw = &sc->hw;
3950 const struct igb_rx_ring *rxr;
3951 const struct igb_tx_ring *txr;
3952 uint32_t ivar, index;
3956 * Enable extended mode
3958 if (sc->hw.mac.type != e1000_82575) {
3962 gpie = E1000_GPIE_NSICR;
3963 if (sc->intr_type == PCI_INTR_TYPE_MSIX) {
3964 gpie |= E1000_GPIE_MSIX_MODE |
3968 E1000_WRITE_REG(hw, E1000_GPIE, gpie);
3973 switch (sc->hw.mac.type) {
3975 ivar_max = IGB_MAX_IVAR_82576;
3979 ivar_max = IGB_MAX_IVAR_82580;
3983 ivar_max = IGB_MAX_IVAR_I350;
3987 ivar_max = IGB_MAX_IVAR_I354;
3991 case e1000_vfadapt_i350:
3992 ivar_max = IGB_MAX_IVAR_VF;
3996 ivar_max = IGB_MAX_IVAR_I210;
4000 ivar_max = IGB_MAX_IVAR_I211;
4004 panic("unknown mac type %d\n", sc->hw.mac.type);
4006 for (i = 0; i < ivar_max; ++i)
4007 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, i, 0);
4008 E1000_WRITE_REG(hw, E1000_IVAR_MISC, 0);
4012 KASSERT(sc->intr_type != PCI_INTR_TYPE_MSIX,
4013 ("82575 w/ MSI-X"));
4014 tmp = E1000_READ_REG(hw, E1000_CTRL_EXT);
4015 tmp |= E1000_CTRL_EXT_IRCA;
4016 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmp);
4020 * Map TX/RX interrupts to EICR
4022 switch (sc->hw.mac.type) {
4027 case e1000_vfadapt_i350:
4031 for (i = 0; i < sc->rx_ring_inuse; ++i) {
4032 rxr = &sc->rx_rings[i];
4035 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
4040 (rxr->rx_intr_vec | E1000_IVAR_VALID) << 16;
4044 (rxr->rx_intr_vec | E1000_IVAR_VALID);
4046 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
4049 for (i = 0; i < sc->tx_ring_inuse; ++i) {
4050 txr = &sc->tx_rings[i];
4053 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
4058 (txr->tx_intr_vec | E1000_IVAR_VALID) << 24;
4062 (txr->tx_intr_vec | E1000_IVAR_VALID) << 8;
4064 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
4066 if (sc->intr_type == PCI_INTR_TYPE_MSIX) {
4067 ivar = (sc->sts_msix_vec | E1000_IVAR_VALID) << 8;
4068 E1000_WRITE_REG(hw, E1000_IVAR_MISC, ivar);
4074 for (i = 0; i < sc->rx_ring_inuse; ++i) {
4075 rxr = &sc->rx_rings[i];
4077 index = i & 0x7; /* Each IVAR has two entries */
4078 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
4083 (rxr->rx_intr_vec | E1000_IVAR_VALID);
4087 (rxr->rx_intr_vec | E1000_IVAR_VALID) << 16;
4089 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
4092 for (i = 0; i < sc->tx_ring_inuse; ++i) {
4093 txr = &sc->tx_rings[i];
4095 index = i & 0x7; /* Each IVAR has two entries */
4096 ivar = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
4101 (txr->tx_intr_vec | E1000_IVAR_VALID) << 8;
4105 (txr->tx_intr_vec | E1000_IVAR_VALID) << 24;
4107 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, ivar);
4109 if (sc->intr_type == PCI_INTR_TYPE_MSIX) {
4110 ivar = (sc->sts_msix_vec | E1000_IVAR_VALID) << 8;
4111 E1000_WRITE_REG(hw, E1000_IVAR_MISC, ivar);
4117 * Enable necessary interrupt bits.
4119 * The name of the register is confusing; in addition to
4120 * configuring the first vector of MSI-X, it also configures
4121 * which bits of EICR could be set by the hardware even when
4122 * MSI or line interrupt is used; it thus controls interrupt
4123 * generation. It MUST be configured explicitly; the default
4124 * value mentioned in the datasheet is wrong: RX queue0 and
4125 * TX queue0 are NOT enabled by default.
4127 E1000_WRITE_REG(&sc->hw, E1000_MSIXBM(0), sc->intr_mask);
4131 panic("unknown mac type %d\n", sc->hw.mac.type);
4136 igb_setup_intr(struct igb_softc *sc)
4140 for (i = 0; i < sc->intr_cnt; ++i) {
4141 struct igb_intr_data *intr = &sc->intr_data[i];
4144 error = bus_setup_intr_descr(sc->dev, intr->intr_res,
4145 INTR_MPSAFE, intr->intr_func, intr->intr_funcarg,
4146 &intr->intr_hand, intr->intr_serialize, intr->intr_desc);
4148 device_printf(sc->dev, "can't setup %dth intr\n", i);
4149 igb_teardown_intr(sc, i);
4157 igb_set_txintr_mask(struct igb_tx_ring *txr, int *intr_vec0, int intr_vecmax)
4159 if (txr->sc->hw.mac.type == e1000_82575) {
4160 txr->tx_intr_vec = 0; /* unused */
4163 txr->tx_intr_mask = E1000_EICR_TX_QUEUE0;
4166 txr->tx_intr_mask = E1000_EICR_TX_QUEUE1;
4169 txr->tx_intr_mask = E1000_EICR_TX_QUEUE2;
4172 txr->tx_intr_mask = E1000_EICR_TX_QUEUE3;
4175 panic("unsupported # of TX ring, %d\n", txr->me);
4178 int intr_vec = *intr_vec0;
4180 txr->tx_intr_vec = intr_vec % intr_vecmax;
4181 txr->tx_intr_mask = 1 << txr->tx_intr_vec;
4183 *intr_vec0 = intr_vec + 1;
4188 igb_set_rxintr_mask(struct igb_rx_ring *rxr, int *intr_vec0, int intr_vecmax)
4190 if (rxr->sc->hw.mac.type == e1000_82575) {
4191 rxr->rx_intr_vec = 0; /* unused */
4194 rxr->rx_intr_mask = E1000_EICR_RX_QUEUE0;
4197 rxr->rx_intr_mask = E1000_EICR_RX_QUEUE1;
4200 rxr->rx_intr_mask = E1000_EICR_RX_QUEUE2;
4203 rxr->rx_intr_mask = E1000_EICR_RX_QUEUE3;
4206 panic("unsupported # of RX ring, %d\n", rxr->me);
4209 int intr_vec = *intr_vec0;
4211 rxr->rx_intr_vec = intr_vec % intr_vecmax;
4212 rxr->rx_intr_mask = 1 << rxr->rx_intr_vec;
4214 *intr_vec0 = intr_vec + 1;
4219 igb_serialize(struct ifnet *ifp, enum ifnet_serialize slz)
4221 struct igb_softc *sc = ifp->if_softc;
4223 ifnet_serialize_array_enter(sc->serializes, sc->serialize_cnt, slz);
4227 igb_deserialize(struct ifnet *ifp, enum ifnet_serialize slz)
4229 struct igb_softc *sc = ifp->if_softc;
4231 ifnet_serialize_array_exit(sc->serializes, sc->serialize_cnt, slz);
4235 igb_tryserialize(struct ifnet *ifp, enum ifnet_serialize slz)
4237 struct igb_softc *sc = ifp->if_softc;
4239 return ifnet_serialize_array_try(sc->serializes, sc->serialize_cnt,
4246 igb_serialize_assert(struct ifnet *ifp, enum ifnet_serialize slz,
4247 boolean_t serialized)
4249 struct igb_softc *sc = ifp->if_softc;
4251 ifnet_serialize_array_assert(sc->serializes, sc->serialize_cnt,
4255 #endif /* INVARIANTS */
4258 igb_set_intr_mask(struct igb_softc *sc)
4262 sc->intr_mask = sc->sts_intr_mask;
4263 for (i = 0; i < sc->rx_ring_inuse; ++i)
4264 sc->intr_mask |= sc->rx_rings[i].rx_intr_mask;
4265 for (i = 0; i < sc->tx_ring_inuse; ++i)
4266 sc->intr_mask |= sc->tx_rings[i].tx_intr_mask;
4268 if_printf(&sc->arpcom.ac_if, "intr mask 0x%08x\n",
4274 igb_alloc_intr(struct igb_softc *sc)
4276 struct igb_tx_ring *txr;
4277 struct igb_intr_data *intr;
4278 int i, intr_vec, intr_vecmax;
4282 if (sc->intr_type == PCI_INTR_TYPE_MSIX) {
4283 igb_set_ring_inuse(sc, FALSE);
4288 * Reset some settings changed by igb_alloc_msix().
4290 if (sc->rx_rmap_intr != NULL) {
4291 if_ringmap_free(sc->rx_rmap_intr);
4292 sc->rx_rmap_intr = NULL;
4294 if (sc->tx_rmap_intr != NULL) {
4295 if_ringmap_free(sc->tx_rmap_intr);
4296 sc->tx_rmap_intr = NULL;
4298 if (sc->intr_data != NULL) {
4299 kfree(sc->intr_data, M_DEVBUF);
4300 sc->intr_data = NULL;
4302 for (i = 0; i < sc->tx_ring_cnt; ++i) {
4303 txr = &sc->tx_rings[i];
4304 txr->tx_intr_vec = 0;
4305 txr->tx_intr_mask = 0;
4306 txr->tx_intr_cpuid = -1;
4308 for (i = 0; i < sc->rx_ring_cnt; ++i) {
4309 struct igb_rx_ring *rxr = &sc->rx_rings[i];
4311 rxr->rx_intr_vec = 0;
4312 rxr->rx_intr_mask = 0;
4317 sc->intr_data = kmalloc(sizeof(struct igb_intr_data), M_DEVBUF,
4319 intr = &sc->intr_data[0];
4322 * Allocate MSI/legacy interrupt resource
4324 sc->intr_type = pci_alloc_1intr(sc->dev, igb_msi_enable,
4325 &intr->intr_rid, &intr_flags);
4327 if (sc->intr_type == PCI_INTR_TYPE_LEGACY) {
4330 unshared = device_getenv_int(sc->dev, "irq.unshared", 0);
4332 sc->flags |= IGB_FLAG_SHARED_INTR;
4334 device_printf(sc->dev, "IRQ shared\n");
4336 intr_flags &= ~RF_SHAREABLE;
4338 device_printf(sc->dev, "IRQ unshared\n");
4342 intr->intr_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ,
4343 &intr->intr_rid, intr_flags);
4344 if (intr->intr_res == NULL) {
4345 device_printf(sc->dev, "Unable to allocate bus resource: "
4350 intr->intr_serialize = &sc->main_serialize;
4351 intr->intr_cpuid = rman_get_cpuid(intr->intr_res);
4352 intr->intr_func = (sc->flags & IGB_FLAG_SHARED_INTR) ?
4353 igb_intr_shared : igb_intr;
4354 intr->intr_funcarg = sc;
4355 intr->intr_rate = IGB_INTR_RATE;
4356 intr->intr_use = IGB_INTR_USE_RXTX;
4358 sc->tx_rings[0].tx_intr_cpuid = intr->intr_cpuid;
4361 * Setup MSI/legacy interrupt mask
4363 switch (sc->hw.mac.type) {
4365 intr_vecmax = IGB_MAX_TXRXINT_82575;
4369 intr_vecmax = IGB_MAX_TXRXINT_82576;
4373 intr_vecmax = IGB_MAX_TXRXINT_82580;
4377 intr_vecmax = IGB_MAX_TXRXINT_I350;
4381 intr_vecmax = IGB_MAX_TXRXINT_I354;
4385 intr_vecmax = IGB_MAX_TXRXINT_I210;
4389 intr_vecmax = IGB_MAX_TXRXINT_I211;
4393 intr_vecmax = IGB_MIN_TXRXINT;
4397 for (i = 0; i < sc->tx_ring_cnt; ++i)
4398 igb_set_txintr_mask(&sc->tx_rings[i], &intr_vec, intr_vecmax);
4399 for (i = 0; i < sc->rx_ring_cnt; ++i)
4400 igb_set_rxintr_mask(&sc->rx_rings[i], &intr_vec, intr_vecmax);
4401 sc->sts_intr_mask = E1000_EICR_OTHER;
4403 igb_set_ring_inuse(sc, FALSE);
4404 KKASSERT(sc->rx_ring_inuse <= IGB_MIN_RING_RSS);
4405 if (sc->rx_ring_inuse == IGB_MIN_RING_RSS) {
4407 * Allocate RX ring map for RSS setup.
4409 sc->rx_rmap_intr = if_ringmap_alloc(sc->dev,
4410 IGB_MIN_RING_RSS, IGB_MIN_RING_RSS);
4411 KASSERT(if_ringmap_count(sc->rx_rmap_intr) ==
4412 sc->rx_ring_inuse, ("RX ring inuse mismatch"));
4415 igb_set_intr_mask(sc);
4416 for (i = 0; i < sc->tx_ring_cnt; ++i) {
4417 txr = &sc->tx_rings[i];
4418 if (txr->tx_intr_cpuid < 0)
4419 txr->tx_intr_cpuid = 0;
4425 igb_free_intr(struct igb_softc *sc)
4427 if (sc->intr_data == NULL)
4430 if (sc->intr_type != PCI_INTR_TYPE_MSIX) {
4431 struct igb_intr_data *intr = &sc->intr_data[0];
4433 KKASSERT(sc->intr_cnt == 1);
4434 if (intr->intr_res != NULL) {
4435 bus_release_resource(sc->dev, SYS_RES_IRQ,
4436 intr->intr_rid, intr->intr_res);
4438 if (sc->intr_type == PCI_INTR_TYPE_MSI)
4439 pci_release_msi(sc->dev);
4441 kfree(sc->intr_data, M_DEVBUF);
4443 igb_free_msix(sc, TRUE);
4448 igb_teardown_intr(struct igb_softc *sc, int intr_cnt)
4452 if (sc->intr_data == NULL)
4455 for (i = 0; i < intr_cnt; ++i) {
4456 struct igb_intr_data *intr = &sc->intr_data[i];
4458 bus_teardown_intr(sc->dev, intr->intr_res, intr->intr_hand);
4463 igb_alloc_msix(struct igb_softc *sc)
4465 int msix_enable, msix_cnt, msix_ring, alloc_cnt;
4467 int ring_cnt, ring_cntmax;
4468 struct igb_intr_data *intr;
4469 boolean_t setup = FALSE;
4472 * Don't enable MSI-X on 82575, see:
4473 * 82575 specification update errata #25
4475 if (sc->hw.mac.type == e1000_82575)
4478 /* Don't enable MSI-X on VF */
4482 msix_enable = device_getenv_int(sc->dev, "msix.enable",
4487 msix_cnt = pci_msix_count(sc->dev);
4488 #ifdef IGB_MSIX_DEBUG
4489 msix_cnt = device_getenv_int(sc->dev, "msix.count", msix_cnt);
4491 if (msix_cnt <= 1) {
4492 /* One MSI-X model does not make sense. */
4496 device_printf(sc->dev, "MSI-X count %d\n", msix_cnt);
4497 msix_ring = msix_cnt - 1; /* -1 for status */
4500 * Configure # of RX/TX rings usable by MSI-X.
4502 igb_get_rxring_cnt(sc, &ring_cnt, &ring_cntmax);
4503 if (ring_cntmax > msix_ring)
4504 ring_cntmax = msix_ring;
4505 sc->rx_rmap_intr = if_ringmap_alloc(sc->dev, ring_cnt, ring_cntmax);
4507 igb_get_txring_cnt(sc, &ring_cnt, &ring_cntmax);
4508 if (ring_cntmax > msix_ring)
4509 ring_cntmax = msix_ring;
4510 sc->tx_rmap_intr = if_ringmap_alloc(sc->dev, ring_cnt, ring_cntmax);
4512 if_ringmap_match(sc->dev, sc->rx_rmap_intr, sc->tx_rmap_intr);
4513 sc->rx_ring_msix = if_ringmap_count(sc->rx_rmap_intr);
4514 KASSERT(sc->rx_ring_msix <= sc->rx_ring_cnt,
4515 ("total RX ring count %d, MSI-X RX ring count %d",
4516 sc->rx_ring_cnt, sc->rx_ring_msix));
4517 sc->tx_ring_msix = if_ringmap_count(sc->tx_rmap_intr);
4518 KASSERT(sc->tx_ring_msix <= sc->tx_ring_cnt,
4519 ("total TX ring count %d, MSI-X TX ring count %d",
4520 sc->tx_ring_cnt, sc->tx_ring_msix));
4523 * Aggregate TX/RX MSI-X
4525 ring_cntmax = sc->rx_ring_msix;
4526 if (ring_cntmax < sc->tx_ring_msix)
4527 ring_cntmax = sc->tx_ring_msix;
4528 KASSERT(ring_cntmax <= msix_ring,
4529 ("invalid ring count max %d, MSI-X count for rings %d",
4530 ring_cntmax, msix_ring));
4532 alloc_cnt = ring_cntmax + 1; /* +1 for status */
4534 device_printf(sc->dev, "MSI-X alloc %d, "
4535 "RX ring %d, TX ring %d\n", alloc_cnt,
4536 sc->rx_ring_msix, sc->tx_ring_msix);
4539 sc->msix_mem_rid = PCIR_BAR(IGB_MSIX_BAR);
4540 sc->msix_mem_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
4541 &sc->msix_mem_rid, RF_ACTIVE);
4542 if (sc->msix_mem_res == NULL) {
4543 sc->msix_mem_rid = PCIR_BAR(IGB_MSIX_BAR_ALT);
4544 sc->msix_mem_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
4545 &sc->msix_mem_rid, RF_ACTIVE);
4546 if (sc->msix_mem_res == NULL) {
4547 device_printf(sc->dev, "Unable to map MSI-X table\n");
4552 sc->intr_cnt = alloc_cnt;
4553 sc->intr_data = kmalloc(sizeof(struct igb_intr_data) * sc->intr_cnt,
4554 M_DEVBUF, M_WAITOK | M_ZERO);
4555 for (x = 0; x < sc->intr_cnt; ++x) {
4556 intr = &sc->intr_data[x];
4557 intr->intr_rid = -1;
4558 intr->intr_rate = IGB_INTR_RATE;
4562 for (i = 0; i < sc->rx_ring_msix; ++i) {
4563 struct igb_rx_ring *rxr = &sc->rx_rings[i];
4564 struct igb_tx_ring *txr = NULL;
4567 KKASSERT(x < sc->intr_cnt);
4568 rxr->rx_intr_vec = x;
4569 rxr->rx_intr_mask = 1 << rxr->rx_intr_vec;
4571 cpuid = if_ringmap_cpumap(sc->rx_rmap_intr, i);
4574 * Try finding TX ring to piggyback.
4576 for (j = 0; j < sc->tx_ring_msix; ++j) {
4578 if_ringmap_cpumap(sc->tx_rmap_intr, j)) {
4579 txr = &sc->tx_rings[j];
4580 KKASSERT(txr->tx_intr_cpuid < 0);
4586 intr = &sc->intr_data[x++];
4587 intr->intr_serialize = &rxr->rx_serialize;
4588 intr->intr_cpuid = cpuid;
4589 KKASSERT(intr->intr_cpuid < netisr_ncpus);
4590 intr->intr_funcarg = rxr;
4592 intr->intr_func = igb_msix_rxtx;
4593 intr->intr_use = IGB_INTR_USE_RXTX;
4594 ksnprintf(intr->intr_desc0, sizeof(intr->intr_desc0),
4595 "%s rx%dtx%d", device_get_nameunit(sc->dev),
4598 txr->tx_intr_vec = rxr->rx_intr_vec;
4599 txr->tx_intr_mask = rxr->rx_intr_mask;
4600 txr->tx_intr_cpuid = intr->intr_cpuid;
4602 intr->intr_func = igb_msix_rx;
4603 intr->intr_rate = IGB_MSIX_RX_RATE;
4604 intr->intr_use = IGB_INTR_USE_RX;
4606 ksnprintf(intr->intr_desc0, sizeof(intr->intr_desc0),
4607 "%s rx%d", device_get_nameunit(sc->dev), i);
4609 intr->intr_desc = intr->intr_desc0;
4612 for (i = 0; i < sc->tx_ring_msix; ++i) {
4613 struct igb_tx_ring *txr = &sc->tx_rings[i];
4615 if (txr->tx_intr_cpuid >= 0) {
4616 /* Piggybacked by RX ring. */
4620 KKASSERT(x < sc->intr_cnt);
4621 txr->tx_intr_vec = x;
4622 txr->tx_intr_mask = 1 << txr->tx_intr_vec;
4624 intr = &sc->intr_data[x++];
4625 intr->intr_serialize = &txr->tx_serialize;
4626 intr->intr_func = igb_msix_tx;
4627 intr->intr_funcarg = txr;
4628 intr->intr_rate = IGB_MSIX_TX_RATE;
4629 intr->intr_use = IGB_INTR_USE_TX;
4631 intr->intr_cpuid = if_ringmap_cpumap(sc->tx_rmap_intr, i);
4632 KKASSERT(intr->intr_cpuid < netisr_ncpus);
4633 txr->tx_intr_cpuid = intr->intr_cpuid;
4635 ksnprintf(intr->intr_desc0, sizeof(intr->intr_desc0), "%s tx%d",
4636 device_get_nameunit(sc->dev), i);
4637 intr->intr_desc = intr->intr_desc0;
4643 KKASSERT(x < sc->intr_cnt);
4644 sc->sts_msix_vec = x;
4645 sc->sts_intr_mask = 1 << sc->sts_msix_vec;
4647 intr = &sc->intr_data[x++];
4648 intr->intr_serialize = &sc->main_serialize;
4649 intr->intr_func = igb_msix_status;
4650 intr->intr_funcarg = sc;
4651 intr->intr_cpuid = 0;
4652 intr->intr_use = IGB_INTR_USE_STATUS;
4654 ksnprintf(intr->intr_desc0, sizeof(intr->intr_desc0), "%s sts",
4655 device_get_nameunit(sc->dev));
4656 intr->intr_desc = intr->intr_desc0;
4658 KKASSERT(x == sc->intr_cnt);
4660 error = pci_setup_msix(sc->dev);
4662 device_printf(sc->dev, "Setup MSI-X failed\n");
4667 for (i = 0; i < sc->intr_cnt; ++i) {
4668 intr = &sc->intr_data[i];
4670 error = pci_alloc_msix_vector(sc->dev, i, &intr->intr_rid,
4673 device_printf(sc->dev,
4674 "Unable to allocate MSI-X %d on cpu%d\n", i,
4679 intr->intr_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ,
4680 &intr->intr_rid, RF_ACTIVE);
4681 if (intr->intr_res == NULL) {
4682 device_printf(sc->dev,
4683 "Unable to allocate MSI-X %d resource\n", i);
4689 pci_enable_msix(sc->dev);
4690 sc->intr_type = PCI_INTR_TYPE_MSIX;
4693 igb_free_msix(sc, setup);
4697 igb_free_msix(struct igb_softc *sc, boolean_t setup)
4701 KKASSERT(sc->intr_cnt > 1);
4703 for (i = 0; i < sc->intr_cnt; ++i) {
4704 struct igb_intr_data *intr = &sc->intr_data[i];
4706 if (intr->intr_res != NULL) {
4707 bus_release_resource(sc->dev, SYS_RES_IRQ,
4708 intr->intr_rid, intr->intr_res);
4710 if (intr->intr_rid >= 0)
4711 pci_release_msix_vector(sc->dev, intr->intr_rid);
4714 pci_teardown_msix(sc->dev);
4717 kfree(sc->intr_data, M_DEVBUF);
4718 sc->intr_data = NULL;
4722 igb_msix_rx(void *arg)
4724 struct igb_rx_ring *rxr = arg;
4726 ASSERT_SERIALIZED(&rxr->rx_serialize);
4729 E1000_WRITE_REG(&rxr->sc->hw, E1000_EIMS, rxr->rx_intr_mask);
4733 igb_msix_tx(void *arg)
4735 struct igb_tx_ring *txr = arg;
4737 ASSERT_SERIALIZED(&txr->tx_serialize);
4739 igb_tx_intr(txr, *(txr->tx_hdr));
4740 E1000_WRITE_REG(&txr->sc->hw, E1000_EIMS, txr->tx_intr_mask);
4744 igb_msix_status(void *arg)
4746 struct igb_softc *sc = arg;
4749 ASSERT_SERIALIZED(&sc->main_serialize);
4751 icr = E1000_READ_REG(&sc->hw, E1000_ICR);
4752 if (icr & E1000_ICR_LSC) {
4753 sc->hw.mac.get_link_status = 1;
4754 igb_update_link_status(sc);
4757 E1000_WRITE_REG(&sc->hw, E1000_EIMS, sc->sts_intr_mask);
4761 igb_set_ring_inuse(struct igb_softc *sc, boolean_t polling)
4763 sc->rx_ring_inuse = igb_get_rxring_inuse(sc, polling);
4764 sc->tx_ring_inuse = igb_get_txring_inuse(sc, polling);
4766 if_printf(&sc->arpcom.ac_if, "RX rings %d/%d, TX rings %d/%d\n",
4767 sc->rx_ring_inuse, sc->rx_ring_cnt,
4768 sc->tx_ring_inuse, sc->tx_ring_cnt);
4773 igb_get_rxring_inuse(const struct igb_softc *sc, boolean_t polling)
4775 if (!IGB_ENABLE_HWRSS(sc))
4779 return sc->rx_ring_cnt;
4780 else if (sc->intr_type != PCI_INTR_TYPE_MSIX)
4781 return IGB_MIN_RING_RSS;
4783 return sc->rx_ring_msix;
4787 igb_get_txring_inuse(const struct igb_softc *sc, boolean_t polling)
4789 if (!IGB_ENABLE_HWTSS(sc))
4793 return sc->tx_ring_cnt;
4794 else if (sc->intr_type != PCI_INTR_TYPE_MSIX)
4795 return IGB_MIN_RING;
4797 return sc->tx_ring_msix;
4801 igb_tso_pullup(struct igb_tx_ring *txr, struct mbuf **mp)
4803 int hoff, iphlen, thoff;
4807 KASSERT(M_WRITABLE(m), ("TSO mbuf not writable"));
4809 iphlen = m->m_pkthdr.csum_iphlen;
4810 thoff = m->m_pkthdr.csum_thlen;
4811 hoff = m->m_pkthdr.csum_lhlen;
4813 KASSERT(iphlen > 0, ("invalid ip hlen"));
4814 KASSERT(thoff > 0, ("invalid tcp hlen"));
4815 KASSERT(hoff > 0, ("invalid ether hlen"));
4817 if (__predict_false(m->m_len < hoff + iphlen + thoff)) {
4818 m = m_pullup(m, hoff + iphlen + thoff);
4825 if (txr->tx_flags & IGB_TXFLAG_TSO_IPLEN0) {
4828 ip = mtodoff(m, struct ip *, hoff);
4836 igb_tso_ctx(struct igb_tx_ring *txr, struct mbuf *m, uint32_t *hlen)
4838 struct e1000_adv_tx_context_desc *TXD;
4839 uint32_t vlan_macip_lens, type_tucmd_mlhl, mss_l4len_idx;
4840 int hoff, ctxd, iphlen, thoff;
4842 iphlen = m->m_pkthdr.csum_iphlen;
4843 thoff = m->m_pkthdr.csum_thlen;
4844 hoff = m->m_pkthdr.csum_lhlen;
4846 vlan_macip_lens = type_tucmd_mlhl = mss_l4len_idx = 0;
4848 ctxd = txr->next_avail_desc;
4849 TXD = (struct e1000_adv_tx_context_desc *)&txr->tx_base[ctxd];
4851 if (m->m_flags & M_VLANTAG) {
4854 vlantag = htole16(m->m_pkthdr.ether_vlantag);
4855 vlan_macip_lens |= (vlantag << E1000_ADVTXD_VLAN_SHIFT);
4858 vlan_macip_lens |= (hoff << E1000_ADVTXD_MACLEN_SHIFT);
4859 vlan_macip_lens |= iphlen;
4861 type_tucmd_mlhl |= E1000_ADVTXD_DCMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
4862 type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP;
4863 type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV4;
4865 mss_l4len_idx |= (m->m_pkthdr.tso_segsz << E1000_ADVTXD_MSS_SHIFT);
4866 mss_l4len_idx |= (thoff << E1000_ADVTXD_L4LEN_SHIFT);
4869 * 82575 needs the TX context index added; the queue
4870 * index is used as TX context index here.
4872 if (txr->sc->hw.mac.type == e1000_82575)
4873 mss_l4len_idx |= txr->me << 4;
4875 TXD->vlan_macip_lens = htole32(vlan_macip_lens);
4876 TXD->type_tucmd_mlhl = htole32(type_tucmd_mlhl);
4877 TXD->seqnum_seed = htole32(0);
4878 TXD->mss_l4len_idx = htole32(mss_l4len_idx);
4880 /* We've consumed the first desc, adjust counters */
4881 if (++ctxd == txr->num_tx_desc)
4883 txr->next_avail_desc = ctxd;
4886 *hlen = hoff + iphlen + thoff;
4890 igb_setup_serialize(struct igb_softc *sc)
4894 /* Main + RX + TX */
4895 sc->serialize_cnt = 1 + sc->rx_ring_cnt + sc->tx_ring_cnt;
4897 kmalloc(sc->serialize_cnt * sizeof(struct lwkt_serialize *),
4898 M_DEVBUF, M_WAITOK | M_ZERO);
4903 * NOTE: Order is critical
4906 KKASSERT(i < sc->serialize_cnt);
4907 sc->serializes[i++] = &sc->main_serialize;
4909 for (j = 0; j < sc->rx_ring_cnt; ++j) {
4910 KKASSERT(i < sc->serialize_cnt);
4911 sc->serializes[i++] = &sc->rx_rings[j].rx_serialize;
4914 for (j = 0; j < sc->tx_ring_cnt; ++j) {
4915 KKASSERT(i < sc->serialize_cnt);
4916 sc->serializes[i++] = &sc->tx_rings[j].tx_serialize;
4919 KKASSERT(i == sc->serialize_cnt);
4923 igb_msix_rxtx(void *arg)
4925 struct igb_rx_ring *rxr = arg;
4926 struct igb_tx_ring *txr;
4929 ASSERT_SERIALIZED(&rxr->rx_serialize);
4935 * Since next_to_clean is only changed by igb_txeof(),
4936 * which is called only in interrupt handler, the
4937 * check w/o holding tx serializer is MPSAFE.
4940 hdr = *(txr->tx_hdr);
4941 if (hdr != txr->next_to_clean) {
4942 lwkt_serialize_enter(&txr->tx_serialize);
4943 igb_tx_intr(txr, hdr);
4944 lwkt_serialize_exit(&txr->tx_serialize);
4947 E1000_WRITE_REG(&rxr->sc->hw, E1000_EIMS, rxr->rx_intr_mask);
4951 igb_set_timer_cpuid(struct igb_softc *sc, boolean_t polling)
4953 if (polling || sc->intr_type == PCI_INTR_TYPE_MSIX)
4954 sc->timer_cpuid = 0; /* XXX fixed */
4956 sc->timer_cpuid = rman_get_cpuid(sc->intr_data[0].intr_res);
4960 igb_init_dmac(struct igb_softc *sc, uint32_t pba)
4962 struct e1000_hw *hw = &sc->hw;
4965 if (hw->mac.type == e1000_i211)
4968 if (hw->mac.type > e1000_82580) {
4972 if (sc->dma_coalesce == 0) { /* Disabling it */
4973 reg = ~E1000_DMACR_DMAC_EN;
4974 E1000_WRITE_REG(hw, E1000_DMACR, reg);
4977 if_printf(&sc->arpcom.ac_if,
4978 "DMA Coalescing enabled\n");
4981 /* Set starting threshold */
4982 E1000_WRITE_REG(hw, E1000_DMCTXTH, 0);
4984 hwm = 64 * pba - sc->max_frame_size / 16;
4985 if (hwm < 64 * (pba - 6))
4986 hwm = 64 * (pba - 6);
4987 reg = E1000_READ_REG(hw, E1000_FCRTC);
4988 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
4989 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
4990 & E1000_FCRTC_RTH_COAL_MASK);
4991 E1000_WRITE_REG(hw, E1000_FCRTC, reg);
4993 dmac = pba - sc->max_frame_size / 512;
4994 if (dmac < pba - 10)
4996 reg = E1000_READ_REG(hw, E1000_DMACR);
4997 reg &= ~E1000_DMACR_DMACTHR_MASK;
4998 reg |= ((dmac << E1000_DMACR_DMACTHR_SHIFT)
4999 & E1000_DMACR_DMACTHR_MASK);
5001 /* transition to L0x or L1 if available..*/
5002 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
5005 * Check if status is 2.5Gb backplane connection
5006 * before configuration of watchdog timer, which
5007 * is in msec values in 12.8usec intervals watchdog
5008 * timer = msec values in 32usec intervals for non
5011 if (hw->mac.type == e1000_i354) {
5012 int status = E1000_READ_REG(hw, E1000_STATUS);
5014 if ((status & E1000_STATUS_2P5_SKU) &&
5015 !(status & E1000_STATUS_2P5_SKU_OVER))
5016 reg |= ((sc->dma_coalesce * 5) >> 6);
5018 reg |= (sc->dma_coalesce >> 5);
5020 reg |= (sc->dma_coalesce >> 5);
5023 E1000_WRITE_REG(hw, E1000_DMACR, reg);
5025 E1000_WRITE_REG(hw, E1000_DMCRTRH, 0);
5027 /* Set the interval before transition */
5028 reg = E1000_READ_REG(hw, E1000_DMCTLX);
5029 if (hw->mac.type == e1000_i350)
5030 reg |= IGB_DMCTLX_DCFLUSH_DIS;
5032 * In 2.5Gb connection, TTLX unit is 0.4 usec, which
5033 * is 0x4*2 = 0xA. But delay is still 4 usec.
5035 if (hw->mac.type == e1000_i354) {
5036 int status = E1000_READ_REG(hw, E1000_STATUS);
5038 if ((status & E1000_STATUS_2P5_SKU) &&
5039 !(status & E1000_STATUS_2P5_SKU_OVER))
5046 E1000_WRITE_REG(hw, E1000_DMCTLX, reg);
5048 /* Free space in tx packet buffer to wake from DMA coal */
5049 E1000_WRITE_REG(hw, E1000_DMCTXTH,
5050 (IGB_TXPBSIZE - (2 * sc->max_frame_size)) >> 6);
5052 /* Make low power state decision controlled by DMA coal */
5053 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
5054 reg &= ~E1000_PCIEMISC_LX_DECISION;
5055 E1000_WRITE_REG(hw, E1000_PCIEMISC, reg);
5056 } else if (hw->mac.type == e1000_82580) {
5057 reg = E1000_READ_REG(hw, E1000_PCIEMISC);
5058 E1000_WRITE_REG(hw, E1000_PCIEMISC,
5059 reg & ~E1000_PCIEMISC_LX_DECISION);
5060 E1000_WRITE_REG(hw, E1000_DMACR, 0);
5065 igb_reg_dump(struct igb_softc *sc)
5067 device_t dev = sc->dev;
5070 #define DUMPREG(regno) \
5071 kprintf(" %13s=%08x", #regno + 6, E1000_READ_REG(&sc->hw, regno));\
5077 device_printf(dev, "REGISTER DUMP\n");
5078 DUMPREG(E1000_CTRL);
5079 DUMPREG(E1000_STATUS);
5080 DUMPREG(E1000_EECD);
5081 DUMPREG(E1000_EERD);
5082 DUMPREG(E1000_CTRL_EXT);
5084 DUMPREG(E1000_MDIC);
5085 DUMPREG(E1000_SCTL);
5086 DUMPREG(E1000_FCAL);
5087 DUMPREG(E1000_FCAH);
5089 DUMPREG(E1000_CONNSW);
5094 DUMPREG(E1000_IVAR);
5095 DUMPREG(E1000_SVCR);
5097 DUMPREG(E1000_LPIC);
5098 DUMPREG(E1000_RCTL);
5099 DUMPREG(E1000_FCTTV);
5100 DUMPREG(E1000_TXCW);
5101 DUMPREG(E1000_RXCW);
5102 DUMPREG(E1000_EIMS);
5103 DUMPREG(E1000_EIAC);
5104 DUMPREG(E1000_EIAM);
5105 DUMPREG(E1000_GPIE);
5106 DUMPREG(E1000_IVAR0);
5107 DUMPREG(E1000_IVAR_MISC);
5108 DUMPREG(E1000_TCTL);
5109 DUMPREG(E1000_TCTL_EXT);
5110 DUMPREG(E1000_TIPG);
5113 DUMPREG(E1000_LEDCTL);
5114 DUMPREG(E1000_EXTCNF_CTRL);
5115 DUMPREG(E1000_EXTCNF_SIZE);
5116 DUMPREG(E1000_PHY_CTRL);
5119 DUMPREG(E1000_PBECCSTS);
5120 DUMPREG(E1000_EEMNGCTL);
5121 DUMPREG(E1000_EEARBC);
5122 DUMPREG(E1000_FLASHT);
5123 DUMPREG(E1000_EEARBC_I210);
5124 DUMPREG(E1000_EEWR);
5125 DUMPREG(E1000_FLSWCTL);
5126 DUMPREG(E1000_FLSWDATA);
5127 DUMPREG(E1000_FLSWCNT);
5128 DUMPREG(E1000_FLOP);
5129 DUMPREG(E1000_I2CCMD);
5130 DUMPREG(E1000_I2CPARAMS);
5131 DUMPREG(E1000_WDSTP);
5132 DUMPREG(E1000_SWDSTS);
5133 DUMPREG(E1000_FRTIMER);
5134 DUMPREG(E1000_TCPTIMER);
5135 DUMPREG(E1000_VPDDIAG);
5136 DUMPREG(E1000_IMS_V2);
5137 DUMPREG(E1000_IAM_V2);
5139 DUMPREG(E1000_FCRTL);
5140 DUMPREG(E1000_FCRTH);
5141 DUMPREG(E1000_PSRCTL);
5142 DUMPREG(E1000_RDFH);
5143 DUMPREG(E1000_RDFT);
5144 DUMPREG(E1000_RDFHS);
5145 DUMPREG(E1000_RDFTS);
5146 DUMPREG(E1000_RDFPC);
5147 DUMPREG(E1000_PBRTH);
5148 DUMPREG(E1000_FCRTV);
5149 DUMPREG(E1000_RDPUMB);
5150 DUMPREG(E1000_RDPUAD);
5151 DUMPREG(E1000_RDPUWD);
5152 DUMPREG(E1000_RDPURD);
5153 DUMPREG(E1000_RDPUCTL);
5154 DUMPREG(E1000_PBDIAG);
5155 DUMPREG(E1000_RXPBS);
5156 DUMPREG(E1000_IRPBS);
5157 DUMPREG(E1000_PBRWAC);
5158 DUMPREG(E1000_RDTR);
5159 DUMPREG(E1000_RADV);
5160 DUMPREG(E1000_SRWR);
5161 DUMPREG(E1000_I210_FLMNGCTL);
5162 DUMPREG(E1000_I210_FLMNGDATA);
5163 DUMPREG(E1000_I210_FLMNGCNT);
5164 DUMPREG(E1000_I210_FLSWCTL);
5165 DUMPREG(E1000_I210_FLSWDATA);
5166 DUMPREG(E1000_I210_FLSWCNT);
5167 DUMPREG(E1000_I210_FLA);
5168 DUMPREG(E1000_INVM_SIZE);
5169 DUMPREG(E1000_I210_TQAVCTRL);
5170 DUMPREG(E1000_RSRPD);
5171 DUMPREG(E1000_RAID);
5172 DUMPREG(E1000_TXDMAC);
5173 DUMPREG(E1000_KABGTXD);
5174 DUMPREG(E1000_PBSLAC);
5175 DUMPREG(E1000_TXPBS);
5176 DUMPREG(E1000_ITPBS);
5177 DUMPREG(E1000_TDFH);
5178 DUMPREG(E1000_TDFT);
5179 DUMPREG(E1000_TDFHS);
5180 DUMPREG(E1000_TDFTS);
5181 DUMPREG(E1000_TDFPC);
5182 DUMPREG(E1000_TDPUMB);
5183 DUMPREG(E1000_TDPUAD);
5184 DUMPREG(E1000_TDPUWD);
5185 DUMPREG(E1000_TDPURD);
5186 DUMPREG(E1000_TDPUCTL);
5187 DUMPREG(E1000_DTXCTL);
5188 DUMPREG(E1000_DTXTCPFLGL);
5189 DUMPREG(E1000_DTXTCPFLGH);
5190 DUMPREG(E1000_DTXMXSZRQ);
5191 DUMPREG(E1000_TIDV);
5192 DUMPREG(E1000_TADV);
5193 DUMPREG(E1000_TSPMT);
5194 DUMPREG(E1000_VFGPRC);
5195 DUMPREG(E1000_VFGORC);
5196 DUMPREG(E1000_VFMPRC);
5197 DUMPREG(E1000_VFGPTC);
5198 DUMPREG(E1000_VFGOTC);
5199 DUMPREG(E1000_VFGOTLBC);
5200 DUMPREG(E1000_VFGPTLBC);
5201 DUMPREG(E1000_VFGORLBC);
5202 DUMPREG(E1000_VFGPRLBC);
5203 DUMPREG(E1000_LSECTXCAP);
5204 DUMPREG(E1000_LSECRXCAP);
5205 DUMPREG(E1000_LSECTXCTRL);
5206 DUMPREG(E1000_LSECRXCTRL);
5207 DUMPREG(E1000_LSECTXSCL);
5208 DUMPREG(E1000_LSECTXSCH);
5209 DUMPREG(E1000_LSECTXSA);
5210 DUMPREG(E1000_LSECTXPN0);
5211 DUMPREG(E1000_LSECTXPN1);
5212 DUMPREG(E1000_LSECRXSCL);
5213 DUMPREG(E1000_LSECRXSCH);
5214 DUMPREG(E1000_IPSCTRL);
5215 DUMPREG(E1000_IPSRXCMD);
5216 DUMPREG(E1000_IPSRXIDX);
5217 DUMPREG(E1000_IPSRXSALT);
5218 DUMPREG(E1000_IPSRXSPI);
5219 DUMPREG(E1000_IPSTXSALT);
5220 DUMPREG(E1000_IPSTXIDX);
5221 DUMPREG(E1000_PCS_CFG0);
5222 DUMPREG(E1000_PCS_LCTL);
5223 DUMPREG(E1000_PCS_LSTAT);
5224 DUMPREG(E1000_PCS_ANADV);
5225 DUMPREG(E1000_PCS_LPAB);
5226 DUMPREG(E1000_PCS_NPTX);
5227 DUMPREG(E1000_PCS_LPABNP);
5228 DUMPREG(E1000_RXCSUM);
5229 DUMPREG(E1000_RLPML);
5230 DUMPREG(E1000_RFCTL);
5234 DUMPREG(E1000_VFTA);
5235 DUMPREG(E1000_VT_CTL);
5236 DUMPREG(E1000_CIAA);
5237 DUMPREG(E1000_CIAD);
5238 DUMPREG(E1000_VFQA0);
5239 DUMPREG(E1000_VFQA1);
5241 DUMPREG(E1000_WUFC);
5243 DUMPREG(E1000_MANC);
5244 DUMPREG(E1000_IPAV);
5245 DUMPREG(E1000_IP4AT);
5246 DUMPREG(E1000_IP6AT);
5247 DUMPREG(E1000_WUPL);
5248 DUMPREG(E1000_WUPM);
5249 DUMPREG(E1000_PBACL);
5250 DUMPREG(E1000_FFLT);
5251 DUMPREG(E1000_HOST_IF);
5252 DUMPREG(E1000_HIBBA);
5253 DUMPREG(E1000_KMRNCTRLSTA);
5254 DUMPREG(E1000_MANC2H);
5255 DUMPREG(E1000_CCMCTL);
5256 DUMPREG(E1000_GIOCTL);
5257 DUMPREG(E1000_SCCTL);
5259 #define E1000_WCS 0x558C
5261 #define E1000_GCR_EXT 0x586C
5262 DUMPREG(E1000_GCR_EXT);
5264 DUMPREG(E1000_GCR2);
5265 DUMPREG(E1000_FACTPS);
5266 DUMPREG(E1000_DCA_ID);
5267 DUMPREG(E1000_DCA_CTRL);
5268 DUMPREG(E1000_UFUSE);
5269 DUMPREG(E1000_FFLT_DBG);
5270 DUMPREG(E1000_HICR);
5271 DUMPREG(E1000_FWSTS);
5272 DUMPREG(E1000_CPUVEC);
5273 DUMPREG(E1000_MRQC);
5274 DUMPREG(E1000_SWPBS);
5275 DUMPREG(E1000_MBVFICR);
5276 DUMPREG(E1000_MBVFIMR);
5277 DUMPREG(E1000_VFLRE);
5278 DUMPREG(E1000_VFRE);
5279 DUMPREG(E1000_VFTE);
5281 DUMPREG(E1000_DTXSWC);
5282 DUMPREG(E1000_WVBR);
5283 DUMPREG(E1000_RPLOLR);
5285 DUMPREG(E1000_IOVTCL);
5286 DUMPREG(E1000_VMRCTL);
5287 DUMPREG(E1000_VMRVLAN);
5288 DUMPREG(E1000_VMRVM);
5289 DUMPREG(E1000_LVMMC);
5290 DUMPREG(E1000_TXSWC);
5291 DUMPREG(E1000_SCCRL);
5292 DUMPREG(E1000_BSCTRH);
5293 DUMPREG(E1000_MSCTRH);
5294 DUMPREG(E1000_RXSTMPL);
5295 DUMPREG(E1000_RXSTMPH);
5296 DUMPREG(E1000_RXSATRL);
5297 DUMPREG(E1000_RXSATRH);
5298 DUMPREG(E1000_TXSTMPL);
5299 DUMPREG(E1000_TXSTMPH);
5300 DUMPREG(E1000_TIMINCA);
5301 DUMPREG(E1000_TIMADJL);
5302 DUMPREG(E1000_TIMADJH);
5303 DUMPREG(E1000_TSAUXC);
5304 DUMPREG(E1000_SYSSTMPL);
5305 DUMPREG(E1000_SYSSTMPH);
5306 DUMPREG(E1000_PLTSTMPL);
5307 DUMPREG(E1000_PLTSTMPH);
5308 DUMPREG(E1000_RXMTRL);
5309 DUMPREG(E1000_RXUDP);
5310 DUMPREG(E1000_SYSTIMR);
5311 DUMPREG(E1000_TSICR);
5312 DUMPREG(E1000_TSIM);
5313 DUMPREG(E1000_DMACR);
5314 DUMPREG(E1000_DMCTXTH);
5315 DUMPREG(E1000_DMCTLX);
5316 DUMPREG(E1000_DMCRTRH);
5317 DUMPREG(E1000_DMCCNT);
5318 DUMPREG(E1000_FCRTC);
5319 DUMPREG(E1000_PCIEMISC);
5320 DUMPREG(E1000_PCIEERRSTS);
5321 DUMPREG(E1000_IPCNFG);
5322 DUMPREG(E1000_LTRC);
5323 DUMPREG(E1000_EEER);
5324 DUMPREG(E1000_EEE_SU);
5325 DUMPREG(E1000_TLPIC);
5326 DUMPREG(E1000_RLPIC);
5333 igb_sysctl_reg_dump(SYSCTL_HANDLER_ARGS)
5335 struct igb_softc *sc = (void *)arg1;
5336 struct ifnet *ifp = &sc->arpcom.ac_if;
5337 int error, dump = 0;
5339 error = sysctl_handle_int(oidp, &dump, 0, req);
5340 if (error || req->newptr == NULL)
5345 ifnet_serialize_all(ifp);
5347 ifnet_deserialize_all(ifp);