aboutsummaryrefslogtreecommitdiff
path: root/vnet503-rfmd.c
blob: 553b6e76a24fe6da92ddede52300b7ec92157bce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* -*- linux-c -*- */
/*
 * vnet503-rfmd.c:
 *
 * Driver for at76c503-based devices based on the Atmel "Fast-Vnet" reference
 * design using RFMD radio chips
 *
 * Copyright (c) 2002 - 2003 Oliver Kurth <oku@masqmail.cx>
 *
 *	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 driver is derived from usb-skeleton.c
 *
 * This driver contains code specific to Atmel AT76C503 (USB wireless 802.11)
 * devices which use radio chips from RF Micro Devices (RFMD).  Almost
 * all of the actual driver is handled by the generic at76c503.c module, this
 * file mostly just deals with the initial probes and downloading the correct
 * firmware to the device before handing it off to at76c503.
 *
 * History:
 *
 * 2003_02_11 0.1: (alex)
 * - split board-specific code off from at76c503.c
 * - reverted to 0.90.2 firmware because 0.100.x is broken for WUSB11
 *
 */

#include <linux/config.h>
#include <linux/module.h>
#include <linux/usb.h>

#include "at76c503.h"
#include "usbdfu.h"

/* Include firmware data definition */

#include "fw-rfmd-0.90.2-140.h"

/* Version Information */

#define DRIVER_NAME "vnet503-rfmd"
#define DRIVER_AUTHOR "Oliver Kurth <oku@masqmail.cx>"
#define DRIVER_DESC "Atmel at76c503 (RFMD) Wireless LAN Driver"

/* USB Device IDs supported by this driver */

#define VENDOR_ID_ATMEL               0x03eb
#define PRODUCT_ID_ATMEL_503R         0x7605 /* Generic AT76C503/RFMD device */

#define VENDOR_ID_BELKIN              0x0d5c
#define PRODUCT_ID_BELKIN_F5D6050     0xa002 /* Belkin F5D6050 / SMC 2662W v2 */

#define VENDOR_ID_DYNALINK            0x069a
#define PRODUCT_ID_DYNALINK_WLL013_R  0x0321 /* Dynalink/Askey WLL013 (rfmd) */

#define VENDOR_ID_LINKSYS             0x077b
#define PRODUCT_ID_LINKSYS_WUSB11_V26 0x2219 /* Linksys WUSB11 v2.6 */

#define VENDOR_ID_NETGEAR             0x0864
#define PRODUCT_ID_NETGEAR_MA101B     0x4102 /* Netgear MA 101 Rev. B */

static struct usb_device_id vnet_table[] = {
	{ USB_DEVICE(VENDOR_ID_ATMEL,    PRODUCT_ID_ATMEL_503R        ) },
	{ USB_DEVICE(VENDOR_ID_BELKIN,   PRODUCT_ID_BELKIN_F5D6050    ) },
	{ USB_DEVICE(VENDOR_ID_DYNALINK, PRODUCT_ID_DYNALINK_WLL013_R ) },
	{ USB_DEVICE(VENDOR_ID_LINKSYS,  PRODUCT_ID_LINKSYS_WUSB11_V26) },
	{ USB_DEVICE(VENDOR_ID_NETGEAR,  PRODUCT_ID_NETGEAR_MA101B    ) },
	{ }
};

MODULE_DEVICE_TABLE (usb, vnet_table);

/* firmware / config variables */

static unsigned char fw_internal[] = FW_503RFMD_INTERNAL;
static unsigned char fw_external[] = FW_503RFMD_EXTERNAL;

static int board_type = BOARDTYPE_RFMD;

/*---------------------------------------------------------------------------*/

/* Module paramaters */

#ifdef CONFIG_USB_DEBUG
static int debug = 1;
#else
static int debug = 0;
#endif
MODULE_PARM(debug, "i");
MODULE_PARM_DESC(debug, "Level of debugging messages");

static char eth_name[IFNAMSIZ+1] = "eth%d";
MODULE_PARM(eth_name, "c" __MODULE_STRING(IFNAMSIZ));
MODULE_PARM_DESC(eth_name,
                 "network device name (default is eth%d)");

/* local function prototypes */

static void * vnet_probe(struct usb_device *dev, unsigned int ifnum,
			     const struct usb_device_id *id);
static void vnet_disconnect(struct usb_device *dev, void *ptr);
static int vnet_usbdfu_post(struct usb_device *udev);

/* structure for registering this driver with the usb subsystem */

static struct usb_driver vnet_driver = {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
	owner:      THIS_MODULE,
#endif
	name:	    DRIVER_NAME,
	probe:	    vnet_probe,
	disconnect: vnet_disconnect,
	id_table:   vnet_table,
};

/* structure for registering this firmware with the usbdfu subsystem */

static struct usbdfu_info vnet_usbdfu = {
	name:			DRIVER_NAME,
	id_table:		vnet_table,
	fw_buf:			fw_internal,
	fw_buf_len:		sizeof(fw_internal),
	post_download_hook:	vnet_usbdfu_post,
};

/* debug stuff */

#undef dbg
#define dbg(format, arg...) do { if (debug) printk(KERN_DEBUG __FILE__ ": " format "\n" , ## arg); } while (0)

/**
 * 	vnet_usbdfu_post
 *
 * 	Called by usbdfu after the firmware has been downloaded to the device,
 * 	before the final reset.
 * 	(this is called in a usb probe (khubd) context)
 */
static int vnet_usbdfu_post(struct usb_device *udev)
{
	int result;

	dbg("Sending remap command...");
	result = at76c503_remap(udev, 1);
	if (result < 0) {
		err("Remap command failed (%d)", result);
		return result;
	}
	return 0;
}

/**
 *	vnet_probe
 *
 *	Called by the usb core when a compatible device is plugged into the
 *	system.
 */
static void *vnet_probe(struct usb_device *udev, unsigned int ifnum, const struct usb_device_id *id)
{
	int ret;
	struct at76c503 *dev;

	if (usbdfu_in_use(udev, ifnum)) {
		/* the device is in DFU mode and usbdfu.c is handling it */
		return NULL;
	}

	usb_inc_dev_use(udev);

	if ((ret = usb_get_configuration(udev)) != 0) {
		err("get configuration failed: %d", ret);
		goto error;
	}
  
	if ((ret = usb_set_configuration(udev, 1)) != 0) {
		err("set configuration to 1 failed: %d", ret);
		goto error;
	}

	ret = at76c503_download_external_fw(udev, fw_external,
					    sizeof(fw_external));
	if (ret < 0) {
		err("Downloading external firmware failed: %d", ret);
		goto error;
	}

	dev = at76c503_new_device(udev, board_type, eth_name);
	if (!dev) {
		dbg("at76c503_new_device returned NULL");
		goto error;
	}

	SET_MODULE_OWNER(dev->netdev);
	ret = register_netdev(dev->netdev);
	if (ret) {
		err("Unable to register netdevice %s (status %d)!",
		    dev->netdev->name, ret);
		at76c503_delete_device(dev);
		goto error;
	}

	return dev;

 error:
	usb_dec_dev_use(udev);
	return NULL;
}

/**
 *	vnet_disconnect
 *
 *	Called by the usb core when the device is removed from the system.
 */
static void vnet_disconnect(struct usb_device *udev, void *ptr)
{
	struct at76c503 *dev = (struct at76c503 *)ptr;

	dbg("udev=%p, ptr=%p", udev, ptr);

	info("%s disconnected", dev->netdev->name);

	unregister_netdev(dev->netdev);
	at76c503_delete_device(dev);
	usb_dec_dev_use(udev);
}

static int __init vnet_init(void)
{
	int result;

	info(DRIVER_DESC " " DRIVER_VERSION);

	/* register with usbdfu so that the firmware will be automatically
	 * downloaded to the device on detection */
	result = usbdfu_register(&vnet_usbdfu);
	if (result < 0) {
		err("usbdfu_register failed (status %d)", result);
		return -1;
	}

	/* register this driver with the USB subsystem */
	result = usb_register(&vnet_driver);
	if (result < 0) {
		err("usb_register failed (status %d)", result);
		return -1;
	}

	return 0;
}

static void __exit vnet_exit(void)
{
	info(DRIVER_DESC " " DRIVER_VERSION " unloading");
	/* deregister this driver with the USB subsystem */
	usbdfu_deregister(&vnet_usbdfu);
	usb_deregister(&vnet_driver);
}

module_init (vnet_init);
module_exit (vnet_exit);

MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");