usb driver for intellon int51x1 based PLC like devolo dlan duo
Subsystems (3)
PATCH RESEND 1/1 usb driver for intellon int51x1 based PLC like devolo dlan duo
This is a usb driver for the intellon int51x1 based PLC (Powerline Communications) like devolo dlan duo.
--- drivers/net/usb/Kconfig | 8 ++ drivers/net/usb/Makefile | 1 + drivers/net/usb/int51x1.c | 268 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 0 deletions(-) create mode 100644 drivers/net/usb/int51x1.c
drivers/net/usb/Kconfig +8 -0
@@ -345,4 +345,12 @@ config USB_HSO To compile this driver as a module, choose M here: the module will be called hso. +config USB_NET_INT51X1 + tristate "Intellon PLC based usb adapter" + depends on USB_USBNET + help + Choose this option if you're using a USB-based PLC + (Powerline Communications) solution with an Intellon + int51x1 chip, like the "devolo dLan duo". + endmenu
drivers/net/usb/Makefile +1 -0
@@ -19,4 +19,5 @@ obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o obj-$(CONFIG_USB_NET_ZAURUS) += zaurus.o obj-$(CONFIG_USB_NET_MCS7830) += mcs7830.o obj-$(CONFIG_USB_USBNET) += usbnet.o +obj-$(CONFIG_USB_NET_INT51X1) += int51x1.o
drivers/net/usb/int51x1.c new file +268 -0
268 lines not on this page · raw message
Signature · 7 lines
1.6.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 17 lines · Peter Holik
This is a usb driver for the intellon int51x1 based PLC (Powerline Communications) like devolo dlan duo.
Signed-off-by Peter Holik <[email protected]>--- drivers/net/usb/Kconfig | 8 ++ drivers/net/usb/Makefile | 1 + drivers/net/usb/int51x1.c | 268 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 0 deletions(-) create mode 100644 drivers/net/usb/int51x1.cdrivers/net/usb/int51x1.c new file +0
-0
drivers/net/usb/int51x1.c line 81
Quoted 6 lines
drivers/net/usb/int51x1.c new file +5
-0@@ -0,0 +1,268 @@ +static int int51x1_rx_fixup (struct usbnet *dev,struct sk_buff *skb) +{ +int len; + +if (unlikely (skb->len <INT51X1_HEADER_SIZE )) {
pskb_may_pull(...)
Quoted 21 lines
drivers/net/usb/int51x1.c new file +21
-0+deverr (dev,"unexpected tiny rx frame" ); +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 headroom =skb_headroom (skb); +int tailroom =skb_tailroom (skb); +int need_tail =0 ; +__le16 *len; + +/*
drivers/net/usb/int51x1.c line 112
Quoted 10 lines
drivers/net/usb/int51x1.c new file +10
-0+* 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... +*/ +if (!((pack_len +INT51X1_HEADER_SIZE ) % dev->maxpacket)) + need_tail =1 ; + +/* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */ +if ((pack_len +INT51X1_HEADER_SIZE + need_tail) < dev->maxpacket +1 ) + need_tail = dev->maxpacket +1 - pack_len -INT51X1_HEADER_SIZE ;
This is totally crazy code fragment, first need_tail is used like a boolean? But on the same some +1 scalar trick is being done? Is there some reason why DIV_ROUND_UP (linux/kernel.h) won't do what you want here and then you can trivally find diff = new - old ?
Quoted 42 lines
drivers/net/usb/int51x1.c new file +42
-0+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 ; + + len = (__le16 *)__skb_push (skb,INT51X1_HEADER_SIZE ); + *len =cpu_to_le16 (pack_len); + +if (need_tail) +memset (__skb_put (skb, need_tail),0 , need_tail); + +return skb; +} + +static void int51x1_async_cmd_callback (struct urb *urb) +{ +struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; +int status = urb->status; + +if (status <0 ) +dev_warn (&urb->dev->dev,"async callback failed with %d\n" , status); + +kfree (req); +usb_free_urb (urb);
drivers/net/usb/int51x1.c line 165
Quoted 10 lines
drivers/net/usb/int51x1.c new file +10
-0+} + +static void int51x1_set_multicast (struct net_device *netdev) +{ +struct usb_ctrlrequest *req; +int status; +struct urb *urb; +struct usbnet *dev =netdev_priv (netdev); +u16 filter =PACKET_TYPE_DIRECTED | +PACKET_TYPE_BROADCAST ;
Won't this fit on a single line?
Quoted 11 lines
drivers/net/usb/int51x1.c new file +11
-0+ +if (netdev->flags &IFF_PROMISC ) { +/* do not expect to see traffic of other PLCs */ + filter |=PACKET_TYPE_PROMISCUOUS ; +devinfo (dev,"promiscuous mode enabled" ); + }else if (netdev->mc_count || + (netdev->flags &IFF_ALLMULTI )) { + filter |=PACKET_TYPE_ALL_MULTICAST ; +devdbg (dev,"receive all multicast enabled" ); + }else { +/* ~PROMISCUOUS, ~MULTICAST */
drivers/net/usb/int51x1.c line 186
Quoted 10 lines
drivers/net/usb/int51x1.c new file +10
-0+devdbg (dev,"receive own packets only" ); + } + + urb =usb_alloc_urb (0 ,GFP_ATOMIC ); +if (!urb) { +devwarn (dev,"Error allocating URB" ); +return ; + } + + req =kmalloc (sizeof *req,GFP_ATOMIC );
sizeof(*req)
drivers/net/usb/int51x1.c line 190
Quoted 4 lines
drivers/net/usb/int51x1.c new file +4
-0+if (!req) { +devwarn (dev,"Error allocating control msg" ); +usb_free_urb (urb); +return ;
I'd use gotos instead for error handling since you need similar call in the later error handling block too. Gotos make it somewhat harder to miss some necessary rollback actions in one of the error blocks (not that this case is buggy atm).
Quoted 8 lines
drivers/net/usb/int51x1.c new file +8
-0+ } + + req->bRequestType =USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ; + req->bRequest =SET_ETHERNET_PACKET_FILTER ; + req->wValue =cpu_to_le16 (filter); + req->wIndex =0 ; + req->wLength =0 ; +
drivers/net/usb/int51x1.c line 208
Quoted 10 lines
drivers/net/usb/int51x1.c new file +10
-0+usb_fill_control_urb (urb, dev->udev,usb_sndctrlpipe (dev->udev,0 ), + (void *)req,NULL ,0 , + int51x1_async_cmd_callback, + (void *)req); + + status =usb_submit_urb (urb,GFP_ATOMIC ); +if (status <0 ) { +devwarn (dev,"Error submitting control msg, sts=%d" , status); +kfree (req); +usb_free_urb (urb);
Ditto.
Quoted 2 lines
drivers/net/usb/int51x1.c new file +2
-0+ } +}
Signature · 5 lines
i. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 20 lines · Peter Holik
Quoted 18 lines
This is a usb driver for the intellon int51x1 based PLC (Powerline Communications) like devolo dlan duo.
Signed-off-by Peter Holik <[email protected]>--- drivers/net/usb/Kconfig | 8 ++ drivers/net/usb/Makefile | 1 + drivers/net/usb/int51x1.c | 268 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+), 0 deletions(-) create mode 100644 drivers/net/usb/int51x1.cdrivers/net/usb/int51x1.c new file +0
-0@@ -0,0 +1,268 @@
Quoted 7 lines
drivers/net/usb/int51x1.c line 81
Quoted 5 lines
drivers/net/usb/int51x1.c new file +5
-0+static int int51x1_rx_fixup (struct usbnet *dev,struct sk_buff *skb) +{ +int len; + +if (unlikely (skb->len <INT51X1_HEADER_SIZE )) {
pskb_may_pull(...)
ok, done:
static int int51x1_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
{
int len;
if (pskb_may_pull(skb, INT51X1_HEADER_SIZE)) {
deverr(dev, "unexpected tiny rx frame");
return 0;
}
len = le16_to_cpu(*(__le16 *)&skb->data[skb->len - 2]);
skb_trim(skb, len);
return 1;
}Quoted 28 lines
Quoted 28 lines
drivers/net/usb/int51x1.c new file +28
-0+deverr (dev,"unexpected tiny rx frame" ); +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 headroom =skb_headroom (skb); +int tailroom =skb_tailroom (skb); +int need_tail =0 ; +__le16 *len; + +/* +* 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... +*/ +if (!((pack_len +INT51X1_HEADER_SIZE ) % dev->maxpacket)) + need_tail =1 ; +
Quoted 9 lines
drivers/net/usb/int51x1.c line 112
Quoted 3 lines
drivers/net/usb/int51x1.c new file +3
-0+/* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */ +if ((pack_len +INT51X1_HEADER_SIZE + need_tail) < dev->maxpacket +1 ) + need_tail = dev->maxpacket +1 - pack_len -INT51X1_HEADER_SIZE ;This is totally crazy code fragment, first
need_tailis used like a boolean? But on the same some +1 scalar trick is being done? Is there some reason whyDIV_ROUND_UP(linux/kernel.h) won't do what you want here and then you can trivally find diff = new - old ?
sorry i can't follow, can you convert this code to DIV_ROUND_UP
Quoted 46 lines
Quoted 46 lines
drivers/net/usb/int51x1.c new file +46
-0+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 ; + + len = (__le16 *)__skb_push (skb,INT51X1_HEADER_SIZE ); + *len =cpu_to_le16 (pack_len); + +if (need_tail) +memset (__skb_put (skb, need_tail),0 , need_tail); + +return skb; +} + +static void int51x1_async_cmd_callback (struct urb *urb) +{ +struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; +int status = urb->status; + +if (status <0 ) +dev_warn (&urb->dev->dev,"async callback failed with %d\n" , status); + +kfree (req); +usb_free_urb (urb); +} + +static void int51x1_set_multicast (struct net_device *netdev) +{
Quoted 9 lines
drivers/net/usb/int51x1.c line 165
Quoted 6 lines
drivers/net/usb/int51x1.c new file +6
-0+struct usb_ctrlrequest *req; +int status; +struct urb *urb; +struct usbnet *dev =netdev_priv (netdev); +u16 filter =PACKET_TYPE_DIRECTED | +PACKET_TYPE_BROADCAST ;Won't this fit on a single line?
ok, done
Quoted 15 lines
Quoted 15 lines
drivers/net/usb/int51x1.c new file +15
-0+ +if (netdev->flags &IFF_PROMISC ) { +/* do not expect to see traffic of other PLCs */ + filter |=PACKET_TYPE_PROMISCUOUS ; +devinfo (dev,"promiscuous mode enabled" ); + }else if (netdev->mc_count || + (netdev->flags &IFF_ALLMULTI )) { + filter |=PACKET_TYPE_ALL_MULTICAST ; +devdbg (dev,"receive all multicast enabled" ); + }else { +/* ~PROMISCUOUS, ~MULTICAST */ +devdbg (dev,"receive own packets only" ); + } + + urb =usb_alloc_urb (0 ,GFP_ATOMIC );
Quoted 9 lines
drivers/net/usb/int51x1.c line 186
Quoted 6 lines
drivers/net/usb/int51x1.c new file +6
-0+if (!urb) { +devwarn (dev,"Error allocating URB" ); +return ; + } + + req =kmalloc (sizeof *req,GFP_ATOMIC );
sizeof(*req)
ok, done
Quoted 10 lines
drivers/net/usb/int51x1.c line 190
Quoted 4 lines
drivers/net/usb/int51x1.c new file +4
-0+if (!req) { +devwarn (dev,"Error allocating control msg" ); +usb_free_urb (urb); +return ;I'd use gotos instead for error handling since you need similar call in the later error handling block too. Gotos make it somewhat harder to miss some necessary rollback actions in one of the error blocks (not that this case is buggy atm).
ok, done like you suggested - see at the end
Quoted 12 lines
Quoted 12 lines
drivers/net/usb/int51x1.c new file +12
-0+ } + + req->bRequestType =USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ; + req->bRequest =SET_ETHERNET_PACKET_FILTER ; + req->wValue =cpu_to_le16 (filter); + req->wIndex =0 ; + req->wLength =0 ; + +usb_fill_control_urb (urb, dev->udev,usb_sndctrlpipe (dev->udev,0 ), + (void *)req,NULL ,0 , + int51x1_async_cmd_callback, + (void *)req);
Quoted 8 lines
drivers/net/usb/int51x1.c line 208
Quoted 6 lines
drivers/net/usb/int51x1.c new file +6
-0+ + status =usb_submit_urb (urb,GFP_ATOMIC ); +if (status <0 ) { +devwarn (dev,"Error submitting control msg, sts=%d" , status); +kfree (req); +usb_free_urb (urb);Ditto.
static void int51x1_set_multicast(struct net_device *netdev)
{
struct usb_ctrlrequest *req;
int status;
struct urb *urb;
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;
devinfo(dev, "promiscuous mode enabled");
} else if (netdev->mc_count ||
(netdev->flags & IFF_ALLMULTI)) {
filter |= PACKET_TYPE_ALL_MULTICAST;
devdbg(dev, "receive all multicast enabled");
} else {
/* ~PROMISCUOUS, ~MULTICAST */
devdbg(dev, "receive own packets only");
}
urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!urb) {
devwarn(dev, "Error allocating URB");
goto out;
}
req = kmalloc(sizeof(*req), GFP_ATOMIC);
if (!req) {
devwarn(dev, "Error allocating control msg");
goto out1;
}
req->bRequestType = USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
req->bRequest = SET_ETHERNET_PACKET_FILTER;
req->wValue = cpu_to_le16(filter);
req->wIndex = 0;
req->wLength = 0;
usb_fill_control_urb(urb, dev->udev, usb_sndctrlpipe(dev->udev, 0),
(void *)req, NULL, 0,
int51x1_async_cmd_callback,
(void *)req);
status = usb_submit_urb(urb, GFP_ATOMIC);
if (status < 0) {
devwarn(dev, "Error submitting control msg, sts=%d", status);
goto out2;
}
return;
out2:
kfree(req);
out1:
usb_free_urb(urb);out:
}
cu Peter
Quoted 17 lines
Quoted 17 lines
drivers/net/usb/int51x1.c new file +17
-0+static struct sk_buff *int51x1_tx_fixup (struct usbnet *dev, +struct sk_buff *skb,gfp_t flags) +{ +int pack_len = skb->len; +int headroom =skb_headroom (skb); +int tailroom =skb_tailroom (skb); +int need_tail =0 ; +__le16 *len; + +/* +* 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... +*/ +if (!((pack_len +INT51X1_HEADER_SIZE ) % dev->maxpacket)) + need_tail =1 ; +
Quoted 9 lines
drivers/net/usb/int51x1.c line 112
Quoted 3 lines
drivers/net/usb/int51x1.c new file +3
-0+/* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */ +if ((pack_len +INT51X1_HEADER_SIZE + need_tail) < dev->maxpacket +1 ) + need_tail = dev->maxpacket +1 - pack_len -INT51X1_HEADER_SIZE ;This is totally crazy code fragment, first
need_tailis used like a boolean? But on the same some +1 scalar trick is being done? Is there some reason whyDIV_ROUND_UP(linux/kernel.h) won't do what you want here and then you can trivally find diff = new - old ?
maybe this version is not so crazy for you?
/* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */
if ((pack_len + INT51X1_HEADER_SIZE) < dev->maxpacket)
need_tail = dev->maxpacket - pack_len - INT51X1_HEADER_SIZE + 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_len + INT51X1_HEADER_SIZE) % dev->maxpacket))
need_tail = 1;cu Peter
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 29 lines · Peter Holik
Quoted 17 lines
Quoted 17 lines
drivers/net/usb/int51x1.c new file +17
-0+static struct sk_buff *int51x1_tx_fixup (struct usbnet *dev, +struct sk_buff *skb,gfp_t flags) +{ +int pack_len = skb->len; +int headroom =skb_headroom (skb); +int tailroom =skb_tailroom (skb); +int need_tail =0 ; +__le16 *len; + +/* +* 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... +*/ +if (!((pack_len +INT51X1_HEADER_SIZE ) % dev->maxpacket)) + need_tail =1 ; +Quoted 9 lines
drivers/net/usb/int51x1.c line 112
Quoted 3 lines
drivers/net/usb/int51x1.c new file +3
-0+/* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */ +if ((pack_len +INT51X1_HEADER_SIZE + need_tail) < dev->maxpacket +1 ) + need_tail = dev->maxpacket +1 - pack_len -INT51X1_HEADER_SIZE ;This is totally crazy code fragment, first
need_tailis used like a boolean? But on the same some +1 scalar trick is being done? Is there some reason whyDIV_ROUND_UP(linux/kernel.h) won't do what you want here and then you can trivally find diff = new - old ?maybe this version is not so crazy for you?
Quoted 10 lines
/* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */
if ((pack_len + INT51X1_HEADER_SIZE) < dev->maxpacket)
need_tail = dev->maxpacket - pack_len - INT51X1_HEADER_SIZE + 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_len + INT51X1_HEADER_SIZE) % dev->maxpacket))
need_tail = 1;Certainly looks more obvious, having that + need_tail and the related + 1 on the other side of the condition made the original very hard to read (and I failed to read it correctly which was the reason for the wrong DIV_ROUND_UP comment I made). This one is much better. I guess adding a temporary var for pack_len + INT51X1_HEADER_SIZE would also make it somewhat nicer looking.
Signature · 5 lines
i. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
cover usb driver for intellon int51x1 based PLC like devolo dlan duo
Hi,
I am submitting a series of 2 patches for inclusion in 2.6.30. Here is a brief description of the patch series:
- because of using the same function get_ethernet_addr as cdc_ether.c i export usbnet_get_ethernet_addr from usbnet and fixed cdc_ether (suggested by Oliver Neukum).
- usb driver for intellon int51x1 based PLC like devolo dlan duo with improvements suggested by the guys of the mailinglist
cu Peter
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
David Miller
maintainerFrom: "Peter Holik" <[email protected]>
Date: Sat, 18 Apr 2009 18:42:59 +0200 (CEST)
Quoted 7 lines
I am submitting a series of 2 patches for inclusion in 2.6.30. Here is a brief description of the patch series:
- because of using the same functionget_ethernet_addrascdc_ether.ci exportusbnet_get_ethernet_addrfrom usbnet and fixedcdc_ether(suggested by Oliver Neukum).
- usb driver for intellon int51x1 based PLC like devolo dlan duo with improvements suggested by the guys of the mailinglist
I've applied the most recent version of this driver submission to net-next-2.6, thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html