aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/usb/if_axe.c
diff options
context:
space:
mode:
authorMaxim Sobolev <sobomax@FreeBSD.org>2005-03-25 12:42:30 +0000
committerMaxim Sobolev <sobomax@FreeBSD.org>2005-03-25 12:42:30 +0000
commitd521dc21e72afd8e8e4067d64520e807135751e4 (patch)
treed130bc8b094717e0f7840783e08ddaf87dd8f06f /sys/dev/usb/if_axe.c
parent7d2832e654efbeabce3cf7066d90dcb623e44a19 (diff)
downloadsrc-d521dc21e72afd8e8e4067d64520e807135751e4.tar.gz
src-d521dc21e72afd8e8e4067d64520e807135751e4.zip
Move Rx/Tx lists management routines into central location.
Notes
Notes: svn path=/head/; revision=144104
Diffstat (limited to 'sys/dev/usb/if_axe.c')
-rw-r--r--sys/dev/usb/if_axe.c168
1 files changed, 46 insertions, 122 deletions
diff --git a/sys/dev/usb/if_axe.c b/sys/dev/usb/if_axe.c
index 141c7dcdc931..777496f52d00 100644
--- a/sys/dev/usb/if_axe.c
+++ b/sys/dev/usb/if_axe.c
@@ -124,8 +124,6 @@ Static int axe_match(device_ptr_t);
Static int axe_attach(device_ptr_t);
Static int axe_detach(device_ptr_t);
-Static int axe_tx_list_init(struct axe_softc *);
-Static int axe_rx_list_init(struct axe_softc *);
Static int axe_encap(struct axe_softc *, struct mbuf *, int);
Static void axe_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
Static void axe_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
@@ -561,79 +559,30 @@ axe_detach(device_ptr_t dev)
return(0);
}
-Static int
-axe_rx_list_init(struct axe_softc *sc)
-{
- struct axe_cdata *cd;
- struct axe_chain *c;
- int i;
-
- cd = &sc->axe_cdata;
- for (i = 0; i < AXE_RX_LIST_CNT; i++) {
- c = &cd->axe_rx_chain[i];
- c->axe_sc = sc;
- c->axe_idx = i;
- c->axe_mbuf = usb_ether_newbuf(USBDEVNAME(sc->axe_dev));
- if (c->axe_mbuf == NULL)
- return(ENOBUFS);
- if (c->axe_xfer == NULL) {
- c->axe_xfer = usbd_alloc_xfer(sc->axe_udev);
- if (c->axe_xfer == NULL)
- return(ENOBUFS);
- }
- }
-
- return(0);
-}
-
-Static int
-axe_tx_list_init(struct axe_softc *sc)
-{
- struct axe_cdata *cd;
- struct axe_chain *c;
- int i;
-
- cd = &sc->axe_cdata;
- for (i = 0; i < AXE_TX_LIST_CNT; i++) {
- c = &cd->axe_tx_chain[i];
- c->axe_sc = sc;
- c->axe_idx = i;
- c->axe_mbuf = NULL;
- if (c->axe_xfer == NULL) {
- c->axe_xfer = usbd_alloc_xfer(sc->axe_udev);
- if (c->axe_xfer == NULL)
- return(ENOBUFS);
- }
- c->axe_buf = malloc(AXE_BUFSZ, M_USBDEV, M_NOWAIT);
- if (c->axe_buf == NULL)
- return(ENOBUFS);
- }
-
- return(0);
-}
-
Static void
axe_rxstart(struct ifnet *ifp)
{
struct axe_softc *sc;
- struct axe_chain *c;
+ struct ue_chain *c;
sc = ifp->if_softc;
AXE_LOCK(sc);
- c = &sc->axe_cdata.axe_rx_chain[sc->axe_cdata.axe_rx_prod];
+ c = &sc->axe_cdata.ue_rx_chain[sc->axe_cdata.ue_rx_prod];
- c->axe_mbuf = usb_ether_newbuf(USBDEVNAME(sc->axe_dev));
- if (c->axe_mbuf == NULL) {
+ c->ue_mbuf = usb_ether_newbuf();
+ if (c->ue_mbuf == NULL) {
+ printf("%s: no memory for rx list "
+ "-- packet dropped!\n", USBDEVNAME(sc->axe_dev));
ifp->if_ierrors++;
AXE_UNLOCK(sc);
return;
}
/* Setup new transfer. */
- usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
- c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK,
+ usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_RX],
+ c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
USBD_NO_TIMEOUT, axe_rxeof);
- usbd_transfer(c->axe_xfer);
+ usbd_transfer(c->ue_xfer);
AXE_UNLOCK(sc);
return;
@@ -647,13 +596,13 @@ Static void
axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
{
struct axe_softc *sc;
- struct axe_chain *c;
+ struct ue_chain *c;
struct mbuf *m;
struct ifnet *ifp;
int total_len = 0;
c = priv;
- sc = c->axe_sc;
+ sc = c->ue_sc;
AXE_LOCK(sc);
ifp = &sc->arpcom.ac_if;
@@ -677,7 +626,7 @@ axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
- m = c->axe_mbuf;
+ m = c->ue_mbuf;
if (total_len < sizeof(struct ether_header)) {
ifp->if_ierrors++;
@@ -695,10 +644,10 @@ axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
return;
done:
/* Setup new transfer. */
- usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
- c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK,
+ usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_RX],
+ c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
USBD_NO_TIMEOUT, axe_rxeof);
- usbd_transfer(c->axe_xfer);
+ usbd_transfer(c->ue_xfer);
AXE_UNLOCK(sc);
return;
@@ -713,12 +662,12 @@ Static void
axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
{
struct axe_softc *sc;
- struct axe_chain *c;
+ struct ue_chain *c;
struct ifnet *ifp;
usbd_status err;
c = priv;
- sc = c->axe_sc;
+ sc = c->ue_sc;
AXE_LOCK(sc);
ifp = &sc->arpcom.ac_if;
@@ -737,12 +686,12 @@ axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
ifp->if_timer = 0;
ifp->if_flags &= ~IFF_OACTIVE;
- usbd_get_xfer_status(c->axe_xfer, NULL, NULL, NULL, &err);
+ usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &err);
- if (c->axe_mbuf != NULL) {
- c->axe_mbuf->m_pkthdr.rcvif = ifp;
- usb_tx_done(c->axe_mbuf);
- c->axe_mbuf = NULL;
+ if (c->ue_mbuf != NULL) {
+ c->ue_mbuf->m_pkthdr.rcvif = ifp;
+ usb_tx_done(c->ue_mbuf);
+ c->ue_mbuf = NULL;
}
if (err)
@@ -794,30 +743,30 @@ axe_tick(void *xsc)
Static int
axe_encap(struct axe_softc *sc, struct mbuf *m, int idx)
{
- struct axe_chain *c;
+ struct ue_chain *c;
usbd_status err;
- c = &sc->axe_cdata.axe_tx_chain[idx];
+ c = &sc->axe_cdata.ue_tx_chain[idx];
/*
* Copy the mbuf data into a contiguous buffer, leaving two
* bytes at the beginning to hold the frame length.
*/
- m_copydata(m, 0, m->m_pkthdr.len, c->axe_buf);
- c->axe_mbuf = m;
+ m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf);
+ c->ue_mbuf = m;
- usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_TX],
- c, c->axe_buf, m->m_pkthdr.len, USBD_FORCE_SHORT_XFER,
+ usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_TX],
+ c, c->ue_buf, m->m_pkthdr.len, USBD_FORCE_SHORT_XFER,
10000, axe_txeof);
/* Transmit */
- err = usbd_transfer(c->axe_xfer);
+ err = usbd_transfer(c->ue_xfer);
if (err != USBD_IN_PROGRESS) {
axe_stop(sc);
return(EIO);
}
- sc->axe_cdata.axe_tx_cnt++;
+ sc->axe_cdata.ue_tx_cnt++;
return(0);
}
@@ -876,7 +825,7 @@ axe_init(void *xsc)
{
struct axe_softc *sc = xsc;
struct ifnet *ifp = &sc->arpcom.ac_if;
- struct axe_chain *c;
+ struct ue_chain *c;
usbd_status err;
int i;
int rxmode;
@@ -900,14 +849,16 @@ axe_init(void *xsc)
/* Enable RX logic. */
/* Init TX ring. */
- if (axe_tx_list_init(sc) == ENOBUFS) {
+ if (usb_ether_tx_list_init(sc, &sc->axe_cdata,
+ USBDEVNAME(sc->axe_dev), sc->axe_udev) == ENOBUFS) {
printf("axe%d: tx list init failed\n", sc->axe_unit);
AXE_UNLOCK(sc);
return;
}
/* Init RX ring. */
- if (axe_rx_list_init(sc) == ENOBUFS) {
+ if (usb_ether_rx_list_init(sc, &sc->axe_cdata,
+ USBDEVNAME(sc->axe_dev), sc->axe_udev) == ENOBUFS) {
printf("axe%d: rx list init failed\n", sc->axe_unit);
AXE_UNLOCK(sc);
return;
@@ -953,12 +904,12 @@ axe_init(void *xsc)
}
/* Start up the receive pipe. */
- for (i = 0; i < AXE_RX_LIST_CNT; i++) {
- c = &sc->axe_cdata.axe_rx_chain[i];
- usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
- c, mtod(c->axe_mbuf, char *), AXE_BUFSZ,
+ for (i = 0; i < UE_RX_LIST_CNT; i++) {
+ c = &sc->axe_cdata.ue_rx_chain[i];
+ usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_RX],
+ c, mtod(c->ue_mbuf, char *), UE_BUFSZ,
USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, axe_rxeof);
- usbd_transfer(c->axe_xfer);
+ usbd_transfer(c->ue_xfer);
}
ifp->if_flags |= IFF_RUNNING;
@@ -1039,7 +990,7 @@ Static void
axe_watchdog(struct ifnet *ifp)
{
struct axe_softc *sc;
- struct axe_chain *c;
+ struct ue_chain *c;
usbd_status stat;
sc = ifp->if_softc;
@@ -1048,9 +999,9 @@ axe_watchdog(struct ifnet *ifp)
ifp->if_oerrors++;
printf("axe%d: watchdog timeout\n", sc->axe_unit);
- c = &sc->axe_cdata.axe_tx_chain[0];
- usbd_get_xfer_status(c->axe_xfer, NULL, NULL, NULL, &stat);
- axe_txeof(c->axe_xfer, c, stat);
+ c = &sc->axe_cdata.ue_tx_chain[0];
+ usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
+ axe_txeof(c->ue_xfer, c, stat);
AXE_UNLOCK(sc);
@@ -1124,36 +1075,9 @@ axe_stop(struct axe_softc *sc)
axe_reset(sc);
/* Free RX resources. */
- for (i = 0; i < AXE_RX_LIST_CNT; i++) {
- if (sc->axe_cdata.axe_rx_chain[i].axe_buf != NULL) {
- free(sc->axe_cdata.axe_rx_chain[i].axe_buf, M_USBDEV);
- sc->axe_cdata.axe_rx_chain[i].axe_buf = NULL;
- }
- if (sc->axe_cdata.axe_rx_chain[i].axe_mbuf != NULL) {
- m_freem(sc->axe_cdata.axe_rx_chain[i].axe_mbuf);
- sc->axe_cdata.axe_rx_chain[i].axe_mbuf = NULL;
- }
- if (sc->axe_cdata.axe_rx_chain[i].axe_xfer != NULL) {
- usbd_free_xfer(sc->axe_cdata.axe_rx_chain[i].axe_xfer);
- sc->axe_cdata.axe_rx_chain[i].axe_xfer = NULL;
- }
- }
-
+ usb_ether_rx_list_free(&sc->axe_cdata);
/* Free TX resources. */
- for (i = 0; i < AXE_TX_LIST_CNT; i++) {
- if (sc->axe_cdata.axe_tx_chain[i].axe_buf != NULL) {
- free(sc->axe_cdata.axe_tx_chain[i].axe_buf, M_USBDEV);
- sc->axe_cdata.axe_tx_chain[i].axe_buf = NULL;
- }
- if (sc->axe_cdata.axe_tx_chain[i].axe_mbuf != NULL) {
- m_freem(sc->axe_cdata.axe_tx_chain[i].axe_mbuf);
- sc->axe_cdata.axe_tx_chain[i].axe_mbuf = NULL;
- }
- if (sc->axe_cdata.axe_tx_chain[i].axe_xfer != NULL) {
- usbd_free_xfer(sc->axe_cdata.axe_tx_chain[i].axe_xfer);
- sc->axe_cdata.axe_tx_chain[i].axe_xfer = NULL;
- }
- }
+ usb_ether_tx_list_free(&sc->axe_cdata);
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
sc->axe_link = 0;