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/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),
43 MODULE_DEVICE_TABLE(pcmcia
, ipw_ids
);
45 static void ipwireless_detach(struct pcmcia_device
*link
);
50 /* Debug mode: more verbose, print sent/recv bytes */
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
,
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
;
89 unsigned short buf
[64];
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
;
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
);
109 ret
= pcmcia_get_tuple_data(link
, &tuple
);
111 if (ret
!= CS_SUCCESS
) {
112 cs_error(link
, GetTupleData
, ret
);
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
);
127 ret
= pcmcia_get_tuple_data(link
, &tuple
);
129 if (ret
!= CS_SUCCESS
) {
130 cs_error(link
, GetTupleData
, ret
);
134 ret
= pcmcia_parse_tuple(link
, &tuple
, &parse
);
136 if (ret
!= CS_SUCCESS
) {
137 cs_error(link
, ParseTuple
, ret
);
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
);
163 ret
= pcmcia_get_tuple_data(link
, &tuple
);
165 if (ret
!= CS_SUCCESS
) {
166 cs_error(link
, GetTupleData
, ret
);
170 ret
= pcmcia_parse_tuple(link
, &tuple
, &parse
);
172 if (ret
!= CS_SUCCESS
) {
173 cs_error(link
, GetTupleData
, ret
);
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
);
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 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
);
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(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
);
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
);
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
,
289 ret
= pcmcia_request_irq(link
, &link
->irq
);
291 if (ret
!= CS_SUCCESS
) {
292 cs_error(link
, RequestIRQ
, ret
);
296 /* Look up current Vcc */
298 ret
= pcmcia_get_configuration_info(link
, &conf
);
300 if (ret
!= CS_SUCCESS
) {
301 cs_error(link
, GetConfigurationInfo
, ret
);
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
);
328 ipw
->tty
= ipwireless_tty_create(ipw
->hardware
, ipw
->network
,
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
);
346 link
->dev_node
= &ipw
->nodes
[0];
351 pcmcia_disable_device(link
);
353 if (ipw
->attr_memory
) {
354 iounmap(ipw
->attr_memory
);
355 pcmcia_release_window(ipw
->handle_attr_memory
);
356 pcmcia_disable_device(link
);
359 if (ipw
->common_memory
) {
360 iounmap(ipw
->common_memory
);
361 pcmcia_release_window(ipw
->handle_common_memory
);
364 pcmcia_disable_device(link
);
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
)
400 ipw
= kzalloc(sizeof(struct ipw_dev
), GFP_KERNEL
);
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
) {
416 /* RegisterClient will call config_ipwireless */
418 ret
= config_ipwireless(ipw
);
421 cs_error(link
, RegisterClient
, ret
);
422 ipwireless_detach(link
);
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
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 */
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
);
454 static struct pcmcia_driver me
= {
455 .owner
= THIS_MODULE
,
456 .probe
= ipwireless_attach
,
457 .remove
= ipwireless_detach
,
458 .drv
= { .name
= IPWIRELESS_PCCARD_NAME
},
463 * Module insertion : initialisation of the module.
464 * Register the card with cardmgr...
466 static int __init
init_ipwireless(void)
470 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
" "
471 IPWIRELESS_PCMCIA_VERSION
" by " IPWIRELESS_PCMCIA_AUTHOR
"\n");
473 ret
= ipwireless_tty_init();
477 ret
= pcmcia_register_driver(&me
);
479 ipwireless_tty_release();
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");