-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViaRhine.h
289 lines (200 loc) · 8.54 KB
/
ViaRhine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// -----------------------------------------------------------------------------
// Copyright (c) 2006, Yang Wu
// All rights reserved.
// Redistribute or use following BSD License.
// -----------------------------------------------------------------------------
//
// project via rhine nic driver
// ViaRhine.h
// This file is Enthernet Controller class interface for via rhine driver
//
// Yang Wu 2006-3 @ Shanghai, China
// Email : [email protected]
// Web : http://www.pinxue.net
// -----------------------------------------------------------------------------
#ifndef _ViaRhine_H
#define _ViaRhine_H
#include <IOKit/assert.h>
#include <IOKit/IOLib.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/IODeviceMemory.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/IOBufferMemoryDescriptor.h>
#include <IOKit/pci/IOPCIDevice.h>
#include <IOKit/network/IOEthernetController.h>
#include <IOKit/network/IOEthernetInterface.h>
#include <IOKit/network/IOGatedOutputQueue.h>
#include <IOKit/network/IOMbufMemoryCursor.h>
extern "C" {
#include <sys/kpi_mbuf.h>
}
#include "ViaRhineHW.h"
#ifdef DEBUG
#define DEBUG_LOG(args...) IOLog(args)
#else
#define DEBUG_LOG(args...)
#endif
#define BUMP_NET_COUNTER(x) \
netStats->x += 1;
#define BUMP_ETHER_COUNTER(x) \
etherStats->dot3StatsEntry.x += 1;
#define BUMP_ETHER_RX_COUNTER(x) \
etherStats->dot3RxExtraEntry.x += 1;
#define BUMP_ETHER_TX_COUNTER(x) \
etherStats->dot3TxExtraEntry.x += 1;
#define kWatchdogTimerPeriod 10000 // milliseconds
#define kTransmitQueueCapacity 384
#define MINPACK 60 // minimum output packet length
#define MAXPACK 1514 // maximum output packet length
#define RX_RING_SIZE 128 // number of rx descriptors to compsite the ring
#define TX_RING_SIZE 128 // number of tx descriptors to compsite the ring
#define TX_QUEUE_LEN TX_RING_SIZE-4 // actually number of descriptors allowed to be using
#define PKT_BUF_SZ 1536
#define ViaRhine net_pinxue_driver_ViaRhine
class ViaRhine : public IOEthernetController
{
OSDeclareDefaultStructors( net_pinxue_driver_ViaRhine )
protected:
IOEthernetInterface * netif;
IOPCIDevice * pciNub;
IOWorkLoop * workLoop;
IOInterruptEventSource * interruptSrc;
IOOutputQueue * transmitQueue;
IOTimerEventSource * timerSrc;
//IOKernelDebugger * debugger;
IONetworkStats * netStats;
IOEthernetStats * etherStats;
IOMemoryMap * csrMap;
volatile void * csrBase;
bool promiscuousMode;
IOBufferMemoryDescriptor * tx_md;
struct tx_desc * tx_ring;
IOPhysicalAddress tx_ring_dma;
mbuf_t tx_mbuf[TX_RING_SIZE];
IOBufferMemoryDescriptor * tx_buf_md[TX_RING_SIZE];
unsigned char * tx_buf[TX_RING_SIZE];
IOPhysicalAddress tx_buf_dma[TX_RING_SIZE];
UInt32 tx_cur;
UInt32 tx_dirty;
UInt16 rx_copybreak;
IOBufferMemoryDescriptor * rx_md;
struct rx_desc * rx_ring;
IOPhysicalAddress rx_ring_dma;
UInt32 rx_buf_sz; // based on MTU+slack
IOBufferMemoryDescriptor * rx_buf_md[RX_RING_SIZE];
unsigned char * rx_buf[RX_RING_SIZE];
IOPhysicalAddress rx_buf_dma[RX_RING_SIZE];
UInt32 rx_cur;
UInt32 rx_dirty;
struct rx_desc * rx_head_desc;
UInt8 pciRev;
const char * model;
UInt16 phyId;
bool isRhineI;
bool statusWBRace;
bool sixPatterns;
UInt8 reg_config1;
UInt32 currentLevel;
bool enabledByBSD;
bool enabledByKDP;
bool interruptEnabled;
OSDictionary * mediumDict;
const IONetworkMedium * mediumTable[MEDIUM_INDEX_COUNT];
MediumIndex currentMediumIndex;
UInt16 phyStatusLast;
UInt16 reg_bms;
UInt32 reg_mar0;
UInt32 reg_mar1;
UInt8 tx_thresh;
UInt8 rx_thresh;
UInt32 multicast_filter_limit;
void dumpRegisters( void );
void restartReceiver( void );
void transmitterInterrupt( bool * reclaimed );
void receiverInterrupt( bool * queued );
void errorInterrupt( UInt32 intrStatus );
void interruptOccurred( OSObject * client, IOInterruptEventSource * src, int count );
bool initEventSources( IOService * provider );
bool initPCIConfigSpace( IOPCIDevice * provider );
bool enableAdapter( UInt32 level );
bool disableAdapter( UInt32 level );
enum {
kActivationLevel0 = 0,
kActivationLevel1,
kActivationLevel2
};
bool setActivationLevel( UInt32 newLevel );
void timeoutOccurred( OSObject * owner, IOTimerEventSource * timer );
bool allocateDescriptorMemory( void );
enum {
kFullInitialization = 0,
kResetChip = 1
};
bool initAdapter( IOOptionBits options );
void reloadEEPRom( void );
void disableHardwareInterrupts( void );
void enableHardwareInterrupts( void );
void reclaimTransmitBuffer( void );
// PHY functions
void enableLinkMon( void );
void disableLinkMon( void );
UInt16 mdioRead( UInt16 reg );
void mdioWrite( UInt16 reg, UInt16 value );
bool phyAddMediumType( IOMediumType type, UInt32 bps, MediumIndex index);
void phyProbeMediaCapability( void );
bool phyReset( void );
bool phyWaitForAutoNegotiation( void );
bool phySetMedium( MediumIndex mediumIndex );
bool phySetMedium( const IONetworkMedium * medium );
void phyReportLinkStatus( bool forceStatusReport = false );
const IONetworkMedium * phyGetMediumWithIndex( MediumIndex index ) const;
// Access hardware registers
inline void csrWrite32( UInt16 offset, UInt32 value )
{ pciNub->ioWrite32(offset, value, csrMap); }
inline void csrWrite16( UInt16 offset, UInt16 value )
{ pciNub->ioWrite16(offset, value, csrMap); }
inline void csrWrite8( UInt16 offset, UInt8 value )
{ pciNub->ioWrite8(offset, value, csrMap); }
inline void csrWrite32Slow( UInt16 offset, UInt32 value )
{ pciNub->ioWrite32(offset, value, csrMap); pciNub->ioRead32(offset, csrMap); }
inline void csrWrite16Slow( UInt16 offset, UInt16 value )
{ pciNub->ioWrite16(offset, value, csrMap); pciNub->ioRead16(offset, csrMap); }
inline void csrWrite8Slow( UInt16 offset, UInt8 value )
{ pciNub->ioWrite8(offset, value, csrMap); pciNub->ioRead8(offset, csrMap); }
inline UInt32 csrRead32( UInt16 offset )
{ return pciNub->ioRead32(offset, csrMap); }
inline UInt16 csrRead16( UInt16 offset )
{ return pciNub->ioRead16(offset, csrMap); }
inline UInt8 csrRead8( UInt16 offset )
{ return pciNub->ioRead8(offset, csrMap); }
public:
virtual bool init( OSDictionary * properties );
virtual bool start( IOService * provider );
virtual void stop( IOService * provider );
virtual void free( void );
virtual IOReturn enable( IONetworkInterface * netif );
virtual IOReturn disable( IONetworkInterface * netif );
virtual IOReturn enable( IOKernelDebugger * netif );
virtual IOReturn disable( IOKernelDebugger * netif );
virtual UInt32 outputPacket( mbuf_t m, void * param );
virtual void getPacketBufferConstraints(
IOPacketBufferConstraints * constraints ) const;
virtual IOOutputQueue * createOutputQueue( void );
virtual const OSString * newVendorString( void ) const;
virtual const OSString * newModelString( void ) const;
virtual IOReturn selectMedium( const IONetworkMedium * medium );
virtual bool configureInterface( IONetworkInterface * interface );
virtual bool createWorkLoop( void );
virtual IOWorkLoop * getWorkLoop( void ) const;
virtual IOReturn getHardwareAddress( IOEthernetAddress * addr );
virtual IOReturn setPromiscuousMode( bool enabled );
virtual IOReturn setMulticastMode( bool enabled );
virtual IOReturn setMulticastList( IOEthernetAddress * addrs,
UInt32 count );
virtual void sendPacket( void * pkt, UInt32 pkt_len );
virtual void receivePacket( void * pkt, UInt32 * pkt_len, UInt32 timeout );
virtual IOReturn registerWithPolicyMaker( IOService * policyMaker );
virtual IOReturn setPowerState( unsigned long powerStateOrdinal,
IOService * policyMaker );
};
#endif /* !_ViaRhine_H */