Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 14 additions & 32 deletions fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ static ssize_t mxdma_device_read_context(struct file *file, char __user *buf, si
if (ret)
return ret;

if (count >= sizeof(uint64_t))
return read_data_from_device(mx_pdev, buf, count, pos, MXDMA_OP_CONTEXT_READ, mx_cdev->nowait);
else
return read_ctrl_from_device(mx_pdev, buf, count, pos, MXDMA_OP_CONTEXT_READ, mx_cdev->nowait);
return read_data_from_device(mx_pdev, buf, count, pos, MXDMA_OP_CONTEXT_READ, mx_cdev->nowait);
}

static ssize_t mxdma_device_read_sq(struct file *file, char __user *buf, size_t count, loff_t *pos)
Expand All @@ -117,19 +114,16 @@ static ssize_t mxdma_device_read_sq(struct file *file, char __user *buf, size_t
struct mx_pci_dev *mx_pdev;
int ret;

if (!count) {
pr_warn("size of data to read is zero\n");
if (count != sizeof(uint64_t)) {
pr_warn("size of data to read is not supported: %zu\n", count);
return -EINVAL;
}

ret = mxdma_device_prepare(file, &mx_cdev, &mx_pdev);
if (ret)
return ret;

if (count <= sizeof(uint64_t))
return read_ctrl_from_device(mx_pdev, buf, count, pos, MXDMA_OP_SQ_READ, mx_cdev->nowait);
else
return -EINVAL;
return read_ctrl_from_device(mx_pdev, buf, count, pos, MXDMA_OP_SQ_READ, mx_cdev->nowait);
}

static ssize_t mxdma_device_read_cq(struct file *file, char __user *buf, size_t count, loff_t *pos)
Expand All @@ -138,19 +132,16 @@ static ssize_t mxdma_device_read_cq(struct file *file, char __user *buf, size_t
struct mx_pci_dev *mx_pdev;
int ret;

if (!count) {
pr_warn("size of data to read is zero\n");
if (count != sizeof(uint64_t)) {
pr_warn("size of data to read is not supported: %zu\n", count);
return -EINVAL;
}

ret = mxdma_device_prepare(file, &mx_cdev, &mx_pdev);
if (ret)
return ret;

if (count <= sizeof(uint64_t))
return read_ctrl_from_device(mx_pdev, buf, count, pos, MXDMA_OP_CQ_READ, mx_cdev->nowait);
else
return -EINVAL;
return read_ctrl_from_device(mx_pdev, buf, count, pos, MXDMA_OP_CQ_READ, mx_cdev->nowait);
}

static ssize_t mxdma_device_write_data(struct file *file, const char __user *buf, size_t count, loff_t *pos)
Expand Down Expand Up @@ -186,10 +177,7 @@ static ssize_t mxdma_device_write_context(struct file *file, const char __user *
if (ret)
return ret;

if (count >= sizeof(uint64_t))
return write_data_to_device(mx_pdev, buf, count, pos, MXDMA_OP_CONTEXT_WRITE, mx_cdev->nowait);
else
return write_ctrl_to_device(mx_pdev, buf, count, pos, MXDMA_OP_CONTEXT_WRITE, mx_cdev->nowait);
return write_data_to_device(mx_pdev, buf, count, pos, MXDMA_OP_CONTEXT_WRITE, mx_cdev->nowait);
}

static ssize_t mxdma_device_write_sq(struct file *file, const char __user *buf, size_t count, loff_t *pos)
Expand All @@ -198,19 +186,16 @@ static ssize_t mxdma_device_write_sq(struct file *file, const char __user *buf,
struct mx_pci_dev *mx_pdev;
int ret;

if (!count) {
pr_warn("size of data to write is zero\n");
if (count != sizeof(uint32_t)) {
pr_warn("size of data to write is not supported: %zu\n", count);
return -EINVAL;
}

ret = mxdma_device_prepare(file, &mx_cdev, &mx_pdev);
if (ret)
return ret;

if (count <= sizeof(uint64_t))
return write_ctrl_to_device(mx_pdev, buf, count, pos, MXDMA_OP_SQ_WRITE, mx_cdev->nowait);
else
return -EINVAL;
return write_ctrl_to_device(mx_pdev, buf, count, pos, MXDMA_OP_SQ_WRITE, mx_cdev->nowait);
}

static ssize_t mxdma_device_write_cq(struct file *file, const char __user *buf, size_t count, loff_t *pos)
Expand All @@ -219,19 +204,16 @@ static ssize_t mxdma_device_write_cq(struct file *file, const char __user *buf,
struct mx_pci_dev *mx_pdev;
int ret;

if (!count) {
pr_warn("size of data to write is zero\n");
if (count != sizeof(uint32_t)) {
pr_warn("size of data to write is not supported: %zu\n", count);
return -EINVAL;
}

ret = mxdma_device_prepare(file, &mx_cdev, &mx_pdev);
if (ret)
return ret;

if (count <= sizeof(uint64_t))
return write_ctrl_to_device(mx_pdev, buf, count, pos, MXDMA_OP_CQ_WRITE, mx_cdev->nowait);
else
return -EINVAL;
return write_ctrl_to_device(mx_pdev, buf, count, pos, MXDMA_OP_CQ_WRITE, mx_cdev->nowait);
}

static unsigned int mxdma_device_poll(struct file *file, poll_table *wait)
Expand Down
13 changes: 4 additions & 9 deletions transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,11 @@ static int mx_transfer_init_ctrl(struct mx_transfer *transfer, int opcode)
if (transfer->dir != DMA_TO_DEVICE)
return 0;

if (opcode == MXDMA_OP_CONTEXT_WRITE || transfer->nowait == false) {
ret = copy_from_user(&value, transfer->user_addr, transfer->size);
if (ret) {
pr_warn("Failed to copy_from_user (err=%d)\n", ret);
return ret;
}
} else {
value = (uint64_t)transfer->user_addr;
ret = copy_from_user(&value, transfer->user_addr, transfer->size);
if (ret) {
pr_warn("Failed to copy_from_user (err=%d)\n", ret);
return ret;
}

transfer->cmd.host_addr = value;

return 0;
Expand Down