Commit cd915200 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Staging ced1401: cleanup coding style issues.

A basic Lindent run on the .c files, clean up the .h file by hand.

Cc: Alois Schlögl <alois.schloegl@ist.ac.at>
Cc: Greg P. Smith <greg@ced.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2d966501
...@@ -37,17 +37,18 @@ ...@@ -37,17 +37,18 @@
** **
** Empties the Output buffer and sets int lines. Used from user level only ** Empties the Output buffer and sets int lines. Used from user level only
****************************************************************************/ ****************************************************************************/
void FlushOutBuff(DEVICE_EXTENSION *pdx) void FlushOutBuff(DEVICE_EXTENSION * pdx)
{ {
dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__, pdx->sCurrentState); dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__,
if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ pdx->sCurrentState);
return; if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */
return;
// CharSend_Cancel(pdx); /* Kill off any pending I/O */ // CharSend_Cancel(pdx); /* Kill off any pending I/O */
spin_lock_irq(&pdx->charOutLock); spin_lock_irq(&pdx->charOutLock);
pdx->dwNumOutput = 0; pdx->dwNumOutput = 0;
pdx->dwOutBuffGet = 0; pdx->dwOutBuffGet = 0;
pdx->dwOutBuffPut = 0; pdx->dwOutBuffPut = 0;
spin_unlock_irq(&pdx->charOutLock); spin_unlock_irq(&pdx->charOutLock);
} }
/**************************************************************************** /****************************************************************************
...@@ -56,17 +57,18 @@ void FlushOutBuff(DEVICE_EXTENSION *pdx) ...@@ -56,17 +57,18 @@ void FlushOutBuff(DEVICE_EXTENSION *pdx)
** **
** Empties the input buffer and sets int lines ** Empties the input buffer and sets int lines
****************************************************************************/ ****************************************************************************/
void FlushInBuff(DEVICE_EXTENSION *pdx) void FlushInBuff(DEVICE_EXTENSION * pdx)
{ {
dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__, pdx->sCurrentState); dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__,
if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ pdx->sCurrentState);
return; if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */
return;
// CharRead_Cancel(pDevObject); /* Kill off any pending I/O */ // CharRead_Cancel(pDevObject); /* Kill off any pending I/O */
spin_lock_irq(&pdx->charInLock); spin_lock_irq(&pdx->charInLock);
pdx->dwNumInput = 0; pdx->dwNumInput = 0;
pdx->dwInBuffGet = 0; pdx->dwInBuffGet = 0;
pdx->dwInBuffPut = 0; pdx->dwInBuffPut = 0;
spin_unlock_irq(&pdx->charInLock); spin_unlock_irq(&pdx->charInLock);
} }
/**************************************************************************** /****************************************************************************
...@@ -75,29 +77,26 @@ void FlushInBuff(DEVICE_EXTENSION *pdx) ...@@ -75,29 +77,26 @@ void FlushInBuff(DEVICE_EXTENSION *pdx)
** Utility routine to copy chars into the output buffer and fire them off. ** Utility routine to copy chars into the output buffer and fire them off.
** called from user mode, holds charOutLock. ** called from user mode, holds charOutLock.
****************************************************************************/ ****************************************************************************/
static int PutChars(DEVICE_EXTENSION* pdx, const char* pCh, unsigned int uCount) static int PutChars(DEVICE_EXTENSION * pdx, const char *pCh,
unsigned int uCount)
{ {
int iReturn; int iReturn;
spin_lock_irq(&pdx->charOutLock); // get the output spin lock spin_lock_irq(&pdx->charOutLock); // get the output spin lock
if ((OUTBUF_SZ - pdx->dwNumOutput) >= uCount) if ((OUTBUF_SZ - pdx->dwNumOutput) >= uCount) {
{ unsigned int u;
unsigned int u; for (u = 0; u < uCount; u++) {
for (u=0; u<uCount; u++) pdx->outputBuffer[pdx->dwOutBuffPut++] = pCh[u];
{ if (pdx->dwOutBuffPut >= OUTBUF_SZ)
pdx->outputBuffer[pdx->dwOutBuffPut++] = pCh[u]; pdx->dwOutBuffPut = 0;
if (pdx->dwOutBuffPut >= OUTBUF_SZ) }
pdx->dwOutBuffPut = 0; pdx->dwNumOutput += uCount;
} spin_unlock_irq(&pdx->charOutLock);
pdx->dwNumOutput += uCount; iReturn = SendChars(pdx); // ...give a chance to transmit data
spin_unlock_irq(&pdx->charOutLock); } else {
iReturn = SendChars(pdx); // ...give a chance to transmit data iReturn = U14ERR_NOOUT; // no room at the out (ha-ha)
} spin_unlock_irq(&pdx->charOutLock);
else }
{ return iReturn;
iReturn = U14ERR_NOOUT; // no room at the out (ha-ha)
spin_unlock_irq(&pdx->charOutLock);
}
return iReturn;
} }
/***************************************************************************** /*****************************************************************************
...@@ -105,27 +104,29 @@ static int PutChars(DEVICE_EXTENSION* pdx, const char* pCh, unsigned int uCount) ...@@ -105,27 +104,29 @@ static int PutChars(DEVICE_EXTENSION* pdx, const char* pCh, unsigned int uCount)
** trigger an output transfer if this is appropriate. User mode. ** trigger an output transfer if this is appropriate. User mode.
** Holds the io_mutex ** Holds the io_mutex
*****************************************************************************/ *****************************************************************************/
int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n) int SendString(DEVICE_EXTENSION * pdx, const char __user * pData,
unsigned int n)
{ {
int iReturn = U14ERR_NOERROR; // assume all will be well int iReturn = U14ERR_NOERROR; // assume all will be well
char buffer[OUTBUF_SZ+1]; // space in our address space for characters char buffer[OUTBUF_SZ + 1]; // space in our address space for characters
if (n > OUTBUF_SZ) // check space in local buffer... if (n > OUTBUF_SZ) // check space in local buffer...
return U14ERR_NOOUT; // ...too many characters return U14ERR_NOOUT; // ...too many characters
if (copy_from_user(buffer, pData, n)) if (copy_from_user(buffer, pData, n))
return -ENOMEM; // could not copy return -ENOMEM; // could not copy
buffer[n] = 0; // terminate for debug purposes buffer[n] = 0; // terminate for debug purposes
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
if (n > 0) // do nothing if nowt to do! if (n > 0) // do nothing if nowt to do!
{ {
dev_dbg(&pdx->interface->dev, "%s n=%d>%s<", __func__, n, buffer); dev_dbg(&pdx->interface->dev, "%s n=%d>%s<", __func__, n,
iReturn = PutChars(pdx, buffer, n); buffer);
} iReturn = PutChars(pdx, buffer, n);
}
Allowi(pdx, false); // make sure we have input int
mutex_unlock(&pdx->io_mutex); Allowi(pdx, false); // make sure we have input int
mutex_unlock(&pdx->io_mutex);
return iReturn;
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -133,15 +134,15 @@ int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n) ...@@ -133,15 +134,15 @@ int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n)
** **
** Sends a single character to the 1401. User mode, holds io_mutex. ** Sends a single character to the 1401. User mode, holds io_mutex.
****************************************************************************/ ****************************************************************************/
int SendChar(DEVICE_EXTENSION *pdx, char c) int SendChar(DEVICE_EXTENSION * pdx, char c)
{ {
int iReturn; int iReturn;
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
iReturn = PutChars(pdx, &c, 1); iReturn = PutChars(pdx, &c, 1);
dev_dbg(&pdx->interface->dev,"SendChar >%c< (0x%02x)", c, c); dev_dbg(&pdx->interface->dev, "SendChar >%c< (0x%02x)", c, c);
Allowi(pdx, false); // Make sure char reads are running Allowi(pdx, false); // Make sure char reads are running
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/*************************************************************************** /***************************************************************************
...@@ -170,48 +171,47 @@ int SendChar(DEVICE_EXTENSION *pdx, char c) ...@@ -170,48 +171,47 @@ int SendChar(DEVICE_EXTENSION *pdx, char c)
** **
** return error code (U14ERR_NOERROR for OK) ** return error code (U14ERR_NOERROR for OK)
*/ */
int Get1401State(DEVICE_EXTENSION* pdx, __u32* state, __u32* error) int Get1401State(DEVICE_EXTENSION * pdx, __u32 * state, __u32 * error)
{ {
int nGot; int nGot;
dev_dbg(&pdx->interface->dev, "Get1401State() entry"); dev_dbg(&pdx->interface->dev, "Get1401State() entry");
*state = 0xFFFFFFFF; // Start off with invalid state *state = 0xFFFFFFFF; // Start off with invalid state
nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0),
GET_STATUS, (D_TO_H|VENDOR|DEVREQ), 0,0, GET_STATUS, (D_TO_H | VENDOR | DEVREQ), 0, 0,
pdx->statBuf, sizeof(pdx->statBuf), HZ); pdx->statBuf, sizeof(pdx->statBuf), HZ);
if (nGot != sizeof(pdx->statBuf)) if (nGot != sizeof(pdx->statBuf)) {
{ dev_err(&pdx->interface->dev,
dev_err(&pdx->interface->dev, "Get1401State() FAILED, return code %d", nGot); "Get1401State() FAILED, return code %d", nGot);
pdx->sCurrentState = U14ERR_TIME; // Indicate that things are very wrong indeed pdx->sCurrentState = U14ERR_TIME; // Indicate that things are very wrong indeed
*state = 0; // Force status values to a known state *state = 0; // Force status values to a known state
*error = 0; *error = 0;
} } else {
else int nDevice;
{ dev_dbg(&pdx->interface->dev,
int nDevice; "Get1401State() Success, state: 0x%x, 0x%x",
dev_dbg(&pdx->interface->dev, "Get1401State() Success, state: 0x%x, 0x%x", pdx->statBuf[0], pdx->statBuf[1]);
pdx->statBuf[0], pdx->statBuf[1]);
*state = pdx->statBuf[0]; // Return the state values to the calling code
*state = pdx->statBuf[0]; // Return the state values to the calling code *error = pdx->statBuf[1];
*error = pdx->statBuf[1];
nDevice = pdx->udev->descriptor.bcdDevice >> 8; // 1401 type code value
nDevice = pdx->udev->descriptor.bcdDevice >> 8; // 1401 type code value switch (nDevice) // so we can clean up current state
switch (nDevice) // so we can clean up current state {
{ case 0:
case 0: pdx->sCurrentState = U14ERR_U1401;
pdx->sCurrentState = U14ERR_U1401; break;
break;
default: // allow lots of device codes for future 1401s
default: // allow lots of device codes for future 1401s if ((nDevice >= 1) && (nDevice <= 23))
if ((nDevice >= 1) && (nDevice <= 23)) pdx->sCurrentState = (short)(nDevice + 6);
pdx->sCurrentState = (short)(nDevice + 6); else
else pdx->sCurrentState = U14ERR_ILL;
pdx->sCurrentState = U14ERR_ILL; break;
break; }
} }
}
return pdx->sCurrentState >= 0 ? U14ERR_NOERROR : pdx->sCurrentState;
return pdx->sCurrentState >= 0 ? U14ERR_NOERROR : pdx->sCurrentState;
} }
/**************************************************************************** /****************************************************************************
...@@ -219,49 +219,53 @@ int Get1401State(DEVICE_EXTENSION* pdx, __u32* state, __u32* error) ...@@ -219,49 +219,53 @@ int Get1401State(DEVICE_EXTENSION* pdx, __u32* state, __u32* error)
** **
** Kills off staged read\write request from the USB if one is pending. ** Kills off staged read\write request from the USB if one is pending.
****************************************************************************/ ****************************************************************************/
int ReadWrite_Cancel(DEVICE_EXTENSION *pdx) int ReadWrite_Cancel(DEVICE_EXTENSION * pdx)
{ {
dev_dbg(&pdx->interface->dev, "ReadWrite_Cancel entry %d", pdx->bStagedUrbPending); dev_dbg(&pdx->interface->dev, "ReadWrite_Cancel entry %d",
pdx->bStagedUrbPending);
#ifdef NOT_WRITTEN_YET #ifdef NOT_WRITTEN_YET
int ntStatus = STATUS_SUCCESS; int ntStatus = STATUS_SUCCESS;
bool bResult = false; bool bResult = false;
unsigned int i; unsigned int i;
// We can fill this in when we know how we will implement the staged transfer stuff // We can fill this in when we know how we will implement the staged transfer stuff
spin_lock_irq(&pdx->stagedLock); spin_lock_irq(&pdx->stagedLock);
if (pdx->bStagedUrbPending) // anything to be cancelled? May need more... if (pdx->bStagedUrbPending) // anything to be cancelled? May need more...
{ {
dev_info(&pdx->interface-dev, "ReadWrite_Cancel about to cancel Urb"); dev_info(&pdx->interface - dev,
"ReadWrite_Cancel about to cancel Urb");
// KeClearEvent(&pdx->StagingDoneEvent); // Clear the staging done flag
USB_ASSERT(pdx->pStagedIrp != NULL); // KeClearEvent(&pdx->StagingDoneEvent); // Clear the staging done flag
USB_ASSERT(pdx->pStagedIrp != NULL);
// Release the spinlock first otherwise the completion routine may hang
// on the spinlock while this function hands waiting for the event. // Release the spinlock first otherwise the completion routine may hang
spin_unlock_irq(&pdx->stagedLock); // on the spinlock while this function hands waiting for the event.
bResult = IoCancelIrp(pdx->pStagedIrp); // Actually do the cancel spin_unlock_irq(&pdx->stagedLock);
if (bResult) bResult = IoCancelIrp(pdx->pStagedIrp); // Actually do the cancel
{ if (bResult) {
LARGE_INTEGER timeout; LARGE_INTEGER timeout;
timeout.QuadPart = -10000000; // Use a timeout of 1 second timeout.QuadPart = -10000000; // Use a timeout of 1 second
dev_info(&pdx->interface-dev, "ReadWrite_Cancel about to wait till done"); dev_info(&pdx->interface - dev,
ntStatus = KeWaitForSingleObject(&pdx->StagingDoneEvent, Executive, "ReadWrite_Cancel about to wait till done");
KernelMode, FALSE, &timeout); ntStatus =
} KeWaitForSingleObject(&pdx->StagingDoneEvent,
else Executive, KernelMode, FALSE,
{ &timeout);
dev_info(&pdx->interface-dev, "ReadWrite_Cancel, cancellation failed"); } else {
ntStatus = U14ERR_FAIL; dev_info(&pdx->interface - dev,
} "ReadWrite_Cancel, cancellation failed");
USB_KdPrint(DBGLVL_DEFAULT, ("ReadWrite_Cancel ntStatus = 0x%x decimal %d\n", ntStatus, ntStatus)); ntStatus = U14ERR_FAIL;
} }
else USB_KdPrint(DBGLVL_DEFAULT,
spin_unlock_irq(&pdx->stagedLock); ("ReadWrite_Cancel ntStatus = 0x%x decimal %d\n",
ntStatus, ntStatus));
dev_info(&pdx->interface-dev, "ReadWrite_Cancel done"); } else
return ntStatus; spin_unlock_irq(&pdx->stagedLock);
dev_info(&pdx->interface - dev, "ReadWrite_Cancel done");
return ntStatus;
#else #else
return U14ERR_NOERROR; return U14ERR_NOERROR;
#endif #endif
} }
...@@ -270,15 +274,15 @@ int ReadWrite_Cancel(DEVICE_EXTENSION *pdx) ...@@ -270,15 +274,15 @@ int ReadWrite_Cancel(DEVICE_EXTENSION *pdx)
** InSelfTest - utility to check in self test. Return 1 for ST, 0 for not or ** InSelfTest - utility to check in self test. Return 1 for ST, 0 for not or
** a -ve error code if we failed for some reason. ** a -ve error code if we failed for some reason.
***************************************************************************/ ***************************************************************************/
static int InSelfTest(DEVICE_EXTENSION* pdx, unsigned int* pState) static int InSelfTest(DEVICE_EXTENSION * pdx, unsigned int *pState)
{ {
unsigned int state, error; unsigned int state, error;
int iReturn = Get1401State(pdx, &state, &error); // see if in self-test int iReturn = Get1401State(pdx, &state, &error); // see if in self-test
if (iReturn == U14ERR_NOERROR) // if all still OK if (iReturn == U14ERR_NOERROR) // if all still OK
iReturn = (state == (unsigned int)-1) || // TX problem or... iReturn = (state == (unsigned int)-1) || // TX problem or...
((state & 0xff) == 0x80); // ...self test ((state & 0xff) == 0x80); // ...self test
*pState = state; // return actual state *pState = state; // return actual state
return iReturn; return iReturn;
} }
/*************************************************************************** /***************************************************************************
...@@ -299,52 +303,50 @@ static int InSelfTest(DEVICE_EXTENSION* pdx, unsigned int* pState) ...@@ -299,52 +303,50 @@ static int InSelfTest(DEVICE_EXTENSION* pdx, unsigned int* pState)
** **
** Returns TRUE if a 1401 detected and OK, else FALSE ** Returns TRUE if a 1401 detected and OK, else FALSE
****************************************************************************/ ****************************************************************************/
bool Is1401(DEVICE_EXTENSION* pdx) bool Is1401(DEVICE_EXTENSION * pdx)
{ {
int iReturn; int iReturn;
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
ced_draw_down(pdx); // wait for, then kill outstanding Urbs ced_draw_down(pdx); // wait for, then kill outstanding Urbs
FlushInBuff(pdx); // Clear out input buffer & pipe FlushInBuff(pdx); // Clear out input buffer & pipe
FlushOutBuff(pdx); // Clear output buffer & pipe FlushOutBuff(pdx); // Clear output buffer & pipe
// The next call returns 0 if OK, but has returned 1 in the past, meaning that // The next call returns 0 if OK, but has returned 1 in the past, meaning that
// usb_unlock_device() is needed... now it always is // usb_unlock_device() is needed... now it always is
iReturn = usb_lock_device_for_reset(pdx->udev, pdx->interface); iReturn = usb_lock_device_for_reset(pdx->udev, pdx->interface);
// release the io_mutex because if we don't, we will deadlock due to system // release the io_mutex because if we don't, we will deadlock due to system
// calls back into the driver. // calls back into the driver.
mutex_unlock(&pdx->io_mutex); // locked, so we will not get system calls mutex_unlock(&pdx->io_mutex); // locked, so we will not get system calls
if (iReturn >= 0) // if we failed if (iReturn >= 0) // if we failed
{ {
iReturn = usb_reset_device(pdx->udev); // try to do the reset iReturn = usb_reset_device(pdx->udev); // try to do the reset
usb_unlock_device(pdx->udev); // undo the lock usb_unlock_device(pdx->udev); // undo the lock
} }
mutex_lock(&pdx->io_mutex); // hold stuff off while we wait mutex_lock(&pdx->io_mutex); // hold stuff off while we wait
pdx->dwDMAFlag = MODE_CHAR; // Clear DMA mode flag regardless! pdx->dwDMAFlag = MODE_CHAR; // Clear DMA mode flag regardless!
if (iReturn == 0) // if all is OK still if (iReturn == 0) // if all is OK still
{ {
unsigned int state; unsigned int state;
iReturn = InSelfTest(pdx, &state); // see if likely in self test iReturn = InSelfTest(pdx, &state); // see if likely in self test
if (iReturn > 0) // do we need to wait for self-test? if (iReturn > 0) // do we need to wait for self-test?
{ {
unsigned long ulTimeOut = jiffies + 30*HZ; // when to give up unsigned long ulTimeOut = jiffies + 30 * HZ; // when to give up
while((iReturn > 0) && time_before(jiffies, ulTimeOut)) while ((iReturn > 0) && time_before(jiffies, ulTimeOut)) {
{ schedule(); // let other stuff run
schedule(); // let other stuff run iReturn = InSelfTest(pdx, &state); // see if done yet
iReturn = InSelfTest(pdx, &state); // see if done yet }
} }
}
if (iReturn == 0) // if all is OK...
if (iReturn == 0) // if all is OK... iReturn = state == 0; // then sucess is that the state is 0
iReturn = state == 0; // then sucess is that the state is 0 } else
} iReturn = 0; // we failed
else pdx->bForceReset = false; // Clear forced reset flag now
iReturn = 0; // we failed
pdx->bForceReset = false; // Clear forced reset flag now return iReturn > 0;
return iReturn > 0;
} }
/**************************************************************************** /****************************************************************************
...@@ -361,44 +363,48 @@ bool Is1401(DEVICE_EXTENSION* pdx) ...@@ -361,44 +363,48 @@ bool Is1401(DEVICE_EXTENSION* pdx)
** **
** The return value is TRUE if a useable 1401 is found, FALSE if not ** The return value is TRUE if a useable 1401 is found, FALSE if not
*/ */
bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset) bool QuickCheck(DEVICE_EXTENSION * pdx, bool bTestBuff, bool bCanReset)
{ {
bool bRet = false; // assume it will fail and we will reset bool bRet = false; // assume it will fail and we will reset
bool bShortTest; bool bShortTest;
bShortTest = ((pdx->dwDMAFlag == MODE_CHAR) && // no DMA running bShortTest = ((pdx->dwDMAFlag == MODE_CHAR) && // no DMA running
(!pdx->bForceReset) && // Not had a real reset forced (!pdx->bForceReset) && // Not had a real reset forced
(pdx->sCurrentState >= U14ERR_STD)); // No 1401 errors stored (pdx->sCurrentState >= U14ERR_STD)); // No 1401 errors stored
dev_dbg(&pdx->interface->dev, "%s DMAFlag:%d, state:%d, force:%d, testBuff:%d, short:%d", dev_dbg(&pdx->interface->dev,
__func__, pdx->dwDMAFlag, pdx->sCurrentState, pdx->bForceReset, bTestBuff, bShortTest); "%s DMAFlag:%d, state:%d, force:%d, testBuff:%d, short:%d",
__func__, pdx->dwDMAFlag, pdx->sCurrentState, pdx->bForceReset,
if ((bTestBuff) && // Buffer check requested, and... bTestBuff, bShortTest);
(pdx->dwNumInput || pdx->dwNumOutput)) // ...characters were in the buffer?
{ if ((bTestBuff) && // Buffer check requested, and...
bShortTest = false; // Then do the full test (pdx->dwNumInput || pdx->dwNumOutput)) // ...characters were in the buffer?
dev_dbg(&pdx->interface->dev, "%s will reset as buffers not empty", __func__); {
} bShortTest = false; // Then do the full test
dev_dbg(&pdx->interface->dev,
if (bShortTest || !bCanReset) // Still OK to try the short test? "%s will reset as buffers not empty", __func__);
{ // Always test if no reset - we want state update }
unsigned int state, error;
dev_dbg(&pdx->interface->dev, "%s->Get1401State", __func__); if (bShortTest || !bCanReset) // Still OK to try the short test?
if (Get1401State(pdx, &state, &error) == U14ERR_NOERROR) // Check on the 1401 state { // Always test if no reset - we want state update
{ unsigned int state, error;
if ((state & 0xFF) == 0) // If call worked, check the status value dev_dbg(&pdx->interface->dev, "%s->Get1401State", __func__);
bRet = true; // If that was zero, all is OK, no reset needed if (Get1401State(pdx, &state, &error) == U14ERR_NOERROR) // Check on the 1401 state
} {
} if ((state & 0xFF) == 0) // If call worked, check the status value
bRet = true; // If that was zero, all is OK, no reset needed
if (!bRet && bCanReset) // If all not OK, then }
{ }
dev_info(&pdx->interface->dev, "%s->Is1401 %d %d %d %d",
__func__, bShortTest, pdx->sCurrentState, bTestBuff, pdx->bForceReset); if (!bRet && bCanReset) // If all not OK, then
bRet = Is1401(pdx); // do full test {
} dev_info(&pdx->interface->dev, "%s->Is1401 %d %d %d %d",
__func__, bShortTest, pdx->sCurrentState, bTestBuff,
return bRet; pdx->bForceReset);
bRet = Is1401(pdx); // do full test
}
return bRet;
} }
/**************************************************************************** /****************************************************************************
...@@ -406,13 +412,13 @@ bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset) ...@@ -406,13 +412,13 @@ bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset)
** **
** Resets the 1401 and empties the i/o buffers ** Resets the 1401 and empties the i/o buffers
*****************************************************************************/ *****************************************************************************/
int Reset1401(DEVICE_EXTENSION *pdx) int Reset1401(DEVICE_EXTENSION * pdx)
{ {
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
dev_dbg(&pdx->interface->dev,"ABout to call QuickCheck"); dev_dbg(&pdx->interface->dev, "ABout to call QuickCheck");
QuickCheck(pdx, true, true); // Check 1401, reset if not OK QuickCheck(pdx, true, true); // Check 1401, reset if not OK
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return U14ERR_NOERROR; return U14ERR_NOERROR;
} }
/**************************************************************************** /****************************************************************************
...@@ -420,32 +426,31 @@ int Reset1401(DEVICE_EXTENSION *pdx) ...@@ -420,32 +426,31 @@ int Reset1401(DEVICE_EXTENSION *pdx)
** **
** Gets a single character from the 1401 ** Gets a single character from the 1401
****************************************************************************/ ****************************************************************************/
int GetChar(DEVICE_EXTENSION *pdx) int GetChar(DEVICE_EXTENSION * pdx)
{ {
int iReturn = U14ERR_NOIN; // assume we will get nothing int iReturn = U14ERR_NOIN; // assume we will get nothing
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
dev_dbg(&pdx->interface->dev, "GetChar"); dev_dbg(&pdx->interface->dev, "GetChar");
Allowi(pdx, false); // Make sure char reads are running Allowi(pdx, false); // Make sure char reads are running
SendChars(pdx); // and send any buffered chars SendChars(pdx); // and send any buffered chars
spin_lock_irq(&pdx->charInLock); spin_lock_irq(&pdx->charInLock);
if (pdx->dwNumInput > 0) // worth looking if (pdx->dwNumInput > 0) // worth looking
{ {
iReturn = pdx->inputBuffer[pdx->dwInBuffGet++]; iReturn = pdx->inputBuffer[pdx->dwInBuffGet++];
if (pdx->dwInBuffGet >= INBUF_SZ) if (pdx->dwInBuffGet >= INBUF_SZ)
pdx->dwInBuffGet = 0; pdx->dwInBuffGet = 0;
pdx->dwNumInput--; pdx->dwNumInput--;
} } else
else iReturn = U14ERR_NOIN; // no input data to read
iReturn = U14ERR_NOIN; // no input data to read spin_unlock_irq(&pdx->charInLock);
spin_unlock_irq(&pdx->charInLock);
Allowi(pdx, false); // Make sure char reads are running
Allowi(pdx, false); // Make sure char reads are running
mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o return iReturn;
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -459,78 +464,77 @@ int GetChar(DEVICE_EXTENSION *pdx) ...@@ -459,78 +464,77 @@ int GetChar(DEVICE_EXTENSION *pdx)
** returns the count of characters (including the terminator, or 0 if none ** returns the count of characters (including the terminator, or 0 if none
** or a negative error code. ** or a negative error code.
****************************************************************************/ ****************************************************************************/
int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n) int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n)
{ {
int nAvailable; // character in the buffer int nAvailable; // character in the buffer
int iReturn = U14ERR_NOIN; int iReturn = U14ERR_NOIN;
if (n <= 0) if (n <= 0)
return -ENOMEM; return -ENOMEM;
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
Allowi(pdx, false); // Make sure char reads are running Allowi(pdx, false); // Make sure char reads are running
SendChars(pdx); // and send any buffered chars SendChars(pdx); // and send any buffered chars
spin_lock_irq(&pdx->charInLock); spin_lock_irq(&pdx->charInLock);
nAvailable = pdx->dwNumInput; // characters available now nAvailable = pdx->dwNumInput; // characters available now
if (nAvailable > n) // read max of space in pUser... if (nAvailable > n) // read max of space in pUser...
nAvailable = n; // ...or input characters nAvailable = n; // ...or input characters
if (nAvailable > 0) // worth looking? if (nAvailable > 0) // worth looking?
{ {
char buffer[INBUF_SZ+1]; // space for a linear copy of data char buffer[INBUF_SZ + 1]; // space for a linear copy of data
int nGot = 0; int nGot = 0;
int nCopyToUser; // number to copy to user int nCopyToUser; // number to copy to user
char cData; char cData;
do do {
{ cData = pdx->inputBuffer[pdx->dwInBuffGet++];
cData = pdx->inputBuffer[pdx->dwInBuffGet++]; if (cData == CR_CHAR) // replace CR with zero
if (cData == CR_CHAR) // replace CR with zero cData = (char)0;
cData = (char)0;
if (pdx->dwInBuffGet >= INBUF_SZ)
if (pdx->dwInBuffGet >= INBUF_SZ) pdx->dwInBuffGet = 0; // wrap buffer pointer
pdx->dwInBuffGet = 0; // wrap buffer pointer
buffer[nGot++] = cData; // save the output
buffer[nGot++] = cData; // save the output }
} while ((nGot < nAvailable) && cData);
while((nGot < nAvailable) && cData);
nCopyToUser = nGot; // what to copy...
nCopyToUser = nGot; // what to copy... if (cData) // do we need null
if (cData) // do we need null {
{ buffer[nGot] = (char)0; // make it tidy
buffer[nGot] = (char)0; // make it tidy if (nGot < n) // if space in user buffer...
if (nGot < n) // if space in user buffer... ++nCopyToUser; // ...copy the 0 as well.
++nCopyToUser; // ...copy the 0 as well. }
}
pdx->dwNumInput -= nGot;
pdx->dwNumInput -= nGot; spin_unlock_irq(&pdx->charInLock);
spin_unlock_irq(&pdx->charInLock);
dev_dbg(&pdx->interface->dev,
dev_dbg(&pdx->interface->dev,"GetString read %d characters >%s<", nGot, buffer); "GetString read %d characters >%s<", nGot, buffer);
copy_to_user(pUser, buffer, nCopyToUser); copy_to_user(pUser, buffer, nCopyToUser);
iReturn = nGot; // report characters read iReturn = nGot; // report characters read
} } else
else spin_unlock_irq(&pdx->charInLock);
spin_unlock_irq(&pdx->charInLock);
Allowi(pdx, false); // Make sure char reads are running
Allowi(pdx, false); // Make sure char reads are running mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
return iReturn;
return iReturn;
} }
/******************************************************************************* /*******************************************************************************
** Get count of characters in the inout buffer. ** Get count of characters in the inout buffer.
*******************************************************************************/ *******************************************************************************/
int Stat1401(DEVICE_EXTENSION *pdx) int Stat1401(DEVICE_EXTENSION * pdx)
{ {
int iReturn; int iReturn;
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
Allowi(pdx, false); // make sure we allow pending chars Allowi(pdx, false); // make sure we allow pending chars
SendChars(pdx); // in both directions SendChars(pdx); // in both directions
iReturn = pdx->dwNumInput; // no lock as single read iReturn = pdx->dwNumInput; // no lock as single read
mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -540,34 +544,33 @@ int Stat1401(DEVICE_EXTENSION *pdx) ...@@ -540,34 +544,33 @@ int Stat1401(DEVICE_EXTENSION *pdx)
** any fancy interlocks as we only read the interrupt routine data, and the ** any fancy interlocks as we only read the interrupt routine data, and the
** system is arranged so nothing can be destroyed. ** system is arranged so nothing can be destroyed.
****************************************************************************/ ****************************************************************************/
int LineCount(DEVICE_EXTENSION *pdx) int LineCount(DEVICE_EXTENSION * pdx)
{ {
int iReturn = 0; // will be count of line ends int iReturn = 0; // will be count of line ends
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
Allowi(pdx, false); // Make sure char reads are running Allowi(pdx, false); // Make sure char reads are running
SendChars(pdx); // and send any buffered chars SendChars(pdx); // and send any buffered chars
spin_lock_irq(&pdx->charInLock); // Get protection spin_lock_irq(&pdx->charInLock); // Get protection
if (pdx->dwNumInput > 0) // worth looking? if (pdx->dwNumInput > 0) // worth looking?
{ {
unsigned int dwIndex = pdx->dwInBuffGet;// start at first available unsigned int dwIndex = pdx->dwInBuffGet; // start at first available
unsigned int dwEnd = pdx->dwInBuffPut; // Position for search end unsigned int dwEnd = pdx->dwInBuffPut; // Position for search end
do do {
{ if (pdx->inputBuffer[dwIndex++] == CR_CHAR)
if (pdx->inputBuffer[dwIndex++] == CR_CHAR) ++iReturn; // inc count if CR
++iReturn; // inc count if CR
if (dwIndex >= INBUF_SZ) // see if we fall off buff
if (dwIndex >= INBUF_SZ) // see if we fall off buff dwIndex = 0;
dwIndex = 0; }
} while (dwIndex != dwEnd); // go to last avaliable
while (dwIndex != dwEnd); // go to last avaliable }
}
spin_unlock_irq(&pdx->charInLock);
spin_unlock_irq(&pdx->charInLock); dev_dbg(&pdx->interface->dev, "LineCount returned %d", iReturn);
dev_dbg(&pdx->interface->dev,"LineCount returned %d", iReturn); mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o return iReturn;
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -575,15 +578,15 @@ int LineCount(DEVICE_EXTENSION *pdx) ...@@ -575,15 +578,15 @@ int LineCount(DEVICE_EXTENSION *pdx)
** **
** Gets the space in the output buffer. Called from user code. ** Gets the space in the output buffer. Called from user code.
*****************************************************************************/ *****************************************************************************/
int GetOutBufSpace(DEVICE_EXTENSION *pdx) int GetOutBufSpace(DEVICE_EXTENSION * pdx)
{ {
int iReturn; int iReturn;
mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
SendChars(pdx); // send any buffered chars SendChars(pdx); // send any buffered chars
iReturn = (int)(OUTBUF_SZ - pdx->dwNumOutput); // no lock needed for single read iReturn = (int)(OUTBUF_SZ - pdx->dwNumOutput); // no lock needed for single read
dev_dbg(&pdx->interface->dev,"OutBufSpace %d", iReturn); dev_dbg(&pdx->interface->dev, "OutBufSpace %d", iReturn);
mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -593,74 +596,75 @@ int GetOutBufSpace(DEVICE_EXTENSION *pdx) ...@@ -593,74 +596,75 @@ int GetOutBufSpace(DEVICE_EXTENSION *pdx)
** Clears up a transfer area. This is always called in the context of a user ** Clears up a transfer area. This is always called in the context of a user
** request, never from a call-back. ** request, never from a call-back.
****************************************************************************/ ****************************************************************************/
int ClearArea(DEVICE_EXTENSION *pdx, int nArea) int ClearArea(DEVICE_EXTENSION * pdx, int nArea)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
if ((nArea < 0) || (nArea >= MAX_TRANSAREAS)) if ((nArea < 0) || (nArea >= MAX_TRANSAREAS)) {
{ iReturn = U14ERR_BADAREA;
iReturn = U14ERR_BADAREA; dev_err(&pdx->interface->dev, "%s Attempt to clear area %d",
dev_err(&pdx->interface->dev, "%s Attempt to clear area %d", __func__, nArea); __func__, nArea);
} } else {
else TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing
{ if (!pTA->bUsed) // if not used...
TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing iReturn = U14ERR_NOTSET; // ...nothing to be done
if (!pTA->bUsed) // if not used... else {
iReturn = U14ERR_NOTSET; // ...nothing to be done // We must save the memory we return as we shouldn't mess with memory while
else // holding a spin lock.
{ struct page **pPages = 0; // save page address list
// We must save the memory we return as we shouldn't mess with memory while int nPages = 0; // and number of pages
// holding a spin lock. int np;
struct page **pPages = 0; // save page address list
int nPages = 0; // and number of pages dev_dbg(&pdx->interface->dev, "%s area %d", __func__,
int np; nArea);
spin_lock_irq(&pdx->stagedLock);
dev_dbg(&pdx->interface->dev, "%s area %d", __func__, nArea); if ((pdx->StagedId == nArea)
spin_lock_irq(&pdx->stagedLock); && (pdx->dwDMAFlag > MODE_CHAR)) {
if ((pdx->StagedId == nArea) && (pdx->dwDMAFlag > MODE_CHAR)) iReturn = U14ERR_UNLOCKFAIL; // cannot delete as in use
{ dev_err(&pdx->interface->dev,
iReturn = U14ERR_UNLOCKFAIL; // cannot delete as in use "%s call on area %d while active",
dev_err(&pdx->interface->dev, "%s call on area %d while active", __func__, nArea); __func__, nArea);
} } else {
else pPages = pTA->pPages; // save page address list
{ nPages = pTA->nPages; // and page count
pPages = pTA->pPages; // save page address list if (pTA->dwEventSz) // if events flagging in use
nPages = pTA->nPages; // and page count wake_up_interruptible(&pTA->wqEvent); // release anything that was waiting
if (pTA->dwEventSz) // if events flagging in use
wake_up_interruptible(&pTA->wqEvent); // release anything that was waiting if (pdx->bXFerWaiting
&& (pdx->rDMAInfo.wIdent == nArea))
if (pdx->bXFerWaiting && (pdx->rDMAInfo.wIdent == nArea)) pdx->bXFerWaiting = false; // Cannot have pending xfer if area cleared
pdx->bXFerWaiting = false; // Cannot have pending xfer if area cleared
// Clean out the TRANSAREA except for the wait queue, which is at the end
// Clean out the TRANSAREA except for the wait queue, which is at the end // This sets bUsed to false and dwEventSz to 0 to say area not used and no events.
// This sets bUsed to false and dwEventSz to 0 to say area not used and no events. memset(pTA, 0,
memset(pTA, 0, sizeof(TRANSAREA)-sizeof(wait_queue_head_t)); sizeof(TRANSAREA) -
} sizeof(wait_queue_head_t));
spin_unlock_irq(&pdx->stagedLock); }
spin_unlock_irq(&pdx->stagedLock);
if (pPages) // if we decided to release the memory
{ if (pPages) // if we decided to release the memory
// Now we must undo the pinning down of the pages. We will assume the worst and mark {
// all the pages as dirty. Don't be tempted to move this up above as you must not be // Now we must undo the pinning down of the pages. We will assume the worst and mark
// holding a spin lock to do this stuff as it is not atomic. // all the pages as dirty. Don't be tempted to move this up above as you must not be
dev_dbg(&pdx->interface->dev, "%s nPages=%d", __func__, nPages); // holding a spin lock to do this stuff as it is not atomic.
dev_dbg(&pdx->interface->dev, "%s nPages=%d",
for (np = 0; np < nPages; ++np) __func__, nPages);
{
if (pPages[np]) for (np = 0; np < nPages; ++np) {
{ if (pPages[np]) {
SetPageDirty(pPages[np]); SetPageDirty(pPages[np]);
page_cache_release(pPages[np]); page_cache_release(pPages[np]);
} }
} }
kfree(pPages); kfree(pPages);
dev_dbg(&pdx->interface->dev, "%s kfree(pPages) done", __func__); dev_dbg(&pdx->interface->dev,
} "%s kfree(pPages) done", __func__);
} }
} }
}
return iReturn;
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -669,78 +673,78 @@ int ClearArea(DEVICE_EXTENSION *pdx, int nArea) ...@@ -669,78 +673,78 @@ int ClearArea(DEVICE_EXTENSION *pdx, int nArea)
** Sets up a transfer area - the functional part. Called by both ** Sets up a transfer area - the functional part. Called by both
** SetTransfer and SetCircular. ** SetTransfer and SetCircular.
****************************************************************************/ ****************************************************************************/
static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf, static int SetArea(DEVICE_EXTENSION * pdx, int nArea, char __user * puBuf,
unsigned int dwLength, bool bCircular, bool bCircToHost) unsigned int dwLength, bool bCircular, bool bCircToHost)
{ {
// Start by working out the page aligned start of the area and the size // Start by working out the page aligned start of the area and the size
// of the area in pages, allowing for the start not being aligned and the // of the area in pages, allowing for the start not being aligned and the
// end needing to be rounded up to a page boundary. // end needing to be rounded up to a page boundary.
unsigned long ulStart = ((unsigned long)puBuf) & PAGE_MASK; unsigned long ulStart = ((unsigned long)puBuf) & PAGE_MASK;
unsigned int ulOffset = ((unsigned long)puBuf) & (PAGE_SIZE-1); unsigned int ulOffset = ((unsigned long)puBuf) & (PAGE_SIZE - 1);
int len = (dwLength + ulOffset+PAGE_SIZE - 1) >> PAGE_SHIFT; int len = (dwLength + ulOffset + PAGE_SIZE - 1) >> PAGE_SHIFT;
TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing
struct page **pPages = 0; // space for page tables struct page **pPages = 0; // space for page tables
int nPages = 0; // and number of pages int nPages = 0; // and number of pages
int iReturn = ClearArea(pdx, nArea); // see if OK to use this area int iReturn = ClearArea(pdx, nArea); // see if OK to use this area
if ((iReturn != U14ERR_NOTSET) && // if not area unused and... if ((iReturn != U14ERR_NOTSET) && // if not area unused and...
(iReturn != U14ERR_NOERROR)) // ...not all OK, then... (iReturn != U14ERR_NOERROR)) // ...not all OK, then...
return iReturn; // ...we cannot use this area return iReturn; // ...we cannot use this area
if (!access_ok(VERIFY_WRITE, puBuf, dwLength)) // if we cannot access the memory... if (!access_ok(VERIFY_WRITE, puBuf, dwLength)) // if we cannot access the memory...
return -EFAULT; // ...then we are done return -EFAULT; // ...then we are done
// Now allocate space to hold the page pointer and virtual address pointer tables // Now allocate space to hold the page pointer and virtual address pointer tables
pPages = (struct page **)kmalloc(len*sizeof(struct page *), GFP_KERNEL); pPages =
if (!pPages) (struct page **)kmalloc(len * sizeof(struct page *), GFP_KERNEL);
{ if (!pPages) {
iReturn = U14ERR_NOMEMORY; iReturn = U14ERR_NOMEMORY;
goto error; goto error;
} }
dev_dbg(&pdx->interface->dev, "%s %p, length=%06x, circular %d", __func__, puBuf, dwLength, bCircular); dev_dbg(&pdx->interface->dev, "%s %p, length=%06x, circular %d",
__func__, puBuf, dwLength, bCircular);
// To pin down user pages we must first acquire the mapping semaphore.
down_read(&current->mm->mmap_sem); // get memory map semaphore // To pin down user pages we must first acquire the mapping semaphore.
nPages = get_user_pages(current, current->mm, ulStart, len, 1, 0, pPages, 0); down_read(&current->mm->mmap_sem); // get memory map semaphore
up_read(&current->mm->mmap_sem); // release the semaphore nPages =
dev_dbg(&pdx->interface->dev, "%s nPages = %d", __func__, nPages); get_user_pages(current, current->mm, ulStart, len, 1, 0, pPages, 0);
up_read(&current->mm->mmap_sem); // release the semaphore
if (nPages > 0) // if we succeeded dev_dbg(&pdx->interface->dev, "%s nPages = %d", __func__, nPages);
{
// If you are tempted to use page_address (form LDD3), forget it. You MUST use if (nPages > 0) // if we succeeded
// kmap() or kmap_atomic() to get a virtual address. page_address will give you {
// (null) or at least it does in this context with an x86 machine. // If you are tempted to use page_address (form LDD3), forget it. You MUST use
spin_lock_irq(&pdx->stagedLock); // kmap() or kmap_atomic() to get a virtual address. page_address will give you
pTA->lpvBuff = puBuf; // keep start of region (user address) // (null) or at least it does in this context with an x86 machine.
pTA->dwBaseOffset = ulOffset; // save offset in first page to start of xfer spin_lock_irq(&pdx->stagedLock);
pTA->dwLength = dwLength; // Size if the region in bytes pTA->lpvBuff = puBuf; // keep start of region (user address)
pTA->pPages = pPages; // list of pages that are used by buffer pTA->dwBaseOffset = ulOffset; // save offset in first page to start of xfer
pTA->nPages = nPages; // number of pages pTA->dwLength = dwLength; // Size if the region in bytes
pTA->pPages = pPages; // list of pages that are used by buffer
pTA->bCircular = bCircular; pTA->nPages = nPages; // number of pages
pTA->bCircToHost = bCircToHost;
pTA->bCircular = bCircular;
pTA->aBlocks[0].dwOffset = 0; pTA->bCircToHost = bCircToHost;
pTA->aBlocks[0].dwSize = 0;
pTA->aBlocks[1].dwOffset = 0; pTA->aBlocks[0].dwOffset = 0;
pTA->aBlocks[1].dwSize = 0; pTA->aBlocks[0].dwSize = 0;
pTA->bUsed = true; // This is now a used block pTA->aBlocks[1].dwOffset = 0;
pTA->aBlocks[1].dwSize = 0;
spin_unlock_irq(&pdx->stagedLock); pTA->bUsed = true; // This is now a used block
iReturn = U14ERR_NOERROR; // say all was well
} spin_unlock_irq(&pdx->stagedLock);
else iReturn = U14ERR_NOERROR; // say all was well
{ } else {
iReturn = U14ERR_LOCKFAIL; iReturn = U14ERR_LOCKFAIL;
goto error; goto error;
} }
return iReturn; return iReturn;
error: error:
kfree(pPages); kfree(pPages);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -750,32 +754,36 @@ static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf, ...@@ -750,32 +754,36 @@ static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf,
** unset it. Unsetting will fail if the area is booked, and a transfer to that ** unset it. Unsetting will fail if the area is booked, and a transfer to that
** area is in progress. Otherwise, we will release the area and re-assign it. ** area is in progress. Otherwise, we will release the area and re-assign it.
****************************************************************************/ ****************************************************************************/
int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) int SetTransfer(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD)
{ {
int iReturn; int iReturn;
TRANSFERDESC td; TRANSFERDESC td;
copy_from_user(&td, pTD, sizeof(td)); copy_from_user(&td, pTD, sizeof(td));
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev,"%s area:%d, size:%08x", __func__, td.wAreaNum, td.dwLength); dev_dbg(&pdx->interface->dev, "%s area:%d, size:%08x", __func__,
// The strange cast is done so that we don't get warnings in 32-bit linux about the size of the td.wAreaNum, td.dwLength);
// pointer. The pointer is always passed as a 64-bit object so that we don't have problems using // The strange cast is done so that we don't get warnings in 32-bit linux about the size of the
// a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. // pointer. The pointer is always passed as a 64-bit object so that we don't have problems using
iReturn = SetArea(pdx, td.wAreaNum, (char __user *)((unsigned long)td.lpvBuff), td.dwLength, false, false); // a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system.
mutex_unlock(&pdx->io_mutex); iReturn =
return iReturn; SetArea(pdx, td.wAreaNum,
(char __user *)((unsigned long)td.lpvBuff), td.dwLength,
false, false);
mutex_unlock(&pdx->io_mutex);
return iReturn;
} }
/**************************************************************************** /****************************************************************************
** UnSetTransfer ** UnSetTransfer
** Erases a transfer area record ** Erases a transfer area record
****************************************************************************/ ****************************************************************************/
int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea) int UnsetTransfer(DEVICE_EXTENSION * pdx, int nArea)
{ {
int iReturn; int iReturn;
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
iReturn = ClearArea(pdx, nArea); iReturn = ClearArea(pdx, nArea);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -786,31 +794,30 @@ int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea) ...@@ -786,31 +794,30 @@ int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea)
** pretend that whatever the user asked for was achieved, so we return 1 if ** pretend that whatever the user asked for was achieved, so we return 1 if
** try to create one, and 0 if they ask to remove (assuming all else was OK). ** try to create one, and 0 if they ask to remove (assuming all else was OK).
****************************************************************************/ ****************************************************************************/
int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE) int SetEvent(DEVICE_EXTENSION * pdx, TRANSFEREVENT __user * pTE)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
TRANSFEREVENT te; TRANSFEREVENT te;
copy_from_user(&te, pTE, sizeof(te)); // get a local copy of the data copy_from_user(&te, pTE, sizeof(te)); // get a local copy of the data
if (te.wAreaNum >= MAX_TRANSAREAS) // the area must exist if (te.wAreaNum >= MAX_TRANSAREAS) // the area must exist
return U14ERR_BADAREA; return U14ERR_BADAREA;
else else {
{ TRANSAREA *pTA = &pdx->rTransDef[te.wAreaNum];
TRANSAREA *pTA = &pdx->rTransDef[te.wAreaNum]; mutex_lock(&pdx->io_mutex); // make sure we have no competitor
mutex_lock(&pdx->io_mutex); // make sure we have no competitor spin_lock_irq(&pdx->stagedLock);
spin_lock_irq(&pdx->stagedLock); if (pTA->bUsed) // area must be in use
if (pTA->bUsed) // area must be in use {
{ pTA->dwEventSt = te.dwStart; // set area regions
pTA->dwEventSt = te.dwStart; // set area regions pTA->dwEventSz = te.dwLength; // set size (0 cancels it)
pTA->dwEventSz = te.dwLength; // set size (0 cancels it) pTA->bEventToHost = te.wFlags & 1; // set the direction
pTA->bEventToHost = te.wFlags & 1; // set the direction pTA->iWakeUp = 0; // zero the wake up count
pTA->iWakeUp = 0; // zero the wake up count } else
} iReturn = U14ERR_NOTSET;
else spin_unlock_irq(&pdx->stagedLock);
iReturn = U14ERR_NOTSET; mutex_unlock(&pdx->io_mutex);
spin_unlock_irq(&pdx->stagedLock); }
mutex_unlock(&pdx->io_mutex); return iReturn ==
} U14ERR_NOERROR ? (te.iSetEvent ? 1 : U14ERR_NOERROR) : iReturn;
return iReturn == U14ERR_NOERROR ? (te.iSetEvent ? 1 : U14ERR_NOERROR) : iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -819,40 +826,45 @@ int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE) ...@@ -819,40 +826,45 @@ int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE)
** of times that a block met the event condition since we last cleared it or ** of times that a block met the event condition since we last cleared it or
** 0 if timed out, or -ve error (bad area or not set, or signal). ** 0 if timed out, or -ve error (bad area or not set, or signal).
****************************************************************************/ ****************************************************************************/
int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut) int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut)
{ {
int iReturn; int iReturn;
if ((unsigned)nArea > MAX_TRANSAREAS) if ((unsigned)nArea > MAX_TRANSAREAS)
return U14ERR_BADAREA; return U14ERR_BADAREA;
else else {
{ int iWait;
int iWait; TRANSAREA *pTA = &pdx->rTransDef[nArea];
TRANSAREA *pTA = &pdx->rTransDef[nArea]; msTimeOut = (msTimeOut * HZ + 999) / 1000; // convert timeout to jiffies
msTimeOut = (msTimeOut * HZ + 999)/1000; // convert timeout to jiffies
// We cannot wait holding the mutex, but we check the flags while holding
// We cannot wait holding the mutex, but we check the flags while holding // it. This may well be pointless as another thread could get in between
// it. This may well be pointless as another thread could get in between // releasing it and the wait call. However, this would have to clear the
// releasing it and the wait call. However, this would have to clear the // iWakeUp flag. However, the !pTA-bUsed may help us in this case.
// iWakeUp flag. However, the !pTA-bUsed may help us in this case. mutex_lock(&pdx->io_mutex); // make sure we have no competitor
mutex_lock(&pdx->io_mutex); // make sure we have no competitor if (!pTA->bUsed || !pTA->dwEventSz) // check something to wait for...
if (!pTA->bUsed || !pTA->dwEventSz) // check something to wait for... return U14ERR_NOTSET; // ...else we do nothing
return U14ERR_NOTSET; // ...else we do nothing mutex_unlock(&pdx->io_mutex);
mutex_unlock(&pdx->io_mutex);
if (msTimeOut)
if (msTimeOut) iWait =
iWait = wait_event_interruptible_timeout(pTA->wqEvent, pTA->iWakeUp || !pTA->bUsed, msTimeOut); wait_event_interruptible_timeout(pTA->wqEvent,
else pTA->iWakeUp
iWait = wait_event_interruptible(pTA->wqEvent, pTA->iWakeUp || !pTA->bUsed); || !pTA->bUsed,
if (iWait) msTimeOut);
iReturn = -ERESTARTSYS; // oops - we have had a SIGNAL else
else iWait =
iReturn = pTA->iWakeUp; // else the wakeup count wait_event_interruptible(pTA->wqEvent, pTA->iWakeUp
|| !pTA->bUsed);
spin_lock_irq(&pdx->stagedLock); if (iWait)
pTA->iWakeUp = 0; // clear the flag iReturn = -ERESTARTSYS; // oops - we have had a SIGNAL
spin_unlock_irq(&pdx->stagedLock); else
} iReturn = pTA->iWakeUp; // else the wakeup count
return iReturn;
spin_lock_irq(&pdx->stagedLock);
pTA->iWakeUp = 0; // clear the flag
spin_unlock_irq(&pdx->stagedLock);
}
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -861,52 +873,51 @@ int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut) ...@@ -861,52 +873,51 @@ int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut)
** number of times a block completed since the last call, or 0 if none or a ** number of times a block completed since the last call, or 0 if none or a
** negative error. ** negative error.
****************************************************************************/ ****************************************************************************/
int TestEvent(DEVICE_EXTENSION *pdx, int nArea) int TestEvent(DEVICE_EXTENSION * pdx, int nArea)
{ {
int iReturn; int iReturn;
if ((unsigned)nArea > MAX_TRANSAREAS) if ((unsigned)nArea > MAX_TRANSAREAS)
iReturn = U14ERR_BADAREA; iReturn = U14ERR_BADAREA;
else else {
{ TRANSAREA *pTA = &pdx->rTransDef[nArea];
TRANSAREA *pTA = &pdx->rTransDef[nArea]; mutex_lock(&pdx->io_mutex); // make sure we have no competitor
mutex_lock(&pdx->io_mutex); // make sure we have no competitor spin_lock_irq(&pdx->stagedLock);
spin_lock_irq(&pdx->stagedLock); iReturn = pTA->iWakeUp; // get wakeup count since last call
iReturn = pTA->iWakeUp; // get wakeup count since last call pTA->iWakeUp = 0; // clear the count
pTA->iWakeUp = 0; // clear the count spin_unlock_irq(&pdx->stagedLock);
spin_unlock_irq(&pdx->stagedLock); mutex_unlock(&pdx->io_mutex);
mutex_unlock(&pdx->io_mutex); }
} return iReturn;
return iReturn;
} }
/**************************************************************************** /****************************************************************************
** GetTransferInfo ** GetTransferInfo
** Puts the current state of the 1401 in a TGET_TX_BLOCK. ** Puts the current state of the 1401 in a TGET_TX_BLOCK.
*****************************************************************************/ *****************************************************************************/
int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX) int GetTransfer(DEVICE_EXTENSION * pdx, TGET_TX_BLOCK __user * pTX)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
unsigned int dwIdent; unsigned int dwIdent;
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dwIdent = pdx->StagedId; // area ident for last xfer dwIdent = pdx->StagedId; // area ident for last xfer
if (dwIdent >= MAX_TRANSAREAS) if (dwIdent >= MAX_TRANSAREAS)
iReturn = U14ERR_BADAREA; iReturn = U14ERR_BADAREA;
else else {
{ // Return the best information we have - we don't have physical addresses
// Return the best information we have - we don't have physical addresses TGET_TX_BLOCK tx;
TGET_TX_BLOCK tx; memset(&tx, 0, sizeof(tx)); // clean out local work structure
memset(&tx, 0, sizeof(tx)); // clean out local work structure tx.size = pdx->rTransDef[dwIdent].dwLength;
tx.size = pdx->rTransDef[dwIdent].dwLength; tx.linear = (long long)((long)pdx->rTransDef[dwIdent].lpvBuff);
tx.linear = (long long)((long)pdx->rTransDef[dwIdent].lpvBuff); tx.avail = GET_TX_MAXENTRIES; // how many blocks we could return
tx.avail = GET_TX_MAXENTRIES; // how many blocks we could return tx.used = 1; // number we actually return
tx.used = 1; // number we actually return tx.entries[0].physical =
tx.entries[0].physical = (long long)(tx.linear+pdx->StagedOffset); (long long)(tx.linear + pdx->StagedOffset);
tx.entries[0].size = tx.size; tx.entries[0].size = tx.size;
copy_to_user(pTX, &tx, sizeof(tx)); copy_to_user(pTX, &tx, sizeof(tx));
} }
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -914,14 +925,14 @@ int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX) ...@@ -914,14 +925,14 @@ int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX)
** **
** Empties the host i/o buffers ** Empties the host i/o buffers
****************************************************************************/ ****************************************************************************/
int KillIO1401(DEVICE_EXTENSION *pdx) int KillIO1401(DEVICE_EXTENSION * pdx)
{ {
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
FlushOutBuff(pdx); FlushOutBuff(pdx);
FlushInBuff(pdx); FlushInBuff(pdx);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return U14ERR_NOERROR; return U14ERR_NOERROR;
} }
/**************************************************************************** /****************************************************************************
...@@ -929,11 +940,11 @@ int KillIO1401(DEVICE_EXTENSION *pdx) ...@@ -929,11 +940,11 @@ int KillIO1401(DEVICE_EXTENSION *pdx)
** Returns a 0 or a 1 for whether DMA is happening. No point holding a mutex ** Returns a 0 or a 1 for whether DMA is happening. No point holding a mutex
** for this as it only does one read. ** for this as it only does one read.
*****************************************************************************/ *****************************************************************************/
int BlkTransState(DEVICE_EXTENSION *pdx) int BlkTransState(DEVICE_EXTENSION * pdx)
{ {
int iReturn = pdx->dwDMAFlag != MODE_CHAR; int iReturn = pdx->dwDMAFlag != MODE_CHAR;
dev_dbg(&pdx->interface->dev, "%s = %d", __func__, iReturn); dev_dbg(&pdx->interface->dev, "%s = %d", __func__, iReturn);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -941,121 +952,121 @@ int BlkTransState(DEVICE_EXTENSION *pdx) ...@@ -941,121 +952,121 @@ int BlkTransState(DEVICE_EXTENSION *pdx)
** **
** Puts the current state of the 1401 in the Irp return buffer. ** Puts the current state of the 1401 in the Irp return buffer.
*****************************************************************************/ *****************************************************************************/
int StateOf1401(DEVICE_EXTENSION *pdx) int StateOf1401(DEVICE_EXTENSION * pdx)
{ {
int iReturn; int iReturn;
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
QuickCheck(pdx, false, false); // get state up to date, no reset QuickCheck(pdx, false, false); // get state up to date, no reset
iReturn = pdx->sCurrentState; iReturn = pdx->sCurrentState;
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s = %d", __func__, iReturn); dev_dbg(&pdx->interface->dev, "%s = %d", __func__, iReturn);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** StartSelfTest ** StartSelfTest
** **
** Initiates a self-test cycle. The assumption is that we have no interrupts ** Initiates a self-test cycle. The assumption is that we have no interrupts
** active, so we should make sure that this is the case. ** active, so we should make sure that this is the case.
*****************************************************************************/ *****************************************************************************/
int StartSelfTest(DEVICE_EXTENSION *pdx) int StartSelfTest(DEVICE_EXTENSION * pdx)
{ {
int nGot; int nGot;
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
ced_draw_down(pdx); // wait for, then kill outstanding Urbs ced_draw_down(pdx); // wait for, then kill outstanding Urbs
FlushInBuff(pdx); // Clear out input buffer & pipe FlushInBuff(pdx); // Clear out input buffer & pipe
FlushOutBuff(pdx); // Clear output buffer & pipe FlushOutBuff(pdx); // Clear output buffer & pipe
// ReadWrite_Cancel(pDeviceObject); /* so things stay tidy */ // ReadWrite_Cancel(pDeviceObject); /* so things stay tidy */
pdx->dwDMAFlag = MODE_CHAR; /* Clear DMA mode flags here */ pdx->dwDMAFlag = MODE_CHAR; /* Clear DMA mode flags here */
nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), DB_SELFTEST, (H_TO_D | VENDOR | DEVREQ), 0, 0, 0, 0, HZ); // allow 1 second timeout
DB_SELFTEST, (H_TO_D|VENDOR|DEVREQ), 0, 0, pdx->ulSelfTestTime = jiffies + HZ * 30; // 30 seconds into the future
0, 0, HZ); // allow 1 second timeout
pdx->ulSelfTestTime = jiffies + HZ*30; // 30 seconds into the future
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
if (nGot < 0) if (nGot < 0)
dev_err(&pdx->interface->dev, "%s err=%d", __func__, nGot); dev_err(&pdx->interface->dev, "%s err=%d", __func__, nGot);
return nGot < 0 ? U14ERR_FAIL : U14ERR_NOERROR; return nGot < 0 ? U14ERR_FAIL : U14ERR_NOERROR;
} }
/**************************************************************************** /****************************************************************************
** CheckSelfTest ** CheckSelfTest
** **
** Check progress of a self-test cycle ** Check progress of a self-test cycle
****************************************************************************/ ****************************************************************************/
int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST) int CheckSelfTest(DEVICE_EXTENSION * pdx, TGET_SELFTEST __user * pGST)
{ {
unsigned int state, error; unsigned int state, error;
int iReturn; int iReturn;
TGET_SELFTEST gst; // local work space TGET_SELFTEST gst; // local work space
memset(&gst, 0, sizeof(gst)); // clear out the space (sets code 0) memset(&gst, 0, sizeof(gst)); // clear out the space (sets code 0)
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
iReturn = Get1401State(pdx, &state, &error); iReturn = Get1401State(pdx, &state, &error);
if (iReturn == U14ERR_NOERROR) // Only accept zero if it happens twice if (iReturn == U14ERR_NOERROR) // Only accept zero if it happens twice
iReturn = Get1401State(pdx, &state, &error); iReturn = Get1401State(pdx, &state, &error);
if (iReturn != U14ERR_NOERROR) // Self-test can cause comms errors if (iReturn != U14ERR_NOERROR) // Self-test can cause comms errors
{ // so we assume still testing { // so we assume still testing
dev_err(&pdx->interface->dev, "%s Get1401State=%d, assuming still testing", __func__, iReturn); dev_err(&pdx->interface->dev,
state = 0x80; // Force still-testing, no error "%s Get1401State=%d, assuming still testing", __func__,
error = 0; iReturn);
iReturn = U14ERR_NOERROR; state = 0x80; // Force still-testing, no error
} error = 0;
iReturn = U14ERR_NOERROR;
if ((state == -1) && (error == -1)) // If Get1401State had problems }
{
dev_err(&pdx->interface->dev, "%s Get1401State failed, assuming still testing", __func__); if ((state == -1) && (error == -1)) // If Get1401State had problems
state = 0x80; // Force still-testing, no error {
error = 0; dev_err(&pdx->interface->dev,
} "%s Get1401State failed, assuming still testing",
__func__);
if ((state & 0xFF) == 0x80) // If we are still in self-test state = 0x80; // Force still-testing, no error
{ error = 0;
if (state & 0x00FF0000) // Have we got an error? }
{
gst.code = (state & 0x00FF0000) >> 16; // read the error code if ((state & 0xFF) == 0x80) // If we are still in self-test
gst.x = error & 0x0000FFFF; // Error data X {
gst.y = (error & 0xFFFF0000) >> 16; // and data Y if (state & 0x00FF0000) // Have we got an error?
dev_dbg(&pdx->interface->dev,"Self-test error code %d", gst.code); {
} gst.code = (state & 0x00FF0000) >> 16; // read the error code
else // No error, check for timeout gst.x = error & 0x0000FFFF; // Error data X
{ gst.y = (error & 0xFFFF0000) >> 16; // and data Y
unsigned long ulNow = jiffies; // get current time dev_dbg(&pdx->interface->dev, "Self-test error code %d",
if (time_after(ulNow, pdx->ulSelfTestTime)) gst.code);
{ } else // No error, check for timeout
gst.code = -2; // Flag the timeout {
dev_dbg(&pdx->interface->dev, "Self-test timed-out"); unsigned long ulNow = jiffies; // get current time
} if (time_after(ulNow, pdx->ulSelfTestTime)) {
else gst.code = -2; // Flag the timeout
dev_dbg(&pdx->interface->dev, "Self-test on-going"); dev_dbg(&pdx->interface->dev,
} "Self-test timed-out");
} } else
else dev_dbg(&pdx->interface->dev,
{ "Self-test on-going");
gst.code = -1; // Flag the test is done }
dev_dbg(&pdx->interface->dev, "Self-test done"); } else {
} gst.code = -1; // Flag the test is done
dev_dbg(&pdx->interface->dev, "Self-test done");
if (gst.code < 0) // If we have a problem or finished }
{ // If using the 2890 we should reset properly
if ((pdx->nPipes == 4) && (pdx->s1401Type <= TYPEPOWER)) if (gst.code < 0) // If we have a problem or finished
Is1401(pdx); // Get 1401 reset and OK { // If using the 2890 we should reset properly
else if ((pdx->nPipes == 4) && (pdx->s1401Type <= TYPEPOWER))
QuickCheck(pdx, true, true); // Otherwise check without reset unless problems Is1401(pdx); // Get 1401 reset and OK
} else
mutex_unlock(&pdx->io_mutex); QuickCheck(pdx, true, true); // Otherwise check without reset unless problems
}
copy_to_user(pGST, &gst, sizeof(gst)); // copy result to user space mutex_unlock(&pdx->io_mutex);
return iReturn;
copy_to_user(pGST, &gst, sizeof(gst)); // copy result to user space
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -1063,28 +1074,32 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST) ...@@ -1063,28 +1074,32 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST)
** **
** Returns code for standard, plus, micro1401, power1401 or none ** Returns code for standard, plus, micro1401, power1401 or none
****************************************************************************/ ****************************************************************************/
int TypeOf1401(DEVICE_EXTENSION *pdx) int TypeOf1401(DEVICE_EXTENSION * pdx)
{ {
int iReturn = TYPEUNKNOWN; int iReturn = TYPEUNKNOWN;
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
switch (pdx->s1401Type) switch (pdx->s1401Type) {
{ case TYPE1401:
case TYPE1401: iReturn = U14ERR_STD; break; // Handle these types directly iReturn = U14ERR_STD;
case TYPEPLUS: iReturn = U14ERR_PLUS; break; break; // Handle these types directly
case TYPEU1401:iReturn = U14ERR_U1401;break; case TYPEPLUS:
default: iReturn = U14ERR_PLUS;
if ((pdx->s1401Type >= TYPEPOWER) && break;
(pdx->s1401Type <= 25)) case TYPEU1401:
iReturn = pdx->s1401Type + 4; // We can calculate types iReturn = U14ERR_U1401;
else // for up-coming 1401 designs break;
iReturn = TYPEUNKNOWN; // Don't know or not there default:
} if ((pdx->s1401Type >= TYPEPOWER) && (pdx->s1401Type <= 25))
dev_dbg(&pdx->interface->dev, "%s %d", __func__, iReturn); iReturn = pdx->s1401Type + 4; // We can calculate types
mutex_unlock(&pdx->io_mutex); else // for up-coming 1401 designs
iReturn = TYPEUNKNOWN; // Don't know or not there
return iReturn; }
dev_dbg(&pdx->interface->dev, "%s %d", __func__, iReturn);
mutex_unlock(&pdx->io_mutex);
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -1092,17 +1107,17 @@ int TypeOf1401(DEVICE_EXTENSION *pdx) ...@@ -1092,17 +1107,17 @@ int TypeOf1401(DEVICE_EXTENSION *pdx)
** **
** Returns flags on block transfer abilities ** Returns flags on block transfer abilities
****************************************************************************/ ****************************************************************************/
int TransferFlags(DEVICE_EXTENSION *pdx) int TransferFlags(DEVICE_EXTENSION * pdx)
{ {
int iReturn = U14TF_MULTIA | U14TF_DIAG | // we always have multiple DMA area int iReturn = U14TF_MULTIA | U14TF_DIAG | // we always have multiple DMA area
U14TF_NOTIFY | U14TF_CIRCTH; // diagnostics, notify and circular U14TF_NOTIFY | U14TF_CIRCTH; // diagnostics, notify and circular
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
if (pdx->bIsUSB2) // Set flag for USB2 if appropriate if (pdx->bIsUSB2) // Set flag for USB2 if appropriate
iReturn |= U14TF_USB2; iReturn |= U14TF_USB2;
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/*************************************************************************** /***************************************************************************
...@@ -1110,18 +1125,17 @@ int TransferFlags(DEVICE_EXTENSION *pdx) ...@@ -1110,18 +1125,17 @@ int TransferFlags(DEVICE_EXTENSION *pdx)
** Issues a debug\diagnostic command to the 1401 along with a 32-bit datum ** Issues a debug\diagnostic command to the 1401 along with a 32-bit datum
** This is a utility command used for dbg operations. ** This is a utility command used for dbg operations.
*/ */
static int DbgCmd1401(DEVICE_EXTENSION *pdx, unsigned char cmd, unsigned int data) static int DbgCmd1401(DEVICE_EXTENSION * pdx, unsigned char cmd,
unsigned int data)
{ {
int iReturn; int iReturn;
dev_dbg(&pdx->interface->dev, "%s entry", __func__); dev_dbg(&pdx->interface->dev, "%s entry", __func__);
iReturn = usb_control_msg(pdx->udev, usb_sndctrlpipe(pdx->udev, 0), iReturn = usb_control_msg(pdx->udev, usb_sndctrlpipe(pdx->udev, 0), cmd, (H_TO_D | VENDOR | DEVREQ), (unsigned short)data, (unsigned short)(data >> 16), 0, 0, HZ); // allow 1 second timeout
cmd, (H_TO_D|VENDOR|DEVREQ), if (iReturn < 0)
(unsigned short)data, (unsigned short)(data >> 16), dev_err(&pdx->interface->dev, "%s fail code=%d", __func__,
0, 0, HZ); // allow 1 second timeout iReturn);
if (iReturn < 0)
dev_err(&pdx->interface->dev, "%s fail code=%d", __func__, iReturn); return iReturn;
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -1129,146 +1143,141 @@ static int DbgCmd1401(DEVICE_EXTENSION *pdx, unsigned char cmd, unsigned int dat ...@@ -1129,146 +1143,141 @@ static int DbgCmd1401(DEVICE_EXTENSION *pdx, unsigned char cmd, unsigned int dat
** **
** Execute the diagnostic peek operation. Uses address, width and repeats. ** Execute the diagnostic peek operation. Uses address, width and repeats.
****************************************************************************/ ****************************************************************************/
int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user* pDB) int DbgPeek(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB)
{ {
int iReturn; int iReturn;
TDBGBLOCK db; TDBGBLOCK db;
copy_from_user(&db, pDB, sizeof(db)); // get the data copy_from_user(&db, pDB, sizeof(db)); // get the data
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s @ %08x", __func__, db.iAddr); dev_dbg(&pdx->interface->dev, "%s @ %08x", __func__, db.iAddr);
iReturn = DbgCmd1401(pdx, DB_SETADD, db.iAddr); iReturn = DbgCmd1401(pdx, DB_SETADD, db.iAddr);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth); iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats); iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_PEEK, 0); iReturn = DbgCmd1401(pdx, DB_PEEK, 0);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** DbgPoke ** DbgPoke
** **
** Execute the diagnostic poke operation. Parameters are in the CSBLOCK struct ** Execute the diagnostic poke operation. Parameters are in the CSBLOCK struct
** in order address, size, repeats and value to poke. ** in order address, size, repeats and value to poke.
****************************************************************************/ ****************************************************************************/
int DbgPoke(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) int DbgPoke(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB)
{ {
int iReturn; int iReturn;
TDBGBLOCK db; TDBGBLOCK db;
copy_from_user(&db, pDB, sizeof(db)); // get the data copy_from_user(&db, pDB, sizeof(db)); // get the data
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s @ %08x", __func__, db.iAddr); dev_dbg(&pdx->interface->dev, "%s @ %08x", __func__, db.iAddr);
iReturn = DbgCmd1401(pdx, DB_SETADD, db.iAddr); iReturn = DbgCmd1401(pdx, DB_SETADD, db.iAddr);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth); iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats); iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_POKE, db.iData); iReturn = DbgCmd1401(pdx, DB_POKE, db.iData);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** DbgRampData ** DbgRampData
** **
** Execute the diagnostic ramp data operation. Parameters are in the CSBLOCK struct ** Execute the diagnostic ramp data operation. Parameters are in the CSBLOCK struct
** in order address, default, enable mask, size and repeats. ** in order address, default, enable mask, size and repeats.
****************************************************************************/ ****************************************************************************/
int DbgRampData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) int DbgRampData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB)
{ {
int iReturn; int iReturn;
TDBGBLOCK db; TDBGBLOCK db;
copy_from_user(&db, pDB, sizeof(db)); // get the data copy_from_user(&db, pDB, sizeof(db)); // get the data
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s @ %08x", __func__, db.iAddr); dev_dbg(&pdx->interface->dev, "%s @ %08x", __func__, db.iAddr);
iReturn = DbgCmd1401(pdx, DB_SETADD, db.iAddr); iReturn = DbgCmd1401(pdx, DB_SETADD, db.iAddr);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_SETDEF, db.iDefault); iReturn = DbgCmd1401(pdx, DB_SETDEF, db.iDefault);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_SETMASK, db.iMask); iReturn = DbgCmd1401(pdx, DB_SETMASK, db.iMask);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth); iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats); iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_RAMPD, 0); iReturn = DbgCmd1401(pdx, DB_RAMPD, 0);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** DbgRampAddr ** DbgRampAddr
** **
** Execute the diagnostic ramp address operation ** Execute the diagnostic ramp address operation
****************************************************************************/ ****************************************************************************/
int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) int DbgRampAddr(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB)
{ {
int iReturn; int iReturn;
TDBGBLOCK db; TDBGBLOCK db;
copy_from_user(&db, pDB, sizeof(db)); // get the data copy_from_user(&db, pDB, sizeof(db)); // get the data
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
iReturn = DbgCmd1401(pdx, DB_SETDEF, db.iDefault); iReturn = DbgCmd1401(pdx, DB_SETDEF, db.iDefault);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_SETMASK, db.iMask); iReturn = DbgCmd1401(pdx, DB_SETMASK, db.iMask);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth); iReturn = DbgCmd1401(pdx, DB_WIDTH, db.iWidth);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats); iReturn = DbgCmd1401(pdx, DB_REPEATS, db.iRepeats);
if (iReturn == U14ERR_NOERROR) if (iReturn == U14ERR_NOERROR)
iReturn = DbgCmd1401(pdx, DB_RAMPA, 0); iReturn = DbgCmd1401(pdx, DB_RAMPA, 0);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** DbgGetData ** DbgGetData
** **
** Retrieve the data resulting from the last debug Peek operation ** Retrieve the data resulting from the last debug Peek operation
****************************************************************************/ ****************************************************************************/
int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) int DbgGetData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB)
{ {
int iReturn; int iReturn;
TDBGBLOCK db; TDBGBLOCK db;
memset(&db, 0, sizeof(db)); // fill returned block with 0s memset(&db, 0, sizeof(db)); // fill returned block with 0s
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
// Read back the last peeked value from the 1401. // Read back the last peeked value from the 1401.
iReturn = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), iReturn = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0),
DB_DATA, (D_TO_H|VENDOR|DEVREQ), 0,0, DB_DATA, (D_TO_H | VENDOR | DEVREQ), 0, 0,
&db.iData, sizeof(db.iData), HZ); &db.iData, sizeof(db.iData), HZ);
if (iReturn == sizeof(db.iData)) if (iReturn == sizeof(db.iData)) {
{ copy_to_user(pDB, &db, sizeof(db));
copy_to_user(pDB, &db, sizeof(db)); iReturn = U14ERR_NOERROR;
iReturn = U14ERR_NOERROR; } else
} dev_err(&pdx->interface->dev, "%s failed, code %d", __func__,
else iReturn);
dev_err(&pdx->interface->dev, "%s failed, code %d", __func__, iReturn);
mutex_unlock(&pdx->io_mutex);
mutex_unlock(&pdx->io_mutex);
return iReturn;
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -1277,20 +1286,19 @@ int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) ...@@ -1277,20 +1286,19 @@ int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB)
** Stop any never-ending debug loop, we just call Get1401State for USB ** Stop any never-ending debug loop, we just call Get1401State for USB
** **
****************************************************************************/ ****************************************************************************/
int DbgStopLoop(DEVICE_EXTENSION *pdx) int DbgStopLoop(DEVICE_EXTENSION * pdx)
{ {
int iReturn; int iReturn;
unsigned int uState, uErr; unsigned int uState, uErr;
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
iReturn = Get1401State(pdx, &uState, &uErr); iReturn = Get1401State(pdx, &uState, &uErr);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** SetCircular ** SetCircular
** **
...@@ -1299,22 +1307,26 @@ int DbgStopLoop(DEVICE_EXTENSION *pdx) ...@@ -1299,22 +1307,26 @@ int DbgStopLoop(DEVICE_EXTENSION *pdx)
** booked and a transfer to that area is in progress. Otherwise, we will ** booked and a transfer to that area is in progress. Otherwise, we will
** release the area and re-assign it. ** release the area and re-assign it.
****************************************************************************/ ****************************************************************************/
int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) int SetCircular(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD)
{ {
int iReturn; int iReturn;
bool bToHost; bool bToHost;
TRANSFERDESC td; TRANSFERDESC td;
copy_from_user(&td, pTD, sizeof(td)); copy_from_user(&td, pTD, sizeof(td));
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev,"%s area:%d, size:%08x", __func__, td.wAreaNum, td.dwLength); dev_dbg(&pdx->interface->dev, "%s area:%d, size:%08x", __func__,
bToHost = td.eSize != 0; // this is used as the tohost flag td.wAreaNum, td.dwLength);
bToHost = td.eSize != 0; // this is used as the tohost flag
// The strange cast is done so that we don't get warnings in 32-bit linux about the size of the
// pointer. The pointer is always passed as a 64-bit object so that we don't have problems using // The strange cast is done so that we don't get warnings in 32-bit linux about the size of the
// a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. // pointer. The pointer is always passed as a 64-bit object so that we don't have problems using
iReturn = SetArea(pdx, td.wAreaNum, (char __user *)((unsigned long)td.lpvBuff), td.dwLength, true, bToHost); // a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system.
mutex_unlock(&pdx->io_mutex); iReturn =
return iReturn; SetArea(pdx, td.wAreaNum,
(char __user *)((unsigned long)td.lpvBuff), td.dwLength,
true, bToHost);
mutex_unlock(&pdx->io_mutex);
return iReturn;
} }
/**************************************************************************** /****************************************************************************
...@@ -1322,140 +1334,145 @@ int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) ...@@ -1322,140 +1334,145 @@ int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD)
** **
** Return the next available block of circularly-transferred data. ** Return the next available block of circularly-transferred data.
****************************************************************************/ ****************************************************************************/
int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB) int GetCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
unsigned int nArea; unsigned int nArea;
TCIRCBLOCK cb; TCIRCBLOCK cb;
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
copy_from_user(&cb, pCB, sizeof(cb)); copy_from_user(&cb, pCB, sizeof(cb));
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
nArea = cb.nArea; // Retrieve parameters first nArea = cb.nArea; // Retrieve parameters first
cb.dwOffset = 0; // set default result (nothing) cb.dwOffset = 0; // set default result (nothing)
cb.dwSize = 0; cb.dwSize = 0;
if (nArea < MAX_TRANSAREAS) // The area number must be OK if (nArea < MAX_TRANSAREAS) // The area number must be OK
{ {
TRANSAREA* pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info TRANSAREA *pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info
spin_lock_irq(&pdx->stagedLock); // Lock others out spin_lock_irq(&pdx->stagedLock); // Lock others out
if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area
(pArea->bCircToHost)) // For now at least must be to host (pArea->bCircToHost)) // For now at least must be to host
{ {
if (pArea->aBlocks[0].dwSize > 0) // Got anything? if (pArea->aBlocks[0].dwSize > 0) // Got anything?
{ {
cb.dwOffset = pArea->aBlocks[0].dwOffset; cb.dwOffset = pArea->aBlocks[0].dwOffset;
cb.dwSize = pArea->aBlocks[0].dwSize; cb.dwSize = pArea->aBlocks[0].dwSize;
dev_dbg(&pdx->interface->dev, "%s return block 0: %d bytes at %d", __func__, cb.dwSize, cb.dwOffset); dev_dbg(&pdx->interface->dev,
} "%s return block 0: %d bytes at %d",
} __func__, cb.dwSize, cb.dwOffset);
else }
iReturn = U14ERR_NOTSET; } else
iReturn = U14ERR_NOTSET;
spin_unlock_irq(&pdx->stagedLock);
} spin_unlock_irq(&pdx->stagedLock);
else } else
iReturn = U14ERR_BADAREA; iReturn = U14ERR_BADAREA;
copy_to_user(pCB, &cb, sizeof(cb)); copy_to_user(pCB, &cb, sizeof(cb));
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** FreeCircBlock ** FreeCircBlock
** **
** Frees a block of circularly-transferred data and returns the next one. ** Frees a block of circularly-transferred data and returns the next one.
****************************************************************************/ ****************************************************************************/
int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB) int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
unsigned int nArea, uStart, uSize; unsigned int nArea, uStart, uSize;
TCIRCBLOCK cb; TCIRCBLOCK cb;
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
copy_from_user(&cb, pCB, sizeof(cb)); copy_from_user(&cb, pCB, sizeof(cb));
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
nArea = cb.nArea; // Retrieve parameters first nArea = cb.nArea; // Retrieve parameters first
uStart = cb.dwOffset; uStart = cb.dwOffset;
uSize = cb.dwSize; uSize = cb.dwSize;
cb.dwOffset = 0; // then set default result (nothing) cb.dwOffset = 0; // then set default result (nothing)
cb.dwSize = 0; cb.dwSize = 0;
if (nArea < MAX_TRANSAREAS) // The area number must be OK if (nArea < MAX_TRANSAREAS) // The area number must be OK
{ {
TRANSAREA* pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info TRANSAREA *pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info
spin_lock_irq(&pdx->stagedLock); // Lock others out spin_lock_irq(&pdx->stagedLock); // Lock others out
if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area
(pArea->bCircToHost)) // For now at least must be to host (pArea->bCircToHost)) // For now at least must be to host
{ {
bool bWaiting = false; bool bWaiting = false;
if ((pArea->aBlocks[0].dwSize >= uSize) && // Got anything? if ((pArea->aBlocks[0].dwSize >= uSize) && // Got anything?
(pArea->aBlocks[0].dwOffset == uStart)) // Must be legal data (pArea->aBlocks[0].dwOffset == uStart)) // Must be legal data
{ {
pArea->aBlocks[0].dwSize -= uSize; pArea->aBlocks[0].dwSize -= uSize;
pArea->aBlocks[0].dwOffset += uSize; pArea->aBlocks[0].dwOffset += uSize;
if (pArea->aBlocks[0].dwSize == 0) // Have we emptied this block? if (pArea->aBlocks[0].dwSize == 0) // Have we emptied this block?
{ {
if (pArea->aBlocks[1].dwSize) // Is there a second block? if (pArea->aBlocks[1].dwSize) // Is there a second block?
{ {
pArea->aBlocks[0] = pArea->aBlocks[1]; // Copy down block 2 data pArea->aBlocks[0] = pArea->aBlocks[1]; // Copy down block 2 data
pArea->aBlocks[1].dwSize = 0; // and mark the second block as unused pArea->aBlocks[1].dwSize = 0; // and mark the second block as unused
pArea->aBlocks[1].dwOffset = 0; pArea->aBlocks[1].dwOffset = 0;
} } else
else pArea->aBlocks[0].dwOffset = 0;
pArea->aBlocks[0].dwOffset = 0; }
}
dev_dbg(&pdx->interface->dev,
dev_dbg(&pdx->interface->dev, "%s free %d bytes at %d, return %d bytes at %d, wait=%d", "%s free %d bytes at %d, return %d bytes at %d, wait=%d",
__func__, uSize, uStart, pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset, pdx->bXFerWaiting); __func__, uSize, uStart,
pArea->aBlocks[0].dwSize,
// Return the next available block of memory as well pArea->aBlocks[0].dwOffset,
if (pArea->aBlocks[0].dwSize > 0) // Got anything? pdx->bXFerWaiting);
{
cb.dwOffset = pArea->aBlocks[0].dwOffset; // Return the next available block of memory as well
cb.dwSize = pArea->aBlocks[0].dwSize; if (pArea->aBlocks[0].dwSize > 0) // Got anything?
} {
cb.dwOffset =
bWaiting = pdx->bXFerWaiting; pArea->aBlocks[0].dwOffset;
if (bWaiting && pdx->bStagedUrbPending) cb.dwSize = pArea->aBlocks[0].dwSize;
{ }
dev_err(&pdx->interface->dev, "%s ERROR: waiting xfer and staged Urb pending!", __func__);
bWaiting = false; bWaiting = pdx->bXFerWaiting;
} if (bWaiting && pdx->bStagedUrbPending) {
} dev_err(&pdx->interface->dev,
else "%s ERROR: waiting xfer and staged Urb pending!",
{ __func__);
dev_err(&pdx->interface->dev, "%s ERROR: freeing %d bytes at %d, block 0 is %d bytes at %d", bWaiting = false;
__func__, uSize, uStart, pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset); }
iReturn = U14ERR_NOMEMORY; } else {
} dev_err(&pdx->interface->dev,
"%s ERROR: freeing %d bytes at %d, block 0 is %d bytes at %d",
// If we have one, kick off pending transfer __func__, uSize, uStart,
if (bWaiting) // Got a block xfer waiting? pArea->aBlocks[0].dwSize,
{ pArea->aBlocks[0].dwOffset);
int RWMStat = ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard, iReturn = U14ERR_NOMEMORY;
pdx->rDMAInfo.wIdent, pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize); }
if (RWMStat != U14ERR_NOERROR)
dev_err(&pdx->interface->dev, "%s rw setup failed %d", __func__, RWMStat); // If we have one, kick off pending transfer
} if (bWaiting) // Got a block xfer waiting?
} {
else int RWMStat =
iReturn = U14ERR_NOTSET; ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard,
pdx->rDMAInfo.wIdent,
spin_unlock_irq(&pdx->stagedLock); pdx->rDMAInfo.dwOffset,
} pdx->rDMAInfo.dwSize);
else if (RWMStat != U14ERR_NOERROR)
iReturn = U14ERR_BADAREA; dev_err(&pdx->interface->dev,
"%s rw setup failed %d",
copy_to_user(pCB, &cb, sizeof(cb)); __func__, RWMStat);
mutex_unlock(&pdx->io_mutex); }
return iReturn; } else
iReturn = U14ERR_NOTSET;
spin_unlock_irq(&pdx->stagedLock);
} else
iReturn = U14ERR_BADAREA;
copy_to_user(pCB, &cb, sizeof(cb));
mutex_unlock(&pdx->io_mutex);
return iReturn;
} }
/* ced_ioctl.h /*
IOCTL calls for the CED1401 driver * IOCTL calls for the CED1401 driver
Copyright (C) 2010 Cambridge Electronic Design Ltd * Copyright (C) 2010 Cambridge Electronic Design Ltd
Author Greg P Smith (greg@ced.co.uk) * Author Greg P Smith (greg@ced.co.uk)
*
This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
*
This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. * GNU General Public License for more details.
*/
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __CED_IOCTL_H__ #ifndef __CED_IOCTL_H__
#define __CED_IOCTL_H__ #define __CED_IOCTL_H__
#include <asm/ioctl.h>
/// dma modes, only MODE_CHAR and MODE_LINEAR are used in this driver #include <linux/ioctl.h>
#define MODE_CHAR 0
#define MODE_LINEAR 1 /* dma modes, only MODE_CHAR and MODE_LINEAR are used in this driver */
#define MODE_CHAR 0
#define MODE_LINEAR 1
/**************************************************************************** /****************************************************************************
** TypeDefs ** TypeDefs
*****************************************************************************/ *****************************************************************************/
typedef unsigned short TBLOCKENTRY; // index the blk transfer table 0-7 typedef unsigned short TBLOCKENTRY; /* index the blk transfer table 0-7 */
typedef struct TransferDesc typedef struct TransferDesc {
{ long long lpvBuff; /* address of transfer area (for 64 or 32 bit) */
long long lpvBuff; // address of transfer area (for 64 or 32 bit) unsigned int dwLength; /* length of the area */
unsigned int dwLength; // length of the area TBLOCKENTRY wAreaNum; /* number of transfer area to set up */
TBLOCKENTRY wAreaNum; // number of transfer area to set up short eSize; /* element size - is tohost flag for circular */
short eSize; // element size - is tohost flag for circular
} TRANSFERDESC; } TRANSFERDESC;
typedef TRANSFERDESC* LPTRANSFERDESC; typedef TRANSFERDESC * LPTRANSFERDESC;
typedef struct TransferEvent typedef struct TransferEvent {
{ unsigned int dwStart; /* offset into the area */
unsigned int dwStart; // offset into the area unsigned int dwLength; /* length of the region */
unsigned int dwLength; // length of the region unsigned short wAreaNum; /* the area number */
unsigned short wAreaNum; // the area number unsigned short wFlags; /* bit 0 set for toHost */
unsigned short wFlags; // bit 0 set for toHost int iSetEvent; /* could be dummy in LINUX */
int iSetEvent; // could be dummy in LINUX
} TRANSFEREVENT; } TRANSFEREVENT;
#define MAX_TRANSFER_SIZE 0x4000 /* Maximum data bytes per IRP */ #define MAX_TRANSFER_SIZE 0x4000 /* Maximum data bytes per IRP */
#define MAX_AREA_LENGTH 0x100000 /* Maximum size of transfer area */ #define MAX_AREA_LENGTH 0x100000 /* Maximum size of transfer area */
#define MAX_TRANSAREAS 8 /* definitions for dma set up */ #define MAX_TRANSAREAS 8 /* definitions for dma set up */
typedef struct TGetSelfTest typedef struct TGetSelfTest {
{ int code; /* self-test error code */
int code; // self-test error code int x, y; /* additional information */
int x,y; // additional information
} TGET_SELFTEST; } TGET_SELFTEST;
/// Debug block used for several commands. Not all fields are used for all commands. /* Debug block used for several commands. Not all fields are used for all commands. */
typedef struct TDbgBlock typedef struct TDbgBlock {
{ int iAddr; /* the address in the 1401 */
int iAddr; // the address in the 1401 int iRepeats; /* number of repeats */
int iRepeats; // number of repeats int iWidth; /* width in bytes 1, 2, 4 */
int iWidth; // width in bytes 1, 2, 4 int iDefault; /* default value */
int iDefault; // default value int iMask; /* mask to apply */
int iMask; // mask to apply int iData; /* data for poke, result for peek */
int iData; // data for poke, result for peek
} TDBGBLOCK; } TDBGBLOCK;
/// Used to collect information about a circular block from the device driver /* Used to collect information about a circular block from the device driver */
typedef struct TCircBlock typedef struct TCircBlock {
{ unsigned int nArea; /* the area to collect information from */
unsigned int nArea; // the area to collect information from unsigned int dwOffset; /* offset into the area to the available block */
unsigned int dwOffset; // offset into the area to the available block unsigned int dwSize; /* size of the area */
unsigned int dwSize; // size of the area
} TCIRCBLOCK; } TCIRCBLOCK;
/// Used to clollect the 1401 status /* Used to clollect the 1401 status */
typedef struct TCSBlock typedef struct TCSBlock {
{ unsigned int uiState;
unsigned int uiState; unsigned int uiError;
unsigned int uiError;
} TCSBLOCK; } TCSBLOCK;
// As seen by the user, an ioctl call looks like: /*
// int ioctl(int fd, unsigned long cmd, char* argp); * As seen by the user, an ioctl call looks like: int ioctl(int fd, unsigned
// We will then have all sorts of variants on this that can be used * long cmd, char* argp); We will then have all sorts of variants on this that
// to pass stuff to our driver. We will generate macros for each type * can be used to pass stuff to our driver. We will generate macros for each
// of call so as to provide some sort of type safety in the calling: * type of call so as to provide some sort of type safety in the calling:
*/
#define CED_MAGIC_IOC 0xce #define CED_MAGIC_IOC 0xce
// NBNB: READ and WRITE are from the point of view of the device, not user. /* NBNB: READ and WRITE are from the point of view of the device, not user. */
typedef struct ced_ioc_string typedef struct ced_ioc_string {
{ int nChars;
int nChars; char buffer[256];
char buffer[256];
} CED_IOC_STRING; } CED_IOC_STRING;
#define IOCTL_CED_SENDSTRING(n) _IOC(_IOC_WRITE, CED_MAGIC_IOC, 2, n) #define IOCTL_CED_SENDSTRING(n) _IOC(_IOC_WRITE, CED_MAGIC_IOC, 2, n)
#define IOCTL_CED_RESET1401 _IO(CED_MAGIC_IOC, 3) #define IOCTL_CED_RESET1401 _IO(CED_MAGIC_IOC, 3)
#define IOCTL_CED_GETCHAR _IO(CED_MAGIC_IOC, 4) #define IOCTL_CED_GETCHAR _IO(CED_MAGIC_IOC, 4)
#define IOCTL_CED_SENDCHAR _IO(CED_MAGIC_IOC, 5) #define IOCTL_CED_SENDCHAR _IO(CED_MAGIC_IOC, 5)
#define IOCTL_CED_STAT1401 _IO(CED_MAGIC_IOC, 6) #define IOCTL_CED_STAT1401 _IO(CED_MAGIC_IOC, 6)
#define IOCTL_CED_LINECOUNT _IO(CED_MAGIC_IOC, 7) #define IOCTL_CED_LINECOUNT _IO(CED_MAGIC_IOC, 7)
#define IOCTL_CED_GETSTRING(nMax) _IOC(_IOC_READ, CED_MAGIC_IOC, 8, nMax) #define IOCTL_CED_GETSTRING(nMax) _IOC(_IOC_READ, CED_MAGIC_IOC, 8, nMax)
#define IOCTL_CED_SETTRANSFER _IOW(CED_MAGIC_IOC, 11, TRANSFERDESC) #define IOCTL_CED_SETTRANSFER _IOW(CED_MAGIC_IOC, 11, TRANSFERDESC)
#define IOCTL_CED_UNSETTRANSFER _IO(CED_MAGIC_IOC, 12) #define IOCTL_CED_UNSETTRANSFER _IO(CED_MAGIC_IOC, 12)
#define IOCTL_CED_SETEVENT _IOW(CED_MAGIC_IOC,13, TRANSFEREVENT) #define IOCTL_CED_SETEVENT _IOW(CED_MAGIC_IOC, 13, TRANSFEREVENT)
#define IOCTL_CED_GETOUTBUFSPACE _IO(CED_MAGIC_IOC, 14) #define IOCTL_CED_GETOUTBUFSPACE _IO(CED_MAGIC_IOC, 14)
#define IOCTL_CED_GETBASEADDRESS _IO(CED_MAGIC_IOC, 15) #define IOCTL_CED_GETBASEADDRESS _IO(CED_MAGIC_IOC, 15)
#define IOCTL_CED_GETDRIVERREVISION _IO(CED_MAGIC_IOC, 16) #define IOCTL_CED_GETDRIVERREVISION _IO(CED_MAGIC_IOC, 16)
#define IOCTL_CED_GETTRANSFER _IOR(CED_MAGIC_IOC,17, TGET_TX_BLOCK) #define IOCTL_CED_GETTRANSFER _IOR(CED_MAGIC_IOC, 17, TGET_TX_BLOCK)
#define IOCTL_CED_KILLIO1401 _IO(CED_MAGIC_IOC,18) #define IOCTL_CED_KILLIO1401 _IO(CED_MAGIC_IOC, 18)
#define IOCTL_CED_BLKTRANSSTATE _IO(CED_MAGIC_IOC,19) #define IOCTL_CED_BLKTRANSSTATE _IO(CED_MAGIC_IOC, 19)
#define IOCTL_CED_STATEOF1401 _IO(CED_MAGIC_IOC,23) #define IOCTL_CED_STATEOF1401 _IO(CED_MAGIC_IOC, 23)
#define IOCTL_CED_GRAB1401 _IO(CED_MAGIC_IOC,25) #define IOCTL_CED_GRAB1401 _IO(CED_MAGIC_IOC, 25)
#define IOCTL_CED_FREE1401 _IO(CED_MAGIC_IOC,26) #define IOCTL_CED_FREE1401 _IO(CED_MAGIC_IOC, 26)
#define IOCTL_CED_STARTSELFTEST _IO(CED_MAGIC_IOC,31) #define IOCTL_CED_STARTSELFTEST _IO(CED_MAGIC_IOC, 31)
#define IOCTL_CED_CHECKSELFTEST _IOR(CED_MAGIC_IOC,32, TGET_SELFTEST) #define IOCTL_CED_CHECKSELFTEST _IOR(CED_MAGIC_IOC, 32, TGET_SELFTEST)
#define IOCTL_CED_TYPEOF1401 _IO(CED_MAGIC_IOC,33) #define IOCTL_CED_TYPEOF1401 _IO(CED_MAGIC_IOC, 33)
#define IOCTL_CED_TRANSFERFLAGS _IO(CED_MAGIC_IOC,34) #define IOCTL_CED_TRANSFERFLAGS _IO(CED_MAGIC_IOC, 34)
#define IOCTL_CED_DBGPEEK _IOW(CED_MAGIC_IOC,35, TDBGBLOCK) #define IOCTL_CED_DBGPEEK _IOW(CED_MAGIC_IOC, 35, TDBGBLOCK)
#define IOCTL_CED_DBGPOKE _IOW(CED_MAGIC_IOC,36, TDBGBLOCK) #define IOCTL_CED_DBGPOKE _IOW(CED_MAGIC_IOC, 36, TDBGBLOCK)
#define IOCTL_CED_DBGRAMPDATA _IOW(CED_MAGIC_IOC,37, TDBGBLOCK) #define IOCTL_CED_DBGRAMPDATA _IOW(CED_MAGIC_IOC, 37, TDBGBLOCK)
#define IOCTL_CED_DBGRAMPADDR _IOW(CED_MAGIC_IOC,38, TDBGBLOCK) #define IOCTL_CED_DBGRAMPADDR _IOW(CED_MAGIC_IOC, 38, TDBGBLOCK)
#define IOCTL_CED_DBGGETDATA _IOR(CED_MAGIC_IOC,39, TDBGBLOCK) #define IOCTL_CED_DBGGETDATA _IOR(CED_MAGIC_IOC, 39, TDBGBLOCK)
#define IOCTL_CED_DBGSTOPLOOP _IO(CED_MAGIC_IOC,40) #define IOCTL_CED_DBGSTOPLOOP _IO(CED_MAGIC_IOC, 40)
#define IOCTL_CED_FULLRESET _IO(CED_MAGIC_IOC,41) #define IOCTL_CED_FULLRESET _IO(CED_MAGIC_IOC, 41)
#define IOCTL_CED_SETCIRCULAR _IOW(CED_MAGIC_IOC,42, TRANSFERDESC) #define IOCTL_CED_SETCIRCULAR _IOW(CED_MAGIC_IOC, 42, TRANSFERDESC)
#define IOCTL_CED_GETCIRCBLOCK _IOWR(CED_MAGIC_IOC,43, TCIRCBLOCK) #define IOCTL_CED_GETCIRCBLOCK _IOWR(CED_MAGIC_IOC, 43, TCIRCBLOCK)
#define IOCTL_CED_FREECIRCBLOCK _IOWR(CED_MAGIC_IOC,44, TCIRCBLOCK) #define IOCTL_CED_FREECIRCBLOCK _IOWR(CED_MAGIC_IOC, 44, TCIRCBLOCK)
#define IOCTL_CED_WAITEVENT _IO(CED_MAGIC_IOC, 45) #define IOCTL_CED_WAITEVENT _IO(CED_MAGIC_IOC, 45)
#define IOCTL_CED_TESTEVENT _IO(CED_MAGIC_IOC, 46) #define IOCTL_CED_TESTEVENT _IO(CED_MAGIC_IOC, 46)
#ifndef __KERNEL__ #ifndef __KERNEL__
// If nothing said about return value, it is a U14ERR_... error code (U14ERR_NOERROR for none) /*
inline int CED_SendString(int fh, const char* szText, int n){return ioctl(fh, IOCTL_CED_SENDSTRING(n), szText);} * If nothing said about return value, it is a U14ERR_... error code
* (U14ERR_NOERROR for none)
*/
inline int CED_SendString(int fh, const char *szText, int n)
{
return ioctl(fh, IOCTL_CED_SENDSTRING(n), szText);
}
inline int CED_Reset1401(int fh){return ioctl(fh, IOCTL_CED_RESET1401);} inline int CED_Reset1401(int fh)
{
return ioctl(fh, IOCTL_CED_RESET1401);
}
inline int CED_GetChar(int fh){return ioctl(fh, IOCTL_CED_GETCHAR);} /* Return the singe character or a -ve error code. */
// Return the singe character or a -ve error code. inline int CED_GetChar(int fh)
{
return ioctl(fh, IOCTL_CED_GETCHAR);
}
inline int CED_Stat1401(int fh){return ioctl(fh, IOCTL_CED_STAT1401);} /* Return character count in input buffer */
// Return character count in input buffer inline int CED_Stat1401(int fh)
{
return ioctl(fh, IOCTL_CED_STAT1401);
}
inline int CED_SendChar(int fh, char c){return ioctl(fh, IOCTL_CED_SENDCHAR, c);} inline int CED_SendChar(int fh, char c)
{
return ioctl(fh, IOCTL_CED_SENDCHAR, c);
}
inline int CED_LineCount(int fh){return ioctl(fh, IOCTL_CED_LINECOUNT);} inline int CED_LineCount(int fh)
{
return ioctl(fh, IOCTL_CED_LINECOUNT);
}
/*
* return the count of characters returned. If the string was terminated by CR
* or 0, then the 0 is part of the count. Otherwise, we will add a zero if
* there is room, but it is not included in the count. The return value is 0
* if there was nothing to read.
*/
inline int CED_GetString(int fh, char *szText, int nMax)
{
return ioctl(fh, IOCTL_CED_GETSTRING(nMax), szText);
}
inline int CED_GetString(int fh, char* szText, int nMax){return ioctl(fh, IOCTL_CED_GETSTRING(nMax), szText);} /* returns space in the output buffer. */
// return the count of characters returned. If the string was terminated by CR or 0, then the 0 is part inline int CED_GetOutBufSpace(int fh)
// of the count. Otherwise, we will add a zero if there is room, but it is not included in the count. {
// The return value is 0 if there was nothing to read. return ioctl(fh, IOCTL_CED_GETOUTBUFSPACE);
}
inline int CED_GetOutBufSpace(int fh){return ioctl(fh, IOCTL_CED_GETOUTBUFSPACE);} /* This always returns -1 as not implemented. */
// returns space in the output buffer. inline int CED_GetBaseAddress(int fh)
{
return ioctl(fh, IOCTL_CED_GETBASEADDRESS);
}
inline int CED_GetBaseAddress(int fh){return ioctl(fh, IOCTL_CED_GETBASEADDRESS);} /* returns the major revision <<16 | minor revision. */
// This always returns -1 as not implemented. inline int CED_GetDriverRevision(int fh)
{
return ioctl(fh, IOCTL_CED_GETDRIVERREVISION);
}
inline int CED_GetDriverRevision(int fh){return ioctl(fh, IOCTL_CED_GETDRIVERREVISION);} inline int CED_SetTransfer(int fh, TRANSFERDESC *pTD)
// returns the major revision <<16 | minor revision. {
return ioctl(fh, IOCTL_CED_SETTRANSFER, pTD);
}
inline int CED_SetTransfer(int fh, TRANSFERDESC* pTD){return ioctl(fh, IOCTL_CED_SETTRANSFER, pTD);} inline int CED_UnsetTransfer(int fh, int nArea)
{
return ioctl(fh, IOCTL_CED_UNSETTRANSFER, nArea);
}
inline int CED_UnsetTransfer(int fh, int nArea){return ioctl(fh, IOCTL_CED_UNSETTRANSFER, nArea);} inline int CED_SetEvent(int fh, TRANSFEREVENT *pTE)
{
return ioctl(fh, IOCTL_CED_SETEVENT, pTE);
}
inline int CED_SetEvent(int fh, TRANSFEREVENT* pTE){return ioctl(fh, IOCTL_CED_SETEVENT, pTE);} inline int CED_GetTransfer(int fh, TGET_TX_BLOCK *pTX)
{
return ioctl(fh, IOCTL_CED_GETTRANSFER, pTX);
}
inline int CED_GetTransfer(int fh, TGET_TX_BLOCK* pTX){return ioctl(fh, IOCTL_CED_GETTRANSFER, pTX);} inline int CED_KillIO1401(int fh)
{
return ioctl(fh, IOCTL_CED_KILLIO1401);
}
inline int CED_KillIO1401(int fh){return ioctl(fh, IOCTL_CED_KILLIO1401);} /* returns 0 if no active DMA, 1 if active */
inline int CED_BlkTransState(int fh)
{
return ioctl(fh, IOCTL_CED_BLKTRANSSTATE);
}
inline int CED_BlkTransState(int fh){return ioctl(fh, IOCTL_CED_BLKTRANSSTATE);} inline int CED_StateOf1401(int fh)
// returns 0 if no active DMA, 1 if active {
return ioctl(fh, IOCTL_CED_STATEOF1401);
}
inline int CED_StateOf1401(int fh){return ioctl(fh, IOCTL_CED_STATEOF1401);} inline int CED_Grab1401(int fh)
{
return ioctl(fh, IOCTL_CED_GRAB1401);
}
inline int CED_Grab1401(int fh){return ioctl(fh, IOCTL_CED_GRAB1401);} inline int CED_Free1401(int fh)
inline int CED_Free1401(int fh){return ioctl(fh, IOCTL_CED_FREE1401);} {
return ioctl(fh, IOCTL_CED_FREE1401);
}
inline int CED_StartSelfTest(int fh){return ioctl(fh, IOCTL_CED_STARTSELFTEST);} inline int CED_StartSelfTest(int fh)
inline int CED_CheckSelfTest(int fh, TGET_SELFTEST* pGST){return ioctl(fh, IOCTL_CED_CHECKSELFTEST, pGST);} {
return ioctl(fh, IOCTL_CED_STARTSELFTEST);
}
inline int CED_CheckSelfTest(int fh, TGET_SELFTEST *pGST)
{
return ioctl(fh, IOCTL_CED_CHECKSELFTEST, pGST);
}
inline int CED_TypeOf1401(int fh)
{
return ioctl(fh, IOCTL_CED_TYPEOF1401);
}
inline int CED_TransferFlags(int fh)
{
return ioctl(fh, IOCTL_CED_TRANSFERFLAGS);
}
inline int CED_DbgPeek(int fh, TDBGBLOCK *pDB)
{
return ioctl(fh, IOCTL_CED_DBGPEEK, pDB);
}
inline int CED_DbgPoke(int fh, TDBGBLOCK *pDB)
{
return ioctl(fh, IOCTL_CED_DBGPOKE, pDB);
}
inline int CED_DbgRampData(int fh, TDBGBLOCK *pDB)
{
return ioctl(fh, IOCTL_CED_DBGRAMPDATA, pDB);
}
inline int CED_TypeOf1401(int fh){return ioctl(fh, IOCTL_CED_TYPEOF1401);} inline int CED_DbgRampAddr(int fh, TDBGBLOCK *pDB)
inline int CED_TransferFlags(int fh){return ioctl(fh, IOCTL_CED_TRANSFERFLAGS);} {
return ioctl(fh, IOCTL_CED_DBGRAMPADDR, pDB);
}
inline int CED_DbgPeek(int fh, TDBGBLOCK* pDB){return ioctl(fh, IOCTL_CED_DBGPEEK, pDB);} inline int CED_DbgGetData(int fh, TDBGBLOCK *pDB)
inline int CED_DbgPoke(int fh, TDBGBLOCK* pDB){return ioctl(fh, IOCTL_CED_DBGPOKE, pDB);} {
inline int CED_DbgRampData(int fh, TDBGBLOCK* pDB){return ioctl(fh, IOCTL_CED_DBGRAMPDATA, pDB);} return ioctl(fh, IOCTL_CED_DBGGETDATA, pDB);
inline int CED_DbgRampAddr(int fh, TDBGBLOCK* pDB){return ioctl(fh, IOCTL_CED_DBGRAMPADDR, pDB);} }
inline int CED_DbgGetData(int fh, TDBGBLOCK* pDB){return ioctl(fh, IOCTL_CED_DBGGETDATA, pDB);}
inline int CED_DbgStopLoop(int fh){return ioctl(fh, IOCTL_CED_DBGSTOPLOOP);}
inline int CED_FullReset(int fh){return ioctl(fh, IOCTL_CED_FULLRESET);} inline int CED_DbgStopLoop(int fh)
{
return ioctl(fh, IOCTL_CED_DBGSTOPLOOP);
}
inline int CED_SetCircular(int fh, TRANSFERDESC* pTD){return ioctl(fh, IOCTL_CED_SETCIRCULAR, pTD);} inline int CED_FullReset(int fh)
inline int CED_GetCircBlock(int fh, TCIRCBLOCK* pCB){return ioctl(fh, IOCTL_CED_GETCIRCBLOCK, pCB);} {
inline int CED_FreeCircBlock(int fh, TCIRCBLOCK* pCB){return ioctl(fh, IOCTL_CED_FREECIRCBLOCK, pCB);} return ioctl(fh, IOCTL_CED_FULLRESET);
}
inline int CED_WaitEvent(int fh, int nArea, int msTimeOut){return ioctl(fh, IOCTL_CED_WAITEVENT, (nArea & 0xff)|(msTimeOut << 8));} inline int CED_SetCircular(int fh, TRANSFERDESC *pTD)
inline int CED_TestEvent(int fh, int nArea){return ioctl(fh, IOCTL_CED_TESTEVENT, nArea);} {
return ioctl(fh, IOCTL_CED_SETCIRCULAR, pTD);
}
inline int CED_GetCircBlock(int fh, TCIRCBLOCK *pCB)
{
return ioctl(fh, IOCTL_CED_GETCIRCBLOCK, pCB);
}
inline int CED_FreeCircBlock(int fh, TCIRCBLOCK *pCB)
{
return ioctl(fh, IOCTL_CED_FREECIRCBLOCK, pCB);
}
inline int CED_WaitEvent(int fh, int nArea, int msTimeOut)
{
return ioctl(fh, IOCTL_CED_WAITEVENT, (nArea & 0xff)|(msTimeOut << 8));
}
inline int CED_TestEvent(int fh, int nArea)
{
return ioctl(fh, IOCTL_CED_TESTEVENT, nArea);
}
#endif #endif
#ifdef NOTWANTEDYET #ifdef NOTWANTEDYET
#define IOCTL_CED_REGCALLBACK _IO(CED_MAGIC_IOC,9) // Not used #define IOCTL_CED_REGCALLBACK _IO(CED_MAGIC_IOC, 9) /* Not used */
#define IOCTL_CED_GETMONITORBUF _IO(CED_MAGIC_IOC,10) // Not used #define IOCTL_CED_GETMONITORBUF _IO(CED_MAGIC_IOC, 10) /* Not used */
#define IOCTL_CED_BYTECOUNT _IO(CED_MAGIC_IOC,20) // Not used #define IOCTL_CED_BYTECOUNT _IO(CED_MAGIC_IOC, 20) /* Not used */
#define IOCTL_CED_ZEROBLOCKCOUNT _IO(CED_MAGIC_IOC,21) // Not used #define IOCTL_CED_ZEROBLOCKCOUNT _IO(CED_MAGIC_IOC, 21) /* Not used */
#define IOCTL_CED_STOPCIRCULAR _IO(CED_MAGIC_IOC,22) // Not used #define IOCTL_CED_STOPCIRCULAR _IO(CED_MAGIC_IOC, 22) /* Not used */
#define IOCTL_CED_REGISTERS1401 _IO(CED_MAGIC_IOC,24) // Not used #define IOCTL_CED_REGISTERS1401 _IO(CED_MAGIC_IOC, 24) /* Not used */
#define IOCTL_CED_STEP1401 _IO(CED_MAGIC_IOC,27) // Not used #define IOCTL_CED_STEP1401 _IO(CED_MAGIC_IOC, 27) /* Not used */
#define IOCTL_CED_SET1401REGISTERS _IO(CED_MAGIC_IOC,28) // Not used #define IOCTL_CED_SET1401REGISTERS _IO(CED_MAGIC_IOC, 28) /* Not used */
#define IOCTL_CED_STEPTILL1401 _IO(CED_MAGIC_IOC,29) // Not used #define IOCTL_CED_STEPTILL1401 _IO(CED_MAGIC_IOC, 29) /* Not used */
#define IOCTL_CED_SETORIN _IO(CED_MAGIC_IOC,30) // Not used #define IOCTL_CED_SETORIN _IO(CED_MAGIC_IOC, 30) /* Not used */
#endif #endif
// __CED_IOCTL_H__ /* __CED_IOCTL_H__ */
#endif #endif
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment