unsigned int count)
{
int ret;
+
spin_lock_irq(&ced->char_out_lock); /* get the output spin lock */
if ((OUTBUF_SZ - ced->num_output) >= count) {
unsigned int u;
+
for (u = 0; u < count; u++) {
ced->output_buffer[ced->out_buff_put++] = ch[u];
if (ced->out_buff_put >= OUTBUF_SZ)
int ced_send_char(struct ced_data *ced, char c)
{
int ret;
+
mutex_lock(&ced->io_mutex); /* Protect disconnect from new i/o */
ret = ced_put_chars(ced, &c, 1);
dev_dbg(&ced->interface->dev, "ced_send_char >%c< (0x%02x)\n", c, c);
int ced_get_state(struct ced_data *ced, __u32 *state, __u32 *error)
{
int got;
+
dev_dbg(&ced->interface->dev, "%s: entry\n", __func__);
*state = 0xFFFFFFFF; /* Start off with invalid state */
*error = 0;
} else {
int device;
+
dev_dbg(&ced->interface->dev,
"%s: Success, state: 0x%x, 0x%x\n",
__func__, ced->stat_buf[0], ced->stat_buf[1]);
bResult = IoCancelIrp(ced->pStagedIrp); /* Actually do the cancel */
if (bResult) {
LARGE_INTEGER timeout;
+
timeout.QuadPart = -10000000; /* Use a timeout of 1 second */
dev_info(&ced->interface - dev,
"%s: about to wait till done\n", __func__);
{
unsigned int state, error;
int ret = ced_get_state(ced, &state, &error); /* see if in self-test */
+
if (ret == U14ERR_NOERROR) /* if all still OK */
ret = (state == (unsigned int)-1) || /* TX problem or... */
((state & 0xff) == 0x80); /* ...self test */
static bool ced_is_1401(struct ced_data *ced)
{
int ret;
+
dev_dbg(&ced->interface->dev, "%s\n", __func__);
ced_draw_down(ced); /* wait for, then kill outstanding Urbs */
ced->dma_flag = MODE_CHAR; /* Clear DMA mode flag regardless! */
if (ret == 0) { /* if all is OK still */
unsigned int state;
+
ret = ced_in_self_test(ced, &state); /* see if likely in */
/* self test */
if (ret > 0) { /* do we need to wait for self-test? */
/* when to give up */
unsigned long timeout = jiffies + 30 * HZ;
+
while ((ret > 0) && time_before(jiffies, timeout)) {
schedule(); /* let other stuff run */
if (short_test || !can_reset) { /* Still OK to try the short test? */
/* Always test if no reset - we want state update */
unsigned int state, error;
+
dev_dbg(&ced->interface->dev, "%s: ced_get_state\n", __func__);
if (ced_get_state(ced, &state, &error) == U14ERR_NOERROR) { /* Check on the 1401 state */
if ((state & 0xFF) == 0) /* If call worked, check the status value */
int ced_get_char(struct ced_data *ced)
{
int ret = U14ERR_NOIN; /* assume we will get nothing */
+
mutex_lock(&ced->io_mutex); /* Protect disconnect from new i/o */
dev_dbg(&ced->interface->dev, "%s\n", __func__);
{
int available; /* character in the buffer */
int ret = U14ERR_NOIN;
+
if (n <= 0)
return -ENOMEM;
int got = 0;
int n_copy_to_user; /* number to copy to user */
char data;
+
do {
data = ced->input_buffer[ced->in_buff_get++];
if (data == CR_CHAR) /* replace CR with zero */
int ced_stat_1401(struct ced_data *ced)
{
int ret;
+
mutex_lock(&ced->io_mutex); /* Protect disconnect from new i/o */
ced_allowi(ced); /* make sure we allow pending chars */
ced_send_chars(ced); /* in both directions */
unsigned int index = ced->in_buff_get;
/* Position for search end */
unsigned int end = ced->in_buff_put;
+
do {
if (ced->input_buffer[index++] == CR_CHAR)
++ret; /* inc count if CR */
} else {
/* to save typing */
struct transarea *ta = &ced->trans_def[area];
+
if (!ta->used) /* if not used... */
ret = U14ERR_NOTSET; /* ...nothing to be done */
else {
int n_pages = 0; /* and number of pages */
int ret = ced_clear_area(ced, area); /* see if OK to use this area */
+
if ((ret != U14ERR_NOTSET) && /* if not area unused and... */
(ret != U14ERR_NOERROR)) /* ...not all OK, then... */
return ret; /* ...we cannot use this area */
int ced_unset_transfer(struct ced_data *ced, int area)
{
int ret;
+
mutex_lock(&ced->io_mutex);
ret = ced_clear_area(ced, area);
mutex_unlock(&ced->io_mutex);
int ced_wait_event(struct ced_data *ced, int area, int time_out)
{
int ret;
+
if ((unsigned)area >= MAX_TRANSAREAS)
return U14ERR_BADAREA;
else {
int ced_test_event(struct ced_data *ced, int area)
{
int ret;
+
if ((unsigned)area >= MAX_TRANSAREAS)
ret = U14ERR_BADAREA;
else {
int ced_state_of_1401(struct ced_data *ced)
{
int ret;
+
mutex_lock(&ced->io_mutex);
ced_quick_check(ced, false, false); /* get state up to date, no reset */
int ced_start_self_test(struct ced_data *ced)
{
int got;
+
mutex_lock(&ced->io_mutex);
dev_dbg(&ced->interface->dev, "%s\n", __func__);
unsigned int state, error;
int ret;
TGET_SELFTEST gst; /* local work space */
+
memset(&gst, 0, sizeof(gst)); /* clear out the space (sets code 0) */
mutex_lock(&ced->io_mutex);
"Self-test error code %d\n", gst.code);
} else { /* No error, check for timeout */
unsigned long now = jiffies; /* get current time */
+
if (time_after(now, ced->self_test_time)) {
gst.code = -2; /* Flag the timeout */
dev_dbg(&ced->interface->dev,
if (area < MAX_TRANSAREAS) { /* The area number must be OK */
/* Pointer to relevant info */
struct transarea *ta = &ced->trans_def[area];
+
spin_lock_irq(&ced->staged_lock); /* Lock others out */
if ((ta->used) && (ta->circular) && /* Must be circular area */