2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1995-1996 NeXT Software, Inc.
25 * Interface definition for the Mace Ethernet chip
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 */
47 #include <kern/kdebug.h> /* Performance tracepoints */
49 #define KERNEL_DEBUG(x,a,b,c,d,e)
52 #include "MaceEnetRegisters.h"
55 #include <sys/param.h>
63 typedef void * IOPPCAddress
;
65 typedef struct enet_dma_cmd_t
67 IODBDMADescriptor desc_seg
[2];
70 typedef struct enet_txdma_cmd_t
72 IODBDMADescriptor desc_seg
[4];
75 class MaceEnet
: public IOEthernetController
77 OSDeclareDefaultStructors(MaceEnet
)
80 volatile IOPPCAddress ioBaseEnet
;
81 volatile IOPPCAddress ioBaseEnetROM
;
82 volatile IODBDMAChannelRegisters
*ioBaseEnetRxDMA
;
83 volatile IODBDMAChannelRegisters
*ioBaseEnetTxDMA
;
87 IOEthernetAddress myAddress
;
88 IOEthernetInterface
* networkInterface
;
89 IOGatedOutputQueue
* transmitQueue
;
90 IOPacketQueue
* debugQueue
;
91 IOKernelDebugger
* debugger
;
93 bool multicastEnabled
;
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
;
108 struct mbuf
* txMbuf
[TX_RING_LENGTH
];
109 struct mbuf
* rxMbuf
[RX_RING_LENGTH
];
110 struct mbuf
* txDebuggerPkt
;
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
;
126 unsigned char * dmaCommands
;
127 enet_txdma_cmd_t
* txDMACommands
; /* TX descriptor ring ptr */
128 unsigned int txDMACommandsPhys
;
130 enet_dma_cmd_t
* rxDMACommands
; /* RX descriptor ring ptr */
131 unsigned int rxDMACommandsPhys
;
133 u_int32_t txWDInterrupts
;
134 u_int32_t txWDTimeouts
;
138 u_int32_t debuggerPktSize
;
140 u_int16_t hashTableUseCount
[64];
141 u_int8_t hashTableMask
[8];
143 bool _allocateMemory();
148 void _disableAdapterInterrupts();
149 void _enableAdapterInterrupts();
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
,
161 void _resetHashTableMask();
162 void _addToHashTableMask(u_int8_t
*addr
);
163 void _removeFromHashTableMask(u_int8_t
*addr
);
164 void _updateHashTableMask();
166 void _dumpRegisters();
167 void _dumpDesc(void * addr
, u_int32_t size
);
169 IOReturn
_setPromiscuousMode(IOEnetPromiscuousMode mode
);
170 void MaceEnet::_sendTestPacket();
175 void _sendPacket(void *pkt
, unsigned int pkt_len
);
176 void _receivePacket(void *pkt
, unsigned int *pkt_len
, unsigned int
179 bool resetAndEnable(bool enable
);
180 void interruptOccurredForSource(IOInterruptEventSource
*src
, int count
);
181 void timeoutOccurred(IOTimerEventSource
*timer
);
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
);
191 virtual bool createWorkLoop();
192 virtual IOWorkLoop
* getWorkLoop() const;
194 virtual IOReturn
enable(IONetworkInterface
* netif
);
195 virtual IOReturn
disable(IONetworkInterface
* netif
);
197 virtual IOReturn
enable(IOKernelDebugger
* debugger
);
198 virtual IOReturn
disable(IOKernelDebugger
* debugger
);
200 virtual IOReturn
getHardwareAddress(IOEthernetAddress
*addr
);
202 virtual IOReturn
setMulticastMode(IOEnetMulticastMode mode
);
203 virtual IOReturn
setMulticastList(IOEthernetAddress
*addrs
, UInt32 count
);
205 virtual IOReturn
setPromiscuousMode(IOEnetPromiscuousMode mode
);
207 virtual IOOutputQueue
* createOutputQueue();
209 virtual UInt32
outputPacket(struct mbuf
* m
, void * param
);
211 virtual void sendPacket(void *pkt
, UInt32 pkt_len
);
212 virtual void receivePacket(void *pkt
, UInt32
*pkt_len
, UInt32 timeout
);
214 virtual const OSString
* newVendorString() const;
215 virtual const OSString
* newModelString() const;
216 virtual const OSString
* newRevisionString() const;
219 #if 0 // no power management stuff in IOKit yet.
221 * Power management methods.
223 - (IOReturn
)getPowerState
:(PMPowerState
*)state_p
;
224 - (IOReturn
)setPowerState
:(PMPowerState
)state
;
225 - (IOReturn
)getPowerManagement
:(PMPowerManagementState
*)state_p
;
226 - (IOReturn
)setPowerManagement
:(PMPowerManagementState
)state
;
230 * Performance tracepoints
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
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))
245 #endif /* !_MACEENET_H */