102ac6454SAndrew Thompson /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 402ac6454SAndrew Thompson * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 502ac6454SAndrew Thompson * 602ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 702ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 802ac6454SAndrew Thompson * are met: 902ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1002ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1102ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1202ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1302ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1402ac6454SAndrew Thompson * 1502ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1602ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1702ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1802ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1902ac6454SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2002ac6454SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2102ac6454SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2202ac6454SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2302ac6454SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2402ac6454SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2502ac6454SAndrew Thompson * SUCH DAMAGE. 2602ac6454SAndrew Thompson */ 2702ac6454SAndrew Thompson 2875973647SAndrew Thompson #ifndef _USB_ETHERNET_H_ 2975973647SAndrew Thompson #define _USB_ETHERNET_H_ 3002ac6454SAndrew Thompson 3102ac6454SAndrew Thompson #include "opt_inet.h" 3202ac6454SAndrew Thompson 3302ac6454SAndrew Thompson #include <sys/param.h> 3402ac6454SAndrew Thompson #include <sys/systm.h> 3502ac6454SAndrew Thompson #include <sys/mbuf.h> 3602ac6454SAndrew Thompson #include <sys/socket.h> 3702ac6454SAndrew Thompson #include <sys/sockio.h> 3802ac6454SAndrew Thompson #include <sys/limits.h> 3902ac6454SAndrew Thompson 4002ac6454SAndrew Thompson #include <net/if.h> 4102ac6454SAndrew Thompson #include <net/if_arp.h> 4202ac6454SAndrew Thompson #include <net/if_dl.h> 4302ac6454SAndrew Thompson #include <net/if_media.h> 4402ac6454SAndrew Thompson #include <net/if_types.h> 4502ac6454SAndrew Thompson #include <net/bpf.h> 4602ac6454SAndrew Thompson #include <net/ethernet.h> 4702ac6454SAndrew Thompson 48df845c0fSStephen J. Kiernan struct mii_data; 49760bc48eSAndrew Thompson struct usb_ether; 50760bc48eSAndrew Thompson struct usb_device_request; 5102ac6454SAndrew Thompson 52e0a69b51SAndrew Thompson typedef void (uether_fn_t)(struct usb_ether *); 5302ac6454SAndrew Thompson 54760bc48eSAndrew Thompson struct usb_ether_methods { 55e0a69b51SAndrew Thompson uether_fn_t *ue_attach_post; 56e0a69b51SAndrew Thompson uether_fn_t *ue_start; 57e0a69b51SAndrew Thompson uether_fn_t *ue_init; 58e0a69b51SAndrew Thompson uether_fn_t *ue_stop; 59e0a69b51SAndrew Thompson uether_fn_t *ue_setmulti; 60e0a69b51SAndrew Thompson uether_fn_t *ue_setpromisc; 61e0a69b51SAndrew Thompson uether_fn_t *ue_tick; 622fda7967SJustin Hibbits int (*ue_mii_upd)(if_t); 632fda7967SJustin Hibbits void (*ue_mii_sts)(if_t, 6402ac6454SAndrew Thompson struct ifmediareq *); 652fda7967SJustin Hibbits int (*ue_ioctl)(if_t, u_long, caddr_t); 665c6b53d8SPyun YongHyeon int (*ue_attach_post_sub)(struct usb_ether *); 6702ac6454SAndrew Thompson }; 6802ac6454SAndrew Thompson 69760bc48eSAndrew Thompson struct usb_ether_cfg_task { 70760bc48eSAndrew Thompson struct usb_proc_msg hdr; 71760bc48eSAndrew Thompson struct usb_ether *ue; 7202ac6454SAndrew Thompson }; 7302ac6454SAndrew Thompson 74760bc48eSAndrew Thompson struct usb_ether { 7502ac6454SAndrew Thompson /* NOTE: the "ue_ifp" pointer must be first --hps */ 762fda7967SJustin Hibbits if_t ue_ifp; 7702ac6454SAndrew Thompson struct mtx *ue_mtx; 78760bc48eSAndrew Thompson const struct usb_ether_methods *ue_methods; 7902ac6454SAndrew Thompson struct sysctl_oid *ue_sysctl_oid; 8002ac6454SAndrew Thompson void *ue_sc; 81a593f6b8SAndrew Thompson struct usb_device *ue_udev; /* used by uether_do_request() */ 8202ac6454SAndrew Thompson device_t ue_dev; 8302ac6454SAndrew Thompson device_t ue_miibus; 8402ac6454SAndrew Thompson 85760bc48eSAndrew Thompson struct usb_process ue_tq; 8602ac6454SAndrew Thompson struct sysctl_ctx_list ue_sysctl_ctx; 8735d3dd8bSGleb Smirnoff struct mbufq ue_rxq; 88760bc48eSAndrew Thompson struct usb_callout ue_watchdog; 89760bc48eSAndrew Thompson struct usb_ether_cfg_task ue_sync_task[2]; 90760bc48eSAndrew Thompson struct usb_ether_cfg_task ue_media_task[2]; 91760bc48eSAndrew Thompson struct usb_ether_cfg_task ue_multi_task[2]; 92760bc48eSAndrew Thompson struct usb_ether_cfg_task ue_promisc_task[2]; 93760bc48eSAndrew Thompson struct usb_ether_cfg_task ue_tick_task[2]; 9402ac6454SAndrew Thompson 9502ac6454SAndrew Thompson int ue_unit; 9602ac6454SAndrew Thompson 9702ac6454SAndrew Thompson /* ethernet address from eeprom */ 9802ac6454SAndrew Thompson uint8_t ue_eaddr[ETHER_ADDR_LEN]; 9902ac6454SAndrew Thompson }; 10002ac6454SAndrew Thompson 101a593f6b8SAndrew Thompson #define uether_do_request(ue,req,data,timo) \ 102a593f6b8SAndrew Thompson usbd_do_request_proc((ue)->ue_udev,&(ue)->ue_tq,req,data,0,NULL,timo) 10302ac6454SAndrew Thompson 1042fda7967SJustin Hibbits uint8_t uether_pause(struct usb_ether *, unsigned int); 1052fda7967SJustin Hibbits if_t uether_getifp(struct usb_ether *); 106a593f6b8SAndrew Thompson struct mii_data *uether_getmii(struct usb_ether *); 107a593f6b8SAndrew Thompson void *uether_getsc(struct usb_ether *); 108a593f6b8SAndrew Thompson int uether_ifattach(struct usb_ether *); 1090c89167cSHans Petter Selasky void uether_ifattach_wait(struct usb_ether *); 110a593f6b8SAndrew Thompson void uether_ifdetach(struct usb_ether *); 1112fda7967SJustin Hibbits int uether_ifmedia_upd(if_t); 1125c6b53d8SPyun YongHyeon void uether_init(void *); 1132fda7967SJustin Hibbits int uether_ioctl(if_t, u_long, caddr_t); 114a593f6b8SAndrew Thompson struct mbuf *uether_newbuf(void); 115a593f6b8SAndrew Thompson int uether_rxmbuf(struct usb_ether *, struct mbuf *, 11662d42655SHans Petter Selasky unsigned); 117a593f6b8SAndrew Thompson int uether_rxbuf(struct usb_ether *, 118760bc48eSAndrew Thompson struct usb_page_cache *, 11962d42655SHans Petter Selasky unsigned, unsigned); 120a593f6b8SAndrew Thompson void uether_rxflush(struct usb_ether *); 121a593f6b8SAndrew Thompson uint8_t uether_is_gone(struct usb_ether *); 1222fda7967SJustin Hibbits void uether_start(if_t); 12375973647SAndrew Thompson #endif /* _USB_ETHERNET_H_ */ 124