2 * IPWireless 3G PCMCIA Network Driver
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
23 #include <linux/delay.h>
24 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
31 #include <pcmcia/cisreg.h>
32 #include <pcmcia/device_id.h>
33 #include <pcmcia/ss.h>
34 #include <pcmcia/ds.h>
35 #include <pcmcia/cs.h>
37 static struct pcmcia_device_id ipw_ids[] = {
38 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
39 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
42 MODULE_DEVICE_TABLE(pcmcia, ipw_ids);
44 static void ipwireless_detach(struct pcmcia_device *link);
49 /* Debug mode: more verbose, print sent/recv bytes */
51 int ipwireless_loopback;
52 int ipwireless_out_queue = 10;
54 module_param_named(debug, ipwireless_debug, int, 0);
55 module_param_named(loopback, ipwireless_loopback, int, 0);
56 module_param_named(out_queue, ipwireless_out_queue, int, 0);
57 MODULE_PARM_DESC(debug, "switch on debug messages [0]");
58 MODULE_PARM_DESC(loopback,
59 "debug: enable ras_raw channel [0]");
60 MODULE_PARM_DESC(out_queue, "debug: set size of outgoing PPP queue [10]");
62 /* Executes in process context. */
63 static void signalled_reboot_work(struct work_struct *work_reboot)
65 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
67 struct pcmcia_device *link = ipw->link;
68 int ret = pccard_reset_card(link->socket);
70 if (ret != CS_SUCCESS)
71 cs_error(link, ResetCard, ret);
74 static void signalled_reboot_callback(void *callback_data)
76 struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
78 /* Delegate to process context. */
79 schedule_work(&ipw->work_reboot);
82 static int config_ipwireless(struct ipw_dev *ipw)
84 struct pcmcia_device *link = ipw->link;
88 unsigned short buf[64];
90 unsigned short cor_value;
91 memreq_t memreq_attr_memory;
92 memreq_t memreq_common_memory;
97 tuple.TupleData = (cisdata_t *) buf;
98 tuple.TupleDataMax = sizeof(buf);
99 tuple.TupleOffset = 0;
101 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
103 ret = pcmcia_get_first_tuple(link, &tuple);
106 ret = pcmcia_get_tuple_data(link, &tuple);
108 if (ret != CS_SUCCESS) {
109 cs_error(link, GetTupleData, ret);
112 ret = pcmcia_get_next_tuple(link, &tuple);
115 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
117 ret = pcmcia_get_first_tuple(link, &tuple);
119 if (ret != CS_SUCCESS) {
120 cs_error(link, GetFirstTuple, ret);
124 ret = pcmcia_get_tuple_data(link, &tuple);
126 if (ret != CS_SUCCESS) {
127 cs_error(link, GetTupleData, ret);
131 ret = pcmcia_parse_tuple(link, &tuple, &parse);
133 if (ret != CS_SUCCESS) {
134 cs_error(link, ParseTuple, ret);
138 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
139 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
140 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
141 link->io.IOAddrLines = 16;
143 link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1;
145 /* 0x40 causes it to generate level mode interrupts. */
146 /* 0x04 enables IREQ pin. */
147 cor_value = parse.cftable_entry.index | 0x44;
148 link->conf.ConfigIndex = cor_value;
150 /* IRQ and I/O settings */
151 tuple.DesiredTuple = CISTPL_CONFIG;
153 ret = pcmcia_get_first_tuple(link, &tuple);
155 if (ret != CS_SUCCESS) {
156 cs_error(link, GetFirstTuple, ret);
160 ret = pcmcia_get_tuple_data(link, &tuple);
162 if (ret != CS_SUCCESS) {
163 cs_error(link, GetTupleData, ret);
167 ret = pcmcia_parse_tuple(link, &tuple, &parse);
169 if (ret != CS_SUCCESS) {
170 cs_error(link, GetTupleData, ret);
173 link->conf.Attributes = CONF_ENABLE_IRQ;
174 link->conf.ConfigBase = parse.config.base;
175 link->conf.Present = parse.config.rmask[0];
176 link->conf.IntType = INT_MEMORY_AND_IO;
178 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
179 link->irq.Handler = ipwireless_interrupt;
180 link->irq.Instance = ipw->hardware;
182 ret = pcmcia_request_io(link, &link->io);
184 if (ret != CS_SUCCESS) {
185 cs_error(link, RequestIO, ret);
189 request_region(link->io.BasePort1, link->io.NumPorts1,
190 IPWIRELESS_PCCARD_NAME);
192 /* memory settings */
194 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
196 ret = pcmcia_get_first_tuple(link, &tuple);
198 if (ret != CS_SUCCESS) {
199 cs_error(link, GetFirstTuple, ret);
203 ret = pcmcia_get_tuple_data(link, &tuple);
205 if (ret != CS_SUCCESS) {
206 cs_error(link, GetTupleData, ret);
210 ret = pcmcia_parse_tuple(link, &tuple, &parse);
212 if (ret != CS_SUCCESS) {
213 cs_error(link, ParseTuple, ret);
217 if (parse.cftable_entry.mem.nwin > 0) {
218 ipw->request_common_memory.Attributes =
219 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
220 ipw->request_common_memory.Base =
221 parse.cftable_entry.mem.win[0].host_addr;
222 ipw->request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
223 if (ipw->request_common_memory.Size < 0x1000)
224 ipw->request_common_memory.Size = 0x1000;
225 ipw->request_common_memory.AccessSpeed = 0;
227 ret = pcmcia_request_window(&link, &ipw->request_common_memory,
228 &ipw->handle_common_memory);
230 if (ret != CS_SUCCESS) {
231 cs_error(link, RequestWindow, ret);
235 memreq_common_memory.CardOffset =
236 parse.cftable_entry.mem.win[0].card_addr;
237 memreq_common_memory.Page = 0;
239 ret = pcmcia_map_mem_page(ipw->handle_common_memory,
240 &memreq_common_memory);
242 if (ret != CS_SUCCESS) {
243 cs_error(link, MapMemPage, ret);
248 parse.cftable_entry.mem.win[0].len == 0x100;
250 ipw->common_memory = ioremap(ipw->request_common_memory.Base,
251 ipw->request_common_memory.Size);
252 request_mem_region(ipw->request_common_memory.Base,
253 ipw->request_common_memory.Size, IPWIRELESS_PCCARD_NAME);
255 ipw->request_attr_memory.Attributes =
256 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
257 ipw->request_attr_memory.Base = 0;
258 ipw->request_attr_memory.Size = 0; /* this used to be 0x1000 */
259 ipw->request_attr_memory.AccessSpeed = 0;
261 ret = pcmcia_request_window(&link, &ipw->request_attr_memory,
262 &ipw->handle_attr_memory);
264 if (ret != CS_SUCCESS) {
265 cs_error(link, RequestWindow, ret);
269 memreq_attr_memory.CardOffset = 0;
270 memreq_attr_memory.Page = 0;
272 ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
273 &memreq_attr_memory);
275 if (ret != CS_SUCCESS) {
276 cs_error(link, MapMemPage, ret);
280 ipw->attr_memory = ioremap(ipw->request_attr_memory.Base,
281 ipw->request_attr_memory.Size);
282 request_mem_region(ipw->request_attr_memory.Base, ipw->request_attr_memory.Size,
283 IPWIRELESS_PCCARD_NAME);
286 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
288 ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
289 ipw->attr_memory, ipw->common_memory,
290 ipw->is_v2_card, signalled_reboot_callback,
293 ret = pcmcia_request_irq(link, &link->irq);
295 if (ret != CS_SUCCESS) {
296 cs_error(link, RequestIRQ, ret);
300 /* Look up current Vcc */
302 ret = pcmcia_get_configuration_info(link, &conf);
304 if (ret != CS_SUCCESS) {
305 cs_error(link, GetConfigurationInfo, ret);
309 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
310 ipw->is_v2_card ? "V2/V3" : "V1");
311 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
312 ": I/O ports 0x%04x-0x%04x, irq %d\n",
313 (unsigned int) link->io.BasePort1,
314 (unsigned int) (link->io.BasePort1 +
315 link->io.NumPorts1 - 1),
316 (unsigned int) link->irq.AssignedIRQ);
317 if (ipw->attr_memory && ipw->common_memory)
318 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
319 ": attr memory 0x%08lx-0x%08lx, common memory 0x%08lx-0x%08lx\n",
320 ipw->request_attr_memory.Base,
321 ipw->request_attr_memory.Base
322 + ipw->request_attr_memory.Size - 1,
323 ipw->request_common_memory.Base,
324 ipw->request_common_memory.Base
325 + ipw->request_common_memory.Size - 1);
327 ipw->network = ipwireless_network_create(ipw->hardware);
331 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
336 ipwireless_init_hardware_v2_v3(ipw->hardware);
339 * Do the RequestConfiguration last, because it enables interrupts.
340 * Then we don't get any interrupts before we're ready for them.
342 ret = pcmcia_request_configuration(link, &link->conf);
344 if (ret != CS_SUCCESS) {
345 cs_error(link, RequestConfiguration, ret);
349 link->dev_node = &ipw->nodes[0];
354 pcmcia_disable_device(link);
356 if (ipw->attr_memory) {
357 release_mem_region(ipw->request_attr_memory.Base,
358 ipw->request_attr_memory.Size);
359 iounmap(ipw->attr_memory);
360 pcmcia_release_window(ipw->handle_attr_memory);
361 pcmcia_disable_device(link);
364 if (ipw->common_memory) {
365 release_mem_region(ipw->request_common_memory.Base,
366 ipw->request_common_memory.Size);
367 iounmap(ipw->common_memory);
368 pcmcia_release_window(ipw->handle_common_memory);
371 pcmcia_disable_device(link);
376 static void release_ipwireless(struct ipw_dev *ipw)
378 pcmcia_disable_device(ipw->link);
380 if (ipw->common_memory) {
381 release_mem_region(ipw->request_common_memory.Base,
382 ipw->request_common_memory.Size);
383 iounmap(ipw->common_memory);
385 if (ipw->attr_memory) {
386 release_mem_region(ipw->request_attr_memory.Base,
387 ipw->request_attr_memory.Size);
388 iounmap(ipw->attr_memory);
390 if (ipw->common_memory)
391 pcmcia_release_window(ipw->handle_common_memory);
392 if (ipw->attr_memory)
393 pcmcia_release_window(ipw->handle_attr_memory);
395 /* Break the link with Card Services */
396 pcmcia_disable_device(ipw->link);
400 * ipwireless_attach() creates an "instance" of the driver, allocating
401 * local data structures for one device (one interface). The device
402 * is registered with Card Services.
404 * The pcmcia_device structure is initialized, but we don't actually
405 * configure the card at this point -- we wait until we receive a
406 * card insertion event.
408 static int ipwireless_attach(struct pcmcia_device *link)
413 ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
419 link->irq.Instance = ipw;
421 /* Link this device into our device list. */
422 link->dev_node = &ipw->nodes[0];
424 ipw->hardware = ipwireless_hardware_create();
425 if (!ipw->hardware) {
429 /* RegisterClient will call config_ipwireless */
431 ret = config_ipwireless(ipw);
434 cs_error(link, RegisterClient, ret);
435 ipwireless_detach(link);
443 * This deletes a driver "instance". The device is de-registered with
444 * Card Services. If it has been released, all local data structures
445 * are freed. Otherwise, the structures will be freed when the device
448 static void ipwireless_detach(struct pcmcia_device *link)
450 struct ipw_dev *ipw = link->priv;
452 release_ipwireless(ipw);
454 if (ipw->tty != NULL)
455 ipwireless_tty_free(ipw->tty);
456 if (ipw->network != NULL)
457 ipwireless_network_free(ipw->network);
458 if (ipw->hardware != NULL)
459 ipwireless_hardware_free(ipw->hardware);
463 static struct pcmcia_driver me = {
464 .owner = THIS_MODULE,
465 .probe = ipwireless_attach,
466 .remove = ipwireless_detach,
467 .drv = { .name = IPWIRELESS_PCCARD_NAME },
472 * Module insertion : initialisation of the module.
473 * Register the card with cardmgr...
475 static int __init init_ipwireless(void)
479 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
480 IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
482 ret = ipwireless_tty_init();
486 ret = pcmcia_register_driver(&me);
488 ipwireless_tty_release();
496 static void __exit exit_ipwireless(void)
498 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
499 IPWIRELESS_PCMCIA_VERSION " removed\n");
501 pcmcia_unregister_driver(&me);
502 ipwireless_tty_release();
505 module_init(init_ipwireless);
506 module_exit(exit_ipwireless);
508 MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
509 MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
510 MODULE_LICENSE("GPL");