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