Linux Audio

Check our new training course

Loading...
v3.1
  1/*
  2 * GeneSys GL620USB-A based links
  3 * Copyright (C) 2001 by Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
  4 * Copyright (C) 2001 by Stanislav Brabec <utx@penguin.cz>
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License as published by
  8 * the Free Software Foundation; either version 2 of the License, or
  9 * (at your option) any later version.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License
 17 * along with this program; if not, write to the Free Software
 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19 */
 20
 21// #define	DEBUG			// error path messages, extra info
 22// #define	VERBOSE			// more; success messages
 23
 24#include <linux/module.h>
 25#include <linux/init.h>
 26#include <linux/netdevice.h>
 27#include <linux/etherdevice.h>
 28#include <linux/ethtool.h>
 29#include <linux/workqueue.h>
 30#include <linux/mii.h>
 31#include <linux/usb.h>
 32#include <linux/usb/usbnet.h>
 33#include <linux/gfp.h>
 34
 35
 36/*
 37 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
 38 *
 39 * ... should partially interop with the Win32 driver for this hardware.
 40 * The GeneSys docs imply there's some NDIS issue motivating this framing.
 41 *
 42 * Some info from GeneSys:
 43 *  - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
 44 *    (Some cables, like the BAFO-100c, use the half duplex version.)
 45 *  - For the full duplex model, the low bit of the version code says
 46 *    which side is which ("left/right").
 47 *  - For the half duplex type, a control/interrupt handshake settles
 48 *    the transfer direction.  (That's disabled here, partially coded.)
 49 *    A control URB would block until other side writes an interrupt.
 50 *
 51 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
 52 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
 53 */
 54
 55// control msg write command
 56#define GENELINK_CONNECT_WRITE			0xF0
 57// interrupt pipe index
 58#define GENELINK_INTERRUPT_PIPE			0x03
 59// interrupt read buffer size
 60#define INTERRUPT_BUFSIZE			0x08
 61// interrupt pipe interval value
 62#define GENELINK_INTERRUPT_INTERVAL		0x10
 63// max transmit packet number per transmit
 64#define GL_MAX_TRANSMIT_PACKETS			32
 65// max packet length
 66#define GL_MAX_PACKET_LEN			1514
 67// max receive buffer size
 68#define GL_RCV_BUF_SIZE		\
 69	(((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
 70
 71struct gl_packet {
 72	__le32		packet_length;
 73	char		packet_data [1];
 74};
 75
 76struct gl_header {
 77	__le32			packet_count;
 78	struct gl_packet	packets;
 79};
 80
 81static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 82{
 83	struct gl_header	*header;
 84	struct gl_packet	*packet;
 85	struct sk_buff		*gl_skb;
 86	u32			size;
 87	u32			count;
 88
 
 
 
 
 89	header = (struct gl_header *) skb->data;
 90
 91	// get the packet count of the received skb
 92	count = le32_to_cpu(header->packet_count);
 93	if (count > GL_MAX_TRANSMIT_PACKETS) {
 94		dbg("genelink: invalid received packet count %u", count);
 
 
 95		return 0;
 96	}
 97
 98	// set the current packet pointer to the first packet
 99	packet = &header->packets;
100
101	// decrement the length for the packet count size 4 bytes
102	skb_pull(skb, 4);
103
104	while (count > 1) {
105		// get the packet length
106		size = le32_to_cpu(packet->packet_length);
107
108		// this may be a broken packet
109		if (size > GL_MAX_PACKET_LEN) {
110			dbg("genelink: invalid rx length %d", size);
 
111			return 0;
112		}
113
114		// allocate the skb for the individual packet
115		gl_skb = alloc_skb(size, GFP_ATOMIC);
116		if (gl_skb) {
117
118			// copy the packet data to the new skb
119			memcpy(skb_put(gl_skb, size),
120					packet->packet_data, size);
121			usbnet_skb_return(dev, gl_skb);
122		}
123
124		// advance to the next packet
125		packet = (struct gl_packet *)&packet->packet_data[size];
126		count--;
127
128		// shift the data pointer to the next gl_packet
129		skb_pull(skb, size + 4);
130	}
131
132	// skip the packet length field 4 bytes
133	skb_pull(skb, 4);
134
135	if (skb->len > GL_MAX_PACKET_LEN) {
136		dbg("genelink: invalid rx length %d", skb->len);
 
137		return 0;
138	}
139	return 1;
140}
141
142static struct sk_buff *
143genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
144{
145	int 	padlen;
146	int	length = skb->len;
147	int	headroom = skb_headroom(skb);
148	int	tailroom = skb_tailroom(skb);
149	__le32	*packet_count;
150	__le32	*packet_len;
151
152	// FIXME:  magic numbers, bleech
153	padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
154
155	if ((!skb_cloned(skb))
156			&& ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
157		if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
158			skb->data = memmove(skb->head + (4 + 4*1),
159					     skb->data, skb->len);
160			skb_set_tail_pointer(skb, skb->len);
161		}
162	} else {
163		struct sk_buff	*skb2;
164		skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags);
165		dev_kfree_skb_any(skb);
166		skb = skb2;
167		if (!skb)
168			return NULL;
169	}
170
171	// attach the packet count to the header
172	packet_count = (__le32 *) skb_push(skb, (4 + 4*1));
173	packet_len = packet_count + 1;
174
175	*packet_count = cpu_to_le32(1);
176	*packet_len = cpu_to_le32(length);
177
178	// add padding byte
179	if ((skb->len % dev->maxpacket) == 0)
180		skb_put(skb, 1);
181
182	return skb;
183}
184
185static int genelink_bind(struct usbnet *dev, struct usb_interface *intf)
186{
187	dev->hard_mtu = GL_RCV_BUF_SIZE;
188	dev->net->hard_header_len += 4;
189	dev->in = usb_rcvbulkpipe(dev->udev, dev->driver_info->in);
190	dev->out = usb_sndbulkpipe(dev->udev, dev->driver_info->out);
191	return 0;
192}
193
194static const struct driver_info	genelink_info = {
195	.description =	"Genesys GeneLink",
196	.flags =	FLAG_POINTTOPOINT | FLAG_FRAMING_GL | FLAG_NO_SETINT,
197	.bind =		genelink_bind,
198	.rx_fixup =	genelink_rx_fixup,
199	.tx_fixup =	genelink_tx_fixup,
200
201	.in = 1, .out = 2,
202
203#ifdef	GENELINK_ACK
204	.check_connect =genelink_check_connect,
205#endif
206};
207
208static const struct usb_device_id	products [] = {
209
210{
211	USB_DEVICE(0x05e3, 0x0502),	// GL620USB-A
212	.driver_info =	(unsigned long) &genelink_info,
213},
214	/* NOT: USB_DEVICE(0x05e3, 0x0501),	// GL620USB
215	 * that's half duplex, not currently supported
216	 */
217	{ },		// END
218};
219MODULE_DEVICE_TABLE(usb, products);
220
221static struct usb_driver gl620a_driver = {
222	.name =		"gl620a",
223	.id_table =	products,
224	.probe =	usbnet_probe,
225	.disconnect =	usbnet_disconnect,
226	.suspend =	usbnet_suspend,
227	.resume =	usbnet_resume,
 
228};
229
230static int __init usbnet_init(void)
231{
232 	return usb_register(&gl620a_driver);
233}
234module_init(usbnet_init);
235
236static void __exit usbnet_exit(void)
237{
238 	usb_deregister(&gl620a_driver);
239}
240module_exit(usbnet_exit);
241
242MODULE_AUTHOR("Jiun-Jie Huang");
243MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables");
244MODULE_LICENSE("GPL");
245
v4.6
  1/*
  2 * GeneSys GL620USB-A based links
  3 * Copyright (C) 2001 by Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
  4 * Copyright (C) 2001 by Stanislav Brabec <utx@penguin.cz>
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License as published by
  8 * the Free Software Foundation; either version 2 of the License, or
  9 * (at your option) any later version.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License
 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 
 18 */
 19
 20// #define	DEBUG			// error path messages, extra info
 21// #define	VERBOSE			// more; success messages
 22
 23#include <linux/module.h>
 
 24#include <linux/netdevice.h>
 25#include <linux/etherdevice.h>
 26#include <linux/ethtool.h>
 27#include <linux/workqueue.h>
 28#include <linux/mii.h>
 29#include <linux/usb.h>
 30#include <linux/usb/usbnet.h>
 31#include <linux/gfp.h>
 32
 33
 34/*
 35 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
 36 *
 37 * ... should partially interop with the Win32 driver for this hardware.
 38 * The GeneSys docs imply there's some NDIS issue motivating this framing.
 39 *
 40 * Some info from GeneSys:
 41 *  - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
 42 *    (Some cables, like the BAFO-100c, use the half duplex version.)
 43 *  - For the full duplex model, the low bit of the version code says
 44 *    which side is which ("left/right").
 45 *  - For the half duplex type, a control/interrupt handshake settles
 46 *    the transfer direction.  (That's disabled here, partially coded.)
 47 *    A control URB would block until other side writes an interrupt.
 48 *
 49 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
 50 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
 51 */
 52
 53// control msg write command
 54#define GENELINK_CONNECT_WRITE			0xF0
 55// interrupt pipe index
 56#define GENELINK_INTERRUPT_PIPE			0x03
 57// interrupt read buffer size
 58#define INTERRUPT_BUFSIZE			0x08
 59// interrupt pipe interval value
 60#define GENELINK_INTERRUPT_INTERVAL		0x10
 61// max transmit packet number per transmit
 62#define GL_MAX_TRANSMIT_PACKETS			32
 63// max packet length
 64#define GL_MAX_PACKET_LEN			1514
 65// max receive buffer size
 66#define GL_RCV_BUF_SIZE		\
 67	(((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
 68
 69struct gl_packet {
 70	__le32		packet_length;
 71	char		packet_data [1];
 72};
 73
 74struct gl_header {
 75	__le32			packet_count;
 76	struct gl_packet	packets;
 77};
 78
 79static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 80{
 81	struct gl_header	*header;
 82	struct gl_packet	*packet;
 83	struct sk_buff		*gl_skb;
 84	u32			size;
 85	u32			count;
 86
 87	/* This check is no longer done by usbnet */
 88	if (skb->len < dev->net->hard_header_len)
 89		return 0;
 90
 91	header = (struct gl_header *) skb->data;
 92
 93	// get the packet count of the received skb
 94	count = le32_to_cpu(header->packet_count);
 95	if (count > GL_MAX_TRANSMIT_PACKETS) {
 96		netdev_dbg(dev->net,
 97			   "genelink: invalid received packet count %u\n",
 98			   count);
 99		return 0;
100	}
101
102	// set the current packet pointer to the first packet
103	packet = &header->packets;
104
105	// decrement the length for the packet count size 4 bytes
106	skb_pull(skb, 4);
107
108	while (count > 1) {
109		// get the packet length
110		size = le32_to_cpu(packet->packet_length);
111
112		// this may be a broken packet
113		if (size > GL_MAX_PACKET_LEN) {
114			netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
115				   size);
116			return 0;
117		}
118
119		// allocate the skb for the individual packet
120		gl_skb = alloc_skb(size, GFP_ATOMIC);
121		if (gl_skb) {
122
123			// copy the packet data to the new skb
124			memcpy(skb_put(gl_skb, size),
125					packet->packet_data, size);
126			usbnet_skb_return(dev, gl_skb);
127		}
128
129		// advance to the next packet
130		packet = (struct gl_packet *)&packet->packet_data[size];
131		count--;
132
133		// shift the data pointer to the next gl_packet
134		skb_pull(skb, size + 4);
135	}
136
137	// skip the packet length field 4 bytes
138	skb_pull(skb, 4);
139
140	if (skb->len > GL_MAX_PACKET_LEN) {
141		netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
142			   skb->len);
143		return 0;
144	}
145	return 1;
146}
147
148static struct sk_buff *
149genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
150{
151	int 	padlen;
152	int	length = skb->len;
153	int	headroom = skb_headroom(skb);
154	int	tailroom = skb_tailroom(skb);
155	__le32	*packet_count;
156	__le32	*packet_len;
157
158	// FIXME:  magic numbers, bleech
159	padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
160
161	if ((!skb_cloned(skb))
162			&& ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
163		if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
164			skb->data = memmove(skb->head + (4 + 4*1),
165					     skb->data, skb->len);
166			skb_set_tail_pointer(skb, skb->len);
167		}
168	} else {
169		struct sk_buff	*skb2;
170		skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags);
171		dev_kfree_skb_any(skb);
172		skb = skb2;
173		if (!skb)
174			return NULL;
175	}
176
177	// attach the packet count to the header
178	packet_count = (__le32 *) skb_push(skb, (4 + 4*1));
179	packet_len = packet_count + 1;
180
181	*packet_count = cpu_to_le32(1);
182	*packet_len = cpu_to_le32(length);
183
184	// add padding byte
185	if ((skb->len % dev->maxpacket) == 0)
186		skb_put(skb, 1);
187
188	return skb;
189}
190
191static int genelink_bind(struct usbnet *dev, struct usb_interface *intf)
192{
193	dev->hard_mtu = GL_RCV_BUF_SIZE;
194	dev->net->hard_header_len += 4;
195	dev->in = usb_rcvbulkpipe(dev->udev, dev->driver_info->in);
196	dev->out = usb_sndbulkpipe(dev->udev, dev->driver_info->out);
197	return 0;
198}
199
200static const struct driver_info	genelink_info = {
201	.description =	"Genesys GeneLink",
202	.flags =	FLAG_POINTTOPOINT | FLAG_FRAMING_GL | FLAG_NO_SETINT,
203	.bind =		genelink_bind,
204	.rx_fixup =	genelink_rx_fixup,
205	.tx_fixup =	genelink_tx_fixup,
206
207	.in = 1, .out = 2,
208
209#ifdef	GENELINK_ACK
210	.check_connect =genelink_check_connect,
211#endif
212};
213
214static const struct usb_device_id	products [] = {
215
216{
217	USB_DEVICE(0x05e3, 0x0502),	// GL620USB-A
218	.driver_info =	(unsigned long) &genelink_info,
219},
220	/* NOT: USB_DEVICE(0x05e3, 0x0501),	// GL620USB
221	 * that's half duplex, not currently supported
222	 */
223	{ },		// END
224};
225MODULE_DEVICE_TABLE(usb, products);
226
227static struct usb_driver gl620a_driver = {
228	.name =		"gl620a",
229	.id_table =	products,
230	.probe =	usbnet_probe,
231	.disconnect =	usbnet_disconnect,
232	.suspend =	usbnet_suspend,
233	.resume =	usbnet_resume,
234	.disable_hub_initiated_lpm = 1,
235};
236
237module_usb_driver(gl620a_driver);
 
 
 
 
 
 
 
 
 
 
238
239MODULE_AUTHOR("Jiun-Jie Huang");
240MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables");
241MODULE_LICENSE("GPL");
242