2017-11-03 17:28:30 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-12-18 06:49:09 +07:00
|
|
|
/*
|
|
|
|
* f_phonet.c -- USB CDC Phonet function
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Nokia Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Rémi Denis-Courmont
|
|
|
|
*/
|
|
|
|
|
2011-06-16 18:01:34 +07:00
|
|
|
#include <linux/mm.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2008-12-18 06:49:09 +07:00
|
|
|
#include <linux/kernel.h>
|
2013-05-23 15:51:11 +07:00
|
|
|
#include <linux/module.h>
|
2008-12-18 06:49:09 +07:00
|
|
|
#include <linux/device.h>
|
|
|
|
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/if_phonet.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
|
|
|
|
#include <linux/usb/ch9.h>
|
|
|
|
#include <linux/usb/cdc.h>
|
|
|
|
#include <linux/usb/composite.h>
|
|
|
|
|
|
|
|
#include "u_phonet.h"
|
2013-05-23 15:51:15 +07:00
|
|
|
#include "u_ether.h"
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
#define PN_MEDIA_USB 0x1B
|
2009-08-07 04:56:44 +07:00
|
|
|
#define MAXPACKET 512
|
|
|
|
#if (PAGE_SIZE % MAXPACKET)
|
|
|
|
#error MAXPACKET must divide PAGE_SIZE!
|
|
|
|
#endif
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct phonet_port {
|
|
|
|
struct f_phonet *usb;
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct f_phonet {
|
|
|
|
struct usb_function function;
|
2009-08-07 04:56:44 +07:00
|
|
|
struct {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
spinlock_t lock;
|
|
|
|
} rx;
|
2008-12-18 06:49:09 +07:00
|
|
|
struct net_device *dev;
|
|
|
|
struct usb_ep *in_ep, *out_ep;
|
|
|
|
|
|
|
|
struct usb_request *in_req;
|
|
|
|
struct usb_request *out_reqv[0];
|
|
|
|
};
|
|
|
|
|
2009-08-07 04:56:44 +07:00
|
|
|
static int phonet_rxq_size = 17;
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
static inline struct f_phonet *func_to_pn(struct usb_function *f)
|
|
|
|
{
|
|
|
|
return container_of(f, struct f_phonet, function);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#define USB_CDC_SUBCLASS_PHONET 0xfe
|
|
|
|
#define USB_CDC_PHONET_TYPE 0xab
|
|
|
|
|
|
|
|
static struct usb_interface_descriptor
|
|
|
|
pn_control_intf_desc = {
|
|
|
|
.bLength = sizeof pn_control_intf_desc,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
|
|
|
/* .bInterfaceNumber = DYNAMIC, */
|
|
|
|
.bInterfaceClass = USB_CLASS_COMM,
|
|
|
|
.bInterfaceSubClass = USB_CDC_SUBCLASS_PHONET,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_cdc_header_desc
|
|
|
|
pn_header_desc = {
|
|
|
|
.bLength = sizeof pn_header_desc,
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_HEADER_TYPE,
|
2009-02-12 05:11:36 +07:00
|
|
|
.bcdCDC = cpu_to_le16(0x0110),
|
2008-12-18 06:49:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_cdc_header_desc
|
|
|
|
pn_phonet_desc = {
|
|
|
|
.bLength = sizeof pn_phonet_desc,
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_PHONET_TYPE,
|
2009-02-12 05:11:36 +07:00
|
|
|
.bcdCDC = cpu_to_le16(0x1505), /* ??? */
|
2008-12-18 06:49:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_cdc_union_desc
|
|
|
|
pn_union_desc = {
|
|
|
|
.bLength = sizeof pn_union_desc,
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_UNION_TYPE,
|
|
|
|
|
|
|
|
/* .bMasterInterface0 = DYNAMIC, */
|
|
|
|
/* .bSlaveInterface0 = DYNAMIC, */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_interface_descriptor
|
|
|
|
pn_data_nop_intf_desc = {
|
|
|
|
.bLength = sizeof pn_data_nop_intf_desc,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
|
|
|
/* .bInterfaceNumber = DYNAMIC, */
|
|
|
|
.bAlternateSetting = 0,
|
|
|
|
.bNumEndpoints = 0,
|
|
|
|
.bInterfaceClass = USB_CLASS_CDC_DATA,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_interface_descriptor
|
|
|
|
pn_data_intf_desc = {
|
|
|
|
.bLength = sizeof pn_data_intf_desc,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
|
|
|
/* .bInterfaceNumber = DYNAMIC, */
|
|
|
|
.bAlternateSetting = 1,
|
|
|
|
.bNumEndpoints = 2,
|
|
|
|
.bInterfaceClass = USB_CLASS_CDC_DATA,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor
|
|
|
|
pn_fs_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor
|
|
|
|
pn_hs_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
2009-08-07 04:56:44 +07:00
|
|
|
.wMaxPacketSize = cpu_to_le16(MAXPACKET),
|
2008-12-18 06:49:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor
|
|
|
|
pn_fs_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor
|
|
|
|
pn_hs_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
2009-02-12 05:11:36 +07:00
|
|
|
.wMaxPacketSize = cpu_to_le16(512),
|
2008-12-18 06:49:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_descriptor_header *fs_pn_function[] = {
|
|
|
|
(struct usb_descriptor_header *) &pn_control_intf_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_header_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_phonet_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_union_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_data_nop_intf_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_data_intf_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_fs_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_fs_source_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_descriptor_header *hs_pn_function[] = {
|
|
|
|
(struct usb_descriptor_header *) &pn_control_intf_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_header_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_phonet_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_union_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_data_nop_intf_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_data_intf_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_hs_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &pn_hs_source_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int pn_net_open(struct net_device *dev)
|
|
|
|
{
|
2009-06-01 08:18:56 +07:00
|
|
|
netif_wake_queue(dev);
|
2008-12-18 06:49:09 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pn_net_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pn_tx_complete(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
|
|
|
struct f_phonet *fp = ep->driver_data;
|
|
|
|
struct net_device *dev = fp->dev;
|
|
|
|
struct sk_buff *skb = req->context;
|
|
|
|
|
|
|
|
switch (req->status) {
|
|
|
|
case 0:
|
|
|
|
dev->stats.tx_packets++;
|
|
|
|
dev->stats.tx_bytes += skb->len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -ESHUTDOWN: /* disconnected */
|
|
|
|
case -ECONNRESET: /* disabled */
|
|
|
|
dev->stats.tx_aborted_errors++;
|
2017-10-25 02:52:59 +07:00
|
|
|
/* fall through */
|
2008-12-18 06:49:09 +07:00
|
|
|
default:
|
|
|
|
dev->stats.tx_errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_kfree_skb_any(skb);
|
2009-06-01 08:18:56 +07:00
|
|
|
netif_wake_queue(dev);
|
2008-12-18 06:49:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pn_net_xmit(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct phonet_port *port = netdev_priv(dev);
|
|
|
|
struct f_phonet *fp;
|
|
|
|
struct usb_request *req;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (skb->protocol != htons(ETH_P_PHONET))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
fp = port->usb;
|
|
|
|
if (unlikely(!fp)) /* race with carrier loss */
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
req = fp->in_req;
|
|
|
|
req->buf = skb->data;
|
|
|
|
req->length = skb->len;
|
|
|
|
req->complete = pn_tx_complete;
|
|
|
|
req->zero = 1;
|
|
|
|
req->context = skb;
|
|
|
|
|
|
|
|
if (unlikely(usb_ep_queue(fp->in_ep, req, GFP_ATOMIC)))
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
skb = NULL;
|
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
out:
|
|
|
|
if (unlikely(skb)) {
|
2009-06-01 08:18:55 +07:00
|
|
|
dev_kfree_skb(skb);
|
2008-12-18 06:49:09 +07:00
|
|
|
dev->stats.tx_dropped++;
|
|
|
|
}
|
2009-06-23 13:03:08 +07:00
|
|
|
return NETDEV_TX_OK;
|
2008-12-18 06:49:09 +07:00
|
|
|
}
|
|
|
|
|
2009-01-08 08:24:34 +07:00
|
|
|
static const struct net_device_ops pn_netdev_ops = {
|
|
|
|
.ndo_open = pn_net_open,
|
|
|
|
.ndo_stop = pn_net_close,
|
|
|
|
.ndo_start_xmit = pn_net_xmit,
|
|
|
|
};
|
|
|
|
|
2008-12-18 06:49:09 +07:00
|
|
|
static void pn_net_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
dev->features = 0;
|
|
|
|
dev->type = ARPHRD_PHONET;
|
|
|
|
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
|
|
|
|
dev->mtu = PHONET_DEV_MTU;
|
net: use core MTU range checking in misc drivers
firewire-net:
- set min/max_mtu
- remove fwnet_change_mtu
nes:
- set max_mtu
- clean up nes_netdev_change_mtu
xpnet:
- set min/max_mtu
- remove xpnet_dev_change_mtu
hippi:
- set min/max_mtu
- remove hippi_change_mtu
batman-adv:
- set max_mtu
- remove batadv_interface_change_mtu
- initialization is a little async, not 100% certain that max_mtu is set
in the optimal place, don't have hardware to test with
rionet:
- set min/max_mtu
- remove rionet_change_mtu
slip:
- set min/max_mtu
- streamline sl_change_mtu
um/net_kern:
- remove pointless ndo_change_mtu
hsi/clients/ssi_protocol:
- use core MTU range checking
- remove now redundant ssip_pn_set_mtu
ipoib:
- set a default max MTU value
- Note: ipoib's actual max MTU can vary, depending on if the device is in
connected mode or not, so we'll just set the max_mtu value to the max
possible, and let the ndo_change_mtu function continue to validate any new
MTU change requests with checks for CM or not. Note that ipoib has no
min_mtu set, and thus, the network core's mtu > 0 check is the only lower
bounds here.
mptlan:
- use net core MTU range checking
- remove now redundant mpt_lan_change_mtu
fddi:
- min_mtu = 21, max_mtu = 4470
- remove now redundant fddi_change_mtu (including export)
fjes:
- min_mtu = 8192, max_mtu = 65536
- The max_mtu value is actually one over IP_MAX_MTU here, but the idea is to
get past the core net MTU range checks so fjes_change_mtu can validate a
new MTU against what it supports (see fjes_support_mtu in fjes_hw.c)
hsr:
- min_mtu = 0 (calls ether_setup, max_mtu is 1500)
f_phonet:
- min_mtu = 6, max_mtu = 65541
u_ether:
- min_mtu = 14, max_mtu = 15412
phonet/pep-gprs:
- min_mtu = 576, max_mtu = 65530
- remove redundant gprs_set_mtu
CC: netdev@vger.kernel.org
CC: linux-rdma@vger.kernel.org
CC: Stefan Richter <stefanr@s5r6.in-berlin.de>
CC: Faisal Latif <faisal.latif@intel.com>
CC: linux-rdma@vger.kernel.org
CC: Cliff Whickman <cpw@sgi.com>
CC: Robin Holt <robinmholt@gmail.com>
CC: Jes Sorensen <jes@trained-monkey.org>
CC: Marek Lindner <mareklindner@neomailbox.ch>
CC: Simon Wunderlich <sw@simonwunderlich.de>
CC: Antonio Quartulli <a@unstable.cc>
CC: Sathya Prakash <sathya.prakash@broadcom.com>
CC: Chaitra P B <chaitra.basappa@broadcom.com>
CC: Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>
CC: MPT-FusionLinux.pdl@broadcom.com
CC: Sebastian Reichel <sre@kernel.org>
CC: Felipe Balbi <balbi@kernel.org>
CC: Arvid Brodin <arvid.brodin@alten.se>
CC: Remi Denis-Courmont <courmisch@gmail.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-10-21 00:55:22 +07:00
|
|
|
dev->min_mtu = PHONET_MIN_MTU;
|
|
|
|
dev->max_mtu = PHONET_MAX_MTU;
|
2008-12-18 06:49:09 +07:00
|
|
|
dev->hard_header_len = 1;
|
|
|
|
dev->dev_addr[0] = PN_MEDIA_USB;
|
|
|
|
dev->addr_len = 1;
|
|
|
|
dev->tx_queue_len = 1;
|
|
|
|
|
2009-01-08 08:24:34 +07:00
|
|
|
dev->netdev_ops = &pn_netdev_ops;
|
net: Fix inconsistent teardown and release of private netdev state.
Network devices can allocate reasources and private memory using
netdev_ops->ndo_init(). However, the release of these resources
can occur in one of two different places.
Either netdev_ops->ndo_uninit() or netdev->destructor().
The decision of which operation frees the resources depends upon
whether it is necessary for all netdev refs to be released before it
is safe to perform the freeing.
netdev_ops->ndo_uninit() presumably can occur right after the
NETDEV_UNREGISTER notifier completes and the unicast and multicast
address lists are flushed.
netdev->destructor(), on the other hand, does not run until the
netdev references all go away.
Further complicating the situation is that netdev->destructor()
almost universally does also a free_netdev().
This creates a problem for the logic in register_netdevice().
Because all callers of register_netdevice() manage the freeing
of the netdev, and invoke free_netdev(dev) if register_netdevice()
fails.
If netdev_ops->ndo_init() succeeds, but something else fails inside
of register_netdevice(), it does call ndo_ops->ndo_uninit(). But
it is not able to invoke netdev->destructor().
This is because netdev->destructor() will do a free_netdev() and
then the caller of register_netdevice() will do the same.
However, this means that the resources that would normally be released
by netdev->destructor() will not be.
Over the years drivers have added local hacks to deal with this, by
invoking their destructor parts by hand when register_netdevice()
fails.
Many drivers do not try to deal with this, and instead we have leaks.
Let's close this hole by formalizing the distinction between what
private things need to be freed up by netdev->destructor() and whether
the driver needs unregister_netdevice() to perform the free_netdev().
netdev->priv_destructor() performs all actions to free up the private
resources that used to be freed by netdev->destructor(), except for
free_netdev().
netdev->needs_free_netdev is a boolean that indicates whether
free_netdev() should be done at the end of unregister_netdevice().
Now, register_netdevice() can sanely release all resources after
ndo_ops->ndo_init() succeeds, by invoking both ndo_ops->ndo_uninit()
and netdev->priv_destructor().
And at the end of unregister_netdevice(), we invoke
netdev->priv_destructor() and optionally call free_netdev().
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-05-08 23:52:56 +07:00
|
|
|
dev->needs_free_netdev = true;
|
2008-12-18 06:49:09 +07:00
|
|
|
dev->header_ops = &phonet_header_ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue buffer for data from the host
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pn_rx_submit(struct f_phonet *fp, struct usb_request *req, gfp_t gfp_flags)
|
|
|
|
{
|
2009-08-07 04:56:44 +07:00
|
|
|
struct page *page;
|
2008-12-18 06:49:09 +07:00
|
|
|
int err;
|
|
|
|
|
2014-11-12 00:26:50 +07:00
|
|
|
page = __dev_alloc_page(gfp_flags | __GFP_NOMEMALLOC);
|
2009-08-07 04:56:44 +07:00
|
|
|
if (!page)
|
2008-12-18 06:49:09 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-08-07 04:56:44 +07:00
|
|
|
req->buf = page_address(page);
|
|
|
|
req->length = PAGE_SIZE;
|
|
|
|
req->context = page;
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
err = usb_ep_queue(fp->out_ep, req, gfp_flags);
|
|
|
|
if (unlikely(err))
|
2011-11-22 17:57:41 +07:00
|
|
|
put_page(page);
|
2008-12-18 06:49:09 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
|
|
|
struct f_phonet *fp = ep->driver_data;
|
|
|
|
struct net_device *dev = fp->dev;
|
2009-08-07 04:56:44 +07:00
|
|
|
struct page *page = req->context;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
unsigned long flags;
|
2008-12-18 06:49:09 +07:00
|
|
|
int status = req->status;
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case 0:
|
2009-08-07 04:56:44 +07:00
|
|
|
spin_lock_irqsave(&fp->rx.lock, flags);
|
|
|
|
skb = fp->rx.skb;
|
|
|
|
if (!skb)
|
|
|
|
skb = fp->rx.skb = netdev_alloc_skb(dev, 12);
|
|
|
|
if (req->actual < req->length) /* Last fragment */
|
|
|
|
fp->rx.skb = NULL;
|
|
|
|
spin_unlock_irqrestore(&fp->rx.lock, flags);
|
|
|
|
|
|
|
|
if (unlikely(!skb))
|
2008-12-18 06:49:09 +07:00
|
|
|
break;
|
2009-08-07 04:56:44 +07:00
|
|
|
|
2011-02-23 09:51:33 +07:00
|
|
|
if (skb->len == 0) { /* First fragment */
|
2009-08-07 04:56:44 +07:00
|
|
|
skb->protocol = htons(ETH_P_PHONET);
|
|
|
|
skb_reset_mac_header(skb);
|
2011-02-23 09:51:33 +07:00
|
|
|
/* Can't use pskb_pull() on page in IRQ */
|
networking: introduce and use skb_put_data()
A common pattern with skb_put() is to just want to memcpy()
some data into the new space, introduce skb_put_data() for
this.
An spatch similar to the one for skb_put_zero() converts many
of the places using it:
@@
identifier p, p2;
expression len, skb, data;
type t, t2;
@@
(
-p = skb_put(skb, len);
+p = skb_put_data(skb, data, len);
|
-p = (t)skb_put(skb, len);
+p = skb_put_data(skb, data, len);
)
(
p2 = (t2)p;
-memcpy(p2, data, len);
|
-memcpy(p, data, len);
)
@@
type t, t2;
identifier p, p2;
expression skb, data;
@@
t *p;
...
(
-p = skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
|
-p = (t *)skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
)
(
p2 = (t2)p;
-memcpy(p2, data, sizeof(*p));
|
-memcpy(p, data, sizeof(*p));
)
@@
expression skb, len, data;
@@
-memcpy(skb_put(skb, len), data, len);
+skb_put_data(skb, data, len);
(again, manually post-processed to retain some comments)
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:20 +07:00
|
|
|
skb_put_data(skb, page_address(page), 1);
|
2011-02-23 09:51:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
|
2012-03-27 10:04:02 +07:00
|
|
|
skb->len <= 1, req->actual, PAGE_SIZE);
|
2011-02-23 09:51:33 +07:00
|
|
|
page = NULL;
|
|
|
|
|
|
|
|
if (req->actual < req->length) { /* Last fragment */
|
2009-08-07 04:56:44 +07:00
|
|
|
skb->dev = dev;
|
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += skb->len;
|
|
|
|
|
|
|
|
netif_rx(skb);
|
|
|
|
}
|
2008-12-18 06:49:09 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Do not resubmit in these cases: */
|
|
|
|
case -ESHUTDOWN: /* disconnect */
|
|
|
|
case -ECONNABORTED: /* hw reset */
|
|
|
|
case -ECONNRESET: /* dequeued (unlink or netif down) */
|
|
|
|
req = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Do resubmit in these cases: */
|
|
|
|
case -EOVERFLOW: /* request buffer overflow */
|
|
|
|
dev->stats.rx_over_errors++;
|
2017-10-25 02:52:59 +07:00
|
|
|
/* fall through */
|
2008-12-18 06:49:09 +07:00
|
|
|
default:
|
|
|
|
dev->stats.rx_errors++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-07 04:56:44 +07:00
|
|
|
if (page)
|
2011-11-22 17:57:41 +07:00
|
|
|
put_page(page);
|
2008-12-18 06:49:09 +07:00
|
|
|
if (req)
|
2014-11-12 00:26:50 +07:00
|
|
|
pn_rx_submit(fp, req, GFP_ATOMIC);
|
2008-12-18 06:49:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static void __pn_reset(struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_phonet *fp = func_to_pn(f);
|
|
|
|
struct net_device *dev = fp->dev;
|
|
|
|
struct phonet_port *port = netdev_priv(dev);
|
|
|
|
|
|
|
|
netif_carrier_off(dev);
|
|
|
|
port->usb = NULL;
|
|
|
|
|
|
|
|
usb_ep_disable(fp->out_ep);
|
|
|
|
usb_ep_disable(fp->in_ep);
|
2009-08-07 04:56:44 +07:00
|
|
|
if (fp->rx.skb) {
|
|
|
|
dev_kfree_skb_irq(fp->rx.skb);
|
|
|
|
fp->rx.skb = NULL;
|
|
|
|
}
|
2008-12-18 06:49:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
|
|
|
|
{
|
|
|
|
struct f_phonet *fp = func_to_pn(f);
|
|
|
|
struct usb_gadget *gadget = fp->function.config->cdev->gadget;
|
|
|
|
|
|
|
|
if (intf == pn_control_intf_desc.bInterfaceNumber)
|
|
|
|
/* control interface, no altsetting */
|
|
|
|
return (alt > 0) ? -EINVAL : 0;
|
|
|
|
|
|
|
|
if (intf == pn_data_intf_desc.bInterfaceNumber) {
|
|
|
|
struct net_device *dev = fp->dev;
|
|
|
|
struct phonet_port *port = netdev_priv(dev);
|
|
|
|
|
|
|
|
/* data intf (0: inactive, 1: active) */
|
|
|
|
if (alt > 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock(&port->lock);
|
2015-02-03 05:24:17 +07:00
|
|
|
|
2015-09-16 17:10:52 +07:00
|
|
|
if (fp->in_ep->enabled)
|
2015-02-03 05:24:17 +07:00
|
|
|
__pn_reset(f);
|
|
|
|
|
2008-12-18 06:49:09 +07:00
|
|
|
if (alt == 1) {
|
|
|
|
int i;
|
|
|
|
|
2011-06-28 20:33:50 +07:00
|
|
|
if (config_ep_by_speed(gadget, f, fp->in_ep) ||
|
|
|
|
config_ep_by_speed(gadget, f, fp->out_ep)) {
|
|
|
|
fp->in_ep->desc = NULL;
|
|
|
|
fp->out_ep->desc = NULL;
|
2011-08-06 03:14:46 +07:00
|
|
|
spin_unlock(&port->lock);
|
2011-06-28 20:33:50 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-06-28 20:33:48 +07:00
|
|
|
usb_ep_enable(fp->out_ep);
|
|
|
|
usb_ep_enable(fp->in_ep);
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
port->usb = fp;
|
|
|
|
fp->out_ep->driver_data = fp;
|
|
|
|
fp->in_ep->driver_data = fp;
|
|
|
|
|
|
|
|
netif_carrier_on(dev);
|
|
|
|
for (i = 0; i < phonet_rxq_size; i++)
|
2014-11-12 00:26:50 +07:00
|
|
|
pn_rx_submit(fp, fp->out_reqv[i], GFP_ATOMIC);
|
2008-12-18 06:49:09 +07:00
|
|
|
}
|
|
|
|
spin_unlock(&port->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pn_get_alt(struct usb_function *f, unsigned intf)
|
|
|
|
{
|
|
|
|
struct f_phonet *fp = func_to_pn(f);
|
|
|
|
|
|
|
|
if (intf == pn_control_intf_desc.bInterfaceNumber)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (intf == pn_data_intf_desc.bInterfaceNumber) {
|
|
|
|
struct phonet_port *port = netdev_priv(fp->dev);
|
|
|
|
u8 alt;
|
|
|
|
|
|
|
|
spin_lock(&port->lock);
|
|
|
|
alt = port->usb != NULL;
|
|
|
|
spin_unlock(&port->lock);
|
|
|
|
return alt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pn_disconnect(struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_phonet *fp = func_to_pn(f);
|
|
|
|
struct phonet_port *port = netdev_priv(fp->dev);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* remain disabled until set_alt */
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
__pn_reset(f);
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2013-05-23 15:51:11 +07:00
|
|
|
static int pn_bind(struct usb_configuration *c, struct usb_function *f)
|
2008-12-18 06:49:09 +07:00
|
|
|
{
|
|
|
|
struct usb_composite_dev *cdev = c->cdev;
|
|
|
|
struct usb_gadget *gadget = cdev->gadget;
|
|
|
|
struct f_phonet *fp = func_to_pn(f);
|
|
|
|
struct usb_ep *ep;
|
|
|
|
int status, i;
|
|
|
|
|
2013-05-23 15:51:11 +07:00
|
|
|
struct f_phonet_opts *phonet_opts;
|
|
|
|
|
|
|
|
phonet_opts = container_of(f->fi, struct f_phonet_opts, func_inst);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* in drivers/usb/gadget/configfs.c:configfs_composite_bind()
|
|
|
|
* configurations are bound in sequence with list_for_each_entry,
|
|
|
|
* in each configuration its functions are bound in sequence
|
|
|
|
* with list_for_each_entry, so we assume no race condition
|
|
|
|
* with regard to phonet_opts->bound access
|
|
|
|
*/
|
|
|
|
if (!phonet_opts->bound) {
|
|
|
|
gphonet_set_gadget(phonet_opts->net, gadget);
|
|
|
|
status = gphonet_register_netdev(phonet_opts->net);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
phonet_opts->bound = true;
|
|
|
|
}
|
|
|
|
|
2008-12-18 06:49:09 +07:00
|
|
|
/* Reserve interface IDs */
|
|
|
|
status = usb_interface_id(c, f);
|
|
|
|
if (status < 0)
|
|
|
|
goto err;
|
|
|
|
pn_control_intf_desc.bInterfaceNumber = status;
|
|
|
|
pn_union_desc.bMasterInterface0 = status;
|
|
|
|
|
|
|
|
status = usb_interface_id(c, f);
|
|
|
|
if (status < 0)
|
|
|
|
goto err;
|
|
|
|
pn_data_nop_intf_desc.bInterfaceNumber = status;
|
|
|
|
pn_data_intf_desc.bInterfaceNumber = status;
|
|
|
|
pn_union_desc.bSlaveInterface0 = status;
|
|
|
|
|
|
|
|
/* Reserve endpoints */
|
|
|
|
status = -ENODEV;
|
|
|
|
ep = usb_ep_autoconfig(gadget, &pn_fs_sink_desc);
|
|
|
|
if (!ep)
|
|
|
|
goto err;
|
|
|
|
fp->out_ep = ep;
|
|
|
|
|
|
|
|
ep = usb_ep_autoconfig(gadget, &pn_fs_source_desc);
|
|
|
|
if (!ep)
|
|
|
|
goto err;
|
|
|
|
fp->in_ep = ep;
|
|
|
|
|
2012-10-23 03:15:06 +07:00
|
|
|
pn_hs_sink_desc.bEndpointAddress = pn_fs_sink_desc.bEndpointAddress;
|
|
|
|
pn_hs_source_desc.bEndpointAddress = pn_fs_source_desc.bEndpointAddress;
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
/* Do not try to bind Phonet twice... */
|
2012-10-23 03:15:06 +07:00
|
|
|
status = usb_assign_descriptors(f, fs_pn_function, hs_pn_function,
|
2016-02-06 08:06:07 +07:00
|
|
|
NULL, NULL);
|
2012-10-23 03:15:06 +07:00
|
|
|
if (status)
|
|
|
|
goto err;
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
/* Incoming USB requests */
|
|
|
|
status = -ENOMEM;
|
|
|
|
for (i = 0; i < phonet_rxq_size; i++) {
|
|
|
|
struct usb_request *req;
|
|
|
|
|
|
|
|
req = usb_ep_alloc_request(fp->out_ep, GFP_KERNEL);
|
|
|
|
if (!req)
|
2012-10-23 03:15:04 +07:00
|
|
|
goto err_req;
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
req->complete = pn_rx_complete;
|
|
|
|
fp->out_reqv[i] = req;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Outgoing USB requests */
|
|
|
|
fp->in_req = usb_ep_alloc_request(fp->in_ep, GFP_KERNEL);
|
|
|
|
if (!fp->in_req)
|
2012-10-23 03:15:04 +07:00
|
|
|
goto err_req;
|
2008-12-18 06:49:09 +07:00
|
|
|
|
|
|
|
INFO(cdev, "USB CDC Phonet function\n");
|
|
|
|
INFO(cdev, "using %s, OUT %s, IN %s\n", cdev->gadget->name,
|
|
|
|
fp->out_ep->name, fp->in_ep->name);
|
|
|
|
return 0;
|
|
|
|
|
2012-10-23 03:15:04 +07:00
|
|
|
err_req:
|
|
|
|
for (i = 0; i < phonet_rxq_size && fp->out_reqv[i]; i++)
|
|
|
|
usb_ep_free_request(fp->out_ep, fp->out_reqv[i]);
|
2012-10-23 03:15:06 +07:00
|
|
|
usb_free_all_descriptors(f);
|
2014-10-22 20:54:58 +07:00
|
|
|
err:
|
2008-12-18 06:49:09 +07:00
|
|
|
ERROR(cdev, "USB CDC Phonet: cannot autoconfigure\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-05-23 15:51:15 +07:00
|
|
|
static inline struct f_phonet_opts *to_f_phonet_opts(struct config_item *item)
|
|
|
|
{
|
|
|
|
return container_of(to_config_group(item), struct f_phonet_opts,
|
|
|
|
func_inst.group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void phonet_attr_release(struct config_item *item)
|
|
|
|
{
|
|
|
|
struct f_phonet_opts *opts = to_f_phonet_opts(item);
|
|
|
|
|
|
|
|
usb_put_function_instance(&opts->func_inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct configfs_item_operations phonet_item_ops = {
|
|
|
|
.release = phonet_attr_release,
|
|
|
|
};
|
|
|
|
|
2015-10-03 20:32:51 +07:00
|
|
|
static ssize_t f_phonet_ifname_show(struct config_item *item, char *page)
|
2013-05-23 15:51:15 +07:00
|
|
|
{
|
2015-10-03 20:32:51 +07:00
|
|
|
return gether_get_ifname(to_f_phonet_opts(item)->net, page, PAGE_SIZE);
|
2013-05-23 15:51:15 +07:00
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:51 +07:00
|
|
|
CONFIGFS_ATTR_RO(f_phonet_, ifname);
|
2013-05-23 15:51:15 +07:00
|
|
|
|
|
|
|
static struct configfs_attribute *phonet_attrs[] = {
|
2015-10-03 20:32:51 +07:00
|
|
|
&f_phonet_attr_ifname,
|
2013-05-23 15:51:15 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-10-16 22:18:41 +07:00
|
|
|
static const struct config_item_type phonet_func_type = {
|
2013-05-23 15:51:15 +07:00
|
|
|
.ct_item_ops = &phonet_item_ops,
|
|
|
|
.ct_attrs = phonet_attrs,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2013-05-23 15:51:11 +07:00
|
|
|
static void phonet_free_inst(struct usb_function_instance *f)
|
|
|
|
{
|
|
|
|
struct f_phonet_opts *opts;
|
|
|
|
|
|
|
|
opts = container_of(f, struct f_phonet_opts, func_inst);
|
|
|
|
if (opts->bound)
|
|
|
|
gphonet_cleanup(opts->net);
|
|
|
|
else
|
|
|
|
free_netdev(opts->net);
|
|
|
|
kfree(opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_function_instance *phonet_alloc_inst(void)
|
|
|
|
{
|
|
|
|
struct f_phonet_opts *opts;
|
|
|
|
|
|
|
|
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
|
|
|
|
if (!opts)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
opts->func_inst.free_func_inst = phonet_free_inst;
|
|
|
|
opts->net = gphonet_setup_default();
|
2013-07-25 14:13:18 +07:00
|
|
|
if (IS_ERR(opts->net)) {
|
|
|
|
struct net_device *net = opts->net;
|
|
|
|
kfree(opts);
|
|
|
|
return ERR_CAST(net);
|
|
|
|
}
|
2013-05-23 15:51:11 +07:00
|
|
|
|
2013-05-23 15:51:15 +07:00
|
|
|
config_group_init_type_name(&opts->func_inst.group, "",
|
|
|
|
&phonet_func_type);
|
|
|
|
|
2013-05-23 15:51:11 +07:00
|
|
|
return &opts->func_inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void phonet_free(struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_phonet *phonet;
|
|
|
|
|
|
|
|
phonet = func_to_pn(f);
|
|
|
|
kfree(phonet);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pn_unbind(struct usb_configuration *c, struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_phonet *fp = func_to_pn(f);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* We are already disconnected */
|
|
|
|
if (fp->in_req)
|
|
|
|
usb_ep_free_request(fp->in_ep, fp->in_req);
|
|
|
|
for (i = 0; i < phonet_rxq_size; i++)
|
|
|
|
if (fp->out_reqv[i])
|
|
|
|
usb_ep_free_request(fp->out_ep, fp->out_reqv[i]);
|
|
|
|
|
|
|
|
usb_free_all_descriptors(f);
|
|
|
|
}
|
|
|
|
|
2013-12-16 16:44:07 +07:00
|
|
|
static struct usb_function *phonet_alloc(struct usb_function_instance *fi)
|
2013-05-23 15:51:11 +07:00
|
|
|
{
|
|
|
|
struct f_phonet *fp;
|
|
|
|
struct f_phonet_opts *opts;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = sizeof(*fp) + (phonet_rxq_size * sizeof(struct usb_request *));
|
|
|
|
fp = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!fp)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
opts = container_of(fi, struct f_phonet_opts, func_inst);
|
|
|
|
|
|
|
|
fp->dev = opts->net;
|
|
|
|
fp->function.name = "phonet";
|
|
|
|
fp->function.bind = pn_bind;
|
|
|
|
fp->function.unbind = pn_unbind;
|
|
|
|
fp->function.set_alt = pn_set_alt;
|
|
|
|
fp->function.get_alt = pn_get_alt;
|
|
|
|
fp->function.disable = pn_disconnect;
|
|
|
|
fp->function.free_func = phonet_free;
|
|
|
|
spin_lock_init(&fp->rx.lock);
|
|
|
|
|
|
|
|
return &fp->function;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct net_device *gphonet_setup_default(void)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
struct phonet_port *port;
|
|
|
|
|
|
|
|
/* Create net device */
|
net: set name_assign_type in alloc_netdev()
Extend alloc_netdev{,_mq{,s}}() to take name_assign_type as argument, and convert
all users to pass NET_NAME_UNKNOWN.
Coccinelle patch:
@@
expression sizeof_priv, name, setup, txqs, rxqs, count;
@@
(
-alloc_netdev_mqs(sizeof_priv, name, setup, txqs, rxqs)
+alloc_netdev_mqs(sizeof_priv, name, NET_NAME_UNKNOWN, setup, txqs, rxqs)
|
-alloc_netdev_mq(sizeof_priv, name, setup, count)
+alloc_netdev_mq(sizeof_priv, name, NET_NAME_UNKNOWN, setup, count)
|
-alloc_netdev(sizeof_priv, name, setup)
+alloc_netdev(sizeof_priv, name, NET_NAME_UNKNOWN, setup)
)
v9: move comments here from the wrong commit
Signed-off-by: Tom Gundersen <teg@jklm.no>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-07-14 21:37:24 +07:00
|
|
|
dev = alloc_netdev(sizeof(*port), "upnlink%d", NET_NAME_UNKNOWN,
|
|
|
|
pn_net_setup);
|
2013-05-23 15:51:11 +07:00
|
|
|
if (!dev)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
port = netdev_priv(dev);
|
|
|
|
spin_lock_init(&port->lock);
|
|
|
|
netif_carrier_off(dev);
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gphonet_set_gadget(struct net_device *net, struct usb_gadget *g)
|
|
|
|
{
|
|
|
|
SET_NETDEV_DEV(net, &g->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gphonet_register_netdev(struct net_device *net)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = register_netdev(net);
|
|
|
|
if (status)
|
|
|
|
free_netdev(net);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-05-23 15:51:10 +07:00
|
|
|
void gphonet_cleanup(struct net_device *dev)
|
2008-12-18 06:49:09 +07:00
|
|
|
{
|
|
|
|
unregister_netdev(dev);
|
|
|
|
}
|
2013-05-23 15:51:13 +07:00
|
|
|
|
|
|
|
DECLARE_USB_FUNCTION_INIT(phonet, phonet_alloc_inst, phonet_alloc);
|
|
|
|
MODULE_AUTHOR("Rémi Denis-Courmont");
|
|
|
|
MODULE_LICENSE("GPL");
|