BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / network / rtl8169 / device.h
blob4a4ec7380335d4d15e5f8164abee209d28b074ef
1 /* Realtek RTL8169 Family Driver
2 * Copyright (C) 2004 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
4 * Permission to use, copy, modify and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted, provided
6 * that the above copyright notice appear in all copies, and that both the
7 * copyright notice and this permission notice appear in supporting documentation.
9 * Marcus Overhagen makes no representations about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
12 * MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
13 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
14 * OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
15 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #ifndef __DEVICE_H
20 #define __DEVICE_H
22 #include <PCI.h>
23 #include "debug.h"
24 #include "hardware.h"
25 #include "timer.h"
27 #define TX_TIMEOUT 6000000 // 6 seconds
28 #define FRAME_SIZE 1536 // must be multiple of 8
29 #define DEFAULT_TX_BUF_COUNT 256 // must be <= 1024
30 #define DEFAULT_RX_BUF_COUNT 256 // must be <= 1024
32 extern pci_module_info *gPci;
34 status_t rtl8169_open(const char *name, uint32 flags, void** cookie);
35 status_t rtl8169_read(void* cookie, off_t position, void *buf, size_t* num_bytes);
36 status_t rtl8169_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes);
37 status_t rtl8169_control(void *cookie, uint32 op, void *arg, size_t len);
38 status_t rtl8169_close(void* cookie);
39 status_t rtl8169_free(void* cookie);
41 typedef struct {
42 int devId;
43 pci_info * pciInfo;
45 volatile bool nonblocking;
46 volatile bool closed;
48 #ifdef PROFILING
49 volatile int intTotalCount;
50 volatile int intTotalCountOld;
51 volatile int intRxTotalCount;
52 volatile int intTxTotalCount;
53 volatile int intTimerTotalCount;
54 volatile int intCurrentCount;
55 volatile int intRxCurrentCount;
56 volatile int intTxCurrentCount;
57 volatile int intTimerCurrentCount;
58 timer_id timer;
59 #endif // PROFILING
61 spinlock txSpinlock;
62 sem_id txFreeSem;
63 volatile int32 txNextIndex; // next descriptor that will be used for writing
64 volatile int32 txIntIndex; // current descriptor that needs be checked
65 volatile int32 txUsed;
66 int txBufferCount;
68 spinlock rxSpinlock;
69 sem_id rxReadySem;
70 volatile int32 rxNextIndex; // next descriptor that will be used for reading
71 volatile int32 rxIntIndex; // current descriptor that needs be checked
72 volatile int32 rxFree;
73 int rxBufferCount;
75 volatile buf_desc * txDesc;
76 volatile buf_desc * rxDesc;
78 area_id txDescArea;
79 area_id rxDescArea;
81 void ** txBuf;
82 void ** rxBuf;
84 area_id txBufArea;
85 area_id rxBufArea;
87 void * regAddr;
88 area_id regArea;
90 uint8 irq;
91 uint8 macaddr[6];
92 int maxframesize;
93 int mac_version;
94 int phy_version;
96 bool link_ok;
97 uint32 speed;
98 bool full_duplex;
100 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
101 sem_id linkChangeSem;
102 #endif
104 } rtl8169_device;
106 #define read8(offset) (*(volatile uint8 *) ((char *)(device->regAddr) + (offset)))
107 #define read16(offset) (*(volatile uint16 *)((char *)(device->regAddr) + (offset)))
108 #define read32(offset) (*(volatile uint32 *)((char *)(device->regAddr) + (offset)))
109 #define write8(offset, value) (*(volatile uint8 *) ((char *)(device->regAddr) + (offset)) = value)
110 #define write16(offset, value) (*(volatile uint16 *)((char *)(device->regAddr) + (offset)) = value)
111 #define write32(offset, value) (*(volatile uint32 *)((char *)(device->regAddr) + (offset)) = value)
113 #endif