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 pcmcia_reset_card(link->socket);
71 static void signalled_reboot_callback(void *callback_data)
73 struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
75 /* Delegate to process context. */
76 schedule_work(&ipw->work_reboot);
79 static int ipwireless_probe(struct pcmcia_device *p_dev,
80 cistpl_cftable_entry_t *cfg,
81 cistpl_cftable_entry_t *dflt,
85 struct ipw_dev *ipw = priv_data;
86 struct resource *io_resource;
87 memreq_t memreq_attr_memory;
88 memreq_t memreq_common_memory;
91 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
92 p_dev->io.BasePort1 = cfg->io.win[0].base;
93 p_dev->io.NumPorts1 = cfg->io.win[0].len;
94 p_dev->io.IOAddrLines = 16;
96 /* 0x40 causes it to generate level mode interrupts. */
97 /* 0x04 enables IREQ pin. */
98 p_dev->conf.ConfigIndex = cfg->index | 0x44;
99 ret = pcmcia_request_io(p_dev, &p_dev->io);
103 io_resource = request_region(p_dev->io.BasePort1, p_dev->io.NumPorts1,
104 IPWIRELESS_PCCARD_NAME);
106 if (cfg->mem.nwin == 0)
109 ipw->request_common_memory.Attributes =
110 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
111 ipw->request_common_memory.Base = cfg->mem.win[0].host_addr;
112 ipw->request_common_memory.Size = cfg->mem.win[0].len;
113 if (ipw->request_common_memory.Size < 0x1000)
114 ipw->request_common_memory.Size = 0x1000;
115 ipw->request_common_memory.AccessSpeed = 0;
117 ret = pcmcia_request_window(p_dev, &ipw->request_common_memory,
118 &ipw->handle_common_memory);
123 memreq_common_memory.CardOffset = cfg->mem.win[0].card_addr;
124 memreq_common_memory.Page = 0;
126 ret = pcmcia_map_mem_page(p_dev, ipw->handle_common_memory,
127 &memreq_common_memory);
132 ipw->is_v2_card = cfg->mem.win[0].len == 0x100;
134 ipw->common_memory = ioremap(ipw->request_common_memory.Base,
135 ipw->request_common_memory.Size);
136 request_mem_region(ipw->request_common_memory.Base,
137 ipw->request_common_memory.Size,
138 IPWIRELESS_PCCARD_NAME);
140 ipw->request_attr_memory.Attributes =
141 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
142 ipw->request_attr_memory.Base = 0;
143 ipw->request_attr_memory.Size = 0; /* this used to be 0x1000 */
144 ipw->request_attr_memory.AccessSpeed = 0;
146 ret = pcmcia_request_window(p_dev, &ipw->request_attr_memory,
147 &ipw->handle_attr_memory);
152 memreq_attr_memory.CardOffset = 0;
153 memreq_attr_memory.Page = 0;
155 ret = pcmcia_map_mem_page(p_dev, ipw->handle_attr_memory,
156 &memreq_attr_memory);
161 ipw->attr_memory = ioremap(ipw->request_attr_memory.Base,
162 ipw->request_attr_memory.Size);
163 request_mem_region(ipw->request_attr_memory.Base,
164 ipw->request_attr_memory.Size, IPWIRELESS_PCCARD_NAME);
169 pcmcia_release_window(p_dev, ipw->handle_attr_memory);
171 if (ipw->common_memory) {
172 release_mem_region(ipw->request_common_memory.Base,
173 ipw->request_common_memory.Size);
174 iounmap(ipw->common_memory);
175 pcmcia_release_window(p_dev, ipw->handle_common_memory);
177 pcmcia_release_window(p_dev, ipw->handle_common_memory);
179 release_resource(io_resource);
180 pcmcia_disable_device(p_dev);
184 static int config_ipwireless(struct ipw_dev *ipw)
186 struct pcmcia_device *link = ipw->link;
191 ret = pcmcia_loop_config(link, ipwireless_probe, ipw);
195 link->conf.Attributes = CONF_ENABLE_IRQ;
196 link->conf.IntType = INT_MEMORY_AND_IO;
198 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
200 ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
201 ipw->attr_memory, ipw->common_memory,
202 ipw->is_v2_card, signalled_reboot_callback,
205 ret = pcmcia_request_irq(link, ipwireless_interrupt);
209 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
210 ipw->is_v2_card ? "V2/V3" : "V1");
211 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
212 ": I/O ports 0x%04x-0x%04x, irq %d\n",
213 (unsigned int) link->io.BasePort1,
214 (unsigned int) (link->io.BasePort1 +
215 link->io.NumPorts1 - 1),
216 (unsigned int) link->irq);
217 if (ipw->attr_memory && ipw->common_memory)
218 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
219 ": attr memory 0x%08lx-0x%08lx, common memory 0x%08lx-0x%08lx\n",
220 ipw->request_attr_memory.Base,
221 ipw->request_attr_memory.Base
222 + ipw->request_attr_memory.Size - 1,
223 ipw->request_common_memory.Base,
224 ipw->request_common_memory.Base
225 + ipw->request_common_memory.Size - 1);
227 ipw->network = ipwireless_network_create(ipw->hardware);
231 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network);
235 ipwireless_init_hardware_v2_v3(ipw->hardware);
238 * Do the RequestConfiguration last, because it enables interrupts.
239 * Then we don't get any interrupts before we're ready for them.
241 ret = pcmcia_request_configuration(link, &link->conf);
249 if (ipw->attr_memory) {
250 release_mem_region(ipw->request_attr_memory.Base,
251 ipw->request_attr_memory.Size);
252 iounmap(ipw->attr_memory);
253 pcmcia_release_window(link, ipw->handle_attr_memory);
255 if (ipw->common_memory) {
256 release_mem_region(ipw->request_common_memory.Base,
257 ipw->request_common_memory.Size);
258 iounmap(ipw->common_memory);
259 pcmcia_release_window(link, ipw->handle_common_memory);
261 pcmcia_disable_device(link);
265 static void release_ipwireless(struct ipw_dev *ipw)
267 if (ipw->common_memory) {
268 release_mem_region(ipw->request_common_memory.Base,
269 ipw->request_common_memory.Size);
270 iounmap(ipw->common_memory);
272 if (ipw->attr_memory) {
273 release_mem_region(ipw->request_attr_memory.Base,
274 ipw->request_attr_memory.Size);
275 iounmap(ipw->attr_memory);
277 if (ipw->common_memory)
278 pcmcia_release_window(ipw->link, ipw->handle_common_memory);
279 if (ipw->attr_memory)
280 pcmcia_release_window(ipw->link, ipw->handle_attr_memory);
282 pcmcia_disable_device(ipw->link);
286 * ipwireless_attach() creates an "instance" of the driver, allocating
287 * local data structures for one device (one interface). The device
288 * is registered with Card Services.
290 * The pcmcia_device structure is initialized, but we don't actually
291 * configure the card at this point -- we wait until we receive a
292 * card insertion event.
294 static int ipwireless_attach(struct pcmcia_device *link)
299 ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
306 ipw->hardware = ipwireless_hardware_create();
307 if (!ipw->hardware) {
311 /* RegisterClient will call config_ipwireless */
313 ret = config_ipwireless(ipw);
316 ipwireless_detach(link);
324 * This deletes a driver "instance". The device is de-registered with
325 * Card Services. If it has been released, all local data structures
326 * are freed. Otherwise, the structures will be freed when the device
329 static void ipwireless_detach(struct pcmcia_device *link)
331 struct ipw_dev *ipw = link->priv;
333 release_ipwireless(ipw);
335 if (ipw->tty != NULL)
336 ipwireless_tty_free(ipw->tty);
337 if (ipw->network != NULL)
338 ipwireless_network_free(ipw->network);
339 if (ipw->hardware != NULL)
340 ipwireless_hardware_free(ipw->hardware);
344 static struct pcmcia_driver me = {
345 .owner = THIS_MODULE,
346 .probe = ipwireless_attach,
347 .remove = ipwireless_detach,
348 .drv = { .name = IPWIRELESS_PCCARD_NAME },
353 * Module insertion : initialisation of the module.
354 * Register the card with cardmgr...
356 static int __init init_ipwireless(void)
360 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
361 IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
363 ret = ipwireless_tty_init();
367 ret = pcmcia_register_driver(&me);
369 ipwireless_tty_release();
377 static void __exit exit_ipwireless(void)
379 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
380 IPWIRELESS_PCMCIA_VERSION " removed\n");
382 pcmcia_unregister_driver(&me);
383 ipwireless_tty_release();
386 module_init(init_ipwireless);
387 module_exit(exit_ipwireless);
389 MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
390 MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
391 MODULE_LICENSE("GPL");