diff options
Diffstat (limited to 'drivers/staging/ced1401')
-rw-r--r-- | drivers/staging/ced1401/ced_ioc.c | 665 | ||||
-rw-r--r-- | drivers/staging/ced1401/ced_ioctl.h | 2 | ||||
-rw-r--r-- | drivers/staging/ced1401/machine.h | 32 | ||||
-rw-r--r-- | drivers/staging/ced1401/usb1401.c | 613 | ||||
-rw-r--r-- | drivers/staging/ced1401/usb1401.h | 285 | ||||
-rw-r--r-- | drivers/staging/ced1401/use1401.h | 201 | ||||
-rw-r--r-- | drivers/staging/ced1401/use14_ioc.h | 503 | ||||
-rw-r--r-- | drivers/staging/ced1401/userspace/use1401.c | 152 |
8 files changed, 1197 insertions, 1256 deletions
diff --git a/drivers/staging/ced1401/ced_ioc.c b/drivers/staging/ced1401/ced_ioc.c index 82a333f..2dbaf39 100644 --- a/drivers/staging/ced1401/ced_ioc.c +++ b/drivers/staging/ced1401/ced_ioc.c @@ -37,13 +37,14 @@ ** ** Empties the Output buffer and sets int lines. Used from user level only ****************************************************************************/ -void FlushOutBuff(DEVICE_EXTENSION * pdx) +static void FlushOutBuff(DEVICE_EXTENSION *pdx) { dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__, pdx->sCurrentState); if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ return; -// CharSend_Cancel(pdx); /* Kill off any pending I/O */ + /* Kill off any pending I/O */ + /* CharSend_Cancel(pdx); */ spin_lock_irq(&pdx->charOutLock); pdx->dwNumOutput = 0; pdx->dwOutBuffGet = 0; @@ -57,13 +58,14 @@ void FlushOutBuff(DEVICE_EXTENSION * pdx) ** ** Empties the input buffer and sets int lines ****************************************************************************/ -void FlushInBuff(DEVICE_EXTENSION * pdx) +static void FlushInBuff(DEVICE_EXTENSION *pdx) { dev_dbg(&pdx->interface->dev, "%s currentState=%d", __func__, pdx->sCurrentState); if (pdx->sCurrentState == U14ERR_TIME) /* Do nothing if hardware in trouble */ return; -// CharRead_Cancel(pDevObject); /* Kill off any pending I/O */ + /* Kill off any pending I/O */ + /* CharRead_Cancel(pDevObject); */ spin_lock_irq(&pdx->charInLock); pdx->dwNumInput = 0; pdx->dwInBuffGet = 0; @@ -77,11 +79,11 @@ void FlushInBuff(DEVICE_EXTENSION * pdx) ** Utility routine to copy chars into the output buffer and fire them off. ** called from user mode, holds charOutLock. ****************************************************************************/ -static int PutChars(DEVICE_EXTENSION * pdx, const char *pCh, +static int PutChars(DEVICE_EXTENSION *pdx, const char *pCh, unsigned int uCount) { 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) { unsigned int u; for (u = 0; u < uCount; u++) { @@ -91,9 +93,9 @@ static int PutChars(DEVICE_EXTENSION * pdx, const char *pCh, } pdx->dwNumOutput += uCount; spin_unlock_irq(&pdx->charOutLock); - iReturn = SendChars(pdx); // ...give a chance to transmit data + iReturn = SendChars(pdx); /* ...give a chance to transmit data */ } 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); } return iReturn; @@ -104,26 +106,25 @@ static int PutChars(DEVICE_EXTENSION * pdx, const char *pCh, ** trigger an output transfer if this is appropriate. User mode. ** Holds the io_mutex *****************************************************************************/ -int SendString(DEVICE_EXTENSION * pdx, const char __user * pData, +int SendString(DEVICE_EXTENSION *pdx, const char __user *pData, unsigned int n) { - int iReturn = U14ERR_NOERROR; // assume all will be well - char buffer[OUTBUF_SZ + 1]; // space in our address space for characters - if (n > OUTBUF_SZ) // check space in local buffer... - return U14ERR_NOOUT; // ...too many characters + int iReturn = U14ERR_NOERROR; /* assume all will be well */ + char buffer[OUTBUF_SZ + 1]; /* space in our address space for characters */ + if (n > OUTBUF_SZ) /* check space in local buffer... */ + return U14ERR_NOOUT; /* ...too many characters */ if (copy_from_user(buffer, pData, n)) return -EFAULT; - buffer[n] = 0; // terminate for debug purposes + buffer[n] = 0; /* terminate for debug purposes */ - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - if (n > 0) // do nothing if nowt to do! - { + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + if (n > 0) { /* do nothing if nowt to do! */ dev_dbg(&pdx->interface->dev, "%s n=%d>%s<", __func__, n, buffer); iReturn = PutChars(pdx, buffer, n); } - Allowi(pdx); // make sure we have input int + Allowi(pdx); /* make sure we have input int */ mutex_unlock(&pdx->io_mutex); return iReturn; @@ -134,13 +135,13 @@ int SendString(DEVICE_EXTENSION * pdx, const char __user * pData, ** ** 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; - 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); dev_dbg(&pdx->interface->dev, "SendChar >%c< (0x%02x)", c, c); - Allowi(pdx); // Make sure char reads are running + Allowi(pdx); /* Make sure char reads are running */ mutex_unlock(&pdx->io_mutex); return iReturn; } @@ -171,20 +172,20 @@ int SendChar(DEVICE_EXTENSION * pdx, char c) ** ** 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; 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), GET_STATUS, (D_TO_H | VENDOR | DEVREQ), 0, 0, pdx->statBuf, sizeof(pdx->statBuf), HZ); if (nGot != sizeof(pdx->statBuf)) { dev_err(&pdx->interface->dev, "Get1401State() FAILED, return code %d", nGot); - pdx->sCurrentState = U14ERR_TIME; // Indicate that things are very wrong indeed - *state = 0; // Force status values to a known state + pdx->sCurrentState = U14ERR_TIME; /* Indicate that things are very wrong indeed */ + *state = 0; /* Force status values to a known state */ *error = 0; } else { int nDevice; @@ -192,17 +193,16 @@ int Get1401State(DEVICE_EXTENSION * pdx, __u32 * state, __u32 * error) "Get1401State() Success, state: 0x%x, 0x%x", pdx->statBuf[0], pdx->statBuf[1]); - *state = pdx->statBuf[0]; // Return the state values to the calling code + *state = pdx->statBuf[0]; /* Return the state values to the calling code */ *error = pdx->statBuf[1]; - nDevice = pdx->udev->descriptor.bcdDevice >> 8; // 1401 type code value - switch (nDevice) // so we can clean up current state - { + nDevice = pdx->udev->descriptor.bcdDevice >> 8; /* 1401 type code value */ + switch (nDevice) { /* so we can clean up current state */ case 0: pdx->sCurrentState = U14ERR_U1401; break; - default: // allow lots of device codes for future 1401s + default: /* allow lots of device codes for future 1401s */ if ((nDevice >= 1) && (nDevice <= 23)) pdx->sCurrentState = (short)(nDevice + 6); else @@ -219,7 +219,7 @@ int Get1401State(DEVICE_EXTENSION * pdx, __u32 * state, __u32 * error) ** ** 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); @@ -227,24 +227,23 @@ int ReadWrite_Cancel(DEVICE_EXTENSION * pdx) int ntStatus = STATUS_SUCCESS; bool bResult = false; unsigned int i; - // We can fill this in when we know how we will implement the staged transfer stuff + /* We can fill this in when we know how we will implement the staged transfer stuff */ spin_lock_irq(&pdx->stagedLock); - 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"); - - // KeClearEvent(&pdx->StagingDoneEvent); // Clear the staging done flag + /* Clear the staging done flag */ + /* KeClearEvent(&pdx->StagingDoneEvent); */ USB_ASSERT(pdx->pStagedIrp != NULL); - // Release the spinlock first otherwise the completion routine may hang - // on the spinlock while this function hands waiting for the event. + /* Release the spinlock first otherwise the completion routine may hang */ + /* on the spinlock while this function hands waiting for the event. */ spin_unlock_irq(&pdx->stagedLock); - bResult = IoCancelIrp(pdx->pStagedIrp); // Actually do the cancel + bResult = IoCancelIrp(pdx->pStagedIrp); /* Actually do the cancel */ if (bResult) { 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"); ntStatus = @@ -274,14 +273,14 @@ int ReadWrite_Cancel(DEVICE_EXTENSION * pdx) ** 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. ***************************************************************************/ -static int InSelfTest(DEVICE_EXTENSION * pdx, unsigned int *pState) +static int InSelfTest(DEVICE_EXTENSION *pdx, unsigned int *pState) { unsigned int state, error; - int iReturn = Get1401State(pdx, &state, &error); // see if in self-test - if (iReturn == U14ERR_NOERROR) // if all still OK - iReturn = (state == (unsigned int)-1) || // TX problem or... - ((state & 0xff) == 0x80); // ...self test - *pState = state; // return actual state + int iReturn = Get1401State(pdx, &state, &error); /* see if in self-test */ + if (iReturn == U14ERR_NOERROR) /* if all still OK */ + iReturn = (state == (unsigned int)-1) || /* TX problem or... */ + ((state & 0xff) == 0x80); /* ...self test */ + *pState = state; /* return actual state */ return iReturn; } @@ -303,48 +302,45 @@ static int InSelfTest(DEVICE_EXTENSION * pdx, unsigned int *pState) ** ** Returns TRUE if a 1401 detected and OK, else FALSE ****************************************************************************/ -bool Is1401(DEVICE_EXTENSION * pdx) +bool Is1401(DEVICE_EXTENSION *pdx) { int iReturn; dev_dbg(&pdx->interface->dev, "%s", __func__); - ced_draw_down(pdx); // wait for, then kill outstanding Urbs - FlushInBuff(pdx); // Clear out input buffer & pipe - FlushOutBuff(pdx); // Clear output buffer & pipe + ced_draw_down(pdx); /* wait for, then kill outstanding Urbs */ + FlushInBuff(pdx); /* Clear out input buffer & pipe */ + FlushOutBuff(pdx); /* Clear output buffer & pipe */ - // The next call returns 0 if OK, but has returned 1 in the past, meaning that - // usb_unlock_device() is needed... now it always is + /* The next call returns 0 if OK, but has returned 1 in the past, meaning that */ + /* usb_unlock_device() is needed... now it always is */ iReturn = usb_lock_device_for_reset(pdx->udev, pdx->interface); - // release the io_mutex because if we don't, we will deadlock due to system - // calls back into the driver. - mutex_unlock(&pdx->io_mutex); // locked, so we will not get system calls - if (iReturn >= 0) // if we failed - { - iReturn = usb_reset_device(pdx->udev); // try to do the reset - usb_unlock_device(pdx->udev); // undo the lock + /* release the io_mutex because if we don't, we will deadlock due to system */ + /* calls back into the driver. */ + mutex_unlock(&pdx->io_mutex); /* locked, so we will not get system calls */ + if (iReturn >= 0) { /* if we failed */ + iReturn = usb_reset_device(pdx->udev); /* try to do the reset */ + usb_unlock_device(pdx->udev); /* undo the lock */ } - mutex_lock(&pdx->io_mutex); // hold stuff off while we wait - pdx->dwDMAFlag = MODE_CHAR; // Clear DMA mode flag regardless! - if (iReturn == 0) // if all is OK still - { + mutex_lock(&pdx->io_mutex); /* hold stuff off while we wait */ + pdx->dwDMAFlag = MODE_CHAR; /* Clear DMA mode flag regardless! */ + if (iReturn == 0) { /* if all is OK still */ unsigned int state; - iReturn = InSelfTest(pdx, &state); // see if likely in self test - if (iReturn > 0) // do we need to wait for self-test? - { - unsigned long ulTimeOut = jiffies + 30 * HZ; // when to give up + iReturn = InSelfTest(pdx, &state); /* see if likely in self test */ + if (iReturn > 0) { /* do we need to wait for self-test? */ + unsigned long ulTimeOut = jiffies + 30 * HZ; /* when to give up */ while ((iReturn > 0) && time_before(jiffies, ulTimeOut)) { - schedule(); // let other stuff run - iReturn = InSelfTest(pdx, &state); // see if done yet + schedule(); /* let other stuff run */ + iReturn = InSelfTest(pdx, &state); /* see if done yet */ } } - if (iReturn == 0) // if all is OK... - iReturn = state == 0; // then success is that the state is 0 + if (iReturn == 0) /* if all is OK... */ + iReturn = state == 0; /* then success is that the state is 0 */ } else - iReturn = 0; // we failed - pdx->bForceReset = false; // Clear forced reset flag now + iReturn = 0; /* we failed */ + pdx->bForceReset = false; /* Clear forced reset flag now */ return iReturn > 0; } @@ -363,45 +359,42 @@ bool Is1401(DEVICE_EXTENSION * pdx) ** ** 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; - bShortTest = ((pdx->dwDMAFlag == MODE_CHAR) && // no DMA running - (!pdx->bForceReset) && // Not had a real reset forced - (pdx->sCurrentState >= U14ERR_STD)); // No 1401 errors stored + bShortTest = ((pdx->dwDMAFlag == MODE_CHAR) && /* no DMA running */ + (!pdx->bForceReset) && /* Not had a real reset forced */ + (pdx->sCurrentState >= U14ERR_STD)); /* No 1401 errors stored */ dev_dbg(&pdx->interface->dev, "%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... - (pdx->dwNumInput || pdx->dwNumOutput)) // ...characters were in the buffer? - { - bShortTest = false; // Then do the full test + if ((bTestBuff) && /* Buffer check requested, and... */ + (pdx->dwNumInput || pdx->dwNumOutput)) { /* ...characters were in the buffer? */ + bShortTest = false; /* Then do the full test */ dev_dbg(&pdx->interface->dev, "%s will reset as buffers not empty", __func__); } - if (bShortTest || !bCanReset) // Still OK to try the short test? - { // Always test if no reset - we want state update + if (bShortTest || !bCanReset) { /* Still OK to try the short test? */ + /* Always test if no reset - we want state update */ unsigned int state, error; dev_dbg(&pdx->interface->dev, "%s->Get1401State", __func__); - if (Get1401State(pdx, &state, &error) == U14ERR_NOERROR) // Check on the 1401 state - { - if ((state & 0xFF) == 0) // If call worked, check the status value - bRet = true; // If that was zero, all is OK, no reset needed + if (Get1401State(pdx, &state, &error) == U14ERR_NOERROR) { /* Check on the 1401 state */ + if ((state & 0xFF) == 0) /* If call worked, check the status value */ + bRet = true; /* If that was zero, all is OK, no reset needed */ } } - if (!bRet && bCanReset) // If all not OK, then - { + if (!bRet && bCanReset) { /* If all not OK, then */ dev_info(&pdx->interface->dev, "%s->Is1401 %d %d %d %d", __func__, bShortTest, pdx->sCurrentState, bTestBuff, pdx->bForceReset); - bRet = Is1401(pdx); // do full test + bRet = Is1401(pdx); /* do full test */ } return bRet; @@ -412,11 +405,11 @@ bool QuickCheck(DEVICE_EXTENSION * pdx, bool bTestBuff, bool bCanReset) ** ** 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"); - 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); return U14ERR_NOERROR; } @@ -426,30 +419,29 @@ int Reset1401(DEVICE_EXTENSION * pdx) ** ** 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 - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o + int iReturn = U14ERR_NOIN; /* assume we will get nothing */ + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ dev_dbg(&pdx->interface->dev, "GetChar"); - Allowi(pdx); // Make sure char reads are running - SendChars(pdx); // and send any buffered chars + Allowi(pdx); /* Make sure char reads are running */ + SendChars(pdx); /* and send any buffered chars */ spin_lock_irq(&pdx->charInLock); - if (pdx->dwNumInput > 0) // worth looking - { + if (pdx->dwNumInput > 0) { /* worth looking */ iReturn = pdx->inputBuffer[pdx->dwInBuffGet++]; if (pdx->dwInBuffGet >= INBUF_SZ) pdx->dwInBuffGet = 0; pdx->dwNumInput--; } else - iReturn = U14ERR_NOIN; // no input data to read + iReturn = U14ERR_NOIN; /* no input data to read */ spin_unlock_irq(&pdx->charInLock); - Allowi(pdx); // Make sure char reads are running + Allowi(pdx); /* Make sure char reads are running */ - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -464,46 +456,43 @@ int GetChar(DEVICE_EXTENSION * pdx) ** returns the count of characters (including the terminator, or 0 if none ** 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; if (n <= 0) return -ENOMEM; - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx); // Make sure char reads are running - SendChars(pdx); // and send any buffered chars + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + Allowi(pdx); /* Make sure char reads are running */ + SendChars(pdx); /* and send any buffered chars */ spin_lock_irq(&pdx->charInLock); - nAvailable = pdx->dwNumInput; // characters available now - if (nAvailable > n) // read max of space in pUser... - nAvailable = n; // ...or input characters + nAvailable = pdx->dwNumInput; /* characters available now */ + if (nAvailable > n) /* read max of space in pUser... */ + nAvailable = n; /* ...or input characters */ - if (nAvailable > 0) // worth looking? - { - char buffer[INBUF_SZ + 1]; // space for a linear copy of data + if (nAvailable > 0) { /* worth looking? */ + char buffer[INBUF_SZ + 1]; /* space for a linear copy of data */ int nGot = 0; - int nCopyToUser; // number to copy to user + int nCopyToUser; /* number to copy to user */ char cData; do { cData = pdx->inputBuffer[pdx->dwInBuffGet++]; - if (cData == CR_CHAR) // replace CR with zero + if (cData == CR_CHAR) /* replace CR with zero */ cData = (char)0; if (pdx->dwInBuffGet >= INBUF_SZ) - pdx->dwInBuffGet = 0; // wrap buffer pointer + pdx->dwInBuffGet = 0; /* wrap buffer pointer */ - buffer[nGot++] = cData; // save the output - } - while ((nGot < nAvailable) && cData); - - nCopyToUser = nGot; // what to copy... - if (cData) // do we need null - { - buffer[nGot] = (char)0; // make it tidy - if (nGot < n) // if space in user buffer... - ++nCopyToUser; // ...copy the 0 as well. + buffer[nGot++] = cData; /* save the output */ + } while ((nGot < nAvailable) && cData); + + nCopyToUser = nGot; /* what to copy... */ + if (cData) { /* do we need null */ + buffer[nGot] = (char)0; /* make it tidy */ + if (nGot < n) /* if space in user buffer... */ + ++nCopyToUser; /* ...copy the 0 as well. */ } pdx->dwNumInput -= nGot; @@ -514,12 +503,12 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n) if (copy_to_user(pUser, buffer, nCopyToUser)) iReturn = -EFAULT; else - iReturn = nGot; // report characters read + iReturn = nGot; /* report characters read */ } else spin_unlock_irq(&pdx->charInLock); - Allowi(pdx); // Make sure char reads are running - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + Allowi(pdx); /* Make sure char reads are running */ + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -527,14 +516,14 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n) /******************************************************************************* ** Get count of characters in the inout buffer. *******************************************************************************/ -int Stat1401(DEVICE_EXTENSION * pdx) +int Stat1401(DEVICE_EXTENSION *pdx) { int iReturn; - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx); // make sure we allow pending chars - SendChars(pdx); // in both directions - iReturn = pdx->dwNumInput; // no lock as single read - mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + Allowi(pdx); /* make sure we allow pending chars */ + SendChars(pdx); /* in both directions */ + iReturn = pdx->dwNumInput; /* no lock as single read */ + mutex_unlock(&pdx->io_mutex); /* Protect disconnect from new i/o */ return iReturn; } @@ -545,32 +534,30 @@ int Stat1401(DEVICE_EXTENSION * pdx) ** any fancy interlocks as we only read the interrupt routine data, and the ** system is arranged so nothing can be destroyed. ****************************************************************************/ -int LineCount(DEVICE_EXTENSION * pdx) +int LineCount(DEVICE_EXTENSION *pdx) { - int iReturn = 0; // will be count of line ends + int iReturn = 0; /* will be count of line ends */ - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - Allowi(pdx); // Make sure char reads are running - SendChars(pdx); // and send any buffered chars - spin_lock_irq(&pdx->charInLock); // Get protection + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + Allowi(pdx); /* Make sure char reads are running */ + SendChars(pdx); /* and send any buffered chars */ + spin_lock_irq(&pdx->charInLock); /* Get protection */ - if (pdx->dwNumInput > 0) // worth looking? - { - unsigned int dwIndex = pdx->dwInBuffGet; // start at first available - unsigned int dwEnd = pdx->dwInBuffPut; // Position for search end + if (pdx->dwNumInput > 0) { /* worth looking? */ + unsigned int dwIndex = pdx->dwInBuffGet; /* start at first available */ + unsigned int dwEnd = pdx->dwInBuffPut; /* Position for search end */ do { if (pdx->inputBuffer[dwIndex++] == CR_CHAR) - ++iReturn; // inc count if CR + ++iReturn; /* inc count if CR */ - if (dwIndex >= INBUF_SZ) // see if we fall off buff + if (dwIndex >= INBUF_SZ) /* see if we fall off buff */ dwIndex = 0; - } - while (dwIndex != dwEnd); // go to last available + } while (dwIndex != dwEnd); /* go to last available */ } spin_unlock_irq(&pdx->charInLock); 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; } @@ -579,14 +566,14 @@ int LineCount(DEVICE_EXTENSION * pdx) ** ** Gets the space in the output buffer. Called from user code. *****************************************************************************/ -int GetOutBufSpace(DEVICE_EXTENSION * pdx) +int GetOutBufSpace(DEVICE_EXTENSION *pdx) { int iReturn; - mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o - SendChars(pdx); // send any buffered chars - iReturn = (int)(OUTBUF_SZ - pdx->dwNumOutput); // no lock needed for single read + mutex_lock(&pdx->io_mutex); /* Protect disconnect from new i/o */ + SendChars(pdx); /* send any buffered chars */ + iReturn = (int)(OUTBUF_SZ - pdx->dwNumOutput); /* no lock needed for single read */ 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; } @@ -597,7 +584,7 @@ int GetOutBufSpace(DEVICE_EXTENSION * pdx) ** Clears up a transfer area. This is always called in the context of a user ** request, never from a call-back. ****************************************************************************/ -int ClearArea(DEVICE_EXTENSION * pdx, int nArea) +int ClearArea(DEVICE_EXTENSION *pdx, int nArea) { int iReturn = U14ERR_NOERROR; @@ -606,14 +593,14 @@ int ClearArea(DEVICE_EXTENSION * pdx, int nArea) dev_err(&pdx->interface->dev, "%s Attempt to clear area %d", __func__, nArea); } else { - TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing - if (!pTA->bUsed) // if not used... - iReturn = U14ERR_NOTSET; // ...nothing to be done + TRANSAREA *pTA = &pdx->rTransDef[nArea]; /* to save typing */ + if (!pTA->bUsed) /* if not used... */ + iReturn = U14ERR_NOTSET; /* ...nothing to be done */ else { - // We must save the memory we return as we shouldn't mess with memory while - // holding a spin lock. - struct page **pPages = 0; // save page address list - int nPages = 0; // and number of pages + /* We must save the memory we return as we shouldn't mess with memory while */ + /* holding a spin lock. */ + struct page **pPages = NULL; /*save page address list*/ + int nPages = 0; /* and number of pages */ int np; dev_dbg(&pdx->interface->dev, "%s area %d", __func__, @@ -621,33 +608,32 @@ int ClearArea(DEVICE_EXTENSION * pdx, int nArea) spin_lock_irq(&pdx->stagedLock); 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); } else { - pPages = pTA->pPages; // save page address list - nPages = pTA->nPages; // and page count - if (pTA->dwEventSz) // if events flagging in use - wake_up_interruptible(&pTA->wqEvent); // release anything that was waiting + pPages = pTA->pPages; /* save page address list */ + nPages = pTA->nPages; /* and page count */ + if (pTA->dwEventSz) /* if events flagging in use */ + wake_up_interruptible(&pTA->wqEvent); /* release anything that was waiting */ if (pdx->bXFerWaiting && (pdx->rDMAInfo.wIdent == nArea)) - 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 - // This sets bUsed to false and dwEventSz to 0 to say area not used and no events. + /* 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. */ memset(pTA, 0, sizeof(TRANSAREA) - sizeof(wait_queue_head_t)); } spin_unlock_irq(&pdx->stagedLock); - if (pPages) // if we decided to release the memory - { - // Now we must undo the pinning down of the pages. We will assume the worst and mark - // all the pages as dirty. Don't be tempted to move this up above as you must not be - // holding a spin lock to do this stuff as it is not atomic. + if (pPages) { /* if we decided to release the memory */ + /* Now we must undo the pinning down of the pages. We will assume the worst and mark */ + /* all the pages as dirty. Don't be tempted to move this up above as you must not be */ + /* holding a spin lock to do this stuff as it is not atomic. */ dev_dbg(&pdx->interface->dev, "%s nPages=%d", __func__, nPages); @@ -674,29 +660,29 @@ int ClearArea(DEVICE_EXTENSION * pdx, int nArea) ** Sets up a transfer area - the functional part. Called by both ** 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) { - // 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 - // end needing to be rounded up to a page boundary. + /* 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 */ + /* end needing to be rounded up to a page boundary. */ unsigned long ulStart = ((unsigned long)puBuf) & PAGE_MASK; unsigned int ulOffset = ((unsigned long)puBuf) & (PAGE_SIZE - 1); int len = (dwLength + ulOffset + PAGE_SIZE - 1) >> PAGE_SHIFT; - TRANSAREA *pTA = &pdx->rTransDef[nArea]; // to save typing - struct page **pPages = 0; // space for page tables - int nPages = 0; // and number of pages + TRANSAREA *pTA = &pdx->rTransDef[nArea]; /* to save typing */ + struct page **pPages = NULL; /* space for page tables */ + int nPages = 0; /* and number of pages */ - int iReturn = ClearArea(pdx, nArea); // see if OK to use this area - if ((iReturn != U14ERR_NOTSET) && // if not area unused and... - (iReturn != U14ERR_NOERROR)) // ...not all OK, then... - return iReturn; // ...we cannot use this area + int iReturn = ClearArea(pdx, nArea); /* see if OK to use this area */ + if ((iReturn != U14ERR_NOTSET) && /* if not area unused and... */ + (iReturn != U14ERR_NOERROR)) /* ...not all OK, then... */ + return iReturn; /* ...we cannot use this area */ - if (!access_ok(VERIFY_WRITE, puBuf, dwLength)) // if we cannot access the memory... - return -EFAULT; // ...then we are done + if (!access_ok(VERIFY_WRITE, puBuf, dwLength)) /* if we cannot access the memory... */ + 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 = kmalloc(len * sizeof(struct page *), GFP_KERNEL); if (!pPages) { iReturn = U14ERR_NOMEMORY; @@ -705,24 +691,23 @@ static int SetArea(DEVICE_EXTENSION * pdx, int nArea, char __user * puBuf, dev_dbg(&pdx->interface->dev, "%s %p, length=%06x, circular %d", __func__, puBuf, dwLength, bCircular); - // To pin down user pages we must first acquire the mapping semaphore. - down_read(¤t->mm->mmap_sem); // get memory map semaphore - nPages = - get_user_pages(current, current->mm, ulStart, len, 1, 0, pPages, 0); - up_read(¤t->mm->mmap_sem); // release the semaphore + /* To pin down user pages we must first acquire the mapping semaphore. */ + down_read(¤t->mm->mmap_sem); /* get memory map semaphore */ + nPages = get_user_pages(current, current->mm, ulStart, len, 1, 0, + pPages, NULL); + up_read(¤t->mm->mmap_sem); /* release the semaphore */ dev_dbg(&pdx->interface->dev, "%s nPages = %d", __func__, nPages); - if (nPages > 0) // if we succeeded - { - // If you are tempted to use page_address (form LDD3), forget it. You MUST use - // kmap() or kmap_atomic() to get a virtual address. page_address will give you - // (null) or at least it does in this context with an x86 machine. + if (nPages > 0) { /* if we succeeded */ + /* If you are tempted to use page_address (form LDD3), forget it. You MUST use */ + /* kmap() or kmap_atomic() to get a virtual address. page_address will give you */ + /* (null) or at least it does in this context with an x86 machine. */ spin_lock_irq(&pdx->stagedLock); - pTA->lpvBuff = puBuf; // keep start of region (user address) - pTA->dwBaseOffset = ulOffset; // save offset in first page to start of xfer - pTA->dwLength = dwLength; // Size if the region in bytes - pTA->pPages = pPages; // list of pages that are used by buffer - pTA->nPages = nPages; // number of pages + pTA->lpvBuff = puBuf; /* keep start of region (user address) */ + pTA->dwBaseOffset = ulOffset; /* save offset in first page to start of xfer */ + pTA->dwLength = dwLength; /* Size if the region in bytes */ + pTA->pPages = pPages; /* list of pages that are used by buffer */ + pTA->nPages = nPages; /* number of pages */ pTA->bCircular = bCircular; pTA->bCircToHost = bCircToHost; @@ -731,10 +716,10 @@ static int SetArea(DEVICE_EXTENSION * pdx, int nArea, char __user * puBuf, pTA->aBlocks[0].dwSize = 0; pTA->aBlocks[1].dwOffset = 0; pTA->aBlocks[1].dwSize = 0; - pTA->bUsed = true; // This is now a used block + pTA->bUsed = true; /* This is now a used block */ spin_unlock_irq(&pdx->stagedLock); - iReturn = U14ERR_NOERROR; // say all was well + iReturn = U14ERR_NOERROR; /* say all was well */ } else { iReturn = U14ERR_LOCKFAIL; goto error; @@ -754,7 +739,7 @@ error: ** 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. ****************************************************************************/ -int SetTransfer(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) +int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD) { int iReturn; TRANSFERDESC td; @@ -765,9 +750,9 @@ int SetTransfer(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) mutex_lock(&pdx->io_mutex); 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 - // 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. + /* 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 */ + /* 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, @@ -780,7 +765,7 @@ int SetTransfer(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) ** UnSetTransfer ** Erases a transfer area record ****************************************************************************/ -int UnsetTransfer(DEVICE_EXTENSION * pdx, int nArea) +int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea) { int iReturn; mutex_lock(&pdx->io_mutex); @@ -797,27 +782,26 @@ int UnsetTransfer(DEVICE_EXTENSION * pdx, int nArea) ** 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). ****************************************************************************/ -int SetEvent(DEVICE_EXTENSION * pdx, TRANSFEREVENT __user * pTE) +int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user *pTE) { int iReturn = U14ERR_NOERROR; TRANSFEREVENT te; - // get a local copy of the data + /* get a local copy of the data */ if (copy_from_user(&te, pTE, sizeof(te))) return -EFAULT; - if (te.wAreaNum >= MAX_TRANSAREAS) // the area must exist + if (te.wAreaNum >= MAX_TRANSAREAS) /* the area must exist */ return U14ERR_BADAREA; else { 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); - if (pTA->bUsed) // area must be in use - { - pTA->dwEventSt = te.dwStart; // set area regions - pTA->dwEventSz = te.dwLength; // set size (0 cancels it) - pTA->bEventToHost = te.wFlags & 1; // set the direction - pTA->iWakeUp = 0; // zero the wake up count + if (pTA->bUsed) { /* area must be in use */ + pTA->dwEventSt = te.dwStart; /* set area regions */ + pTA->dwEventSz = te.dwLength; /* set size (0 cancels it) */ + pTA->bEventToHost = te.wFlags & 1; /* set the direction */ + pTA->iWakeUp = 0; /* zero the wake up count */ } else iReturn = U14ERR_NOTSET; spin_unlock_irq(&pdx->stagedLock); @@ -833,7 +817,7 @@ int SetEvent(DEVICE_EXTENSION * pdx, TRANSFEREVENT __user * pTE) ** 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). ****************************************************************************/ -int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut) +int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut) { int iReturn; if ((unsigned)nArea >= MAX_TRANSAREAS) @@ -841,15 +825,15 @@ int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut) else { int iWait; TRANSAREA *pTA = &pdx->rTransDef[nArea]; - msTimeOut = (msTimeOut * HZ + 999) / 1000; // convert timeout to jiffies - - // 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 - // releasing it and the wait call. However, this would have to clear the - // iWakeUp flag. However, the !pTA-bUsed may help us in this case. - mutex_lock(&pdx->io_mutex); // make sure we have no competitor - if (!pTA->bUsed || !pTA->dwEventSz) // check something to wait for... - return U14ERR_NOTSET; // ...else we do nothing + msTimeOut = (msTimeOut * HZ + 999) / 1000; /* convert timeout to jiffies */ + + /* 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 */ + /* releasing it and the wait call. However, this would have to clear the */ + /* iWakeUp flag. However, the !pTA-bUsed may help us in this case. */ + mutex_lock(&pdx->io_mutex); /* make sure we have no competitor */ + if (!pTA->bUsed || !pTA->dwEventSz) /* check something to wait for... */ + return U14ERR_NOTSET; /* ...else we do nothing */ mutex_unlock(&pdx->io_mutex); if (msTimeOut) @@ -863,12 +847,12 @@ int WaitEvent(DEVICE_EXTENSION * pdx, int nArea, int msTimeOut) wait_event_interruptible(pTA->wqEvent, pTA->iWakeUp || !pTA->bUsed); if (iWait) - iReturn = -ERESTARTSYS; // oops - we have had a SIGNAL + iReturn = -ERESTARTSYS; /* oops - we have had a SIGNAL */ else - iReturn = pTA->iWakeUp; // else the wakeup count + iReturn = pTA->iWakeUp; /* else the wakeup count */ spin_lock_irq(&pdx->stagedLock); - pTA->iWakeUp = 0; // clear the flag + pTA->iWakeUp = 0; /* clear the flag */ spin_unlock_irq(&pdx->stagedLock); } return iReturn; @@ -880,17 +864,17 @@ 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 ** negative error. ****************************************************************************/ -int TestEvent(DEVICE_EXTENSION * pdx, int nArea) +int TestEvent(DEVICE_EXTENSION *pdx, int nArea) { int iReturn; if ((unsigned)nArea >= MAX_TRANSAREAS) iReturn = U14ERR_BADAREA; else { 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); - iReturn = pTA->iWakeUp; // get wakeup count since last call - pTA->iWakeUp = 0; // clear the count + iReturn = pTA->iWakeUp; /* get wakeup count since last call */ + pTA->iWakeUp = 0; /* clear the count */ spin_unlock_irq(&pdx->stagedLock); mutex_unlock(&pdx->io_mutex); } @@ -901,17 +885,17 @@ int TestEvent(DEVICE_EXTENSION * pdx, int nArea) ** GetTransferInfo ** 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; unsigned int dwIdent; mutex_lock(&pdx->io_mutex); - dwIdent = pdx->StagedId; // area ident for last xfer + dwIdent = pdx->StagedId; /* area ident for last xfer */ if (dwIdent >= MAX_TRANSAREAS) iReturn = U14ERR_BADAREA; 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; tx = kzalloc(sizeof(*tx), GFP_KERNEL); @@ -921,8 +905,8 @@ int GetTransfer(DEVICE_EXTENSION * pdx, TGET_TX_BLOCK __user * pTX) } tx->size = pdx->rTransDef[dwIdent].dwLength; tx->linear = (long long)((long)pdx->rTransDef[dwIdent].lpvBuff); - tx->avail = GET_TX_MAXENTRIES; // how many blocks we could return - tx->used = 1; // number we actually return + tx->avail = GET_TX_MAXENTRIES; /* how many blocks we could return */ + tx->used = 1; /* number we actually return */ tx->entries[0].physical = (long long)(tx->linear + pdx->StagedOffset); tx->entries[0].size = tx->size; @@ -940,7 +924,7 @@ int GetTransfer(DEVICE_EXTENSION * pdx, TGET_TX_BLOCK __user * pTX) ** ** Empties the host i/o buffers ****************************************************************************/ -int KillIO1401(DEVICE_EXTENSION * pdx) +int KillIO1401(DEVICE_EXTENSION *pdx) { dev_dbg(&pdx->interface->dev, "%s", __func__); mutex_lock(&pdx->io_mutex); @@ -955,7 +939,7 @@ int KillIO1401(DEVICE_EXTENSION * pdx) ** Returns a 0 or a 1 for whether DMA is happening. No point holding a mutex ** for this as it only does one read. *****************************************************************************/ -int BlkTransState(DEVICE_EXTENSION * pdx) +int BlkTransState(DEVICE_EXTENSION *pdx) { int iReturn = pdx->dwDMAFlag != MODE_CHAR; dev_dbg(&pdx->interface->dev, "%s = %d", __func__, iReturn); @@ -967,12 +951,12 @@ int BlkTransState(DEVICE_EXTENSION * pdx) ** ** Puts the current state of the 1401 in the Irp return buffer. *****************************************************************************/ -int StateOf1401(DEVICE_EXTENSION * pdx) +int StateOf1401(DEVICE_EXTENSION *pdx) { int iReturn; mutex_lock(&pdx->io_mutex); - QuickCheck(pdx, false, false); // get state up to date, no reset + QuickCheck(pdx, false, false); /* get state up to date, no reset */ iReturn = pdx->sCurrentState; mutex_unlock(&pdx->io_mutex); @@ -987,20 +971,23 @@ int StateOf1401(DEVICE_EXTENSION * pdx) ** Initiates a self-test cycle. The assumption is that we have no interrupts ** active, so we should make sure that this is the case. *****************************************************************************/ -int StartSelfTest(DEVICE_EXTENSION * pdx) +int StartSelfTest(DEVICE_EXTENSION *pdx) { int nGot; mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s", __func__); - ced_draw_down(pdx); // wait for, then kill outstanding Urbs - FlushInBuff(pdx); // Clear out input buffer & pipe - FlushOutBuff(pdx); // Clear output buffer & pipe -// ReadWrite_Cancel(pDeviceObject); /* so things stay tidy */ + ced_draw_down(pdx); /* wait for, then kill outstanding Urbs */ + FlushInBuff(pdx); /* Clear out input buffer & pipe */ + FlushOutBuff(pdx); /* Clear output buffer & pipe */ + /* so things stay tidy */ + /* ReadWrite_Cancel(pDeviceObject); */ pdx->dwDMAFlag = MODE_CHAR; /* Clear DMA mode flags here */ - 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 - pdx->ulSelfTestTime = jiffies + HZ * 30; // 30 seconds into the future + nGot = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), + DB_SELFTEST, (H_TO_D | VENDOR | DEVREQ), + 0, 0, NULL, 0, HZ); /* allow 1 second timeout */ + pdx->ulSelfTestTime = jiffies + HZ * 30; /* 30 seconds into the future */ mutex_unlock(&pdx->io_mutex); if (nGot < 0) @@ -1013,53 +1000,49 @@ int StartSelfTest(DEVICE_EXTENSION * pdx) ** ** 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; int iReturn; - TGET_SELFTEST gst; // local work space - memset(&gst, 0, sizeof(gst)); // clear out the space (sets code 0) + TGET_SELFTEST gst; /* local work space */ + memset(&gst, 0, sizeof(gst)); /* clear out the space (sets code 0) */ mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s", __func__); iReturn = Get1401State(pdx, &state, &error); - if (iReturn == U14ERR_NOERROR) // Only accept zero if it happens twice + if (iReturn == U14ERR_NOERROR) /* Only accept zero if it happens twice */ iReturn = Get1401State(pdx, &state, &error); - if (iReturn != U14ERR_NOERROR) // Self-test can cause comms errors - { // so we assume still testing + if (iReturn != U14ERR_NOERROR) { /* Self-test can cause comms errors */ + /* so we assume still testing */ 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; iReturn = U14ERR_NOERROR; } - 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__); - state = 0x80; // Force still-testing, no error + state = 0x80; /* Force still-testing, no error */ error = 0; } - if ((state & 0xFF) == 0x80) // If we are still in self-test - { - if (state & 0x00FF0000) // Have we got an error? - { - gst.code = (state & 0x00FF0000) >> 16; // read the error code - gst.x = error & 0x0000FFFF; // Error data X - gst.y = (error & 0xFFFF0000) >> 16; // and data Y + if ((state & 0xFF) == 0x80) { /* If we are still in self-test */ + if (state & 0x00FF0000) { /* Have we got an error? */ + gst.code = (state & 0x00FF0000) >> 16; /* read the error code */ + gst.x = error & 0x0000FFFF; /* Error data X */ + gst.y = (error & 0xFFFF0000) >> 16; /* and data Y */ dev_dbg(&pdx->interface->dev, "Self-test error code %d", gst.code); - } else // No error, check for timeout - { - unsigned long ulNow = jiffies; // get current time + } else { /* No error, check for timeout */ + unsigned long ulNow = jiffies; /* get current time */ 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"); } else @@ -1067,16 +1050,16 @@ int CheckSelfTest(DEVICE_EXTENSION * pdx, TGET_SELFTEST __user * pGST) "Self-test on-going"); } } 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"); } - if (gst.code < 0) // If we have a problem or finished - { // If using the 2890 we should reset properly + if (gst.code < 0) { /* If we have a problem or finished */ + /* If using the 2890 we should reset properly */ if ((pdx->nPipes == 4) && (pdx->s1401Type <= TYPEPOWER)) - Is1401(pdx); // Get 1401 reset and OK + Is1401(pdx); /* Get 1401 reset and OK */ else - QuickCheck(pdx, true, true); // Otherwise check without reset unless problems + QuickCheck(pdx, true, true); /* Otherwise check without reset unless problems */ } mutex_unlock(&pdx->io_mutex); @@ -1091,7 +1074,7 @@ int CheckSelfTest(DEVICE_EXTENSION * pdx, TGET_SELFTEST __user * pGST) ** ** Returns code for standard, plus, micro1401, power1401 or none ****************************************************************************/ -int TypeOf1401(DEVICE_EXTENSION * pdx) +int TypeOf1401(DEVICE_EXTENSION *pdx) { int iReturn = TYPEUNKNOWN; mutex_lock(&pdx->io_mutex); @@ -1100,7 +1083,7 @@ int TypeOf1401(DEVICE_EXTENSION * pdx) switch (pdx->s1401Type) { case TYPE1401: iReturn = U14ERR_STD; - break; // Handle these types directly + break; /* Handle these types directly */ case TYPEPLUS: iReturn = U14ERR_PLUS; break; @@ -1109,9 +1092,9 @@ int TypeOf1401(DEVICE_EXTENSION * pdx) break; default: if ((pdx->s1401Type >= TYPEPOWER) && (pdx->s1401Type <= 25)) - iReturn = pdx->s1401Type + 4; // We can calculate types - else // for up-coming 1401 designs - iReturn = TYPEUNKNOWN; // Don't know or not there + iReturn = pdx->s1401Type + 4; /* We can calculate types */ + else /* for up-coming 1401 designs */ + iReturn = TYPEUNKNOWN; /* Don't know or not there */ } dev_dbg(&pdx->interface->dev, "%s %d", __func__, iReturn); mutex_unlock(&pdx->io_mutex); @@ -1124,13 +1107,13 @@ int TypeOf1401(DEVICE_EXTENSION * pdx) ** ** 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 - U14TF_NOTIFY | U14TF_CIRCTH; // diagnostics, notify and circular + int iReturn = U14TF_MULTIA | U14TF_DIAG | /* we always have multiple DMA area */ + U14TF_NOTIFY | U14TF_CIRCTH; /* diagnostics, notify and circular */ dev_dbg(&pdx->interface->dev, "%s", __func__); mutex_lock(&pdx->io_mutex); - if (pdx->bIsUSB2) // Set flag for USB2 if appropriate + if (pdx->bIsUSB2) /* Set flag for USB2 if appropriate */ iReturn |= U14TF_USB2; mutex_unlock(&pdx->io_mutex); @@ -1142,12 +1125,16 @@ int TransferFlags(DEVICE_EXTENSION * pdx) ** Issues a debug\diagnostic command to the 1401 along with a 32-bit datum ** This is a utility command used for dbg operations. */ -static int DbgCmd1401(DEVICE_EXTENSION * pdx, unsigned char cmd, +static int DbgCmd1401(DEVICE_EXTENSION *pdx, unsigned char cmd, unsigned int data) { int iReturn; dev_dbg(&pdx->interface->dev, "%s entry", __func__); - 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 + iReturn = usb_control_msg(pdx->udev, usb_sndctrlpipe(pdx->udev, 0), cmd, + (H_TO_D | VENDOR | DEVREQ), + (unsigned short)data, + (unsigned short)(data >> 16), NULL, 0, HZ); + /* allow 1 second timeout */ if (iReturn < 0) dev_err(&pdx->interface->dev, "%s fail code=%d", __func__, iReturn); @@ -1160,7 +1147,7 @@ static int DbgCmd1401(DEVICE_EXTENSION * pdx, unsigned char cmd, ** ** 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; TDBGBLOCK db; @@ -1189,7 +1176,7 @@ int DbgPeek(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** Execute the diagnostic poke operation. Parameters are in the CSBLOCK struct ** 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; TDBGBLOCK db; @@ -1218,7 +1205,7 @@ int DbgPoke(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** Execute the diagnostic ramp data operation. Parameters are in the CSBLOCK struct ** 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; TDBGBLOCK db; @@ -1250,7 +1237,7 @@ int DbgRampData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** ** Execute the diagnostic ramp address operation ****************************************************************************/ -int DbgRampAddr(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) +int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB) { int iReturn; TDBGBLOCK db; @@ -1280,16 +1267,16 @@ int DbgRampAddr(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** ** 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; TDBGBLOCK db; - memset(&db, 0, sizeof(db)); // fill returned block with 0s + memset(&db, 0, sizeof(db)); /* fill returned block with 0s */ mutex_lock(&pdx->io_mutex); dev_dbg(&pdx->interface->dev, "%s", __func__); - // Read back the last peeked value from the 1401. + /* Read back the last peeked value from the 1401. */ iReturn = usb_control_msg(pdx->udev, usb_rcvctrlpipe(pdx->udev, 0), DB_DATA, (D_TO_H | VENDOR | DEVREQ), 0, 0, &db.iData, sizeof(db.iData), HZ); @@ -1313,7 +1300,7 @@ int DbgGetData(DEVICE_EXTENSION * pdx, TDBGBLOCK __user * pDB) ** Stop any never-ending debug loop, we just call Get1401State for USB ** ****************************************************************************/ -int DbgStopLoop(DEVICE_EXTENSION * pdx) +int DbgStopLoop(DEVICE_EXTENSION *pdx) { int iReturn; unsigned int uState, uErr; @@ -1334,7 +1321,7 @@ int DbgStopLoop(DEVICE_EXTENSION * pdx) ** booked and a transfer to that area is in progress. Otherwise, we will ** 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; bool bToHost; @@ -1346,11 +1333,11 @@ int SetCircular(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) mutex_lock(&pdx->io_mutex); 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 - // 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. + /* 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 */ + /* 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, @@ -1364,7 +1351,7 @@ int SetCircular(DEVICE_EXTENSION * pdx, TRANSFERDESC __user * pTD) ** ** 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; unsigned int nArea; @@ -1377,20 +1364,17 @@ int GetCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) mutex_lock(&pdx->io_mutex); - nArea = cb.nArea; // Retrieve parameters first - cb.dwOffset = 0; // set default result (nothing) + nArea = cb.nArea; /* Retrieve parameters first */ + cb.dwOffset = 0; /* set default result (nothing) */ cb.dwSize = 0; - if (nArea < MAX_TRANSAREAS) // The area number must be OK - { - TRANSAREA *pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info - spin_lock_irq(&pdx->stagedLock); // Lock others out + if (nArea < MAX_TRANSAREAS) { /* The area number must be OK */ + TRANSAREA *pArea = &pdx->rTransDef[nArea]; /* Pointer to relevant info */ + spin_lock_irq(&pdx->stagedLock); /* Lock others out */ - if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area - (pArea->bCircToHost)) // For now at least must be to host - { - if (pArea->aBlocks[0].dwSize > 0) // Got anything? - { + if ((pArea->bUsed) && (pArea->bCircular) && /* Must be circular area */ + (pArea->bCircToHost)) { /* For now at least must be to host */ + if (pArea->aBlocks[0].dwSize > 0) { /* Got anything? */ cb.dwOffset = pArea->aBlocks[0].dwOffset; cb.dwSize = pArea->aBlocks[0].dwSize; dev_dbg(&pdx->interface->dev, @@ -1416,7 +1400,7 @@ int GetCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) ** ** 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; unsigned int nArea, uStart, uSize; @@ -1429,33 +1413,28 @@ int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) mutex_lock(&pdx->io_mutex); - nArea = cb.nArea; // Retrieve parameters first + nArea = cb.nArea; /* Retrieve parameters first */ uStart = cb.dwOffset; uSize = cb.dwSize; - cb.dwOffset = 0; // then set default result (nothing) + cb.dwOffset = 0; /* then set default result (nothing) */ cb.dwSize = 0; - if (nArea < MAX_TRANSAREAS) // The area number must be OK - { - TRANSAREA *pArea = &pdx->rTransDef[nArea]; // Pointer to relevant info - spin_lock_irq(&pdx->stagedLock); // Lock others out + if (nArea < MAX_TRANSAREAS) { /* The area number must be OK */ + TRANSAREA *pArea = &pdx->rTransDef[nArea]; /* Pointer to relevant info */ + spin_lock_irq(&pdx->stagedLock); /* Lock others out */ - if ((pArea->bUsed) && (pArea->bCircular) && // Must be circular area - (pArea->bCircToHost)) // For now at least must be to host - { + if ((pArea->bUsed) && (pArea->bCircular) && /* Must be circular area */ + (pArea->bCircToHost)) { /* For now at least must be to host */ bool bWaiting = false; - if ((pArea->aBlocks[0].dwSize >= uSize) && // Got anything? - (pArea->aBlocks[0].dwOffset == uStart)) // Must be legal data - { + if ((pArea->aBlocks[0].dwSize >= uSize) && /* Got anything? */ + (pArea->aBlocks[0].dwOffset == uStart)) { /* Must be legal data */ pArea->aBlocks[0].dwSize -= uSize; pArea->aBlocks[0].dwOffset += uSize; - if (pArea->aBlocks[0].dwSize == 0) // Have we emptied this block? - { - if (pArea->aBlocks[1].dwSize) // Is there a second block? - { - pArea->aBlocks[0] = pArea->aBlocks[1]; // Copy down block 2 data - pArea->aBlocks[1].dwSize = 0; // and mark the second block as unused + if (pArea->aBlocks[0].dwSize == 0) { /* Have we emptied this block? */ + if (pArea->aBlocks[1].dwSize) { /* Is there a second block? */ + 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].dwOffset = 0; } else pArea->aBlocks[0].dwOffset = 0; @@ -1468,9 +1447,8 @@ int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) pArea->aBlocks[0].dwOffset, pdx->bXFerWaiting); - // Return the next available block of memory as well - if (pArea->aBlocks[0].dwSize > 0) // Got anything? - { + /* Return the next available block of memory as well */ + if (pArea->aBlocks[0].dwSize > 0) { /* Got anything? */ cb.dwOffset = pArea->aBlocks[0].dwOffset; cb.dwSize = pArea->aBlocks[0].dwSize; @@ -1492,9 +1470,8 @@ int FreeCircBlock(DEVICE_EXTENSION * pdx, TCIRCBLOCK __user * pCB) iReturn = U14ERR_NOMEMORY; } - // If we have one, kick off pending transfer - if (bWaiting) // Got a block xfer waiting? - { + /* If we have one, kick off pending transfer */ + if (bWaiting) { /* Got a block xfer waiting? */ int RWMStat = ReadWriteMem(pdx, !pdx->rDMAInfo.bOutWard, pdx->rDMAInfo.wIdent, diff --git a/drivers/staging/ced1401/ced_ioctl.h b/drivers/staging/ced1401/ced_ioctl.h index 0895c94..aa68878 100644 --- a/drivers/staging/ced1401/ced_ioctl.h +++ b/drivers/staging/ced1401/ced_ioctl.h @@ -35,7 +35,7 @@ typedef struct TransferDesc { short eSize; /* element size - is tohost flag for circular */ } TRANSFERDESC; -typedef TRANSFERDESC * LPTRANSFERDESC; +typedef TRANSFERDESC *LPTRANSFERDESC; typedef struct TransferEvent { unsigned int dwStart; /* offset into the area */ diff --git a/drivers/staging/ced1401/machine.h b/drivers/staging/ced1401/machine.h index af07379..dbd4036d 100644 --- a/drivers/staging/ced1401/machine.h +++ b/drivers/staging/ced1401/machine.h @@ -77,20 +77,13 @@ #endif #if defined(LINUX) || defined(MAXOSX) - #define FAR + #define FAR - typedef int BOOL; // To match Windows - typedef char * LPSTR; - typedef const char * LPCSTR; - typedef unsigned short WORD; - typedef unsigned int DWORD; - typedef unsigned char BYTE; - typedef BYTE BOOLEAN; - typedef unsigned char UCHAR; - #define __packed __attribute__((packed)) - typedef BYTE * LPBYTE; - #define HIWORD(x) (WORD)(((x)>>16) & 0xffff) - #define LOWORD(x) (WORD)((x) & 0xffff) + typedef int BOOL; /* To match Windows */ + typedef unsigned char BYTE; + #define __packed __attribute__((packed)) + #define HIWORD(x) (unsigned short)(((x)>>16) & 0xffff) + #define LOWORD(x) (unsigned short)((x) & 0xffff) #endif #ifdef _IS_WINDOWS_ @@ -104,21 +97,20 @@ ** a synonym. */ #ifdef GNUC - #define DllExport __attribute__((dllexport)) - #define DllImport __attribute__((dllimport)) + #define DllExport __attribute__((dllexport)) + #define DllImport __attribute__((dllimport)) #endif #ifndef DllExport #ifdef _IS_WINDOWS_ - #define DllExport __declspec(dllexport) - #define DllImport __declspec(dllimport) + #define DllExport __declspec(dllexport) + #define DllImport __declspec(dllimport) #else - #define DllExport - #define DllImport + #define DllExport + #define DllImport #endif #endif /* _IS_WINDOWS_ */ - #ifndef TRUE #define TRUE 1 #define FALSE 0 diff --git a/drivers/staging/ced1401/usb1401.c b/drivers/staging/ced1401/usb1401.c index 254131d..97c55f9 100644 --- a/drivers/staging/ced1401/usb1401.c +++ b/drivers/staging/ced1401/usb1401.c @@ -126,18 +126,18 @@ static void ced_delete(struct kref *kref) { DEVICE_EXTENSION *pdx = to_DEVICE_EXTENSION(kref); - // 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. + /* 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. */ usb_free_coherent(pdx->udev, OUTBUF_SZ, pdx->pCoherCharOut, pdx->pUrbCharOut->transfer_dma); 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_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_urb(pdx->pStagedUrb); @@ -146,7 +146,7 @@ static void ced_delete(struct kref *kref) kfree(pdx); } -// This is the driver end of the open() call from user space. +/* This is the driver end of the open() call from user space. */ static int ced_open(struct inode *inode, struct file *file) { DEVICE_EXTENSION *pdx; @@ -184,7 +184,7 @@ static int ced_open(struct inode *inode, struct file *file) kref_put(&pdx->kref, ced_delete); 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__); retval = -EBUSY; pdx->open_count--; @@ -210,11 +210,11 @@ static int ced_release(struct inode *inode, struct file *file) dev_dbg(&pdx->interface->dev, "%s called", __func__); 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); mutex_unlock(&pdx->io_mutex); - kref_put(&pdx->kref, ced_delete); // decrement the count on our device + kref_put(&pdx->kref, ced_delete); /* decrement the count on our device */ return 0; } @@ -252,9 +252,9 @@ static int ced_flush(struct file *file, fl_owner_t id) ** not help with a device extension held by a file. ** 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 */ } /**************************************************************************** @@ -264,9 +264,9 @@ static bool CanAcceptIoRequests(DEVICE_EXTENSION * pdx) static void ced_writechar_callback(struct urb *pUrb) { DEVICE_EXTENSION *pdx = pUrb->context; - int nGot = pUrb->actual_length; // what we transferred + int nGot = pUrb->actual_length; /* what we transferred */ - if (pUrb->status) { // sync/async unlink faults aren't errors + if (pUrb->status) { /* sync/async unlink faults aren't errors */ if (! (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) { @@ -278,36 +278,35 @@ static void ced_writechar_callback(struct urb *pUrb) spin_lock(&pdx->err_lock); pdx->errors = pUrb->status; spin_unlock(&pdx->err_lock); - nGot = 0; // and tidy up again if so + nGot = 0; /* and tidy up again if so */ - spin_lock(&pdx->charOutLock); // already at irq level - pdx->dwOutBuffGet = 0; // Reset the output buffer + spin_lock(&pdx->charOutLock); /* already at irq level */ + pdx->dwOutBuffGet = 0; /* Reset the output buffer */ pdx->dwOutBuffPut = 0; - pdx->dwNumOutput = 0; // Clear the char count - pdx->bPipeError[0] = 1; // Flag an error for later - pdx->bSendCharsPending = false; // Allow other threads again - spin_unlock(&pdx->charOutLock); // already at irq level + pdx->dwNumOutput = 0; /* Clear the char count */ + pdx->bPipeError[0] = 1; /* Flag an error for later */ + pdx->bSendCharsPending = false; /* Allow other threads again */ + spin_unlock(&pdx->charOutLock); /* already at irq level */ dev_dbg(&pdx->interface->dev, "%s - char out done, 0 chars sent", __func__); } else { dev_dbg(&pdx->interface->dev, "%s - char out done, %d chars sent", __func__, nGot); - spin_lock(&pdx->charOutLock); // already at irq level - pdx->dwNumOutput -= nGot; // Now adjust the char send buffer - pdx->dwOutBuffGet += nGot; // to match what we did - if (pdx->dwOutBuffGet >= OUTBUF_SZ) // Can't do this any earlier as data could be overwritten + spin_lock(&pdx->charOutLock); /* already at irq level */ + pdx->dwNumOutput -= nGot; /* Now adjust the char send buffer */ + pdx->dwOutBuffGet += nGot; /* to match what we did */ + if (pdx->dwOutBuffGet >= OUTBUF_SZ) /* Can't do this any earlier as data could be overwritten */ pdx->dwOutBuffGet = 0; - if (pdx->dwNumOutput > 0) // if more to be done... - { - int nPipe = 0; // The pipe number to use + if (pdx->dwNumOutput > 0) { /* if more to be done... */ + int nPipe = 0; /* The pipe number to use */ int iReturn; char *pDat = &pdx->outputBuffer[pdx->dwOutBuffGet]; - unsigned int dwCount = pdx->dwNumOutput; // maximum to send - if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) // does it cross buffer end? + unsigned int dwCount = pdx->dwNumOutput; /* maximum to send */ + if ((pdx->dwOutBuffGet + dwCount) > OUTBUF_SZ) /* does it cross buffer end? */ dwCount = OUTBUF_SZ - pdx->dwOutBuffGet; - spin_unlock(&pdx->charOutLock); // we are done with stuff that changes - memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer + spin_unlock(&pdx->charOutLock); /* we are done with stuff that changes */ + memcpy(pdx->pCoherCharOut, pDat, dwCount); /* copy output data to the buffer */ usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev, usb_sndbulkpipe(pdx->udev, pdx->epAddr[0]), @@ -315,22 +314,22 @@ static void ced_writechar_callback(struct urb *pUrb) 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); 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) { - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later - pdx->bSendCharsPending = false; // Allow other threads again + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ + pdx->bSendCharsPending = false; /* Allow other threads again */ usb_unanchor_urb(pdx->pUrbCharOut); dev_err(&pdx->interface->dev, "%s usb_submit_urb() returned %d", __func__, iReturn); } } else - pdx->bSendCharsPending = false; // Allow other threads again - spin_unlock(&pdx->charOutLock); // already at irq level + pdx->bSendCharsPending = false; /* Allow other threads again */ + spin_unlock(&pdx->charOutLock); /* already at irq level */ } } @@ -339,44 +338,43 @@ static void ced_writechar_callback(struct urb *pUrb) ** Transmit the characters in the output buffer to the 1401. This may need ** breaking down into multiple transfers. ****************************************************************************/ -int SendChars(DEVICE_EXTENSION * pdx) +int SendChars(DEVICE_EXTENSION *pdx) { int iReturn = U14ERR_NOERROR; - spin_lock_irq(&pdx->charOutLock); // Protect ourselves + spin_lock_irq(&pdx->charOutLock); /* Protect ourselves */ - if ((!pdx->bSendCharsPending) && // Not currently sending - (pdx->dwNumOutput > 0) && // has characters to output - (CanAcceptIoRequests(pdx))) // and current activity is OK - { - unsigned int dwCount = pdx->dwNumOutput; // Get a copy of the character count - pdx->bSendCharsPending = true; // Set flag to lock out other threads + if ((!pdx->bSendCharsPending) && /* Not currently sending */ + (pdx->dwNumOutput > 0) && /* has characters to output */ + (CanAcceptIoRequests(pdx))) { /* and current activity is OK */ + unsigned int dwCount = pdx->dwNumOutput; /* Get a copy of the character count */ + 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); - // 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) { - // 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. - unsigned int count = dwCount; // Local char counter - unsigned int index = 0; // The index into the char buffer + /* 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. */ + unsigned int count = dwCount; /* Local char counter */ + unsigned int index = 0; /* The index into the char buffer */ - 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)) { - // 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 + /* 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 nSent = usb_control_msg(pdx->udev, - usb_sndctrlpipe(pdx->udev, 0), // use end point 0 - DB_CHARS, // bRequest - (H_TO_D | VENDOR | DEVREQ), // to the device, vendor request to the device - 0, 0, // value and index are both 0 - &pdx->outputBuffer[index], // where to send from - n, // how much to send - 1000); // timeout in jiffies + usb_sndctrlpipe(pdx->udev, 0), /* use end point 0 */ + DB_CHARS, /* bRequest */ + (H_TO_D | VENDOR | DEVREQ), /* to the device, vendor request to the device */ + 0, 0, /* value and index are both 0 */ + &pdx->outputBuffer[index], /* where to send from */ + n, /* how much to send */ + 1000); /* timeout in jiffies */ 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); @@ -388,19 +386,19 @@ int SendChars(DEVICE_EXTENSION * pdx) } } - spin_lock_irq(&pdx->charOutLock); // Protect pdx changes, released by general code - pdx->dwOutBuffGet = 0; // so reset the output buffer + spin_lock_irq(&pdx->charOutLock); /* Protect pdx changes, released by general code */ + pdx->dwOutBuffGet = 0; /* so reset the output buffer */ pdx->dwOutBuffPut = 0; - pdx->dwNumOutput = 0; // and clear the buffer count - pdx->bSendCharsPending = false; // Allow other threads again - } else { // Here for sending chars normally - we hold the spin lock - int nPipe = 0; // The pipe number to use + pdx->dwNumOutput = 0; /* and clear the buffer count */ + pdx->bSendCharsPending = false; /* Allow other threads again */ + } else { /* Here for sending chars normally - we hold the spin lock */ + int nPipe = 0; /* The pipe number to use */ 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; - spin_unlock_irq(&pdx->charOutLock); // we are done with stuff that changes - memcpy(pdx->pCoherCharOut, pDat, dwCount); // copy output data to the buffer + spin_unlock_irq(&pdx->charOutLock); /* we are done with stuff that changes */ + memcpy(pdx->pCoherCharOut, pDat, dwCount); /* copy output data to the buffer */ usb_fill_bulk_urb(pdx->pUrbCharOut, pdx->udev, usb_sndbulkpipe(pdx->udev, pdx->epAddr[0]), @@ -410,11 +408,11 @@ int SendChars(DEVICE_EXTENSION * pdx) URB_NO_TRANSFER_DMA_MAP; usb_anchor_urb(pdx->pUrbCharOut, &pdx->submitted); 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) { - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later - pdx->bSendCharsPending = false; // Allow other threads again - usb_unanchor_urb(pdx->pUrbCharOut); // remove from list of active urbs + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ + pdx->bSendCharsPending = false; /* Allow other threads again */ + usb_unanchor_urb(pdx->pUrbCharOut); /* remove from list of active urbs */ } } } else if (pdx->bSendCharsPending && (pdx->dwNumOutput > 0)) @@ -422,7 +420,7 @@ int SendChars(DEVICE_EXTENSION * pdx) "SendChars bSendCharsPending:true"); 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 */ return iReturn; } @@ -440,14 +438,14 @@ int SendChars(DEVICE_EXTENSION * pdx) ** 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. ***************************************************************************/ -static void CopyUserSpace(DEVICE_EXTENSION * pdx, int n) +static void CopyUserSpace(DEVICE_EXTENSION *pdx, int n) { unsigned int nArea = pdx->StagedId; 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; - char *pCoherBuf = pdx->pCoherStagedIO; // coherent buffer + char *pCoherBuf = pdx->pCoherStagedIO; /* coherent buffer */ if (!pArea->bUsed) { dev_err(&pdx->interface->dev, "%s area %d unused", __func__, nArea); @@ -455,15 +453,15 @@ static void CopyUserSpace(DEVICE_EXTENSION * pdx, int 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) { char *pvAddress = (char *)kmap_atomic(pArea->pPages[nPage]); if (pvAddress) { - unsigned int uiPageOff = dwOffset & (PAGE_SIZE - 1); // offset into the page - size_t uiXfer = PAGE_SIZE - uiPageOff; // max to transfer on this page - if (uiXfer > n) // limit byte count if too much - uiXfer = n; // for 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 */ + if (uiXfer > n) /* limit byte count if too much */ + uiXfer = n; /* for the page */ if (pdx->StagedRead) memcpy(pvAddress + uiPageOff, pCoherBuf, uiXfer); @@ -494,8 +492,8 @@ static void CopyUserSpace(DEVICE_EXTENSION * pdx, int n) nArea); } -// Forward declarations for stuff used circularly -static int StageChunk(DEVICE_EXTENSION * pdx); +/* Forward declarations for stuff used circularly */ +static int StageChunk(DEVICE_EXTENSION *pdx); /*************************************************************************** ** ReadWrite_Complete ** @@ -504,14 +502,14 @@ static int StageChunk(DEVICE_EXTENSION * pdx); static void staged_callback(struct urb *pUrb) { DEVICE_EXTENSION *pdx = pUrb->context; - unsigned int nGot = pUrb->actual_length; // what we transferred + unsigned int nGot = pUrb->actual_length; /* what we transferred */ bool bCancel = false; - bool bRestartCharInput; // used at the end + bool bRestartCharInput; /* used at the end */ - spin_lock(&pdx->stagedLock); // stop ReadWriteMem() action while this routine is running - pdx->bStagedUrbPending = false; // clear the flag for staged IRP pending + spin_lock(&pdx->stagedLock); /* stop ReadWriteMem() action while this routine is running */ + pdx->bStagedUrbPending = false; /* clear the flag for staged IRP pending */ - if (pUrb->status) { // sync/async unlink faults aren't errors + if (pUrb->status) { /* sync/async unlink faults aren't errors */ if (! (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) { @@ -525,40 +523,37 @@ static void staged_callback(struct urb *pUrb) spin_lock(&pdx->err_lock); pdx->errors = pUrb->status; spin_unlock(&pdx->err_lock); - nGot = 0; // and tidy up again if so + nGot = 0; /* and tidy up again if so */ bCancel = true; } else { dev_dbg(&pdx->interface->dev, "%s %d chars xferred", __func__, nGot); - if (pdx->StagedRead) // if reading, save to user space - CopyUserSpace(pdx, nGot); // copy from buffer to user + if (pdx->StagedRead) /* if reading, save to user space */ + CopyUserSpace(pdx, nGot); /* copy from buffer to user */ if (nGot == 0) dev_dbg(&pdx->interface->dev, "%s ZLP", __func__); } - // 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; 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 - (bCancel)) // or this IRP was cancelled - { - TRANSAREA *pArea = &pdx->rTransDef[pdx->StagedId]; // Transfer area info + if ((pdx->StagedDone == pdx->StagedLength) || /* If no more to do */ + (bCancel)) { /* or this IRP was cancelled */ + 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); - // 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 - // add this to the end of a growing block or to use it to start a new block unless the code - // that calculates the offset to use (in ReadWriteMem) is totally duff. - if ((pArea->bCircular) && (pArea->bCircToHost) && (!bCancel) && // Time to sort out circular buffer info? - (pdx->StagedRead)) // Only for tohost transfers for now - { - if (pArea->aBlocks[1].dwSize > 0) // If block 1 is in use we must append to it - { + /* 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 */ + /* add this to the end of a growing block or to use it to start a new block unless the code */ + /* that calculates the offset to use (in ReadWriteMem) is totally duff. */ + if ((pArea->bCircular) && (pArea->bCircToHost) && (!bCancel) && /* Time to sort out circular buffer info? */ + (pdx->StagedRead)) { /* Only for tohost transfers for now */ + 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)) { @@ -569,7 +564,7 @@ static void staged_callback(struct urb *pUrb) 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].dwSize = @@ -580,22 +575,20 @@ static void staged_callback(struct urb *pUrb) 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? - { // Must append onto the existing block 0 + } 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? */ + /* Must append onto the existing block 0 */ 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", pArea->aBlocks[0]. dwSize, pArea->aBlocks[0]. dwOffset); - } else // If it doesn't append, put into new block 1 - { + } else { /* If it doesn't append, put into new block 1 */ pArea->aBlocks[1].dwOffset = pdx->StagedOffset; pArea->aBlocks[1].dwSize = @@ -607,8 +600,7 @@ static void staged_callback(struct urb *pUrb) pArea->aBlocks[1]. dwOffset); } - } else // No info stored yet, just save in block 0 - { + } else { /* No info stored yet, just save in block 0 */ pArea->aBlocks[0].dwOffset = pdx->StagedOffset; pArea->aBlocks[0].dwSize = @@ -621,21 +613,19 @@ static void staged_callback(struct urb *pUrb) } } - 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", pArea->bCircular, pArea->bEventToHost, pArea->dwEventSt, pArea->dwEventSz); - if ((pArea->dwEventSz) && // Set a user-mode event... - (pdx->StagedRead == pArea->bEventToHost)) // ...on transfers in this direction? - { - int iWakeUp = 0; // assume - // If we have completed the right sort of DMA transfer then set the event to notify - // the user code to wake up anyone that is waiting. - if ((pArea->bCircular) && // Circular areas use a simpler test - (pArea->bCircToHost)) // only in supported direction - { // Is total data waiting up to size limit? + if ((pArea->dwEventSz) && /* Set a user-mode event... */ + (pdx->StagedRead == pArea->bEventToHost)) { /* ...on transfers in this direction? */ + int iWakeUp = 0; /* assume */ + /* If we have completed the right sort of DMA transfer then set the event to notify */ + /* the user code to wake up anyone that is waiting. */ + if ((pArea->bCircular) && /* Circular areas use a simpler test */ + (pArea->bCircToHost)) { /* only in supported direction */ + /* Is total data waiting up to size limit? */ unsigned int dwTotal = pArea->aBlocks[0].dwSize + pArea->aBlocks[1].dwSize; @@ -653,19 +643,17 @@ static void staged_callback(struct urb *pUrb) if (iWakeUp) { dev_dbg(&pdx->interface->dev, "About to set event to notify app"); - wake_up_interruptible(&pArea->wqEvent); // wake up waiting processes - ++pArea->iWakeUp; // increment wakeup count + wake_up_interruptible(&pArea->wqEvent); /* wake up waiting processes */ + ++pArea->iWakeUp; /* increment wakeup count */ } } } - pdx->dwDMAFlag = MODE_CHAR; // Switch back to char mode before ReadWriteMem call + pdx->dwDMAFlag = MODE_CHAR; /* Switch back to char mode before ReadWriteMem call */ - if (!bCancel) // Don't look for waiting transfer if cancelled - { - // If we have a transfer waiting, kick it off - if (pdx->bXFerWaiting) // Got a block xfer waiting? - { + if (!bCancel) { /* Don't look for waiting transfer if cancelled */ + /* If we have a transfer waiting, kick it off */ + if (pdx->bXFerWaiting) { /* Got a block xfer waiting? */ int iReturn; dev_info(&pdx->interface->dev, "*** RWM_Complete *** pending transfer will now be set up!!!"); @@ -682,22 +670,22 @@ static void staged_callback(struct urb *pUrb) } } - } else // Here for more to do - StageChunk(pdx); // fire off the next bit + } else /* Here for more to do */ + StageChunk(pdx); /* fire off the next bit */ - // 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. - // This feels wrong as we should ask which spin lock protects dwDMAFlag. + /* 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. */ + /* This feels wrong as we should ask which spin lock protects dwDMAFlag. */ 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 */ - // This is not correct as dwDMAFlag is protected by the staged lock, but it is treated - // in Allowi as if it were protected by the char lock. In any case, most systems will - // not be upset by char input during DMA... sigh. Needs sorting out. - if (bRestartCharInput) // may be out of date, but... - Allowi(pdx); // ...Allowi tests a lock too. + /* This is not correct as dwDMAFlag is protected by the staged lock, but it is treated */ + /* in Allowi as if it were protected by the char lock. In any case, most systems will */ + /* not be upset by char input during DMA... sigh. Needs sorting out. */ + if (bRestartCharInput) /* may be out of date, but... */ + Allowi(pdx); /* ...Allowi tests a lock too. */ dev_dbg(&pdx->interface->dev, "%s done", __func__); } @@ -709,29 +697,28 @@ static void staged_callback(struct urb *pUrb) ** The calling code must have acquired the staging spinlock before calling ** 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; 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 (nPipe < 0) // and trap case that should never happen + nPipe--; /* Adjust for the 3-pipe case */ + if (nPipe < 0) /* and trap case that should never happen */ 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__); - return U14ERR_FAIL; // could do with a better error + return U14ERR_FAIL; /* could do with a better error */ } - ChunkSize = (pdx->StagedLength - pdx->StagedDone); // transfer length remaining - if (ChunkSize > STAGED_SZ) // make sure to keep legal - ChunkSize = STAGED_SZ; // limit to max allowed + ChunkSize = (pdx->StagedLength - pdx->StagedDone); /* transfer length remaining */ + if (ChunkSize > STAGED_SZ) /* make sure to keep legal */ + ChunkSize = STAGED_SZ; /* limit to max allowed */ - if (!pdx->StagedRead) // if writing... - CopyUserSpace(pdx, ChunkSize); // ...copy data into the buffer + if (!pdx->StagedRead) /* if writing... */ + CopyUserSpace(pdx, ChunkSize); /* ...copy data into the buffer */ usb_fill_bulk_urb(pdx->pStagedUrb, pdx->udev, pdx->StagedRead ? usb_rcvbulkpipe(pdx->udev, @@ -740,15 +727,15 @@ static int StageChunk(DEVICE_EXTENSION * pdx) usb_sndbulkpipe(pdx->udev, pdx->epAddr[nPipe]), pdx->pCoherStagedIO, ChunkSize, staged_callback, pdx); 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); if (iReturn) { - usb_unanchor_urb(pdx->pStagedUrb); // kill it - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later + usb_unanchor_urb(pdx->pStagedUrb); /* kill it */ + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ dev_err(&pdx->interface->dev, "%s submit urb failed, code %d", __func__, iReturn); } 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); @@ -772,13 +759,12 @@ static int StageChunk(DEVICE_EXTENSION * pdx) ** 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) { - 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__); return U14ERR_FAIL; @@ -788,56 +774,51 @@ int ReadWriteMem(DEVICE_EXTENSION * pdx, bool Read, unsigned short 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 - // have to check for this situation and, if so, wait until all is OK. + /* 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. */ 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__); 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__); return U14ERR_NOERROR; } - if ((pArea->bCircular) && // Circular transfer? - (pArea->bCircToHost) && (Read)) // In a supported direction - { // If so, we sort out offset ourself - bool bWait = false; // Flag for transfer having to wait + if ((pArea->bCircular) && /* Circular transfer? */ + (pArea->bCircToHost) && (Read)) { /* In a supported direction */ + /* If so, we sort out offset ourself */ + bool bWait = false; /* Flag for transfer having to wait */ dev_dbg(&pdx->interface->dev, "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? - { - 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->dwLength; // or if it overflows the buffer - } 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[1].dwSize > 0) { /* Using the second block already? */ + 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->dwLength; /* or if it overflows the buffer */ + } else { /* Area 1 not in use, try to use area 0 */ + if (pArea->aBlocks[0].dwSize == 0) /* Reset block 0 if not in use */ pArea->aBlocks[0].dwOffset = 0; dwOffs = 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 + if ((dwOffs + dwLen) > pArea->dwLength) { /* Off the end of the buffer? */ + pArea->aBlocks[1].dwOffset = 0; /* Set up to use second block */ dwOffs = 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->aBlocks[0].dwOffset; /* Wait if will overwrite block 0? */ + bWait |= (dwOffs + dwLen) > pArea->dwLength; /* or if it overflows the buffer */ } } - if (bWait) // This transfer will have to wait? - { - pdx->bXFerWaiting = true; // Flag we are waiting + if (bWait) { /* This transfer will have to wait? */ + pdx->bXFerWaiting = true; /* Flag we are waiting */ dev_dbg(&pdx->interface->dev, "%s xfer waiting for circular buffer space", __func__); @@ -848,17 +829,17 @@ int ReadWriteMem(DEVICE_EXTENSION * pdx, bool Read, unsigned short wIdent, "%s circular xfer, %d bytes starting at %d", __func__, dwLen, dwOffs); } - // Save the parameters for the read\write transfer - pdx->StagedRead = Read; // Save the parameters for this read - pdx->StagedId = wIdent; // ID allows us to get transfer area info - pdx->StagedOffset = dwOffs; // The area within the transfer area + /* Save the parameters for the read\write transfer */ + pdx->StagedRead = Read; /* Save the parameters for this read */ + pdx->StagedId = wIdent; /* ID allows us to get transfer area info */ + pdx->StagedOffset = dwOffs; /* The area within the transfer area */ pdx->StagedLength = dwLen; - pdx->StagedDone = 0; // Initialise the byte count - pdx->dwDMAFlag = MODE_LINEAR; // Set DMA mode flag at this point - pdx->bXFerWaiting = false; // Clearly not a transfer waiting now + pdx->StagedDone = 0; /* Initialise the byte count */ + pdx->dwDMAFlag = MODE_LINEAR; /* Set DMA mode flag at this point */ + pdx->bXFerWaiting = false; /* Clearly not a transfer waiting now */ -// KeClearEvent(&pdx->StagingDoneEvent); // Clear the transfer done event - StageChunk(pdx); // fire off the first chunk +/* KeClearEvent(&pdx->StagingDoneEvent); // Clear the transfer done event */ + StageChunk(pdx); /* fire off the first chunk */ return U14ERR_NOERROR; } @@ -877,12 +858,11 @@ static bool ReadChar(unsigned char *pChar, char *pBuf, unsigned int *pdDone, bool bRead = false; unsigned int dDone = *pdDone; - if (dDone < dGot) // If there is more data - { - *pChar = (unsigned char)pBuf[dDone]; // Extract the next char - dDone++; // Increment the done count + if (dDone < dGot) { /* If there is more data */ + *pChar = (unsigned char)pBuf[dDone]; /* Extract the next char */ + dDone++; /* Increment the done count */ *pdDone = dDone; - bRead = true; // and flag success + bRead = true; /* and flag success */ } return bRead; @@ -962,32 +942,32 @@ static bool ReadHuff(volatile unsigned int *pDWord, char *pBuf, ** 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) { - bool bResult = false; // assume we won't succeed + bool bResult = false; /* assume we won't succeed */ unsigned char ucData; - unsigned int dDone = 0; // We haven't parsed anything so far + unsigned int dDone = 0; /* We haven't parsed anything so far */ dev_dbg(&pdx->interface->dev, "%s", __func__); if (ReadChar(&ucData, pBuf, &dDone, dwCount)) { - unsigned char ucTransCode = (ucData & 0x0F); // get code for transfer type - unsigned short wIdent = ((ucData >> 4) & 0x07); // and area identifier + unsigned char ucTransCode = (ucData & 0x0F); /* get code for transfer type */ + unsigned short wIdent = ((ucData >> 4) & 0x07); /* and area identifier */ - // fill in the structure we were given - pDmaDesc->wTransType = ucTransCode; // type of transfer - pDmaDesc->wIdent = wIdent; // area to use - pDmaDesc->dwSize = 0; // initialise other bits + /* fill in the structure we were given */ + pDmaDesc->wTransType = ucTransCode; /* type of transfer */ + pDmaDesc->wIdent = wIdent; /* area to use */ + pDmaDesc->dwSize = 0; /* initialise other bits */ pDmaDesc->dwOffset = 0; 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) { - case TM_EXTTOHOST: // Extended linear transfer modes (the only ones!) + case TM_EXTTOHOST: /* Extended linear transfer modes (the only ones!) */ case TM_EXTTO1401: { bResult = @@ -1001,14 +981,14 @@ static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx, __func__, pDmaDesc->dwOffset, pDmaDesc->dwSize); - if ((wIdent >= MAX_TRANSAREAS) || // Illegal area number, or... - (!pdx->rTransDef[wIdent].bUsed) || // area not set up, or... - (pDmaDesc->dwOffset > pdx->rTransDef[wIdent].dwLength) || // range/size + if ((wIdent >= MAX_TRANSAREAS) || /* Illegal area number, or... */ + (!pdx->rTransDef[wIdent].bUsed) || /* area not set up, or... */ + (pDmaDesc->dwOffset > pdx->rTransDef[wIdent].dwLength) || /* range/size */ ((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", __func__, wIdent, @@ -1028,7 +1008,7 @@ static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx, } else 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__); @@ -1049,30 +1029,29 @@ static bool ReadDMAInfo(volatile DMADESC * pDmaDesc, DEVICE_EXTENSION * pdx, ** this is known to be at least 2 or we will not be called. ** ****************************************************************************/ -static int Handle1401Esc(DEVICE_EXTENSION * pdx, char *pCh, +static int Handle1401Esc(DEVICE_EXTENSION *pdx, char *pCh, unsigned int dwCount) { int iReturn = U14ERR_FAIL; - // I have no idea what this next test is about. '?' is 0x3f, which is area 3, code - // 15. At the moment, this is not used, so it does no harm, but unless someone can - // tell me what this is for, it should be removed from this and the Windows driver. - if (pCh[0] == '?') // Is this an information response - { // Parse and save the information + /* I have no idea what this next test is about. '?' is 0x3f, which is area 3, code */ + /* 15. At the moment, this is not used, so it does no harm, but unless someone can */ + /* tell me what this is for, it should be removed from this and the Windows driver. */ + if (pCh[0] == '?') { /* Is this an information response */ + /* Parse and save the information */ } 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 - { - unsigned short wTransType = pdx->rDMAInfo.wTransType; // check transfer type + if (ReadDMAInfo(&pdx->rDMAInfo, pdx, pCh, dwCount)) { /* Get DMA parameters */ + unsigned short wTransType = pdx->rDMAInfo.wTransType; /* check transfer type */ dev_dbg(&pdx->interface->dev, "%s xfer to %s, offset %d, length %d", __func__, pdx->rDMAInfo.bOutWard ? "1401" : "host", pdx->rDMAInfo.dwOffset, pdx->rDMAInfo.dwSize); - if (pdx->bXFerWaiting) // Check here for badly out of kilter... - { // This can never happen, really + if (pdx->bXFerWaiting) { /* Check here for badly out of kilter... */ + /* This can never happen, really */ dev_err(&pdx->interface->dev, "ERROR: DMA setup while transfer still waiting"); spin_unlock(&pdx->stagedLock); @@ -1090,16 +1069,16 @@ static int Handle1401Esc(DEVICE_EXTENSION * pdx, char *pCh, dev_err(&pdx->interface->dev, "%s ReadWriteMem() failed %d", __func__, iReturn); - } else // This covers non-linear transfer setup + } else /* This covers non-linear transfer setup */ dev_err(&pdx->interface->dev, "%s Unknown block xfer type %d", __func__, wTransType); } - } else // Failed to read parameters + } 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 */ } dev_dbg(&pdx->interface->dev, "%s returns %d", __func__, iReturn); @@ -1113,12 +1092,11 @@ static int Handle1401Esc(DEVICE_EXTENSION * pdx, char *pCh, static void ced_readchar_callback(struct urb *pUrb) { DEVICE_EXTENSION *pdx = pUrb->context; - int nGot = pUrb->actual_length; // what we transferred + int nGot = pUrb->actual_length; /* what we transferred */ - if (pUrb->status) // Do we have a problem to handle? - { - 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 + if (pUrb->status) { /* Do we have a problem to handle? */ + 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 */ if (! (pUrb->status == -ENOENT || pUrb->status == -ECONNRESET || pUrb->status == -ESHUTDOWN)) { @@ -1133,27 +1111,26 @@ static void ced_readchar_callback(struct urb *pUrb) spin_lock(&pdx->err_lock); pdx->errors = pUrb->status; spin_unlock(&pdx->err_lock); - nGot = 0; // and tidy up again if so + nGot = 0; /* and tidy up again if so */ - spin_lock(&pdx->charInLock); // already at irq level - pdx->bPipeError[nPipe] = 1; // Flag an error for later + spin_lock(&pdx->charInLock); /* already at irq level */ + pdx->bPipeError[nPipe] = 1; /* Flag an error for later */ } else { - if ((nGot > 1) && ((pdx->pCoherCharIn[0] & 0x7f) == 0x1b)) // Esc sequence? - { - Handle1401Esc(pdx, &pdx->pCoherCharIn[1], nGot - 1); // handle it - spin_lock(&pdx->charInLock); // already at irq level + if ((nGot > 1) && ((pdx->pCoherCharIn[0] & 0x7f) == 0x1b)) { /* Esc sequence? */ + Handle1401Esc(pdx, &pdx->pCoherCharIn[1], nGot - 1); /* handle it */ + spin_lock(&pdx->charInLock); /* already at irq level */ } else { - spin_lock(&pdx->charInLock); // already at irq level + spin_lock(&pdx->charInLock); /* already at irq level */ if (nGot > 0) { unsigned int i; 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); } - // 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++) { pdx->inputBuffer[pdx->dwInBuffPut++] = pdx->pCoherCharIn[i] & 0x7F; @@ -1162,17 +1139,17 @@ static void ced_readchar_callback(struct urb *pUrb) } if ((pdx->dwNumInput + nGot) <= INBUF_SZ) - pdx->dwNumInput += nGot; // Adjust the buffer count accordingly + pdx->dwNumInput += nGot; /* Adjust the buffer count accordingly */ } else dev_dbg(&pdx->interface->dev, "%s read ZLP", __func__); } } - pdx->bReadCharsPending = false; // No longer have a pending read - spin_unlock(&pdx->charInLock); // already at irq level + pdx->bReadCharsPending = false; /* No longer have a pending read */ + spin_unlock(&pdx->charInLock); /* already at irq level */ - Allowi(pdx); // see if we can do the next one + Allowi(pdx); /* see if we can do the next one */ } /**************************************************************************** @@ -1182,25 +1159,25 @@ static void ced_readchar_callback(struct urb *pUrb) ** we can pick up any inward transfers. This can be called in multiple contexts ** so we use the irqsave version of the spinlock. ****************************************************************************/ -int Allowi(DEVICE_EXTENSION * pdx) +int Allowi(DEVICE_EXTENSION *pdx) { int iReturn = U14ERR_NOERROR; unsigned long flags; - spin_lock_irqsave(&pdx->charInLock, flags); // can be called in multiple contexts - - // We don't want char input running while DMA is in progress as we know that this - // can cause sequencing problems for the 2270. So don't. It will also allow the - // ERR response to get back to the host code too early on some PCs, even if there - // is no actual driver failure, so we don't allow this at all. - if (!pdx->bInDrawDown && // stop input if - !pdx->bReadCharsPending && // If no read request outstanding - (pdx->dwNumInput < (INBUF_SZ / 2)) && // and there is some space - (pdx->dwDMAFlag == MODE_CHAR) && // not doing any DMA - (!pdx->bXFerWaiting) && // no xfer waiting to start - (CanAcceptIoRequests(pdx))) // and activity is generally OK - { // then off we go - unsigned int nMax = INBUF_SZ - pdx->dwNumInput; // max we could read - int nPipe = pdx->nPipes == 4 ? 1 : 0; // The pipe number to use + spin_lock_irqsave(&pdx->charInLock, flags); /* can be called in multiple contexts */ + + /* We don't want char input running while DMA is in progress as we know that this */ + /* can cause sequencing problems for the 2270. So don't. It will also allow the */ + /* ERR response to get back to the host code too early on some PCs, even if there */ + /* is no actual driver failure, so we don't allow this at all. */ + if (!pdx->bInDrawDown && /* stop input if */ + !pdx->bReadCharsPending && /* If no read request outstanding */ + (pdx->dwNumInput < (INBUF_SZ / 2)) && /* and there is some space */ + (pdx->dwDMAFlag == MODE_CHAR) && /* not doing any DMA */ + (!pdx->bXFerWaiting) && /* no xfer waiting to start */ + (CanAcceptIoRequests(pdx))) { /* and activity is generally OK */ + /* then off we go */ + unsigned int nMax = INBUF_SZ - pdx->dwNumInput; /* max we could read */ + 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); @@ -1209,16 +1186,16 @@ int Allowi(DEVICE_EXTENSION * pdx) usb_rcvintpipe(pdx->udev, pdx->epAddr[nPipe]), pdx->pCoherCharIn, nMax, ced_readchar_callback, pdx, pdx->bInterval); - 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 + 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 */ iReturn = usb_submit_urb(pdx->pUrbCharIn, GFP_ATOMIC); if (iReturn) { - usb_unanchor_urb(pdx->pUrbCharIn); // remove from list of active Urbs - pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later + usb_unanchor_urb(pdx->pUrbCharIn); /* remove from list of active Urbs */ + pdx->bPipeError[nPipe] = 1; /* Flag an error to be handled later */ dev_err(&pdx->interface->dev, "%s submit urb failed: %d", __func__, iReturn); } else - pdx->bReadCharsPending = true; // Flag that we are active here + pdx->bReadCharsPending = true; /* Flag that we are active here */ } spin_unlock_irqrestore(&pdx->charInLock, flags); @@ -1238,15 +1215,15 @@ static long ced_ioctl(struct file *file, unsigned int cmd, unsigned long ulArg) { int err = 0; DEVICE_EXTENSION *pdx = file->private_data; - if (!CanAcceptIoRequests(pdx)) // check we still exist + if (!CanAcceptIoRequests(pdx)) /* check we still exist */ return -ENODEV; - // Check that access is allowed, where is is needed. Anything that would have an indeterminate - // size will be checked by the specific command. - if (_IOC_DIR(cmd) & _IOC_READ) // read from point of view of user... - err = !access_ok(VERIFY_WRITE, (void __user *)ulArg, _IOC_SIZE(cmd)); // is kernel write - else if (_IOC_DIR(cmd) & _IOC_WRITE) // and write from point of view of user... - err = !access_ok(VERIFY_READ, (void __user *)ulArg, _IOC_SIZE(cmd)); // is kernel read + /* Check that access is allowed, where is is needed. Anything that would have an indeterminate */ + /* size will be checked by the specific command. */ + if (_IOC_DIR(cmd) & _IOC_READ) /* read from point of view of user... */ + err = !access_ok(VERIFY_WRITE, (void __user *)ulArg, _IOC_SIZE(cmd)); /* is kernel write */ + else if (_IOC_DIR(cmd) & _IOC_WRITE) /* and write from point of view of user... */ + err = !access_ok(VERIFY_READ, (void __user *)ulArg, _IOC_SIZE(cmd)); /* is kernel read */ if (err) return -EFAULT; @@ -1289,7 +1266,7 @@ static long ced_ioctl(struct file *file, unsigned int cmd, unsigned long ulArg) return -1; 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): return GetTransfer(pdx, (TGET_TX_BLOCK __user *) ulArg); @@ -1335,7 +1312,7 @@ static long ced_ioctl(struct file *file, unsigned int cmd, unsigned long ulArg) return DbgStopLoop(pdx); case _IOC_NR(IOCTL_CED_FULLRESET): - pdx->bForceReset = true; // Set a flag for a full reset + pdx->bForceReset = true; /* Set a flag for a full reset */ break; case _IOC_NR(IOCTL_CED_SETCIRCULAR): @@ -1378,8 +1355,8 @@ static struct usb_class_driver ced_class = { .minor_base = USB_CED_MINOR_BASE, }; -// Check that the device that matches a 1401 vendor and product ID is OK to use and -// initialise our DEVICE_EXTENSION. +/* Check that the device that matches a 1401 vendor and product ID is OK to use and */ +/* initialise our DEVICE_EXTENSION. */ static int ced_probe(struct usb_interface *interface, const struct usb_device_id *id) { @@ -1389,23 +1366,22 @@ static int ced_probe(struct usb_interface *interface, int i, bcdDevice; int retval = -ENOMEM; - // allocate memory for our device extension and initialize it + /* allocate memory for our device extension and initialize it */ pdx = kzalloc(sizeof(*pdx), GFP_KERNEL); if (!pdx) 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); } - // Put initialises for our stuff here. Note that all of *pdx is zero, so - // no need to explicitly zero it. + /* Put initialises for our stuff here. Note that all of *pdx is zero, so */ + /* no need to explicitly zero it. */ spin_lock_init(&pdx->charOutLock); spin_lock_init(&pdx->charInLock); spin_lock_init(&pdx->stagedLock); - // Initialises from the skeleton stuff + /* Initialises from the skeleton stuff */ kref_init(&pdx->kref); mutex_init(&pdx->io_mutex); spin_lock_init(&pdx->err_lock); @@ -1414,7 +1390,7 @@ static int ced_probe(struct usb_interface *interface, pdx->udev = usb_get_dev(interface_to_usbdev(interface)); pdx->interface = interface; - // Attempt to identify the device + /* Attempt to identify the device */ bcdDevice = pdx->udev->descriptor.bcdDevice; i = (bcdDevice >> 8); if (i == 0) @@ -1426,8 +1402,8 @@ static int ced_probe(struct usb_interface *interface, __func__, bcdDevice); goto error; } - // set up the endpoint information. We only care about the number of EP as - // we know that we are dealing with a 1401 device. + /* set up the endpoint information. We only care about the number of EP as */ + /* we know that we are dealing with a 1401 device. */ iface_desc = interface->cur_altsetting; pdx->nPipes = iface_desc->desc.bNumEndpoints; dev_info(&interface->dev, "1401Type=%d with %d End Points", @@ -1435,10 +1411,10 @@ static int ced_probe(struct usb_interface *interface, if ((pdx->nPipes < 3) || (pdx->nPipes > 4)) goto error; - // Allocate the URBs we hold for performing transfers - pdx->pUrbCharOut = usb_alloc_urb(0, GFP_KERNEL); // character output URB - pdx->pUrbCharIn = usb_alloc_urb(0, GFP_KERNEL); // character input URB - pdx->pStagedUrb = usb_alloc_urb(0, GFP_KERNEL); // block transfer URB + /* Allocate the URBs we hold for performing transfers */ + pdx->pUrbCharOut = usb_alloc_urb(0, GFP_KERNEL); /* character output URB */ + pdx->pUrbCharIn = usb_alloc_urb(0, GFP_KERNEL); /* character input URB */ + pdx->pStagedUrb = usb_alloc_urb(0, GFP_KERNEL); /* block transfer URB */ if (!pdx->pUrbCharOut || !pdx->pUrbCharIn || !pdx->pStagedUrb) { dev_err(&interface->dev, "%s URB alloc failed", __func__); goto error; @@ -1464,15 +1440,14 @@ static int ced_probe(struct usb_interface *interface, pdx->epAddr[i] = endpoint->bEndpointAddress; dev_info(&interface->dev, "Pipe %d, ep address %02x", i, pdx->epAddr[i]); - if (((pdx->nPipes == 3) && (i == 0)) || // if char input end point + 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); } - // Detect USB2 by checking last ep size (64 if USB1) - if (i == pdx->nPipes - 1) // if this is the last ep (bulk) - { + /* Detect USB2 by checking last ep size (64 if USB1) */ + if (i == pdx->nPipes - 1) { /* if this is the last ep (bulk) */ pdx->bIsUSB2 = le16_to_cpu(endpoint->wMaxPacketSize) > 64; dev_info(&pdx->interface->dev, "USB%d", @@ -1501,7 +1476,7 @@ static int ced_probe(struct usb_interface *interface, error: if (pdx) - kref_put(&pdx->kref, ced_delete); // frees allocated memory + kref_put(&pdx->kref, ced_delete); /* frees allocated memory */ return retval; } @@ -1511,39 +1486,39 @@ static void ced_disconnect(struct usb_interface *interface) int minor = interface->minor; int i; - usb_set_intfdata(interface, NULL); // remove the pdx from the interface - usb_deregister_dev(interface, &ced_class); // give back our minor device number + usb_set_intfdata(interface, NULL); /* remove the pdx from the interface */ + usb_deregister_dev(interface, &ced_class); /* give back our minor device number */ - mutex_lock(&pdx->io_mutex); // stop more I/O starting while... - ced_draw_down(pdx); // ...wait for then kill any io + mutex_lock(&pdx->io_mutex); /* stop more I/O starting while... */ + ced_draw_down(pdx); /* ...wait for then kill any io */ 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) 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); usb_kill_anchored_urbs(&pdx->submitted); - kref_put(&pdx->kref, ced_delete); // decrement our usage count + kref_put(&pdx->kref, ced_delete); /* decrement our usage count */ dev_info(&interface->dev, "USB cedusb #%d now disconnected", minor); } -// Wait for all the urbs we know of to be done with, then kill off any that -// 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 -// to be done. -void ced_draw_down(DEVICE_EXTENSION * pdx) +/* Wait for all the urbs we know of to be done with, then kill off any that */ +/* 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 */ +/* to be done. */ +void ced_draw_down(DEVICE_EXTENSION *pdx) { int time; dev_dbg(&pdx->interface->dev, "%s called", __func__); pdx->bInDrawDown = true; 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); dev_err(&pdx->interface->dev, "%s timed out", __func__); } diff --git a/drivers/staging/ced1401/usb1401.h b/drivers/staging/ced1401/usb1401.h index 8fc6958..f031e3a 100644 --- a/drivers/staging/ced1401/usb1401.h +++ b/drivers/staging/ced1401/usb1401.h @@ -26,31 +26,32 @@ #define UINT unsigned int #endif -/// Device type codes, but these don't need to be extended - a succession is assumed -/// These are set for usb from the bcdDevice field (suitably mangled). Future devices -/// will be added in order of device creation to the list, so the names here are just -/// to help use remember which device is which. The U14ERR_... values follow the same -/// pattern for modern devices. -#define TYPEUNKNOWN -1 // dont know -#define TYPE1401 0 // standard 1401 -#define TYPEPLUS 1 // 1401 plus -#define TYPEU1401 2 // u1401 -#define TYPEPOWER 3 // Power1401 -#define TYPEU14012 4 // u1401 mkII -#define TYPEPOWER2 5 // Power1401 mk II -#define TYPEMICRO3 6 // Micro1401-3 -#define TYPEPOWER3 7 // Power1401-3 - -/// Some useful defines of constants. DONT FORGET to change the version in the -/// resources whenever you change it here!. -#define DRIVERMAJREV 2 // driver revision level major (match windows) -#define DRIVERMINREV 0 // driver revision level minor - -/// Definitions of the various block transfer command codes -#define TM_EXTTOHOST 8 // extended tohost -#define TM_EXTTO1401 9 // extended to1401 - -/// Definitions of values in usbReqtype. Used in sorting out setup actions +/** Device type codes, but these don't need to be extended - a succession is assumed +** These are set for usb from the bcdDevice field (suitably mangled). Future devices +** will be added in order of device creation to the list, so the names here are just +** to help use remember which device is which. The U14ERR_... values follow the same +** pattern for modern devices.a +**/ +#define TYPEUNKNOWN -1 /* dont know */ +#define TYPE1401 0 /* standard 1401 */ +#define TYPEPLUS 1 /* 1401 plus */ +#define TYPEU1401 2 /* u1401 */ +#define TYPEPOWER 3 /* Power1401 */ +#define TYPEU14012 4 /* u1401 mkII */ +#define TYPEPOWER2 5 /* Power1401 mk II */ +#define TYPEMICRO3 6 /* Micro1401-3 */ +#define TYPEPOWER3 7 /* Power1401-3 */ + +/* Some useful defines of constants. DONT FORGET to change the version in the */ +/* resources whenever you change it here!. */ +#define DRIVERMAJREV 2 /* driver revision level major (match windows) */ +#define DRIVERMINREV 0 /* driver revision level minor */ + +/* Definitions of the various block transfer command codes */ +#define TM_EXTTOHOST 8 /* extended tohost */ +#define TM_EXTTO1401 9 /* extended to1401 */ + +/* Definitions of values in usbReqtype. Used in sorting out setup actions */ #define H_TO_D 0x00 #define D_TO_H 0x80 #define VENDOR 0x40 @@ -58,7 +59,7 @@ #define INTREQ 0x01 #define ENDREQ 0x02 -/// Definition of values in usbRequest, again used to sort out setup +/* Definition of values in usbRequest, again used to sort out setup */ #define GET_STATUS 0x00 #define CLEAR_FEATURE 0x01 #define SET_FEATURE 0x03 @@ -71,8 +72,8 @@ #define SET_INTERFACE 0x0b #define SYNCH_FRAME 0x0c -/// Definitions of the various debug command codes understood by the 1401. These -/// are used in various vendor-specific commands to achieve the desired effect +/* Definitions of the various debug command codes understood by the 1401. These */ +/* are used in various vendor-specific commands to achieve the desired effect */ #define DB_GRAB 0x50 /* Grab is a NOP for USB */ #define DB_FREE 0x51 /* Free is a NOP for the USB */ #define DB_SETADD 0x52 /* Set debug address (double) */ @@ -91,139 +92,135 @@ #define CR_CHAR 0x0D /* The carriage return character */ #define CR_CHAR_80 0x8d /* and with bit 7 set */ -/// A structure holding information about a block of memory for use in circular transfers -typedef struct circBlk -{ - volatile UINT dwOffset; /* Offset within area of block start */ - volatile UINT dwSize; /* Size of the block, in bytes (0 = unused) */ +/* A structure holding information about a block of memory for use in circular transfers */ +typedef struct circBlk { + volatile UINT dwOffset; /* Offset within area of block start */ + volatile UINT dwSize; /* Size of the block, in bytes (0 = unused) */ } CIRCBLK; -/// A structure holding all of the information about a transfer area - an area of -/// memory set up for use either as a source or destination in DMA transfers. -typedef struct transarea -{ - void* lpvBuff; // User address of xfer area saved for completeness - UINT dwBaseOffset; // offset to start of xfer area in first page - UINT dwLength; // Length of xfer area, in bytes - struct page **pPages; // Points at array of locked down pages - int nPages; // number of pages that are locked down - bool bUsed; // Is this structure in use? - bool bCircular; // Is this area for circular transfers? - bool bCircToHost; // Flag for direction of circular transfer - bool bEventToHost; // Set event on transfer to host? - int iWakeUp; // Set 1 on event, cleared by TestEvent() - UINT dwEventSt; // Defines section within xfer area for... - UINT dwEventSz; // ...notification by the event SZ is 0 if unset - CIRCBLK aBlocks[2]; // Info on a pair of circular blocks - wait_queue_head_t wqEvent; // The wait queue for events in this area MUST BE LAST +/* A structure holding all of the information about a transfer area - an area of */ +/* memory set up for use either as a source or destination in DMA transfers. */ +typedef struct transarea { + void *lpvBuff; /* User address of xfer area saved for completeness */ + UINT dwBaseOffset; /* offset to start of xfer area in first page */ + UINT dwLength; /* Length of xfer area, in bytes */ + struct page **pPages; /* Points at array of locked down pages */ + int nPages; /* number of pages that are locked down */ + bool bUsed; /* Is this structure in use? */ + bool bCircular; /* Is this area for circular transfers? */ + bool bCircToHost; /* Flag for direction of circular transfer */ + bool bEventToHost; /* Set event on transfer to host? */ + int iWakeUp; /* Set 1 on event, cleared by TestEvent() */ + UINT dwEventSt; /* Defines section within xfer area for... */ + UINT dwEventSz; /* ...notification by the event SZ is 0 if unset */ + CIRCBLK aBlocks[2]; /* Info on a pair of circular blocks */ + wait_queue_head_t wqEvent; /* The wait queue for events in this area MUST BE LAST */ } TRANSAREA; -/// The DMADESC structure is used to hold information on the transfer in progress. It -/// is set up by ReadDMAInfo, using information sent by the 1401 in an escape sequence. -typedef struct dmadesc -{ - unsigned short wTransType; /* transfer type as TM_xxx above */ - unsigned short wIdent; /* identifier word */ - unsigned int dwSize; /* bytes to transfer */ - unsigned int dwOffset; /* offset into transfer area for trans */ - bool bOutWard; /* true when data is going TO 1401 */ +/* The DMADESC structure is used to hold information on the transfer in progress. It */ +/* is set up by ReadDMAInfo, using information sent by the 1401 in an escape sequence. */ +typedef struct dmadesc { + unsigned short wTransType; /* transfer type as TM_xxx above */ + unsigned short wIdent; /* identifier word */ + unsigned int dwSize; /* bytes to transfer */ + unsigned int dwOffset; /* offset into transfer area for trans */ + bool bOutWard; /* true when data is going TO 1401 */ } DMADESC; #define INBUF_SZ 256 /* input buffer size */ #define OUTBUF_SZ 256 /* output buffer size */ -#define STAGED_SZ 0x10000 // size of coherent buffer for staged transfers - -/// Structure to hold all of our device specific stuff. We are making this as similar as we -/// can to the Windows driver to help in our understanding of what is going on. -typedef struct _DEVICE_EXTENSION -{ - char inputBuffer[INBUF_SZ]; /* The two buffers */ - char outputBuffer[OUTBUF_SZ]; /* accessed by the host functions */ - volatile unsigned int dwNumInput; /* num of chars in input buffer */ - volatile unsigned int dwInBuffGet; /* where to get from input buffer */ - volatile unsigned int dwInBuffPut; /* where to put into input buffer */ - volatile unsigned int dwNumOutput; /* num of chars in output buffer */ - volatile unsigned int dwOutBuffGet; /* where to get from output buffer*/ - volatile unsigned int dwOutBuffPut; /* where to put into output buffer*/ - - volatile bool bSendCharsPending; /* Flag to indicate sendchar active */ - volatile bool bReadCharsPending; /* Flag to indicate a read is primed */ - char* pCoherCharOut; /* special aligned buffer for chars to 1401 */ - struct urb* pUrbCharOut; /* urb used for chars to 1401 */ - char* pCoherCharIn; /* special aligned buffer for chars to host */ - struct urb* pUrbCharIn; /* urb used for chars to host */ - - spinlock_t charOutLock; /* to protect the outputBuffer and outputting */ - spinlock_t charInLock; /* to protect the inputBuffer and char reads */ - __u8 bInterval; /* Interrupt end point interval */ - - volatile unsigned int dwDMAFlag; /* state of DMA */ - TRANSAREA rTransDef[MAX_TRANSAREAS];/* transfer area info */ - volatile DMADESC rDMAInfo; // info on current DMA transfer - volatile bool bXFerWaiting; // Flag set if DMA transfer stalled - volatile bool bInDrawDown; // Flag that we want to halt transfers - - // Parameters relating to a block read\write that is in progress. Some of these values - // are equivalent to values in rDMAInfo. The values here are those in use, while those - // in rDMAInfo are those received from the 1401 via an escape sequence. If another - // escape sequence arrives before the previous xfer ends, rDMAInfo values are updated while these - // are used to finish off the current transfer. - volatile short StagedId; // The transfer area id for this transfer - volatile bool StagedRead; // Flag TRUE for read from 1401, FALSE for write - volatile unsigned int StagedLength; // Total length of this transfer - volatile unsigned int StagedOffset; // Offset within memory area for transfer start - volatile unsigned int StagedDone; // Bytes transferred so far - volatile bool bStagedUrbPending; // Flag to indicate active - char* pCoherStagedIO; // buffer used for block transfers - struct urb* pStagedUrb; // The URB to use - spinlock_t stagedLock; // protects ReadWriteMem() and circular buffer stuff - - short s1401Type; // type of 1401 attached - short sCurrentState; // current error state - bool bIsUSB2; // type of the interface we connect to - bool bForceReset; // Flag to make sure we get a real reset - __u32 statBuf[2]; // buffer for 1401 state info - - unsigned long ulSelfTestTime; // used to timeout self test - - int nPipes; // Should be 3 or 4 depending on 1401 usb chip - int bPipeError[4]; // set non-zero if an error on one of the pipe - __u8 epAddr[4]; // addresses of the 3/4 end points - - struct usb_device *udev; // the usb device for this device - struct usb_interface *interface; // the interface for this device, NULL if removed - struct usb_anchor submitted; // in case we need to retract our submissions - struct mutex io_mutex; // synchronize I/O with disconnect, one user-mode caller at a time - - int errors; // the last request tanked - int open_count; // count the number of openers - spinlock_t err_lock; // lock for errors - struct kref kref; -}DEVICE_EXTENSION, *PDEVICE_EXTENSION; +#define STAGED_SZ 0x10000 /* size of coherent buffer for staged transfers */ + +/* Structure to hold all of our device specific stuff. We are making this as similar as we */ +/* can to the Windows driver to help in our understanding of what is going on. */ +typedef struct _DEVICE_EXTENSION { + char inputBuffer[INBUF_SZ]; /* The two buffers */ + char outputBuffer[OUTBUF_SZ]; /* accessed by the host functions */ + volatile unsigned int dwNumInput; /* num of chars in input buffer */ + volatile unsigned int dwInBuffGet; /* where to get from input buffer */ + volatile unsigned int dwInBuffPut; /* where to put into input buffer */ + volatile unsigned int dwNumOutput; /* num of chars in output buffer */ + volatile unsigned int dwOutBuffGet; /* where to get from output buffer*/ + volatile unsigned int dwOutBuffPut; /* where to put into output buffer*/ + + volatile bool bSendCharsPending; /* Flag to indicate sendchar active */ + volatile bool bReadCharsPending; /* Flag to indicate a read is primed */ + char *pCoherCharOut; /* special aligned buffer for chars to 1401 */ + struct urb *pUrbCharOut; /* urb used for chars to 1401 */ + char *pCoherCharIn; /* special aligned buffer for chars to host */ + struct urb *pUrbCharIn; /* urb used for chars to host */ + + spinlock_t charOutLock; /* to protect the outputBuffer and outputting */ + spinlock_t charInLock; /* to protect the inputBuffer and char reads */ + __u8 bInterval; /* Interrupt end point interval */ + + volatile unsigned int dwDMAFlag; /* state of DMA */ + TRANSAREA rTransDef[MAX_TRANSAREAS];/* transfer area info */ + volatile DMADESC rDMAInfo; /* info on current DMA transfer */ + volatile bool bXFerWaiting; /* Flag set if DMA transfer stalled */ + volatile bool bInDrawDown; /* Flag that we want to halt transfers */ + + /* Parameters relating to a block read\write that is in progress. Some of these values */ + /* are equivalent to values in rDMAInfo. The values here are those in use, while those */ + /* in rDMAInfo are those received from the 1401 via an escape sequence. If another */ + /* escape sequence arrives before the previous xfer ends, rDMAInfo values are updated while these */ + /* are used to finish off the current transfer. */ + volatile short StagedId; /* The transfer area id for this transfer */ + volatile bool StagedRead; /* Flag TRUE for read from 1401, FALSE for write */ + volatile unsigned int StagedLength; /* Total length of this transfer */ + volatile unsigned int StagedOffset; /* Offset within memory area for transfer start */ + volatile unsigned int StagedDone; /* Bytes transferred so far */ + volatile bool bStagedUrbPending; /* Flag to indicate active */ + char *pCoherStagedIO; /* buffer used for block transfers */ + struct urb *pStagedUrb; /* The URB to use */ + spinlock_t stagedLock; /* protects ReadWriteMem() and circular buffer stuff */ + + short s1401Type; /* type of 1401 attached */ + short sCurrentState; /* current error state */ + bool bIsUSB2; /* type of the interface we connect to */ + bool bForceReset; /* Flag to make sure we get a real reset */ + __u32 statBuf[2]; /* buffer for 1401 state info */ + + unsigned long ulSelfTestTime; /* used to timeout self test */ + + int nPipes; /* Should be 3 or 4 depending on 1401 usb chip */ + int bPipeError[4]; /* set non-zero if an error on one of the pipe */ + __u8 epAddr[4]; /* addresses of the 3/4 end points */ + + struct usb_device *udev; /* the usb device for this device */ + struct usb_interface *interface; /* the interface for this device, NULL if removed */ + struct usb_anchor submitted; /* in case we need to retract our submissions */ + struct mutex io_mutex; /* synchronize I/O with disconnect, one user-mode caller at a time */ + + int errors; /* the last request tanked */ + int open_count; /* count the number of openers */ + spinlock_t err_lock; /* lock for errors */ + struct kref kref; +} DEVICE_EXTENSION, *PDEVICE_EXTENSION; #define to_DEVICE_EXTENSION(d) container_of(d, DEVICE_EXTENSION, kref) -/// Definitions of routimes used between compilation object files -// in usb1401.c -extern int Allowi(DEVICE_EXTENSION* pdx); -extern int SendChars(DEVICE_EXTENSION* pdx); +/* Definitions of routimes used between compilation object files */ +/* in usb1401.c */ +extern int Allowi(DEVICE_EXTENSION *pdx); +extern int SendChars(DEVICE_EXTENSION *pdx); extern void ced_draw_down(DEVICE_EXTENSION *pdx); extern int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, - unsigned int dwOffs, unsigned int dwLen); + unsigned int dwOffs, unsigned int dwLen); -// in ced_ioc.c +/* in ced_ioc.c */ extern int ClearArea(DEVICE_EXTENSION *pdx, int nArea); -extern int SendString(DEVICE_EXTENSION* pdx, const char __user* pData, unsigned int n); +extern int SendString(DEVICE_EXTENSION *pdx, const char __user *pData, unsigned int n); extern int SendChar(DEVICE_EXTENSION *pdx, char c); -extern int Get1401State(DEVICE_EXTENSION* pdx, __u32* state, __u32* error); +extern int Get1401State(DEVICE_EXTENSION *pdx, __u32 *state, __u32 *error); extern int ReadWrite_Cancel(DEVICE_EXTENSION *pdx); -extern bool Is1401(DEVICE_EXTENSION* pdx); -extern bool QuickCheck(DEVICE_EXTENSION* pdx, bool bTestBuff, bool bCanReset); +extern bool Is1401(DEVICE_EXTENSION *pdx); +extern bool QuickCheck(DEVICE_EXTENSION *pdx, bool bTestBuff, bool bCanReset); extern int Reset1401(DEVICE_EXTENSION *pdx); extern int GetChar(DEVICE_EXTENSION *pdx); -extern int GetString(DEVICE_EXTENSION *pdx, char __user* pUser, int n); +extern int GetString(DEVICE_EXTENSION *pdx, char __user *pUser, int n); extern int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD); extern int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea); -extern int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user*pTE); +extern int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user *pTE); extern int Stat1401(DEVICE_EXTENSION *pdx); extern int LineCount(DEVICE_EXTENSION *pdx); extern int GetOutBufSpace(DEVICE_EXTENSION *pdx); @@ -235,15 +232,15 @@ extern int StartSelfTest(DEVICE_EXTENSION *pdx); extern int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST); extern int TypeOf1401(DEVICE_EXTENSION *pdx); extern int TransferFlags(DEVICE_EXTENSION *pdx); -extern int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user* pDB); +extern int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgPoke(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgRampData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB); extern int DbgStopLoop(DEVICE_EXTENSION *pdx); extern int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD); -extern int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB); -extern int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user* pCB); +extern int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB); +extern int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB); extern int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut); extern int TestEvent(DEVICE_EXTENSION *pdx, int nArea); #endif diff --git a/drivers/staging/ced1401/use1401.h b/drivers/staging/ced1401/use1401.h index 86294e2..b7997c9 100644 --- a/drivers/staging/ced1401/use1401.h +++ b/drivers/staging/ced1401/use1401.h @@ -11,16 +11,16 @@ #define __USE1401_H__ #include "machine.h" -// Some definitions to make things compatible. If you want to use Use1401 directly -// from a Windows program you should define U14_NOT_DLL, in which case you also -// MUST make sure that your application startup code calls U14InitLib(). -// DLL_USE1401 is defined when you are building the Use1401 dll, not otherwise. +/* Some definitions to make things compatible. If you want to use Use1401 directly */ +/* from a Windows program you should define U14_NOT_DLL, in which case you also */ +/* MUST make sure that your application startup code calls U14InitLib(). */ +/* DLL_USE1401 is defined when you are building the Use1401 dll, not otherwise. */ #ifdef _IS_WINDOWS_ #ifndef U14_NOT_DLL #ifdef DLL_USE1401 -#define U14API(retType) retType DllExport __stdcall +#define U14API(retType) (retType DllExport __stdcall) #else -#define U14API(retType) retType DllImport __stdcall +#define U14API(retType) (retType DllImport __stdcall) #endif #endif @@ -36,7 +36,7 @@ #ifdef _QT #ifndef U14_NOT_DLL #undef U14API -#define U14API(retType) retType __declspec(dllimport) __stdcall +#define U14API(retType) (retType __declspec(dllimport) __stdcall) #endif #undef U14LONG #define U14LONG int @@ -50,20 +50,20 @@ #define U14LONG long #endif -/// Error codes: We need them here as user space can see them. -#define U14ERR_NOERROR 0 // no problems +/* Error codes: We need them here as user space can see them. */ +#define U14ERR_NOERROR 0 /* no problems */ -/// Device error codes, but these don't need to be extended - a succession is assumed -#define U14ERR_STD 4 // standard 1401 connected -#define U14ERR_U1401 5 // u1401 connected -#define U14ERR_PLUS 6 // 1401 plus connected -#define U14ERR_POWER 7 // Power1401 connected -#define U14ERR_U14012 8 // u1401 mkII connected +/* Device error codes, but these don't need to be extended - a succession is assumed */ +#define U14ERR_STD 4 /* standard 1401 connected */ +#define U14ERR_U1401 5 /* u1401 connected */ +#define U14ERR_PLUS 6 /* 1401 plus connected */ +#define U14ERR_POWER 7 /* Power1401 connected */ +#define U14ERR_U14012 8 /* u1401 mkII connected */ #define U14ERR_POWER2 9 #define U14ERR_U14013 10 #define U14ERR_POWER3 11 -/// NBNB Error numbers need shifting as some linux error codes start at 512 +/* NBNB Error numbers need shifting as some linux error codes start at 512 */ #define U14ERR(n) (n+U14ERRBASE) #define U14ERR_OFF U14ERR(0) /* 1401 there but switched off */ #define U14ERR_NC U14ERR(-1) /* 1401 not connected */ @@ -113,7 +113,7 @@ #define U14ERR_DRIVCOMMS U14ERR(-110) /* failed talking to driver */ #define U14ERR_OUTOFMEMORY U14ERR(-111) /* needed memory and couldnt get it*/ -/// 1401 type codes. +/* / 1401 type codes. */ #define U14TYPE1401 0 /* standard 1401 */ #define U14TYPEPLUS 1 /* 1401 plus */ #define U14TYPEU1401 2 /* u1401 */ @@ -124,9 +124,9 @@ #define U14TYPEPOWER3 7 /* power1401-3 */ #define U14TYPEUNKNOWN -1 /* dont know */ -/// Transfer flags to allow driver capabilities to be interrogated +/* Transfer flags to allow driver capabilities to be interrogated */ -/// Constants for transfer flags +/* Constants for transfer flags */ #define U14TF_USEDMA 1 /* Transfer flag for use DMA */ #define U14TF_MULTIA 2 /* Transfer flag for multi areas */ #define U14TF_FIFO 4 /* for FIFO interface card */ @@ -138,18 +138,18 @@ #define U14TF_DIAG 256 /* Diagnostics/debug functions */ #define U14TF_CIRC14 512 /* Circular-mode to 1401 */ -/// Definitions of element sizes for DMA transfers - to allow byte-swapping +/* Definitions of element sizes for DMA transfers - to allow byte-swapping */ #define ESZBYTES 0 /* BYTE element size value */ -#define ESZWORDS 1 /* WORD element size value */ +#define ESZWORDS 1 /* unsigned short element size value */ #define ESZLONGS 2 /* long element size value */ #define ESZUNKNOWN 0 /* unknown element size value */ -/// These define required access types for the debug/diagnostics function +/* These define required access types for the debug/diagnostics function */ #define BYTE_SIZE 1 /* 8-bit access */ #define WORD_SIZE 2 /* 16-bit access */ #define LONG_SIZE 3 /* 32-bit access */ -/// Stuff used by U14_GetTransfer +/* Stuff used by U14_GetTransfer */ #define GET_TX_MAXENTRIES 257 /* (max length / page size + 1) */ #ifdef _IS_WINDOWS_ @@ -157,19 +157,19 @@ typedef struct /* used for U14_GetTransfer results */ { /* Info on a single mapped block */ - U14LONG physical; - U14LONG size; + U14LONG physical; + U14LONG size; } TXENTRY; typedef struct TGetTxBlock /* used for U14_GetTransfer results */ { /* matches structure in VXD */ - U14LONG size; - U14LONG linear; - short seg; - short reserved; - short avail; /* number of available entries */ - short used; /* number of used entries */ - TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ + U14LONG size; + U14LONG linear; + short seg; + short reserved; + short avail; /* number of available entries */ + short used; /* number of used entries */ + TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ } TGET_TX_BLOCK; typedef TGET_TX_BLOCK *LPGET_TX_BLOCK; @@ -180,19 +180,19 @@ typedef TGET_TX_BLOCK *LPGET_TX_BLOCK; #ifdef LINUX typedef struct /* used for U14_GetTransfer results */ { /* Info on a single mapped block */ - long long physical; - long size; + long long physical; + long size; } TXENTRY; typedef struct TGetTxBlock /* used for U14_GetTransfer results */ { /* matches structure in VXD */ - long long linear; /* linear address */ - long size; /* total size of the mapped area, holds id when called */ - short seg; /* segment of the address for Win16 */ - short reserved; - short avail; /* number of available entries */ - short used; /* number of used entries */ - TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ + long long linear; /* linear address */ + long size; /* total size of the mapped area, holds id when called */ + short seg; /* segment of the address for Win16 */ + short reserved; + short avail; /* number of available entries */ + short used; /* number of used entries */ + TXENTRY entries[GET_TX_MAXENTRIES]; /* Array of mapped block info */ } TGET_TX_BLOCK; #endif @@ -200,84 +200,84 @@ typedef struct TGetTxBlock /* used for U14_GetTransfer results */ extern "C" { #endif -U14API(int) U14WhenToTimeOut(short hand); // when to timeout in ms -U14API(short) U14PassedTime(int iTime); // non-zero if iTime passed +U14API(int) U14WhenToTimeOut(short hand); /* when to timeout in ms */ +U14API(short) U14PassedTime(int iTime); /* non-zero if iTime passed */ -U14API(short) U14LastErrCode(short hand); +U14API(short) U14LastErrCode(short hand); -U14API(short) U14Open1401(short n1401); -U14API(short) U14Close1401(short hand); -U14API(short) U14Reset1401(short hand); -U14API(short) U14ForceReset(short hand); -U14API(short) U14TypeOf1401(short hand); -U14API(short) U14NameOf1401(short hand, char* pBuf, WORD wMax); +U14API(short) U14Open1401(short n1401); +U14API(short) U14Close1401(short hand); +U14API(short) U14Reset1401(short hand); +U14API(short) U14ForceReset(short hand); +U14API(short) U14TypeOf1401(short hand); +U14API(short) U14NameOf1401(short hand, char *pBuf, unsigned short wMax); -U14API(short) U14Stat1401(short hand); -U14API(short) U14CharCount(short hand); -U14API(short) U14LineCount(short hand); +U14API(short) U14Stat1401(short hand); +U14API(short) U14CharCount(short hand); +U14API(short) U14LineCount(short hand); -U14API(short) U14SendString(short hand, const char* pString); -U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen); -U14API(short) U14SendChar(short hand, char cChar); -U14API(short) U14GetChar(short hand, char* pcChar); +U14API(short) U14SendString(short hand, const char *pString); +U14API(short) U14GetString(short hand, char *pBuffer, unsigned short wMaxLen); +U14API(short) U14SendChar(short hand, char cChar); +U14API(short) U14GetChar(short hand, char *pcChar); -U14API(short) U14LdCmd(short hand, const char* command); -U14API(DWORD) U14Ld(short hand, const char* vl, const char* str); +U14API(short) U14LdCmd(short hand, const char *command); +U14API(unsigned int) U14Ld(short hand, const char *vl, const char *str); -U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, - DWORD dwLength, short eSz); -U14API(short) U14UnSetTransfer(short hand, WORD wArea); -U14API(short) U14SetTransferEvent(short hand, WORD wArea, BOOL bEvent, - BOOL bToHost, DWORD dwStart, DWORD dwLength); -U14API(int) U14TestTransferEvent(short hand, WORD wArea); -U14API(int) U14WaitTransferEvent(short hand, WORD wArea, int msTimeOut); -U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock); +U14API(short) U14SetTransArea(short hand, unsigned short wArea, void *pvBuff, + unsigned int dwLength, short eSz); +U14API(short) U14UnSetTransfer(short hand, unsigned short wArea); +U14API(short) U14SetTransferEvent(short hand, unsigned short wArea, BOOL bEvent, + BOOL bToHost, unsigned int dwStart, unsigned int dwLength); +U14API(int) U14TestTransferEvent(short hand, unsigned short wArea); +U14API(int) U14WaitTransferEvent(short hand, unsigned short wArea, int msTimeOut); +U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock); -U14API(short) U14ToHost(short hand, char* pAddrHost,DWORD dwSize,DWORD dw1401, - short eSz); -U14API(short) U14To1401(short hand, const char* pAddrHost,DWORD dwSize,DWORD dw1401, - short eSz); +U14API(short) U14ToHost(short hand, char *pAddrHost, unsigned int dwSize, unsigned int dw1401, + short eSz); +U14API(short) U14To1401(short hand, const char *pAddrHost, unsigned int dwSize, unsigned int dw1401, + short eSz); -U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, void *pvBuff, - DWORD dwLength); +U14API(short) U14SetCircular(short hand, unsigned short wArea, BOOL bToHost, void *pvBuff, + unsigned int dwLength); -U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs); -U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, - DWORD *pdwOffs); +U14API(int) U14GetCircBlk(short hand, unsigned short wArea, unsigned int *pdwOffs); +U14API(int) U14FreeCircBlk(short hand, unsigned short wArea, unsigned int dwOffs, unsigned int dwSize, + unsigned int *pdwOffs); -U14API(short) U14StrToLongs(const char* pszBuff, U14LONG *palNums, short sMaxLongs); -U14API(short) U14LongsFrom1401(short hand, U14LONG *palBuff, short sMaxLongs); +U14API(short) U14StrToLongs(const char *pszBuff, U14LONG *palNums, short sMaxLongs); +U14API(short) U14LongsFrom1401(short hand, U14LONG *palBuff, short sMaxLongs); U14API(void) U14SetTimeout(short hand, int lTimeout); U14API(int) U14GetTimeout(short hand); -U14API(short) U14OutBufSpace(short hand); +U14API(short) U14OutBufSpace(short hand); U14API(int) U14BaseAddr1401(short hand); U14API(int) U14DriverVersion(short hand); U14API(int) U14DriverType(short hand); -U14API(short) U14DriverName(short hand, char* pBuf, WORD wMax); -U14API(short) U14GetUserMemorySize(short hand, DWORD *pMemorySize); -U14API(short) U14KillIO1401(short hand); - -U14API(short) U14BlkTransState(short hand); -U14API(short) U14StateOf1401(short hand); - -U14API(short) U14Grab1401(short hand); -U14API(short) U14Free1401(short hand); -U14API(short) U14Peek1401(short hand, DWORD dwAddr, int nSize, int nRepeats); -U14API(short) U14Poke1401(short hand, DWORD dwAddr, DWORD dwValue, int nSize, int nRepeats); -U14API(short) U14Ramp1401(short hand, DWORD dwAddr, DWORD dwDef, DWORD dwEnable, int nSize, int nRepeats); -U14API(short) U14RampAddr(short hand, DWORD dwDef, DWORD dwEnable, int nSize, int nRepeats); -U14API(short) U14StopDebugLoop(short hand); -U14API(short) U14GetDebugData(short hand, U14LONG *plValue); - -U14API(short) U14StartSelfTest(short hand); -U14API(short) U14CheckSelfTest(short hand, U14LONG *pData); -U14API(short) U14TransferFlags(short hand); -U14API(void) U14GetErrorString(short nErr, char* pStr, WORD wMax); +U14API(short) U14DriverName(short hand, char *pBuf, unsigned short wMax); +U14API(short) U14GetUserMemorySize(short hand, unsigned int *pMemorySize); +U14API(short) U14KillIO1401(short hand); + +U14API(short) U14BlkTransState(short hand); +U14API(short) U14StateOf1401(short hand); + +U14API(short) U14Grab1401(short hand); +U14API(short) U14Free1401(short hand); +U14API(short) U14Peek1401(short hand, unsigned int dwAddr, int nSize, int nRepeats); +U14API(short) U14Poke1401(short hand, unsigned int dwAddr, unsigned int dwValue, int nSize, int nRepeats); +U14API(short) U14Ramp1401(short hand, unsigned int dwAddr, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats); +U14API(short) U14RampAddr(short hand, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats); +U14API(short) U14StopDebugLoop(short hand); +U14API(short) U14GetDebugData(short hand, U14LONG *plValue); + +U14API(short) U14StartSelfTest(short hand); +U14API(short) U14CheckSelfTest(short hand, U14LONG *pData); +U14API(short) U14TransferFlags(short hand); +U14API(void) U14GetErrorString(short nErr, char *pStr, unsigned short wMax); U14API(int) U14MonitorRev(short hand); U14API(void) U14CloseAll(void); -U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb); +U14API(short) U14WorkingSet(unsigned int dwMinKb, unsigned int dwMaxKb); U14API(int) U14InitLib(void); #ifdef __cplusplus @@ -285,3 +285,4 @@ U14API(int) U14InitLib(void); #endif #endif /* End of ifndef __USE1401_H__ */ + diff --git a/drivers/staging/ced1401/use14_ioc.h b/drivers/staging/ced1401/use14_ioc.h index 15ca638..97d7913 100644 --- a/drivers/staging/ced1401/use14_ioc.h +++ b/drivers/staging/ced1401/use14_ioc.h @@ -19,283 +19,282 @@ ** The IOCTL function codes from 0x80 to 0xFF are for developer use. */ #define FILE_DEVICE_CED1401 0x8001 -#define FNNUMBASE 0x800 - -#define U14_OPEN1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_CLOSE1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+1, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_SENDSTRING CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+2, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_RESET1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+3, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETCHAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+4, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_SENDCHAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+5, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_STAT1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+6, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_LINECOUNT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+7, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETSTRING CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+8, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_REGCALLBACK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+9, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETMONITORBUF CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+10, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_SETTRANSFER CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+11, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_UNSETTRANSFER CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+12, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_SETTRANSEVENT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+13, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETOUTBUFSPACE CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+14, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETBASEADDRESS CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+15, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETDRIVERREVISION CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+16, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETTRANSFER CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+17, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_KILLIO1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+18, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_BLKTRANSSTATE CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+19, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_BYTECOUNT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+20, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_ZEROBLOCKCOUNT CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+21, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_STOPCIRCULAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+22, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_STATEOF1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+23, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_REGISTERS1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+24, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GRAB1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+25, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_FREE1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+26, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_STEP1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+27, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_SET1401REGISTERS CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+28, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_STEPTILL1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+29, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_SETORIN CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+30, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_STARTSELFTEST CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+31, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_CHECKSELFTEST CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+32, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_TYPEOF1401 CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+33, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_TRANSFERFLAGS CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+34, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_DBGPEEK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+35, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_DBGPOKE CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+36, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_DBGRAMPDATA CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+37, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_DBGRAMPADDR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+38, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_DBGGETDATA CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+39, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_DBGSTOPLOOP CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+40, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_FULLRESET CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+41, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_SETCIRCULAR CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+42, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_GETCIRCBLK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+43, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -#define U14_FREECIRCBLK CTL_CODE( FILE_DEVICE_CED1401, \ - FNNUMBASE+44, \ - METHOD_BUFFERED, \ - FILE_ANY_ACCESS) - -//--------------- Structures that are shared with the driver ------------- + FNNUMBASE 0x800 + +#define U14_OPEN1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_CLOSE1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+1, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_SENDSTRING CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+2, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_RESET1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+3, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETCHAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+4, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_SENDCHAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+5, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_STAT1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+6, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_LINECOUNT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+7, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETSTRING CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+8, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_REGCALLBACK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+9, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETMONITORBUF CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+10, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_SETTRANSFER CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+11, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_UNSETTRANSFER CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+12, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_SETTRANSEVENT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+13, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETOUTBUFSPACE CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+14, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETBASEADDRESS CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+15, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETDRIVERREVISION CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+16, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETTRANSFER CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+17, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_KILLIO1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+18, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_BLKTRANSSTATE CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+19, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_BYTECOUNT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+20, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_ZEROBLOCKCOUNT CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+21, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_STOPCIRCULAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+22, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_STATEOF1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+23, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_REGISTERS1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+24, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GRAB1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+25, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_FREE1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+26, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_STEP1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+27, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_SET1401REGISTERS CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+28, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_STEPTILL1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+29, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_SETORIN CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+30, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_STARTSELFTEST CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+31, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_CHECKSELFTEST CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+32, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_TYPEOF1401 CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+33, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_TRANSFERFLAGS CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+34, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_DBGPEEK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+35, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_DBGPOKE CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+36, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_DBGRAMPDATA CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+37, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_DBGRAMPADDR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+38, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_DBGGETDATA CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+39, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_DBGSTOPLOOP CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+40, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_FULLRESET CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+41, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_SETCIRCULAR CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+42, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_GETCIRCBLK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+43, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define U14_FREECIRCBLK CTL_CODE(FILE_DEVICE_CED1401, \ + FNNUMBASE+44, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +/*--------------- Structures that are shared with the driver ------------- */ #pragma pack(1) typedef struct /* used for get/set standard 1401 registers */ { - short sPC; - char A; - char X; - char Y; - char stat; - char rubbish; + short sPC; + char A; + char X; + char Y; + char stat; + char rubbish; } T1401REGISTERS; typedef union /* to communicate with 1401 driver status & control funcs */ { - char chrs[22]; - short ints[11]; - long longs[5]; - T1401REGISTERS registers; + char chrs[22]; + short ints[11]; + long longs[5]; + T1401REGISTERS registers; } TCSBLOCK; typedef TCSBLOCK* LPTCSBLOCK; -typedef struct paramBlk -{ - short sState; - TCSBLOCK csBlock; +typedef struct paramBlk { + short sState; + TCSBLOCK csBlock; } PARAMBLK; typedef PARAMBLK* PPARAMBLK; typedef struct TransferDesc /* Structure and type for SetTransArea */ { - WORD wArea; /* number of transfer area to set up */ - void FAR * lpvBuff; /* address of transfer area */ - DWORD dwLength; /* length of area to set up */ - short eSize; /* size to move (for swapping on MAC) */ + unsigned short wArea; /* number of transfer area to set up */ + void FAR *lpvBuff; /* address of transfer area */ + unsigned int dwLength; /* length of area to set up */ + short eSize; /* size to move (for swapping on MAC) */ } TRANSFERDESC; -typedef TRANSFERDESC FAR * LPTRANSFERDESC; +typedef TRANSFERDESC FAR *LPTRANSFERDESC; /* This is the structure used to set up a transfer area */ typedef struct VXTransferDesc /* use1401.c and use1432x.x use only */ { - WORD wArea; /* number of transfer area to set up */ - WORD wAddrSel; /* 16 bit selector for area */ - DWORD dwAddrOfs; /* 32 bit offset for area start */ - DWORD dwLength; /* length of area to set up */ + unsigned short wArea; /* number of transfer area to set up */ + unsigned short wAddrSel; /* 16 bit selector for area */ + unsigned int dwAddrOfs; /* 32 bit offset for area start */ + unsigned int dwLength; /* length of area to set up */ } VXTRANSFERDESC; #pragma pack() -#endif
\ No newline at end of file +#endif diff --git a/drivers/staging/ced1401/userspace/use1401.c b/drivers/staging/ced1401/userspace/use1401.c index 38e7c1c..c9bc2eb 100644 --- a/drivers/staging/ced1401/userspace/use1401.c +++ b/drivers/staging/ced1401/userspace/use1401.c @@ -36,7 +36,7 @@ ** Under Windows 9x and NT, Use1401 uses DeviceIoControl to get access to ** the 1401 driver. This has parameters for the device handle, the function ** code, an input pointer and byte count, an output pointer and byte count -** and a pointer to a DWORD to hold the output byte count. Note that input +** and a pointer to a unsigned int to hold the output byte count. Note that input ** and output are from the point-of-view of the driver, so the output stuff ** is used to read values from the 1401, not send to the 1401. The use of ** these parameters varies with the function in use and the operating @@ -250,7 +250,7 @@ static int iAttached = 0; // counts process attaches so ca static HANDLE aHand1401[MAX1401] = {0}; // handles for 1401s static HANDLE aXferEvent[MAX1401] = {0}; // transfer events for the 1401s static LPVOID apAreas[MAX1401][MAX_TRANSAREAS]; // Locked areas -static DWORD auAreas[MAX1401][MAX_TRANSAREAS]; // Size of locked areas +static unsigned int auAreas[MAX1401][MAX_TRANSAREAS]; // Size of locked areas static BOOL bWindows9x = FALSE; // if we are Windows 95 or better #ifdef _WIN64 #define USE_NT_DIOC(ind) TRUE @@ -276,8 +276,8 @@ static int aHand1401[MAX1401] = {0}; // handles for 1401s typedef struct CmdHead // defines header block on command { // for PC commands char acBasic[5]; // BASIC information - needed to align things - WORD wBasicSz; // size as seen by BASIC - WORD wCmdSize; // size of the following info + unsigned short wBasicSz; // size as seen by BASIC + unsigned short wCmdSize; // size of the following info } __packed CMDHEAD; #pragma pack() // back to normal @@ -311,7 +311,7 @@ static short CheckHandle(short h) ****************************************************************************/ static short U14Status1401(short sHand, LONG lCode, TCSBLOCK* pBlk) { - DWORD dwBytes = 0; + unsigned int dwBytes = 0; if ((sHand < 0) || (sHand >= MAX1401)) /* Check parameters */ return U14ERR_BADHAND; @@ -345,7 +345,7 @@ static short U14Status1401(short sHand, LONG lCode, TCSBLOCK* pBlk) ****************************************************************************/ static short U14Control1401(short sHand, LONG lCode, TCSBLOCK* pBlk) { - DWORD dwBytes = 0; + unsigned int dwBytes = 0; if ((sHand < 0) || (sHand >= MAX1401)) /* Check parameters */ return U14ERR_BADHAND; @@ -455,7 +455,7 @@ static void TranslateString(char* pStr) ****************************************************************************/ U14API(short) U14StrToLongs(const char* pszBuff, U14LONG *palNums, short sMaxLongs) { - WORD wChInd = 0; // index into source + unsigned short wChInd = 0; // index into source short sLgInd = 0; // index into result longs while (pszBuff[wChInd] && // until we get to end of string... @@ -681,7 +681,7 @@ U14API(int) U14DriverType(short hand) ** U14DriverName ** Returns the driver type as 3 character (ISA, PCI, USB or HSS)) ****************************************************************************/ -U14API(short) U14DriverName(short hand, char* pBuf, WORD wMax) +U14API(short) U14DriverName(short hand, char* pBuf, unsigned short wMax) { char* pName; *pBuf = 0; // Start off with a blank string @@ -779,7 +779,7 @@ U14API(short) U14Free1401(short hand) ** is called. After the peek is done, use U14GetDebugData to retrieve ** the results of the peek. ****************************************************************************/ -U14API(short) U14Peek1401(short hand, DWORD dwAddr, int nSize, int nRepeats) +U14API(short) U14Peek1401(short hand, unsigned int dwAddr, int nSize, int nRepeats) { short sErr = CheckHandle(hand); if (sErr == U14ERR_NOERROR) @@ -813,7 +813,7 @@ U14API(short) U14Peek1401(short hand, DWORD dwAddr, int nSize, int nRepeats) ** If lRepeats is zero, the loop will continue until U14StopDebugLoop ** is called. ****************************************************************************/ -U14API(short) U14Poke1401(short hand, DWORD dwAddr, DWORD dwValue, +U14API(short) U14Poke1401(short hand, unsigned int dwAddr, unsigned int dwValue, int nSize, int nRepeats) { short sErr = CheckHandle(hand); @@ -849,7 +849,7 @@ U14API(short) U14Poke1401(short hand, DWORD dwAddr, DWORD dwValue, ** DESCRIPTION Cause the 1401 to loop, writing a ramp to a location. ** If lRepeats is zero, the loop will continue until U14StopDebugLoop. ****************************************************************************/ -U14API(short) U14Ramp1401(short hand, DWORD dwAddr, DWORD dwDef, DWORD dwEnable, +U14API(short) U14Ramp1401(short hand, unsigned int dwAddr, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats) { short sErr = CheckHandle(hand); @@ -887,7 +887,7 @@ U14API(short) U14Ramp1401(short hand, DWORD dwAddr, DWORD dwDef, DWORD dwEnable, ** DESCRIPTION Cause the 1401 to loop, reading from a ramping location. ** If lRepeats is zero, the loop will continue until U14StopDebugLoop ****************************************************************************/ -U14API(short) U14RampAddr(short hand, DWORD dwDef, DWORD dwEnable, +U14API(short) U14RampAddr(short hand, unsigned int dwDef, unsigned int dwEnable, int nSize, int nRepeats) { short sErr = CheckHandle(hand); @@ -1024,7 +1024,7 @@ U14API(short) U14CheckSelfTest(short hand, U14LONG *pData) /**************************************************************************** ** U14GetUserMemorySize ****************************************************************************/ -U14API(short) U14GetUserMemorySize(short hand, DWORD *pMemorySize) +U14API(short) U14GetUserMemorySize(short hand, unsigned int *pMemorySize) { // The original 1401 used a different command for getting the size short sErr = U14SendString(hand, (asType1401[hand] == U14TYPE1401) ? "MEMTOP;" : "MEMTOP,?;"); @@ -1061,7 +1061,7 @@ U14API(short) U14TypeOf1401(short hand) ** U14NameOf1401 ** Returns the type of the 1401 as a string, blank if unknown ****************************************************************************/ -U14API(short) U14NameOf1401(short hand, char* pBuf, WORD wMax) +U14API(short) U14NameOf1401(short hand, char* pBuf, unsigned short wMax) { short sErr = CheckHandle(hand); if (sErr == U14ERR_NOERROR) @@ -1207,7 +1207,7 @@ static short U14TryToOpen(int n1401, long* plRetVal, short* psHandle) { short sErr = U14ERR_NOERROR; HANDLE hDevice = INVALID_HANDLE_VALUE; - DWORD dwErr = 0; + unsigned int dwErr = 0; int nFirst, nLast, nDev = 0; /* Used for the search for a 1401 */ BOOL bOldName = FALSE; /* start by looking for a modern driver */ @@ -1262,7 +1262,7 @@ static short U14TryToOpen(int n1401, long* plRetVal, short* psHandle) } else { - DWORD dwe = GetLastError(); /* Get error code otherwise */ + unsigned int dwe = GetLastError(); /* Get error code otherwise */ if ((dwe != ERROR_FILE_NOT_FOUND) || (dwErr == 0)) dwErr = dwe; /* Ignore repeats of 'not found' */ } @@ -1454,7 +1454,7 @@ U14API(short) U14Close1401(short hand) U14Reset1401(hand); // in case an active transfer running for (j = 0; j < MAX_TRANSAREAS; ++j) // Locate locked areas if (iAreaMask & (1 << j)) // And kill off any transfers - U14UnSetTransfer(hand, (WORD)j); + U14UnSetTransfer(hand, (unsigned short)j); } #ifdef _IS_WINDOWS_ @@ -1581,7 +1581,7 @@ U14API(short) U14SendString(short hand, const char* pString) if (bSpaceToSend) { PARAMBLK rData; - DWORD dwBytes; + unsigned int dwBytes; char tstr[MAXSTRLEN+5]; /* Buffer for chars */ if ((hand < 0) || (hand >= MAX1401)) @@ -1592,18 +1592,18 @@ U14API(short) U14SendString(short hand, const char* pString) #ifndef _WIN64 if (!USE_NT_DIOC(hand)) /* Using WIN 95 driver access? */ { - int iOK = DeviceIoControl(aHand1401[hand], (DWORD)U14_SENDSTRING, + int iOK = DeviceIoControl(aHand1401[hand], (unsigned int)U14_SENDSTRING, NULL, 0, tstr, nChars, &dwBytes, NULL); if (iOK) - sErr = (dwBytes >= (DWORD)nChars) ? U14ERR_NOERROR : U14ERR_DRIVCOMMS; + sErr = (dwBytes >= (unsigned int)nChars) ? U14ERR_NOERROR : U14ERR_DRIVCOMMS; else sErr = (short)GetLastError(); } else #endif { - int iOK = DeviceIoControl(aHand1401[hand],(DWORD)U14_SENDSTRING, + int iOK = DeviceIoControl(aHand1401[hand],(unsigned int)U14_SENDSTRING, tstr, nChars, &rData,sizeof(PARAMBLK),&dwBytes,NULL); if (iOK && (dwBytes >= sizeof(PARAMBLK))) @@ -1697,7 +1697,7 @@ U14API(short) U14SendChar(short hand, char cChar) ** error code. Any error from the device causes us to set up for ** a full reset. ****************************************************************************/ -U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) +U14API(short) U14GetString(short hand, char* pBuffer, unsigned short wMaxLen) { short sErr = CheckHandle(hand); if (sErr != U14ERR_NOERROR) // If an error... @@ -1726,8 +1726,8 @@ U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) { if (asLastRetCode[hand] == U14ERR_NOERROR) /* all ok so far */ { - DWORD dwBytes = 0; - *((WORD *)pBuffer) = wMaxLen; /* set up length */ + unsigned int dwBytes = 0; + *((unsigned short *)pBuffer) = wMaxLen; /* set up length */ #ifndef _WIN64 if (!USE_NT_DIOC(hand)) /* Win 95 DIOC here ? */ { @@ -1737,9 +1737,9 @@ U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) if (wMaxLen > MAXSTRLEN) /* Truncate length */ wMaxLen = MAXSTRLEN; - *((WORD *)tstr) = wMaxLen; /* set len */ + *((unsigned short *)tstr) = wMaxLen; /* set len */ - iOK = DeviceIoControl(aHand1401[hand],(DWORD)U14_GETSTRING, + iOK = DeviceIoControl(aHand1401[hand],(unsigned int)U14_GETSTRING, NULL, 0, tstr, wMaxLen+sizeof(short), &dwBytes, NULL); if (iOK) /* Device IO control OK ? */ @@ -1768,7 +1768,7 @@ U14API(short) U14GetString(short hand, char* pBuffer, WORD wMaxLen) char* pMem = (char*)GlobalLock(hMem); if (pMem) { - int iOK = DeviceIoControl(aHand1401[hand],(DWORD)U14_GETSTRING, + int iOK = DeviceIoControl(aHand1401[hand],(unsigned int)U14_GETSTRING, NULL, 0, pMem, wMaxLen+sizeof(short), &dwBytes, NULL); if (iOK) /* Device IO control OK ? */ @@ -1946,7 +1946,7 @@ U14API(short) U14LineCount(short hand) ** other functions after getting an error and before using ** this function. ****************************************************************************/ -U14API(void) U14GetErrorString(short nErr, char* pStr, WORD wMax) +U14API(void) U14GetErrorString(short nErr, char* pStr, unsigned short wMax) { char wstr[150]; @@ -2105,7 +2105,7 @@ U14API(void) U14GetErrorString(short nErr, char* pStr, WORD wMax) break; } - if ((WORD)strlen(wstr) >= wMax-1) /* Check for string being too long */ + if ((unsigned short)strlen(wstr) >= wMax-1) /* Check for string being too long */ wstr[wMax-1] = 0; /* and truncate it if so */ strcpy(pStr, wstr); /* Return the error string */ } @@ -2120,8 +2120,8 @@ U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock) #ifdef _IS_WINDOWS_ if (sErr == U14ERR_NOERROR) { - DWORD dwBytes = 0; - BOOL bOK = DeviceIoControl(aHand1401[hand], (DWORD)U14_GETTRANSFER, NULL, 0, pTransBlock, + unsigned int dwBytes = 0; + BOOL bOK = DeviceIoControl(aHand1401[hand], (unsigned int)U14_GETTRANSFER, NULL, 0, pTransBlock, sizeof(TGET_TX_BLOCK), &dwBytes, NULL); if (bOK && (dwBytes >= sizeof(TGET_TX_BLOCK))) @@ -2145,12 +2145,12 @@ U14API(short) U14GetTransfer(short hand, TGET_TX_BLOCK *pTransBlock) // 1 unable to access process (insufficient rights?) // 2 unable to read process working set // 3 unable to set process working set - bad parameters? -U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb) +U14API(short) U14WorkingSet(unsigned int dwMinKb, unsigned int dwMaxKb) { #ifdef _IS_WINDOWS_ short sRetVal = 0; // 0 means all is OK HANDLE hProcess; - DWORD dwVer = GetVersion(); + unsigned int dwVer = GetVersion(); if (dwVer & 0x80000000) // is this not NT? return 0; // then give up right now @@ -2164,8 +2164,8 @@ U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb) SIZE_T dwMinSize,dwMaxSize; if (GetProcessWorkingSetSize(hProcess, &dwMinSize, &dwMaxSize)) { - DWORD dwMin = dwMinKb << 10; // convert from kb to bytes - DWORD dwMax = dwMaxKb << 10; + unsigned int dwMin = dwMinKb << 10; // convert from kb to bytes + unsigned int dwMax = dwMaxKb << 10; // if we get here, we have managed to read the current size if (dwMin > dwMinSize) // need to change sizes? @@ -2200,7 +2200,7 @@ U14API(short) U14WorkingSet(DWORD dwMinKb, DWORD dwMaxKb) ** U14UnSetTransfer Cancels a transfer area ** wArea The index of a block previously used in by SetTransfer *****************************************************************************/ -U14API(short) U14UnSetTransfer(short hand, WORD wArea) +U14API(short) U14UnSetTransfer(short hand, unsigned short wArea) { short sErr = CheckHandle(hand); #ifdef _IS_WINDOWS_ @@ -2223,13 +2223,13 @@ U14API(short) U14UnSetTransfer(short hand, WORD wArea) /**************************************************************************** ** U14SetTransArea Sets an area up to be used for transfers -** WORD wArea The area number to set up +** unsigned short wArea The area number to set up ** void *pvBuff The address of the buffer for the data. -** DWORD dwLength The length of the buffer for the data +** unsigned int dwLength The length of the buffer for the data ** short eSz The element size (used for byte swapping on the Mac) ****************************************************************************/ -U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, - DWORD dwLength, short eSz) +U14API(short) U14SetTransArea(short hand, unsigned short wArea, void *pvBuff, + unsigned int dwLength, short eSz) { TRANSFERDESC td; short sErr = CheckHandle(hand); @@ -2254,7 +2254,7 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, #ifndef _WIN64 if (!USE_NT_DIOC(hand)) /* Use Win 9x DIOC? */ { - DWORD dwBytes; + unsigned int dwBytes; VXTRANSFERDESC vxDesc; /* Structure to pass to VXD */ vxDesc.wArea = wArea; /* Copy across simple params */ vxDesc.dwLength = dwLength; @@ -2264,10 +2264,10 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, sErr = U14ERR_DRIVTOOOLD; else { - vxDesc.dwAddrOfs = (DWORD)pvBuff; /* 32 bit offset */ + vxDesc.dwAddrOfs = (unsigned int)pvBuff; /* 32 bit offset */ vxDesc.wAddrSel = 0; - if (DeviceIoControl(aHand1401[hand], (DWORD)U14_SETTRANSFER, + if (DeviceIoControl(aHand1401[hand], (unsigned int)U14_SETTRANSFER, pvBuff,dwLength, /* Will translate pointer */ &vxDesc,sizeof(VXTRANSFERDESC), &dwBytes,NULL)) @@ -2285,13 +2285,13 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, #endif { PARAMBLK rWork; - DWORD dwBytes; + unsigned int dwBytes; td.wArea = wArea; /* Pure NT - put data into struct */ td.lpvBuff = pvBuff; td.dwLength = dwLength; td.eSize = 0; // Dummy element size - if (DeviceIoControl(aHand1401[hand],(DWORD)U14_SETTRANSFER, + if (DeviceIoControl(aHand1401[hand],(unsigned int)U14_SETTRANSFER, &td,sizeof(TRANSFERDESC), &rWork,sizeof(PARAMBLK),&dwBytes,NULL)) { @@ -2344,8 +2344,8 @@ U14API(short) U14SetTransArea(short hand, WORD wArea, void *pvBuff, ** Returns 1 if an event handle exists, 0 if all OK and no event handle or ** a negative code for an error. ****************************************************************************/ -U14API(short) U14SetTransferEvent(short hand, WORD wArea, BOOL bEvent, - BOOL bToHost, DWORD dwStart, DWORD dwLength) +U14API(short) U14SetTransferEvent(short hand, unsigned short wArea, BOOL bEvent, + BOOL bToHost, unsigned int dwStart, unsigned int dwLength) { #ifdef _IS_WINDOWS_ TCSBLOCK csBlock; @@ -2416,7 +2416,7 @@ U14API(short) U14SetTransferEvent(short hand, WORD wArea, BOOL bEvent, ** Would a U14WaitTransferEvent() call return immediately? return 1 if so, ** 0 if not or a negative code if a problem. ****************************************************************************/ -U14API(int) U14TestTransferEvent(short hand, WORD wArea) +U14API(int) U14TestTransferEvent(short hand, unsigned short wArea) { #ifdef _IS_WINDOWS_ int iErr = CheckHandle(hand); @@ -2441,7 +2441,7 @@ U14API(int) U14TestTransferEvent(short hand, WORD wArea) ** Returns If no event handle then return immediately. Else return 1 if ** timed out or 0=event, and a negative code if a problem. ****************************************************************************/ -U14API(int) U14WaitTransferEvent(short hand, WORD wArea, int msTimeOut) +U14API(int) U14WaitTransferEvent(short hand, unsigned short wArea, int msTimeOut) { #ifdef _IS_WINDOWS_ int iErr = CheckHandle(hand); @@ -2466,13 +2466,13 @@ U14API(int) U14WaitTransferEvent(short hand, WORD wArea, int msTimeOut) /**************************************************************************** ** U14SetCircular Sets an area up for circular DMA transfers -** WORD wArea The area number to set up +** unsigned short wArea The area number to set up ** BOOL bToHost Sets the direction of data transfer ** void *pvBuff The address of the buffer for the data -** DWORD dwLength The length of the buffer for the data +** unsigned int dwLength The length of the buffer for the data ****************************************************************************/ -U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, - void *pvBuff, DWORD dwLength) +U14API(short) U14SetCircular(short hand, unsigned short wArea, BOOL bToHost, + void *pvBuff, unsigned int dwLength) { short sErr = CheckHandle(hand); if (sErr != U14ERR_NOERROR) @@ -2495,14 +2495,14 @@ U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, else { PARAMBLK rWork; - DWORD dwBytes; + unsigned int dwBytes; TRANSFERDESC txDesc; txDesc.wArea = wArea; /* Pure NT - put data into struct */ txDesc.lpvBuff = pvBuff; txDesc.dwLength = dwLength; txDesc.eSize = (short)bToHost; /* Use this for direction flag */ - if (DeviceIoControl(aHand1401[hand],(DWORD)U14_SETCIRCULAR, + if (DeviceIoControl(aHand1401[hand],(unsigned int)U14_SETCIRCULAR, &txDesc, sizeof(TRANSFERDESC), &rWork, sizeof(PARAMBLK),&dwBytes,NULL)) { @@ -2542,7 +2542,7 @@ U14API(short) U14SetCircular(short hand, WORD wArea, BOOL bToHost, ** Function GetCircBlk returns the size (& start offset) of the next ** available block of circular data. ****************************************************************************/ -U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs) +U14API(int) U14GetCircBlk(short hand, unsigned short wArea, unsigned int *pdwOffs) { int lErr = CheckHandle(hand); if (lErr != U14ERR_NOERROR) @@ -2555,10 +2555,10 @@ U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs) #ifdef _IS_WINDOWS_ PARAMBLK rWork; TCSBLOCK csBlock; - DWORD dwBytes; + unsigned int dwBytes; csBlock.longs[0] = wArea; // Area number into control block rWork.sState = U14ERR_DRIVCOMMS; - if (DeviceIoControl(aHand1401[hand], (DWORD)U14_GETCIRCBLK, &csBlock, sizeof(TCSBLOCK), &rWork, sizeof(PARAMBLK), &dwBytes, NULL) && + if (DeviceIoControl(aHand1401[hand], (unsigned int)U14_GETCIRCBLK, &csBlock, sizeof(TCSBLOCK), &rWork, sizeof(PARAMBLK), &dwBytes, NULL) && (dwBytes >= sizeof(PARAMBLK))) lErr = rWork.sState; else @@ -2591,8 +2591,8 @@ U14API(int) U14GetCircBlk(short hand, WORD wArea, DWORD *pdwOffs) ** resuse for circular transfers and returns the size (& start ** offset) of the next available block of circular data. ****************************************************************************/ -U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, - DWORD *pdwOffs) +U14API(int) U14FreeCircBlk(short hand, unsigned short wArea, unsigned int dwOffs, unsigned int dwSize, + unsigned int *pdwOffs) { int lErr = CheckHandle(hand); if (lErr != U14ERR_NOERROR) @@ -2603,12 +2603,12 @@ U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, #ifdef _IS_WINDOWS_ PARAMBLK rWork; TCSBLOCK csBlock; - DWORD dwBytes; + unsigned int dwBytes; csBlock.longs[0] = wArea; // Area number into control block csBlock.longs[1] = dwOffs; csBlock.longs[2] = dwSize; rWork.sState = U14ERR_DRIVCOMMS; - if (DeviceIoControl(aHand1401[hand], (DWORD)U14_FREECIRCBLK, &csBlock, sizeof(TCSBLOCK), + if (DeviceIoControl(aHand1401[hand], (unsigned int)U14_FREECIRCBLK, &csBlock, sizeof(TCSBLOCK), &rWork, sizeof(PARAMBLK), &dwBytes, NULL) && (dwBytes >= sizeof(PARAMBLK))) lErr = rWork.sState; @@ -2647,7 +2647,7 @@ U14API(int) U14FreeCircBlk(short hand, WORD wArea, DWORD dwOffs, DWORD dwSize, ** which it should be to get a pointer *****************************************************************************/ static short Transfer(short hand, BOOL bTo1401, char* pData, - DWORD dwSize, DWORD dw1401, short eSz) + unsigned int dwSize, unsigned int dw1401, short eSz) { char strcopy[MAXSTRLEN+1]; // to hold copy of work string short sResult = U14SetTransArea(hand, 0, (void *)pData, dwSize, eSz); @@ -2670,8 +2670,8 @@ static short Transfer(short hand, BOOL bTo1401, char* pData, /**************************************************************************** ** Function ToHost transfers data into the host from the 1401 ****************************************************************************/ -U14API(short) U14ToHost(short hand, char* pAddrHost, DWORD dwSize, - DWORD dw1401, short eSz) +U14API(short) U14ToHost(short hand, char* pAddrHost, unsigned int dwSize, + unsigned int dw1401, short eSz) { short sErr = CheckHandle(hand); if ((sErr == U14ERR_NOERROR) && dwSize) // TOHOST is a constant @@ -2682,8 +2682,8 @@ U14API(short) U14ToHost(short hand, char* pAddrHost, DWORD dwSize, /**************************************************************************** ** Function To1401 transfers data into the 1401 from the host ****************************************************************************/ -U14API(short) U14To1401(short hand, const char* pAddrHost,DWORD dwSize, - DWORD dw1401, short eSz) +U14API(short) U14To1401(short hand, const char* pAddrHost,unsigned int dwSize, + unsigned int dw1401, short eSz) { short sErr = CheckHandle(hand); if ((sErr == U14ERR_NOERROR) && dwSize) // TO1401 is a constant @@ -2707,7 +2707,7 @@ U14API(short) U14To1401(short hand, const char* pAddrHost,DWORD dwSize, #define file_close(h) close(h) #define file_seek(h, pos) lseek(h, pos, SEEK_SET) #define file_read(h, buffer, size) (read(h, buffer, size) == (ssize_t)size) -static DWORD GetModuleFileName(void* dummy, char* buffer, int max) +static unsigned int GetModuleFileName(void* dummy, char* buffer, int max) { // The following works for Linux systems with a /proc file system. char szProcPath[32]; @@ -2766,7 +2766,7 @@ U14API(short) U14LdCmd(short hand, const char* command) // application was run from. if (!bGotIt) // Still not got it? { - DWORD dwLen = GetModuleFileName(NULL, filnam, FNSZ); // Get app path + unsigned int dwLen = GetModuleFileName(NULL, filnam, FNSZ); // Get app path if (dwLen > 0) // and use it as path if found { char* pStr = strrchr(filnam, PATHSEP); // Point to last separator @@ -2821,7 +2821,7 @@ U14API(short) U14LdCmd(short hand, const char* command) file_seek(iFHandle, sizeof(CMDHEAD)); if (file_read(iFHandle, pMem, (UINT)nComSize)) { - sErr = U14SetTransArea(hand, 0, (void *)pMem, (DWORD)nComSize, ESZBYTES); + sErr = U14SetTransArea(hand, 0, (void *)pMem, (unsigned int)nComSize, ESZBYTES); if (sErr == U14ERR_NOERROR) { sprintf(strcopy, "CLOAD,0,$%X;", (int)nComSize); @@ -2858,9 +2858,9 @@ U14API(short) U14LdCmd(short hand, const char* command) ** Returns NOERROR code or a long with error in lo word and index of ** command that failed in high word ****************************************************************************/ -U14API(DWORD) U14Ld(short hand, const char* vl, const char* str) +U14API(unsigned int) U14Ld(short hand, const char* vl, const char* str) { - DWORD dwIndex = 0; // index to current command + unsigned int dwIndex = 0; // index to current command long lErr = U14ERR_NOERROR; // what the error was that went wrong char strcopy[MAXSTRLEN+1]; // stores unmodified str parameter char szFExt[8]; // The command file extension @@ -2939,7 +2939,7 @@ U14API(DWORD) U14Ld(short hand, const char* vl, const char* str) return lErr; } else - return ((dwIndex<<16) | ((DWORD)lErr & 0x0000FFFF)); + return ((dwIndex<<16) | ((unsigned int)lErr & 0x0000FFFF)); } // Initialise the library (if not initialised) and return the library version @@ -2951,7 +2951,7 @@ U14API(int) U14InitLib(void) int i; #ifdef _IS_WINDOWS_ int j; - DWORD dwVersion = GetVersion(); + unsigned int dwVersion = GetVersion(); bWindows9x = FALSE; // Assume not Win9x if (dwVersion & 0x80000000) // if not windows NT @@ -2993,12 +2993,12 @@ U14API(int) U14InitLib(void) #ifdef _IS_WINDOWS_ #ifndef U14_NOT_DLL /**************************************************************************** -** FUNCTION: DllMain(HANDLE, DWORD, LPVOID) +** FUNCTION: DllMain(HANDLE, unsigned int, LPVOID) ** LibMain is called by Windows when the DLL is initialized, Thread Attached, ** and other times. Refer to SDK documentation, as to the different ways this ** may be called. ****************************************************************************/ -INT APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved) +INT APIENTRY DllMain(HANDLE hInst, unsigned int ul_reason_being_called, LPVOID lpReserved) { int iRetVal = 1; |