2020-05-15 12:38:34

by Vladimir Stankovic

[permalink] [raw]
Subject: [PATCH v6 1/8] usb: Add MA-USB Host kernel module

Added utility macros, kernel device creation and cleanup, functions for
handling log formatting and a placeholder module for MA-USB Host device
driver.

Signed-off-by: Vladimir Stankovic <[email protected]>
---
MAINTAINERS | 7 +++++
drivers/usb/Kconfig | 2 ++
drivers/usb/Makefile | 1 +
drivers/usb/host/mausb/Kconfig | 15 +++++++++
drivers/usb/host/mausb/Makefile | 10 ++++++
drivers/usb/host/mausb/mausb_core.c | 24 +++++++++++++++
drivers/usb/host/mausb/utils.c | 47 +++++++++++++++++++++++++++++
drivers/usb/host/mausb/utils.h | 15 +++++++++
8 files changed, 121 insertions(+)
create mode 100644 drivers/usb/host/mausb/Kconfig
create mode 100644 drivers/usb/host/mausb/Makefile
create mode 100644 drivers/usb/host/mausb/mausb_core.c
create mode 100644 drivers/usb/host/mausb/utils.c
create mode 100644 drivers/usb/host/mausb/utils.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 091ec22c1a23..9b7b79215f47 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10343,6 +10343,13 @@ W: https://linuxtv.org
T: git git://linuxtv.org/media_tree.git
F: drivers/media/radio/radio-maxiradio*

+MEDIA AGNOSTIC (MA) USB HOST DRIVER
+M: Vladimir Stankovic <[email protected]>
+L: [email protected]
+W: https://www.displaylink.com
+S: Maintained
+F: drivers/usb/host/mausb/*
+
MCAN MMIO DEVICE DRIVER
M: Dan Murphy <[email protected]>
M: Sriram Dash <[email protected]>
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 275568abc670..35f5c3ac6656 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -99,6 +99,8 @@ source "drivers/usb/mon/Kconfig"

source "drivers/usb/host/Kconfig"

+source "drivers/usb/host/mausb/Kconfig"
+
source "drivers/usb/renesas_usbhs/Kconfig"

source "drivers/usb/class/Kconfig"
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 1c1c1d659394..2389b55723ab 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_USB_IMX21_HCD) += host/
obj-$(CONFIG_USB_FSL_USB2) += host/
obj-$(CONFIG_USB_FOTG210_HCD) += host/
obj-$(CONFIG_USB_MAX3421_HCD) += host/
+obj-$(CONFIG_USB_HOST_MAUSB) += host/mausb/

obj-$(CONFIG_USB_C67X00_HCD) += c67x00/

diff --git a/drivers/usb/host/mausb/Kconfig b/drivers/usb/host/mausb/Kconfig
new file mode 100644
index 000000000000..ba72ef42f942
--- /dev/null
+++ b/drivers/usb/host/mausb/Kconfig
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Kernel configuration file for MA-USB Host driver.
+#
+# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+#
+
+config USB_HOST_MAUSB
+ tristate "Media Agnostic (MA) USB Host Driver"
+ depends on USB=y
+ help
+ This is a Media Agnostic (MA) USB Host driver which enables host
+ communication via MA USB protocol stack.
+
+ If this driver is compiled as a module, it will be named mausb_host.
diff --git a/drivers/usb/host/mausb/Makefile b/drivers/usb/host/mausb/Makefile
new file mode 100644
index 000000000000..cafccac0edba
--- /dev/null
+++ b/drivers/usb/host/mausb/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for DisplayLink MA-USB Host driver.
+#
+# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+#
+
+obj-$(CONFIG_USB_HOST_MAUSB) += mausb_host.o
+mausb_host-y := mausb_core.o
+mausb_host-y += utils.o
diff --git a/drivers/usb/host/mausb/mausb_core.c b/drivers/usb/host/mausb/mausb_core.c
new file mode 100644
index 000000000000..44f76a1b74de
--- /dev/null
+++ b/drivers/usb/host/mausb/mausb_core.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+ */
+#include <linux/module.h>
+
+#include "utils.h"
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("DisplayLink (UK) Ltd.");
+
+static int mausb_host_init(void)
+{
+ return mausb_host_dev_register();
+}
+
+static void mausb_host_exit(void)
+{
+ dev_info(mausb_host_dev.this_device, "Module unloading started...");
+ mausb_host_dev_deregister();
+}
+
+module_init(mausb_host_init);
+module_exit(mausb_host_exit);
diff --git a/drivers/usb/host/mausb/utils.c b/drivers/usb/host/mausb/utils.c
new file mode 100644
index 000000000000..1cfa2140311e
--- /dev/null
+++ b/drivers/usb/host/mausb/utils.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+ */
+#include "utils.h"
+
+#include <linux/fs.h>
+#include <linux/slab.h>
+
+#define MAUSB_KERNEL_DEV_NAME "mausb_host"
+#define MAUSB_READ_DEVICE_TIMEOUT_MS 500
+
+struct miscdevice mausb_host_dev;
+
+static int mausb_host_dev_open(struct inode *inode, struct file *filp)
+{
+ filp->private_data = NULL;
+
+ return 0;
+}
+
+static int mausb_host_dev_release(struct inode *inode, struct file *filp)
+{
+ kfree(filp->private_data);
+ filp->private_data = NULL;
+
+ return 0;
+}
+
+static const struct file_operations mausb_host_dev_fops = {
+ .open = mausb_host_dev_open,
+ .release = mausb_host_dev_release,
+};
+
+int mausb_host_dev_register(void)
+{
+ mausb_host_dev.minor = MISC_DYNAMIC_MINOR;
+ mausb_host_dev.name = MAUSB_KERNEL_DEV_NAME;
+ mausb_host_dev.fops = &mausb_host_dev_fops;
+ mausb_host_dev.mode = 0;
+ return misc_register(&mausb_host_dev);
+}
+
+void mausb_host_dev_deregister(void)
+{
+ misc_deregister(&mausb_host_dev);
+}
diff --git a/drivers/usb/host/mausb/utils.h b/drivers/usb/host/mausb/utils.h
new file mode 100644
index 000000000000..e810e691c39d
--- /dev/null
+++ b/drivers/usb/host/mausb/utils.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+ */
+#ifndef __MAUSB_UTILS_H__
+#define __MAUSB_UTILS_H__
+
+#include <linux/miscdevice.h>
+
+extern struct miscdevice mausb_host_dev;
+
+int mausb_host_dev_register(void);
+void mausb_host_dev_deregister(void);
+
+#endif /* __MAUSB_UTILS_H__ */
--
2.17.1


2020-05-15 13:04:21

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v6 1/8] usb: Add MA-USB Host kernel module

On Fri, May 15, 2020 at 02:34:55PM +0200, Vladimir Stankovic wrote:
> --- /dev/null
> +++ b/drivers/usb/host/mausb/Kconfig
> @@ -0,0 +1,15 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Kernel configuration file for MA-USB Host driver.
> +#
> +# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
> +#
> +
> +config USB_HOST_MAUSB
> + tristate "Media Agnostic (MA) USB Host Driver"
> + depends on USB=y

Why =y? That should not be a requirement for any usb host driver.

> + help
> + This is a Media Agnostic (MA) USB Host driver which enables host
> + communication via MA USB protocol stack.
> +
> + If this driver is compiled as a module, it will be named mausb_host.

Provide links to the userspace and spec here so that people have a
chance to be able to use this driver?



> diff --git a/drivers/usb/host/mausb/Makefile b/drivers/usb/host/mausb/Makefile
> new file mode 100644
> index 000000000000..cafccac0edba
> --- /dev/null
> +++ b/drivers/usb/host/mausb/Makefile
> @@ -0,0 +1,10 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Makefile for DisplayLink MA-USB Host driver.
> +#
> +# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
> +#
> +
> +obj-$(CONFIG_USB_HOST_MAUSB) += mausb_host.o
> +mausb_host-y := mausb_core.o
> +mausb_host-y += utils.o
> diff --git a/drivers/usb/host/mausb/mausb_core.c b/drivers/usb/host/mausb/mausb_core.c
> new file mode 100644
> index 000000000000..44f76a1b74de
> --- /dev/null
> +++ b/drivers/usb/host/mausb/mausb_core.c
> @@ -0,0 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
> + */
> +#include <linux/module.h>
> +
> +#include "utils.h"
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("DisplayLink (UK) Ltd.");
> +
> +static int mausb_host_init(void)
> +{
> + return mausb_host_dev_register();
> +}
> +
> +static void mausb_host_exit(void)
> +{
> + dev_info(mausb_host_dev.this_device, "Module unloading started...");
> + mausb_host_dev_deregister();
> +}
> +
> +module_init(mausb_host_init);
> +module_exit(mausb_host_exit);
> diff --git a/drivers/usb/host/mausb/utils.c b/drivers/usb/host/mausb/utils.c
> new file mode 100644
> index 000000000000..1cfa2140311e
> --- /dev/null
> +++ b/drivers/usb/host/mausb/utils.c
> @@ -0,0 +1,47 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
> + */
> +#include "utils.h"
> +
> +#include <linux/fs.h>
> +#include <linux/slab.h>
> +
> +#define MAUSB_KERNEL_DEV_NAME "mausb_host"
> +#define MAUSB_READ_DEVICE_TIMEOUT_MS 500
> +
> +struct miscdevice mausb_host_dev;
> +
> +static int mausb_host_dev_open(struct inode *inode, struct file *filp)
> +{
> + filp->private_data = NULL;
> +
> + return 0;
> +}
> +
> +static int mausb_host_dev_release(struct inode *inode, struct file *filp)
> +{
> + kfree(filp->private_data);
> + filp->private_data = NULL;
> +
> + return 0;
> +}
> +
> +static const struct file_operations mausb_host_dev_fops = {
> + .open = mausb_host_dev_open,
> + .release = mausb_host_dev_release,
> +};
> +
> +int mausb_host_dev_register(void)
> +{
> + mausb_host_dev.minor = MISC_DYNAMIC_MINOR;
> + mausb_host_dev.name = MAUSB_KERNEL_DEV_NAME;
> + mausb_host_dev.fops = &mausb_host_dev_fops;
> + mausb_host_dev.mode = 0;

You only have 1 device in the system at a time? With a global
structure? And no locking at all?

That feels _very_ wrong, why?

And mode of 0? You don't want any userspace code to use this device
node?

confused,

greg k-h

2020-05-15 13:05:13

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v6 1/8] usb: Add MA-USB Host kernel module

On Fri, May 15, 2020 at 02:34:55PM +0200, Vladimir Stankovic wrote:
> Added utility macros, kernel device creation and cleanup, functions for
> handling log formatting and a placeholder module for MA-USB Host device
> driver.
>
> Signed-off-by: Vladimir Stankovic <[email protected]>
> ---
> MAINTAINERS | 7 +++++
> drivers/usb/Kconfig | 2 ++
> drivers/usb/Makefile | 1 +
> drivers/usb/host/mausb/Kconfig | 15 +++++++++
> drivers/usb/host/mausb/Makefile | 10 ++++++
> drivers/usb/host/mausb/mausb_core.c | 24 +++++++++++++++
> drivers/usb/host/mausb/utils.c | 47 +++++++++++++++++++++++++++++
> drivers/usb/host/mausb/utils.h | 15 +++++++++
> 8 files changed, 121 insertions(+)
> create mode 100644 drivers/usb/host/mausb/Kconfig
> create mode 100644 drivers/usb/host/mausb/Makefile
> create mode 100644 drivers/usb/host/mausb/mausb_core.c
> create mode 100644 drivers/usb/host/mausb/utils.c
> create mode 100644 drivers/usb/host/mausb/utils.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 091ec22c1a23..9b7b79215f47 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -10343,6 +10343,13 @@ W: https://linuxtv.org
> T: git git://linuxtv.org/media_tree.git
> F: drivers/media/radio/radio-maxiradio*
>
> +MEDIA AGNOSTIC (MA) USB HOST DRIVER
> +M: Vladimir Stankovic <[email protected]>
> +L: [email protected]

Please just do this on the linux-usb mailing list, why have a whole new
list for just a single small driver?

thanks,

greg k-h

2020-06-11 18:28:30

by Vladimir Stankovic

[permalink] [raw]
Subject: Re: [External] Re: [PATCH v6 1/8] usb: Add MA-USB Host kernel module

On 15.5.20. 15:02, Greg KH wrote:
> On Fri, May 15, 2020 at 02:34:55PM +0200, Vladimir Stankovic wrote:
>> Added utility macros, kernel device creation and cleanup, functions for
>> handling log formatting and a placeholder module for MA-USB Host device
>> driver.
>>
>> Signed-off-by: Vladimir Stankovic <[email protected]>
>> ---
>> MAINTAINERS | 7 +++++
>> drivers/usb/Kconfig | 2 ++
>> drivers/usb/Makefile | 1 +
>> drivers/usb/host/mausb/Kconfig | 15 +++++++++
>> drivers/usb/host/mausb/Makefile | 10 ++++++
>> drivers/usb/host/mausb/mausb_core.c | 24 +++++++++++++++
>> drivers/usb/host/mausb/utils.c | 47 +++++++++++++++++++++++++++++
>> drivers/usb/host/mausb/utils.h | 15 +++++++++
>> 8 files changed, 121 insertions(+)
>> create mode 100644 drivers/usb/host/mausb/Kconfig
>> create mode 100644 drivers/usb/host/mausb/Makefile
>> create mode 100644 drivers/usb/host/mausb/mausb_core.c
>> create mode 100644 drivers/usb/host/mausb/utils.c
>> create mode 100644 drivers/usb/host/mausb/utils.h
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 091ec22c1a23..9b7b79215f47 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -10343,6 +10343,13 @@ W: https://linuxtv.org
>> T: git git://linuxtv.org/media_tree.git
>> F: drivers/media/radio/radio-maxiradio*
>>
>> +MEDIA AGNOSTIC (MA) USB HOST DRIVER
>> +M: Vladimir Stankovic <[email protected]>
>> +L: [email protected]
>
> Please just do this on the linux-usb mailing list, why have a whole new
> list for just a single small driver?
>
> thanks,
>
> greg k-h
>
Idea was to have the team notified about any comment/issue within the
driver. However, as you noted, same can be achieved with linux-usb
subscriptions.

--
Regards,
Vladimir.

2020-06-11 18:29:13

by Vladimir Stankovic

[permalink] [raw]
Subject: Re: [PATCH v6 1/8] usb: Add MA-USB Host kernel module

On 15.5.20. 15:01, Greg KH wrote:
> On Fri, May 15, 2020 at 02:34:55PM +0200, Vladimir Stankovic wrote:
>> --- /dev/null
>> +++ b/drivers/usb/host/mausb/Kconfig
>> @@ -0,0 +1,15 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +#
>> +# Kernel configuration file for MA-USB Host driver.
>> +#
>> +# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
>> +#
>> +
>> +config USB_HOST_MAUSB
>> + tristate "Media Agnostic (MA) USB Host Driver"
>> + depends on USB=y
>
> Why =y? That should not be a requirement for any usb host driver.
With current driver in-tree location, it's not needed. Will be removed.
>
>> + help
>> + This is a Media Agnostic (MA) USB Host driver which enables host
>> + communication via MA USB protocol stack.
>> +
>> + If this driver is compiled as a module, it will be named mausb_host.
>
> Provide links to the userspace and spec here so that people have a
> chance to be able to use this driver?
>
>
>
>> diff --git a/drivers/usb/host/mausb/Makefile b/drivers/usb/host/mausb/Makefile
>> new file mode 100644
>> index 000000000000..cafccac0edba
>> --- /dev/null
>> +++ b/drivers/usb/host/mausb/Makefile
>> @@ -0,0 +1,10 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +#
>> +# Makefile for DisplayLink MA-USB Host driver.
>> +#
>> +# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
>> +#
>> +
>> +obj-$(CONFIG_USB_HOST_MAUSB) += mausb_host.o
>> +mausb_host-y := mausb_core.o
>> +mausb_host-y += utils.o
>> diff --git a/drivers/usb/host/mausb/mausb_core.c b/drivers/usb/host/mausb/mausb_core.c
>> new file mode 100644
>> index 000000000000..44f76a1b74de
>> --- /dev/null
>> +++ b/drivers/usb/host/mausb/mausb_core.c
>> @@ -0,0 +1,24 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
>> + */
>> +#include <linux/module.h>
>> +
>> +#include "utils.h"
>> +
>> +MODULE_LICENSE("GPL");
>> +MODULE_AUTHOR("DisplayLink (UK) Ltd.");
>> +
>> +static int mausb_host_init(void)
>> +{
>> + return mausb_host_dev_register();
>> +}
>> +
>> +static void mausb_host_exit(void)
>> +{
>> + dev_info(mausb_host_dev.this_device, "Module unloading started...");
>> + mausb_host_dev_deregister();
>> +}
>> +
>> +module_init(mausb_host_init);
>> +module_exit(mausb_host_exit);
>> diff --git a/drivers/usb/host/mausb/utils.c b/drivers/usb/host/mausb/utils.c
>> new file mode 100644
>> index 000000000000..1cfa2140311e
>> --- /dev/null
>> +++ b/drivers/usb/host/mausb/utils.c
>> @@ -0,0 +1,47 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
>> + */
>> +#include "utils.h"
>> +
>> +#include <linux/fs.h>
>> +#include <linux/slab.h>
>> +
>> +#define MAUSB_KERNEL_DEV_NAME "mausb_host"
>> +#define MAUSB_READ_DEVICE_TIMEOUT_MS 500
>> +
>> +struct miscdevice mausb_host_dev;
>> +
>> +static int mausb_host_dev_open(struct inode *inode, struct file *filp)
>> +{
>> + filp->private_data = NULL;
>> +
>> + return 0;
>> +}
>> +
>> +static int mausb_host_dev_release(struct inode *inode, struct file *filp)
>> +{
>> + kfree(filp->private_data);
>> + filp->private_data = NULL;
>> +
>> + return 0;
>> +}
>> +
>> +static const struct file_operations mausb_host_dev_fops = {
>> + .open = mausb_host_dev_open,
>> + .release = mausb_host_dev_release,
>> +};
>> +
>> +int mausb_host_dev_register(void)
>> +{
>> + mausb_host_dev.minor = MISC_DYNAMIC_MINOR;
>> + mausb_host_dev.name = MAUSB_KERNEL_DEV_NAME;
>> + mausb_host_dev.fops = &mausb_host_dev_fops;
>> + mausb_host_dev.mode = 0;
>
> You only have 1 device in the system at a time? With a global
> structure? And no locking at all?
>
> That feels _very_ wrong, why?
>
> And mode of 0? You don't want any userspace code to use this device
> node?
>
> confused,
>
> greg k-h
>
Agree. This will be revised in following patch version.


--
Regards,
Vladimir.