2020-03-12 14:44:35

by Vladimir Stankovic

[permalink] [raw]
Subject: [PATCH v3 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 | 2 +
drivers/usb/mausb_host/Kconfig | 14 +++++
drivers/usb/mausb_host/Makefile | 12 ++++
drivers/usb/mausb_host/mausb_core.c | 90 +++++++++++++++++++++++++++++
drivers/usb/mausb_host/utils.c | 85 +++++++++++++++++++++++++++
drivers/usb/mausb_host/utils.h | 40 +++++++++++++
8 files changed, 252 insertions(+)
create mode 100644 drivers/usb/mausb_host/Kconfig
create mode 100644 drivers/usb/mausb_host/Makefile
create mode 100644 drivers/usb/mausb_host/mausb_core.c
create mode 100644 drivers/usb/mausb_host/utils.c
create mode 100644 drivers/usb/mausb_host/utils.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 235ab38ed478..12aac44196d7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10226,6 +10226,13 @@ W: https://linuxtv.org
S: Maintained
F: drivers/media/radio/radio-maxiradio*
+MA USB HOST DRIVER
+M: Vladimir Stankovic <[email protected]>
+L: [email protected]
+W: https://www.displaylink.com
+S: Maintained
+F: drivers/usb/mausb_host/*
+
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..4e92f1fa0fa5 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -164,6 +164,8 @@ source "drivers/usb/misc/Kconfig"
source "drivers/usb/atm/Kconfig"
+source "drivers/usb/mausb_host/Kconfig"
+
endif # USB
source "drivers/usb/phy/Kconfig"
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 1c1c1d659394..22d1998db0e2 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -66,3 +66,5 @@ obj-$(CONFIG_USBIP_CORE) += usbip/
obj-$(CONFIG_TYPEC) += typec/
obj-$(CONFIG_USB_ROLE_SWITCH) += roles/
+
+obj-$(CONFIG_HOST_MAUSB) += mausb_host/
diff --git a/drivers/usb/mausb_host/Kconfig b/drivers/usb/mausb_host/Kconfig
new file mode 100644
index 000000000000..2465aac713fe
--- /dev/null
+++ b/drivers/usb/mausb_host/Kconfig
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Kernel configuration file for MA-USB Host driver.
+#
+# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+#
+
+config HOST_MAUSB
+ tristate "MA-USB Host Driver"
+ depends on USB=y
+ default n
+ help
+ This is a MA-USB Host driver which enables host communication
+ via MA-USB protocol stack.
diff --git a/drivers/usb/mausb_host/Makefile
b/drivers/usb/mausb_host/Makefile
new file mode 100644
index 000000000000..2e353fa0958b
--- /dev/null
+++ b/drivers/usb/mausb_host/Makefile
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for DisplayLink MA-USB Host driver.
+#
+# Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+#
+
+obj-$(CONFIG_HOST_MAUSB) += mausb_host.o
+mausb_host-y := mausb_core.o
+mausb_host-y += utils.o
+
+ccflags-y += -I$(srctree)/$(src)
diff --git a/drivers/usb/mausb_host/mausb_core.c
b/drivers/usb/mausb_host/mausb_core.c
new file mode 100644
index 000000000000..8638dd0a4856
--- /dev/null
+++ b/drivers/usb/mausb_host/mausb_core.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+ */
+#include <linux/in.h>
+#include <linux/inet.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/kobject.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/net.h>
+
+#include "utils.h"
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("DisplayLink (UK) Ltd.");
+MODULE_VERSION(MAUSB_DRIVER_VERSION);
+
+static int mausb_client_connect(const char *value,
+ const struct kernel_param *kp)
+{
+ mausb_pr_info("Version=%s", MAUSB_DRIVER_VERSION);
+
+ return 0;
+}
+
+static int mausb_client_disconnect(const char *value,
+ const struct kernel_param *kp)
+{
+ mausb_pr_info("Version=%s", MAUSB_DRIVER_VERSION);
+
+ return 0;
+}
+
+static int mausb_device_connect(const char *value,
+ const struct kernel_param *kp)
+{
+ mausb_pr_info("Version=%s", MAUSB_DRIVER_VERSION);
+
+ return 0;
+}
+
+static int mausb_device_disconnect(const char *value,
+ const struct kernel_param *kp)
+{
+ mausb_pr_info("Version=%s", MAUSB_DRIVER_VERSION);
+
+ return 0;
+}
+
+static const struct kernel_param_ops mausb_device_connect_ops = {
+ .set = mausb_device_connect
+};
+
+static const struct kernel_param_ops mausb_device_disconnect_ops = {
+ .set = mausb_device_disconnect
+};
+
+static const struct kernel_param_ops mausb_client_connect_ops = {
+ .set = mausb_client_connect
+};
+
+static const struct kernel_param_ops mausb_client_disconnect_ops = {
+ .set = mausb_client_disconnect
+};
+
+static int mausb_host_init(void)
+{
+ int status = mausb_create_dev();
+
+ mausb_pr_info("Module load. Version=%s", MAUSB_DRIVER_VERSION);
+
+ if (status < 0) {
+ mausb_pr_alert("Failed to load MAUSB module!");
+ return status;
+ }
+
+ return 0;
+}
+
+static void mausb_host_exit(void)
+{
+ mausb_pr_info("Module unloading started...");
+ mausb_cleanup_dev(1);
+ mausb_pr_info("Module unloaded. Version=%s", MAUSB_DRIVER_VERSION);
+}
+
+module_init(mausb_host_init);
+module_exit(mausb_host_exit);
diff --git a/drivers/usb/mausb_host/utils.c b/drivers/usb/mausb_host/utils.c
new file mode 100644
index 000000000000..c055b578e402
--- /dev/null
+++ b/drivers/usb/mausb_host/utils.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+ */
+#include "utils.h"
+
+#include <linux/atomic.h>
+#include <linux/cdev.h>
+#include <linux/completion.h>
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+
+#define MAUSB_KERNEL_DEV_NAME "mausb_host"
+#define MAUSB_READ_DEVICE_TIMEOUT_MS 500
+
+static dev_t mausb_major_kernel;
+static struct cdev mausb_kernel_dev;
+static struct class *mausb_kernel_class;
+
+static int mausb_file_open(struct inode *inode, struct file *filp)
+{
+ filp->private_data = NULL;
+
+ return 0;
+}
+
+static int mausb_file_close(struct inode *inode, struct file *filp)
+{
+ kfree(filp->private_data);
+ filp->private_data = NULL;
+
+ return 0;
+}
+
+static const struct file_operations mausb_file_ops = {
+ .open = mausb_file_open,
+ .release = mausb_file_close,
+};
+
+int mausb_create_dev(void)
+{
+ int device_created = 0;
+ int status = alloc_chrdev_region(&mausb_major_kernel, 0, 1,
+ MAUSB_KERNEL_DEV_NAME "_proc");
+ if (status)
+ goto cleanup;
+
+ mausb_kernel_class = class_create(THIS_MODULE,
+ MAUSB_KERNEL_DEV_NAME "_sys");
+ if (!mausb_kernel_class) {
+ status = -ENOMEM;
+ goto cleanup;
+ }
+
+ if (!device_create(mausb_kernel_class, NULL, mausb_major_kernel, NULL,
+ MAUSB_KERNEL_DEV_NAME "_dev")) {
+ status = -ENOMEM;
+ goto cleanup;
+ }
+ device_created = 1;
+ cdev_init(&mausb_kernel_dev, &mausb_file_ops);
+ status = cdev_add(&mausb_kernel_dev, mausb_major_kernel, 1);
+ if (status)
+ goto cleanup;
+ return 0;
+cleanup:
+ mausb_cleanup_dev(device_created);
+ return status;
+}
+
+void mausb_cleanup_dev(int device_created)
+{
+ if (device_created) {
+ device_destroy(mausb_kernel_class, mausb_major_kernel);
+ cdev_del(&mausb_kernel_dev);
+ }
+
+ if (mausb_kernel_class)
+ class_destroy(mausb_kernel_class);
+
+ unregister_chrdev_region(mausb_major_kernel, 1);
+}
diff --git a/drivers/usb/mausb_host/utils.h b/drivers/usb/mausb_host/utils.h
new file mode 100644
index 000000000000..699f94fcb75b
--- /dev/null
+++ b/drivers/usb/mausb_host/utils.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd.
+ */
+#ifndef __MAUSB_UTILS_H__
+#define __MAUSB_UTILS_H__
+
+#if defined(MAUSB_NO_LOGS)
+#define mausb_pr_logs(...)
+#else
+#include <linux/printk.h>
+#include <linux/sched.h>
+#define mausb_pr_logs(level_str, level, log, ...)\
+ pr_##level_str("MAUSB " #level " [%x:%x] [%s] " log "\n",\
+ current->pid, current->tgid, __func__, ##__VA_ARGS__)
+#endif /* MAUSB_NO_LOGS */
+
+#define mausb_pr_alert(...) mausb_pr_logs(alert, 1, ##__VA_ARGS__)
+
+#define mausb_pr_err(...) mausb_pr_logs(err, 2, ##__VA_ARGS__)
+
+#define mausb_pr_warn(...) mausb_pr_logs(warn, 3, ##__VA_ARGS__)
+
+#define mausb_pr_info(...) mausb_pr_logs(info, 4, ##__VA_ARGS__)
+
+#if defined(MAUSB_LOG_VERBOSE)
+ #define mausb_pr_debug(...) mausb_pr_logs(debug, 5, ##__VA_ARGS__)
+#else
+ #define mausb_pr_debug(...)
+#endif /* defined(MAUSB_LOG_VERBOSE) */
+
+#define MAUSB_STRINGIFY2(x) #x
+#define MAUSB_STRINGIFY(x) MAUSB_STRINGIFY2(x)
+
+#define MAUSB_DRIVER_VERSION MAUSB_STRINGIFY(1.2.0.0.36451aec)
+
+int mausb_create_dev(void);
+void mausb_cleanup_dev(int device_created);
+
+#endif /* __MAUSB_UTILS_H__ */
--
2.17.1



2020-03-12 15:23:08

by Greg Kroah-Hartman

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

On Thu, Mar 12, 2020 at 03:42:30PM +0100, 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 | 2 +
> drivers/usb/mausb_host/Kconfig | 14 +++++
> drivers/usb/mausb_host/Makefile | 12 ++++
> drivers/usb/mausb_host/mausb_core.c | 90 +++++++++++++++++++++++++++++
> drivers/usb/mausb_host/utils.c | 85 +++++++++++++++++++++++++++
> drivers/usb/mausb_host/utils.h | 40 +++++++++++++
> 8 files changed, 252 insertions(+)
> create mode 100644 drivers/usb/mausb_host/Kconfig
> create mode 100644 drivers/usb/mausb_host/Makefile
> create mode 100644 drivers/usb/mausb_host/mausb_core.c
> create mode 100644 drivers/usb/mausb_host/utils.c
> create mode 100644 drivers/usb/mausb_host/utils.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 235ab38ed478..12aac44196d7 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -10226,6 +10226,13 @@ W: https://linuxtv.org
> S: Maintained
> F: drivers/media/radio/radio-maxiradio*
> +MA USB HOST DRIVER
> +M: Vladimir Stankovic <[email protected]>
> +L: [email protected]
> +W: https://www.displaylink.com
> +S: Maintained
> +F: drivers/usb/mausb_host/*
> +
> MCAN MMIO DEVICE DRIVER
> M: Dan Murphy <[email protected]>
> M: Sriram Dash <[email protected]>

Does that patch look correct?

Does this apply?

Something is odd here :(


> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
> index 275568abc670..4e92f1fa0fa5 100644
> --- a/drivers/usb/Kconfig
> +++ b/drivers/usb/Kconfig
> @@ -164,6 +164,8 @@ source "drivers/usb/misc/Kconfig"
> source "drivers/usb/atm/Kconfig"
> +source "drivers/usb/mausb_host/Kconfig"
> +
> endif # USB
> source "drivers/usb/phy/Kconfig"

Yeah, something is really wrong with your email client :(

Can you use 'git send-email' to send all of these out so they do not get
corrupted?

That will also fix the lack of email threading which this series still
has as well.

thanks,

greg k-h

2020-03-12 16:25:55

by Vladimir Stankovic

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

On 12.3.20. 16:20, Greg KH wrote:
> On Thu, Mar 12, 2020 at 03:42:30PM +0100, 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 | 2 +
> > drivers/usb/mausb_host/Kconfig | 14 +++++
> > drivers/usb/mausb_host/Makefile | 12 ++++
> > drivers/usb/mausb_host/mausb_core.c | 90 +++++++++++++++++++++++++++++
> > drivers/usb/mausb_host/utils.c | 85 +++++++++++++++++++++++++++
> > drivers/usb/mausb_host/utils.h | 40 +++++++++++++
> > 8 files changed, 252 insertions(+)
> > create mode 100644 drivers/usb/mausb_host/Kconfig
> > create mode 100644 drivers/usb/mausb_host/Makefile
> > create mode 100644 drivers/usb/mausb_host/mausb_core.c
> > create mode 100644 drivers/usb/mausb_host/utils.c
> > create mode 100644 drivers/usb/mausb_host/utils.h
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 235ab38ed478..12aac44196d7 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -10226,6 +10226,13 @@ W: https://linuxtv.org
> <https://linuxtv.org>
> > S: Maintained
> > F: drivers/media/radio/radio-maxiradio*
> > +MA USB HOST DRIVER
> > +M: Vladimir Stankovic <[email protected]>
> > +L: [email protected]
> > +W: https://www.displaylink.com
> <https://www.displaylink.com>
> > +S: Maintained
> > +F: drivers/usb/mausb_host/*
> > +
> > MCAN MMIO DEVICE DRIVER
> > M: Dan Murphy <[email protected]>
> > M: Sriram Dash <[email protected]>
>
> Does that patch look correct?
>
> Does this apply?
>
> Something is odd here :(
>
>
> > diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
> > index 275568abc670..4e92f1fa0fa5 100644
> > --- a/drivers/usb/Kconfig
> > +++ b/drivers/usb/Kconfig
> > @@ -164,6 +164,8 @@ source "drivers/usb/misc/Kconfig"
> > source "drivers/usb/atm/Kconfig"
> > +source "drivers/usb/mausb_host/Kconfig"
> > +
> > endif # USB
> > source "drivers/usb/phy/Kconfig"
>
> Yeah, something is really wrong with your email client :(
>
> Can you use 'git send-email' to send all of these out so they do not get
> corrupted?
>
> That will also fix the lack of email threading which this series still
> has as well.
>
> thanks,
>
> greg k-h
I'd say it's the issue with mail server used by company, since patches
and mails were generated via git (i.e. used git imap-send to create mail
drafts). One of the reasons we've sent attachments in the first version
of the patch was to avoid weird mail client/server issues.

Anyhow, I've tried applying diffs from linux-usb mailthread and from
patchwork, and that failed as expected, stating that patch is corrupt.
However, comparison of those diffs with the .patch file generated with
git, provided somewhat odd result: only first 30+ lines of the diff
(mail headers excluded) contained additional space chars that are not
part of the git-generated .patch files (specifically, a single space
char is added at the start of each line that is not being modified by
the patch itself; only Kconfig, Makefile, and MAINTAINERS are affected);
the rest of the diff (new source code) matched with .patch file.

Been expecting "tabs vs spaces" issue that is specific to mail
clients/servers, but this makes it a bit odd.

Will check if this issue (prepended single space chars) is already
reported/fixed within the community.

Regards,
Vladimir.

2020-03-12 16:33:45

by Greg Kroah-Hartman

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

On Thu, Mar 12, 2020 at 05:23:53PM +0100, Vladimir Stankovic wrote:
> On 12.3.20. 16:20, Greg KH wrote:
> > On Thu, Mar 12, 2020 at 03:42:30PM +0100, 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 | 2 +
> > > drivers/usb/mausb_host/Kconfig | 14 +++++
> > > drivers/usb/mausb_host/Makefile | 12 ++++
> > > drivers/usb/mausb_host/mausb_core.c | 90 +++++++++++++++++++++++++++++
> > > drivers/usb/mausb_host/utils.c | 85 +++++++++++++++++++++++++++
> > > drivers/usb/mausb_host/utils.h | 40 +++++++++++++
> > > 8 files changed, 252 insertions(+)
> > > create mode 100644 drivers/usb/mausb_host/Kconfig
> > > create mode 100644 drivers/usb/mausb_host/Makefile
> > > create mode 100644 drivers/usb/mausb_host/mausb_core.c
> > > create mode 100644 drivers/usb/mausb_host/utils.c
> > > create mode 100644 drivers/usb/mausb_host/utils.h
> > >
> > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > index 235ab38ed478..12aac44196d7 100644
> > > --- a/MAINTAINERS
> > > +++ b/MAINTAINERS
> > > @@ -10226,6 +10226,13 @@ W: https://linuxtv.org <https://linuxtv.org>
> > > S: Maintained
> > > F: drivers/media/radio/radio-maxiradio*
> > > +MA USB HOST DRIVER
> > > +M: Vladimir Stankovic <[email protected]>
> > > +L: [email protected]
> > > +W: https://www.displaylink.com <https://www.displaylink.com>
> > > +S: Maintained
> > > +F: drivers/usb/mausb_host/*
> > > +
> > > MCAN MMIO DEVICE DRIVER
> > > M: Dan Murphy <[email protected]>
> > > M: Sriram Dash <[email protected]>
> >
> > Does that patch look correct?
> >
> > Does this apply?
> >
> > Something is odd here :(
> >
> >
> > > diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
> > > index 275568abc670..4e92f1fa0fa5 100644
> > > --- a/drivers/usb/Kconfig
> > > +++ b/drivers/usb/Kconfig
> > > @@ -164,6 +164,8 @@ source "drivers/usb/misc/Kconfig"
> > > source "drivers/usb/atm/Kconfig"
> > > +source "drivers/usb/mausb_host/Kconfig"
> > > +
> > > endif # USB
> > > source "drivers/usb/phy/Kconfig"
> >
> > Yeah, something is really wrong with your email client :(
> >
> > Can you use 'git send-email' to send all of these out so they do not get
> > corrupted?
> >
> > That will also fix the lack of email threading which this series still
> > has as well.
> >
> > thanks,
> >
> > greg k-h
> I'd say it's the issue with mail server used by company, since patches and
> mails were generated via git (i.e. used git imap-send to create mail
> drafts). One of the reasons we've sent attachments in the first version of
> the patch was to avoid weird mail client/server issues.

If this is an Exchange server, you can give up now, they are known to
corrupt patches. There is some "magic" settings you can do to the
server, but personally I do not know what they are.

good luck!

greg k-h