usb_ethernet.h revision 190749
1194869Sjamie/* $FreeBSD: head/sys/dev/usb/net/usb_ethernet.h 190749 2009-04-05 21:24:15Z piso $ */
2194869Sjamie/*-
3194869Sjamie * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4194869Sjamie *
5194869Sjamie * Redistribution and use in source and binary forms, with or without
6194869Sjamie * modification, are permitted provided that the following conditions
7194869Sjamie * are met:
8194869Sjamie * 1. Redistributions of source code must retain the above copyright
9194869Sjamie *    notice, this list of conditions and the following disclaimer.
10194869Sjamie * 2. Redistributions in binary form must reproduce the above copyright
11194869Sjamie *    notice, this list of conditions and the following disclaimer in the
12194869Sjamie *    documentation and/or other materials provided with the distribution.
13194869Sjamie *
14194869Sjamie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15194869Sjamie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16194869Sjamie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17194869Sjamie * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18194869Sjamie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19194869Sjamie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20194869Sjamie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21194869Sjamie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22194869Sjamie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23194869Sjamie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24194869Sjamie * SUCH DAMAGE.
25194869Sjamie */
26194869Sjamie
27194869Sjamie#ifndef _USB2_ETHERNET_H_
28194869Sjamie#define	_USB2_ETHERNET_H_
29194869Sjamie
30194869Sjamie#include "opt_inet.h"
31194869Sjamie
32194869Sjamie#include <sys/param.h>
33194869Sjamie#include <sys/systm.h>
34194869Sjamie#include <sys/mbuf.h>
35194869Sjamie#include <sys/socket.h>
36194869Sjamie#include <sys/sockio.h>
37194869Sjamie#include <sys/limits.h>
38194869Sjamie
39194869Sjamie#include <net/if.h>
40194869Sjamie#include <net/if_arp.h>
41194869Sjamie#include <net/if_dl.h>
42194869Sjamie#include <net/if_media.h>
43194869Sjamie#include <net/if_types.h>
44194869Sjamie#include <net/bpf.h>
45194869Sjamie#include <net/ethernet.h>
46194869Sjamie
47194869Sjamie#include "miibus_if.h"
48194869Sjamie
49194869Sjamie#include <dev/mii/mii.h>
50194869Sjamie#include <dev/mii/miivar.h>
51194869Sjamie
52194869Sjamiestruct usb2_ether;
53194869Sjamiestruct usb2_device_request;
54194869Sjamie
55194869Sjamietypedef void (usb2_ether_fn_t)(struct usb2_ether *);
56194869Sjamie
57194869Sjamiestruct usb2_ether_methods {
58194869Sjamie	usb2_ether_fn_t		*ue_attach_post;
59194869Sjamie	usb2_ether_fn_t		*ue_start;
60194869Sjamie	usb2_ether_fn_t		*ue_init;
61194869Sjamie	usb2_ether_fn_t		*ue_stop;
62194869Sjamie	usb2_ether_fn_t		*ue_setmulti;
63194869Sjamie	usb2_ether_fn_t		*ue_setpromisc;
64194869Sjamie	usb2_ether_fn_t		*ue_tick;
65194869Sjamie	int			(*ue_mii_upd)(struct ifnet *);
66194869Sjamie	void			(*ue_mii_sts)(struct ifnet *,
67194869Sjamie				    struct ifmediareq *);
68194869Sjamie	int			(*ue_ioctl)(struct ifnet *, u_long, caddr_t);
69
70};
71
72struct usb2_ether_cfg_task {
73	struct usb2_proc_msg hdr;
74	struct usb2_ether *ue;
75};
76
77struct usb2_ether {
78	/* NOTE: the "ue_ifp" pointer must be first --hps */
79	struct ifnet		*ue_ifp;
80	struct mtx		*ue_mtx;
81	const struct usb2_ether_methods *ue_methods;
82	struct sysctl_oid	*ue_sysctl_oid;
83	void			*ue_sc;
84	struct usb2_device	*ue_udev; /* used by usb2_ether_do_request() */
85	device_t		ue_dev;
86	device_t		ue_miibus;
87
88	struct usb2_process	ue_tq;
89	struct sysctl_ctx_list	ue_sysctl_ctx;
90	struct ifqueue		ue_rxq;
91	struct usb2_callout	ue_watchdog;
92	struct usb2_ether_cfg_task	ue_sync_task[2];
93	struct usb2_ether_cfg_task	ue_media_task[2];
94	struct usb2_ether_cfg_task	ue_multi_task[2];
95	struct usb2_ether_cfg_task	ue_promisc_task[2];
96	struct usb2_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	usb2_ether_do_request(ue,req,data,timo) \
105    usb2_do_request_proc((ue)->ue_udev,&(ue)->ue_tq,req,data,0,NULL,timo)
106
107uint8_t		usb2_ether_pause(struct usb2_ether *, unsigned int);
108struct ifnet	*usb2_ether_getifp(struct usb2_ether *);
109struct mii_data *usb2_ether_getmii(struct usb2_ether *);
110void		*usb2_ether_getsc(struct usb2_ether *);
111int		usb2_ether_ifattach(struct usb2_ether *);
112void		usb2_ether_ifdetach(struct usb2_ether *);
113int		usb2_ether_ioctl(struct ifnet *, u_long, caddr_t);
114struct mbuf	*usb2_ether_newbuf(void);
115int		usb2_ether_rxmbuf(struct usb2_ether *, struct mbuf *,
116		    unsigned int);
117int		usb2_ether_rxbuf(struct usb2_ether *,
118		    struct usb2_page_cache *,
119		    unsigned int, unsigned int);
120void		usb2_ether_rxflush(struct usb2_ether *);
121void		usb2_ether_ifshutdown(struct usb2_ether *);
122uint8_t		usb2_ether_is_gone(struct usb2_ether *);
123#endif					/* _USB2_ETHERNET_H_ */
124