2 * Copyright (c) 2009 Peter Holik
4 * Intellon usb PLC (Powerline Communications) usb net driver
6 * http://www.tandel.be/downloads/INT51X1_Datasheet.pdf
8 * Based on the work of Jan 'RedBully' Seiffert
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or.
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 #include <linux/module.h>
27 #include <linux/ctype.h>
28 #include <linux/netdevice.h>
29 #include <linux/etherdevice.h>
30 #include <linux/ethtool.h>
31 #include <linux/slab.h>
32 #include <linux/mii.h>
33 #include <linux/usb.h>
34 #include <linux/usb/usbnet.h>
36 #define INT51X1_VENDOR_ID 0x09e1
37 #define INT51X1_PRODUCT_ID 0x5121
39 #define INT51X1_HEADER_SIZE 2 /* 2 byte header */
41 #define PACKET_TYPE_PROMISCUOUS (1 << 0)
42 #define PACKET_TYPE_ALL_MULTICAST (1 << 1) /* no filter */
43 #define PACKET_TYPE_DIRECTED (1 << 2)
44 #define PACKET_TYPE_BROADCAST (1 << 3)
45 #define PACKET_TYPE_MULTICAST (1 << 4) /* filtered */
47 #define SET_ETHERNET_PACKET_FILTER 0x43
49 static int int51x1_rx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
)
53 if (!(pskb_may_pull(skb
, INT51X1_HEADER_SIZE
))) {
54 netdev_err(dev
->net
, "unexpected tiny rx frame\n");
58 len
= le16_to_cpu(*(__le16
*)&skb
->data
[skb
->len
- 2]);
65 static struct sk_buff
*int51x1_tx_fixup(struct usbnet
*dev
,
66 struct sk_buff
*skb
, gfp_t flags
)
68 int pack_len
= skb
->len
;
69 int pack_with_header_len
= pack_len
+ INT51X1_HEADER_SIZE
;
70 int headroom
= skb_headroom(skb
);
71 int tailroom
= skb_tailroom(skb
);
75 /* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */
76 if ((pack_with_header_len
) < dev
->maxpacket
)
77 need_tail
= dev
->maxpacket
- pack_with_header_len
+ 1;
79 * usbnet would send a ZLP if packetlength mod urbsize == 0 for us,
80 * but we need to know ourself, because this would add to the length
81 * we send down to the device...
83 else if (!(pack_with_header_len
% dev
->maxpacket
))
86 if (!skb_cloned(skb
) &&
87 (headroom
+ tailroom
>= need_tail
+ INT51X1_HEADER_SIZE
)) {
88 if (headroom
< INT51X1_HEADER_SIZE
|| tailroom
< need_tail
) {
89 skb
->data
= memmove(skb
->head
+ INT51X1_HEADER_SIZE
,
91 skb_set_tail_pointer(skb
, skb
->len
);
96 skb2
= skb_copy_expand(skb
,
100 dev_kfree_skb_any(skb
);
106 pack_len
+= need_tail
;
109 len
= __skb_push(skb
, INT51X1_HEADER_SIZE
);
110 *len
= cpu_to_le16(pack_len
);
113 __skb_put_zero(skb
, need_tail
);
118 static void int51x1_set_multicast(struct net_device
*netdev
)
120 struct usbnet
*dev
= netdev_priv(netdev
);
121 u16 filter
= PACKET_TYPE_DIRECTED
| PACKET_TYPE_BROADCAST
;
123 if (netdev
->flags
& IFF_PROMISC
) {
124 /* do not expect to see traffic of other PLCs */
125 filter
|= PACKET_TYPE_PROMISCUOUS
;
126 netdev_info(dev
->net
, "promiscuous mode enabled\n");
127 } else if (!netdev_mc_empty(netdev
) ||
128 (netdev
->flags
& IFF_ALLMULTI
)) {
129 filter
|= PACKET_TYPE_ALL_MULTICAST
;
130 netdev_dbg(dev
->net
, "receive all multicast enabled\n");
132 /* ~PROMISCUOUS, ~MULTICAST */
133 netdev_dbg(dev
->net
, "receive own packets only\n");
136 usbnet_write_cmd_async(dev
, SET_ETHERNET_PACKET_FILTER
,
137 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
141 static const struct net_device_ops int51x1_netdev_ops
= {
142 .ndo_open
= usbnet_open
,
143 .ndo_stop
= usbnet_stop
,
144 .ndo_start_xmit
= usbnet_start_xmit
,
145 .ndo_tx_timeout
= usbnet_tx_timeout
,
146 .ndo_change_mtu
= usbnet_change_mtu
,
147 .ndo_get_stats64
= usbnet_get_stats64
,
148 .ndo_set_mac_address
= eth_mac_addr
,
149 .ndo_validate_addr
= eth_validate_addr
,
150 .ndo_set_rx_mode
= int51x1_set_multicast
,
153 static int int51x1_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
155 int status
= usbnet_get_ethernet_addr(dev
, 3);
160 dev
->net
->hard_header_len
+= INT51X1_HEADER_SIZE
;
161 dev
->hard_mtu
= dev
->net
->mtu
+ dev
->net
->hard_header_len
;
162 dev
->net
->netdev_ops
= &int51x1_netdev_ops
;
164 return usbnet_get_endpoints(dev
, intf
);
167 static const struct driver_info int51x1_info
= {
168 .description
= "Intellon usb powerline adapter",
169 .bind
= int51x1_bind
,
170 .rx_fixup
= int51x1_rx_fixup
,
171 .tx_fixup
= int51x1_tx_fixup
,
177 static const struct usb_device_id products
[] = {
179 USB_DEVICE(INT51X1_VENDOR_ID
, INT51X1_PRODUCT_ID
),
180 .driver_info
= (unsigned long) &int51x1_info
,
184 MODULE_DEVICE_TABLE(usb
, products
);
186 static struct usb_driver int51x1_driver
= {
188 .id_table
= products
,
189 .probe
= usbnet_probe
,
190 .disconnect
= usbnet_disconnect
,
191 .suspend
= usbnet_suspend
,
192 .resume
= usbnet_resume
,
193 .disable_hub_initiated_lpm
= 1,
196 module_usb_driver(int51x1_driver
);
198 MODULE_AUTHOR("Peter Holik");
199 MODULE_DESCRIPTION("Intellon usb powerline adapter");
200 MODULE_LICENSE("GPL");