1184610Salfred/* $FreeBSD$ */
2184610Salfred/*-
3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4184610Salfred *
5184610Salfred * Redistribution and use in source and binary forms, with or without
6184610Salfred * modification, are permitted provided that the following conditions
7184610Salfred * are met:
8184610Salfred * 1. Redistributions of source code must retain the above copyright
9184610Salfred *    notice, this list of conditions and the following disclaimer.
10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer in the
12184610Salfred *    documentation and/or other materials provided with the distribution.
13184610Salfred *
14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17184610Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24184610Salfred * SUCH DAMAGE.
25226709Syongari *
26226709Syongari * $FreeBSD$
27184610Salfred */
28184610Salfred
29194230Sthompsa#ifndef _USB_ETHERNET_H_
30194230Sthompsa#define	_USB_ETHERNET_H_
31184610Salfred
32184610Salfred#include "opt_inet.h"
33184610Salfred
34184610Salfred#include <sys/param.h>
35184610Salfred#include <sys/systm.h>
36184610Salfred#include <sys/mbuf.h>
37184610Salfred#include <sys/socket.h>
38184610Salfred#include <sys/sockio.h>
39188412Sthompsa#include <sys/limits.h>
40184610Salfred
41184610Salfred#include <net/if.h>
42184610Salfred#include <net/if_arp.h>
43184610Salfred#include <net/if_dl.h>
44184610Salfred#include <net/if_media.h>
45184610Salfred#include <net/if_types.h>
46184610Salfred#include <net/bpf.h>
47184610Salfred#include <net/ethernet.h>
48184610Salfred
49184610Salfred#include "miibus_if.h"
50184610Salfred
51184610Salfred#include <dev/mii/mii.h>
52184610Salfred#include <dev/mii/miivar.h>
53184610Salfred
54192984Sthompsastruct usb_ether;
55192984Sthompsastruct usb_device_request;
56184610Salfred
57193045Sthompsatypedef void (uether_fn_t)(struct usb_ether *);
58188412Sthompsa
59192984Sthompsastruct usb_ether_methods {
60193045Sthompsa	uether_fn_t		*ue_attach_post;
61193045Sthompsa	uether_fn_t		*ue_start;
62193045Sthompsa	uether_fn_t		*ue_init;
63193045Sthompsa	uether_fn_t		*ue_stop;
64193045Sthompsa	uether_fn_t		*ue_setmulti;
65193045Sthompsa	uether_fn_t		*ue_setpromisc;
66193045Sthompsa	uether_fn_t		*ue_tick;
67188412Sthompsa	int			(*ue_mii_upd)(struct ifnet *);
68188412Sthompsa	void			(*ue_mii_sts)(struct ifnet *,
69188412Sthompsa				    struct ifmediareq *);
70188412Sthompsa	int			(*ue_ioctl)(struct ifnet *, u_long, caddr_t);
71226709Syongari	int			(*ue_attach_post_sub)(struct usb_ether *);
72184610Salfred};
73184610Salfred
74192984Sthompsastruct usb_ether_cfg_task {
75192984Sthompsa	struct usb_proc_msg hdr;
76192984Sthompsa	struct usb_ether *ue;
77188412Sthompsa};
78184610Salfred
79192984Sthompsastruct usb_ether {
80188412Sthompsa	/* NOTE: the "ue_ifp" pointer must be first --hps */
81188412Sthompsa	struct ifnet		*ue_ifp;
82188412Sthompsa	struct mtx		*ue_mtx;
83192984Sthompsa	const struct usb_ether_methods *ue_methods;
84188412Sthompsa	struct sysctl_oid	*ue_sysctl_oid;
85188412Sthompsa	void			*ue_sc;
86194228Sthompsa	struct usb_device	*ue_udev; /* used by uether_do_request() */
87188412Sthompsa	device_t		ue_dev;
88188412Sthompsa	device_t		ue_miibus;
89184610Salfred
90192984Sthompsa	struct usb_process	ue_tq;
91188412Sthompsa	struct sysctl_ctx_list	ue_sysctl_ctx;
92188412Sthompsa	struct ifqueue		ue_rxq;
93192984Sthompsa	struct usb_callout	ue_watchdog;
94192984Sthompsa	struct usb_ether_cfg_task	ue_sync_task[2];
95192984Sthompsa	struct usb_ether_cfg_task	ue_media_task[2];
96192984Sthompsa	struct usb_ether_cfg_task	ue_multi_task[2];
97192984Sthompsa	struct usb_ether_cfg_task	ue_promisc_task[2];
98192984Sthompsa	struct usb_ether_cfg_task	ue_tick_task[2];
99188412Sthompsa
100188412Sthompsa	int			ue_unit;
101188412Sthompsa
102188412Sthompsa	/* ethernet address from eeprom */
103188412Sthompsa	uint8_t			ue_eaddr[ETHER_ADDR_LEN];
104188412Sthompsa};
105188412Sthompsa
106194228Sthompsa#define	uether_do_request(ue,req,data,timo) \
107194228Sthompsa    usbd_do_request_proc((ue)->ue_udev,&(ue)->ue_tq,req,data,0,NULL,timo)
108188412Sthompsa
109194228Sthompsauint8_t		uether_pause(struct usb_ether *, unsigned int);
110194228Sthompsastruct ifnet	*uether_getifp(struct usb_ether *);
111194228Sthompsastruct mii_data *uether_getmii(struct usb_ether *);
112194228Sthompsavoid		*uether_getsc(struct usb_ether *);
113194228Sthompsaint		uether_ifattach(struct usb_ether *);
114194228Sthompsavoid		uether_ifdetach(struct usb_ether *);
115226709Syongariint		uether_ifmedia_upd(struct ifnet *);
116226709Syongarivoid		uether_init(void *);
117194228Sthompsaint		uether_ioctl(struct ifnet *, u_long, caddr_t);
118194228Sthompsastruct mbuf	*uether_newbuf(void);
119194228Sthompsaint		uether_rxmbuf(struct usb_ether *, struct mbuf *,
120188412Sthompsa		    unsigned int);
121194228Sthompsaint		uether_rxbuf(struct usb_ether *,
122192984Sthompsa		    struct usb_page_cache *,
123188412Sthompsa		    unsigned int, unsigned int);
124194228Sthompsavoid		uether_rxflush(struct usb_ether *);
125194228Sthompsauint8_t		uether_is_gone(struct usb_ether *);
126226709Syongarivoid		uether_start(struct ifnet *);
127194230Sthompsa#endif					/* _USB_ETHERNET_H_ */
128