2 * Copyright (c) 1997, 1998, 1999, 2000-2003
3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/dev/usb/if_axe.c,v 1.10 2003/12/08 07:54:14 obrien Exp $
33 * $DragonFly: src/sys/dev/netif/axe/if_axe.c,v 1.7 2004/09/27 05:57:58 asmodai Exp $
36 * ASIX Electronics AX88172 USB 2.0 ethernet driver. Used in the
37 * LinkSys USB200M and various other adapters.
39 * Manuals available from:
40 * http://www.asix.com.tw/datasheet/mac/Ax88172.PDF
41 * Note: you need the manual for the AX88170 chip (USB 1.x ethernet
42 * controller) to find the definitions for the RX control register.
43 * http://www.asix.com.tw/datasheet/mac/Ax88170.PDF
45 * Written by Bill Paul <wpaul@windriver.com>
51 * The AX88172 provides USB ethernet supports at 10 and 100Mbps.
52 * It uses an external PHY (reference designs use a RealTek chip),
53 * and has a 64-bit multicast hash filter. There is some information
54 * missing from the manual which one needs to know in order to make
57 * - You must set bit 7 in the RX control register, otherwise the
58 * chip won't receive any packets.
59 * - You must initialize all 3 IPG registers, or you won't be able
60 * to send any packets.
62 * Note that this device appears to only support loading the station
63 * address via autload from the EEPROM (i.e. there's no way to manaully
66 * (Adam Weinberger wanted me to name this driver if_gir.c.)
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/sockio.h>
73 #include <sys/malloc.h>
74 #include <sys/kernel.h>
75 #include <sys/socket.h>
78 #include <net/if_arp.h>
79 #include <net/ethernet.h>
80 #include <net/if_dl.h>
81 #include <net/if_media.h>
86 #include <machine/bus.h>
88 #include <bus/usb/usb.h>
89 #include <bus/usb/usbdi.h>
90 #include <bus/usb/usbdi_util.h>
91 #include <bus/usb/usbdivar.h>
92 #include <bus/usb/usbdevs.h>
93 #include <bus/usb/usb_ethersubr.h>
95 #include "../mii_layer//mii.h"
96 #include "../mii_layer/miivar.h"
98 /* "controller miibus0" required. See GENERIC if you get errors here. */
99 #include "miibus_if.h"
101 #include "if_axereg.h"
104 * Various supported device vendors/products.
106 Static struct axe_type axe_devs[] = {
107 { USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88172 },
108 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DUBE100 },
109 { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_USB200M },
110 { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA120 },
114 Static struct usb_qdat axe_qdat;
116 Static int axe_match(device_ptr_t);
117 Static int axe_attach(device_ptr_t);
118 Static int axe_detach(device_ptr_t);
120 Static int axe_tx_list_init(struct axe_softc *);
121 Static int axe_rx_list_init(struct axe_softc *);
122 Static int axe_newbuf(struct axe_softc *, struct axe_chain *, struct mbuf *);
123 Static int axe_encap(struct axe_softc *, struct mbuf *, int);
124 Static void axe_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
125 Static void axe_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
126 Static void axe_tick(void *);
127 Static void axe_rxstart(struct ifnet *);
128 Static void axe_start(struct ifnet *);
129 Static int axe_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
130 Static void axe_init(void *);
131 Static void axe_stop(struct axe_softc *);
132 Static void axe_watchdog(struct ifnet *);
133 Static void axe_shutdown(device_ptr_t);
134 Static int axe_miibus_readreg(device_ptr_t, int, int);
135 Static int axe_miibus_writereg(device_ptr_t, int, int, int);
136 Static void axe_miibus_statchg(device_ptr_t);
137 Static int axe_cmd(struct axe_softc *, int, int, int, void *);
138 Static int axe_ifmedia_upd(struct ifnet *);
139 Static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
141 Static void axe_setmulti(struct axe_softc *);
142 Static uint32_t axe_mchash(const uint8_t *);
144 Static device_method_t axe_methods[] = {
145 /* Device interface */
146 DEVMETHOD(device_probe, axe_match),
147 DEVMETHOD(device_attach, axe_attach),
148 DEVMETHOD(device_detach, axe_detach),
149 DEVMETHOD(device_shutdown, axe_shutdown),
152 DEVMETHOD(bus_print_child, bus_generic_print_child),
153 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
156 DEVMETHOD(miibus_readreg, axe_miibus_readreg),
157 DEVMETHOD(miibus_writereg, axe_miibus_writereg),
158 DEVMETHOD(miibus_statchg, axe_miibus_statchg),
163 Static driver_t axe_driver = {
166 sizeof(struct axe_softc)
169 Static devclass_t axe_devclass;
171 DRIVER_MODULE(axe, uhub, axe_driver, axe_devclass, usbd_driver_load, 0);
172 DRIVER_MODULE(miibus, axe, miibus_driver, miibus_devclass, 0, 0);
173 MODULE_DEPEND(axe, usb, 1, 1, 1);
174 MODULE_DEPEND(axe, miibus, 1, 1, 1);
177 axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
179 usb_device_request_t req;
185 if (AXE_CMD_DIR(cmd))
186 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
188 req.bmRequestType = UT_READ_VENDOR_DEVICE;
189 req.bRequest = AXE_CMD_CMD(cmd);
190 USETW(req.wValue, val);
191 USETW(req.wIndex, index);
192 USETW(req.wLength, AXE_CMD_LEN(cmd));
194 err = usbd_do_request(sc->axe_udev, &req, buf);
203 axe_miibus_readreg(device_ptr_t dev, int phy, int reg)
205 struct axe_softc *sc = USBGETSOFTC(dev);
215 * The chip tells us the MII address of any supported
216 * PHYs attached to the chip, so only read from those.
219 if (sc->axe_phyaddrs[0] != AXE_NOPHY && phy != sc->axe_phyaddrs[0])
222 if (sc->axe_phyaddrs[1] != AXE_NOPHY && phy != sc->axe_phyaddrs[1])
225 if (sc->axe_phyaddrs[0] != 0xFF && sc->axe_phyaddrs[0] != phy)
229 axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
230 err = axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, (void *)&val);
231 axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
235 printf("axe%d: read PHY failed\n", sc->axe_unit);
240 sc->axe_phyaddrs[0] = phy;
246 axe_miibus_writereg(device_ptr_t dev, int phy, int reg, int val)
248 struct axe_softc *sc = USBGETSOFTC(dev);
256 axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
257 err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, (void *)&val);
258 axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
262 printf("axe%d: write PHY failed\n", sc->axe_unit);
270 axe_miibus_statchg(device_ptr_t dev)
273 struct axe_softc *sc = USBGETSOFTC(dev);
274 struct mii_data *mii = GET_MII(sc);
276 /* doesn't seem to be necessary */
285 axe_ifmedia_upd(struct ifnet *ifp)
287 struct axe_softc *sc = ifp->if_softc;
288 struct mii_data *mii = GET_MII(sc);
291 if (mii->mii_instance) {
292 struct mii_softc *miisc;
293 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
294 mii_phy_reset(miisc);
302 * Report current media status.
305 axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
307 struct axe_softc *sc = ifp->if_softc;
308 struct mii_data *mii = GET_MII(sc);
311 ifmr->ifm_active = mii->mii_media_active;
312 ifmr->ifm_status = mii->mii_media_status;
318 axe_mchash(const uint8_t *addr)
324 /* Compute CRC for the address value. */
325 crc = 0xFFFFFFFF; /* initial value */
327 for (idx = 0; idx < 6; idx++) {
328 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) {
329 carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
332 crc = (crc ^ 0x04c11db6) | carry;
336 /* return the filter bit position */
337 return((crc >> 26) & 0x0000003F);
341 axe_setmulti(struct axe_softc *sc)
344 struct ifmultiaddr *ifma;
347 u_int8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
350 ifp = &sc->arpcom.ac_if;
353 axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, (void *)&rxmode);
355 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
356 rxmode |= AXE_RXCMD_ALLMULTI;
357 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
361 rxmode &= ~AXE_RXCMD_ALLMULTI;
363 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
364 if (ifma->ifma_addr->sa_family != AF_LINK)
366 h = axe_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
367 hashtbl[h / 8] |= 1 << (h % 8);
370 axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl);
371 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
377 axe_reset(struct axe_softc *sc)
382 if (usbd_set_config_no(sc->axe_udev, AXE_CONFIG_NO, 1) ||
383 usbd_device2interface_handle(sc->axe_udev, AXE_IFACE_IDX,
385 printf("axe%d: getting interface handle failed\n",
389 /* Wait a little while for the chip to get its brains in order. */
395 * Probe for a AX88172 chip.
399 USB_MATCH_START(axe, uaa);
407 if (uaa->vendor == t->axe_vid &&
408 uaa->product == t->axe_did) {
409 return(UMATCH_VENDOR_PRODUCT);
418 * Attach the interface. Allocate softc structures, do ifmedia
419 * setup and ethernet/BPF attach.
423 USB_ATTACH_START(axe, sc, uaa);
425 u_char eaddr[ETHER_ADDR_LEN];
427 usb_interface_descriptor_t *id;
428 usb_endpoint_descriptor_t *ed;
431 bzero(sc, sizeof(struct axe_softc));
432 sc->axe_udev = uaa->device;
434 sc->axe_unit = device_get_unit(self);
435 callout_init(&sc->axe_stat_timer);
437 if (usbd_set_config_no(sc->axe_udev, AXE_CONFIG_NO, 1)) {
438 printf("axe%d: getting interface handle failed\n",
440 USB_ATTACH_ERROR_RETURN;
443 if (usbd_device2interface_handle(uaa->device,
444 AXE_IFACE_IDX, &sc->axe_iface)) {
445 printf("axe%d: getting interface handle failed\n",
447 USB_ATTACH_ERROR_RETURN;
450 id = usbd_get_interface_descriptor(sc->axe_iface);
452 usbd_devinfo(uaa->device, 0, devinfo);
453 device_set_desc_copy(self, devinfo);
454 printf("%s: %s\n", USBDEVNAME(self), devinfo);
456 /* Find endpoints. */
457 for (i = 0; i < id->bNumEndpoints; i++) {
458 ed = usbd_interface2endpoint_descriptor(sc->axe_iface, i);
460 printf("axe%d: couldn't get ep %d\n",
462 USB_ATTACH_ERROR_RETURN;
464 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
465 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
466 sc->axe_ed[AXE_ENDPT_RX] = ed->bEndpointAddress;
467 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
468 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
469 sc->axe_ed[AXE_ENDPT_TX] = ed->bEndpointAddress;
470 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
471 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
472 sc->axe_ed[AXE_ENDPT_INTR] = ed->bEndpointAddress;
477 * Get station address.
479 axe_cmd(sc, AXE_CMD_READ_NODEID, 0, 0, &eaddr);
482 * Load IPG values and PHY indexes.
484 axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, (void *)&sc->axe_ipgs);
485 axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs);
488 * Work around broken adapters that appear to lie about
489 * their PHY addresses.
491 sc->axe_phyaddrs[0] = sc->axe_phyaddrs[1] = 0xFF;
493 ifp = &sc->arpcom.ac_if;
495 if_initname(ifp, "axe", sc->axe_unit);
496 ifp->if_mtu = ETHERMTU;
497 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
498 ifp->if_ioctl = axe_ioctl;
499 ifp->if_start = axe_start;
500 ifp->if_watchdog = axe_watchdog;
501 ifp->if_init = axe_init;
502 ifp->if_baudrate = 10000000;
503 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
506 axe_qdat.if_rxstart = axe_rxstart;
508 if (mii_phy_probe(self, &sc->axe_miibus,
509 axe_ifmedia_upd, axe_ifmedia_sts)) {
510 printf("axe%d: MII without any PHY!\n", sc->axe_unit);
511 USB_ATTACH_ERROR_RETURN;
515 * Call MI attach routine.
518 ether_ifattach(ifp, eaddr);
522 usb_register_netisr();
524 USB_ATTACH_SUCCESS_RETURN;
528 axe_detach(device_ptr_t dev)
530 struct axe_softc *sc;
534 sc = device_get_softc(dev);
535 ifp = &sc->arpcom.ac_if;
539 callout_stop(&sc->axe_stat_timer);
542 if (sc->axe_ep[AXE_ENDPT_TX] != NULL)
543 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
544 if (sc->axe_ep[AXE_ENDPT_RX] != NULL)
545 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]);
546 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL)
547 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
555 * Initialize an RX descriptor and attach an MBUF cluster.
558 axe_newbuf(struct axe_softc *sc, struct axe_chain *c, struct mbuf *m)
560 struct mbuf *m_new = NULL;
563 m_new = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
565 printf("axe%d: no memory for rx list "
566 "-- packet dropped!\n", sc->axe_unit);
569 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
572 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
573 m_new->m_data = m_new->m_ext.ext_buf;
576 m_adj(m_new, ETHER_ALIGN);
583 axe_rx_list_init(struct axe_softc *sc)
585 struct axe_cdata *cd;
590 for (i = 0; i < AXE_RX_LIST_CNT; i++) {
591 c = &cd->axe_rx_chain[i];
594 if (axe_newbuf(sc, c, NULL) == ENOBUFS)
596 if (c->axe_xfer == NULL) {
597 c->axe_xfer = usbd_alloc_xfer(sc->axe_udev);
598 if (c->axe_xfer == NULL)
607 axe_tx_list_init(struct axe_softc *sc)
609 struct axe_cdata *cd;
614 for (i = 0; i < AXE_TX_LIST_CNT; i++) {
615 c = &cd->axe_tx_chain[i];
619 if (c->axe_xfer == NULL) {
620 c->axe_xfer = usbd_alloc_xfer(sc->axe_udev);
621 if (c->axe_xfer == NULL)
624 c->axe_buf = malloc(AXE_BUFSZ, M_USBDEV, M_WAITOK);
625 if (c->axe_buf == NULL)
633 axe_rxstart(struct ifnet *ifp)
635 struct axe_softc *sc;
641 c = &sc->axe_cdata.axe_rx_chain[sc->axe_cdata.axe_rx_prod];
643 if (axe_newbuf(sc, c, NULL) == ENOBUFS) {
649 /* Setup new transfer. */
650 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
651 c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK,
652 USBD_NO_TIMEOUT, axe_rxeof);
653 usbd_transfer(c->axe_xfer);
660 * A frame has been uploaded: pass the resulting mbuf chain up to
661 * the higher level protocols.
664 axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
666 struct axe_softc *sc;
670 int s, total_len = 0;
675 ifp = &sc->arpcom.ac_if;
677 if (!(ifp->if_flags & IFF_RUNNING)) {
682 if (status != USBD_NORMAL_COMPLETION) {
683 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
687 if (usbd_ratecheck(&sc->axe_rx_notice))
688 printf("axe%d: usb error on rx: %s\n", sc->axe_unit,
689 usbd_errstr(status));
690 if (status == USBD_STALLED)
691 usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_RX]);
695 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
699 if (total_len < sizeof(struct ether_header)) {
705 m->m_pkthdr.rcvif = (struct ifnet *)&axe_qdat;
706 m->m_pkthdr.len = m->m_len = total_len;
708 /* Put the packet on the special USB input queue. */
714 /* Setup new transfer. */
715 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
716 c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK,
717 USBD_NO_TIMEOUT, axe_rxeof);
718 usbd_transfer(c->axe_xfer);
725 * A frame was downloaded to the chip. It's safe for us to clean up
730 axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
732 struct axe_softc *sc;
740 ifp = &sc->arpcom.ac_if;
744 if (status != USBD_NORMAL_COMPLETION) {
745 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
749 printf("axe%d: usb error on tx: %s\n", sc->axe_unit,
750 usbd_errstr(status));
751 if (status == USBD_STALLED)
752 usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_TX]);
758 ifp->if_flags &= ~IFF_OACTIVE;
759 usbd_get_xfer_status(c->axe_xfer, NULL, NULL, NULL, &err);
761 if (c->axe_mbuf != NULL) {
762 c->axe_mbuf->m_pkthdr.rcvif = ifp;
763 usb_tx_done(c->axe_mbuf);
778 struct axe_softc *sc;
780 struct mii_data *mii;
788 ifp = &sc->arpcom.ac_if;
796 if (!sc->axe_link && mii->mii_media_status & IFM_ACTIVE &&
797 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
799 if (ifp->if_snd.ifq_head != NULL)
803 callout_reset(&sc->axe_stat_timer, hz, axe_tick, sc);
809 axe_encap(struct axe_softc *sc, struct mbuf *m, int idx)
814 c = &sc->axe_cdata.axe_tx_chain[idx];
817 * Copy the mbuf data into a contiguous buffer, leaving two
818 * bytes at the beginning to hold the frame length.
820 m_copydata(m, 0, m->m_pkthdr.len, c->axe_buf);
823 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_TX],
824 c, c->axe_buf, m->m_pkthdr.len, 0, 10000, axe_txeof);
827 err = usbd_transfer(c->axe_xfer);
828 if (err != USBD_IN_PROGRESS) {
833 sc->axe_cdata.axe_tx_cnt++;
839 axe_start(struct ifnet *ifp)
841 struct axe_softc *sc;
842 struct mbuf *m_head = NULL;
853 if (ifp->if_flags & IFF_OACTIVE) {
858 IF_DEQUEUE(&ifp->if_snd, m_head);
859 if (m_head == NULL) {
864 if (axe_encap(sc, m_head, 0)) {
865 IF_PREPEND(&ifp->if_snd, m_head);
866 ifp->if_flags |= IFF_OACTIVE;
872 * If there's a BPF listener, bounce a copy of this frame
875 BPF_MTAP(ifp, m_head);
877 ifp->if_flags |= IFF_OACTIVE;
880 * Set a timeout in case the chip goes out to lunch.
889 struct axe_softc *sc = xsc;
890 struct ifnet *ifp = &sc->arpcom.ac_if;
895 if (ifp->if_flags & IFF_RUNNING)
901 * Cancel pending I/O and free all RX/TX buffers.
907 /* Set MAC address */
908 axe_mac(sc, sc->arpcom.ac_enaddr, 1);
911 /* Enable RX logic. */
914 if (axe_tx_list_init(sc) == ENOBUFS) {
915 printf("axe%d: tx list init failed\n", sc->axe_unit);
921 if (axe_rx_list_init(sc) == ENOBUFS) {
922 printf("axe%d: rx list init failed\n", sc->axe_unit);
927 /* Set transmitter IPG values */
928 axe_cmd(sc, AXE_CMD_WRITE_IPG0, 0, sc->axe_ipgs[0], NULL);
929 axe_cmd(sc, AXE_CMD_WRITE_IPG1, 0, sc->axe_ipgs[1], NULL);
930 axe_cmd(sc, AXE_CMD_WRITE_IPG2, 0, sc->axe_ipgs[2], NULL);
932 /* Enable receiver, set RX mode */
933 rxmode = AXE_RXCMD_UNICAST|AXE_RXCMD_MULTICAST|AXE_RXCMD_ENABLE;
935 /* If we want promiscuous mode, set the allframes bit. */
936 if (ifp->if_flags & IFF_PROMISC)
937 rxmode |= AXE_RXCMD_PROMISC;
939 if (ifp->if_flags & IFF_BROADCAST)
940 rxmode |= AXE_RXCMD_BROADCAST;
942 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
944 /* Load the multicast filter. */
947 /* Open RX and TX pipes. */
948 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_RX],
949 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_RX]);
951 printf("axe%d: open rx pipe failed: %s\n",
952 sc->axe_unit, usbd_errstr(err));
957 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_TX],
958 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_TX]);
960 printf("axe%d: open tx pipe failed: %s\n",
961 sc->axe_unit, usbd_errstr(err));
966 /* Start up the receive pipe. */
967 for (i = 0; i < AXE_RX_LIST_CNT; i++) {
968 c = &sc->axe_cdata.axe_rx_chain[i];
969 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
970 c, mtod(c->axe_mbuf, char *), AXE_BUFSZ,
971 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, axe_rxeof);
972 usbd_transfer(c->axe_xfer);
975 ifp->if_flags |= IFF_RUNNING;
976 ifp->if_flags &= ~IFF_OACTIVE;
980 callout_reset(&sc->axe_stat_timer, hz, axe_tick, sc);
986 axe_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
988 struct axe_softc *sc = ifp->if_softc;
989 struct ifreq *ifr = (struct ifreq *)data;
990 struct mii_data *mii;
998 if (ifp->if_flags & IFF_UP) {
999 if (ifp->if_flags & IFF_RUNNING &&
1000 ifp->if_flags & IFF_PROMISC &&
1001 !(sc->axe_if_flags & IFF_PROMISC)) {
1002 axe_cmd(sc, AXE_CMD_RXCTL_READ,
1003 0, 0, (void *)&rxmode);
1004 rxmode |= AXE_RXCMD_PROMISC;
1005 axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
1008 } else if (ifp->if_flags & IFF_RUNNING &&
1009 !(ifp->if_flags & IFF_PROMISC) &&
1010 sc->axe_if_flags & IFF_PROMISC) {
1011 axe_cmd(sc, AXE_CMD_RXCTL_READ,
1012 0, 0, (void *)&rxmode);
1013 rxmode &= ~AXE_RXCMD_PROMISC;
1014 axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
1017 } else if (!(ifp->if_flags & IFF_RUNNING))
1020 if (ifp->if_flags & IFF_RUNNING)
1023 sc->axe_if_flags = ifp->if_flags;
1034 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1038 error = ether_ioctl(ifp, command, data);
1048 axe_watchdog(struct ifnet *ifp)
1050 struct axe_softc *sc;
1051 struct axe_chain *c;
1059 printf("axe%d: watchdog timeout\n", sc->axe_unit);
1061 c = &sc->axe_cdata.axe_tx_chain[0];
1062 usbd_get_xfer_status(c->axe_xfer, NULL, NULL, NULL, &stat);
1063 axe_txeof(c->axe_xfer, c, stat);
1065 if (ifp->if_snd.ifq_head != NULL)
1072 * Stop the adapter and free any mbufs allocated to the
1076 axe_stop(struct axe_softc *sc)
1086 ifp = &sc->arpcom.ac_if;
1089 callout_stop(&sc->axe_stat_timer);
1091 /* Stop transfers. */
1092 if (sc->axe_ep[AXE_ENDPT_RX] != NULL) {
1093 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]);
1095 printf("axe%d: abort rx pipe failed: %s\n",
1096 sc->axe_unit, usbd_errstr(err));
1098 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_RX]);
1100 printf("axe%d: close rx pipe failed: %s\n",
1101 sc->axe_unit, usbd_errstr(err));
1103 sc->axe_ep[AXE_ENDPT_RX] = NULL;
1106 if (sc->axe_ep[AXE_ENDPT_TX] != NULL) {
1107 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
1109 printf("axe%d: abort tx pipe failed: %s\n",
1110 sc->axe_unit, usbd_errstr(err));
1112 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_TX]);
1114 printf("axe%d: close tx pipe failed: %s\n",
1115 sc->axe_unit, usbd_errstr(err));
1117 sc->axe_ep[AXE_ENDPT_TX] = NULL;
1120 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL) {
1121 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
1123 printf("axe%d: abort intr pipe failed: %s\n",
1124 sc->axe_unit, usbd_errstr(err));
1126 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
1128 printf("axe%d: close intr pipe failed: %s\n",
1129 sc->axe_unit, usbd_errstr(err));
1131 sc->axe_ep[AXE_ENDPT_INTR] = NULL;
1134 /* Free RX resources. */
1135 for (i = 0; i < AXE_RX_LIST_CNT; i++) {
1136 if (sc->axe_cdata.axe_rx_chain[i].axe_buf != NULL) {
1137 free(sc->axe_cdata.axe_rx_chain[i].axe_buf, M_USBDEV);
1138 sc->axe_cdata.axe_rx_chain[i].axe_buf = NULL;
1140 if (sc->axe_cdata.axe_rx_chain[i].axe_mbuf != NULL) {
1141 m_freem(sc->axe_cdata.axe_rx_chain[i].axe_mbuf);
1142 sc->axe_cdata.axe_rx_chain[i].axe_mbuf = NULL;
1144 if (sc->axe_cdata.axe_rx_chain[i].axe_xfer != NULL) {
1145 usbd_free_xfer(sc->axe_cdata.axe_rx_chain[i].axe_xfer);
1146 sc->axe_cdata.axe_rx_chain[i].axe_xfer = NULL;
1150 /* Free TX resources. */
1151 for (i = 0; i < AXE_TX_LIST_CNT; i++) {
1152 if (sc->axe_cdata.axe_tx_chain[i].axe_buf != NULL) {
1153 free(sc->axe_cdata.axe_tx_chain[i].axe_buf, M_USBDEV);
1154 sc->axe_cdata.axe_tx_chain[i].axe_buf = NULL;
1156 if (sc->axe_cdata.axe_tx_chain[i].axe_mbuf != NULL) {
1157 m_freem(sc->axe_cdata.axe_tx_chain[i].axe_mbuf);
1158 sc->axe_cdata.axe_tx_chain[i].axe_mbuf = NULL;
1160 if (sc->axe_cdata.axe_tx_chain[i].axe_xfer != NULL) {
1161 usbd_free_xfer(sc->axe_cdata.axe_tx_chain[i].axe_xfer);
1162 sc->axe_cdata.axe_tx_chain[i].axe_xfer = NULL;
1166 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1172 * Stop all chip I/O so that the kernel's probe routines don't
1173 * get confused by errant DMAs when rebooting.
1176 axe_shutdown(device_ptr_t dev)
1178 struct axe_softc *sc;
1180 sc = device_get_softc(dev);