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.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * ASIX Electronics AX88172 USB 2.0 ethernet driver. Used in the
38 * LinkSys USB200M and various other adapters.
40 * Manuals available from:
41 * http://www.asix.com.tw/datasheet/mac/Ax88172.PDF
42 * Note: you need the manual for the AX88170 chip (USB 1.x ethernet
43 * controller) to find the definitions for the RX control register.
44 * http://www.asix.com.tw/datasheet/mac/Ax88170.PDF
46 * Written by Bill Paul <wpaul@windriver.com>
52 * The AX88172 provides USB ethernet supports at 10 and 100Mbps.
53 * It uses an external PHY (reference designs use a RealTek chip),
54 * and has a 64-bit multicast hash filter. There is some information
55 * missing from the manual which one needs to know in order to make
58 * - You must set bit 7 in the RX control register, otherwise the
59 * chip won't receive any packets.
60 * - You must initialize all 3 IPG registers, or you won't be able
61 * to send any packets.
63 * Note that this device appears to only support loading the station
64 * address via autload from the EEPROM (i.e. there's no way to manaully
67 * (Adam Weinberger wanted me to name this driver if_gir.c.)
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/sockio.h>
74 #include <sys/malloc.h>
75 #include <sys/kernel.h>
76 #include <sys/module.h>
77 #include <sys/socket.h>
80 #include <net/if_arp.h>
81 #include <net/ethernet.h>
82 #include <net/if_dl.h>
83 #include <net/if_media.h>
84 #include <net/if_types.h>
89 #include <machine/bus.h>
91 #include <dev/usb/usb.h>
92 #include <dev/usb/usbdi.h>
93 #include <dev/usb/usbdi_util.h>
94 #include <dev/usb/usbdivar.h>
96 #include <dev/usb/usb_ethersubr.h>
98 #include <dev/mii/mii.h>
99 #include <dev/mii/miivar.h>
101 /* "controller miibus0" required. See GENERIC if you get errors here. */
102 #include "miibus_if.h"
104 #include <dev/usb/if_axereg.h>
107 * Various supported device vendors/products.
109 Static struct axe_type axe_devs[] = {
110 { USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88172 },
111 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DUBE100 },
112 { USB_VENDOR_JVC, USB_PRODUCT_JVC_MP_PRX1 },
113 { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_USB200M },
114 { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAU2KTX },
115 { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA120 },
116 { USB_VENDOR_SYSTEMTALKS, USB_PRODUCT_SYSTEMTALKS_SGCX2UL },
117 { USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_LN029 },
121 Static int axe_match(device_ptr_t);
122 Static int axe_attach(device_ptr_t);
123 Static int axe_detach(device_ptr_t);
125 Static int axe_encap(struct axe_softc *, struct mbuf *, int);
126 Static void axe_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
127 Static void axe_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
128 Static void axe_tick(void *);
129 Static void axe_rxstart(struct ifnet *);
130 Static void axe_start(struct ifnet *);
131 Static int axe_ioctl(struct ifnet *, u_long, caddr_t);
132 Static void axe_init(void *);
133 Static void axe_stop(struct axe_softc *);
134 Static void axe_watchdog(struct ifnet *);
135 Static void axe_shutdown(device_ptr_t);
136 Static int axe_miibus_readreg(device_ptr_t, int, int);
137 Static int axe_miibus_writereg(device_ptr_t, int, int, int);
138 Static void axe_miibus_statchg(device_ptr_t);
139 Static int axe_cmd(struct axe_softc *, int, int, int, void *);
140 Static int axe_ifmedia_upd(struct ifnet *);
141 Static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
143 Static void axe_setmulti(struct axe_softc *);
145 Static device_method_t axe_methods[] = {
146 /* Device interface */
147 DEVMETHOD(device_probe, axe_match),
148 DEVMETHOD(device_attach, axe_attach),
149 DEVMETHOD(device_detach, axe_detach),
150 DEVMETHOD(device_shutdown, axe_shutdown),
153 DEVMETHOD(bus_print_child, bus_generic_print_child),
154 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
157 DEVMETHOD(miibus_readreg, axe_miibus_readreg),
158 DEVMETHOD(miibus_writereg, axe_miibus_writereg),
159 DEVMETHOD(miibus_statchg, axe_miibus_statchg),
164 Static driver_t axe_driver = {
167 sizeof(struct axe_softc)
170 Static devclass_t axe_devclass;
172 DRIVER_MODULE(axe, uhub, axe_driver, axe_devclass, usbd_driver_load, 0);
173 DRIVER_MODULE(miibus, axe, miibus_driver, miibus_devclass, 0, 0);
174 MODULE_DEPEND(axe, usb, 1, 1, 1);
175 MODULE_DEPEND(axe, miibus, 1, 1, 1);
178 axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
180 usb_device_request_t req;
186 if (AXE_CMD_DIR(cmd))
187 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
189 req.bmRequestType = UT_READ_VENDOR_DEVICE;
190 req.bRequest = AXE_CMD_CMD(cmd);
191 USETW(req.wValue, val);
192 USETW(req.wIndex, index);
193 USETW(req.wLength, AXE_CMD_LEN(cmd));
195 err = usbd_do_request(sc->axe_udev, &req, buf);
204 axe_miibus_readreg(device_ptr_t dev, int phy, int reg)
206 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);
255 axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
256 err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, (void *)&val);
257 axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
261 printf("axe%d: write PHY failed\n", sc->axe_unit);
269 axe_miibus_statchg(device_ptr_t dev)
272 struct axe_softc *sc = USBGETSOFTC(dev);
273 struct mii_data *mii = GET_MII(sc);
275 /* doesn't seem to be necessary */
284 axe_ifmedia_upd(struct ifnet *ifp)
286 struct axe_softc *sc = ifp->if_softc;
287 struct mii_data *mii = GET_MII(sc);
290 if (mii->mii_instance) {
291 struct mii_softc *miisc;
292 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
293 mii_phy_reset(miisc);
301 * Report current media status.
304 axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
306 struct axe_softc *sc = ifp->if_softc;
307 struct mii_data *mii = GET_MII(sc);
310 ifmr->ifm_active = mii->mii_media_active;
311 ifmr->ifm_status = mii->mii_media_status;
317 axe_setmulti(struct axe_softc *sc)
320 struct ifmultiaddr *ifma;
323 u_int8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
328 axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, (void *)&rxmode);
330 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
331 rxmode |= AXE_RXCMD_ALLMULTI;
332 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
336 rxmode &= ~AXE_RXCMD_ALLMULTI;
339 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
341 if (ifma->ifma_addr->sa_family != AF_LINK)
343 h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
344 ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
345 hashtbl[h / 8] |= 1 << (h % 8);
349 axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl);
350 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
357 axe_reset(struct axe_softc *sc)
362 if (usbd_set_config_no(sc->axe_udev, AXE_CONFIG_NO, 1) ||
363 usbd_device2interface_handle(sc->axe_udev, AXE_IFACE_IDX,
365 printf("axe%d: getting interface handle failed\n",
369 /* Wait a little while for the chip to get its brains in order. */
375 * Probe for a AX88172 chip.
379 USB_MATCH_START(axe, uaa);
387 if (uaa->vendor == t->axe_vid &&
388 uaa->product == t->axe_did) {
389 return(UMATCH_VENDOR_PRODUCT);
398 * Attach the interface. Allocate softc structures, do ifmedia
399 * setup and ethernet/BPF attach.
403 USB_ATTACH_START(axe, sc, uaa);
405 u_char eaddr[ETHER_ADDR_LEN];
407 usb_interface_descriptor_t *id;
408 usb_endpoint_descriptor_t *ed;
411 bzero(sc, sizeof(struct axe_softc));
412 sc->axe_udev = uaa->device;
414 sc->axe_unit = device_get_unit(self);
416 if (usbd_set_config_no(sc->axe_udev, AXE_CONFIG_NO, 1)) {
417 printf("axe%d: getting interface handle failed\n",
419 USB_ATTACH_ERROR_RETURN;
422 if (usbd_device2interface_handle(uaa->device,
423 AXE_IFACE_IDX, &sc->axe_iface)) {
424 printf("axe%d: getting interface handle failed\n",
426 USB_ATTACH_ERROR_RETURN;
429 id = usbd_get_interface_descriptor(sc->axe_iface);
431 usbd_devinfo(uaa->device, 0, devinfo);
432 device_set_desc_copy(self, devinfo);
433 printf("%s: %s\n", USBDEVNAME(self), devinfo);
435 /* Find endpoints. */
436 for (i = 0; i < id->bNumEndpoints; i++) {
437 ed = usbd_interface2endpoint_descriptor(sc->axe_iface, i);
439 printf("axe%d: couldn't get ep %d\n",
441 USB_ATTACH_ERROR_RETURN;
443 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
444 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
445 sc->axe_ed[AXE_ENDPT_RX] = ed->bEndpointAddress;
446 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
447 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
448 sc->axe_ed[AXE_ENDPT_TX] = ed->bEndpointAddress;
449 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
450 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
451 sc->axe_ed[AXE_ENDPT_INTR] = ed->bEndpointAddress;
455 mtx_init(&sc->axe_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
456 MTX_DEF | MTX_RECURSE);
460 * Get station address.
462 axe_cmd(sc, AXE_CMD_READ_NODEID, 0, 0, &eaddr);
465 * Load IPG values and PHY indexes.
467 axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, (void *)&sc->axe_ipgs);
468 axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs);
471 * Work around broken adapters that appear to lie about
472 * their PHY addresses.
474 sc->axe_phyaddrs[0] = sc->axe_phyaddrs[1] = 0xFF;
476 ifp = sc->axe_ifp = if_alloc(IFT_ETHER);
478 printf("axe%d: can not if_alloc()\n", sc->axe_unit);
480 mtx_destroy(&sc->axe_mtx);
481 USB_ATTACH_ERROR_RETURN;
484 if_initname(ifp, "axe", sc->axe_unit);
485 ifp->if_mtu = ETHERMTU;
486 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
488 ifp->if_ioctl = axe_ioctl;
489 ifp->if_start = axe_start;
490 ifp->if_watchdog = axe_watchdog;
491 ifp->if_init = axe_init;
492 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
493 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
494 IFQ_SET_READY(&ifp->if_snd);
496 sc->axe_qdat.ifp = ifp;
497 sc->axe_qdat.if_rxstart = axe_rxstart;
499 if (mii_phy_probe(self, &sc->axe_miibus,
500 axe_ifmedia_upd, axe_ifmedia_sts)) {
501 printf("axe%d: MII without any PHY!\n", sc->axe_unit);
504 mtx_destroy(&sc->axe_mtx);
505 USB_ATTACH_ERROR_RETURN;
509 * Call MI attach routine.
512 ether_ifattach(ifp, eaddr);
513 callout_handle_init(&sc->axe_stat_ch);
514 usb_register_netisr();
520 USB_ATTACH_SUCCESS_RETURN;
524 axe_detach(device_ptr_t dev)
526 struct axe_softc *sc;
529 sc = device_get_softc(dev);
534 untimeout(axe_tick, sc, sc->axe_stat_ch);
538 if (sc->axe_ep[AXE_ENDPT_TX] != NULL)
539 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
540 if (sc->axe_ep[AXE_ENDPT_RX] != NULL)
541 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]);
542 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL)
543 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
546 mtx_destroy(&sc->axe_mtx);
552 axe_rxstart(struct ifnet *ifp)
554 struct axe_softc *sc;
559 c = &sc->axe_cdata.ue_rx_chain[sc->axe_cdata.ue_rx_prod];
561 c->ue_mbuf = usb_ether_newbuf();
562 if (c->ue_mbuf == NULL) {
563 printf("%s: no memory for rx list "
564 "-- packet dropped!\n", USBDEVNAME(sc->axe_dev));
570 /* Setup new transfer. */
571 usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_RX],
572 c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
573 USBD_NO_TIMEOUT, axe_rxeof);
574 usbd_transfer(c->ue_xfer);
581 * A frame has been uploaded: pass the resulting mbuf chain up to
582 * the higher level protocols.
585 axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
587 struct axe_softc *sc;
598 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
603 if (status != USBD_NORMAL_COMPLETION) {
604 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
608 if (usbd_ratecheck(&sc->axe_rx_notice))
609 printf("axe%d: usb error on rx: %s\n", sc->axe_unit,
610 usbd_errstr(status));
611 if (status == USBD_STALLED)
612 usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_RX]);
616 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
620 if (total_len < sizeof(struct ether_header)) {
626 m->m_pkthdr.rcvif = (void *)&sc->axe_qdat;
627 m->m_pkthdr.len = m->m_len = total_len;
629 /* Put the packet on the special USB input queue. */
635 /* Setup new transfer. */
636 usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_RX],
637 c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
638 USBD_NO_TIMEOUT, axe_rxeof);
639 usbd_transfer(c->ue_xfer);
646 * A frame was downloaded to the chip. It's safe for us to clean up
651 axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
653 struct axe_softc *sc;
663 if (status != USBD_NORMAL_COMPLETION) {
664 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
668 printf("axe%d: usb error on tx: %s\n", sc->axe_unit,
669 usbd_errstr(status));
670 if (status == USBD_STALLED)
671 usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_TX]);
677 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
678 usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &err);
680 if (c->ue_mbuf != NULL) {
681 c->ue_mbuf->m_pkthdr.rcvif = ifp;
682 usb_tx_done(c->ue_mbuf);
699 struct axe_softc *sc;
701 struct mii_data *mii;
718 if (!sc->axe_link && mii->mii_media_status & IFM_ACTIVE &&
719 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
721 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
725 sc->axe_stat_ch = timeout(axe_tick, sc, hz);
733 axe_encap(struct axe_softc *sc, struct mbuf *m, int idx)
738 c = &sc->axe_cdata.ue_tx_chain[idx];
741 * Copy the mbuf data into a contiguous buffer, leaving two
742 * bytes at the beginning to hold the frame length.
744 m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf);
747 usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_TX],
748 c, c->ue_buf, m->m_pkthdr.len, USBD_FORCE_SHORT_XFER,
752 err = usbd_transfer(c->ue_xfer);
753 if (err != USBD_IN_PROGRESS) {
758 sc->axe_cdata.ue_tx_cnt++;
764 axe_start(struct ifnet *ifp)
766 struct axe_softc *sc;
767 struct mbuf *m_head = NULL;
777 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
782 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
783 if (m_head == NULL) {
788 if (axe_encap(sc, m_head, 0)) {
789 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
790 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
796 * If there's a BPF listener, bounce a copy of this frame
799 BPF_MTAP(ifp, m_head);
801 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
804 * Set a timeout in case the chip goes out to lunch.
815 struct axe_softc *sc = xsc;
816 struct ifnet *ifp = sc->axe_ifp;
822 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
828 * Cancel pending I/O and free all RX/TX buffers.
834 /* Set MAC address */
835 axe_mac(sc, IFP2ENADDR(sc->axe_ifp), 1);
838 /* Enable RX logic. */
841 if (usb_ether_tx_list_init(sc, &sc->axe_cdata,
842 sc->axe_udev) == ENOBUFS) {
843 printf("axe%d: tx list init failed\n", sc->axe_unit);
849 if (usb_ether_rx_list_init(sc, &sc->axe_cdata,
850 sc->axe_udev) == ENOBUFS) {
851 printf("axe%d: rx list init failed\n", sc->axe_unit);
856 /* Set transmitter IPG values */
857 axe_cmd(sc, AXE_CMD_WRITE_IPG0, 0, sc->axe_ipgs[0], NULL);
858 axe_cmd(sc, AXE_CMD_WRITE_IPG1, 0, sc->axe_ipgs[1], NULL);
859 axe_cmd(sc, AXE_CMD_WRITE_IPG2, 0, sc->axe_ipgs[2], NULL);
861 /* Enable receiver, set RX mode */
862 rxmode = AXE_RXCMD_UNICAST|AXE_RXCMD_MULTICAST|AXE_RXCMD_ENABLE;
864 /* If we want promiscuous mode, set the allframes bit. */
865 if (ifp->if_flags & IFF_PROMISC)
866 rxmode |= AXE_RXCMD_PROMISC;
868 if (ifp->if_flags & IFF_BROADCAST)
869 rxmode |= AXE_RXCMD_BROADCAST;
871 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
873 /* Load the multicast filter. */
876 /* Open RX and TX pipes. */
877 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_RX],
878 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_RX]);
880 printf("axe%d: open rx pipe failed: %s\n",
881 sc->axe_unit, usbd_errstr(err));
886 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_TX],
887 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_TX]);
889 printf("axe%d: open tx pipe failed: %s\n",
890 sc->axe_unit, usbd_errstr(err));
895 /* Start up the receive pipe. */
896 for (i = 0; i < UE_RX_LIST_CNT; i++) {
897 c = &sc->axe_cdata.ue_rx_chain[i];
898 usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_RX],
899 c, mtod(c->ue_mbuf, char *), UE_BUFSZ,
900 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, axe_rxeof);
901 usbd_transfer(c->ue_xfer);
904 ifp->if_drv_flags |= IFF_DRV_RUNNING;
905 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
909 sc->axe_stat_ch = timeout(axe_tick, sc, hz);
915 axe_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
917 struct axe_softc *sc = ifp->if_softc;
918 struct ifreq *ifr = (struct ifreq *)data;
919 struct mii_data *mii;
925 if (ifp->if_flags & IFF_UP) {
926 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
927 ifp->if_flags & IFF_PROMISC &&
928 !(sc->axe_if_flags & IFF_PROMISC)) {
930 axe_cmd(sc, AXE_CMD_RXCTL_READ,
931 0, 0, (void *)&rxmode);
932 rxmode |= AXE_RXCMD_PROMISC;
933 axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
937 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
938 !(ifp->if_flags & IFF_PROMISC) &&
939 sc->axe_if_flags & IFF_PROMISC) {
941 axe_cmd(sc, AXE_CMD_RXCTL_READ,
942 0, 0, (void *)&rxmode);
943 rxmode &= ~AXE_RXCMD_PROMISC;
944 axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
948 } else if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
951 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
954 sc->axe_if_flags = ifp->if_flags;
965 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
969 error = ether_ioctl(ifp, command, data);
979 axe_watchdog(struct ifnet *ifp)
981 struct axe_softc *sc;
989 printf("axe%d: watchdog timeout\n", sc->axe_unit);
991 c = &sc->axe_cdata.ue_tx_chain[0];
992 usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
993 axe_txeof(c->ue_xfer, c, stat);
997 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1004 * Stop the adapter and free any mbufs allocated to the
1008 axe_stop(struct axe_softc *sc)
1018 untimeout(axe_tick, sc, sc->axe_stat_ch);
1020 /* Stop transfers. */
1021 if (sc->axe_ep[AXE_ENDPT_RX] != NULL) {
1022 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]);
1024 printf("axe%d: abort rx pipe failed: %s\n",
1025 sc->axe_unit, usbd_errstr(err));
1027 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_RX]);
1029 printf("axe%d: close rx pipe failed: %s\n",
1030 sc->axe_unit, usbd_errstr(err));
1032 sc->axe_ep[AXE_ENDPT_RX] = NULL;
1035 if (sc->axe_ep[AXE_ENDPT_TX] != NULL) {
1036 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
1038 printf("axe%d: abort tx pipe failed: %s\n",
1039 sc->axe_unit, usbd_errstr(err));
1041 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_TX]);
1043 printf("axe%d: close tx pipe failed: %s\n",
1044 sc->axe_unit, usbd_errstr(err));
1046 sc->axe_ep[AXE_ENDPT_TX] = NULL;
1049 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL) {
1050 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
1052 printf("axe%d: abort intr pipe failed: %s\n",
1053 sc->axe_unit, usbd_errstr(err));
1055 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
1057 printf("axe%d: close intr pipe failed: %s\n",
1058 sc->axe_unit, usbd_errstr(err));
1060 sc->axe_ep[AXE_ENDPT_INTR] = NULL;
1065 /* Free RX resources. */
1066 usb_ether_rx_list_free(&sc->axe_cdata);
1067 /* Free TX resources. */
1068 usb_ether_tx_list_free(&sc->axe_cdata);
1070 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1078 * Stop all chip I/O so that the kernel's probe routines don't
1079 * get confused by errant DMAs when rebooting.
1082 axe_shutdown(device_ptr_t dev)
1084 struct axe_softc *sc;
1086 sc = device_get_softc(dev);