Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-cao committed Jan 15, 2021
2 parents ad180a2 + aa03800 commit f86407a
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions switchtec.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum mrpc_state {
MRPC_QUEUED,
MRPC_RUNNING,
MRPC_DONE,
MRPC_IO_ERROR,
};

struct switchtec_user {
Expand All @@ -72,6 +73,13 @@ struct switchtec_user {
int event_cnt;
};

static int check_access(struct switchtec_dev *stdev)
{
u32 device = ioread32(&stdev->mmio_sys_info->device_id);

return stdev->pdev->device == device;
}

static struct switchtec_user *stuser_create(struct switchtec_dev *stdev)
{
struct switchtec_user *stuser;
Expand Down Expand Up @@ -119,6 +127,7 @@ static void stuser_set_state(struct switchtec_user *stuser,
[MRPC_QUEUED] = "QUEUED",
[MRPC_RUNNING] = "RUNNING",
[MRPC_DONE] = "DONE",
[MRPC_IO_ERROR] = "IO_ERROR",
};

stuser->state = state;
Expand Down Expand Up @@ -186,6 +195,20 @@ static int mrpc_queue_cmd(struct switchtec_user *stuser)
return 0;
}

static void mrpc_cleanup_cmd(struct switchtec_dev *stdev)
{
/* requires the mrpc_mutex to already be held when called */
struct switchtec_user *stuser = list_entry(stdev->mrpc_queue.next,
struct switchtec_user, list);

complete_all(&stuser->comp);
list_del_init(&stuser->list);
stuser_put(stuser);
stdev->mrpc_busy = 0;

mrpc_cmd_submit(stdev);
}

static void mrpc_complete_cmd(struct switchtec_dev *stdev)
{
/* requires the mrpc_mutex to already be held when called */
Expand Down Expand Up @@ -226,12 +249,7 @@ static void mrpc_complete_cmd(struct switchtec_dev *stdev)
memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data,
stuser->read_len);
out:
complete_all(&stuser->comp);
list_del_init(&stuser->list);
stuser_put(stuser);
stdev->mrpc_busy = 0;

mrpc_cmd_submit(stdev);
mrpc_cleanup_cmd(stdev);
}

static void mrpc_event_work(struct work_struct *work)
Expand All @@ -248,6 +266,23 @@ static void mrpc_event_work(struct work_struct *work)
mutex_unlock(&stdev->mrpc_mutex);
}

static void mrpc_error_complete_cmd(struct switchtec_dev *stdev)
{
/* requires the mrpc_mutex to already be held when called */

struct switchtec_user *stuser;

if (list_empty(&stdev->mrpc_queue))
return;

stuser = list_entry(stdev->mrpc_queue.next,
struct switchtec_user, list);

stuser_set_state(stuser, MRPC_IO_ERROR);

mrpc_cleanup_cmd(stdev);
}

static void mrpc_timeout_work(struct work_struct *work)
{
struct switchtec_dev *stdev;
Expand All @@ -259,6 +294,11 @@ static void mrpc_timeout_work(struct work_struct *work)

mutex_lock(&stdev->mrpc_mutex);

if (!check_access(stdev)) {
mrpc_error_complete_cmd(stdev);
goto out;
}

if (stdev->dma_mrpc)
status = stdev->dma_mrpc->status;
else
Expand Down Expand Up @@ -544,6 +584,11 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
if (rc)
return rc;

if (stuser->state == MRPC_IO_ERROR) {
mutex_unlock(&stdev->mrpc_mutex);
return -EIO;
}

if (stuser->state != MRPC_DONE) {
mutex_unlock(&stdev->mrpc_mutex);
return -EBADE;
Expand Down

0 comments on commit f86407a

Please sign in to comment.