home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.sustworks.com 2018
/
ftp.sustworks.com.zip
/
ftp.sustworks.com
/
USBAx8817x_101.dmg
/
src
/
Source
/
USBAx8817x.h
< prev
next >
Wrap
C/C++ Source or Header
|
2005-10-08
|
14KB
|
385 lines
/*
File: USBAx8817x.h
Description: Driver for USBAx8817 USB-To-Ethernet devices
Copyright: Copyright 2005, Daniel Sumorok and Peter Sichel
Disclaimer: This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General
along with this program; if not, write to the Free
Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. Change History (least
recent first):
Change History (most recent first):
<1> 03/25/05 USBPegasusEthernet source
*/
/*
* Copyright (c) 1997, 1998, 1999, 2000-2003
* Bill Paul <wpaul@windriver.com>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Bill Paul.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
*/
#include <libkern/OSByteOrder.h>
#include <IOKit/network/IOEthernetController.h>
#include <IOKit/network/IOEthernetInterface.h>
#include <IOKit/network/IONetworkInterface.h>
//#include <IOKit/network/IOBasicOutputQueue.h>
#include <IOKit/network/IOOutputQueue.h>
#include "AxOutputQueue.h"
#include <IOKit/network/IOBasicOutputQueue.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/assert.h>
#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>
#include <IOKit/IOBufferMemoryDescriptor.h>
#include <IOKit/IOMessage.h>
#include <IOKit/pwr_mgt/RootDomain.h>
#include <IOKit/usb/IOUSBBus.h>
#include <IOKit/usb/IOUSBNub.h>
#include <IOKit/usb/IOUSBDevice.h>
#include <IOKit/usb/IOUSBPipe.h>
#include <IOKit/usb/USB.h>
#include <IOKit/usb/IOUSBInterface.h>
#include <UserNotification/KUNCUserNotifications.h>
extern "C" {
#include <sys/param.h>
#if TIGER
#include <sys/kpi_mbuf.h>
#else
//#include <sys/mbuf.h>
#include "mbufPanther.h"
#endif
}
/* The following code definitions were taken from the bsd source file:
if_axereg.h
*/
//#define BUFSIZE 1536
#define BUFSIZE 2048
#define AXE_CMD_DIR(x) (((x) & 0x0F00) >> 8)
#define AXE_CMD_LEN(x) (((x) & 0xF000) >> 12)
#define AXE_CMD_CMD(x) ((x) & 0x00FF)
#define ONE_TX_AT_A_TIME 0
#define TRANSMIT_QUEUE_SIZE 256
#define TX_RING_SIZE 24
#define TX_QUEUE_RESTART 16
#define NUM_RX_BUFFERS 24
#define RXTHREAD_STOP (1 << 0)
#define RXTHREAD_STOPPED (1 << 1)
#define RXTHREAD_RESET (1 << 2)
#define RXTHREAD_CLOSE (1 << 3)
#define RXTHREAD_OPEN (1 << 4)
#define RXTHREAD_READSTALLED (1 << 5)
#define RXTHREAD_WRITESTALLED (1 << 6)
#define RXTHREAD_INTRSTALLED (1 << 7)
#define RXTHREAD_CTRLSTALLED (1 << 8)
enum {
kUSBEthernetOffState = 0,
kUSBEthernetOnState = 1,
kNumPowerStates = 2
};
typedef enum ctrlEventTag {
ctrlEventServiceQueue,
ctrlEventStart,
ctrlEventTimer,
ctrlEventChekcLink,
ctrlEventCallback,
ctrlEventEnable,
ctrlEventDisable,
ctrlEventTxDone,
ctrlEventTransmit,
ctrlEventNudge,
ctrlEventSetMulticast,
ctrlEventSuspend,
ctrlEventResume,
ctrlEventTerminate,
ctrlEventLinkUp,
ctrlEventLinkDown,
ctrlEventWriteStalled,
ctrlEventClearedWriteStall
} ctrlEvent_t;
typedef enum miiStateTag {
miiStateIdle,
miiStateRead,
miiStateFinish1,
miiStateFinish2,
miiStateWrite,
} miiState_t;
typedef enum ctrlStateTag {
ctrlStateIdle,
ctrlStateLinkStatus,
ctrlStateSetMedium,
ctrlStateCheckGiga,
ctrlStateAutoDone1,
ctrlStateAutoDone2,
ctrlStateDisable,
ctrlStateWaitEth,
ctrlStateWaitMii,
ctrlStateSuspend,
ctrlStateClearWriteStall
} ctrlState_t;
typedef struct ax8817xCompletion {
IOUSBCompletion *completion;
IOBufferMemoryDescriptor *mdp;
struct ax8817xCompletion *next;
int flags;
UInt32 packetLength;
} ax8817xCompletion_t;
typedef struct ax8817xTxRing {
IOBufferMemoryDescriptor *mdp;
UInt8 *buffer;
IOUSBCompletion writeCompletionInfo;
IOUSBCompletion writeZeroCompletionInfo;
mbuf_t packet;
struct ax8817xTxRing *next;
int flags;
} ax8817xTxRing_t;
class USBAx8817x : public IOEthernetController {
// Constructor & Destructor stuff
OSDeclareDefaultStructors(USBAx8817x);
private:
IOUSBDevice *fpDevice;
mbuf_t txPkt;
//IOBasicOutputQueue *fTransmitQueue;
IOWorkLoop *fWorkLoop;
IOTimerEventSource *fTimerSource;
bool fMulticastEnable;
char vendorStr[32];
char modelStr[32];
char revisionStr[32];
IOUSBInterface *fDataInterface;
IOUSBPipe *fCntlPipe;
IOUSBPipe *fInterruptPipe;
IOBufferMemoryDescriptor *fPipeInterruptMDP;
IOBufferMemoryDescriptor *fPipeCtrlMDP;
IOBufferMemoryDescriptor *rxMDPList[NUM_RX_BUFFERS];
ax8817xTxRing_t txRing[TX_RING_SIZE];
ax8817xCompletion_t *rxRing;
ax8817xTxRing_t *txProducePtr;
ax8817xCompletion_t readComp[NUM_RX_BUFFERS];
UInt8 *fInterruptPipeBuffer;
IOUSBCompletion fCtrlCompletionInfo;
IOUSBCompletion fReadCompletionInfo[NUM_RX_BUFFERS];
IOUSBCompletion fInterruptCompletionInfo;
IOUSBDevRequestDesc fCtrlRead;
IOUSBDevRequestDesc fCtrlWrite;
IOEthernetStats *fpEtherStats;
bool txQueueStopped;
bool readActive;
ctrlState_t cState;
bool rcvdLinkStatus;
bool interruptPending;
bool readingInterrupt;
UInt8 ethCtrl0Val;
UInt8 ethCtrl1Val;
UInt8 ethCtrl2Val;
int txDone;
UInt32 linkSpeed;
UInt32 gpioBits;
IOLock *txQueueLock;
IOLock *txLock;
IOThread rxThread;
int txSpots;
thread_call_t powerDownThread, powerUpThread;
unsigned long currentPowerState;
int debugFlags;
int txInProgress;
bool fNetifRequestEnabled;
bool timerPending;
int mcBytesToWrite;
int setMc;
int pktQueueLen;
bool suspendPending;
bool resumePending;
bool ackPowerPending;
UInt32 selectedMedium;
UInt32 requestedMedium;
bool awake;
bool fLinkUp;
bool callbackPending;
bool checkLinkPending;
bool writePipeStalled;
bool writeStallCleared;
int recursionLevel;
miiState_t miiState;
UInt8 miiIndx;
UInt16 miiData;
ax8817xTxRing_t *txConsumePtr;
bool fTerminate;
AxOutputQueue *fTransmitQueue;
UInt8 *fCtrlPipeBuffer;
bool miiPending;
UInt8 mHashTable[8];
IOService *ourPolicyMaker;
bool started;
int promiscMode;
int promiscRequest;
OSDictionary *fMediumDict;
bool fNetifEnabled;
IOUSBPipe *fOutPipe;
// Static Methods
static void dataReadComplete(void *obj, void *param, IOReturn ior,
UInt32 remaining);
static void dataWriteComplete(void *obj, void *param, IOReturn ior,
UInt32 remaining);
static void dataWriteZeroComplete(void *obj, void *param, IOReturn ior,
UInt32 remaining);
static void ctrlComplete(void *obj, void *param, IOReturn rc,
UInt32 remaining);
static void interruptComplete(void *obj, void *param, IOReturn rc,
UInt32 remaining);
static IOReturn postEvent(OSObject *target, void *evt,
void *result = (void *)kIOReturnSuccess,
void *gotLock = (void *)false,
void *arg3 = NULL);
static void handleSetPowerStateOff( thread_call_param_t param0,
thread_call_param_t param1 );
static void handleSetPowerStateOn( thread_call_param_t param0,
thread_call_param_t param1 );
static void timerFired(OSObject *owner, IOTimerEventSource *sender);
static void rxThreadEntry(void *ob);
// Driver instance Methods
// Misc. Driver methods
UInt32 outputPacket(mbuf_t pkt, void *param);
void rxLoop();
bool handleRxThreadCmd();
void cleanUp();
protected:
IOEthernetInterface *fNetworkInterface;
IONetworkStats *fpNetStats;
IOUSBPipe *fInPipe;
UInt16 mediumStatus;
IOLock *rxQueueLock;
bool supports1000BaseT;
UInt8 fEaddr[6];
int phy;
UInt16 deviceFlag;
UInt16 maxPacketSize;
UInt32 readThreadCmd;
UInt16 rxCtrlVal;
virtual void setState(ctrlEvent_t event);
virtual int copyPktToBuffer(mbuf_t mbuf, UInt8 *buf, int len);
virtual void receivePacket(UInt32 remaining,
IOBufferMemoryDescriptor *inMDP,
IOUSBCompletion *completion);
// Device Control
bool axCmd(UInt16 cmd, UInt16 index, UInt16 val, void *buf);
IOReturn axCmdAsync(UInt16 cmd, UInt16 index, UInt16 val);
virtual bool readMiiWord(UInt8 phyIn, UInt8 indx, UInt16 *regd);
virtual bool writeMiiWord(UInt8 phyIn, UInt8 indx, UInt16 regd);
virtual IOReturn readMiiWordAsync(UInt8 indx);
virtual IOReturn writeMiiWordAsync(UInt8 indx, UInt16 data);
virtual void setMediumStatus(UInt32 selectedMedium);
// Initialization
virtual bool openUSB(IOService *provider);
virtual bool allocateBuffers(void);
virtual bool resetMAC(void);
virtual bool createNetworkInterface(void);
virtual bool createMediumTables(void);
virtual bool startIO(void);
virtual IONetworkInterface *createInterface(void);
virtual IOReturn registerWithPolicyMaker(IOService *policyMaker);
public:
// IOKit methods
virtual bool init(OSDictionary *properties = 0);
virtual bool start(IOService *provider);
virtual void stop(IOService *provider);
virtual bool willTerminate(IOService *provider,
IOOptionBits options );
virtual bool configureInterface(IONetworkInterface
*netif);
virtual IOService * probe(IOService *provider, SInt32 *score );
virtual IOReturn setPowerState(unsigned long powerStateOrdinal,
IOService *whatDevice);
// IOEthernetController methods
virtual IOReturn enable(IONetworkInterface *netif);
virtual IOReturn disable(IONetworkInterface *netif);
virtual IOReturn getPacketFilters(const OSSymbol *group,
UInt32 *filters ) const;
virtual IOReturn selectMedium(const IONetworkMedium *medium);
virtual IOReturn getHardwareAddress(IOEthernetAddress *addr);
virtual IOReturn setMulticastMode(IOEnetMulticastMode mode);
virtual IOReturn setMulticastList(IOEthernetAddress *addrs,
UInt32 count);
virtual IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode);
virtual IOOutputQueue *createOutputQueue(void);
virtual const OSString *newVendorString(void) const;
virtual const OSString *newModelString(void) const;
virtual const OSString *newRevisionString(void) const;
}; /* end class USBAx8817x */