xref: /plan9-contrib/sys/src/cmd/usb/ether/ether.h (revision e1c0af539adcc53c770ef6e067291d1d2730e221)
1 typedef struct Ether Ether;
2 typedef struct Etherops Etherops;
3 typedef struct Conn Conn;
4 typedef struct Cinfo Cinfo;
5 typedef struct Buf Buf;
6 typedef struct Etherpkt Etherpkt;
7 
8 enum
9 {
10 	/* controller ids */
11 	Cdc = 0,
12 	A8817x,		/* Asis */
13 	A88178,
14 	A88179,
15 	A88772,
16 	S95xx,		/* SMSC */
17 	S78xx,
18 
19 	Eaddrlen = 6,
20 	Epktlen = 1514,
21 	Ehdrsize = 2*Eaddrlen + 2,
22 
23 	Maxpkt	= 2000,	/* no jumbo packets here */
24 	Nconns	= 8,	/* max number of connections */
25 	Nbufs	= 32,	/* max number of buffers */
26 	Scether = 6,	/* ethernet cdc subclass */
27 	Fnheader = 0,	/* Functions */
28 	Fnunion = 6,
29 	Fnether = 15,
30 
31 	Cdcunion	= 6,	/* CDC Union descriptor subtype */
32 };
33 
34 struct Buf
35 {
36 	int	type;
37 	int	ndata;
38 	uchar*	rp;
39 	uchar	data[Hdrsize+Maxpkt];
40 };
41 
42 struct Conn
43 {
44 	Ref;			/* one per file in use */
45 	int	nb;
46 	int	type;
47 	int	headersonly;
48 	int	prom;
49 	Channel*rc;		/* [2] of Buf* */
50 };
51 
52 struct Etherops
53 {
54 	int	(*init)(Ether*, int *epin, int *epout);
55 	long	(*bread)(Ether*, Buf*);
56 	long	(*bwrite)(Ether*, Buf*);
57 	int	(*ctl)(Ether*, char*);
58 	int	(*promiscuous)(Ether*, int);
59 	int	(*multicast)(Ether*, uchar*, int);
60 	char*	(*seprintstats)(char*, char*, Ether*);
61 	void	(*free)(Ether*);
62 	int	bufsize;
63 	char	*name;
64 	void*	aux;
65 };
66 
67 struct Ether
68 {
69 	QLock;
70 	QLock	wlck;			/* write one at a time */
71 	int	epinid;			/* epin address */
72 	int	epoutid;			/* epout address */
73 	Dev*	dev;
74 	Dev*	epin;
75 	Dev*	epout;
76 	int	cid;			/* ctlr id */
77 	int	phy;			/* phy id */
78 	Ref	prom;			/* nb. of promiscuous conns */
79 	int	exiting;			/* shutting down */
80 	int	wrexited;			/* write process died */
81 	uchar	addr[Eaddrlen];		/* mac */
82 	int	nconns;			/* nb. of entries used in... */
83 	Conn*	conns[Nconns];		/* connections */
84 	int	nabufs;			/* nb. of allocated buffers */
85 	int	nbufs;			/* nb. of buffers in use */
86 	int	nblock;			/* nonblocking (output)? */
87 	long	nin;
88 	long	nout;
89 	long	nierrs;
90 	long	noerrs;
91 	int	mbps;
92 	int	nmcasts;
93 	Channel*rc;			/* read channel (of Buf*) */
94 	Channel*wc;			/* write channel (of Buf*) */
95 	Channel*bc;			/* free buf. chan. (of Buf*) */
96 	Etherops;
97 	Usbfs	fs;
98 };
99 
100 struct Cinfo
101 {
102 	int vid;		/* usb vendor id */
103 	int did;		/* usb device/product id */
104 	int cid;		/* controller id assigned by us */
105 };
106 
107 struct Etherpkt
108 {
109 	uchar d[Eaddrlen];
110 	uchar s[Eaddrlen];
111 	uchar type[2];
112 	uchar data[1500];
113 };
114 
115 int	ethermain(Dev *dev, int argc, char **argv);
116 int	asixreset(Ether*);
117 int smscreset(Ether*);
118 int lan78xxreset(Ether*);
119 int	cdcreset(Ether*);
120 int	parseaddr(uchar *m, char *s);
121 void	dumpframe(char *tag, void *p, int n);
122 
123 extern Cinfo cinfo[];
124 extern int etherdebug;
125 
126 #define	deprint	if(etherdebug)fprint
127