usb_ethernet.h revision 194228
1255376Sdes/* $FreeBSD: head/sys/dev/usb/net/usb_ethernet.h 194228 2009-06-15 01:02:43Z thompsa $ */ 2255376Sdes/*- 3271947Sdes * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 491100Sdes * 591100Sdes * Redistribution and use in source and binary forms, with or without 691100Sdes * modification, are permitted provided that the following conditions 791100Sdes * are met: 891100Sdes * 1. Redistributions of source code must retain the above copyright 991100Sdes * notice, this list of conditions and the following disclaimer. 1091100Sdes * 2. Redistributions in binary form must reproduce the above copyright 1191100Sdes * notice, this list of conditions and the following disclaimer in the 12108794Sdes * documentation and/or other materials provided with the distribution. 1391100Sdes * 1491100Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15117610Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1691100Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1791100Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1891100Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19236109Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2091100Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2191100Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2291100Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2391100Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2491100Sdes * SUCH DAMAGE. 2591100Sdes */ 26236109Sdes 2791100Sdes#ifndef _USB2_ETHERNET_H_ 2891100Sdes#define _USB2_ETHERNET_H_ 2991100Sdes 3091100Sdes#include "opt_inet.h" 3191100Sdes 32141098Sdes#include <sys/param.h> 3391100Sdes#include <sys/systm.h> 3491100Sdes#include <sys/mbuf.h> 3591100Sdes#include <sys/socket.h> 3691100Sdes#include <sys/sockio.h> 3791100Sdes#include <sys/limits.h> 3891100Sdes 3991100Sdes#include <net/if.h> 4091100Sdes#include <net/if_arp.h> 4191100Sdes#include <net/if_dl.h> 4291100Sdes#include <net/if_media.h> 4391100Sdes#include <net/if_types.h> 4491100Sdes#include <net/bpf.h> 4591100Sdes#include <net/ethernet.h> 4691100Sdes 4791100Sdes#include "miibus_if.h" 4891100Sdes 4991100Sdes#include <dev/mii/mii.h> 5091100Sdes#include <dev/mii/miivar.h> 5191100Sdes 5291100Sdesstruct usb_ether; 5391100Sdesstruct usb_device_request; 5491100Sdes 5591100Sdestypedef void (uether_fn_t)(struct usb_ether *); 5691100Sdes 5791100Sdesstruct usb_ether_methods { 5891100Sdes uether_fn_t *ue_attach_post; 5991100Sdes uether_fn_t *ue_start; 6091100Sdes uether_fn_t *ue_init; 6191100Sdes uether_fn_t *ue_stop; 6291100Sdes uether_fn_t *ue_setmulti; 63236109Sdes uether_fn_t *ue_setpromisc; 64236109Sdes uether_fn_t *ue_tick; 65236109Sdes int (*ue_mii_upd)(struct ifnet *); 66117610Sdes void (*ue_mii_sts)(struct ifnet *, 67236109Sdes struct ifmediareq *); 68147466Sdes int (*ue_ioctl)(struct ifnet *, u_long, caddr_t); 69117610Sdes 7091100Sdes}; 7191100Sdes 72255376Sdesstruct usb_ether_cfg_task { 73255376Sdes struct usb_proc_msg hdr; 74255376Sdes struct usb_ether *ue; 75}; 76 77struct usb_ether { 78 /* NOTE: the "ue_ifp" pointer must be first --hps */ 79 struct ifnet *ue_ifp; 80 struct mtx *ue_mtx; 81 const struct usb_ether_methods *ue_methods; 82 struct sysctl_oid *ue_sysctl_oid; 83 void *ue_sc; 84 struct usb_device *ue_udev; /* used by uether_do_request() */ 85 device_t ue_dev; 86 device_t ue_miibus; 87 88 struct usb_process ue_tq; 89 struct sysctl_ctx_list ue_sysctl_ctx; 90 struct ifqueue ue_rxq; 91 struct usb_callout ue_watchdog; 92 struct usb_ether_cfg_task ue_sync_task[2]; 93 struct usb_ether_cfg_task ue_media_task[2]; 94 struct usb_ether_cfg_task ue_multi_task[2]; 95 struct usb_ether_cfg_task ue_promisc_task[2]; 96 struct usb_ether_cfg_task ue_tick_task[2]; 97 98 int ue_unit; 99 100 /* ethernet address from eeprom */ 101 uint8_t ue_eaddr[ETHER_ADDR_LEN]; 102}; 103 104#define uether_do_request(ue,req,data,timo) \ 105 usbd_do_request_proc((ue)->ue_udev,&(ue)->ue_tq,req,data,0,NULL,timo) 106 107uint8_t uether_pause(struct usb_ether *, unsigned int); 108struct ifnet *uether_getifp(struct usb_ether *); 109struct mii_data *uether_getmii(struct usb_ether *); 110void *uether_getsc(struct usb_ether *); 111int uether_ifattach(struct usb_ether *); 112void uether_ifdetach(struct usb_ether *); 113int uether_ioctl(struct ifnet *, u_long, caddr_t); 114struct mbuf *uether_newbuf(void); 115int uether_rxmbuf(struct usb_ether *, struct mbuf *, 116 unsigned int); 117int uether_rxbuf(struct usb_ether *, 118 struct usb_page_cache *, 119 unsigned int, unsigned int); 120void uether_rxflush(struct usb_ether *); 121uint8_t uether_is_gone(struct usb_ether *); 122#endif /* _USB2_ETHERNET_H_ */ 123