aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/usb/rmnet_usb_data.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/usb/rmnet_usb_data.c')
-rw-r--r--drivers/net/usb/rmnet_usb_data.c356
1 files changed, 62 insertions, 294 deletions
diff --git a/drivers/net/usb/rmnet_usb_data.c b/drivers/net/usb/rmnet_usb_data.c
index e2514537163..7a17525560b 100644
--- a/drivers/net/usb/rmnet_usb_data.c
+++ b/drivers/net/usb/rmnet_usb_data.c
@@ -24,13 +24,7 @@
#include "rmnet_usb.h"
#define RMNET_DATA_LEN 2000
-#define RMNET_HEADROOM_W_MUX (sizeof(struct mux_hdr) + \
- sizeof(struct QMI_QOS_HDR_S))
#define RMNET_HEADROOM sizeof(struct QMI_QOS_HDR_S)
-#define RMNET_TAILROOM MAX_PAD_BYTES(4);
-
-static unsigned int override_data_muxing = 1;
-module_param(override_data_muxing, uint, S_IRUGO | S_IWUSR);
static unsigned int no_rmnet_devs = 1;
module_param(no_rmnet_devs, uint, S_IRUGO | S_IWUSR);
@@ -46,9 +40,6 @@ module_param(no_rmnet_insts_per_dev, uint, S_IRUGO | S_IWUSR);
static unsigned long mux_enabled;
module_param(mux_enabled, ulong, S_IRUGO | S_IWUSR);
-static unsigned int no_fwd_rmnet_links;
-module_param(no_fwd_rmnet_links, uint, S_IRUGO | S_IWUSR);
-
struct usbnet *unet_list[TOTAL_RMNET_DEV_COUNT];
/* net device name prefixes, indexed by driver_info->data */
@@ -57,11 +48,6 @@ static const char * const rmnet_names[] = {
"rmnet2_usb%d",
};
-/* net device reverse link name prefixes, indexed by driver_info->data */
-static const char * const rev_rmnet_names[] = {
- "rev_rmnet_usb%d",
- "rev_rmnet2_usb%d",
-};
static int data_msg_dbg_mask;
enum {
@@ -145,93 +131,40 @@ static struct kernel_param_ops rmnet_init_ops = {
module_param_cb(rmnet_data_init, &rmnet_init_ops, &rmnet_data_init,
S_IRUGO | S_IWUSR);
-static void rmnet_usb_setup(struct net_device *, int mux_enabled);
+static void rmnet_usb_setup(struct net_device *);
static int rmnet_ioctl(struct net_device *, struct ifreq *, int);
static int rmnet_usb_suspend(struct usb_interface *iface, pm_message_t message)
{
struct usbnet *unet = usb_get_intfdata(iface);
- struct rmnet_ctrl_dev *dev;
- int i, n, rdev_cnt, unet_id;
- int retval = 0;
-
- rdev_cnt = unet->data[4] ? no_rmnet_insts_per_dev : 1;
-
- for (n = 0; n < rdev_cnt; n++) {
- unet_id = n + unet->driver_info->data * no_rmnet_insts_per_dev;
- unet =
- unet->data[4] ? unet_list[unet_id] : usb_get_intfdata(iface);
-
- dev = (struct rmnet_ctrl_dev *)unet->data[1];
- spin_lock_irq(&unet->txq.lock);
- if (work_busy(&dev->get_encap_work) || unet->txq.qlen) {
- spin_unlock_irq(&unet->txq.lock);
- retval = -EBUSY;
- goto abort_suspend;
- }
+ struct rmnet_ctrl_udev *dev;
- set_bit(EVENT_DEV_ASLEEP, &unet->flags);
- spin_unlock_irq(&unet->txq.lock);
+ dev = (struct rmnet_ctrl_udev *)unet->data[1];
+ if (work_busy(&dev->get_encap_work))
+ return -EBUSY;
- usb_kill_anchored_urbs(&dev->rx_submitted);
- if (work_busy(&dev->get_encap_work)) {
- spin_lock_irq(&unet->txq.lock);
- clear_bit(EVENT_DEV_ASLEEP, &unet->flags);
- spin_unlock_irq(&unet->txq.lock);
- retval = -EBUSY;
- goto abort_suspend;
- }
- }
+ usb_kill_anchored_urbs(&dev->rx_submitted);
+ if (work_busy(&dev->get_encap_work))
+ return -EBUSY;
- for (n = 0; n < rdev_cnt; n++) {
- unet_id = n + unet->driver_info->data * no_rmnet_insts_per_dev;
- unet =
- unet->data[4] ? unet_list[unet_id] : usb_get_intfdata(iface);
-
- dev = (struct rmnet_ctrl_dev *)unet->data[1];
- netif_device_detach(unet->net);
- usbnet_terminate_urbs(unet);
- netif_device_attach(unet->net);
+ if (usbnet_suspend(iface, message)) {
+ rmnet_usb_ctrl_start_rx(dev);
+ return -EBUSY;
}
return 0;
-
-abort_suspend:
- for (i = 0; i < n; i++) {
- unet_id = i + unet->driver_info->data * no_rmnet_insts_per_dev;
- unet =
- unet->data[4] ? unet_list[unet_id] : usb_get_intfdata(iface);
-
- dev = (struct rmnet_ctrl_dev *)unet->data[1];
- rmnet_usb_ctrl_start_rx(dev);
- spin_lock_irq(&unet->txq.lock);
- clear_bit(EVENT_DEV_ASLEEP, &unet->flags);
- spin_unlock_irq(&unet->txq.lock);
- }
- return retval;
}
static int rmnet_usb_resume(struct usb_interface *iface)
{
struct usbnet *unet = usb_get_intfdata(iface);
- struct rmnet_ctrl_dev *dev;
- int n, rdev_cnt, unet_id;
-
- rdev_cnt = unet->data[4] ? no_rmnet_insts_per_dev : 1;
+ struct rmnet_ctrl_udev *dev;
- for (n = 0; n < rdev_cnt; n++) {
- unet_id = n + unet->driver_info->data * no_rmnet_insts_per_dev;
- unet =
- unet->data[4] ? unet_list[unet_id] : usb_get_intfdata(iface);
+ dev = (struct rmnet_ctrl_udev *)unet->data[1];
- dev = (struct rmnet_ctrl_dev *)unet->data[1];
- rmnet_usb_ctrl_start_rx(dev);
- usb_set_intfdata(iface, unet);
- unet->suspend_count = 1;
- usbnet_resume(iface);
- }
+ usbnet_resume(iface);
- return 0;
+ return rmnet_usb_ctrl_start_rx(dev);
}
static int rmnet_usb_bind(struct usbnet *usbnet, struct usb_interface *iface)
@@ -244,9 +177,6 @@ static int rmnet_usb_bind(struct usbnet *usbnet, struct usb_interface *iface)
int status = 0;
int i;
int numends;
- bool mux;
-
- mux = test_bit(info->data, &mux_enabled);
numends = iface->cur_altsetting->desc.bNumEndpoints;
for (i = 0; i < numends; i++) {
@@ -276,87 +206,13 @@ static int rmnet_usb_bind(struct usbnet *usbnet, struct usb_interface *iface)
bulk_out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
usbnet->status = int_in;
- /*change name of net device to rmnet_usbx here*/
- if (mux && (info->in > no_fwd_rmnet_links))
- strlcpy(usbnet->net->name, rev_rmnet_names[info->data],
- IFNAMSIZ);
- else
- strlcpy(usbnet->net->name, rmnet_names[info->data],
- IFNAMSIZ);
-
- if (mux)
- usbnet->rx_urb_size = usbnet->hard_mtu + sizeof(struct mux_hdr)
- + MAX_PAD_BYTES(4);
+ strlcpy(usbnet->net->name, rmnet_names[info->data],
+ IFNAMSIZ);
+
out:
return status;
}
-static int rmnet_usb_data_dmux(struct sk_buff *skb, struct urb *rx_urb)
-{
- struct mux_hdr *hdr;
- size_t pad_len;
- size_t total_len;
- unsigned int mux_id;
-
- hdr = (struct mux_hdr *)skb->data;
- mux_id = hdr->mux_id;
- if (!mux_id || mux_id > no_rmnet_insts_per_dev) {
- pr_err_ratelimited("%s: Invalid data channel id %u.\n",
- __func__, mux_id);
- return -EINVAL;
- }
-
- pad_len = hdr->padding_info >> MUX_PAD_SHIFT;
- if (pad_len > MAX_PAD_BYTES(4)) {
- pr_err_ratelimited("%s: Invalid pad len %d\n",
- __func__, pad_len);
- return -EINVAL;
- }
-
- total_len = le16_to_cpu(hdr->pkt_len_w_padding);
- if (!total_len || !(total_len - pad_len)) {
- pr_err_ratelimited("%s: Invalid pkt length %d\n", __func__,
- total_len);
- return -EINVAL;
- }
-
- skb->data = (unsigned char *)(hdr + 1);
- skb_reset_tail_pointer(skb);
- rx_urb->actual_length = total_len - pad_len;
-
- return mux_id - 1;
-}
-
-static struct sk_buff *rmnet_usb_data_mux(struct sk_buff *skb, unsigned int id)
-{
- struct mux_hdr *hdr;
- size_t len;
- struct sk_buff *new_skb;
-
- if ((skb->len & 0x3) && (skb_tailroom(skb) < (4 - (skb->len & 0x3)))) {
- new_skb = skb_copy_expand(skb, skb_headroom(skb),
- 4 - (skb->len & 0x3), GFP_ATOMIC);
- dev_kfree_skb_any(skb);
- if (new_skb == NULL) {
- pr_err("%s: cannot allocate skb\n", __func__);
- return NULL;
- }
- skb = new_skb;
- }
-
- hdr = (struct mux_hdr *)skb_push(skb, sizeof(struct mux_hdr));
- hdr->mux_id = id + 1;
- len = skb->len - sizeof(struct mux_hdr);
-
- /*add padding if len is not 4 byte aligned*/
- skb_put(skb, ALIGN(len, 4) - len);
-
- hdr->pkt_len_w_padding = cpu_to_le16(skb->len - sizeof(struct mux_hdr));
- hdr->padding_info = (ALIGN(len, 4) - len) << MUX_PAD_SHIFT;
-
- return skb;
-}
-
static struct sk_buff *rmnet_usb_tx_fixup(struct usbnet *dev,
struct sk_buff *skb, gfp_t flags)
{
@@ -370,9 +226,6 @@ static struct sk_buff *rmnet_usb_tx_fixup(struct usbnet *dev,
qmih->flow_id = skb->mark;
}
- if (!override_data_muxing && dev->data[4])
- rmnet_usb_data_mux(skb, dev->data[3]);
-
if (skb)
DBG1("[%s] Tx packet #%lu len=%d mark=0x%x\n",
dev->net->name, dev->net->stats.tx_packets,
@@ -403,32 +256,6 @@ static __be16 rmnet_ip_type_trans(struct sk_buff *skb)
return protocol;
}
-static void rmnet_usb_rx_complete(struct urb *rx_urb)
-{
- struct sk_buff *skb = (struct sk_buff *) rx_urb->context;
- struct skb_data *entry = (struct skb_data *) skb->cb;
- struct usbnet *dev = entry->dev;
- unsigned int unet_offset;
- unsigned int unet_id;
- int mux_id;
-
- unet_offset = dev->driver_info->data * no_rmnet_insts_per_dev;
-
- if (!override_data_muxing && !rx_urb->status && dev->data[4]) {
- mux_id = rmnet_usb_data_dmux(skb, rx_urb);
- if (mux_id < 0) {
- /*resubmit urb and free skb in rx_complete*/
- rx_urb->status = -EINVAL;
- } else {
- /*map urb to actual network iface based on mux id*/
- unet_id = unet_offset + mux_id;
- skb->dev = unet_list[unet_id]->net;
- }
- }
-
- rx_complete(rx_urb);
-}
-
static int rmnet_usb_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
{
if (test_bit(RMNET_MODE_LLP_IP, &dev->data[0]))
@@ -642,7 +469,7 @@ static int rmnet_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
return rc;
}
-static void rmnet_usb_setup(struct net_device *dev, int mux_enabled)
+static void rmnet_usb_setup(struct net_device *dev)
{
/* Using Ethernet mode by default */
dev->netdev_ops = &rmnet_usb_ops_ether;
@@ -650,14 +477,8 @@ static void rmnet_usb_setup(struct net_device *dev, int mux_enabled)
/* set this after calling ether_setup */
dev->mtu = RMNET_DATA_LEN;
- if (mux_enabled) {
- dev->needed_headroom = RMNET_HEADROOM_W_MUX;
-
- /*max pad bytes for 4 byte alignment*/
- dev->needed_tailroom = RMNET_TAILROOM;
- } else {
- dev->needed_headroom = RMNET_HEADROOM;
- }
+ /* for QOS header */
+ dev->needed_headroom = RMNET_HEADROOM;
random_ether_addr(dev->dev_addr);
dev->watchdog_timeo = 1000; /* 10 seconds? */
@@ -755,75 +576,51 @@ static int rmnet_usb_probe(struct usb_interface *iface,
struct driver_info *info = (struct driver_info *)prod->driver_info;
struct usb_device *udev;
int status = 0;
- unsigned int i, unet_id, rdev_cnt, n = 0;
- bool mux;
- struct rmnet_ctrl_dev *dev;
udev = interface_to_usbdev(iface);
if (iface->num_altsetting != 1) {
dev_err(&iface->dev, "%s invalid num_altsetting %u\n",
__func__, iface->num_altsetting);
- status = -EINVAL;
- goto out;
+ return -EINVAL;
}
- mux = test_bit(info->data, &mux_enabled);
- rdev_cnt = mux ? no_rmnet_insts_per_dev : 1;
- info->in = 0;
-
- for (n = 0; n < rdev_cnt; n++) {
-
- /* Use this filed to increment device count this will be
- * used by bind to determin the forward link and reverse
- * link network interface names.
- */
- info->in++;
- status = usbnet_probe(iface, prod);
- if (status < 0) {
- dev_err(&iface->dev, "usbnet_probe failed %d\n",
- status);
- goto out;
- }
-
- unet_id = n + info->data * no_rmnet_insts_per_dev;
-
- unet_list[unet_id] = unet = usb_get_intfdata(iface);
-
- /*store mux id for later access*/
- unet->data[3] = n;
-
- /*save mux info for control and usbnet devices*/
- unet->data[1] = unet->data[4] = mux;
+ status = usbnet_probe(iface, prod);
+ if (status < 0) {
+ dev_err(&iface->dev, "usbnet_probe failed %d\n",
+ status);
+ return status;
+ }
- /*set rmnet operation mode to eth by default*/
- set_bit(RMNET_MODE_LLP_ETH, &unet->data[0]);
+ unet = usb_get_intfdata(iface);
- /*update net device*/
- rmnet_usb_setup(unet->net, mux);
+ /*set rmnet operation mode to eth by default*/
+ set_bit(RMNET_MODE_LLP_ETH, &unet->data[0]);
- /*create /sys/class/net/rmnet_usbx/dbg_mask*/
- status = device_create_file(&unet->net->dev,
- &dev_attr_dbg_mask);
- if (status) {
- usbnet_disconnect(iface);
- goto out;
- }
+ /*update net device*/
+ rmnet_usb_setup(unet->net);
- status = rmnet_usb_ctrl_probe(iface, unet->status, info->data,
- &unet->data[1]);
- if (status) {
- device_remove_file(&unet->net->dev, &dev_attr_dbg_mask);
- usbnet_disconnect(iface);
- goto out;
- }
+ /*create /sys/class/net/rmnet_usbx/dbg_mask*/
+ status = device_create_file(&unet->net->dev,
+ &dev_attr_dbg_mask);
+ if (status) {
+ usbnet_disconnect(iface);
+ return status;
+ }
- status = rmnet_usb_data_debugfs_init(unet);
- if (status)
- dev_dbg(&iface->dev,
- "mode debugfs file is not available\n");
+ status = rmnet_usb_ctrl_probe(iface, unet->status, info->data,
+ &unet->data[1]);
+ if (status) {
+ device_remove_file(&unet->net->dev, &dev_attr_dbg_mask);
+ usbnet_disconnect(iface);
+ return status;
}
+ status = rmnet_usb_data_debugfs_init(unet);
+ if (status)
+ dev_dbg(&iface->dev,
+ "mode debugfs file is not available\n");
+
usb_enable_autosuspend(udev);
if (udev->parent && !udev->parent->parent) {
@@ -833,51 +630,23 @@ static int rmnet_usb_probe(struct usb_interface *iface,
}
return 0;
-
-out:
- for (i = 0; i < n; i++) {
- /* This cleanup happens only for MUX case */
- unet_id = i + info->data * no_rmnet_insts_per_dev;
- unet = unet_list[unet_id];
- dev = (struct rmnet_ctrl_dev *)unet->data[1];
-
- rmnet_usb_data_debugfs_cleanup(unet);
- rmnet_usb_ctrl_disconnect(dev);
- device_remove_file(&unet->net->dev, &dev_attr_dbg_mask);
- usb_set_intfdata(iface, unet_list[unet_id]);
- usbnet_disconnect(iface);
- unet_list[unet_id] = NULL;
- }
-
- return status;
}
static void rmnet_usb_disconnect(struct usb_interface *intf)
{
struct usbnet *unet = usb_get_intfdata(intf);
- struct rmnet_ctrl_dev *dev;
- unsigned int n, rdev_cnt, unet_id;
- struct driver_info *info = unet->driver_info;
- bool mux = unet->data[4];
-
- rdev_cnt = mux ? no_rmnet_insts_per_dev : 1;
+ struct rmnet_ctrl_udev *dev;
device_set_wakeup_enable(&unet->udev->dev, 0);
- for (n = 0; n < rdev_cnt; n++) {
- unet_id = n + info->data * no_rmnet_insts_per_dev;
- unet = mux ? unet_list[unet_id] : usb_get_intfdata(intf);
- device_remove_file(&unet->net->dev, &dev_attr_dbg_mask);
+ device_remove_file(&unet->net->dev, &dev_attr_dbg_mask);
- dev = (struct rmnet_ctrl_dev *)unet->data[1];
- rmnet_usb_ctrl_disconnect(dev);
- unet->data[0] = 0;
- unet->data[1] = 0;
- rmnet_usb_data_debugfs_cleanup(unet);
- usb_set_intfdata(intf, unet);
- usbnet_disconnect(intf);
- unet_list[unet_id] = NULL;
- }
+ dev = (struct rmnet_ctrl_udev *)unet->data[1];
+ rmnet_usb_ctrl_disconnect(dev);
+ unet->data[0] = 0;
+ unet->data[1] = 0;
+ rmnet_usb_data_debugfs_cleanup(unet);
+ usbnet_disconnect(intf);
}
static struct driver_info rmnet_info = {
@@ -886,7 +655,6 @@ static struct driver_info rmnet_info = {
.bind = rmnet_usb_bind,
.tx_fixup = rmnet_usb_tx_fixup,
.rx_fixup = rmnet_usb_rx_fixup,
- .rx_complete = rmnet_usb_rx_complete,
.manage_power = rmnet_usb_manage_power,
.data = 0,
};
@@ -897,7 +665,6 @@ static struct driver_info rmnet_usb_info = {
.bind = rmnet_usb_bind,
.tx_fixup = rmnet_usb_tx_fixup,
.rx_fixup = rmnet_usb_rx_fixup,
- .rx_complete = rmnet_usb_rx_complete,
.manage_power = rmnet_usb_manage_power,
.data = 1,
};
@@ -984,7 +751,8 @@ static int rmnet_data_start(void)
}
/* initialize ctrl devices */
- retval = rmnet_usb_ctrl_init(no_rmnet_devs, no_rmnet_insts_per_dev);
+ retval = rmnet_usb_ctrl_init(no_rmnet_devs, no_rmnet_insts_per_dev,
+ mux_enabled);
if (retval) {
pr_err("rmnet_usb_cmux_init failed: %d", retval);
return retval;
@@ -1002,7 +770,7 @@ static int rmnet_data_start(void)
static void __exit rmnet_usb_exit(void)
{
usb_deregister(&rmnet_usb);
- rmnet_usb_ctrl_exit(no_rmnet_devs, no_rmnet_insts_per_dev);
+ rmnet_usb_ctrl_exit(no_rmnet_devs, no_rmnet_insts_per_dev, mux_enabled);
}
module_exit(rmnet_usb_exit);