Add MA USB Host driver
v3 cover Add MA USB Host driver
Media Agnostic Universal Serial Bus (MA USB) Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
This driver depends on the functions provided by DisplayLink's user-space driver.
v2:
- Fixed licensing info in headers
- Reorganized code to lower file count
- Patch has been split into 8 smaller patches
v3:
- Fixed nested spinlock usage
- Implemented IPv6 support
Vladimir Stankovic (8):
usb: Add MA-USB Host kernel module
usb: mausb_host: Add link layer implementation
usb: mausb_host: HCD initialization
usb: mausb_host: Implement initial hub handlers
usb: mausb_host: Introduce PAL processing
usb: mausb_host: Add logic for PAL-to-PAL communication
usb: mausb_host: MA-USB PAL events processing
usb: mausb_host: Process MA-USB data packets
MAINTAINERS | 7 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/mausb_host/Kconfig | 14 + drivers/usb/mausb_host/Makefile | 17 + drivers/usb/mausb_host/hcd.c | 1897 ++++++++++++++++ drivers/usb/mausb_host/hcd.h | 162 ++ drivers/usb/mausb_host/hpal.c | 2083 ++++++++++++++++++ drivers/usb/mausb_host/hpal.h | 339 +++ drivers/usb/mausb_host/hpal_data.c | 719 ++++++ drivers/usb/mausb_host/hpal_data.h | 34 + drivers/usb/mausb_host/hpal_events.c | 611 +++++ drivers/usb/mausb_host/hpal_events.h | 85 + drivers/usb/mausb_host/ip_link.c | 374 ++++ drivers/usb/mausb_host/ip_link.h | 87 + drivers/usb/mausb_host/ma_usb.h | 869 ++++++++ drivers/usb/mausb_host/mausb_address.h | 26 + drivers/usb/mausb_host/mausb_core.c | 212 ++ drivers/usb/mausb_host/mausb_driver_status.h | 17 + drivers/usb/mausb_host/mausb_event.h | 224 ++ drivers/usb/mausb_host/utils.c | 360 +++ drivers/usb/mausb_host/utils.h | 45 + 22 files changed, 8186 insertions(+) create mode 100644 drivers/usb/mausb_host/Kconfig create mode 100644 drivers/usb/mausb_host/Makefile create mode 100644 drivers/usb/mausb_host/hcd.c create mode 100644 drivers/usb/mausb_host/hcd.h create mode 100644 drivers/usb/mausb_host/hpal.c create mode 100644 drivers/usb/mausb_host/hpal.h create mode 100644 drivers/usb/mausb_host/hpal_data.c create mode 100644 drivers/usb/mausb_host/hpal_data.h create mode 100644 drivers/usb/mausb_host/hpal_events.c create mode 100644 drivers/usb/mausb_host/hpal_events.h create mode 100644 drivers/usb/mausb_host/ip_link.c create mode 100644 drivers/usb/mausb_host/ip_link.h create mode 100644 drivers/usb/mausb_host/ma_usb.h create mode 100644 drivers/usb/mausb_host/mausb_address.h create mode 100644 drivers/usb/mausb_host/mausb_core.c create mode 100644 drivers/usb/mausb_host/mausb_driver_status.h create mode 100644 drivers/usb/mausb_host/mausb_event.h create mode 100644 drivers/usb/mausb_host/utils.c create mode 100644 drivers/usb/mausb_host/utils.h
Signature · 1 line
2.17.1
v4 cover Add MA USB Host driver
Media Agnostic Universal Serial Bus (MA USB) Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
This driver depends on the functions provided by DisplayLink's user-space driver.
v2:
- Fixed licensing info in headers
- Reorganized code to lower file count
- Patch has been split into 8 smaller patches
v3:
- Fixed nested spinlock usage
- Implemented IPv6 support
v4:
- No code changes
- Re-sent patch with different mail client config
Vladimir Stankovic (8):
usb: Add MA-USB Host kernel module
usb: mausb_host: Add link layer implementation
usb: mausb_host: HCD initialization
usb: mausb_host: Implement initial hub handlers
usb: mausb_host: Introduce PAL processing
usb: mausb_host: Add logic for PAL-to-PAL communication
usb: mausb_host: MA-USB PAL events processing
usb: mausb_host: Process MA-USB data packets
MAINTAINERS | 7 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/mausb_host/Kconfig | 14 + drivers/usb/mausb_host/Makefile | 17 + drivers/usb/mausb_host/hcd.c | 1897 ++++++++++++++++ drivers/usb/mausb_host/hcd.h | 162 ++ drivers/usb/mausb_host/hpal.c | 2083 ++++++++++++++++++ drivers/usb/mausb_host/hpal.h | 339 +++ drivers/usb/mausb_host/hpal_data.c | 719 ++++++ drivers/usb/mausb_host/hpal_data.h | 34 + drivers/usb/mausb_host/hpal_events.c | 611 +++++ drivers/usb/mausb_host/hpal_events.h | 85 + drivers/usb/mausb_host/ip_link.c | 374 ++++ drivers/usb/mausb_host/ip_link.h | 87 + drivers/usb/mausb_host/ma_usb.h | 869 ++++++++ drivers/usb/mausb_host/mausb_address.h | 26 + drivers/usb/mausb_host/mausb_core.c | 212 ++ drivers/usb/mausb_host/mausb_driver_status.h | 17 + drivers/usb/mausb_host/mausb_event.h | 224 ++ drivers/usb/mausb_host/utils.c | 360 +++ drivers/usb/mausb_host/utils.h | 45 + 22 files changed, 8186 insertions(+) create mode 100644 drivers/usb/mausb_host/Kconfig create mode 100644 drivers/usb/mausb_host/Makefile create mode 100644 drivers/usb/mausb_host/hcd.c create mode 100644 drivers/usb/mausb_host/hcd.h create mode 100644 drivers/usb/mausb_host/hpal.c create mode 100644 drivers/usb/mausb_host/hpal.h create mode 100644 drivers/usb/mausb_host/hpal_data.c create mode 100644 drivers/usb/mausb_host/hpal_data.h create mode 100644 drivers/usb/mausb_host/hpal_events.c create mode 100644 drivers/usb/mausb_host/hpal_events.h create mode 100644 drivers/usb/mausb_host/ip_link.c create mode 100644 drivers/usb/mausb_host/ip_link.h create mode 100644 drivers/usb/mausb_host/ma_usb.h create mode 100644 drivers/usb/mausb_host/mausb_address.h create mode 100644 drivers/usb/mausb_host/mausb_core.c create mode 100644 drivers/usb/mausb_host/mausb_driver_status.h create mode 100644 drivers/usb/mausb_host/mausb_event.h create mode 100644 drivers/usb/mausb_host/utils.c create mode 100644 drivers/usb/mausb_host/utils.h
Signature · 1 line
2.17.1
PATCH v4 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.
--- 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
MAINTAINERS +7 -0
@@ -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]>
drivers/usb/Kconfig +2 -0
@@ -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"
drivers/usb/Makefile +2 -0
@@ -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/
drivers/usb/mausb_host/Kconfig new file +14 -0
@@ -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.
drivers/usb/mausb_host/Makefile new file +12 -0
@@ -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)
drivers/usb/mausb_host/mausb_core.c new file +90 -0
90 lines not on this page · raw message
drivers/usb/mausb_host/utils.c new file +85 -0
85 lines not on this page · raw message
drivers/usb/mausb_host/utils.h new file +40 -0
@@ -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__ */
Signature · 1 line
2.17.1
Re: [PATCH v4 1/8] usb: Add MA-USB Host kernel module
Quoted 10 lines · On Fri, 27 Mar 2020 [email protected] 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]>index
235ab38ed478..12aac44196d7100644
MAINTAINERS W: https://linuxtv.org · line 10229
Quoted 4 lines
MAINTAINERS +1
-0@@ -10226,6 +10226,13 @@ W: https://linuxtv.org S: Maintained F: drivers/media/radio/radio-maxiradio* +MA USB HOST DRIVER
It would be an excellent idea to change this title to:
MA (MEDIA-AGNOSTIC) USB HOST DRIVER
Otherwise to me it looks like the Massachusetts USB HOST DRIVER, since MA is the 2-letter abbreviation for the state where I live. A two-letter acronym is just too generic; you mustn't expect people to understand it.
Quoted 11 lines
MAINTAINERS +6
-0+M: Vladimir Stankovic <[email protected]> +L: [email protected] +W: https://www.displaylink.com +S: Maintained +F: drivers/usb/mausb_host/* +drivers/usb/mausb_host/Kconfig new file +1
-0@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0
drivers/usb/mausb_host/Kconfig line 11
Quoted 10 lines
drivers/usb/mausb_host/Kconfig new file +10
-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
No need for this line; n is always the default setting unless you specify otherwise.
drivers/usb/mausb_host/Kconfig line 14
Quoted 3 lines
drivers/usb/mausb_host/Kconfig new file +3
-0+ help + This is a MA-USB Host driver which enables host communication + via MA-USB protocol stack.
And I insist that you insert "Media Agnostic" in here somewhere, either in the "tristate" line or in the help. Without this, people trying to configure their kernels will have no idea whether or not they should enable the setting because they won't know what MA-USB is.
It also wouldn't hurt to mention in the help text that if the driver is built as a module, the name of the module will be "mausb_host".
Alan Stern
PATCH v4 2/8 usb: mausb_host: Add link layer implementation
In reply to [email protected]Implemented link layer using kernel sockets. Link layer manages network communication and provides interface for upper layers of MA-USB stack.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/ip_link.c | 374 +++++++++++++++++++++++++++++++ drivers/usb/mausb_host/ip_link.h | 87 +++++++ 3 files changed, 462 insertions(+) create mode 100644 drivers/usb/mausb_host/ip_link.c create mode 100644 drivers/usb/mausb_host/ip_link.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -8,5 +8,6 @@ obj-$(CONFIG_HOST_MAUSB) += mausb_host.o mausb_host-y := mausb_core.o mausb_host-y += utils.o +mausb_host-y += ip_link.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/ip_link.c new file +374 -0
374 lines not on this page · raw message
drivers/usb/mausb_host/ip_link.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 3/8 usb: mausb_host: HCD initialization
In reply to [email protected]Implemented HCD initialization/deinitialization functionality.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hcd.c | 188 ++++++++++++++++++++++++++++ drivers/usb/mausb_host/hcd.h | 71 +++++++++++ drivers/usb/mausb_host/mausb_core.c | 20 ++- 4 files changed, 275 insertions(+), 5 deletions(-) create mode 100644 drivers/usb/mausb_host/hcd.c create mode 100644 drivers/usb/mausb_host/hcd.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -9,5 +9,6 @@ obj-$(CONFIG_HOST_MAUSB) += mausb_host.o mausb_host-y := mausb_core.o mausb_host-y += utils.o mausb_host-y += ip_link.o +mausb_host-y += hcd.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hcd.c new file +188 -0
188 lines not on this page · raw message
drivers/usb/mausb_host/hcd.h new file +71 -0
71 lines not on this page · raw message
drivers/usb/mausb_host/mausb_core.c +15 -5
@@ -11,6 +11,7 @@#include <linux/moduleparam.h> #include <linux/net.h> +#include "hcd.h" #include "utils.h" MODULE_LICENSE ("GPL" );
@@ -67,21 +68,30 @@ static const struct kernel_param_ops mausb_client_disconnect_ops = {static int mausb_host_init (void ) { -int status =mausb_create_dev (); +int status;mausb_pr_info ("Module load. Version=%s" ,MAUSB_DRIVER_VERSION ); + status =mausb_init_hcd (); +if (status <0 ) + goto cleanup; -if (status <0 ) { -mausb_pr_alert ("Failed to load MAUSB module!" ); -return status; - } + status =mausb_create_dev (); +if (status <0 ) + goto cleanup_hcd;return 0 ; + +cleanup_hcd: +mausb_deinit_hcd (); +cleanup: +mausb_pr_alert ("Failed to load MAUSB module!" ); +return status; }static void mausb_host_exit (void ) {mausb_pr_info ("Module unloading started..." ); +mausb_deinit_hcd ();mausb_cleanup_dev (1 );mausb_pr_info ("Module unloaded. Version=%s" ,MAUSB_DRIVER_VERSION ); }
Signature · 1 line
2.17.1
PATCH v4 4/8 usb: mausb_host: Implement initial hub handlers
In reply to [email protected]Implemented handlers for subset of HCD events.
--- drivers/usb/mausb_host/hcd.c | 964 ++++++++++++++++++++++++++++++++++- drivers/usb/mausb_host/hcd.h | 86 +++- 2 files changed, 1046 insertions(+), 4 deletions(-)
drivers/usb/mausb_host/hcd.c +963 -1
@@ -71,7 +71,7 @@ static void mausb_remove(void)static int mausb_bus_probe (struct device *dev) { -return 0 ; +return mausb_probe (dev); }static int mausb_bus_remove (struct device *dev)
@@ -159,7 +159,15 @@ int mausb_init_hcd(void) device->driver = &mausb_driver; + retval =mausb_probe (device); +if (retval) { +mausb_pr_err ("Mausb_probe failed" ); + goto mausb_probe_failed; + } +return retval; +mausb_probe_failed: +device_destroy (mausb_class, devt); device_create_error:kfree (mhcd); mhcd =NULL ;
@@ -186,3 +194,957 @@ void mausb_deinit_hcd(void)unregister_chrdev (major,DEVICE_NAME ); } } + +static const char driver_name[] ="MA-USB host controller" ; + +static void mausb_get_hub_descriptor (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length); +static void mausb_set_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static void mausb_get_port_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static void mausb_clear_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length); +static void mausb_get_hub_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static int mausb_add_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint); +static int mausb_address_device (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_alloc_dev (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_check_bandwidth (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_drop_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint); +static int mausb_enable_device (struct usb_hcd *hcd,struct usb_device *dev); +static void mausb_endpoint_disable (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint); +static void mausb_endpoint_reset (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint); +static void mausb_free_dev (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_hcd_bus_resume (struct usb_hcd *hcd); +static int mausb_hcd_bus_suspend (struct usb_hcd *hcd); +static int mausb_hcd_get_frame_number (struct usb_hcd *hcd); +static int mausb_hcd_hub_control (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static int mausb_hcd_hub_status (struct usb_hcd *hcd,char *buff); +static int mausb_hcd_reset (struct usb_hcd *hcd); +static int mausb_hcd_start (struct usb_hcd *hcd); +static void mausb_hcd_stop (struct usb_hcd *hcd); +static int mausb_hub_update_device (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_tt *tt,gfp_t mem_flags); +static void mausb_reset_bandwidth (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_reset_device (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_update_device (struct usb_hcd *hcd,struct usb_device *dev); + +static const struct hc_driver mausb_hc_driver = { + .description = driver_name, + .product_desc = driver_name, + .flags =HCD_USB3 |HCD_SHARED , + + .hcd_priv_size =sizeof (struct hub_ctx ), + + .reset = mausb_hcd_reset, + .start = mausb_hcd_start, + .stop = mausb_hcd_stop, + + .get_frame_number = mausb_hcd_get_frame_number, + + .hub_status_data = mausb_hcd_hub_status, + .hub_control = mausb_hcd_hub_control, + .update_hub_device = mausb_hub_update_device, + .bus_suspend = mausb_hcd_bus_suspend, + .bus_resume = mausb_hcd_bus_resume, + + .alloc_dev = mausb_alloc_dev, + .free_dev = mausb_free_dev, + .enable_device = mausb_enable_device, + .update_device = mausb_update_device, + .reset_device = mausb_reset_device, + + .add_endpoint = mausb_add_endpoint, + .drop_endpoint = mausb_drop_endpoint, + .check_bandwidth = mausb_check_bandwidth, + .reset_bandwidth = mausb_reset_bandwidth, + .address_device = mausb_address_device, + .endpoint_disable = mausb_endpoint_disable, + .endpoint_reset = mausb_endpoint_reset, +}; + +static struct { +struct usb_bos_descriptor bos; +struct usb_ss_cap_descriptor ss_cap; +} usb3_bos_desc = { + .bos = { + .bLength =USB_DT_BOS_SIZE , + .bDescriptorType =USB_DT_BOS , + .wTotalLength =cpu_to_le16 (sizeof (usb3_bos_desc)), + .bNumDeviceCaps =1 + }, + .ss_cap = { + .bLength =USB_DT_USB_SS_CAP_SIZE , + .bDescriptorType =USB_DT_DEVICE_CAPABILITY , + .bDevCapabilityType =USB_SS_CAP_TYPE , + .wSpeedSupported =cpu_to_le16 (USB_5GBPS_OPERATION ), + .bFunctionalitySupport =ilog2 (USB_5GBPS_OPERATION ) + } +}; + +static int get_root_hub_port_number (struct usb_device *dev,u8 *port_number) +{ +struct usb_device *first_hub_device = dev; + +if (!dev->parent) { + (*port_number) =0 ; +return -EINVAL ; + } + +while (first_hub_device->parent->parent) + first_hub_device = first_hub_device->parent; + + (*port_number) = first_hub_device->portnum -1 ; + +return 0 ; +} + +static struct mausb_usb_device_ctx *mausb_find_usb_device (struct mausb_dev + *mdevs,void *dev_addr) +{ +struct rb_node *node = mdevs->usb_devices.rb_node; + +while (node) { +struct mausb_usb_device_ctx *usb_device = + rb_entry(node, struct mausb_usb_device_ctx, rb_node); + +if (dev_addr < usb_device->dev_addr) + node = usb_device->rb_node.rb_left; +else if (dev_addr > usb_device->dev_addr) + node = usb_device->rb_node.rb_right; +else +return usb_device; + } +return NULL ; +} + +static int mausb_hcd_get_frame_number (struct usb_hcd *hcd) +{ +return 0 ; +} + +static int mausb_hcd_reset (struct usb_hcd *hcd) +{ +if (usb_hcd_is_primary_hcd (hcd)) { + hcd->speed =HCD_USB2 ; + hcd->self.root_hub->speed =USB_SPEED_HIGH ; + }else { + hcd->speed =HCD_USB3 ; + hcd->self.root_hub->speed =USB_SPEED_SUPER ; + } + hcd->self.no_sg_constraint =1 ; + hcd->self.sg_tablesize =UINT_MAX ; + +return 0 ; +} + +static int mausb_hcd_start (struct usb_hcd *hcd) +{ + hcd->power_budget =0 ; + hcd->uses_new_polling =1 ; +return 0 ; +} + +static void mausb_hcd_stop (struct usb_hcd *hcd) +{ +mausb_pr_debug ("Not implemented" ); +} + +static int mausb_hcd_hub_status (struct usb_hcd *hcd,char *buff) +{ +int retval; +int changed; +int i; +struct hub_ctx *hub; +unsigned long flags =0 ; + + hub = (struct hub_ctx *)hcd->hcd_priv; + + retval =DIV_ROUND_UP (NUMBER_OF_PORTS +1 ,8 ); + changed =0 ; + +memset (buff,0 , (unsigned int )retval); + +spin_lock_irqsave (&mhcd->lock, flags); + +if (!HCD_HW_ACCESSIBLE (hcd)) { +mausb_pr_info ("hcd not accessible, hcd speed=%d" , hcd->speed); +spin_unlock_irqrestore (&mhcd->lock, flags); +return 0 ; + } + +for (i =0 ; i <NUMBER_OF_PORTS ; ++i) { +if ((hub->ma_devs[i].port_status &PORT_C_MASK )) { + buff[(i +1 ) /8 ] |=1 << (i +1 ) %8 ; + changed =1 ; + } + } + +mausb_pr_info ("Usb %d.0 : changed=%d, retval=%d" , + (hcd->speed ==HCD_USB2 ) ?2 :3 , changed, retval); + +if (hcd->state ==HC_STATE_SUSPENDED && changed ==1 ) { +mausb_pr_info ("hcd state is suspended" ); +usb_hcd_resume_root_hub (hcd); + } + +spin_unlock_irqrestore (&mhcd->lock, flags); + +return changed ? retval :0 ; +} + +static int mausb_hcd_bus_resume (struct usb_hcd *hcd) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mhcd->lock, flags); +if (!HCD_HW_ACCESSIBLE (hcd)) { +mausb_pr_info ("hcd not accessible, hcd speed=%d" , hcd->speed); +spin_unlock_irqrestore (&mhcd->lock, flags); +return -ESHUTDOWN ; + } + hcd->state =HC_STATE_RUNNING ; +spin_unlock_irqrestore (&mhcd->lock, flags); + +return 0 ; +} + +static int mausb_hcd_bus_suspend (struct usb_hcd *hcd) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mhcd->lock, flags); + hcd->state =HC_STATE_SUSPENDED ; +spin_unlock_irqrestore (&mhcd->lock, flags); + +return 0 ; +} + +static int mausb_hcd_hub_control (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +int retval =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_hcd *hub_mhcd = hub->mhcd; +unsigned long flags; +bool invalid_rhport = false; + + index = ((__u8)(index &0x00ff )); +if (index <1 || index >NUMBER_OF_PORTS ) + invalid_rhport = true; + +mausb_pr_info ("TypeReq=%d" , type_req); + +spin_lock_irqsave (&hub_mhcd->lock, flags); + +if (!HCD_HW_ACCESSIBLE (hcd)) { +mausb_pr_info ("hcd not accessible, hcd speed=%d" , hcd->speed); +spin_unlock_irqrestore (&hub_mhcd->lock, flags); +return -ETIMEDOUT ; + } + +switch (type_req) { +case ClearHubFeature: +break ; +case ClearPortFeature: +if (invalid_rhport) + goto invalid_port; + +mausb_clear_port_feature (hcd, type_req, value, index, buff, + length); +break ; +case DeviceRequest |USB_REQ_GET_DESCRIPTOR : +memcpy (buff, &usb3_bos_desc,sizeof (usb3_bos_desc)); + retval =sizeof (usb3_bos_desc); +break ; +case GetHubDescriptor: +mausb_get_hub_descriptor (hcd, type_req, value, index, buff, + length); +break ; +case GetHubStatus: +mausb_get_hub_status (hcd, type_req, value, index, buff, + length); +break ; +case GetPortStatus: +if (invalid_rhport) + goto invalid_port; + +mausb_get_port_status (hcd, type_req, value, index, buff, + length); +break ; +case SetHubFeature: + retval = -EPIPE ; +break ; +case SetPortFeature: +if (invalid_rhport) + goto invalid_port; + +mausb_set_port_feature (hcd, type_req, value, index, buff, + length); +break ; +default : + retval = -EPIPE ; + } + +invalid_port: +spin_unlock_irqrestore (&hub_mhcd->lock, flags); +return retval; +} + +int mausb_probe (struct device *dev) +{ +struct mausb_hcd *mausb_hcd; +struct usb_hcd *hcd_ss; +struct usb_hcd *hcd_hs; +int ret; + + mausb_hcd =dev_get_drvdata (dev); +spin_lock_init (&mausb_hcd->lock); + + hcd_hs =usb_create_hcd (&mausb_hc_driver, dev,dev_name (dev)); +if (!hcd_hs) +return -ENOMEM ; + + hcd_hs->has_tt =1 ; + mausb_hcd->hcd_hs_ctx = (struct hub_ctx *)hcd_hs->hcd_priv; + mausb_hcd->hcd_hs_ctx->mhcd = mausb_hcd; + mausb_hcd->hcd_hs_ctx->hcd = hcd_hs; +memset (mausb_hcd->hcd_hs_ctx->ma_devs,0 , +sizeof (struct mausb_dev ) *NUMBER_OF_PORTS ); + + ret =usb_add_hcd (hcd_hs,0 ,0 ); +if (ret) { +mausb_pr_err ("usb_add_hcd failed" ); + goto put_hcd_hs; + } + + hcd_ss =usb_create_shared_hcd (&mausb_hc_driver, dev,dev_name (dev), + hcd_hs); +if (!hcd_ss) { + ret = -ENOMEM ; + goto remove_hcd_hs; + } + mausb_hcd->hcd_ss_ctx = (struct hub_ctx *)hcd_ss->hcd_priv; + mausb_hcd->hcd_ss_ctx->mhcd = mausb_hcd; + mausb_hcd->hcd_ss_ctx->hcd = hcd_ss; + +memset (mausb_hcd->hcd_ss_ctx->ma_devs,0 , +sizeof (struct mausb_dev ) *NUMBER_OF_PORTS ); + + ret =usb_add_hcd (hcd_ss,0 ,0 ); +if (ret) { +mausb_pr_err ("usb_add_hcd failed" ); + goto put_hcd_ss; + } + +return ret; + +put_hcd_ss: +usb_put_hcd (hcd_ss); +remove_hcd_hs: +usb_remove_hcd (hcd_hs); +put_hcd_hs: +usb_put_hcd (hcd_hs); + mausb_hcd->hcd_hs_ctx =NULL ; + mausb_hcd->hcd_ss_ctx =NULL ; +return ret; +} + +static void mausb_get_hub_descriptor (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length) +{ +u8 width; +struct usb_hub_descriptor *desc = (struct usb_hub_descriptor *)buff; + +memset (desc,0 ,sizeof (struct usb_hub_descriptor )); + +if (hcd->speed ==HCD_USB3 ) { + desc->bDescriptorType =USB_DT_SS_HUB ; + desc->bDescLength =12 ; + desc->wHubCharacteristics = +cpu_to_le16 (HUB_CHAR_INDV_PORT_LPSM |HUB_CHAR_COMMON_OCPM ); + desc->bNbrPorts =NUMBER_OF_PORTS ; + desc->u.ss.bHubHdrDecLat =0x04 ; + desc->u.ss.DeviceRemovable =cpu_to_le16 (0xffff ); + }else { + desc->bDescriptorType =USB_DT_HUB ; + desc->wHubCharacteristics = +cpu_to_le16 (HUB_CHAR_INDV_PORT_LPSM |HUB_CHAR_COMMON_OCPM ); + desc->bNbrPorts =NUMBER_OF_PORTS ; + width = (u8)(desc->bNbrPorts /8 +1 ); + desc->bDescLength =USB_DT_HUB_NONVAR_SIZE +2 * width; + +memset (&desc->u.hs.DeviceRemovable[0 ],0 , width); +memset (&desc->u.hs.DeviceRemovable[width],0xff , width); + } +} + +static void mausb_set_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +switch (value) { +case USB_PORT_FEAT_LINK_STATE : +mausb_pr_debug ("USB_PORT_FEAT_LINK_STATE" ); +if (hcd->speed ==HCD_USB3 ) { +if ((hub->ma_devs[index -1 ].port_status & +USB_SS_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + }else { +if ((hub->ma_devs[index -1 ].port_status & +USB_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + } +break ; +case USB_PORT_FEAT_U1_TIMEOUT : +case USB_PORT_FEAT_U2_TIMEOUT : +break ; +case USB_PORT_FEAT_SUSPEND : +break ; +case USB_PORT_FEAT_POWER : +mausb_pr_debug ("USB_PORT_FEAT_POWER" ); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status |= +USB_SS_PORT_STAT_POWER ; + }else { + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_POWER ; + } +break ; +case USB_PORT_FEAT_BH_PORT_RESET : +mausb_pr_debug ("USB_PORT_FEAT_BH_PORT_RESET" ); +/* fall through */ +case USB_PORT_FEAT_RESET : +mausb_pr_debug ("USB_PORT_FEAT_RESET hcd->speed=%d" , hcd->speed); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status =0 ; + hub->ma_devs[index -1 ].port_status = + (USB_SS_PORT_STAT_POWER | +USB_PORT_STAT_CONNECTION |USB_PORT_STAT_RESET ); + }else if (hub->ma_devs[index -1 ].port_status + &USB_PORT_STAT_ENABLE ) { + hub->ma_devs[index -1 ].port_status &= + ~(USB_PORT_STAT_ENABLE | +USB_PORT_STAT_LOW_SPEED | +USB_PORT_STAT_HIGH_SPEED ); + } +/* fall through */ +default : +mausb_pr_info ("Default value=%d" , value); + +if (hcd->speed ==HCD_USB3 ) { +if ((hub->ma_devs[index -1 ].port_status & +USB_SS_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + }else { +if ((hub->ma_devs[index -1 ].port_status & +USB_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + } + } +} + +static void mausb_get_port_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +u8 dev_speed; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +if ((hub->ma_devs[index -1 ].port_status & + (1 <<USB_PORT_FEAT_RESET )) !=0 ) { +mausb_pr_info ("Finished reset hcd->speed=%d" , hcd->speed); + + dev_speed = hub->ma_devs[index -1 ].dev_speed; +switch (dev_speed) { +case LOW_SPEED : + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_LOW_SPEED ; +break ; +case HIGH_SPEED : + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_HIGH_SPEED ; +break ; +default : +mausb_pr_info ("Not updating port_status for device speed %d" , + dev_speed); + } + + hub->ma_devs[index -1 ].port_status |= + (1 <<USB_PORT_FEAT_C_RESET ) |USB_PORT_STAT_ENABLE ; + hub->ma_devs[index -1 ].port_status &= + ~(1 <<USB_PORT_FEAT_RESET ); + } + + ((__le16 *)buff)[0 ] =cpu_to_le16 (hub->ma_devs[index -1 ].port_status); + ((__le16 *)buff)[1 ] = +cpu_to_le16 (hub->ma_devs[index -1 ].port_status >>16 ); + +mausb_pr_info ("port_status=%d" , hub->ma_devs[index -1 ].port_status); +} + +static void mausb_clear_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length) +{ +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +switch (value) { +case USB_PORT_FEAT_SUSPEND : +break ; +case USB_PORT_FEAT_POWER : +mausb_pr_debug ("USB_PORT_FEAT_POWER" ); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status &= + ~USB_SS_PORT_STAT_POWER ; + }else { + hub->ma_devs[index -1 ].port_status &= + ~USB_PORT_STAT_POWER ; + } +break ; +case USB_PORT_FEAT_RESET : + +case USB_PORT_FEAT_C_RESET : + +default : +mausb_pr_info ("Default value: %d" , value); + + hub->ma_devs[index -1 ].port_status &= ~(1 << value); + } +} + +static void mausb_get_hub_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ + *(__le32 *)buff =cpu_to_le32 (0 ); +} + +static int mausb_alloc_dev (struct usb_hcd *hcd,struct usb_device *dev) +{ +mausb_pr_info ("Usb device=%p" , dev); + +return 1 ; +} + +static void mausb_free_dev (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number; +s16 dev_handle; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_dev *mdev =NULL ; +struct mausb_usb_device_ctx *usb_device_ctx; +struct mausb_endpoint_ctx *ep_ctx = dev->ep0.hcpriv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return ; + } + + mdev = &hub->ma_devs[port_number]; + + usb_device_ctx =mausb_find_usb_device (mdev, dev); +if (!usb_device_ctx) { +mausb_pr_warn ("device_ctx is not found" ); +return ; + } + + dev_handle = usb_device_ctx->dev_handle; + +if (ep_ctx) { + dev->ep0.hcpriv =NULL ; +kfree (ep_ctx); + + }else { +mausb_pr_warn ("ep_ctx is NULL: dev_handle=%#x" , dev_handle); + } + +rb_erase (&usb_device_ctx->rb_node, &mdev->usb_devices); +mausb_pr_info ("USB device deleted device=%p" , usb_device_ctx->dev_addr); +kfree (usb_device_ctx); +} + +/* +* For usb 2.0 logitech camera called multiple times, once during +* enumeration of device and later after mausb_reset_device. +*/ +static int mausb_address_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; +struct mausb_endpoint_ctx *endpoint_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_warn ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) +return -ENODEV ; + +mausb_pr_info ("dev_handle=%#x, dev_speed=%#x" , + usb_device_ctx->dev_handle, dev->speed); + +if (dev->speed >=USB_SPEED_SUPER ) +mausb_pr_info ("USB 3.0" ); +else +mausb_pr_info ("USB 2.0" ); + +if (usb_device_ctx->dev_handle ==DEV_HANDLE_NOT_ASSIGNED ) { + status =mausb_enable_device (hcd, dev); +if (status <0 ) +return status; + } + + endpoint_ctx = dev->ep0.hcpriv; +if (!endpoint_ctx) { +mausb_pr_err ("endpoint_ctx is NULL: dev_handle=%#x" , + usb_device_ctx->dev_handle); +return -EINVAL ; + } + +return 0 ; +} + +static int mausb_add_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint) +{ +int status; +u8 port_number; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_dev_ctx; +struct mausb_endpoint_ctx *endpoint_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return 0 ; + } + + usb_dev_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!usb_dev_ctx) { +mausb_pr_warn ("Device not found" ); +return -ENODEV ; + } + + endpoint_ctx =kzalloc (sizeof (*endpoint_ctx),GFP_ATOMIC ); +if (!endpoint_ctx) +return -ENOMEM ; + + endpoint_ctx->dev_handle = usb_dev_ctx->dev_handle; + endpoint_ctx->usb_device_ctx = usb_dev_ctx; + endpoint->hcpriv = endpoint_ctx; + +return 0 ; +} + +static int mausb_drop_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint) +{ +u8 port_number; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_dev_ctx; +struct mausb_endpoint_ctx *endpoint_ctx = endpoint->hcpriv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_dev_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!endpoint_ctx) { +mausb_pr_err ("Endpoint context doesn't exist" ); +return 0 ; + } +if (!usb_dev_ctx) { +mausb_pr_err ("Usb device context doesn't exist" ); +return -ENODEV ; + } + + endpoint->hcpriv =NULL ; +kfree (endpoint_ctx); +return 0 ; +} + +/* +* For usb 2.0 logitech camera called multiple times, once during enumeration +* of device and later after mausb_reset_device. In latter case it is +* required to address the device again in order for ep0 to work properly. +*/ +static int mausb_enable_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +int status; +u8 port_number; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) +return -ENODEV ; + +mausb_pr_info ("Device assigned and addressed usb_device_ctx=%p" , + usb_device_ctx); + +return 0 ; +} + +static int mausb_is_hub_device (struct usb_device *dev) +{ +return dev->descriptor.bDeviceClass ==0x09 ; +} + +static int mausb_update_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number =0 ; +int status =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx =NULL ; + +if (mausb_is_hub_device (dev)) { +mausb_pr_warn ("Device is hub" ); +return 0 ; + } + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) { +mausb_pr_warn ("Device not found" ); +return -ENODEV ; + } + +return 0 ; +} + +static int mausb_hub_update_device (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_tt *tt,gfp_t mem_flags) +{ +int status; +u8 port_number; +u16 max_exit_latency =0 ; +u8 mtt =0 ; +u8 ttt =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; + +if (dev->speed ==USB_SPEED_HIGH ) { + mtt = tt->multi ==0 ?1 :0 ; + ttt = (u8 )tt->think_time; + } + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return 0 ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], + dev); + +if (!usb_device_ctx) { +mausb_pr_err ("USB device not found" ); +return -ENODEV ; + } + +if (dev->usb3_lpm_u1_enabled) + max_exit_latency = (u16 )dev->u1_params.mel; +else if (dev->usb3_lpm_u2_enabled) + max_exit_latency = (u16 )dev->u2_params.mel; + +return 0 ; +} + +static int mausb_check_bandwidth (struct usb_hcd *hcd,struct usb_device *dev) +{ +mausb_pr_debug ("Not implemented" ); +return 0 ; +} + +static void mausb_reset_bandwidth (struct usb_hcd *hcd,struct usb_device *dev) +{ +mausb_pr_debug ("Not implemented" ); +} + +static void mausb_endpoint_disable (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint) +{ +mausb_pr_debug ("Not implemented" ); +} + +static void mausb_endpoint_reset (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint) +{ +int status; +int is_control; +int epnum; +int is_out; +u16 dev_handle; +u8 tsp; +u8 port_number; +struct hub_ctx *hub; +struct mausb_usb_device_ctx *usb_device_ctx; +struct usb_device *dev; +struct mausb_endpoint_ctx *ep_ctx; + + ep_ctx = endpoint->hcpriv; +if (!ep_ctx) { +mausb_pr_err ("ep->hcpriv is NULL" ); +return ; + } + + usb_device_ctx = ep_ctx->usb_device_ctx; + dev_handle = usb_device_ctx->dev_handle; + dev = usb_device_ctx->dev_addr; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return ; + } + hub = (struct hub_ctx *)hcd->hcd_priv; + + is_control =usb_endpoint_xfer_control (&endpoint->desc); + epnum =usb_endpoint_num (&endpoint->desc); + is_out =usb_endpoint_dir_out (&endpoint->desc); + tsp = (u8)(is_out ? dev->toggle[1 ] : dev->toggle[0 ]); + +if (status <0 ) +return ; + +if (status !=EUCLEAN ) { +if (!tsp) { +usb_settoggle (dev, epnum, is_out,0U ); +if (is_control) +usb_settoggle (dev, epnum, !is_out,0U ); + } + +return ; + } + +if (tsp) +return ; + +mausb_pr_info ("ep_handle request status=%d, ep_handle=%#x, dev_handle=%#x" , + status, ep_ctx->ep_handle, dev_handle); +} + +/* +* For usb 2.0 logitech camera called multiple times, +* followed by either mausb_enable_device or mausb_address_device. +* Resets device to non-addressed state. +*/ +static int mausb_reset_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +int status; +u8 port_number; +u16 dev_handle; +struct hub_ctx *hub; +struct mausb_usb_device_ctx *usb_device_ctx; + + hub = (struct hub_ctx *)hcd->hcd_priv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!usb_device_ctx || + usb_device_ctx->dev_handle ==DEV_HANDLE_NOT_ASSIGNED ) +return 0 ; + + dev_handle = usb_device_ctx->dev_handle; + +return 0 ; +} + +void mausb_clear_hcd_madev (u16 port_number) +{ +unsigned long flags =0 ; + +if (port_number >=NUMBER_OF_PORTS ) { +mausb_pr_err ("port_number out of range, port_number=%x" , + port_number); +return ; + } + +spin_lock_irqsave (&mhcd->lock, flags); + +memset (&mhcd->hcd_hs_ctx->ma_devs[port_number],0 , +sizeof (struct mausb_dev )); +memset (&mhcd->hcd_ss_ctx->ma_devs[port_number],0 , +sizeof (struct mausb_dev )); + + mhcd->connected_ports &= ~(1 << port_number); + + mhcd->hcd_hs_ctx->ma_devs[port_number].port_status = +USB_PORT_STAT_POWER ; + mhcd->hcd_ss_ctx->ma_devs[port_number].port_status = +USB_SS_PORT_STAT_POWER ; + +spin_unlock_irqrestore (&mhcd->lock, flags); +}
drivers/usb/mausb_host/hcd.h +83 -3
96 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 4/8] usb: mausb_host: Implement initial hub handlers
Quoted 13 lines · On Fri, 27 Mar 2020 [email protected] wrote:
Implemented handlers for subset of HCD events.
Signed-off-by Vladimir Stankovic <[email protected]>---
(quoted diff) +8
-0+/* + * For usb 2.0 logitech camera called multiple times, once during + * enumeration of device and later after mausb_reset_device. + */ +static int mausb_address_device(struct usb_hcd *hcd, struct usb_device *dev) +/* + * For usb 2.0 logitech camera called multiple times, once during enumeration + * of device and later after mausb_reset_device. In latter case it is
Review
Quoted 10 lines
(quoted diff) +9
-0+ * required to address the device again in order for ep0 to work properly. + */ +static int mausb_enable_device(struct usb_hcd *hcd, struct usb_device *dev) +/* + * For usb 2.0 logitech camera called multiple times, + * followed by either mausb_enable_device or mausb_address_device. + * Resets device to non-addressed state. + */ +static int mausb_reset_device(struct usb_hcd *hcd, struct usb_device *dev)
Why on earth do you have all these comments about Logitech cameras? A host controller driver shouldn't care about the type of devices it gets connected to.
Alan Stern
Re: [PATCH v4 4/8] usb: mausb_host: Implement initial hub handlers
Quoted 30 lines · Alan Stern
Quoted 13 lines · On Fri, 27 Mar 2020 [email protected] wrote:
Implemented handlers for subset of HCD events.
Signed-off-by Vladimir Stankovic <[email protected]>---
(quoted diff) +8
-0+/* + * For usb 2.0 logitech camera called multiple times, once during + * enumeration of device and later after mausb_reset_device. + */ +static int mausb_address_device(struct usb_hcd *hcd, struct usb_device *dev) +/* + * For usb 2.0 logitech camera called multiple times, once during enumeration + * of device and later after mausb_reset_device. In latter case it isReview
Quoted 10 lines
(quoted diff) +9
-0+ * required to address the device again in order for ep0 to work properly. + */ +static int mausb_enable_device(struct usb_hcd *hcd, struct usb_device *dev) +/* + * For usb 2.0 logitech camera called multiple times, + * followed by either mausb_enable_device or mausb_address_device. + * Resets device to non-addressed state. + */ +static int mausb_reset_device(struct usb_hcd *hcd, struct usb_device *dev)Why on earth do you have all these comments about Logitech cameras? A host controller driver shouldn't care about the type of devices it gets connected to.
Quoted 2 lines
Alan Stern
You're right. As it turns out, it is leftover during development. Implementation has been tested with cameras from other vendors as well.
We'll remove those in next patch version.
Regards,
Vladimir.
PATCH v4 5/8 usb: mausb_host: Introduce PAL processing
In reply to [email protected]Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hcd.c | 523 ++++++++++- drivers/usb/mausb_host/hcd.h | 11 + drivers/usb/mausb_host/hpal.c | 1094 ++++++++++++++++++++++++ drivers/usb/mausb_host/hpal.h | 289 +++++++ drivers/usb/mausb_host/ma_usb.h | 869 +++++++++++++++++++ drivers/usb/mausb_host/mausb_address.h | 26 + drivers/usb/mausb_host/mausb_core.c | 13 +- drivers/usb/mausb_host/mausb_event.h | 224 +++++ 9 files changed, 3040 insertions(+), 10 deletions(-) create mode 100644 drivers/usb/mausb_host/hpal.c create mode 100644 drivers/usb/mausb_host/hpal.h create mode 100644 drivers/usb/mausb_host/ma_usb.h create mode 100644 drivers/usb/mausb_host/mausb_address.h create mode 100644 drivers/usb/mausb_host/mausb_event.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -10,5 +10,6 @@ mausb_host-y := mausb_core.o mausb_host-y += utils.o mausb_host-y += ip_link.o mausb_host-y += hcd.o +mausb_host-y += hpal.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hcd.c +514 -9
736 lines not on this page · raw message
drivers/usb/mausb_host/hcd.h +11 -0
@@ -15,6 +15,8 @@#include <linux/usb.h> #include <linux/usb/hcd.h> +#include "hpal.h" +#define DEVICE_NAME "mausb_host_hcd_dev"#define CLASS_NAME "mausb"
@@ -65,6 +67,13 @@ struct hub_ctx {int mausb_init_hcd (void );void mausb_deinit_hcd (void ); +void mausb_port_has_changed (const enum mausb_device_type device_type, +const enum mausb_device_speed device_speed, +void *ma_dev); +void mausb_hcd_disconnect (const u16 port_number, +const enum mausb_device_type device_type, +const enum mausb_device_speed device_speed); +#define PORT_C_MASK \ ((USB_PORT_STAT_C_CONNECTION \ | USB_PORT_STAT_C_ENABLE \
@@ -140,11 +149,13 @@ struct mausb_endpoint_ctx {struct mausb_urb_ctx {struct urb *urb; +struct mausb_data_iter iterator;struct rb_node rb_node;struct work_struct work; };int mausb_probe (struct device *dev); +void mausb_hcd_urb_complete (struct urb *urb,u32 actual_length,int status);void mausb_clear_hcd_madev (u16 port_number);
drivers/usb/mausb_host/hpal.c new file +1094 -0
1,094 lines not on this page · raw message
drivers/usb/mausb_host/hpal.h new file +289 -0
289 lines not on this page · raw message
drivers/usb/mausb_host/ma_usb.h new file +869 -0
841 lines not on this page · raw message
drivers/usb/mausb_host/mausb_address.h new file +26 -0
Lines of this file are not shown. View the raw message.
drivers/usb/mausb_host/mausb_event.h new file +224 -0
224 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v4 5/8] usb: mausb_host: Introduce PAL processing
drivers/usb/mausb_host/hcd.c static int mausb_hcd_hub_control(struct usb_hcd *hcd, u16 type_req, · line 718
Quoted 10 lines · On Fri, 27 Mar 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>---
drivers/usb/mausb_host/hcd.c +5
-0+/* +* Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it +* should not, so it is breaking the USB drive on the linux +*/ + urb->transfer_flags &= ~URB_SHORT_NOT_OK ;
Please explain more fully. What SCSI driver are you talking about? Where is the flag getting added incorrectly? What USB drive is getting broken, and how?
If there's a bug in a SCSI driver, why don't you report it and get it fixed instead of trying to create a workaround in just one host controller driver?
Alan Stern
kbuild test robot
build botRe: [PATCH v4 5/8] usb: mausb_host: Introduce PAL processing
In reply to [email protected]I love your patch! Perhaps something to improve:
Hi,
I love your patch! Perhaps something to improve:
[auto build test WARNING on usb/usb-testing]
[also build test WARNING on balbi-usb/next peter.chen-usb/ci-for-usb-next linus/master linux/master v5.6-rc7 next-20200327] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/vladimir-stankovic-displaylink-com/Add-MA-USB-Host-driver/20200328-042436 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing config: c6x-allyesconfig (attached as .config) compiler: c6x-elf-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=c6x
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
drivers/usb/mausb_host/hpal.c: In function 'mausb_release_event_resources':
>> drivers/usb/mausb_host/hpal.c:221:45: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
221 | struct ma_usb_hdr_common *receive_buffer = (struct ma_usb_hdr_common *)
| ^
drivers/usb/mausb_host/hpal.c: In function 'mausb_complete_urb':
drivers/usb/mausb_host/hpal.c:229:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
229 | struct urb *urb = (struct urb *)event->data.urb;
| ^
drivers/usb/mausb_host/hpal.c: In function 'mausb_data_req_enqueue_event':
>> drivers/usb/mausb_host/hpal.c:357:26: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
357 | mausb_event.data.urb = (u64)request;
| ^
drivers/usb/mausb_host/hpal.c: In function 'mausb_execute_urb_dequeue':
drivers/usb/mausb_host/hpal.c:492:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
492 | mausb_event.data.urb = (u64)urb;
| ^
drivers/usb/mausb_host/hpal.c: In function 'mausb_send_data_msg':
drivers/usb/mausb_host/hpal.c:725:35: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
725 | urb_ctx = mausb_find_urb_in_tree((struct urb *)event->data.urb);
| ^
drivers/usb/mausb_host/hpal.c: In function 'mausb_receive_data_msg':
drivers/usb/mausb_host/hpal.c:752:35: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
752 | urb_ctx = mausb_find_urb_in_tree((struct urb *)event->data.urb);
| ^ /tmp/ccABqgDp.s: Assembler messages:
/tmp/ccABqgDp.s:3838: Warning: ignoring changed section attributes for .far
vim +221 drivers/usb/mausb_host/hpal.c
218
219 void mausb_release_event_resources(struct mausb_event *event)
220 {
> 221 struct ma_usb_hdr_common *receive_buffer = (struct ma_usb_hdr_common *)
222 event->data.recv_buf;
223
224 kfree(receive_buffer);
225 }
226
227 void mausb_complete_urb(struct mausb_event *event)
228 {
229 struct urb *urb = (struct urb *)event->data.urb;
230
231 mausb_pr_debug("transfer_size=%d, rem_transfer_size=%d, status=%d",
232 event->data.transfer_size,
233 event->data.rem_transfer_size, event->status);
234 mausb_complete_request(urb,
235 event->data.transfer_size -
236 event->data.rem_transfer_size,
237 event->status);
238 }
239
240 static int mausb_get_first_free_port_number(u16 *port_number)
241 {
242 (*port_number) = 0;
243 while ((mhcd->connected_ports & (1 << *port_number)) != 0 &&
244 *port_number < NUMBER_OF_PORTS)
245 ++(*port_number);
246
247 if (*port_number == NUMBER_OF_PORTS)
248 return -EINVAL;
249
250 mhcd->connected_ports |= (1 << *port_number);
251
252 return 0;
253 }
254
255 static inline void mausb_port_has_changed_event(struct mausb_device *dev,
256 struct mausb_event *event)
257 {
258 int status;
259 u16 port_number;
260 unsigned long flags = 0;
261
262 spin_lock_irqsave(&mhcd->lock, flags);
263
264 status = mausb_get_first_free_port_number(&port_number);
265 if (status < 0) {
266 spin_unlock_irqrestore(&mhcd->lock, flags);
267 mausb_pr_err("There is no free port, schedule delete ma_dev");
268 queue_work(dev->workq, &dev->socket_disconnect_work);
269 return;
270 }
271
272 spin_unlock_irqrestore(&mhcd->lock, flags);
273
274 dev->dev_type = event->port_changed.dev_type;
275 dev->dev_speed = event->port_changed.dev_speed;
276 dev->lse = event->port_changed.lse;
277 dev->dev_connected = 1;
278 dev->port_number = port_number;
279
280 mausb_port_has_changed(event->port_changed.dev_type,
281 event->port_changed.dev_speed, dev);
282
283 if ((enum mausb_device_type)event->port_changed.dev_type == USB30HUB)
284 mausb_port_has_changed(USB20HUB, HIGH_SPEED, dev);
285 }
286
287 static void mausb_heartbeat_timer_func(struct timer_list *timer)
288 {
289 unsigned long flags = 0;
290 struct mausb_device *dev = NULL;
291
292 if (mausb_start_heartbeat_timer() < 0) {
293 mausb_pr_err("Devices disconnecting - app is unresponsive");
294 spin_lock_irqsave(&mss.lock, flags);
295
296 /* Reset connected clients */
297 mss.client_connected = false;
298 mss.missed_heartbeats = 0;
299
300 list_for_each_entry(dev, &mss.madev_list, list_entry) {
301 mausb_pr_debug("Enqueue heartbeat_work madev_addr=%x",
302 dev->madev_addr);
303 queue_work(dev->workq, &dev->heartbeat_work);
304 }
305
306 complete(&mss.client_stopped);
307 spin_unlock_irqrestore(&mss.lock, flags);
308 }
309 }
310
311 void mausb_release_ma_dev_async(struct kref *kref)
312 {
313 struct mausb_device *dev = container_of(kref, struct mausb_device,
314 refcount);
315
316 mausb_pr_info("Scheduling work for MAUSB device to be deleted");
317
318 schedule_work(&dev->madev_delete_work);
319 }
320
321 int mausb_enqueue_event_from_user(u8 madev_addr, u16 num_of_events,
322 u16 num_of_completed)
323 {
324 unsigned long flags;
325 struct mausb_device *dev;
326
327 spin_lock_irqsave(&mss.lock, flags);
328 dev = mausb_get_dev_from_addr_unsafe(madev_addr);
329
330 if (!dev) {
331 spin_unlock_irqrestore(&mss.lock, flags);
332 return -EINVAL;
333 }
334
335 spin_lock(&dev->num_of_user_events_lock);
336 dev->num_of_user_events += num_of_events;
337 dev->num_of_completed_events += num_of_completed;
338 spin_unlock(&dev->num_of_user_events_lock);
339 queue_work(dev->workq, &dev->work);
340 spin_unlock_irqrestore(&mss.lock, flags);
341
342 return 0;
343 }
344
345 int mausb_data_req_enqueue_event(struct mausb_device *dev, u16 ep_handle,
346 struct urb *request)
347 {
348 struct mausb_event mausb_event;
349
350 mausb_event.type = MAUSB_EVENT_TYPE_SEND_DATA_MSG;
351 mausb_event.status = 0;
352
353 mausb_event.data.transfer_type =
354 mausb_transfer_type_from_usb(&request->ep->desc);
355 mausb_event.data.device_id = dev->id;
356 mausb_event.data.ep_handle = ep_handle;
> 357 mausb_event.data.urb = (u64)request; 358 mausb_event.data.setup_packet =
359 (usb_endpoint_xfer_control(&request->ep->desc) &&
360 request->setup_packet);
361 mausb_event.data.transfer_size = request->transfer_buffer_length;
362 mausb_event.data.direction = (usb_urb_dir_in(request) ?
363 MAUSB_DATA_MSG_DIRECTION_IN :
364 MAUSB_DATA_MSG_DIRECTION_OUT);
365 mausb_event.data.transfer_size +=
366 ((mausb_event.data.direction == MAUSB_DATA_MSG_DIRECTION_OUT &&
367 mausb_event.data.setup_packet) ?
368 MAUSB_CONTROL_SETUP_SIZE : 0);
369 mausb_event.data.rem_transfer_size = mausb_event.data.transfer_size;
370 mausb_event.data.transfer_flags = request->transfer_flags;
371 mausb_event.data.transfer_eot = false;
372 mausb_event.data.isoch_seg_num = (u32)request->number_of_packets;
373 mausb_event.data.recv_buf = 0;
374 mausb_event.data.payload_size =
375 (usb_endpoint_xfer_isoc(&request->ep->desc) &&
376 usb_endpoint_dir_out(&request->ep->desc)) ?
377 (request->iso_frame_desc[request->number_of_packets - 1]
378 .offset +
379 request->iso_frame_desc[request->number_of_packets - 1]
380 .length) : 0;
381
382 if (mausb_event.data.setup_packet) {
383 memcpy(mausb_event.data.hdr_ack, request->setup_packet,
384 MAUSB_CONTROL_SETUP_SIZE);
385 memcpy(shift_ptr(mausb_event.data.hdr_ack,
386 MAUSB_CONTROL_SETUP_SIZE),
387 &request->dev->route, sizeof(request->dev->route));
388 }
389
390 return 0;
391 }
392
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v4 6/8 usb: mausb_host: Add logic for PAL-to-PAL communication
In reply to [email protected]Implemeneted connection between PAL and Link layers and set up environment for exchanging PAL-to-PAL messages.
Within this patch, driver's sysfs parameters have been created with intention to configure remote connection parameters.
--- drivers/usb/mausb_host/hpal.c | 522 ++++++++++++++++++++++++++++ drivers/usb/mausb_host/hpal.h | 6 + drivers/usb/mausb_host/mausb_core.c | 103 +++++- 3 files changed, 630 insertions(+), 1 deletion(-)
drivers/usb/mausb_host/hpal.c +522 -0
@@ -13,10 +13,15 @@#include "hcd.h" #include "utils.h" +#define MAUSB_DELETE_MADEV_TIMEOUT_MS 3000 +struct mss mss; +static int mausb_start_connection_timer (struct mausb_device *dev);static int mausb_power_state_cb (struct notifier_block *nb,unsigned long action,void *data); +static void mausb_signal_empty_mss (void ); +static void mausb_remove_madev_from_list (u8 madev_addr);static void mausb_execute_urb_dequeue (struct work_struct *dequeue_work);static int mausb_start_heartbeat_timer (void );
@@ -177,6 +182,55 @@ static bool mausb_return_urb_ctx_to_tree(struct mausb_urb_ctx *urb_ctx,return true; } +static void mausb_complete_urbs_from_tree (void ) +{ +struct mausb_urb_ctx *urb_ctx =NULL ; +struct urb *current_urb =NULL ; +struct rb_node *current_node =NULL ; +unsigned long flags; +int status =0 ; +int ret; + +mausb_pr_debug ("Completing all urbs from tree" ); + +spin_lock_irqsave (&mhcd->lock, flags); + +while ((current_node =rb_first (&mhcd->mausb_urbs))) { + urb_ctx = rb_entry(current_node, struct mausb_urb_ctx, rb_node); + + current_urb = urb_ctx->urb; +mausb_delete_urb_ctx_from_tree (urb_ctx); +mausb_uninit_data_iterator (&urb_ctx->iterator); +kfree (urb_ctx); + + ret =usb_hcd_check_unlink_urb (current_urb->hcpriv, + current_urb, status); +if (ret == -EIDRM ) +mausb_pr_warn ("Urb=%p is already unlinked" , + current_urb); +else +usb_hcd_unlink_urb_from_ep (current_urb->hcpriv, + current_urb); + +spin_unlock_irqrestore (&mhcd->lock, flags); + +/* Prepare urb for completion */ +mausb_pr_debug ("Completing urb=%p" , current_urb); + + current_urb->status = -EPROTO ; + current_urb->actual_length =0 ; +atomic_dec (¤t_urb->use_count); +usb_hcd_giveback_urb (current_urb->hcpriv, current_urb, + current_urb->status); + +spin_lock_irqsave (&mhcd->lock, flags); + } + +spin_unlock_irqrestore (&mhcd->lock, flags); + +mausb_pr_debug ("Completed all urbs from tree" ); +} +/*After this function call only valid thing to do with urb is to give it back*/ struct mausb_urb_ctx *mausb_unlink_and_delete_urb_from_tree (struct urb *urb,int status)
@@ -284,6 +338,161 @@ static inline void mausb_port_has_changed_event(struct mausb_device *dev,mausb_port_has_changed (USB20HUB ,HIGH_SPEED , dev); } +static void mausb_socket_disconnect_event (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + socket_disconnect_work); +struct mausb_event event; + +mausb_pr_info ("madev_addr=%d" , dev->madev_addr); + +mausb_ip_disconnect (dev->ctrl_channel); +mausb_destroy_ip_ctx (dev->ctrl_channel); + dev->ctrl_channel =NULL ; + +mausb_ip_disconnect (dev->bulk_channel); +mausb_destroy_ip_ctx (dev->bulk_channel); + dev->bulk_channel =NULL ; + +mausb_ip_disconnect (dev->isoch_channel); +mausb_destroy_ip_ctx (dev->isoch_channel); + dev->isoch_channel =NULL ; + +if (dev->mgmt_channel) { +memset (&event,0 ,sizeof (event)); + event.type =MAUSB_EVENT_TYPE_NETWORK_DISCONNECTED ; + event.data.device_id = dev->id; + +mausb_pr_info ("Releasing MAUSB device ref" ); +kref_put (&dev->refcount, mausb_release_ma_dev_async); + } + +mausb_ip_disconnect (dev->mgmt_channel); +mausb_destroy_ip_ctx (dev->mgmt_channel); + dev->mgmt_channel =NULL ; + +memset (dev->channel_map,0 ,sizeof (dev->channel_map)); +} + +static void mausb_disconnect_ma_dev (struct mausb_device *dev) +{ +mausb_pr_info ("Disconnecting MAUSB device madev_addr=%d" , + dev->madev_addr); + +if (!dev->dev_connected) { +mausb_pr_warn ("MAUSB device is not connected" ); +kref_put (&dev->refcount, mausb_release_ma_dev_async); +return ; + } +mausb_hcd_disconnect (dev->port_number, dev->dev_type, dev->dev_speed); + +if (dev->dev_type ==USB30HUB ) +mausb_hcd_disconnect (dev->port_number,USB20HUB ,HIGH_SPEED ); +} + +static void mausb_hcd_disconnect_event (struct work_struct *work) +{ + struct mausb_device *ma_dev = container_of(work, struct mausb_device, + hcd_disconnect_work); + +mausb_disconnect_ma_dev (ma_dev); +} + +static void mausb_delete_madev (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + madev_delete_work); +struct mausb_event event; +struct completion completion; +struct completion *user_event; +struct mausb_completion mausb_completion; +long status; +unsigned long timeout =msecs_to_jiffies (MAUSB_DELETE_MADEV_TIMEOUT_MS ); + +mausb_pr_info ("Deleting MAUSB device madev_addr=%d" , dev->madev_addr); + +del_timer_sync (&dev->connection_timer); + +/* Client IS responsive */ +if (!atomic_read (&dev->unresponsive_client)) { +memset (&event,0 ,sizeof (event)); + event.type =MAUSB_EVENT_TYPE_DELETE_MA_DEV ; + event.mgmt.delete_ma_dev.device_id = dev->id; + event.mgmt.delete_ma_dev.event_id =mausb_event_id (dev); + +init_completion (&completion); + mausb_completion.completion_event = &completion; + mausb_completion.event_id = event.mgmt.delete_ma_dev.event_id; + mausb_completion.mausb_event = &event; + +mausb_insert_event (dev, &mausb_completion); + +mausb_pr_debug ("Deleting MAUSB device..." ); + + status =wait_for_completion_interruptible_timeout (&completion, + timeout); + +mausb_pr_debug ("Deleting MAUSB device event finished with %ld" , + status); + +mausb_remove_event (dev, &mausb_completion); + + user_event = &dev->user_finished_event; + + status =wait_for_completion_interruptible_timeout (user_event, + timeout); +mausb_pr_info ("User event finished with %ld" , status); + } + +flush_workqueue (dev->workq); +destroy_workqueue (dev->workq); + +mausb_clear_hcd_madev (dev->port_number); + +mausb_remove_madev_from_list (dev->madev_addr); + +put_net (dev->net_ns); + +kfree (dev); +mausb_signal_empty_mss (); + +mausb_pr_info ("MAUSB device deleted. Version=%s" ,MAUSB_DRIVER_VERSION ); +} + +static void mausb_ping_work (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + ping_work); + +if (mausb_start_connection_timer (dev) <0 ) { +mausb_pr_err ("Device disconnecting due to session timeout madev_addr=%d" , + dev->madev_addr); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +return ; + } +} + +static void mausb_heartbeat_work (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + heartbeat_work); + +mausb_pr_err ("Device disconnecting - app is unresponsive" ); +atomic_set (&dev->unresponsive_client,1 ); +mausb_complete_urbs_from_tree (); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +} + +static void mausb_connection_timer_func (struct timer_list *timer) +{ + struct mausb_device *dev = container_of(timer, struct mausb_device, + connection_timer); + +queue_work (dev->workq, &dev->ping_work); +} +static void mausb_heartbeat_timer_func (struct timer_list *timer) {unsigned long flags =0 ;
@@ -308,6 +517,99 @@ static void mausb_heartbeat_timer_func(struct timer_list *timer) } } +static struct mausb_device * +mausb_create_madev (struct mausb_device_address dev_addr,u8 madev_address, +int *status) +{ +struct mausb_device *dev; +unsigned long flags =0 ; +char workq_name[16 ]; +struct workqueue_struct *workq; + +memset (workq_name,0 ,sizeof (workq_name)); +sprintf (workq_name,"%x" , madev_address); +strcat (workq_name,"_madev_workq" ); + +mausb_pr_debug ("madev_workq_name = %s" , workq_name); + + workq =alloc_ordered_workqueue (workq_name,WQ_MEM_RECLAIM ); +if (!workq) { +mausb_pr_alert ("Could not allocate workqueue!" ); + *status = -ENOMEM ; +return NULL ; + } + +spin_lock_irqsave (&mss.lock, flags); + +if (mss.deinit_in_progress) { +spin_unlock_irqrestore (&mss.lock, flags); +mausb_pr_alert ("Device creating failed - mss deinit in progress" ); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -ESHUTDOWN ; +return NULL ; + } + + dev =mausb_get_dev_from_addr_unsafe (madev_address); +if (dev) { +spin_unlock_irqrestore (&mss.lock, flags); +mausb_pr_debug ("MAUSB device already connected, madev_address=%x" , + madev_address); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -EEXIST ; +return NULL ; + } + + dev =kzalloc (sizeof (*dev),GFP_ATOMIC ); + +if (!dev) { +spin_unlock_irqrestore (&mss.lock, flags); +mausb_pr_alert ("Could not allocate MAUSB device!" ); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -ENOMEM ; +return NULL ; + } + +mausb_pr_info ("Create MAUSB device. Version=%s" ,MAUSB_DRIVER_VERSION ); + + dev->workq = workq; + +INIT_WORK (&dev->socket_disconnect_work, mausb_socket_disconnect_event); +INIT_WORK (&dev->hcd_disconnect_work, mausb_hcd_disconnect_event); +INIT_WORK (&dev->madev_delete_work, mausb_delete_madev); +INIT_WORK (&dev->ping_work, mausb_ping_work); +INIT_WORK (&dev->heartbeat_work, mausb_heartbeat_work); + +kref_init (&dev->refcount); + + dev->event_id =0 ; +spin_lock_init (&dev->event_id_lock); + +INIT_LIST_HEAD (&dev->completion_events); +spin_lock_init (&dev->completion_events_lock); +spin_lock_init (&dev->num_of_user_events_lock); +spin_lock_init (&dev->connection_timer_lock); + +init_completion (&dev->user_finished_event); +atomic_set (&dev->unresponsive_client,0 ); + +timer_setup (&dev->connection_timer, mausb_connection_timer_func,0 ); + + dev->dev_addr = dev_addr; + dev->madev_addr = madev_address; + dev->net_ns =get_net (current->nsproxy->net_ns); + +list_add_tail (&dev->list_entry, &mss.madev_list); + +reinit_completion (&mss.empty); + +spin_unlock_irqrestore (&mss.lock, flags); + +return dev; +} +void mausb_release_ma_dev_async (struct kref *kref) { struct mausb_device *dev = container_of(kref, struct mausb_device,
@@ -318,6 +620,45 @@ void mausb_release_ma_dev_async(struct kref *kref)schedule_work (&dev->madev_delete_work); } +int mausb_initiate_dev_connection (struct mausb_device_address dev_addr, +u8 madev_address) +{ +int error =0 ; +struct mausb_device *dev; +unsigned long flags =0 ; + +spin_lock_irqsave (&mss.lock, flags); + dev =mausb_get_dev_from_addr_unsafe (madev_address); +spin_unlock_irqrestore (&mss.lock, flags); + +if (dev) { +mausb_pr_debug ("MAUSB device already connected, madev_address=%x" , + madev_address); +return -EEXIST ; + } + + dev =mausb_create_madev (dev_addr, madev_address, &error); + +if (!dev) +return error; + +mausb_pr_info ("New MAUSB device created madev_addr=%d" , madev_address); + + error =mausb_init_ip_ctx (&dev->mgmt_channel, dev->net_ns, + dev->dev_addr.ip.address, + dev->dev_addr.ip.port.management, dev, + mausb_ip_callback,MAUSB_MGMT_CHANNEL ); +if (error) { +mausb_pr_err ("Mgmt ip context init failed: error=%d" , error); +kref_put (&dev->refcount, mausb_release_ma_dev_async); +return error; + } + +mausb_ip_connect_async (dev->mgmt_channel); + +return 0 ; +} +int mausb_enqueue_event_from_user (u8 madev_addr,u16 num_of_events,u16 num_of_completed) {
@@ -418,6 +759,26 @@ int mausb_signal_event(struct mausb_device *dev,return -ETIMEDOUT ; } +static int mausb_start_connection_timer (struct mausb_device *dev) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&dev->connection_timer_lock, flags); + +if (++dev->receive_failures_num >MAUSB_MAX_RECEIVE_FAILURES ) { +mausb_pr_err ("Missed more than %d ping responses" , +MAUSB_MAX_RECEIVE_FAILURES ); +spin_unlock_irqrestore (&dev->connection_timer_lock, flags); +return -ETIMEDOUT ; + } + +mod_timer (&dev->connection_timer, jiffies +msecs_to_jiffies (1000 )); + +spin_unlock_irqrestore (&dev->connection_timer_lock, flags); + +return 0 ; +} +void mausb_reset_connection_timer (struct mausb_device *dev) {unsigned long flags =0 ;
@@ -661,6 +1022,36 @@ struct mausb_device *mausb_get_dev_from_addr_unsafe(u8 madev_addr)return NULL ; } +static void mausb_remove_madev_from_list (u8 madev_addr) +{ +unsigned long flags =0 ; +struct mausb_device *ma_dev, *tmp =NULL ; + +spin_lock_irqsave (&mss.lock, flags); + +list_for_each_entry_safe (ma_dev, tmp, &mss.madev_list, list_entry) { +if (ma_dev->madev_addr == madev_addr) { +list_del (&ma_dev->list_entry); +break ; + } + } + +if (list_empty (&mss.madev_list)) +reinit_completion (&mss.rings_events.mausb_ring_has_events); + +spin_unlock_irqrestore (&mss.lock, flags); +} + +static void mausb_signal_empty_mss (void ) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mss.lock, flags); +if (list_empty (&mss.madev_list)) +complete (&mss.empty); +spin_unlock_irqrestore (&mss.lock, flags); +} +static inline struct mausb_ip_ctx *mausb_get_data_channel (struct mausb_device *ma_dev,enum mausb_channel channel)
@@ -814,6 +1205,137 @@ void mausb_cleanup_chunks_list(struct list_head *chunks_list) } } +static void mausb_init_ip_ctx_helper (struct mausb_device *dev, +struct mausb_ip_ctx **ip_ctx, +u16 port, +enum mausb_channel channel) +{ +int status =mausb_init_ip_ctx (ip_ctx, dev->net_ns, + dev->dev_addr.ip.address, port, dev, + mausb_ip_callback, channel); +if (status <0 ) { +mausb_pr_err ("Init ip context failed with error=%d" , status); +queue_work (dev->workq, &dev->socket_disconnect_work); +return ; + } + + dev->channel_map[channel] = *ip_ctx; +mausb_ip_connect_async (*ip_ctx); +} + +static void mausb_connect_callback (struct mausb_device *dev, +enum mausb_channel channel,int status) +{ +struct mausb_device_address *dev_addr = &dev->dev_addr; + +mausb_pr_info ("Connect callback for channel=%d with status=%d" , + channel, status); + +if (status <0 ) { +queue_work (dev->workq, &dev->socket_disconnect_work); +return ; + } + +if (channel ==MAUSB_MGMT_CHANNEL ) { +if (dev_addr->ip.port.control ==0 ) { + dev->channel_map[MAUSB_CTRL_CHANNEL ] = + dev->mgmt_channel; + channel =MAUSB_CTRL_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->ctrl_channel, + dev_addr->ip.port.control, +MAUSB_CTRL_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_CTRL_CHANNEL ) { +if (dev_addr->ip.port.bulk ==0 ) { + dev->channel_map[MAUSB_BULK_CHANNEL ] = + dev->channel_map[MAUSB_CTRL_CHANNEL ]; + channel =MAUSB_BULK_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->bulk_channel, + dev_addr->ip.port.bulk, +MAUSB_BULK_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_BULK_CHANNEL ) { +if (dev_addr->ip.port.isochronous ==0 ) { +/* if there is no isoch port use tcp for it */ + dev->channel_map[MAUSB_ISOCH_CHANNEL ] = + dev->channel_map[MAUSB_BULK_CHANNEL ]; + channel =MAUSB_ISOCH_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->isoch_channel, + dev_addr->ip.port.isochronous, +MAUSB_ISOCH_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_ISOCH_CHANNEL ) { + dev->channel_map[MAUSB_INTR_CHANNEL ] = + dev->channel_map[MAUSB_CTRL_CHANNEL ]; + } +} + +static void mausb_handle_connect_event (struct mausb_device *dev, +enum mausb_channel channel,int status, +void *data) +{ +mausb_connect_callback (dev, channel, status); +} + +static void mausb_handle_receive_event (struct mausb_device *dev, +enum mausb_channel channel,int status, +void *data) +{ +struct mausb_event event; + + event.madev_addr = dev->madev_addr; + +if (status <=0 ) { +mausb_pr_err ("Receive event error status=%d" , status); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +return ; + } + +mausb_reset_connection_timer (dev); +} + +void mausb_ip_callback (void *ctx,enum mausb_channel channel, +enum mausb_link_action action,int status,void *data) +{ +struct mausb_device *dev = (struct mausb_device *)ctx; + +switch (action) { +case MAUSB_LINK_CONNECT : +mausb_handle_connect_event (dev, channel, status, data); +break ; +case MAUSB_LINK_SEND : +/* +* Currently there is nothing to do, as send operation is +* synchronous +*/ +break ; +case MAUSB_LINK_RECV : +mausb_handle_receive_event (dev, channel, status, data); +break ; +case MAUSB_LINK_DISCONNECT : +/* +* Currently there is nothing to do, as disconnect operation is +* synchronous +*/ +break ; +default : +mausb_pr_warn ("Unknown network action" ); + } +} + static int mausb_read_virtual_buffer(struct mausb_data_iter *iterator, u32 byte_num, struct list_head *data_chunks_list,
drivers/usb/mausb_host/hpal.h +6 -0
@@ -131,6 +131,8 @@ static inline u64 mausb_event_id(struct mausb_device *dev)return val; } +int mausb_initiate_dev_connection (struct mausb_device_address device_address, +u8 madev_address);int mausb_data_req_enqueue_event (struct mausb_device *dev,u16 ep_handle,struct urb *request); int mausb_signal_event(struct mausb_device *dev, struct mausb_event *event,
@@ -158,6 +160,7 @@ static inline void mausb_remove_event(struct mausb_device *dev, }void mausb_release_ma_dev_async (struct kref *kref); +void mausb_on_madev_connected (struct mausb_device *dev);void mausb_complete_request (struct urb *urb,u32 actual_length,int status);void mausb_complete_urb (struct mausb_event *event);void mausb_reset_connection_timer (struct mausb_device *dev);
@@ -240,6 +243,9 @@ enum mausb_channel mausb_transfer_type_to_channel(u8 transfer_type)return transfer_type >>3 ; } +void mausb_ip_callback (void *ctx,enum mausb_channel channel, +enum mausb_link_action action,int status,void *data); +struct mausb_data_iter {u32 length;
drivers/usb/mausb_host/mausb_core.c +102 -1
149 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 7/8 usb: mausb_host: MA-USB PAL events processing
In reply to [email protected]Implemented MA-USB management messages processing and communication with user-space driver via mapped memory.
MA USB PAL events are being enqueued into ring buffer from which data is being send/received to/from user-space.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hcd.c | 252 +++++++- drivers/usb/mausb_host/hpal.c | 449 +++++++++++++- drivers/usb/mausb_host/hpal.h | 44 ++ drivers/usb/mausb_host/hpal_events.c | 611 +++++++++++++++++++ drivers/usb/mausb_host/hpal_events.h | 85 +++ drivers/usb/mausb_host/mausb_driver_status.h | 17 + drivers/usb/mausb_host/utils.c | 275 +++++++++ drivers/usb/mausb_host/utils.h | 5 + 9 files changed, 1729 insertions(+), 10 deletions(-) create mode 100644 drivers/usb/mausb_host/hpal_events.c create mode 100644 drivers/usb/mausb_host/hpal_events.h create mode 100644 drivers/usb/mausb_host/mausb_driver_status.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -11,5 +11,6 @@ mausb_host-y += utils.o mausb_host-y += ip_link.o mausb_host-y += hcd.o mausb_host-y += hpal.o +mausb_host-y += hpal_events.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hcd.c +247 -5
383 lines not on this page · raw message
drivers/usb/mausb_host/hpal.c +444 -5
599 lines not on this page · raw message
drivers/usb/mausb_host/hpal.h +44 -0
66 lines not on this page · raw message
drivers/usb/mausb_host/hpal_events.c new file +611 -0
611 lines not on this page · raw message
drivers/usb/mausb_host/hpal_events.h new file +85 -0
85 lines not on this page · raw message
drivers/usb/mausb_host/mausb_driver_status.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_MAUSB_DRIVER_STATUS_H__ +#define __MAUSB_MAUSB_DRIVER_STATUS_H__ + +#define MAUSB_DRIVER_BAD_READ_BUFFER_SIZE -1 +#define MAUSB_DRIVER_RING_EVENTS_STOPPED -2 +#define MAUSB_DRIVER_SYSTEM_SUSPENDED -3 +#define MAUSB_DRIVER_COPY_TO_BUFFER_FAILED -4 + +#define MAUSB_DRIVER_READ_TIMEOUT 0 +#define MAUSB_DRIVER_READ_ERROR -1 +#define MAUSB_DRIVER_WRITE_ERROR -2 + +#endif /* __MAUSB_MAUSB_DRIVER_STATUS_H__ */
drivers/usb/mausb_host/utils.c +275 -0
299 lines not on this page · raw message
drivers/usb/mausb_host/utils.h +5 -0
@@ -5,6 +5,8 @@#ifndef __MAUSB_UTILS_H__#define __MAUSB_UTILS_H__ +#include "hpal.h" +#if defined(MAUSB_NO_LOGS )#define mausb_pr_logs (...)#else
@@ -36,5 +38,8 @@int mausb_create_dev (void );void mausb_cleanup_dev (int device_created); +void mausb_notify_completed_user_events (struct mausb_ring_buffer *ring_buffer); +void mausb_notify_ring_events (struct mausb_ring_buffer *ring_buffer); +void mausb_stop_ring_events (void );#endif /* __MAUSB_UTILS_H__ */
Signature · 1 line
2.17.1
kbuild test robot
build botRe: [PATCH v4 7/8] usb: mausb_host: MA-USB PAL events processing
I love your patch! Perhaps something to improve:
Hi,
I love your patch! Perhaps something to improve:
[auto build test WARNING on usb/usb-testing]
[also build test WARNING on balbi-usb/next peter.chen-usb/ci-for-usb-next linus/master linux/master v5.6-rc7 next-20200327] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/vladimir-stankovic-displaylink-com/Add-MA-USB-Host-driver/20200328-042436 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing config: c6x-allyesconfig (attached as .config) compiler: c6x-elf-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=c6x
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
In file included from include/linux/printk.h:7,
from include/linux/kernel.h:15, from include/linux/list.h:9,
from include/linux/preempt.h:11, from include/linux/spinlock.h:51, from include/linux/kref.h:16,
from drivers/usb/mausb_host/hpal.h:8, from drivers/usb/mausb_host/utils.h:8, from drivers/usb/mausb_host/utils.c:5:
drivers/usb/mausb_host/utils.c: In function 'mausb_file_read':
>> include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'ssize_t' {aka 'int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/kern_levels.h:9:20: note: in expansion of macro 'KERN_SOH'
9 | #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
| ^~~~~~~~
include/linux/printk.h:300:9: note: in expansion of macro 'KERN_ALERT'
300 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
>> drivers/usb/mausb_host/utils.h:16:2: note: in expansion of macro 'pr_alert'
16 | pr_##level_str("MAUSB " #level " [%x:%x] [%s] " log "\n",\
| ^~~
>> drivers/usb/mausb_host/utils.h:20:29: note: in expansion of macro 'mausb_pr_logs'
20 | #define mausb_pr_alert(...) mausb_pr_logs(alert, 1, ##__VA_ARGS__)
| ^~~~~~~~~~~~~
>> drivers/usb/mausb_host/utils.c:102:3: note: in expansion of macro 'mausb_pr_alert'
102 | mausb_pr_alert("Different expected bytes to read (%ld) from actual size (%ld)",
| ^~~~~~~~~~~~~~
include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 6 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/kern_levels.h:9:20: note: in expansion of macro 'KERN_SOH'
9 | #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
| ^~~~~~~~
include/linux/printk.h:300:9: note: in expansion of macro 'KERN_ALERT'
300 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
>> drivers/usb/mausb_host/utils.h:16:2: note: in expansion of macro 'pr_alert'
16 | pr_##level_str("MAUSB " #level " [%x:%x] [%s] " log "\n",\
| ^~~
>> drivers/usb/mausb_host/utils.h:20:29: note: in expansion of macro 'mausb_pr_logs'
20 | #define mausb_pr_alert(...) mausb_pr_logs(alert, 1, ##__VA_ARGS__)
| ^~~~~~~~~~~~~
>> drivers/usb/mausb_host/utils.c:102:3: note: in expansion of macro 'mausb_pr_alert'
102 | mausb_pr_alert("Different expected bytes to read (%ld) from actual size (%ld)",
| ^~~~~~~~~~~~~~
drivers/usb/mausb_host/utils.c: In function 'mausb_file_write':
>> include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'ssize_t' {aka 'int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/kern_levels.h:9:20: note: in expansion of macro 'KERN_SOH'
9 | #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
| ^~~~~~~~
include/linux/printk.h:300:9: note: in expansion of macro 'KERN_ALERT'
300 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
>> drivers/usb/mausb_host/utils.h:16:2: note: in expansion of macro 'pr_alert'
16 | pr_##level_str("MAUSB " #level " [%x:%x] [%s] " log "\n",\
| ^~~
>> drivers/usb/mausb_host/utils.h:20:29: note: in expansion of macro 'mausb_pr_logs'
20 | #define mausb_pr_alert(...) mausb_pr_logs(alert, 1, ##__VA_ARGS__)
| ^~~~~~~~~~~~~
drivers/usb/mausb_host/utils.c:193:3: note: in expansion of macro 'mausb_pr_alert'
193 | mausb_pr_alert("Different expected bytes to write (%ld) from actual size (%ld)",
| ^~~~~~~~~~~~~~
include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 6 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/kern_levels.h:9:20: note: in expansion of macro 'KERN_SOH'
9 | #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
| ^~~~~~~~
include/linux/printk.h:300:9: note: in expansion of macro 'KERN_ALERT'
300 | printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
>> drivers/usb/mausb_host/utils.h:16:2: note: in expansion of macro 'pr_alert'
16 | pr_##level_str("MAUSB " #level " [%x:%x] [%s] " log "\n",\
| ^~~
>> drivers/usb/mausb_host/utils.h:20:29: note: in expansion of macro 'mausb_pr_logs'
20 | #define mausb_pr_alert(...) mausb_pr_logs(alert, 1, ##__VA_ARGS__)
| ^~~~~~~~~~~~~
drivers/usb/mausb_host/utils.c:193:3: note: in expansion of macro 'mausb_pr_alert'
193 | mausb_pr_alert("Different expected bytes to write (%ld) from actual size (%ld)",
| ^~~~~~~~~~~~~~
--
drivers/usb/mausb_host/hpal_events.c: In function 'mausb_data_msg_received_event':
>> drivers/usb/mausb_host/hpal_events.c:44:27: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
44 | event->data.recv_buf = (u64)hdr;
| ^
drivers/usb/mausb_host/hpal_events.c: In function 'mausb_isoch_msg_received_event':
drivers/usb/mausb_host/hpal_events.c:66:27: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
66 | event->data.recv_buf = (u64)hdr;
| ^
drivers/usb/mausb_host/hpal_events.c: In function 'mausb_cleanup_delete_data_transfer_event':
>> drivers/usb/mausb_host/hpal_events.c:593:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
593 | struct urb *urb = (struct urb *)event->data.urb;
| ^vim +/pr_alert +16 drivers/usb/mausb_host/utils.h
5f578d5631444d vladimir.stankovic(a)displaylink.com 2020-03-27 9
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 10 #if defined(MAUSB_NO_LOGS)
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 11 #define mausb_pr_logs(...)
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 12 #else
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 13 #include <linux/printk.h>
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 14 #include <linux/sched.h>
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 15 #define mausb_pr_logs(level_str, level, log, ...)\
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 @16 pr_##level_str("MAUSB " #level " [%x:%x] [%s] " log "\n",\
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 17 current->pid, current->tgid, __func__, ##__VA_ARGS__)
cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 18 #endif /* MAUSB_NO_LOGS */cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 19cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 @20 #define mausb_pr_alert(...) mausb_pr_logs(alert, 1, ##__VA_ARGS__) cca4e12f279232 vladimir.stankovic(a)displaylink.com 2020-03-27 21
:::::: The code at line 16 was first introduced by commit
:::::: cca4e12f279232d69e2a551b72966976d5cda619 usb: Add MA-USB Host kernel module
:::::: TO: vladimir.stankovic(a)displaylink.com <[email protected]> :::::: CC: 0day robot <[email protected]>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kbuild test robot
build botRe: [PATCH v4 7/8] usb: mausb_host: MA-USB PAL events processing
In reply to [email protected]I love your patch! Perhaps something to improve:
Hi,
I love your patch! Perhaps something to improve:
[auto build test WARNING on usb/usb-testing]
[also build test WARNING on balbi-usb/next peter.chen-usb/ci-for-usb-next linus/master linux/master v5.6 next-20200403] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/vladimir-stankovic-displaylink-com/Add-MA-USB-Host-driver/20200328-042436 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
If you fix the issue, kindly add following tag as appropriate
coccinelle warnings: (new ones prefixed by >>)
>> drivers/usb/mausb_host/utils.c:209:1-18: ERROR: nested lock+irqsave that reuses flags from line 201. -- >> drivers/usb/mausb_host/hpal_events.c:86:46-49: ERROR: reference preceded by free on line 85
vim +209 drivers/usb/mausb_host/utils.c
182
183 static ssize_t mausb_file_write(struct file *filp, const char __user *buffer,
184 size_t size, loff_t *offset)
185 {
186 ssize_t num_of_bytes_to_write =
187 sizeof(struct mausb_events_notification);
188 struct mausb_events_notification notification;
189 unsigned long flags;
190 struct mausb_device *dev;
191
192 if (size != (size_t)num_of_bytes_to_write) {
193 mausb_pr_alert("Different expected bytes to write (%ld) from actual size (%ld)",
194 num_of_bytes_to_write, size);
195 return MAUSB_DRIVER_WRITE_ERROR;
196 }
197
198 if (copy_from_user(¬ification, buffer, size))
199 return MAUSB_DRIVER_WRITE_ERROR;
200
> 201 spin_lock_irqsave(&mss.lock, flags);
202 dev = mausb_get_dev_from_addr_unsafe(notification.madev_addr);
203
204 if (!dev) {
205 spin_unlock_irqrestore(&mss.lock, flags);
206 return 0;
207 }
208
> 209 spin_lock_irqsave(&dev->num_of_user_events_lock, flags); 210 dev->num_of_user_events += notification.num_of_events;
211 dev->num_of_completed_events += notification.num_of_completed_events;
212 spin_unlock_irqrestore(&dev->num_of_user_events_lock, flags);
213
214 queue_work(dev->workq, &dev->work);
215 spin_unlock_irqrestore(&mss.lock, flags);
216
217 return num_of_bytes_to_write;
218 }
219
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v4 8/8 usb: mausb_host: Process MA-USB data packets
In reply to [email protected]Added implementation of MA-USB data&isoch packets processing logic, both for IN and OUT directions.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hpal.c | 32 +- drivers/usb/mausb_host/hpal_data.c | 719 +++++++++++++++++++++++++++++ drivers/usb/mausb_host/hpal_data.h | 34 ++ 4 files changed, 784 insertions(+), 2 deletions(-) create mode 100644 drivers/usb/mausb_host/hpal_data.c create mode 100644 drivers/usb/mausb_host/hpal_data.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -12,5 +12,6 @@ mausb_host-y += ip_link.o mausb_host-y += hcd.o mausb_host-y += hpal.o mausb_host-y += hpal_events.o +mausb_host-y += hpal_data.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hpal.c +30 -2
@@ -11,6 +11,7 @@#include <linux/uio.h> #include "hcd.h" +#include "hpal_data.h" #include "hpal_events.h" #include "utils.h"
@@ -1387,6 +1388,7 @@ int mausb_send_transfer_ack(struct mausb_device *dev, struct mausb_event *event)int mausb_send_data_msg (struct mausb_device *dev,struct mausb_event *event) {struct mausb_urb_ctx *urb_ctx; +int status =0 ;if (event->status !=0 ) { mausb_pr_err("Event %d failed with status %d",
@@ -1401,9 +1403,22 @@ int mausb_send_data_msg(struct mausb_device *dev, struct mausb_event *event)/* Transfer will be deleted from dequeue task */ mausb_pr_warn ("Urb is already cancelled for event=%d" , event->type); +return status; } -return 0 ; +if (mausb_isoch_data_event (event)) { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) + status =mausb_send_isoch_in_msg (dev, event); +else + status =mausb_send_isoch_out_msg (dev, event, urb_ctx); + }else { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) + status =mausb_send_in_data_msg (dev, event); +else + status =mausb_send_out_data_msg (dev, event, urb_ctx); + } + +return status; }int mausb_receive_data_msg (struct mausb_device *dev,struct mausb_event *event)
@@ -1426,6 +1441,20 @@ int mausb_receive_data_msg(struct mausb_device *dev, struct mausb_event *event)if (!urb_ctx) {/* Transfer will be deleted from dequeue task */ mausb_pr_warn ("Urb is already cancelled" ); + goto cleanup; + } + +if (mausb_isoch_data_event (event)) { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) + status =mausb_receive_isoch_in_data (dev, event, + urb_ctx); +else + status =mausb_receive_isoch_out (event); + }else { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) +mausb_receive_in_data (event, urb_ctx); +else +mausb_receive_out_data (event, urb_ctx); } cleanup:
@@ -1593,7 +1622,6 @@ static void mausb_handle_receive_event(struct mausb_device *dev, status =mausb_msg_received_event (&event, (struct ma_usb_hdr_common *)data, channel); -if (status ==0 ) status =mausb_enqueue_event_to_user (dev, &event);
drivers/usb/mausb_host/hpal_data.c new file +719 -0
719 lines not on this page · raw message
drivers/usb/mausb_host/hpal_data.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_HPAL_DATA_H__ +#define __MAUSB_HPAL_DATA_H__ + +#include <linux/types.h> + +#include "hpal_events.h" + +int mausb_send_in_data_msg (struct mausb_device *dev,struct mausb_event *event); +void mausb_receive_in_data (struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +int mausb_send_out_data_msg (struct mausb_device *dev,struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); +void mausb_receive_out_data (struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +#define MAUSB_ISOCH_IN_KVEC_NUM 3 + +int mausb_send_isoch_in_msg (struct mausb_device *dev, +struct mausb_event *event); +int mausb_receive_isoch_in_data (struct mausb_device *dev, +struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +int mausb_send_isoch_out_msg (struct mausb_device *ma_dev, +struct mausb_event *mausb_event, +struct mausb_urb_ctx *urb_ctx); +int mausb_receive_isoch_out (struct mausb_event *event); + +#endif /* __MAUSB_HPAL_DATA_H__ */
Signature · 1 line
2.17.1
v5 cover Add MA USB Host driver
In reply to [email protected]Media Agnostic (MA) USB Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
This driver depends on the functions provided by DisplayLink's user-space driver.
v2:
- Fixed licensing info in headers
- Reorganized code to lower file count
- Patch has been split into 8 smaller patches
v3:
- Fixed nested spinlock usage
- Implemented IPv6 support
v4:
- No code changes
- Re-sent patch with different mail client config
v5:
- Updated kernel configuration with MA info
- Addressed build warnings for c6x architecture
- Fixed coccinelle warnings
Vladimir Stankovic (8):
usb: Add MA-USB Host kernel module
usb: mausb_host: Add link layer implementation
usb: mausb_host: HCD initialization
usb: mausb_host: Implement initial hub handlers
usb: mausb_host: Introduce PAL processing
usb: mausb_host: Add logic for PAL-to-PAL communication
usb: mausb_host: MA-USB PAL events processing
usb: mausb_host: Process MA-USB data packets
MAINTAINERS | 7 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/mausb_host/Kconfig | 15 + drivers/usb/mausb_host/Makefile | 17 + drivers/usb/mausb_host/hcd.c | 1874 ++++++++++++++++ drivers/usb/mausb_host/hcd.h | 162 ++ drivers/usb/mausb_host/hpal.c | 2082 ++++++++++++++++++ drivers/usb/mausb_host/hpal.h | 339 +++ drivers/usb/mausb_host/hpal_data.c | 714 ++++++ drivers/usb/mausb_host/hpal_data.h | 34 + drivers/usb/mausb_host/hpal_events.c | 611 +++++ drivers/usb/mausb_host/hpal_events.h | 85 + drivers/usb/mausb_host/ip_link.c | 374 ++++ drivers/usb/mausb_host/ip_link.h | 87 + drivers/usb/mausb_host/ma_usb.h | 869 ++++++++ drivers/usb/mausb_host/mausb_address.h | 26 + drivers/usb/mausb_host/mausb_core.c | 212 ++ drivers/usb/mausb_host/mausb_driver_status.h | 17 + drivers/usb/mausb_host/mausb_event.h | 224 ++ drivers/usb/mausb_host/utils.c | 358 +++ drivers/usb/mausb_host/utils.h | 45 + 22 files changed, 8156 insertions(+) create mode 100644 drivers/usb/mausb_host/Kconfig create mode 100644 drivers/usb/mausb_host/Makefile create mode 100644 drivers/usb/mausb_host/hcd.c create mode 100644 drivers/usb/mausb_host/hcd.h create mode 100644 drivers/usb/mausb_host/hpal.c create mode 100644 drivers/usb/mausb_host/hpal.h create mode 100644 drivers/usb/mausb_host/hpal_data.c create mode 100644 drivers/usb/mausb_host/hpal_data.h create mode 100644 drivers/usb/mausb_host/hpal_events.c create mode 100644 drivers/usb/mausb_host/hpal_events.h create mode 100644 drivers/usb/mausb_host/ip_link.c create mode 100644 drivers/usb/mausb_host/ip_link.h create mode 100644 drivers/usb/mausb_host/ma_usb.h create mode 100644 drivers/usb/mausb_host/mausb_address.h create mode 100644 drivers/usb/mausb_host/mausb_core.c create mode 100644 drivers/usb/mausb_host/mausb_driver_status.h create mode 100644 drivers/usb/mausb_host/mausb_event.h create mode 100644 drivers/usb/mausb_host/utils.c create mode 100644 drivers/usb/mausb_host/utils.h
base-commit: ab51cac00ef2859f20a73d33a53f3a8987b65e11
Signature · 1 line
2.17.1
PATCH v5 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.
--- MAINTAINERS | 7 +++ drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/mausb_host/Kconfig | 15 +++++ 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, 253 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
MAINTAINERS +7 -0
@@ -10352,6 +10352,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/mausb_host/* + MCAN MMIO DEVICE DRIVER M: Dan Murphy <[email protected]> M: Sriram Dash <[email protected]>
drivers/usb/Kconfig +2 -0
@@ -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"
drivers/usb/Makefile +2 -0
@@ -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/
drivers/usb/mausb_host/Kconfig new file +15 -0
@@ -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 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.
drivers/usb/mausb_host/Makefile new file +12 -0
@@ -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)
drivers/usb/mausb_host/mausb_core.c new file +90 -0
90 lines not on this page · raw message
drivers/usb/mausb_host/utils.c new file +85 -0
85 lines not on this page · raw message
drivers/usb/mausb_host/utils.h new file +40 -0
@@ -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.3.0.0.6f5beb53) + +int mausb_create_dev (void ); +void mausb_cleanup_dev (int device_created); + +#endif /* __MAUSB_UTILS_H__ */
Signature · 1 line
2.17.1
Greg KH
maintainerRe: [PATCH v5 1/8] usb: Add MA-USB Host kernel module
Quoted 68 lines · On Sat, Apr 25, 2020 at 11:19:47AM +0200, [email protected]…
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 | 15 +++++ 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, 253 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.hMAINTAINERS +7
-0@@ -10352,6 +10352,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/mausb_host/* + MCAN MMIO DEVICE DRIVER M: Dan Murphy <[email protected]> M: Sriram Dash <[email protected]>drivers/usb/Kconfig +2
-0@@ -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"drivers/usb/Makefile +2
-0@@ -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/drivers/usb/mausb_host/Kconfig new file +0
-0
drivers/usb/mausb_host/Kconfig line 10
Quoted 10 lines
drivers/usb/mausb_host/Kconfig new file +10
-0@@ -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 HOST_MAUSB + tristate "Media Agnostic (MA) USB Host Driver" + depends on USB=y
Why can't USB=m?
drivers/usb/mausb_host/Kconfig line 15
Quoted 5 lines
drivers/usb/mausb_host/Kconfig new file +5
-0+ 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.
And why isn't this all in drivers/usb/host/ ? Why a separate directory?
If you really need your own directory, why not drivers/usb/host/mausb/ ?
Quoted 8 lines
drivers/usb/mausb_host/Makefile new file +2
-0@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +#
drivers/usb/mausb_host/Makefile line 12
Quoted 10 lines
drivers/usb/mausb_host/Makefile new file +10
-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)
Ick, really? Why? You should not need this.
drivers/usb/mausb_host/mausb_core.c line 6
Quoted 12 lines
drivers/usb/mausb_host/mausb_core.c new file +6
-0@@ -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>
Why do you need these two .h files for this file at this time?
drivers/usb/mausb_host/mausb_core.c line 11
Quoted 5 lines
drivers/usb/mausb_host/mausb_core.c new file +5
-0+#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/kobject.h> +#include <linux/module.h> +#include <linux/moduleparam.h>
You have no module parameters here, why do you need this?
drivers/usb/mausb_host/mausb_core.c line 12
Quoted 1 line
drivers/usb/mausb_host/mausb_core.c new file +1
-0+#include <linux/net.h>
Why do you need this?
drivers/usb/mausb_host/mausb_core.c line 23
Quoted 11 lines
drivers/usb/mausb_host/mausb_core.c new file +11
-0+ +#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 );
No custom driver "printk" macros please. We have been stomping them out for years. Just use dev_*() instead.
And a driver version means nothing when it is in the kernel itself, please just remove.
drivers/usb/mausb_host/mausb_core.c line 31
Quoted 8 lines
drivers/usb/mausb_host/mausb_core.c new file +8
-0+ +return 0 ; +} + +static int mausb_client_disconnect (const char *value, +const struct kernel_param *kp) +{ +mausb_pr_info ("Version=%s" ,MAUSB_DRIVER_VERSION );
Also, why info? This is just fun debugging stuff, don't do that, that is what ftrace is for.
If you are trying to provide stubs to later fill in, that's fine, but don't clutter it up with this type of stuff please.
drivers/usb/mausb_host/mausb_core.c line 36
Quoted 5 lines
drivers/usb/mausb_host/mausb_core.c new file +5
-0+int mausb_create_dev (void ) +{ +int device_created =0 ; +int status =alloc_chrdev_region (&mausb_major_kernel,0 ,1 , +MAUSB_KERNEL_DEV_NAME "_proc" );
Why does a USB host driver need a char dev node?
drivers/usb/mausb_host/mausb_core.c line 41
Quoted 5 lines
drivers/usb/mausb_host/mausb_core.c new file +5
-0+if (status) + goto cleanup; + + mausb_kernel_class =class_create (THIS_MODULE , +MAUSB_KERNEL_DEV_NAME "_sys" );
Why do you need your own class that has a different name from your device node? None of that should be needed at all here, right?
drivers/usb/mausb_host/mausb_core.c line 52
Quoted 11 lines
drivers/usb/mausb_host/mausb_core.c new file +11
-0+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 ;
You set this and never touch it again :(
Oh wait, you pass it into a cleanup function later, which isn't really needed anyway.
drivers/usb/mausb_host/mausb_core.c line 54
Quoted 2 lines
drivers/usb/mausb_host/mausb_core.c new file +2
-0+cdev_init (&mausb_kernel_dev, &mausb_file_ops); + status =cdev_add (&mausb_kernel_dev, mausb_major_kernel,1 );
one device node? If you REALLY need it, just use a misc device, but we need a ton of documentation here as to what you are doing with this, and why it is needed, because as-is, I have no idea just looking at this patch :(
drivers/usb/mausb_host/mausb_core.c line 65
Quoted 11 lines
drivers/usb/mausb_host/mausb_core.c new file +11
-0+if (status) + goto cleanup; +return 0 ; +cleanup: +mausb_cleanup_dev (device_created); +return status; +} + +void mausb_cleanup_dev (int device_created) +{ +if (device_created) {
So this isn't a global variable??
That really isn't needed, please don't.
Quoted 35 lines
drivers/usb/mausb_host/mausb_core.c new file +9
-0+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 ); +}drivers/usb/mausb_host/utils.h new file +20
-0@@ -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__)
drivers/usb/mausb_host/utils.h line 30
Quoted 10 lines
drivers/usb/mausb_host/utils.h new file +10
-0+ +#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) */
Again, drop all of this, and use the build-in kernel functions, there's nothing special about this one tiny driver to override uniformity.
drivers/usb/mausb_host/utils.h line 33
Quoted 3 lines
drivers/usb/mausb_host/utils.h new file +3
-0+ +#define MAUSB_STRINGIFY2 (x) #x +#define MAUSB_STRINGIFY (x) MAUSB_STRINGIFY2(x)
Ick, why???
drivers/usb/mausb_host/utils.h line 35
Quoted 2 lines
drivers/usb/mausb_host/utils.h new file +2
-0+ +#define MAUSB_DRIVER_VERSION MAUSB_STRINGIFY(1.3.0.0.6f5beb53)
That's funny. And pointless :)
drivers/usb/mausb_host/utils.h line 38
Quoted 3 lines
drivers/usb/mausb_host/utils.h new file +3
-0+ +int mausb_create_dev (void ); +void mausb_cleanup_dev (int device_created);
No need for that parameter.
thanks,
greg k-h
PATCH v5 2/8 usb: mausb_host: Add link layer implementation
In reply to [email protected]Implemented link layer using kernel sockets. Link layer manages network communication and provides interface for upper layers of MA-USB stack.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/ip_link.c | 374 +++++++++++++++++++++++++++++++ drivers/usb/mausb_host/ip_link.h | 87 +++++++ 3 files changed, 462 insertions(+) create mode 100644 drivers/usb/mausb_host/ip_link.c create mode 100644 drivers/usb/mausb_host/ip_link.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -8,5 +8,6 @@ obj-$(CONFIG_HOST_MAUSB) += mausb_host.o mausb_host-y := mausb_core.o mausb_host-y += utils.o +mausb_host-y += ip_link.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/ip_link.c new file +374 -0
374 lines not on this page · raw message
drivers/usb/mausb_host/ip_link.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 3/8 usb: mausb_host: HCD initialization
In reply to [email protected]Implemented HCD initialization/deinitialization functionality.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hcd.c | 188 ++++++++++++++++++++++++++++ drivers/usb/mausb_host/hcd.h | 71 +++++++++++ drivers/usb/mausb_host/mausb_core.c | 20 ++- 4 files changed, 275 insertions(+), 5 deletions(-) create mode 100644 drivers/usb/mausb_host/hcd.c create mode 100644 drivers/usb/mausb_host/hcd.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -9,5 +9,6 @@ obj-$(CONFIG_HOST_MAUSB) += mausb_host.o mausb_host-y := mausb_core.o mausb_host-y += utils.o mausb_host-y += ip_link.o +mausb_host-y += hcd.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hcd.c new file +188 -0
188 lines not on this page · raw message
drivers/usb/mausb_host/hcd.h new file +71 -0
71 lines not on this page · raw message
drivers/usb/mausb_host/mausb_core.c +15 -5
@@ -11,6 +11,7 @@#include <linux/moduleparam.h> #include <linux/net.h> +#include "hcd.h" #include "utils.h" MODULE_LICENSE ("GPL" );
@@ -67,21 +68,30 @@ static const struct kernel_param_ops mausb_client_disconnect_ops = {static int mausb_host_init (void ) { -int status =mausb_create_dev (); +int status;mausb_pr_info ("Module load. Version=%s" ,MAUSB_DRIVER_VERSION ); + status =mausb_init_hcd (); +if (status <0 ) + goto cleanup; -if (status <0 ) { -mausb_pr_alert ("Failed to load MAUSB module!" ); -return status; - } + status =mausb_create_dev (); +if (status <0 ) + goto cleanup_hcd;return 0 ; + +cleanup_hcd: +mausb_deinit_hcd (); +cleanup: +mausb_pr_alert ("Failed to load MAUSB module!" ); +return status; }static void mausb_host_exit (void ) {mausb_pr_info ("Module unloading started..." ); +mausb_deinit_hcd ();mausb_cleanup_dev (1 );mausb_pr_info ("Module unloaded. Version=%s" ,MAUSB_DRIVER_VERSION ); }
Signature · 1 line
2.17.1
Greg KH
maintainerRe: [PATCH v5 3/8] usb: mausb_host: HCD initialization
drivers/usb/mausb_host/hcd.c line 117
Quoted 6 lines · On Sat, Apr 25, 2020 at 11:19:49AM +0200, [email protected]…
drivers/usb/mausb_host/hcd.c new file +6
-0+static long mausb_ioctl (struct file *file,unsigned int ioctl_func, +unsigned long ioctl_buffer) +{ +return 0 ; +} +
Why do you have an ioctl that does nothing? Same for the other functions that just return "success", if you don't do anything in them, don't declare them please.
drivers/usb/mausb_host/hcd.c line 122
Quoted 5 lines
drivers/usb/mausb_host/hcd.c new file +5
-0+int mausb_init_hcd (void ) +{ +int retval; + + retval =register_chrdev (0 ,DEVICE_NAME , &mausb_fops);
But you already have a chardev? Why use another one?
I don't understand the need for these, it's not obvious at all, please provide a lot more information on what is going on with these userspace facing interfaces please.
thanks,
greg k-h
PATCH v5 4/8 usb: mausb_host: Implement initial hub handlers
In reply to [email protected]Implemented handlers for subset of HCD events.
--- drivers/usb/mausb_host/hcd.c | 948 ++++++++++++++++++++++++++++++++++- drivers/usb/mausb_host/hcd.h | 86 +++- 2 files changed, 1030 insertions(+), 4 deletions(-)
drivers/usb/mausb_host/hcd.c +947 -1
@@ -71,7 +71,7 @@ static void mausb_remove(void)static int mausb_bus_probe (struct device *dev) { -return 0 ; +return mausb_probe (dev); }static int mausb_bus_remove (struct device *dev)
@@ -159,7 +159,15 @@ int mausb_init_hcd(void) device->driver = &mausb_driver; + retval =mausb_probe (device); +if (retval) { +mausb_pr_err ("Mausb_probe failed" ); + goto mausb_probe_failed; + } +return retval; +mausb_probe_failed: +device_destroy (mausb_class, devt); device_create_error:kfree (mhcd); mhcd =NULL ;
@@ -186,3 +194,941 @@ void mausb_deinit_hcd(void)unregister_chrdev (major,DEVICE_NAME ); } } + +static const char driver_name[] ="MA-USB host controller" ; + +static void mausb_get_hub_descriptor (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length); +static void mausb_set_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static void mausb_get_port_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static void mausb_clear_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length); +static void mausb_get_hub_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static int mausb_add_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint); +static int mausb_address_device (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_alloc_dev (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_check_bandwidth (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_drop_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint); +static int mausb_enable_device (struct usb_hcd *hcd,struct usb_device *dev); +static void mausb_endpoint_disable (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint); +static void mausb_endpoint_reset (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint); +static void mausb_free_dev (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_hcd_bus_resume (struct usb_hcd *hcd); +static int mausb_hcd_bus_suspend (struct usb_hcd *hcd); +static int mausb_hcd_get_frame_number (struct usb_hcd *hcd); +static int mausb_hcd_hub_control (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static int mausb_hcd_hub_status (struct usb_hcd *hcd,char *buff); +static int mausb_hcd_reset (struct usb_hcd *hcd); +static int mausb_hcd_start (struct usb_hcd *hcd); +static void mausb_hcd_stop (struct usb_hcd *hcd); +static int mausb_hub_update_device (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_tt *tt,gfp_t mem_flags); +static void mausb_reset_bandwidth (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_reset_device (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_update_device (struct usb_hcd *hcd,struct usb_device *dev); + +static const struct hc_driver mausb_hc_driver = { + .description = driver_name, + .product_desc = driver_name, + .flags =HCD_USB3 |HCD_SHARED , + + .hcd_priv_size =sizeof (struct hub_ctx ), + + .reset = mausb_hcd_reset, + .start = mausb_hcd_start, + .stop = mausb_hcd_stop, + + .get_frame_number = mausb_hcd_get_frame_number, + + .hub_status_data = mausb_hcd_hub_status, + .hub_control = mausb_hcd_hub_control, + .update_hub_device = mausb_hub_update_device, + .bus_suspend = mausb_hcd_bus_suspend, + .bus_resume = mausb_hcd_bus_resume, + + .alloc_dev = mausb_alloc_dev, + .free_dev = mausb_free_dev, + .enable_device = mausb_enable_device, + .update_device = mausb_update_device, + .reset_device = mausb_reset_device, + + .add_endpoint = mausb_add_endpoint, + .drop_endpoint = mausb_drop_endpoint, + .check_bandwidth = mausb_check_bandwidth, + .reset_bandwidth = mausb_reset_bandwidth, + .address_device = mausb_address_device, + .endpoint_disable = mausb_endpoint_disable, + .endpoint_reset = mausb_endpoint_reset, +}; + +static struct { +struct usb_bos_descriptor bos; +struct usb_ss_cap_descriptor ss_cap; +} usb3_bos_desc = { + .bos = { + .bLength =USB_DT_BOS_SIZE , + .bDescriptorType =USB_DT_BOS , + .wTotalLength =cpu_to_le16 (sizeof (usb3_bos_desc)), + .bNumDeviceCaps =1 + }, + .ss_cap = { + .bLength =USB_DT_USB_SS_CAP_SIZE , + .bDescriptorType =USB_DT_DEVICE_CAPABILITY , + .bDevCapabilityType =USB_SS_CAP_TYPE , + .wSpeedSupported =cpu_to_le16 (USB_5GBPS_OPERATION ), + .bFunctionalitySupport =ilog2 (USB_5GBPS_OPERATION ) + } +}; + +static int get_root_hub_port_number (struct usb_device *dev,u8 *port_number) +{ +struct usb_device *first_hub_device = dev; + +if (!dev->parent) { + (*port_number) =0 ; +return -EINVAL ; + } + +while (first_hub_device->parent->parent) + first_hub_device = first_hub_device->parent; + + (*port_number) = first_hub_device->portnum -1 ; + +return 0 ; +} + +static struct mausb_usb_device_ctx *mausb_find_usb_device (struct mausb_dev + *mdevs,void *dev_addr) +{ +struct rb_node *node = mdevs->usb_devices.rb_node; + +while (node) { +struct mausb_usb_device_ctx *usb_device = + rb_entry(node, struct mausb_usb_device_ctx, rb_node); + +if (dev_addr < usb_device->dev_addr) + node = usb_device->rb_node.rb_left; +else if (dev_addr > usb_device->dev_addr) + node = usb_device->rb_node.rb_right; +else +return usb_device; + } +return NULL ; +} + +static int mausb_hcd_get_frame_number (struct usb_hcd *hcd) +{ +return 0 ; +} + +static int mausb_hcd_reset (struct usb_hcd *hcd) +{ +if (usb_hcd_is_primary_hcd (hcd)) { + hcd->speed =HCD_USB2 ; + hcd->self.root_hub->speed =USB_SPEED_HIGH ; + }else { + hcd->speed =HCD_USB3 ; + hcd->self.root_hub->speed =USB_SPEED_SUPER ; + } + hcd->self.no_sg_constraint =1 ; + hcd->self.sg_tablesize =UINT_MAX ; + +return 0 ; +} + +static int mausb_hcd_start (struct usb_hcd *hcd) +{ + hcd->power_budget =0 ; + hcd->uses_new_polling =1 ; +return 0 ; +} + +static void mausb_hcd_stop (struct usb_hcd *hcd) +{ +mausb_pr_debug ("Not implemented" ); +} + +static int mausb_hcd_hub_status (struct usb_hcd *hcd,char *buff) +{ +int retval; +int changed; +int i; +struct hub_ctx *hub; +unsigned long flags =0 ; + + hub = (struct hub_ctx *)hcd->hcd_priv; + + retval =DIV_ROUND_UP (NUMBER_OF_PORTS +1 ,8 ); + changed =0 ; + +memset (buff,0 , (unsigned int )retval); + +spin_lock_irqsave (&mhcd->lock, flags); + +if (!HCD_HW_ACCESSIBLE (hcd)) { +mausb_pr_info ("hcd not accessible, hcd speed=%d" , hcd->speed); +spin_unlock_irqrestore (&mhcd->lock, flags); +return 0 ; + } + +for (i =0 ; i <NUMBER_OF_PORTS ; ++i) { +if ((hub->ma_devs[i].port_status &PORT_C_MASK )) { + buff[(i +1 ) /8 ] |=1 << (i +1 ) %8 ; + changed =1 ; + } + } + +mausb_pr_info ("Usb %d.0 : changed=%d, retval=%d" , + (hcd->speed ==HCD_USB2 ) ?2 :3 , changed, retval); + +if (hcd->state ==HC_STATE_SUSPENDED && changed ==1 ) { +mausb_pr_info ("hcd state is suspended" ); +usb_hcd_resume_root_hub (hcd); + } + +spin_unlock_irqrestore (&mhcd->lock, flags); + +return changed ? retval :0 ; +} + +static int mausb_hcd_bus_resume (struct usb_hcd *hcd) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mhcd->lock, flags); +if (!HCD_HW_ACCESSIBLE (hcd)) { +mausb_pr_info ("hcd not accessible, hcd speed=%d" , hcd->speed); +spin_unlock_irqrestore (&mhcd->lock, flags); +return -ESHUTDOWN ; + } + hcd->state =HC_STATE_RUNNING ; +spin_unlock_irqrestore (&mhcd->lock, flags); + +return 0 ; +} + +static int mausb_hcd_bus_suspend (struct usb_hcd *hcd) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mhcd->lock, flags); + hcd->state =HC_STATE_SUSPENDED ; +spin_unlock_irqrestore (&mhcd->lock, flags); + +return 0 ; +} + +static int mausb_hcd_hub_control (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +int retval =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_hcd *hub_mhcd = hub->mhcd; +unsigned long flags; +bool invalid_rhport = false; + + index = ((__u8)(index &0x00ff )); +if (index <1 || index >NUMBER_OF_PORTS ) + invalid_rhport = true; + +mausb_pr_info ("TypeReq=%d" , type_req); + +spin_lock_irqsave (&hub_mhcd->lock, flags); + +if (!HCD_HW_ACCESSIBLE (hcd)) { +mausb_pr_info ("hcd not accessible, hcd speed=%d" , hcd->speed); +spin_unlock_irqrestore (&hub_mhcd->lock, flags); +return -ETIMEDOUT ; + } + +switch (type_req) { +case ClearHubFeature: +break ; +case ClearPortFeature: +if (invalid_rhport) + goto invalid_port; + +mausb_clear_port_feature (hcd, type_req, value, index, buff, + length); +break ; +case DeviceRequest |USB_REQ_GET_DESCRIPTOR : +memcpy (buff, &usb3_bos_desc,sizeof (usb3_bos_desc)); + retval =sizeof (usb3_bos_desc); +break ; +case GetHubDescriptor: +mausb_get_hub_descriptor (hcd, type_req, value, index, buff, + length); +break ; +case GetHubStatus: +mausb_get_hub_status (hcd, type_req, value, index, buff, + length); +break ; +case GetPortStatus: +if (invalid_rhport) + goto invalid_port; + +mausb_get_port_status (hcd, type_req, value, index, buff, + length); +break ; +case SetHubFeature: + retval = -EPIPE ; +break ; +case SetPortFeature: +if (invalid_rhport) + goto invalid_port; + +mausb_set_port_feature (hcd, type_req, value, index, buff, + length); +break ; +default : + retval = -EPIPE ; + } + +invalid_port: +spin_unlock_irqrestore (&hub_mhcd->lock, flags); +return retval; +} + +int mausb_probe (struct device *dev) +{ +struct mausb_hcd *mausb_hcd; +struct usb_hcd *hcd_ss; +struct usb_hcd *hcd_hs; +int ret; + + mausb_hcd =dev_get_drvdata (dev); +spin_lock_init (&mausb_hcd->lock); + + hcd_hs =usb_create_hcd (&mausb_hc_driver, dev,dev_name (dev)); +if (!hcd_hs) +return -ENOMEM ; + + hcd_hs->has_tt =1 ; + mausb_hcd->hcd_hs_ctx = (struct hub_ctx *)hcd_hs->hcd_priv; + mausb_hcd->hcd_hs_ctx->mhcd = mausb_hcd; + mausb_hcd->hcd_hs_ctx->hcd = hcd_hs; +memset (mausb_hcd->hcd_hs_ctx->ma_devs,0 , +sizeof (struct mausb_dev ) *NUMBER_OF_PORTS ); + + ret =usb_add_hcd (hcd_hs,0 ,0 ); +if (ret) { +mausb_pr_err ("usb_add_hcd failed" ); + goto put_hcd_hs; + } + + hcd_ss =usb_create_shared_hcd (&mausb_hc_driver, dev,dev_name (dev), + hcd_hs); +if (!hcd_ss) { + ret = -ENOMEM ; + goto remove_hcd_hs; + } + mausb_hcd->hcd_ss_ctx = (struct hub_ctx *)hcd_ss->hcd_priv; + mausb_hcd->hcd_ss_ctx->mhcd = mausb_hcd; + mausb_hcd->hcd_ss_ctx->hcd = hcd_ss; + +memset (mausb_hcd->hcd_ss_ctx->ma_devs,0 , +sizeof (struct mausb_dev ) *NUMBER_OF_PORTS ); + + ret =usb_add_hcd (hcd_ss,0 ,0 ); +if (ret) { +mausb_pr_err ("usb_add_hcd failed" ); + goto put_hcd_ss; + } + +return ret; + +put_hcd_ss: +usb_put_hcd (hcd_ss); +remove_hcd_hs: +usb_remove_hcd (hcd_hs); +put_hcd_hs: +usb_put_hcd (hcd_hs); + mausb_hcd->hcd_hs_ctx =NULL ; + mausb_hcd->hcd_ss_ctx =NULL ; +return ret; +} + +static void mausb_get_hub_descriptor (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length) +{ +u8 width; +struct usb_hub_descriptor *desc = (struct usb_hub_descriptor *)buff; + +memset (desc,0 ,sizeof (struct usb_hub_descriptor )); + +if (hcd->speed ==HCD_USB3 ) { + desc->bDescriptorType =USB_DT_SS_HUB ; + desc->bDescLength =12 ; + desc->wHubCharacteristics = +cpu_to_le16 (HUB_CHAR_INDV_PORT_LPSM |HUB_CHAR_COMMON_OCPM ); + desc->bNbrPorts =NUMBER_OF_PORTS ; + desc->u.ss.bHubHdrDecLat =0x04 ; + desc->u.ss.DeviceRemovable =cpu_to_le16 (0xffff ); + }else { + desc->bDescriptorType =USB_DT_HUB ; + desc->wHubCharacteristics = +cpu_to_le16 (HUB_CHAR_INDV_PORT_LPSM |HUB_CHAR_COMMON_OCPM ); + desc->bNbrPorts =NUMBER_OF_PORTS ; + width = (u8)(desc->bNbrPorts /8 +1 ); + desc->bDescLength =USB_DT_HUB_NONVAR_SIZE +2 * width; + +memset (&desc->u.hs.DeviceRemovable[0 ],0 , width); +memset (&desc->u.hs.DeviceRemovable[width],0xff , width); + } +} + +static void mausb_set_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +switch (value) { +case USB_PORT_FEAT_LINK_STATE : +mausb_pr_debug ("USB_PORT_FEAT_LINK_STATE" ); +if (hcd->speed ==HCD_USB3 ) { +if ((hub->ma_devs[index -1 ].port_status & +USB_SS_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + }else { +if ((hub->ma_devs[index -1 ].port_status & +USB_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + } +break ; +case USB_PORT_FEAT_U1_TIMEOUT : +case USB_PORT_FEAT_U2_TIMEOUT : +break ; +case USB_PORT_FEAT_SUSPEND : +break ; +case USB_PORT_FEAT_POWER : +mausb_pr_debug ("USB_PORT_FEAT_POWER" ); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status |= +USB_SS_PORT_STAT_POWER ; + }else { + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_POWER ; + } +break ; +case USB_PORT_FEAT_BH_PORT_RESET : +mausb_pr_debug ("USB_PORT_FEAT_BH_PORT_RESET" ); +case USB_PORT_FEAT_RESET : +mausb_pr_debug ("USB_PORT_FEAT_RESET hcd->speed=%d" , hcd->speed); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status =0 ; + hub->ma_devs[index -1 ].port_status = + (USB_SS_PORT_STAT_POWER | +USB_PORT_STAT_CONNECTION |USB_PORT_STAT_RESET ); + }else if (hub->ma_devs[index -1 ].port_status + &USB_PORT_STAT_ENABLE ) { + hub->ma_devs[index -1 ].port_status &= + ~(USB_PORT_STAT_ENABLE | +USB_PORT_STAT_LOW_SPEED | +USB_PORT_STAT_HIGH_SPEED ); + } +default : +mausb_pr_info ("Default value=%d" , value); + +if (hcd->speed ==HCD_USB3 ) { +if ((hub->ma_devs[index -1 ].port_status & +USB_SS_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + }else { +if ((hub->ma_devs[index -1 ].port_status & +USB_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + } + } +} + +static void mausb_get_port_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +u8 dev_speed; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +if ((hub->ma_devs[index -1 ].port_status & + (1 <<USB_PORT_FEAT_RESET )) !=0 ) { +mausb_pr_info ("Finished reset hcd->speed=%d" , hcd->speed); + + dev_speed = hub->ma_devs[index -1 ].dev_speed; +switch (dev_speed) { +case LOW_SPEED : + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_LOW_SPEED ; +break ; +case HIGH_SPEED : + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_HIGH_SPEED ; +break ; +default : +mausb_pr_info ("Not updating port_status for device speed %d" , + dev_speed); + } + + hub->ma_devs[index -1 ].port_status |= + (1 <<USB_PORT_FEAT_C_RESET ) |USB_PORT_STAT_ENABLE ; + hub->ma_devs[index -1 ].port_status &= + ~(1 <<USB_PORT_FEAT_RESET ); + } + + ((__le16 *)buff)[0 ] =cpu_to_le16 (hub->ma_devs[index -1 ].port_status); + ((__le16 *)buff)[1 ] = +cpu_to_le16 (hub->ma_devs[index -1 ].port_status >>16 ); + +mausb_pr_info ("port_status=%d" , hub->ma_devs[index -1 ].port_status); +} + +static void mausb_clear_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length) +{ +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +switch (value) { +case USB_PORT_FEAT_SUSPEND : +break ; +case USB_PORT_FEAT_POWER : +mausb_pr_debug ("USB_PORT_FEAT_POWER" ); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status &= + ~USB_SS_PORT_STAT_POWER ; + }else { + hub->ma_devs[index -1 ].port_status &= + ~USB_PORT_STAT_POWER ; + } +break ; +case USB_PORT_FEAT_RESET : + +case USB_PORT_FEAT_C_RESET : + +default : +mausb_pr_info ("Default value: %d" , value); + + hub->ma_devs[index -1 ].port_status &= ~(1 << value); + } +} + +static void mausb_get_hub_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ + *(__le32 *)buff =cpu_to_le32 (0 ); +} + +static int mausb_alloc_dev (struct usb_hcd *hcd,struct usb_device *dev) +{ +mausb_pr_info ("Usb device=%p" , dev); + +return 1 ; +} + +static void mausb_free_dev (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number; +s16 dev_handle; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_dev *mdev =NULL ; +struct mausb_usb_device_ctx *usb_device_ctx; +struct mausb_endpoint_ctx *ep_ctx = dev->ep0.hcpriv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return ; + } + + mdev = &hub->ma_devs[port_number]; + + usb_device_ctx =mausb_find_usb_device (mdev, dev); +if (!usb_device_ctx) { +mausb_pr_warn ("device_ctx is not found" ); +return ; + } + + dev_handle = usb_device_ctx->dev_handle; + +if (ep_ctx) { + dev->ep0.hcpriv =NULL ; +kfree (ep_ctx); + + }else { +mausb_pr_warn ("ep_ctx is NULL: dev_handle=%#x" , dev_handle); + } + +rb_erase (&usb_device_ctx->rb_node, &mdev->usb_devices); +mausb_pr_info ("USB device deleted device=%p" , usb_device_ctx->dev_addr); +kfree (usb_device_ctx); +} + +static int mausb_address_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; +struct mausb_endpoint_ctx *endpoint_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_warn ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) +return -ENODEV ; + +mausb_pr_info ("dev_handle=%#x, dev_speed=%#x" , + usb_device_ctx->dev_handle, dev->speed); + +if (dev->speed >=USB_SPEED_SUPER ) +mausb_pr_info ("USB 3.0" ); +else +mausb_pr_info ("USB 2.0" ); + +if (usb_device_ctx->dev_handle ==DEV_HANDLE_NOT_ASSIGNED ) { + status =mausb_enable_device (hcd, dev); +if (status <0 ) +return status; + } + + endpoint_ctx = dev->ep0.hcpriv; +if (!endpoint_ctx) { +mausb_pr_err ("endpoint_ctx is NULL: dev_handle=%#x" , + usb_device_ctx->dev_handle); +return -EINVAL ; + } + +return 0 ; +} + +static int mausb_add_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint) +{ +int status; +u8 port_number; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_dev_ctx; +struct mausb_endpoint_ctx *endpoint_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return 0 ; + } + + usb_dev_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!usb_dev_ctx) { +mausb_pr_warn ("Device not found" ); +return -ENODEV ; + } + + endpoint_ctx =kzalloc (sizeof (*endpoint_ctx),GFP_ATOMIC ); +if (!endpoint_ctx) +return -ENOMEM ; + + endpoint_ctx->dev_handle = usb_dev_ctx->dev_handle; + endpoint_ctx->usb_device_ctx = usb_dev_ctx; + endpoint->hcpriv = endpoint_ctx; + +return 0 ; +} + +static int mausb_drop_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint) +{ +u8 port_number; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_dev_ctx; +struct mausb_endpoint_ctx *endpoint_ctx = endpoint->hcpriv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_dev_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!endpoint_ctx) { +mausb_pr_err ("Endpoint context doesn't exist" ); +return 0 ; + } +if (!usb_dev_ctx) { +mausb_pr_err ("Usb device context doesn't exist" ); +return -ENODEV ; + } + + endpoint->hcpriv =NULL ; +kfree (endpoint_ctx); +return 0 ; +} + +static int mausb_enable_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +int status; +u8 port_number; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) +return -ENODEV ; + +mausb_pr_info ("Device assigned and addressed usb_device_ctx=%p" , + usb_device_ctx); + +return 0 ; +} + +static int mausb_is_hub_device (struct usb_device *dev) +{ +return dev->descriptor.bDeviceClass ==0x09 ; +} + +static int mausb_update_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number =0 ; +int status =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx =NULL ; + +if (mausb_is_hub_device (dev)) { +mausb_pr_warn ("Device is hub" ); +return 0 ; + } + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) { +mausb_pr_warn ("Device not found" ); +return -ENODEV ; + } + +return 0 ; +} + +static int mausb_hub_update_device (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_tt *tt,gfp_t mem_flags) +{ +int status; +u8 port_number; +u16 max_exit_latency =0 ; +u8 mtt =0 ; +u8 ttt =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; + +if (dev->speed ==USB_SPEED_HIGH ) { + mtt = tt->multi ==0 ?1 :0 ; + ttt = (u8 )tt->think_time; + } + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return 0 ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], + dev); + +if (!usb_device_ctx) { +mausb_pr_err ("USB device not found" ); +return -ENODEV ; + } + +if (dev->usb3_lpm_u1_enabled) + max_exit_latency = (u16 )dev->u1_params.mel; +else if (dev->usb3_lpm_u2_enabled) + max_exit_latency = (u16 )dev->u2_params.mel; + +return 0 ; +} + +static int mausb_check_bandwidth (struct usb_hcd *hcd,struct usb_device *dev) +{ +mausb_pr_debug ("Not implemented" ); +return 0 ; +} + +static void mausb_reset_bandwidth (struct usb_hcd *hcd,struct usb_device *dev) +{ +mausb_pr_debug ("Not implemented" ); +} + +static void mausb_endpoint_disable (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint) +{ +mausb_pr_debug ("Not implemented" ); +} + +static void mausb_endpoint_reset (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint) +{ +int status; +int is_control; +int epnum; +int is_out; +u16 dev_handle; +u8 tsp; +u8 port_number; +struct hub_ctx *hub; +struct mausb_usb_device_ctx *usb_device_ctx; +struct usb_device *dev; +struct mausb_endpoint_ctx *ep_ctx; + + ep_ctx = endpoint->hcpriv; +if (!ep_ctx) { +mausb_pr_err ("ep->hcpriv is NULL" ); +return ; + } + + usb_device_ctx = ep_ctx->usb_device_ctx; + dev_handle = usb_device_ctx->dev_handle; + dev = usb_device_ctx->dev_addr; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return ; + } + hub = (struct hub_ctx *)hcd->hcd_priv; + + is_control =usb_endpoint_xfer_control (&endpoint->desc); + epnum =usb_endpoint_num (&endpoint->desc); + is_out =usb_endpoint_dir_out (&endpoint->desc); + tsp = (u8)(is_out ? dev->toggle[1 ] : dev->toggle[0 ]); + +if (status <0 ) +return ; + +if (status !=EUCLEAN ) { +if (!tsp) { +usb_settoggle (dev, epnum, is_out,0U ); +if (is_control) +usb_settoggle (dev, epnum, !is_out,0U ); + } + +return ; + } + +if (tsp) +return ; + +mausb_pr_info ("ep_handle request status=%d, ep_handle=%#x, dev_handle=%#x" , + status, ep_ctx->ep_handle, dev_handle); +} + +static int mausb_reset_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +int status; +u8 port_number; +u16 dev_handle; +struct hub_ctx *hub; +struct mausb_usb_device_ctx *usb_device_ctx; + + hub = (struct hub_ctx *)hcd->hcd_priv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +mausb_pr_info ("port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!usb_device_ctx || + usb_device_ctx->dev_handle ==DEV_HANDLE_NOT_ASSIGNED ) +return 0 ; + + dev_handle = usb_device_ctx->dev_handle; + +return 0 ; +} + +void mausb_clear_hcd_madev (u16 port_number) +{ +unsigned long flags =0 ; + +if (port_number >=NUMBER_OF_PORTS ) { +mausb_pr_err ("port_number out of range, port_number=%x" , + port_number); +return ; + } + +spin_lock_irqsave (&mhcd->lock, flags); + +memset (&mhcd->hcd_hs_ctx->ma_devs[port_number],0 , +sizeof (struct mausb_dev )); +memset (&mhcd->hcd_ss_ctx->ma_devs[port_number],0 , +sizeof (struct mausb_dev )); + + mhcd->connected_ports &= ~(1 << port_number); + + mhcd->hcd_hs_ctx->ma_devs[port_number].port_status = +USB_PORT_STAT_POWER ; + mhcd->hcd_ss_ctx->ma_devs[port_number].port_status = +USB_SS_PORT_STAT_POWER ; + +spin_unlock_irqrestore (&mhcd->lock, flags); +}
drivers/usb/mausb_host/hcd.h +83 -3
96 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 5/8 usb: mausb_host: Introduce PAL processing
In reply to [email protected]Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hcd.c | 523 ++++++++++- drivers/usb/mausb_host/hcd.h | 11 + drivers/usb/mausb_host/hpal.c | 1094 ++++++++++++++++++++++++ drivers/usb/mausb_host/hpal.h | 289 +++++++ drivers/usb/mausb_host/ma_usb.h | 869 +++++++++++++++++++ drivers/usb/mausb_host/mausb_address.h | 26 + drivers/usb/mausb_host/mausb_core.c | 13 +- drivers/usb/mausb_host/mausb_event.h | 224 +++++ 9 files changed, 3040 insertions(+), 10 deletions(-) create mode 100644 drivers/usb/mausb_host/hpal.c create mode 100644 drivers/usb/mausb_host/hpal.h create mode 100644 drivers/usb/mausb_host/ma_usb.h create mode 100644 drivers/usb/mausb_host/mausb_address.h create mode 100644 drivers/usb/mausb_host/mausb_event.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -10,5 +10,6 @@ mausb_host-y := mausb_core.o mausb_host-y += utils.o mausb_host-y += ip_link.o mausb_host-y += hcd.o +mausb_host-y += hpal.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hcd.c +514 -9
735 lines not on this page · raw message
drivers/usb/mausb_host/hcd.h +11 -0
@@ -15,6 +15,8 @@#include <linux/usb.h> #include <linux/usb/hcd.h> +#include "hpal.h" +#define DEVICE_NAME "mausb_host_hcd_dev"#define CLASS_NAME "mausb"
@@ -65,6 +67,13 @@ struct hub_ctx {int mausb_init_hcd (void );void mausb_deinit_hcd (void ); +void mausb_port_has_changed (const enum mausb_device_type device_type, +const enum mausb_device_speed device_speed, +void *ma_dev); +void mausb_hcd_disconnect (const u16 port_number, +const enum mausb_device_type device_type, +const enum mausb_device_speed device_speed); +#define PORT_C_MASK \ ((USB_PORT_STAT_C_CONNECTION \ | USB_PORT_STAT_C_ENABLE \
@@ -140,11 +149,13 @@ struct mausb_endpoint_ctx {struct mausb_urb_ctx {struct urb *urb; +struct mausb_data_iter iterator;struct rb_node rb_node;struct work_struct work; };int mausb_probe (struct device *dev); +void mausb_hcd_urb_complete (struct urb *urb,u32 actual_length,int status);void mausb_clear_hcd_madev (u16 port_number);
drivers/usb/mausb_host/hpal.c new file +1094 -0
1,094 lines not on this page · raw message
drivers/usb/mausb_host/hpal.h new file +289 -0
289 lines not on this page · raw message
drivers/usb/mausb_host/ma_usb.h new file +869 -0
842 lines not on this page · raw message
drivers/usb/mausb_host/mausb_address.h new file +26 -0
Lines of this file are not shown. View the raw message.
drivers/usb/mausb_host/mausb_event.h new file +224 -0
224 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>
...
drivers/usb/mausb_host/hcd.c static int mausb_hcd_hub_control(struct usb_hcd *hcd, u16 type_req, · line 718
Quoted 5 lines
drivers/usb/mausb_host/hcd.c +5
-0+/* +* Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it +* should not, so it is breaking the USB drive on the linux +*/ + urb->transfer_flags &= ~URB_SHORT_NOT_OK ;
Removing the SHORT_NOT_OK flag is _not_ a valid thing to do. It will cause drivers to malfunction.
Can you please explain this comment?
What SCSI driver?
When is the flag being added?
How does it break USB drives?
Why haven't you already reported this problem to the appropriate maintainers?
Alan Stern
Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 22 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
drivers/usb/mausb_host/hcd.c static int mausb_hcd_hub_control(struct usb_hcd *hcd, u16 type_req, · line 718
Quoted 5 lines
drivers/usb/mausb_host/hcd.c +5
-0+/* +* Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it +* should not, so it is breaking the USB drive on the linux +*/ + urb->transfer_flags &= ~URB_SHORT_NOT_OK ;Removing the
SHORT_NOT_OKflag is _not_ a valid thing to do. It will cause drivers to malfunction.Can you please explain this comment?
What SCSI driver?
Quoted 9 lines
When is the flag being added?
How does it break USB drives?
Why haven't you already reported this problem to the appropriate maintainers?
Alan Stern
Hi,
Issue that removal of SHORT_NOT_OK flag addressed is linked to particular set of Kingston USB 3.0 flash drives (super speed) - other USB flash drives haven't had this flag set. Without this "fix", those Kingston flash drives are not being enumerated properly.
This particular line was added in the early stage of development, during enumeration process implementation. The reason why it remained in the code since is because we haven't noticed any side-effects, even with various USB devices being attached to remote MA-USB device, including flash drives, cameras, wireless mice, etc.
The problem has been reported, and is actively being investigated.
As soon as it gets addressed properly (w/o global negation of the flag), a new patch will be pushed.
Signature · 2 lines
Regards, Vladimir.
Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 33 lines · Vladimir Stankovic
Quoted 22 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
drivers/usb/mausb_host/hcd.c static int mausb_hcd_hub_control(struct usb_hcd *hcd, u16 type_req, · line 718
Quoted 5 lines
drivers/usb/mausb_host/hcd.c +5
-0+/* +* Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it +* should not, so it is breaking the USB drive on the linux +*/ + urb->transfer_flags &= ~URB_SHORT_NOT_OK ;Removing the
SHORT_NOT_OKflag is _not_ a valid thing to do. It will cause drivers to malfunction.Can you please explain this comment?
What SCSI driver?
Quoted 9 lines
When is the flag being added?
How does it break USB drives?
Why haven't you already reported this problem to the appropriate maintainers?
Alan Stern
Quoted 6 lines
Hi,
Issue that removal of
SHORT_NOT_OKflag addressed is linked to particular set of Kingston USB 3.0 flash drives (super speed) - other USB flash drives haven't had this flag set. Without this "fix", those Kingston flash drives are not being enumerated properly.
Please explain in detail how the enumeration of these Kingston flash drives fails. Or if such an explanation has already been posted, please provide a link to it.
Quoted 5 lines
This particular line was added in the early stage of development, during enumeration process implementation. The reason why it remained in the code since is because we haven't noticed any side-effects, even with various USB devices being attached to remote MA-USB device, including flash drives, cameras, wireless mice, etc.
Come to think of it, the SHORT_NOT_OK flag is mainly used with HCDs that don't have scatter-gather support. Since your mausb driver does support scatter-gather, you most likely won't encounter any problems unless you go looking for them specifically.
Quoted 1 line
The problem has been reported, and is actively being investigated.
Where was the problem reported (URL to a mailing list archive)? Who is investigating it?
Quoted 2 lines
As soon as it gets addressed properly (w/o global negation of the flag), a new patch will be pushed.
Thank you.
Alan Stern
Re: [External] Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 37 lines · Alan Stern
Quoted 35 lines · Vladimir Stankovic
Quoted 22 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
drivers/usb/mausb_host/hcd.c static int mausb_hcd_hub_control(struct usb_hcd *hcd, u16 type_req, · line 718
Quoted 5 lines
drivers/usb/mausb_host/hcd.c +5
-0+/* +* Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it +* should not, so it is breaking the USB drive on the linux +*/ + urb->transfer_flags &= ~URB_SHORT_NOT_OK ;Removing the
SHORT_NOT_OKflag is _not_ a valid thing to do. It will cause drivers to malfunction.Can you please explain this comment?
What SCSI driver?
Quoted 9 lines
When is the flag being added?
How does it break USB drives?
Why haven't you already reported this problem to the appropriate maintainers?
Alan Stern
Hi,
Quoted 8 lines
Quoted 4 lines
Issue that removal of
SHORT_NOT_OKflag addressed is linked to particular set of Kingston USB 3.0 flash drives (super speed) - other USB flash drives haven't had this flag set. Without this "fix", those Kingston flash drives are not being enumerated properly.Please explain in detail how the enumeration of these Kingston flash drives fails. Or if such an explanation has already been posted, please provide a link to it.
Will reproduce the issue once again (w/o the fix) and run through the events. Issue has been noticed during early development, and addressed right away.
Quoted 12 lines
Quoted 6 lines
This particular line was added in the early stage of development, during enumeration process implementation. The reason why it remained in the code since is because we haven't noticed any side-effects, even with various USB devices being attached to remote MA-USB device, including flash drives, cameras, wireless mice, etc.
Come to think of it, the
SHORT_NOT_OKflag is mainly used with HCDs that don't have scatter-gather support. Since your mausb driver does support scatter-gather, you most likely won't encounter any problems unless you go looking for them specifically.
Quoted 4 lines
Quoted 1 line
The problem has been reported, and is actively being investigated.
Where was the problem reported (URL to a mailing list archive)? Who is investigating it?
Ticket has been submitted to DisplayLink's internal issue-tracking system and is being investigated by mausb-host-devel team.
Quoted 8 lines
Quoted 3 lines
As soon as it gets addressed properly (w/o global negation of the flag), a new patch will be pushed.
Thank you.
Alan Stern
Signature · 2 lines
Regards, Vladimir.
Re: [External] Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 61 lines · Vladimir Stankovic
Quoted 37 lines · Alan Stern
Quoted 35 lines · Vladimir Stankovic
Quoted 22 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
drivers/usb/mausb_host/hcd.c static int mausb_hcd_hub_control(struct usb_hcd *hcd, u16 type_req, · line 718
Quoted 5 lines
drivers/usb/mausb_host/hcd.c +5
-0+/* +* Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it +* should not, so it is breaking the USB drive on the linux +*/ + urb->transfer_flags &= ~URB_SHORT_NOT_OK ;Removing the
SHORT_NOT_OKflag is _not_ a valid thing to do. It will cause drivers to malfunction.Can you please explain this comment?
What SCSI driver?
Quoted 9 lines
When is the flag being added?
How does it break USB drives?
Why haven't you already reported this problem to the appropriate maintainers?
Alan Stern
Hi,
Quoted 8 lines
Quoted 4 lines
Issue that removal of
SHORT_NOT_OKflag addressed is linked to particular set of Kingston USB 3.0 flash drives (super speed) - other USB flash drives haven't had this flag set. Without this "fix", those Kingston flash drives are not being enumerated properly.Please explain in detail how the enumeration of these Kingston flash drives fails. Or if such an explanation has already been posted, please provide a link to it.
Will reproduce the issue once again (w/o the fix) and run through the events. Issue has been noticed during early development, and addressed right away.
Quoted 12 lines
Quoted 6 lines
This particular line was added in the early stage of development, during enumeration process implementation. The reason why it remained in the code since is because we haven't noticed any side-effects, even with various USB devices being attached to remote MA-USB device, including flash drives, cameras, wireless mice, etc.
Come to think of it, the
SHORT_NOT_OKflag is mainly used with HCDs that don't have scatter-gather support. Since your mausb driver does support scatter-gather, you most likely won't encounter any problems unless you go looking for them specifically.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
The problem has been reported, and is actively being investigated.
Where was the problem reported (URL to a mailing list archive)? Who is investigating it?
Ticket has been submitted to DisplayLink's internal issue-tracking system and is being investigated by mausb-host-devel team.
Okay. What SCSI driver does the comment refer to? Is it something internal to DisplayLink or is it part of the regular Linux kernel?
Alan Stern
Re: [External] Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 68 lines · Alan Stern
Quoted 66 lines · Vladimir Stankovic
Quoted 37 lines · Alan Stern
Quoted 35 lines · Vladimir Stankovic
Quoted 22 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
drivers/usb/mausb_host/hcd.c static int mausb_hcd_hub_control(struct usb_hcd *hcd, u16 type_req, · line 718
Quoted 5 lines
drivers/usb/mausb_host/hcd.c +5
-0+/* +* Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it +* should not, so it is breaking the USB drive on the linux +*/ + urb->transfer_flags &= ~URB_SHORT_NOT_OK ;Removing the
SHORT_NOT_OKflag is _not_ a valid thing to do. It will cause drivers to malfunction.Can you please explain this comment?
What SCSI driver?
Quoted 9 lines
When is the flag being added?
How does it break USB drives?
Why haven't you already reported this problem to the appropriate maintainers?
Alan Stern
Hi,
Quoted 8 lines
Quoted 4 lines
Issue that removal of
SHORT_NOT_OKflag addressed is linked to particular set of Kingston USB 3.0 flash drives (super speed) - other USB flash drives haven't had this flag set. Without this "fix", those Kingston flash drives are not being enumerated properly.Please explain in detail how the enumeration of these Kingston flash drives fails. Or if such an explanation has already been posted, please provide a link to it.
Will reproduce the issue once again (w/o the fix) and run through the events. Issue has been noticed during early development, and addressed right away.
Quoted 16 lines
Quoted 6 lines
This particular line was added in the early stage of development, during enumeration process implementation. The reason why it remained in the code since is because we haven't noticed any side-effects, even with various USB devices being attached to remote MA-USB device, including flash drives, cameras, wireless mice, etc.
Come to think of it, the
SHORT_NOT_OKflag is mainly used with HCDs that don't have scatter-gather support. Since your mausb driver does support scatter-gather, you most likely won't encounter any problems unless you go looking for them specifically.Quoted 1 line
The problem has been reported, and is actively being investigated.
Where was the problem reported (URL to a mailing list archive)? Who is investigating it?
Quoted 8 lines
Quoted 2 lines
Ticket has been submitted to DisplayLink's internal issue-tracking system and is being investigated by mausb-host-devel team.
Okay. What SCSI driver does the comment refer to? Is it something internal to DisplayLink or is it part of the regular Linux kernel?
Alan Stern
Hi,
Comment was related to the SCSI driver that's part of regular Linux kernel - once the remote USB flash drive gets enumerated by host, it would appear as directly attached to host and then handled by the kernel.
With current implementation, following messages are being logged:
scsi 3:0:0:0: Direct-Access Kingston DataTraveler 3.0 PMAP PQ: 0 ANSI: 6
sd 3:0:0:0: Attached scsi generic sg2 type 0
after which the flash drive is usable/accessible from host side.
Signature · 2 lines
Regards, Vladimir.
Re: [External] Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 21 lines · Vladimir Stankovic
Quoted 20 lines · Alan Stern
Quoted 18 lines · Vladimir Stankovic
Quoted 17 lines · Alan Stern
Quoted 15 lines · Vladimir Stankovic
Quoted 14 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
Quoted 5 lines
(quoted diff) +5
-0+ /* + * Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it + * should not, so it is breaking the USB drive on the linux + */ + urb->transfer_flags &= ~URB_SHORT_NOT_OK;
...
Quoted 11 lines
Quoted 5 lines
Okay. What SCSI driver does the comment refer to? Is it something internal to DisplayLink or is it part of the regular Linux kernel?
Alan Stern
Hi,
Comment was related to the SCSI driver that's part of regular Linux kernel - once the remote USB flash drive gets enumerated by host, it would appear as directly attached to host and then handled by the kernel.
Quoted 6 lines
With current implementation, following messages are being logged:
scsi 3:0:0:0: Direct-Access Kingston DataTraveler 3.0 PMAP PQ: 0 ANSI: 6
sd 3:0:0:0: Attached scsi generic sg2 type 0after which the flash drive is usable/accessible from host side.
More context please. Without the log messages preceding this one we can't tell whether the device is using the usb-storage driver or the uas driver.
Also, what makes you think the driver is setting the SHORT_NOT_OK flag at the wrong time? In fact, how can there be a wrong time? SHORT_NOT_OK is a valid flag to use with any control or bulk URB.
Alan Stern
Re: [External] Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 48 lines · Alan Stern
Quoted 21 lines · Vladimir Stankovic
Quoted 20 lines · Alan Stern
Quoted 18 lines · Vladimir Stankovic
Quoted 17 lines · Alan Stern
Quoted 15 lines · Vladimir Stankovic
Quoted 14 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
Quoted 5 lines
(quoted diff) +5
-0+ /* + * Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it + * should not, so it is breaking the USB drive on the linux + */ + urb->transfer_flags &= ~URB_SHORT_NOT_OK;...
Quoted 11 lines
Quoted 5 lines
Okay. What SCSI driver does the comment refer to? Is it something internal to DisplayLink or is it part of the regular Linux kernel?
Alan Stern
Hi,
Comment was related to the SCSI driver that's part of regular Linux kernel - once the remote USB flash drive gets enumerated by host, it would appear as directly attached to host and then handled by the kernel.
Quoted 6 lines
With current implementation, following messages are being logged:
scsi 3:0:0:0: Direct-Access Kingston DataTraveler 3.0 PMAP PQ: 0 ANSI: 6
sd 3:0:0:0: Attached scsi generic sg2 type 0after which the flash drive is usable/accessible from host side.
More context please. Without the log messages preceding this one we can't tell whether the device is using the usb-storage driver or the uas driver.
Quoted 6 lines
Also, what makes you think the driver is setting the
SHORT_NOT_OKflag at the wrong time? In fact, how can there be a wrong time?SHORT_NOT_OKis a valid flag to use with any control or bulk URB.Alan Stern
The comment is clearly wrong - as mentioned earlier, this fix was added in early development phase and I guess that implementer was not clear on how the particular flag was added. Investigation is ongoing around proper fix for this.
Anyhow, it is a usb-storage driver related to this - here is usb-related log snippet:
usb 3-1.1.2: new high-speed USB device number 5 using mausb_host_hcd_dev usb 3-1.1.2: New USB device found, idVendor=0951, idProduct=1666 usb 3-1.1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 usb 3-1.1.2: Product: DataTraveler 3.0
usb 3-1.1.2: Manufacturer: Kingston
usb 3-1.1.2: SerialNumber: 0C9D9210E304E311095E087A usb-storage 3-1.1.2:1.0: USB Mass Storage device detected scsi host3: usb-storage 3-1.1.2:1.0
scsi 3:0:0:0: Direct-Access Kingston DataTraveler 3.0 PMAP PQ: 0 ANSI: 6
Attached scsi generic sg2 type 0
[sdb] 30277632 512-byte logical blocks: (15.5 GB/14.4 GiB)
As can be seen, USB flash attached to remote device is properly enumerated via MA USB. Without the fix, usb driver is not able to read USB descriptors, ending up in USB storage not being accessible.
Signature · 2 lines
Regards, Vladimir.
Re: [External] Re: [PATCH v5 5/8] usb: mausb_host: Introduce PAL processing
Quoted 51 lines · Vladimir Stankovic
Quoted 26 lines · Alan Stern
Quoted 21 lines · Vladimir Stankovic
Quoted 20 lines · Alan Stern
Quoted 18 lines · Vladimir Stankovic
Quoted 17 lines · Alan Stern
Quoted 15 lines · Vladimir Stankovic
Quoted 14 lines · Alan Stern
Quoted 4 lines · On Sat, 25 Apr 2020 [email protected] wrote:
Protocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
Signed-off-by Vladimir Stankovic <[email protected]>...
Quoted 5 lines
(quoted diff) +5
-0+ /* + * Masking URB_SHORT_NOT_OK flag as SCSI driver is adding it where it + * should not, so it is breaking the USB drive on the linux + */ + urb->transfer_flags &= ~URB_SHORT_NOT_OK;...
Quoted 6 lines
Also, what makes you think the driver is setting the
SHORT_NOT_OKflag at the wrong time? In fact, how can there be a wrong time?SHORT_NOT_OKis a valid flag to use with any control or bulk URB.Alan Stern
The comment is clearly wrong - as mentioned earlier, this fix was added in early development phase and I guess that implementer was not clear on how the particular flag was added. Investigation is ongoing around proper fix for this.
Anyhow, it is a usb-storage driver related to this - here is usb-related log snippet:
usb 3-1.1.2: new high-speed USB device number 5 using
mausb_host_hcd_devusb 3-1.1.2: New USB device found, idVendor=0951, idProduct=1666 usb 3-1.1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 usb 3-1.1.2: Product: DataTraveler 3.0
usb 3-1.1.2: Manufacturer: Kingston
usb 3-1.1.2: SerialNumber: 0C9D9210E304E311095E087A usb-storage 3-1.1.2:1.0: USB Mass Storage device detected scsi host3: usb-storage 3-1.1.2:1.0
scsi 3:0:0:0: Direct-Access Kingston DataTraveler 3.0 PMAP PQ: 0 ANSI: 6
Attached scsi generic sg2 type 0
[sdb] 30277632 512-byte logical blocks: (15.5 GB/14.4 GiB)
Quoted 3 lines
As can be seen, USB flash attached to remote device is properly enumerated via MA USB. Without the fix, usb driver is not able to read USB descriptors, ending up in USB storage not being accessible.
That's strange, considering that the SHORT_NOT_OK flag doesn't get set when the system is reading the device's USB descriptors.
Alan Stern
PATCH v5 6/8 usb: mausb_host: Add logic for PAL-to-PAL communication
In reply to [email protected]Implemeneted connection between PAL and Link layers and set up environment for exchanging PAL-to-PAL messages.
Within this patch, driver's sysfs parameters have been created with intention to configure remote connection parameters.
--- drivers/usb/mausb_host/hpal.c | 522 ++++++++++++++++++++++++++++ drivers/usb/mausb_host/hpal.h | 6 + drivers/usb/mausb_host/mausb_core.c | 103 +++++- 3 files changed, 630 insertions(+), 1 deletion(-)
drivers/usb/mausb_host/hpal.c +522 -0
@@ -13,10 +13,15 @@#include "hcd.h" #include "utils.h" +#define MAUSB_DELETE_MADEV_TIMEOUT_MS 3000 +struct mss mss; +static int mausb_start_connection_timer (struct mausb_device *dev);static int mausb_power_state_cb (struct notifier_block *nb,unsigned long action,void *data); +static void mausb_signal_empty_mss (void ); +static void mausb_remove_madev_from_list (u8 madev_addr);static void mausb_execute_urb_dequeue (struct work_struct *dequeue_work);static int mausb_start_heartbeat_timer (void );
@@ -177,6 +182,55 @@ static bool mausb_return_urb_ctx_to_tree(struct mausb_urb_ctx *urb_ctx,return true; } +static void mausb_complete_urbs_from_tree (void ) +{ +struct mausb_urb_ctx *urb_ctx =NULL ; +struct urb *current_urb =NULL ; +struct rb_node *current_node =NULL ; +unsigned long flags; +int status =0 ; +int ret; + +mausb_pr_debug ("Completing all urbs from tree" ); + +spin_lock_irqsave (&mhcd->lock, flags); + +while ((current_node =rb_first (&mhcd->mausb_urbs))) { + urb_ctx = rb_entry(current_node, struct mausb_urb_ctx, rb_node); + + current_urb = urb_ctx->urb; +mausb_delete_urb_ctx_from_tree (urb_ctx); +mausb_uninit_data_iterator (&urb_ctx->iterator); +kfree (urb_ctx); + + ret =usb_hcd_check_unlink_urb (current_urb->hcpriv, + current_urb, status); +if (ret == -EIDRM ) +mausb_pr_warn ("Urb=%p is already unlinked" , + current_urb); +else +usb_hcd_unlink_urb_from_ep (current_urb->hcpriv, + current_urb); + +spin_unlock_irqrestore (&mhcd->lock, flags); + +/* Prepare urb for completion */ +mausb_pr_debug ("Completing urb=%p" , current_urb); + + current_urb->status = -EPROTO ; + current_urb->actual_length =0 ; +atomic_dec (¤t_urb->use_count); +usb_hcd_giveback_urb (current_urb->hcpriv, current_urb, + current_urb->status); + +spin_lock_irqsave (&mhcd->lock, flags); + } + +spin_unlock_irqrestore (&mhcd->lock, flags); + +mausb_pr_debug ("Completed all urbs from tree" ); +} +/*After this function call only valid thing to do with urb is to give it back*/ struct mausb_urb_ctx *mausb_unlink_and_delete_urb_from_tree (struct urb *urb,int status)
@@ -284,6 +338,161 @@ static inline void mausb_port_has_changed_event(struct mausb_device *dev,mausb_port_has_changed (USB20HUB ,HIGH_SPEED , dev); } +static void mausb_socket_disconnect_event (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + socket_disconnect_work); +struct mausb_event event; + +mausb_pr_info ("madev_addr=%d" , dev->madev_addr); + +mausb_ip_disconnect (dev->ctrl_channel); +mausb_destroy_ip_ctx (dev->ctrl_channel); + dev->ctrl_channel =NULL ; + +mausb_ip_disconnect (dev->bulk_channel); +mausb_destroy_ip_ctx (dev->bulk_channel); + dev->bulk_channel =NULL ; + +mausb_ip_disconnect (dev->isoch_channel); +mausb_destroy_ip_ctx (dev->isoch_channel); + dev->isoch_channel =NULL ; + +if (dev->mgmt_channel) { +memset (&event,0 ,sizeof (event)); + event.type =MAUSB_EVENT_TYPE_NETWORK_DISCONNECTED ; + event.data.device_id = dev->id; + +mausb_pr_info ("Releasing MAUSB device ref" ); +kref_put (&dev->refcount, mausb_release_ma_dev_async); + } + +mausb_ip_disconnect (dev->mgmt_channel); +mausb_destroy_ip_ctx (dev->mgmt_channel); + dev->mgmt_channel =NULL ; + +memset (dev->channel_map,0 ,sizeof (dev->channel_map)); +} + +static void mausb_disconnect_ma_dev (struct mausb_device *dev) +{ +mausb_pr_info ("Disconnecting MAUSB device madev_addr=%d" , + dev->madev_addr); + +if (!dev->dev_connected) { +mausb_pr_warn ("MAUSB device is not connected" ); +kref_put (&dev->refcount, mausb_release_ma_dev_async); +return ; + } +mausb_hcd_disconnect (dev->port_number, dev->dev_type, dev->dev_speed); + +if (dev->dev_type ==USB30HUB ) +mausb_hcd_disconnect (dev->port_number,USB20HUB ,HIGH_SPEED ); +} + +static void mausb_hcd_disconnect_event (struct work_struct *work) +{ + struct mausb_device *ma_dev = container_of(work, struct mausb_device, + hcd_disconnect_work); + +mausb_disconnect_ma_dev (ma_dev); +} + +static void mausb_delete_madev (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + madev_delete_work); +struct mausb_event event; +struct completion completion; +struct completion *user_event; +struct mausb_completion mausb_completion; +long status; +unsigned long timeout =msecs_to_jiffies (MAUSB_DELETE_MADEV_TIMEOUT_MS ); + +mausb_pr_info ("Deleting MAUSB device madev_addr=%d" , dev->madev_addr); + +del_timer_sync (&dev->connection_timer); + +/* Client IS responsive */ +if (!atomic_read (&dev->unresponsive_client)) { +memset (&event,0 ,sizeof (event)); + event.type =MAUSB_EVENT_TYPE_DELETE_MA_DEV ; + event.mgmt.delete_ma_dev.device_id = dev->id; + event.mgmt.delete_ma_dev.event_id =mausb_event_id (dev); + +init_completion (&completion); + mausb_completion.completion_event = &completion; + mausb_completion.event_id = event.mgmt.delete_ma_dev.event_id; + mausb_completion.mausb_event = &event; + +mausb_insert_event (dev, &mausb_completion); + +mausb_pr_debug ("Deleting MAUSB device..." ); + + status =wait_for_completion_interruptible_timeout (&completion, + timeout); + +mausb_pr_debug ("Deleting MAUSB device event finished with %ld" , + status); + +mausb_remove_event (dev, &mausb_completion); + + user_event = &dev->user_finished_event; + + status =wait_for_completion_interruptible_timeout (user_event, + timeout); +mausb_pr_info ("User event finished with %ld" , status); + } + +flush_workqueue (dev->workq); +destroy_workqueue (dev->workq); + +mausb_clear_hcd_madev (dev->port_number); + +mausb_remove_madev_from_list (dev->madev_addr); + +put_net (dev->net_ns); + +kfree (dev); +mausb_signal_empty_mss (); + +mausb_pr_info ("MAUSB device deleted. Version=%s" ,MAUSB_DRIVER_VERSION ); +} + +static void mausb_ping_work (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + ping_work); + +if (mausb_start_connection_timer (dev) <0 ) { +mausb_pr_err ("Device disconnecting due to session timeout madev_addr=%d" , + dev->madev_addr); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +return ; + } +} + +static void mausb_heartbeat_work (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + heartbeat_work); + +mausb_pr_err ("Device disconnecting - app is unresponsive" ); +atomic_set (&dev->unresponsive_client,1 ); +mausb_complete_urbs_from_tree (); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +} + +static void mausb_connection_timer_func (struct timer_list *timer) +{ + struct mausb_device *dev = container_of(timer, struct mausb_device, + connection_timer); + +queue_work (dev->workq, &dev->ping_work); +} +static void mausb_heartbeat_timer_func (struct timer_list *timer) {unsigned long flags =0 ;
@@ -308,6 +517,99 @@ static void mausb_heartbeat_timer_func(struct timer_list *timer) } } +static struct mausb_device * +mausb_create_madev (struct mausb_device_address dev_addr,u8 madev_address, +int *status) +{ +struct mausb_device *dev; +unsigned long flags =0 ; +char workq_name[16 ]; +struct workqueue_struct *workq; + +memset (workq_name,0 ,sizeof (workq_name)); +sprintf (workq_name,"%x" , madev_address); +strcat (workq_name,"_madev_workq" ); + +mausb_pr_debug ("madev_workq_name = %s" , workq_name); + + workq =alloc_ordered_workqueue (workq_name,WQ_MEM_RECLAIM ); +if (!workq) { +mausb_pr_alert ("Could not allocate workqueue!" ); + *status = -ENOMEM ; +return NULL ; + } + +spin_lock_irqsave (&mss.lock, flags); + +if (mss.deinit_in_progress) { +spin_unlock_irqrestore (&mss.lock, flags); +mausb_pr_alert ("Device creating failed - mss deinit in progress" ); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -ESHUTDOWN ; +return NULL ; + } + + dev =mausb_get_dev_from_addr_unsafe (madev_address); +if (dev) { +spin_unlock_irqrestore (&mss.lock, flags); +mausb_pr_debug ("MAUSB device already connected, madev_address=%x" , + madev_address); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -EEXIST ; +return NULL ; + } + + dev =kzalloc (sizeof (*dev),GFP_ATOMIC ); + +if (!dev) { +spin_unlock_irqrestore (&mss.lock, flags); +mausb_pr_alert ("Could not allocate MAUSB device!" ); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -ENOMEM ; +return NULL ; + } + +mausb_pr_info ("Create MAUSB device. Version=%s" ,MAUSB_DRIVER_VERSION ); + + dev->workq = workq; + +INIT_WORK (&dev->socket_disconnect_work, mausb_socket_disconnect_event); +INIT_WORK (&dev->hcd_disconnect_work, mausb_hcd_disconnect_event); +INIT_WORK (&dev->madev_delete_work, mausb_delete_madev); +INIT_WORK (&dev->ping_work, mausb_ping_work); +INIT_WORK (&dev->heartbeat_work, mausb_heartbeat_work); + +kref_init (&dev->refcount); + + dev->event_id =0 ; +spin_lock_init (&dev->event_id_lock); + +INIT_LIST_HEAD (&dev->completion_events); +spin_lock_init (&dev->completion_events_lock); +spin_lock_init (&dev->num_of_user_events_lock); +spin_lock_init (&dev->connection_timer_lock); + +init_completion (&dev->user_finished_event); +atomic_set (&dev->unresponsive_client,0 ); + +timer_setup (&dev->connection_timer, mausb_connection_timer_func,0 ); + + dev->dev_addr = dev_addr; + dev->madev_addr = madev_address; + dev->net_ns =get_net (current->nsproxy->net_ns); + +list_add_tail (&dev->list_entry, &mss.madev_list); + +reinit_completion (&mss.empty); + +spin_unlock_irqrestore (&mss.lock, flags); + +return dev; +} +void mausb_release_ma_dev_async (struct kref *kref) { struct mausb_device *dev = container_of(kref, struct mausb_device,
@@ -318,6 +620,45 @@ void mausb_release_ma_dev_async(struct kref *kref)schedule_work (&dev->madev_delete_work); } +int mausb_initiate_dev_connection (struct mausb_device_address dev_addr, +u8 madev_address) +{ +int error =0 ; +struct mausb_device *dev; +unsigned long flags =0 ; + +spin_lock_irqsave (&mss.lock, flags); + dev =mausb_get_dev_from_addr_unsafe (madev_address); +spin_unlock_irqrestore (&mss.lock, flags); + +if (dev) { +mausb_pr_debug ("MAUSB device already connected, madev_address=%x" , + madev_address); +return -EEXIST ; + } + + dev =mausb_create_madev (dev_addr, madev_address, &error); + +if (!dev) +return error; + +mausb_pr_info ("New MAUSB device created madev_addr=%d" , madev_address); + + error =mausb_init_ip_ctx (&dev->mgmt_channel, dev->net_ns, + dev->dev_addr.ip.address, + dev->dev_addr.ip.port.management, dev, + mausb_ip_callback,MAUSB_MGMT_CHANNEL ); +if (error) { +mausb_pr_err ("Mgmt ip context init failed: error=%d" , error); +kref_put (&dev->refcount, mausb_release_ma_dev_async); +return error; + } + +mausb_ip_connect_async (dev->mgmt_channel); + +return 0 ; +} +int mausb_enqueue_event_from_user (u8 madev_addr,u16 num_of_events,u16 num_of_completed) {
@@ -418,6 +759,26 @@ int mausb_signal_event(struct mausb_device *dev,return -ETIMEDOUT ; } +static int mausb_start_connection_timer (struct mausb_device *dev) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&dev->connection_timer_lock, flags); + +if (++dev->receive_failures_num >MAUSB_MAX_RECEIVE_FAILURES ) { +mausb_pr_err ("Missed more than %d ping responses" , +MAUSB_MAX_RECEIVE_FAILURES ); +spin_unlock_irqrestore (&dev->connection_timer_lock, flags); +return -ETIMEDOUT ; + } + +mod_timer (&dev->connection_timer, jiffies +msecs_to_jiffies (1000 )); + +spin_unlock_irqrestore (&dev->connection_timer_lock, flags); + +return 0 ; +} +void mausb_reset_connection_timer (struct mausb_device *dev) {unsigned long flags =0 ;
@@ -661,6 +1022,36 @@ struct mausb_device *mausb_get_dev_from_addr_unsafe(u8 madev_addr)return NULL ; } +static void mausb_remove_madev_from_list (u8 madev_addr) +{ +unsigned long flags =0 ; +struct mausb_device *ma_dev, *tmp =NULL ; + +spin_lock_irqsave (&mss.lock, flags); + +list_for_each_entry_safe (ma_dev, tmp, &mss.madev_list, list_entry) { +if (ma_dev->madev_addr == madev_addr) { +list_del (&ma_dev->list_entry); +break ; + } + } + +if (list_empty (&mss.madev_list)) +reinit_completion (&mss.rings_events.mausb_ring_has_events); + +spin_unlock_irqrestore (&mss.lock, flags); +} + +static void mausb_signal_empty_mss (void ) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mss.lock, flags); +if (list_empty (&mss.madev_list)) +complete (&mss.empty); +spin_unlock_irqrestore (&mss.lock, flags); +} +static inline struct mausb_ip_ctx *mausb_get_data_channel (struct mausb_device *ma_dev,enum mausb_channel channel)
@@ -814,6 +1205,137 @@ void mausb_cleanup_chunks_list(struct list_head *chunks_list) } } +static void mausb_init_ip_ctx_helper (struct mausb_device *dev, +struct mausb_ip_ctx **ip_ctx, +u16 port, +enum mausb_channel channel) +{ +int status =mausb_init_ip_ctx (ip_ctx, dev->net_ns, + dev->dev_addr.ip.address, port, dev, + mausb_ip_callback, channel); +if (status <0 ) { +mausb_pr_err ("Init ip context failed with error=%d" , status); +queue_work (dev->workq, &dev->socket_disconnect_work); +return ; + } + + dev->channel_map[channel] = *ip_ctx; +mausb_ip_connect_async (*ip_ctx); +} + +static void mausb_connect_callback (struct mausb_device *dev, +enum mausb_channel channel,int status) +{ +struct mausb_device_address *dev_addr = &dev->dev_addr; + +mausb_pr_info ("Connect callback for channel=%d with status=%d" , + channel, status); + +if (status <0 ) { +queue_work (dev->workq, &dev->socket_disconnect_work); +return ; + } + +if (channel ==MAUSB_MGMT_CHANNEL ) { +if (dev_addr->ip.port.control ==0 ) { + dev->channel_map[MAUSB_CTRL_CHANNEL ] = + dev->mgmt_channel; + channel =MAUSB_CTRL_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->ctrl_channel, + dev_addr->ip.port.control, +MAUSB_CTRL_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_CTRL_CHANNEL ) { +if (dev_addr->ip.port.bulk ==0 ) { + dev->channel_map[MAUSB_BULK_CHANNEL ] = + dev->channel_map[MAUSB_CTRL_CHANNEL ]; + channel =MAUSB_BULK_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->bulk_channel, + dev_addr->ip.port.bulk, +MAUSB_BULK_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_BULK_CHANNEL ) { +if (dev_addr->ip.port.isochronous ==0 ) { +/* if there is no isoch port use tcp for it */ + dev->channel_map[MAUSB_ISOCH_CHANNEL ] = + dev->channel_map[MAUSB_BULK_CHANNEL ]; + channel =MAUSB_ISOCH_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->isoch_channel, + dev_addr->ip.port.isochronous, +MAUSB_ISOCH_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_ISOCH_CHANNEL ) { + dev->channel_map[MAUSB_INTR_CHANNEL ] = + dev->channel_map[MAUSB_CTRL_CHANNEL ]; + } +} + +static void mausb_handle_connect_event (struct mausb_device *dev, +enum mausb_channel channel,int status, +void *data) +{ +mausb_connect_callback (dev, channel, status); +} + +static void mausb_handle_receive_event (struct mausb_device *dev, +enum mausb_channel channel,int status, +void *data) +{ +struct mausb_event event; + + event.madev_addr = dev->madev_addr; + +if (status <=0 ) { +mausb_pr_err ("Receive event error status=%d" , status); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +return ; + } + +mausb_reset_connection_timer (dev); +} + +void mausb_ip_callback (void *ctx,enum mausb_channel channel, +enum mausb_link_action action,int status,void *data) +{ +struct mausb_device *dev = (struct mausb_device *)ctx; + +switch (action) { +case MAUSB_LINK_CONNECT : +mausb_handle_connect_event (dev, channel, status, data); +break ; +case MAUSB_LINK_SEND : +/* +* Currently there is nothing to do, as send operation is +* synchronous +*/ +break ; +case MAUSB_LINK_RECV : +mausb_handle_receive_event (dev, channel, status, data); +break ; +case MAUSB_LINK_DISCONNECT : +/* +* Currently there is nothing to do, as disconnect operation is +* synchronous +*/ +break ; +default : +mausb_pr_warn ("Unknown network action" ); + } +} + static int mausb_read_virtual_buffer(struct mausb_data_iter *iterator, u32 byte_num, struct list_head *data_chunks_list,
drivers/usb/mausb_host/hpal.h +6 -0
@@ -131,6 +131,8 @@ static inline u64 mausb_event_id(struct mausb_device *dev)return val; } +int mausb_initiate_dev_connection (struct mausb_device_address device_address, +u8 madev_address);int mausb_data_req_enqueue_event (struct mausb_device *dev,u16 ep_handle,struct urb *request); int mausb_signal_event(struct mausb_device *dev, struct mausb_event *event,
@@ -158,6 +160,7 @@ static inline void mausb_remove_event(struct mausb_device *dev, }void mausb_release_ma_dev_async (struct kref *kref); +void mausb_on_madev_connected (struct mausb_device *dev);void mausb_complete_request (struct urb *urb,u32 actual_length,int status);void mausb_complete_urb (struct mausb_event *event);void mausb_reset_connection_timer (struct mausb_device *dev);
@@ -240,6 +243,9 @@ enum mausb_channel mausb_transfer_type_to_channel(u8 transfer_type)return transfer_type >>3 ; } +void mausb_ip_callback (void *ctx,enum mausb_channel channel, +enum mausb_link_action action,int status,void *data); +struct mausb_data_iter {u32 length;
drivers/usb/mausb_host/mausb_core.c +102 -1
149 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 7/8 usb: mausb_host: MA-USB PAL events processing
In reply to [email protected]Implemented MA-USB management messages processing and communication with user-space driver via mapped memory.
MA USB PAL events are being enqueued into ring buffer from which data is being send/received to/from user-space.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hcd.c | 245 +++++++- drivers/usb/mausb_host/hpal.c | 449 +++++++++++++- drivers/usb/mausb_host/hpal.h | 44 ++ drivers/usb/mausb_host/hpal_events.c | 611 +++++++++++++++++++ drivers/usb/mausb_host/hpal_events.h | 85 +++ drivers/usb/mausb_host/mausb_driver_status.h | 17 + drivers/usb/mausb_host/utils.c | 273 +++++++++ drivers/usb/mausb_host/utils.h | 5 + 9 files changed, 1720 insertions(+), 10 deletions(-) create mode 100644 drivers/usb/mausb_host/hpal_events.c create mode 100644 drivers/usb/mausb_host/hpal_events.h create mode 100644 drivers/usb/mausb_host/mausb_driver_status.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -11,5 +11,6 @@ mausb_host-y += utils.o mausb_host-y += ip_link.o mausb_host-y += hcd.o mausb_host-y += hpal.o +mausb_host-y += hpal_events.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hcd.c +240 -5
376 lines not on this page · raw message
drivers/usb/mausb_host/hpal.c +444 -5
599 lines not on this page · raw message
drivers/usb/mausb_host/hpal.h +44 -0
66 lines not on this page · raw message
drivers/usb/mausb_host/hpal_events.c new file +611 -0
611 lines not on this page · raw message
drivers/usb/mausb_host/hpal_events.h new file +85 -0
85 lines not on this page · raw message
drivers/usb/mausb_host/mausb_driver_status.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_MAUSB_DRIVER_STATUS_H__ +#define __MAUSB_MAUSB_DRIVER_STATUS_H__ + +#define MAUSB_DRIVER_BAD_READ_BUFFER_SIZE -1 +#define MAUSB_DRIVER_RING_EVENTS_STOPPED -2 +#define MAUSB_DRIVER_SYSTEM_SUSPENDED -3 +#define MAUSB_DRIVER_COPY_TO_BUFFER_FAILED -4 + +#define MAUSB_DRIVER_READ_TIMEOUT 0 +#define MAUSB_DRIVER_READ_ERROR -1 +#define MAUSB_DRIVER_WRITE_ERROR -2 + +#endif /* __MAUSB_MAUSB_DRIVER_STATUS_H__ */
drivers/usb/mausb_host/utils.c +273 -0
297 lines not on this page · raw message
drivers/usb/mausb_host/utils.h +5 -0
@@ -5,6 +5,8 @@#ifndef __MAUSB_UTILS_H__#define __MAUSB_UTILS_H__ +#include "hpal.h" +#if defined(MAUSB_NO_LOGS )#define mausb_pr_logs (...)#else
@@ -36,5 +38,8 @@int mausb_create_dev (void );void mausb_cleanup_dev (int device_created); +void mausb_notify_completed_user_events (struct mausb_ring_buffer *ring_buffer); +void mausb_notify_ring_events (struct mausb_ring_buffer *ring_buffer); +void mausb_stop_ring_events (void );#endif /* __MAUSB_UTILS_H__ */
Signature · 1 line
2.17.1
Greg KH
maintainerRe: [PATCH v5 7/8] usb: mausb_host: MA-USB PAL events processing
drivers/usb/mausb_host/hcd.c static void mausb_free_dev(struct usb_hcd *hcd, struct usb_device *dev) · line 1127
Quoted 10 lines · On Sat, Apr 25, 2020 at 11:19:53AM +0200, [email protected]…
drivers/usb/mausb_host/hcd.c +10
-0+static int mausb_device_assign_address (struct mausb_device *dev, +struct mausb_usb_device_ctx *usb_dev_ctx) +{ +int status = +mausb_setusbdevaddress_event_to_user (dev, + usb_dev_ctx->dev_handle, +RESPONSE_TIMEOUT ); + +mausb_pr_info ("dev_handle=%#x, status=%d" , usb_dev_ctx->dev_handle, + status);
When drivers are working properly, they are totally silent. Please remove this type of debugging code from the driver entirely, or change it to be dev_dbg().
Otherwise this really looks like a very noisy driver.
greg k-h
PATCH v5 8/8 usb: mausb_host: Process MA-USB data packets
In reply to [email protected]Added implementation of MA-USB data&isoch packets processing logic, both for IN and OUT directions.
--- drivers/usb/mausb_host/Makefile | 1 + drivers/usb/mausb_host/hpal.c | 31 +- drivers/usb/mausb_host/hpal_data.c | 714 +++++++++++++++++++++++++++++ drivers/usb/mausb_host/hpal_data.h | 34 ++ 4 files changed, 778 insertions(+), 2 deletions(-) create mode 100644 drivers/usb/mausb_host/hpal_data.c create mode 100644 drivers/usb/mausb_host/hpal_data.h
drivers/usb/mausb_host/Makefile +1 -0
@@ -12,5 +12,6 @@ mausb_host-y += ip_link.o mausb_host-y += hcd.o mausb_host-y += hpal.o mausb_host-y += hpal_events.o +mausb_host-y += hpal_data.o ccflags-y += -I$(srctree)/$(src)
drivers/usb/mausb_host/hpal.c +29 -2
@@ -11,6 +11,7 @@#include <linux/uio.h> #include "hcd.h" +#include "hpal_data.h" #include "hpal_events.h" #include "utils.h"
@@ -1387,6 +1388,7 @@ int mausb_send_transfer_ack(struct mausb_device *dev, struct mausb_event *event)int mausb_send_data_msg (struct mausb_device *dev,struct mausb_event *event) {struct mausb_urb_ctx *urb_ctx; +int status =0 ;if (event->status !=0 ) { mausb_pr_err("Event %d failed with status %d",
@@ -1401,9 +1403,22 @@ int mausb_send_data_msg(struct mausb_device *dev, struct mausb_event *event)/* Transfer will be deleted from dequeue task */ mausb_pr_warn ("Urb is already cancelled for event=%d" , event->type); +return status; } -return 0 ; +if (mausb_isoch_data_event (event)) { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) + status =mausb_send_isoch_in_msg (dev, event); +else + status =mausb_send_isoch_out_msg (dev, event, urb_ctx); + }else { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) + status =mausb_send_in_data_msg (dev, event); +else + status =mausb_send_out_data_msg (dev, event, urb_ctx); + } + +return status; }int mausb_receive_data_msg (struct mausb_device *dev,struct mausb_event *event)
@@ -1426,6 +1441,19 @@ int mausb_receive_data_msg(struct mausb_device *dev, struct mausb_event *event)if (!urb_ctx) {/* Transfer will be deleted from dequeue task */ mausb_pr_warn ("Urb is already cancelled" ); + goto cleanup; + } + +if (mausb_isoch_data_event (event)) { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) +mausb_receive_isoch_in_data (dev, event, urb_ctx); +else +mausb_receive_isoch_out (event); + }else { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) +mausb_receive_in_data (event, urb_ctx); +else +mausb_receive_out_data (event, urb_ctx); } cleanup:
@@ -1593,7 +1621,6 @@ static void mausb_handle_receive_event(struct mausb_device *dev, status =mausb_msg_received_event (&event, (struct ma_usb_hdr_common *)data, channel); -if (status ==0 ) status =mausb_enqueue_event_to_user (dev, &event);
drivers/usb/mausb_host/hpal_data.c new file +714 -0
714 lines not on this page · raw message
drivers/usb/mausb_host/hpal_data.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_HPAL_DATA_H__ +#define __MAUSB_HPAL_DATA_H__ + +#include <linux/types.h> + +#include "hpal_events.h" + +int mausb_send_in_data_msg (struct mausb_device *dev,struct mausb_event *event); +void mausb_receive_in_data (struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +int mausb_send_out_data_msg (struct mausb_device *dev,struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); +void mausb_receive_out_data (struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +#define MAUSB_ISOCH_IN_KVEC_NUM 3 + +int mausb_send_isoch_in_msg (struct mausb_device *dev, +struct mausb_event *event); +void mausb_receive_isoch_in_data (struct mausb_device *dev, +struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +int mausb_send_isoch_out_msg (struct mausb_device *ma_dev, +struct mausb_event *mausb_event, +struct mausb_urb_ctx *urb_ctx); +void mausb_receive_isoch_out (struct mausb_event *event); + +#endif /* __MAUSB_HPAL_DATA_H__ */
Signature · 1 line
2.17.1
Greg KH
maintainerQuoted 10 lines · On Sat, Apr 25, 2020 at 11:19:46AM +0200, [email protected]…
Media Agnostic (MA) USB Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
Is that a USB-released spec?
Quoted 3 lines
This driver depends on the functions provided by DisplayLink's user-space driver.
Where can that userspace code be found?
thanks,
greg k-h
Quoted 5 lines · Greg KH
Quoted 4 lines · On Sat, Apr 25, 2020 at 11:19:46AM +0200, [email protected]…
Media Agnostic (MA) USB Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
Quoted 8 lines
Quoted 6 lines
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
Is that a USB-released spec?
Correct, document is being maintained by USB IF and is publicly available. However, I just noticed a typo, correct version is 1.0a. Will correct.
In short, MA USB Specification defines an MA USB protocol that performs USB communication via any communication medium. As such, it defines how to pack USB data within MA USB payload, and how to communicate with remote MA USB device.
Quoted 11 lines
Quoted 4 lines
This driver depends on the functions provided by DisplayLink's user-space driver.
Where can that userspace code be found?
thanks,
greg k-h
Userspace code is not publicly available. However, in short, it's purpose is twofold, to provide interface to application layer, and to prepare MA USB packets that will be used by remote device.
Related to userspace related questions (i.e. comments around two devices used), we can provide detailed description of the used IPC. In that sense, please state the most appropriate way/place to state/publish such description (i.e. is it ok to add it within the cover letter, or publicly available URL is preferred).
Signature · 2 lines
Regards, Vladimir.
Greg KH
maintainerQuoted 27 lines · Vladimir Stankovic
Quoted 5 lines · Greg KH
Quoted 4 lines · On Sat, Apr 25, 2020 at 11:19:46AM +0200, [email protected]…
Media Agnostic (MA) USB Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
Quoted 8 lines
Quoted 6 lines
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
Is that a USB-released spec?
Correct, document is being maintained by USB IF and is publicly available. However, I just noticed a typo, correct version is 1.0a. Will correct.
In short, MA USB Specification defines an MA USB protocol that performs USB communication via any communication medium. As such, it defines how to pack USB data within MA USB payload, and how to communicate with remote MA USB device.
Quoted 7 lines
Quoted 4 lines
This driver depends on the functions provided by DisplayLink's user-space driver.
Where can that userspace code be found?
Quoted 7 lines
Quoted 4 lines
thanks,
greg k-h
Userspace code is not publicly available. However, in short, it's purpose is twofold, to provide interface to application layer, and to prepare MA USB packets that will be used by remote device.
So you want us to take a one-off char-driver kernel code for a closed source userspace application for a public spec? That feels really really odd, if not actually against a few licenses. I hate to ask it, but are your lawyers ok with this?
Quoted 4 lines
Related to userspace related questions (i.e. comments around two devices used), we can provide detailed description of the used IPC. In that sense, please state the most appropriate way/place to state/publish such description (i.e. is it ok to add it within the cover letter, or publicly available URL is preferred).
I asked a bunch of questions about this in the patches themselves, you all need to document the heck out of it everywhere you can, otherwise we can't even review the code properly. Could you review it without knowing what userspace is supposed to be doing?
But, note, I will not take a spec-compliant driver that requires closed source userspace code, nor should you even want me to do that if you rely on Linux.
So please, release the userspace code, as it's going to have to be changed anyway as your current user/kernel api is broken/incorrect as-is. Why not just bundle it in the kernel tree like we have the usbip code? That way you know it all works properly, and better yet, it can be tested and maintained properly over time.
thanks,
greg k-h
Quoted 61 lines · Greg KH
Quoted 27 lines · Vladimir Stankovic
Quoted 5 lines · Greg KH
Quoted 4 lines · On Sat, Apr 25, 2020 at 11:19:46AM +0200, [email protected]…
Media Agnostic (MA) USB Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
Quoted 8 lines
Quoted 6 lines
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
Is that a USB-released spec?
Correct, document is being maintained by USB IF and is publicly available. However, I just noticed a typo, correct version is 1.0a. Will correct.
In short, MA USB Specification defines an MA USB protocol that performs USB communication via any communication medium. As such, it defines how to pack USB data within MA USB payload, and how to communicate with remote MA USB device.
Quoted 7 lines
Quoted 4 lines
This driver depends on the functions provided by DisplayLink's user-space driver.
Where can that userspace code be found?
Quoted 7 lines
Quoted 4 lines
thanks,
greg k-h
Userspace code is not publicly available. However, in short, it's purpose is twofold, to provide interface to application layer, and to prepare MA USB packets that will be used by remote device.
So you want us to take a one-off char-driver kernel code for a closed source userspace application for a public spec? That feels really really odd, if not actually against a few licenses. I hate to ask it, but are your lawyers ok with this?
Quoted 4 lines
Related to userspace related questions (i.e. comments around two devices used), we can provide detailed description of the used IPC. In that sense, please state the most appropriate way/place to state/publish such description (i.e. is it ok to add it within the cover letter, or publicly available URL is preferred).
I asked a bunch of questions about this in the patches themselves, you all need to document the heck out of it everywhere you can, otherwise we can't even review the code properly. Could you review it without knowing what userspace is supposed to be doing?
But, note, I will not take a spec-compliant driver that requires closed source userspace code, nor should you even want me to do that if you rely on Linux.
So please, release the userspace code, as it's going to have to be changed anyway as your current user/kernel api is broken/incorrect as-is. Why not just bundle it in the kernel tree like we have the usbip code? That way you know it all works properly, and better yet, it can be tested and maintained properly over time.
Quoted 4 lines
thanks,
greg k-h
We've started internal discussion around user/kernel IPC. Other comments from v5 have been addressed within v6.
Signature · 2 lines
Regards, Vladimir.
Hi!
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 2 lines
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
Is that a USB-released spec?
Correct, document is being maintained by USB IF and is publicly available. However, I just noticed a typo, correct version is 1.0a. Will correct.
In short, MA USB Specification defines an MA USB protocol that performs USB communication via any communication medium. As such, it defines how to pack USB data within MA USB payload, and how to communicate with remote MA USB device.
Ok
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Userspace code is not publicly available. However, in short, it's purpose is twofold, to provide interface to application layer, and to prepare MA USB packets that will be used by remote device.
So you want us to take a one-off char-driver kernel code for a closed source userspace application for a public spec? That feels really really odd, if not actually against a few licenses. I hate to ask it, but are your lawyers ok with this?
More importantly... does that work?
Userland is okay for communication setup, but if userspace is involved with every packet being sent... It will deadlock.
One example: attach mass storage device over MUSB, put swap there; what happens if your userland helper is now swapped out?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
v6 cover Add MA USB Host driver
In reply to [email protected]Media Agnostic (MA) USB Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
This driver depends on the functions provided by DisplayLink's user-space driver.
v2:
- Fixed licensing info in headers
- Reorganized code to lower file count
- Patch has been split into 8 smaller patches
v3:
- Fixed nested spinlock usage
- Implemented IPv6 support
v4:
- No code changes
- Re-sent patch with different mail client config
v5:
- Updated kernel configuration with MA info
- Addressed build warnings for c6x architecture
- Fixed coccinelle warnings
v6:
- Changed module location to drivers/usb/host/mausb
- Switched from custom to dev_* logging
- Utilize misc device for the driver
- Removed versioning info from log entries
Vladimir Stankovic (8):
usb: Add MA-USB Host kernel module
usb: mausb_host: Add link layer implementation
usb: mausb_host: HCD initialization
usb: mausb_host: Implement initial hub handlers
usb: mausb_host: Introduce PAL processing
usb: mausb_host: Add logic for PAL-to-PAL communication
usb: mausb_host: MA-USB PAL events processing
usb: mausb_host: Process MA-USB data packets
MAINTAINERS | 7 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 1 + drivers/usb/host/mausb/Kconfig | 15 + drivers/usb/host/mausb/Makefile | 15 + drivers/usb/host/mausb/hcd.c | 1780 +++++++++++++++ drivers/usb/host/mausb/hcd.h | 154 ++ drivers/usb/host/mausb/hpal.c | 2094 ++++++++++++++++++ drivers/usb/host/mausb/hpal.h | 340 +++ drivers/usb/host/mausb/hpal_data.c | 713 ++++++ drivers/usb/host/mausb/hpal_data.h | 34 + drivers/usb/host/mausb/hpal_events.c | 614 +++++ drivers/usb/host/mausb/hpal_events.h | 85 + drivers/usb/host/mausb/ip_link.c | 367 +++ drivers/usb/host/mausb/ip_link.h | 88 + drivers/usb/host/mausb/ma_usb.h | 869 ++++++++ drivers/usb/host/mausb/mausb_address.h | 26 + drivers/usb/host/mausb/mausb_core.c | 191 ++ drivers/usb/host/mausb/mausb_driver_status.h | 17 + drivers/usb/host/mausb/mausb_event.h | 224 ++ drivers/usb/host/mausb/utils.c | 317 +++ drivers/usb/host/mausb/utils.h | 16 + 22 files changed, 7969 insertions(+) create mode 100644 drivers/usb/host/mausb/Kconfig create mode 100644 drivers/usb/host/mausb/Makefile create mode 100644 drivers/usb/host/mausb/hcd.c create mode 100644 drivers/usb/host/mausb/hcd.h create mode 100644 drivers/usb/host/mausb/hpal.c create mode 100644 drivers/usb/host/mausb/hpal.h create mode 100644 drivers/usb/host/mausb/hpal_data.c create mode 100644 drivers/usb/host/mausb/hpal_data.h create mode 100644 drivers/usb/host/mausb/hpal_events.c create mode 100644 drivers/usb/host/mausb/hpal_events.h create mode 100644 drivers/usb/host/mausb/ip_link.c create mode 100644 drivers/usb/host/mausb/ip_link.h create mode 100644 drivers/usb/host/mausb/ma_usb.h create mode 100644 drivers/usb/host/mausb/mausb_address.h create mode 100644 drivers/usb/host/mausb/mausb_core.c create mode 100644 drivers/usb/host/mausb/mausb_driver_status.h create mode 100644 drivers/usb/host/mausb/mausb_event.h create mode 100644 drivers/usb/host/mausb/utils.c create mode 100644 drivers/usb/host/mausb/utils.h
base-commit: 24085f70a6e1b0cb647ec92623284641d8270637
Signature · 1 line
2.17.1
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.
--- 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
MAINTAINERS +7 -0
@@ -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]>
drivers/usb/Kconfig +2 -0
@@ -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"
drivers/usb/Makefile +1 -0
@@ -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/
drivers/usb/host/mausb/Kconfig new file +15 -0
@@ -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.
drivers/usb/host/mausb/Makefile new file +10 -0
@@ -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
drivers/usb/host/mausb/mausb_core.c new file +24 -0
@@ -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);
drivers/usb/host/mausb/utils.c new file +47 -0
47 lines not on this page · raw message
drivers/usb/host/mausb/utils.h new file +15 -0
@@ -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__ */
Signature · 1 line
2.17.1
Greg KH
maintainerRe: [PATCH v6 1/8] usb: Add MA-USB Host kernel module
drivers/usb/host/mausb/Kconfig line 10
Quoted 13 lines · Vladimir Stankovic
drivers/usb/host/mausb/Kconfig new file +10
-0@@ -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.
drivers/usb/host/mausb/Kconfig line 15
Quoted 5 lines
drivers/usb/host/mausb/Kconfig new file +5
-0+ 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?
Quoted 82 lines
drivers/usb/host/mausb/Makefile new file +10
-0@@ -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.odrivers/usb/host/mausb/mausb_core.c new file +24
-0@@ -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);drivers/usb/host/mausb/utils.c new file +30
-0@@ -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 = {
drivers/usb/host/mausb/utils.c line 40
Quoted 10 lines
drivers/usb/host/mausb/utils.c new file +10
-0+ .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
Re: [PATCH v6 1/8] usb: Add MA-USB Host kernel module
Quoted 16 lines · Greg KH
drivers/usb/host/mausb/Kconfig line 10
Quoted 13 lines · Vladimir Stankovic
drivers/usb/host/mausb/Kconfig new file +10
-0@@ -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=yWhy =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.
Quoted 108 lines
drivers/usb/host/mausb/Kconfig line 15
Quoted 6 lines
drivers/usb/host/mausb/Kconfig new file +5
-0+ 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?
Quoted 82 lines
drivers/usb/host/mausb/Makefile new file +10
-0@@ -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.odrivers/usb/host/mausb/mausb_core.c new file +24
-0@@ -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);drivers/usb/host/mausb/utils.c new file +30
-0@@ -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 = {drivers/usb/host/mausb/utils.c line 40
Quoted 10 lines
drivers/usb/host/mausb/utils.c new file +10
-0+ .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?
Quoted 9 lines
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.
Signature · 2 lines
Regards, Vladimir.
Greg KH
maintainerRe: [PATCH v6 1/8] usb: Add MA-USB Host kernel module
In reply to Vladimir StankovicQuoted 26 lines · Vladimir Stankovic
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.hMAINTAINERS +0
-0
MAINTAINERS W: https://linuxtv.org · line 10348
Quoted 6 lines
MAINTAINERS +3
-0@@ -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
Re: [External] Re: [PATCH v6 1/8] usb: Add MA-USB Host kernel module
Quoted 37 lines · Greg KH
Quoted 26 lines · Vladimir Stankovic
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.hMAINTAINERS +0
-0MAINTAINERS W: https://linuxtv.org · line 10348
Quoted 6 lines
MAINTAINERS +3
-0@@ -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?
Quoted 4 lines
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.
Signature · 2 lines
Regards, Vladimir.
PATCH v6 2/8 usb: mausb_host: Add link layer implementation
In reply to Vladimir StankovicImplemented link layer using kernel sockets. Link layer manages network communication and provides interface for upper layers of MA-USB stack.
--- drivers/usb/host/mausb/Makefile | 1 + drivers/usb/host/mausb/ip_link.c | 367 +++++++++++++++++++++++++++++++ drivers/usb/host/mausb/ip_link.h | 88 ++++++++ 3 files changed, 456 insertions(+) create mode 100644 drivers/usb/host/mausb/ip_link.c create mode 100644 drivers/usb/host/mausb/ip_link.h
drivers/usb/host/mausb/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_USB_HOST_MAUSB) += mausb_host.o mausb_host-y := mausb_core.o mausb_host-y += utils.o +mausb_host-y += ip_link.o
drivers/usb/host/mausb/ip_link.c new file +367 -0
367 lines not on this page · raw message
drivers/usb/host/mausb/ip_link.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v6 3/8 usb: mausb_host: HCD initialization
In reply to Vladimir StankovicImplemented HCD initialization/deinitialization functionality.
--- drivers/usb/host/mausb/Makefile | 1 + drivers/usb/host/mausb/hcd.c | 120 ++++++++++++++++++++++++++++ drivers/usb/host/mausb/hcd.h | 65 +++++++++++++++ drivers/usb/host/mausb/mausb_core.c | 18 ++++- 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/host/mausb/hcd.c create mode 100644 drivers/usb/host/mausb/hcd.h
drivers/usb/host/mausb/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_USB_HOST_MAUSB) += mausb_host.o mausb_host-y := mausb_core.o mausb_host-y += utils.o mausb_host-y += ip_link.o +mausb_host-y += hcd.o
drivers/usb/host/mausb/hcd.c new file +120 -0
120 lines not on this page · raw message
drivers/usb/host/mausb/hcd.h new file +65 -0
65 lines not on this page · raw message
drivers/usb/host/mausb/mausb_core.c +17 -1
@@ -4,6 +4,7 @@*/ #include <linux/module.h> +#include "hcd.h" #include "utils.h" MODULE_LICENSE ("GPL" );
@@ -11,12 +12,27 @@ MODULE_AUTHOR("DisplayLink (UK) Ltd.");static int mausb_host_init (void ) { -return mausb_host_dev_register (); +int status =mausb_host_dev_register (); + +if (status <0 ) + goto exit; + + status =mausb_init_hcd (); +if (status <0 ) + goto cleanup_dev; + +return 0 ; + +cleanup_dev: +mausb_host_dev_deregister (); +exit: +return status; }static void mausb_host_exit (void ) {dev_info (mausb_host_dev.this_device,"Module unloading started..." ); +mausb_deinit_hcd ();mausb_host_dev_deregister (); }
Signature · 1 line
2.17.1
Greg KH
maintainerRe: [PATCH v6 3/8] usb: mausb_host: HCD initialization
Quoted 1 line · Vladimir Stankovic
Implemented HCD initialization/deinitialization functionality.
Shortest changelog ever :(
Please describe things better.
thanks,
greg k-h
Re: [PATCH v6 3/8] usb: mausb_host: HCD initialization
Quoted 11 lines · Greg KH
Quoted 1 line · Vladimir Stankovic
Implemented HCD initialization/deinitialization functionality.
Shortest changelog ever :(
Please describe things better.
thanks,
greg k-h
Agree. We'll start adding a bunch of documentation and comments in following patch versions - this was a quick fix during patchset reorg done in initial phase of upstreaming.
Signature · 2 lines
Regards, Vladimir.
Greg KH
maintainerRe: [PATCH v6 3/8] usb: mausb_host: HCD initialization
In reply to Vladimir StankovicQuoted 16 lines · Vladimir Stankovic
drivers/usb/host/mausb/hcd.c new file +13
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#include "hcd.h" + +#include "utils.h" + +static int mausb_bus_match (struct device *dev,struct device_driver *drv); + +static const struct file_operations mausb_fops; + +static unsigned int major;
drivers/usb/host/mausb/hcd.c line 23
Quoted 10 lines
drivers/usb/host/mausb/hcd.c new file +10
-0+static unsigned int minor =1 ; +static dev_t devt; +static struct device *device; + +struct mausb_hcd *mhcd; +static struct class *mausb_class; +static struct bus_type mausb_bus_type = { + .name =DEVICE_NAME , + .match = mausb_bus_match, +};
A static bus type??? For a single driver?
drivers/usb/host/mausb/hcd.c line 29
Quoted 6 lines
drivers/usb/host/mausb/hcd.c new file +6
-0+ +static struct device_driver mausb_driver = { + .name =DEVICE_NAME , + .bus = &mausb_bus_type, + .owner =THIS_MODULE , +};
Wait, what??? A static "raw" struct device_driver? Why???
Quoted 53 lines
drivers/usb/host/mausb/hcd.c new file +53
-0+ +static void mausb_remove (void ) +{ +struct usb_hcd *hcd, *shared_hcd; + + hcd = mhcd->hcd_hs_ctx->hcd; + shared_hcd = mhcd->hcd_ss_ctx->hcd; + +if (shared_hcd) { +usb_remove_hcd (shared_hcd); +usb_put_hcd (shared_hcd); + mhcd->hcd_ss_ctx =NULL ; + } + +usb_remove_hcd (hcd); +usb_put_hcd (hcd); + mhcd->hcd_hs_ctx =NULL ; +} + +static int mausb_bus_match (struct device *dev,struct device_driver *drv) +{ +if (strncmp (dev->bus->name, drv->name,strlen (drv->name))) +return 0 ; +else +return 1 ; +} + +int mausb_init_hcd (void ) +{ +int retval =register_chrdev (0 ,DEVICE_NAME , &mausb_fops); + +if (retval <0 ) +return retval; + + major = (unsigned int )retval; + retval =bus_register (&mausb_bus_type); +if (retval) + goto bus_register_error; + + mausb_class =class_create (THIS_MODULE ,CLASS_NAME ); +if (IS_ERR (mausb_class)) { + retval = (int )PTR_ERR (mausb_class); + goto class_error; + } + + retval =driver_register (&mausb_driver); +if (retval) + goto driver_register_error; + + mhcd =kzalloc (sizeof (*mhcd),GFP_ATOMIC ); +if (!mhcd) { + retval = -ENOMEM ; + goto mausb_hcd_alloc_failed;
drivers/usb/host/mausb/hcd.c line 92
Quoted 10 lines
drivers/usb/host/mausb/hcd.c new file +10
-0+ } + + devt =MKDEV (major, minor); + device =device_create (mausb_class,NULL , devt, mhcd,DEVICE_NAME ); +if (IS_ERR (device)) { + retval = (int )IS_ERR (device); + goto device_create_error; + } + + device->driver = &mausb_driver;
Why? What is this device going to do? What do you need it for?
drivers/usb/host/mausb/hcd.c line 105
Quoted 13 lines
drivers/usb/host/mausb/hcd.c new file +13
-0+ +return retval; +device_create_error: +kfree (mhcd); + mhcd =NULL ; +mausb_hcd_alloc_failed: +driver_unregister (&mausb_driver); +driver_register_error: +class_destroy (mausb_class); +class_error: +bus_unregister (&mausb_bus_type); +bus_register_error: +unregister_chrdev (major,DEVICE_NAME );
I thought you were using the misc device, what are you doing with a class and chardev? Why is that still here?
Quoted 26 lines
drivers/usb/host/mausb/hcd.c new file +15
-0+ +return retval; +} + +void mausb_deinit_hcd (void ) +{ +if (mhcd) { +mausb_remove (); +device_destroy (mausb_class, devt); +driver_unregister (&mausb_driver); +class_destroy (mausb_class); +bus_unregister (&mausb_bus_type); +unregister_chrdev (major,DEVICE_NAME ); + } +}drivers/usb/host/mausb/hcd.h new file +5
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_HCD_H__
drivers/usb/host/mausb/hcd.h line 15
Quoted 10 lines
drivers/usb/host/mausb/hcd.h new file +10
-0+#define __MAUSB_HCD_H__ + +#include <linux/slab.h> +#include <linux/usb.h> +#include <linux/usb/hcd.h> + +#define DEVICE_NAME "mausb_host_hcd" +#define CLASS_NAME "mausb" + +#define NUMBER_OF_PORTS 15
Why this max?
drivers/usb/host/mausb/hcd.h line 17
Quoted 2 lines
drivers/usb/host/mausb/hcd.h new file +2
-0+ +#define MAX_USB_DEVICE_DEPTH 6
Where does this max come from?
drivers/usb/host/mausb/hcd.h line 19
Quoted 2 lines
drivers/usb/host/mausb/hcd.h new file +2
-0+ +#define RESPONSE_TIMEOUT 5000
Units?
drivers/usb/host/mausb/hcd.h line 22
Quoted 3 lines
drivers/usb/host/mausb/hcd.h new file +3
-0+ +#define MAUSB_PORT_20_STATUS_LOW_SPEED 0x0200 +#define MAUSB_PORT_20_STATUS_HIGH_SPEED 0x0400
Device ids? Something else?
If something else, use BIT()?
drivers/usb/host/mausb/hcd.h line 27
Quoted 5 lines
drivers/usb/host/mausb/hcd.h new file +5
-0+ +enum mausb_device_type { +USBDEVICE =0 , +USB20HUB =1 , +USB30HUB =2
Trailing , please
drivers/usb/host/mausb/hcd.h line 35
Quoted 8 lines
drivers/usb/host/mausb/hcd.h new file +8
-0+}; + +enum mausb_device_speed { +LOW_SPEED =0 , +FULL_SPEED =1 , +HIGH_SPEED =2 , +SUPER_SPEED =3 , +SUPER_SPEED_PLUS =4
, please.
drivers/usb/host/mausb/hcd.h line 36
Quoted 1 line
drivers/usb/host/mausb/hcd.h new file +1
-0+};
Where do these values come from?
drivers/usb/host/mausb/hcd.h line 41
Quoted 5 lines
drivers/usb/host/mausb/hcd.h new file +5
-0+ +struct mausb_hcd { +spinlock_t lock;/* Protect HCD during URB processing */ +struct device *pdev; +u16 connected_ports;
Why u16?
Quoted 51 lines
drivers/usb/host/mausb/hcd.h new file +24
-0+ +struct rb_root mausb_urbs; +struct hub_ctx *hcd_ss_ctx; +struct hub_ctx *hcd_hs_ctx; + struct notifier_block power_state_listener; +}; + +struct mausb_dev { +u32 port_status; +struct rb_root usb_devices; +u8 dev_speed; +void *ma_dev; +}; + +struct hub_ctx { +struct mausb_hcd *mhcd; +struct usb_hcd *hcd; +struct mausb_dev ma_devs[NUMBER_OF_PORTS ]; +}; + +int mausb_init_hcd (void ); +void mausb_deinit_hcd (void ); + +#endif /* __MAUSB_HCD_H__ */ drivers/usb/host/mausb/mausb_core.c +11
-1@@ -4,6 +4,7 @@*/ #include <linux/module.h> +#include "hcd.h" #include "utils.h" MODULE_LICENSE ("GPL" );@@ -11,12 +12,27 @@ MODULE_AUTHOR("DisplayLink (UK) Ltd.");static int mausb_host_init (void ) { -return mausb_host_dev_register (); +int status =mausb_host_dev_register (); + +if (status <0 ) + goto exit; + + status =mausb_init_hcd (); +if (status <0 ) + goto cleanup_dev; + +return 0 ;
drivers/usb/host/mausb/mausb_core.c MODULE_AUTHOR("DisplayLink (UK) Ltd."); · line 34
Quoted 10 lines
drivers/usb/host/mausb/mausb_core.c +5
-0+ +cleanup_dev: +mausb_host_dev_deregister (); +exit: +return status; }static void mausb_host_exit (void ) {dev_info (mausb_host_dev.this_device,"Module unloading started..." );
This is debugging statements, please remove. If a driver works properly, it does not print anything out.
Especially as you never give the user the chance to see if module unloading ever finished :)
thanks,
greg k-h
Re: [External] Re: [PATCH v6 3/8] usb: mausb_host: HCD initialization
Quoted 30 lines · Greg KH
Quoted 16 lines · Vladimir Stankovic
drivers/usb/host/mausb/hcd.c new file +13
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#include "hcd.h" + +#include "utils.h" + +static int mausb_bus_match (struct device *dev,struct device_driver *drv); + +static const struct file_operations mausb_fops; + +static unsigned int major;drivers/usb/host/mausb/hcd.c line 23
Quoted 10 lines
drivers/usb/host/mausb/hcd.c new file +10
-0+static unsigned int minor =1 ; +static dev_t devt; +static struct device *device; + +struct mausb_hcd *mhcd; +static struct class *mausb_class; +static struct bus_type mausb_bus_type = { + .name =DEVICE_NAME , + .match = mausb_bus_match, +};A static bus type??? For a single driver?
Quoted 8 lines
drivers/usb/host/mausb/hcd.c line 29
Quoted 6 lines
drivers/usb/host/mausb/hcd.c new file +6
-0+ +static struct device_driver mausb_driver = { + .name =DEVICE_NAME , + .bus = &mausb_bus_type, + .owner =THIS_MODULE , +};Wait, what??? A static "raw" struct
device_driver? Why???
This was our initial driver setup that was "inherited" from some in-tree drivers. We are currently revising driver setup. In general, device driver will not work properly w/o bus being setup and the only way to avoid explicit bus and simplify driver setup is to use platform driver; however, we are not aware of any explicit dependency on the platform, so not sure whether it's acceptable to switch to platform device driver setup.
Quoted 58 lines
Quoted 58 lines
drivers/usb/host/mausb/hcd.c new file +57
-0+ +static void mausb_remove (void ) +{ +struct usb_hcd *hcd, *shared_hcd; + + hcd = mhcd->hcd_hs_ctx->hcd; + shared_hcd = mhcd->hcd_ss_ctx->hcd; + +if (shared_hcd) { +usb_remove_hcd (shared_hcd); +usb_put_hcd (shared_hcd); + mhcd->hcd_ss_ctx =NULL ; + } + +usb_remove_hcd (hcd); +usb_put_hcd (hcd); + mhcd->hcd_hs_ctx =NULL ; +} + +static int mausb_bus_match (struct device *dev,struct device_driver *drv) +{ +if (strncmp (dev->bus->name, drv->name,strlen (drv->name))) +return 0 ; +else +return 1 ; +} + +int mausb_init_hcd (void ) +{ +int retval =register_chrdev (0 ,DEVICE_NAME , &mausb_fops); + +if (retval <0 ) +return retval; + + major = (unsigned int )retval; + retval =bus_register (&mausb_bus_type); +if (retval) + goto bus_register_error; + + mausb_class =class_create (THIS_MODULE ,CLASS_NAME ); +if (IS_ERR (mausb_class)) { + retval = (int )PTR_ERR (mausb_class); + goto class_error; + } + + retval =driver_register (&mausb_driver); +if (retval) + goto driver_register_error; + + mhcd =kzalloc (sizeof (*mhcd),GFP_ATOMIC ); +if (!mhcd) { + retval = -ENOMEM ; + goto mausb_hcd_alloc_failed; + } + + devt =MKDEV (major, minor); + device =device_create (mausb_class,NULL , devt, mhcd,DEVICE_NAME );
Quoted 8 lines
drivers/usb/host/mausb/hcd.c line 92
Quoted 6 lines
drivers/usb/host/mausb/hcd.c new file +6
-0+if (IS_ERR (device)) { + retval = (int )IS_ERR (device); + goto device_create_error; + } + + device->driver = &mausb_driver;Why? What is this device going to do? What do you need it for?
Yeah, this one is not needed at all. Will be removed.
Quoted 18 lines
Quoted 4 lines
drivers/usb/host/mausb/hcd.c new file +3
-0+ +return retval; +device_create_error:drivers/usb/host/mausb/hcd.c line 105
Quoted 10 lines
drivers/usb/host/mausb/hcd.c new file +10
-0+kfree (mhcd); + mhcd =NULL ; +mausb_hcd_alloc_failed: +driver_unregister (&mausb_driver); +driver_register_error: +class_destroy (mausb_class); +class_error: +bus_unregister (&mausb_bus_type); +bus_register_error: +unregister_chrdev (major,DEVICE_NAME );I thought you were using the misc device, what are you doing with a class and chardev? Why is that still here?
We're currently revising driver setup logic - this part should be much cleaner in new patch version.
Quoted 33 lines
Quoted 33 lines
drivers/usb/host/mausb/hcd.c new file +15
-0+ +return retval; +} + +void mausb_deinit_hcd (void ) +{ +if (mhcd) { +mausb_remove (); +device_destroy (mausb_class, devt); +driver_unregister (&mausb_driver); +class_destroy (mausb_class); +bus_unregister (&mausb_bus_type); +unregister_chrdev (major,DEVICE_NAME ); + } +}drivers/usb/host/mausb/hcd.h new file +9
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_HCD_H__ +#define __MAUSB_HCD_H__ + +#include <linux/slab.h> +#include <linux/usb.h>
Quoted 8 lines
drivers/usb/host/mausb/hcd.h line 15
Quoted 6 lines
drivers/usb/host/mausb/hcd.h new file +6
-0+#include <linux/usb/hcd.h> + +#define DEVICE_NAME "mausb_host_hcd" +#define CLASS_NAME "mausb" + +#define NUMBER_OF_PORTS 15Why this max?
Related to USB_SS_MAXPORTS - a worst case scenario.
Quoted 5 lines
drivers/usb/host/mausb/hcd.h line 17
Quoted 3 lines
drivers/usb/host/mausb/hcd.h new file +2
-0+ +#define MAX_USB_DEVICE_DEPTH 6Where does this max come from?
Unknown origin and unused - will be removed.
Quoted 5 lines
drivers/usb/host/mausb/hcd.h line 19
Quoted 3 lines
drivers/usb/host/mausb/hcd.h new file +2
-0+ +#define RESPONSE_TIMEOUT 5000Units?
ms - will be renamed to reflect the same.
Quoted 32 lines
drivers/usb/host/mausb/hcd.h line 22
Quoted 4 lines
drivers/usb/host/mausb/hcd.h new file +3
-0+ +#define MAUSB_PORT_20_STATUS_LOW_SPEED 0x0200 +#define MAUSB_PORT_20_STATUS_HIGH_SPEED 0x0400Device ids? Something else?
If something else, use
BIT()?drivers/usb/host/mausb/hcd.h line 27
Quoted 5 lines
drivers/usb/host/mausb/hcd.h new file +5
-0+ +enum mausb_device_type { +USBDEVICE =0 , +USB20HUB =1 , +USB30HUB =2 Trailing , please
drivers/usb/host/mausb/hcd.h line 35
Quoted 8 lines
drivers/usb/host/mausb/hcd.h new file +8
-0+}; + +enum mausb_device_speed { +LOW_SPEED =0 , +FULL_SPEED =1 , +HIGH_SPEED =2 , +SUPER_SPEED =3 , +SUPER_SPEED_PLUS =4 , please.
drivers/usb/host/mausb/hcd.h line 36
Quoted 1 line
drivers/usb/host/mausb/hcd.h new file +1
-0+};Where do these values come from?
Quoted 7 lines
drivers/usb/host/mausb/hcd.h line 41
Quoted 5 lines
drivers/usb/host/mausb/hcd.h new file +5
-0+ +struct mausb_hcd { +spinlock_t lock;/* Protect HCD during URB processing */ +struct device *pdev; +u16 connected_ports;Why u16?
Seems odd, since max number of ports is much less. Should be corrected.
Quoted 66 lines
Quoted 52 lines
drivers/usb/host/mausb/hcd.h new file +24
-0+ +struct rb_root mausb_urbs; +struct hub_ctx *hcd_ss_ctx; +struct hub_ctx *hcd_hs_ctx; + struct notifier_block power_state_listener; +}; + +struct mausb_dev { +u32 port_status; +struct rb_root usb_devices; +u8 dev_speed; +void *ma_dev; +}; + +struct hub_ctx { +struct mausb_hcd *mhcd; +struct usb_hcd *hcd; +struct mausb_dev ma_devs[NUMBER_OF_PORTS ]; +}; + +int mausb_init_hcd (void ); +void mausb_deinit_hcd (void ); + +#endif /* __MAUSB_HCD_H__ */ drivers/usb/host/mausb/mausb_core.c +11
-1@@ -4,6 +4,7 @@*/ #include <linux/module.h> +#include "hcd.h" #include "utils.h" MODULE_LICENSE ("GPL" );@@ -11,12 +12,27 @@ MODULE_AUTHOR("DisplayLink (UK) Ltd.");static int mausb_host_init (void ) { -return mausb_host_dev_register (); +int status =mausb_host_dev_register (); + +if (status <0 ) + goto exit; + + status =mausb_init_hcd (); +if (status <0 ) + goto cleanup_dev; + +return 0 ;drivers/usb/host/mausb/mausb_core.c MODULE_AUTHOR("DisplayLink (UK) Ltd."); · line 34
Quoted 10 lines
drivers/usb/host/mausb/mausb_core.c +5
-0+ +cleanup_dev: +mausb_host_dev_deregister (); +exit: +return status; }static void mausb_host_exit (void ) {dev_info (mausb_host_dev.this_device,"Module unloading started..." );This is debugging statements, please remove. If a driver works properly, it does not print anything out.
Quoted 2 lines
Especially as you never give the user the chance to see if module unloading ever finished :)
Agree :)
Quoted 5 lines
thanks,
greg k-h
Signature · 2 lines
Regards, Vladimir.
Greg KH
maintainerRe: [External] Re: [PATCH v6 3/8] usb: mausb_host: HCD initialization
Quoted 39 lines · Vladimir Stankovic
Quoted 30 lines · Greg KH
Quoted 16 lines · Vladimir Stankovic
drivers/usb/host/mausb/hcd.c new file +13
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#include "hcd.h" + +#include "utils.h" + +static int mausb_bus_match (struct device *dev,struct device_driver *drv); + +static const struct file_operations mausb_fops; + +static unsigned int major;drivers/usb/host/mausb/hcd.c line 23
Quoted 10 lines
drivers/usb/host/mausb/hcd.c new file +10
-0+static unsigned int minor =1 ; +static dev_t devt; +static struct device *device; + +struct mausb_hcd *mhcd; +static struct class *mausb_class; +static struct bus_type mausb_bus_type = { + .name =DEVICE_NAME , + .match = mausb_bus_match, +};A static bus type??? For a single driver?
Quoted 8 lines
drivers/usb/host/mausb/hcd.c line 29
Quoted 6 lines
drivers/usb/host/mausb/hcd.c new file +6
-0+ +static struct device_driver mausb_driver = { + .name =DEVICE_NAME , + .bus = &mausb_bus_type, + .owner =THIS_MODULE , +};Wait, what??? A static "raw" struct
device_driver? Why???
Quoted 7 lines
This was our initial driver setup that was "inherited" from some in-tree drivers. We are currently revising driver setup. In general, device driver will not work properly w/o bus being setup and the only way to avoid explicit bus and simplify driver setup is to use platform driver; however, we are not aware of any explicit dependency on the platform, so not sure whether it's acceptable to switch to platform device driver setup.
platform devices/drivers are to be used ONLY if your really have a platform device (i.e. something connected to the system only through device-tree or hard-coded memory locations.) Do not use this for virtual devices or anything else that is on a "real" bus.
thanks,
greg k-h
PATCH v6 4/8 usb: mausb_host: Implement initial hub handlers
In reply to Vladimir StankovicImplemented handlers for subset of HCD events.
--- drivers/usb/host/mausb/hcd.c | 925 +++++++++++++++++++++++++++++++++++ drivers/usb/host/mausb/hcd.h | 86 +++- 2 files changed, 1008 insertions(+), 3 deletions(-)
drivers/usb/host/mausb/hcd.c +925 -0
@@ -6,6 +6,7 @@#include "utils.h" +static int mausb_bus_probe (struct device *dev);static int mausb_bus_match (struct device *dev,struct device_driver *drv);static const struct file_operations mausb_fops;
@@ -20,6 +21,7 @@ static struct class *mausb_class;static struct bus_type mausb_bus_type = { .name =DEVICE_NAME , .match = mausb_bus_match, + .probe = mausb_bus_probe, };static struct device_driver mausb_driver = {
@@ -46,6 +48,11 @@ static void mausb_remove(void) mhcd->hcd_hs_ctx =NULL ; } +static int mausb_bus_probe (struct device *dev) +{ +return mausb_probe (dev); +} +static int mausb_bus_match (struct device *dev,struct device_driver *drv) {if (strncmp (dev->bus->name, drv->name,strlen (drv->name)))
@@ -91,7 +98,13 @@ int mausb_init_hcd(void) device->driver = &mausb_driver; + retval =mausb_probe (device); +if (retval) + goto mausb_probe_failed; +return retval; +mausb_probe_failed: +device_destroy (mausb_class, devt); device_create_error:kfree (mhcd); mhcd =NULL ;
@@ -118,3 +131,915 @@ void mausb_deinit_hcd(void)unregister_chrdev (major,DEVICE_NAME ); } } + +static const char driver_name[] ="MA-USB host controller" ; + +static void mausb_get_hub_descriptor (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length); +static void mausb_set_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static void mausb_get_port_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static void mausb_clear_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length); +static void mausb_get_hub_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static int mausb_add_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint); +static int mausb_address_device (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_alloc_dev (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_drop_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint); +static int mausb_enable_device (struct usb_hcd *hcd,struct usb_device *dev); +static void mausb_endpoint_reset (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint); +static void mausb_free_dev (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_hcd_bus_resume (struct usb_hcd *hcd); +static int mausb_hcd_bus_suspend (struct usb_hcd *hcd); +static int mausb_hcd_get_frame_number (struct usb_hcd *hcd); +static int mausb_hcd_hub_control (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length); +static int mausb_hcd_hub_status (struct usb_hcd *hcd,char *buff); +static int mausb_hcd_reset (struct usb_hcd *hcd); +static int mausb_hcd_start (struct usb_hcd *hcd); +static int mausb_hub_update_device (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_tt *tt,gfp_t mem_flags); +static int mausb_reset_device (struct usb_hcd *hcd,struct usb_device *dev); +static int mausb_update_device (struct usb_hcd *hcd,struct usb_device *dev); + +static const struct hc_driver mausb_hc_driver = { + .description = driver_name, + .product_desc = driver_name, + .flags =HCD_USB3 |HCD_SHARED , + + .hcd_priv_size =sizeof (struct hub_ctx ), + + .reset = mausb_hcd_reset, + .start = mausb_hcd_start, + + .get_frame_number = mausb_hcd_get_frame_number, + + .hub_status_data = mausb_hcd_hub_status, + .hub_control = mausb_hcd_hub_control, + .update_hub_device = mausb_hub_update_device, + .bus_suspend = mausb_hcd_bus_suspend, + .bus_resume = mausb_hcd_bus_resume, + + .alloc_dev = mausb_alloc_dev, + .free_dev = mausb_free_dev, + .enable_device = mausb_enable_device, + .update_device = mausb_update_device, + .reset_device = mausb_reset_device, + + .add_endpoint = mausb_add_endpoint, + .drop_endpoint = mausb_drop_endpoint, + .address_device = mausb_address_device, + .endpoint_reset = mausb_endpoint_reset, +}; + +static struct { +struct usb_bos_descriptor bos; +struct usb_ss_cap_descriptor ss_cap; +} usb3_bos_desc = { + .bos = { + .bLength =USB_DT_BOS_SIZE , + .bDescriptorType =USB_DT_BOS , + .wTotalLength =cpu_to_le16 (sizeof (usb3_bos_desc)), + .bNumDeviceCaps =1 + }, + .ss_cap = { + .bLength =USB_DT_USB_SS_CAP_SIZE , + .bDescriptorType =USB_DT_DEVICE_CAPABILITY , + .bDevCapabilityType =USB_SS_CAP_TYPE , + .wSpeedSupported =cpu_to_le16 (USB_5GBPS_OPERATION ), + .bFunctionalitySupport =ilog2 (USB_5GBPS_OPERATION ) + } +}; + +static int get_root_hub_port_number (struct usb_device *dev,u8 *port_number) +{ +struct usb_device *first_hub_device = dev; + +if (!dev->parent) { + (*port_number) =0 ; +return -EINVAL ; + } + +while (first_hub_device->parent->parent) + first_hub_device = first_hub_device->parent; + + (*port_number) = first_hub_device->portnum -1 ; + +return 0 ; +} + +static struct mausb_usb_device_ctx *mausb_find_usb_device (struct mausb_dev + *mdevs,void *dev_addr) +{ +struct rb_node *node = mdevs->usb_devices.rb_node; + +while (node) { +struct mausb_usb_device_ctx *usb_device = + rb_entry(node, struct mausb_usb_device_ctx, rb_node); + +if (dev_addr < usb_device->dev_addr) + node = usb_device->rb_node.rb_left; +else if (dev_addr > usb_device->dev_addr) + node = usb_device->rb_node.rb_right; +else +return usb_device; + } +return NULL ; +} + +static int mausb_hcd_get_frame_number (struct usb_hcd *hcd) +{ +return 0 ; +} + +static int mausb_hcd_reset (struct usb_hcd *hcd) +{ +if (usb_hcd_is_primary_hcd (hcd)) { + hcd->speed =HCD_USB2 ; + hcd->self.root_hub->speed =USB_SPEED_HIGH ; + }else { + hcd->speed =HCD_USB3 ; + hcd->self.root_hub->speed =USB_SPEED_SUPER ; + } + hcd->self.no_sg_constraint =1 ; + hcd->self.sg_tablesize =UINT_MAX ; + +return 0 ; +} + +static int mausb_hcd_start (struct usb_hcd *hcd) +{ + hcd->power_budget =0 ; + hcd->uses_new_polling =1 ; +return 0 ; +} + +static int mausb_hcd_hub_status (struct usb_hcd *hcd,char *buff) +{ +int retval; +int changed; +int i; +struct hub_ctx *hub; +unsigned long flags =0 ; + + hub = (struct hub_ctx *)hcd->hcd_priv; + + retval =DIV_ROUND_UP (NUMBER_OF_PORTS +1 ,8 ); + changed =0 ; + +memset (buff,0 , (unsigned int )retval); + +spin_lock_irqsave (&mhcd->lock, flags); + +if (!HCD_HW_ACCESSIBLE (hcd)) { +dev_info (mausb_host_dev.this_device,"hcd not accessible, hcd speed=%d" , + hcd->speed); +spin_unlock_irqrestore (&mhcd->lock, flags); +return 0 ; + } + +for (i =0 ; i <NUMBER_OF_PORTS ; ++i) { +if ((hub->ma_devs[i].port_status &PORT_C_MASK )) { + buff[(i +1 ) /8 ] |=1 << (i +1 ) %8 ; + changed =1 ; + } + } + +dev_info (mausb_host_dev.this_device,"Usb %d.0 : changed=%d, retval=%d" , + (hcd->speed ==HCD_USB2 ) ?2 :3 , changed, retval); + +if (hcd->state ==HC_STATE_SUSPENDED && changed ==1 ) { +dev_info (mausb_host_dev.this_device,"hcd state is suspended" ); +usb_hcd_resume_root_hub (hcd); + } + +spin_unlock_irqrestore (&mhcd->lock, flags); + +return changed ? retval :0 ; +} + +static int mausb_hcd_bus_resume (struct usb_hcd *hcd) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mhcd->lock, flags); +if (!HCD_HW_ACCESSIBLE (hcd)) { +dev_info (mausb_host_dev.this_device,"hcd not accessible, hcd speed=%d" , + hcd->speed); +spin_unlock_irqrestore (&mhcd->lock, flags); +return -ESHUTDOWN ; + } + hcd->state =HC_STATE_RUNNING ; +spin_unlock_irqrestore (&mhcd->lock, flags); + +return 0 ; +} + +static int mausb_hcd_bus_suspend (struct usb_hcd *hcd) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mhcd->lock, flags); + hcd->state =HC_STATE_SUSPENDED ; +spin_unlock_irqrestore (&mhcd->lock, flags); + +return 0 ; +} + +static int mausb_hcd_hub_control (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +int retval =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_hcd *hub_mhcd = hub->mhcd; +unsigned long flags; +bool invalid_rhport = false; + + index = ((__u8)(index &0x00ff )); +if (index <1 || index >NUMBER_OF_PORTS ) + invalid_rhport = true; + +dev_vdbg (mausb_host_dev.this_device,"TypeReq=%d" , type_req); + +spin_lock_irqsave (&hub_mhcd->lock, flags); + +if (!HCD_HW_ACCESSIBLE (hcd)) { +dev_err (mausb_host_dev.this_device,"hcd not accessible, hcd speed=%d" , + hcd->speed); +spin_unlock_irqrestore (&hub_mhcd->lock, flags); +return -ETIMEDOUT ; + } + +switch (type_req) { +case ClearHubFeature: +break ; +case ClearPortFeature: +if (invalid_rhport) + goto invalid_port; + +mausb_clear_port_feature (hcd, type_req, value, index, buff, + length); +break ; +case DeviceRequest |USB_REQ_GET_DESCRIPTOR : +memcpy (buff, &usb3_bos_desc,sizeof (usb3_bos_desc)); + retval =sizeof (usb3_bos_desc); +break ; +case GetHubDescriptor: +mausb_get_hub_descriptor (hcd, type_req, value, index, buff, + length); +break ; +case GetHubStatus: +mausb_get_hub_status (hcd, type_req, value, index, buff, + length); +break ; +case GetPortStatus: +if (invalid_rhport) + goto invalid_port; + +mausb_get_port_status (hcd, type_req, value, index, buff, + length); +break ; +case SetHubFeature: + retval = -EPIPE ; +break ; +case SetPortFeature: +if (invalid_rhport) + goto invalid_port; + +mausb_set_port_feature (hcd, type_req, value, index, buff, + length); +break ; +default : + retval = -EPIPE ; + } + +invalid_port: +spin_unlock_irqrestore (&hub_mhcd->lock, flags); +return retval; +} + +int mausb_probe (struct device *dev) +{ +struct mausb_hcd *mausb_hcd; +struct usb_hcd *hcd_ss; +struct usb_hcd *hcd_hs; +int ret; + + mausb_hcd =dev_get_drvdata (dev); +spin_lock_init (&mausb_hcd->lock); + + hcd_hs =usb_create_hcd (&mausb_hc_driver, dev,dev_name (dev)); +if (!hcd_hs) +return -ENOMEM ; + + hcd_hs->has_tt =1 ; + mausb_hcd->hcd_hs_ctx = (struct hub_ctx *)hcd_hs->hcd_priv; + mausb_hcd->hcd_hs_ctx->mhcd = mausb_hcd; + mausb_hcd->hcd_hs_ctx->hcd = hcd_hs; +memset (mausb_hcd->hcd_hs_ctx->ma_devs,0 , +sizeof (struct mausb_dev ) *NUMBER_OF_PORTS ); + + ret =usb_add_hcd (hcd_hs,0 ,0 ); +if (ret) { +dev_err (dev,"usb_add_hcd failed" ); + goto put_hcd_hs; + } + + hcd_ss =usb_create_shared_hcd (&mausb_hc_driver, dev,dev_name (dev), + hcd_hs); +if (!hcd_ss) { + ret = -ENOMEM ; + goto remove_hcd_hs; + } + mausb_hcd->hcd_ss_ctx = (struct hub_ctx *)hcd_ss->hcd_priv; + mausb_hcd->hcd_ss_ctx->mhcd = mausb_hcd; + mausb_hcd->hcd_ss_ctx->hcd = hcd_ss; + +memset (mausb_hcd->hcd_ss_ctx->ma_devs,0 , +sizeof (struct mausb_dev ) *NUMBER_OF_PORTS ); + + ret =usb_add_hcd (hcd_ss,0 ,0 ); +if (ret) { +dev_err (dev,"usb_add_hcd failed" ); + goto put_hcd_ss; + } + +return ret; + +put_hcd_ss: +usb_put_hcd (hcd_ss); +remove_hcd_hs: +usb_remove_hcd (hcd_hs); +put_hcd_hs: +usb_put_hcd (hcd_hs); + mausb_hcd->hcd_hs_ctx =NULL ; + mausb_hcd->hcd_ss_ctx =NULL ; +return ret; +} + +static void mausb_get_hub_descriptor (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length) +{ +u8 width; +struct usb_hub_descriptor *desc = (struct usb_hub_descriptor *)buff; + +memset (desc,0 ,sizeof (struct usb_hub_descriptor )); + +if (hcd->speed ==HCD_USB3 ) { + desc->bDescriptorType =USB_DT_SS_HUB ; + desc->bDescLength =12 ; + desc->wHubCharacteristics = +cpu_to_le16 (HUB_CHAR_INDV_PORT_LPSM |HUB_CHAR_COMMON_OCPM ); + desc->bNbrPorts =NUMBER_OF_PORTS ; + desc->u.ss.bHubHdrDecLat =0x04 ; + desc->u.ss.DeviceRemovable =cpu_to_le16 (0xffff ); + }else { + desc->bDescriptorType =USB_DT_HUB ; + desc->wHubCharacteristics = +cpu_to_le16 (HUB_CHAR_INDV_PORT_LPSM |HUB_CHAR_COMMON_OCPM ); + desc->bNbrPorts =NUMBER_OF_PORTS ; + width = (u8)(desc->bNbrPorts /8 +1 ); + desc->bDescLength =USB_DT_HUB_NONVAR_SIZE +2 * width; + +memset (&desc->u.hs.DeviceRemovable[0 ],0 , width); +memset (&desc->u.hs.DeviceRemovable[width],0xff , width); + } +} + +static void mausb_set_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +switch (value) { +case USB_PORT_FEAT_LINK_STATE : +dev_vdbg (mausb_host_dev.this_device,"USB_PORT_FEAT_LINK_STATE" ); +if (hcd->speed ==HCD_USB3 ) { +if ((hub->ma_devs[index -1 ].port_status & +USB_SS_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + }else { +if ((hub->ma_devs[index -1 ].port_status & +USB_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + } +break ; +case USB_PORT_FEAT_U1_TIMEOUT : +case USB_PORT_FEAT_U2_TIMEOUT : +break ; +case USB_PORT_FEAT_SUSPEND : +break ; +case USB_PORT_FEAT_POWER : +dev_vdbg (mausb_host_dev.this_device,"USB_PORT_FEAT_POWER" ); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status |= +USB_SS_PORT_STAT_POWER ; + }else { + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_POWER ; + } +break ; +case USB_PORT_FEAT_BH_PORT_RESET : +dev_dbg (mausb_host_dev.this_device,"USB_PORT_FEAT_BH_PORT_RESET" ); +/* fall through */ +case USB_PORT_FEAT_RESET : +dev_vdbg (mausb_host_dev.this_device,"USB_PORT_FEAT_RESET hcd->speed=%d" , + hcd->speed); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status =0 ; + hub->ma_devs[index -1 ].port_status = + (USB_SS_PORT_STAT_POWER | +USB_PORT_STAT_CONNECTION |USB_PORT_STAT_RESET ); + }else if (hub->ma_devs[index -1 ].port_status + &USB_PORT_STAT_ENABLE ) { + hub->ma_devs[index -1 ].port_status &= + ~(USB_PORT_STAT_ENABLE | +USB_PORT_STAT_LOW_SPEED | +USB_PORT_STAT_HIGH_SPEED ); + } +/* fall through */ +default : +dev_vdbg (mausb_host_dev.this_device,"Default value=%d" , value); + +if (hcd->speed ==HCD_USB3 ) { +if ((hub->ma_devs[index -1 ].port_status & +USB_SS_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + }else { +if ((hub->ma_devs[index -1 ].port_status & +USB_PORT_STAT_POWER ) !=0 ) { + hub->ma_devs[index -1 ].port_status |= + (1U << value); + } + } + } +} + +static void mausb_get_port_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ +u8 dev_speed; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +if ((hub->ma_devs[index -1 ].port_status & + (1 <<USB_PORT_FEAT_RESET )) !=0 ) { +dev_info (mausb_host_dev.this_device,"Finished reset hcd->speed=%d" , + hcd->speed); + + dev_speed = hub->ma_devs[index -1 ].dev_speed; +switch (dev_speed) { +case LOW_SPEED : + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_LOW_SPEED ; +break ; +case HIGH_SPEED : + hub->ma_devs[index -1 ].port_status |= +USB_PORT_STAT_HIGH_SPEED ; +break ; +default : +dev_info (mausb_host_dev.this_device,"Not updating port_status for device speed %d" , + dev_speed); + } + + hub->ma_devs[index -1 ].port_status |= + (1 <<USB_PORT_FEAT_C_RESET ) |USB_PORT_STAT_ENABLE ; + hub->ma_devs[index -1 ].port_status &= + ~(1 <<USB_PORT_FEAT_RESET ); + } + + ((__le16 *)buff)[0 ] =cpu_to_le16 (hub->ma_devs[index -1 ].port_status); + ((__le16 *)buff)[1 ] = +cpu_to_le16 (hub->ma_devs[index -1 ].port_status >>16 ); + +dev_vdbg (mausb_host_dev.this_device,"port_status=%d" , + hub->ma_devs[index -1 ].port_status); +} + +static void mausb_clear_port_feature (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index, +char *buff,u16 length) +{ +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; + + index = ((__u8)(index &0x00ff )); + +switch (value) { +case USB_PORT_FEAT_SUSPEND : +break ; +case USB_PORT_FEAT_POWER : +dev_vdbg (mausb_host_dev.this_device,"USB_PORT_FEAT_POWER" ); + +if (hcd->speed ==HCD_USB3 ) { + hub->ma_devs[index -1 ].port_status &= + ~USB_SS_PORT_STAT_POWER ; + }else { + hub->ma_devs[index -1 ].port_status &= + ~USB_PORT_STAT_POWER ; + } +break ; +case USB_PORT_FEAT_RESET : +case USB_PORT_FEAT_C_RESET : +default : +dev_vdbg (mausb_host_dev.this_device,"Default value: %d" , + value); + + hub->ma_devs[index -1 ].port_status &= ~(1 << value); + } +} + +static void mausb_get_hub_status (struct usb_hcd *hcd,u16 type_req, +u16 value,u16 index,char *buff, +u16 length) +{ + *(__le32 *)buff =cpu_to_le32 (0 ); +} + +static int mausb_alloc_dev (struct usb_hcd *hcd,struct usb_device *dev) +{ +dev_info (mausb_host_dev.this_device,"Usb device=%p" , dev); + +return 1 ; +} + +static void mausb_free_dev (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number; +s16 dev_handle; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_dev *mdev =NULL ; +struct mausb_usb_device_ctx *usb_device_ctx; +struct mausb_endpoint_ctx *ep_ctx = dev->ep0.hcpriv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (mausb_host_dev.this_device,"port_number out of range, port_number=%x" , + port_number); +return ; + } + + mdev = &hub->ma_devs[port_number]; + + usb_device_ctx =mausb_find_usb_device (mdev, dev); +if (!usb_device_ctx) { +dev_warn (mausb_host_dev.this_device,"device_ctx is not found" ); +return ; + } + + dev_handle = usb_device_ctx->dev_handle; + +if (ep_ctx) { + dev->ep0.hcpriv =NULL ; +kfree (ep_ctx); + }else { +dev_warn (mausb_host_dev.this_device,"ep_ctx is NULL: dev_handle=%#x" , + dev_handle); + } + +rb_erase (&usb_device_ctx->rb_node, &mdev->usb_devices); +dev_info (mausb_host_dev.this_device,"USB device deleted device=%p" , + usb_device_ctx->dev_addr); +kfree (usb_device_ctx); +} + +static int mausb_address_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; +struct mausb_endpoint_ctx *endpoint_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_warn (&dev->dev,"port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) +return -ENODEV ; + +dev_info (&dev->dev,"dev_handle=%#x, dev_speed=%#x" , + usb_device_ctx->dev_handle, dev->speed); + +if (dev->speed >=USB_SPEED_SUPER ) +dev_info (&dev->dev,"USB 3.0" ); +else +dev_info (&dev->dev,"USB 2.0" ); + +if (usb_device_ctx->dev_handle ==DEV_HANDLE_NOT_ASSIGNED ) { + status =mausb_enable_device (hcd, dev); +if (status <0 ) +return status; + } + + endpoint_ctx = dev->ep0.hcpriv; +if (!endpoint_ctx) { +dev_err (&dev->dev,"endpoint_ctx is NULL: dev_handle=%#x" , + usb_device_ctx->dev_handle); +return -EINVAL ; + } + +return 0 ; +} + +static int mausb_add_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint) +{ +int status; +u8 port_number; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_dev_ctx; +struct mausb_endpoint_ctx *endpoint_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (&dev->dev,"port_number out of range, port_number=%x" , + port_number); +return 0 ; + } + + usb_dev_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_dev_ctx) { +dev_warn (&dev->dev,"Device not found" ); +return -ENODEV ; + } + + endpoint_ctx =kzalloc (sizeof (*endpoint_ctx),GFP_ATOMIC ); +if (!endpoint_ctx) +return -ENOMEM ; + + endpoint_ctx->dev_handle = usb_dev_ctx->dev_handle; + endpoint_ctx->usb_device_ctx = usb_dev_ctx; + endpoint->hcpriv = endpoint_ctx; + +return 0 ; +} + +static int mausb_drop_endpoint (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_host_endpoint *endpoint) +{ +u8 port_number; +int status; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_dev_ctx; +struct mausb_endpoint_ctx *endpoint_ctx = endpoint->hcpriv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (&dev->dev,"port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_dev_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!endpoint_ctx) { +dev_err (&dev->dev,"Endpoint context doesn't exist" ); +return 0 ; + } +if (!usb_dev_ctx) { +dev_err (&dev->dev,"Usb device context doesn't exist" ); +return -ENODEV ; + } + + endpoint->hcpriv =NULL ; +kfree (endpoint_ctx); +return 0 ; +} + +static int mausb_enable_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +int status; +u8 port_number; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (mausb_host_dev.this_device,"port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) +return -ENODEV ; + +dev_info (mausb_host_dev.this_device,"Device assigned and addressed usb_device_ctx=%p" , + usb_device_ctx); + +return 0 ; +} + +static int mausb_is_hub_device (struct usb_device *dev) +{ +return dev->descriptor.bDeviceClass ==0x09 ; +} + +static int mausb_update_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +u8 port_number =0 ; +int status =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx =NULL ; + +if (mausb_is_hub_device (dev)) { +dev_warn (mausb_host_dev.this_device,"Device is hub" ); +return 0 ; + } + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (mausb_host_dev.this_device,"port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); +if (!usb_device_ctx) { +dev_warn (mausb_host_dev.this_device,"Device not found" ); +return -ENODEV ; + } + +return 0 ; +} + +static int mausb_hub_update_device (struct usb_hcd *hcd,struct usb_device *dev, +struct usb_tt *tt,gfp_t mem_flags) +{ +int status; +u8 port_number; +u16 max_exit_latency =0 ; +u8 mtt =0 ; +u8 ttt =0 ; +struct hub_ctx *hub = (struct hub_ctx *)hcd->hcd_priv; +struct mausb_usb_device_ctx *usb_device_ctx; + +if (dev->speed ==USB_SPEED_HIGH ) { + mtt = tt->multi ==0 ?1 :0 ; + ttt = (u8 )tt->think_time; + } + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (mausb_host_dev.this_device,"port_number out of range, port_number=%x" , + port_number); +return 0 ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], + dev); + +if (!usb_device_ctx) { +dev_err (mausb_host_dev.this_device,"USB device not found" ); +return -ENODEV ; + } + +if (dev->usb3_lpm_u1_enabled) + max_exit_latency = (u16 )dev->u1_params.mel; +else if (dev->usb3_lpm_u2_enabled) + max_exit_latency = (u16 )dev->u2_params.mel; + +return 0 ; +} + +static void mausb_endpoint_reset (struct usb_hcd *hcd, +struct usb_host_endpoint *endpoint) +{ +int status; +int is_control; +int epnum; +int is_out; +u16 dev_handle; +u8 tsp; +u8 port_number; +struct hub_ctx *hub; +struct mausb_usb_device_ctx *usb_device_ctx; +struct usb_device *dev; +struct mausb_endpoint_ctx *ep_ctx; + + ep_ctx = endpoint->hcpriv; +if (!ep_ctx) +return ; + + usb_device_ctx = ep_ctx->usb_device_ctx; + dev_handle = usb_device_ctx->dev_handle; + dev = usb_device_ctx->dev_addr; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (&dev->dev,"port_number out of range, port_number=%x" , + port_number); +return ; + } + hub = (struct hub_ctx *)hcd->hcd_priv; + + is_control =usb_endpoint_xfer_control (&endpoint->desc); + epnum =usb_endpoint_num (&endpoint->desc); + is_out =usb_endpoint_dir_out (&endpoint->desc); + tsp = (u8)(is_out ? dev->toggle[1 ] : dev->toggle[0 ]); + +if (status <0 ) +return ; + +if (status !=EUCLEAN ) { +if (!tsp) { +usb_settoggle (dev, epnum, is_out,0U ); +if (is_control) +usb_settoggle (dev, epnum, !is_out,0U ); + } + +return ; + } + +if (tsp) +return ; + +dev_info (&dev->dev,"ep_handle request status=%d, ep_handle=%#x, dev_handle=%#x" , + status, ep_ctx->ep_handle, dev_handle); +} + +static int mausb_reset_device (struct usb_hcd *hcd,struct usb_device *dev) +{ +int status; +u8 port_number; +u16 dev_handle; +struct hub_ctx *hub; +struct mausb_usb_device_ctx *usb_device_ctx; + + hub = (struct hub_ctx *)hcd->hcd_priv; + + status =get_root_hub_port_number (dev, &port_number); +if (status <0 || port_number >=NUMBER_OF_PORTS ) { +dev_dbg (mausb_host_dev.this_device,"port_number out of range, port_number=%x" , + port_number); +return -EINVAL ; + } + + usb_device_ctx =mausb_find_usb_device (&hub->ma_devs[port_number], dev); + +if (!usb_device_ctx || + usb_device_ctx->dev_handle ==DEV_HANDLE_NOT_ASSIGNED ) +return 0 ; + + dev_handle = usb_device_ctx->dev_handle; + +return 0 ; +} + +void mausb_clear_hcd_madev (u16 port_number) +{ +unsigned long flags =0 ; + +if (port_number >=NUMBER_OF_PORTS ) { +dev_err (mausb_host_dev.this_device,"port_number out of range, port_number=%x" , + port_number); +return ; + } + +spin_lock_irqsave (&mhcd->lock, flags); + +memset (&mhcd->hcd_hs_ctx->ma_devs[port_number],0 , +sizeof (struct mausb_dev )); +memset (&mhcd->hcd_ss_ctx->ma_devs[port_number],0 , +sizeof (struct mausb_dev )); + + mhcd->connected_ports &= ~(1 << port_number); + + mhcd->hcd_hs_ctx->ma_devs[port_number].port_status = +USB_PORT_STAT_POWER ; + mhcd->hcd_ss_ctx->ma_devs[port_number].port_status = +USB_SS_PORT_STAT_POWER ; + +spin_unlock_irqrestore (&mhcd->lock, flags); +}
drivers/usb/host/mausb/hcd.h +83 -3
96 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v6 5/8 usb: mausb_host: Introduce PAL processing
In reply to Vladimir StankovicProtocol adaptation layer (PAL) implementation has been added to introduce MA-USB structures and logic.
--- drivers/usb/host/mausb/Makefile | 1 + drivers/usb/host/mausb/hcd.c | 516 ++++++++++- drivers/usb/host/mausb/hcd.h | 13 +- drivers/usb/host/mausb/hpal.c | 1092 ++++++++++++++++++++++++ drivers/usb/host/mausb/hpal.h | 289 +++++++ drivers/usb/host/mausb/ma_usb.h | 869 +++++++++++++++++++ drivers/usb/host/mausb/mausb_address.h | 26 + drivers/usb/host/mausb/mausb_core.c | 11 + drivers/usb/host/mausb/mausb_event.h | 224 +++++ 9 files changed, 3032 insertions(+), 9 deletions(-) create mode 100644 drivers/usb/host/mausb/hpal.c create mode 100644 drivers/usb/host/mausb/hpal.h create mode 100644 drivers/usb/host/mausb/ma_usb.h create mode 100644 drivers/usb/host/mausb/mausb_address.h create mode 100644 drivers/usb/host/mausb/mausb_event.h
drivers/usb/host/mausb/Makefile +1 -0
@@ -10,3 +10,4 @@ mausb_host-y := mausb_core.o mausb_host-y += utils.o mausb_host-y += ip_link.o mausb_host-y += hcd.o +mausb_host-y += hpal.o
drivers/usb/host/mausb/hcd.c +509 -7
724 lines not on this page · raw message
drivers/usb/host/mausb/hcd.h +11 -2
@@ -9,13 +9,13 @@#include <linux/usb.h> #include <linux/usb/hcd.h> +#include "hpal.h" +#define DEVICE_NAME "mausb_host_hcd"#define CLASS_NAME "mausb"#define NUMBER_OF_PORTS 15 -#define MAX_USB_DEVICE_DEPTH 6 -#define RESPONSE_TIMEOUT 5000enum mausb_device_type {
@@ -59,6 +59,13 @@ struct hub_ctx {int mausb_init_hcd (void );void mausb_deinit_hcd (void ); +void mausb_port_has_changed (const enum mausb_device_type device_type, +const enum mausb_device_speed device_speed, +void *ma_dev); +void mausb_hcd_disconnect (const u16 port_number, +const enum mausb_device_type device_type, +const enum mausb_device_speed device_speed); +#define PORT_C_MASK \ ((USB_PORT_STAT_C_CONNECTION \ | USB_PORT_STAT_C_ENABLE \
@@ -134,11 +141,13 @@ struct mausb_endpoint_ctx {struct mausb_urb_ctx {struct urb *urb; +struct mausb_data_iter iterator;struct rb_node rb_node;struct work_struct work; };int mausb_probe (struct device *dev); +void mausb_hcd_urb_complete (struct urb *urb,u32 actual_length,int status);void mausb_clear_hcd_madev (u16 port_number);
drivers/usb/host/mausb/hpal.c new file +1092 -0
1,092 lines not on this page · raw message
drivers/usb/host/mausb/hpal.h new file +289 -0
289 lines not on this page · raw message
drivers/usb/host/mausb/ma_usb.h new file +869 -0
850 lines not on this page · raw message
drivers/usb/host/mausb/mausb_address.h new file +26 -0
Lines of this file are not shown. View the raw message.
drivers/usb/host/mausb/mausb_event.h new file +224 -0
224 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH v6 6/8 usb: mausb_host: Add logic for PAL-to-PAL communication
In reply to Vladimir StankovicImplemeneted connection between PAL and Link layers and set up environment for exchanging PAL-to-PAL messages.
Within this patch, driver's sysfs parameters have been created with intention to configure remote connection parameters.
--- drivers/usb/host/mausb/hpal.c | 529 ++++++++++++++++++++++++++++ drivers/usb/host/mausb/hpal.h | 6 + drivers/usb/host/mausb/mausb_core.c | 140 ++++++++ 3 files changed, 675 insertions(+)
drivers/usb/host/mausb/hpal.c +529 -0
@@ -9,10 +9,15 @@#include "hcd.h" #include "utils.h" +#define MAUSB_DELETE_MADEV_TIMEOUT_MS 3000 +struct mss mss; +static int mausb_start_connection_timer (struct mausb_device *dev);static int mausb_power_state_cb (struct notifier_block *nb,unsigned long action,void *data); +static void mausb_signal_empty_mss (void ); +static void mausb_remove_madev_from_list (u8 madev_addr);static void mausb_execute_urb_dequeue (struct work_struct *dequeue_work);static int mausb_start_heartbeat_timer (void );
@@ -173,6 +178,56 @@ static bool mausb_return_urb_ctx_to_tree(struct mausb_urb_ctx *urb_ctx,return true; } +static void mausb_complete_urbs_from_tree (void ) +{ +struct mausb_urb_ctx *urb_ctx =NULL ; +struct urb *current_urb =NULL ; +struct rb_node *current_node =NULL ; +unsigned long flags; +int status =0 ; +int ret; + +dev_dbg (mausb_host_dev.this_device,"Completing all urbs from tree" ); + +spin_lock_irqsave (&mhcd->lock, flags); + +while ((current_node =rb_first (&mhcd->mausb_urbs))) { + urb_ctx = rb_entry(current_node, struct mausb_urb_ctx, rb_node); + + current_urb = urb_ctx->urb; +mausb_delete_urb_ctx_from_tree (urb_ctx); +mausb_uninit_data_iterator (&urb_ctx->iterator); +kfree (urb_ctx); + + ret =usb_hcd_check_unlink_urb (current_urb->hcpriv, + current_urb, status); +if (ret == -EIDRM ) +dev_warn (mausb_host_dev.this_device,"Urb=%p is already unlinked" , + current_urb); +else +usb_hcd_unlink_urb_from_ep (current_urb->hcpriv, + current_urb); + +spin_unlock_irqrestore (&mhcd->lock, flags); + +/* Prepare urb for completion */ +dev_dbg (mausb_host_dev.this_device,"Completing urb=%p" , + current_urb); + + current_urb->status = -EPROTO ; + current_urb->actual_length =0 ; +atomic_dec (¤t_urb->use_count); +usb_hcd_giveback_urb (current_urb->hcpriv, current_urb, + current_urb->status); + +spin_lock_irqsave (&mhcd->lock, flags); + } + +spin_unlock_irqrestore (&mhcd->lock, flags); + +dev_dbg (mausb_host_dev.this_device,"Completed all urbs from tree" ); +} +/*After this function call only valid thing to do with urb is to give it back*/ struct mausb_urb_ctx *mausb_unlink_and_delete_urb_from_tree (struct urb *urb,int status)
@@ -280,6 +335,164 @@ static inline void mausb_port_has_changed_event(struct mausb_device *dev,mausb_port_has_changed (USB20HUB ,HIGH_SPEED , dev); } +static void mausb_socket_disconnect_event (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + socket_disconnect_work); +struct mausb_event event; + +dev_info (mausb_host_dev.this_device,"Disconnect madev_addr=%d" , + dev->madev_addr); + +mausb_ip_disconnect (dev->ctrl_channel); +mausb_destroy_ip_ctx (dev->ctrl_channel); + dev->ctrl_channel =NULL ; + +mausb_ip_disconnect (dev->bulk_channel); +mausb_destroy_ip_ctx (dev->bulk_channel); + dev->bulk_channel =NULL ; + +mausb_ip_disconnect (dev->isoch_channel); +mausb_destroy_ip_ctx (dev->isoch_channel); + dev->isoch_channel =NULL ; + +if (dev->mgmt_channel) { +memset (&event,0 ,sizeof (event)); + event.type =MAUSB_EVENT_TYPE_NETWORK_DISCONNECTED ; + event.data.device_id = dev->id; + +dev_info (mausb_host_dev.this_device,"Releasing MAUSB device ref" ); +kref_put (&dev->refcount, mausb_release_ma_dev_async); + } + +mausb_ip_disconnect (dev->mgmt_channel); +mausb_destroy_ip_ctx (dev->mgmt_channel); + dev->mgmt_channel =NULL ; + +memset (dev->channel_map,0 ,sizeof (dev->channel_map)); +} + +static void mausb_disconnect_ma_dev (struct mausb_device *dev) +{ +dev_info (mausb_host_dev.this_device,"Disconnecting MAUSB device madev_addr=%d" , + dev->madev_addr); + +if (!dev->dev_connected) { +dev_warn (mausb_host_dev.this_device,"MAUSB device is not connected" ); +kref_put (&dev->refcount, mausb_release_ma_dev_async); +return ; + } +mausb_hcd_disconnect (dev->port_number, dev->dev_type, dev->dev_speed); + +if (dev->dev_type ==USB30HUB ) +mausb_hcd_disconnect (dev->port_number,USB20HUB ,HIGH_SPEED ); +} + +static void mausb_hcd_disconnect_event (struct work_struct *work) +{ + struct mausb_device *ma_dev = container_of(work, struct mausb_device, + hcd_disconnect_work); + +mausb_disconnect_ma_dev (ma_dev); +} + +static void mausb_delete_madev (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + madev_delete_work); +struct mausb_event event; +struct completion completion; +struct completion *user_event; +struct mausb_completion mausb_completion; +long status; +unsigned long timeout =msecs_to_jiffies (MAUSB_DELETE_MADEV_TIMEOUT_MS ); + +dev_info (mausb_host_dev.this_device,"Deleting MAUSB device madev_addr=%d" , + dev->madev_addr); + +del_timer_sync (&dev->connection_timer); + +/* Client IS responsive */ +if (!atomic_read (&dev->unresponsive_client)) { +memset (&event,0 ,sizeof (event)); + event.type =MAUSB_EVENT_TYPE_DELETE_MA_DEV ; + event.mgmt.delete_ma_dev.device_id = dev->id; + event.mgmt.delete_ma_dev.event_id =mausb_event_id (dev); + +init_completion (&completion); + mausb_completion.completion_event = &completion; + mausb_completion.event_id = event.mgmt.delete_ma_dev.event_id; + mausb_completion.mausb_event = &event; + +mausb_insert_event (dev, &mausb_completion); + +dev_dbg (mausb_host_dev.this_device,"Deleting MAUSB device..." ); + + status =wait_for_completion_interruptible_timeout (&completion, + timeout); + +dev_dbg (mausb_host_dev.this_device,"Deleting MAUSB device event finished with %ld" , + status); + +mausb_remove_event (dev, &mausb_completion); + + user_event = &dev->user_finished_event; + + status =wait_for_completion_interruptible_timeout (user_event, + timeout); +dev_info (mausb_host_dev.this_device,"User event finished with %ld" , + status); + } + +flush_workqueue (dev->workq); +destroy_workqueue (dev->workq); + +mausb_clear_hcd_madev (dev->port_number); + +mausb_remove_madev_from_list (dev->madev_addr); + +put_net (dev->net_ns); + +kfree (dev); +mausb_signal_empty_mss (); + +dev_dbg (mausb_host_dev.this_device,"MAUSB device deleted." ); +} + +static void mausb_ping_work (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + ping_work); + +if (mausb_start_connection_timer (dev) <0 ) { +dev_err (mausb_host_dev.this_device,"Session timeout - disconnnecting device madev_addr=%d" , + dev->madev_addr); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +return ; + } +} + +static void mausb_heartbeat_work (struct work_struct *work) +{ + struct mausb_device *dev = container_of(work, struct mausb_device, + heartbeat_work); + +dev_err (mausb_host_dev.this_device,"App is unresponsive - disconnect device" ); +atomic_set (&dev->unresponsive_client,1 ); +mausb_complete_urbs_from_tree (); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +} + +static void mausb_connection_timer_func (struct timer_list *timer) +{ + struct mausb_device *dev = container_of(timer, struct mausb_device, + connection_timer); + +queue_work (dev->workq, &dev->ping_work); +} +static void mausb_heartbeat_timer_func (struct timer_list *timer) {unsigned long flags =0 ;
@@ -304,6 +517,99 @@ static void mausb_heartbeat_timer_func(struct timer_list *timer) } } +static struct mausb_device * +mausb_create_madev (struct mausb_device_address dev_addr,u8 madev_address, +int *status) +{ +struct mausb_device *dev; +unsigned long flags =0 ; +char workq_name[16 ]; +struct workqueue_struct *workq; + +memset (workq_name,0 ,sizeof (workq_name)); +sprintf (workq_name,"%x" , madev_address); +strcat (workq_name,"_madev_workq" ); + +dev_vdbg (mausb_host_dev.this_device,"madev_workq_name = %s" , + workq_name); + + workq =alloc_ordered_workqueue (workq_name,WQ_MEM_RECLAIM ); +if (!workq) { + *status = -ENOMEM ; +return NULL ; + } + +spin_lock_irqsave (&mss.lock, flags); + +if (mss.deinit_in_progress) { +spin_unlock_irqrestore (&mss.lock, flags); +dev_alert (mausb_host_dev.this_device,"Device creating failed - mss deinit in progress" ); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -ESHUTDOWN ; +return NULL ; + } + + dev =mausb_get_dev_from_addr_unsafe (madev_address); +if (dev) { +spin_unlock_irqrestore (&mss.lock, flags); +dev_warn (mausb_host_dev.this_device,"MAUSB device already connected, madev_address=%x" , + madev_address); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -EEXIST ; +return NULL ; + } + + dev =kzalloc (sizeof (*dev),GFP_ATOMIC ); + +if (!dev) { +spin_unlock_irqrestore (&mss.lock, flags); +dev_alert (mausb_host_dev.this_device,"Could not allocate MAUSB device!" ); +flush_workqueue (workq); +destroy_workqueue (workq); + *status = -ENOMEM ; +return NULL ; + } + +dev_dbg (mausb_host_dev.this_device,"Create MAUSB device." ); + + dev->workq = workq; + +INIT_WORK (&dev->socket_disconnect_work, mausb_socket_disconnect_event); +INIT_WORK (&dev->hcd_disconnect_work, mausb_hcd_disconnect_event); +INIT_WORK (&dev->madev_delete_work, mausb_delete_madev); +INIT_WORK (&dev->ping_work, mausb_ping_work); +INIT_WORK (&dev->heartbeat_work, mausb_heartbeat_work); + +kref_init (&dev->refcount); + + dev->event_id =0 ; +spin_lock_init (&dev->event_id_lock); + +INIT_LIST_HEAD (&dev->completion_events); +spin_lock_init (&dev->completion_events_lock); +spin_lock_init (&dev->num_of_user_events_lock); +spin_lock_init (&dev->connection_timer_lock); + +init_completion (&dev->user_finished_event); +atomic_set (&dev->unresponsive_client,0 ); + +timer_setup (&dev->connection_timer, mausb_connection_timer_func,0 ); + + dev->dev_addr = dev_addr; + dev->madev_addr = madev_address; + dev->net_ns =get_net (current->nsproxy->net_ns); + +list_add_tail (&dev->list_entry, &mss.madev_list); + +reinit_completion (&mss.empty); + +spin_unlock_irqrestore (&mss.lock, flags); + +return dev; +} +void mausb_release_ma_dev_async (struct kref *kref) { struct mausb_device *dev = container_of(kref, struct mausb_device,
@@ -314,6 +620,46 @@ void mausb_release_ma_dev_async(struct kref *kref)schedule_work (&dev->madev_delete_work); } +int mausb_initiate_dev_connection (struct mausb_device_address dev_addr, +u8 madev_address) +{ +int error =0 ; +struct mausb_device *dev; +unsigned long flags =0 ; + +spin_lock_irqsave (&mss.lock, flags); + dev =mausb_get_dev_from_addr_unsafe (madev_address); +spin_unlock_irqrestore (&mss.lock, flags); + +if (dev) { +dev_warn (mausb_host_dev.this_device,"MAUSB device already connected, madev_address=%x" , + madev_address); +return -EEXIST ; + } + + dev =mausb_create_madev (dev_addr, madev_address, &error); +if (!dev) +return error; + +dev_info (mausb_host_dev.this_device,"New MAUSB device created madev_addr=%d" , + madev_address); + + error =mausb_init_ip_ctx (&dev->mgmt_channel, dev->net_ns, + dev->dev_addr.ip.address, + dev->dev_addr.ip.port.management, dev, + mausb_ip_callback,MAUSB_MGMT_CHANNEL ); +if (error) { +dev_err (mausb_host_dev.this_device,"Mgmt ip context init failed: error=%d" , + error); +kref_put (&dev->refcount, mausb_release_ma_dev_async); +return error; + } + +mausb_ip_connect_async (dev->mgmt_channel); + +return 0 ; +} +int mausb_enqueue_event_from_user (u8 madev_addr,u16 num_of_events,u16 num_of_completed) {
@@ -414,6 +760,26 @@ int mausb_signal_event(struct mausb_device *dev,return -ETIMEDOUT ; } +static int mausb_start_connection_timer (struct mausb_device *dev) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&dev->connection_timer_lock, flags); + +if (++dev->receive_failures_num >MAUSB_MAX_RECEIVE_FAILURES ) { +dev_err (mausb_host_dev.this_device,"Missed more than %d ping responses" , +MAUSB_MAX_RECEIVE_FAILURES ); +spin_unlock_irqrestore (&dev->connection_timer_lock, flags); +return -ETIMEDOUT ; + } + +mod_timer (&dev->connection_timer, jiffies +msecs_to_jiffies (1000 )); + +spin_unlock_irqrestore (&dev->connection_timer_lock, flags); + +return 0 ; +} +void mausb_reset_connection_timer (struct mausb_device *dev) {unsigned long flags =0 ;
@@ -658,6 +1024,36 @@ struct mausb_device *mausb_get_dev_from_addr_unsafe(u8 madev_addr)return NULL ; } +static void mausb_remove_madev_from_list (u8 madev_addr) +{ +unsigned long flags =0 ; +struct mausb_device *ma_dev, *tmp =NULL ; + +spin_lock_irqsave (&mss.lock, flags); + +list_for_each_entry_safe (ma_dev, tmp, &mss.madev_list, list_entry) { +if (ma_dev->madev_addr == madev_addr) { +list_del (&ma_dev->list_entry); +break ; + } + } + +if (list_empty (&mss.madev_list)) +reinit_completion (&mss.rings_events.mausb_ring_has_events); + +spin_unlock_irqrestore (&mss.lock, flags); +} + +static void mausb_signal_empty_mss (void ) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&mss.lock, flags); +if (list_empty (&mss.madev_list)) +complete (&mss.empty); +spin_unlock_irqrestore (&mss.lock, flags); +} +static inline struct mausb_ip_ctx *mausb_get_data_channel (struct mausb_device *ma_dev,enum mausb_channel channel)
@@ -812,6 +1208,139 @@ void mausb_cleanup_chunks_list(struct list_head *chunks_list) } } +static void mausb_init_ip_ctx_helper (struct mausb_device *dev, +struct mausb_ip_ctx **ip_ctx, +u16 port, +enum mausb_channel channel) +{ +int status =mausb_init_ip_ctx (ip_ctx, dev->net_ns, + dev->dev_addr.ip.address, port, dev, + mausb_ip_callback, channel); +if (status <0 ) { +dev_err (mausb_host_dev.this_device,"Init ip context failed with error=%d" , + status); +queue_work (dev->workq, &dev->socket_disconnect_work); +return ; + } + + dev->channel_map[channel] = *ip_ctx; +mausb_ip_connect_async (*ip_ctx); +} + +static void mausb_connect_callback (struct mausb_device *dev, +enum mausb_channel channel,int status) +{ +struct mausb_device_address *dev_addr = &dev->dev_addr; + +dev_info (mausb_host_dev.this_device,"Connect callback for channel=%d with status=%d" , + channel, status); + +if (status <0 ) { +queue_work (dev->workq, &dev->socket_disconnect_work); +return ; + } + +if (channel ==MAUSB_MGMT_CHANNEL ) { +if (dev_addr->ip.port.control ==0 ) { + dev->channel_map[MAUSB_CTRL_CHANNEL ] = + dev->mgmt_channel; + channel =MAUSB_CTRL_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->ctrl_channel, + dev_addr->ip.port.control, +MAUSB_CTRL_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_CTRL_CHANNEL ) { +if (dev_addr->ip.port.bulk ==0 ) { + dev->channel_map[MAUSB_BULK_CHANNEL ] = + dev->channel_map[MAUSB_CTRL_CHANNEL ]; + channel =MAUSB_BULK_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->bulk_channel, + dev_addr->ip.port.bulk, +MAUSB_BULK_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_BULK_CHANNEL ) { +if (dev_addr->ip.port.isochronous ==0 ) { +/* if there is no isoch port use tcp for it */ + dev->channel_map[MAUSB_ISOCH_CHANNEL ] = + dev->channel_map[MAUSB_BULK_CHANNEL ]; + channel =MAUSB_ISOCH_CHANNEL ; + }else { +mausb_init_ip_ctx_helper (dev, &dev->isoch_channel, + dev_addr->ip.port.isochronous, +MAUSB_ISOCH_CHANNEL ); +return ; + } + } + +if (channel ==MAUSB_ISOCH_CHANNEL ) { + dev->channel_map[MAUSB_INTR_CHANNEL ] = + dev->channel_map[MAUSB_CTRL_CHANNEL ]; + } +} + +static void mausb_handle_connect_event (struct mausb_device *dev, +enum mausb_channel channel,int status, +void *data) +{ +mausb_connect_callback (dev, channel, status); +} + +static void mausb_handle_receive_event (struct mausb_device *dev, +enum mausb_channel channel,int status, +void *data) +{ +struct mausb_event event; + + event.madev_addr = dev->madev_addr; + +if (status <=0 ) { +dev_err (mausb_host_dev.this_device,"Receive event error status=%d" , + status); +queue_work (dev->workq, &dev->socket_disconnect_work); +queue_work (dev->workq, &dev->hcd_disconnect_work); +return ; + } + +mausb_reset_connection_timer (dev); +} + +void mausb_ip_callback (void *ctx,enum mausb_channel channel, +enum mausb_link_action action,int status,void *data) +{ +struct mausb_device *dev = (struct mausb_device *)ctx; + +switch (action) { +case MAUSB_LINK_CONNECT : +mausb_handle_connect_event (dev, channel, status, data); +break ; +case MAUSB_LINK_SEND : +/* +* Currently there is nothing to do, as send operation is +* synchronous +*/ +break ; +case MAUSB_LINK_RECV : +mausb_handle_receive_event (dev, channel, status, data); +break ; +case MAUSB_LINK_DISCONNECT : +/* +* Currently there is nothing to do, as disconnect operation is +* synchronous +*/ +break ; +default : +dev_warn (mausb_host_dev.this_device,"Unknown network action" ); + } +} + static int mausb_read_virtual_buffer(struct mausb_data_iter *iterator, u32 byte_num, struct list_head *data_chunks_list,
drivers/usb/host/mausb/hpal.h +6 -0
@@ -131,6 +131,8 @@ static inline u64 mausb_event_id(struct mausb_device *dev)return val; } +int mausb_initiate_dev_connection (struct mausb_device_address device_address, +u8 madev_address);int mausb_data_req_enqueue_event (struct mausb_device *dev,u16 ep_handle,struct urb *request); int mausb_signal_event(struct mausb_device *dev, struct mausb_event *event,
@@ -158,6 +160,7 @@ static inline void mausb_remove_event(struct mausb_device *dev, }void mausb_release_ma_dev_async (struct kref *kref); +void mausb_on_madev_connected (struct mausb_device *dev);void mausb_complete_request (struct urb *urb,u32 actual_length,int status);void mausb_complete_urb (struct mausb_event *event);void mausb_reset_connection_timer (struct mausb_device *dev);
@@ -240,6 +243,9 @@ enum mausb_channel mausb_transfer_type_to_channel(u8 transfer_type)return transfer_type >>3 ; } +void mausb_ip_callback (void *ctx,enum mausb_channel channel, +enum mausb_link_action action,int status,void *data); +struct mausb_data_iter {u32 length;
drivers/usb/host/mausb/mausb_core.c +140 -0
146 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v6 7/8 usb: mausb_host: MA-USB PAL events processing
In reply to Vladimir StankovicImplemented MA-USB management messages processing and communication with user-space driver via mapped memory.
MA USB PAL events are being enqueued into ring buffer from which data is being send/received to/from user-space.
--- drivers/usb/host/mausb/Makefile | 1 + drivers/usb/host/mausb/hcd.c | 245 +++++++- drivers/usb/host/mausb/hpal.c | 456 +++++++++++++- drivers/usb/host/mausb/hpal.h | 47 +- drivers/usb/host/mausb/hpal_events.c | 614 +++++++++++++++++++ drivers/usb/host/mausb/hpal_events.h | 85 +++ drivers/usb/host/mausb/mausb_driver_status.h | 17 + drivers/usb/host/mausb/utils.c | 270 ++++++++ drivers/usb/host/mausb/utils.h | 7 +- 9 files changed, 1726 insertions(+), 16 deletions(-) create mode 100644 drivers/usb/host/mausb/hpal_events.c create mode 100644 drivers/usb/host/mausb/hpal_events.h create mode 100644 drivers/usb/host/mausb/mausb_driver_status.h
drivers/usb/host/mausb/Makefile +1 -0
@@ -11,3 +11,4 @@ mausb_host-y += utils.o mausb_host-y += ip_link.o mausb_host-y += hcd.o mausb_host-y += hpal.o +mausb_host-y += hpal_events.o
drivers/usb/host/mausb/hcd.c +239 -6
381 lines not on this page · raw message
drivers/usb/host/mausb/hpal.c +450 -6
609 lines not on this page · raw message
drivers/usb/host/mausb/hpal.h +46 -1
81 lines not on this page · raw message
drivers/usb/host/mausb/hpal_events.c new file +614 -0
614 lines not on this page · raw message
drivers/usb/host/mausb/hpal_events.h new file +85 -0
85 lines not on this page · raw message
drivers/usb/host/mausb/mausb_driver_status.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_MAUSB_DRIVER_STATUS_H__ +#define __MAUSB_MAUSB_DRIVER_STATUS_H__ + +#define MAUSB_DRIVER_BAD_READ_BUFFER_SIZE -1 +#define MAUSB_DRIVER_RING_EVENTS_STOPPED -2 +#define MAUSB_DRIVER_SYSTEM_SUSPENDED -3 +#define MAUSB_DRIVER_COPY_TO_BUFFER_FAILED -4 + +#define MAUSB_DRIVER_READ_TIMEOUT 0 +#define MAUSB_DRIVER_READ_ERROR -1 +#define MAUSB_DRIVER_WRITE_ERROR -2 + +#endif /* __MAUSB_MAUSB_DRIVER_STATUS_H__ */
drivers/usb/host/mausb/utils.c +270 -0
295 lines not on this page · raw message
drivers/usb/host/mausb/utils.h +4 -3
@@ -5,11 +5,12 @@#ifndef __MAUSB_UTILS_H__#define __MAUSB_UTILS_H__ -#include <linux/miscdevice.h> - -extern struct miscdevice mausb_host_dev; +#include "hpal.h" int mausb_host_dev_register (void );void mausb_host_dev_deregister (void ); +void mausb_notify_completed_user_events (struct mausb_ring_buffer *ring_buffer); +void mausb_notify_ring_events (struct mausb_ring_buffer *ring_buffer); +void mausb_stop_ring_events (void );#endif /* __MAUSB_UTILS_H__ */
Signature · 1 line
2.17.1
PATCH v6 8/8 usb: mausb_host: Process MA-USB data packets
In reply to Vladimir StankovicAdded implementation of MA-USB data&isoch packets processing logic, both for IN and OUT directions.
--- drivers/usb/host/mausb/Makefile | 1 + drivers/usb/host/mausb/hpal.c | 35 +- drivers/usb/host/mausb/hpal_data.c | 713 +++++++++++++++++++++++++++++ drivers/usb/host/mausb/hpal_data.h | 34 ++ 4 files changed, 780 insertions(+), 3 deletions(-) create mode 100644 drivers/usb/host/mausb/hpal_data.c create mode 100644 drivers/usb/host/mausb/hpal_data.h
drivers/usb/host/mausb/Makefile +1 -0
@@ -12,3 +12,4 @@ mausb_host-y += ip_link.o mausb_host-y += hcd.o mausb_host-y += hpal.o mausb_host-y += hpal_events.o +mausb_host-y += hpal_data.o
drivers/usb/host/mausb/hpal.c +32 -3
@@ -7,7 +7,7 @@#include <linux/circ_buf.h> #include "hcd.h" -#include "hpal_events.h" +#include "hpal_data.h" #include "utils.h" #define MAUSB_DELETE_MADEV_TIMEOUT_MS 3000
@@ -1392,6 +1392,7 @@ int mausb_send_transfer_ack(struct mausb_device *dev, struct mausb_event *event)int mausb_send_data_msg (struct mausb_device *dev,struct mausb_event *event) {struct mausb_urb_ctx *urb_ctx; +int status =0 ;if (event->status !=0 ) { dev_err(mausb_host_dev.this_device, "Event %d failed with status %d",
@@ -1405,9 +1406,22 @@ int mausb_send_data_msg(struct mausb_device *dev, struct mausb_event *event)/* Transfer will be deleted from dequeue task */ dev_warn (mausb_host_dev.this_device,"Urb is already cancelled for event=%d" , event->type); +return status; } -return 0 ; +if (mausb_isoch_data_event (event)) { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) + status =mausb_send_isoch_in_msg (dev, event); +else + status =mausb_send_isoch_out_msg (dev, event, urb_ctx); + }else { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) + status =mausb_send_in_data_msg (dev, event); +else + status =mausb_send_out_data_msg (dev, event, urb_ctx); + } + +return status; }int mausb_receive_data_msg (struct mausb_device *dev,struct mausb_event *event)
@@ -1427,8 +1441,23 @@ int mausb_receive_data_msg(struct mausb_device *dev, struct mausb_event *event) } urb_ctx =mausb_find_urb_in_tree ((struct urb *)event->data.urb); -if (!urb_ctx) +if (!urb_ctx) { +/* Transfer will be deleted from dequeue task */ dev_warn (mausb_host_dev.this_device,"Urb is already cancelled" ); + goto cleanup; + } + +if (mausb_isoch_data_event (event)) { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) +mausb_receive_isoch_in_data (dev, event, urb_ctx); +else +mausb_receive_isoch_out (event); + }else { +if (event->data.direction ==MAUSB_DATA_MSG_DIRECTION_IN ) +mausb_receive_in_data (event, urb_ctx); +else +mausb_receive_out_data (event, urb_ctx); + } cleanup:mausb_release_event_resources (event);
drivers/usb/host/mausb/hpal_data.c new file +713 -0
713 lines not on this page · raw message
drivers/usb/host/mausb/hpal_data.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 - 2020 DisplayLink (UK) Ltd. +*/ +#ifndef __MAUSB_HPAL_DATA_H__ +#define __MAUSB_HPAL_DATA_H__ + +#include <linux/types.h> + +#include "hpal_events.h" + +int mausb_send_in_data_msg (struct mausb_device *dev,struct mausb_event *event); +void mausb_receive_in_data (struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +int mausb_send_out_data_msg (struct mausb_device *dev,struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); +void mausb_receive_out_data (struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +#define MAUSB_ISOCH_IN_KVEC_NUM 3 + +int mausb_send_isoch_in_msg (struct mausb_device *dev, +struct mausb_event *event); +void mausb_receive_isoch_in_data (struct mausb_device *dev, +struct mausb_event *event, +struct mausb_urb_ctx *urb_ctx); + +int mausb_send_isoch_out_msg (struct mausb_device *ma_dev, +struct mausb_event *mausb_event, +struct mausb_urb_ctx *urb_ctx); +void mausb_receive_isoch_out (struct mausb_event *event); + +#endif /* __MAUSB_HPAL_DATA_H__ */
Signature · 1 line
2.17.1
Greg KH
maintainerQuoted 8 lines · Vladimir Stankovic
Media Agnostic (MA) USB Host driver provides USB connectivity over an available network, allowing host device to access remote USB devices attached to one or more MA USB devices (accessible via network).
This driver has been developed to enable the host to communicate with DisplayLink products supporting MA USB protocol (MA USB device, in terms of MA USB Specification).
Quoted 5 lines
MA USB protocol used by MA USB Host driver has been implemented in accordance with MA USB Specification Release 1.0b.
This driver depends on the functions provided by DisplayLink's user-space driver.
Any pointer to the code for this? Without reviewing that, reviewing this code is going to be impossible, as I stated last time.
thanks,
greg k-h