1 |
/* |
2 |
* Ethernet.cpp - SheepShaver ethernet PCI driver stub |
3 |
* |
4 |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include "sysdeps.h" |
22 |
#include "xlowmem.h" |
23 |
#include "ether_defs.h" |
24 |
|
25 |
|
26 |
/* |
27 |
* Driver Description structure |
28 |
*/ |
29 |
|
30 |
struct DriverDescription { |
31 |
uint32 driverDescSignature; |
32 |
uint32 driverDescVersion; |
33 |
char nameInfoStr[32]; |
34 |
uint32 version; |
35 |
uint32 driverRuntime; |
36 |
char driverName[32]; |
37 |
uint32 driverDescReserved[8]; |
38 |
uint32 nServices; |
39 |
uint32 serviceCategory; |
40 |
uint32 serviceType; |
41 |
uint32 serviceVersion; |
42 |
}; |
43 |
|
44 |
#pragma export on |
45 |
DriverDescription TheDriverDescription = { |
46 |
'mtej', |
47 |
0, |
48 |
"\pSheepShaver Ethernet", |
49 |
0x01008000, // V1.0.0final |
50 |
4, // kDriverIsUnderExpertControl |
51 |
"\penet", |
52 |
0, 0, 0, 0, 0, 0, 0, 0, |
53 |
1, |
54 |
'otan', |
55 |
0x000a0b01, // Ethernet, Framing: Ethernet/EthernetIPX/802.2, IsDLPI |
56 |
0x01000000, // V1.0.0 |
57 |
}; |
58 |
#pragma export off |
59 |
|
60 |
|
61 |
/* |
62 |
* install_info and related structures |
63 |
*/ |
64 |
|
65 |
static int ether_open(queue_t *rdq, void *dev, int flag, int sflag, void *creds); |
66 |
static int ether_close(queue_t *rdq, int flag, void *creds); |
67 |
static int ether_wput(queue_t *q, msgb *mp); |
68 |
static int ether_wsrv(queue_t *q); |
69 |
static int ether_rput(queue_t *q, msgb *mp); |
70 |
static int ether_rsrv(queue_t *q); |
71 |
|
72 |
struct ot_module_info { |
73 |
uint16 mi_idnum; |
74 |
char *mi_idname; |
75 |
int32 mi_minpsz; // Minimum packet size |
76 |
int32 mi_maxpsz; // Maximum packet size |
77 |
uint32 mi_hiwat; // Queue hi-water mark |
78 |
uint32 mi_lowat; // Queue lo-water mark |
79 |
}; |
80 |
|
81 |
static ot_module_info module_information = { |
82 |
kEnetModuleID, |
83 |
"SheepShaver Ethernet", |
84 |
0, |
85 |
kEnetTSDU, |
86 |
6000, |
87 |
5000 |
88 |
}; |
89 |
|
90 |
typedef int (*putp_t)(queue_t *, msgb *); |
91 |
typedef int (*srvp_t)(queue_t *); |
92 |
typedef int (*openp_t)(queue_t *, void *, int, int, void *); |
93 |
typedef int (*closep_t)(queue_t *, int, void *); |
94 |
|
95 |
struct qinit { |
96 |
putp_t qi_putp; |
97 |
srvp_t qi_srvp; |
98 |
openp_t qi_qopen; |
99 |
closep_t qi_qclose; |
100 |
void *qi_qadmin; |
101 |
struct ot_module_info *qi_minfo; |
102 |
void *qi_mstat; |
103 |
}; |
104 |
|
105 |
static qinit read_side = { |
106 |
NULL, |
107 |
ether_rsrv, |
108 |
ether_open, |
109 |
ether_close, |
110 |
NULL, |
111 |
&module_information, |
112 |
NULL |
113 |
}; |
114 |
|
115 |
static qinit write_side = { |
116 |
ether_wput, |
117 |
NULL, |
118 |
ether_open, |
119 |
ether_close, |
120 |
NULL, |
121 |
&module_information, |
122 |
NULL |
123 |
}; |
124 |
|
125 |
struct streamtab { |
126 |
struct qinit *st_rdinit; |
127 |
struct qinit *st_wrinit; |
128 |
struct qinit *st_muxrinit; |
129 |
struct qinit *st_muxwinit; |
130 |
}; |
131 |
|
132 |
static streamtab the_streamtab = { |
133 |
&read_side, |
134 |
&write_side, |
135 |
NULL, |
136 |
NULL |
137 |
}; |
138 |
|
139 |
struct install_info { |
140 |
struct streamtab *install_str; |
141 |
uint32 install_flags; |
142 |
uint32 install_sqlvl; |
143 |
char *install_buddy; |
144 |
void *ref_load; |
145 |
uint32 ref_count; |
146 |
}; |
147 |
|
148 |
enum { |
149 |
kOTModIsDriver = 0x00000001, |
150 |
kOTModUpperIsDLPI = 0x00002000, |
151 |
SQLVL_MODULE = 3, |
152 |
}; |
153 |
|
154 |
static install_info the_install_info = { |
155 |
&the_streamtab, |
156 |
kOTModIsDriver /*| kOTModUpperIsDLPI */, |
157 |
SQLVL_MODULE, |
158 |
NULL, |
159 |
NULL, |
160 |
0 |
161 |
}; |
162 |
|
163 |
|
164 |
// Prototypes for exported functions |
165 |
extern "C" { |
166 |
#pragma export on |
167 |
extern uint32 ValidateHardware(void *theID); |
168 |
extern install_info* GetOTInstallInfo(); |
169 |
extern uint8 InitStreamModule(void *theID); |
170 |
extern void TerminateStreamModule(void); |
171 |
#pragma export off |
172 |
} |
173 |
|
174 |
|
175 |
/* |
176 |
* Validate that our hardware is available (always available) |
177 |
*/ |
178 |
|
179 |
uint32 ValidateHardware(void *theID) |
180 |
{ |
181 |
return 0; |
182 |
} |
183 |
|
184 |
|
185 |
/* |
186 |
* Return pointer to install_info structure |
187 |
*/ |
188 |
|
189 |
install_info *GetOTInstallInfo(void) |
190 |
{ |
191 |
return &the_install_info; |
192 |
} |
193 |
|
194 |
|
195 |
/* |
196 |
* Init module |
197 |
*/ |
198 |
|
199 |
asm uint8 InitStreamModule(register void *theID) |
200 |
{ |
201 |
lwz r2,XLM_TOC |
202 |
lwz r0,XLM_ETHER_INIT |
203 |
mtctr r0 |
204 |
bctr |
205 |
} |
206 |
|
207 |
|
208 |
/* |
209 |
* Terminate module |
210 |
*/ |
211 |
|
212 |
asm void TerminateStreamModule(void) |
213 |
{ |
214 |
lwz r2,XLM_TOC |
215 |
lwz r0,XLM_ETHER_TERM |
216 |
mtctr r0 |
217 |
bctr |
218 |
} |
219 |
|
220 |
|
221 |
/* |
222 |
* DLPI functions |
223 |
*/ |
224 |
|
225 |
static asm int ether_open(register queue_t *rdq, register void *dev, register int flag, register int sflag, register void *creds) |
226 |
{ |
227 |
lwz r2,XLM_TOC |
228 |
lwz r0,XLM_ETHER_OPEN |
229 |
mtctr r0 |
230 |
bctr |
231 |
} |
232 |
|
233 |
static asm int ether_close(register queue_t *rdq, register int flag, register void *creds) |
234 |
{ |
235 |
lwz r2,XLM_TOC |
236 |
lwz r0,XLM_ETHER_CLOSE |
237 |
mtctr r0 |
238 |
bctr |
239 |
} |
240 |
|
241 |
static asm int ether_wput(register queue_t *q, register msgb *mp) |
242 |
{ |
243 |
lwz r2,XLM_TOC |
244 |
lwz r0,XLM_ETHER_WPUT |
245 |
mtctr r0 |
246 |
bctr |
247 |
} |
248 |
|
249 |
static asm int ether_rsrv(register queue_t *q) |
250 |
{ |
251 |
lwz r2,XLM_TOC |
252 |
lwz r0,XLM_ETHER_RSRV |
253 |
mtctr r0 |
254 |
bctr |
255 |
} |