5 Copyright (C) 2000-2011 Neil Cafferkey
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 #include <exec/types.h>
26 #include <exec/resident.h>
27 #include <utility/utility.h>
28 #include <libraries/query.h>
30 #include <proto/exec.h>
34 #include "device_protos.h"
37 /* Private prototypes */
39 static struct DevBase
*MOSDevInit(struct DevBase
*dev_base
, APTR seg_list
,
40 struct DevBase
*base
);
41 static BYTE
MOSDevOpen();
42 static APTR
MOSDevClose();
43 static APTR
MOSDevExpunge();
44 static VOID
MOSDevBeginIO();
45 static VOID
MOSDevAbortIO();
46 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
);
47 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
);
48 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
);
51 extern const APTR init_data
;
52 extern const struct Resident rom_tag
;
53 extern const TEXT device_name
[];
54 extern const TEXT version_string
[];
57 static const TEXT openpci_name
[] = "openpci.library";
60 static const APTR mos_vectors
[] =
62 (APTR
)FUNCARRAY_32BIT_NATIVE
,
73 static const APTR mos_init_table
[] =
75 (APTR
)sizeof(struct DevBase
),
82 static const struct TagItem query_tags
[] =
84 {QUERYINFOATTR_NAME
, (UPINT
)device_name
},
85 {QUERYINFOATTR_IDSTRING
, (UPINT
)version_string
},
86 {QUERYINFOATTR_DESCRIPTION
, (UPINT
)"Atheros5000 WLAN network driver"},
87 {QUERYINFOATTR_COPYRIGHT
, (UPINT
)"2000-2011 Neil Cafferkey"},
88 {QUERYINFOATTR_AUTHOR
, (UPINT
)"Neil Cafferkey"},
89 {QUERYINFOATTR_DATE
, (UPINT
)DATE
},
90 {QUERYINFOATTR_VERSION
, VERSION
},
91 {QUERYINFOATTR_REVISION
, REVISION
},
92 {QUERYINFOATTR_CODETYPE
, MACHINE_PPC
},
93 {QUERYINFOATTR_SUBTYPE
, QUERYSUBTYPE_DEVICE
},
94 {QUERYINFOATTR_CLASS
, QUERYCLASS_NET
},
95 {QUERYINFOATTR_NET_IPTYPE
, 2048},
100 const struct Resident mos_rom_tag
=
103 (struct Resident
*)&mos_rom_tag
,
104 (APTR
)(&rom_tag
+ 1),
105 RTF_AUTOINIT
| RTF_PPC
| RTF_EXTENDED
,
110 (STRPTR
)version_string
,
111 (APTR
)mos_init_table
,
113 (struct TagItem
*)&query_tags
117 static const struct EmulLibEntry int_trap
=
126 /****i* atheros5000.device/MOSDevInit **************************************
131 ****************************************************************************
135 static struct DevBase
*MOSDevInit(struct DevBase
*dev_base
, APTR seg_list
,
136 struct DevBase
*base
)
138 base
= DevInit(dev_base
, seg_list
, base
);
142 base
->openpci_base
= OpenLibrary(openpci_name
, OPENPCI_VERSION
);
143 base
->wrapper_int_code
= (APTR
)&int_trap
;
150 /****i* atheros5000.device/MOSDevOpen **************************************
155 ****************************************************************************
159 static BYTE
MOSDevOpen()
161 struct IOSana2Req
*request
;
162 struct Opener
*opener
;
165 request
= (APTR
)REG_A1
;
166 error
= DevOpen(request
, REG_D0
, REG_D1
, (APTR
)REG_A6
);
168 /* Set up wrapper hooks to hide 68k emulation */
172 opener
= request
->ios2_BufferManagement
;
173 opener
->real_rx_function
= opener
->rx_function
;
174 opener
->real_tx_function
= opener
->tx_function
;
175 opener
->rx_function
= (APTR
)RXFunction
;
176 opener
->tx_function
= (APTR
)TXFunction
;
177 if(opener
->dma_tx_function
!= NULL
)
179 opener
->real_dma_tx_function
= opener
->dma_tx_function
;
180 opener
->dma_tx_function
= (APTR
)DMATXFunction
;
189 /****i* atheros5000.device/MOSDevClose *************************************
194 ****************************************************************************
198 static APTR
MOSDevClose()
200 return DevClose((APTR
)REG_A1
, (APTR
)REG_A6
);
205 /****i* atheros5000.device/MOSDevExpunge ***********************************
210 ****************************************************************************
214 static APTR
MOSDevExpunge()
216 return DevExpunge((APTR
)REG_A6
);
221 /****i* atheros5000.device/MOSDevBeginIO ***********************************
226 ****************************************************************************
230 static VOID
MOSDevBeginIO()
232 struct IOSana2Req
*request
= (APTR
)REG_A1
;
234 /* Replace caller's cookie with our own */
236 switch(request
->ios2_Req
.io_Command
)
243 request
->ios2_StatData
= request
->ios2_Data
;
244 request
->ios2_Data
= request
;
247 DevBeginIO(request
, (APTR
)REG_A6
);
254 /****i* atheros5000.device/MOSDevAbortIO ***********************************
257 * MOSDevAbortIO -- Try to stop a request.
259 ****************************************************************************
263 static VOID
MOSDevAbortIO()
265 DevAbortIO((APTR
)REG_A1
, (APTR
)REG_A6
);
270 /****i* atheros5000.device/RXFunction **************************************
275 ****************************************************************************
279 static BOOL
RXFunction(struct IOSana2Req
*request
, APTR buffer
, ULONG size
)
281 struct DevBase
*base
;
282 struct EmulCaos context
;
283 struct Opener
*opener
;
286 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
287 opener
= request
->ios2_BufferManagement
;
288 cookie
= request
->ios2_StatData
;
289 request
->ios2_Data
= cookie
;
291 context
.caos_Un
.Function
= (APTR
)opener
->real_rx_function
;
292 context
.reg_a0
= (ULONG
)cookie
;
293 context
.reg_a1
= (ULONG
)buffer
;
294 context
.reg_d0
= size
;
295 return MyEmulHandle
->EmulCall68k(&context
);
300 /****i* atheros5000.device/TXFunction **************************************
305 ****************************************************************************
309 static BOOL
TXFunction(APTR buffer
, struct IOSana2Req
*request
, ULONG size
)
311 struct DevBase
*base
;
312 struct EmulCaos context
;
313 struct Opener
*opener
;
316 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
317 opener
= request
->ios2_BufferManagement
;
318 cookie
= request
->ios2_StatData
;
319 request
->ios2_Data
= cookie
;
321 context
.caos_Un
.Function
= (APTR
)opener
->real_tx_function
;
322 context
.reg_a0
= (ULONG
)buffer
;
323 context
.reg_a1
= (ULONG
)cookie
;
324 context
.reg_d0
= size
;
325 return MyEmulHandle
->EmulCall68k(&context
);
330 /****i* atheros5000.device/DMATXFunction ***********************************
335 ****************************************************************************
339 static UBYTE
*DMATXFunction(struct IOSana2Req
*request
)
341 struct DevBase
*base
;
342 struct EmulCaos context
;
343 struct Opener
*opener
;
346 base
= (struct DevBase
*)request
->ios2_Req
.io_Device
;
347 opener
= request
->ios2_BufferManagement
;
348 cookie
= request
->ios2_StatData
;
349 request
->ios2_Data
= cookie
;
351 context
.caos_Un
.Function
= (APTR
)opener
->real_dma_tx_function
;
352 context
.reg_a0
= (ULONG
)cookie
;
353 return (UBYTE
*)MyEmulHandle
->EmulCall68k(&context
);
358 /****i* atheros5000.device/MOSInt ******************************************
363 ****************************************************************************
370 BOOL (*int_code
)(APTR
, APTR
);
372 int_data
= (APTR
)REG_A1
;
373 int_code
= int_data
[0];
374 return int_code(int_data
[1], int_code
);