2019-05-19 21:51:43 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-04-18 15:24:21 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Peter Holik
|
|
|
|
*
|
|
|
|
* Intellon usb PLC (Powerline Communications) usb net driver
|
|
|
|
*
|
|
|
|
* http://www.tandel.be/downloads/INT51X1_Datasheet.pdf
|
|
|
|
*
|
|
|
|
* Based on the work of Jan 'RedBully' Seiffert
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-04-18 15:24:21 +08:00
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/usbnet.h>
|
|
|
|
|
|
|
|
#define INT51X1_VENDOR_ID 0x09e1
|
|
|
|
#define INT51X1_PRODUCT_ID 0x5121
|
|
|
|
|
|
|
|
#define INT51X1_HEADER_SIZE 2 /* 2 byte header */
|
|
|
|
|
|
|
|
#define PACKET_TYPE_PROMISCUOUS (1 << 0)
|
|
|
|
#define PACKET_TYPE_ALL_MULTICAST (1 << 1) /* no filter */
|
|
|
|
#define PACKET_TYPE_DIRECTED (1 << 2)
|
|
|
|
#define PACKET_TYPE_BROADCAST (1 << 3)
|
|
|
|
#define PACKET_TYPE_MULTICAST (1 << 4) /* filtered */
|
|
|
|
|
|
|
|
#define SET_ETHERNET_PACKET_FILTER 0x43
|
|
|
|
|
|
|
|
static int int51x1_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!(pskb_may_pull(skb, INT51X1_HEADER_SIZE))) {
|
2010-02-17 18:30:23 +08:00
|
|
|
netdev_err(dev->net, "unexpected tiny rx frame\n");
|
2009-04-18 15:24:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = le16_to_cpu(*(__le16 *)&skb->data[skb->len - 2]);
|
|
|
|
|
|
|
|
skb_trim(skb, len);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sk_buff *int51x1_tx_fixup(struct usbnet *dev,
|
|
|
|
struct sk_buff *skb, gfp_t flags)
|
|
|
|
{
|
|
|
|
int pack_len = skb->len;
|
|
|
|
int pack_with_header_len = pack_len + INT51X1_HEADER_SIZE;
|
|
|
|
int headroom = skb_headroom(skb);
|
|
|
|
int tailroom = skb_tailroom(skb);
|
|
|
|
int need_tail = 0;
|
|
|
|
__le16 *len;
|
|
|
|
|
|
|
|
/* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */
|
|
|
|
if ((pack_with_header_len) < dev->maxpacket)
|
|
|
|
need_tail = dev->maxpacket - pack_with_header_len + 1;
|
|
|
|
/*
|
|
|
|
* usbnet would send a ZLP if packetlength mod urbsize == 0 for us,
|
|
|
|
* but we need to know ourself, because this would add to the length
|
|
|
|
* we send down to the device...
|
|
|
|
*/
|
|
|
|
else if (!(pack_with_header_len % dev->maxpacket))
|
|
|
|
need_tail = 1;
|
|
|
|
|
|
|
|
if (!skb_cloned(skb) &&
|
|
|
|
(headroom + tailroom >= need_tail + INT51X1_HEADER_SIZE)) {
|
|
|
|
if (headroom < INT51X1_HEADER_SIZE || tailroom < need_tail) {
|
|
|
|
skb->data = memmove(skb->head + INT51X1_HEADER_SIZE,
|
|
|
|
skb->data, skb->len);
|
|
|
|
skb_set_tail_pointer(skb, skb->len);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct sk_buff *skb2;
|
|
|
|
|
|
|
|
skb2 = skb_copy_expand(skb,
|
|
|
|
INT51X1_HEADER_SIZE,
|
|
|
|
need_tail,
|
|
|
|
flags);
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
if (!skb2)
|
|
|
|
return NULL;
|
|
|
|
skb = skb2;
|
|
|
|
}
|
|
|
|
|
|
|
|
pack_len += need_tail;
|
|
|
|
pack_len &= 0x07ff;
|
|
|
|
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:23 +08:00
|
|
|
len = __skb_push(skb, INT51X1_HEADER_SIZE);
|
2009-04-18 15:24:21 +08:00
|
|
|
*len = cpu_to_le16(pack_len);
|
|
|
|
|
|
|
|
if(need_tail)
|
net: introduce __skb_put_[zero, data, u8]
follow Johannes Berg, semantic patch file as below,
@@
identifier p, p2;
expression len;
expression skb;
type t, t2;
@@
(
-p = __skb_put(skb, len);
+p = __skb_put_zero(skb, len);
|
-p = (t)__skb_put(skb, len);
+p = __skb_put_zero(skb, len);
)
... when != p
(
p2 = (t2)p;
-memset(p2, 0, len);
|
-memset(p, 0, len);
)
@@
identifier p;
expression len;
expression skb;
type t;
@@
(
-t p = __skb_put(skb, len);
+t p = __skb_put_zero(skb, len);
)
... when != p
(
-memset(p, 0, len);
)
@@
type t, t2;
identifier p, p2;
expression skb;
@@
t *p;
...
(
-p = __skb_put(skb, sizeof(t));
+p = __skb_put_zero(skb, sizeof(t));
|
-p = (t *)__skb_put(skb, sizeof(t));
+p = __skb_put_zero(skb, sizeof(t));
)
... when != p
(
p2 = (t2)p;
-memset(p2, 0, sizeof(*p));
|
-memset(p, 0, sizeof(*p));
)
@@
expression skb, len;
@@
-memset(__skb_put(skb, len), 0, len);
+__skb_put_zero(skb, len);
@@
expression skb, len, data;
@@
-memcpy(__skb_put(skb, len), data, len);
+__skb_put_data(skb, data, len);
@@
expression SKB, C, S;
typedef u8;
identifier fn = {__skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-18 22:48:17 +08:00
|
|
|
__skb_put_zero(skb, need_tail);
|
2009-04-18 15:24:21 +08:00
|
|
|
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void int51x1_set_multicast(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct usbnet *dev = netdev_priv(netdev);
|
|
|
|
u16 filter = PACKET_TYPE_DIRECTED | PACKET_TYPE_BROADCAST;
|
|
|
|
|
|
|
|
if (netdev->flags & IFF_PROMISC) {
|
|
|
|
/* do not expect to see traffic of other PLCs */
|
|
|
|
filter |= PACKET_TYPE_PROMISCUOUS;
|
2010-02-17 18:30:23 +08:00
|
|
|
netdev_info(dev->net, "promiscuous mode enabled\n");
|
2010-02-08 12:30:35 +08:00
|
|
|
} else if (!netdev_mc_empty(netdev) ||
|
2009-04-18 15:24:21 +08:00
|
|
|
(netdev->flags & IFF_ALLMULTI)) {
|
|
|
|
filter |= PACKET_TYPE_ALL_MULTICAST;
|
2010-02-17 18:30:23 +08:00
|
|
|
netdev_dbg(dev->net, "receive all multicast enabled\n");
|
2009-04-18 15:24:21 +08:00
|
|
|
} else {
|
|
|
|
/* ~PROMISCUOUS, ~MULTICAST */
|
2010-02-17 18:30:23 +08:00
|
|
|
netdev_dbg(dev->net, "receive own packets only\n");
|
2009-04-18 15:24:21 +08:00
|
|
|
}
|
|
|
|
|
2012-10-25 03:46:58 +08:00
|
|
|
usbnet_write_cmd_async(dev, SET_ETHERNET_PACKET_FILTER,
|
|
|
|
USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
|
|
|
filter, 0, NULL, 0);
|
2009-04-18 15:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct net_device_ops int51x1_netdev_ops = {
|
|
|
|
.ndo_open = usbnet_open,
|
|
|
|
.ndo_stop = usbnet_stop,
|
|
|
|
.ndo_start_xmit = usbnet_start_xmit,
|
|
|
|
.ndo_tx_timeout = usbnet_tx_timeout,
|
|
|
|
.ndo_change_mtu = usbnet_change_mtu,
|
2020-11-11 03:51:03 +08:00
|
|
|
.ndo_get_stats64 = dev_get_tstats64,
|
2009-04-18 15:24:21 +08:00
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
2011-08-16 14:29:01 +08:00
|
|
|
.ndo_set_rx_mode = int51x1_set_multicast,
|
2009-04-18 15:24:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int int51x1_bind(struct usbnet *dev, struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
int status = usbnet_get_ethernet_addr(dev, 3);
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
dev->net->hard_header_len += INT51X1_HEADER_SIZE;
|
|
|
|
dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
|
|
|
|
dev->net->netdev_ops = &int51x1_netdev_ops;
|
|
|
|
|
|
|
|
return usbnet_get_endpoints(dev, intf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct driver_info int51x1_info = {
|
|
|
|
.description = "Intellon usb powerline adapter",
|
|
|
|
.bind = int51x1_bind,
|
|
|
|
.rx_fixup = int51x1_rx_fixup,
|
|
|
|
.tx_fixup = int51x1_tx_fixup,
|
|
|
|
.in = 1,
|
|
|
|
.out = 2,
|
|
|
|
.flags = FLAG_ETHER,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_device_id products[] = {
|
|
|
|
{
|
|
|
|
USB_DEVICE(INT51X1_VENDOR_ID, INT51X1_PRODUCT_ID),
|
|
|
|
.driver_info = (unsigned long) &int51x1_info,
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, products);
|
|
|
|
|
|
|
|
static struct usb_driver int51x1_driver = {
|
|
|
|
.name = "int51x1",
|
|
|
|
.id_table = products,
|
|
|
|
.probe = usbnet_probe,
|
|
|
|
.disconnect = usbnet_disconnect,
|
|
|
|
.suspend = usbnet_suspend,
|
|
|
|
.resume = usbnet_resume,
|
2012-04-24 01:08:51 +08:00
|
|
|
.disable_hub_initiated_lpm = 1,
|
2009-04-18 15:24:21 +08:00
|
|
|
};
|
|
|
|
|
2011-11-19 01:44:20 +08:00
|
|
|
module_usb_driver(int51x1_driver);
|
2009-04-18 15:24:21 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Peter Holik");
|
|
|
|
MODULE_DESCRIPTION("Intellon usb powerline adapter");
|
|
|
|
MODULE_LICENSE("GPL");
|