3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef _USB_ETHERNET_H_
32 #define _USB_ETHERNET_H_
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/socket.h>
40 #include <sys/sockio.h>
41 #include <sys/limits.h>
44 #include <net/if_arp.h>
45 #include <net/if_dl.h>
46 #include <net/if_media.h>
47 #include <net/if_types.h>
49 #include <net/ethernet.h>
51 #include "miibus_if.h"
53 #include <dev/mii/mii.h>
54 #include <dev/mii/miivar.h>
57 struct usb_device_request;
59 typedef void (uether_fn_t)(struct usb_ether *);
61 struct usb_ether_methods {
62 uether_fn_t *ue_attach_post;
63 uether_fn_t *ue_start;
66 uether_fn_t *ue_setmulti;
67 uether_fn_t *ue_setpromisc;
69 int (*ue_mii_upd)(struct ifnet *);
70 void (*ue_mii_sts)(struct ifnet *,
72 int (*ue_ioctl)(struct ifnet *, u_long, caddr_t);
73 int (*ue_attach_post_sub)(struct usb_ether *);
76 struct usb_ether_cfg_task {
77 struct usb_proc_msg hdr;
82 /* NOTE: the "ue_ifp" pointer must be first --hps */
85 const struct usb_ether_methods *ue_methods;
86 struct sysctl_oid *ue_sysctl_oid;
88 struct usb_device *ue_udev; /* used by uether_do_request() */
92 struct usb_process ue_tq;
93 struct sysctl_ctx_list ue_sysctl_ctx;
94 struct ifqueue ue_rxq;
95 struct usb_callout ue_watchdog;
96 struct usb_ether_cfg_task ue_sync_task[2];
97 struct usb_ether_cfg_task ue_media_task[2];
98 struct usb_ether_cfg_task ue_multi_task[2];
99 struct usb_ether_cfg_task ue_promisc_task[2];
100 struct usb_ether_cfg_task ue_tick_task[2];
104 /* ethernet address from eeprom */
105 uint8_t ue_eaddr[ETHER_ADDR_LEN];
108 #define uether_do_request(ue,req,data,timo) \
109 usbd_do_request_proc((ue)->ue_udev,&(ue)->ue_tq,req,data,0,NULL,timo)
111 uint8_t uether_pause(struct usb_ether *, unsigned int);
112 struct ifnet *uether_getifp(struct usb_ether *);
113 struct mii_data *uether_getmii(struct usb_ether *);
114 void *uether_getsc(struct usb_ether *);
115 int uether_ifattach(struct usb_ether *);
116 void uether_ifdetach(struct usb_ether *);
117 int uether_ifmedia_upd(struct ifnet *);
118 void uether_init(void *);
119 int uether_ioctl(struct ifnet *, u_long, caddr_t);
120 struct mbuf *uether_newbuf(void);
121 int uether_rxmbuf(struct usb_ether *, struct mbuf *,
123 int uether_rxbuf(struct usb_ether *,
124 struct usb_page_cache *,
125 unsigned int, unsigned int);
126 void uether_rxflush(struct usb_ether *);
127 uint8_t uether_is_gone(struct usb_ether *);
128 void uether_start(struct ifnet *);
129 #endif /* _USB_ETHERNET_H_ */