Home | History | Annotate | Line # | Download | only in usb
usbnet.h revision 1.14.2.2
      1  1.14.2.2  martin /*	$NetBSD: usbnet.h,v 1.14.2.2 2019/09/01 13:00:36 martin Exp $	*/
      2  1.14.2.2  martin 
      3  1.14.2.2  martin /*
      4  1.14.2.2  martin  * Copyright (c) 2019 Matthew R. Green
      5  1.14.2.2  martin  * All rights reserved.
      6  1.14.2.2  martin  *
      7  1.14.2.2  martin  * Redistribution and use in source and binary forms, with or without
      8  1.14.2.2  martin  * modification, are permitted provided that the following conditions
      9  1.14.2.2  martin  * are met:
     10  1.14.2.2  martin  * 1. Redistributions of source code must retain the above copyright
     11  1.14.2.2  martin  *    notice, this list of conditions and the following disclaimer.
     12  1.14.2.2  martin  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.14.2.2  martin  *    notice, this list of conditions and the following disclaimer in the
     14  1.14.2.2  martin  *    documentation and/or other materials provided with the distribution.
     15  1.14.2.2  martin  * 3. The name of the author may not be used to endorse or promote products
     16  1.14.2.2  martin  *    derived from this software without specific prior written permission.
     17  1.14.2.2  martin  *
     18  1.14.2.2  martin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.14.2.2  martin  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.14.2.2  martin  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.14.2.2  martin  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.14.2.2  martin  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  1.14.2.2  martin  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  1.14.2.2  martin  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  1.14.2.2  martin  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  1.14.2.2  martin  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.14.2.2  martin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.14.2.2  martin  * SUCH DAMAGE.
     29  1.14.2.2  martin  */
     30  1.14.2.2  martin 
     31  1.14.2.2  martin #ifndef _DEV_USB_USBNET_H
     32  1.14.2.2  martin #define _DEV_USB_USBNET_H
     33  1.14.2.2  martin 
     34  1.14.2.2  martin /*
     35  1.14.2.2  martin  * Common code/data shared by all USB ethernet drivers (using these routines.)
     36  1.14.2.2  martin  *
     37  1.14.2.2  martin  * This framework provides the following features for USB ethernet drivers:
     38  1.14.2.2  martin  *
     39  1.14.2.2  martin  * - USB endpoint pipe handling
     40  1.14.2.2  martin  * - rx and tx chain handling
     41  1.14.2.2  martin  * - generic handlers or support for several struct ifnet callbacks
     42  1.14.2.2  martin  * - MII bus locking
     43  1.14.2.2  martin  * - interrupt handling
     44  1.14.2.2  martin  * - partial autoconf handling
     45  1.14.2.2  martin  *
     46  1.14.2.2  martin  * Consumers of this interface need to:
     47  1.14.2.2  martin  *
     48  1.14.2.2  martin  * - replace most softc members with "struct usbnet" usage, in particular
     49  1.14.2.2  martin  *   use usbnet pointer for ifp->if_softc, and device_private (real softc
     50  1.14.2.2  martin  *   can be stored in un_sc member)
     51  1.14.2.2  martin  * - use MII bus lock / access methods
     52  1.14.2.2  martin  * - usbnet_attach() to initialise and allocate rx/tx chains
     53  1.14.2.2  martin  * - usbnet_attach_ifp() to attach the interface, and either ether_ifattach()
     54  1.14.2.2  martin  *   for ethernet devices, or if_alloc_sadl()/bpf_attach() pair otherwise.
     55  1.14.2.2  martin  * - usbnet_detach() to clean them up
     56  1.14.2.2  martin  * - usbnet_activate() for autoconf
     57  1.14.2.2  martin  * - interface ioctl and start have direct frontends with callbacks for
     58  1.14.2.2  martin  *   device specific handling:
     59  1.14.2.2  martin  *   - ioctl can use either a device-specific override (useful for special
     60  1.14.2.2  martin  *     cases), but provides a normal handler with callback to handle
     61  1.14.2.2  martin  *     ENETRESET conditions that should be sufficient for most users
     62  1.14.2.2  martin  *   - start uses usbnet send callback
     63  1.14.2.2  martin  * - interface init and stop have helper functions
     64  1.14.2.2  martin  *   - device specific init should use usbnet_init_rx_tx() to open pipes
     65  1.14.2.2  martin  *     to the device and setup the rx/tx chains for use after any device
     66  1.14.2.2  martin  *     specific setup
     67  1.14.2.2  martin  *   - usbnet_stop() must be called with the un_lock held, and will
     68  1.14.2.2  martin  *     call the device-specific usbnet stop callback, which enables the
     69  1.14.2.2  martin  *     standard init calls stop idiom.
     70  1.14.2.2  martin  * - interrupt handling:
     71  1.14.2.2  martin  *   - for rx, usbnet_init_rx_tx() will enable the receive pipes and
     72  1.14.2.2  martin  *     call the rx_loop callback to handle device specific processing of
     73  1.14.2.2  martin  *     packets, which can use usbnet_enqueue() to provide data to the
     74  1.14.2.2  martin  *     higher layers
     75  1.14.2.2  martin  *   - for tx, usbnet_start (if_start) will pull entries out of the
     76  1.14.2.2  martin  *     transmit queue and use the send callback for the given mbuf.
     77  1.14.2.2  martin  *     the usb callback will use usbnet_txeof() for the transmit
     78  1.14.2.2  martin  *     completion function (internal to usbnet)
     79  1.14.2.2  martin  *   - there is special interrupt pipe handling
     80  1.14.2.2  martin  * - timer/tick:
     81  1.14.2.2  martin  *   - the uno_tick callback will be called once a second if present.
     82  1.14.2.2  martin  */
     83  1.14.2.2  martin 
     84  1.14.2.2  martin #include <sys/device.h>
     85  1.14.2.2  martin #include <sys/mbuf.h>
     86  1.14.2.2  martin #include <sys/rndsource.h>
     87  1.14.2.2  martin #include <sys/mutex.h>
     88  1.14.2.2  martin #include <sys/module.h>
     89  1.14.2.2  martin #include <sys/sysctl.h>
     90  1.14.2.2  martin 
     91  1.14.2.2  martin #include <net/bpf.h>
     92  1.14.2.2  martin #include <net/if.h>
     93  1.14.2.2  martin #include <net/if_arp.h>
     94  1.14.2.2  martin #include <net/if_dl.h>
     95  1.14.2.2  martin #include <net/if_ether.h>
     96  1.14.2.2  martin #include <net/if_media.h>
     97  1.14.2.2  martin 
     98  1.14.2.2  martin #include <dev/mii/mii.h>
     99  1.14.2.2  martin #include <dev/mii/miivar.h>
    100  1.14.2.2  martin 
    101  1.14.2.2  martin #include <dev/usb/usb.h>
    102  1.14.2.2  martin #include <dev/usb/usbdi.h>
    103  1.14.2.2  martin #include <dev/usb/usbdivar.h>
    104  1.14.2.2  martin #include <dev/usb/usbdi_util.h>
    105  1.14.2.2  martin #include <dev/usb/usbdevs.h>
    106  1.14.2.2  martin 
    107  1.14.2.2  martin /*
    108  1.14.2.2  martin  * Per-transfer data.
    109  1.14.2.2  martin  *
    110  1.14.2.2  martin  * Front-end must set un_rx_list_cnt and un_tx_list_cnt before
    111  1.14.2.2  martin  * calling usbnet_attach(), and then call usbnet_rx_tx_init()
    112  1.14.2.2  martin  * which will allocate the chain arrays, and must be NULL to
    113  1.14.2.2  martin  * indicate the first call.
    114  1.14.2.2  martin  */
    115  1.14.2.2  martin struct usbnet;
    116  1.14.2.2  martin struct usbnet_chain {
    117  1.14.2.2  martin 	struct usbnet		*unc_un;
    118  1.14.2.2  martin 	struct usbd_xfer	*unc_xfer;
    119  1.14.2.2  martin 	uint8_t			*unc_buf;
    120  1.14.2.2  martin };
    121  1.14.2.2  martin 
    122  1.14.2.2  martin /*
    123  1.14.2.2  martin  * Extend this as necessary.  axe(4) claims to want 6 total, but
    124  1.14.2.2  martin  * does not implement them.
    125  1.14.2.2  martin  */
    126  1.14.2.2  martin enum usbnet_ep {
    127  1.14.2.2  martin 	USBNET_ENDPT_RX,
    128  1.14.2.2  martin 	USBNET_ENDPT_TX,
    129  1.14.2.2  martin 	USBNET_ENDPT_INTR,
    130  1.14.2.2  martin 	USBNET_ENDPT_MAX,
    131  1.14.2.2  martin };
    132  1.14.2.2  martin 
    133  1.14.2.2  martin /* Interface stop callback. */
    134  1.14.2.2  martin typedef void (*usbnet_stop_cb)(struct ifnet *, int);
    135  1.14.2.2  martin /* Interface ioctl callback. */
    136  1.14.2.2  martin typedef int (*usbnet_ioctl_cb)(struct ifnet *, u_long, void *);
    137  1.14.2.2  martin /* Initialise device callback. */
    138  1.14.2.2  martin typedef int (*usbnet_init_cb)(struct ifnet *);
    139  1.14.2.2  martin 
    140  1.14.2.2  martin /* MII read register callback. */
    141  1.14.2.2  martin typedef int (*usbnet_mii_read_reg_cb)(struct usbnet *, int reg,
    142  1.14.2.2  martin 				      int phy, uint16_t *val);
    143  1.14.2.2  martin /* MII write register callback. */
    144  1.14.2.2  martin typedef int (*usbnet_mii_write_reg_cb)(struct usbnet *, int reg,
    145  1.14.2.2  martin 				       int phy, uint16_t val);
    146  1.14.2.2  martin /* MII status change callback. */
    147  1.14.2.2  martin typedef void (*usbnet_mii_statchg_cb)(struct ifnet *);
    148  1.14.2.2  martin 
    149  1.14.2.2  martin /* Prepare packet to send callback, returns length. */
    150  1.14.2.2  martin typedef unsigned (*usbnet_tx_prepare_cb)(struct usbnet *, struct mbuf *,
    151  1.14.2.2  martin 					 struct usbnet_chain *);
    152  1.14.2.2  martin /* Receive some packets callback. */
    153  1.14.2.2  martin typedef void (*usbnet_rx_loop_cb)(struct usbnet *, struct usbnet_chain *,
    154  1.14.2.2  martin 				  uint32_t);
    155  1.14.2.2  martin /* Tick callback. */
    156  1.14.2.2  martin typedef void (*usbnet_tick_cb)(struct usbnet *);
    157  1.14.2.2  martin /* Interrupt pipe callback. */
    158  1.14.2.2  martin typedef void (*usbnet_intr_cb)(struct usbnet *, usbd_status);
    159  1.14.2.2  martin 
    160  1.14.2.2  martin struct usbnet_ops {
    161  1.14.2.2  martin 	usbnet_stop_cb		uno_stop;
    162  1.14.2.2  martin 	usbnet_ioctl_cb		uno_ioctl;
    163  1.14.2.2  martin 	usbnet_ioctl_cb		uno_override_ioctl;
    164  1.14.2.2  martin 	usbnet_init_cb		uno_init;
    165  1.14.2.2  martin 	usbnet_mii_read_reg_cb	uno_read_reg;
    166  1.14.2.2  martin 	usbnet_mii_write_reg_cb uno_write_reg;
    167  1.14.2.2  martin 	usbnet_mii_statchg_cb	uno_statchg;
    168  1.14.2.2  martin 	usbnet_tx_prepare_cb	uno_tx_prepare;
    169  1.14.2.2  martin 	usbnet_rx_loop_cb	uno_rx_loop;
    170  1.14.2.2  martin 	usbnet_tick_cb		uno_tick;
    171  1.14.2.2  martin 	usbnet_intr_cb		uno_intr;
    172  1.14.2.2  martin };
    173  1.14.2.2  martin 
    174  1.14.2.2  martin /*
    175  1.14.2.2  martin  * USB interrupt pipe support.  Use this if usbd_open_pipe_intr() should
    176  1.14.2.2  martin  * be used for the interrupt pipe.
    177  1.14.2.2  martin  */
    178  1.14.2.2  martin struct usbnet_intr {
    179  1.14.2.2  martin 	/*
    180  1.14.2.2  martin 	 * Point un_intr to this structure to use usbd_open_pipe_intr() not
    181  1.14.2.2  martin 	 * usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer, size,
    182  1.14.2.2  martin 	 * and interval.
    183  1.14.2.2  martin 	 */
    184  1.14.2.2  martin 	void			*uni_buf;
    185  1.14.2.2  martin 	unsigned		uni_bufsz;
    186  1.14.2.2  martin 	unsigned		uni_interval;
    187  1.14.2.2  martin };
    188  1.14.2.2  martin 
    189  1.14.2.2  martin /*
    190  1.14.2.2  martin  * Structure to setup MII.  Use the USBNET_MII_DECL_DEFAULT() macro for
    191  1.14.2.2  martin  * sane default.  Pass a copy to usbnet_attach_ifp().  Not used
    192  1.14.2.2  martin  * after the usbnet_attach_ifp() function returns.
    193  1.14.2.2  martin  */
    194  1.14.2.2  martin struct usbnet_mii {
    195  1.14.2.2  martin 	int			un_mii_flags;
    196  1.14.2.2  martin 	int			un_mii_capmask;
    197  1.14.2.2  martin 	int			un_mii_phyloc;
    198  1.14.2.2  martin 	int			un_mii_offset;
    199  1.14.2.2  martin };
    200  1.14.2.2  martin 
    201  1.14.2.2  martin #define UBSNET_MII_DECL(name, capmask, loc, off, flags)	\
    202  1.14.2.2  martin 	struct usbnet_mii name = {			\
    203  1.14.2.2  martin 		.un_mii_capmask = capmask,		\
    204  1.14.2.2  martin 		.un_mii_phyloc = loc,			\
    205  1.14.2.2  martin 		.un_mii_offset = off,			\
    206  1.14.2.2  martin 		.un_mii_flags = flags,			\
    207  1.14.2.2  martin 	}
    208  1.14.2.2  martin #define USBNET_MII_DECL_DEFAULT(name)				\
    209  1.14.2.2  martin 	UBSNET_MII_DECL(name, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0)
    210  1.14.2.2  martin 
    211  1.14.2.2  martin /*
    212  1.14.2.2  martin  * Generic USB ethernet structure.  Use this as ifp->if_softc and set as
    213  1.14.2.2  martin  * device_private() in attach unless already using struct usbnet here.
    214  1.14.2.2  martin  *
    215  1.14.2.2  martin  * Devices without MII should call usbnet_attach_ifp() with have_mii set
    216  1.14.2.2  martin  * to true, and should ensure that the un_statchg_cb callback sets the
    217  1.14.2.2  martin  * un_link member.  Devices without MII have this forced to true.
    218  1.14.2.2  martin  */
    219  1.14.2.2  martin struct usbnet_private;
    220  1.14.2.2  martin struct usbnet {
    221  1.14.2.2  martin 	/*
    222  1.14.2.2  martin 	 * This section should be filled in before calling
    223  1.14.2.2  martin 	 * usbnet_attach().
    224  1.14.2.2  martin 	 */
    225  1.14.2.2  martin 	void			*un_sc;			/* real softc */
    226  1.14.2.2  martin 	device_t		un_dev;
    227  1.14.2.2  martin 	struct usbd_interface	*un_iface;
    228  1.14.2.2  martin 	struct usbd_device	*un_udev;
    229  1.14.2.2  martin 	struct usbnet_ops	*un_ops;
    230  1.14.2.2  martin 	struct usbnet_intr	*un_intr;
    231  1.14.2.2  martin 
    232  1.14.2.2  martin 	/* Inputs for rx/tx chain control. */
    233  1.14.2.2  martin 	unsigned		un_rx_bufsz;
    234  1.14.2.2  martin 	unsigned		un_tx_bufsz;
    235  1.14.2.2  martin 	unsigned		un_rx_list_cnt;
    236  1.14.2.2  martin 	unsigned		un_tx_list_cnt;
    237  1.14.2.2  martin 	int			un_rx_xfer_flags;
    238  1.14.2.2  martin 	int			un_tx_xfer_flags;
    239  1.14.2.2  martin 
    240  1.14.2.2  martin 	/*
    241  1.14.2.2  martin 	 * This section should be filled in before calling
    242  1.14.2.2  martin 	 * usbnet_attach_ifp().
    243  1.14.2.2  martin 	 */
    244  1.14.2.2  martin 	enum usbnet_ep		un_ed[USBNET_ENDPT_MAX];
    245  1.14.2.2  martin 
    246  1.14.2.2  martin 	/* MII specific. Not used without MII. */
    247  1.14.2.2  martin 	int			un_phyno;
    248  1.14.2.2  martin 	/* Ethernet specific. All zeroes indicates non-Ethernet. */
    249  1.14.2.2  martin 	uint8_t			un_eaddr[ETHER_ADDR_LEN];
    250  1.14.2.2  martin 
    251  1.14.2.2  martin 	/*
    252  1.14.2.2  martin 	 * This section is for driver to use, not touched by usbnet.
    253  1.14.2.2  martin 	 */
    254  1.14.2.2  martin 	unsigned		un_flags;
    255  1.14.2.2  martin 
    256  1.14.2.2  martin 	/*
    257  1.14.2.2  martin 	 * This section is private to usbnet. Don't touch.
    258  1.14.2.2  martin 	 */
    259  1.14.2.2  martin 	struct usbnet_private	*un_pri;
    260  1.14.2.2  martin 
    261  1.14.2.2  martin 	/*
    262  1.14.2.2  martin 	 * NetBSD 9.x specific portion.  Not needed afterwards.
    263  1.14.2.2  martin 	 *
    264  1.14.2.2  martin 	 * This structure will be passed to sysctl_teardown() in
    265  1.14.2.2  martin 	 * usbnet_detach() if it is not NULL.
    266  1.14.2.2  martin 	 */
    267  1.14.2.2  martin 	struct sysctllog	*un_sysctl_log;
    268  1.14.2.2  martin };
    269  1.14.2.2  martin 
    270  1.14.2.2  martin /* Various accessors. */
    271  1.14.2.2  martin 
    272  1.14.2.2  martin void usbnet_set_link(struct usbnet *, bool);
    273  1.14.2.2  martin void usbnet_set_dying(struct usbnet *, bool);
    274  1.14.2.2  martin 
    275  1.14.2.2  martin struct ifnet *usbnet_ifp(struct usbnet *);
    276  1.14.2.2  martin struct ethercom *usbnet_ec(struct usbnet *);
    277  1.14.2.2  martin struct mii_data *usbnet_mii(struct usbnet *);
    278  1.14.2.2  martin krndsource_t *usbnet_rndsrc(struct usbnet *);
    279  1.14.2.2  martin void *usbnet_softc(struct usbnet *);
    280  1.14.2.2  martin 
    281  1.14.2.2  martin bool usbnet_havelink(struct usbnet *);
    282  1.14.2.2  martin bool usbnet_isdying(struct usbnet *);
    283  1.14.2.2  martin 
    284  1.14.2.2  martin 
    285  1.14.2.2  martin /*
    286  1.14.2.2  martin  * Locking.  Note that the isowned() are implemented here so that
    287  1.14.2.2  martin  * empty-KASSERT() causes them to be elided for non-DIAG builds.
    288  1.14.2.2  martin  */
    289  1.14.2.2  martin void	usbnet_lock(struct usbnet *);
    290  1.14.2.2  martin void	usbnet_unlock(struct usbnet *);
    291  1.14.2.2  martin kmutex_t *usbnet_mutex(struct usbnet *);
    292  1.14.2.2  martin static __inline__ void
    293  1.14.2.2  martin usbnet_isowned(struct usbnet *un)
    294  1.14.2.2  martin {
    295  1.14.2.2  martin 	KASSERT(mutex_owned(usbnet_mutex(un)));
    296  1.14.2.2  martin }
    297  1.14.2.2  martin 
    298  1.14.2.2  martin void	usbnet_lock_rx(struct usbnet *);
    299  1.14.2.2  martin void	usbnet_unlock_rx(struct usbnet *);
    300  1.14.2.2  martin kmutex_t *usbnet_mutex_rx(struct usbnet *);
    301  1.14.2.2  martin static __inline__ void
    302  1.14.2.2  martin usbnet_isowned_rx(struct usbnet *un)
    303  1.14.2.2  martin {
    304  1.14.2.2  martin 	KASSERT(mutex_owned(usbnet_mutex_rx(un)));
    305  1.14.2.2  martin }
    306  1.14.2.2  martin 
    307  1.14.2.2  martin void	usbnet_lock_tx(struct usbnet *);
    308  1.14.2.2  martin void	usbnet_unlock_tx(struct usbnet *);
    309  1.14.2.2  martin kmutex_t *usbnet_mutex_tx(struct usbnet *);
    310  1.14.2.2  martin static __inline__ void
    311  1.14.2.2  martin usbnet_isowned_tx(struct usbnet *un)
    312  1.14.2.2  martin {
    313  1.14.2.2  martin 	KASSERT(mutex_owned(usbnet_mutex_tx(un)));
    314  1.14.2.2  martin }
    315  1.14.2.2  martin 
    316  1.14.2.2  martin /*
    317  1.14.2.2  martin  * Endpoint / rx/tx chain management:
    318  1.14.2.2  martin  *
    319  1.14.2.2  martin  * usbnet_attach() initialises usbnet and allocates rx and tx chains
    320  1.14.2.2  martin  * usbnet_init_rx_tx() open pipes, initialises the rx/tx chains for use
    321  1.14.2.2  martin  * usbnet_stop() stops pipes, cleans (not frees) rx/tx chains, locked
    322  1.14.2.2  martin  *               version assumes un_lock is held
    323  1.14.2.2  martin  * usbnet_detach() frees the rx/tx chains
    324  1.14.2.2  martin  *
    325  1.14.2.2  martin  * Setup un_ed[] with valid end points before calling usbnet_attach().
    326  1.14.2.2  martin  * Call usbnet_init_rx_tx() to initialise pipes, which will be open
    327  1.14.2.2  martin  * upon success.
    328  1.14.2.2  martin  */
    329  1.14.2.2  martin int	usbnet_init_rx_tx(struct usbnet * const);
    330  1.14.2.2  martin 
    331  1.14.2.2  martin /* MII. */
    332  1.14.2.2  martin void	usbnet_lock_mii(struct usbnet *);
    333  1.14.2.2  martin void	usbnet_lock_mii_un_locked(struct usbnet *);
    334  1.14.2.2  martin void	usbnet_unlock_mii(struct usbnet *);
    335  1.14.2.2  martin void	usbnet_unlock_mii_un_locked(struct usbnet *);
    336  1.14.2.2  martin kmutex_t *usbnet_mutex_mii(struct usbnet *);
    337  1.14.2.2  martin static __inline__ void
    338  1.14.2.2  martin usbnet_isowned_mii(struct usbnet *un)
    339  1.14.2.2  martin {
    340  1.14.2.2  martin 	KASSERT(mutex_owned(usbnet_mutex_mii(un)));
    341  1.14.2.2  martin }
    342  1.14.2.2  martin 
    343  1.14.2.2  martin 
    344  1.14.2.2  martin int	usbnet_mii_readreg(device_t, int, int, uint16_t *);
    345  1.14.2.2  martin int	usbnet_mii_writereg(device_t, int, int, uint16_t);
    346  1.14.2.2  martin void	usbnet_mii_statchg(struct ifnet *);
    347  1.14.2.2  martin 
    348  1.14.2.2  martin /* interrupt handling */
    349  1.14.2.2  martin void	usbnet_enqueue(struct usbnet * const, uint8_t *, size_t, int,
    350  1.14.2.2  martin 		       uint32_t, int);
    351  1.14.2.2  martin void	usbnet_input(struct usbnet * const, uint8_t *, size_t);
    352  1.14.2.2  martin 
    353  1.14.2.2  martin /* autoconf */
    354  1.14.2.2  martin void	usbnet_attach(struct usbnet *un, const char *);
    355  1.14.2.2  martin void	usbnet_attach_ifp(struct usbnet *, unsigned, unsigned, const struct usbnet_mii *);
    356  1.14.2.2  martin int	usbnet_detach(device_t, int);
    357  1.14.2.2  martin int	usbnet_activate(device_t, devact_t);
    358  1.14.2.2  martin 
    359  1.14.2.2  martin /* stop backend */
    360  1.14.2.2  martin void	usbnet_stop(struct usbnet *, struct ifnet *, int);
    361  1.14.2.2  martin 
    362  1.14.2.2  martin /* module hook up */
    363  1.14.2.2  martin 
    364  1.14.2.2  martin #ifdef _MODULE
    365  1.14.2.2  martin #define USENET_INIT(name)						\
    366  1.14.2.2  martin 	error = config_init_component(cfdriver_ioconf_##name,		\
    367  1.14.2.2  martin 	    cfattach_ioconf_##name, cfdata_ioconf_##name);
    368  1.14.2.2  martin #define USENET_FINI(name)						\
    369  1.14.2.2  martin 	error = config_fini_component(cfdriver_ioconf_##name,		\
    370  1.14.2.2  martin 	    cfattach_ioconf_##name, cfdata_ioconf_##name);
    371  1.14.2.2  martin #else
    372  1.14.2.2  martin #define USENET_INIT(name)
    373  1.14.2.2  martin #define USENET_FINI(name)
    374  1.14.2.2  martin #endif
    375  1.14.2.2  martin 
    376  1.14.2.2  martin #define USBNET_MODULE(name)						\
    377  1.14.2.2  martin 									\
    378  1.14.2.2  martin MODULE(MODULE_CLASS_DRIVER, if_##name, "usbnet");			\
    379  1.14.2.2  martin 									\
    380  1.14.2.2  martin static int								\
    381  1.14.2.2  martin if_##name##_modcmd(modcmd_t cmd, void *aux)				\
    382  1.14.2.2  martin {									\
    383  1.14.2.2  martin 	int error = 0;							\
    384  1.14.2.2  martin 									\
    385  1.14.2.2  martin 	switch (cmd) {							\
    386  1.14.2.2  martin 	case MODULE_CMD_INIT:						\
    387  1.14.2.2  martin 		USENET_INIT(name)					\
    388  1.14.2.2  martin 		return error;						\
    389  1.14.2.2  martin 	case MODULE_CMD_FINI:						\
    390  1.14.2.2  martin 		USENET_FINI(name)					\
    391  1.14.2.2  martin 		return error;						\
    392  1.14.2.2  martin 	default:							\
    393  1.14.2.2  martin 		return ENOTTY;						\
    394  1.14.2.2  martin 	}								\
    395  1.14.2.2  martin }
    396  1.14.2.2  martin 
    397  1.14.2.2  martin #endif /* _DEV_USB_USBNET_H */
    398