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 = pcmcia_reset_card(link->socket);
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 ipwireless_ioprobe(struct pcmcia_device *p_dev,
83 cistpl_cftable_entry_t *cfg,
84 cistpl_cftable_entry_t *dflt,
88 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
89 p_dev->io.BasePort1 = cfg->io.win[0].base;
90 p_dev->io.NumPorts1 = cfg->io.win[0].len;
91 p_dev->io.IOAddrLines = 16;
93 p_dev->irq.IRQInfo1 = cfg->irq.IRQInfo1;
95 /* 0x40 causes it to generate level mode interrupts. */
96 /* 0x04 enables IREQ pin. */
97 p_dev->conf.ConfigIndex = cfg->index | 0x44;
98 return pcmcia_request_io(p_dev, &p_dev->io);
101 static int config_ipwireless(struct ipw_dev *ipw)
103 struct pcmcia_device *link = ipw->link;
106 unsigned short buf[64];
108 memreq_t memreq_attr_memory;
109 memreq_t memreq_common_memory;
113 tuple.Attributes = 0;
114 tuple.TupleData = (cisdata_t *) buf;
115 tuple.TupleDataMax = sizeof(buf);
116 tuple.TupleOffset = 0;
118 ret = pcmcia_loop_config(link, ipwireless_ioprobe, NULL);
120 cs_error(link, RequestIO, ret);
124 link->conf.Attributes = CONF_ENABLE_IRQ;
125 link->conf.IntType = INT_MEMORY_AND_IO;
127 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
128 link->irq.Handler = ipwireless_interrupt;
129 link->irq.Instance = ipw->hardware;
131 request_region(link->io.BasePort1, link->io.NumPorts1,
132 IPWIRELESS_PCCARD_NAME);
134 /* memory settings */
135 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
137 ret = pcmcia_get_first_tuple(link, &tuple);
139 cs_error(link, GetFirstTuple, ret);
143 ret = pcmcia_get_tuple_data(link, &tuple);
146 cs_error(link, GetTupleData, ret);
150 ret = pcmcia_parse_tuple(&tuple, &parse);
153 cs_error(link, ParseTuple, ret);
157 if (parse.cftable_entry.mem.nwin > 0) {
158 ipw->request_common_memory.Attributes =
159 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
160 ipw->request_common_memory.Base =
161 parse.cftable_entry.mem.win[0].host_addr;
162 ipw->request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
163 if (ipw->request_common_memory.Size < 0x1000)
164 ipw->request_common_memory.Size = 0x1000;
165 ipw->request_common_memory.AccessSpeed = 0;
167 ret = pcmcia_request_window(&link, &ipw->request_common_memory,
168 &ipw->handle_common_memory);
171 cs_error(link, RequestWindow, ret);
175 memreq_common_memory.CardOffset =
176 parse.cftable_entry.mem.win[0].card_addr;
177 memreq_common_memory.Page = 0;
179 ret = pcmcia_map_mem_page(ipw->handle_common_memory,
180 &memreq_common_memory);
183 cs_error(link, MapMemPage, ret);
188 parse.cftable_entry.mem.win[0].len == 0x100;
190 ipw->common_memory = ioremap(ipw->request_common_memory.Base,
191 ipw->request_common_memory.Size);
192 request_mem_region(ipw->request_common_memory.Base,
193 ipw->request_common_memory.Size, IPWIRELESS_PCCARD_NAME);
195 ipw->request_attr_memory.Attributes =
196 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
197 ipw->request_attr_memory.Base = 0;
198 ipw->request_attr_memory.Size = 0; /* this used to be 0x1000 */
199 ipw->request_attr_memory.AccessSpeed = 0;
201 ret = pcmcia_request_window(&link, &ipw->request_attr_memory,
202 &ipw->handle_attr_memory);
205 cs_error(link, RequestWindow, ret);
209 memreq_attr_memory.CardOffset = 0;
210 memreq_attr_memory.Page = 0;
212 ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
213 &memreq_attr_memory);
216 cs_error(link, MapMemPage, ret);
220 ipw->attr_memory = ioremap(ipw->request_attr_memory.Base,
221 ipw->request_attr_memory.Size);
222 request_mem_region(ipw->request_attr_memory.Base, ipw->request_attr_memory.Size,
223 IPWIRELESS_PCCARD_NAME);
226 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
228 ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
229 ipw->attr_memory, ipw->common_memory,
230 ipw->is_v2_card, signalled_reboot_callback,
233 ret = pcmcia_request_irq(link, &link->irq);
236 cs_error(link, RequestIRQ, ret);
240 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
241 ipw->is_v2_card ? "V2/V3" : "V1");
242 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
243 ": I/O ports 0x%04x-0x%04x, irq %d\n",
244 (unsigned int) link->io.BasePort1,
245 (unsigned int) (link->io.BasePort1 +
246 link->io.NumPorts1 - 1),
247 (unsigned int) link->irq.AssignedIRQ);
248 if (ipw->attr_memory && ipw->common_memory)
249 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
250 ": attr memory 0x%08lx-0x%08lx, common memory 0x%08lx-0x%08lx\n",
251 ipw->request_attr_memory.Base,
252 ipw->request_attr_memory.Base
253 + ipw->request_attr_memory.Size - 1,
254 ipw->request_common_memory.Base,
255 ipw->request_common_memory.Base
256 + ipw->request_common_memory.Size - 1);
258 ipw->network = ipwireless_network_create(ipw->hardware);
262 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
267 ipwireless_init_hardware_v2_v3(ipw->hardware);
270 * Do the RequestConfiguration last, because it enables interrupts.
271 * Then we don't get any interrupts before we're ready for them.
273 ret = pcmcia_request_configuration(link, &link->conf);
276 cs_error(link, RequestConfiguration, ret);
280 link->dev_node = &ipw->nodes[0];
285 pcmcia_disable_device(link);
287 if (ipw->attr_memory) {
288 release_mem_region(ipw->request_attr_memory.Base,
289 ipw->request_attr_memory.Size);
290 iounmap(ipw->attr_memory);
291 pcmcia_release_window(ipw->handle_attr_memory);
292 pcmcia_disable_device(link);
295 if (ipw->common_memory) {
296 release_mem_region(ipw->request_common_memory.Base,
297 ipw->request_common_memory.Size);
298 iounmap(ipw->common_memory);
299 pcmcia_release_window(ipw->handle_common_memory);
302 pcmcia_disable_device(link);
307 static void release_ipwireless(struct ipw_dev *ipw)
309 pcmcia_disable_device(ipw->link);
311 if (ipw->common_memory) {
312 release_mem_region(ipw->request_common_memory.Base,
313 ipw->request_common_memory.Size);
314 iounmap(ipw->common_memory);
316 if (ipw->attr_memory) {
317 release_mem_region(ipw->request_attr_memory.Base,
318 ipw->request_attr_memory.Size);
319 iounmap(ipw->attr_memory);
321 if (ipw->common_memory)
322 pcmcia_release_window(ipw->handle_common_memory);
323 if (ipw->attr_memory)
324 pcmcia_release_window(ipw->handle_attr_memory);
326 /* Break the link with Card Services */
327 pcmcia_disable_device(ipw->link);
331 * ipwireless_attach() creates an "instance" of the driver, allocating
332 * local data structures for one device (one interface). The device
333 * is registered with Card Services.
335 * The pcmcia_device structure is initialized, but we don't actually
336 * configure the card at this point -- we wait until we receive a
337 * card insertion event.
339 static int ipwireless_attach(struct pcmcia_device *link)
344 ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
350 link->irq.Instance = ipw;
352 /* Link this device into our device list. */
353 link->dev_node = &ipw->nodes[0];
355 ipw->hardware = ipwireless_hardware_create();
356 if (!ipw->hardware) {
360 /* RegisterClient will call config_ipwireless */
362 ret = config_ipwireless(ipw);
365 cs_error(link, RegisterClient, ret);
366 ipwireless_detach(link);
374 * This deletes a driver "instance". The device is de-registered with
375 * Card Services. If it has been released, all local data structures
376 * are freed. Otherwise, the structures will be freed when the device
379 static void ipwireless_detach(struct pcmcia_device *link)
381 struct ipw_dev *ipw = link->priv;
383 release_ipwireless(ipw);
385 if (ipw->tty != NULL)
386 ipwireless_tty_free(ipw->tty);
387 if (ipw->network != NULL)
388 ipwireless_network_free(ipw->network);
389 if (ipw->hardware != NULL)
390 ipwireless_hardware_free(ipw->hardware);
394 static struct pcmcia_driver me = {
395 .owner = THIS_MODULE,
396 .probe = ipwireless_attach,
397 .remove = ipwireless_detach,
398 .drv = { .name = IPWIRELESS_PCCARD_NAME },
403 * Module insertion : initialisation of the module.
404 * Register the card with cardmgr...
406 static int __init init_ipwireless(void)
410 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
411 IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
413 ret = ipwireless_tty_init();
417 ret = pcmcia_register_driver(&me);
419 ipwireless_tty_release();
427 static void __exit exit_ipwireless(void)
429 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
430 IPWIRELESS_PCMCIA_VERSION " removed\n");
432 pcmcia_unregister_driver(&me);
433 ipwireless_tty_release();
436 module_init(init_ipwireless);
437 module_exit(exit_ipwireless);
439 MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
440 MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
441 MODULE_LICENSE("GPL");