| 1 | |
| 2 | |
| 3 | * GeneSys GL620USB-A based links
|
| 4 | * Copyright (C) 2001 by Jiun-Jie Huang <[email protected]>
|
| 5 | * Copyright (C) 2001 by Stanislav Brabec <[email protected]>
|
| 6 |
|
| 7 |
|
| 8 | |
| 9 | |
| 10 |
|
| 11 | #include <linux/module.h>
|
| 12 | #include <linux/netdevice.h>
|
| 13 | #include <linux/etherdevice.h>
|
| 14 | #include <linux/ethtool.h>
|
| 15 | #include <linux/workqueue.h>
|
| 16 | #include <linux/mii.h>
|
| 17 | #include <linux/usb.h>
|
| 18 | #include <linux/usb/usbnet.h>
|
| 19 | #include <linux/gfp.h>
|
| 20 |
|
| 21 |
|
| 22 | |
| 23 | * GeneSys GL620USB-A (www.genesyslogic.com.tw)
|
| 24 | *
|
| 25 | * ... should partially interop with the Win32 driver for this hardware.
|
| 26 | * The GeneSys docs imply there's some NDIS issue motivating this framing.
|
| 27 | *
|
| 28 | * Some info from GeneSys:
|
| 29 | * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
|
| 30 | * (Some cables, like the BAFO-100c, use the half duplex version.)
|
| 31 | * - For the full duplex model, the low bit of the version code says
|
| 32 | * which side is which ("left/right").
|
| 33 | * - For the half duplex type, a control/interrupt handshake settles
|
| 34 | * the transfer direction. (That's disabled here, partially coded.)
|
| 35 | * A control URB would block until other side writes an interrupt.
|
| 36 | *
|
| 37 | * Original code from Jiun-Jie Huang <[email protected]>
|
| 38 | * and merged into "usbnet" by Stanislav Brabec <[email protected]>.
|
| 39 |
|
| 40 |
|
| 41 | |
| 42 | #define GENELINK_CONNECT_WRITE 0xF0
|
| 43 | |
| 44 | #define GENELINK_INTERRUPT_PIPE 0x03
|
| 45 | |
| 46 | #define INTERRUPT_BUFSIZE 0x08
|
| 47 | |
| 48 | #define GENELINK_INTERRUPT_INTERVAL 0x10
|
| 49 | |
| 50 | #define GL_MAX_TRANSMIT_PACKETS 32
|
| 51 | |
| 52 | #define GL_MAX_PACKET_LEN 1514
|
| 53 | |
| 54 | #define GL_RCV_BUF_SIZE \
|
| 55 | (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
|
| 56 |
|
| 57 | struct gl_packet {
|
| 58 | __le32 packet_length;
|
| 59 | char packet_data[];
|
| 60 | };
|
| 61 |
|
| 62 | struct gl_header {
|
| 63 | __le32 packet_count;
|
| 64 | struct gl_packet packets;
|
| 65 | };
|
| 66 |
|
| 67 | static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
| 68 | {
|
| 69 | struct gl_header *header;
|
| 70 | struct gl_packet *packet;
|
| 71 | struct sk_buff *gl_skb;
|
| 72 | u32 size;
|
| 73 | u32 count;
|
| 74 |
|
| 75 |
|
| 76 | if (skb->len < dev->net->hard_header_len)
|
| 77 | return 0;
|
| 78 |
|
| 79 | header = (struct gl_header *) skb->data;
|
| 80 |
|
| 81 | |
| 82 | count = le32_to_cpu(header->packet_count);
|
| 83 | if (count > GL_MAX_TRANSMIT_PACKETS) {
|
| 84 | netdev_dbg(dev->net,
|
| 85 | "genelink: invalid received packet count %u\n",
|
| 86 | count);
|
| 87 | return 0;
|
| 88 | }
|
| 89 |
|
| 90 | |
| 91 | packet = &header->packets;
|
| 92 |
|
| 93 | |
| 94 | skb_pull(skb, 4);
|
| 95 |
|
| 96 | while (count > 1) {
|
| 97 | |
| 98 | size = le32_to_cpu(packet->packet_length);
|
| 99 |
|
| 100 | |
| 101 | if (size > GL_MAX_PACKET_LEN) {
|
| 102 | netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
|
| 103 | size);
|
| 104 | return 0;
|
| 105 | }
|
| 106 |
|
| 107 | if (!skb_pull(skb, size + 4))
|
| 108 | return 0;
|
| 109 |
|
| 110 | |
| 111 | gl_skb = alloc_skb(size, GFP_ATOMIC);
|
| 112 | if (gl_skb) {
|
| 113 |
|
| 114 | |
| 115 | skb_put_data(gl_skb, packet->packet_data, size);
|
| 116 | usbnet_skb_return(dev, gl_skb);
|
| 117 | }
|
| 118 |
|
| 119 | |
| 120 | packet = (struct gl_packet *)&packet->packet_data[size];
|
| 121 | count--;
|
| 122 | }
|
| 123 |
|
| 124 | |
| 125 | skb_pull(skb, 4);
|
| 126 |
|
| 127 | if (skb->len > GL_MAX_PACKET_LEN) {
|
| 128 | netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
|
| 129 | skb->len);
|
| 130 | return 0;
|
| 131 | }
|
| 132 | return 1;
|
| 133 | }
|
| 134 |
|
| 135 | static struct sk_buff *
|
| 136 | genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
|
| 137 | {
|
| 138 | int padlen;
|
| 139 | int length = skb->len;
|
| 140 | int headroom = skb_headroom(skb);
|
| 141 | int tailroom = skb_tailroom(skb);
|
| 142 | __le32 *packet_count;
|
| 143 | __le32 *packet_len;
|
| 144 |
|
| 145 | |
| 146 | padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
|
| 147 |
|
| 148 | if ((!skb_cloned(skb))
|
| 149 | && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
|
| 150 | if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
|
| 151 | skb->data = memmove(skb->head + (4 + 4*1),
|
| 152 | skb->data, skb->len);
|
| 153 | skb_set_tail_pointer(skb, skb->len);
|
| 154 | }
|
| 155 | } else {
|
| 156 | struct sk_buff *skb2;
|
| 157 | skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags);
|
| 158 | dev_kfree_skb_any(skb);
|
| 159 | skb = skb2;
|
| 160 | if (!skb)
|
| 161 | return NULL;
|
| 162 | }
|
| 163 |
|
| 164 | |
| 165 | packet_count = skb_push(skb, (4 + 4 * 1));
|
| 166 | packet_len = packet_count + 1;
|
| 167 |
|
| 168 | *packet_count = cpu_to_le32(1);
|
| 169 | *packet_len = cpu_to_le32(length);
|
| 170 |
|
| 171 | |
| 172 | if ((skb->len % dev->maxpacket) == 0)
|
| 173 | skb_put(skb, 1);
|
| 174 |
|
| 175 | return skb;
|
| 176 | }
|
| 177 |
|
| 178 | static int genelink_bind(struct usbnet *dev, struct usb_interface *intf)
|
| 179 | {
|
| 180 | dev->hard_mtu = GL_RCV_BUF_SIZE;
|
| 181 | dev->net->hard_header_len += 4;
|
| 182 | return usbnet_get_endpoints(dev, intf);
|
| 183 | }
|
| 184 |
|
| 185 | static const struct driver_info genelink_info = {
|
| 186 | .description = "Genesys GeneLink",
|
| 187 | .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_GL | FLAG_NO_SETINT,
|
| 188 | .bind = genelink_bind,
|
| 189 | .rx_fixup = genelink_rx_fixup,
|
| 190 | .tx_fixup = genelink_tx_fixup,
|
| 191 |
|
| 192 | .in = 1, .out = 2,
|
| 193 |
|
| 194 | #ifdef GENELINK_ACK
|
| 195 | .check_connect =genelink_check_connect,
|
| 196 | #endif
|
| 197 | };
|
| 198 |
|
| 199 | static const struct usb_device_id products [] = {
|
| 200 |
|
| 201 | {
|
| 202 | USB_DEVICE(0x05e3, 0x0502), |
| 203 | .driver_info = (unsigned long) &genelink_info,
|
| 204 | },
|
| 205 | |
| 206 | * that's half duplex, not currently supported
|
| 207 |
|
| 208 | { }, |
| 209 | };
|
| 210 | MODULE_DEVICE_TABLE(usb, products);
|
| 211 |
|
| 212 | static struct usb_driver gl620a_driver = {
|
| 213 | .name = "gl620a",
|
| 214 | .id_table = products,
|
| 215 | .probe = usbnet_probe,
|
| 216 | .disconnect = usbnet_disconnect,
|
| 217 | .suspend = usbnet_suspend,
|
| 218 | .resume = usbnet_resume,
|
| 219 | .disable_hub_initiated_lpm = 1,
|
| 220 | };
|
| 221 |
|
| 222 | module_usb_driver(gl620a_driver);
|
| 223 |
|
| 224 | MODULE_AUTHOR("Jiun-Jie Huang");
|
| 225 | MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables");
|
| 226 | MODULE_LICENSE("GPL");
|
| 227 |
|