2019-09-08 21:59:32 +03:00
|
|
|
/* $NetBSD: usbnet.c,v 1.26 2019/09/08 18:59:32 mrg Exp $ */
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Matthew R. Green
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2019-08-12 02:55:43 +03:00
|
|
|
* Common code shared between USB network drivers.
|
2019-07-31 12:13:16 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2019-09-08 21:59:32 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.26 2019/09/08 18:59:32 mrg Exp $");
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/kmem.h>
|
|
|
|
#include <sys/module.h>
|
2019-08-23 07:29:28 +03:00
|
|
|
#include <sys/atomic.h>
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
#include <dev/usb/usbnet.h>
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
#include <dev/usb/usbhist.h>
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata {
|
|
|
|
struct usbnet_chain *uncd_tx_chain;
|
|
|
|
struct usbnet_chain *uncd_rx_chain;
|
|
|
|
|
|
|
|
int uncd_tx_prod;
|
|
|
|
int uncd_tx_cnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct usbnet_private {
|
|
|
|
/*
|
|
|
|
* - unp_lock protects most of the structure, and the public one
|
|
|
|
* - unp_miilock must be held to access this device's MII bus
|
|
|
|
* - unp_rxlock protects the rx path and its data
|
|
|
|
* - unp_txlock protects the tx path and its data
|
|
|
|
* - unp_detachcv handles detach vs open references
|
|
|
|
*/
|
|
|
|
kmutex_t unp_lock;
|
|
|
|
kmutex_t unp_miilock;
|
|
|
|
kmutex_t unp_rxlock;
|
|
|
|
kmutex_t unp_txlock;
|
|
|
|
kcondvar_t unp_detachcv;
|
|
|
|
|
|
|
|
struct usbnet_cdata unp_cdata;
|
|
|
|
|
|
|
|
struct ethercom unp_ec;
|
|
|
|
struct mii_data unp_mii;
|
|
|
|
struct usb_task unp_ticktask;
|
|
|
|
struct callout unp_stat_ch;
|
|
|
|
struct usbd_pipe *unp_ep[USBNET_ENDPT_MAX];
|
|
|
|
|
|
|
|
bool unp_dying;
|
|
|
|
bool unp_stopping;
|
|
|
|
bool unp_attached;
|
|
|
|
bool unp_link;
|
|
|
|
|
|
|
|
int unp_refcnt;
|
|
|
|
int unp_timer;
|
|
|
|
int unp_if_flags;
|
2019-08-23 07:29:28 +03:00
|
|
|
unsigned unp_number;
|
2019-08-10 05:17:36 +03:00
|
|
|
|
|
|
|
krndsource_t unp_rndsrc;
|
|
|
|
|
|
|
|
struct timeval unp_rx_notice;
|
|
|
|
struct timeval unp_tx_notice;
|
|
|
|
struct timeval unp_intr_notice;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define un_cdata(un) (&(un)->un_pri->unp_cdata)
|
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
volatile unsigned usbnet_number;
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
static int usbnet_modcmd(modcmd_t, void *);
|
|
|
|
|
2019-08-01 02:47:16 +03:00
|
|
|
#ifdef USB_DEBUG
|
|
|
|
#ifndef USBNET_DEBUG
|
|
|
|
#define usbnetdebug 0
|
|
|
|
#else
|
2019-09-08 21:59:32 +03:00
|
|
|
static int usbnetdebug = 0;
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
|
2019-08-01 02:47:16 +03:00
|
|
|
SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup")
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
const struct sysctlnode *rnode;
|
|
|
|
const struct sysctlnode *cnode;
|
|
|
|
|
|
|
|
err = sysctl_createv(clog, 0, NULL, &rnode,
|
|
|
|
CTLFLAG_PERMANENT, CTLTYPE_NODE, "usbnet",
|
|
|
|
SYSCTL_DESCR("usbnet global controls"),
|
|
|
|
NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* control debugging printfs */
|
|
|
|
err = sysctl_createv(clog, 0, &rnode, &cnode,
|
|
|
|
CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
|
|
|
|
"debug", SYSCTL_DESCR("Enable debugging output"),
|
|
|
|
NULL, 0, &usbnetdebug, sizeof(usbnetdebug), CTL_CREATE, CTL_EOL);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return;
|
|
|
|
fail:
|
|
|
|
aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USBNET_DEBUG */
|
|
|
|
#endif /* USB_DEBUG */
|
|
|
|
|
|
|
|
#define DPRINTF(FMT,A,B,C,D) USBHIST_LOGN(usbnetdebug,1,FMT,A,B,C,D)
|
|
|
|
#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(usbnetdebug,N,FMT,A,B,C,D)
|
|
|
|
#define USBNETHIST_FUNC() USBHIST_FUNC()
|
|
|
|
#define USBNETHIST_CALLED(name) USBHIST_CALLED(usbnetdebug)
|
2019-08-19 09:35:14 +03:00
|
|
|
#define USBNETHIST_CALLARGS(FMT,A,B,C,D) \
|
|
|
|
USBHIST_CALLARGS(usbnetdebug,FMT,A,B,C,D)
|
2019-08-23 07:29:28 +03:00
|
|
|
#define USBNETHIST_CALLARGSN(N,FMT,A,B,C,D) \
|
|
|
|
USBHIST_CALLARGSN(usbnetdebug,N,FMT,A,B,C,D)
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
/* Callback vectors. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
uno_stop(struct usbnet *un, struct ifnet *ifp, int disable)
|
|
|
|
{
|
|
|
|
if (un->un_ops->uno_stop)
|
|
|
|
(*un->un_ops->uno_stop)(ifp, disable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
uno_ioctl(struct usbnet *un, struct ifnet *ifp, u_long cmd, void *data)
|
|
|
|
{
|
|
|
|
if (un->un_ops->uno_ioctl)
|
|
|
|
return (*un->un_ops->uno_ioctl)(ifp, cmd, data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
uno_override_ioctl(struct usbnet *un, struct ifnet *ifp, u_long cmd, void *data)
|
|
|
|
{
|
|
|
|
return (*un->un_ops->uno_override_ioctl)(ifp, cmd, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
uno_init(struct usbnet *un, struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
return (*un->un_ops->uno_init)(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
uno_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val)
|
|
|
|
{
|
|
|
|
return (*un->un_ops->uno_read_reg)(un, phy, reg, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
uno_write_reg(struct usbnet *un, int phy, int reg, uint16_t val)
|
|
|
|
{
|
|
|
|
return (*un->un_ops->uno_write_reg)(un, phy, reg, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
uno_mii_statchg(struct usbnet *un, struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
(*un->un_ops->uno_statchg)(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
|
|
|
|
{
|
|
|
|
return (*un->un_ops->uno_tx_prepare)(un, m, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-15 08:52:23 +03:00
|
|
|
uno_rx_loop(struct usbnet *un, struct usbnet_chain *c, uint32_t total_len)
|
|
|
|
{
|
|
|
|
(*un->un_ops->uno_rx_loop)(un, c, total_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
uno_tick(struct usbnet *un)
|
2019-08-09 04:17:33 +03:00
|
|
|
{
|
2019-08-15 08:52:23 +03:00
|
|
|
if (un->un_ops->uno_tick)
|
|
|
|
(*un->un_ops->uno_tick)(un);
|
2019-08-09 04:17:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
uno_intr(struct usbnet *un, usbd_status status)
|
|
|
|
{
|
|
|
|
if (un->un_ops->uno_intr)
|
|
|
|
(*un->un_ops->uno_intr)(un, status);
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
/* Interrupt handling. */
|
|
|
|
|
|
|
|
static struct mbuf *
|
2019-08-16 11:38:21 +03:00
|
|
|
usbnet_newbuf(size_t buflen)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2019-08-16 11:38:21 +03:00
|
|
|
if (buflen > MHLEN - ETHER_ALIGN) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if (!(m->m_flags & M_EXT)) {
|
|
|
|
m_freem(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_adj(m, ETHER_ALIGN);
|
2019-08-16 11:38:21 +03:00
|
|
|
m->m_len = m->m_pkthdr.len = buflen;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* usbnet_rxeof() is designed to be the done callback for rx completion.
|
|
|
|
* it provides generic setup and finalisation, calls a different usbnet
|
|
|
|
* rx_loop callback in the middle, which can use usbnet_enqueue() to
|
2019-08-06 03:19:57 +03:00
|
|
|
* enqueue a packet for higher levels (or usbnet_input() if previously
|
|
|
|
* using if_input() path.)
|
2019-07-31 12:13:16 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
usbnet_enqueue(struct usbnet * const un, uint8_t *buf, size_t buflen,
|
2019-08-06 03:19:57 +03:00
|
|
|
int csum_flags, uint32_t csum_data, int mbuf_flags)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-08-10 05:17:36 +03:00
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
2019-08-23 07:29:28 +03:00
|
|
|
struct usbnet_private * const unp __unused = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct mbuf *m;
|
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_CALLARGSN(5, "%d: enter: len=%zu csf %x mbf %x",
|
|
|
|
unp->unp_number, buflen, csum_flags, mbuf_flags);
|
|
|
|
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_isowned_rx(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-16 11:38:21 +03:00
|
|
|
m = usbnet_newbuf(buflen);
|
2019-07-31 12:13:16 +03:00
|
|
|
if (m == NULL) {
|
2019-08-23 07:29:28 +03:00
|
|
|
DPRINTF("%d: no memory", unp->unp_number, 0, 0, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_set_rcvif(m, ifp);
|
2019-08-06 03:19:57 +03:00
|
|
|
m->m_pkthdr.csum_flags = csum_flags;
|
|
|
|
m->m_pkthdr.csum_data = csum_data;
|
|
|
|
m->m_flags |= mbuf_flags;
|
2019-08-16 11:38:21 +03:00
|
|
|
memcpy(mtod(m, uint8_t *), buf, buflen);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/* push the packet up */
|
|
|
|
if_percpuq_enqueue(ifp->if_percpuq, m);
|
|
|
|
}
|
|
|
|
|
2019-08-06 03:19:57 +03:00
|
|
|
void
|
|
|
|
usbnet_input(struct usbnet * const un, uint8_t *buf, size_t buflen)
|
|
|
|
{
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-08-06 03:19:57 +03:00
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
2019-08-23 07:29:28 +03:00
|
|
|
struct usbnet_private * const unp __unused = un->un_pri;
|
2019-08-06 03:19:57 +03:00
|
|
|
struct mbuf *m;
|
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_CALLARGSN(5, "%d: enter: buf %jx len %ju",
|
|
|
|
unp->unp_number, (uintptr_t)buf, buflen, 0);
|
|
|
|
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_isowned_rx(un);
|
2019-08-06 03:19:57 +03:00
|
|
|
|
2019-08-16 11:38:21 +03:00
|
|
|
m = usbnet_newbuf(buflen);
|
2019-08-06 03:19:57 +03:00
|
|
|
if (m == NULL) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_set_rcvif(m, ifp);
|
|
|
|
memcpy(mtod(m, char *), buf, buflen);
|
|
|
|
|
|
|
|
/* push the packet up */
|
|
|
|
if_input(ifp, m);
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
/*
|
|
|
|
* A frame has been uploaded: pass the resulting mbuf chain up to
|
|
|
|
* the higher level protocols.
|
|
|
|
*/
|
|
|
|
static void
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
usbnet_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_chain * const c = priv;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = c->unc_un;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-08-06 03:19:57 +03:00
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
uint32_t total_len;
|
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_CALLARGSN(5, "%d: enter: status %x xfer %jx",
|
|
|
|
unp->unp_number, status, (uintptr_t)xfer, 0);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_rxlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (unp->unp_dying || unp->unp_stopping ||
|
2019-07-31 12:13:16 +03:00
|
|
|
status == USBD_INVAL || status == USBD_NOT_STARTED ||
|
|
|
|
status == USBD_CANCELLED || !(ifp->if_flags & IFF_RUNNING))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
2019-08-10 05:17:36 +03:00
|
|
|
if (usbd_ratecheck(&unp->unp_rx_notice))
|
2019-07-31 12:13:16 +03:00
|
|
|
aprint_error_dev(un->un_dev, "usb errors on rx: %s\n",
|
|
|
|
usbd_errstr(status));
|
|
|
|
if (status == USBD_STALLED)
|
2019-08-10 05:17:36 +03:00
|
|
|
usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_RX]);
|
2019-07-31 12:13:16 +03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (total_len > un->un_rx_bufsz) {
|
2019-07-31 12:13:16 +03:00
|
|
|
aprint_error_dev(un->un_dev,
|
|
|
|
"rxeof: too large transfer (%u > %u)\n",
|
2019-08-10 05:17:36 +03:00
|
|
|
total_len, un->un_rx_bufsz);
|
2019-07-31 12:13:16 +03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-08-15 08:52:23 +03:00
|
|
|
uno_rx_loop(un, c, total_len);
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_isowned_rx(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
done:
|
2019-08-10 05:17:36 +03:00
|
|
|
if (unp->unp_dying || unp->unp_stopping)
|
2019-07-31 12:13:16 +03:00
|
|
|
goto out;
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_rxlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/* Setup new transfer. */
|
2019-08-10 05:17:36 +03:00
|
|
|
usbd_setup_xfer(xfer, c, c->unc_buf, un->un_rx_bufsz,
|
|
|
|
un->un_rx_xfer_flags, USBD_NO_TIMEOUT, usbnet_rxeof);
|
2019-07-31 12:13:16 +03:00
|
|
|
usbd_transfer(xfer);
|
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_rxlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
usbnet_txeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_chain * const c = priv;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = c->unc_un;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_CALLARGSN(5, "%d: enter: status %x xfer %jx",
|
|
|
|
unp->unp_number, status, (uintptr_t)xfer, 0);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_txlock);
|
|
|
|
if (unp->unp_stopping || unp->unp_dying) {
|
|
|
|
mutex_exit(&unp->unp_txlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KASSERT(cd->uncd_tx_cnt > 0);
|
|
|
|
cd->uncd_tx_cnt--;
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_timer = 0;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case USBD_NOT_STARTED:
|
|
|
|
case USBD_CANCELLED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USBD_NORMAL_COMPLETION:
|
|
|
|
ifp->if_opackets++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
ifp->if_oerrors++;
|
2019-08-10 05:17:36 +03:00
|
|
|
if (usbd_ratecheck(&unp->unp_tx_notice))
|
2019-07-31 12:13:16 +03:00
|
|
|
aprint_error_dev(un->un_dev, "usb error on tx: %s\n",
|
|
|
|
usbd_errstr(status));
|
|
|
|
if (status == USBD_STALLED)
|
2019-08-10 05:17:36 +03:00
|
|
|
usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_TX]);
|
2019-07-31 12:13:16 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_txlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
if (status == USBD_NORMAL_COMPLETION && !IFQ_IS_EMPTY(&ifp->if_snd))
|
|
|
|
(*ifp->if_start)(ifp);
|
|
|
|
}
|
|
|
|
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
static void
|
2019-08-10 05:17:36 +03:00
|
|
|
usbnet_pipe_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
{
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet * const un = priv;
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
struct usbnet_intr * const uni = un->un_intr;
|
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (uni == NULL || unp->unp_dying || unp->unp_stopping ||
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
status == USBD_INVAL || status == USBD_NOT_STARTED ||
|
2019-09-08 21:59:32 +03:00
|
|
|
status == USBD_CANCELLED || !(ifp->if_flags & IFF_RUNNING)) {
|
|
|
|
USBNETHIST_CALLARGS("%d: uni %jx d/s %x status %x",
|
|
|
|
unp->unp_number, (uintptr_t)uni,
|
|
|
|
(unp->unp_dying << 8) | unp->unp_stopping, status);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
return;
|
2019-09-08 21:59:32 +03:00
|
|
|
}
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
2019-08-10 05:17:36 +03:00
|
|
|
if (usbd_ratecheck(&unp->unp_intr_notice)) {
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
aprint_error_dev(un->un_dev, "usb error on intr: %s\n",
|
|
|
|
usbd_errstr(status));
|
|
|
|
}
|
|
|
|
if (status == USBD_STALLED)
|
2019-08-10 05:17:36 +03:00
|
|
|
usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_INTR]);
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_CALLARGS("%d: not normal status %x",
|
|
|
|
unp->unp_number, status, 0, 0);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
uno_intr(un, status);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
}
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
static void
|
|
|
|
usbnet_start_locked(struct ifnet *ifp)
|
|
|
|
{
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = ifp->if_softc;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct mbuf *m;
|
|
|
|
unsigned length;
|
2019-09-08 21:59:32 +03:00
|
|
|
bool done_transmit = false;
|
2019-07-31 12:13:16 +03:00
|
|
|
int idx;
|
|
|
|
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_CALLARGS("%d: tx_cnt %d list_cnt %d link %d",
|
|
|
|
unp->unp_number, cd->uncd_tx_cnt, un->un_tx_list_cnt,
|
|
|
|
unp->unp_link);
|
|
|
|
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_isowned_tx(un);
|
2019-08-10 05:17:36 +03:00
|
|
|
KASSERT(cd->uncd_tx_cnt <= un->un_tx_list_cnt);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-15 08:52:23 +03:00
|
|
|
if (!unp->unp_link || (ifp->if_flags & IFF_RUNNING) == 0) {
|
|
|
|
DPRINTF("start called no link (%x) or running (flags %x)",
|
|
|
|
unp->unp_link, ifp->if_flags, 0, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
return;
|
2019-08-15 08:52:23 +03:00
|
|
|
}
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
if (cd->uncd_tx_cnt == un->un_tx_list_cnt) {
|
|
|
|
DPRINTF("start called, tx busy (%jx == %jx)",
|
|
|
|
cd->uncd_tx_cnt, un->un_tx_list_cnt, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
idx = cd->uncd_tx_prod;
|
2019-08-10 05:17:36 +03:00
|
|
|
while (cd->uncd_tx_cnt < un->un_tx_list_cnt) {
|
2019-07-31 12:13:16 +03:00
|
|
|
IFQ_POLL(&ifp->if_snd, m);
|
2019-08-23 07:29:28 +03:00
|
|
|
if (m == NULL) {
|
|
|
|
DPRINTF("start called, queue empty", 0, 0, 0, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
break;
|
2019-08-23 07:29:28 +03:00
|
|
|
}
|
2019-08-12 02:55:43 +03:00
|
|
|
KASSERT(m->m_pkthdr.len <= un->un_tx_bufsz);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
struct usbnet_chain *c = &cd->uncd_tx_chain[idx];
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
length = uno_tx_prepare(un, m, c);
|
2019-07-31 12:13:16 +03:00
|
|
|
if (length == 0) {
|
2019-08-23 07:29:28 +03:00
|
|
|
DPRINTF("uno_tx_prepare gave zero length", 0, 0, 0, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (__predict_false(c->unc_xfer == NULL)) {
|
2019-08-23 07:29:28 +03:00
|
|
|
DPRINTF("unc_xfer is NULL", 0, 0, 0, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
usbd_setup_xfer(c->unc_xfer, c, c->unc_buf, length,
|
2019-08-10 05:17:36 +03:00
|
|
|
un->un_tx_xfer_flags, 10000, usbnet_txeof);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/* Transmit */
|
|
|
|
usbd_status err = usbd_transfer(c->unc_xfer);
|
|
|
|
if (err != USBD_IN_PROGRESS) {
|
2019-08-23 07:29:28 +03:00
|
|
|
DPRINTF("usbd_transfer on %jx for %ju bytes: %d",
|
|
|
|
(uintptr_t)c->unc_buf, length, err, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
break;
|
|
|
|
}
|
2019-09-08 21:59:32 +03:00
|
|
|
done_transmit = true;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there's a BPF listener, bounce a copy of this frame
|
|
|
|
* to him.
|
|
|
|
*/
|
|
|
|
bpf_mtap(ifp, m, BPF_D_OUT);
|
|
|
|
m_freem(m);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
idx = (idx + 1) % un->un_tx_list_cnt;
|
2019-07-31 12:13:16 +03:00
|
|
|
cd->uncd_tx_cnt++;
|
|
|
|
}
|
|
|
|
cd->uncd_tx_prod = idx;
|
|
|
|
|
2019-09-08 21:59:32 +03:00
|
|
|
DPRINTF("finished with start; tx_cnt %d list_cnt %d link %d",
|
|
|
|
cd->uncd_tx_cnt, un->un_tx_list_cnt, unp->unp_link, 0);
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
/*
|
|
|
|
* Set a timeout in case the chip goes out to lunch.
|
|
|
|
*/
|
2019-09-08 21:59:32 +03:00
|
|
|
if (done_transmit)
|
|
|
|
unp->unp_timer = 5;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usbnet_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct usbnet * const un = ifp->if_softc;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_FUNC();
|
|
|
|
USBNETHIST_CALLARGS("%d, stopping %d",
|
|
|
|
unp->unp_number, unp->unp_stopping, 0, 0);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_txlock);
|
|
|
|
if (!unp->unp_stopping)
|
2019-07-31 12:13:16 +03:00
|
|
|
usbnet_start_locked(ifp);
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_txlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Chain management.
|
|
|
|
*
|
|
|
|
* RX and TX are identical. Keep them that way.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Start of common RX functions */
|
|
|
|
|
|
|
|
static size_t
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_rx_list_size(struct usbnet_cdata * const cd, struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
return sizeof(*cd->uncd_rx_chain) * un->un_rx_list_cnt;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_rx_list_alloc(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
cd->uncd_rx_chain = kmem_zalloc(usbnet_rx_list_size(cd, un), KM_SLEEP);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_rx_list_free(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
if (cd->uncd_rx_chain) {
|
2019-08-10 05:17:36 +03:00
|
|
|
kmem_free(cd->uncd_rx_chain, usbnet_rx_list_size(cd, un));
|
2019-07-31 12:13:16 +03:00
|
|
|
cd->uncd_rx_chain = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_rx_list_init(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
for (size_t i = 0; i < un->un_rx_list_cnt; i++) {
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet_chain *c = &cd->uncd_rx_chain[i];
|
|
|
|
|
|
|
|
c->unc_un = un;
|
|
|
|
if (c->unc_xfer == NULL) {
|
2019-08-10 05:17:36 +03:00
|
|
|
int err = usbd_create_xfer(unp->unp_ep[USBNET_ENDPT_RX],
|
|
|
|
un->un_rx_bufsz, un->un_rx_xfer_flags, 0,
|
2019-08-09 04:17:33 +03:00
|
|
|
&c->unc_xfer);
|
2019-07-31 12:13:16 +03:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
c->unc_buf = usbd_get_buffer(c->unc_xfer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_rx_list_fini(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
for (size_t i = 0; i < un->un_rx_list_cnt; i++) {
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet_chain *c = &cd->uncd_rx_chain[i];
|
|
|
|
|
|
|
|
if (c->unc_xfer != NULL) {
|
|
|
|
usbd_destroy_xfer(c->unc_xfer);
|
|
|
|
c->unc_xfer = NULL;
|
|
|
|
c->unc_buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End of common RX functions */
|
|
|
|
|
|
|
|
static void
|
2019-08-16 11:38:21 +03:00
|
|
|
usbnet_rx_start_pipes(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_rxlock);
|
|
|
|
mutex_enter(&unp->unp_txlock);
|
|
|
|
unp->unp_stopping = false;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
for (size_t i = 0; i < un->un_rx_list_cnt; i++) {
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet_chain *c = &cd->uncd_rx_chain[i];
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
usbd_setup_xfer(c->unc_xfer, c, c->unc_buf, un->un_rx_bufsz,
|
2019-08-16 11:38:21 +03:00
|
|
|
un->un_rx_xfer_flags, USBD_NO_TIMEOUT, usbnet_rxeof);
|
2019-07-31 12:13:16 +03:00
|
|
|
usbd_transfer(c->unc_xfer);
|
2019-08-03 18:58:14 +03:00
|
|
|
}
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_txlock);
|
|
|
|
mutex_exit(&unp->unp_rxlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start of common TX functions */
|
|
|
|
|
|
|
|
static size_t
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_tx_list_size(struct usbnet_cdata * const cd, struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
return sizeof(*cd->uncd_tx_chain) * un->un_tx_list_cnt;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_tx_list_alloc(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
cd->uncd_tx_chain = kmem_zalloc(usbnet_tx_list_size(cd, un), KM_SLEEP);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_tx_list_free(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
if (cd->uncd_tx_chain) {
|
2019-08-10 05:17:36 +03:00
|
|
|
kmem_free(cd->uncd_tx_chain, usbnet_tx_list_size(cd, un));
|
2019-07-31 12:13:16 +03:00
|
|
|
cd->uncd_tx_chain = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_tx_list_init(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
for (size_t i = 0; i < un->un_tx_list_cnt; i++) {
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet_chain *c = &cd->uncd_tx_chain[i];
|
|
|
|
|
|
|
|
c->unc_un = un;
|
|
|
|
if (c->unc_xfer == NULL) {
|
2019-08-10 05:17:36 +03:00
|
|
|
int err = usbd_create_xfer(unp->unp_ep[USBNET_ENDPT_TX],
|
|
|
|
un->un_tx_bufsz, un->un_tx_xfer_flags, 0,
|
2019-08-09 04:17:33 +03:00
|
|
|
&c->unc_xfer);
|
2019-07-31 12:13:16 +03:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
c->unc_buf = usbd_get_buffer(c->unc_xfer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_tx_list_fini(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
for (size_t i = 0; i < un->un_tx_list_cnt; i++) {
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet_chain *c = &cd->uncd_tx_chain[i];
|
|
|
|
|
|
|
|
if (c->unc_xfer != NULL) {
|
|
|
|
usbd_destroy_xfer(c->unc_xfer);
|
|
|
|
c->unc_xfer = NULL;
|
|
|
|
c->unc_buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
2019-08-23 07:29:28 +03:00
|
|
|
cd->uncd_tx_prod = cd->uncd_tx_cnt = 0;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* End of common TX functions */
|
|
|
|
|
|
|
|
/* Endpoint pipe management. */
|
|
|
|
|
|
|
|
static void
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_ep_close_pipes(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < __arraycount(unp->unp_ep); i++) {
|
|
|
|
if (unp->unp_ep[i] == NULL)
|
2019-07-31 12:13:16 +03:00
|
|
|
continue;
|
2019-08-10 05:17:36 +03:00
|
|
|
usbd_status err = usbd_close_pipe(unp->unp_ep[i]);
|
2019-07-31 12:13:16 +03:00
|
|
|
if (err)
|
|
|
|
aprint_error_dev(un->un_dev, "close pipe %zu: %s\n", i,
|
|
|
|
usbd_errstr(err));
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_ep[i] = NULL;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static usbd_status
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_ep_open_pipes(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_intr * const uni = un->un_intr;
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < __arraycount(unp->unp_ep); i++) {
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
usbd_status err;
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
if (un->un_ed[i] == 0)
|
|
|
|
continue;
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (i == USBNET_ENDPT_INTR && uni) {
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
err = usbd_open_pipe_intr(un->un_iface, un->un_ed[i],
|
2019-08-10 05:17:36 +03:00
|
|
|
USBD_EXCLUSIVE_USE | USBD_MPSAFE, &unp->unp_ep[i], un,
|
|
|
|
uni->uni_buf, uni->uni_bufsz, usbnet_pipe_intr,
|
|
|
|
uni->uni_interval);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
} else {
|
|
|
|
err = usbd_open_pipe(un->un_iface, un->un_ed[i],
|
2019-08-10 05:17:36 +03:00
|
|
|
USBD_EXCLUSIVE_USE | USBD_MPSAFE, &unp->unp_ep[i]);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
}
|
2019-07-31 12:13:16 +03:00
|
|
|
if (err) {
|
|
|
|
usbnet_ep_close_pipes(un);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return USBD_NORMAL_COMPLETION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static usbd_status
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_ep_stop_pipes(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-08-18 12:29:38 +03:00
|
|
|
usbd_status err = USBD_NORMAL_COMPLETION;
|
2019-08-10 05:17:36 +03:00
|
|
|
|
|
|
|
for (size_t i = 0; i < __arraycount(unp->unp_ep); i++) {
|
|
|
|
if (unp->unp_ep[i] == NULL)
|
2019-07-31 12:13:16 +03:00
|
|
|
continue;
|
2019-08-18 12:29:38 +03:00
|
|
|
usbd_status err2 = usbd_abort_pipe(unp->unp_ep[i]);
|
|
|
|
if (err == USBD_NORMAL_COMPLETION && err2)
|
2019-08-18 12:46:58 +03:00
|
|
|
err = err2;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
2019-08-18 12:29:38 +03:00
|
|
|
return err;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-08-09 04:17:33 +03:00
|
|
|
usbnet_init_rx_tx(struct usbnet * const un)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
|
|
|
usbd_status err;
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
usbnet_isowned(un);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (unp->unp_dying) {
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
return EIO;
|
|
|
|
}
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_refcnt++;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/* Open RX and TX pipes. */
|
|
|
|
err = usbnet_ep_open_pipes(un);
|
|
|
|
if (err) {
|
|
|
|
aprint_error_dev(un->un_dev, "open rx/tx pipes failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
error = EIO;
|
|
|
|
goto out;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init RX ring. */
|
2019-08-09 04:17:33 +03:00
|
|
|
if (usbnet_rx_list_init(un)) {
|
2019-07-31 12:13:16 +03:00
|
|
|
aprint_error_dev(un->un_dev, "rx list init failed\n");
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto out;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Init TX ring. */
|
2019-08-09 04:17:33 +03:00
|
|
|
if (usbnet_tx_list_init(un)) {
|
2019-07-31 12:13:16 +03:00
|
|
|
aprint_error_dev(un->un_dev, "tx list init failed\n");
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto out;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start up the receive pipe(s). */
|
2019-08-16 11:38:21 +03:00
|
|
|
usbnet_rx_start_pipes(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/* Indicate we are up and running. */
|
2019-08-18 12:29:38 +03:00
|
|
|
#if 0
|
|
|
|
/* XXX if_mcast_op() can call this without ifnet locked */
|
2019-08-07 04:47:18 +03:00
|
|
|
KASSERT(ifp->if_softc == NULL || IFNET_LOCKED(ifp));
|
2019-08-18 12:29:38 +03:00
|
|
|
#endif
|
2019-07-31 12:13:16 +03:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
callout_schedule(&unp->unp_stat_ch, hz);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
out:
|
|
|
|
if (error) {
|
|
|
|
usbnet_rx_list_fini(un);
|
|
|
|
usbnet_tx_list_fini(un);
|
|
|
|
usbnet_ep_close_pipes(un);
|
|
|
|
}
|
2019-08-10 05:17:36 +03:00
|
|
|
if (--unp->unp_refcnt < 0)
|
|
|
|
cv_broadcast(&unp->unp_detachcv);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
|
|
|
|
usbnet_isowned(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
return error;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* MII management. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Access functions for MII. Take the MII lock to call access MII regs.
|
|
|
|
* Two forms: usbnet (softc) lock currently held or not.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
usbnet_lock_mii(struct usbnet *un)
|
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
|
|
|
unp->unp_refcnt++;
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_miilock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_lock_mii_un_locked(struct usbnet *un)
|
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_isowned(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_refcnt++;
|
|
|
|
mutex_enter(&unp->unp_miilock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_unlock_mii(struct usbnet *un)
|
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_miilock);
|
|
|
|
mutex_enter(&unp->unp_lock);
|
|
|
|
if (--unp->unp_refcnt < 0)
|
|
|
|
cv_broadcast(&unp->unp_detachcv);
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_unlock_mii_un_locked(struct usbnet *un)
|
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_isowned(un);
|
2019-08-10 05:17:36 +03:00
|
|
|
|
|
|
|
mutex_exit(&unp->unp_miilock);
|
|
|
|
if (--unp->unp_refcnt < 0)
|
|
|
|
cv_broadcast(&unp->unp_detachcv);
|
|
|
|
}
|
|
|
|
|
|
|
|
kmutex_t *
|
|
|
|
usbnet_mutex_mii(struct usbnet *un)
|
|
|
|
{
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
|
|
|
|
return &unp->unp_miilock;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-08-09 04:17:33 +03:00
|
|
|
usbnet_mii_readreg(device_t dev, int phy, int reg, uint16_t *val)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-19 09:35:14 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = device_private(dev);
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-08-20 09:37:06 +03:00
|
|
|
int err;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
2019-08-19 10:33:37 +03:00
|
|
|
if (unp->unp_dying) {
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
2019-08-19 10:33:37 +03:00
|
|
|
usbnet_lock_mii_un_locked(un);
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-08-09 04:17:33 +03:00
|
|
|
err = uno_read_reg(un, phy, reg, val);
|
2019-07-31 12:13:16 +03:00
|
|
|
usbnet_unlock_mii(un);
|
|
|
|
|
|
|
|
if (err) {
|
2019-08-19 09:35:14 +03:00
|
|
|
USBNETHIST_CALLARGS("read PHY failed: %d", err, 0, 0, 0);
|
2019-08-20 09:37:06 +03:00
|
|
|
return err;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-08-09 04:17:33 +03:00
|
|
|
usbnet_mii_writereg(device_t dev, int phy, int reg, uint16_t val)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
2019-08-19 09:35:14 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = device_private(dev);
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-08-20 09:37:06 +03:00
|
|
|
int err;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
2019-08-19 10:33:37 +03:00
|
|
|
if (unp->unp_dying) {
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
2019-08-19 10:33:37 +03:00
|
|
|
usbnet_lock_mii_un_locked(un);
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-08-09 04:17:33 +03:00
|
|
|
err = uno_write_reg(un, phy, reg, val);
|
2019-07-31 12:13:16 +03:00
|
|
|
usbnet_unlock_mii(un);
|
|
|
|
|
|
|
|
if (err) {
|
2019-08-19 09:35:14 +03:00
|
|
|
USBNETHIST_CALLARGS("write PHY failed: %d", err, 0, 0, 0);
|
2019-08-20 09:37:06 +03:00
|
|
|
return err;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-08-09 04:17:33 +03:00
|
|
|
usbnet_mii_statchg(struct ifnet *ifp)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = ifp->if_softc;
|
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
uno_mii_statchg(un, ifp);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
usbnet_media_upd(struct ifnet *ifp)
|
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = ifp->if_softc;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct mii_data * const mii = usbnet_mii(un);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (unp->unp_dying)
|
2019-07-31 12:13:16 +03:00
|
|
|
return EIO;
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_link = false;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
if (mii->mii_instance) {
|
|
|
|
struct mii_softc *miisc;
|
|
|
|
|
|
|
|
LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
|
|
|
|
mii_phy_reset(miisc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ether_mediachange(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ioctl */
|
|
|
|
|
|
|
|
static int
|
|
|
|
usbnet_ifflags_cb(struct ethercom *ec)
|
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct ifnet *ifp = &ec->ec_if;
|
|
|
|
struct usbnet *un = ifp->if_softc;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
int rv = 0;
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
const int changed = ifp->if_flags ^ unp->unp_if_flags;
|
2019-07-31 12:13:16 +03:00
|
|
|
if ((changed & ~(IFF_CANTCHANGE | IFF_DEBUG)) == 0) {
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_if_flags = ifp->if_flags;
|
2019-07-31 12:13:16 +03:00
|
|
|
if ((changed & IFF_PROMISC) != 0)
|
|
|
|
rv = ENETRESET;
|
|
|
|
} else {
|
|
|
|
rv = ENETRESET;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
usbnet_ioctl(struct ifnet *ifp, u_long cmd, void *data)
|
|
|
|
{
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = ifp->if_softc;
|
2019-08-23 07:29:28 +03:00
|
|
|
struct usbnet_private * const unp __unused = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
int error;
|
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_CALLARGSN(11, "%d: enter %jx data %x",
|
|
|
|
unp->unp_number, cmd, (uintptr_t)data, 0);
|
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
if (un->un_ops->uno_override_ioctl)
|
|
|
|
return uno_override_ioctl(un, ifp, cmd, data);
|
2019-08-06 03:19:57 +03:00
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
2019-08-09 04:17:33 +03:00
|
|
|
if (error == ENETRESET)
|
|
|
|
error = uno_ioctl(un, ifp, cmd, data);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic stop network function:
|
|
|
|
* - mark as stopping
|
|
|
|
* - call DD routine to stop the device
|
|
|
|
* - turn off running, timer, statchg callout, link
|
|
|
|
* - stop transfers
|
|
|
|
* - free RX and TX resources
|
|
|
|
* - close pipes
|
|
|
|
*
|
|
|
|
* usbnet_stop() is exported for drivers to use, expects lock held.
|
|
|
|
*
|
|
|
|
* usbnet_stop_ifp() is for the if_stop handler.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
usbnet_stop(struct usbnet *un, struct ifnet *ifp, int disable)
|
|
|
|
{
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
|
|
|
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_isowned(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_rxlock);
|
|
|
|
mutex_enter(&unp->unp_txlock);
|
|
|
|
unp->unp_stopping = true;
|
|
|
|
mutex_exit(&unp->unp_txlock);
|
|
|
|
mutex_exit(&unp->unp_rxlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
uno_stop(un, ifp, disable);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXSMP Would like to
|
|
|
|
* KASSERT(IFNET_LOCKED(ifp))
|
|
|
|
* here but the locking order is:
|
|
|
|
* ifnet -> unlock -> rxlock -> txlock
|
|
|
|
* and unlock is already held.
|
|
|
|
*/
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_timer = 0;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-09-08 21:59:32 +03:00
|
|
|
callout_halt(&unp->unp_stat_ch, &unp->unp_lock);
|
|
|
|
usb_rem_task_wait(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER,
|
|
|
|
&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/* Stop transfers. */
|
|
|
|
usbnet_ep_stop_pipes(un);
|
|
|
|
|
|
|
|
/* Free RX/TX resources. */
|
|
|
|
usbnet_rx_list_fini(un);
|
|
|
|
usbnet_tx_list_fini(un);
|
|
|
|
|
|
|
|
/* Close pipes. */
|
|
|
|
usbnet_ep_close_pipes(un);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usbnet_stop_ifp(struct ifnet *ifp, int disable)
|
|
|
|
{
|
|
|
|
struct usbnet * const un = ifp->if_softc;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
usbnet_stop(un, ifp, disable);
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic tick task function.
|
|
|
|
*
|
|
|
|
* usbnet_tick() is triggered from a callout, and triggers a call to
|
|
|
|
* usbnet_tick_task() from the usb_task subsystem.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
usbnet_tick(void *arg)
|
|
|
|
{
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = arg;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_CALLARGSN(10, "%d: enter", unp->unp_number, 0, 0, 0);
|
|
|
|
|
2019-08-29 12:17:51 +03:00
|
|
|
if (unp != NULL && !unp->unp_stopping && !unp->unp_dying) {
|
2019-07-31 12:13:16 +03:00
|
|
|
/* Perform periodic stuff in process context */
|
2019-08-10 05:17:36 +03:00
|
|
|
usb_add_task(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usbnet_watchdog(struct ifnet *ifp)
|
|
|
|
{
|
2019-08-23 07:29:28 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = ifp->if_softc;
|
2019-08-18 12:29:38 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_cdata * const cd = un_cdata(un);
|
2019-08-18 12:29:38 +03:00
|
|
|
usbd_status err;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
aprint_error_dev(un->un_dev, "watchdog timeout\n");
|
|
|
|
|
|
|
|
if (cd->uncd_tx_cnt > 0) {
|
2019-08-23 07:29:28 +03:00
|
|
|
DPRINTF("uncd_tx_cnt=%u non zero, aborting pipe", 0, 0, 0, 0);
|
2019-08-18 12:29:38 +03:00
|
|
|
err = usbd_abort_pipe(unp->unp_ep[USBNET_ENDPT_TX]);
|
2019-08-19 10:33:37 +03:00
|
|
|
if (err)
|
|
|
|
aprint_error_dev(un->un_dev, "pipe abort failed: %s\n",
|
|
|
|
usbd_errstr(err));
|
2019-08-23 07:29:28 +03:00
|
|
|
if (cd->uncd_tx_cnt != 0)
|
|
|
|
DPRINTF("uncd_tx_cnt now %u", cd->uncd_tx_cnt, 0, 0, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!IFQ_IS_EMPTY(&ifp->if_snd))
|
|
|
|
(*ifp->if_start)(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usbnet_tick_task(void *arg)
|
|
|
|
{
|
2019-09-08 21:59:32 +03:00
|
|
|
USBNETHIST_FUNC();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = arg;
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-09-08 21:59:32 +03:00
|
|
|
if (unp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
USBNETHIST_CALLARGSN(8, "%d: enter", unp->unp_number, 0, 0, 0);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
|
|
|
if (unp->unp_stopping || unp->unp_dying) {
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
|
|
|
struct mii_data * const mii = usbnet_mii(un);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_refcnt++;
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (ifp && unp->unp_timer != 0 && --unp->unp_timer == 0)
|
2019-07-31 12:13:16 +03:00
|
|
|
usbnet_watchdog(ifp);
|
|
|
|
|
|
|
|
if (mii && ifp) {
|
2019-09-08 21:59:32 +03:00
|
|
|
DPRINTFN(8, "mii %jx ifp %jx", (uintptr_t)mii, (uintptr_t)ifp, 0, 0);
|
2019-07-31 12:13:16 +03:00
|
|
|
mii_tick(mii);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
if (!unp->unp_link)
|
2019-07-31 12:13:16 +03:00
|
|
|
(*mii->mii_statchg)(ifp);
|
|
|
|
}
|
|
|
|
|
2019-08-15 08:52:23 +03:00
|
|
|
/* Call driver if requested. */
|
|
|
|
uno_tick(un);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
|
|
|
if (--unp->unp_refcnt < 0)
|
|
|
|
cv_broadcast(&unp->unp_detachcv);
|
|
|
|
if (!unp->unp_stopping && !unp->unp_dying)
|
|
|
|
callout_schedule(&unp->unp_stat_ch, hz);
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
usbnet_init(struct ifnet *ifp)
|
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = ifp->if_softc;
|
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
return uno_init(un, ifp);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
2019-08-11 04:31:19 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
/* Various accessors. */
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_set_link(struct usbnet *un, bool link)
|
|
|
|
{
|
|
|
|
un->un_pri->unp_link = link;
|
|
|
|
}
|
|
|
|
|
2019-08-14 06:44:58 +03:00
|
|
|
void
|
|
|
|
usbnet_set_dying(struct usbnet *un, bool link)
|
|
|
|
{
|
|
|
|
un->un_pri->unp_dying = link;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
struct ifnet *
|
|
|
|
usbnet_ifp(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return &un->un_pri->unp_ec.ec_if;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ethercom *
|
|
|
|
usbnet_ec(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return &un->un_pri->unp_ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mii_data *
|
|
|
|
usbnet_mii(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return un->un_pri->unp_ec.ec_mii;
|
|
|
|
}
|
|
|
|
|
|
|
|
krndsource_t *
|
|
|
|
usbnet_rndsrc(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return &un->un_pri->unp_rndsrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
usbnet_softc(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return un->un_sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
usbnet_havelink(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return un->un_pri->unp_link;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
usbnet_isdying(struct usbnet *un)
|
|
|
|
{
|
2019-08-29 12:17:51 +03:00
|
|
|
return un->un_pri == NULL || un->un_pri->unp_dying;
|
2019-08-10 05:17:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Locking. */
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_lock(struct usbnet *un)
|
|
|
|
{
|
|
|
|
mutex_enter(&un->un_pri->unp_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_unlock(struct usbnet *un)
|
|
|
|
{
|
|
|
|
mutex_exit(&un->un_pri->unp_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
kmutex_t *
|
|
|
|
usbnet_mutex(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return &un->un_pri->unp_lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_lock_rx(struct usbnet *un)
|
|
|
|
{
|
|
|
|
mutex_enter(&un->un_pri->unp_rxlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_unlock_rx(struct usbnet *un)
|
|
|
|
{
|
|
|
|
mutex_exit(&un->un_pri->unp_rxlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
kmutex_t *
|
|
|
|
usbnet_mutex_rx(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return &un->un_pri->unp_rxlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_lock_tx(struct usbnet *un)
|
|
|
|
{
|
|
|
|
mutex_enter(&un->un_pri->unp_txlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_unlock_tx(struct usbnet *un)
|
|
|
|
{
|
|
|
|
mutex_exit(&un->un_pri->unp_txlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
kmutex_t *
|
|
|
|
usbnet_mutex_tx(struct usbnet *un)
|
|
|
|
{
|
|
|
|
return &un->un_pri->unp_txlock;
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
/* Autoconf management. */
|
|
|
|
|
2019-08-06 03:19:57 +03:00
|
|
|
static bool
|
2019-08-11 04:31:19 +03:00
|
|
|
usbnet_empty_eaddr(struct usbnet * const un)
|
2019-08-06 03:19:57 +03:00
|
|
|
{
|
|
|
|
return (un->un_eaddr[0] == 0 && un->un_eaddr[1] == 0 &&
|
|
|
|
un->un_eaddr[2] == 0 && un->un_eaddr[3] == 0 &&
|
|
|
|
un->un_eaddr[4] == 0 && un->un_eaddr[5] == 0);
|
|
|
|
}
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
/*
|
|
|
|
* usbnet_attach() and usbnet_attach_ifp() perform setup of the relevant
|
|
|
|
* 'usbnet'. The first is enough to enable device access (eg, endpoints
|
|
|
|
* are connected and commands can be sent), and the second connects the
|
|
|
|
* device to the system networking.
|
|
|
|
*
|
|
|
|
* Always call usbnet_detach(), even if usbnet_attach_ifp() is skippped.
|
|
|
|
* Also usable as driver detach directly.
|
2019-08-06 03:19:57 +03:00
|
|
|
*
|
|
|
|
* To skip ethernet configuration (eg, point-to-point), make sure that
|
|
|
|
* the un_eaddr[] is fully zero.
|
2019-07-31 12:13:16 +03:00
|
|
|
*/
|
2019-08-10 05:17:36 +03:00
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
void
|
|
|
|
usbnet_attach(struct usbnet *un,
|
2019-08-10 05:17:36 +03:00
|
|
|
const char *detname) /* detach cv name */
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
/* Required inputs. */
|
|
|
|
KASSERT(un->un_ops->uno_tx_prepare);
|
|
|
|
KASSERT(un->un_ops->uno_rx_loop);
|
|
|
|
KASSERT(un->un_ops->uno_init);
|
2019-08-10 05:17:36 +03:00
|
|
|
KASSERT(un->un_rx_bufsz);
|
|
|
|
KASSERT(un->un_tx_bufsz);
|
|
|
|
KASSERT(un->un_rx_list_cnt);
|
|
|
|
KASSERT(un->un_tx_list_cnt);
|
|
|
|
|
2019-08-12 02:55:43 +03:00
|
|
|
/* Unfortunate fact. */
|
|
|
|
KASSERT(un == device_private(un->un_dev));
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
un->un_pri = kmem_zalloc(sizeof(*un->un_pri), KM_SLEEP);
|
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
|
|
|
|
usb_init_task(&unp->unp_ticktask, usbnet_tick_task, un, USB_TASKQ_MPSAFE);
|
|
|
|
callout_init(&unp->unp_stat_ch, CALLOUT_MPSAFE);
|
|
|
|
callout_setfunc(&unp->unp_stat_ch, usbnet_tick, un);
|
|
|
|
|
|
|
|
mutex_init(&unp->unp_miilock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
mutex_init(&unp->unp_txlock, MUTEX_DEFAULT, IPL_SOFTUSB);
|
|
|
|
mutex_init(&unp->unp_rxlock, MUTEX_DEFAULT, IPL_SOFTUSB);
|
|
|
|
mutex_init(&unp->unp_lock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
cv_init(&unp->unp_detachcv, detname);
|
|
|
|
|
|
|
|
rnd_attach_source(&unp->unp_rndsrc, device_xname(un->un_dev),
|
2019-07-31 12:13:16 +03:00
|
|
|
RND_TYPE_NET, RND_FLAG_DEFAULT);
|
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
usbnet_rx_list_alloc(un);
|
|
|
|
usbnet_tx_list_alloc(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-23 07:29:28 +03:00
|
|
|
unp->unp_number = atomic_inc_uint_nv(&usbnet_number);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_attached = true;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-20 09:37:06 +03:00
|
|
|
usbnet_attach_mii(struct usbnet *un, const struct usbnet_mii *unm)
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
struct mii_data * const mii = &unp->unp_mii;
|
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-09 04:17:33 +03:00
|
|
|
KASSERT(un->un_ops->uno_read_reg);
|
|
|
|
KASSERT(un->un_ops->uno_write_reg);
|
|
|
|
KASSERT(un->un_ops->uno_statchg);
|
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
mii->mii_ifp = ifp;
|
2019-08-09 04:17:33 +03:00
|
|
|
mii->mii_readreg = usbnet_mii_readreg;
|
|
|
|
mii->mii_writereg = usbnet_mii_writereg;
|
|
|
|
mii->mii_statchg = usbnet_mii_statchg;
|
2019-07-31 12:13:16 +03:00
|
|
|
mii->mii_flags = MIIF_AUTOTSLEEP;
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
usbnet_ec(un)->ec_mii = mii;
|
2019-07-31 12:13:16 +03:00
|
|
|
ifmedia_init(&mii->mii_media, 0, usbnet_media_upd, ether_mediastatus);
|
2019-08-20 09:37:06 +03:00
|
|
|
mii_attach(un->un_dev, mii, unm->un_mii_capmask, unm->un_mii_phyloc,
|
|
|
|
unm->un_mii_offset, unm->un_mii_flags);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
if (LIST_FIRST(&mii->mii_phys) == NULL) {
|
|
|
|
ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
|
|
|
|
ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
|
|
|
|
} else
|
|
|
|
ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usbnet_attach_ifp(struct usbnet *un,
|
|
|
|
unsigned if_flags, /* additional if_flags */
|
2019-08-01 02:47:16 +03:00
|
|
|
unsigned if_extflags, /* additional if_extflags */
|
2019-08-20 09:37:06 +03:00
|
|
|
const struct usbnet_mii *unm) /* additional mii_attach flags */
|
2019-07-31 12:13:16 +03:00
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
KASSERT(unp->unp_attached);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
strlcpy(ifp->if_xname, device_xname(un->un_dev), IFNAMSIZ);
|
|
|
|
ifp->if_flags = if_flags;
|
|
|
|
ifp->if_extflags = IFEF_MPSAFE | if_extflags;
|
|
|
|
ifp->if_ioctl = usbnet_ioctl;
|
|
|
|
ifp->if_start = usbnet_start;
|
|
|
|
ifp->if_init = usbnet_init;
|
|
|
|
ifp->if_stop = usbnet_stop_ifp;
|
|
|
|
|
2019-08-20 09:37:06 +03:00
|
|
|
if (unm)
|
|
|
|
usbnet_attach_mii(un, unm);
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
else
|
2019-08-10 05:17:36 +03:00
|
|
|
unp->unp_link = true;
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
/* Attach the interface. */
|
2019-08-18 12:29:38 +03:00
|
|
|
int rv = if_initialize(ifp);
|
|
|
|
if (rv != 0) {
|
|
|
|
aprint_error_dev(un->un_dev, "if_initialize failed(%d)\n", rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ifp->_if_input == NULL)
|
|
|
|
ifp->if_percpuq = if_percpuq_create(ifp);
|
|
|
|
if_register(ifp);
|
2019-08-06 03:19:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If ethernet address is all zero, skip ether_ifattach() and
|
|
|
|
* instead attach bpf here..
|
|
|
|
*/
|
|
|
|
if (!usbnet_empty_eaddr(un)) {
|
2019-08-10 05:17:36 +03:00
|
|
|
ether_set_ifflags_cb(&unp->unp_ec, usbnet_ifflags_cb);
|
2019-08-06 04:42:22 +03:00
|
|
|
aprint_normal_dev(un->un_dev, "Ethernet address %s\n",
|
|
|
|
ether_sprintf(un->un_eaddr));
|
2019-08-06 03:19:57 +03:00
|
|
|
ether_ifattach(ifp, un->un_eaddr);
|
|
|
|
} else {
|
|
|
|
if_alloc_sadl(ifp);
|
|
|
|
bpf_attach(ifp, DLT_RAW, 0);
|
|
|
|
}
|
2019-08-07 04:47:18 +03:00
|
|
|
|
2019-08-18 12:29:38 +03:00
|
|
|
/* Now ready, and attached. */
|
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
|
|
|
ifp->if_softc = un;
|
|
|
|
|
2019-08-07 04:47:18 +03:00
|
|
|
usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, un->un_udev, un->un_dev);
|
|
|
|
|
|
|
|
if (!pmf_device_register(un->un_dev, NULL, NULL))
|
|
|
|
aprint_error_dev(un->un_dev, "couldn't establish power handler\n");
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
usbnet_detach(device_t self, int flags)
|
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = device_private(self);
|
2019-08-28 09:07:21 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
|
|
|
|
|
|
|
/* Detached before attached finished, so just bail out. */
|
|
|
|
if (unp == NULL || !unp->unp_attached)
|
|
|
|
return 0;
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
|
|
|
struct mii_data * const mii = usbnet_mii(un);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
|
|
|
unp->unp_dying = true;
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
IFNET_LOCK(ifp);
|
|
|
|
usbnet_stop_ifp(ifp, 1);
|
|
|
|
IFNET_UNLOCK(ifp);
|
|
|
|
}
|
|
|
|
|
2019-09-08 21:59:32 +03:00
|
|
|
callout_halt(&unp->unp_stat_ch, NULL);
|
|
|
|
usb_rem_task_wait(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER,
|
|
|
|
NULL);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
|
|
|
unp->unp_refcnt--;
|
|
|
|
while (unp->unp_refcnt > 0) {
|
2019-07-31 12:13:16 +03:00
|
|
|
/* Wait for processes to go away */
|
2019-08-10 05:17:36 +03:00
|
|
|
cv_wait(&unp->unp_detachcv, &unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
usbnet_rx_list_free(un);
|
|
|
|
usbnet_tx_list_free(un);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
callout_destroy(&unp->unp_stat_ch);
|
|
|
|
rnd_detach_source(&unp->unp_rndsrc);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
if (mii) {
|
|
|
|
mii_detach(mii, MII_PHY_ANY, MII_OFFSET_ANY);
|
|
|
|
ifmedia_delete_instance(&mii->mii_media, IFM_INST_ANY);
|
2019-09-08 21:59:32 +03:00
|
|
|
usbnet_ec(un)->ec_mii = NULL;
|
2019-07-31 12:13:16 +03:00
|
|
|
}
|
|
|
|
if (ifp->if_softc) {
|
2019-08-06 03:19:57 +03:00
|
|
|
if (!usbnet_empty_eaddr(un))
|
|
|
|
ether_ifdetach(ifp);
|
|
|
|
else
|
|
|
|
bpf_detach(ifp);
|
2019-07-31 12:13:16 +03:00
|
|
|
if_detach(ifp);
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
cv_destroy(&unp->unp_detachcv);
|
|
|
|
mutex_destroy(&unp->unp_lock);
|
|
|
|
mutex_destroy(&unp->unp_rxlock);
|
|
|
|
mutex_destroy(&unp->unp_txlock);
|
|
|
|
mutex_destroy(&unp->unp_miilock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
pmf_device_deregister(un->un_dev);
|
|
|
|
|
|
|
|
usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, un->un_udev, un->un_dev);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
kmem_free(unp, sizeof(*unp));
|
2019-09-08 21:59:32 +03:00
|
|
|
un->un_pri = NULL;
|
2019-08-10 05:17:36 +03:00
|
|
|
|
2019-07-31 12:13:16 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
usbnet_activate(device_t self, devact_t act)
|
|
|
|
{
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
USBNETHIST_FUNC(); USBNETHIST_CALLED();
|
2019-07-31 12:13:16 +03:00
|
|
|
struct usbnet * const un = device_private(self);
|
2019-08-10 05:17:36 +03:00
|
|
|
struct usbnet_private * const unp = un->un_pri;
|
2019-07-31 12:13:16 +03:00
|
|
|
struct ifnet * const ifp = usbnet_ifp(un);
|
|
|
|
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
if_deactivate(ifp);
|
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_lock);
|
|
|
|
unp->unp_dying = true;
|
|
|
|
mutex_exit(&unp->unp_lock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
2019-08-10 05:17:36 +03:00
|
|
|
mutex_enter(&unp->unp_rxlock);
|
|
|
|
mutex_enter(&unp->unp_txlock);
|
|
|
|
unp->unp_stopping = true;
|
|
|
|
mutex_exit(&unp->unp_txlock);
|
|
|
|
mutex_exit(&unp->unp_rxlock);
|
2019-07-31 12:13:16 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE(MODULE_CLASS_MISC, usbnet, NULL);
|
|
|
|
|
|
|
|
static int
|
|
|
|
usbnet_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
new comment:
* if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
* usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
* size, and interval.
the standard handling is in usbnet.c, with a callback to deal with
the interrupt it self. not fully tested, designed for if_aue.c
and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
and *owned*() for asserting
welcome 9.99.3!
2019-08-04 11:59:13 +03:00
|
|
|
return 0;
|
2019-07-31 12:13:16 +03:00
|
|
|
case MODULE_CMD_FINI:
|
|
|
|
return 0;
|
|
|
|
case MODULE_CMD_STAT:
|
|
|
|
case MODULE_CMD_AUTOUNLOAD:
|
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
}
|