From 61fd971eddecdc82586bbdcce26be01c984ae193 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Mon, 22 Jun 2020 10:48:10 +0200 Subject: staging: most: cdev: remove noisy log messages This patch removes unnecessary log messages to avoid noise in the kernel log. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592815695-19305-2-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/cdev/cdev.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c index cc1e3dea196d..093b44d095a9 100644 --- a/drivers/staging/most/cdev/cdev.c +++ b/drivers/staging/most/cdev/cdev.c @@ -129,19 +129,16 @@ static int comp_open(struct inode *inode, struct file *filp) ((filp->f_flags & O_ACCMODE) != O_RDONLY)) || ((c->cfg->direction == MOST_CH_TX) && ((filp->f_flags & O_ACCMODE) != O_WRONLY))) { - pr_info("WARN: Access flags mismatch\n"); return -EACCES; } mutex_lock(&c->io_mutex); if (!c->dev) { - pr_info("WARN: Device is destroyed\n"); mutex_unlock(&c->io_mutex); return -ENODEV; } if (c->access_ref) { - pr_info("WARN: Device is busy\n"); mutex_unlock(&c->io_mutex); return -EBUSY; } @@ -328,10 +325,8 @@ static int comp_disconnect_channel(struct most_interface *iface, int channel_id) { struct comp_channel *c; - if (!iface) { - pr_info("Bad interface pointer\n"); + if (!iface) return -EINVAL; - } c = get_channel(iface, channel_id); if (!c) @@ -397,10 +392,9 @@ static int comp_tx_completion(struct most_interface *iface, int channel_id) { struct comp_channel *c; - if (!iface) { - pr_info("Bad interface pointer\n"); + if (!iface) return -EINVAL; - } + if ((channel_id < 0) || (channel_id >= iface->num_channels)) { pr_info("Channel ID out of range\n"); return -EINVAL; @@ -432,10 +426,9 @@ static int comp_probe(struct most_interface *iface, int channel_id, int retval; int current_minor; - if ((!iface) || (!cfg) || (!name)) { - pr_info("Probing component with bad arguments"); + if ((!iface) || (!cfg) || (!name)) return -EINVAL; - } + c = get_channel(iface, channel_id); if (c) return -EEXIST; @@ -474,7 +467,6 @@ static int comp_probe(struct most_interface *iface, int channel_id, if (IS_ERR(c->dev)) { retval = PTR_ERR(c->dev); - pr_info("failed to create new device node %s\n", name); goto err_free_kfifo_and_del_list; } kobject_uevent(&c->dev->kobj, KOBJ_ADD); @@ -507,13 +499,9 @@ static int __init mod_init(void) { int err; - pr_info("init()\n"); - comp.class = class_create(THIS_MODULE, "most_cdev"); - if (IS_ERR(comp.class)) { - pr_info("No udev support.\n"); + if (IS_ERR(comp.class)) return PTR_ERR(comp.class); - } INIT_LIST_HEAD(&channel_list); spin_lock_init(&ch_list_lock); @@ -545,8 +533,6 @@ static void __exit mod_exit(void) { struct comp_channel *c, *tmp; - pr_info("exit module\n"); - most_deregister_configfs_subsys(&comp.cc); most_deregister_component(&comp.cc); -- cgit v1.2.3 From 08839388d31ba85d550f60e8e4bc3956b0586e86 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Mon, 22 Jun 2020 10:48:11 +0200 Subject: staging: most: cdev: use dev_*() functions to print messages This patch removes the pr_*() functions and uses dev_*() instead. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592815695-19305-3-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/cdev/cdev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c index 093b44d095a9..394c7621cb51 100644 --- a/drivers/staging/most/cdev/cdev.c +++ b/drivers/staging/most/cdev/cdev.c @@ -5,7 +5,6 @@ * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include #include #include @@ -375,7 +374,7 @@ static int comp_rx_completion(struct mbo *mbo) spin_unlock(&c->unlink); #ifdef DEBUG_MESG if (kfifo_is_full(&c->fifo)) - pr_info("WARN: Fifo is full\n"); + dev_warn(c->dev, "Fifo is full\n"); #endif wake_up_interruptible(&c->wq); return 0; @@ -395,14 +394,15 @@ static int comp_tx_completion(struct most_interface *iface, int channel_id) if (!iface) return -EINVAL; + c = get_channel(iface, channel_id); + if (!c) + return -ENXIO; + if ((channel_id < 0) || (channel_id >= iface->num_channels)) { - pr_info("Channel ID out of range\n"); + dev_warn(c->dev, "Channel ID out of range\n"); return -EINVAL; } - c = get_channel(iface, channel_id); - if (!c) - return -ENXIO; wake_up_interruptible(&c->wq); return 0; } -- cgit v1.2.3 From 7aed13d1653678137ef291ced45158eaa8c39e96 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Mon, 22 Jun 2020 10:48:12 +0200 Subject: staging: most: cdev: remove overcautious parameter checking The interface pointer passed to a component API function cannot be NULL. This patch removes unnecessary sanity checks of the pointer. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592815695-19305-4-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/cdev/cdev.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c index 394c7621cb51..9fc84fae21fd 100644 --- a/drivers/staging/most/cdev/cdev.c +++ b/drivers/staging/most/cdev/cdev.c @@ -324,9 +324,6 @@ static int comp_disconnect_channel(struct most_interface *iface, int channel_id) { struct comp_channel *c; - if (!iface) - return -EINVAL; - c = get_channel(iface, channel_id); if (!c) return -ENXIO; @@ -391,9 +388,6 @@ static int comp_tx_completion(struct most_interface *iface, int channel_id) { struct comp_channel *c; - if (!iface) - return -EINVAL; - c = get_channel(iface, channel_id); if (!c) return -ENXIO; @@ -426,7 +420,7 @@ static int comp_probe(struct most_interface *iface, int channel_id, int retval; int current_minor; - if ((!iface) || (!cfg) || (!name)) + if ((!cfg) || (!name)) return -EINVAL; c = get_channel(iface, channel_id); -- cgit v1.2.3 From e8e0f7fd7715de745ef522b5ed96e1f947e3fb91 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Mon, 22 Jun 2020 10:48:13 +0200 Subject: staging: most: cdev: fix up parenthesizing This patch removes unnecessary parnthesis. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592815695-19305-5-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/cdev/cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c index 9fc84fae21fd..d374cc05e447 100644 --- a/drivers/staging/most/cdev/cdev.c +++ b/drivers/staging/most/cdev/cdev.c @@ -420,7 +420,7 @@ static int comp_probe(struct most_interface *iface, int channel_id, int retval; int current_minor; - if ((!cfg) || (!name)) + if (!cfg || !name) return -EINVAL; c = get_channel(iface, channel_id); -- cgit v1.2.3 From 78aee6516670d1f8f4e74e5982ea8d557f114b2b Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Mon, 22 Jun 2020 10:48:14 +0200 Subject: staging: most: cdev: fix return values This patch makes use of the proper return values when reporting an error to the caller. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592815695-19305-6-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/cdev/cdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c index d374cc05e447..aa7d7afd7d83 100644 --- a/drivers/staging/most/cdev/cdev.c +++ b/drivers/staging/most/cdev/cdev.c @@ -326,7 +326,7 @@ static int comp_disconnect_channel(struct most_interface *iface, int channel_id) c = get_channel(iface, channel_id); if (!c) - return -ENXIO; + return -EINVAL; mutex_lock(&c->io_mutex); spin_lock(&c->unlink); @@ -360,7 +360,7 @@ static int comp_rx_completion(struct mbo *mbo) c = get_channel(mbo->ifp, mbo->hdm_channel_id); if (!c) - return -ENXIO; + return -EINVAL; spin_lock(&c->unlink); if (!c->access_ref || !c->dev) { @@ -390,7 +390,7 @@ static int comp_tx_completion(struct most_interface *iface, int channel_id) c = get_channel(iface, channel_id); if (!c) - return -ENXIO; + return -EINVAL; if ((channel_id < 0) || (channel_id >= iface->num_channels)) { dev_warn(c->dev, "Channel ID out of range\n"); -- cgit v1.2.3 From 0ae9e4f22d1c046e53ad2eb0a8a8c3d9e441fd3d Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Mon, 22 Jun 2020 10:48:15 +0200 Subject: staging: most: cdev: simplify list iteration This patch uses a less confusing list traversing structure to either return an item of the list that meets the prerequisites or NULL otherwise. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592815695-19305-7-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/cdev/cdev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c index aa7d7afd7d83..044880760b58 100644 --- a/drivers/staging/most/cdev/cdev.c +++ b/drivers/staging/most/cdev/cdev.c @@ -66,19 +66,16 @@ static struct comp_channel *get_channel(struct most_interface *iface, int id) { struct comp_channel *c, *tmp; unsigned long flags; - int found_channel = 0; spin_lock_irqsave(&ch_list_lock, flags); list_for_each_entry_safe(c, tmp, &channel_list, list) { if ((c->iface == iface) && (c->channel_id == id)) { - found_channel = 1; - break; + spin_unlock_irqrestore(&ch_list_lock, flags); + return c; } } spin_unlock_irqrestore(&ch_list_lock, flags); - if (!found_channel) - return NULL; - return c; + return NULL; } static void stop_channel(struct comp_channel *c) -- cgit v1.2.3 From c0b122a04e1274b6714a3a1176a89fb0c98b82e4 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Tue, 23 Jun 2020 17:07:31 +0200 Subject: staging: most: sound: remove noisy log messages This patch removes unnecessary log messages to avoid noise in the kernel log. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592924855-25569-2-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/sound/sound.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c index 1527f410af2b..e6396d11cbb0 100644 --- a/drivers/staging/most/sound/sound.c +++ b/drivers/staging/most/sound/sound.c @@ -360,10 +360,8 @@ static int pcm_prepare(struct snd_pcm_substream *substream) channel->copy_fn = most_to_alsa_copy32; } - if (!channel->copy_fn) { - pr_err("unsupported format\n"); + if (!channel->copy_fn) return -EINVAL; - } channel->period_pos = 0; channel->buffer_pos = 0; @@ -396,7 +394,6 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) return 0; default: - pr_info("%s(), invalid\n", __func__); return -EINVAL; } return 0; @@ -664,11 +661,8 @@ static int audio_disconnect_channel(struct most_interface *iface, struct sound_adapter *adpt = iface->priv; channel = get_channel(iface, channel_id); - if (!channel) { - pr_err("sound_disconnect_channel(), invalid channel %d\n", - channel_id); + if (!channel) return -EINVAL; - } list_del(&channel->list); @@ -692,11 +686,8 @@ static int audio_rx_completion(struct mbo *mbo) struct channel *channel = get_channel(mbo->ifp, mbo->hdm_channel_id); bool period_elapsed = false; - if (!channel) { - pr_err("sound_rx_completion(), invalid channel %d\n", - mbo->hdm_channel_id); + if (!channel) return -EINVAL; - } if (channel->is_stream_running) period_elapsed = copy_data(channel, mbo); @@ -724,14 +715,10 @@ static int audio_tx_completion(struct most_interface *iface, int channel_id) { struct channel *channel = get_channel(iface, channel_id); - if (!channel) { - pr_err("sound_tx_completion(), invalid channel %d\n", - channel_id); + if (!channel) return -EINVAL; - } wake_up_interruptible(&channel->playback_waitq); - return 0; } @@ -752,8 +739,6 @@ static int __init audio_init(void) { int ret; - pr_info("init()\n"); - INIT_LIST_HEAD(&adpt_list); ret = most_register_component(&comp); @@ -770,7 +755,6 @@ static int __init audio_init(void) static void __exit audio_exit(void) { - pr_info("exit()\n"); most_deregister_configfs_subsys(&comp); most_deregister_component(&comp); } -- cgit v1.2.3 From 36b67efe0cb3b33f6d58e1e86d5b2a02ff5ab387 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Tue, 23 Jun 2020 17:07:32 +0200 Subject: staging: most: sound: fix error path Return error and exit the function in case registering the component with the core is failing. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592924855-25569-3-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/sound/sound.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c index e6396d11cbb0..80a8feba1662 100644 --- a/drivers/staging/most/sound/sound.c +++ b/drivers/staging/most/sound/sound.c @@ -742,8 +742,10 @@ static int __init audio_init(void) INIT_LIST_HEAD(&adpt_list); ret = most_register_component(&comp); - if (ret) + if (ret) { pr_err("Failed to register %s\n", comp.name); + return ret; + } ret = most_register_configfs_subsys(&comp); if (ret) { pr_err("Failed to register %s configfs subsys\n", comp.name); -- cgit v1.2.3 From b1abd84d551b39c10ba86ffe8b27aaa659015e08 Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Tue, 23 Jun 2020 17:07:33 +0200 Subject: staging: most: sound: fix return values This patch returns the proper values when reporting an error to the caller. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592924855-25569-4-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/sound/sound.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c index 80a8feba1662..467faa1cb6b3 100644 --- a/drivers/staging/most/sound/sound.c +++ b/drivers/staging/most/sound/sound.c @@ -278,6 +278,7 @@ static int pcm_open(struct snd_pcm_substream *substream) struct channel *channel = substream->private_data; struct snd_pcm_runtime *runtime = substream->runtime; struct most_channel_config *cfg = channel->cfg; + int ret; channel->substream = substream; @@ -290,11 +291,12 @@ static int pcm_open(struct snd_pcm_substream *substream) } } - if (most_start_channel(channel->iface, channel->id, &comp)) { + ret = most_start_channel(channel->iface, channel->id, &comp); + if (ret) { pr_err("most_start_channel() failed!\n"); if (cfg->direction == MOST_CH_TX) kthread_stop(channel->playback_task); - return -EBUSY; + return ret; } runtime->hw = channel->pcm_hardware; @@ -444,7 +446,7 @@ static int split_arg_list(char *buf, u16 *ch_num, char **sample_res) err: pr_err("Bad PCM format\n"); - return -EIO; + return -EINVAL; } static const struct sample_resolution_info { @@ -469,7 +471,7 @@ static int audio_set_hw_params(struct snd_pcm_hardware *pcm_hw, goto found; } pr_err("Unsupported PCM format\n"); - return -EIO; + return -EINVAL; found: if (!ch_num) { @@ -580,7 +582,7 @@ skip_adpt_alloc: if (get_channel(iface, channel_id)) { pr_err("channel (%s:%d) is already linked\n", iface->description, channel_id); - return -EINVAL; + return -EEXIST; } if (cfg->direction == MOST_CH_TX) { -- cgit v1.2.3 From 749a14343ecbbe1c8c5d8000301553aa815cce7d Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Tue, 23 Jun 2020 17:07:34 +0200 Subject: staging: most: sound: fix white spaces This patch removes unnecessary empty lines. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592924855-25569-5-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/sound/sound.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c index 467faa1cb6b3..7c56cdb4d8ee 100644 --- a/drivers/staging/most/sound/sound.c +++ b/drivers/staging/most/sound/sound.c @@ -50,10 +50,8 @@ struct channel { unsigned int period_pos; unsigned int buffer_pos; bool is_stream_running; - struct task_struct *playback_task; wait_queue_head_t playback_waitq; - void (*copy_fn)(void *alsa, void *most, unsigned int bytes); }; @@ -176,7 +174,6 @@ static struct channel *get_channel(struct most_interface *iface, if ((channel->iface == iface) && (channel->id == channel_id)) return channel; } - return NULL; } @@ -220,7 +217,6 @@ static bool copy_data(struct channel *channel, struct mbo *mbo) channel->period_pos -= runtime->period_size; return true; } - return false; } @@ -260,7 +256,6 @@ static int playback_thread(void *data) if (period_elapsed) snd_pcm_period_elapsed(channel->substream); } - return 0; } @@ -320,7 +315,6 @@ static int pcm_close(struct snd_pcm_substream *substream) if (channel->cfg->direction == MOST_CH_TX) kthread_stop(channel->playback_task); most_stop_channel(channel->iface, channel->id, &comp); - return 0; } @@ -364,10 +358,8 @@ static int pcm_prepare(struct snd_pcm_substream *substream) if (!channel->copy_fn) return -EINVAL; - channel->period_pos = 0; channel->buffer_pos = 0; - return 0; } @@ -441,7 +433,6 @@ static int split_arg_list(char *buf, u16 *ch_num, char **sample_res) *sample_res = strsep(&buf, ".\n"); if (!*sample_res) goto err; - return 0; err: @@ -619,7 +610,6 @@ skip_adpt_alloc: strscpy(pcm->name, device_name, sizeof(pcm->name)); snd_pcm_set_ops(pcm, direction, &pcm_ops); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0); - return 0; err_free_adpt: @@ -690,15 +680,11 @@ static int audio_rx_completion(struct mbo *mbo) if (!channel) return -EINVAL; - if (channel->is_stream_running) period_elapsed = copy_data(channel, mbo); - most_put_mbo(mbo); - if (period_elapsed) snd_pcm_period_elapsed(channel->substream); - return 0; } @@ -753,7 +739,6 @@ static int __init audio_init(void) pr_err("Failed to register %s configfs subsys\n", comp.name); most_deregister_component(&comp); } - return ret; } -- cgit v1.2.3 From 75d0bf8762640728316c3bbce1aba87b1cc3428f Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Tue, 23 Jun 2020 17:07:35 +0200 Subject: staging: most: sound: remove overcautious argument checking The interface pointer passed to a component API function cannot be NULL. This patch removes the unnecessary sanity check of this argument. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1592924855-25569-6-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/sound/sound.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c index 7c56cdb4d8ee..8a449ab9bdce 100644 --- a/drivers/staging/most/sound/sound.c +++ b/drivers/staging/most/sound/sound.c @@ -531,9 +531,6 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id, char *sample_res; char arg_list_cpy[STRING_SIZE]; - if (!iface) - return -EINVAL; - if (cfg->data_type != MOST_CH_SYNC) { pr_err("Incompatible channel type\n"); return -EINVAL; -- cgit v1.2.3 From 7f921e92e72a52e6390207d3ebeb8f3b5966ebde Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Tue, 28 Jul 2020 11:07:55 +0200 Subject: staging: most: usb: remove NET dependency This patch removes the dependency to NET as it is no longer needed. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1595927275-27462-1-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/usb/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/usb/Kconfig b/drivers/staging/most/usb/Kconfig index 75dc25c0e0e5..a47a973dfb1d 100644 --- a/drivers/staging/most/usb/Kconfig +++ b/drivers/staging/most/usb/Kconfig @@ -5,10 +5,9 @@ config MOST_USB tristate "USB" - depends on USB && NET + depends on USB help Say Y here if you want to connect via USB to network transceiver. - This device driver depends on the networking AIM. To compile this driver as a module, choose M here: the module will be called most_usb. -- cgit v1.2.3 From 11c416e3f0ea437661514fa68967a5dba3cdf886 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 30 Jul 2020 18:15:06 +0300 Subject: staging: most: Use %pM format specifier for MAC addresses Convert to %pM instead of using custom code. Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20200730151506.38827-1-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/net/net.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/net/net.c b/drivers/staging/most/net/net.c index 830f089f1a88..b6fecb06a0e6 100644 --- a/drivers/staging/most/net/net.c +++ b/drivers/staging/most/net/net.c @@ -564,13 +564,11 @@ static void on_netinfo(struct most_interface *iface, if (m && is_valid_ether_addr(m)) { if (!is_valid_ether_addr(dev->dev_addr)) { - netdev_info(dev, "set mac %02x-%02x-%02x-%02x-%02x-%02x\n", - m[0], m[1], m[2], m[3], m[4], m[5]); + netdev_info(dev, "set mac %pM\n", m); ether_addr_copy(dev->dev_addr, m); netif_dormant_off(dev); } else if (!ether_addr_equal(dev->dev_addr, m)) { - netdev_warn(dev, "reject mac %02x-%02x-%02x-%02x-%02x-%02x\n", - m[0], m[1], m[2], m[3], m[4], m[5]); + netdev_warn(dev, "reject mac %pM\n", m); } } -- cgit v1.2.3 From 97a6f772f36b7f52bcfa56a581bbd2470cffe23d Mon Sep 17 00:00:00 2001 From: Christian Gromm Date: Fri, 31 Jul 2020 14:20:58 +0200 Subject: drivers: most: add USB adapter driver This patch adds the USB driver source file most_usb.c and modifies the Makefile and Kconfig accordingly. Signed-off-by: Christian Gromm Link: https://lore.kernel.org/r/1596198058-26541-1-git-send-email-christian.gromm@microchip.com Signed-off-by: Greg Kroah-Hartman --- drivers/most/Kconfig | 11 + drivers/most/Makefile | 2 + drivers/most/most_usb.c | 1170 +++++++++++++++++++++++++++++++++++++ drivers/staging/most/Kconfig | 2 - drivers/staging/most/usb/Kconfig | 13 - drivers/staging/most/usb/Makefile | 4 - drivers/staging/most/usb/usb.c | 1170 ------------------------------------- 7 files changed, 1183 insertions(+), 1189 deletions(-) create mode 100644 drivers/most/most_usb.c delete mode 100644 drivers/staging/most/usb/Kconfig delete mode 100644 drivers/staging/most/usb/Makefile delete mode 100644 drivers/staging/most/usb/usb.c (limited to 'drivers/staging/most') diff --git a/drivers/most/Kconfig b/drivers/most/Kconfig index 58d7999170a7..60fc0820dad3 100644 --- a/drivers/most/Kconfig +++ b/drivers/most/Kconfig @@ -13,3 +13,14 @@ menuconfig MOST module will be called most_core. If in doubt, say N here. + +if MOST +config MOST_USB_HDM + tristate "USB" + depends on USB + help + Say Y here if you want to connect via USB to network transceiver. + + To compile this driver as a module, choose M here: the + module will be called most_usb. +endif diff --git a/drivers/most/Makefile b/drivers/most/Makefile index e810cd3a47ee..6a3cb9056288 100644 --- a/drivers/most/Makefile +++ b/drivers/most/Makefile @@ -2,3 +2,5 @@ obj-$(CONFIG_MOST) += most_core.o most_core-y := core.o \ configfs.o + +obj-$(CONFIG_MOST_USB_HDM) += most_usb.o diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c new file mode 100644 index 000000000000..2640c5b326a4 --- /dev/null +++ b/drivers/most/most_usb.c @@ -0,0 +1,1170 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * usb.c - Hardware dependent module for USB + * + * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define USB_MTU 512 +#define NO_ISOCHRONOUS_URB 0 +#define AV_PACKETS_PER_XACT 2 +#define BUF_CHAIN_SIZE 0xFFFF +#define MAX_NUM_ENDPOINTS 30 +#define MAX_SUFFIX_LEN 10 +#define MAX_STRING_LEN 80 +#define MAX_BUF_SIZE 0xFFFF + +#define USB_VENDOR_ID_SMSC 0x0424 /* VID: SMSC */ +#define USB_DEV_ID_BRDG 0xC001 /* PID: USB Bridge */ +#define USB_DEV_ID_OS81118 0xCF18 /* PID: USB OS81118 */ +#define USB_DEV_ID_OS81119 0xCF19 /* PID: USB OS81119 */ +#define USB_DEV_ID_OS81210 0xCF30 /* PID: USB OS81210 */ +/* DRCI Addresses */ +#define DRCI_REG_NI_STATE 0x0100 +#define DRCI_REG_PACKET_BW 0x0101 +#define DRCI_REG_NODE_ADDR 0x0102 +#define DRCI_REG_NODE_POS 0x0103 +#define DRCI_REG_MEP_FILTER 0x0140 +#define DRCI_REG_HASH_TBL0 0x0141 +#define DRCI_REG_HASH_TBL1 0x0142 +#define DRCI_REG_HASH_TBL2 0x0143 +#define DRCI_REG_HASH_TBL3 0x0144 +#define DRCI_REG_HW_ADDR_HI 0x0145 +#define DRCI_REG_HW_ADDR_MI 0x0146 +#define DRCI_REG_HW_ADDR_LO 0x0147 +#define DRCI_REG_BASE 0x1100 +#define DRCI_COMMAND 0x02 +#define DRCI_READ_REQ 0xA0 +#define DRCI_WRITE_REQ 0xA1 + +/** + * struct most_dci_obj - Direct Communication Interface + * @kobj:position in sysfs + * @usb_device: pointer to the usb device + * @reg_addr: register address for arbitrary DCI access + */ +struct most_dci_obj { + struct device dev; + struct usb_device *usb_device; + u16 reg_addr; +}; + +#define to_dci_obj(p) container_of(p, struct most_dci_obj, dev) + +struct most_dev; + +struct clear_hold_work { + struct work_struct ws; + struct most_dev *mdev; + unsigned int channel; + int pipe; +}; + +#define to_clear_hold_work(w) container_of(w, struct clear_hold_work, ws) + +/** + * struct most_dev - holds all usb interface specific stuff + * @usb_device: pointer to usb device + * @iface: hardware interface + * @cap: channel capabilities + * @conf: channel configuration + * @dci: direct communication interface of hardware + * @ep_address: endpoint address table + * @description: device description + * @suffix: suffix for channel name + * @channel_lock: synchronize channel access + * @padding_active: indicates channel uses padding + * @is_channel_healthy: health status table of each channel + * @busy_urbs: list of anchored items + * @io_mutex: synchronize I/O with disconnect + * @link_stat_timer: timer for link status reports + * @poll_work_obj: work for polling link status + */ +struct most_dev { + struct device dev; + struct usb_device *usb_device; + struct most_interface iface; + struct most_channel_capability *cap; + struct most_channel_config *conf; + struct most_dci_obj *dci; + u8 *ep_address; + char description[MAX_STRING_LEN]; + char suffix[MAX_NUM_ENDPOINTS][MAX_SUFFIX_LEN]; + spinlock_t channel_lock[MAX_NUM_ENDPOINTS]; /* sync channel access */ + bool padding_active[MAX_NUM_ENDPOINTS]; + bool is_channel_healthy[MAX_NUM_ENDPOINTS]; + struct clear_hold_work clear_work[MAX_NUM_ENDPOINTS]; + struct usb_anchor *busy_urbs; + struct mutex io_mutex; + struct timer_list link_stat_timer; + struct work_struct poll_work_obj; + void (*on_netinfo)(struct most_interface *most_iface, + unsigned char link_state, unsigned char *addrs); +}; + +#define to_mdev(d) container_of(d, struct most_dev, iface) +#define to_mdev_from_dev(d) container_of(d, struct most_dev, dev) +#define to_mdev_from_work(w) container_of(w, struct most_dev, poll_work_obj) + +static void wq_clear_halt(struct work_struct *wq_obj); +static void wq_netinfo(struct work_struct *wq_obj); + +/** + * drci_rd_reg - read a DCI register + * @dev: usb device + * @reg: register address + * @buf: buffer to store data + * + * This is reads data from INIC's direct register communication interface + */ +static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf) +{ + int retval; + __le16 *dma_buf; + u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE; + + dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL); + if (!dma_buf) + return -ENOMEM; + + retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + DRCI_READ_REQ, req_type, + 0x0000, + reg, dma_buf, sizeof(*dma_buf), 5 * HZ); + *buf = le16_to_cpu(*dma_buf); + kfree(dma_buf); + + if (retval < 0) + return retval; + return 0; +} + +/** + * drci_wr_reg - write a DCI register + * @dev: usb device + * @reg: register address + * @data: data to write + * + * This is writes data to INIC's direct register communication interface + */ +static inline int drci_wr_reg(struct usb_device *dev, u16 reg, u16 data) +{ + return usb_control_msg(dev, + usb_sndctrlpipe(dev, 0), + DRCI_WRITE_REQ, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + data, + reg, + NULL, + 0, + 5 * HZ); +} + +static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep) +{ + return drci_wr_reg(usb_dev, DRCI_REG_BASE + DRCI_COMMAND + ep * 16, 1); +} + +/** + * get_stream_frame_size - calculate frame size of current configuration + * @dev: device structure + * @cfg: channel configuration + */ +static unsigned int get_stream_frame_size(struct device *dev, + struct most_channel_config *cfg) +{ + unsigned int frame_size; + unsigned int sub_size = cfg->subbuffer_size; + + if (!sub_size) { + dev_warn(dev, "Misconfig: Subbuffer size zero.\n"); + return 0; + } + switch (cfg->data_type) { + case MOST_CH_ISOC: + frame_size = AV_PACKETS_PER_XACT * sub_size; + break; + case MOST_CH_SYNC: + if (cfg->packets_per_xact == 0) { + dev_warn(dev, "Misconfig: Packets per XACT zero\n"); + frame_size = 0; + } else if (cfg->packets_per_xact == 0xFF) { + frame_size = (USB_MTU / sub_size) * sub_size; + } else { + frame_size = cfg->packets_per_xact * sub_size; + } + break; + default: + dev_warn(dev, "Query frame size of non-streaming channel\n"); + frame_size = 0; + break; + } + return frame_size; +} + +/** + * hdm_poison_channel - mark buffers of this channel as invalid + * @iface: pointer to the interface + * @channel: channel ID + * + * This unlinks all URBs submitted to the HCD, + * calls the associated completion function of the core and removes + * them from the list. + * + * Returns 0 on success or error code otherwise. + */ +static int hdm_poison_channel(struct most_interface *iface, int channel) +{ + struct most_dev *mdev = to_mdev(iface); + unsigned long flags; + spinlock_t *lock; /* temp. lock */ + + if (channel < 0 || channel >= iface->num_channels) { + dev_warn(&mdev->usb_device->dev, "Channel ID out of range.\n"); + return -ECHRNG; + } + + lock = mdev->channel_lock + channel; + spin_lock_irqsave(lock, flags); + mdev->is_channel_healthy[channel] = false; + spin_unlock_irqrestore(lock, flags); + + cancel_work_sync(&mdev->clear_work[channel].ws); + + mutex_lock(&mdev->io_mutex); + usb_kill_anchored_urbs(&mdev->busy_urbs[channel]); + if (mdev->padding_active[channel]) + mdev->padding_active[channel] = false; + + if (mdev->conf[channel].data_type == MOST_CH_ASYNC) { + del_timer_sync(&mdev->link_stat_timer); + cancel_work_sync(&mdev->poll_work_obj); + } + mutex_unlock(&mdev->io_mutex); + return 0; +} + +/** + * hdm_add_padding - add padding bytes + * @mdev: most device + * @channel: channel ID + * @mbo: buffer object + * + * This inserts the INIC hardware specific padding bytes into a streaming + * channel's buffer + */ +static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo) +{ + struct most_channel_config *conf = &mdev->conf[channel]; + unsigned int frame_size = get_stream_frame_size(&mdev->dev, conf); + unsigned int j, num_frames; + + if (!frame_size) + return -EINVAL; + num_frames = mbo->buffer_length / frame_size; + + if (num_frames < 1) { + dev_err(&mdev->usb_device->dev, + "Missed minimal transfer unit.\n"); + return -EINVAL; + } + + for (j = num_frames - 1; j > 0; j--) + memmove(mbo->virt_address + j * USB_MTU, + mbo->virt_address + j * frame_size, + frame_size); + mbo->buffer_length = num_frames * USB_MTU; + return 0; +} + +/** + * hdm_remove_padding - remove padding bytes + * @mdev: most device + * @channel: channel ID + * @mbo: buffer object + * + * This takes the INIC hardware specific padding bytes off a streaming + * channel's buffer. + */ +static int hdm_remove_padding(struct most_dev *mdev, int channel, + struct mbo *mbo) +{ + struct most_channel_config *const conf = &mdev->conf[channel]; + unsigned int frame_size = get_stream_frame_size(&mdev->dev, conf); + unsigned int j, num_frames; + + if (!frame_size) + return -EINVAL; + num_frames = mbo->processed_length / USB_MTU; + + for (j = 1; j < num_frames; j++) + memmove(mbo->virt_address + frame_size * j, + mbo->virt_address + USB_MTU * j, + frame_size); + + mbo->processed_length = frame_size * num_frames; + return 0; +} + +/** + * hdm_write_completion - completion function for submitted Tx URBs + * @urb: the URB that has been completed + * + * This checks the status of the completed URB. In case the URB has been + * unlinked before, it is immediately freed. On any other error the MBO + * transfer flag is set. On success it frees allocated resources and calls + * the completion function. + * + * Context: interrupt! + */ +static void hdm_write_completion(struct urb *urb) +{ + struct mbo *mbo = urb->context; + struct most_dev *mdev = to_mdev(mbo->ifp); + unsigned int channel = mbo->hdm_channel_id; + spinlock_t *lock = mdev->channel_lock + channel; + unsigned long flags; + + spin_lock_irqsave(lock, flags); + + mbo->processed_length = 0; + mbo->status = MBO_E_INVAL; + if (likely(mdev->is_channel_healthy[channel])) { + switch (urb->status) { + case 0: + case -ESHUTDOWN: + mbo->processed_length = urb->actual_length; + mbo->status = MBO_SUCCESS; + break; + case -EPIPE: + dev_warn(&mdev->usb_device->dev, + "Broken pipe on ep%02x\n", + mdev->ep_address[channel]); + mdev->is_channel_healthy[channel] = false; + mdev->clear_work[channel].pipe = urb->pipe; + schedule_work(&mdev->clear_work[channel].ws); + break; + case -ENODEV: + case -EPROTO: + mbo->status = MBO_E_CLOSE; + break; + } + } + + spin_unlock_irqrestore(lock, flags); + + if (likely(mbo->complete)) + mbo->complete(mbo); + usb_free_urb(urb); +} + +/** + * hdm_read_completion - completion function for submitted Rx URBs + * @urb: the URB that has been completed + * + * This checks the status of the completed URB. In case the URB has been + * unlinked before it is immediately freed. On any other error the MBO transfer + * flag is set. On success it frees allocated resources, removes + * padding bytes -if necessary- and calls the completion function. + * + * Context: interrupt! + */ +static void hdm_read_completion(struct urb *urb) +{ + struct mbo *mbo = urb->context; + struct most_dev *mdev = to_mdev(mbo->ifp); + unsigned int channel = mbo->hdm_channel_id; + struct device *dev = &mdev->usb_device->dev; + spinlock_t *lock = mdev->channel_lock + channel; + unsigned long flags; + + spin_lock_irqsave(lock, flags); + + mbo->processed_length = 0; + mbo->status = MBO_E_INVAL; + if (likely(mdev->is_channel_healthy[channel])) { + switch (urb->status) { + case 0: + case -ESHUTDOWN: + mbo->processed_length = urb->actual_length; + mbo->status = MBO_SUCCESS; + if (mdev->padding_active[channel] && + hdm_remove_padding(mdev, channel, mbo)) { + mbo->processed_length = 0; + mbo->status = MBO_E_INVAL; + } + break; + case -EPIPE: + dev_warn(dev, "Broken pipe on ep%02x\n", + mdev->ep_address[channel]); + mdev->is_channel_healthy[channel] = false; + mdev->clear_work[channel].pipe = urb->pipe; + schedule_work(&mdev->clear_work[channel].ws); + break; + case -ENODEV: + case -EPROTO: + mbo->status = MBO_E_CLOSE; + break; + case -EOVERFLOW: + dev_warn(dev, "Babble on ep%02x\n", + mdev->ep_address[channel]); + break; + } + } + + spin_unlock_irqrestore(lock, flags); + + if (likely(mbo->complete)) + mbo->complete(mbo); + usb_free_urb(urb); +} + +/** + * hdm_enqueue - receive a buffer to be used for data transfer + * @iface: interface to enqueue to + * @channel: ID of the channel + * @mbo: pointer to the buffer object + * + * This allocates a new URB and fills it according to the channel + * that is being used for transmission of data. Before the URB is + * submitted it is stored in the private anchor list. + * + * Returns 0 on success. On any error the URB is freed and a error code + * is returned. + * + * Context: Could in _some_ cases be interrupt! + */ +static int hdm_enqueue(struct most_interface *iface, int channel, + struct mbo *mbo) +{ + struct most_dev *mdev = to_mdev(iface); + struct most_channel_config *conf; + int retval = 0; + struct urb *urb; + unsigned long length; + void *virt_address; + + if (!mbo) + return -EINVAL; + if (iface->num_channels <= channel || channel < 0) + return -ECHRNG; + + urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_KERNEL); + if (!urb) + return -ENOMEM; + + conf = &mdev->conf[channel]; + + mutex_lock(&mdev->io_mutex); + if (!mdev->usb_device) { + retval = -ENODEV; + goto err_free_urb; + } + + if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] && + hdm_add_padding(mdev, channel, mbo)) { + retval = -EINVAL; + goto err_free_urb; + } + + urb->transfer_dma = mbo->bus_address; + virt_address = mbo->virt_address; + length = mbo->buffer_length; + + if (conf->direction & MOST_CH_TX) { + usb_fill_bulk_urb(urb, mdev->usb_device, + usb_sndbulkpipe(mdev->usb_device, + mdev->ep_address[channel]), + virt_address, + length, + hdm_write_completion, + mbo); + if (conf->data_type != MOST_CH_ISOC && + conf->data_type != MOST_CH_SYNC) + urb->transfer_flags |= URB_ZERO_PACKET; + } else { + usb_fill_bulk_urb(urb, mdev->usb_device, + usb_rcvbulkpipe(mdev->usb_device, + mdev->ep_address[channel]), + virt_address, + length + conf->extra_len, + hdm_read_completion, + mbo); + } + urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; + + usb_anchor_urb(urb, &mdev->busy_urbs[channel]); + + retval = usb_submit_urb(urb, GFP_KERNEL); + if (retval) { + dev_err(&mdev->usb_device->dev, + "URB submit failed with error %d.\n", retval); + goto err_unanchor_urb; + } + mutex_unlock(&mdev->io_mutex); + return 0; + +err_unanchor_urb: + usb_unanchor_urb(urb); +err_free_urb: + usb_free_urb(urb); + mutex_unlock(&mdev->io_mutex); + return retval; +} + +static void *hdm_dma_alloc(struct mbo *mbo, u32 size) +{ + struct most_dev *mdev = to_mdev(mbo->ifp); + + return usb_alloc_coherent(mdev->usb_device, size, GFP_KERNEL, + &mbo->bus_address); +} + +static void hdm_dma_free(struct mbo *mbo, u32 size) +{ + struct most_dev *mdev = to_mdev(mbo->ifp); + + usb_free_coherent(mdev->usb_device, size, mbo->virt_address, + mbo->bus_address); +} + +/** + * hdm_configure_channel - receive channel configuration from core + * @iface: interface + * @channel: channel ID + * @conf: structure that holds the configuration information + * + * The attached network interface controller (NIC) supports a padding mode + * to avoid short packets on USB, hence increasing the performance due to a + * lower interrupt load. This mode is default for synchronous data and can + * be switched on for isochronous data. In case padding is active the + * driver needs to know the frame size of the payload in order to calculate + * the number of bytes it needs to pad when transmitting or to cut off when + * receiving data. + * + */ +static int hdm_configure_channel(struct most_interface *iface, int channel, + struct most_channel_config *conf) +{ + unsigned int num_frames; + unsigned int frame_size; + struct most_dev *mdev = to_mdev(iface); + struct device *dev = &mdev->usb_device->dev; + + if (!conf) { + dev_err(dev, "Bad config pointer.\n"); + return -EINVAL; + } + if (channel < 0 || channel >= iface->num_channels) { + dev_err(dev, "Channel ID out of range.\n"); + return -EINVAL; + } + + mdev->is_channel_healthy[channel] = true; + mdev->clear_work[channel].channel = channel; + mdev->clear_work[channel].mdev = mdev; + INIT_WORK(&mdev->clear_work[channel].ws, wq_clear_halt); + + if (!conf->num_buffers || !conf->buffer_size) { + dev_err(dev, "Misconfig: buffer size or #buffers zero.\n"); + return -EINVAL; + } + + if (conf->data_type != MOST_CH_SYNC && + !(conf->data_type == MOST_CH_ISOC && + conf->packets_per_xact != 0xFF)) { + mdev->padding_active[channel] = false; + /* + * Since the NIC's padding mode is not going to be + * used, we can skip the frame size calculations and + * move directly on to exit. + */ + goto exit; + } + + mdev->padding_active[channel] = true; + + frame_size = get_stream_frame_size(&mdev->dev, conf); + if (frame_size == 0 || frame_size > USB_MTU) { + dev_warn(dev, "Misconfig: frame size wrong\n"); + return -EINVAL; + } + + num_frames = conf->buffer_size / frame_size; + + if (conf->buffer_size % frame_size) { + u16 old_size = conf->buffer_size; + + conf->buffer_size = num_frames * frame_size; + dev_warn(dev, "%s: fixed buffer size (%d -> %d)\n", + mdev->suffix[channel], old_size, conf->buffer_size); + } + + /* calculate extra length to comply w/ HW padding */ + conf->extra_len = num_frames * (USB_MTU - frame_size); + +exit: + mdev->conf[channel] = *conf; + if (conf->data_type == MOST_CH_ASYNC) { + u16 ep = mdev->ep_address[channel]; + + if (start_sync_ep(mdev->usb_device, ep) < 0) + dev_warn(dev, "sync for ep%02x failed", ep); + } + return 0; +} + +/** + * hdm_request_netinfo - request network information + * @iface: pointer to interface + * @channel: channel ID + * + * This is used as trigger to set up the link status timer that + * polls for the NI state of the INIC every 2 seconds. + * + */ +static void hdm_request_netinfo(struct most_interface *iface, int channel, + void (*on_netinfo)(struct most_interface *, + unsigned char, + unsigned char *)) +{ + struct most_dev *mdev = to_mdev(iface); + + mdev->on_netinfo = on_netinfo; + if (!on_netinfo) + return; + + mdev->link_stat_timer.expires = jiffies + HZ; + mod_timer(&mdev->link_stat_timer, mdev->link_stat_timer.expires); +} + +/** + * link_stat_timer_handler - schedule work obtaining mac address and link status + * @data: pointer to USB device instance + * + * The handler runs in interrupt context. That's why we need to defer the + * tasks to a work queue. + */ +static void link_stat_timer_handler(struct timer_list *t) +{ + struct most_dev *mdev = from_timer(mdev, t, link_stat_timer); + + schedule_work(&mdev->poll_work_obj); + mdev->link_stat_timer.expires = jiffies + (2 * HZ); + add_timer(&mdev->link_stat_timer); +} + +/** + * wq_netinfo - work queue function to deliver latest networking information + * @wq_obj: object that holds data for our deferred work to do + * + * This retrieves the network interface status of the USB INIC + */ +static void wq_netinfo(struct work_struct *wq_obj) +{ + struct most_dev *mdev = to_mdev_from_work(wq_obj); + struct usb_device *usb_device = mdev->usb_device; + struct device *dev = &usb_device->dev; + u16 hi, mi, lo, link; + u8 hw_addr[6]; + + if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_HI, &hi)) { + dev_err(dev, "Vendor request 'hw_addr_hi' failed\n"); + return; + } + + if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_MI, &mi)) { + dev_err(dev, "Vendor request 'hw_addr_mid' failed\n"); + return; + } + + if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_LO, &lo)) { + dev_err(dev, "Vendor request 'hw_addr_low' failed\n"); + return; + } + + if (drci_rd_reg(usb_device, DRCI_REG_NI_STATE, &link)) { + dev_err(dev, "Vendor request 'link status' failed\n"); + return; + } + + hw_addr[0] = hi >> 8; + hw_addr[1] = hi; + hw_addr[2] = mi >> 8; + hw_addr[3] = mi; + hw_addr[4] = lo >> 8; + hw_addr[5] = lo; + + if (mdev->on_netinfo) + mdev->on_netinfo(&mdev->iface, link, hw_addr); +} + +/** + * wq_clear_halt - work queue function + * @wq_obj: work_struct object to execute + * + * This sends a clear_halt to the given USB pipe. + */ +static void wq_clear_halt(struct work_struct *wq_obj) +{ + struct clear_hold_work *clear_work = to_clear_hold_work(wq_obj); + struct most_dev *mdev = clear_work->mdev; + unsigned int channel = clear_work->channel; + int pipe = clear_work->pipe; + int snd_pipe; + int peer; + + mutex_lock(&mdev->io_mutex); + most_stop_enqueue(&mdev->iface, channel); + usb_kill_anchored_urbs(&mdev->busy_urbs[channel]); + if (usb_clear_halt(mdev->usb_device, pipe)) + dev_warn(&mdev->usb_device->dev, "Failed to reset endpoint.\n"); + + /* If the functional Stall condition has been set on an + * asynchronous rx channel, we need to clear the tx channel + * too, since the hardware runs its clean-up sequence on both + * channels, as they are physically one on the network. + * + * The USB interface that exposes the asynchronous channels + * contains always two endpoints, and two only. + */ + if (mdev->conf[channel].data_type == MOST_CH_ASYNC && + mdev->conf[channel].direction == MOST_CH_RX) { + if (channel == 0) + peer = 1; + else + peer = 0; + snd_pipe = usb_sndbulkpipe(mdev->usb_device, + mdev->ep_address[peer]); + usb_clear_halt(mdev->usb_device, snd_pipe); + } + mdev->is_channel_healthy[channel] = true; + most_resume_enqueue(&mdev->iface, channel); + mutex_unlock(&mdev->io_mutex); +} + +/** + * hdm_usb_fops - file operation table for USB driver + */ +static const struct file_operations hdm_usb_fops = { + .owner = THIS_MODULE, +}; + +/** + * usb_device_id - ID table for HCD device probing + */ +static const struct usb_device_id usbid[] = { + { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_BRDG), }, + { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81118), }, + { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81119), }, + { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81210), }, + { } /* Terminating entry */ +}; + +struct regs { + const char *name; + u16 reg; +}; + +static const struct regs ro_regs[] = { + { "ni_state", DRCI_REG_NI_STATE }, + { "packet_bandwidth", DRCI_REG_PACKET_BW }, + { "node_address", DRCI_REG_NODE_ADDR }, + { "node_position", DRCI_REG_NODE_POS }, +}; + +static const struct regs rw_regs[] = { + { "mep_filter", DRCI_REG_MEP_FILTER }, + { "mep_hash0", DRCI_REG_HASH_TBL0 }, + { "mep_hash1", DRCI_REG_HASH_TBL1 }, + { "mep_hash2", DRCI_REG_HASH_TBL2 }, + { "mep_hash3", DRCI_REG_HASH_TBL3 }, + { "mep_eui48_hi", DRCI_REG_HW_ADDR_HI }, + { "mep_eui48_mi", DRCI_REG_HW_ADDR_MI }, + { "mep_eui48_lo", DRCI_REG_HW_ADDR_LO }, +}; + +static int get_stat_reg_addr(const struct regs *regs, int size, + const char *name, u16 *reg_addr) +{ + int i; + + for (i = 0; i < size; i++) { + if (sysfs_streq(name, regs[i].name)) { + *reg_addr = regs[i].reg; + return 0; + } + } + return -EINVAL; +} + +#define get_static_reg_addr(regs, name, reg_addr) \ + get_stat_reg_addr(regs, ARRAY_SIZE(regs), name, reg_addr) + +static ssize_t value_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + const char *name = attr->attr.name; + struct most_dci_obj *dci_obj = to_dci_obj(dev); + u16 val; + u16 reg_addr; + int err; + + if (sysfs_streq(name, "arb_address")) + return snprintf(buf, PAGE_SIZE, "%04x\n", dci_obj->reg_addr); + + if (sysfs_streq(name, "arb_value")) + reg_addr = dci_obj->reg_addr; + else if (get_static_reg_addr(ro_regs, name, ®_addr) && + get_static_reg_addr(rw_regs, name, ®_addr)) + return -EINVAL; + + err = drci_rd_reg(dci_obj->usb_device, reg_addr, &val); + if (err < 0) + return err; + + return snprintf(buf, PAGE_SIZE, "%04x\n", val); +} + +static ssize_t value_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + u16 val; + u16 reg_addr; + const char *name = attr->attr.name; + struct most_dci_obj *dci_obj = to_dci_obj(dev); + struct usb_device *usb_dev = dci_obj->usb_device; + int err; + + err = kstrtou16(buf, 16, &val); + if (err) + return err; + + if (sysfs_streq(name, "arb_address")) { + dci_obj->reg_addr = val; + return count; + } + + if (sysfs_streq(name, "arb_value")) + err = drci_wr_reg(usb_dev, dci_obj->reg_addr, val); + else if (sysfs_streq(name, "sync_ep")) + err = start_sync_ep(usb_dev, val); + else if (!get_static_reg_addr(rw_regs, name, ®_addr)) + err = drci_wr_reg(usb_dev, reg_addr, val); + else + return -EINVAL; + + if (err < 0) + return err; + + return count; +} + +static DEVICE_ATTR(ni_state, 0444, value_show, NULL); +static DEVICE_ATTR(packet_bandwidth, 0444, value_show, NULL); +static DEVICE_ATTR(node_address, 0444, value_show, NULL); +static DEVICE_ATTR(node_position, 0444, value_show, NULL); +static DEVICE_ATTR(sync_ep, 0200, NULL, value_store); +static DEVICE_ATTR(mep_filter, 0644, value_show, value_store); +static DEVICE_ATTR(mep_hash0, 0644, value_show, value_store); +static DEVICE_ATTR(mep_hash1, 0644, value_show, value_store); +static DEVICE_ATTR(mep_hash2, 0644, value_show, value_store); +static DEVICE_ATTR(mep_hash3, 0644, value_show, value_store); +static DEVICE_ATTR(mep_eui48_hi, 0644, value_show, value_store); +static DEVICE_ATTR(mep_eui48_mi, 0644, value_show, value_store); +static DEVICE_ATTR(mep_eui48_lo, 0644, value_show, value_store); +static DEVICE_ATTR(arb_address, 0644, value_show, value_store); +static DEVICE_ATTR(arb_value, 0644, value_show, value_store); + +static struct attribute *dci_attrs[] = { + &dev_attr_ni_state.attr, + &dev_attr_packet_bandwidth.attr, + &dev_attr_node_address.attr, + &dev_attr_node_position.attr, + &dev_attr_sync_ep.attr, + &dev_attr_mep_filter.attr, + &dev_attr_mep_hash0.attr, + &dev_attr_mep_hash1.attr, + &dev_attr_mep_hash2.attr, + &dev_attr_mep_hash3.attr, + &dev_attr_mep_eui48_hi.attr, + &dev_attr_mep_eui48_mi.attr, + &dev_attr_mep_eui48_lo.attr, + &dev_attr_arb_address.attr, + &dev_attr_arb_value.attr, + NULL, +}; + +ATTRIBUTE_GROUPS(dci); + +static void release_dci(struct device *dev) +{ + struct most_dci_obj *dci = to_dci_obj(dev); + + put_device(dev->parent); + kfree(dci); +} + +static void release_mdev(struct device *dev) +{ + struct most_dev *mdev = to_mdev_from_dev(dev); + + kfree(mdev); +} +/** + * hdm_probe - probe function of USB device driver + * @interface: Interface of the attached USB device + * @id: Pointer to the USB ID table. + * + * This allocates and initializes the device instance, adds the new + * entry to the internal list, scans the USB descriptors and registers + * the interface with the core. + * Additionally, the DCI objects are created and the hardware is sync'd. + * + * Return 0 on success. In case of an error a negative number is returned. + */ +static int +hdm_probe(struct usb_interface *interface, const struct usb_device_id *id) +{ + struct usb_host_interface *usb_iface_desc = interface->cur_altsetting; + struct usb_device *usb_dev = interface_to_usbdev(interface); + struct device *dev = &usb_dev->dev; + struct most_dev *mdev; + unsigned int i; + unsigned int num_endpoints; + struct most_channel_capability *tmp_cap; + struct usb_endpoint_descriptor *ep_desc; + int ret = -ENOMEM; + + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); + if (!mdev) + return -ENOMEM; + + usb_set_intfdata(interface, mdev); + num_endpoints = usb_iface_desc->desc.bNumEndpoints; + if (num_endpoints > MAX_NUM_ENDPOINTS) { + kfree(mdev); + return -EINVAL; + } + mutex_init(&mdev->io_mutex); + INIT_WORK(&mdev->poll_work_obj, wq_netinfo); + timer_setup(&mdev->link_stat_timer, link_stat_timer_handler, 0); + + mdev->usb_device = usb_dev; + mdev->link_stat_timer.expires = jiffies + (2 * HZ); + + mdev->iface.mod = hdm_usb_fops.owner; + mdev->iface.dev = &mdev->dev; + mdev->iface.driver_dev = &interface->dev; + mdev->iface.interface = ITYPE_USB; + mdev->iface.configure = hdm_configure_channel; + mdev->iface.request_netinfo = hdm_request_netinfo; + mdev->iface.enqueue = hdm_enqueue; + mdev->iface.poison_channel = hdm_poison_channel; + mdev->iface.dma_alloc = hdm_dma_alloc; + mdev->iface.dma_free = hdm_dma_free; + mdev->iface.description = mdev->description; + mdev->iface.num_channels = num_endpoints; + + snprintf(mdev->description, sizeof(mdev->description), + "%d-%s:%d.%d", + usb_dev->bus->busnum, + usb_dev->devpath, + usb_dev->config->desc.bConfigurationValue, + usb_iface_desc->desc.bInterfaceNumber); + + mdev->dev.init_name = mdev->description; + mdev->dev.parent = &interface->dev; + mdev->dev.release = release_mdev; + mdev->conf = kcalloc(num_endpoints, sizeof(*mdev->conf), GFP_KERNEL); + if (!mdev->conf) + goto err_free_mdev; + + mdev->cap = kcalloc(num_endpoints, sizeof(*mdev->cap), GFP_KERNEL); + if (!mdev->cap) + goto err_free_conf; + + mdev->iface.channel_vector = mdev->cap; + mdev->ep_address = + kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL); + if (!mdev->ep_address) + goto err_free_cap; + + mdev->busy_urbs = + kcalloc(num_endpoints, sizeof(*mdev->busy_urbs), GFP_KERNEL); + if (!mdev->busy_urbs) + goto err_free_ep_address; + + tmp_cap = mdev->cap; + for (i = 0; i < num_endpoints; i++) { + ep_desc = &usb_iface_desc->endpoint[i].desc; + mdev->ep_address[i] = ep_desc->bEndpointAddress; + mdev->padding_active[i] = false; + mdev->is_channel_healthy[i] = true; + + snprintf(&mdev->suffix[i][0], MAX_SUFFIX_LEN, "ep%02x", + mdev->ep_address[i]); + + tmp_cap->name_suffix = &mdev->suffix[i][0]; + tmp_cap->buffer_size_packet = MAX_BUF_SIZE; + tmp_cap->buffer_size_streaming = MAX_BUF_SIZE; + tmp_cap->num_buffers_packet = BUF_CHAIN_SIZE; + tmp_cap->num_buffers_streaming = BUF_CHAIN_SIZE; + tmp_cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC | + MOST_CH_ISOC | MOST_CH_SYNC; + if (usb_endpoint_dir_in(ep_desc)) + tmp_cap->direction = MOST_CH_RX; + else + tmp_cap->direction = MOST_CH_TX; + tmp_cap++; + init_usb_anchor(&mdev->busy_urbs[i]); + spin_lock_init(&mdev->channel_lock[i]); + } + dev_dbg(dev, "claimed gadget: Vendor=%4.4x ProdID=%4.4x Bus=%02x Device=%02x\n", + le16_to_cpu(usb_dev->descriptor.idVendor), + le16_to_cpu(usb_dev->descriptor.idProduct), + usb_dev->bus->busnum, + usb_dev->devnum); + + dev_dbg(dev, "device path: /sys/bus/usb/devices/%d-%s:%d.%d\n", + usb_dev->bus->busnum, + usb_dev->devpath, + usb_dev->config->desc.bConfigurationValue, + usb_iface_desc->desc.bInterfaceNumber); + + ret = most_register_interface(&mdev->iface); + if (ret) + goto err_free_busy_urbs; + + mutex_lock(&mdev->io_mutex); + if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 || + le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81119 || + le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81210) { + mdev->dci = kzalloc(sizeof(*mdev->dci), GFP_KERNEL); + if (!mdev->dci) { + mutex_unlock(&mdev->io_mutex); + most_deregister_interface(&mdev->iface); + ret = -ENOMEM; + goto err_free_busy_urbs; + } + + mdev->dci->dev.init_name = "dci"; + mdev->dci->dev.parent = get_device(mdev->iface.dev); + mdev->dci->dev.groups = dci_groups; + mdev->dci->dev.release = release_dci; + if (device_register(&mdev->dci->dev)) { + mutex_unlock(&mdev->io_mutex); + most_deregister_interface(&mdev->iface); + ret = -ENOMEM; + goto err_free_dci; + } + mdev->dci->usb_device = mdev->usb_device; + } + mutex_unlock(&mdev->io_mutex); + return 0; +err_free_dci: + put_device(&mdev->dci->dev); +err_free_busy_urbs: + kfree(mdev->busy_urbs); +err_free_ep_address: + kfree(mdev->ep_address); +err_free_cap: + kfree(mdev->cap); +err_free_conf: + kfree(mdev->conf); +err_free_mdev: + put_device(&mdev->dev); + return ret; +} + +/** + * hdm_disconnect - disconnect function of USB device driver + * @interface: Interface of the attached USB device + * + * This deregisters the interface with the core, removes the kernel timer + * and frees resources. + * + * Context: hub kernel thread + */ +static void hdm_disconnect(struct usb_interface *interface) +{ + struct most_dev *mdev = usb_get_intfdata(interface); + + mutex_lock(&mdev->io_mutex); + usb_set_intfdata(interface, NULL); + mdev->usb_device = NULL; + mutex_unlock(&mdev->io_mutex); + + del_timer_sync(&mdev->link_stat_timer); + cancel_work_sync(&mdev->poll_work_obj); + + if (mdev->dci) + device_unregister(&mdev->dci->dev); + most_deregister_interface(&mdev->iface); + + kfree(mdev->busy_urbs); + kfree(mdev->cap); + kfree(mdev->conf); + kfree(mdev->ep_address); + put_device(&mdev->dci->dev); + put_device(&mdev->dev); +} + +static int hdm_suspend(struct usb_interface *interface, pm_message_t message) +{ + struct most_dev *mdev = usb_get_intfdata(interface); + int i; + + mutex_lock(&mdev->io_mutex); + for (i = 0; i < mdev->iface.num_channels; i++) { + most_stop_enqueue(&mdev->iface, i); + usb_kill_anchored_urbs(&mdev->busy_urbs[i]); + } + mutex_unlock(&mdev->io_mutex); + return 0; +} + +static int hdm_resume(struct usb_interface *interface) +{ + struct most_dev *mdev = usb_get_intfdata(interface); + int i; + + mutex_lock(&mdev->io_mutex); + for (i = 0; i < mdev->iface.num_channels; i++) + most_resume_enqueue(&mdev->iface, i); + mutex_unlock(&mdev->io_mutex); + return 0; +} + +static struct usb_driver hdm_usb = { + .name = "hdm_usb", + .id_table = usbid, + .probe = hdm_probe, + .disconnect = hdm_disconnect, + .resume = hdm_resume, + .suspend = hdm_suspend, +}; + +module_usb_driver(hdm_usb); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Christian Gromm "); +MODULE_DESCRIPTION("HDM_4_USB"); diff --git a/drivers/staging/most/Kconfig b/drivers/staging/most/Kconfig index c5a99f750abe..c35fb34fae79 100644 --- a/drivers/staging/most/Kconfig +++ b/drivers/staging/most/Kconfig @@ -30,6 +30,4 @@ source "drivers/staging/most/dim2/Kconfig" source "drivers/staging/most/i2c/Kconfig" -source "drivers/staging/most/usb/Kconfig" - endif diff --git a/drivers/staging/most/usb/Kconfig b/drivers/staging/most/usb/Kconfig deleted file mode 100644 index a47a973dfb1d..000000000000 --- a/drivers/staging/most/usb/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# MOST USB configuration -# - -config MOST_USB - tristate "USB" - depends on USB - help - Say Y here if you want to connect via USB to network transceiver. - - To compile this driver as a module, choose M here: the - module will be called most_usb. diff --git a/drivers/staging/most/usb/Makefile b/drivers/staging/most/usb/Makefile deleted file mode 100644 index c2b207339aec..000000000000 --- a/drivers/staging/most/usb/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_MOST_USB) += most_usb.o - -most_usb-objs := usb.o diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c deleted file mode 100644 index 2640c5b326a4..000000000000 --- a/drivers/staging/most/usb/usb.c +++ /dev/null @@ -1,1170 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * usb.c - Hardware dependent module for USB - * - * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define USB_MTU 512 -#define NO_ISOCHRONOUS_URB 0 -#define AV_PACKETS_PER_XACT 2 -#define BUF_CHAIN_SIZE 0xFFFF -#define MAX_NUM_ENDPOINTS 30 -#define MAX_SUFFIX_LEN 10 -#define MAX_STRING_LEN 80 -#define MAX_BUF_SIZE 0xFFFF - -#define USB_VENDOR_ID_SMSC 0x0424 /* VID: SMSC */ -#define USB_DEV_ID_BRDG 0xC001 /* PID: USB Bridge */ -#define USB_DEV_ID_OS81118 0xCF18 /* PID: USB OS81118 */ -#define USB_DEV_ID_OS81119 0xCF19 /* PID: USB OS81119 */ -#define USB_DEV_ID_OS81210 0xCF30 /* PID: USB OS81210 */ -/* DRCI Addresses */ -#define DRCI_REG_NI_STATE 0x0100 -#define DRCI_REG_PACKET_BW 0x0101 -#define DRCI_REG_NODE_ADDR 0x0102 -#define DRCI_REG_NODE_POS 0x0103 -#define DRCI_REG_MEP_FILTER 0x0140 -#define DRCI_REG_HASH_TBL0 0x0141 -#define DRCI_REG_HASH_TBL1 0x0142 -#define DRCI_REG_HASH_TBL2 0x0143 -#define DRCI_REG_HASH_TBL3 0x0144 -#define DRCI_REG_HW_ADDR_HI 0x0145 -#define DRCI_REG_HW_ADDR_MI 0x0146 -#define DRCI_REG_HW_ADDR_LO 0x0147 -#define DRCI_REG_BASE 0x1100 -#define DRCI_COMMAND 0x02 -#define DRCI_READ_REQ 0xA0 -#define DRCI_WRITE_REQ 0xA1 - -/** - * struct most_dci_obj - Direct Communication Interface - * @kobj:position in sysfs - * @usb_device: pointer to the usb device - * @reg_addr: register address for arbitrary DCI access - */ -struct most_dci_obj { - struct device dev; - struct usb_device *usb_device; - u16 reg_addr; -}; - -#define to_dci_obj(p) container_of(p, struct most_dci_obj, dev) - -struct most_dev; - -struct clear_hold_work { - struct work_struct ws; - struct most_dev *mdev; - unsigned int channel; - int pipe; -}; - -#define to_clear_hold_work(w) container_of(w, struct clear_hold_work, ws) - -/** - * struct most_dev - holds all usb interface specific stuff - * @usb_device: pointer to usb device - * @iface: hardware interface - * @cap: channel capabilities - * @conf: channel configuration - * @dci: direct communication interface of hardware - * @ep_address: endpoint address table - * @description: device description - * @suffix: suffix for channel name - * @channel_lock: synchronize channel access - * @padding_active: indicates channel uses padding - * @is_channel_healthy: health status table of each channel - * @busy_urbs: list of anchored items - * @io_mutex: synchronize I/O with disconnect - * @link_stat_timer: timer for link status reports - * @poll_work_obj: work for polling link status - */ -struct most_dev { - struct device dev; - struct usb_device *usb_device; - struct most_interface iface; - struct most_channel_capability *cap; - struct most_channel_config *conf; - struct most_dci_obj *dci; - u8 *ep_address; - char description[MAX_STRING_LEN]; - char suffix[MAX_NUM_ENDPOINTS][MAX_SUFFIX_LEN]; - spinlock_t channel_lock[MAX_NUM_ENDPOINTS]; /* sync channel access */ - bool padding_active[MAX_NUM_ENDPOINTS]; - bool is_channel_healthy[MAX_NUM_ENDPOINTS]; - struct clear_hold_work clear_work[MAX_NUM_ENDPOINTS]; - struct usb_anchor *busy_urbs; - struct mutex io_mutex; - struct timer_list link_stat_timer; - struct work_struct poll_work_obj; - void (*on_netinfo)(struct most_interface *most_iface, - unsigned char link_state, unsigned char *addrs); -}; - -#define to_mdev(d) container_of(d, struct most_dev, iface) -#define to_mdev_from_dev(d) container_of(d, struct most_dev, dev) -#define to_mdev_from_work(w) container_of(w, struct most_dev, poll_work_obj) - -static void wq_clear_halt(struct work_struct *wq_obj); -static void wq_netinfo(struct work_struct *wq_obj); - -/** - * drci_rd_reg - read a DCI register - * @dev: usb device - * @reg: register address - * @buf: buffer to store data - * - * This is reads data from INIC's direct register communication interface - */ -static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf) -{ - int retval; - __le16 *dma_buf; - u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE; - - dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL); - if (!dma_buf) - return -ENOMEM; - - retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - DRCI_READ_REQ, req_type, - 0x0000, - reg, dma_buf, sizeof(*dma_buf), 5 * HZ); - *buf = le16_to_cpu(*dma_buf); - kfree(dma_buf); - - if (retval < 0) - return retval; - return 0; -} - -/** - * drci_wr_reg - write a DCI register - * @dev: usb device - * @reg: register address - * @data: data to write - * - * This is writes data to INIC's direct register communication interface - */ -static inline int drci_wr_reg(struct usb_device *dev, u16 reg, u16 data) -{ - return usb_control_msg(dev, - usb_sndctrlpipe(dev, 0), - DRCI_WRITE_REQ, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - data, - reg, - NULL, - 0, - 5 * HZ); -} - -static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep) -{ - return drci_wr_reg(usb_dev, DRCI_REG_BASE + DRCI_COMMAND + ep * 16, 1); -} - -/** - * get_stream_frame_size - calculate frame size of current configuration - * @dev: device structure - * @cfg: channel configuration - */ -static unsigned int get_stream_frame_size(struct device *dev, - struct most_channel_config *cfg) -{ - unsigned int frame_size; - unsigned int sub_size = cfg->subbuffer_size; - - if (!sub_size) { - dev_warn(dev, "Misconfig: Subbuffer size zero.\n"); - return 0; - } - switch (cfg->data_type) { - case MOST_CH_ISOC: - frame_size = AV_PACKETS_PER_XACT * sub_size; - break; - case MOST_CH_SYNC: - if (cfg->packets_per_xact == 0) { - dev_warn(dev, "Misconfig: Packets per XACT zero\n"); - frame_size = 0; - } else if (cfg->packets_per_xact == 0xFF) { - frame_size = (USB_MTU / sub_size) * sub_size; - } else { - frame_size = cfg->packets_per_xact * sub_size; - } - break; - default: - dev_warn(dev, "Query frame size of non-streaming channel\n"); - frame_size = 0; - break; - } - return frame_size; -} - -/** - * hdm_poison_channel - mark buffers of this channel as invalid - * @iface: pointer to the interface - * @channel: channel ID - * - * This unlinks all URBs submitted to the HCD, - * calls the associated completion function of the core and removes - * them from the list. - * - * Returns 0 on success or error code otherwise. - */ -static int hdm_poison_channel(struct most_interface *iface, int channel) -{ - struct most_dev *mdev = to_mdev(iface); - unsigned long flags; - spinlock_t *lock; /* temp. lock */ - - if (channel < 0 || channel >= iface->num_channels) { - dev_warn(&mdev->usb_device->dev, "Channel ID out of range.\n"); - return -ECHRNG; - } - - lock = mdev->channel_lock + channel; - spin_lock_irqsave(lock, flags); - mdev->is_channel_healthy[channel] = false; - spin_unlock_irqrestore(lock, flags); - - cancel_work_sync(&mdev->clear_work[channel].ws); - - mutex_lock(&mdev->io_mutex); - usb_kill_anchored_urbs(&mdev->busy_urbs[channel]); - if (mdev->padding_active[channel]) - mdev->padding_active[channel] = false; - - if (mdev->conf[channel].data_type == MOST_CH_ASYNC) { - del_timer_sync(&mdev->link_stat_timer); - cancel_work_sync(&mdev->poll_work_obj); - } - mutex_unlock(&mdev->io_mutex); - return 0; -} - -/** - * hdm_add_padding - add padding bytes - * @mdev: most device - * @channel: channel ID - * @mbo: buffer object - * - * This inserts the INIC hardware specific padding bytes into a streaming - * channel's buffer - */ -static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo) -{ - struct most_channel_config *conf = &mdev->conf[channel]; - unsigned int frame_size = get_stream_frame_size(&mdev->dev, conf); - unsigned int j, num_frames; - - if (!frame_size) - return -EINVAL; - num_frames = mbo->buffer_length / frame_size; - - if (num_frames < 1) { - dev_err(&mdev->usb_device->dev, - "Missed minimal transfer unit.\n"); - return -EINVAL; - } - - for (j = num_frames - 1; j > 0; j--) - memmove(mbo->virt_address + j * USB_MTU, - mbo->virt_address + j * frame_size, - frame_size); - mbo->buffer_length = num_frames * USB_MTU; - return 0; -} - -/** - * hdm_remove_padding - remove padding bytes - * @mdev: most device - * @channel: channel ID - * @mbo: buffer object - * - * This takes the INIC hardware specific padding bytes off a streaming - * channel's buffer. - */ -static int hdm_remove_padding(struct most_dev *mdev, int channel, - struct mbo *mbo) -{ - struct most_channel_config *const conf = &mdev->conf[channel]; - unsigned int frame_size = get_stream_frame_size(&mdev->dev, conf); - unsigned int j, num_frames; - - if (!frame_size) - return -EINVAL; - num_frames = mbo->processed_length / USB_MTU; - - for (j = 1; j < num_frames; j++) - memmove(mbo->virt_address + frame_size * j, - mbo->virt_address + USB_MTU * j, - frame_size); - - mbo->processed_length = frame_size * num_frames; - return 0; -} - -/** - * hdm_write_completion - completion function for submitted Tx URBs - * @urb: the URB that has been completed - * - * This checks the status of the completed URB. In case the URB has been - * unlinked before, it is immediately freed. On any other error the MBO - * transfer flag is set. On success it frees allocated resources and calls - * the completion function. - * - * Context: interrupt! - */ -static void hdm_write_completion(struct urb *urb) -{ - struct mbo *mbo = urb->context; - struct most_dev *mdev = to_mdev(mbo->ifp); - unsigned int channel = mbo->hdm_channel_id; - spinlock_t *lock = mdev->channel_lock + channel; - unsigned long flags; - - spin_lock_irqsave(lock, flags); - - mbo->processed_length = 0; - mbo->status = MBO_E_INVAL; - if (likely(mdev->is_channel_healthy[channel])) { - switch (urb->status) { - case 0: - case -ESHUTDOWN: - mbo->processed_length = urb->actual_length; - mbo->status = MBO_SUCCESS; - break; - case -EPIPE: - dev_warn(&mdev->usb_device->dev, - "Broken pipe on ep%02x\n", - mdev->ep_address[channel]); - mdev->is_channel_healthy[channel] = false; - mdev->clear_work[channel].pipe = urb->pipe; - schedule_work(&mdev->clear_work[channel].ws); - break; - case -ENODEV: - case -EPROTO: - mbo->status = MBO_E_CLOSE; - break; - } - } - - spin_unlock_irqrestore(lock, flags); - - if (likely(mbo->complete)) - mbo->complete(mbo); - usb_free_urb(urb); -} - -/** - * hdm_read_completion - completion function for submitted Rx URBs - * @urb: the URB that has been completed - * - * This checks the status of the completed URB. In case the URB has been - * unlinked before it is immediately freed. On any other error the MBO transfer - * flag is set. On success it frees allocated resources, removes - * padding bytes -if necessary- and calls the completion function. - * - * Context: interrupt! - */ -static void hdm_read_completion(struct urb *urb) -{ - struct mbo *mbo = urb->context; - struct most_dev *mdev = to_mdev(mbo->ifp); - unsigned int channel = mbo->hdm_channel_id; - struct device *dev = &mdev->usb_device->dev; - spinlock_t *lock = mdev->channel_lock + channel; - unsigned long flags; - - spin_lock_irqsave(lock, flags); - - mbo->processed_length = 0; - mbo->status = MBO_E_INVAL; - if (likely(mdev->is_channel_healthy[channel])) { - switch (urb->status) { - case 0: - case -ESHUTDOWN: - mbo->processed_length = urb->actual_length; - mbo->status = MBO_SUCCESS; - if (mdev->padding_active[channel] && - hdm_remove_padding(mdev, channel, mbo)) { - mbo->processed_length = 0; - mbo->status = MBO_E_INVAL; - } - break; - case -EPIPE: - dev_warn(dev, "Broken pipe on ep%02x\n", - mdev->ep_address[channel]); - mdev->is_channel_healthy[channel] = false; - mdev->clear_work[channel].pipe = urb->pipe; - schedule_work(&mdev->clear_work[channel].ws); - break; - case -ENODEV: - case -EPROTO: - mbo->status = MBO_E_CLOSE; - break; - case -EOVERFLOW: - dev_warn(dev, "Babble on ep%02x\n", - mdev->ep_address[channel]); - break; - } - } - - spin_unlock_irqrestore(lock, flags); - - if (likely(mbo->complete)) - mbo->complete(mbo); - usb_free_urb(urb); -} - -/** - * hdm_enqueue - receive a buffer to be used for data transfer - * @iface: interface to enqueue to - * @channel: ID of the channel - * @mbo: pointer to the buffer object - * - * This allocates a new URB and fills it according to the channel - * that is being used for transmission of data. Before the URB is - * submitted it is stored in the private anchor list. - * - * Returns 0 on success. On any error the URB is freed and a error code - * is returned. - * - * Context: Could in _some_ cases be interrupt! - */ -static int hdm_enqueue(struct most_interface *iface, int channel, - struct mbo *mbo) -{ - struct most_dev *mdev = to_mdev(iface); - struct most_channel_config *conf; - int retval = 0; - struct urb *urb; - unsigned long length; - void *virt_address; - - if (!mbo) - return -EINVAL; - if (iface->num_channels <= channel || channel < 0) - return -ECHRNG; - - urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_KERNEL); - if (!urb) - return -ENOMEM; - - conf = &mdev->conf[channel]; - - mutex_lock(&mdev->io_mutex); - if (!mdev->usb_device) { - retval = -ENODEV; - goto err_free_urb; - } - - if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] && - hdm_add_padding(mdev, channel, mbo)) { - retval = -EINVAL; - goto err_free_urb; - } - - urb->transfer_dma = mbo->bus_address; - virt_address = mbo->virt_address; - length = mbo->buffer_length; - - if (conf->direction & MOST_CH_TX) { - usb_fill_bulk_urb(urb, mdev->usb_device, - usb_sndbulkpipe(mdev->usb_device, - mdev->ep_address[channel]), - virt_address, - length, - hdm_write_completion, - mbo); - if (conf->data_type != MOST_CH_ISOC && - conf->data_type != MOST_CH_SYNC) - urb->transfer_flags |= URB_ZERO_PACKET; - } else { - usb_fill_bulk_urb(urb, mdev->usb_device, - usb_rcvbulkpipe(mdev->usb_device, - mdev->ep_address[channel]), - virt_address, - length + conf->extra_len, - hdm_read_completion, - mbo); - } - urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - - usb_anchor_urb(urb, &mdev->busy_urbs[channel]); - - retval = usb_submit_urb(urb, GFP_KERNEL); - if (retval) { - dev_err(&mdev->usb_device->dev, - "URB submit failed with error %d.\n", retval); - goto err_unanchor_urb; - } - mutex_unlock(&mdev->io_mutex); - return 0; - -err_unanchor_urb: - usb_unanchor_urb(urb); -err_free_urb: - usb_free_urb(urb); - mutex_unlock(&mdev->io_mutex); - return retval; -} - -static void *hdm_dma_alloc(struct mbo *mbo, u32 size) -{ - struct most_dev *mdev = to_mdev(mbo->ifp); - - return usb_alloc_coherent(mdev->usb_device, size, GFP_KERNEL, - &mbo->bus_address); -} - -static void hdm_dma_free(struct mbo *mbo, u32 size) -{ - struct most_dev *mdev = to_mdev(mbo->ifp); - - usb_free_coherent(mdev->usb_device, size, mbo->virt_address, - mbo->bus_address); -} - -/** - * hdm_configure_channel - receive channel configuration from core - * @iface: interface - * @channel: channel ID - * @conf: structure that holds the configuration information - * - * The attached network interface controller (NIC) supports a padding mode - * to avoid short packets on USB, hence increasing the performance due to a - * lower interrupt load. This mode is default for synchronous data and can - * be switched on for isochronous data. In case padding is active the - * driver needs to know the frame size of the payload in order to calculate - * the number of bytes it needs to pad when transmitting or to cut off when - * receiving data. - * - */ -static int hdm_configure_channel(struct most_interface *iface, int channel, - struct most_channel_config *conf) -{ - unsigned int num_frames; - unsigned int frame_size; - struct most_dev *mdev = to_mdev(iface); - struct device *dev = &mdev->usb_device->dev; - - if (!conf) { - dev_err(dev, "Bad config pointer.\n"); - return -EINVAL; - } - if (channel < 0 || channel >= iface->num_channels) { - dev_err(dev, "Channel ID out of range.\n"); - return -EINVAL; - } - - mdev->is_channel_healthy[channel] = true; - mdev->clear_work[channel].channel = channel; - mdev->clear_work[channel].mdev = mdev; - INIT_WORK(&mdev->clear_work[channel].ws, wq_clear_halt); - - if (!conf->num_buffers || !conf->buffer_size) { - dev_err(dev, "Misconfig: buffer size or #buffers zero.\n"); - return -EINVAL; - } - - if (conf->data_type != MOST_CH_SYNC && - !(conf->data_type == MOST_CH_ISOC && - conf->packets_per_xact != 0xFF)) { - mdev->padding_active[channel] = false; - /* - * Since the NIC's padding mode is not going to be - * used, we can skip the frame size calculations and - * move directly on to exit. - */ - goto exit; - } - - mdev->padding_active[channel] = true; - - frame_size = get_stream_frame_size(&mdev->dev, conf); - if (frame_size == 0 || frame_size > USB_MTU) { - dev_warn(dev, "Misconfig: frame size wrong\n"); - return -EINVAL; - } - - num_frames = conf->buffer_size / frame_size; - - if (conf->buffer_size % frame_size) { - u16 old_size = conf->buffer_size; - - conf->buffer_size = num_frames * frame_size; - dev_warn(dev, "%s: fixed buffer size (%d -> %d)\n", - mdev->suffix[channel], old_size, conf->buffer_size); - } - - /* calculate extra length to comply w/ HW padding */ - conf->extra_len = num_frames * (USB_MTU - frame_size); - -exit: - mdev->conf[channel] = *conf; - if (conf->data_type == MOST_CH_ASYNC) { - u16 ep = mdev->ep_address[channel]; - - if (start_sync_ep(mdev->usb_device, ep) < 0) - dev_warn(dev, "sync for ep%02x failed", ep); - } - return 0; -} - -/** - * hdm_request_netinfo - request network information - * @iface: pointer to interface - * @channel: channel ID - * - * This is used as trigger to set up the link status timer that - * polls for the NI state of the INIC every 2 seconds. - * - */ -static void hdm_request_netinfo(struct most_interface *iface, int channel, - void (*on_netinfo)(struct most_interface *, - unsigned char, - unsigned char *)) -{ - struct most_dev *mdev = to_mdev(iface); - - mdev->on_netinfo = on_netinfo; - if (!on_netinfo) - return; - - mdev->link_stat_timer.expires = jiffies + HZ; - mod_timer(&mdev->link_stat_timer, mdev->link_stat_timer.expires); -} - -/** - * link_stat_timer_handler - schedule work obtaining mac address and link status - * @data: pointer to USB device instance - * - * The handler runs in interrupt context. That's why we need to defer the - * tasks to a work queue. - */ -static void link_stat_timer_handler(struct timer_list *t) -{ - struct most_dev *mdev = from_timer(mdev, t, link_stat_timer); - - schedule_work(&mdev->poll_work_obj); - mdev->link_stat_timer.expires = jiffies + (2 * HZ); - add_timer(&mdev->link_stat_timer); -} - -/** - * wq_netinfo - work queue function to deliver latest networking information - * @wq_obj: object that holds data for our deferred work to do - * - * This retrieves the network interface status of the USB INIC - */ -static void wq_netinfo(struct work_struct *wq_obj) -{ - struct most_dev *mdev = to_mdev_from_work(wq_obj); - struct usb_device *usb_device = mdev->usb_device; - struct device *dev = &usb_device->dev; - u16 hi, mi, lo, link; - u8 hw_addr[6]; - - if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_HI, &hi)) { - dev_err(dev, "Vendor request 'hw_addr_hi' failed\n"); - return; - } - - if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_MI, &mi)) { - dev_err(dev, "Vendor request 'hw_addr_mid' failed\n"); - return; - } - - if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_LO, &lo)) { - dev_err(dev, "Vendor request 'hw_addr_low' failed\n"); - return; - } - - if (drci_rd_reg(usb_device, DRCI_REG_NI_STATE, &link)) { - dev_err(dev, "Vendor request 'link status' failed\n"); - return; - } - - hw_addr[0] = hi >> 8; - hw_addr[1] = hi; - hw_addr[2] = mi >> 8; - hw_addr[3] = mi; - hw_addr[4] = lo >> 8; - hw_addr[5] = lo; - - if (mdev->on_netinfo) - mdev->on_netinfo(&mdev->iface, link, hw_addr); -} - -/** - * wq_clear_halt - work queue function - * @wq_obj: work_struct object to execute - * - * This sends a clear_halt to the given USB pipe. - */ -static void wq_clear_halt(struct work_struct *wq_obj) -{ - struct clear_hold_work *clear_work = to_clear_hold_work(wq_obj); - struct most_dev *mdev = clear_work->mdev; - unsigned int channel = clear_work->channel; - int pipe = clear_work->pipe; - int snd_pipe; - int peer; - - mutex_lock(&mdev->io_mutex); - most_stop_enqueue(&mdev->iface, channel); - usb_kill_anchored_urbs(&mdev->busy_urbs[channel]); - if (usb_clear_halt(mdev->usb_device, pipe)) - dev_warn(&mdev->usb_device->dev, "Failed to reset endpoint.\n"); - - /* If the functional Stall condition has been set on an - * asynchronous rx channel, we need to clear the tx channel - * too, since the hardware runs its clean-up sequence on both - * channels, as they are physically one on the network. - * - * The USB interface that exposes the asynchronous channels - * contains always two endpoints, and two only. - */ - if (mdev->conf[channel].data_type == MOST_CH_ASYNC && - mdev->conf[channel].direction == MOST_CH_RX) { - if (channel == 0) - peer = 1; - else - peer = 0; - snd_pipe = usb_sndbulkpipe(mdev->usb_device, - mdev->ep_address[peer]); - usb_clear_halt(mdev->usb_device, snd_pipe); - } - mdev->is_channel_healthy[channel] = true; - most_resume_enqueue(&mdev->iface, channel); - mutex_unlock(&mdev->io_mutex); -} - -/** - * hdm_usb_fops - file operation table for USB driver - */ -static const struct file_operations hdm_usb_fops = { - .owner = THIS_MODULE, -}; - -/** - * usb_device_id - ID table for HCD device probing - */ -static const struct usb_device_id usbid[] = { - { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_BRDG), }, - { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81118), }, - { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81119), }, - { USB_DEVICE(USB_VENDOR_ID_SMSC, USB_DEV_ID_OS81210), }, - { } /* Terminating entry */ -}; - -struct regs { - const char *name; - u16 reg; -}; - -static const struct regs ro_regs[] = { - { "ni_state", DRCI_REG_NI_STATE }, - { "packet_bandwidth", DRCI_REG_PACKET_BW }, - { "node_address", DRCI_REG_NODE_ADDR }, - { "node_position", DRCI_REG_NODE_POS }, -}; - -static const struct regs rw_regs[] = { - { "mep_filter", DRCI_REG_MEP_FILTER }, - { "mep_hash0", DRCI_REG_HASH_TBL0 }, - { "mep_hash1", DRCI_REG_HASH_TBL1 }, - { "mep_hash2", DRCI_REG_HASH_TBL2 }, - { "mep_hash3", DRCI_REG_HASH_TBL3 }, - { "mep_eui48_hi", DRCI_REG_HW_ADDR_HI }, - { "mep_eui48_mi", DRCI_REG_HW_ADDR_MI }, - { "mep_eui48_lo", DRCI_REG_HW_ADDR_LO }, -}; - -static int get_stat_reg_addr(const struct regs *regs, int size, - const char *name, u16 *reg_addr) -{ - int i; - - for (i = 0; i < size; i++) { - if (sysfs_streq(name, regs[i].name)) { - *reg_addr = regs[i].reg; - return 0; - } - } - return -EINVAL; -} - -#define get_static_reg_addr(regs, name, reg_addr) \ - get_stat_reg_addr(regs, ARRAY_SIZE(regs), name, reg_addr) - -static ssize_t value_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - const char *name = attr->attr.name; - struct most_dci_obj *dci_obj = to_dci_obj(dev); - u16 val; - u16 reg_addr; - int err; - - if (sysfs_streq(name, "arb_address")) - return snprintf(buf, PAGE_SIZE, "%04x\n", dci_obj->reg_addr); - - if (sysfs_streq(name, "arb_value")) - reg_addr = dci_obj->reg_addr; - else if (get_static_reg_addr(ro_regs, name, ®_addr) && - get_static_reg_addr(rw_regs, name, ®_addr)) - return -EINVAL; - - err = drci_rd_reg(dci_obj->usb_device, reg_addr, &val); - if (err < 0) - return err; - - return snprintf(buf, PAGE_SIZE, "%04x\n", val); -} - -static ssize_t value_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - u16 val; - u16 reg_addr; - const char *name = attr->attr.name; - struct most_dci_obj *dci_obj = to_dci_obj(dev); - struct usb_device *usb_dev = dci_obj->usb_device; - int err; - - err = kstrtou16(buf, 16, &val); - if (err) - return err; - - if (sysfs_streq(name, "arb_address")) { - dci_obj->reg_addr = val; - return count; - } - - if (sysfs_streq(name, "arb_value")) - err = drci_wr_reg(usb_dev, dci_obj->reg_addr, val); - else if (sysfs_streq(name, "sync_ep")) - err = start_sync_ep(usb_dev, val); - else if (!get_static_reg_addr(rw_regs, name, ®_addr)) - err = drci_wr_reg(usb_dev, reg_addr, val); - else - return -EINVAL; - - if (err < 0) - return err; - - return count; -} - -static DEVICE_ATTR(ni_state, 0444, value_show, NULL); -static DEVICE_ATTR(packet_bandwidth, 0444, value_show, NULL); -static DEVICE_ATTR(node_address, 0444, value_show, NULL); -static DEVICE_ATTR(node_position, 0444, value_show, NULL); -static DEVICE_ATTR(sync_ep, 0200, NULL, value_store); -static DEVICE_ATTR(mep_filter, 0644, value_show, value_store); -static DEVICE_ATTR(mep_hash0, 0644, value_show, value_store); -static DEVICE_ATTR(mep_hash1, 0644, value_show, value_store); -static DEVICE_ATTR(mep_hash2, 0644, value_show, value_store); -static DEVICE_ATTR(mep_hash3, 0644, value_show, value_store); -static DEVICE_ATTR(mep_eui48_hi, 0644, value_show, value_store); -static DEVICE_ATTR(mep_eui48_mi, 0644, value_show, value_store); -static DEVICE_ATTR(mep_eui48_lo, 0644, value_show, value_store); -static DEVICE_ATTR(arb_address, 0644, value_show, value_store); -static DEVICE_ATTR(arb_value, 0644, value_show, value_store); - -static struct attribute *dci_attrs[] = { - &dev_attr_ni_state.attr, - &dev_attr_packet_bandwidth.attr, - &dev_attr_node_address.attr, - &dev_attr_node_position.attr, - &dev_attr_sync_ep.attr, - &dev_attr_mep_filter.attr, - &dev_attr_mep_hash0.attr, - &dev_attr_mep_hash1.attr, - &dev_attr_mep_hash2.attr, - &dev_attr_mep_hash3.attr, - &dev_attr_mep_eui48_hi.attr, - &dev_attr_mep_eui48_mi.attr, - &dev_attr_mep_eui48_lo.attr, - &dev_attr_arb_address.attr, - &dev_attr_arb_value.attr, - NULL, -}; - -ATTRIBUTE_GROUPS(dci); - -static void release_dci(struct device *dev) -{ - struct most_dci_obj *dci = to_dci_obj(dev); - - put_device(dev->parent); - kfree(dci); -} - -static void release_mdev(struct device *dev) -{ - struct most_dev *mdev = to_mdev_from_dev(dev); - - kfree(mdev); -} -/** - * hdm_probe - probe function of USB device driver - * @interface: Interface of the attached USB device - * @id: Pointer to the USB ID table. - * - * This allocates and initializes the device instance, adds the new - * entry to the internal list, scans the USB descriptors and registers - * the interface with the core. - * Additionally, the DCI objects are created and the hardware is sync'd. - * - * Return 0 on success. In case of an error a negative number is returned. - */ -static int -hdm_probe(struct usb_interface *interface, const struct usb_device_id *id) -{ - struct usb_host_interface *usb_iface_desc = interface->cur_altsetting; - struct usb_device *usb_dev = interface_to_usbdev(interface); - struct device *dev = &usb_dev->dev; - struct most_dev *mdev; - unsigned int i; - unsigned int num_endpoints; - struct most_channel_capability *tmp_cap; - struct usb_endpoint_descriptor *ep_desc; - int ret = -ENOMEM; - - mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); - if (!mdev) - return -ENOMEM; - - usb_set_intfdata(interface, mdev); - num_endpoints = usb_iface_desc->desc.bNumEndpoints; - if (num_endpoints > MAX_NUM_ENDPOINTS) { - kfree(mdev); - return -EINVAL; - } - mutex_init(&mdev->io_mutex); - INIT_WORK(&mdev->poll_work_obj, wq_netinfo); - timer_setup(&mdev->link_stat_timer, link_stat_timer_handler, 0); - - mdev->usb_device = usb_dev; - mdev->link_stat_timer.expires = jiffies + (2 * HZ); - - mdev->iface.mod = hdm_usb_fops.owner; - mdev->iface.dev = &mdev->dev; - mdev->iface.driver_dev = &interface->dev; - mdev->iface.interface = ITYPE_USB; - mdev->iface.configure = hdm_configure_channel; - mdev->iface.request_netinfo = hdm_request_netinfo; - mdev->iface.enqueue = hdm_enqueue; - mdev->iface.poison_channel = hdm_poison_channel; - mdev->iface.dma_alloc = hdm_dma_alloc; - mdev->iface.dma_free = hdm_dma_free; - mdev->iface.description = mdev->description; - mdev->iface.num_channels = num_endpoints; - - snprintf(mdev->description, sizeof(mdev->description), - "%d-%s:%d.%d", - usb_dev->bus->busnum, - usb_dev->devpath, - usb_dev->config->desc.bConfigurationValue, - usb_iface_desc->desc.bInterfaceNumber); - - mdev->dev.init_name = mdev->description; - mdev->dev.parent = &interface->dev; - mdev->dev.release = release_mdev; - mdev->conf = kcalloc(num_endpoints, sizeof(*mdev->conf), GFP_KERNEL); - if (!mdev->conf) - goto err_free_mdev; - - mdev->cap = kcalloc(num_endpoints, sizeof(*mdev->cap), GFP_KERNEL); - if (!mdev->cap) - goto err_free_conf; - - mdev->iface.channel_vector = mdev->cap; - mdev->ep_address = - kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL); - if (!mdev->ep_address) - goto err_free_cap; - - mdev->busy_urbs = - kcalloc(num_endpoints, sizeof(*mdev->busy_urbs), GFP_KERNEL); - if (!mdev->busy_urbs) - goto err_free_ep_address; - - tmp_cap = mdev->cap; - for (i = 0; i < num_endpoints; i++) { - ep_desc = &usb_iface_desc->endpoint[i].desc; - mdev->ep_address[i] = ep_desc->bEndpointAddress; - mdev->padding_active[i] = false; - mdev->is_channel_healthy[i] = true; - - snprintf(&mdev->suffix[i][0], MAX_SUFFIX_LEN, "ep%02x", - mdev->ep_address[i]); - - tmp_cap->name_suffix = &mdev->suffix[i][0]; - tmp_cap->buffer_size_packet = MAX_BUF_SIZE; - tmp_cap->buffer_size_streaming = MAX_BUF_SIZE; - tmp_cap->num_buffers_packet = BUF_CHAIN_SIZE; - tmp_cap->num_buffers_streaming = BUF_CHAIN_SIZE; - tmp_cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC | - MOST_CH_ISOC | MOST_CH_SYNC; - if (usb_endpoint_dir_in(ep_desc)) - tmp_cap->direction = MOST_CH_RX; - else - tmp_cap->direction = MOST_CH_TX; - tmp_cap++; - init_usb_anchor(&mdev->busy_urbs[i]); - spin_lock_init(&mdev->channel_lock[i]); - } - dev_dbg(dev, "claimed gadget: Vendor=%4.4x ProdID=%4.4x Bus=%02x Device=%02x\n", - le16_to_cpu(usb_dev->descriptor.idVendor), - le16_to_cpu(usb_dev->descriptor.idProduct), - usb_dev->bus->busnum, - usb_dev->devnum); - - dev_dbg(dev, "device path: /sys/bus/usb/devices/%d-%s:%d.%d\n", - usb_dev->bus->busnum, - usb_dev->devpath, - usb_dev->config->desc.bConfigurationValue, - usb_iface_desc->desc.bInterfaceNumber); - - ret = most_register_interface(&mdev->iface); - if (ret) - goto err_free_busy_urbs; - - mutex_lock(&mdev->io_mutex); - if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 || - le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81119 || - le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81210) { - mdev->dci = kzalloc(sizeof(*mdev->dci), GFP_KERNEL); - if (!mdev->dci) { - mutex_unlock(&mdev->io_mutex); - most_deregister_interface(&mdev->iface); - ret = -ENOMEM; - goto err_free_busy_urbs; - } - - mdev->dci->dev.init_name = "dci"; - mdev->dci->dev.parent = get_device(mdev->iface.dev); - mdev->dci->dev.groups = dci_groups; - mdev->dci->dev.release = release_dci; - if (device_register(&mdev->dci->dev)) { - mutex_unlock(&mdev->io_mutex); - most_deregister_interface(&mdev->iface); - ret = -ENOMEM; - goto err_free_dci; - } - mdev->dci->usb_device = mdev->usb_device; - } - mutex_unlock(&mdev->io_mutex); - return 0; -err_free_dci: - put_device(&mdev->dci->dev); -err_free_busy_urbs: - kfree(mdev->busy_urbs); -err_free_ep_address: - kfree(mdev->ep_address); -err_free_cap: - kfree(mdev->cap); -err_free_conf: - kfree(mdev->conf); -err_free_mdev: - put_device(&mdev->dev); - return ret; -} - -/** - * hdm_disconnect - disconnect function of USB device driver - * @interface: Interface of the attached USB device - * - * This deregisters the interface with the core, removes the kernel timer - * and frees resources. - * - * Context: hub kernel thread - */ -static void hdm_disconnect(struct usb_interface *interface) -{ - struct most_dev *mdev = usb_get_intfdata(interface); - - mutex_lock(&mdev->io_mutex); - usb_set_intfdata(interface, NULL); - mdev->usb_device = NULL; - mutex_unlock(&mdev->io_mutex); - - del_timer_sync(&mdev->link_stat_timer); - cancel_work_sync(&mdev->poll_work_obj); - - if (mdev->dci) - device_unregister(&mdev->dci->dev); - most_deregister_interface(&mdev->iface); - - kfree(mdev->busy_urbs); - kfree(mdev->cap); - kfree(mdev->conf); - kfree(mdev->ep_address); - put_device(&mdev->dci->dev); - put_device(&mdev->dev); -} - -static int hdm_suspend(struct usb_interface *interface, pm_message_t message) -{ - struct most_dev *mdev = usb_get_intfdata(interface); - int i; - - mutex_lock(&mdev->io_mutex); - for (i = 0; i < mdev->iface.num_channels; i++) { - most_stop_enqueue(&mdev->iface, i); - usb_kill_anchored_urbs(&mdev->busy_urbs[i]); - } - mutex_unlock(&mdev->io_mutex); - return 0; -} - -static int hdm_resume(struct usb_interface *interface) -{ - struct most_dev *mdev = usb_get_intfdata(interface); - int i; - - mutex_lock(&mdev->io_mutex); - for (i = 0; i < mdev->iface.num_channels; i++) - most_resume_enqueue(&mdev->iface, i); - mutex_unlock(&mdev->io_mutex); - return 0; -} - -static struct usb_driver hdm_usb = { - .name = "hdm_usb", - .id_table = usbid, - .probe = hdm_probe, - .disconnect = hdm_disconnect, - .resume = hdm_resume, - .suspend = hdm_suspend, -}; - -module_usb_driver(hdm_usb); -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Christian Gromm "); -MODULE_DESCRIPTION("HDM_4_USB"); -- cgit v1.2.3 From 5bbd90550da8f7bdac769b5825597e67183c9411 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 2 Aug 2020 11:21:39 +0200 Subject: staging: most: fix up movement of USB driver When moving the most usb driver out of staging, we forgot to remove the subdirectory out of the staging Makefile as well. Fixes: 97a6f772f36b ("drivers: most: add USB adapter driver") Cc: Christian Gromm Reported-by: Michael Straube Link: https://lore.kernel.org/r/20200802092139.GA140088@kroah.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/most/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/staging/most') diff --git a/drivers/staging/most/Makefile b/drivers/staging/most/Makefile index a803a98654a8..7c10b84ebac0 100644 --- a/drivers/staging/most/Makefile +++ b/drivers/staging/most/Makefile @@ -6,4 +6,3 @@ obj-$(CONFIG_MOST_SOUND) += sound/ obj-$(CONFIG_MOST_VIDEO) += video/ obj-$(CONFIG_MOST_DIM2) += dim2/ obj-$(CONFIG_MOST_I2C) += i2c/ -obj-$(CONFIG_MOST_USB) += usb/ -- cgit v1.2.3