9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 #include <exec/types.h>
28 #include <exec/libraries.h>
29 #include <exec/semaphores.h>
30 #include <exec/devices.h>
31 #include <exec/interrupts.h>
38 #include <devices/timer.h>
39 #include <devices/sana2.h>
40 #include <devices/sana2specialstats.h>
42 #include <proto/exec.h>
43 #include <aros/debug.h>
45 #include LC_LIBDEFS_FILE
47 #define PCNET32_TASK_NAME "PCNet32 task"
48 #define PCNET32_PORT_NAME "PCNet32 port"
51 struct Device pcnb_Device
;
52 struct MsgPort
*pcnb_syncport
;
56 OOP_AttrBase pcnb_pciDeviceAttrBase
;
58 struct Sana2DeviceQuery pcnb_Sana2Info
;
59 struct PCN32Unit
*pcnb_unit
;
62 #undef HiddPCIDeviceAttrBase
63 #define HiddPCIDeviceAttrBase (LIBBASE->pcnb_pciDeviceAttrBase)
76 struct MsgPort read_port
;
77 BOOL (*rx_function
)(APTR
, APTR
, ULONG
);
78 BOOL (*tx_function
)(APTR
, APTR
, ULONG
);
79 struct Hook
*filter_hook
;
80 struct MinList initial_stats
;
87 struct Sana2PacketTypeStats stats
;
95 struct Sana2PacketTypeStats stats
;
104 ULONG lower_bound_left
;
105 ULONG upper_bound_left
;
106 UWORD lower_bound_right
;
107 UWORD upper_bound_right
;
110 /* Big endian: should work, but is untested */
117 ULONG BufferMsgLength
;
133 struct MinNode
*pcnu_Node
;
134 struct MinList pcnu_Openers
;
135 struct MinList pcnu_multicast_ranges
;
136 struct MinList pcnu_type_trackers
;
138 LONG pcnu_range_count
;
140 OOP_Object
*pcnu_PCIDevice
;
141 OOP_Object
*pcnu_PCIDriver
;
143 struct timeval pcnu_toutPOLL
;
147 struct MsgPort
*pcnu_TimerSlowPort
;
148 struct timerequest
*pcnu_TimerSlowReq
;
150 struct MsgPort
*pcnu_TimerFastPort
;
151 struct timerequest
*pcnu_TimerFastReq
;
153 struct Sana2DeviceStats pcnu_stats
;
154 ULONG pcnu_special_stats
[STAT_COUNT
];
156 int pcnu_pcnet_chiprevision
; /* pcn32: pcnet chipset revision id */
157 char *pcnu_pcnet_chipname
; /* pcn32: textual name for detected chipset */
158 ULONG pcnu_pcnet_supported
; /* pcn32: Supported features of pcnet family */
159 #define support_fdx (1 << 0) // Supports Full Duplex
160 #define support_mii (1 << 1)
161 #define support_fset (1 << 2)
162 #define support_ltint (1 << 3)
163 #define support_dxsuflo (1 << 4)
164 /* Card Control Funcs */
165 UWORD (*read_csr
)(APTR
, int); /* pcn32: */
166 void (*write_csr
)(APTR
, int, UWORD
); /* pcn32: */
167 UWORD (*read_bcr
)(APTR
, int); /* pcn32: */
168 void (*write_bcr
)(APTR
, int, UWORD
); /* pcn32: */
169 UWORD (*read_rap
)(APTR
); /* pcn32: */
170 void (*write_rap
)(APTR
, UWORD
); /* pcn32: */
171 void (*reset
)(APTR
); /* pcn32: */
173 void (*initialize
)(struct PCN32Unit
*);
174 void (*deinitialize
)(struct PCN32Unit
*);
175 int (*start
)(struct PCN32Unit
*);
176 int (*stop
)(struct PCN32Unit
*);
177 int (*alloc_rx
)(struct PCN32Unit
*);
178 void (*set_mac_address
)(struct PCN32Unit
*);
179 void (*linkchange
)(struct PCN32Unit
*);
180 void (*linkirq
)(struct PCN32Unit
*);
181 // ULONG (*descr_getlength)(struct ring_desc *prd, ULONG v);
182 void (*set_multicast
)(struct PCN32Unit
*);
185 struct SignalSemaphore pcnu_unit_lock
;
187 struct Process
*pcnu_Process
;
189 struct PCN32Base
*pcnu_device
;
190 struct Interrupt pcnu_irqhandler
;
191 struct Interrupt pcnu_touthandler
;
193 IPTR pcnu_DriverFlags
;
204 struct MsgPort
*pcnu_input_port
;
206 struct MsgPort
*pcnu_request_ports
[REQUEST_QUEUE_COUNT
];
208 struct Interrupt pcnu_rx_int
;
209 struct Interrupt pcnu_tx_int
;
210 struct Interrupt pcnu_tx_end_int
;
217 UBYTE pcnu_dev_addr
[6];
218 UBYTE pcnu_org_addr
[6];
219 struct fe_priv
*pcnu_fe_priv
;
222 void handle_request(LIBBASETYPEPTR
, struct IOSana2Req
*);
224 /* Media selection options. */
235 /* These flag bits are private to the generic network queueing
236 * layer, they may not be explicitly referenced by any other
244 __LINK_STATE_PRESENT
,
246 __LINK_STATE_NOCARRIER
,
247 __LINK_STATE_RX_SCHED
,
248 __LINK_STATE_LINKWATCH_PENDING
251 static inline int test_bit(int nr
, const volatile ULONG
*addr
)
253 return ((1UL << (nr
& 31)) & (addr
[nr
>> 5])) != 0;
256 static inline void set_bit(int nr
, volatile ULONG
*addr
)
258 addr
[nr
>> 5] |= 1UL << (nr
& 31);
261 static inline void clear_bit(int nr
, volatile ULONG
*addr
)
263 addr
[nr
>> 5] &= ~(1UL << (nr
& 31));
266 static inline int test_and_set_bit(int nr
, volatile ULONG
*addr
)
268 int oldbit
= test_bit(nr
, addr
);
273 static inline int test_and_clear_bit(int nr
, volatile ULONG
*addr
)
275 int oldbit
= test_bit(nr
, addr
);
280 static inline void netif_schedule(struct PCN32Unit
*dev
)
282 if (!test_bit(__LINK_STATE_XOFF
, &dev
->pcnu_state
)) {
283 Cause(&dev
->pcnu_tx_int
);
288 static inline void netif_start_queue(struct PCN32Unit
*dev
)
290 clear_bit(__LINK_STATE_XOFF
, &dev
->pcnu_state
);
293 static inline void netif_wake_queue(struct PCN32Unit
*dev
)
295 if (test_and_clear_bit(__LINK_STATE_XOFF
, &dev
->pcnu_state
)) {
296 Cause(&dev
->pcnu_tx_int
);
300 static inline void netif_stop_queue(struct PCN32Unit
*dev
)
302 set_bit(__LINK_STATE_XOFF
, &dev
->pcnu_state
);
305 static inline int netif_queue_stopped(const struct PCN32Unit
*dev
)
307 return test_bit(__LINK_STATE_XOFF
, &dev
->pcnu_state
);
310 static inline int netif_running(const struct PCN32Unit
*dev
)
312 return test_bit(__LINK_STATE_START
, &dev
->pcnu_state
);
315 static inline int netif_carrier_ok(const struct PCN32Unit
*dev
)
317 return !test_bit(__LINK_STATE_NOCARRIER
, &dev
->pcnu_state
);
320 extern void __netdev_watchdog_up(struct PCN32Unit
*dev
);
322 static inline void netif_carrier_on(struct PCN32Unit
*dev
)
324 if (test_and_clear_bit(__LINK_STATE_NOCARRIER
, &dev
->pcnu_state
)) {
325 // linkwatch_fire_event(dev);
327 if (netif_running(dev
)) {
328 // __netdev_watchdog_up(dev);
332 static inline void netif_carrier_off(struct PCN32Unit
*dev
)
334 if (!test_and_set_bit(__LINK_STATE_NOCARRIER
, &dev
->pcnu_state
)) {
335 // linkwatch_fire_event(dev);
339 /* Standard interface flags (netdevice->flags). */
340 #define IFF_UP 0x1 /* interface is up */
341 #define IFF_BROADCAST 0x2 /* broadcast address valid */
342 #define IFF_DEBUG 0x4 /* turn on debugging */
343 #define IFF_LOOPBACK 0x8 /* is a loopback net */
344 #define IFF_POINTOPOINT 0x10 /* interface is has p-p link */
345 #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
346 #define IFF_RUNNING 0x40 /* resources allocated */
347 #define IFF_NOARP 0x80 /* no ARP protocol */
348 #define IFF_PROMISC 0x100 /* receive all packets */
349 #define IFF_ALLMULTI 0x200 /* receive all multicast packets*/
351 #define IFF_MASTER 0x400 /* master of a load balancer */
352 #define IFF_SLAVE 0x800 /* slave of a load balancer */
354 #define IFF_MULTICAST 0x1000 /* Supports multicast */
356 #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_MASTER|IFF_SLAVE|IFF_RUNNING)
358 #define IFF_PORTSEL 0x2000 /* can set media type */
359 #define IFF_AUTOMEDIA 0x4000 /* auto media select active */
360 #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/
361 #define IFF_SHARED 0x10000 /* interface may be shared */
362 #define IFF_CONFIGURED 0x20000 /* interface already configured */
365 * We tag multicasts with these structures.
368 #define MAX_ADDR_LEN 32
372 struct dev_mc_list
*next
;
373 UBYTE dmi_addr
[MAX_ADDR_LEN
];
374 unsigned char dmi_addrlen
;
379 struct pcnet32_init_block
{ // - The PCnet32 32-bit initialisation block.
380 // desribed in databook.
386 /* Recieve and Transmit ring base */
389 }; // pcnet32_init_block
392 struct PCN32Unit
*pci_dev
;
400 unsigned int phy_oui
;
403 struct SignalSemaphore lock
;
407 struct eth_frame
*rx_buffer
;
408 struct eth_frame
*tx_buffer
;
410 ULONG cur_rx
, refill_rx
;
412 ULONG next_tx
, nic_tx
;
416 ULONG need_linktimer
;
417 struct timeval link_timeout
;
419 struct pcnet32_init_block
*fep_pcnet_init_block
;
422 #define pci_name(unit) (unit->pcnu_name)
427 #define ETH_DATA_LEN 1500
429 #define ETH_ADDRESSSIZE 6
430 #define ETH_HEADERSIZE 14
431 #define ETH_CRCSIZE 4
432 #define ETH_MTU (ETH_DATA_LEN)
433 #define ETH_MAXPACKETSIZE ((ETH_HEADERSIZE) + (ETH_MTU) + (ETH_CRCSIZE))
435 #define ETH_PACKET_DEST 0
436 #define ETH_PACKET_SOURCE 6
437 #define ETH_PACKET_TYPE 12
438 #define ETH_PACKET_IEEELEN 12
439 #define ETH_PACKET_SNAPTYPE 20
440 #define ETH_PACKET_DATA 14
441 #define ETH_PACKET_CRC (ETH_PACKET_DATA + ETH_MTU)
443 #define RXTX_ALLOC_BUFSIZE (ETH_MAXPACKETSIZE + 26)
445 #define TX_LIMIT_STOP 63
446 #define TX_LIMIT_START 62
449 UBYTE eth_packet_dest
[6];
450 UBYTE eth_packet_source
[6];
451 UWORD eth_packet_type
;
452 UBYTE eth_packet_data
[ETH_MTU
];
453 UBYTE eth_packet_crc
[4];
454 UBYTE eth_pad
[RXTX_ALLOC_BUFSIZE
- ETH_MAXPACKETSIZE
];
455 } __attribute__((packed
));
456 #define eth_packet_ieeelen eth_packet_type
458 void pcn32_get_functions(struct PCN32Unit
*Unit
);
460 /* ************************************** */
461 /* BEGIN : REAL PCNET32 DEFINES */
462 /* ************************************** */
464 #ifndef PCNET32_LOG_TX_BUFFERS
465 #define PCNET32_LOG_TX_BUFFERS 3
466 #define PCNET32_LOG_RX_BUFFERS 4
469 #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
470 #define TX_RING_MOD_MASK (TX_RING_SIZE - 1)
471 #define TX_RING_LEN_BITS ((PCNET32_LOG_TX_BUFFERS) << 12)
473 #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
474 #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
475 #define RX_RING_LEN_BITS ((PCNET32_LOG_RX_BUFFERS) << 4)