1/* 2 * 3 * @APPLE_LICENSE_HEADER_START@ 4 * 5 * Copyright (c) 1998-2003 Apple Computer, Inc. All Rights Reserved. 6 * 7 * This file contains Original Code and/or Modifications of Original Code 8 * as defined in and that are subject to the Apple Public Source License 9 * Version 2.0 (the 'License'). You may not use this file except in 10 * compliance with the License. Please obtain a copy of the License at 11 * http://www.opensource.apple.com/apsl/ and read it before using this 12 * file. 13 * 14 * The Original Code and all software distributed under the License are 15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 * Please see the License for the specific language governing rights and 20 * limitations under the License. 21 * 22 * @APPLE_LICENSE_HEADER_END@ 23 */ 24 25#ifndef __APPLEUSBCDCECMData__ 26#define __APPLEUSBCDCECMData__ 27 28#include "AppleUSBCDCCommon.h" 29#include "AppleUSBCDC.h" 30#include "AppleUSBCDCECMControl.h" 31 32#define TRANSMIT_QUEUE_SIZE PAGE_SIZE 33#define WATCHDOG_TIMER_MS 1000 34 35#define MAX_BLOCK_SIZE PAGE_SIZE 36#define COMM_BUFF_SIZE 16 37 38#define nameLength 32 // Arbitrary length 39#define defaultName "USB Ethernet" 40 41#define kFiltersSupportedMask 0xefff 42#define kPipeStalled 1 43 44 // Default and Maximum buffer pool values 45 46#define kInBufPool 4 47#define kOutBufPool 8 48 49#define kMaxInBufPool kInBufPool*16 50#define kMaxOutBufPool kOutBufPool*16 51 52#define inputTag "InputBuffers" 53#define outputTag "OutputBuffers" 54 55typedef struct 56{ 57 IOBufferMemoryDescriptor *pipeOutMDP; 58 UInt8 *pipeOutBuffer; 59 mbuf_t m; 60 bool avail; 61 IOUSBCompletion writeCompletionInfo; 62 UInt32 indx; 63} pipeOutBuffers; 64 65typedef struct 66{ 67 IOBufferMemoryDescriptor *pipeInMDP; 68 UInt8 *pipeInBuffer; 69 bool dead; 70 IOUSBCompletion readCompletionInfo; 71 UInt32 indx; 72} pipeInBuffers; 73 74class AppleUSBCDC; 75class AppleUSBCDCECMControl; 76 77class AppleUSBCDCECMData : public IOEthernetController 78{ 79 OSDeclareDefaultStructors(AppleUSBCDCECMData); // Constructor & Destructor stuff 80 81private: 82 bool fTerminate; // Are we being terminated (ie the device was unplugged) 83 UInt16 fVendorID; 84 UInt16 fProductID; 85 86 IOEthernetInterface *fNetworkInterface; 87 IOGatedOutputQueue *fTransmitQueue; 88 89 IOTimerEventSource *fTimerSource; 90 91 OSDictionary *fMediumDict; 92 93 bool fNetifEnabled; 94 bool fWOL; 95 UInt64 fUpSpeed; 96 UInt64 fDownSpeed; 97 bool fSleeping; 98 99 IOUSBPipe *fInPipe; 100 IOUSBPipe *fOutPipe; 101 102 pipeInBuffers fPipeInBuff[kMaxInBufPool]; 103 pipeOutBuffers fPipeOutBuff[kMaxOutBufPool]; 104 UInt16 fOutPoolIndex; 105 106 UInt8 fCommInterfaceNumber; 107 UInt32 fCount; 108 UInt32 fOutPacketSize; 109 110 bool fDeferredClear; 111 112 static void dataReadComplete(void *obj, void *param, IOReturn ior, UInt32 remaining); 113 static void dataWriteComplete(void *obj, void *param, IOReturn ior, UInt32 remaining); 114 115 // CDC Driver instance Methods 116 117 bool configureData(void); 118 bool wakeUp(void); 119 void putToSleep(void); 120 bool createMediumTables(void); 121 bool allocateResources(void); 122 void releaseResources(void); 123 bool createNetworkInterface(void); 124 UInt32 outputPacket(mbuf_t pkt, void *param); 125 bool getOutputBuffer(UInt32 *bufIndx); 126 IOReturn USBTransmitPacket(mbuf_t packet); 127 IOReturn clearPipeStall(IOUSBPipe *thePipe); 128 void receivePacket(UInt8 *packet, UInt32 size); 129 void setLinkStatusUp(void); 130 void setLinkStatusDown(void); 131 static void timerFired(OSObject *owner, IOTimerEventSource *sender); 132 void timeoutOccurred(IOTimerEventSource *timer); 133 134public: 135 136#if LOG_DATA 137 virtual void USBLogData(UInt8 Dir, SInt32 Count, char *buf); 138 virtual void dumpData(char *buf, SInt32 size); 139#endif 140 141 AppleUSBCDCECMControl *fControlDriver; // Our Control driver 142 IOUSBInterface *fDataInterface; 143 IOWorkLoop *fWorkLoop; 144 UInt8 fDataInterfaceNumber; 145 UInt16 fAltInterface; 146 147 UInt16 fInBufPool; 148 UInt16 fOutBufPool; 149 150 UInt8 fConfigAttributes; 151 UInt8 fEthernetaddr[6]; 152 153 UInt8 fLinkStatus; 154 155 bool fReady; 156 UInt8 fResetState; 157 bool fQueueStarted; 158 bool fTxStalled; 159 bool fEnumOnWake; // Do we need to re-enumerate on wake 160 161 IONetworkStats *fpNetStats; 162 IOEthernetStats *fpEtherStats; 163 164 // CDC Driver instance Methods 165 166 virtual void linkStatusChange(UInt8 linkState); 167 virtual void linkSpeedChange(UInt32 upSpeed, UInt32 downSpeed); 168 169 // IOKit methods 170 171 virtual bool init(OSDictionary *properties = 0); 172 virtual IOService *probe(IOService *provider, SInt32 *score); 173 virtual bool start(IOService *provider); 174 virtual void stop(IOService *provider); 175 virtual bool willTerminate( IOService * provider, IOOptionBits options ); 176 virtual IOReturn message(UInt32 type, IOService *provider, void *argument = 0); 177 178 // IOEthernetController methods 179 180 virtual IOReturn enable(IONetworkInterface *netif); 181 virtual IOReturn disable(IONetworkInterface *netif); 182 virtual IOReturn setWakeOnMagicPacket(bool active); 183 virtual IOReturn getPacketFilters(const OSSymbol *group, UInt32 *filters ) const; 184 virtual IOReturn selectMedium(const IONetworkMedium *medium); 185 virtual IOReturn getHardwareAddress(IOEthernetAddress *addr); 186 virtual IOReturn getMaxPacketSize(UInt32 *maxSize) const; 187 virtual IOReturn setMulticastMode(IOEnetMulticastMode mode); 188 virtual IOReturn setMulticastList(IOEthernetAddress *addrs, UInt32 count); 189 virtual IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode); 190 virtual IOOutputQueue *createOutputQueue(void); 191 virtual const OSString *newVendorString(void) const; 192 virtual const OSString *newModelString(void) const; 193 virtual const OSString *newRevisionString(void) const; 194 virtual bool configureInterface(IONetworkInterface *netif); 195 virtual IOReturn registerWithPolicyMaker(IOService *policyMaker); 196 197}; /* end class AppleUSBCDCECMData */ 198#endif