blob: 594c23be69f5db5d4e9c414e23219432096624fe [file] [log] [blame]
David Sterba099dc4f2008-02-07 10:57:12 +01001/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#include "hardware.h"
19#include "network.h"
20#include "main.h"
21#include "tty.h"
22
23#include <linux/delay.h>
24#include <linux/init.h>
25#include <linux/io.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/slab.h>
30
David Sterba099dc4f2008-02-07 10:57:12 +010031#include <pcmcia/cisreg.h>
32#include <pcmcia/device_id.h>
33#include <pcmcia/ss.h>
34#include <pcmcia/ds.h>
David Sterba099dc4f2008-02-07 10:57:12 +010035
36static struct pcmcia_device_id ipw_ids[] = {
37 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
38 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
39 PCMCIA_DEVICE_NULL
40};
41MODULE_DEVICE_TABLE(pcmcia, ipw_ids);
42
43static void ipwireless_detach(struct pcmcia_device *link);
44
45/*
46 * Module params
47 */
48/* Debug mode: more verbose, print sent/recv bytes */
49int ipwireless_debug;
50int ipwireless_loopback;
David Sterbabee9c7c2008-07-28 16:53:21 +020051int ipwireless_out_queue = 10;
David Sterba099dc4f2008-02-07 10:57:12 +010052
53module_param_named(debug, ipwireless_debug, int, 0);
54module_param_named(loopback, ipwireless_loopback, int, 0);
55module_param_named(out_queue, ipwireless_out_queue, int, 0);
56MODULE_PARM_DESC(debug, "switch on debug messages [0]");
57MODULE_PARM_DESC(loopback,
58 "debug: enable ras_raw channel [0]");
David Sterbabee9c7c2008-07-28 16:53:21 +020059MODULE_PARM_DESC(out_queue, "debug: set size of outgoing PPP queue [10]");
David Sterba099dc4f2008-02-07 10:57:12 +010060
61/* Executes in process context. */
62static void signalled_reboot_work(struct work_struct *work_reboot)
63{
64 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
65 work_reboot);
66 struct pcmcia_device *link = ipw->link;
Dominik Brodowskicbf624f2009-10-24 15:47:29 +020067 pcmcia_reset_card(link->socket);
David Sterba099dc4f2008-02-07 10:57:12 +010068}
69
70static void signalled_reboot_callback(void *callback_data)
71{
72 struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
73
74 /* Delegate to process context. */
75 schedule_work(&ipw->work_reboot);
76}
77
Dominik Brodowski00990e72010-07-30 13:13:46 +020078static int ipwireless_probe(struct pcmcia_device *p_dev, void *priv_data)
Dominik Brodowskiaaa8cfd2009-10-18 18:28:39 +020079{
Dominik Brodowskiaf7579232009-10-18 19:48:39 +020080 struct ipw_dev *ipw = priv_data;
81 struct resource *io_resource;
Dominik Brodowskiaf7579232009-10-18 19:48:39 +020082 int ret;
83
Dominik Brodowski00990e72010-07-30 13:13:46 +020084 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
Dominik Brodowski90abdc32010-07-24 17:23:51 +020085 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
Dominik Brodowskiaaa8cfd2009-10-18 18:28:39 +020086
Dominik Brodowskiaaa8cfd2009-10-18 18:28:39 +020087 /* 0x40 causes it to generate level mode interrupts. */
88 /* 0x04 enables IREQ pin. */
Dominik Brodowski00990e72010-07-30 13:13:46 +020089 p_dev->config_index |= 0x44;
Dominik Brodowski90abdc32010-07-24 17:23:51 +020090 p_dev->io_lines = 16;
91 ret = pcmcia_request_io(p_dev);
Dominik Brodowskiaf7579232009-10-18 19:48:39 +020092 if (ret)
93 return ret;
94
Dominik Brodowski9a017a92010-07-24 15:58:54 +020095 io_resource = request_region(p_dev->resource[0]->start,
96 resource_size(p_dev->resource[0]),
Dominik Brodowskiaf7579232009-10-18 19:48:39 +020097 IPWIRELESS_PCCARD_NAME);
98
Dominik Brodowskicdb13802010-07-28 10:59:06 +020099 p_dev->resource[2]->flags |=
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200100 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200101
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200102 ret = pcmcia_request_window(p_dev, p_dev->resource[2], 0);
Dominik Brodowskicbf624f2009-10-24 15:47:29 +0200103 if (ret != 0)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200104 goto exit1;
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200105
Dominik Brodowski00990e72010-07-30 13:13:46 +0200106 ret = pcmcia_map_mem_page(p_dev, p_dev->resource[2], p_dev->card_addr);
Dominik Brodowskicbf624f2009-10-24 15:47:29 +0200107 if (ret != 0)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200108 goto exit2;
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200109
Dominik Brodowski00990e72010-07-30 13:13:46 +0200110 ipw->is_v2_card = resource_size(p_dev->resource[2]) == 0x100;
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200111
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200112 ipw->attr_memory = ioremap(p_dev->resource[2]->start,
113 resource_size(p_dev->resource[2]));
114 request_mem_region(p_dev->resource[2]->start,
115 resource_size(p_dev->resource[2]),
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200116 IPWIRELESS_PCCARD_NAME);
117
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200118 p_dev->resource[3]->flags |= WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM |
119 WIN_ENABLE;
120 p_dev->resource[3]->end = 0; /* this used to be 0x1000 */
121 ret = pcmcia_request_window(p_dev, p_dev->resource[3], 0);
Dominik Brodowskicbf624f2009-10-24 15:47:29 +0200122 if (ret != 0)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200123 goto exit2;
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200124
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200125 ret = pcmcia_map_mem_page(p_dev, p_dev->resource[3], 0);
Dominik Brodowskicbf624f2009-10-24 15:47:29 +0200126 if (ret != 0)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200127 goto exit3;
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200128
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200129 ipw->attr_memory = ioremap(p_dev->resource[3]->start,
130 resource_size(p_dev->resource[3]));
131 request_mem_region(p_dev->resource[3]->start,
132 resource_size(p_dev->resource[3]),
133 IPWIRELESS_PCCARD_NAME);
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200134
135 return 0;
136
137exit3:
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200138exit2:
139 if (ipw->common_memory) {
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200140 release_mem_region(p_dev->resource[2]->start,
141 resource_size(p_dev->resource[2]));
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200142 iounmap(ipw->common_memory);
Dominik Brodowski0ca724d2010-07-24 19:03:02 +0200143 }
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200144exit1:
145 release_resource(io_resource);
146 pcmcia_disable_device(p_dev);
147 return -1;
Dominik Brodowskiaaa8cfd2009-10-18 18:28:39 +0200148}
149
David Sterba099dc4f2008-02-07 10:57:12 +0100150static int config_ipwireless(struct ipw_dev *ipw)
151{
152 struct pcmcia_device *link = ipw->link;
Dominik Brodowskiaaa8cfd2009-10-18 18:28:39 +0200153 int ret = 0;
David Sterba099dc4f2008-02-07 10:57:12 +0100154
155 ipw->is_v2_card = 0;
Dominik Brodowski00990e72010-07-30 13:13:46 +0200156 link->config_flags |= CONF_AUTO_SET_IO | CONF_AUTO_SET_IOMEM |
157 CONF_ENABLE_IRQ;
David Sterba099dc4f2008-02-07 10:57:12 +0100158
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200159 ret = pcmcia_loop_config(link, ipwireless_probe, ipw);
Dominik Brodowskicbf624f2009-10-24 15:47:29 +0200160 if (ret != 0)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200161 return ret;
David Sterba099dc4f2008-02-07 10:57:12 +0100162
David Sterba099dc4f2008-02-07 10:57:12 +0100163 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
164
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200165 ipwireless_init_hardware_v1(ipw->hardware, link->resource[0]->start,
David Sterba099dc4f2008-02-07 10:57:12 +0100166 ipw->attr_memory, ipw->common_memory,
167 ipw->is_v2_card, signalled_reboot_callback,
168 ipw);
169
Dominik Brodowskieb141202010-03-07 12:21:16 +0100170 ret = pcmcia_request_irq(link, ipwireless_interrupt);
Dominik Brodowskicbf624f2009-10-24 15:47:29 +0200171 if (ret != 0)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200172 goto exit;
David Sterba099dc4f2008-02-07 10:57:12 +0100173
David Sterba099dc4f2008-02-07 10:57:12 +0100174 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
175 ipw->is_v2_card ? "V2/V3" : "V1");
176 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200177 ": I/O ports %pR, irq %d\n", link->resource[0],
Dominik Brodowskieb141202010-03-07 12:21:16 +0100178 (unsigned int) link->irq);
David Sterba099dc4f2008-02-07 10:57:12 +0100179 if (ipw->attr_memory && ipw->common_memory)
180 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200181 ": attr memory %pR, common memory %pR\n",
182 link->resource[3],
183 link->resource[2]);
David Sterba099dc4f2008-02-07 10:57:12 +0100184
185 ipw->network = ipwireless_network_create(ipw->hardware);
186 if (!ipw->network)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200187 goto exit;
David Sterba099dc4f2008-02-07 10:57:12 +0100188
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100189 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network);
David Sterba099dc4f2008-02-07 10:57:12 +0100190 if (!ipw->tty)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200191 goto exit;
David Sterba099dc4f2008-02-07 10:57:12 +0100192
193 ipwireless_init_hardware_v2_v3(ipw->hardware);
194
195 /*
196 * Do the RequestConfiguration last, because it enables interrupts.
197 * Then we don't get any interrupts before we're ready for them.
198 */
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200199 ret = pcmcia_enable_device(link);
Dominik Brodowskicbf624f2009-10-24 15:47:29 +0200200 if (ret != 0)
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200201 goto exit;
David Sterba099dc4f2008-02-07 10:57:12 +0100202
David Sterba099dc4f2008-02-07 10:57:12 +0100203 return 0;
204
Dominik Brodowskiaf7579232009-10-18 19:48:39 +0200205exit:
David Sterba099dc4f2008-02-07 10:57:12 +0100206 if (ipw->common_memory) {
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200207 release_mem_region(link->resource[2]->start,
208 resource_size(link->resource[2]));
David Sterba099dc4f2008-02-07 10:57:12 +0100209 iounmap(ipw->common_memory);
David Sterba099dc4f2008-02-07 10:57:12 +0100210 }
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200211 if (ipw->attr_memory) {
212 release_mem_region(link->resource[3]->start,
213 resource_size(link->resource[3]));
214 iounmap(ipw->attr_memory);
215 }
David Sterba099dc4f2008-02-07 10:57:12 +0100216 pcmcia_disable_device(link);
David Sterba099dc4f2008-02-07 10:57:12 +0100217 return -1;
218}
219
220static void release_ipwireless(struct ipw_dev *ipw)
221{
David Sterba09e491e2008-07-28 16:53:16 +0200222 if (ipw->common_memory) {
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200223 release_mem_region(ipw->link->resource[2]->start,
224 resource_size(ipw->link->resource[2]));
David Sterba099dc4f2008-02-07 10:57:12 +0100225 iounmap(ipw->common_memory);
David Sterba09e491e2008-07-28 16:53:16 +0200226 }
227 if (ipw->attr_memory) {
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200228 release_mem_region(ipw->link->resource[3]->start,
229 resource_size(ipw->link->resource[3]));
David Sterba099dc4f2008-02-07 10:57:12 +0100230 iounmap(ipw->attr_memory);
David Sterba09e491e2008-07-28 16:53:16 +0200231 }
David Sterba09e491e2008-07-28 16:53:16 +0200232 pcmcia_disable_device(ipw->link);
David Sterba099dc4f2008-02-07 10:57:12 +0100233}
234
235/*
236 * ipwireless_attach() creates an "instance" of the driver, allocating
237 * local data structures for one device (one interface). The device
238 * is registered with Card Services.
239 *
240 * The pcmcia_device structure is initialized, but we don't actually
241 * configure the card at this point -- we wait until we receive a
242 * card insertion event.
243 */
244static int ipwireless_attach(struct pcmcia_device *link)
245{
246 struct ipw_dev *ipw;
247 int ret;
248
249 ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
250 if (!ipw)
251 return -ENOMEM;
252
253 ipw->link = link;
254 link->priv = ipw;
David Sterba099dc4f2008-02-07 10:57:12 +0100255
David Sterba099dc4f2008-02-07 10:57:12 +0100256 ipw->hardware = ipwireless_hardware_create();
257 if (!ipw->hardware) {
258 kfree(ipw);
259 return -ENOMEM;
260 }
261 /* RegisterClient will call config_ipwireless */
262
263 ret = config_ipwireless(ipw);
264
265 if (ret != 0) {
David Sterba099dc4f2008-02-07 10:57:12 +0100266 ipwireless_detach(link);
267 return ret;
268 }
269
270 return 0;
271}
272
273/*
274 * This deletes a driver "instance". The device is de-registered with
275 * Card Services. If it has been released, all local data structures
276 * are freed. Otherwise, the structures will be freed when the device
277 * is released.
278 */
279static void ipwireless_detach(struct pcmcia_device *link)
280{
281 struct ipw_dev *ipw = link->priv;
282
283 release_ipwireless(ipw);
284
David Sterba099dc4f2008-02-07 10:57:12 +0100285 if (ipw->tty != NULL)
286 ipwireless_tty_free(ipw->tty);
287 if (ipw->network != NULL)
288 ipwireless_network_free(ipw->network);
289 if (ipw->hardware != NULL)
290 ipwireless_hardware_free(ipw->hardware);
291 kfree(ipw);
292}
293
294static struct pcmcia_driver me = {
295 .owner = THIS_MODULE,
296 .probe = ipwireless_attach,
297 .remove = ipwireless_detach,
298 .drv = { .name = IPWIRELESS_PCCARD_NAME },
299 .id_table = ipw_ids
300};
301
302/*
303 * Module insertion : initialisation of the module.
304 * Register the card with cardmgr...
305 */
306static int __init init_ipwireless(void)
307{
308 int ret;
309
310 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
311 IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
312
313 ret = ipwireless_tty_init();
314 if (ret != 0)
315 return ret;
316
317 ret = pcmcia_register_driver(&me);
318 if (ret != 0)
319 ipwireless_tty_release();
320
321 return ret;
322}
323
324/*
325 * Module removal
326 */
327static void __exit exit_ipwireless(void)
328{
329 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
330 IPWIRELESS_PCMCIA_VERSION " removed\n");
331
332 pcmcia_unregister_driver(&me);
333 ipwireless_tty_release();
334}
335
336module_init(init_ipwireless);
337module_exit(exit_ipwireless);
338
339MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
340MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
341MODULE_LICENSE("GPL");