2005-08-31 16:53:42 +00:00
|
|
|
/*
|
|
|
|
* GeneSys GL620USB-A based links
|
|
|
|
* Copyright (C) 2001 by Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
|
|
|
|
* Copyright (C) 2001 by Stanislav Brabec <utx@penguin.cz>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2013-12-06 14:28:46 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2005-08-31 16:53:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// #define DEBUG // error path messages, extra info
|
|
|
|
// #define VERBOSE // more; success messages
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/usb.h>
|
2008-01-25 22:51:45 +00:00
|
|
|
#include <linux/usb/usbnet.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 08:04:11 +00:00
|
|
|
#include <linux/gfp.h>
|
2005-08-31 16:53:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GeneSys GL620USB-A (www.genesyslogic.com.tw)
|
|
|
|
*
|
|
|
|
* ... should partially interop with the Win32 driver for this hardware.
|
|
|
|
* The GeneSys docs imply there's some NDIS issue motivating this framing.
|
|
|
|
*
|
|
|
|
* Some info from GeneSys:
|
|
|
|
* - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
|
|
|
|
* (Some cables, like the BAFO-100c, use the half duplex version.)
|
|
|
|
* - For the full duplex model, the low bit of the version code says
|
|
|
|
* which side is which ("left/right").
|
|
|
|
* - For the half duplex type, a control/interrupt handshake settles
|
|
|
|
* the transfer direction. (That's disabled here, partially coded.)
|
|
|
|
* A control URB would block until other side writes an interrupt.
|
|
|
|
*
|
|
|
|
* Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
|
|
|
|
* and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// control msg write command
|
|
|
|
#define GENELINK_CONNECT_WRITE 0xF0
|
|
|
|
// interrupt pipe index
|
|
|
|
#define GENELINK_INTERRUPT_PIPE 0x03
|
|
|
|
// interrupt read buffer size
|
|
|
|
#define INTERRUPT_BUFSIZE 0x08
|
|
|
|
// interrupt pipe interval value
|
|
|
|
#define GENELINK_INTERRUPT_INTERVAL 0x10
|
|
|
|
// max transmit packet number per transmit
|
|
|
|
#define GL_MAX_TRANSMIT_PACKETS 32
|
|
|
|
// max packet length
|
|
|
|
#define GL_MAX_PACKET_LEN 1514
|
|
|
|
// max receive buffer size
|
|
|
|
#define GL_RCV_BUF_SIZE \
|
|
|
|
(((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
|
|
|
|
|
|
|
|
struct gl_packet {
|
2007-02-09 16:39:55 +00:00
|
|
|
__le32 packet_length;
|
2005-08-31 16:53:42 +00:00
|
|
|
char packet_data [1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gl_header {
|
2007-02-09 16:39:55 +00:00
|
|
|
__le32 packet_count;
|
2005-08-31 16:53:42 +00:00
|
|
|
struct gl_packet packets;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct gl_header *header;
|
|
|
|
struct gl_packet *packet;
|
|
|
|
struct sk_buff *gl_skb;
|
|
|
|
u32 size;
|
2007-02-09 16:39:55 +00:00
|
|
|
u32 count;
|
2005-08-31 16:53:42 +00:00
|
|
|
|
2014-02-13 16:50:19 +00:00
|
|
|
/* This check is no longer done by usbnet */
|
|
|
|
if (skb->len < dev->net->hard_header_len)
|
|
|
|
return 0;
|
|
|
|
|
2005-08-31 16:53:42 +00:00
|
|
|
header = (struct gl_header *) skb->data;
|
|
|
|
|
|
|
|
// get the packet count of the received skb
|
2007-02-09 16:39:55 +00:00
|
|
|
count = le32_to_cpu(header->packet_count);
|
|
|
|
if (count > GL_MAX_TRANSMIT_PACKETS) {
|
2012-09-19 09:46:14 +00:00
|
|
|
netdev_dbg(dev->net,
|
|
|
|
"genelink: invalid received packet count %u\n",
|
|
|
|
count);
|
2005-08-31 16:53:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the current packet pointer to the first packet
|
|
|
|
packet = &header->packets;
|
|
|
|
|
|
|
|
// decrement the length for the packet count size 4 bytes
|
|
|
|
skb_pull(skb, 4);
|
|
|
|
|
2007-02-09 16:39:55 +00:00
|
|
|
while (count > 1) {
|
2005-08-31 16:53:42 +00:00
|
|
|
// get the packet length
|
|
|
|
size = le32_to_cpu(packet->packet_length);
|
|
|
|
|
|
|
|
// this may be a broken packet
|
|
|
|
if (size > GL_MAX_PACKET_LEN) {
|
2012-09-19 09:46:14 +00:00
|
|
|
netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
|
|
|
|
size);
|
2005-08-31 16:53:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate the skb for the individual packet
|
|
|
|
gl_skb = alloc_skb(size, GFP_ATOMIC);
|
|
|
|
if (gl_skb) {
|
|
|
|
|
|
|
|
// copy the packet data to the new skb
|
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 12:29:20 +00:00
|
|
|
skb_put_data(gl_skb, packet->packet_data, size);
|
2005-08-31 16:53:42 +00:00
|
|
|
usbnet_skb_return(dev, gl_skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
// advance to the next packet
|
2007-02-09 16:39:55 +00:00
|
|
|
packet = (struct gl_packet *)&packet->packet_data[size];
|
|
|
|
count--;
|
2005-08-31 16:53:42 +00:00
|
|
|
|
|
|
|
// shift the data pointer to the next gl_packet
|
|
|
|
skb_pull(skb, size + 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip the packet length field 4 bytes
|
|
|
|
skb_pull(skb, 4);
|
|
|
|
|
|
|
|
if (skb->len > GL_MAX_PACKET_LEN) {
|
2012-09-19 09:46:14 +00:00
|
|
|
netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
|
|
|
|
skb->len);
|
2005-08-31 16:53:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sk_buff *
|
2005-10-21 07:21:58 +00:00
|
|
|
genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
|
2005-08-31 16:53:42 +00:00
|
|
|
{
|
|
|
|
int padlen;
|
|
|
|
int length = skb->len;
|
|
|
|
int headroom = skb_headroom(skb);
|
|
|
|
int tailroom = skb_tailroom(skb);
|
2007-02-09 16:39:55 +00:00
|
|
|
__le32 *packet_count;
|
|
|
|
__le32 *packet_len;
|
2005-08-31 16:53:42 +00:00
|
|
|
|
|
|
|
// FIXME: magic numbers, bleech
|
|
|
|
padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
|
|
|
|
|
|
|
|
if ((!skb_cloned(skb))
|
|
|
|
&& ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
|
|
|
|
if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
|
|
|
|
skb->data = memmove(skb->head + (4 + 4*1),
|
|
|
|
skb->data, skb->len);
|
2007-04-20 03:29:13 +00:00
|
|
|
skb_set_tail_pointer(skb, skb->len);
|
2005-08-31 16:53:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct sk_buff *skb2;
|
|
|
|
skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags);
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
skb = skb2;
|
|
|
|
if (!skb)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attach the packet count to the header
|
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 12:29:23 +00:00
|
|
|
packet_count = skb_push(skb, (4 + 4 * 1));
|
2005-08-31 16:53:42 +00:00
|
|
|
packet_len = packet_count + 1;
|
|
|
|
|
|
|
|
*packet_count = cpu_to_le32(1);
|
|
|
|
*packet_len = cpu_to_le32(length);
|
|
|
|
|
|
|
|
// add padding byte
|
|
|
|
if ((skb->len % dev->maxpacket) == 0)
|
|
|
|
skb_put(skb, 1);
|
|
|
|
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int genelink_bind(struct usbnet *dev, struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
dev->hard_mtu = GL_RCV_BUF_SIZE;
|
|
|
|
dev->net->hard_header_len += 4;
|
|
|
|
dev->in = usb_rcvbulkpipe(dev->udev, dev->driver_info->in);
|
|
|
|
dev->out = usb_sndbulkpipe(dev->udev, dev->driver_info->out);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct driver_info genelink_info = {
|
|
|
|
.description = "Genesys GeneLink",
|
usbnet: use eth%d name for known ethernet devices
The documentation for the USB ethernet devices suggests that
only some devices are supposed to use usb0 as the network interface
name instead of eth0. The logic used there, and documented in
Kconfig for CDC is that eth0 will be used when the mac address
is a globally assigned one, but usb0 is used for the locally
managed range that is typically used on point-to-point links.
Unfortunately, this has caused a lot of pain on the smsc95xx
device that is used on the popular pandaboard without an
EEPROM to store the MAC address, which causes the driver to
call random_ether_address().
Obviously, there should be a proper MAC addressed assigned to
the device, and discussions are ongoing about how to solve
this, but this patch at least makes sure that the default
interface naming gets a little saner and matches what the
user can expect based on the documentation, including for
new devices.
The approach taken here is to flag whether a device might be a
point-to-point link with the new FLAG_POINTTOPOINT setting in
the usbnet driver_info. A driver can set both FLAG_POINTTOPOINT
and FLAG_ETHER if it is not sure (e.g. cdc_ether), or just one
of the two. The usbnet framework only looks at the MAC address
for device naming if both flags are set, otherwise it trusts the
flag.
Signed-off-by: Arnd Bergmann <arnd.bergmann@linaro.org>
Tested-by: Andy Green <andy.green@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-04-02 03:12:02 +00:00
|
|
|
.flags = FLAG_POINTTOPOINT | FLAG_FRAMING_GL | FLAG_NO_SETINT,
|
2005-08-31 16:53:42 +00:00
|
|
|
.bind = genelink_bind,
|
|
|
|
.rx_fixup = genelink_rx_fixup,
|
|
|
|
.tx_fixup = genelink_tx_fixup,
|
|
|
|
|
|
|
|
.in = 1, .out = 2,
|
|
|
|
|
|
|
|
#ifdef GENELINK_ACK
|
|
|
|
.check_connect =genelink_check_connect,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_device_id products [] = {
|
|
|
|
|
|
|
|
{
|
|
|
|
USB_DEVICE(0x05e3, 0x0502), // GL620USB-A
|
|
|
|
.driver_info = (unsigned long) &genelink_info,
|
|
|
|
},
|
|
|
|
/* NOT: USB_DEVICE(0x05e3, 0x0501), // GL620USB
|
|
|
|
* that's half duplex, not currently supported
|
|
|
|
*/
|
|
|
|
{ }, // END
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, products);
|
|
|
|
|
|
|
|
static struct usb_driver gl620a_driver = {
|
|
|
|
.name = "gl620a",
|
|
|
|
.id_table = products,
|
|
|
|
.probe = usbnet_probe,
|
|
|
|
.disconnect = usbnet_disconnect,
|
|
|
|
.suspend = usbnet_suspend,
|
|
|
|
.resume = usbnet_resume,
|
2012-04-23 17:08:51 +00:00
|
|
|
.disable_hub_initiated_lpm = 1,
|
2005-08-31 16:53:42 +00:00
|
|
|
};
|
|
|
|
|
2011-11-18 17:44:20 +00:00
|
|
|
module_usb_driver(gl620a_driver);
|
2005-08-31 16:53:42 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Jiun-Jie Huang");
|
|
|
|
MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|