#ifndef _IOKIT_IOFWCOMMAND_H
#define _IOKIT_IOFWCOMMAND_H
#include <IOKit/IOCommand.h>
#include <IOKit/IOLib.h>
#include <IOKit/firewire/IOFireWireFamilyCommon.h>
#include <IOKit/firewire/IOFWSyncer.h>
#define kFWCmdDefaultRetries 3
#define kFWCmdZeroRetries 0
#define kFWCmdReducedRetries 2
#define kFWCmdIncreasedRetries 6
class IOMemoryDescriptor;
class IOSyncer;
class IOFireWireBus;
class IOFireWireController;
class IOFireWireNub;
class IOFWAddressSpace; class IOFWCommand;
class IOFWBusCommand;
class IOFWAsyncStreamCommand;
class IOCommandGate;
class IOFWAsyncPHYCommand;
struct AsyncPendingTrans;
struct IOFWCmdQ
{
IOFWCommand *fHead;
IOFWCommand *fTail;
bool executeQueue(bool all);
virtual void headChanged(IOFWCommand *oldHead);
virtual ~IOFWCmdQ() {}
void checkProgress( void );
};
typedef void (*FWDeviceCallback)(void *refcon, IOReturn status, IOFireWireNub *device, IOFWCommand *fwCmd);
typedef void (*FWBusCallback)(void *refcon, IOReturn status, IOFireWireBus *bus, IOFWBusCommand *fwCmd);
typedef void (*FWAsyncStreamCallback)(void *refcon, IOReturn status, IOFireWireBus *bus, IOFWAsyncStreamCommand *fwCmd);
typedef void (*FWAsyncPHYCallback)(void *refcon, IOReturn status, IOFireWireBus *bus, IOFWAsyncPHYCommand *fwCmd );
typedef void (*FWAsyncStreamReceiveCallback)(void *refcon, const void *buf);
#pragma mark -
class IOFWCommand : public IOCommand
{
OSDeclareAbstractStructors(IOFWCommand)
protected:
IOReturn fStatus;
IOFireWireController *fControl;
IOFWCommand * fQueuePrev;
IOFWCommand * fQueueNext;
IOFWCmdQ * fQueue;
UInt32 fTimeout; AbsoluteTime fDeadline; IOFWSyncer * fSyncWakeup;
UInt8 fSync;
UInt8 fCancelOnReset;
UInt8 spare[2];
struct MemberVariables
{
void * fFWIMRefCon;
IOReturn fCompletionStatus;
bool fSubmitTimeLatched;
AbsoluteTime fSubmitTime;
bool fFlush;
};
MemberVariables * fMembers;
virtual IOReturn complete(IOReturn status);
virtual void updateTimer();
virtual IOReturn startExecution();
virtual IOReturn execute() = 0;
public:
virtual bool initWithController(IOFireWireController *control);
virtual void free( void );
IOReturn getStatus() const { return fStatus; };
virtual IOReturn submit(bool queue = false);
virtual IOReturn cancel(IOReturn reason);
virtual void setHead(IOFWCmdQ &queue);
virtual void insertAfter(IOFWCommand &prev);
virtual void removeFromQ();
IOFWCommand *getPrevious() const
{ return fQueuePrev; };
IOFWCommand *getNext() const
{ return fQueueNext; };
const AbsoluteTime &getDeadline() const
{ return fDeadline; };
bool cancelOnReset() const
{ return fCancelOnReset; };
bool Busy() const
{ return fStatus == kIOReturnBusy || fStatus == kIOFireWirePending;};
void setTimeout( UInt32 timeout )
{ fTimeout = timeout; };
friend class IOFWCmdQ;
void * getFWIMRefCon( void )
{
return fMembers->fFWIMRefCon;
}
void setFWIMRefCon( void * refcon )
{
fMembers->fFWIMRefCon = refcon;
}
void setFlush( bool flush )
{
fMembers->fFlush = flush;
}
virtual IOReturn checkProgress( void );
private:
OSMetaClassDeclareReservedUsed(IOFWCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWCommand, 1);
};
#pragma mark -
class IOFWBusCommand : public IOFWCommand
{
OSDeclareAbstractStructors(IOFWBusCommand)
protected:
FWBusCallback fComplete;
void * fRefCon;
struct ExpansionData { };
ExpansionData *reserved;
virtual IOReturn complete(IOReturn status);
virtual bool initWithController(IOFireWireController *control,
FWBusCallback completion=NULL, void *refcon=NULL);
virtual IOReturn reinit(FWBusCallback completion, void *refcon);
private:
OSMetaClassDeclareReservedUnused(IOFWBusCommand, 0);
};
#pragma mark -
class IOFWDelayCommand : public IOFWBusCommand
{
OSDeclareDefaultStructors(IOFWDelayCommand)
struct ExpansionData { };
ExpansionData *reserved;
protected:
virtual IOReturn execute();
public:
virtual bool initWithDelay(IOFireWireController *control, UInt32 uSecs,
FWBusCallback completion, void *refcon);
virtual IOReturn reinit(UInt32 uSecs, FWBusCallback completion, void *refcon);
private:
OSMetaClassDeclareReservedUnused(IOFWDelayCommand, 0);
};
class IOFWUserReadQuadletCommand ;
class IOFWUserWriteCommand ;
#pragma mark -
class IOFWAsyncCommand : public IOFWCommand
{
OSDeclareAbstractStructors(IOFWAsyncCommand)
protected:
IOFireWireNub * fDevice;
FWDeviceCallback fComplete;
void * fRefCon;
IOMemoryDescriptor *fMemDesc;
AsyncPendingTrans * fTrans;
UInt32 fAddressHi;
UInt32 fAddressLo;
IOByteCount fBytesTransferred;
int fSize;
int fSpeed;
int fMaxPack;
int fCurRetries;
int fMaxRetries;
UInt32 fGeneration; UInt16 fNodeID;
bool fFailOnReset;
bool fWrite;
typedef struct
{
void * fSubclassMembers;
int fMaxSpeed;
int fAckCode;
UInt32 fResponseCode;
UInt32 fFastRetryCount;
int fResponseSpeed;
bool fForceBlockRequests;
}
MemberVariables;
MemberVariables * fMembers;
virtual IOReturn complete(IOReturn status);
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon);
virtual void free( void );
virtual IOReturn reinit(FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon);
bool createMemberVariables( void );
void destroyMemberVariables( void );
public:
virtual void setGeneration(UInt32 generation)
{ fGeneration = generation; }
virtual void gotPacket(int rcode, const void* data, int size) = 0;
virtual void gotAck(int ackCode);
IOReturn updateGeneration();
IOReturn updateNodeID(UInt32 generation, UInt16 nodeID);
IOByteCount getBytesTransferred() const
{ return fBytesTransferred; };
FWAddress getAddress() const
{ return FWAddress(fAddressHi, fAddressLo, fNodeID); }
bool failOnReset() const
{ return fFailOnReset; }
IOFireWireNub * getDevice() const
{ return fDevice; }
IOReturn setMaxPacket(UInt32 maxBytes)
{
if(fStatus == kIOReturnBusy || fStatus == kIOFireWirePending)
return fStatus;
fMaxPack = maxBytes;
return kIOReturnSuccess;
}
void setMaxSpeed( int speed );
void setAckCode( int ack );
int getAckCode( void );
void setRetries( int retries);
int getMaxRetries( void );
void setResponseCode( UInt32 rcode );
UInt32 getResponseCode( void ) const;
void setFastRetryCount( UInt32 count )
{ fMembers->fFastRetryCount = count; };
UInt32 getFastRetryCount( void )
{ return fMembers->fFastRetryCount; };
void setResponseSpeed( int speed )
{ fMembers->fResponseSpeed = speed; };
int getResponseSpeed( void )
{ return fMembers->fResponseSpeed; };
void setForceBlockRequests( bool enabled )
{ fMembers->fForceBlockRequests = enabled; }
virtual IOReturn checkProgress( void );
private:
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 1);
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 2);
OSMetaClassDeclareReservedUnused(IOFWAsyncCommand, 3);
};
#pragma mark -
class IOFWReadCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWReadCommand)
protected:
virtual void gotPacket(int rcode, const void* data, int size);
virtual IOReturn execute();
public:
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
IOMemoryDescriptor *hostMem,
FWDeviceCallback completion, void *refcon);
virtual IOReturn reinit(FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion=NULL, void *refcon=NULL,
bool failOnReset=false);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress, IOMemoryDescriptor *hostMem,
FWDeviceCallback completion=NULL, void *refcon=NULL);
private:
OSMetaClassDeclareReservedUnused(IOFWReadCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWReadCommand, 1);
};
#pragma mark -
class IOFWReadQuadCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWReadQuadCommand)
protected:
UInt32 * fQuads;
typedef struct
{
bool fPingTime;
}
MemberVariables;
bool createMemberVariables( void );
void destroyMemberVariables( void );
virtual void free( void );
virtual void gotPacket(int rcode, const void* data, int size);
virtual IOReturn execute();
public:
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
UInt32 *quads, int numQuads,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
UInt32 *quads, int numQuads,
FWDeviceCallback completion, void *refcon);
virtual IOReturn reinit(FWAddress devAddress, UInt32 *quads, int numQuads,
FWDeviceCallback completion=NULL, void *refcon=NULL,
bool failOnReset=false);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress, UInt32 *quads, int numQuads,
FWDeviceCallback completion=NULL, void *refcon=NULL);
void setPingTime( bool state )
{ ((MemberVariables*)fMembers->fSubclassMembers)->fPingTime = state; };
private:
OSMetaClassDeclareReservedUnused(IOFWReadQuadCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWReadQuadCommand, 1);
};
#pragma mark -
class IOFWWriteCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWWriteCommand)
protected:
int fPackSize;
typedef struct
{
bool fDeferredNotify;
bool fFastRetryOnBusy;
}
MemberVariables;
virtual IOReturn execute();
virtual void gotPacket( int rcode, const void* data, int size );
bool createMemberVariables( void );
void destroyMemberVariables( void );
public:
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll( IOFireWireNub * device,
FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion,
void * refcon,
bool failOnReset );
virtual bool initAll( IOFireWireController * control,
UInt32 generation,
FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion,
void * refcon );
virtual void free( void );
virtual IOReturn reinit( FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion = NULL,
void * refcon = NULL,
bool failOnReset = false );
virtual IOReturn reinit( UInt32 generation,
FWAddress devAddress,
IOMemoryDescriptor * hostMem,
FWDeviceCallback completion = NULL,
void * refcon = NULL );
void setDeferredNotify( bool state )
{ ((MemberVariables*)fMembers->fSubclassMembers)->fDeferredNotify = state; };
void setFastRetryOnBusy( bool state )
{ ((MemberVariables*)fMembers->fSubclassMembers)->fFastRetryOnBusy = state; };
private:
OSMetaClassDeclareReservedUnused(IOFWWriteCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWWriteCommand, 1);
};
#pragma mark -
class IOFWWriteQuadCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWWriteQuadCommand)
public:
enum
{
kMaxWriteQuads = 8
};
protected:
UInt32 fQuads[kMaxWriteQuads];
UInt32 * fQPtr;
int fPackSize;
typedef struct
{
bool fDeferredNotify;
IOMemoryDescriptor * fMemory;
}
MemberVariables;
virtual void gotPacket( int rcode, const void* data, int size );
virtual IOReturn execute();
bool createMemberVariables( void );
void destroyMemberVariables( void );
public:
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll( IOFireWireNub * device,
FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion,
void * refcon,
bool failOnReset );
virtual bool initAll( IOFireWireController * control,
UInt32 generation,
FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion,
void * refcon );
virtual void free( void );
virtual IOReturn reinit( FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion = NULL,
void * refcon = NULL,
bool failOnReset = false );
virtual IOReturn reinit( UInt32 generation,
FWAddress devAddress,
UInt32 * quads,
int numQuads,
FWDeviceCallback completion = NULL,
void * refcon = NULL );
protected:
void setQuads( UInt32 * quads, int numQuads );
bool createMemoryDescriptor( void );
void destroyMemoryDescriptor( void );
public:
void setDeferredNotify( bool state )
{ ((MemberVariables*)fMembers->fSubclassMembers)->fDeferredNotify = state; };
private:
OSMetaClassDeclareReservedUnused(IOFWWriteQuadCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWWriteQuadCommand, 1);
};
#pragma mark -
class IOFWCompareAndSwapCommand : public IOFWAsyncCommand
{
OSDeclareDefaultStructors(IOFWCompareAndSwapCommand)
protected:
UInt32 fInputVals[4];
UInt32 fOldVal[2];
typedef struct
{
IOMemoryDescriptor * fMemory;
}
MemberVariables;
MemberVariables * fMembers;
virtual void gotPacket(int rcode, const void* data, int size);
virtual IOReturn execute();
public:
virtual bool initWithController(IOFireWireController *control);
virtual bool initAll(IOFireWireNub *device, FWAddress devAddress,
const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion, void *refcon, bool failOnReset);
virtual bool initAll(IOFireWireController *control,
UInt32 generation, FWAddress devAddress,
const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion, void *refcon);
virtual IOReturn reinit(FWAddress devAddress, const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion=NULL, void *refcon=NULL, bool failOnReset=false);
virtual IOReturn reinit(UInt32 generation, FWAddress devAddress,
const UInt32 *cmpVal, const UInt32 *newVal, int size,
FWDeviceCallback completion=NULL, void *refcon=NULL);
virtual bool locked(UInt32 *oldVal);
virtual void free( void );
protected:
bool createMemberVariables( void );
void destroyMemberVariables( void );
void setInputVals( const UInt32 * cmpVal, const UInt32 * newVal, int size );
bool createMemoryDescriptor( void );
void destroyMemoryDescriptor( void );
private:
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 1);
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 2);
OSMetaClassDeclareReservedUnused(IOFWCompareAndSwapCommand, 3);
};
#pragma mark -
class IOFWAsyncStreamCommand : public IOFWCommand
{
friend class IOFireWireUserClient ;
OSDeclareDefaultStructors(IOFWAsyncStreamCommand)
protected:
FWAsyncStreamCallback fComplete;
void * fRefCon;
IOMemoryDescriptor * fMemDesc;
int fSpeed;
int fSize;
int fCurRetries;
int fMaxRetries;
int fChannel;
int fSyncBits;
int fTag;
UInt32 fGeneration; bool fFailOnReset;
typedef struct
{ }
MemberVariables;
MemberVariables * fMembers;
virtual IOReturn complete(
IOReturn status);
virtual IOReturn execute();
public:
virtual bool initAll(
IOFireWireController * control,
UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon);
virtual void free( void );
virtual IOReturn reinit( UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon);
virtual void gotAck(
int ackCode);
virtual void setGeneration(
UInt32 generation)
{ fGeneration = generation; }
IOReturn updateGeneration();
bool failOnReset() const
{ return fFailOnReset; }
private:
OSMetaClassDeclareReservedUnused(IOFWAsyncStreamCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWAsyncStreamCommand, 1);
public:
virtual bool initAll(
IOFireWireController * control,
UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon,
bool failOnReset );
virtual IOReturn reinit(
UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon,
bool failOnReset);
};
#pragma mark -
class IOFWAsyncPHYCommand : public IOFWCommand
{
friend class IOFireWireUserClient;
OSDeclareDefaultStructors( IOFWAsyncPHYCommand )
protected:
AsyncPendingTrans * fTrans;
FWAsyncPHYCallback fComplete;
void * fRefCon;
int fCurRetries;
int fMaxRetries;
UInt32 fGeneration;
bool fFailOnReset;
UInt32 fData1;
UInt32 fData2;
int fAckCode;
UInt32 fResponseCode;
typedef struct
{ }
MemberVariables;
MemberVariables * fMembers;
virtual IOReturn complete(
IOReturn status );
virtual IOReturn execute();
void setResponseCode( UInt32 rcode );
void setAckCode( int ack );
public:
virtual bool initAll(
IOFireWireController * control,
UInt32 generation,
UInt32 data1,
UInt32 data2,
FWAsyncPHYCallback completion,
void * refcon,
bool failOnReset );
virtual void free( void );
virtual IOReturn reinit( UInt32 generation,
UInt32 data1,
UInt32 data2,
FWAsyncPHYCallback completion,
void * refcon,
bool failOnReset );
virtual void gotAck(
int ackCode );
virtual void setGeneration(
UInt32 generation )
{ fGeneration = generation; }
IOReturn updateGeneration();
bool failOnReset() const
{ return fFailOnReset; }
virtual void gotPacket( int rcode );
int getAckCode( void );
UInt32 getResponseCode( void ) const;
void setRetries( int retries);
private:
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 0);
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 1);
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 2);
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 3);
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 4);
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 5);
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 6);
OSMetaClassDeclareReservedUnused(IOFWAsyncPHYCommand, 7);
};
#endif