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