|
|
1.1 ! root 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 Apple Software, Inc. ! 24: * ! 25: * Interface definition for the UniN Ethernet Controller ! 26: * ! 27: * HISTORY ! 28: * ! 29: */ ! 30: ! 31: #include <IOKit/network/IOEthernetController.h> ! 32: #include <IOKit/network/IOEthernetInterface.h> ! 33: #include <IOKit/network/IOOQLockFIFOQueue.h> ! 34: #include <IOKit/IOInterruptEventSource.h> ! 35: #include <IOKit/IOTimerEventSource.h> ! 36: #include <IOKit/network/IOMBufMemoryCursor.h> ! 37: #include <IOKit/IODeviceMemory.h> ! 38: #include <IOKit/pci/IOPCIDevice.h> ! 39: #include <IOKit/IOLib.h> /* bcopy */ ! 40: ! 41: #include "../../platform/drvAppleCore99PE/Core99.h" ! 42: ! 43: extern "C" ! 44: { ! 45: #include <sys/param.h> ! 46: #include <sys/mbuf.h> ! 47: } ! 48: ! 49: //#define IOLog kprintf ! 50: ! 51: // No kernel tracing support at this time. ! 52: // ! 53: #define KERNEL_DEBUG(x,a,b,c,d,e) ! 54: ! 55: #include "UniNEnetRegisters.h" ! 56: ! 57: typedef void * IOPPCAddress; ! 58: ! 59: #define NUM_RX_DESC 1 ! 60: typedef struct enet_dma_cmd_t ! 61: { ! 62: GEMRxDescriptor desc_seg[NUM_RX_DESC]; ! 63: } enet_dma_cmd_t; ! 64: ! 65: #define NUM_TX_DESC 1 ! 66: typedef struct enet_txdma_cmd_t ! 67: { ! 68: GEMTxDescriptor desc_seg[NUM_TX_DESC]; ! 69: } enet_txdma_cmd_t; ! 70: ! 71: ! 72: typedef struct TxQueueElement ! 73: { ! 74: queue_chain_t next; ! 75: queue_head_t *list; ! 76: ! 77: struct mbuf *mbuf; ! 78: UInt32 slot; ! 79: UInt32 count; ! 80: } TxQueueElement; ! 81: ! 82: ! 83: class UniNEnet: public IOEthernetController ! 84: { ! 85: OSDeclareDefaultStructors(UniNEnet) ! 86: ! 87: IOPCIDevice *nub; ! 88: Core99PE *platformNub; ! 89: ! 90: IOMemoryMap *ioMapEnet; ! 91: volatile IOPPCAddress ioBaseEnet; ! 92: ! 93: IOEthernetInterface *networkInterface; ! 94: IOOQLockFIFOQueue *transmitQueue; ! 95: IOPacketQueue *debugQueue; ! 96: IOKernelDebugger *debugger; ! 97: ! 98: IOInterruptEventSource *interruptSource; ! 99: IONetworkStats *netStats; ! 100: IOTimerEventSource *timerSource; ! 101: IOMBufBigMemoryCursor *mbufCursor; ! 102: ! 103: bool ready; ! 104: bool netifClient; ! 105: bool debugClient; ! 106: bool debugTxPoll; ! 107: ! 108: enet_addr_t myAddress; ! 109: bool isPromiscuous; ! 110: bool multicastEnabled; ! 111: bool isFullDuplex; ! 112: ! 113: UInt32 phyType; ! 114: UInt8 phyId; ! 115: ! 116: UInt16 phyStatusPrev; ! 117: bool linkStatusPrev; ! 118: ! 119: queue_head_t txActiveQueue; ! 120: queue_head_t txFreeQueue; ! 121: ! 122: TxQueueElement *txElementPtrs[TX_RING_LENGTH]; ! 123: struct mbuf *rxMbuf[RX_RING_LENGTH]; ! 124: struct mbuf *txDebuggerPkt; ! 125: ! 126: void * debuggerPkt; ! 127: u_int32_t debuggerPktSize; ! 128: ! 129: UInt32 txCommandHead; /* Transmit ring descriptor index */ ! 130: UInt32 txCommandTail; ! 131: UInt32 txMaxCommand; ! 132: UInt32 rxCommandHead; /* Receive ring descriptor index */ ! 133: UInt32 rxCommandTail; ! 134: UInt32 rxMaxCommand; ! 135: ! 136: UInt32 dmaCommandsSize; ! 137: UInt8 *dmaCommands; ! 138: enet_txdma_cmd_t *txDMACommands; /* TX descriptor ring ptr */ ! 139: UInt32 txDMACommandsPhys; ! 140: UInt32 txCommandsAvail; ! 141: ! 142: enet_dma_cmd_t *rxDMACommands; /* RX descriptor ring ptr */ ! 143: UInt32 rxDMACommandsPhys; ! 144: ! 145: UInt32 txRingIndexLast; ! 146: UInt32 txWDInterrupts; ! 147: UInt32 txWDCount; ! 148: ! 149: UInt16 hashTableUseCount[256]; ! 150: UInt16 hashTableMask[16]; ! 151: ! 152: ! 153: bool allocateMemory(); ! 154: bool initTxRing(); ! 155: bool initRxRing(); ! 156: bool initChip(); ! 157: bool resetChip(); ! 158: void disableAdapterInterrupts(); ! 159: void enableAdapterInterrupts(); ! 160: void setDuplexMode(bool duplexMode); ! 161: void startChip(); ! 162: void stopChip(); ! 163: bool updateDescriptorFromMbuf(struct mbuf * m, enet_dma_cmd_t *desc, bool isReceive); ! 164: void monitorLinkStatus(); ! 165: void restartTransmitter(); ! 166: void stopTransmitDMA(); ! 167: bool transmitPacket(struct mbuf * packet); ! 168: bool transmitInterruptOccurred(); ! 169: bool debugTransmitInterruptOccurred(); ! 170: void debugTransmitCleanup(); ! 171: bool receiveInterruptOccurred(); ! 172: bool receivePackets(bool fDebugger); ! 173: void packetToDebugger(struct mbuf * packet, u_int size); ! 174: void restartReceiver(); ! 175: void stopReceiveDMA(); ! 176: bool resetAndEnable(bool enable); ! 177: void sendDummyPacket(); ! 178: void resetHashTableMask(); ! 179: void addToHashTableMask(u_int8_t *addr); ! 180: void removeFromHashTableMask(u_int8_t *addr); ! 181: void updateHashTableMask(); ! 182: ! 183: ! 184: TxQueueElement *getTxElement(); ! 185: void releaseTxElement(TxQueueElement *txElement); ! 186: ! 187: #ifdef DEBUG ! 188: void dumpRegisters(); ! 189: #endif DEBUG ! 190: ! 191: void sendPacket(void *pkt, unsigned int pkt_len); ! 192: void receivePacket(void *pkt, unsigned int *pkt_len, unsigned int timeout); ! 193: ! 194: bool miiReadWord(unsigned short *dataPtr, unsigned short reg, UInt8 phy); ! 195: bool miiWriteWord(unsigned short data, unsigned short reg, UInt8 phy); ! 196: void miiWrite(UInt32 miiData, UInt32 dataSize); ! 197: bool miiResetPHY(UInt8 phy); ! 198: bool miiWaitForLink(UInt8 phy); ! 199: bool miiWaitForAutoNegotiation(UInt8 phy); ! 200: void miiRestartAutoNegotiation(UInt8 phy); ! 201: bool miiFindPHY(UInt8 *phy_num); ! 202: bool miiInitializePHY(UInt8 phy); ! 203: ! 204: UInt32 outputPacket(struct mbuf *m); ! 205: ! 206: void interruptOccurred(IOInterruptEventSource *src, int count); ! 207: void timeoutOccurred(IOTimerEventSource *timer); ! 208: ! 209: public: ! 210: virtual bool init(OSDictionary * properties = 0); ! 211: virtual bool start(IOService * provider); ! 212: virtual void free(); ! 213: ! 214: virtual IOReturn enable(IONetworkInterface * netif); ! 215: virtual IOReturn disable(IONetworkInterface * netif); ! 216: ! 217: virtual IOReturn getHardwareAddress(enet_addr_t *addr); ! 218: ! 219: virtual IOReturn setMulticastMode(IOEnetMulticastMode mode); ! 220: virtual IOReturn setMulticastList(enet_addr_t *addrs, UInt count); ! 221: ! 222: virtual IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode); ! 223: ! 224: virtual IOOutputQueue *allocateOutputQueue(); ! 225: ! 226: virtual const char *getVendorString() const; ! 227: virtual const char *getModelString() const; ! 228: virtual const char *getRevisionString() const; ! 229: ! 230: virtual IOReturn handleDebuggerOpen(IOKernelDebugger * debugger); ! 231: virtual IOReturn handleDebuggerClose(IOKernelDebugger * debugger); ! 232: ! 233: #if 1 ! 234: bool configureNetworkInterface(IONetworkInterface * netif); ! 235: #endif ! 236: }; ! 237: ! 238: ! 239: /* ! 240: * Performance tracepoints ! 241: * ! 242: * DBG_UniN_RXIRQ - Receive ISR run time ! 243: * DBG_UniN_TXIRQ - Transmit ISR run time ! 244: * DBG_UniN_TXQUEUE - Transmit packet passed from network stack ! 245: * DBG_UniN_TXCOMPLETE - Transmit packet sent ! 246: * DBG_UniN_RXCOMPLETE - Receive packet passed to network stack ! 247: */ ! 248: #define DBG_UniN_ENET 0x0900 ! 249: #define DBG_UniN_RXIRQ DRVDBG_CODE(DBG_DRVNETWORK,(DBG_UniN_ENET+1)) ! 250: #define DBG_UniN_TXIRQ DRVDBG_CODE(DBG_DRVNETWORK,(DBG_UniN_ENET+2)) ! 251: #define DBG_UniN_TXQUEUE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_UniN_ENET+3)) ! 252: #define DBG_UniN_TXCOMPLETE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_UniN_ENET+4)) ! 253: #define DBG_UniN_RXCOMPLETE DRVDBG_CODE(DBG_DRVNETWORK,(DBG_UniN_ENET+5))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.