store the pre-alphacomposit hook and allow it to be queried.
[AROS.git] / workbench / devs / networks / pcnet32 / pcnet32.h
blob39dd974f233acdb7de0f36e927fcaabca33af9dd
1 #ifndef _PCNET32_H
2 #define _PCNET32_H
4 /*
5 * $Id$
6 */
8 /*
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,
22 MA 02111-1307, USA.
25 #define DEBUG 0
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>
32 #include <dos/bptr.h>
34 #include <oop/oop.h>
36 #include <hidd/pci.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"
50 struct PCN32Base {
51 struct Device pcnb_Device;
52 struct MsgPort *pcnb_syncport;
54 OOP_Object *pcnb_pci;
55 OOP_Object *pcnb_irq;
56 OOP_AttrBase pcnb_pciDeviceAttrBase;
58 struct Sana2DeviceQuery pcnb_Sana2Info;
59 struct PCN32Unit *pcnb_unit;
62 #undef HiddPCIDeviceAttrBase
63 #define HiddPCIDeviceAttrBase (LIBBASE->pcnb_pciDeviceAttrBase)
65 enum {
66 WRITE_QUEUE,
67 ADOPT_QUEUE,
68 EVENT_QUEUE,
69 GENERAL_QUEUE,
70 REQUEST_QUEUE_COUNT
73 struct Opener
75 struct MinNode node;
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;
83 struct TypeStats
85 struct MinNode node;
86 ULONG packet_type;
87 struct Sana2PacketTypeStats stats;
91 struct TypeTracker
93 struct MinNode node;
94 ULONG packet_type;
95 struct Sana2PacketTypeStats stats;
96 ULONG user_count;
100 struct AddressRange
102 struct MinNode node;
103 ULONG add_count;
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 */
112 struct rx_ring_desc
114 IPTR PacketBuffer;
115 UWORD BufferLength;
116 UWORD BufferStatus;
117 ULONG BufferMsgLength;
118 ULONG Reserved;
121 struct tx_ring_desc
123 IPTR PacketBuffer;
124 UWORD BufferLength;
125 UWORD BufferStatus;
126 ULONG Misc;
127 ULONG Reserved;
130 #define STAT_COUNT 3
132 struct PCN32Unit {
133 struct MinNode *pcnu_Node;
134 struct MinList pcnu_Openers;
135 struct MinList pcnu_multicast_ranges;
136 struct MinList pcnu_type_trackers;
137 ULONG pcnu_UnitNum;
138 LONG pcnu_range_count;
140 OOP_Object *pcnu_PCIDevice;
141 OOP_Object *pcnu_PCIDriver;
143 struct timeval pcnu_toutPOLL;
144 BOOL pcnu_toutNEED;
145 BOOL pcnu_IntsAdded;
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: */
172 /* Card Funcs */
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 *);
184 int pcnu_open_count;
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;
192 IPTR pcnu_DeviceID;
193 IPTR pcnu_DriverFlags;
194 IPTR pcnu_IRQ;
195 APTR pcnu_BaseMem;
196 IPTR pcnu_SizeMem;
197 IPTR pcnu_BaseIO;
199 BYTE pcnu_signal_0;
200 BYTE pcnu_signal_1;
201 BYTE pcnu_signal_2;
202 BYTE pcnu_signal_3;
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;
212 STRPTR pcnu_name;
213 ULONG pcnu_mtu;
214 ULONG pcnu_flags;
215 ULONG pcnu_state;
216 APTR pcnu_mc_list;
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. */
225 enum {
226 IF_PORT_UNKNOWN = 0,
227 IF_PORT_10BASE2,
228 IF_PORT_10BASET,
229 IF_PORT_AUI,
230 IF_PORT_100BASET,
231 IF_PORT_100BASETX,
232 IF_PORT_100BASEFX
235 /* These flag bits are private to the generic network queueing
236 * layer, they may not be explicitly referenced by any other
237 * code.
240 enum netdev_state_t
242 __LINK_STATE_XOFF=0,
243 __LINK_STATE_START,
244 __LINK_STATE_PRESENT,
245 __LINK_STATE_SCHED,
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);
269 set_bit(nr, addr);
270 return oldbit;
273 static inline int test_and_clear_bit(int nr, volatile ULONG *addr)
275 int oldbit = test_bit(nr, addr);
276 clear_bit(nr, addr);
277 return oldbit;
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
370 struct dev_mc_list
372 struct dev_mc_list *next;
373 UBYTE dmi_addr[MAX_ADDR_LEN];
374 unsigned char dmi_addrlen;
375 int dmi_users;
376 int dmi_gusers;
379 struct pcnet32_init_block { // - The PCnet32 32-bit initialisation block.
380 // desribed in databook.
381 UWORD mode;
382 UWORD tlen_rlen;
383 UBYTE phys_addr[6];
384 UWORD reserved;
385 ULONG filter[2];
386 /* Recieve and Transmit ring base */
387 ULONG rx_ring;
388 ULONG tx_ring;
389 }; // pcnet32_init_block
391 struct fe_priv {
392 struct PCN32Unit *pci_dev;
393 int in_shutdown;
394 ULONG linkspeed;
395 int duplex;
396 int autoneg;
397 int fixed_mode;
398 int phyaddr;
399 int wolenabled;
400 unsigned int phy_oui;
401 UWORD gigabit;
402 ULONG desc_ver;
403 struct SignalSemaphore lock;
405 APTR ring_addr;
407 struct eth_frame *rx_buffer;
408 struct eth_frame *tx_buffer;
410 ULONG cur_rx, refill_rx;
412 ULONG next_tx, nic_tx;
413 ULONG tx_flags;
415 ULONG irqmask;
416 ULONG need_linktimer;
417 struct timeval link_timeout;
418 ULONG orig_mac[2];
419 struct pcnet32_init_block *fep_pcnet_init_block;
422 #define pci_name(unit) (unit->pcnu_name)
424 /* ENET defines */
426 #define HZ 1000000
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
448 struct eth_frame {
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
467 #endif
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)
477 #endif