]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1998-1999 by Apple Computer, Inc., All rights reserved. | |
24 | * | |
25 | * Interface definition for the BMac Ethernet Controller | |
26 | * | |
27 | * HISTORY | |
28 | * | |
29 | * Dec 10, 1998 jliu | |
30 | * Converted to IOKit/C++. | |
31 | */ | |
32 | ||
33 | #ifndef _BMACENET_H | |
34 | #define _BMACENET_H | |
35 | ||
36 | #include <IOKit/network/IOEthernetController.h> | |
37 | #include <IOKit/network/IOEthernetInterface.h> | |
38 | #include <IOKit/network/IOGatedOutputQueue.h> | |
39 | #include <IOKit/IOInterruptEventSource.h> | |
40 | #include <IOKit/IOTimerEventSource.h> | |
41 | #include <IOKit/network/IOMbufMemoryCursor.h> | |
42 | #include <IOKit/IODeviceMemory.h> | |
43 | #include <IOKit/ppc/IODBDMA.h> | |
44 | #include <string.h> /* bcopy */ | |
45 | #include "BMacEnetRegisters.h" | |
46 | ||
47 | extern "C" { | |
48 | #include <sys/param.h> | |
49 | #include <sys/mbuf.h> | |
50 | } | |
51 | ||
52 | // No kernel tracing support at this time. | |
53 | // | |
54 | #define KERNEL_DEBUG(x,a,b,c,d,e) | |
55 | ||
56 | // #define IOLog kprintf | |
57 | ||
58 | typedef void * IOPPCAddress; | |
59 | ||
60 | typedef struct enet_dma_cmd_t | |
61 | { | |
62 | IODBDMADescriptor desc_seg[2]; | |
63 | } enet_dma_cmd_t; | |
64 | ||
65 | typedef struct enet_txdma_cmd_t | |
66 | { | |
67 | IODBDMADescriptor desc_seg[3]; | |
68 | } enet_txdma_cmd_t; | |
69 | ||
70 | class BMacEnet : public IOEthernetController | |
71 | { | |
72 | OSDeclareDefaultStructors( BMacEnet ) | |
73 | ||
74 | private: | |
75 | volatile IOPPCAddress ioBaseEnet; | |
76 | volatile IOPPCAddress ioBaseHeathrow; | |
77 | volatile IODBDMAChannelRegisters * ioBaseEnetRxDMA; | |
78 | volatile IODBDMAChannelRegisters * ioBaseEnetTxDMA; | |
79 | ||
80 | IOEthernetAddress myAddress; | |
81 | IOEthernetInterface * networkInterface; | |
82 | IOGatedOutputQueue * transmitQueue; | |
83 | IOPacketQueue * debugQueue; | |
84 | IOKernelDebugger * debugger; | |
85 | bool isPromiscuous; | |
86 | bool multicastEnabled; | |
87 | bool isFullDuplex; | |
88 | ||
89 | IOWorkLoop * workLoop; | |
90 | IOInterruptEventSource * rxIntSrc; | |
91 | IOMemoryMap * maps[MEMORY_MAP_COUNT]; | |
92 | IONetworkStats * netStats; | |
93 | IOTimerEventSource * timerSrc; | |
94 | IOMbufBigMemoryCursor * mbufCursor; | |
95 | ||
96 | bool ready; | |
97 | bool netifEnabled; | |
98 | bool debugEnabled; | |
99 | bool debugTxPoll; | |
100 | bool useUnicastFilter; | |
101 | unsigned int enetAddressOffset; | |
102 | ||
103 | unsigned long chipId; | |
104 | ||
105 | unsigned long phyType; | |
106 | unsigned long phyMIIDelay; | |
107 | ||
108 | unsigned char phyId; | |
109 | unsigned char sromAddressBits; | |
110 | ||
111 | unsigned short phyStatusPrev; | |
112 | ||
113 | OSDictionary * mediumDict; | |
114 | ||
115 | struct mbuf * txMbuf[TX_RING_LENGTH]; | |
116 | struct mbuf * rxMbuf[RX_RING_LENGTH]; | |
117 | struct mbuf * txDebuggerPkt; | |
118 | ||
119 | unsigned int txCommandHead; // TX ring descriptor index | |
120 | unsigned int txCommandTail; | |
121 | unsigned int txMaxCommand; | |
122 | unsigned int rxCommandHead; // RX ring descriptor index | |
123 | unsigned int rxCommandTail; | |
124 | unsigned int rxMaxCommand; | |
125 | ||
126 | struct { | |
127 | void * ptr; | |
128 | u_int size; | |
129 | void * ptrReal; | |
130 | u_int sizeReal; | |
131 | } dmaMemory; | |
132 | ||
133 | unsigned char * dmaCommands; | |
134 | enet_txdma_cmd_t * txDMACommands; // TX descriptor ring ptr | |
135 | unsigned int txDMACommandsPhys; | |
136 | ||
137 | enet_dma_cmd_t * rxDMACommands; // RX descriptor ring ptr | |
138 | unsigned int rxDMACommandsPhys; | |
139 | ||
140 | u_int32_t txWDInterrupts; | |
141 | u_int32_t txWDCount; | |
142 | ||
143 | void * debuggerPkt; | |
144 | u_int32_t debuggerPktSize; | |
145 | ||
146 | u_int16_t statReg; // Current STAT register contents | |
147 | ||
148 | u_int16_t hashTableUseCount[64]; | |
149 | u_int16_t hashTableMask[4]; | |
150 | ||
151 | unsigned long currentPowerState; | |
152 | ||
153 | bool _allocateMemory(); | |
154 | bool _initTxRing(); | |
155 | bool _initRxRing(); | |
156 | bool _initChip(); | |
157 | void _resetChip(); | |
158 | void _disableAdapterInterrupts(); | |
159 | void _enableAdapterInterrupts(); | |
160 | void _setDuplexMode(bool duplexMode); | |
161 | void _startChip(); | |
162 | bool _updateDescriptorFromMbuf(struct mbuf * m, enet_dma_cmd_t * desc, | |
163 | bool isReceive); | |
164 | void _restartTransmitter(); | |
165 | void _stopTransmitDMA(); | |
166 | bool _transmitPacket(struct mbuf * packet); | |
167 | bool _transmitInterruptOccurred(); | |
168 | bool _debugTransmitInterruptOccurred(); | |
169 | bool _receiveInterruptOccurred(); | |
170 | bool _rejectBadUnicastPacket(ether_header_t * etherHeader); | |
171 | bool _receivePackets(bool fDebugger); | |
172 | void _packetToDebugger(struct mbuf * packet, u_int size); | |
173 | void _restartReceiver(); | |
174 | void _stopReceiveDMA(); | |
175 | bool _resetAndEnable(bool enable); | |
176 | void _sendDummyPacket(); | |
177 | void _resetHashTableMask(); | |
178 | void _addToHashTableMask(u_int8_t * addr); | |
179 | void _removeFromHashTableMask(u_int8_t * addr); | |
180 | void _updateBMacHashTableMask(); | |
181 | bool createMediumTables(); | |
182 | ||
183 | #ifdef DEBUG | |
184 | void _dumpRegisters(); | |
185 | void _dumpDesc(void * addr, u_int32_t size); | |
186 | void _dump_srom(); | |
187 | #endif DEBUG | |
188 | ||
189 | void _sendPacket(void * pkt, unsigned int pkt_len); | |
190 | void _receivePacket(void * pkt, unsigned int * pkt_len, | |
191 | unsigned int timeout); | |
192 | ||
193 | void sendPacket(void * pkt, UInt32 pkt_len); | |
194 | void receivePacket(void * pkt, UInt32 * pkt_len, | |
195 | UInt32 timeout); | |
196 | ||
197 | bool miiReadWord(unsigned short * dataPtr, unsigned short reg, | |
198 | unsigned char phy); | |
199 | bool miiWriteWord(unsigned short data, unsigned short reg, | |
200 | unsigned char phy); | |
201 | void miiWrite(unsigned int miiData, unsigned int dataSize); | |
202 | int miiReadBit(); | |
203 | bool miiCheckZeroBit(); | |
204 | void miiOutThreeState(); | |
205 | bool miiResetPHY(unsigned char phy); | |
206 | bool miiWaitForLink(unsigned char phy); | |
207 | bool miiWaitForAutoNegotiation(unsigned char phy); | |
208 | void miiRestartAutoNegotiation(unsigned char phy); | |
209 | bool miiFindPHY(unsigned char * phy_num); | |
210 | bool miiInitializePHY(unsigned char phy); | |
211 | ||
212 | UInt32 outputPacket(struct mbuf * m, void * param); | |
213 | ||
214 | void interruptOccurredForSource(IOInterruptEventSource * src, int count); | |
215 | ||
216 | void timeoutOccurred(IOTimerEventSource * timer); | |
217 | ||
218 | void monitorLinkStatus( bool firstPoll = false ); | |
219 | ||
220 | public: | |
221 | virtual bool init(OSDictionary * properties = 0); | |
222 | virtual bool start(IOService * provider); | |
223 | virtual void free(); | |
224 | ||
225 | virtual bool createWorkLoop(); | |
226 | virtual IOWorkLoop * getWorkLoop() const; | |
227 | ||
228 | virtual IOReturn enable(IONetworkInterface * netif); | |
229 | virtual IOReturn disable(IONetworkInterface * netif); | |
230 | ||
231 | virtual IOReturn getHardwareAddress(IOEthernetAddress * addr); | |
232 | ||
233 | virtual IOReturn setMulticastMode(IOEnetMulticastMode mode); | |
234 | virtual IOReturn setMulticastList(IOEthernetAddress * addrs, UInt32 count); | |
235 | ||
236 | virtual IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode); | |
237 | ||
238 | virtual IOOutputQueue * createOutputQueue(); | |
239 | ||
240 | virtual const OSString * newVendorString() const; | |
241 | virtual const OSString * newModelString() const; | |
242 | virtual const OSString * newRevisionString() const; | |
243 | ||
244 | virtual IOReturn enable(IOKernelDebugger * debugger); | |
245 | virtual IOReturn disable(IOKernelDebugger * debugger); | |
246 | ||
247 | virtual bool configureInterface(IONetworkInterface * netif); | |
248 | ||
249 | // Simple power managment support: | |
250 | virtual IOReturn setPowerState( UInt32 powerStateOrdinal, | |
251 | IOService * whatDevice ); | |
252 | ||
253 | virtual IOReturn registerWithPolicyMaker(IOService * policyMaker); | |
254 | }; | |
255 | ||
256 | /* | |
257 | * Performance tracepoints | |
258 | * | |
259 | * DBG_BMAC_RXIRQ - Receive ISR run time | |
260 | * DBG_BMAC_TXIRQ - Transmit ISR run time | |
261 | * DBG_BMAC_TXQUEUE - Transmit packet passed from network stack | |
262 | * DBG_BMAC_TXCOMPLETE - Transmit packet sent | |
263 | * DBG_BMAC_RXCOMPLETE - Receive packet passed to network stack | |
264 | */ | |
265 | #define DBG_BMAC_ENET 0x0900 | |
266 | #define DBG_BMAC_RXIRQ DRVDBG_CODE(DBG_DRVNETWORK,(DBG_BMAC_ENET+1)) | |
267 | #define DBG_BMAC_TXIRQ DRVDBG_CODE(DBG_DRVNETWORK,(DBG_BMAC_ENET+2)) | |
268 | #define DBG_BMAC_TXQUEUE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_BMAC_ENET+3)) | |
269 | #define DBG_BMAC_TXCOMPLETE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_BMAC_ENET+4)) | |
270 | #define DBG_BMAC_RXCOMPLETE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_BMAC_ENET+5)) | |
271 | ||
272 | #endif /* !_BMACENET_H */ |