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,9 +37,10 @@ ...@@ -37,9 +37,10 @@
** **
** 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__,
pdx->sCurrentState);
if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */
return; return;
// CharSend_Cancel(pdx); /* Kill off any pending I/O */ // CharSend_Cancel(pdx); /* Kill off any pending I/O */
...@@ -56,9 +57,10 @@ void FlushOutBuff(DEVICE_EXTENSION *pdx) ...@@ -56,9 +57,10 @@ 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__,
pdx->sCurrentState);
if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */
return; return;
// CharRead_Cancel(pDevObject); /* Kill off any pending I/O */ // CharRead_Cancel(pDevObject); /* Kill off any pending I/O */
...@@ -75,15 +77,14 @@ void FlushInBuff(DEVICE_EXTENSION *pdx) ...@@ -75,15 +77,14 @@ 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]; pdx->outputBuffer[pdx->dwOutBuffPut++] = pCh[u];
if (pdx->dwOutBuffPut >= OUTBUF_SZ) if (pdx->dwOutBuffPut >= OUTBUF_SZ)
pdx->dwOutBuffPut = 0; pdx->dwOutBuffPut = 0;
...@@ -91,9 +92,7 @@ static int PutChars(DEVICE_EXTENSION* pdx, const char* pCh, unsigned int uCount) ...@@ -91,9 +92,7 @@ static int PutChars(DEVICE_EXTENSION* pdx, const char* pCh, unsigned int uCount)
pdx->dwNumOutput += uCount; pdx->dwNumOutput += uCount;
spin_unlock_irq(&pdx->charOutLock); spin_unlock_irq(&pdx->charOutLock);
iReturn = SendChars(pdx); // ...give a chance to transmit data iReturn = SendChars(pdx); // ...give a chance to transmit data
} } else {
else
{
iReturn = U14ERR_NOOUT; // no room at the out (ha-ha) iReturn = U14ERR_NOOUT; // no room at the out (ha-ha)
spin_unlock_irq(&pdx->charOutLock); spin_unlock_irq(&pdx->charOutLock);
} }
...@@ -105,10 +104,11 @@ static int PutChars(DEVICE_EXTENSION* pdx, const char* pCh, unsigned int uCount) ...@@ -105,10 +104,11 @@ 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))
...@@ -118,7 +118,8 @@ int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n) ...@@ -118,7 +118,8 @@ int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n)
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,
buffer);
iReturn = PutChars(pdx, buffer, n); iReturn = PutChars(pdx, buffer, n);
} }
...@@ -133,12 +134,12 @@ int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n) ...@@ -133,12 +134,12 @@ 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,26 +171,25 @@ int SendChar(DEVICE_EXTENSION *pdx, char c) ...@@ -170,26 +171,25 @@ 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; int nDevice;
dev_dbg(&pdx->interface->dev, "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
...@@ -219,9 +219,10 @@ int Get1401State(DEVICE_EXTENSION* pdx, __u32* state, __u32* error) ...@@ -219,9 +219,10 @@ 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;
...@@ -231,7 +232,8 @@ int ReadWrite_Cancel(DEVICE_EXTENSION *pdx) ...@@ -231,7 +232,8 @@ int ReadWrite_Cancel(DEVICE_EXTENSION *pdx)
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 // KeClearEvent(&pdx->StagingDoneEvent); // Clear the staging done flag
USB_ASSERT(pdx->pStagedIrp != NULL); USB_ASSERT(pdx->pStagedIrp != NULL);
...@@ -240,25 +242,27 @@ int ReadWrite_Cancel(DEVICE_EXTENSION *pdx) ...@@ -240,25 +242,27 @@ int ReadWrite_Cancel(DEVICE_EXTENSION *pdx)
// on the spinlock while this function hands waiting for the event. // on the spinlock while this function hands waiting for the event.
spin_unlock_irq(&pdx->stagedLock); spin_unlock_irq(&pdx->stagedLock);
bResult = IoCancelIrp(pdx->pStagedIrp); // Actually do the cancel bResult = IoCancelIrp(pdx->pStagedIrp); // Actually do the cancel
if (bResult) 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 {
dev_info(&pdx->interface - dev,
"ReadWrite_Cancel, cancellation failed");
ntStatus = U14ERR_FAIL; ntStatus = U14ERR_FAIL;
} }
USB_KdPrint(DBGLVL_DEFAULT, ("ReadWrite_Cancel ntStatus = 0x%x decimal %d\n", ntStatus, ntStatus)); USB_KdPrint(DBGLVL_DEFAULT,
} ("ReadWrite_Cancel ntStatus = 0x%x decimal %d\n",
else ntStatus, ntStatus));
} else
spin_unlock_irq(&pdx->stagedLock); spin_unlock_irq(&pdx->stagedLock);
dev_info(&pdx->interface-dev, "ReadWrite_Cancel done"); dev_info(&pdx->interface - dev, "ReadWrite_Cancel done");
return ntStatus; return ntStatus;
#else #else
return U14ERR_NOERROR; return U14ERR_NOERROR;
...@@ -270,7 +274,7 @@ int ReadWrite_Cancel(DEVICE_EXTENSION *pdx) ...@@ -270,7 +274,7 @@ 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
...@@ -299,7 +303,7 @@ static int InSelfTest(DEVICE_EXTENSION* pdx, unsigned int* pState) ...@@ -299,7 +303,7 @@ 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__);
...@@ -329,9 +333,8 @@ bool Is1401(DEVICE_EXTENSION* pdx) ...@@ -329,9 +333,8 @@ bool Is1401(DEVICE_EXTENSION* pdx)
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
} }
...@@ -339,8 +342,7 @@ bool Is1401(DEVICE_EXTENSION* pdx) ...@@ -339,8 +342,7 @@ bool Is1401(DEVICE_EXTENSION* pdx)
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
else
iReturn = 0; // we failed iReturn = 0; // we failed
pdx->bForceReset = false; // Clear forced reset flag now pdx->bForceReset = false; // Clear forced reset flag now
...@@ -361,7 +363,7 @@ bool Is1401(DEVICE_EXTENSION* pdx) ...@@ -361,7 +363,7 @@ 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;
...@@ -370,14 +372,17 @@ bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset) ...@@ -370,14 +372,17 @@ bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset)
(!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,
bTestBuff, bShortTest);
if ((bTestBuff) && // Buffer check requested, and... if ((bTestBuff) && // Buffer check requested, and...
(pdx->dwNumInput || pdx->dwNumOutput)) // ...characters were in the buffer? (pdx->dwNumInput || pdx->dwNumOutput)) // ...characters were in the buffer?
{ {
bShortTest = false; // Then do the full test bShortTest = false; // Then do the full test
dev_dbg(&pdx->interface->dev, "%s will reset as buffers not empty", __func__); dev_dbg(&pdx->interface->dev,
"%s will reset as buffers not empty", __func__);
} }
if (bShortTest || !bCanReset) // Still OK to try the short test? if (bShortTest || !bCanReset) // Still OK to try the short test?
...@@ -394,7 +399,8 @@ bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset) ...@@ -394,7 +399,8 @@ bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset)
if (!bRet && bCanReset) // If all not OK, then if (!bRet && bCanReset) // If all not OK, then
{ {
dev_info(&pdx->interface->dev, "%s->Is1401 %d %d %d %d", dev_info(&pdx->interface->dev, "%s->Is1401 %d %d %d %d",
__func__, bShortTest, pdx->sCurrentState, bTestBuff, pdx->bForceReset); __func__, bShortTest, pdx->sCurrentState, bTestBuff,
pdx->bForceReset);
bRet = Is1401(pdx); // do full test bRet = Is1401(pdx); // do full test
} }
...@@ -406,10 +412,10 @@ bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset) ...@@ -406,10 +412,10 @@ 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,7 +426,7 @@ int Reset1401(DEVICE_EXTENSION *pdx) ...@@ -420,7 +426,7 @@ 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
...@@ -437,8 +443,7 @@ int GetChar(DEVICE_EXTENSION *pdx) ...@@ -437,8 +443,7 @@ int GetChar(DEVICE_EXTENSION *pdx)
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);
...@@ -459,7 +464,7 @@ int GetChar(DEVICE_EXTENSION *pdx) ...@@ -459,7 +464,7 @@ 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;
...@@ -477,12 +482,11 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n) ...@@ -477,12 +482,11 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n)
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;
...@@ -492,7 +496,7 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n) ...@@ -492,7 +496,7 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n)
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
...@@ -505,12 +509,12 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n) ...@@ -505,12 +509,12 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n)
pdx->dwNumInput -= nGot; pdx->dwNumInput -= nGot;
spin_unlock_irq(&pdx->charInLock); spin_unlock_irq(&pdx->charInLock);
dev_dbg(&pdx->interface->dev,"GetString read %d characters >%s<", nGot, buffer); dev_dbg(&pdx->interface->dev,
"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
...@@ -522,7 +526,7 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n) ...@@ -522,7 +526,7 @@ int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n)
/******************************************************************************* /*******************************************************************************
** 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
...@@ -540,7 +544,7 @@ int Stat1401(DEVICE_EXTENSION *pdx) ...@@ -540,7 +544,7 @@ 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
...@@ -551,10 +555,9 @@ int LineCount(DEVICE_EXTENSION *pdx) ...@@ -551,10 +555,9 @@ int LineCount(DEVICE_EXTENSION *pdx)
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
...@@ -565,7 +568,7 @@ int LineCount(DEVICE_EXTENSION *pdx) ...@@ -565,7 +568,7 @@ int LineCount(DEVICE_EXTENSION *pdx)
} }
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,13 +578,13 @@ int LineCount(DEVICE_EXTENSION *pdx) ...@@ -575,13 +578,13 @@ 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,48 +596,49 @@ int GetOutBufSpace(DEVICE_EXTENSION *pdx) ...@@ -593,48 +596,49 @@ 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", __func__, nArea); dev_err(&pdx->interface->dev, "%s Attempt to clear area %d",
} __func__, nArea);
else } else {
{
TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing
if (!pTA->bUsed) // if not used... if (!pTA->bUsed) // if not used...
iReturn = U14ERR_NOTSET; // ...nothing to be done iReturn = U14ERR_NOTSET; // ...nothing to be done
else else {
{
// We must save the memory we return as we shouldn't mess with memory while // We must save the memory we return as we shouldn't mess with memory while
// holding a spin lock. // holding a spin lock.
struct page **pPages = 0; // save page address list struct page **pPages = 0; // save page address list
int nPages = 0; // and number of pages int nPages = 0; // and number of pages
int np; int np;
dev_dbg(&pdx->interface->dev, "%s area %d", __func__, nArea); dev_dbg(&pdx->interface->dev, "%s area %d", __func__,
nArea);
spin_lock_irq(&pdx->stagedLock); spin_lock_irq(&pdx->stagedLock);
if ((pdx->StagedId == nArea) && (pdx->dwDMAFlag > MODE_CHAR)) if ((pdx->StagedId == nArea)
{ && (pdx->dwDMAFlag > MODE_CHAR)) {
iReturn = U14ERR_UNLOCKFAIL; // cannot delete as in use iReturn = U14ERR_UNLOCKFAIL; // cannot delete as in use
dev_err(&pdx->interface->dev, "%s call on area %d while active", __func__, nArea); dev_err(&pdx->interface->dev,
} "%s call on area %d while active",
else __func__, nArea);
{ } else {
pPages = pTA->pPages; // save page address list pPages = pTA->pPages; // save page address list
nPages = pTA->nPages; // and page count nPages = pTA->nPages; // and page count
if (pTA->dwEventSz) // if events flagging in use if (pTA->dwEventSz) // if events flagging in use
wake_up_interruptible(&pTA->wqEvent); // release anything that was waiting 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, sizeof(TRANSAREA)-sizeof(wait_queue_head_t)); memset(pTA, 0,
sizeof(TRANSAREA) -
sizeof(wait_queue_head_t));
} }
spin_unlock_irq(&pdx->stagedLock); spin_unlock_irq(&pdx->stagedLock);
...@@ -643,19 +647,19 @@ int ClearArea(DEVICE_EXTENSION *pdx, int nArea) ...@@ -643,19 +647,19 @@ int ClearArea(DEVICE_EXTENSION *pdx, int nArea)
// Now we must undo the pinning down of the pages. We will assume the worst and mark // 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 // all the pages as dirty. Don't be tempted to move this up above as you must not be
// holding a spin lock to do this stuff as it is not atomic. // holding a spin lock to do this stuff as it is not atomic.
dev_dbg(&pdx->interface->dev, "%s nPages=%d", __func__, nPages); dev_dbg(&pdx->interface->dev, "%s nPages=%d",
__func__, nPages);
for (np = 0; np < nPages; ++np) for (np = 0; np < nPages; ++np) {
{ if (pPages[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__);
} }
} }
} }
...@@ -669,15 +673,15 @@ int ClearArea(DEVICE_EXTENSION *pdx, int nArea) ...@@ -669,15 +673,15 @@ 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
...@@ -692,17 +696,19 @@ static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf, ...@@ -692,17 +696,19 @@ static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf,
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. // To pin down user pages we must first acquire the mapping semaphore.
down_read(&current->mm->mmap_sem); // get memory map semaphore down_read(&current->mm->mmap_sem); // get memory map semaphore
nPages = get_user_pages(current, current->mm, ulStart, len, 1, 0, pPages, 0); nPages =
get_user_pages(current, current->mm, ulStart, len, 1, 0, pPages, 0);
up_read(&current->mm->mmap_sem); // release the semaphore up_read(&current->mm->mmap_sem); // release the semaphore
dev_dbg(&pdx->interface->dev, "%s nPages = %d", __func__, nPages); dev_dbg(&pdx->interface->dev, "%s nPages = %d", __func__, nPages);
...@@ -729,9 +735,7 @@ static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf, ...@@ -729,9 +735,7 @@ static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf,
spin_unlock_irq(&pdx->stagedLock); spin_unlock_irq(&pdx->stagedLock);
iReturn = U14ERR_NOERROR; // say all was well iReturn = U14ERR_NOERROR; // say all was well
} } else {
else
{
iReturn = U14ERR_LOCKFAIL; iReturn = U14ERR_LOCKFAIL;
goto error; goto error;
} }
...@@ -750,17 +754,21 @@ static int SetArea(DEVICE_EXTENSION *pdx, int nArea, char __user* puBuf, ...@@ -750,17 +754,21 @@ 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__,
td.wAreaNum, td.dwLength);
// The strange cast is done so that we don't get warnings in 32-bit linux about the size of the // 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 // pointer. The pointer is always passed as a 64-bit object so that we don't have problems using
// a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. // a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system.
iReturn = SetArea(pdx, td.wAreaNum, (char __user *)((unsigned long)td.lpvBuff), td.dwLength, false, false); iReturn =
SetArea(pdx, td.wAreaNum,
(char __user *)((unsigned long)td.lpvBuff), td.dwLength,
false, false);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
...@@ -769,7 +777,7 @@ int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) ...@@ -769,7 +777,7 @@ int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD)
** 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);
...@@ -786,15 +794,14 @@ int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea) ...@@ -786,15 +794,14 @@ 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);
...@@ -804,13 +811,13 @@ int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE) ...@@ -804,13 +811,13 @@ int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE)
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
else
iReturn = U14ERR_NOTSET; iReturn = U14ERR_NOTSET;
spin_unlock_irq(&pdx->stagedLock); spin_unlock_irq(&pdx->stagedLock);
mutex_unlock(&pdx->io_mutex); 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,16 +826,15 @@ int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE) ...@@ -819,16 +826,15 @@ 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
...@@ -840,9 +846,15 @@ int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut) ...@@ -840,9 +846,15 @@ int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut)
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
if (msTimeOut) if (msTimeOut)
iWait = wait_event_interruptible_timeout(pTA->wqEvent, pTA->iWakeUp || !pTA->bUsed, msTimeOut); iWait =
wait_event_interruptible_timeout(pTA->wqEvent,
pTA->iWakeUp
|| !pTA->bUsed,
msTimeOut);
else else
iWait = wait_event_interruptible(pTA->wqEvent, pTA->iWakeUp || !pTA->bUsed); iWait =
wait_event_interruptible(pTA->wqEvent, pTA->iWakeUp
|| !pTA->bUsed);
if (iWait) if (iWait)
iReturn = -ERESTARTSYS; // oops - we have had a SIGNAL iReturn = -ERESTARTSYS; // oops - we have had a SIGNAL
else else
...@@ -861,13 +873,12 @@ int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut) ...@@ -861,13 +873,12 @@ 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);
...@@ -883,7 +894,7 @@ int TestEvent(DEVICE_EXTENSION *pdx, int nArea) ...@@ -883,7 +894,7 @@ int TestEvent(DEVICE_EXTENSION *pdx, int nArea)
** 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;
...@@ -892,8 +903,7 @@ int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX) ...@@ -892,8 +903,7 @@ int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX)
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
...@@ -901,7 +911,8 @@ int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX) ...@@ -901,7 +911,8 @@ int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX)
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 = (long long)(tx.linear+pdx->StagedOffset); tx.entries[0].physical =
(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));
} }
...@@ -914,7 +925,7 @@ int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pTX) ...@@ -914,7 +925,7 @@ 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);
...@@ -929,7 +940,7 @@ int KillIO1401(DEVICE_EXTENSION *pdx) ...@@ -929,7 +940,7 @@ 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);
...@@ -941,7 +952,7 @@ int BlkTransState(DEVICE_EXTENSION *pdx) ...@@ -941,7 +952,7 @@ 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);
...@@ -954,13 +965,14 @@ int StateOf1401(DEVICE_EXTENSION *pdx) ...@@ -954,13 +965,14 @@ int StateOf1401(DEVICE_EXTENSION *pdx)
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);
...@@ -972,10 +984,8 @@ int StartSelfTest(DEVICE_EXTENSION *pdx) ...@@ -972,10 +984,8 @@ int StartSelfTest(DEVICE_EXTENSION *pdx)
// 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)
...@@ -983,13 +993,12 @@ int StartSelfTest(DEVICE_EXTENSION *pdx) ...@@ -983,13 +993,12 @@ int StartSelfTest(DEVICE_EXTENSION *pdx)
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;
...@@ -1005,7 +1014,9 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST) ...@@ -1005,7 +1014,9 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST)
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,
"%s Get1401State=%d, assuming still testing", __func__,
iReturn);
state = 0x80; // Force still-testing, no error state = 0x80; // Force still-testing, no error
error = 0; error = 0;
iReturn = U14ERR_NOERROR; iReturn = U14ERR_NOERROR;
...@@ -1013,7 +1024,9 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST) ...@@ -1013,7 +1024,9 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST)
if ((state == -1) && (error == -1)) // If Get1401State had problems if ((state == -1) && (error == -1)) // If Get1401State had problems
{ {
dev_err(&pdx->interface->dev, "%s Get1401State failed, assuming still testing", __func__); dev_err(&pdx->interface->dev,
"%s Get1401State failed, assuming still testing",
__func__);
state = 0x80; // Force still-testing, no error state = 0x80; // Force still-testing, no error
error = 0; error = 0;
} }
...@@ -1025,22 +1038,20 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST) ...@@ -1025,22 +1038,20 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST)
gst.code = (state & 0x00FF0000) >> 16; // read the error code gst.code = (state & 0x00FF0000) >> 16; // read the error code
gst.x = error & 0x0000FFFF; // Error data X gst.x = error & 0x0000FFFF; // Error data X
gst.y = (error & 0xFFFF0000) >> 16; // and data Y gst.y = (error & 0xFFFF0000) >> 16; // and data Y
dev_dbg(&pdx->interface->dev,"Self-test error code %d", gst.code); dev_dbg(&pdx->interface->dev, "Self-test error code %d",
} gst.code);
else // No error, check for timeout } else // No error, check for timeout
{ {
unsigned long ulNow = jiffies; // get current time unsigned long ulNow = jiffies; // get current time
if (time_after(ulNow, pdx->ulSelfTestTime)) if (time_after(ulNow, pdx->ulSelfTestTime)) {
{
gst.code = -2; // Flag the timeout gst.code = -2; // Flag the timeout
dev_dbg(&pdx->interface->dev, "Self-test timed-out"); dev_dbg(&pdx->interface->dev,
} "Self-test timed-out");
else } else
dev_dbg(&pdx->interface->dev, "Self-test on-going"); dev_dbg(&pdx->interface->dev,
"Self-test on-going");
} }
} } else {
else
{
gst.code = -1; // Flag the test is done gst.code = -1; // Flag the test is done
dev_dbg(&pdx->interface->dev, "Self-test done"); dev_dbg(&pdx->interface->dev, "Self-test done");
} }
...@@ -1063,20 +1074,24 @@ int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST) ...@@ -1063,20 +1074,24 @@ 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:
iReturn = U14ERR_PLUS;
break;
case TYPEU1401:
iReturn = U14ERR_U1401;
break;
default: default:
if ((pdx->s1401Type >= TYPEPOWER) && if ((pdx->s1401Type >= TYPEPOWER) && (pdx->s1401Type <= 25))
(pdx->s1401Type <= 25))
iReturn = pdx->s1401Type + 4; // We can calculate types iReturn = pdx->s1401Type + 4; // We can calculate types
else // for up-coming 1401 designs else // for up-coming 1401 designs
iReturn = TYPEUNKNOWN; // Don't know or not there iReturn = TYPEUNKNOWN; // Don't know or not there
...@@ -1092,7 +1107,7 @@ int TypeOf1401(DEVICE_EXTENSION *pdx) ...@@ -1092,7 +1107,7 @@ 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
...@@ -1110,16 +1125,15 @@ int TransferFlags(DEVICE_EXTENSION *pdx) ...@@ -1110,16 +1125,15 @@ 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),
(unsigned short)data, (unsigned short)(data >> 16),
0, 0, HZ); // allow 1 second timeout
if (iReturn < 0) if (iReturn < 0)
dev_err(&pdx->interface->dev, "%s fail code=%d", __func__, iReturn); dev_err(&pdx->interface->dev, "%s fail code=%d", __func__,
iReturn);
return iReturn; return iReturn;
} }
...@@ -1129,7 +1143,7 @@ static int DbgCmd1401(DEVICE_EXTENSION *pdx, unsigned char cmd, unsigned int dat ...@@ -1129,7 +1143,7 @@ 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;
...@@ -1150,14 +1164,13 @@ int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user* pDB) ...@@ -1150,14 +1164,13 @@ int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user* pDB)
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;
...@@ -1178,14 +1191,13 @@ int DbgPoke(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) ...@@ -1178,14 +1191,13 @@ int DbgPoke(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB)
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;
...@@ -1210,13 +1222,12 @@ int DbgRampData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) ...@@ -1210,13 +1222,12 @@ int DbgRampData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB)
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;
...@@ -1239,13 +1250,12 @@ int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) ...@@ -1239,13 +1250,12 @@ int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB)
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;
...@@ -1256,15 +1266,14 @@ int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) ...@@ -1256,15 +1266,14 @@ int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB)
// 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
else dev_err(&pdx->interface->dev, "%s failed, code %d", __func__,
dev_err(&pdx->interface->dev, "%s failed, code %d", __func__, iReturn); iReturn);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
...@@ -1277,7 +1286,7 @@ int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) ...@@ -1277,7 +1286,7 @@ 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;
...@@ -1290,7 +1299,6 @@ int DbgStopLoop(DEVICE_EXTENSION *pdx) ...@@ -1290,7 +1299,6 @@ int DbgStopLoop(DEVICE_EXTENSION *pdx)
return iReturn; return iReturn;
} }
/**************************************************************************** /****************************************************************************
** SetCircular ** SetCircular
** **
...@@ -1299,20 +1307,24 @@ int DbgStopLoop(DEVICE_EXTENSION *pdx) ...@@ -1299,20 +1307,24 @@ 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__,
td.wAreaNum, td.dwLength);
bToHost = td.eSize != 0; // this is used as the tohost flag 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 // 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 // pointer. The pointer is always passed as a 64-bit object so that we don't have problems using
// a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system. // a 32-bit program on a 64-bit system. unsigned long is 64-bits on a 64-bit system.
iReturn = SetArea(pdx, td.wAreaNum, (char __user *)((unsigned long)td.lpvBuff), td.dwLength, true, bToHost); iReturn =
SetArea(pdx, td.wAreaNum,
(char __user *)((unsigned long)td.lpvBuff), td.dwLength,
true, bToHost);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
return iReturn; return iReturn;
} }
...@@ -1322,7 +1334,7 @@ int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) ...@@ -1322,7 +1334,7 @@ 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;
...@@ -1337,7 +1349,7 @@ int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB) ...@@ -1337,7 +1349,7 @@ int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB)
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
...@@ -1347,15 +1359,15 @@ int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB) ...@@ -1347,15 +1359,15 @@ int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB)
{ {
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
else
iReturn = U14ERR_NOTSET; 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));
...@@ -1363,13 +1375,12 @@ int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB) ...@@ -1363,13 +1375,12 @@ int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB)
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;
...@@ -1386,7 +1397,7 @@ int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB) ...@@ -1386,7 +1397,7 @@ int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB)
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
...@@ -1406,56 +1417,62 @@ int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB) ...@@ -1406,56 +1417,62 @@ int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB)
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, "%s free %d bytes at %d, return %d bytes at %d, wait=%d", dev_dbg(&pdx->interface->dev,
__func__, uSize, uStart, pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset, pdx->bXFerWaiting); "%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);
// Return the next available block of memory as well // Return the next available block of memory as well
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;
} }
bWaiting = pdx->bXFerWaiting; bWaiting = pdx->bXFerWaiting;
if (bWaiting && pdx->bStagedUrbPending) if (bWaiting && pdx->bStagedUrbPending) {
{ dev_err(&pdx->interface->dev,
dev_err(&pdx->interface->dev, "%s ERROR: waiting xfer and staged Urb pending!", __func__); "%s ERROR: waiting xfer and staged Urb pending!",
__func__);
bWaiting = false; bWaiting = false;
} }
} } else {
else dev_err(&pdx->interface->dev,
{ "%s ERROR: freeing %d bytes at %d, block 0 is %d bytes at %d",
dev_err(&pdx->interface->dev, "%s ERROR: freeing %d bytes at %d, block 0 is %d bytes at %d", __func__, uSize, uStart,
__func__, uSize, uStart, pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset); pArea->aBlocks[0].dwSize,
pArea->aBlocks[0].dwOffset);
iReturn = U14ERR_NOMEMORY; iReturn = U14ERR_NOMEMORY;
} }
// If we have one, kick off pending transfer // If we have one, kick off pending transfer
if (bWaiting) // Got a block xfer waiting? if (bWaiting) // Got a block xfer waiting?
{ {
int RWMStat = ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard, int RWMStat =
pdx->rDMAInfo.wIdent, pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize); ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard,
pdx->rDMAInfo.wIdent,
pdx->rDMAInfo.dwOffset,
pdx->rDMAInfo.dwSize);
if (RWMStat != U14ERR_NOERROR) if (RWMStat != U14ERR_NOERROR)
dev_err(&pdx->interface->dev, "%s rw setup failed %d", __func__, RWMStat); dev_err(&pdx->interface->dev,
} "%s rw setup failed %d",
__func__, RWMStat);
} }
else } else
iReturn = U14ERR_NOTSET; 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;
} }
/* 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>
/* dma modes, only MODE_CHAR and MODE_LINEAR are used in this driver */
#define MODE_CHAR 0 #define MODE_CHAR 0
#define MODE_LINEAR 1 #define MODE_LINEAR 1
...@@ -29,73 +26,67 @@ ...@@ -29,73 +26,67 @@
** 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;
...@@ -111,122 +102,244 @@ typedef struct ced_ioc_string ...@@ -111,122 +102,244 @@ typedef struct ced_ioc_string
#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
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Endpoints Endpoints
********* *********
There are 4 endpoints plus the control endpoint in the standard interface There are 4 endpoints plus the control endpoint in the standard interface
...@@ -92,14 +91,13 @@ synchronous non-Urb based transfers. ...@@ -92,14 +91,13 @@ synchronous non-Urb based transfers.
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/version.h> #include <linux/version.h>
#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35) ) #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35) )
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#endif #endif
#include "usb1401.h" #include "usb1401.h"
/* Define these values to match your devices */ /* Define these values to match your devices */
...@@ -107,13 +105,12 @@ synchronous non-Urb based transfers. ...@@ -107,13 +105,12 @@ synchronous non-Urb based transfers.
#define USB_CED_PRODUCT_ID 0xa0f0 #define USB_CED_PRODUCT_ID 0xa0f0
/* table of devices that work with this driver */ /* table of devices that work with this driver */
static const struct usb_device_id ced_table[] = static const struct usb_device_id ced_table[] = {
{ {USB_DEVICE(USB_CED_VENDOR_ID, USB_CED_PRODUCT_ID)},
{ USB_DEVICE(USB_CED_VENDOR_ID, USB_CED_PRODUCT_ID) }, {} /* Terminating entry */
{ } /* Terminating entry */
}; };
MODULE_DEVICE_TABLE(usb, ced_table);
MODULE_DEVICE_TABLE(usb, ced_table);
/* Get a minor range for your devices from the usb maintainer */ /* Get a minor range for your devices from the usb maintainer */
#define USB_CED_MINOR_BASE 192 #define USB_CED_MINOR_BASE 192
...@@ -134,9 +131,9 @@ The cause for these errors is that the driver makes use of the functions usb_buf ...@@ -134,9 +131,9 @@ The cause for these errors is that the driver makes use of the functions usb_buf
This is needed on Debian 2.6.32-5-amd64 This is needed on Debian 2.6.32-5-amd64
*/ */
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) ) #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) )
#define usb_alloc_coherent usb_buffer_alloc #define usb_alloc_coherent usb_buffer_alloc
#define usb_free_coherent usb_buffer_free #define usb_free_coherent usb_buffer_free
#define noop_llseek NULL #define noop_llseek NULL
#endif #endif
static struct usb_driver ced_driver; static struct usb_driver ced_driver;
...@@ -147,15 +144,18 @@ static void ced_delete(struct kref *kref) ...@@ -147,15 +144,18 @@ static void ced_delete(struct kref *kref)
// Free up the output buffer, then free the output urb. Note that the interface member // Free up the output buffer, then free the output urb. Note that the interface member
// of pdx will probably be NULL, so cannot be used to get to dev. // of pdx will probably be NULL, so cannot be used to get to dev.
usb_free_coherent(pdx->udev, OUTBUF_SZ, pdx->pCoherCharOut, pdx->pUrbCharOut->transfer_dma); usb_free_coherent(pdx->udev, OUTBUF_SZ, pdx->pCoherCharOut,
pdx->pUrbCharOut->transfer_dma);
usb_free_urb(pdx->pUrbCharOut); usb_free_urb(pdx->pUrbCharOut);
// Do the same for chan input // Do the same for chan input
usb_free_coherent(pdx->udev, INBUF_SZ, pdx->pCoherCharIn, pdx->pUrbCharIn->transfer_dma); usb_free_coherent(pdx->udev, INBUF_SZ, pdx->pCoherCharIn,
pdx->pUrbCharIn->transfer_dma);
usb_free_urb(pdx->pUrbCharIn); usb_free_urb(pdx->pUrbCharIn);
// Do the same for the block transfers // Do the same for the block transfers
usb_free_coherent(pdx->udev, STAGED_SZ, pdx->pCoherStagedIO, pdx->pStagedUrb->transfer_dma); usb_free_coherent(pdx->udev, STAGED_SZ, pdx->pCoherStagedIO,
pdx->pStagedUrb->transfer_dma);
usb_free_urb(pdx->pStagedUrb); usb_free_urb(pdx->pStagedUrb);
usb_put_dev(pdx->udev); usb_put_dev(pdx->udev);
...@@ -168,17 +168,17 @@ static int ced_open(struct inode *inode, struct file *file) ...@@ -168,17 +168,17 @@ static int ced_open(struct inode *inode, struct file *file)
DEVICE_EXTENSION *pdx; DEVICE_EXTENSION *pdx;
int retval = 0; int retval = 0;
int subminor = iminor(inode); int subminor = iminor(inode);
struct usb_interface* interface = usb_find_interface(&ced_driver, subminor); struct usb_interface *interface =
if (!interface) usb_find_interface(&ced_driver, subminor);
{ if (!interface) {
pr_err("%s - error, can't find device for minor %d", __func__, subminor); pr_err("%s - error, can't find device for minor %d", __func__,
subminor);
retval = -ENODEV; retval = -ENODEV;
goto exit; goto exit;
} }
pdx = usb_get_intfdata(interface); pdx = usb_get_intfdata(interface);
if (!pdx) if (!pdx) {
{
retval = -ENODEV; retval = -ENODEV;
goto exit; goto exit;
} }
...@@ -192,19 +192,15 @@ static int ced_open(struct inode *inode, struct file *file) ...@@ -192,19 +192,15 @@ static int ced_open(struct inode *inode, struct file *file)
* in resumption */ * in resumption */
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
if (!pdx->open_count++) if (!pdx->open_count++) {
{
retval = usb_autopm_get_interface(interface); retval = usb_autopm_get_interface(interface);
if (retval) if (retval) {
{
pdx->open_count--; pdx->open_count--;
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
kref_put(&pdx->kref, ced_delete); kref_put(&pdx->kref, ced_delete);
goto exit; goto exit;
} }
} } else { //uncomment this block if you want exclusive open
else
{ //uncomment this block if you want exclusive open
dev_err(&interface->dev, "%s fail: already open", __func__); dev_err(&interface->dev, "%s fail: already open", __func__);
retval = -EBUSY; retval = -EBUSY;
pdx->open_count--; pdx->open_count--;
...@@ -228,7 +224,7 @@ static int ced_release(struct inode *inode, struct file *file) ...@@ -228,7 +224,7 @@ static int ced_release(struct inode *inode, struct file *file)
if (pdx == NULL) if (pdx == NULL)
return -ENODEV; return -ENODEV;
dev_dbg(&pdx->interface->dev,"%s called", __func__); dev_dbg(&pdx->interface->dev, "%s called", __func__);
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
if (!--pdx->open_count && pdx->interface) // Allow autosuspend if (!--pdx->open_count && pdx->interface) // Allow autosuspend
usb_autopm_put_interface(pdx->interface); usb_autopm_put_interface(pdx->interface);
...@@ -245,11 +241,12 @@ static int ced_flush(struct file *file, fl_owner_t id) ...@@ -245,11 +241,12 @@ static int ced_flush(struct file *file, fl_owner_t id)
if (pdx == NULL) if (pdx == NULL)
return -ENODEV; return -ENODEV;
dev_dbg(&pdx->interface->dev,"%s char in pend=%d", __func__, pdx->bReadCharsPending); dev_dbg(&pdx->interface->dev, "%s char in pend=%d", __func__,
pdx->bReadCharsPending);
/* wait for io to stop */ /* wait for io to stop */
mutex_lock(&pdx->io_mutex); mutex_lock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev,"%s got io_mutex", __func__); dev_dbg(&pdx->interface->dev, "%s got io_mutex", __func__);
ced_draw_down(pdx); ced_draw_down(pdx);
/* read out errors, leave subsequent opens a clean slate */ /* read out errors, leave subsequent opens a clean slate */
...@@ -259,25 +256,26 @@ static int ced_flush(struct file *file, fl_owner_t id) ...@@ -259,25 +256,26 @@ static int ced_flush(struct file *file, fl_owner_t id)
spin_unlock_irq(&pdx->err_lock); spin_unlock_irq(&pdx->err_lock);
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
dev_dbg(&pdx->interface->dev,"%s exit reached", __func__); dev_dbg(&pdx->interface->dev, "%s exit reached", __func__);
return res; return res;
} }
static ssize_t ced_read(struct file *file, char *buffer, size_t count, static ssize_t ced_read(struct file *file, char *buffer, size_t count,
loff_t *ppos) loff_t * ppos)
{ {
DEVICE_EXTENSION *pdx = file->private_data; DEVICE_EXTENSION *pdx = file->private_data;
dev_err(&pdx->interface->dev, "%s called: use ioctl for cedusb", __func__); dev_err(&pdx->interface->dev, "%s called: use ioctl for cedusb",
__func__);
return 0; // as we do not do reads this way return 0; // as we do not do reads this way
} }
static ssize_t ced_write(struct file *file, const char *user_buffer, static ssize_t ced_write(struct file *file, const char *user_buffer,
size_t count, loff_t *ppos) size_t count, loff_t * ppos)
{ {
DEVICE_EXTENSION *pdx = file->private_data; DEVICE_EXTENSION *pdx = file->private_data;
dev_err(&pdx->interface->dev, "%s called: use ioctl for cedusb", __func__); dev_err(&pdx->interface->dev, "%s called: use ioctl for cedusb",
__func__);
return 0; return 0;
} }
...@@ -288,7 +286,7 @@ static ssize_t ced_write(struct file *file, const char *user_buffer, ...@@ -288,7 +286,7 @@ static ssize_t ced_write(struct file *file, const char *user_buffer,
** not help with a device extension held by a file. ** not help with a device extension held by a file.
** return true if can accept new io requests, else false ** return true if can accept new io requests, else false
*/ */
static bool CanAcceptIoRequests(DEVICE_EXTENSION* pdx) static bool CanAcceptIoRequests(DEVICE_EXTENSION * pdx)
{ {
return pdx && pdx->interface; // Can we accept IO requests return pdx && pdx->interface; // Can we accept IO requests
} }
...@@ -297,16 +295,18 @@ static bool CanAcceptIoRequests(DEVICE_EXTENSION* pdx) ...@@ -297,16 +295,18 @@ static bool CanAcceptIoRequests(DEVICE_EXTENSION* pdx)
** Callback routine to complete writes. This may need to fire off another ** Callback routine to complete writes. This may need to fire off another
** urb to complete the transfer. ** urb to complete the transfer.
****************************************************************************/ ****************************************************************************/
static void ced_writechar_callback(struct urb* pUrb) static void ced_writechar_callback(struct urb *pUrb)
{ {
DEVICE_EXTENSION *pdx = pUrb->context; DEVICE_EXTENSION *pdx = pUrb->context;
int nGot = pUrb->actual_length; // what we transferred int nGot = pUrb->actual_length; // what we transferred
if (pUrb->status) if (pUrb->status) { // sync/async unlink faults aren't errors
{ // sync/async unlink faults aren't errors if (!
if (!(pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET
{ || pUrb->status == -ESHUTDOWN)) {
dev_err(&pdx->interface->dev, "%s - nonzero write bulk status received: %d", __func__, pUrb->status); dev_err(&pdx->interface->dev,
"%s - nonzero write bulk status received: %d",
__func__, pUrb->status);
} }
spin_lock(&pdx->err_lock); spin_lock(&pdx->err_lock);
...@@ -321,11 +321,11 @@ static void ced_writechar_callback(struct urb* pUrb) ...@@ -321,11 +321,11 @@ static void ced_writechar_callback(struct urb* pUrb)
pdx->bPipeError[0] = 1; // Flag an error for later pdx->bPipeError[0] = 1; // Flag an error for later
pdx->bSendCharsPending = false; // Allow other threads again pdx->bSendCharsPending = false; // Allow other threads again
spin_unlock(&pdx->charOutLock); // already at irq level spin_unlock(&pdx->charOutLock); // already at irq level
dev_dbg(&pdx->interface->dev, "%s - char out done, 0 chars sent", __func__); dev_dbg(&pdx->interface->dev,
} "%s - char out done, 0 chars sent", __func__);
else } else {
{ dev_dbg(&pdx->interface->dev,
dev_dbg(&pdx->interface->dev, "%s - char out done, %d chars sent", __func__, nGot); "%s - char out done, %d chars sent", __func__, nGot);
spin_lock(&pdx->charOutLock); // already at irq level spin_lock(&pdx->charOutLock); // already at irq level
pdx->dwNumOutput -= nGot; // Now adjust the char send buffer pdx->dwNumOutput -= nGot; // Now adjust the char send buffer
pdx->dwOutBuffGet += nGot; // to match what we did pdx->dwOutBuffGet += nGot; // to match what we did
...@@ -336,29 +336,33 @@ static void ced_writechar_callback(struct urb* pUrb) ...@@ -336,29 +336,33 @@ static void ced_writechar_callback(struct urb* pUrb)
{ {
int nPipe = 0; // The pipe number to use int nPipe = 0; // The pipe number to use
int iReturn; int iReturn;
char* pDat = &pdx->outputBuffer[pdx->dwOutBuffGet]; char *pDat = &pdx->outputBuffer[pdx->dwOutBuffGet];
unsigned int dwCount = pdx->dwNumOutput; // maximum to send unsigned int dwCount = pdx->dwNumOutput; // maximum to send
if ((pdx->dwOutBuffGet+dwCount) > OUTBUF_SZ) // does it cross buffer end? if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) // does it cross buffer end?
dwCount = OUTBUF_SZ - pdx->dwOutBuffGet; dwCount = OUTBUF_SZ - pdx->dwOutBuffGet;
spin_unlock(&pdx->charOutLock); // we are done with stuff that changes spin_unlock(&pdx->charOutLock); // we are done with stuff that changes
memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer
usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev, usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev,
usb_sndbulkpipe(pdx->udev, pdx->epAddr[0]), usb_sndbulkpipe(pdx->udev,
pdx->pCoherCharOut, dwCount, ced_writechar_callback, pdx); pdx->epAddr[0]),
pdx->pUrbCharOut->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; pdx->pCoherCharOut, dwCount,
ced_writechar_callback, pdx);
pdx->pUrbCharOut->transfer_flags |=
URB_NO_TRANSFER_DMA_MAP;
usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted); // in case we need to kill it usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted); // in case we need to kill it
iReturn = usb_submit_urb(pdx->pUrbCharOut, GFP_ATOMIC); iReturn = usb_submit_urb(pdx->pUrbCharOut, GFP_ATOMIC);
dev_dbg(&pdx->interface->dev, "%s n=%d>%s<", __func__, dwCount, pDat); dev_dbg(&pdx->interface->dev, "%s n=%d>%s<", __func__,
dwCount, pDat);
spin_lock(&pdx->charOutLock); // grab lock for errors spin_lock(&pdx->charOutLock); // grab lock for errors
if (iReturn) if (iReturn) {
{
pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later
pdx->bSendCharsPending = false; // Allow other threads again pdx->bSendCharsPending = false; // Allow other threads again
usb_unanchor_urb(pdx->pUrbCharOut); usb_unanchor_urb(pdx->pUrbCharOut);
dev_err(&pdx->interface->dev, "%s usb_submit_urb() returned %d", __func__, iReturn); dev_err(&pdx->interface->dev,
} "%s usb_submit_urb() returned %d",
__func__, iReturn);
} }
else } else
pdx->bSendCharsPending = false; // Allow other threads again pdx->bSendCharsPending = false; // Allow other threads again
spin_unlock(&pdx->charOutLock); // already at irq level spin_unlock(&pdx->charOutLock); // already at irq level
} }
...@@ -369,7 +373,7 @@ static void ced_writechar_callback(struct urb* pUrb) ...@@ -369,7 +373,7 @@ static void ced_writechar_callback(struct urb* pUrb)
** Transmit the characters in the output buffer to the 1401. This may need ** Transmit the characters in the output buffer to the 1401. This may need
** breaking down into multiple transfers. ** breaking down into multiple transfers.
****************************************************************************/ ****************************************************************************/
int SendChars(DEVICE_EXTENSION* pdx) int SendChars(DEVICE_EXTENSION * pdx)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
...@@ -382,10 +386,11 @@ int SendChars(DEVICE_EXTENSION* pdx) ...@@ -382,10 +386,11 @@ int SendChars(DEVICE_EXTENSION* pdx)
unsigned int dwCount = pdx->dwNumOutput; // Get a copy of the character count unsigned int dwCount = pdx->dwNumOutput; // Get a copy of the character count
pdx->bSendCharsPending = true; // Set flag to lock out other threads pdx->bSendCharsPending = true; // Set flag to lock out other threads
dev_dbg(&pdx->interface->dev, "Send %d chars to 1401, EP0 flag %d\n", dwCount, pdx->nPipes == 3); dev_dbg(&pdx->interface->dev,
"Send %d chars to 1401, EP0 flag %d\n", dwCount,
pdx->nPipes == 3);
// If we have only 3 end points we must send the characters to the 1401 using EP0. // If we have only 3 end points we must send the characters to the 1401 using EP0.
if (pdx->nPipes == 3) if (pdx->nPipes == 3) {
{
// For EP0 character transmissions to the 1401, we have to hang about until they // For EP0 character transmissions to the 1401, we have to hang about until they
// are gone, as otherwise without more character IO activity they will never go. // are gone, as otherwise without more character IO activity they will never go.
unsigned int count = dwCount; // Local char counter unsigned int count = dwCount; // Local char counter
...@@ -393,26 +398,25 @@ int SendChars(DEVICE_EXTENSION* pdx) ...@@ -393,26 +398,25 @@ int SendChars(DEVICE_EXTENSION* pdx)
spin_unlock_irq(&pdx->charOutLock); // Free spinlock as we call USBD spin_unlock_irq(&pdx->charOutLock); // Free spinlock as we call USBD
while ((count > 0) && (iReturn == U14ERR_NOERROR)) while ((count > 0) && (iReturn == U14ERR_NOERROR)) {
{
// We have to break the transfer up into 64-byte chunks because of a 2270 problem // We have to break the transfer up into 64-byte chunks because of a 2270 problem
int n = count > 64 ? 64 : count; // Chars for this xfer, max of 64 int n = count > 64 ? 64 : count; // Chars for this xfer, max of 64
int nSent = usb_control_msg(pdx->udev, int nSent = usb_control_msg(pdx->udev,
usb_sndctrlpipe(pdx->udev,0), // use end point 0 usb_sndctrlpipe(pdx->udev, 0), // use end point 0
DB_CHARS, // bRequest DB_CHARS, // bRequest
(H_TO_D|VENDOR|DEVREQ), // to the device, vendor request to the device (H_TO_D | VENDOR | DEVREQ), // to the device, vendor request to the device
0,0, // value and index are both 0 0, 0, // value and index are both 0
&pdx->outputBuffer[index], // where to send from &pdx->outputBuffer[index], // where to send from
n, // how much to send n, // how much to send
1000); // timeout in jiffies 1000); // timeout in jiffies
if (nSent <= 0) if (nSent <= 0) {
{
iReturn = nSent ? nSent : -ETIMEDOUT; // if 0 chars says we timed out iReturn = nSent ? nSent : -ETIMEDOUT; // if 0 chars says we timed out
dev_err(&pdx->interface->dev, "Send %d chars by EP0 failed: %d", n, iReturn); dev_err(&pdx->interface->dev,
} "Send %d chars by EP0 failed: %d",
else n, iReturn);
{ } else {
dev_dbg(&pdx->interface->dev, "Sent %d chars by EP0", n); dev_dbg(&pdx->interface->dev,
"Sent %d chars by EP0", n);
count -= nSent; count -= nSent;
index += nSent; index += nSent;
} }
...@@ -423,35 +427,33 @@ int SendChars(DEVICE_EXTENSION* pdx) ...@@ -423,35 +427,33 @@ int SendChars(DEVICE_EXTENSION* pdx)
pdx->dwOutBuffPut = 0; pdx->dwOutBuffPut = 0;
pdx->dwNumOutput = 0; // and clear the buffer count pdx->dwNumOutput = 0; // and clear the buffer count
pdx->bSendCharsPending = false; // Allow other threads again pdx->bSendCharsPending = false; // Allow other threads again
} } else { // Here for sending chars normally - we hold the spin lock
else
{ // Here for sending chars normally - we hold the spin lock
int nPipe = 0; // The pipe number to use int nPipe = 0; // The pipe number to use
char* pDat = &pdx->outputBuffer[pdx->dwOutBuffGet]; char *pDat = &pdx->outputBuffer[pdx->dwOutBuffGet];
if ((pdx->dwOutBuffGet+dwCount) > OUTBUF_SZ) // does it cross buffer end? if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) // does it cross buffer end?
dwCount = OUTBUF_SZ - pdx->dwOutBuffGet; dwCount = OUTBUF_SZ - pdx->dwOutBuffGet;
spin_unlock_irq(&pdx->charOutLock); // we are done with stuff that changes spin_unlock_irq(&pdx->charOutLock); // we are done with stuff that changes
memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer
usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev, usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev,
usb_sndbulkpipe(pdx->udev, pdx->epAddr[0]), usb_sndbulkpipe(pdx->udev,
pdx->pCoherCharOut, dwCount, ced_writechar_callback, pdx); pdx->epAddr[0]),
pdx->pUrbCharOut->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; pdx->pCoherCharOut, dwCount,
ced_writechar_callback, pdx);
pdx->pUrbCharOut->transfer_flags |=
URB_NO_TRANSFER_DMA_MAP;
usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted); usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted);
iReturn = usb_submit_urb(pdx->pUrbCharOut, GFP_KERNEL); iReturn = usb_submit_urb(pdx->pUrbCharOut, GFP_KERNEL);
spin_lock_irq(&pdx->charOutLock); // grab lock for errors spin_lock_irq(&pdx->charOutLock); // grab lock for errors
if (iReturn) if (iReturn) {
{
pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later
pdx->bSendCharsPending = false; // Allow other threads again pdx->bSendCharsPending = false; // Allow other threads again
usb_unanchor_urb(pdx->pUrbCharOut); // remove from list of active urbs usb_unanchor_urb(pdx->pUrbCharOut); // remove from list of active urbs
} }
} }
} } else if (pdx->bSendCharsPending && (pdx->dwNumOutput > 0))
else dev_dbg(&pdx->interface->dev,
if (pdx->bSendCharsPending && (pdx->dwNumOutput > 0)) "SendChars bSendCharsPending:true");
dev_dbg(&pdx->interface->dev, "SendChars bSendCharsPending:true");
dev_dbg(&pdx->interface->dev, "SendChars exit code: %d", iReturn); dev_dbg(&pdx->interface->dev, "SendChars exit code: %d", iReturn);
spin_unlock_irq(&pdx->charOutLock); // Now let go of the spinlock spin_unlock_irq(&pdx->charOutLock); // Now let go of the spinlock
...@@ -472,67 +474,68 @@ int SendChars(DEVICE_EXTENSION* pdx) ...@@ -472,67 +474,68 @@ int SendChars(DEVICE_EXTENSION* pdx)
** pdx Is our device extension which holds all we know about the transfer. ** pdx Is our device extension which holds all we know about the transfer.
** n The number of bytes to move one way or the other. ** n The number of bytes to move one way or the other.
***************************************************************************/ ***************************************************************************/
static void CopyUserSpace(DEVICE_EXTENSION *pdx, int n) static void CopyUserSpace(DEVICE_EXTENSION * pdx, int n)
{ {
unsigned int nArea = pdx->StagedId; unsigned int nArea = pdx->StagedId;
if (nArea < MAX_TRANSAREAS) if (nArea < MAX_TRANSAREAS) {
{
TRANSAREA *pArea = &pdx->rTransDef[nArea]; // area to be used TRANSAREA *pArea = &pdx->rTransDef[nArea]; // area to be used
unsigned int dwOffset = pdx->StagedDone + pdx->StagedOffset + pArea->dwBaseOffset; unsigned int dwOffset =
char* pCoherBuf = pdx->pCoherStagedIO; // coherent buffer pdx->StagedDone + pdx->StagedOffset + pArea->dwBaseOffset;
if (!pArea->bUsed) char *pCoherBuf = pdx->pCoherStagedIO; // coherent buffer
{ if (!pArea->bUsed) {
dev_err(&pdx->interface->dev, "%s area %d unused", __func__, nArea); dev_err(&pdx->interface->dev, "%s area %d unused",
__func__, nArea);
return; return;
} }
while (n) while (n) {
{
int nPage = dwOffset >> PAGE_SHIFT; // page number in table int nPage = dwOffset >> PAGE_SHIFT; // page number in table
if (nPage < pArea->nPages) if (nPage < pArea->nPages) {
{ char *pvAddress =
char *pvAddress = (char*)kmap_atomic(pArea->pPages[nPage]); (char *)kmap_atomic(pArea->pPages[nPage]);
if (pvAddress) if (pvAddress) {
{ unsigned int uiPageOff = dwOffset & (PAGE_SIZE - 1); // offset into the page
unsigned int uiPageOff = dwOffset & (PAGE_SIZE-1); // offset into the page
size_t uiXfer = PAGE_SIZE - uiPageOff; // max to transfer on this page size_t uiXfer = PAGE_SIZE - uiPageOff; // max to transfer on this page
if (uiXfer > n) // limit byte count if too much if (uiXfer > n) // limit byte count if too much
uiXfer = n; // for the page uiXfer = n; // for the page
if (pdx->StagedRead) if (pdx->StagedRead)
memcpy(pvAddress+uiPageOff, pCoherBuf, uiXfer); memcpy(pvAddress + uiPageOff,
pCoherBuf, uiXfer);
else else
memcpy(pCoherBuf, pvAddress+uiPageOff, uiXfer); memcpy(pCoherBuf,
pvAddress + uiPageOff,
uiXfer);
kunmap_atomic(pvAddress); kunmap_atomic(pvAddress);
dwOffset += uiXfer; dwOffset += uiXfer;
pCoherBuf += uiXfer; pCoherBuf += uiXfer;
n -= uiXfer; n -= uiXfer;
} } else {
else dev_err(&pdx->interface->dev,
{ "%s did not map page %d",
dev_err(&pdx->interface->dev, "%s did not map page %d", __func__, nPage); __func__, nPage);
return; return;
} }
} } else {
else dev_err(&pdx->interface->dev,
{ "%s exceeded pages %d", __func__,
dev_err(&pdx->interface->dev, "%s exceeded pages %d", __func__, nPage); nPage);
return; return;
} }
} }
} } else
else dev_err(&pdx->interface->dev, "%s bad area %d", __func__,
dev_err(&pdx->interface->dev, "%s bad area %d", __func__, nArea); nArea);
} }
// Forward declarations for stuff used circularly // Forward declarations for stuff used circularly
static int StageChunk(DEVICE_EXTENSION *pdx); static int StageChunk(DEVICE_EXTENSION * pdx);
/*************************************************************************** /***************************************************************************
** ReadWrite_Complete ** ReadWrite_Complete
** **
** Completion routine for our staged read/write Irps ** Completion routine for our staged read/write Irps
*/ */
static void staged_callback(struct urb* pUrb) static void staged_callback(struct urb *pUrb)
{ {
DEVICE_EXTENSION *pdx = pUrb->context; DEVICE_EXTENSION *pdx = pUrb->context;
unsigned int nGot = pUrb->actual_length; // what we transferred unsigned int nGot = pUrb->actual_length; // what we transferred
...@@ -542,24 +545,25 @@ static void staged_callback(struct urb* pUrb) ...@@ -542,24 +545,25 @@ static void staged_callback(struct urb* pUrb)
spin_lock(&pdx->stagedLock); // stop ReadWriteMem() action while this routine is running spin_lock(&pdx->stagedLock); // stop ReadWriteMem() action while this routine is running
pdx->bStagedUrbPending = false; // clear the flag for staged IRP pending pdx->bStagedUrbPending = false; // clear the flag for staged IRP pending
if (pUrb->status) if (pUrb->status) { // sync/async unlink faults aren't errors
{ // sync/async unlink faults aren't errors if (!
if (!(pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET
{ || pUrb->status == -ESHUTDOWN)) {
dev_err(&pdx->interface->dev, "%s - nonzero write bulk status received: %d", __func__, pUrb->status); dev_err(&pdx->interface->dev,
} "%s - nonzero write bulk status received: %d",
else __func__, pUrb->status);
dev_info(&pdx->interface->dev, "%s - staged xfer cancelled", __func__); } else
dev_info(&pdx->interface->dev,
"%s - staged xfer cancelled", __func__);
spin_lock(&pdx->err_lock); spin_lock(&pdx->err_lock);
pdx->errors = pUrb->status; pdx->errors = pUrb->status;
spin_unlock(&pdx->err_lock); spin_unlock(&pdx->err_lock);
nGot = 0; // and tidy up again if so nGot = 0; // and tidy up again if so
bCancel = true; bCancel = true;
} } else {
else dev_dbg(&pdx->interface->dev, "%s %d chars xferred", __func__,
{ nGot);
dev_dbg(&pdx->interface->dev, "%s %d chars xferred", __func__, nGot);
if (pdx->StagedRead) // if reading, save to user space if (pdx->StagedRead) // if reading, save to user space
CopyUserSpace(pdx, nGot); // copy from buffer to user CopyUserSpace(pdx, nGot); // copy from buffer to user
if (nGot == 0) if (nGot == 0)
...@@ -569,13 +573,16 @@ static void staged_callback(struct urb* pUrb) ...@@ -569,13 +573,16 @@ static void staged_callback(struct urb* pUrb)
// Update the transfer length based on the TransferBufferLength value in the URB // Update the transfer length based on the TransferBufferLength value in the URB
pdx->StagedDone += nGot; pdx->StagedDone += nGot;
dev_dbg(&pdx->interface->dev, "%s, done %d bytes of %d", __func__, pdx->StagedDone, pdx->StagedLength); dev_dbg(&pdx->interface->dev, "%s, done %d bytes of %d", __func__,
pdx->StagedDone, pdx->StagedLength);
if ((pdx->StagedDone == pdx->StagedLength) || // If no more to do if ((pdx->StagedDone == pdx->StagedLength) || // If no more to do
(bCancel)) // or this IRP was cancelled (bCancel)) // or this IRP was cancelled
{ {
TRANSAREA* pArea = &pdx->rTransDef[pdx->StagedId]; // Transfer area info TRANSAREA *pArea = &pdx->rTransDef[pdx->StagedId]; // Transfer area info
dev_dbg(&pdx->interface->dev, "%s transfer done, bytes %d, cancel %d", __func__, pdx->StagedDone, bCancel); dev_dbg(&pdx->interface->dev,
"%s transfer done, bytes %d, cancel %d", __func__,
pdx->StagedDone, bCancel);
// Here is where we sort out what to do with this transfer if using a circular buffer. We have // Here is where we sort out what to do with this transfer if using a circular buffer. We have
// a completed transfer that can be assumed to fit into the transfer area. We should be able to // a completed transfer that can be assumed to fit into the transfer area. We should be able to
...@@ -586,53 +593,74 @@ static void staged_callback(struct urb* pUrb) ...@@ -586,53 +593,74 @@ static void staged_callback(struct urb* pUrb)
{ {
if (pArea->aBlocks[1].dwSize > 0) // If block 1 is in use we must append to it if (pArea->aBlocks[1].dwSize > 0) // If block 1 is in use we must append to it
{ {
if (pdx->StagedOffset == (pArea->aBlocks[1].dwOffset + pArea->aBlocks[1].dwSize)) if (pdx->StagedOffset ==
{ (pArea->aBlocks[1].dwOffset +
pArea->aBlocks[1].dwSize += pdx->StagedLength; pArea->aBlocks[1].dwSize)) {
dev_dbg(&pdx->interface->dev, "RWM_Complete, circ block 1 now %d bytes at %d", pArea->aBlocks[1].dwSize +=
pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset); pdx->StagedLength;
} dev_dbg(&pdx->interface->dev,
else "RWM_Complete, circ block 1 now %d bytes at %d",
{ pArea->aBlocks[1].dwSize,
pArea->aBlocks[1].dwOffset);
} else {
// Here things have gone very, very, wrong, but I cannot see how this can actually be achieved // Here things have gone very, very, wrong, but I cannot see how this can actually be achieved
pArea->aBlocks[1].dwOffset = pdx->StagedOffset; pArea->aBlocks[1].dwOffset =
pArea->aBlocks[1].dwSize = pdx->StagedLength; pdx->StagedOffset;
dev_err(&pdx->interface->dev, "%s ERROR, circ block 1 re-started %d bytes at %d", pArea->aBlocks[1].dwSize =
__func__, pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset); pdx->StagedLength;
} dev_err(&pdx->interface->dev,
} "%s ERROR, circ block 1 re-started %d bytes at %d",
else // If block 1 is not used, we try to add to block 0 __func__,
pArea->aBlocks[1].dwSize,
pArea->aBlocks[1].dwOffset);
}
} else // If block 1 is not used, we try to add to block 0
{ {
if (pArea->aBlocks[0].dwSize > 0) // Got stored block 0 information? if (pArea->aBlocks[0].dwSize > 0) // Got stored block 0 information?
{ // Must append onto the existing block 0 { // Must append onto the existing block 0
if (pdx->StagedOffset == (pArea->aBlocks[0].dwOffset + pArea->aBlocks[0].dwSize)) if (pdx->StagedOffset ==
{ (pArea->aBlocks[0].dwOffset +
pArea->aBlocks[0].dwSize)) {
pArea->aBlocks[0].dwSize += pdx->StagedLength; // Just add this transfer in pArea->aBlocks[0].dwSize += pdx->StagedLength; // Just add this transfer in
dev_dbg(&pdx->interface->dev, "RWM_Complete, circ block 0 now %d bytes at %d", dev_dbg(&pdx->interface->dev,
pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset); "RWM_Complete, circ block 0 now %d bytes at %d",
} pArea->aBlocks[0].
else // If it doesn't append, put into new block 1 dwSize,
{ pArea->aBlocks[0].
pArea->aBlocks[1].dwOffset = pdx->StagedOffset; dwOffset);
pArea->aBlocks[1].dwSize = pdx->StagedLength; } else // If it doesn't append, put into new block 1
dev_dbg(&pdx->interface->dev, "RWM_Complete, circ block 1 started %d bytes at %d", {
pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset); pArea->aBlocks[1].dwOffset =
} pdx->StagedOffset;
} pArea->aBlocks[1].dwSize =
else // No info stored yet, just save in block 0 pdx->StagedLength;
{ dev_dbg(&pdx->interface->dev,
pArea->aBlocks[0].dwOffset = pdx->StagedOffset; "RWM_Complete, circ block 1 started %d bytes at %d",
pArea->aBlocks[0].dwSize = pdx->StagedLength; pArea->aBlocks[1].
dev_dbg(&pdx->interface->dev, "RWM_Complete, circ block 0 started %d bytes at %d", dwSize,
pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset); pArea->aBlocks[1].
dwOffset);
}
} else // No info stored yet, just save in block 0
{
pArea->aBlocks[0].dwOffset =
pdx->StagedOffset;
pArea->aBlocks[0].dwSize =
pdx->StagedLength;
dev_dbg(&pdx->interface->dev,
"RWM_Complete, circ block 0 started %d bytes at %d",
pArea->aBlocks[0].dwSize,
pArea->aBlocks[0].dwOffset);
} }
} }
} }
if (!bCancel) // Don't generate an event if cancelled if (!bCancel) // Don't generate an event if cancelled
{ {
dev_dbg(&pdx->interface->dev, "RWM_Complete, bCircular %d, bToHost %d, eStart %d, eSize %d", dev_dbg(&pdx->interface->dev,
pArea->bCircular, pArea->bEventToHost, pArea->dwEventSt, pArea->dwEventSz); "RWM_Complete, bCircular %d, bToHost %d, eStart %d, eSize %d",
pArea->bCircular, pArea->bEventToHost,
pArea->dwEventSt, pArea->dwEventSz);
if ((pArea->dwEventSz) && // Set a user-mode event... if ((pArea->dwEventSz) && // Set a user-mode event...
(pdx->StagedRead == pArea->bEventToHost)) // ...on transfers in this direction? (pdx->StagedRead == pArea->bEventToHost)) // ...on transfers in this direction?
{ {
...@@ -642,19 +670,23 @@ static void staged_callback(struct urb* pUrb) ...@@ -642,19 +670,23 @@ static void staged_callback(struct urb* pUrb)
if ((pArea->bCircular) && // Circular areas use a simpler test if ((pArea->bCircular) && // Circular areas use a simpler test
(pArea->bCircToHost)) // only in supported direction (pArea->bCircToHost)) // only in supported direction
{ // Is total data waiting up to size limit? { // Is total data waiting up to size limit?
unsigned int dwTotal = pArea->aBlocks[0].dwSize + pArea->aBlocks[1].dwSize; unsigned int dwTotal =
pArea->aBlocks[0].dwSize +
pArea->aBlocks[1].dwSize;
iWakeUp = (dwTotal >= pArea->dwEventSz); iWakeUp = (dwTotal >= pArea->dwEventSz);
} } else {
else unsigned int transEnd =
{ pdx->StagedOffset +
unsigned int transEnd = pdx->StagedOffset + pdx->StagedLength; pdx->StagedLength;
unsigned int eventEnd = pArea->dwEventSt + pArea->dwEventSz; unsigned int eventEnd =
iWakeUp = (pdx->StagedOffset < eventEnd) && (transEnd > pArea->dwEventSt); pArea->dwEventSt + pArea->dwEventSz;
} iWakeUp = (pdx->StagedOffset < eventEnd)
&& (transEnd > pArea->dwEventSt);
if (iWakeUp) }
{
dev_dbg(&pdx->interface->dev, "About to set event to notify app"); if (iWakeUp) {
dev_dbg(&pdx->interface->dev,
"About to set event to notify app");
wake_up_interruptible(&pArea->wqEvent); // wake up waiting processes wake_up_interruptible(&pArea->wqEvent); // wake up waiting processes
++pArea->iWakeUp; // increment wakeup count ++pArea->iWakeUp; // increment wakeup count
} }
...@@ -669,22 +701,29 @@ static void staged_callback(struct urb* pUrb) ...@@ -669,22 +701,29 @@ static void staged_callback(struct urb* pUrb)
if (pdx->bXFerWaiting) // Got a block xfer waiting? if (pdx->bXFerWaiting) // Got a block xfer waiting?
{ {
int iReturn; int iReturn;
dev_info(&pdx->interface->dev, "*** RWM_Complete *** pending transfer will now be set up!!!"); dev_info(&pdx->interface->dev,
iReturn = ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard, pdx->rDMAInfo.wIdent, pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize); "*** RWM_Complete *** pending transfer will now be set up!!!");
iReturn =
ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard,
pdx->rDMAInfo.wIdent,
pdx->rDMAInfo.dwOffset,
pdx->rDMAInfo.dwSize);
if (iReturn) if (iReturn)
dev_err(&pdx->interface->dev, "RWM_Complete rw setup failed %d", iReturn); dev_err(&pdx->interface->dev,
"RWM_Complete rw setup failed %d",
iReturn);
} }
} }
} } else // Here for more to do
else // Here for more to do
StageChunk(pdx); // fire off the next bit StageChunk(pdx); // fire off the next bit
// While we hold the stagedLock, see if we should reallow character input ints // While we hold the stagedLock, see if we should reallow character input ints
// Don't allow if cancelled, or if a new block has started or if there is a waiting block. // Don't allow if cancelled, or if a new block has started or if there is a waiting block.
// This feels wrong as we should ask which spin lock protects dwDMAFlag. // This feels wrong as we should ask which spin lock protects dwDMAFlag.
bRestartCharInput = !bCancel && (pdx->dwDMAFlag == MODE_CHAR) && !pdx->bXFerWaiting; bRestartCharInput = !bCancel && (pdx->dwDMAFlag == MODE_CHAR)
&& !pdx->bXFerWaiting;
spin_unlock(&pdx->stagedLock); // Finally release the lock again spin_unlock(&pdx->stagedLock); // Finally release the lock again
...@@ -704,18 +743,20 @@ static void staged_callback(struct urb* pUrb) ...@@ -704,18 +743,20 @@ static void staged_callback(struct urb* pUrb)
** The calling code must have acquired the staging spinlock before calling ** The calling code must have acquired the staging spinlock before calling
** this function, and is responsible for releasing it. We are at callback level. ** this function, and is responsible for releasing it. We are at callback level.
****************************************************************************/ ****************************************************************************/
static int StageChunk(DEVICE_EXTENSION *pdx) static int StageChunk(DEVICE_EXTENSION * pdx)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
unsigned int ChunkSize; unsigned int ChunkSize;
int nPipe = pdx->StagedRead ? 3 : 2; // The pipe number to use for reads or writes int nPipe = pdx->StagedRead ? 3 : 2; // The pipe number to use for reads or writes
if (pdx->nPipes == 3) nPipe--; // Adjust for the 3-pipe case if (pdx->nPipes == 3)
nPipe--; // Adjust for the 3-pipe case
if (nPipe < 0) // and trap case that should never happen if (nPipe < 0) // and trap case that should never happen
return U14ERR_FAIL; return U14ERR_FAIL;
if (!CanAcceptIoRequests(pdx)) // got sudden remove? if (!CanAcceptIoRequests(pdx)) // got sudden remove?
{ {
dev_info(&pdx->interface->dev, "%s sudden remove, giving up", __func__); dev_info(&pdx->interface->dev, "%s sudden remove, giving up",
__func__);
return U14ERR_FAIL; // could do with a better error return U14ERR_FAIL; // could do with a better error
} }
...@@ -727,21 +768,23 @@ static int StageChunk(DEVICE_EXTENSION *pdx) ...@@ -727,21 +768,23 @@ static int StageChunk(DEVICE_EXTENSION *pdx)
CopyUserSpace(pdx, ChunkSize); // ...copy data into the buffer CopyUserSpace(pdx, ChunkSize); // ...copy data into the buffer
usb_fill_bulk_urb(pdx->pStagedUrb, pdx->udev, usb_fill_bulk_urb(pdx->pStagedUrb, pdx->udev,
pdx->StagedRead ? usb_rcvbulkpipe(pdx->udev, pdx->epAddr[nPipe]): pdx->StagedRead ? usb_rcvbulkpipe(pdx->udev,
pdx->
epAddr[nPipe]) :
usb_sndbulkpipe(pdx->udev, pdx->epAddr[nPipe]), usb_sndbulkpipe(pdx->udev, pdx->epAddr[nPipe]),
pdx->pCoherStagedIO, ChunkSize, staged_callback, pdx); pdx->pCoherStagedIO, ChunkSize, staged_callback, pdx);
pdx->pStagedUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; pdx->pStagedUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
usb_anchor_urb(pdx->pStagedUrb, &pdx->submitted); // in case we need to kill it usb_anchor_urb(pdx->pStagedUrb, &pdx->submitted); // in case we need to kill it
iReturn = usb_submit_urb(pdx->pStagedUrb, GFP_ATOMIC); iReturn = usb_submit_urb(pdx->pStagedUrb, GFP_ATOMIC);
if (iReturn) if (iReturn) {
{
usb_unanchor_urb(pdx->pStagedUrb); // kill it usb_unanchor_urb(pdx->pStagedUrb); // kill it
pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later
dev_err(&pdx->interface->dev, "%s submit urb failed, code %d", __func__, iReturn); dev_err(&pdx->interface->dev, "%s submit urb failed, code %d",
} __func__, iReturn);
else } else
pdx->bStagedUrbPending = true; // Set the flag for staged URB pending pdx->bStagedUrbPending = true; // Set the flag for staged URB pending
dev_dbg(&pdx->interface->dev, "%s done so far:%d, this size:%d", __func__, pdx->StagedDone, ChunkSize); dev_dbg(&pdx->interface->dev, "%s done so far:%d, this size:%d",
__func__, pdx->StagedDone, ChunkSize);
return iReturn; return iReturn;
} }
...@@ -763,32 +806,36 @@ static int StageChunk(DEVICE_EXTENSION *pdx) ...@@ -763,32 +806,36 @@ static int StageChunk(DEVICE_EXTENSION *pdx)
** transfer. ** transfer.
** dwLen - the number of bytes to transfer. ** dwLen - the number of bytes to transfer.
*/ */
int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, int ReadWriteMem(DEVICE_EXTENSION * pdx, bool Read, unsigned short wIdent,
unsigned int dwOffs, unsigned int dwLen) unsigned int dwOffs, unsigned int dwLen)
{ {
TRANSAREA* pArea = &pdx->rTransDef[wIdent]; // Transfer area info TRANSAREA *pArea = &pdx->rTransDef[wIdent]; // Transfer area info
if (!CanAcceptIoRequests(pdx)) // Are we in a state to accept new requests? if (!CanAcceptIoRequests(pdx)) // Are we in a state to accept new requests?
{ {
dev_err(&pdx->interface->dev, "%s can't accept requests", __func__); dev_err(&pdx->interface->dev, "%s can't accept requests",
__func__);
return U14ERR_FAIL; return U14ERR_FAIL;
} }
dev_dbg(&pdx->interface->dev, "%s xfer %d bytes to %s, offset %d, area %d", dev_dbg(&pdx->interface->dev,
__func__, dwLen, Read ? "host" : "1401", dwOffs, wIdent); "%s xfer %d bytes to %s, offset %d, area %d", __func__, dwLen,
Read ? "host" : "1401", dwOffs, wIdent);
// Amazingly, we can get an escape sequence back before the current staged Urb is done, so we // Amazingly, we can get an escape sequence back before the current staged Urb is done, so we
// have to check for this situation and, if so, wait until all is OK. // have to check for this situation and, if so, wait until all is OK.
if (pdx->bStagedUrbPending) if (pdx->bStagedUrbPending) {
{
pdx->bXFerWaiting = true; // Flag we are waiting pdx->bXFerWaiting = true; // Flag we are waiting
dev_info(&pdx->interface->dev, "%s xfer is waiting, as previous staged pending", __func__); dev_info(&pdx->interface->dev,
"%s xfer is waiting, as previous staged pending",
__func__);
return U14ERR_NOERROR; return U14ERR_NOERROR;
} }
if (dwLen == 0) // allow 0-len read or write; just return success if (dwLen == 0) // allow 0-len read or write; just return success
{ {
dev_dbg(&pdx->interface->dev, "%s OK; zero-len read/write request", __func__); dev_dbg(&pdx->interface->dev,
"%s OK; zero-len read/write request", __func__);
return U14ERR_NOERROR; return U14ERR_NOERROR;
} }
...@@ -797,20 +844,23 @@ int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, ...@@ -797,20 +844,23 @@ int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent,
{ // If so, we sort out offset ourself { // If so, we sort out offset ourself
bool bWait = false; // Flag for transfer having to wait bool bWait = false; // Flag for transfer having to wait
dev_dbg(&pdx->interface->dev, "Circular buffers are %d at %d and %d at %d", dev_dbg(&pdx->interface->dev,
pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset, pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset); "Circular buffers are %d at %d and %d at %d",
pArea->aBlocks[0].dwSize, pArea->aBlocks[0].dwOffset,
pArea->aBlocks[1].dwSize, pArea->aBlocks[1].dwOffset);
if (pArea->aBlocks[1].dwSize > 0) // Using the second block already? if (pArea->aBlocks[1].dwSize > 0) // Using the second block already?
{ {
dwOffs = pArea->aBlocks[1].dwOffset + pArea->aBlocks[1].dwSize; // take offset from that dwOffs = pArea->aBlocks[1].dwOffset + pArea->aBlocks[1].dwSize; // take offset from that
bWait = (dwOffs + dwLen) > pArea->aBlocks[0].dwOffset; // Wait if will overwrite block 0? bWait = (dwOffs + dwLen) > pArea->aBlocks[0].dwOffset; // Wait if will overwrite block 0?
bWait |= (dwOffs + dwLen) > pArea->dwLength; // or if it overflows the buffer bWait |= (dwOffs + dwLen) > pArea->dwLength; // or if it overflows the buffer
} } else // Area 1 not in use, try to use area 0
else // Area 1 not in use, try to use area 0
{ {
if (pArea->aBlocks[0].dwSize == 0) // Reset block 0 if not in use if (pArea->aBlocks[0].dwSize == 0) // Reset block 0 if not in use
pArea->aBlocks[0].dwOffset = 0; pArea->aBlocks[0].dwOffset = 0;
dwOffs = pArea->aBlocks[0].dwOffset + pArea->aBlocks[0].dwSize; dwOffs =
if ((dwOffs+dwLen) > pArea->dwLength) // Off the end of the buffer? pArea->aBlocks[0].dwOffset +
pArea->aBlocks[0].dwSize;
if ((dwOffs + dwLen) > pArea->dwLength) // Off the end of the buffer?
{ {
pArea->aBlocks[1].dwOffset = 0; // Set up to use second block pArea->aBlocks[1].dwOffset = 0; // Set up to use second block
dwOffs = 0; dwOffs = 0;
...@@ -822,13 +872,16 @@ int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, ...@@ -822,13 +872,16 @@ int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent,
if (bWait) // This transfer will have to wait? if (bWait) // This transfer will have to wait?
{ {
pdx->bXFerWaiting = true; // Flag we are waiting pdx->bXFerWaiting = true; // Flag we are waiting
dev_dbg(&pdx->interface->dev, "%s xfer waiting for circular buffer space", __func__); dev_dbg(&pdx->interface->dev,
"%s xfer waiting for circular buffer space",
__func__);
return U14ERR_NOERROR; return U14ERR_NOERROR;
} }
dev_dbg(&pdx->interface->dev, "%s circular xfer, %d bytes starting at %d", __func__, dwLen, dwOffs); dev_dbg(&pdx->interface->dev,
"%s circular xfer, %d bytes starting at %d", __func__,
dwLen, dwOffs);
} }
// Save the parameters for the read\write transfer // Save the parameters for the read\write transfer
pdx->StagedRead = Read; // Save the parameters for this read pdx->StagedRead = Read; // Save the parameters for this read
pdx->StagedId = wIdent; // ID allows us to get transfer area info pdx->StagedId = wIdent; // ID allows us to get transfer area info
...@@ -852,14 +905,15 @@ int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, ...@@ -852,14 +905,15 @@ int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent,
** data we return FALSE. Used as part of decoding a DMA request. ** data we return FALSE. Used as part of decoding a DMA request.
** **
****************************************************************************/ ****************************************************************************/
static bool ReadChar(unsigned char* pChar, char* pBuf, unsigned int* pdDone, unsigned int dGot) static bool ReadChar(unsigned char *pChar, char *pBuf, unsigned int *pdDone,
unsigned int dGot)
{ {
bool bRead = false; bool bRead = false;
unsigned int dDone = *pdDone; unsigned int dDone = *pdDone;
if (dDone < dGot) // If there is more data if (dDone < dGot) // If there is more data
{ {
*pChar = (unsigned char)pBuf[dDone];// Extract the next char *pChar = (unsigned char)pBuf[dDone]; // Extract the next char
dDone++; // Increment the done count dDone++; // Increment the done count
*pdDone = dDone; *pdDone = dDone;
bRead = true; // and flag success bRead = true; // and flag success
...@@ -876,10 +930,12 @@ static bool ReadChar(unsigned char* pChar, char* pBuf, unsigned int* pdDone, uns ...@@ -876,10 +930,12 @@ static bool ReadChar(unsigned char* pChar, char* pBuf, unsigned int* pdDone, uns
** Reads a word from the 1401, just uses ReadChar twice; passes on any error ** Reads a word from the 1401, just uses ReadChar twice; passes on any error
** **
*****************************************************************************/ *****************************************************************************/
static bool ReadWord(unsigned short* pWord, char* pBuf, unsigned int* pdDone, unsigned int dGot) static bool ReadWord(unsigned short *pWord, char *pBuf, unsigned int *pdDone,
unsigned int dGot)
{ {
if (ReadChar((unsigned char*)pWord, pBuf, pdDone, dGot)) if (ReadChar((unsigned char *)pWord, pBuf, pdDone, dGot))
return ReadChar(((unsigned char*)pWord)+1, pBuf, pdDone, dGot); return ReadChar(((unsigned char *)pWord) + 1, pBuf, pdDone,
dGot);
else else
return false; return false;
} }
...@@ -895,35 +951,31 @@ static bool ReadWord(unsigned short* pWord, char* pBuf, unsigned int* pdDone, un ...@@ -895,35 +951,31 @@ static bool ReadWord(unsigned short* pWord, char* pBuf, unsigned int* pdDone, un
** to indicate three byte total. ** to indicate three byte total.
** **
*****************************************************************************/ *****************************************************************************/
static bool ReadHuff(volatile unsigned int* pDWord, char* pBuf, unsigned int* pdDone, unsigned int dGot) static bool ReadHuff(volatile unsigned int *pDWord, char *pBuf,
unsigned int *pdDone, unsigned int dGot)
{ {
unsigned char ucData; /* for each read to ReadChar */ unsigned char ucData; /* for each read to ReadChar */
bool bReturn = true; /* assume we will succeed */ bool bReturn = true; /* assume we will succeed */
unsigned int dwData = 0; /* Accumulator for the data */ unsigned int dwData = 0; /* Accumulator for the data */
if (ReadChar(&ucData, pBuf, pdDone, dGot)) if (ReadChar(&ucData, pBuf, pdDone, dGot)) {
{
dwData = ucData; /* copy the data */ dwData = ucData; /* copy the data */
if ((dwData & 0x00000080) != 0) /* Bit set for more data ? */ if ((dwData & 0x00000080) != 0) { /* Bit set for more data ? */
{
dwData &= 0x0000007F; /* Clear the relevant bit */ dwData &= 0x0000007F; /* Clear the relevant bit */
if (ReadChar(&ucData, pBuf, pdDone, dGot)) if (ReadChar(&ucData, pBuf, pdDone, dGot)) {
{
dwData = (dwData << 8) | ucData; dwData = (dwData << 8) | ucData;
if ((dwData & 0x00004000) != 0) /* three byte sequence ? */ if ((dwData & 0x00004000) != 0) { /* three byte sequence ? */
{
dwData &= 0x00003FFF; /* Clear the relevant bit */ dwData &= 0x00003FFF; /* Clear the relevant bit */
if (ReadChar(&ucData, pBuf, pdDone, dGot)) if (ReadChar
(&ucData, pBuf, pdDone, dGot))
dwData = (dwData << 8) | ucData; dwData = (dwData << 8) | ucData;
else else
bReturn = false; bReturn = false;
} }
} } else
else
bReturn = false; /* couldn't read data */ bReturn = false; /* couldn't read data */
} }
} } else
else
bReturn = false; bReturn = false;
*pDWord = dwData; /* return the data */ *pDWord = dwData; /* return the data */
...@@ -944,8 +996,8 @@ static bool ReadHuff(volatile unsigned int* pDWord, char* pBuf, unsigned int* pd ...@@ -944,8 +996,8 @@ static bool ReadHuff(volatile unsigned int* pDWord, char* pBuf, unsigned int* pd
** we start handling the data at offset zero. ** we start handling the data at offset zero.
** **
*****************************************************************************/ *****************************************************************************/
static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx, static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx,
char* pBuf, unsigned int dwCount) char *pBuf, unsigned int dwCount)
{ {
bool bResult = false; // assume we won't succeed bool bResult = false; // assume we won't succeed
unsigned char ucData; unsigned char ucData;
...@@ -953,8 +1005,7 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx, ...@@ -953,8 +1005,7 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx,
dev_dbg(&pdx->interface->dev, "%s", __func__); dev_dbg(&pdx->interface->dev, "%s", __func__);
if (ReadChar(&ucData, pBuf, &dDone, dwCount)) if (ReadChar(&ucData, pBuf, &dDone, dwCount)) {
{
unsigned char ucTransCode = (ucData & 0x0F); // get code for transfer type unsigned char ucTransCode = (ucData & 0x0F); // get code for transfer type
unsigned short wIdent = ((ucData >> 4) & 0x07); // and area identifier unsigned short wIdent = ((ucData >> 4) & 0x07); // and area identifier
...@@ -964,31 +1015,43 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx, ...@@ -964,31 +1015,43 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx,
pDmaDesc->dwSize = 0; // initialise other bits pDmaDesc->dwSize = 0; // initialise other bits
pDmaDesc->dwOffset = 0; pDmaDesc->dwOffset = 0;
dev_dbg(&pdx->interface->dev, "%s type: %d ident: %d", __func__, pDmaDesc->wTransType, pDmaDesc->wIdent); dev_dbg(&pdx->interface->dev, "%s type: %d ident: %d", __func__,
pDmaDesc->wTransType, pDmaDesc->wIdent);
pDmaDesc->bOutWard = (ucTransCode != TM_EXTTOHOST); // set transfer direction pDmaDesc->bOutWard = (ucTransCode != TM_EXTTOHOST); // set transfer direction
switch (ucTransCode) switch (ucTransCode) {
{
case TM_EXTTOHOST: // Extended linear transfer modes (the only ones!) case TM_EXTTOHOST: // Extended linear transfer modes (the only ones!)
case TM_EXTTO1401: case TM_EXTTO1401:
{ {
bResult = ReadHuff(&(pDmaDesc->dwOffset), pBuf, &dDone, dwCount) && bResult =
ReadHuff(&(pDmaDesc->dwSize), pBuf, &dDone, dwCount); ReadHuff(&(pDmaDesc->dwOffset), pBuf,
if (bResult) &dDone, dwCount)
{ && ReadHuff(&(pDmaDesc->dwSize), pBuf,
dev_dbg(&pdx->interface->dev, "%s xfer offset & size %d %d", &dDone, dwCount);
__func__, pDmaDesc->dwOffset, pDmaDesc->dwSize); if (bResult) {
dev_dbg(&pdx->interface->dev,
"%s xfer offset & size %d %d",
__func__, pDmaDesc->dwOffset,
pDmaDesc->dwSize);
if ((wIdent >= MAX_TRANSAREAS) || // Illegal area number, or... if ((wIdent >= MAX_TRANSAREAS) || // Illegal area number, or...
(!pdx->rTransDef[wIdent].bUsed) || // area not set up, or... (!pdx->rTransDef[wIdent].bUsed) || // area not set up, or...
(pDmaDesc->dwOffset > pdx->rTransDef[wIdent].dwLength) || // range/size (pDmaDesc->dwOffset > pdx->rTransDef[wIdent].dwLength) || // range/size
((pDmaDesc->dwOffset + pDmaDesc->dwSize) > (pdx->rTransDef[wIdent].dwLength))) ((pDmaDesc->dwOffset +
{ pDmaDesc->dwSize) >
(pdx->rTransDef[wIdent].
dwLength))) {
bResult = false; // bad parameter(s) bResult = false; // bad parameter(s)
dev_dbg(&pdx->interface->dev, "%s bad param - id %d, bUsed %d, offset %d, size %d, area length %d", dev_dbg(&pdx->interface->dev,
__func__, wIdent, pdx->rTransDef[wIdent].bUsed, pDmaDesc->dwOffset, pDmaDesc->dwSize, "%s bad param - id %d, bUsed %d, offset %d, size %d, area length %d",
pdx->rTransDef[wIdent].dwLength); __func__, wIdent,
pdx->rTransDef[wIdent].
bUsed,
pDmaDesc->dwOffset,
pDmaDesc->dwSize,
pdx->rTransDef[wIdent].
dwLength);
} }
} }
break; break;
...@@ -996,12 +1059,12 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx, ...@@ -996,12 +1059,12 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx,
default: default:
break; break;
} }
} } else
else
bResult = false; bResult = false;
if (!bResult) // now check parameters for validity if (!bResult) // now check parameters for validity
dev_err(&pdx->interface->dev, "%s error reading Esc sequence", __func__); dev_err(&pdx->interface->dev, "%s error reading Esc sequence",
__func__);
return bResult; return bResult;
} }
...@@ -1020,7 +1083,8 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx, ...@@ -1020,7 +1083,8 @@ static bool ReadDMAInfo(volatile DMADESC* pDmaDesc, DEVICE_EXTENSION *pdx,
** this is known to be at least 2 or we will not be called. ** this is known to be at least 2 or we will not be called.
** **
****************************************************************************/ ****************************************************************************/
static int Handle1401Esc(DEVICE_EXTENSION* pdx, char* pCh, unsigned int dwCount) static int Handle1401Esc(DEVICE_EXTENSION * pdx, char *pCh,
unsigned int dwCount)
{ {
int iReturn = U14ERR_FAIL; int iReturn = U14ERR_FAIL;
...@@ -1029,38 +1093,45 @@ static int Handle1401Esc(DEVICE_EXTENSION* pdx, char* pCh, unsigned int dwCount) ...@@ -1029,38 +1093,45 @@ static int Handle1401Esc(DEVICE_EXTENSION* pdx, char* pCh, unsigned int dwCount)
// tell me what this is for, it should be removed from this and the Windows driver. // tell me what this is for, it should be removed from this and the Windows driver.
if (pCh[0] == '?') // Is this an information response if (pCh[0] == '?') // Is this an information response
{ // Parse and save the information { // Parse and save the information
} } else {
else
{
spin_lock(&pdx->stagedLock); // Lock others out spin_lock(&pdx->stagedLock); // Lock others out
if (ReadDMAInfo(&pdx->rDMAInfo, pdx, pCh, dwCount)) // Get DMA parameters if (ReadDMAInfo(&pdx->rDMAInfo, pdx, pCh, dwCount)) // Get DMA parameters
{ {
unsigned short wTransType = pdx->rDMAInfo.wTransType; // check transfer type unsigned short wTransType = pdx->rDMAInfo.wTransType; // check transfer type
dev_dbg(&pdx->interface->dev, "%s xfer to %s, offset %d, length %d", __func__, dev_dbg(&pdx->interface->dev,
"%s xfer to %s, offset %d, length %d", __func__,
pdx->rDMAInfo.bOutWard ? "1401" : "host", pdx->rDMAInfo.bOutWard ? "1401" : "host",
pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize); pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize);
if (pdx->bXFerWaiting) // Check here for badly out of kilter... if (pdx->bXFerWaiting) // Check here for badly out of kilter...
{ // This can never happen, really { // This can never happen, really
dev_err(&pdx->interface->dev, "ERROR: DMA setup while transfer still waiting"); dev_err(&pdx->interface->dev,
"ERROR: DMA setup while transfer still waiting");
spin_unlock(&pdx->stagedLock); spin_unlock(&pdx->stagedLock);
} } else {
else if ((wTransType == TM_EXTTOHOST)
{ || (wTransType == TM_EXTTO1401)) {
if ((wTransType == TM_EXTTOHOST) || (wTransType == TM_EXTTO1401)) iReturn =
{ ReadWriteMem(pdx,
iReturn = ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard, pdx->rDMAInfo.wIdent, pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize); !pdx->rDMAInfo.
bOutWard,
pdx->rDMAInfo.wIdent,
pdx->rDMAInfo.dwOffset,
pdx->rDMAInfo.dwSize);
if (iReturn != U14ERR_NOERROR) if (iReturn != U14ERR_NOERROR)
dev_err(&pdx->interface->dev, "%s ReadWriteMem() failed %d", __func__, iReturn); dev_err(&pdx->interface->dev,
} "%s ReadWriteMem() failed %d",
else // This covers non-linear transfer setup __func__, iReturn);
dev_err(&pdx->interface->dev, "%s Unknown block xfer type %d", __func__, wTransType); } else // This covers non-linear transfer setup
} dev_err(&pdx->interface->dev,
} "%s Unknown block xfer type %d",
else // Failed to read parameters __func__, wTransType);
dev_err(&pdx->interface->dev, "%s ReadDMAInfo() fail", __func__); }
} else // Failed to read parameters
dev_err(&pdx->interface->dev, "%s ReadDMAInfo() fail",
__func__);
spin_unlock(&pdx->stagedLock); // OK here spin_unlock(&pdx->stagedLock); // OK here
} }
...@@ -1073,7 +1144,7 @@ static int Handle1401Esc(DEVICE_EXTENSION* pdx, char* pCh, unsigned int dwCount) ...@@ -1073,7 +1144,7 @@ static int Handle1401Esc(DEVICE_EXTENSION* pdx, char* pCh, unsigned int dwCount)
/**************************************************************************** /****************************************************************************
** Callback for the character read complete or error ** Callback for the character read complete or error
****************************************************************************/ ****************************************************************************/
static void ced_readchar_callback(struct urb* pUrb) static void ced_readchar_callback(struct urb *pUrb)
{ {
DEVICE_EXTENSION *pdx = pUrb->context; DEVICE_EXTENSION *pdx = pUrb->context;
int nGot = pUrb->actual_length; // what we transferred int nGot = pUrb->actual_length; // what we transferred
...@@ -1082,12 +1153,16 @@ static void ced_readchar_callback(struct urb* pUrb) ...@@ -1082,12 +1153,16 @@ static void ced_readchar_callback(struct urb* pUrb)
{ {
int nPipe = pdx->nPipes == 4 ? 1 : 0; // The pipe number to use for error int nPipe = pdx->nPipes == 4 ? 1 : 0; // The pipe number to use for error
// sync/async unlink faults aren't errors... just saying device removed or stopped // sync/async unlink faults aren't errors... just saying device removed or stopped
if (!(pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) if (!
{ (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET
dev_err(&pdx->interface->dev, "%s - nonzero write bulk status received: %d", __func__, pUrb->status); || pUrb->status == -ESHUTDOWN)) {
} dev_err(&pdx->interface->dev,
else "%s - nonzero write bulk status received: %d",
dev_dbg(&pdx->interface->dev, "%s - 0 chars pUrb->status=%d (shutdown?)", __func__, pUrb->status); __func__, pUrb->status);
} else
dev_dbg(&pdx->interface->dev,
"%s - 0 chars pUrb->status=%d (shutdown?)",
__func__, pUrb->status);
spin_lock(&pdx->err_lock); spin_lock(&pdx->err_lock);
pdx->errors = pUrb->status; pdx->errors = pUrb->status;
...@@ -1096,39 +1171,35 @@ static void ced_readchar_callback(struct urb* pUrb) ...@@ -1096,39 +1171,35 @@ static void ced_readchar_callback(struct urb* pUrb)
spin_lock(&pdx->charInLock); // already at irq level spin_lock(&pdx->charInLock); // already at irq level
pdx->bPipeError[nPipe] = 1; // Flag an error for later pdx->bPipeError[nPipe] = 1; // Flag an error for later
} } else {
else
{
if ((nGot > 1) && ((pdx->pCoherCharIn[0] & 0x7f) == 0x1b)) // Esc sequence? if ((nGot > 1) && ((pdx->pCoherCharIn[0] & 0x7f) == 0x1b)) // Esc sequence?
{ {
Handle1401Esc(pdx, &pdx->pCoherCharIn[1], nGot-1); // handle it Handle1401Esc(pdx, &pdx->pCoherCharIn[1], nGot - 1); // handle it
spin_lock(&pdx->charInLock); // already at irq level spin_lock(&pdx->charInLock); // already at irq level
} } else {
else
{
spin_lock(&pdx->charInLock); // already at irq level spin_lock(&pdx->charInLock); // already at irq level
if (nGot > 0) if (nGot > 0) {
{
unsigned int i; unsigned int i;
if (nGot < INBUF_SZ) if (nGot < INBUF_SZ) {
{
pdx->pCoherCharIn[nGot] = 0; // tidy the string pdx->pCoherCharIn[nGot] = 0; // tidy the string
dev_dbg(&pdx->interface->dev, "%s got %d chars >%s<", __func__, nGot, pdx->pCoherCharIn); dev_dbg(&pdx->interface->dev,
"%s got %d chars >%s<",
__func__, nGot,
pdx->pCoherCharIn);
} }
// We know that whatever we read must fit in the input buffer // We know that whatever we read must fit in the input buffer
for (i = 0; i < nGot; i++) for (i = 0; i < nGot; i++) {
{ pdx->inputBuffer[pdx->dwInBuffPut++] =
pdx->inputBuffer[pdx->dwInBuffPut++] = pdx->pCoherCharIn[i] & 0x7F; pdx->pCoherCharIn[i] & 0x7F;
if (pdx->dwInBuffPut >= INBUF_SZ) if (pdx->dwInBuffPut >= INBUF_SZ)
pdx->dwInBuffPut = 0; pdx->dwInBuffPut = 0;
} }
if ((pdx->dwNumInput + nGot) <= INBUF_SZ) if ((pdx->dwNumInput + nGot) <= INBUF_SZ)
pdx->dwNumInput += nGot; // Adjust the buffer count accordingly pdx->dwNumInput += nGot; // Adjust the buffer count accordingly
} } else
else dev_dbg(&pdx->interface->dev, "%s read ZLP",
dev_dbg(&pdx->interface->dev, "%s read ZLP", __func__); __func__);
} }
} }
...@@ -1145,7 +1216,7 @@ static void ced_readchar_callback(struct urb* pUrb) ...@@ -1145,7 +1216,7 @@ static void ced_readchar_callback(struct urb* pUrb)
** we can pick up any inward transfers. This can be called in multiple contexts ** we can pick up any inward transfers. This can be called in multiple contexts
** so we use the irqsave version of the spinlock. ** so we use the irqsave version of the spinlock.
****************************************************************************/ ****************************************************************************/
int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback) int Allowi(DEVICE_EXTENSION * pdx, bool bInCallback)
{ {
int iReturn = U14ERR_NOERROR; int iReturn = U14ERR_NOERROR;
unsigned long flags; unsigned long flags;
...@@ -1157,15 +1228,16 @@ int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback) ...@@ -1157,15 +1228,16 @@ int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback)
// is no actual driver failure, so we don't allow this at all. // is no actual driver failure, so we don't allow this at all.
if (!pdx->bInDrawDown && // stop input if if (!pdx->bInDrawDown && // stop input if
!pdx->bReadCharsPending && // If no read request outstanding !pdx->bReadCharsPending && // If no read request outstanding
(pdx->dwNumInput < (INBUF_SZ/2)) && // and there is some space (pdx->dwNumInput < (INBUF_SZ / 2)) && // and there is some space
(pdx->dwDMAFlag == MODE_CHAR) && // not doing any DMA (pdx->dwDMAFlag == MODE_CHAR) && // not doing any DMA
(!pdx->bXFerWaiting) && // no xfer waiting to start (!pdx->bXFerWaiting) && // no xfer waiting to start
(CanAcceptIoRequests(pdx))) // and activity is generally OK (CanAcceptIoRequests(pdx))) // and activity is generally OK
{ // then off we go { // then off we go
unsigned int nMax = INBUF_SZ-pdx->dwNumInput; // max we could read unsigned int nMax = INBUF_SZ - pdx->dwNumInput; // max we could read
int nPipe = pdx->nPipes == 4 ? 1 : 0; // The pipe number to use int nPipe = pdx->nPipes == 4 ? 1 : 0; // The pipe number to use
dev_dbg(&pdx->interface->dev, "%s %d chars in input buffer", __func__, pdx->dwNumInput); dev_dbg(&pdx->interface->dev, "%s %d chars in input buffer",
__func__, pdx->dwNumInput);
usb_fill_int_urb(pdx->pUrbCharIn, pdx->udev, usb_fill_int_urb(pdx->pUrbCharIn, pdx->udev,
usb_rcvintpipe(pdx->udev, pdx->epAddr[nPipe]), usb_rcvintpipe(pdx->udev, pdx->epAddr[nPipe]),
...@@ -1173,14 +1245,15 @@ int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback) ...@@ -1173,14 +1245,15 @@ int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback)
pdx, pdx->bInterval); pdx, pdx->bInterval);
pdx->pUrbCharIn->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; // short xfers are OK by default pdx->pUrbCharIn->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; // short xfers are OK by default
usb_anchor_urb(pdx->pUrbCharIn, &pdx->submitted); // in case we need to kill it usb_anchor_urb(pdx->pUrbCharIn, &pdx->submitted); // in case we need to kill it
iReturn = usb_submit_urb(pdx->pUrbCharIn, bInCallback ? GFP_ATOMIC : GFP_KERNEL); iReturn =
if (iReturn) usb_submit_urb(pdx->pUrbCharIn,
{ bInCallback ? GFP_ATOMIC : GFP_KERNEL);
if (iReturn) {
usb_unanchor_urb(pdx->pUrbCharIn); // remove from list of active Urbs usb_unanchor_urb(pdx->pUrbCharIn); // remove from list of active Urbs
pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later
dev_err(&pdx->interface->dev,"%s submit urb failed: %d", __func__, iReturn); dev_err(&pdx->interface->dev,
} "%s submit urb failed: %d", __func__, iReturn);
else } else
pdx->bReadCharsPending = true; // Flag that we are active here pdx->bReadCharsPending = true; // Flag that we are active here
} }
...@@ -1198,9 +1271,10 @@ int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback) ...@@ -1198,9 +1271,10 @@ int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback)
** enough for a 64-bit pointer. ** enough for a 64-bit pointer.
*****************************************************************************/ *****************************************************************************/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
static long ced_ioctl(struct file * file, unsigned int cmd, unsigned long ulArg) static long ced_ioctl(struct file *file, unsigned int cmd, unsigned long ulArg)
#else #else
static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, unsigned long ulArg) static int ced_ioctl(struct inode *node, struct file *file, unsigned int cmd,
unsigned long ulArg)
#endif #endif
{ {
int err = 0; int err = 0;
...@@ -1217,10 +1291,10 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, ...@@ -1217,10 +1291,10 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd,
if (err) if (err)
return -EFAULT; return -EFAULT;
switch (_IOC_NR(cmd)) switch (_IOC_NR(cmd)) {
{
case _IOC_NR(IOCTL_CED_SENDSTRING(0)): case _IOC_NR(IOCTL_CED_SENDSTRING(0)):
return SendString(pdx, (const char __user*)ulArg, _IOC_SIZE(cmd)); return SendString(pdx, (const char __user *)ulArg,
_IOC_SIZE(cmd));
case _IOC_NR(IOCTL_CED_RESET1401): case _IOC_NR(IOCTL_CED_RESET1401):
return Reset1401(pdx); return Reset1401(pdx);
...@@ -1238,16 +1312,16 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, ...@@ -1238,16 +1312,16 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd,
return LineCount(pdx); return LineCount(pdx);
case _IOC_NR(IOCTL_CED_GETSTRING(0)): case _IOC_NR(IOCTL_CED_GETSTRING(0)):
return GetString(pdx, (char __user*)ulArg, _IOC_SIZE(cmd)); return GetString(pdx, (char __user *)ulArg, _IOC_SIZE(cmd));
case _IOC_NR(IOCTL_CED_SETTRANSFER): case _IOC_NR(IOCTL_CED_SETTRANSFER):
return SetTransfer(pdx, (TRANSFERDESC __user*)ulArg); return SetTransfer(pdx, (TRANSFERDESC __user *) ulArg);
case _IOC_NR(IOCTL_CED_UNSETTRANSFER): case _IOC_NR(IOCTL_CED_UNSETTRANSFER):
return UnsetTransfer(pdx, (int)ulArg); return UnsetTransfer(pdx, (int)ulArg);
case _IOC_NR(IOCTL_CED_SETEVENT): case _IOC_NR(IOCTL_CED_SETEVENT):
return SetEvent(pdx, (TRANSFEREVENT __user*)ulArg); return SetEvent(pdx, (TRANSFEREVENT __user *) ulArg);
case _IOC_NR(IOCTL_CED_GETOUTBUFSPACE): case _IOC_NR(IOCTL_CED_GETOUTBUFSPACE):
return GetOutBufSpace(pdx); return GetOutBufSpace(pdx);
...@@ -1256,10 +1330,10 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, ...@@ -1256,10 +1330,10 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd,
return -1; return -1;
case _IOC_NR(IOCTL_CED_GETDRIVERREVISION): case _IOC_NR(IOCTL_CED_GETDRIVERREVISION):
return (2<<24)|(DRIVERMAJREV<<16) | DRIVERMINREV; // USB | MAJOR | MINOR return (2 << 24) | (DRIVERMAJREV << 16) | DRIVERMINREV; // USB | MAJOR | MINOR
case _IOC_NR(IOCTL_CED_GETTRANSFER): case _IOC_NR(IOCTL_CED_GETTRANSFER):
return GetTransfer(pdx, (TGET_TX_BLOCK __user*)ulArg); return GetTransfer(pdx, (TGET_TX_BLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_KILLIO1401): case _IOC_NR(IOCTL_CED_KILLIO1401):
return KillIO1401(pdx); return KillIO1401(pdx);
...@@ -1275,7 +1349,7 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, ...@@ -1275,7 +1349,7 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd,
return StartSelfTest(pdx); return StartSelfTest(pdx);
case _IOC_NR(IOCTL_CED_CHECKSELFTEST): case _IOC_NR(IOCTL_CED_CHECKSELFTEST):
return CheckSelfTest(pdx, (TGET_SELFTEST __user*)ulArg); return CheckSelfTest(pdx, (TGET_SELFTEST __user *) ulArg);
case _IOC_NR(IOCTL_CED_TYPEOF1401): case _IOC_NR(IOCTL_CED_TYPEOF1401):
return TypeOf1401(pdx); return TypeOf1401(pdx);
...@@ -1284,19 +1358,19 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, ...@@ -1284,19 +1358,19 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd,
return TransferFlags(pdx); return TransferFlags(pdx);
case _IOC_NR(IOCTL_CED_DBGPEEK): case _IOC_NR(IOCTL_CED_DBGPEEK):
return DbgPeek(pdx, (TDBGBLOCK __user*)ulArg); return DbgPeek(pdx, (TDBGBLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_DBGPOKE): case _IOC_NR(IOCTL_CED_DBGPOKE):
return DbgPoke(pdx, (TDBGBLOCK __user*)ulArg); return DbgPoke(pdx, (TDBGBLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_DBGRAMPDATA): case _IOC_NR(IOCTL_CED_DBGRAMPDATA):
return DbgRampData(pdx, (TDBGBLOCK __user*)ulArg); return DbgRampData(pdx, (TDBGBLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_DBGRAMPADDR): case _IOC_NR(IOCTL_CED_DBGRAMPADDR):
return DbgRampAddr(pdx, (TDBGBLOCK __user*)ulArg); return DbgRampAddr(pdx, (TDBGBLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_DBGGETDATA): case _IOC_NR(IOCTL_CED_DBGGETDATA):
return DbgGetData(pdx, (TDBGBLOCK __user*)ulArg); return DbgGetData(pdx, (TDBGBLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_DBGSTOPLOOP): case _IOC_NR(IOCTL_CED_DBGSTOPLOOP):
return DbgStopLoop(pdx); return DbgStopLoop(pdx);
...@@ -1306,13 +1380,13 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, ...@@ -1306,13 +1380,13 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd,
break; break;
case _IOC_NR(IOCTL_CED_SETCIRCULAR): case _IOC_NR(IOCTL_CED_SETCIRCULAR):
return SetCircular(pdx, (TRANSFERDESC __user*)ulArg); return SetCircular(pdx, (TRANSFERDESC __user *) ulArg);
case _IOC_NR(IOCTL_CED_GETCIRCBLOCK): case _IOC_NR(IOCTL_CED_GETCIRCBLOCK):
return GetCircBlock(pdx, (TCIRCBLOCK __user*)ulArg); return GetCircBlock(pdx, (TCIRCBLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_FREECIRCBLOCK): case _IOC_NR(IOCTL_CED_FREECIRCBLOCK):
return FreeCircBlock(pdx, (TCIRCBLOCK __user*)ulArg); return FreeCircBlock(pdx, (TCIRCBLOCK __user *) ulArg);
case _IOC_NR(IOCTL_CED_WAITEVENT): case _IOC_NR(IOCTL_CED_WAITEVENT):
return WaitEvent(pdx, (int)(ulArg & 0xff), (int)(ulArg >> 8)); return WaitEvent(pdx, (int)(ulArg & 0xff), (int)(ulArg >> 8));
...@@ -1326,8 +1400,7 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd, ...@@ -1326,8 +1400,7 @@ static int ced_ioctl(struct inode * node, struct file * file, unsigned int cmd,
return U14ERR_NOERROR; return U14ERR_NOERROR;
} }
static const struct file_operations ced_fops = static const struct file_operations ced_fops = {
{
.owner = THIS_MODULE, .owner = THIS_MODULE,
.read = ced_read, .read = ced_read,
.write = ced_write, .write = ced_write,
...@@ -1346,8 +1419,7 @@ static const struct file_operations ced_fops = ...@@ -1346,8 +1419,7 @@ static const struct file_operations ced_fops =
* usb class driver info in order to get a minor number from the usb core, * usb class driver info in order to get a minor number from the usb core,
* and to have the device registered with the driver core * and to have the device registered with the driver core
*/ */
static struct usb_class_driver ced_class = static struct usb_class_driver ced_class = {
{
.name = "cedusb%d", .name = "cedusb%d",
.fops = &ced_fops, .fops = &ced_fops,
.minor_base = USB_CED_MINOR_BASE, .minor_base = USB_CED_MINOR_BASE,
...@@ -1355,7 +1427,8 @@ static struct usb_class_driver ced_class = ...@@ -1355,7 +1427,8 @@ static struct usb_class_driver ced_class =
// Check that the device that matches a 1401 vendor and product ID is OK to use and // Check that the device that matches a 1401 vendor and product ID is OK to use and
// initialise our DEVICE_EXTENSION. // initialise our DEVICE_EXTENSION.
static int ced_probe(struct usb_interface *interface, const struct usb_device_id *id) static int ced_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{ {
DEVICE_EXTENSION *pdx; DEVICE_EXTENSION *pdx;
struct usb_host_interface *iface_desc; struct usb_host_interface *iface_desc;
...@@ -1365,13 +1438,12 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id ...@@ -1365,13 +1438,12 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id
// allocate memory for our device extension and initialize it // allocate memory for our device extension and initialize it
pdx = kzalloc(sizeof(*pdx), GFP_KERNEL); pdx = kzalloc(sizeof(*pdx), GFP_KERNEL);
if (!pdx) if (!pdx) {
{
dev_err(&interface->dev, "Out of memory\n"); dev_err(&interface->dev, "Out of memory\n");
goto error; goto error;
} }
for (i=0; i<MAX_TRANSAREAS; ++i) // Initialise the wait queues for (i = 0; i < MAX_TRANSAREAS; ++i) // Initialise the wait queues
{ {
init_waitqueue_head(&pdx->rTransDef[i].wqEvent); init_waitqueue_head(&pdx->rTransDef[i].wqEvent);
} }
...@@ -1396,18 +1468,19 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id ...@@ -1396,18 +1468,19 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id
i = (bcdDevice >> 8); i = (bcdDevice >> 8);
if (i == 0) if (i == 0)
pdx->s1401Type = TYPEU1401; pdx->s1401Type = TYPEU1401;
else if ((i>=1) && (i<=23)) else if ((i >= 1) && (i <= 23))
pdx->s1401Type = i+2; pdx->s1401Type = i + 2;
else else {
{ dev_err(&interface->dev, "%s Unknown device. bcdDevice = %d",
dev_err(&interface->dev, "%s Unknown device. bcdDevice = %d", __func__, bcdDevice); __func__, bcdDevice);
goto error; goto error;
} }
// set up the endpoint information. We only care about the number of EP as // set up the endpoint information. We only care about the number of EP as
// we know that we are dealing with a 1401 device. // we know that we are dealing with a 1401 device.
iface_desc = interface->cur_altsetting; iface_desc = interface->cur_altsetting;
pdx->nPipes = iface_desc->desc.bNumEndpoints; pdx->nPipes = iface_desc->desc.bNumEndpoints;
dev_info(&interface->dev, "1401Type=%d with %d End Points", pdx->s1401Type, pdx->nPipes); dev_info(&interface->dev, "1401Type=%d with %d End Points",
pdx->s1401Type, pdx->nPipes);
if ((pdx->nPipes < 3) || (pdx->nPipes > 4)) if ((pdx->nPipes < 3) || (pdx->nPipes > 4))
goto error; goto error;
...@@ -1415,38 +1488,44 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id ...@@ -1415,38 +1488,44 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id
pdx->pUrbCharOut = usb_alloc_urb(0, GFP_KERNEL); // character output URB pdx->pUrbCharOut = usb_alloc_urb(0, GFP_KERNEL); // character output URB
pdx->pUrbCharIn = usb_alloc_urb(0, GFP_KERNEL); // character input URB pdx->pUrbCharIn = usb_alloc_urb(0, GFP_KERNEL); // character input URB
pdx->pStagedUrb = usb_alloc_urb(0, GFP_KERNEL); // block transfer URB pdx->pStagedUrb = usb_alloc_urb(0, GFP_KERNEL); // block transfer URB
if (!pdx->pUrbCharOut || !pdx->pUrbCharIn || !pdx->pStagedUrb) if (!pdx->pUrbCharOut || !pdx->pUrbCharIn || !pdx->pStagedUrb) {
{
dev_err(&interface->dev, "%s URB alloc failed", __func__); dev_err(&interface->dev, "%s URB alloc failed", __func__);
goto error; goto error;
} }
pdx->pCoherStagedIO = usb_alloc_coherent(pdx->udev, STAGED_SZ, GFP_KERNEL, &pdx->pStagedUrb->transfer_dma); pdx->pCoherStagedIO =
pdx->pCoherCharOut = usb_alloc_coherent(pdx->udev, OUTBUF_SZ, GFP_KERNEL, &pdx->pUrbCharOut->transfer_dma); usb_alloc_coherent(pdx->udev, STAGED_SZ, GFP_KERNEL,
pdx->pCoherCharIn = usb_alloc_coherent(pdx->udev, INBUF_SZ, GFP_KERNEL, &pdx->pUrbCharIn->transfer_dma); &pdx->pStagedUrb->transfer_dma);
if (!pdx->pCoherCharOut || !pdx->pCoherCharIn || !pdx->pCoherStagedIO) pdx->pCoherCharOut =
{ usb_alloc_coherent(pdx->udev, OUTBUF_SZ, GFP_KERNEL,
dev_err(&interface->dev, "%s Coherent buffer alloc failed", __func__); &pdx->pUrbCharOut->transfer_dma);
pdx->pCoherCharIn =
usb_alloc_coherent(pdx->udev, INBUF_SZ, GFP_KERNEL,
&pdx->pUrbCharIn->transfer_dma);
if (!pdx->pCoherCharOut || !pdx->pCoherCharIn || !pdx->pCoherStagedIO) {
dev_err(&interface->dev, "%s Coherent buffer alloc failed",
__func__);
goto error; goto error;
} }
for (i = 0; i < pdx->nPipes; ++i) for (i = 0; i < pdx->nPipes; ++i) {
{
endpoint = &iface_desc->endpoint[i].desc; endpoint = &iface_desc->endpoint[i].desc;
pdx->epAddr[i] = endpoint->bEndpointAddress; pdx->epAddr[i] = endpoint->bEndpointAddress;
dev_info(&interface->dev, "Pipe %d, ep address %02x", i, pdx->epAddr[i]); dev_info(&interface->dev, "Pipe %d, ep address %02x", i,
if (((pdx->nPipes==3) && (i==0)) || // if char input end point pdx->epAddr[i]);
((pdx->nPipes==4) && (i==1))) if (((pdx->nPipes == 3) && (i == 0)) || // if char input end point
{ ((pdx->nPipes == 4) && (i == 1))) {
pdx->bInterval = endpoint->bInterval; // save the endpoint interrupt interval pdx->bInterval = endpoint->bInterval; // save the endpoint interrupt interval
dev_info(&interface->dev, "Pipe %d, bInterval = %d", i, pdx->bInterval); dev_info(&interface->dev, "Pipe %d, bInterval = %d", i,
pdx->bInterval);
} }
// Detect USB2 by checking last ep size (64 if USB1) // Detect USB2 by checking last ep size (64 if USB1)
if (i == pdx->nPipes-1) // if this is the last ep (bulk) if (i == pdx->nPipes - 1) // if this is the last ep (bulk)
{ {
pdx->bIsUSB2 = le16_to_cpu(endpoint->wMaxPacketSize) > 64; pdx->bIsUSB2 =
dev_info(&pdx->interface->dev, "USB%d", pdx->bIsUSB2 + 1); le16_to_cpu(endpoint->wMaxPacketSize) > 64;
dev_info(&pdx->interface->dev, "USB%d",
pdx->bIsUSB2 + 1);
} }
} }
...@@ -1455,10 +1534,10 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id ...@@ -1455,10 +1534,10 @@ static int ced_probe(struct usb_interface *interface, const struct usb_device_id
/* we can register the device now, as it is ready */ /* we can register the device now, as it is ready */
retval = usb_register_dev(interface, &ced_class); retval = usb_register_dev(interface, &ced_class);
if (retval) if (retval) {
{
/* something prevented us from registering this driver */ /* something prevented us from registering this driver */
dev_err(&interface->dev, "Not able to get a minor for this device.\n"); dev_err(&interface->dev,
"Not able to get a minor for this device.\n");
usb_set_intfdata(interface, NULL); usb_set_intfdata(interface, NULL);
goto error; goto error;
} }
...@@ -1486,11 +1565,11 @@ static void ced_disconnect(struct usb_interface *interface) ...@@ -1486,11 +1565,11 @@ static void ced_disconnect(struct usb_interface *interface)
mutex_lock(&pdx->io_mutex); // stop more I/O starting while... mutex_lock(&pdx->io_mutex); // stop more I/O starting while...
ced_draw_down(pdx); // ...wait for then kill any io ced_draw_down(pdx); // ...wait for then kill any io
for (i=0; i<MAX_TRANSAREAS; ++i) for (i = 0; i < MAX_TRANSAREAS; ++i) {
{
int iErr = ClearArea(pdx, i); // ...release any used memory int iErr = ClearArea(pdx, i); // ...release any used memory
if (iErr == U14ERR_UNLOCKFAIL) if (iErr == U14ERR_UNLOCKFAIL)
dev_err(&pdx->interface->dev, "%s Area %d was in used", __func__, i); dev_err(&pdx->interface->dev, "%s Area %d was in used",
__func__, i);
} }
pdx->interface = NULL; // ...we kill off link to interface pdx->interface = NULL; // ...we kill off link to interface
mutex_unlock(&pdx->io_mutex); mutex_unlock(&pdx->io_mutex);
...@@ -1506,20 +1585,20 @@ static void ced_disconnect(struct usb_interface *interface) ...@@ -1506,20 +1585,20 @@ static void ced_disconnect(struct usb_interface *interface)
// are left. NBNB we will need to have a mechanism to stop circular xfers // are left. NBNB we will need to have a mechanism to stop circular xfers
// from trying to fire off more urbs. We will wait up to 3 seconds for Urbs // from trying to fire off more urbs. We will wait up to 3 seconds for Urbs
// to be done. // to be done.
void ced_draw_down(DEVICE_EXTENSION *pdx) void ced_draw_down(DEVICE_EXTENSION * pdx)
{ {
int time; int time;
dev_dbg(&pdx->interface->dev,"%s called", __func__); dev_dbg(&pdx->interface->dev, "%s called", __func__);
pdx->bInDrawDown = true; pdx->bInDrawDown = true;
time = usb_wait_anchor_empty_timeout(&pdx->submitted, 3000); time = usb_wait_anchor_empty_timeout(&pdx->submitted, 3000);
if (!time) // if we timed out we kill the urbs if (!time) // if we timed out we kill the urbs
{ {
usb_kill_anchored_urbs(&pdx->submitted); usb_kill_anchored_urbs(&pdx->submitted);
dev_err(&pdx->interface->dev,"%s timed out", __func__); dev_err(&pdx->interface->dev, "%s timed out", __func__);
} }
pdx->bInDrawDown = false; pdx->bInDrawDown = false;
} }
static int ced_suspend(struct usb_interface *intf, pm_message_t message) static int ced_suspend(struct usb_interface *intf, pm_message_t message)
{ {
...@@ -1528,7 +1607,7 @@ static int ced_suspend(struct usb_interface *intf, pm_message_t message) ...@@ -1528,7 +1607,7 @@ static int ced_suspend(struct usb_interface *intf, pm_message_t message)
return 0; return 0;
ced_draw_down(pdx); ced_draw_down(pdx);
dev_dbg(&pdx->interface->dev,"%s called", __func__); dev_dbg(&pdx->interface->dev, "%s called", __func__);
return 0; return 0;
} }
...@@ -1537,7 +1616,7 @@ static int ced_resume(struct usb_interface *intf) ...@@ -1537,7 +1616,7 @@ static int ced_resume(struct usb_interface *intf)
DEVICE_EXTENSION *pdx = usb_get_intfdata(intf); DEVICE_EXTENSION *pdx = usb_get_intfdata(intf);
if (!pdx) if (!pdx)
return 0; return 0;
dev_dbg(&pdx->interface->dev,"%s called", __func__); dev_dbg(&pdx->interface->dev, "%s called", __func__);
return 0; return 0;
} }
...@@ -1562,8 +1641,7 @@ static int ced_post_reset(struct usb_interface *intf) ...@@ -1562,8 +1641,7 @@ static int ced_post_reset(struct usb_interface *intf)
return 0; return 0;
} }
static struct usb_driver ced_driver = static struct usb_driver ced_driver = {
{
.name = "cedusb", .name = "cedusb",
.probe = ced_probe, .probe = ced_probe,
.disconnect = ced_disconnect, .disconnect = ced_disconnect,
......
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