Skip to content

Commit

Permalink
Merge branch 'wwan-link-creation-improvements'
Browse files Browse the repository at this point in the history
Sergey Ryazanov says:

====================
net: WWAN link creation improvements

This series is intended to make the WWAN network links management easier
for WWAN device drivers.

The series begins with adding support for network links creation to the
WWAN HW simulator to facilitate code testing. Then there are a couple of
changes that prepe the WWAN core code for further modifications. The
following patches (4-6) simplify driver unregistering procedures by
performing the created links cleanup in the WWAN core. 7th patch is to
avoid the odd hold of a driver module. Next patches (8th and 9th) make
it easier for drivers to create a network interface for a default data
channel. Finally, 10th patch adds support for reporting of data link
(aka channel aka context) id to make user aware which network
interface is bound to which WWAN device data channel.

All core changes have been tested with the HW simulator. The MHI and
IOSM drivers were only compile tested as I have no access to this
hardware. So the coresponding patches require ACK from the driver
authors.

Changelog:
  v1 -> v2:
    * rebased on top of latest net-next
    * patch that reworks the creation of mhi_net default netdev was
      dropped; as Loic explained, this network device has different
      purpose depending on a driver mode; Loic has a plan to rework the
      mhi_net driver, so we will defer the default netdev creation
      reworkings
    * add a new patch that creates a default network interface for IOSM
      modems
    * 7th, 8th, 10th patches have a minor updates (see the patches for
      details)
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jun 22, 2021
2 parents 1a77de0 + 6994092 commit 78c235f
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 108 deletions.
18 changes: 9 additions & 9 deletions drivers/net/mhi/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct mhi_device_info {

static int mhi_ndo_open(struct net_device *ndev)
{
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev);

/* Feed the rx buffer pool */
schedule_delayed_work(&mhi_netdev->rx_refill, 0);
Expand All @@ -47,7 +47,7 @@ static int mhi_ndo_open(struct net_device *ndev)

static int mhi_ndo_stop(struct net_device *ndev)
{
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev);

netif_stop_queue(ndev);
netif_carrier_off(ndev);
Expand All @@ -58,7 +58,7 @@ static int mhi_ndo_stop(struct net_device *ndev)

static netdev_tx_t mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev)
{
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev);
const struct mhi_net_proto *proto = mhi_netdev->proto;
struct mhi_device *mdev = mhi_netdev->mdev;
int err;
Expand Down Expand Up @@ -93,7 +93,7 @@ static netdev_tx_t mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev)
static void mhi_ndo_get_stats64(struct net_device *ndev,
struct rtnl_link_stats64 *stats)
{
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev);
unsigned int start;

do {
Expand Down Expand Up @@ -322,7 +322,7 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id,
if (dev_get_drvdata(&mhi_dev->dev))
return -EBUSY;

mhi_netdev = netdev_priv(ndev);
mhi_netdev = wwan_netdev_drvpriv(ndev);

dev_set_drvdata(&mhi_dev->dev, mhi_netdev);
mhi_netdev->ndev = ndev;
Expand Down Expand Up @@ -367,7 +367,7 @@ static int mhi_net_newlink(void *ctxt, struct net_device *ndev, u32 if_id,
static void mhi_net_dellink(void *ctxt, struct net_device *ndev,
struct list_head *head)
{
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
struct mhi_net_dev *mhi_netdev = wwan_netdev_drvpriv(ndev);
struct mhi_device *mhi_dev = ctxt;

if (head)
Expand All @@ -383,7 +383,6 @@ static void mhi_net_dellink(void *ctxt, struct net_device *ndev,
}

static const struct wwan_ops mhi_wwan_ops = {
.owner = THIS_MODULE,
.priv_size = sizeof(struct mhi_net_dev),
.setup = mhi_net_setup,
.newlink = mhi_net_newlink,
Expand All @@ -398,7 +397,8 @@ static int mhi_net_probe(struct mhi_device *mhi_dev,
struct net_device *ndev;
int err;

err = wwan_register_ops(&cntrl->mhi_dev->dev, &mhi_wwan_ops, mhi_dev);
err = wwan_register_ops(&cntrl->mhi_dev->dev, &mhi_wwan_ops, mhi_dev,
WWAN_NO_DEFAULT_LINK);
if (err)
return err;

Expand Down Expand Up @@ -436,7 +436,7 @@ static void mhi_net_remove(struct mhi_device *mhi_dev)
struct mhi_net_dev *mhi_netdev = dev_get_drvdata(&mhi_dev->dev);
struct mhi_controller *cntrl = mhi_dev->mhi_cntrl;

/* rtnetlink takes care of removing remaining links */
/* WWAN core takes care of removing remaining links */
wwan_unregister_ops(&cntrl->mhi_dev->dev);

if (create_default_iface)
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/mhi/proto_mbim.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/ip.h>
#include <linux/mii.h>
#include <linux/netdevice.h>
#include <linux/wwan.h>
#include <linux/skbuff.h>
#include <linux/usb.h>
#include <linux/usb/cdc.h>
Expand Down Expand Up @@ -56,7 +57,7 @@ static void __mbim_errors_inc(struct mhi_net_dev *dev)

static int mbim_rx_verify_nth16(struct sk_buff *skb)
{
struct mhi_net_dev *dev = netdev_priv(skb->dev);
struct mhi_net_dev *dev = wwan_netdev_drvpriv(skb->dev);
struct mbim_context *ctx = dev->proto_data;
struct usb_cdc_ncm_nth16 *nth16;
int len;
Expand Down Expand Up @@ -102,7 +103,7 @@ static int mbim_rx_verify_nth16(struct sk_buff *skb)

static int mbim_rx_verify_ndp16(struct sk_buff *skb, struct usb_cdc_ncm_ndp16 *ndp16)
{
struct mhi_net_dev *dev = netdev_priv(skb->dev);
struct mhi_net_dev *dev = wwan_netdev_drvpriv(skb->dev);
int ret;

if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) {
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/wwan/iosm/iosm_ipc_imem_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#define IP_MUX_SESSION_START 1
#define IP_MUX_SESSION_END 8

/* Default IP MUX channel */
#define IP_MUX_SESSION_DEFAULT 1

/**
* ipc_imem_sys_port_open - Open a port link to CP.
* @ipc_imem: Imem instance.
Expand Down
31 changes: 10 additions & 21 deletions drivers/net/wwan/iosm/iosm_ipc_wwan.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define IOSM_IF_ID_PAYLOAD 2

/**
* struct iosm_netdev_priv - netdev private data
* struct iosm_netdev_priv - netdev WWAN driver specific private data
* @ipc_wwan: Pointer to iosm_wwan struct
* @netdev: Pointer to network interface device structure
* @if_id: Interface id for device.
Expand Down Expand Up @@ -51,7 +51,7 @@ struct iosm_wwan {
/* Bring-up the wwan net link */
static int ipc_wwan_link_open(struct net_device *netdev)
{
struct iosm_netdev_priv *priv = netdev_priv(netdev);
struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);
struct iosm_wwan *ipc_wwan = priv->ipc_wwan;
int if_id = priv->if_id;
int ret;
Expand Down Expand Up @@ -88,7 +88,7 @@ static int ipc_wwan_link_open(struct net_device *netdev)
/* Bring-down the wwan net link */
static int ipc_wwan_link_stop(struct net_device *netdev)
{
struct iosm_netdev_priv *priv = netdev_priv(netdev);
struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);

netif_stop_queue(netdev);

Expand All @@ -105,7 +105,7 @@ static int ipc_wwan_link_stop(struct net_device *netdev)
static int ipc_wwan_link_transmit(struct sk_buff *skb,
struct net_device *netdev)
{
struct iosm_netdev_priv *priv = netdev_priv(netdev);
struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);
struct iosm_wwan *ipc_wwan = priv->ipc_wwan;
int if_id = priv->if_id;
int ret;
Expand Down Expand Up @@ -178,7 +178,7 @@ static int ipc_wwan_newlink(void *ctxt, struct net_device *dev,
if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist))
return -EINVAL;

priv = netdev_priv(dev);
priv = wwan_netdev_drvpriv(dev);
priv->if_id = if_id;
priv->netdev = dev;
priv->ipc_wwan = ipc_wwan;
Expand Down Expand Up @@ -208,8 +208,8 @@ static int ipc_wwan_newlink(void *ctxt, struct net_device *dev,
static void ipc_wwan_dellink(void *ctxt, struct net_device *dev,
struct list_head *head)
{
struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(dev);
struct iosm_wwan *ipc_wwan = ctxt;
struct iosm_netdev_priv *priv = netdev_priv(dev);
int if_id = priv->if_id;

if (WARN_ON(if_id < IP_MUX_SESSION_START ||
Expand Down Expand Up @@ -317,7 +317,9 @@ struct iosm_wwan *ipc_wwan_init(struct iosm_imem *ipc_imem, struct device *dev)
ipc_wwan->dev = dev;
ipc_wwan->ipc_imem = ipc_imem;

if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops, ipc_wwan)) {
/* WWAN core will create a netdev for the default IP MUX channel */
if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops, ipc_wwan,
IP_MUX_SESSION_DEFAULT)) {
kfree(ipc_wwan);
return NULL;
}
Expand All @@ -329,22 +331,9 @@ struct iosm_wwan *ipc_wwan_init(struct iosm_imem *ipc_imem, struct device *dev)

void ipc_wwan_deinit(struct iosm_wwan *ipc_wwan)
{
int if_id;

/* This call will remove all child netdev(s) */
wwan_unregister_ops(ipc_wwan->dev);

for (if_id = 0; if_id < ARRAY_SIZE(ipc_wwan->sub_netlist); if_id++) {
struct iosm_netdev_priv *priv;

priv = rcu_access_pointer(ipc_wwan->sub_netlist[if_id]);
if (!priv)
continue;

rtnl_lock();
ipc_wwan_dellink(ipc_wwan, priv->netdev, NULL);
rtnl_unlock();
}

mutex_destroy(&ipc_wwan->if_mutex);

kfree(ipc_wwan);
Expand Down
Loading

0 comments on commit 78c235f

Please sign in to comment.