netinet{,6}: Assert in{,6}_inithead() are only used for system routing tables.
[dragonfly.git] / sys / bus / u4b / net / usb_ethernet.h
1 /* $FreeBSD$ */
2 /*-
3  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _USB_ETHERNET_H_
30 #define _USB_ETHERNET_H_
31
32 #include "opt_inet.h"
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/mbuf.h>
37 #include <sys/socket.h>
38 #include <sys/sockio.h>
39 #include <sys/limits.h>
40
41 #include <net/if.h>
42 #include <net/if_arp.h>
43 #include <net/if_dl.h>
44 #include <net/if_media.h>
45 #include <net/if_types.h>
46 #include <net/bpf.h>
47 #include <net/ethernet.h>
48
49 #include "miibus_if.h"
50
51 #include <dev/netif/mii_layer/mii.h>
52 #include <dev/netif/mii_layer/miivar.h>
53
54 struct usb_ether;
55 struct usb_device_request;
56
57 typedef void (uether_fn_t)(struct usb_ether *);
58
59 struct usb_ether_methods {
60         uether_fn_t             *ue_attach_post;
61         uether_fn_t             *ue_start;
62         uether_fn_t             *ue_init;
63         uether_fn_t             *ue_stop;
64         uether_fn_t             *ue_setmulti;
65         uether_fn_t             *ue_setpromisc;
66         uether_fn_t             *ue_tick;
67         int                     (*ue_mii_upd)(struct ifnet *);
68         void                    (*ue_mii_sts)(struct ifnet *,
69                                     struct ifmediareq *);
70         int                     (*ue_ioctl)(struct ifnet *, u_long, caddr_t,
71                                     struct ucred *);
72         int                     (*ue_attach_post_sub)(struct usb_ether *);
73 };
74
75 struct usb_ether_cfg_task {
76         struct usb_proc_msg hdr;
77         struct usb_ether *ue;
78 };
79
80 struct usb_ether {
81         /* NOTE: the arpcom structure must be first, and usb_ether must be
82                  the first member of any usb ethernet driver softc! This is 
83                  due to assumptions made by code in mii and in other
84                  places in the network stack. See also if_var.h --mpf */
85         struct arpcom           ue_arpcom;
86         struct lock             *ue_lock;
87         const struct usb_ether_methods *ue_methods;
88         struct sysctl_oid       *ue_sysctl_oid;
89         void                    *ue_sc;
90         struct usb_device       *ue_udev; /* used by uether_do_request() */
91         device_t                ue_dev;
92         device_t                ue_miibus;
93
94         struct usb_process      ue_tq;
95         struct sysctl_ctx_list  ue_sysctl_ctx;
96         struct ifqueue          ue_rxq;
97         struct usb_callout      ue_watchdog;
98         struct usb_ether_cfg_task       ue_sync_task[2];
99         struct usb_ether_cfg_task       ue_media_task[2];
100         struct usb_ether_cfg_task       ue_multi_task[2];
101         struct usb_ether_cfg_task       ue_promisc_task[2];
102         struct usb_ether_cfg_task       ue_tick_task[2];
103
104         int                     ue_unit;
105
106         /* ethernet address from eeprom */
107         uint8_t                 ue_eaddr[ETHER_ADDR_LEN];
108 };
109
110 #define uether_do_request(ue,req,data,timo) \
111     usbd_do_request_proc((ue)->ue_udev,&(ue)->ue_tq,req,data,0,NULL,timo)
112
113 uint8_t         uether_pause(struct usb_ether *, unsigned int);
114 struct ifnet    *uether_getifp(struct usb_ether *);
115 struct mii_data *uether_getmii(struct usb_ether *);
116 void            *uether_getsc(struct usb_ether *);
117 int             uether_ifattach(struct usb_ether *);
118 void            uether_ifdetach(struct usb_ether *);
119 int             uether_ifmedia_upd(struct ifnet *);
120 void            uether_init(void *);
121 int             uether_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
122 struct mbuf     *uether_newbuf(void);
123 int             uether_rxmbuf(struct usb_ether *, struct mbuf *, 
124                     unsigned int);
125 int             uether_rxbuf(struct usb_ether *,
126                     struct usb_page_cache *, 
127                     unsigned int, unsigned int);
128 void            uether_rxflush(struct usb_ether *);
129 uint8_t         uether_is_gone(struct usb_ether *);
130 void            uether_start(struct ifnet *, struct ifaltq_subque *);
131 #endif                                  /* _USB_ETHERNET_H_ */