David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * IPWireless 3G PCMCIA Network Driver |
| 3 | * |
| 4 | * Original code |
| 5 | * by Stephen Blackheath <stephen@blacksapphire.com>, |
| 6 | * Ben Martel <benm@symmetric.co.nz> |
| 7 | * |
| 8 | * Copyrighted as follows: |
| 9 | * Copyright (C) 2004 by Symmetric Systems Ltd (NZ) |
| 10 | * |
| 11 | * Various driver changes and rewrites, port to new kernels |
| 12 | * Copyright (C) 2006-2007 Jiri Kosina |
| 13 | * |
| 14 | * Misc code cleanups and updates |
| 15 | * Copyright (C) 2007 David Sterba |
| 16 | */ |
| 17 | |
| 18 | #include "hardware.h" |
| 19 | #include "network.h" |
| 20 | #include "main.h" |
| 21 | #include "tty.h" |
| 22 | |
| 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> |
| 30 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 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> |
| 36 | |
| 37 | static struct pcmcia_device_id ipw_ids[] = { |
| 38 | PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100), |
| 39 | PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200), |
| 40 | PCMCIA_DEVICE_NULL |
| 41 | }; |
| 42 | MODULE_DEVICE_TABLE(pcmcia, ipw_ids); |
| 43 | |
| 44 | static void ipwireless_detach(struct pcmcia_device *link); |
| 45 | |
| 46 | /* |
| 47 | * Module params |
| 48 | */ |
| 49 | /* Debug mode: more verbose, print sent/recv bytes */ |
| 50 | int ipwireless_debug; |
| 51 | int ipwireless_loopback; |
David Sterba | bee9c7c | 2008-07-28 16:53:21 +0200 | [diff] [blame] | 52 | int ipwireless_out_queue = 10; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 53 | |
| 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]"); |
David Sterba | bee9c7c | 2008-07-28 16:53:21 +0200 | [diff] [blame] | 60 | MODULE_PARM_DESC(out_queue, "debug: set size of outgoing PPP queue [10]"); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 61 | |
| 62 | /* Executes in process context. */ |
| 63 | static void signalled_reboot_work(struct work_struct *work_reboot) |
| 64 | { |
| 65 | struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev, |
| 66 | work_reboot); |
| 67 | struct pcmcia_device *link = ipw->link; |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 68 | pcmcia_reset_card(link->socket); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void signalled_reboot_callback(void *callback_data) |
| 72 | { |
| 73 | struct ipw_dev *ipw = (struct ipw_dev *) callback_data; |
| 74 | |
| 75 | /* Delegate to process context. */ |
| 76 | schedule_work(&ipw->work_reboot); |
| 77 | } |
| 78 | |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 79 | static int ipwireless_probe(struct pcmcia_device *p_dev, |
| 80 | cistpl_cftable_entry_t *cfg, |
| 81 | cistpl_cftable_entry_t *dflt, |
| 82 | unsigned int vcc, |
| 83 | void *priv_data) |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 84 | { |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 85 | struct ipw_dev *ipw = priv_data; |
| 86 | struct resource *io_resource; |
| 87 | memreq_t memreq_attr_memory; |
| 88 | memreq_t memreq_common_memory; |
| 89 | int ret; |
| 90 | |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 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; |
| 95 | |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 96 | /* 0x40 causes it to generate level mode interrupts. */ |
| 97 | /* 0x04 enables IREQ pin. */ |
| 98 | p_dev->conf.ConfigIndex = cfg->index | 0x44; |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 99 | ret = pcmcia_request_io(p_dev, &p_dev->io); |
| 100 | if (ret) |
| 101 | return ret; |
| 102 | |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame^] | 103 | io_resource = request_region(p_dev->resource[0]->start, |
| 104 | resource_size(p_dev->resource[0]), |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 105 | IPWIRELESS_PCCARD_NAME); |
| 106 | |
| 107 | if (cfg->mem.nwin == 0) |
| 108 | return 0; |
| 109 | |
| 110 | ipw->request_common_memory.Attributes = |
| 111 | WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE; |
| 112 | ipw->request_common_memory.Base = cfg->mem.win[0].host_addr; |
| 113 | ipw->request_common_memory.Size = cfg->mem.win[0].len; |
| 114 | if (ipw->request_common_memory.Size < 0x1000) |
| 115 | ipw->request_common_memory.Size = 0x1000; |
| 116 | ipw->request_common_memory.AccessSpeed = 0; |
| 117 | |
Dominik Brodowski | 6838b03 | 2009-11-03 01:31:52 +0100 | [diff] [blame] | 118 | ret = pcmcia_request_window(p_dev, &ipw->request_common_memory, |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 119 | &ipw->handle_common_memory); |
| 120 | |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 121 | if (ret != 0) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 122 | goto exit1; |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 123 | |
| 124 | memreq_common_memory.CardOffset = cfg->mem.win[0].card_addr; |
| 125 | memreq_common_memory.Page = 0; |
| 126 | |
Magnus Damm | 868575d | 2006-12-13 19:46:43 +0900 | [diff] [blame] | 127 | ret = pcmcia_map_mem_page(p_dev, ipw->handle_common_memory, |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 128 | &memreq_common_memory); |
| 129 | |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 130 | if (ret != 0) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 131 | goto exit2; |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 132 | |
| 133 | ipw->is_v2_card = cfg->mem.win[0].len == 0x100; |
| 134 | |
| 135 | ipw->common_memory = ioremap(ipw->request_common_memory.Base, |
| 136 | ipw->request_common_memory.Size); |
| 137 | request_mem_region(ipw->request_common_memory.Base, |
| 138 | ipw->request_common_memory.Size, |
| 139 | IPWIRELESS_PCCARD_NAME); |
| 140 | |
| 141 | ipw->request_attr_memory.Attributes = |
| 142 | WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE; |
| 143 | ipw->request_attr_memory.Base = 0; |
| 144 | ipw->request_attr_memory.Size = 0; /* this used to be 0x1000 */ |
| 145 | ipw->request_attr_memory.AccessSpeed = 0; |
| 146 | |
Dominik Brodowski | 6838b03 | 2009-11-03 01:31:52 +0100 | [diff] [blame] | 147 | ret = pcmcia_request_window(p_dev, &ipw->request_attr_memory, |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 148 | &ipw->handle_attr_memory); |
| 149 | |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 150 | if (ret != 0) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 151 | goto exit2; |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 152 | |
| 153 | memreq_attr_memory.CardOffset = 0; |
| 154 | memreq_attr_memory.Page = 0; |
| 155 | |
Magnus Damm | 868575d | 2006-12-13 19:46:43 +0900 | [diff] [blame] | 156 | ret = pcmcia_map_mem_page(p_dev, ipw->handle_attr_memory, |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 157 | &memreq_attr_memory); |
| 158 | |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 159 | if (ret != 0) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 160 | goto exit3; |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 161 | |
| 162 | ipw->attr_memory = ioremap(ipw->request_attr_memory.Base, |
| 163 | ipw->request_attr_memory.Size); |
| 164 | request_mem_region(ipw->request_attr_memory.Base, |
| 165 | ipw->request_attr_memory.Size, IPWIRELESS_PCCARD_NAME); |
| 166 | |
| 167 | return 0; |
| 168 | |
| 169 | exit3: |
Magnus Damm | f5560da | 2006-12-13 19:46:38 +0900 | [diff] [blame] | 170 | pcmcia_release_window(p_dev, ipw->handle_attr_memory); |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 171 | exit2: |
| 172 | if (ipw->common_memory) { |
| 173 | release_mem_region(ipw->request_common_memory.Base, |
| 174 | ipw->request_common_memory.Size); |
| 175 | iounmap(ipw->common_memory); |
Magnus Damm | f5560da | 2006-12-13 19:46:38 +0900 | [diff] [blame] | 176 | pcmcia_release_window(p_dev, ipw->handle_common_memory); |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 177 | } else |
Magnus Damm | f5560da | 2006-12-13 19:46:38 +0900 | [diff] [blame] | 178 | pcmcia_release_window(p_dev, ipw->handle_common_memory); |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 179 | exit1: |
| 180 | release_resource(io_resource); |
| 181 | pcmcia_disable_device(p_dev); |
| 182 | return -1; |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 183 | } |
| 184 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 185 | static int config_ipwireless(struct ipw_dev *ipw) |
| 186 | { |
| 187 | struct pcmcia_device *link = ipw->link; |
Dominik Brodowski | aaa8cfd | 2009-10-18 18:28:39 +0200 | [diff] [blame] | 188 | int ret = 0; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 189 | |
| 190 | ipw->is_v2_card = 0; |
| 191 | |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 192 | ret = pcmcia_loop_config(link, ipwireless_probe, ipw); |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 193 | if (ret != 0) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 194 | return ret; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 195 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 196 | link->conf.Attributes = CONF_ENABLE_IRQ; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 197 | link->conf.IntType = INT_MEMORY_AND_IO; |
| 198 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 199 | INIT_WORK(&ipw->work_reboot, signalled_reboot_work); |
| 200 | |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame^] | 201 | ipwireless_init_hardware_v1(ipw->hardware, link->resource[0]->start, |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 202 | ipw->attr_memory, ipw->common_memory, |
| 203 | ipw->is_v2_card, signalled_reboot_callback, |
| 204 | ipw); |
| 205 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 206 | ret = pcmcia_request_irq(link, ipwireless_interrupt); |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 207 | if (ret != 0) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 208 | goto exit; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 209 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 210 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n", |
| 211 | ipw->is_v2_card ? "V2/V3" : "V1"); |
| 212 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME |
Dominik Brodowski | 9a017a9 | 2010-07-24 15:58:54 +0200 | [diff] [blame^] | 213 | ": I/O ports %pR, irq %d\n", link->resource[0], |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 214 | (unsigned int) link->irq); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 215 | if (ipw->attr_memory && ipw->common_memory) |
| 216 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME |
David Sterba | 622e713 | 2008-07-28 16:52:55 +0200 | [diff] [blame] | 217 | ": attr memory 0x%08lx-0x%08lx, common memory 0x%08lx-0x%08lx\n", |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 218 | ipw->request_attr_memory.Base, |
| 219 | ipw->request_attr_memory.Base |
| 220 | + ipw->request_attr_memory.Size - 1, |
| 221 | ipw->request_common_memory.Base, |
| 222 | ipw->request_common_memory.Base |
| 223 | + ipw->request_common_memory.Size - 1); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 224 | |
| 225 | ipw->network = ipwireless_network_create(ipw->hardware); |
| 226 | if (!ipw->network) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 227 | goto exit; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 228 | |
Dominik Brodowski | b498ada | 2010-03-20 19:43:26 +0100 | [diff] [blame] | 229 | ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 230 | if (!ipw->tty) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 231 | goto exit; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 232 | |
| 233 | ipwireless_init_hardware_v2_v3(ipw->hardware); |
| 234 | |
| 235 | /* |
| 236 | * Do the RequestConfiguration last, because it enables interrupts. |
| 237 | * Then we don't get any interrupts before we're ready for them. |
| 238 | */ |
| 239 | ret = pcmcia_request_configuration(link, &link->conf); |
| 240 | |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 241 | if (ret != 0) |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 242 | goto exit; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 243 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 244 | return 0; |
| 245 | |
Dominik Brodowski | af757923 | 2009-10-18 19:48:39 +0200 | [diff] [blame] | 246 | exit: |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 247 | if (ipw->attr_memory) { |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 248 | release_mem_region(ipw->request_attr_memory.Base, |
| 249 | ipw->request_attr_memory.Size); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 250 | iounmap(ipw->attr_memory); |
Magnus Damm | f5560da | 2006-12-13 19:46:38 +0900 | [diff] [blame] | 251 | pcmcia_release_window(link, ipw->handle_attr_memory); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 252 | } |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 253 | if (ipw->common_memory) { |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 254 | release_mem_region(ipw->request_common_memory.Base, |
| 255 | ipw->request_common_memory.Size); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 256 | iounmap(ipw->common_memory); |
Magnus Damm | f5560da | 2006-12-13 19:46:38 +0900 | [diff] [blame] | 257 | pcmcia_release_window(link, ipw->handle_common_memory); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 258 | } |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 259 | pcmcia_disable_device(link); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 260 | return -1; |
| 261 | } |
| 262 | |
| 263 | static void release_ipwireless(struct ipw_dev *ipw) |
| 264 | { |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 265 | if (ipw->common_memory) { |
| 266 | release_mem_region(ipw->request_common_memory.Base, |
| 267 | ipw->request_common_memory.Size); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 268 | iounmap(ipw->common_memory); |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 269 | } |
| 270 | if (ipw->attr_memory) { |
| 271 | release_mem_region(ipw->request_attr_memory.Base, |
| 272 | ipw->request_attr_memory.Size); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 273 | iounmap(ipw->attr_memory); |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 274 | } |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 275 | if (ipw->common_memory) |
Magnus Damm | f5560da | 2006-12-13 19:46:38 +0900 | [diff] [blame] | 276 | pcmcia_release_window(ipw->link, ipw->handle_common_memory); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 277 | if (ipw->attr_memory) |
Magnus Damm | f5560da | 2006-12-13 19:46:38 +0900 | [diff] [blame] | 278 | pcmcia_release_window(ipw->link, ipw->handle_attr_memory); |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 279 | |
David Sterba | 09e491e | 2008-07-28 16:53:16 +0200 | [diff] [blame] | 280 | pcmcia_disable_device(ipw->link); |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* |
| 284 | * ipwireless_attach() creates an "instance" of the driver, allocating |
| 285 | * local data structures for one device (one interface). The device |
| 286 | * is registered with Card Services. |
| 287 | * |
| 288 | * The pcmcia_device structure is initialized, but we don't actually |
| 289 | * configure the card at this point -- we wait until we receive a |
| 290 | * card insertion event. |
| 291 | */ |
| 292 | static int ipwireless_attach(struct pcmcia_device *link) |
| 293 | { |
| 294 | struct ipw_dev *ipw; |
| 295 | int ret; |
| 296 | |
| 297 | ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL); |
| 298 | if (!ipw) |
| 299 | return -ENOMEM; |
| 300 | |
| 301 | ipw->link = link; |
| 302 | link->priv = ipw; |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 303 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 304 | ipw->hardware = ipwireless_hardware_create(); |
| 305 | if (!ipw->hardware) { |
| 306 | kfree(ipw); |
| 307 | return -ENOMEM; |
| 308 | } |
| 309 | /* RegisterClient will call config_ipwireless */ |
| 310 | |
| 311 | ret = config_ipwireless(ipw); |
| 312 | |
| 313 | if (ret != 0) { |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 314 | ipwireless_detach(link); |
| 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * This deletes a driver "instance". The device is de-registered with |
| 323 | * Card Services. If it has been released, all local data structures |
| 324 | * are freed. Otherwise, the structures will be freed when the device |
| 325 | * is released. |
| 326 | */ |
| 327 | static void ipwireless_detach(struct pcmcia_device *link) |
| 328 | { |
| 329 | struct ipw_dev *ipw = link->priv; |
| 330 | |
| 331 | release_ipwireless(ipw); |
| 332 | |
David Sterba | 099dc4f | 2008-02-07 10:57:12 +0100 | [diff] [blame] | 333 | if (ipw->tty != NULL) |
| 334 | ipwireless_tty_free(ipw->tty); |
| 335 | if (ipw->network != NULL) |
| 336 | ipwireless_network_free(ipw->network); |
| 337 | if (ipw->hardware != NULL) |
| 338 | ipwireless_hardware_free(ipw->hardware); |
| 339 | kfree(ipw); |
| 340 | } |
| 341 | |
| 342 | static struct pcmcia_driver me = { |
| 343 | .owner = THIS_MODULE, |
| 344 | .probe = ipwireless_attach, |
| 345 | .remove = ipwireless_detach, |
| 346 | .drv = { .name = IPWIRELESS_PCCARD_NAME }, |
| 347 | .id_table = ipw_ids |
| 348 | }; |
| 349 | |
| 350 | /* |
| 351 | * Module insertion : initialisation of the module. |
| 352 | * Register the card with cardmgr... |
| 353 | */ |
| 354 | static int __init init_ipwireless(void) |
| 355 | { |
| 356 | int ret; |
| 357 | |
| 358 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME " " |
| 359 | IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n"); |
| 360 | |
| 361 | ret = ipwireless_tty_init(); |
| 362 | if (ret != 0) |
| 363 | return ret; |
| 364 | |
| 365 | ret = pcmcia_register_driver(&me); |
| 366 | if (ret != 0) |
| 367 | ipwireless_tty_release(); |
| 368 | |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Module removal |
| 374 | */ |
| 375 | static void __exit exit_ipwireless(void) |
| 376 | { |
| 377 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME " " |
| 378 | IPWIRELESS_PCMCIA_VERSION " removed\n"); |
| 379 | |
| 380 | pcmcia_unregister_driver(&me); |
| 381 | ipwireless_tty_release(); |
| 382 | } |
| 383 | |
| 384 | module_init(init_ipwireless); |
| 385 | module_exit(exit_ipwireless); |
| 386 | |
| 387 | MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR); |
| 388 | MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION); |
| 389 | MODULE_LICENSE("GPL"); |