From patchwork Tue Jun 8 04:02:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 456447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B99DC4743E for ; Tue, 8 Jun 2021 04:03:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C46F60FE3 for ; Tue, 8 Jun 2021 04:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbhFHEFA (ORCPT ); Tue, 8 Jun 2021 00:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbhFHEE6 (ORCPT ); Tue, 8 Jun 2021 00:04:58 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5DA6C061787; Mon, 7 Jun 2021 21:02:52 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id a1so20133781lfr.12; Mon, 07 Jun 2021 21:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OHFz2XiGKzjMgGqDHw8Ln6pO4vzSXzZficuVDOKNoOo=; b=f26c1mSujkUX/ImJQ8SNUPBjZ5RnTP34UeX+xJK66/pAGejZI1PoCE/118wNiB7RFE Wd/ASO216UgvyczSNRZ+knpFOAXErUGW5UunOQla+i6ct2bOB2mF31u64LAeIibdQSOX C1ygTZl3bQSEDh7DZQRzTm5a0BCOTYhZHdL6YbvC0JKBaq951YfcekTWe8d8SqGUSymb XSia+eC+FinqIGjxMV6fJlV2R6OnNc4+9G+IrsJgFAa+CK4yWA/VUYO9ciqhk21CS2YA N0BJi7RNKKKGwfpgWZPp1Tpq6ijddtLnkDEPKB5FjtoKZOBwsXtWer//aN3ctX+H5pw/ Jdxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OHFz2XiGKzjMgGqDHw8Ln6pO4vzSXzZficuVDOKNoOo=; b=d3VFQirgCiw3sahAkArvouIcX3n3OJOGghhFv6diJs77Cd3Pa4awAsZRoYjX4Hon8a cvLZ6XzgzX1UdMqHzAk67AXcQ/z8XoGFMPjHKOkISu7V6xBcih9asq5fLww8qyUS8xEM 4lUrz995Gd15iHgH1ZGUNp0mOLDU7u1zbOMyWytrW6vFOKwcsg5QXTI3kZatS7dQaFTp Sq5c/YRS9TyglwomGgZDc35OB37iqLl4siOsPB5ukxVnRLhfcqEvVzu8T7moESMpbeBn kIody0XbEItMKuwnj53TY1mf8FhSwhtdAhfgGwYSfiRz4joK4/p055q1hhYwFK6d7bwc JVXA== X-Gm-Message-State: AOAM533fdM77YIj2GgAcDG/VpU//tO+SkH8/1AAVo1Ytgdu7gdKTFXEn aK3qYwvt0U8HTbV6z+TLAezqQLgj3uc= X-Google-Smtp-Source: ABdhPJwQJ8edDU0q6xED+wYi1hRWxoziQkwDjPeRu6yHOo+Lc/PEErEU3MdhJoHzJxqqd2hjNtfjOQ== X-Received: by 2002:a05:6512:32a5:: with SMTP id q5mr13439043lfe.171.1623124971147; Mon, 07 Jun 2021 21:02:51 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id l23sm1729096lfj.26.2021.06.07.21.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 21:02:50 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH 02/10] wwan_hwsim: add debugfs management interface Date: Tue, 8 Jun 2021 07:02:33 +0300 Message-Id: <20210608040241.10658-3-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210608040241.10658-1-ryazanov.s.a@gmail.com> References: <20210608040241.10658-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org wwan_hwsim creates and removes simulated control ports on module loading and unloading. It would be helpful to be able to create/remove devices and ports at run-time to trigger wwan port (un-)register actions without module reloading. Some simulator objects (e.g. ports) do not have the underling device and it is not possible to fully manage the simulator via sysfs. wwan_hsim intend for developers, so implement it as a self-contained debugfs based management interface. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_hwsim.c | 186 +++++++++++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 2 deletions(-) diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c index 96d25d7e5bb8..472cae544a2b 100644 --- a/drivers/net/wwan/wwan_hwsim.c +++ b/drivers/net/wwan/wwan_hwsim.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include static int wwan_hwsim_devsnum = 2; module_param_named(devices, wwan_hwsim_devsnum, int, 0444); @@ -22,6 +24,9 @@ MODULE_PARM_DESC(devices, "Number of simulated devices"); static struct class *wwan_hwsim_class; +static struct dentry *wwan_hwsim_debugfs_topdir; +static struct dentry *wwan_hwsim_debugfs_devcreate; + static DEFINE_SPINLOCK(wwan_hwsim_devs_lock); static LIST_HEAD(wwan_hwsim_devs); static unsigned int wwan_hwsim_dev_idx; @@ -30,6 +35,9 @@ struct wwan_hwsim_dev { struct list_head list; unsigned int id; struct device dev; + struct work_struct del_work; + struct dentry *debugfs_topdir; + struct dentry *debugfs_portcreate; spinlock_t ports_lock; /* Serialize ports creation/deletion */ unsigned int port_idx; struct list_head ports; @@ -40,6 +48,8 @@ struct wwan_hwsim_port { unsigned int id; struct wwan_hwsim_dev *dev; struct wwan_port *wwan; + struct work_struct del_work; + struct dentry *debugfs_topdir; enum { /* AT command parser state */ AT_PARSER_WAIT_A, AT_PARSER_WAIT_T, @@ -48,6 +58,12 @@ struct wwan_hwsim_port { } pstate; }; +static const struct file_operations wwan_hwsim_debugfs_portdestroy_fops; +static const struct file_operations wwan_hwsim_debugfs_portcreate_fops; +static const struct file_operations wwan_hwsim_debugfs_devdestroy_fops; +static void wwan_hwsim_port_del_work(struct work_struct *work); +static void wwan_hwsim_dev_del_work(struct work_struct *work); + static int wwan_hwsim_port_start(struct wwan_port *wport) { struct wwan_hwsim_port *port = wwan_port_get_drvdata(wport); @@ -139,6 +155,7 @@ static const struct wwan_port_ops wwan_hwsim_port_ops = { static struct wwan_hwsim_port *wwan_hwsim_port_new(struct wwan_hwsim_dev *dev) { struct wwan_hwsim_port *port; + char name[0x10]; int err; port = kzalloc(sizeof(*port), GFP_KERNEL); @@ -159,6 +176,13 @@ static struct wwan_hwsim_port *wwan_hwsim_port_new(struct wwan_hwsim_dev *dev) goto err_free_port; } + INIT_WORK(&port->del_work, wwan_hwsim_port_del_work); + + snprintf(name, sizeof(name), "port%u", port->id); + port->debugfs_topdir = debugfs_create_dir(name, dev->debugfs_topdir); + debugfs_create_file("destroy", 0200, port->debugfs_topdir, port, + &wwan_hwsim_debugfs_portdestroy_fops); + return port; err_free_port: @@ -169,10 +193,34 @@ static struct wwan_hwsim_port *wwan_hwsim_port_new(struct wwan_hwsim_dev *dev) static void wwan_hwsim_port_del(struct wwan_hwsim_port *port) { + debugfs_remove(port->debugfs_topdir); + + /* Make sure that there is no pending deletion work */ + if (current_work() != &port->del_work) + cancel_work_sync(&port->del_work); + wwan_remove_port(port->wwan); kfree(port); } +static void wwan_hwsim_port_del_work(struct work_struct *work) +{ + struct wwan_hwsim_port *port = + container_of(work, typeof(*port), del_work); + struct wwan_hwsim_dev *dev = port->dev; + + spin_lock(&dev->ports_lock); + if (list_empty(&port->list)) { + /* Someone else deleting port at the moment */ + spin_unlock(&dev->ports_lock); + return; + } + list_del_init(&port->list); + spin_unlock(&dev->ports_lock); + + wwan_hwsim_port_del(port); +} + static void wwan_hwsim_dev_release(struct device *sysdev) { struct wwan_hwsim_dev *dev = container_of(sysdev, typeof(*dev), dev); @@ -204,6 +252,17 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void) if (err) goto err_free_dev; + INIT_WORK(&dev->del_work, wwan_hwsim_dev_del_work); + + dev->debugfs_topdir = debugfs_create_dir(dev_name(&dev->dev), + wwan_hwsim_debugfs_topdir); + debugfs_create_file("destroy", 0200, dev->debugfs_topdir, dev, + &wwan_hwsim_debugfs_devdestroy_fops); + dev->debugfs_portcreate = + debugfs_create_file("portcreate", 0200, + dev->debugfs_topdir, dev, + &wwan_hwsim_debugfs_portcreate_fops); + return dev; err_free_dev: @@ -214,23 +273,136 @@ static struct wwan_hwsim_dev *wwan_hwsim_dev_new(void) static void wwan_hwsim_dev_del(struct wwan_hwsim_dev *dev) { + debugfs_remove(dev->debugfs_portcreate); /* Avoid new ports */ + spin_lock(&dev->ports_lock); while (!list_empty(&dev->ports)) { struct wwan_hwsim_port *port; port = list_first_entry(&dev->ports, struct wwan_hwsim_port, list); - list_del(&port->list); + list_del_init(&port->list); spin_unlock(&dev->ports_lock); wwan_hwsim_port_del(port); spin_lock(&dev->ports_lock); } spin_unlock(&dev->ports_lock); + debugfs_remove(dev->debugfs_topdir); + + /* Make sure that there is no pending deletion work */ + if (current_work() != &dev->del_work) + cancel_work_sync(&dev->del_work); + device_unregister(&dev->dev); /* Memory will be freed in the device release callback */ } +static void wwan_hwsim_dev_del_work(struct work_struct *work) +{ + struct wwan_hwsim_dev *dev = container_of(work, typeof(*dev), del_work); + + spin_lock(&wwan_hwsim_devs_lock); + if (list_empty(&dev->list)) { + /* Someone else deleting device at the moment */ + spin_unlock(&wwan_hwsim_devs_lock); + return; + } + list_del_init(&dev->list); + spin_unlock(&wwan_hwsim_devs_lock); + + wwan_hwsim_dev_del(dev); +} + +static ssize_t wwan_hwsim_debugfs_portdestroy_write(struct file *file, + const char __user *usrbuf, + size_t count, loff_t *ppos) +{ + struct wwan_hwsim_port *port = file->private_data; + + /* We can not delete port here since it will cause a deadlock due to + * waiting this callback to finish in the debugfs_remove() call. So, + * use workqueue. + */ + schedule_work(&port->del_work); + + return count; +} + +static const struct file_operations wwan_hwsim_debugfs_portdestroy_fops = { + .write = wwan_hwsim_debugfs_portdestroy_write, + .open = simple_open, + .llseek = noop_llseek, +}; + +static ssize_t wwan_hwsim_debugfs_portcreate_write(struct file *file, + const char __user *usrbuf, + size_t count, loff_t *ppos) +{ + struct wwan_hwsim_dev *dev = file->private_data; + struct wwan_hwsim_port *port; + + port = wwan_hwsim_port_new(dev); + if (IS_ERR(port)) + return PTR_ERR(port); + + spin_lock(&dev->ports_lock); + list_add_tail(&port->list, &dev->ports); + spin_unlock(&dev->ports_lock); + + return count; +} + +static const struct file_operations wwan_hwsim_debugfs_portcreate_fops = { + .write = wwan_hwsim_debugfs_portcreate_write, + .open = simple_open, + .llseek = noop_llseek, +}; + +static ssize_t wwan_hwsim_debugfs_devdestroy_write(struct file *file, + const char __user *usrbuf, + size_t count, loff_t *ppos) +{ + struct wwan_hwsim_dev *dev = file->private_data; + + /* We can not delete device here since it will cause a deadlock due to + * waiting this callback to finish in the debugfs_remove() call. So, + * use workqueue. + */ + schedule_work(&dev->del_work); + + return count; +} + +static const struct file_operations wwan_hwsim_debugfs_devdestroy_fops = { + .write = wwan_hwsim_debugfs_devdestroy_write, + .open = simple_open, + .llseek = noop_llseek, +}; + +static ssize_t wwan_hwsim_debugfs_devcreate_write(struct file *file, + const char __user *usrbuf, + size_t count, loff_t *ppos) +{ + struct wwan_hwsim_dev *dev; + + dev = wwan_hwsim_dev_new(); + if (IS_ERR(dev)) + return PTR_ERR(dev); + + spin_lock(&wwan_hwsim_devs_lock); + list_add_tail(&dev->list, &wwan_hwsim_devs); + spin_unlock(&wwan_hwsim_devs_lock); + + return count; +} + +static const struct file_operations wwan_hwsim_debugfs_devcreate_fops = { + .write = wwan_hwsim_debugfs_devcreate_write, + .open = simple_open, + .llseek = noop_llseek, +}; + static int __init wwan_hwsim_init_devs(void) { struct wwan_hwsim_dev *dev; @@ -272,7 +444,7 @@ static void wwan_hwsim_free_devs(void) while (!list_empty(&wwan_hwsim_devs)) { dev = list_first_entry(&wwan_hwsim_devs, struct wwan_hwsim_dev, list); - list_del(&dev->list); + list_del_init(&dev->list); spin_unlock(&wwan_hwsim_devs_lock); wwan_hwsim_dev_del(dev); spin_lock(&wwan_hwsim_devs_lock); @@ -291,6 +463,12 @@ static int __init wwan_hwsim_init(void) if (IS_ERR(wwan_hwsim_class)) return PTR_ERR(wwan_hwsim_class); + wwan_hwsim_debugfs_topdir = debugfs_create_dir("wwan_hwsim", NULL); + wwan_hwsim_debugfs_devcreate = + debugfs_create_file("devcreate", 0200, + wwan_hwsim_debugfs_topdir, NULL, + &wwan_hwsim_debugfs_devcreate_fops); + err = wwan_hwsim_init_devs(); if (err) goto err_clean_devs; @@ -299,6 +477,7 @@ static int __init wwan_hwsim_init(void) err_clean_devs: wwan_hwsim_free_devs(); + debugfs_remove(wwan_hwsim_debugfs_topdir); class_destroy(wwan_hwsim_class); return err; @@ -306,7 +485,10 @@ static int __init wwan_hwsim_init(void) static void __exit wwan_hwsim_exit(void) { + debugfs_remove(wwan_hwsim_debugfs_devcreate); /* Avoid new devs */ wwan_hwsim_free_devs(); + flush_scheduled_work(); /* Wait deletion works completion */ + debugfs_remove(wwan_hwsim_debugfs_topdir); class_destroy(wwan_hwsim_class); } From patchwork Tue Jun 8 04:02:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 456443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88141C4743E for ; Tue, 8 Jun 2021 04:04:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F1C16120F for ; Tue, 8 Jun 2021 04:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbhFHEFz (ORCPT ); Tue, 8 Jun 2021 00:05:55 -0400 Received: from mail-lf1-f45.google.com ([209.85.167.45]:37659 "EHLO mail-lf1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbhFHEFz (ORCPT ); Tue, 8 Jun 2021 00:05:55 -0400 Received: by mail-lf1-f45.google.com with SMTP id f11so29739329lfq.4; Mon, 07 Jun 2021 21:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2T7mIKspOgOa6iTte+bN4zWzDmpXAFYCXaoc2hPlut8=; b=kTFV8DhKMJsh1Yus1Ow1Db/nNszmSRADk8rAAwc/E2XYFMMmZqRQ2AfF5e/VO8mwJY GZkRjgfKv37q2f8BSobmwrTbWCHdIxBeB5dgUaKPMtQUqTUqO1RmtNI0QcRlguGz5EmW Fd2GF+x0YI6miZQf+gCqc+AUQWhJwCJU6pmaW76DrRbTfhCAfSIP+R/1iiS6zHLq67km PocKRfirjesACDsRD9bQnwZgJ/q8mRhBHv7akoOZMk0mH1HZgKgZ1iFg9VCGx4ITJHEW 8QKtPlZToaW92W4Yt8HRKcyaGJKCv10I7V92lustFmRVI0QifJFXLDZ8UvnmWBdSBQG9 N7rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2T7mIKspOgOa6iTte+bN4zWzDmpXAFYCXaoc2hPlut8=; b=O0k166V0nKBSxAfWdtoKp9bYWC93ufOALJVEq35iKxAo5sbhmy2sp98z/hq2Sy2OYO fhsQTljUBsT8oxK6e4aYMEmfYTZHFnK9F0+gL5yonal84WSmlFnd5Mt4INhs0+6hlaxq chn9wmmuly0btwr3byrafSbYyHxzSpP04WOzCd9+0dzbB/SmCG0Z+5+VZ+5bDp/SWeqV CMa/TnvKhBGyDsvHx69ReG1JyWIWLBLEv7ndOjg/QiPhNnMw4SYXGOCbJ6atuF3ncB+8 5f9Ke0LXkkXV2+fpIP6Ymy4Cm/PkMRRkaH91zFwWg766A4waU1fKm6FQE6un7MfcfEJL AgKQ== X-Gm-Message-State: AOAM5314uqq5er7AGRgHGCcVNfVlJmtXwEaIprwcQj3Ybx7SrDx4MBq5 CkKSQIw5QIhmq0m0161qVizNKPjeFHg= X-Google-Smtp-Source: ABdhPJzXt8hdW4gKAPUGP3uhN1h4UA2IIXI01v30gewJbphkSxI1315OBuOEUukvter7mU7Bi+3xBg== X-Received: by 2002:ac2:4c0a:: with SMTP id t10mr13415850lfq.401.1623124972121; Mon, 07 Jun 2021 21:02:52 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id l23sm1729096lfj.26.2021.06.07.21.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 21:02:51 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH 03/10] net: wwan: make WWAN_PORT_MAX meaning less surprised Date: Tue, 8 Jun 2021 07:02:34 +0300 Message-Id: <20210608040241.10658-4-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210608040241.10658-1-ryazanov.s.a@gmail.com> References: <20210608040241.10658-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It is quite unusual when some value can not be equal to a defined range max value. Also most subsystems defines FOO_TYPE_MAX as a maximum valid value. So turn the WAN_PORT_MAX meaning from the number of supported port types to the maximum valid port type. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 2 +- include/linux/wwan.h | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 6e8f19c71a9e..632ff86398ac 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -250,7 +250,7 @@ struct wwan_port *wwan_create_port(struct device *parent, struct wwan_port *port; int minor, err = -ENOMEM; - if (type >= WWAN_PORT_MAX || !ops) + if (type > WWAN_PORT_MAX || !ops) return ERR_PTR(-EINVAL); /* A port is always a child of a WWAN device, retrieve (allocate or diff --git a/include/linux/wwan.h b/include/linux/wwan.h index 7216c114d758..fa33cc16d931 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -15,8 +15,10 @@ * @WWAN_PORT_QMI: Qcom modem/MSM interface for modem control * @WWAN_PORT_QCDM: Qcom Modem diagnostic interface * @WWAN_PORT_FIREHOSE: XML based command protocol - * @WWAN_PORT_UNKNOWN: Unknown port type - * @WWAN_PORT_MAX: Number of supported port types + * + * @WWAN_PORT_MAX: Highest supported port types + * @WWAN_PORT_UNKNOWN: Special value to indicate an unknown port type + * @__WWAN_PORT_MAX: Internal use */ enum wwan_port_type { WWAN_PORT_AT, @@ -24,8 +26,12 @@ enum wwan_port_type { WWAN_PORT_QMI, WWAN_PORT_QCDM, WWAN_PORT_FIREHOSE, + + /* Add new port types above this line */ + + __WWAN_PORT_MAX, + WWAN_PORT_MAX = __WWAN_PORT_MAX - 1, WWAN_PORT_UNKNOWN, - WWAN_PORT_MAX = WWAN_PORT_UNKNOWN, }; struct wwan_port; From patchwork Tue Jun 8 04:02:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 456444 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 557EEC4743D for ; Tue, 8 Jun 2021 04:03:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32E1260FE3 for ; Tue, 8 Jun 2021 04:03:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbhFHEFr (ORCPT ); Tue, 8 Jun 2021 00:05:47 -0400 Received: from mail-lj1-f178.google.com ([209.85.208.178]:37467 "EHLO mail-lj1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbhFHEFq (ORCPT ); Tue, 8 Jun 2021 00:05:46 -0400 Received: by mail-lj1-f178.google.com with SMTP id e2so25129057ljk.4; Mon, 07 Jun 2021 21:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pPIdebRJBNO3bofmM1cHoD9YdsleLfcIV4SSBMyfI6g=; b=rg/D2oX5HGQDJEupPTB3i6Eoyd9mDK4JGLBxP4Z6oOUYj0HnOcD/eQQb+m0yJvor4Y FK+3nT5vcPqC7sYCpOa9IOv0sXQy8pAZ+qsMaKR9Oh6S5bzd5laWK0pfBQJFrHVXedF9 KTT3ZIzsgrF1KXmg0p0L+98WQ3/gKh+xL6+4Ci4XjlyvX+efocMrtbJNZyD+ElhThpB7 V7VZw+SfzqKsu/AOAQANYuzFU7bGedhrXZyr4qk9NaME6ymJQ0THGoShkNuhnmxEmG7n HDOb0ICRNNmiGlvC3dqZFMHhGWkGLiEa7f4FwoqKfRDVKVnLZED9NE6ovcls0Yt/SCCA fVfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pPIdebRJBNO3bofmM1cHoD9YdsleLfcIV4SSBMyfI6g=; b=JX7C0uvwvQ2yirb1Rhm/hTpJ9rg93WTyGUa57Px/2dd6rDOCAe2aLqhlZ6T5OPE7zc WpT5glWgGjm9DBqTFUZ7S7NrRHP0kqdYAgYo3ThCDZHlglgFXMWyVPk6z7zdud34Q60a cW3fZXC0z6JiVYdkCQtvXy3VrtgwprHjw//GQ34v9AKXhJK41tpSZx05omr8wMqrqF8O J4T3BcbXhJocDf+2l3lGoE2Rf/jf6xpSOM8/jhA1KU6XNSJ5bYv3/2RRtKR85kZjncmZ ddVlijbKMXUV0Q+X5TGYUiOLJeFC09eRJRcNrKyi+rxX90evRfJrlgz8SrOGgzOQ0aFC J11g== X-Gm-Message-State: AOAM533jAE6+p8QSZQWCaCTQp193b//6zTRpQefwLRX7JdshBfQ6RAS3 8uBi+eO0Lg5YoDp7wTiGrNw= X-Google-Smtp-Source: ABdhPJxgXAaYKkR7I9XHwAi+zyAKhcNbXXSRMFzBworIkFYk/aAPJ0jL7PAZDHBHXsLqDjC2yq33ZA== X-Received: by 2002:a2e:b4b0:: with SMTP id q16mr16790107ljm.434.1623124973054; Mon, 07 Jun 2021 21:02:53 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id l23sm1729096lfj.26.2021.06.07.21.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 21:02:52 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH 04/10] net: wwan: core: init port type string array using enum values Date: Tue, 8 Jun 2021 07:02:35 +0300 Message-Id: <20210608040241.10658-5-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210608040241.10658-1-ryazanov.s.a@gmail.com> References: <20210608040241.10658-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This array is indexed by port type. Make it self-descriptive by using the port type enum values as indices in the array initializer. Signed-off-by: Sergey Ryazanov Reviewed-by: Loic Poulain --- drivers/net/wwan/wwan_core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 632ff86398ac..97d77b06d222 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -184,13 +184,12 @@ static void wwan_remove_dev(struct wwan_device *wwandev) /* ------- WWAN port management ------- */ -/* Keep aligned with wwan_port_type enum */ -static const char * const wwan_port_type_str[] = { - "AT", - "MBIM", - "QMI", - "QCDM", - "FIREHOSE" +static const char * const wwan_port_type_str[WWAN_PORT_MAX + 1] = { + [WWAN_PORT_AT] = "AT", + [WWAN_PORT_MBIM] = "MBIM", + [WWAN_PORT_QMI] = "QMI", + [WWAN_PORT_QCDM] = "QCDM", + [WWAN_PORT_FIREHOSE] = "FIREHOSE", }; static ssize_t type_show(struct device *dev, struct device_attribute *attr, From patchwork Tue Jun 8 04:02:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 456446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E508DC4743D for ; Tue, 8 Jun 2021 04:03:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4A1D6120F for ; Tue, 8 Jun 2021 04:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230293AbhFHEFG (ORCPT ); Tue, 8 Jun 2021 00:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230223AbhFHEFF (ORCPT ); Tue, 8 Jun 2021 00:05:05 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 868F6C061789; Mon, 7 Jun 2021 21:02:56 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id s22so4688017ljg.5; Mon, 07 Jun 2021 21:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lVnV9bzdy6uuIzlfqAADzTp6JOA579xDrvynPNNeP4g=; b=G3CeIgUYoBiBPFOc2fzqb5S8GPmuhTnsNMc+bJOQ9hQ27dg4qluBT2HOH62hO3BHb6 K2yq0hvG4kb4OsvHCeCGZ3chkFfhv2g1p+zrdq0BdWdfznFfjsy4Ckl++glp38mUASaX guKX7VYqIQFGEvFN+4pv7dfbhxxfxprPBLs8rLOVW8ZIcGNSqoGSUvdgY6EOupTs36RZ FE+lx2/mrT3ZUytfkHpHmY6nIrsi9FW2EMLGWP7eWDtALSoUcAg4O5T/zlMq+sDMle5e UqHHoQ/XYLd1nNnAdPCMvdn48zhcHpMwOVD4O1NIjmxh7gaADMzoZEEjEasJRlocijEj ApSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lVnV9bzdy6uuIzlfqAADzTp6JOA579xDrvynPNNeP4g=; b=LisP9HE0yNYcZOWRt62OoJmdA8J8ZW28zYhXUh6aoZUMiWRokT4saad3W2jaDxg6e/ NPwhbMBo7RUINOuHtqQCD0FBQtugXHaGeG+7453HkCCZGRJ91/krJCYMrKsUz2Vb9lH7 N0cFznDZ150en2adF6XqJEYhZveX7pkJyP+l5xd5zXPdesmjeAKMcO6YIAGaw9f0zNM5 CViJ6FGycO6Og+UV7gc/OP33TLHRiIg/2ThRfZ2F4WjsLINQ56MrrTop0Rnd1bkRzeBk GnAFoT3+hAphKCEGwClEdIRWobdVQI5CR5dukqbij1IiD3MNyCQWMlXqwKHWVHlO9A4U 3I+w== X-Gm-Message-State: AOAM531tn9C1kJWNX9TwYTN6LdyAvzuUFaDYNG8WRi8UvXJJgOY/lZA0 d5oQ0IFOgTqlieMY+KAcMjc= X-Google-Smtp-Source: ABdhPJxfZhVrT7KLAx9VFuVzf/hRu22kqRSq+2lmO/jC10K3bPeeJp4+qQMrwMuEgouyRND6fsnZAg== X-Received: by 2002:a05:651c:324:: with SMTP id b4mr16941663ljp.166.1623124974910; Mon, 07 Jun 2021 21:02:54 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id l23sm1729096lfj.26.2021.06.07.21.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 21:02:54 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH 06/10] net: wwan: core: make port names more user-friendly Date: Tue, 8 Jun 2021 07:02:37 +0300 Message-Id: <20210608040241.10658-7-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210608040241.10658-1-ryazanov.s.a@gmail.com> References: <20210608040241.10658-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org At the moment, the port name is allocated based on the parent device name, port id and the port type. Where the port id specifies nothing but the ports registration order and is only used to make the port name unique. Most likely, to configure a WWAN device, the user will look for a port of a specific type (e.g. AT port or MBIM port, etc.). The current naming scheme can make it difficult to find a port of a specific type. Consider a WWAN device that has 3 ports: AT port, MBIM port, and another one AT port. With the global port index, the port names will be: * wwan0p1at * wwan0p2mbim * wwan0p3at To find the MBIM port, user should know in advance the device ports composition (i.e. the user should know that the MBIM port is the 2nd one) or carefully examine the whole ports list. It is not unusual for USB modems to have a different composition, even if they are build on a same chipset. Moreover, some modems able to change the ports composition based on the user's configuration. All this makes port names fully unpredictable. To make naming more user-friendly, remove the global port id and enumerate ports by its type. E.g.: * wwan0p1at -> wwan0at0 * wwan0p2mbim -> wwan0mbim0 * wwan0p3at -> wwan0at1 With this naming scheme, the first AT port name will always be wwanXat0, the first MBIM port name will always be wwanXmbim0, etc. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 67 ++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index ba4392d71b80..2844b17a724c 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -33,12 +33,10 @@ static int wwan_major; * * @id: WWAN device unique ID. * @dev: Underlying device. - * @port_id: Current available port ID to pick. */ struct wwan_device { unsigned int id; struct device dev; - atomic_t port_id; }; /** @@ -258,6 +256,56 @@ static struct wwan_port *wwan_port_get_by_minor(unsigned int minor) return to_wwan_port(dev); } +/* Allocate and set unique name based on passed format + * + * Name allocation approach is highly inspired by the __dev_alloc_name() + * function. + * + * To avoid names collision, the caller must prevent the new port device + * registration as well as concurrent invocation of this function. + */ +static int __wwan_port_dev_assign_name(struct wwan_port *port, const char *fmt) +{ + struct wwan_device *wwandev = to_wwan_dev(port->dev.parent); + const unsigned int max_ports = PAGE_SIZE * 8; + struct class_dev_iter iter; + unsigned long *idmap; + struct device *dev; + char buf[0x20]; + int id; + + idmap = (unsigned long *)get_zeroed_page(GFP_KERNEL); + if (!idmap) + return -ENOMEM; + + /* Collect ids of same name format ports */ + class_dev_iter_init(&iter, wwan_class, NULL, &wwan_port_dev_type); + while ((dev = class_dev_iter_next(&iter))) { + if (dev->parent != &wwandev->dev) + continue; + if (sscanf(dev_name(dev), fmt, &id) != 1) + continue; + if (id < 0 || id >= max_ports) + continue; + set_bit(id, idmap); + } + class_dev_iter_exit(&iter); + + /* Allocate unique id */ + id = find_first_zero_bit(idmap, max_ports); + free_page((unsigned long)idmap); + + snprintf(buf, sizeof(buf), fmt, id); /* Name generation */ + + dev = device_find_child_by_name(&wwandev->dev, buf); + if (dev) { + put_device(dev); + return -ENFILE; + } + + return dev_set_name(&port->dev, buf); +} + struct wwan_port *wwan_create_port(struct device *parent, enum wwan_port_type type, const struct wwan_port_ops *ops, @@ -266,6 +314,7 @@ struct wwan_port *wwan_create_port(struct device *parent, struct wwan_device *wwandev; struct wwan_port *port; int minor, err = -ENOMEM; + char namefmt[0x20]; if (type > WWAN_PORT_MAX || !ops) return ERR_PTR(-EINVAL); @@ -300,12 +349,18 @@ struct wwan_port *wwan_create_port(struct device *parent, port->dev.devt = MKDEV(wwan_major, minor); dev_set_drvdata(&port->dev, drvdata); - /* create unique name based on wwan device id, port index and type */ - dev_set_name(&port->dev, "wwan%up%u%s", wwandev->id, - atomic_inc_return(&wwandev->port_id), - wwan_port_types[port->type].devsuf); + /* allocate unique name based on wwan device id, port type and number */ + snprintf(namefmt, sizeof(namefmt), "wwan%u%s%%d", wwandev->id, + wwan_port_types[port->type].devsuf); + /* Serialize ports registration */ + mutex_lock(&wwan_register_lock); + + __wwan_port_dev_assign_name(port, namefmt); err = device_register(&port->dev); + + mutex_unlock(&wwan_register_lock); + if (err) goto error_put_device; From patchwork Tue Jun 8 04:02:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 456442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81C22C48BCD for ; Tue, 8 Jun 2021 04:04:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67F3861249 for ; Tue, 8 Jun 2021 04:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbhFHEGA (ORCPT ); Tue, 8 Jun 2021 00:06:00 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:38411 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230481AbhFHEF7 (ORCPT ); Tue, 8 Jun 2021 00:05:59 -0400 Received: by mail-lf1-f44.google.com with SMTP id r5so29919923lfr.5; Mon, 07 Jun 2021 21:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P49wBkaDkamht0wn8kZscQTKx/D9qYCGtYJXiHNCtDE=; b=lcSN+Umc9GgwrvCbBZZQImUXPmJlL17VaxfHR4K0545GcFAqJqCZFOvx5NhwvpxPlB 7wLHuRgmXgHYuK13V9kBt8gBORJrfbb6fVD02PAUi3MgFbSYcATr2uIVlcE7EOB5nSSq sKV/838A7Cr8au9l4K7i0rUGCKizvqcwRrERvZ1mC0vSSQ4MSWeB8zqywwooOLUWRzG/ jgHqEsMUhO6Wqwf4VB8T98nD8pMAfsjWsPcV+jl16MRWBBa45HcwhZH3jKUwOxHHseRr 5AEZHXTL+4U4l/K5cwBsPoOD9J7EIGUIFd3r1dfUtvSKL7EQLZv3iR3sGFLIN7OTPDqO dWKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P49wBkaDkamht0wn8kZscQTKx/D9qYCGtYJXiHNCtDE=; b=ZcR1iTarjLrpqlIHp5Vzqo36MkQDaV7YeuqR2hakRloOzM0YBsFTZEzAEO9jY43QBm AZYrvgZesLHzY9AEJH0/GQjaQaBzhgtkD+g3Y3Ns5IwOi61FYqnh1tXbGWEnA+auVnnE htlZVOgB3XCIPnEbgl368CgevCOyT8pHgA6V/HxWlUPM/Zy29AgxDU7RtDU9ZkbZ9FjU aKzOdyzaQeKypMTH7fGsQOf41Voi5oh77WQevIOw2dvIM8GGNJW41IFiJuFeRJ12OEvQ 6Bg9oFbVddREzGdlvDefhVsIH0Mnl6tEW/n338X8JQoDB7u936TUwKTEFwlJwnQd6Q7n UR9Q== X-Gm-Message-State: AOAM530iuzEQSiVp97v4Q8x1QR1aq68/dzKJiYRJr3kYnWbZSeTueYVf r/2HAUp9WgXfQpeSAenUwko= X-Google-Smtp-Source: ABdhPJxliUFhZSLoP6zAle7JYsWSmZOfOptpPgsAFeL4YxUS0+fQmNmXUUije4EP8sSgCfUucEw7YQ== X-Received: by 2002:a05:6512:2186:: with SMTP id b6mr13480688lft.490.1623124975933; Mon, 07 Jun 2021 21:02:55 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id l23sm1729096lfj.26.2021.06.07.21.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 21:02:55 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH 07/10] net: wwan: core: expand ports number limit Date: Tue, 8 Jun 2021 07:02:38 +0300 Message-Id: <20210608040241.10658-8-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210608040241.10658-1-ryazanov.s.a@gmail.com> References: <20210608040241.10658-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, we limit the total ports number to 256. It is quite common for PBX or SMS gateway to be equipped with a lot of modems. In now days, a modem could have 2-4 control ports or even more, what only accelerates the ports exhausing rate. To avoid facing the port number limitation issue reports, increase the limit up the maximum number of minors (i.e. up to 1 << MINORBITS). Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 2844b17a724c..9346b2661eb3 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -14,7 +14,8 @@ #include #include -#define WWAN_MAX_MINORS 256 /* 256 minors allowed with register_chrdev() */ +/* Maximum number of minors in use */ +#define WWAN_MAX_MINORS (1 << MINORBITS) static DEFINE_MUTEX(wwan_register_lock); /* WWAN device create|remove lock */ static DEFINE_IDA(minors); /* minors for WWAN port chardevs */ @@ -634,7 +635,8 @@ static int __init wwan_init(void) return PTR_ERR(wwan_class); /* chrdev used for wwan ports */ - wwan_major = register_chrdev(0, "wwan_port", &wwan_port_fops); + wwan_major = __register_chrdev(0, 0, WWAN_MAX_MINORS, "wwan_port", + &wwan_port_fops); if (wwan_major < 0) { class_destroy(wwan_class); return wwan_major; @@ -645,7 +647,7 @@ static int __init wwan_init(void) static void __exit wwan_exit(void) { - unregister_chrdev(wwan_major, "wwan_port"); + __unregister_chrdev(wwan_major, 0, WWAN_MAX_MINORS, "wwan_port"); class_destroy(wwan_class); } From patchwork Tue Jun 8 04:02:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Ryazanov X-Patchwork-Id: 456445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50D3BC4743E for ; Tue, 8 Jun 2021 04:03:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 39C876124B for ; Tue, 8 Jun 2021 04:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbhFHEFK (ORCPT ); Tue, 8 Jun 2021 00:05:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbhFHEFJ (ORCPT ); Tue, 8 Jun 2021 00:05:09 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E232C061795; Mon, 7 Jun 2021 21:03:00 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id w33so29887881lfu.7; Mon, 07 Jun 2021 21:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zdX62WlQ3p8rs50GDVVp4jfIL+laVX6G6USVtA2GR9M=; b=g5pN/FchaU0RenbJFPXPQr4TpJMqLe+hFbEu9qXh/uAt5e+kClyVNjTVjWREYIPNTW baPT1dcPq35GRbilSK+H0KT2JmNhDlJAwMrvDgUOJJKWC/ekJv0poNO411+jmOInCjsX ZB6trJXyXofMmSqysjx7z6rtJUFukIu9f7LV7Zk8cqUw59+Yu870Dkc6D78/tBjozX6B LUfPRt6Ue/Wf8jjTTjTX7w8236nLrAlfwsDvyvwQLwzmG1GY2fskV5lhDZuNMApRPOnR L5HN2itKxwXgHjrMrbsmuh8xUbH8yS98FKjo0K/bQdWwHaCoZmFAcbxfzzNHPGqRvaVn 3y+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zdX62WlQ3p8rs50GDVVp4jfIL+laVX6G6USVtA2GR9M=; b=ASErEg5s4z5q3WOCzufrR6d0vSnPfJpY0srHjc1i/R0xVhIzHJtTcJumEfQOT0ihux FaBDuYvQLWkaXyiAWEPa72l9qTtJXQSnS8vPzugpGChTqv2gWnhrUfCVbOi/Z7TnTsRV C7/luTcoVaU0Kdf6760zzgxuCR6U7K+FtHZQQ7+N6IcWr+pPvDu0nXYEbZ7/XLkhLloL zLZNPytD2nQcJQWZ+IkO6DfBEbIpWUphTO+sSbfTAhQkEbwbWfhIpd7D1oZaqwJSc9LU mPF3B5WmBENK4sXApuWVfQ5YkaNqnzB817Koax4Bag2FCUfqqTAMMQYB0xFRBcdUOJcO AJqA== X-Gm-Message-State: AOAM531eH0UuIPj01N9OcZiqzmJFIkYBVIFKpSbk0jRQpiobSZ3kfMYh ep7IM4UoQy6l8lPOfQZceh8= X-Google-Smtp-Source: ABdhPJw6NARPj59vStBB/DjqY4pVBcOetCaXqKqJozj4vaPv9wTVOhKCG9WnSAWBL4PXtRp00klsjg== X-Received: by 2002:a19:7909:: with SMTP id u9mr9815144lfc.13.1623124978631; Mon, 07 Jun 2021 21:02:58 -0700 (PDT) Received: from rsa-laptop.internal.lan ([217.25.229.52]) by smtp.gmail.com with ESMTPSA id l23sm1729096lfj.26.2021.06.07.21.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 21:02:58 -0700 (PDT) From: Sergey Ryazanov To: Loic Poulain , "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org Subject: [PATCH 10/10] net: wwan: core: purge rx queue on port close Date: Tue, 8 Jun 2021 07:02:41 +0300 Message-Id: <20210608040241.10658-11-ryazanov.s.a@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210608040241.10658-1-ryazanov.s.a@gmail.com> References: <20210608040241.10658-1-ryazanov.s.a@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Purge the rx queue as soon as a user closes the port, just after the port stop callback invocation. This is to prevent feeding a user that will open the port next time with outdated and possibly unrelated data. While at it also remove the odd skb_queue_purge() call in the port device destroy callback. The queue will be purged just before the callback is ivoncated in the wwan_remove_port() function. Signed-off-by: Sergey Ryazanov --- drivers/net/wwan/wwan_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 38da3124d81e..45a41aee8958 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -240,7 +240,6 @@ static void wwan_port_destroy(struct device *dev) ida_free(&minors, MINOR(port->dev.devt)); mutex_destroy(&port->data_lock); - skb_queue_purge(&port->rxq); mutex_destroy(&port->ops_lock); kfree(port); } @@ -462,8 +461,11 @@ static void wwan_port_op_stop(struct wwan_port *port) { mutex_lock(&port->ops_lock); port->start_count--; - if (port->ops && !port->start_count) - port->ops->stop(port); + if (!port->start_count) { + if (port->ops) + port->ops->stop(port); + skb_queue_purge(&port->rxq); + } mutex_unlock(&port->ops_lock); }