Submission of XillyUSB driver
Subsystems (4)
[email protected]
maintainerv3 cover Submission of XillyUSB driver
From: Eli Billauer <[email protected]>
This is a resubmission of the XillyUSB driver, which is the USB variant of the existing Xillybus driver.
Because these driver share some API related functions, this submission consists of two patches:
(1) A patch moving away Xillybus' class related functions to a separate module file.
(2) A patch adding the new XillyUSB driver, based upon this new separate module.
As far as I can tell, the shared code between the Xillybus and XillyUSB drivers covers everything that makes sense to share. I submit XillyUSB as a staging driver, with the hope for a detailed review on this issue, as well as a general code audit.
Thanks,
Eli
Eli Billauer (2):
char: xillybus: Move class-related functions to new xillybus_class.c
staging: Add driver for XillyUSB (Xillybus variant for USB)
MAINTAINERS | 1 + drivers/char/xillybus/Kconfig | 4 + drivers/char/xillybus/Makefile | 1 + drivers/char/xillybus/xillybus.h | 10 +- drivers/char/xillybus/xillybus_class.c | 263 +++ drivers/char/xillybus/xillybus_core.c | 181 +- drivers/staging/Kconfig | 2 + drivers/staging/Makefile | 1 + drivers/staging/xillyusb/Kconfig | 20 + drivers/staging/xillyusb/Makefile | 6 + drivers/staging/xillyusb/TODO | 13 + drivers/staging/xillyusb/xillyusb.c | 2184 ++++++++++++++++++++++++ include/linux/xillybus_class.h | 30 + 13 files changed, 2549 insertions(+), 167 deletions(-) create mode 100644 drivers/char/xillybus/xillybus_class.c create mode 100644 drivers/staging/xillyusb/Kconfig create mode 100644 drivers/staging/xillyusb/Makefile create mode 100644 drivers/staging/xillyusb/TODO create mode 100644 drivers/staging/xillyusb/xillyusb.c create mode 100644 include/linux/xillybus_class.h
Signature · 1 line
2.17.1
[email protected]
maintainerPATCH v3 1/2 char: xillybus: Move class-related functions to new xillybus_class.c
From: Eli Billauer <[email protected]>
This patch is a preparation for adding another related driver, XillyUSB. In order to share some code between the existing Xillybus driver and the one to be added, some functions are moved to xillybus_class.c
The header file, xillybus_class.h, is temporarily placed in include/linux/, because the new XillyUSB driver is intended as a staging driver for the time being.
---
Notes:
Changelog:
This patch did not exist prior to v3.
drivers/char/xillybus/Kconfig | 4 + drivers/char/xillybus/Makefile | 1 + drivers/char/xillybus/xillybus.h | 10 +- drivers/char/xillybus/xillybus_class.c | 263 +++++++++++++++++++++++++ drivers/char/xillybus/xillybus_core.c | 181 +++-------------- include/linux/xillybus_class.h | 30 +++ 6 files changed, 322 insertions(+), 167 deletions(-) create mode 100644 drivers/char/xillybus/xillybus_class.c create mode 100644 include/linux/xillybus_class.h
drivers/char/xillybus/Kconfig +4 -0
@@ -3,10 +3,14 @@ # Xillybus devices # +config XILLYBUS_CLASS + tristate + config XILLYBUS tristate "Xillybus generic FPGA interface" depends on PCI || OF select CRC32 + select XILLYBUS_CLASS help Xillybus is a generic interface for peripherals designed on programmable logic (FPGA). The driver probes the hardware for
drivers/char/xillybus/Makefile +1 -0
@@ -3,6 +3,7 @@ # Makefile for Xillybus driver # +obj-$(CONFIG_XILLYBUS_CLASS) += xillybus_class.o obj-$(CONFIG_XILLYBUS) += xillybus_core.o obj-$(CONFIG_XILLYBUS_PCIE) += xillybus_pcie.o obj-$(CONFIG_XILLYBUS_OF) += xillybus_of.o
drivers/char/xillybus/xillybus.h +2 -8
@@ -30,7 +30,8 @@ struct xilly_buffer {struct xilly_idt_handle {unsigned char *chandesc; -unsigned char *idt; +unsigned char *names; +int names_len;int entries; };
@@ -94,7 +95,6 @@ struct xilly_endpoint {struct device *dev;struct xilly_endpoint_hardware *ephw; -struct list_head ep_list;int dma_using_dac;/* =1 if 64-bit DMA is used, =0 otherwise. */ __iomem void *registers;int fatal_error;
@@ -102,12 +102,6 @@ struct xilly_endpoint {struct mutex register_mutex;wait_queue_head_t ep_wait; -/* Channels and message handling */ -struct cdev cdev; - -int major; -int lowest_minor;/* Highest minor = lowest_minor + num_channels - 1 */ -int num_channels;/* EXCLUDING message buffer */ struct xilly_channel **channels;int msg_counter;
drivers/char/xillybus/xillybus_class.c new file +263 -0
263 lines not on this page · raw message
drivers/char/xillybus/xillybus_core.c +22 -159
266 lines not on this page · raw message
include/linux/xillybus_class.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright 2021 Xillybus Ltd, http://www.xillybus.com +* +* Header file for the Xillybus class +*/ + +#ifndef __XILLYBUS_CLASS_H +#define __XILLYBUS_CLASS_H + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/module.h> + +int xillybus_init_chrdev (struct device *dev, +const struct file_operations *fops, +struct module *owner, +void *private_data, +unsigned char *idt,unsigned int len, +int num_nodes, +const char *prefix,bool enumerate); + +void xillybus_cleanup_chrdev (void *private_data, +struct device *dev); + +int xillybus_find_inode (struct inode *inode, +void **private_data,int *index); + +#endif /* __XILLYBUS_CLASS_H */
Signature · 1 line
2.17.1
[kbuild] Re: [PATCH v3 1/2] char: xillybus: Move class-related functions to new xillybus_class.c
url: https://github.com/0day-ci/linux/commits/eli-billauer-gmail-com/Submission-of-XillyUSB-driver/20210309-193645 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 080951f99de1e483a9a48f34c079b634f2912a54 config: x86_64-randconfig-m001-20210309 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
smatch warnings:drivers/char/xillybus/xillybus_class.c:86 xillybus_init_chrdev() warn: ignoring unreachable code. drivers/char/xillybus/xillybus_class.c:96 xillybus_init_chrdev() warn: missing error code 'rc'
vim +86 drivers/char/xillybus/xillybus_class.c
10702b71f93292 Eli Billauer 2021-03-09 42 int xillybus_init_chrdev(struct device *dev,
10702b71f93292 Eli Billauer 2021-03-09 43 const struct file_operations *fops,
10702b71f93292 Eli Billauer 2021-03-09 44 struct module *owner,
10702b71f93292 Eli Billauer 2021-03-09 45 void *private_data,
10702b71f93292 Eli Billauer 2021-03-09 46 unsigned char *idt, unsigned int len,
10702b71f93292 Eli Billauer 2021-03-09 47 int num_nodes,
10702b71f93292 Eli Billauer 2021-03-09 48 const char *prefix, bool enumerate)
10702b71f93292 Eli Billauer 2021-03-09 49 {
10702b71f93292 Eli Billauer 2021-03-09 50 int rc;
10702b71f93292 Eli Billauer 2021-03-09 51 dev_t mdev;
10702b71f93292 Eli Billauer 2021-03-09 52 int i;
10702b71f93292 Eli Billauer 2021-03-09 53 char devname[48];
10702b71f93292 Eli Billauer 2021-03-09 54
10702b71f93292 Eli Billauer 2021-03-09 55 struct device *device;
10702b71f93292 Eli Billauer 2021-03-09 56 size_t namelen;
10702b71f93292 Eli Billauer 2021-03-09 57 struct xilly_unit *unit, *u;
10702b71f93292 Eli Billauer 2021-03-09 58
10702b71f93292 Eli Billauer 2021-03-09 59 unit = kzalloc(sizeof(*unit), GFP_KERNEL);
10702b71f93292 Eli Billauer 2021-03-09 60
10702b71f93292 Eli Billauer 2021-03-09 61 if (!unit)
10702b71f93292 Eli Billauer 2021-03-09 62 return -ENOMEM;
10702b71f93292 Eli Billauer 2021-03-09 63
10702b71f93292 Eli Billauer 2021-03-09 64 mutex_lock(&unit_mutex);
10702b71f93292 Eli Billauer 2021-03-09 65
10702b71f93292 Eli Billauer 2021-03-09 66 if (!enumerate)
10702b71f93292 Eli Billauer 2021-03-09 67 snprintf(unit->name, UNITNAMELEN, "%s", prefix);
10702b71f93292 Eli Billauer 2021-03-09 68
10702b71f93292 Eli Billauer 2021-03-09 69 for (i = 0; enumerate; i++) {
10702b71f93292 Eli Billauer 2021-03-09 70 snprintf(unit->name, UNITNAMELEN, "%s_%02d",
10702b71f93292 Eli Billauer 2021-03-09 71 prefix, i);
10702b71f93292 Eli Billauer 2021-03-09 72
10702b71f93292 Eli Billauer 2021-03-09 73 enumerate = false;
10702b71f93292 Eli Billauer 2021-03-09 74 list_for_each_entry(u, &unit_list, list_entry)
10702b71f93292 Eli Billauer 2021-03-09 75 if (!strcmp(unit->name, u->name)) {
10702b71f93292 Eli Billauer 2021-03-09 76 enumerate = true;
10702b71f93292 Eli Billauer 2021-03-09 77 break;
10702b71f93292 Eli Billauer 2021-03-09 78 }
10702b71f93292 Eli Billauer 2021-03-09 79 }
10702b71f93292 Eli Billauer 2021-03-09 80
10702b71f93292 Eli Billauer 2021-03-09 81 rc = alloc_chrdev_region(&mdev, 0, num_nodes, unit->name);
10702b71f93292 Eli Billauer 2021-03-09 82
10702b71f93292 Eli Billauer 2021-03-09 83 if (rc) {
10702b71f93292 Eli Billauer 2021-03-09 84 dev_warn(dev, "Failed to obtain major/minors");
10702b71f93292 Eli Billauer 2021-03-09 85 goto fail_obtain;
^^^^^^^^^^^^^^^^^
10702b71f93292 Eli Billauer 2021-03-09 @86 return rc;
^^^^^^^^^^Unreachable
10702b71f93292 Eli Billauer 2021-03-09 87 } 10702b71f93292 Eli Billauer 2021-03-09 88 10702b71f93292 Eli Billauer 2021-03-09 89 unit->major = MAJOR(mdev); 10702b71f93292 Eli Billauer 2021-03-09 90 unit->lowest_minor = MINOR(mdev); 10702b71f93292 Eli Billauer 2021-03-09 91 unit->num_nodes = num_nodes; 10702b71f93292 Eli Billauer 2021-03-09 92 unit->private_data = private_data; 10702b71f93292 Eli Billauer 2021-03-09 93 10702b71f93292 Eli Billauer 2021-03-09 94 unit->cdev = cdev_alloc(); 10702b71f93292 Eli Billauer 2021-03-09 95 if (!unit->cdev)
10702b71f93292 Eli Billauer 2021-03-09 @96 goto unregister_chrdev;
"rc = -ENOMEM;"
10702b71f93292 Eli Billauer 2021-03-09 97
10702b71f93292 Eli Billauer 2021-03-09 98 unit->cdev->ops = fops;
10702b71f93292 Eli Billauer 2021-03-09 99 unit->cdev->owner = owner;
10702b71f93292 Eli Billauer 2021-03-09 100
10702b71f93292 Eli Billauer 2021-03-09 101 rc = cdev_add(unit->cdev, MKDEV(unit->major, unit->lowest_minor),
10702b71f93292 Eli Billauer 2021-03-09 102 unit->num_nodes);
10702b71f93292 Eli Billauer 2021-03-09 103 if (rc) {
10702b71f93292 Eli Billauer 2021-03-09 104 dev_err(dev, "Failed to add cdev.\n");
10702b71f93292 Eli Billauer 2021-03-09 105 /* kobject_put() is normally done by cdev_del() */
10702b71f93292 Eli Billauer 2021-03-09 106 kobject_put(&unit->cdev->kobj);
10702b71f93292 Eli Billauer 2021-03-09 107 goto unregister_chrdev;
10702b71f93292 Eli Billauer 2021-03-09 108 }
10702b71f93292 Eli Billauer 2021-03-09 109
10702b71f93292 Eli Billauer 2021-03-09 110 for (i = 0; i < num_nodes; i++) {
10702b71f93292 Eli Billauer 2021-03-09 111 namelen = strnlen(idt, len);
10702b71f93292 Eli Billauer 2021-03-09 112
10702b71f93292 Eli Billauer 2021-03-09 113 if (namelen == len) {
10702b71f93292 Eli Billauer 2021-03-09 114 dev_err(dev, "IDT's list of names is too short. This is exceptionally weird, because its CRC is OK\n");
10702b71f93292 Eli Billauer 2021-03-09 115 rc = -ENODEV;
10702b71f93292 Eli Billauer 2021-03-09 116 goto unroll_device_create;
10702b71f93292 Eli Billauer 2021-03-09 117 }
10702b71f93292 Eli Billauer 2021-03-09 118
10702b71f93292 Eli Billauer 2021-03-09 119 snprintf(devname, sizeof(devname), "%s_%s",
10702b71f93292 Eli Billauer 2021-03-09 120 unit->name, idt);
10702b71f93292 Eli Billauer 2021-03-09 121
10702b71f93292 Eli Billauer 2021-03-09 122 len -= namelen + 1;
10702b71f93292 Eli Billauer 2021-03-09 123 idt += namelen + 1;
10702b71f93292 Eli Billauer 2021-03-09 124
10702b71f93292 Eli Billauer 2021-03-09 125 device = device_create(xillybus_class,
10702b71f93292 Eli Billauer 2021-03-09 126 NULL,
10702b71f93292 Eli Billauer 2021-03-09 127 MKDEV(unit->major,
10702b71f93292 Eli Billauer 2021-03-09 128 i + unit->lowest_minor),
10702b71f93292 Eli Billauer 2021-03-09 129 NULL,
10702b71f93292 Eli Billauer 2021-03-09 130 "%s", devname);
10702b71f93292 Eli Billauer 2021-03-09 131
10702b71f93292 Eli Billauer 2021-03-09 132 if (IS_ERR(device)) {
10702b71f93292 Eli Billauer 2021-03-09 133 dev_err(dev, "Failed to create %s device. Aborting.\n",
10702b71f93292 Eli Billauer 2021-03-09 134 devname);
10702b71f93292 Eli Billauer 2021-03-09 135 rc = -ENODEV;
10702b71f93292 Eli Billauer 2021-03-09 136 goto unroll_device_create;
10702b71f93292 Eli Billauer 2021-03-09 137 }
10702b71f93292 Eli Billauer 2021-03-09 138 }
10702b71f93292 Eli Billauer 2021-03-09 139
10702b71f93292 Eli Billauer 2021-03-09 140 if (len) {
10702b71f93292 Eli Billauer 2021-03-09 141 dev_err(dev, "IDT's list of names is too long. This is exceptionally weird, because its CRC is OK\n");
10702b71f93292 Eli Billauer 2021-03-09 142 rc = -ENODEV;
10702b71f93292 Eli Billauer 2021-03-09 143 goto unroll_device_create;
10702b71f93292 Eli Billauer 2021-03-09 144 }
10702b71f93292 Eli Billauer 2021-03-09 145
10702b71f93292 Eli Billauer 2021-03-09 146 list_add_tail(&unit->list_entry, &unit_list);
10702b71f93292 Eli Billauer 2021-03-09 147
10702b71f93292 Eli Billauer 2021-03-09 148 dev_info(dev, "Created %d device files.\n", num_nodes);
10702b71f93292 Eli Billauer 2021-03-09 149
10702b71f93292 Eli Billauer 2021-03-09 150 mutex_unlock(&unit_mutex);
10702b71f93292 Eli Billauer 2021-03-09 151
10702b71f93292 Eli Billauer 2021-03-09 152 return 0;
10702b71f93292 Eli Billauer 2021-03-09 153
10702b71f93292 Eli Billauer 2021-03-09 154 unroll_device_create:
10702b71f93292 Eli Billauer 2021-03-09 155 for (i--; i >= 0; i--)
10702b71f93292 Eli Billauer 2021-03-09 156 device_destroy(xillybus_class, MKDEV(unit->major,
10702b71f93292 Eli Billauer 2021-03-09 157 i + unit->lowest_minor));
10702b71f93292 Eli Billauer 2021-03-09 158
10702b71f93292 Eli Billauer 2021-03-09 159 cdev_del(unit->cdev);
10702b71f93292 Eli Billauer 2021-03-09 160
10702b71f93292 Eli Billauer 2021-03-09 161 unregister_chrdev:
10702b71f93292 Eli Billauer 2021-03-09 162 unregister_chrdev_region(MKDEV(unit->major, unit->lowest_minor),
10702b71f93292 Eli Billauer 2021-03-09 163 unit->num_nodes);
10702b71f93292 Eli Billauer 2021-03-09 164
10702b71f93292 Eli Billauer 2021-03-09 165 fail_obtain:
10702b71f93292 Eli Billauer 2021-03-09 166 mutex_unlock(&unit_mutex);
10702b71f93292 Eli Billauer 2021-03-09 167
10702b71f93292 Eli Billauer 2021-03-09 168 kfree(unit);
10702b71f93292 Eli Billauer 2021-03-09 169
10702b71f93292 Eli Billauer 2021-03-09 170 return rc;
10702b71f93292 Eli Billauer 2021-03-09 171 }---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
_______________________________________________
kbuild mailing list -- kbuild(a)lists.01.org
To unsubscribe send an email to kbuild-leave(a)lists.01.org
Eli Billauer
maintainerRe: [kbuild] Re: [PATCH v3 1/2] char: xillybus: Move class-related functions to new xillybus_class.c
Quoted 5 lines · Dan Carpenter
url:https://github.com/0day-ci/linux/commits/eli-billauer-gmail-com/Submission-of-XillyUSB-driver/20210309-193645
base:https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git080951f99de1e483a9a48f34c079b634f2912a54
config: x86_64-randconfig-m001-20210309 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
Quoted 8 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot<[email protected]>Reported-by Dan Carpenter<[email protected]>smatch warnings:
drivers/char/xillybus/xillybus_class.c:86xillybus_init_chrdev()warn: ignoring unreachable code.drivers/char/xillybus/xillybus_class.c:96xillybus_init_chrdev()warn: missing error code 'rc'
Thanks a lot. I guess there's a patch v4 coming up.
Regards,
Eli
[email protected]
maintainerPATCH v3 2/2 staging: Add driver for XillyUSB (Xillybus variant for USB)
In reply to [email protected]From: Eli Billauer <[email protected]>
The XillyUSB driver is the USB variant for the Xillybus FPGA IP core. Even though it presents a nearly identical API on the FPGA and host, it's almost a complete rewrite of the driver: The framework for exchanging data on a USB bus is fundamentally different from doing the same with a PCIe interface, which leaves very little in common between the existing driver and the new one for XillyUSB.
---
Notes:
Changelog:
v3:
- Move to staging
- Rely on xillybus_class for device file operations
- Fix no return value bug in xillyusb_discovery()
- Add module parameters for URB buffer size and count
v2:
- Add comment in Kconfig file, saying XILLYUSB really doesn't depend on XILLYBUS (following comment by Randy Dunlap)
- Use SEEK_* predefined constants instead of numbers
MAINTAINERS | 1 + drivers/staging/Kconfig | 2 + drivers/staging/Makefile | 1 + drivers/staging/xillyusb/Kconfig | 20 + drivers/staging/xillyusb/Makefile | 6 + drivers/staging/xillyusb/TODO | 13 + drivers/staging/xillyusb/xillyusb.c | 2184 +++++++++++++++++++++++++++ 7 files changed, 2227 insertions(+) create mode 100644 drivers/staging/xillyusb/Kconfig create mode 100644 drivers/staging/xillyusb/Makefile create mode 100644 drivers/staging/xillyusb/TODO create mode 100644 drivers/staging/xillyusb/xillyusb.c
MAINTAINERS +1 -0
@@ -19749,6 +19749,7 @@ M: Eli Billauer <[email protected]> L: [email protected] S: Supported F: drivers/char/xillybus/ +F: drivers/staging/xillyusb/ XLP9XX I2C DRIVER M: George Cherian <[email protected]>
drivers/staging/Kconfig +2 -0
@@ -114,4 +114,6 @@ source "drivers/staging/wfx/Kconfig" source "drivers/staging/hikey9xx/Kconfig" +source "drivers/staging/xillyusb/Kconfig" + endif # STAGING
drivers/staging/Makefile +1 -0
@@ -47,3 +47,4 @@ obj-$(CONFIG_QLGE) += qlge/ obj-$(CONFIG_WIMAX) += wimax/ obj-$(CONFIG_WFX) += wfx/ obj-y += hikey9xx/ +obj-$(CONFIG_XILLYUSB) += xillyusb/
drivers/staging/xillyusb/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# XillyUSB devices +# + +config XILLYUSB + tristate "Xillybus generic FPGA interface for USB" + depends on USB + select CRC32 + select XILLYBUS_CLASS + help + XillyUSB is the Xillybus variant which uses USB for communicating + with the FPGA. + + Xillybus is a generic interface for peripherals designed on + programmable logic (FPGA). The driver probes the hardware for + its capabilities, and creates device files accordingly. + + Set to M if you want Xillybus to use USB for communicating with + the FPGA.
drivers/staging/xillyusb/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for XillyUSB driver +# + +obj-$(CONFIG_XILLYUSB) += xillyusb.o
drivers/staging/xillyusb/TODO new file +13 -0
@@ -0,0 +1,13 @@ +XillyUSB driver +=============== + +This driver is the USB counterpart for the driver at drivers/char/xillybus/. +See Documentation/driver-api/xillybus.rst. + +TODO +---- + - Enhance code reuse with the existing Xillybus driver. + + - General code review. + +Patches to: Eli Billauer <[email protected]>
drivers/staging/xillyusb/xillyusb.c new file +2184 -0
2,184 lines not on this page · raw message
Signature · 1 line
2.17.1