]>
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) 1995-1996 NeXT Software, Inc. | |
24 | * | |
25 | * Interface definition for the Mace Ethernet chip | |
26 | * | |
27 | * HISTORY | |
28 | * | |
29 | * 16-Sept-97 | |
30 | * Created. | |
31 | */ | |
32 | ||
33 | #ifndef _MACEENET_H | |
34 | #define _MACEENET_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 | ||
46 | #if 0 | |
47 | #include <kern/kdebug.h> /* Performance tracepoints */ | |
48 | #else | |
49 | #define KERNEL_DEBUG(x,a,b,c,d,e) | |
50 | #endif | |
51 | ||
52 | #include "MaceEnetRegisters.h" | |
53 | ||
54 | extern "C" { | |
55 | #include <sys/param.h> | |
56 | #include <sys/mbuf.h> | |
57 | } | |
58 | ||
59 | #if 0 | |
60 | #define IOLog kprintf | |
61 | #endif | |
62 | ||
63 | typedef void * IOPPCAddress; | |
64 | ||
65 | typedef struct enet_dma_cmd_t | |
66 | { | |
67 | IODBDMADescriptor desc_seg[2]; | |
68 | } enet_dma_cmd_t; | |
69 | ||
70 | typedef struct enet_txdma_cmd_t | |
71 | { | |
72 | IODBDMADescriptor desc_seg[4]; | |
73 | } enet_txdma_cmd_t; | |
74 | ||
75 | class MaceEnet : public IOEthernetController | |
76 | { | |
77 | OSDeclareDefaultStructors(MaceEnet) | |
78 | ||
79 | private: | |
80 | volatile IOPPCAddress ioBaseEnet; | |
81 | volatile IOPPCAddress ioBaseEnetROM; | |
82 | volatile IODBDMAChannelRegisters *ioBaseEnetRxDMA; | |
83 | volatile IODBDMAChannelRegisters *ioBaseEnetTxDMA; | |
84 | ||
85 | u_int16_t chipId; | |
86 | ||
87 | IOEthernetAddress myAddress; | |
88 | IOEthernetInterface * networkInterface; | |
89 | IOGatedOutputQueue * transmitQueue; | |
90 | IOPacketQueue * debugQueue; | |
91 | IOKernelDebugger * debugger; | |
92 | bool isPromiscuous; | |
93 | bool multicastEnabled; | |
94 | bool ready; | |
95 | bool netifClient; | |
96 | bool debugClient; | |
97 | bool debugTxPoll; | |
98 | ||
99 | IOWorkLoop * workLoop; | |
100 | IOInterruptEventSource *rxIntSrc; | |
101 | IOInterruptEventSource *txIntSrc; | |
102 | IOMemoryMap * maps[MEMORY_MAP_COUNT]; | |
103 | IOMemoryMap * romMap; | |
104 | IONetworkStats * netStats; | |
105 | IOTimerEventSource * timerSrc; | |
106 | IOMbufBigMemoryCursor * mbufCursor; | |
107 | ||
108 | struct mbuf * txMbuf[TX_RING_LENGTH]; | |
109 | struct mbuf * rxMbuf[RX_RING_LENGTH]; | |
110 | struct mbuf * txDebuggerPkt; | |
111 | ||
112 | unsigned int txCommandHead; /* Transmit ring descriptor index */ | |
113 | unsigned int txCommandTail; | |
114 | unsigned int txMaxCommand; | |
115 | unsigned int rxCommandHead; /* Receive ring descriptor index */ | |
116 | unsigned int rxCommandTail; | |
117 | unsigned int rxMaxCommand; | |
118 | ||
119 | struct { | |
120 | void *ptr; | |
121 | u_int size; | |
122 | void *ptrReal; | |
123 | u_int sizeReal; | |
124 | } dmaMemory; | |
125 | ||
126 | unsigned char * dmaCommands; | |
127 | enet_txdma_cmd_t * txDMACommands; /* TX descriptor ring ptr */ | |
128 | unsigned int txDMACommandsPhys; | |
129 | ||
130 | enet_dma_cmd_t * rxDMACommands; /* RX descriptor ring ptr */ | |
131 | unsigned int rxDMACommandsPhys; | |
132 | ||
133 | u_int32_t txWDInterrupts; | |
134 | u_int32_t txWDTimeouts; | |
135 | bool txWDForceReset; | |
136 | ||
137 | void * debuggerPkt; | |
138 | u_int32_t debuggerPktSize; | |
139 | ||
140 | u_int16_t hashTableUseCount[64]; | |
141 | u_int8_t hashTableMask[8]; | |
142 | ||
143 | bool _allocateMemory(); | |
144 | bool _initTxRing(); | |
145 | bool _initRxRing(); | |
146 | bool _initChip(); | |
147 | void _resetChip(); | |
148 | void _disableAdapterInterrupts(); | |
149 | void _enableAdapterInterrupts(); | |
150 | void _startChip(); | |
151 | void _restartChip(); | |
152 | void _stopReceiveDMA(); | |
153 | void _stopTransmitDMA(); | |
154 | bool _transmitPacket(struct mbuf * packet); | |
155 | bool _transmitInterruptOccurred(bool fDebugger = false); | |
156 | bool _receiveInterruptOccurred(); | |
157 | bool _receivePackets(bool fDebugger); | |
158 | void _packetToDebugger(struct mbuf * packet, u_int size); | |
159 | bool _updateDescriptorFromMbuf(struct mbuf * m, enet_dma_cmd_t *desc, | |
160 | bool isReceive); | |
161 | void _resetHashTableMask(); | |
162 | void _addToHashTableMask(u_int8_t *addr); | |
163 | void _removeFromHashTableMask(u_int8_t *addr); | |
164 | void _updateHashTableMask(); | |
165 | #ifdef DEBUG | |
166 | void _dumpRegisters(); | |
167 | void _dumpDesc(void * addr, u_int32_t size); | |
168 | #endif | |
169 | IOReturn _setPromiscuousMode(IOEnetPromiscuousMode mode); | |
170 | void MaceEnet::_sendTestPacket(); | |
171 | ||
172 | /* | |
173 | * Kernel Debugger | |
174 | */ | |
175 | void _sendPacket(void *pkt, unsigned int pkt_len); | |
176 | void _receivePacket(void *pkt, unsigned int *pkt_len, unsigned int | |
177 | timeout); | |
178 | ||
179 | bool resetAndEnable(bool enable); | |
180 | void interruptOccurredForSource(IOInterruptEventSource *src, int count); | |
181 | void timeoutOccurred(IOTimerEventSource *timer); | |
182 | ||
183 | public: | |
184 | virtual MaceEnet * MaceEnet::probe(IOService * provider, | |
185 | unsigned int * score, | |
186 | unsigned int * specificity); | |
187 | virtual bool init(OSDictionary * properties = 0); | |
188 | virtual bool start(IOService * provider); | |
189 | virtual void free(); | |
190 | ||
191 | virtual bool createWorkLoop(); | |
192 | virtual IOWorkLoop * getWorkLoop() const; | |
193 | ||
194 | virtual IOReturn enable(IONetworkInterface * netif); | |
195 | virtual IOReturn disable(IONetworkInterface * netif); | |
196 | ||
197 | virtual IOReturn enable(IOKernelDebugger * debugger); | |
198 | virtual IOReturn disable(IOKernelDebugger * debugger); | |
199 | ||
200 | virtual IOReturn getHardwareAddress(IOEthernetAddress *addr); | |
201 | ||
202 | virtual IOReturn setMulticastMode(IOEnetMulticastMode mode); | |
203 | virtual IOReturn setMulticastList(IOEthernetAddress *addrs, UInt32 count); | |
204 | ||
205 | virtual IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode); | |
206 | ||
207 | virtual IOOutputQueue * createOutputQueue(); | |
208 | ||
209 | virtual UInt32 outputPacket(struct mbuf * m, void * param); | |
210 | ||
211 | virtual void sendPacket(void *pkt, UInt32 pkt_len); | |
212 | virtual void receivePacket(void *pkt, UInt32 *pkt_len, UInt32 timeout); | |
213 | ||
214 | virtual const OSString * newVendorString() const; | |
215 | virtual const OSString * newModelString() const; | |
216 | virtual const OSString * newRevisionString() const; | |
217 | }; | |
218 | ||
219 | #if 0 // no power management stuff in IOKit yet. | |
220 | /* | |
221 | * Power management methods. | |
222 | */ | |
223 | - (IOReturn)getPowerState:(PMPowerState *)state_p; | |
224 | - (IOReturn)setPowerState:(PMPowerState)state; | |
225 | - (IOReturn)getPowerManagement:(PMPowerManagementState *)state_p; | |
226 | - (IOReturn)setPowerManagement:(PMPowerManagementState)state; | |
227 | #endif | |
228 | ||
229 | /* | |
230 | * Performance tracepoints | |
231 | * | |
232 | * DBG_MACE_RXIRQ - Receive ISR run time | |
233 | * DBG_MACE_TXIRQ - Transmit ISR run time | |
234 | * DBG_MACE_TXQUEUE - Transmit packet passed from network stack | |
235 | * DBG_MACE_TXCOMPLETE - Transmit packet sent | |
236 | * DBG_MACE_RXCOMPLETE - Receive packet passed to network stack | |
237 | */ | |
238 | #define DBG_MACE_ENET 0x0800 | |
239 | #define DBG_MACE_RXIRQ DRVDBG_CODE(DBG_DRVNETWORK,(DBG_MACE_ENET+1)) | |
240 | #define DBG_MACE_TXIRQ DRVDBG_CODE(DBG_DRVNETWORK,(DBG_MACE_ENET+2)) | |
241 | #define DBG_MACE_TXQUEUE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_MACE_ENET+3)) | |
242 | #define DBG_MACE_TXCOMPLETE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_MACE_ENET+4)) | |
243 | #define DBG_MACE_RXCOMPLETE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_MACE_ENET+5)) | |
244 | ||
245 | #endif /* !_MACEENET_H */ |