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.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
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,
24 #include <exec/types.h>
25 #include <exec/resident.h>
27 #include <exec/errors.h>
28 #include <exec/lists.h>
30 #include <aros/libcall.h>
31 #include <aros/symbolsets.h>
35 #include <devices/sana2.h>
36 #include <devices/sana2specialstats.h>
38 #include <utility/utility.h>
39 #include <utility/tagitem.h>
40 #include <utility/hooks.h>
44 #include <proto/oop.h>
45 #include <proto/exec.h>
46 #include <proto/utility.h>
51 #include LC_LIBDEFS_FILE
53 AROS_UFH3(void, PCI_Enumerator
,
54 AROS_UFHA(struct Hook
*, hook
, A0
),
55 AROS_UFHA(OOP_Object
*, pciDevice
, A2
),
56 AROS_UFHA(APTR
, message
, A1
))
60 struct RTL8168Unit
*unit
= NULL
;
63 D(bug("[rtl8168] PCI_Enumerator(PCI Device Obj @ %p)\n", pciDevice
));
65 LIBBASETYPEPTR LIBBASE
= (LIBBASETYPEPTR
)hook
->h_Data
;
67 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_RevisionID
, &RevisionID
);
69 D(bug("[rtl8168] PCI_Enumerator: Found RTL8168 NIC Rev:%d\n", RevisionID
));
71 if ((LIBBASE
->rtl8168b_UnitCount
< MAX_UNITS
) && ((unit
= CreateUnit(LIBBASE
, pciDevice
, RevisionID
)) != NULL
))
73 AddTail(&LIBBASE
->rtl8168b_Units
, (struct Node
*)&unit
->rtl8168u_Node
);
75 else if (LIBBASE
->rtl8168b_UnitCount
< MAX_UNITS
)
77 D(bug("[rtl8168] PCI_Enumerator: Failed to create unit!\n"));
82 D(bug("[rtl8168] PCI_Enumerator: Max supported units already reached\n"));
85 RTLD(bug("[%s] PCI_Enumerator: %s NIC MMIO @ %p\n", unit
->rtl8168u_name
, unit
->rtl8168u_rtl_chipname
, unit
->rtl8168u_BaseMem
))
90 static int GM_UNIQUENAME(Init
)(LIBBASETYPEPTR LIBBASE
)
92 D(bug("[rtl8168] Init()\n"));
97 sprintf((char *)tmpbuff
, RTL8168_TASK_NAME
, "rtl8168.0");
99 if (FindTask(tmpbuff
) != NULL
)
101 D(bug("[rtl8168] Init: Found Task '%s'! - Device already up and running.\n", tmpbuff
));
105 /* Load config options */
106 LIBBASE
->rtl8168b_MaxIntWork
= 20;
107 LIBBASE
->rtl8168b_MulticastFilterLimit
= 32;
109 for (i
= 0; i
< MAX_UNITS
; i
++)
111 LIBBASE
->speed
[i
] = -1;
112 LIBBASE
->duplex
[i
] = -1;
113 LIBBASE
->autoneg
[i
] = -1;
116 NEWLIST(&LIBBASE
->rtl8168b_Units
);
118 LIBBASE
->rtl8168b_PCIDeviceAttrBase
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
120 if (LIBBASE
->rtl8168b_PCIDeviceAttrBase
!= 0)
122 D(bug("[rtl8168] Init: HiddPCIDeviceAttrBase @ %p\n", LIBBASE
->rtl8168b_PCIDeviceAttrBase
));
124 LIBBASE
->rtl8168b_PCI
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
126 if (LIBBASE
->rtl8168b_PCI
)
128 D(bug("[rtl8168] Init: PCI Subsystem HIDD object @ %p\n", LIBBASE
->rtl8168b_PCI
));
130 struct TagItem Requirements
[] = {
131 {tHidd_PCI_VendorID
, 0x10ec},
132 {tHidd_PCI_ProductID
, 0x8168},
136 struct Hook FindHook
= {
137 h_Entry
: (IPTR (*)())PCI_Enumerator
,
141 struct pHidd_PCI_EnumDevices enummsg
= {
142 mID
: OOP_GetMethodID(IID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
144 requirements
: (struct TagItem
*)&Requirements
,
147 OOP_DoMethod(LIBBASE
->rtl8168b_PCI
, (OOP_Msg
)msg
);
149 if (!(IsListEmpty(&LIBBASE
->rtl8168b_Units
)))
158 static int GM_UNIQUENAME(Expunge
)(LIBBASETYPEPTR LIBBASE
)
160 D(bug("[rtl8168] Expunge()\n"));
162 struct RTL8168Unit
*unit_current
, *unit_tmp
;
164 if (!(IsListEmpty(&LIBBASE
->rtl8168b_Units
)))
166 ForeachNodeSafe(&LIBBASE
->rtl8168b_Units
, unit_current
, unit_tmp
)
168 DeleteUnit(LIBBASE
, unit_current
);
172 if (LIBBASE
->rtl8168b_PCIDeviceAttrBase
!= 0)
173 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
175 LIBBASE
->rtl8168b_PCIDeviceAttrBase
= 0;
177 if (LIBBASE
->rtl8168b_PCI
!= NULL
)
178 OOP_DisposeObject(LIBBASE
->rtl8168b_PCI
);
183 static const ULONG rx_tags
[] = {
188 static const ULONG tx_tags
[] = {
194 static int GM_UNIQUENAME(Open
)
196 LIBBASETYPEPTR LIBBASE
,
197 struct IOSana2Req
* req
,
202 struct TagItem
*tags
;
203 struct RTL8168Unit
*unit
= NULL
, *unit_current
;
204 struct Opener
*opener
;
208 if (!(IsListEmpty(&LIBBASE
->rtl8168b_Units
)))
210 ForeachNode(&LIBBASE
->rtl8168b_Units
, unit_current
)
212 if (unit_current
->rtl8168u_UnitNum
== unitnum
)
217 D(bug("[rtl8168] OpenDevice(%d)\n", unitnum
));
221 RTLD(bug("[%s] OpenDevice: Unit %d @ %p\n", unit
->rtl8168u_name
, unitnum
, unit
))
223 req
->ios2_Req
.io_Unit
= NULL
;
224 tags
= req
->ios2_BufferManagement
;
226 req
->ios2_BufferManagement
= NULL
;
228 /* Check request size */
229 if (req
->ios2_Req
.io_Message
.mn_Length
< sizeof(struct IOSana2Req
))
230 error
= IOERR_OPENFAIL
;
232 /* Get the requested unit */
234 req
->ios2_Req
.io_Unit
= (APTR
)unit
;
236 /* Handle device sharing */
239 if ((unit
->rtl8168u_open_count
!= 0) &&
240 ((unit
->rtl8168u_flags
& IFF_SHARED
) == 0 ||
241 (flags
& SANA2OPF_MINE
) != 0))
242 error
= IOERR_UNITBUSY
;
244 unit
->rtl8168u_open_count
++;
249 if ((flags
& SANA2OPF_MINE
) == 0)
250 unit
->rtl8168u_flags
|= IFF_SHARED
;
251 else if ((flags
& SANA2OPF_PROM
) != 0)
252 unit
->rtl8168u_flags
|= IFF_PROMISC
;
254 /* Set up buffer-management structure and get hooks */
255 opener
= AllocVec(sizeof(struct Opener
), MEMF_PUBLIC
| MEMF_CLEAR
);
256 req
->ios2_BufferManagement
= (APTR
)opener
;
259 error
= IOERR_OPENFAIL
;
264 NEWLIST(&opener
->read_port
.mp_MsgList
);
265 opener
->read_port
.mp_Flags
= PA_IGNORE
;
266 NEWLIST((APTR
)&opener
->initial_stats
);
268 for (i
= 0; i
< 2; i
++)
269 opener
->rx_function
= (APTR
)GetTagData(rx_tags
[i
], (IPTR
)opener
->rx_function
, tags
);
270 for (i
= 0; i
< 3; i
++)
271 opener
->tx_function
= (APTR
)GetTagData(tx_tags
[i
], (IPTR
)opener
->tx_function
, tags
);
273 opener
->filter_hook
= (APTR
)GetTagData(S2_PacketFilter
, 0, tags
);
276 AddTail((APTR
)&unit
->rtl8168u_Openers
, (APTR
)opener
);
281 CloseDevice((struct IORequest
*)req
);
287 D(bug("[rtl8168] OpenDevice: Invalid Unit! (unitno = %d)\n", unitnum
));
288 error
= IOERR_OPENFAIL
;
291 req
->ios2_Req
.io_Error
= error
;
293 return (error
!= 0) ? FALSE
: TRUE
;
296 static int GM_UNIQUENAME(Close
)
298 LIBBASETYPEPTR LIBBASE
,
299 struct IOSana2Req
* req
302 struct RTL8168Unit
*unit
= (struct RTL8168Unit
*)req
->ios2_Req
.io_Unit
;
303 struct Opener
*opener
;
305 if ((unit
= (struct RTL8168Unit
*)req
->ios2_Req
.io_Unit
) != NULL
)
307 RTLD(bug("[rtl8168] CloseDevice(unit @ %p, unitno %d)\n", unit
, unit
->rtl8168u_UnitNum
))
311 opener
= (APTR
)req
->ios2_BufferManagement
;
315 Remove((struct Node
*)opener
);
324 ADD2INITLIB(GM_UNIQUENAME(Init
),0)
325 ADD2EXPUNGELIB(GM_UNIQUENAME(Expunge
),0)
326 ADD2OPENDEV(GM_UNIQUENAME(Open
),0)
327 ADD2CLOSEDEV(GM_UNIQUENAME(Close
),0)
329 AROS_LH1(void, BeginIO
,
330 AROS_LHA(struct IOSana2Req
*, req
, A1
),
331 LIBBASETYPEPTR
, LIBBASE
, 5, RTL8168Dev
)
334 struct RTL8168Unit
*unit
;
336 D(bug("[rtl8168] BeginIO()\n"));
338 req
->ios2_Req
.io_Error
= 0;
339 if ((unit
= (struct RTL8168Unit
*)req
->ios2_Req
.io_Unit
) != NULL
)
341 if (AttemptSemaphore(&unit
->rtl8168u_unit_lock
))
343 handle_request(LIBBASE
, req
);
347 req
->ios2_Req
.io_Flags
&= ~IOF_QUICK
;
348 PutMsg(unit
->rtl8168u_input_port
, (struct Message
*)req
);
353 D(bug("[rtl8168] BeginIO: Called with unit == NULL\n"));
359 AROS_LH1(LONG
, AbortIO
,
360 AROS_LHA(struct IOSana2Req
*, req
, A1
),
361 LIBBASETYPEPTR
, LIBBASE
, 6, RTL8168Dev
)
364 struct RTL8168Unit
*unit
;
366 D(bug("[rtl8168] AbortIO()\n"));
368 if ((unit
= (struct RTL8168Unit
*)req
->ios2_Req
.io_Unit
) != NULL
)
371 if ((req
->ios2_Req
.io_Message
.mn_Node
.ln_Type
== NT_MESSAGE
) &&
372 (req
->ios2_Req
.io_Flags
& IOF_QUICK
) == 0)
374 Remove((struct Node
*)req
);
375 req
->ios2_Req
.io_Error
= IOERR_ABORTED
;
376 req
->ios2_WireError
= S2WERR_GENERIC_ERROR
;
377 ReplyMsg((struct Message
*)req
);