iwlwifi: introduce host commands callbacks
[linux/fpc-iii.git] / drivers / char / pcmcia / ipwireless / main.c
blob00c7f8407e3ecfcfaf3520e0dbdc99ec4ac7933c
1 /*
2 * IPWireless 3G PCMCIA Network Driver
4 * Original code
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
18 #include "hardware.h"
19 #include "network.h"
20 #include "main.h"
21 #include "tty.h"
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>
31 #include <pcmcia/version.h>
32 #include <pcmcia/cisreg.h>
33 #include <pcmcia/device_id.h>
34 #include <pcmcia/ss.h>
35 #include <pcmcia/ds.h>
36 #include <pcmcia/cs.h>
38 static struct pcmcia_device_id ipw_ids[] = {
39 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
40 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
41 PCMCIA_DEVICE_NULL
43 MODULE_DEVICE_TABLE(pcmcia, ipw_ids);
45 static void ipwireless_detach(struct pcmcia_device *link);
48 * Module params
50 /* Debug mode: more verbose, print sent/recv bytes */
51 int ipwireless_debug;
52 int ipwireless_loopback;
53 int ipwireless_out_queue = 1;
55 module_param_named(debug, ipwireless_debug, int, 0);
56 module_param_named(loopback, ipwireless_loopback, int, 0);
57 module_param_named(out_queue, ipwireless_out_queue, int, 0);
58 MODULE_PARM_DESC(debug, "switch on debug messages [0]");
59 MODULE_PARM_DESC(loopback,
60 "debug: enable ras_raw channel [0]");
61 MODULE_PARM_DESC(out_queue, "debug: set size of outgoing queue [1]");
63 /* Executes in process context. */
64 static void signalled_reboot_work(struct work_struct *work_reboot)
66 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
67 work_reboot);
68 struct pcmcia_device *link = ipw->link;
69 int ret = pccard_reset_card(link->socket);
71 if (ret != CS_SUCCESS)
72 cs_error(link, ResetCard, ret);
75 static void signalled_reboot_callback(void *callback_data)
77 struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
79 /* Delegate to process context. */
80 schedule_work(&ipw->work_reboot);
83 static int config_ipwireless(struct ipw_dev *ipw)
85 struct pcmcia_device *link = ipw->link;
86 int ret;
87 config_info_t conf;
88 tuple_t tuple;
89 unsigned short buf[64];
90 cisparse_t parse;
91 unsigned short cor_value;
92 win_req_t request_attr_memory;
93 win_req_t request_common_memory;
94 memreq_t memreq_attr_memory;
95 memreq_t memreq_common_memory;
97 ipw->is_v2_card = 0;
99 tuple.Attributes = 0;
100 tuple.TupleData = (cisdata_t *) buf;
101 tuple.TupleDataMax = sizeof(buf);
102 tuple.TupleOffset = 0;
104 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
106 ret = pcmcia_get_first_tuple(link, &tuple);
108 while (ret == 0) {
109 ret = pcmcia_get_tuple_data(link, &tuple);
111 if (ret != CS_SUCCESS) {
112 cs_error(link, GetTupleData, ret);
113 goto exit0;
115 ret = pcmcia_get_next_tuple(link, &tuple);
118 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
120 ret = pcmcia_get_first_tuple(link, &tuple);
122 if (ret != CS_SUCCESS) {
123 cs_error(link, GetFirstTuple, ret);
124 goto exit0;
127 ret = pcmcia_get_tuple_data(link, &tuple);
129 if (ret != CS_SUCCESS) {
130 cs_error(link, GetTupleData, ret);
131 goto exit0;
134 ret = pcmcia_parse_tuple(link, &tuple, &parse);
136 if (ret != CS_SUCCESS) {
137 cs_error(link, ParseTuple, ret);
138 goto exit0;
141 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
142 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
143 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
144 link->io.IOAddrLines = 16;
146 link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1;
148 /* 0x40 causes it to generate level mode interrupts. */
149 /* 0x04 enables IREQ pin. */
150 cor_value = parse.cftable_entry.index | 0x44;
151 link->conf.ConfigIndex = cor_value;
153 /* IRQ and I/O settings */
154 tuple.DesiredTuple = CISTPL_CONFIG;
156 ret = pcmcia_get_first_tuple(link, &tuple);
158 if (ret != CS_SUCCESS) {
159 cs_error(link, GetFirstTuple, ret);
160 goto exit0;
163 ret = pcmcia_get_tuple_data(link, &tuple);
165 if (ret != CS_SUCCESS) {
166 cs_error(link, GetTupleData, ret);
167 goto exit0;
170 ret = pcmcia_parse_tuple(link, &tuple, &parse);
172 if (ret != CS_SUCCESS) {
173 cs_error(link, GetTupleData, ret);
174 goto exit0;
176 link->conf.Attributes = CONF_ENABLE_IRQ;
177 link->conf.ConfigBase = parse.config.base;
178 link->conf.Present = parse.config.rmask[0];
179 link->conf.IntType = INT_MEMORY_AND_IO;
181 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
182 link->irq.Handler = ipwireless_interrupt;
183 link->irq.Instance = ipw->hardware;
185 ret = pcmcia_request_io(link, &link->io);
187 if (ret != CS_SUCCESS) {
188 cs_error(link, RequestIO, ret);
189 goto exit0;
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);
200 goto exit1;
203 ret = pcmcia_get_tuple_data(link, &tuple);
205 if (ret != CS_SUCCESS) {
206 cs_error(link, GetTupleData, ret);
207 goto exit1;
210 ret = pcmcia_parse_tuple(link, &tuple, &parse);
212 if (ret != CS_SUCCESS) {
213 cs_error(link, ParseTuple, ret);
214 goto exit1;
217 if (parse.cftable_entry.mem.nwin > 0) {
218 request_common_memory.Attributes =
219 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
220 request_common_memory.Base =
221 parse.cftable_entry.mem.win[0].host_addr;
222 request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
223 if (request_common_memory.Size < 0x1000)
224 request_common_memory.Size = 0x1000;
225 request_common_memory.AccessSpeed = 0;
227 ret = pcmcia_request_window(&link, &request_common_memory,
228 &ipw->handle_common_memory);
230 if (ret != CS_SUCCESS) {
231 cs_error(link, RequestWindow, ret);
232 goto exit1;
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);
244 goto exit1;
247 ipw->is_v2_card =
248 parse.cftable_entry.mem.win[0].len == 0x100;
250 ipw->common_memory = ioremap(request_common_memory.Base,
251 request_common_memory.Size);
253 request_attr_memory.Attributes =
254 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
255 request_attr_memory.Base = 0;
256 request_attr_memory.Size = 0; /* this used to be 0x1000 */
257 request_attr_memory.AccessSpeed = 0;
259 ret = pcmcia_request_window(&link, &request_attr_memory,
260 &ipw->handle_attr_memory);
262 if (ret != CS_SUCCESS) {
263 cs_error(link, RequestWindow, ret);
264 goto exit2;
267 memreq_attr_memory.CardOffset = 0;
268 memreq_attr_memory.Page = 0;
270 ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
271 &memreq_attr_memory);
273 if (ret != CS_SUCCESS) {
274 cs_error(link, MapMemPage, ret);
275 goto exit2;
278 ipw->attr_memory = ioremap(request_attr_memory.Base,
279 request_attr_memory.Size);
282 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
284 ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
285 ipw->attr_memory, ipw->common_memory,
286 ipw->is_v2_card, signalled_reboot_callback,
287 ipw);
289 ret = pcmcia_request_irq(link, &link->irq);
291 if (ret != CS_SUCCESS) {
292 cs_error(link, RequestIRQ, ret);
293 goto exit3;
296 /* Look up current Vcc */
298 ret = pcmcia_get_configuration_info(link, &conf);
300 if (ret != CS_SUCCESS) {
301 cs_error(link, GetConfigurationInfo, ret);
302 goto exit4;
305 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
306 ipw->is_v2_card ? "V2/V3" : "V1");
307 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
308 ": I/O ports 0x%04x-0x%04x, irq %d\n",
309 (unsigned int) link->io.BasePort1,
310 (unsigned int) (link->io.BasePort1 +
311 link->io.NumPorts1 - 1),
312 (unsigned int) link->irq.AssignedIRQ);
313 if (ipw->attr_memory && ipw->common_memory)
314 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
315 ": attr memory 0x%08lx-0x%08lx, "
316 "common memory 0x%08lx-0x%08lx\n",
317 request_attr_memory.Base,
318 request_attr_memory.Base
319 + request_attr_memory.Size - 1,
320 request_common_memory.Base,
321 request_common_memory.Base
322 + request_common_memory.Size - 1);
324 ipw->network = ipwireless_network_create(ipw->hardware);
325 if (!ipw->network)
326 goto exit3;
328 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
329 ipw->nodes);
330 if (!ipw->tty)
331 goto exit3;
333 ipwireless_init_hardware_v2_v3(ipw->hardware);
336 * Do the RequestConfiguration last, because it enables interrupts.
337 * Then we don't get any interrupts before we're ready for them.
339 ret = pcmcia_request_configuration(link, &link->conf);
341 if (ret != CS_SUCCESS) {
342 cs_error(link, RequestConfiguration, ret);
343 goto exit4;
346 link->dev_node = &ipw->nodes[0];
348 return 0;
350 exit4:
351 pcmcia_disable_device(link);
352 exit3:
353 if (ipw->attr_memory) {
354 iounmap(ipw->attr_memory);
355 pcmcia_release_window(ipw->handle_attr_memory);
356 pcmcia_disable_device(link);
358 exit2:
359 if (ipw->common_memory) {
360 iounmap(ipw->common_memory);
361 pcmcia_release_window(ipw->handle_common_memory);
363 exit1:
364 pcmcia_disable_device(link);
365 exit0:
366 return -1;
369 static void release_ipwireless(struct ipw_dev *ipw)
371 struct pcmcia_device *link = ipw->link;
373 pcmcia_disable_device(link);
375 if (ipw->common_memory)
376 iounmap(ipw->common_memory);
377 if (ipw->attr_memory)
378 iounmap(ipw->attr_memory);
379 if (ipw->common_memory)
380 pcmcia_release_window(ipw->handle_common_memory);
381 if (ipw->attr_memory)
382 pcmcia_release_window(ipw->handle_attr_memory);
383 pcmcia_disable_device(link);
387 * ipwireless_attach() creates an "instance" of the driver, allocating
388 * local data structures for one device (one interface). The device
389 * is registered with Card Services.
391 * The pcmcia_device structure is initialized, but we don't actually
392 * configure the card at this point -- we wait until we receive a
393 * card insertion event.
395 static int ipwireless_attach(struct pcmcia_device *link)
397 struct ipw_dev *ipw;
398 int ret;
400 ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
401 if (!ipw)
402 return -ENOMEM;
404 ipw->link = link;
405 link->priv = ipw;
406 link->irq.Instance = ipw;
408 /* Link this device into our device list. */
409 link->dev_node = &ipw->nodes[0];
411 ipw->hardware = ipwireless_hardware_create();
412 if (!ipw->hardware) {
413 kfree(ipw);
414 return -ENOMEM;
416 /* RegisterClient will call config_ipwireless */
418 ret = config_ipwireless(ipw);
420 if (ret != 0) {
421 cs_error(link, RegisterClient, ret);
422 ipwireless_detach(link);
423 return ret;
426 return 0;
430 * This deletes a driver "instance". The device is de-registered with
431 * Card Services. If it has been released, all local data structures
432 * are freed. Otherwise, the structures will be freed when the device
433 * is released.
435 static void ipwireless_detach(struct pcmcia_device *link)
437 struct ipw_dev *ipw = link->priv;
439 release_ipwireless(ipw);
441 /* Break the link with Card Services */
442 if (link)
443 pcmcia_disable_device(link);
445 if (ipw->tty != NULL)
446 ipwireless_tty_free(ipw->tty);
447 if (ipw->network != NULL)
448 ipwireless_network_free(ipw->network);
449 if (ipw->hardware != NULL)
450 ipwireless_hardware_free(ipw->hardware);
451 kfree(ipw);
454 static struct pcmcia_driver me = {
455 .owner = THIS_MODULE,
456 .probe = ipwireless_attach,
457 .remove = ipwireless_detach,
458 .drv = { .name = IPWIRELESS_PCCARD_NAME },
459 .id_table = ipw_ids
463 * Module insertion : initialisation of the module.
464 * Register the card with cardmgr...
466 static int __init init_ipwireless(void)
468 int ret;
470 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
471 IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
473 ret = ipwireless_tty_init();
474 if (ret != 0)
475 return ret;
477 ret = pcmcia_register_driver(&me);
478 if (ret != 0)
479 ipwireless_tty_release();
481 return ret;
485 * Module removal
487 static void __exit exit_ipwireless(void)
489 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
490 IPWIRELESS_PCMCIA_VERSION " removed\n");
492 pcmcia_unregister_driver(&me);
493 ipwireless_tty_release();
496 module_init(init_ipwireless);
497 module_exit(exit_ipwireless);
499 MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
500 MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
501 MODULE_LICENSE("GPL");