[BACK]Return to usbnet.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev / usb

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/dev/usb/usbnet.c between version 1.3 and 1.4

version 1.3, 2019/08/03 15:58:14 version 1.4, 2019/08/04 08:59:13
Line 41  __KERNEL_RCSID(0, "$NetBSD$");
Line 41  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/module.h>  #include <sys/module.h>
   
 #include <dev/usb/usbnet.h>  #include <dev/usb/usbnet.h>
   #include <dev/usb/usbhist.h>
   
 static int usbnet_modcmd(modcmd_t, void *);  static int usbnet_modcmd(modcmd_t, void *);
   
Line 48  static int usbnet_modcmd(modcmd_t, void 
Line 49  static int usbnet_modcmd(modcmd_t, void 
 #ifndef USBNET_DEBUG  #ifndef USBNET_DEBUG
 #define usbnetdebug 0  #define usbnetdebug 0
 #else  #else
 static int usbnetdebug = 20;  static int usbnetdebug = 1;
   
   int     sysctl_hw_usbnet_setup(SYSCTLFN_PROTO);
   
 SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup")  SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup")
 {  {
Line 118  void
Line 121  void
 usbnet_enqueue(struct usbnet * const un, uint8_t *buf, size_t buflen,  usbnet_enqueue(struct usbnet * const un, uint8_t *buf, size_t buflen,
                 int flags)                  int flags)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct ifnet *ifp = &un->un_ec.ec_if;          struct ifnet *ifp = &un->un_ec.ec_if;
         struct mbuf *m;          struct mbuf *m;
   
Line 143  usbnet_enqueue(struct usbnet * const un,
Line 147  usbnet_enqueue(struct usbnet * const un,
  * the higher level protocols.   * the higher level protocols.
  */   */
 static void  static void
 usbnet_rxeof(struct usbd_xfer *xfer, void * priv, usbd_status status)  usbnet_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {  {
         struct usbnet_chain *c = (struct usbnet_chain *)priv;          USBNETHIST_FUNC(); USBNETHIST_CALLED();
           struct usbnet_chain *c = priv;
         struct usbnet * const un = c->unc_un;          struct usbnet * const un = c->unc_un;
         struct ifnet *ifp = &un->un_ec.ec_if;          struct ifnet *ifp = &un->un_ec.ec_if;
         uint32_t total_len;          uint32_t total_len;
Line 195  out:
Line 200  out:
 }  }
   
 static void  static void
 usbnet_txeof(struct usbd_xfer *xfer, void * priv, usbd_status status)  usbnet_txeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {  {
         struct usbnet_chain *c = (struct usbnet_chain *)priv;          USBNETHIST_FUNC(); USBNETHIST_CALLED();
           struct usbnet_chain *c = priv;
         struct usbnet * const un = c->unc_un;          struct usbnet * const un = c->unc_un;
         struct usbnet_cdata *cd = &un->un_cdata;          struct usbnet_cdata *cd = &un->un_cdata;
         struct ifnet * const ifp = usbnet_ifp(un);          struct ifnet * const ifp = usbnet_ifp(un);
Line 240  usbnet_txeof(struct usbd_xfer *xfer, voi
Line 246  usbnet_txeof(struct usbd_xfer *xfer, voi
 }  }
   
 static void  static void
   usbnet_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
   {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
           struct usbnet           *un = priv;
           struct ifnet            *ifp = usbnet_ifp(un);
   
           if (un->un_dying || un->un_stopping ||
               status == USBD_INVAL || status == USBD_NOT_STARTED ||
               status == USBD_CANCELLED || !(ifp->if_flags & IFF_RUNNING))
                   return;
   
           if (status != USBD_NORMAL_COMPLETION) {
                   if (usbd_ratecheck(&un->un_intr_notice)) {
                           aprint_error_dev(un->un_dev, "usb error on intr: %s\n",
                               usbd_errstr(status));
                   }
                   if (status == USBD_STALLED)
                           usbd_clear_endpoint_stall_async(un->un_ep[USBNET_ENDPT_INTR]);
                   return;
           }
   
           if (un->un_intr_cb)
                   (*un->un_intr_cb)(un, status);
   }
   
   static void
 usbnet_start_locked(struct ifnet *ifp)  usbnet_start_locked(struct ifnet *ifp)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = ifp->if_softc;          struct usbnet * const un = ifp->if_softc;
         struct usbnet_cdata *cd = &un->un_cdata;          struct usbnet_cdata *cd = &un->un_cdata;
         struct mbuf *m;          struct mbuf *m;
Line 495  static usbd_status
Line 528  static usbd_status
 usbnet_ep_open_pipes(struct usbnet *un)  usbnet_ep_open_pipes(struct usbnet *un)
 {  {
         for (size_t i = 0; i < __arraycount(un->un_ep); i++) {          for (size_t i = 0; i < __arraycount(un->un_ep); i++) {
                   usbd_status err;
   
                 if (un->un_ed[i] == 0)                  if (un->un_ed[i] == 0)
                         continue;                          continue;
                 usbd_status err = usbd_open_pipe(un->un_iface, un->un_ed[i],  
                     USBD_EXCLUSIVE_USE | USBD_MPSAFE, &un->un_ep[i]);                  if (i == USBNET_ENDPT_INTR && un->un_intr_buf) {
                           err = usbd_open_pipe_intr(un->un_iface, un->un_ed[i],
                               USBD_EXCLUSIVE_USE | USBD_MPSAFE, &un->un_ep[i], un,
                               un->un_intr_buf, un->un_intr_bufsz, usbnet_intr,
                               un->un_intr_interval);
                   } else {
                           err = usbd_open_pipe(un->un_iface, un->un_ed[i],
                               USBD_EXCLUSIVE_USE | USBD_MPSAFE, &un->un_ep[i]);
                   }
                 if (err) {                  if (err) {
                         usbnet_ep_close_pipes(un);                          usbnet_ep_close_pipes(un);
                         return err;                          return err;
Line 525  usbnet_ep_stop_pipes(struct usbnet *un)
Line 568  usbnet_ep_stop_pipes(struct usbnet *un)
 int  int
 usbnet_init_rx_tx(struct usbnet * const un, unsigned rxflags, unsigned txflags)  usbnet_init_rx_tx(struct usbnet * const un, unsigned rxflags, unsigned txflags)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct ifnet * const ifp = usbnet_ifp(un);          struct ifnet * const ifp = usbnet_ifp(un);
         usbd_status err;          usbd_status err;
           int error = 0;
   
           usbnet_isowned(un);
   
           if (un->un_dying) {
                   return EIO;
           }
           un->un_refcnt++;
   
         /* Open RX and TX pipes. */          /* Open RX and TX pipes. */
         err = usbnet_ep_open_pipes(un);          err = usbnet_ep_open_pipes(un);
         if (err) {          if (err) {
                 aprint_error_dev(un->un_dev, "open rx/tx pipes failed: %s\n",                  aprint_error_dev(un->un_dev, "open rx/tx pipes failed: %s\n",
                     usbd_errstr(err));                      usbd_errstr(err));
                 return EIO;                  error = EIO;
                   goto out;
         }          }
   
         /* Init RX ring. */          /* Init RX ring. */
         if (usbnet_rx_list_init(un, rxflags)) {          if (usbnet_rx_list_init(un, rxflags)) {
                 aprint_error_dev(un->un_dev, "rx list init failed\n");                  aprint_error_dev(un->un_dev, "rx list init failed\n");
                 goto nobufs;                  error = ENOBUFS;
                   goto out;
         }          }
   
         /* Init TX ring. */          /* Init TX ring. */
         if (usbnet_tx_list_init(un, txflags)) {          if (usbnet_tx_list_init(un, txflags)) {
                 aprint_error_dev(un->un_dev, "tx list init failed\n");                  aprint_error_dev(un->un_dev, "tx list init failed\n");
                 goto nobufs;                  error = ENOBUFS;
                   goto out;
         }          }
   
         /* Start up the receive pipe(s). */          /* Start up the receive pipe(s). */
Line 556  usbnet_init_rx_tx(struct usbnet * const 
Line 611  usbnet_init_rx_tx(struct usbnet * const 
         ifp->if_flags |= IFF_RUNNING;          ifp->if_flags |= IFF_RUNNING;
   
         callout_schedule(&un->un_stat_ch, hz);          callout_schedule(&un->un_stat_ch, hz);
         return 0;  
   
 nobufs:  out:
         usbnet_rx_list_fini(un);          if (error) {
         usbnet_tx_list_fini(un);                  usbnet_rx_list_fini(un);
         usbnet_ep_close_pipes(un);                  usbnet_tx_list_fini(un);
                   usbnet_ep_close_pipes(un);
           }
           if (--un->un_refcnt < 0)
                   cv_broadcast(&un->un_detachcv);
   
           usbnet_isowned(un);
   
         return ENOBUFS;          return error;
 }  }
   
 /* MII management. */  /* MII management. */
Line 666  usbnet_miibus_writereg(device_t dev, int
Line 726  usbnet_miibus_writereg(device_t dev, int
 void  void
 usbnet_miibus_statchg(struct ifnet *ifp)  usbnet_miibus_statchg(struct ifnet *ifp)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = ifp->if_softc;          struct usbnet * const un = ifp->if_softc;
   
         (*un->un_statchg_cb)(ifp);          (*un->un_statchg_cb)(ifp);
Line 674  usbnet_miibus_statchg(struct ifnet *ifp)
Line 735  usbnet_miibus_statchg(struct ifnet *ifp)
 static int  static int
 usbnet_media_upd(struct ifnet *ifp)  usbnet_media_upd(struct ifnet *ifp)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = ifp->if_softc;          struct usbnet * const un = ifp->if_softc;
         struct mii_data * const mii = usbnet_mii(un);          struct mii_data * const mii = usbnet_mii(un);
   
Line 697  usbnet_media_upd(struct ifnet *ifp)
Line 759  usbnet_media_upd(struct ifnet *ifp)
 static int  static int
 usbnet_ifflags_cb(struct ethercom *ec)  usbnet_ifflags_cb(struct ethercom *ec)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct ifnet *ifp = &ec->ec_if;          struct ifnet *ifp = &ec->ec_if;
         struct usbnet *un = ifp->if_softc;          struct usbnet *un = ifp->if_softc;
         int rv = 0;          int rv = 0;
Line 720  usbnet_ifflags_cb(struct ethercom *ec)
Line 783  usbnet_ifflags_cb(struct ethercom *ec)
 static int  static int
 usbnet_ioctl(struct ifnet *ifp, u_long cmd, void *data)  usbnet_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = ifp->if_softc;          struct usbnet * const un = ifp->if_softc;
         int error;          int error;
   
Line 746  usbnet_ioctl(struct ifnet *ifp, u_long c
Line 810  usbnet_ioctl(struct ifnet *ifp, u_long c
 void  void
 usbnet_stop(struct usbnet *un, struct ifnet *ifp, int disable)  usbnet_stop(struct usbnet *un, struct ifnet *ifp, int disable)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
   
         KASSERT(mutex_owned(&un->un_lock));          KASSERT(mutex_owned(&un->un_lock));
   
         mutex_enter(&un->un_rxlock);          mutex_enter(&un->un_rxlock);
Line 836  usbnet_watchdog(struct ifnet *ifp)
Line 902  usbnet_watchdog(struct ifnet *ifp)
 static void  static void
 usbnet_tick_task(void *arg)  usbnet_tick_task(void *arg)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = arg;          struct usbnet * const un = arg;
   
         mutex_enter(&un->un_lock);          mutex_enter(&un->un_lock);
Line 871  usbnet_tick_task(void *arg)
Line 938  usbnet_tick_task(void *arg)
 static int  static int
 usbnet_init(struct ifnet *ifp)  usbnet_init(struct ifnet *ifp)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = ifp->if_softc;          struct usbnet * const un = ifp->if_softc;
   
         return (*un->un_init_cb)(ifp);          return (*un->un_init_cb)(ifp);
Line 893  usbnet_attach(struct usbnet *un,
Line 961  usbnet_attach(struct usbnet *un,
               unsigned rx_list_cnt,     /* size of rx chain list */                unsigned rx_list_cnt,     /* size of rx chain list */
               unsigned tx_list_cnt)     /* size of tx chain list */                unsigned tx_list_cnt)     /* size of tx chain list */
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
   
         KASSERT(un->un_tx_prepare_cb);          KASSERT(un->un_tx_prepare_cb);
         KASSERT(un->un_rx_loop_cb);          KASSERT(un->un_rx_loop_cb);
Line 926  usbnet_attach(struct usbnet *un,
Line 995  usbnet_attach(struct usbnet *un,
 static void  static void
 usbnet_attach_mii(struct usbnet *un, int mii_flags)  usbnet_attach_mii(struct usbnet *un, int mii_flags)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct mii_data * const mii = &un->un_mii;          struct mii_data * const mii = &un->un_mii;
         struct ifnet *ifp = usbnet_ifp(un);          struct ifnet *ifp = usbnet_ifp(un);
   
Line 959  usbnet_attach_ifp(struct usbnet *un,
Line 1029  usbnet_attach_ifp(struct usbnet *un,
                   unsigned if_extflags,         /* additional if_extflags */                    unsigned if_extflags,         /* additional if_extflags */
                   int mii_flags)                /* additional mii_attach flags */                    int mii_flags)                /* additional mii_attach flags */
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct ifnet *ifp = usbnet_ifp(un);          struct ifnet *ifp = usbnet_ifp(un);
   
         KASSERT(un->un_attached);          KASSERT(un->un_attached);
Line 978  usbnet_attach_ifp(struct usbnet *un,
Line 1049  usbnet_attach_ifp(struct usbnet *un,
   
         if (have_mii)          if (have_mii)
                 usbnet_attach_mii(un, mii_flags);                  usbnet_attach_mii(un, mii_flags);
           else
                   un->un_link = true;
   
         /* Attach the interface. */          /* Attach the interface. */
         if_attach(ifp);          if_attach(ifp);
Line 987  usbnet_attach_ifp(struct usbnet *un,
Line 1060  usbnet_attach_ifp(struct usbnet *un,
 int  int
 usbnet_detach(device_t self, int flags)  usbnet_detach(device_t self, int flags)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = device_private(self);          struct usbnet * const un = device_private(self);
         struct ifnet *ifp = usbnet_ifp(un);          struct ifnet *ifp = usbnet_ifp(un);
         struct mii_data *mii = usbnet_mii(un);          struct mii_data *mii = usbnet_mii(un);
Line 1047  usbnet_detach(device_t self, int flags)
Line 1121  usbnet_detach(device_t self, int flags)
 int  int
 usbnet_activate(device_t self, devact_t act)  usbnet_activate(device_t self, devact_t act)
 {  {
           USBNETHIST_FUNC(); USBNETHIST_CALLED();
         struct usbnet * const un = device_private(self);          struct usbnet * const un = device_private(self);
         struct ifnet * const ifp = usbnet_ifp(un);          struct ifnet * const ifp = usbnet_ifp(un);
   
Line 1077  usbnet_modcmd(modcmd_t cmd, void *arg)
Line 1152  usbnet_modcmd(modcmd_t cmd, void *arg)
 {  {
         switch (cmd) {          switch (cmd) {
         case MODULE_CMD_INIT:          case MODULE_CMD_INIT:
   #ifdef _MODULE
   # if defined(USB_DEBUG) && defined(USBNET_DEBUG)
                   sysctl_hw_usbnet_setup(&usbnet_clog);
   # endif
   #endif
                   return 0;
         case MODULE_CMD_FINI:          case MODULE_CMD_FINI:
   #ifdef _MODULE
   # if defined(USB_DEBUG) && defined(USBNET_DEBUG)
                   sysctl_teardown(&usbnet_clog);
   # endif
   #endif
                 return 0;                  return 0;
         case MODULE_CMD_STAT:          case MODULE_CMD_STAT:
         case MODULE_CMD_AUTOUNLOAD:          case MODULE_CMD_AUTOUNLOAD:

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

CVSweb <webmaster@jp.NetBSD.org>