Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: module.c,v 1.14.6.4 2001/09/23 22:24:32 kai Exp $ |
| 2 | * |
| 3 | * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000. |
| 4 | * |
| 5 | * Author Fritz Elfert |
| 6 | * Copyright by Fritz Elfert <fritz@isdn4linux.de> |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This software may be used and distributed according to the terms |
| 9 | * of the GNU General Public License, incorporated herein by reference. |
| 10 | * |
| 11 | * Thanks to Friedemann Baitinger and IBM Germany |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include "act2000.h" |
| 16 | #include "act2000_isa.h" |
| 17 | #include "capi.h" |
| 18 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | |
| 22 | static unsigned short act2000_isa_ports[] = |
| 23 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 24 | 0x0200, 0x0240, 0x0280, 0x02c0, 0x0300, 0x0340, 0x0380, |
| 25 | 0xcfe0, 0xcfa0, 0xcf60, 0xcf20, 0xcee0, 0xcea0, 0xce60, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | static act2000_card *cards = (act2000_card *) NULL; |
| 29 | |
| 30 | /* Parameters to be set by insmod */ |
| 31 | static int act_bus = 0; |
| 32 | static int act_port = -1; /* -1 = Autoprobe */ |
| 33 | static int act_irq = -1; |
| 34 | static char *act_id = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; |
| 35 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 36 | MODULE_DESCRIPTION("ISDN4Linux: Driver for IBM Active 2000 ISDN card"); |
| 37 | MODULE_AUTHOR("Fritz Elfert"); |
| 38 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | MODULE_PARM_DESC(act_bus, "BusType of first card, 1=ISA, 2=MCA, 3=PCMCIA, currently only ISA"); |
| 40 | MODULE_PARM_DESC(membase, "Base port address of first card"); |
| 41 | MODULE_PARM_DESC(act_irq, "IRQ of first card"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 42 | MODULE_PARM_DESC(act_id, "ID-String of first card"); |
| 43 | module_param(act_bus, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | module_param(act_port, int, 0); |
| 45 | module_param(act_irq, int, 0); |
| 46 | module_param(act_id, charp, 0); |
| 47 | |
| 48 | static int act2000_addcard(int, int, int, char *); |
| 49 | |
| 50 | static act2000_chan * |
| 51 | find_channel(act2000_card *card, int channel) |
| 52 | { |
| 53 | if ((channel >= 0) && (channel < ACT2000_BCH)) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 54 | return &(card->bch[channel]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | printk(KERN_WARNING "act2000: Invalid channel %d\n", channel); |
| 56 | return NULL; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Free MSN list |
| 61 | */ |
| 62 | static void |
| 63 | act2000_clear_msn(act2000_card *card) |
| 64 | { |
| 65 | struct msn_entry *p = card->msn_list; |
| 66 | struct msn_entry *q; |
| 67 | unsigned long flags; |
| 68 | |
| 69 | spin_lock_irqsave(&card->lock, flags); |
| 70 | card->msn_list = NULL; |
| 71 | spin_unlock_irqrestore(&card->lock, flags); |
| 72 | while (p) { |
| 73 | q = p->next; |
| 74 | kfree(p); |
| 75 | p = q; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Find an MSN entry in the list. |
| 81 | * If ia5 != 0, return IA5-encoded EAZ, else |
| 82 | * return a bitmask with corresponding bit set. |
| 83 | */ |
| 84 | static __u16 |
| 85 | act2000_find_msn(act2000_card *card, char *msn, int ia5) |
| 86 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 87 | struct msn_entry *p = card->msn_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | __u8 eaz = '0'; |
| 89 | |
| 90 | while (p) { |
| 91 | if (!strcmp(p->msn, msn)) { |
| 92 | eaz = p->eaz; |
| 93 | break; |
| 94 | } |
| 95 | p = p->next; |
| 96 | } |
| 97 | if (!ia5) |
| 98 | return (1 << (eaz - '0')); |
| 99 | else |
| 100 | return eaz; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Find an EAZ entry in the list. |
| 105 | * return a string with corresponding msn. |
| 106 | */ |
| 107 | char * |
| 108 | act2000_find_eaz(act2000_card *card, char eaz) |
| 109 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 110 | struct msn_entry *p = card->msn_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | while (p) { |
| 113 | if (p->eaz == eaz) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 114 | return (p->msn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | p = p->next; |
| 116 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 117 | return ("\0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Add or delete an MSN to the MSN list |
| 122 | * |
| 123 | * First character of msneaz is EAZ, rest is MSN. |
| 124 | * If length of eazmsn is 1, delete that entry. |
| 125 | */ |
| 126 | static int |
| 127 | act2000_set_msn(act2000_card *card, char *eazmsn) |
| 128 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 129 | struct msn_entry *p = card->msn_list; |
| 130 | struct msn_entry *q = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | unsigned long flags; |
| 132 | int i; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | if (!strlen(eazmsn)) |
| 135 | return 0; |
| 136 | if (strlen(eazmsn) > 16) |
| 137 | return -EINVAL; |
| 138 | for (i = 0; i < strlen(eazmsn); i++) |
| 139 | if (!isdigit(eazmsn[i])) |
| 140 | return -EINVAL; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 141 | if (strlen(eazmsn) == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Delete a single MSN */ |
| 143 | while (p) { |
| 144 | if (p->eaz == eazmsn[0]) { |
| 145 | spin_lock_irqsave(&card->lock, flags); |
| 146 | if (q) |
| 147 | q->next = p->next; |
| 148 | else |
| 149 | card->msn_list = p->next; |
| 150 | spin_unlock_irqrestore(&card->lock, flags); |
| 151 | kfree(p); |
| 152 | printk(KERN_DEBUG |
| 153 | "Mapping for EAZ %c deleted\n", |
| 154 | eazmsn[0]); |
| 155 | return 0; |
| 156 | } |
| 157 | q = p; |
| 158 | p = p->next; |
| 159 | } |
| 160 | return 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* Add a single MSN */ |
| 163 | while (p) { |
| 164 | /* Found in list, replace MSN */ |
| 165 | if (p->eaz == eazmsn[0]) { |
| 166 | spin_lock_irqsave(&card->lock, flags); |
| 167 | strcpy(p->msn, &eazmsn[1]); |
| 168 | spin_unlock_irqrestore(&card->lock, flags); |
| 169 | printk(KERN_DEBUG |
| 170 | "Mapping for EAZ %c changed to %s\n", |
| 171 | eazmsn[0], |
| 172 | &eazmsn[1]); |
| 173 | return 0; |
| 174 | } |
| 175 | p = p->next; |
| 176 | } |
| 177 | /* Not found in list, add new entry */ |
| 178 | p = kmalloc(sizeof(msn_entry), GFP_KERNEL); |
| 179 | if (!p) |
| 180 | return -ENOMEM; |
| 181 | p->eaz = eazmsn[0]; |
| 182 | strcpy(p->msn, &eazmsn[1]); |
| 183 | p->next = card->msn_list; |
| 184 | spin_lock_irqsave(&card->lock, flags); |
| 185 | card->msn_list = p; |
| 186 | spin_unlock_irqrestore(&card->lock, flags); |
| 187 | printk(KERN_DEBUG |
| 188 | "Mapping %c -> %s added\n", |
| 189 | eazmsn[0], |
| 190 | &eazmsn[1]); |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 195 | act2000_transmit(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 197 | struct act2000_card *card = |
| 198 | container_of(work, struct act2000_card, snd_tq); |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | switch (card->bus) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 201 | case ACT2000_BUS_ISA: |
| 202 | act2000_isa_send(card); |
| 203 | break; |
| 204 | case ACT2000_BUS_PCMCIA: |
| 205 | case ACT2000_BUS_MCA: |
| 206 | default: |
| 207 | printk(KERN_WARNING |
| 208 | "act2000_transmit: Illegal bustype %d\n", card->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | static void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 213 | act2000_receive(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 215 | struct act2000_card *card = |
| 216 | container_of(work, struct act2000_card, poll_tq); |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | switch (card->bus) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 219 | case ACT2000_BUS_ISA: |
| 220 | act2000_isa_receive(card); |
| 221 | break; |
| 222 | case ACT2000_BUS_PCMCIA: |
| 223 | case ACT2000_BUS_MCA: |
| 224 | default: |
| 225 | printk(KERN_WARNING |
| 226 | "act2000_receive: Illegal bustype %d\n", card->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | static void |
| 231 | act2000_poll(unsigned long data) |
| 232 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 233 | act2000_card *card = (act2000_card *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | unsigned long flags; |
| 235 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 236 | act2000_receive(&card->poll_tq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | spin_lock_irqsave(&card->lock, flags); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 238 | mod_timer(&card->ptimer, jiffies + 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | spin_unlock_irqrestore(&card->lock, flags); |
| 240 | } |
| 241 | |
| 242 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 243 | act2000_command(act2000_card *card, isdn_ctrl *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 245 | ulong a; |
| 246 | act2000_chan *chan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | act2000_cdef cdef; |
| 248 | isdn_ctrl cmd; |
| 249 | char tmp[17]; |
| 250 | int ret; |
| 251 | unsigned long flags; |
| 252 | void __user *arg; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 253 | |
| 254 | switch (c->command) { |
| 255 | case ISDN_CMD_IOCTL: |
| 256 | memcpy(&a, c->parm.num, sizeof(ulong)); |
| 257 | arg = (void __user *)a; |
| 258 | switch (c->arg) { |
| 259 | case ACT2000_IOCTL_LOADBOOT: |
| 260 | switch (card->bus) { |
| 261 | case ACT2000_BUS_ISA: |
| 262 | ret = act2000_isa_download(card, |
| 263 | arg); |
| 264 | if (!ret) { |
| 265 | card->flags |= ACT2000_FLAGS_LOADED; |
| 266 | if (!(card->flags & ACT2000_FLAGS_IVALID)) { |
| 267 | card->ptimer.expires = jiffies + 3; |
| 268 | card->ptimer.function = act2000_poll; |
| 269 | card->ptimer.data = (unsigned long)card; |
| 270 | add_timer(&card->ptimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 272 | actcapi_manufacturer_req_errh(card); |
| 273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 275 | default: |
| 276 | printk(KERN_WARNING |
| 277 | "act2000: Illegal BUS type %d\n", |
| 278 | card->bus); |
| 279 | ret = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | return ret; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 282 | case ACT2000_IOCTL_SETPROTO: |
| 283 | card->ptype = a ? ISDN_PTYPE_EURO : ISDN_PTYPE_1TR6; |
Alexey Dobriyan | eaa0ff1 | 2008-02-06 01:36:06 -0800 | [diff] [blame] | 284 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 285 | return 0; |
| 286 | actcapi_manufacturer_req_net(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 288 | case ACT2000_IOCTL_SETMSN: |
| 289 | if (copy_from_user(tmp, arg, |
| 290 | sizeof(tmp))) |
| 291 | return -EFAULT; |
| 292 | if ((ret = act2000_set_msn(card, tmp))) |
| 293 | return ret; |
| 294 | if (card->flags & ACT2000_FLAGS_RUNNING) |
| 295 | return (actcapi_manufacturer_req_msn(card)); |
| 296 | return 0; |
| 297 | case ACT2000_IOCTL_ADDCARD: |
| 298 | if (copy_from_user(&cdef, arg, |
| 299 | sizeof(cdef))) |
| 300 | return -EFAULT; |
| 301 | if (act2000_addcard(cdef.bus, cdef.port, cdef.irq, cdef.id)) |
| 302 | return -EIO; |
| 303 | return 0; |
| 304 | case ACT2000_IOCTL_TEST: |
Alexey Dobriyan | eaa0ff1 | 2008-02-06 01:36:06 -0800 | [diff] [blame] | 305 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return -ENODEV; |
| 307 | return 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 308 | default: |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | break; |
| 312 | case ISDN_CMD_DIAL: |
| 313 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 314 | return -ENODEV; |
| 315 | if (!(chan = find_channel(card, c->arg & 0x0f))) |
| 316 | break; |
| 317 | spin_lock_irqsave(&card->lock, flags); |
| 318 | if (chan->fsm_state != ACT2000_STATE_NULL) { |
| 319 | spin_unlock_irqrestore(&card->lock, flags); |
| 320 | printk(KERN_WARNING "Dial on channel with state %d\n", |
| 321 | chan->fsm_state); |
| 322 | return -EBUSY; |
| 323 | } |
| 324 | if (card->ptype == ISDN_PTYPE_EURO) |
| 325 | tmp[0] = act2000_find_msn(card, c->parm.setup.eazmsn, 1); |
| 326 | else |
| 327 | tmp[0] = c->parm.setup.eazmsn[0]; |
| 328 | chan->fsm_state = ACT2000_STATE_OCALL; |
| 329 | chan->callref = 0xffff; |
| 330 | spin_unlock_irqrestore(&card->lock, flags); |
| 331 | ret = actcapi_connect_req(card, chan, c->parm.setup.phone, |
| 332 | tmp[0], c->parm.setup.si1, |
| 333 | c->parm.setup.si2); |
| 334 | if (ret) { |
| 335 | cmd.driver = card->myid; |
| 336 | cmd.command = ISDN_STAT_DHUP; |
| 337 | cmd.arg &= 0x0f; |
| 338 | card->interface.statcallb(&cmd); |
| 339 | } |
| 340 | return ret; |
| 341 | case ISDN_CMD_ACCEPTD: |
| 342 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 343 | return -ENODEV; |
| 344 | if (!(chan = find_channel(card, c->arg & 0x0f))) |
| 345 | break; |
| 346 | if (chan->fsm_state == ACT2000_STATE_ICALL) |
| 347 | actcapi_select_b2_protocol_req(card, chan); |
| 348 | return 0; |
| 349 | case ISDN_CMD_ACCEPTB: |
| 350 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 351 | return -ENODEV; |
| 352 | return 0; |
| 353 | case ISDN_CMD_HANGUP: |
| 354 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 355 | return -ENODEV; |
| 356 | if (!(chan = find_channel(card, c->arg & 0x0f))) |
| 357 | break; |
| 358 | switch (chan->fsm_state) { |
| 359 | case ACT2000_STATE_ICALL: |
| 360 | case ACT2000_STATE_BSETUP: |
| 361 | actcapi_connect_resp(card, chan, 0x15); |
| 362 | break; |
| 363 | case ACT2000_STATE_ACTIVE: |
| 364 | actcapi_disconnect_b3_req(card, chan); |
| 365 | break; |
| 366 | } |
| 367 | return 0; |
| 368 | case ISDN_CMD_SETEAZ: |
| 369 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 370 | return -ENODEV; |
| 371 | if (!(chan = find_channel(card, c->arg & 0x0f))) |
| 372 | break; |
| 373 | if (strlen(c->parm.num)) { |
| 374 | if (card->ptype == ISDN_PTYPE_EURO) { |
| 375 | chan->eazmask = act2000_find_msn(card, c->parm.num, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 377 | if (card->ptype == ISDN_PTYPE_1TR6) { |
| 378 | int i; |
| 379 | chan->eazmask = 0; |
| 380 | for (i = 0; i < strlen(c->parm.num); i++) |
| 381 | if (isdigit(c->parm.num[i])) |
| 382 | chan->eazmask |= (1 << (c->parm.num[i] - '0')); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 384 | } else |
| 385 | chan->eazmask = 0x3ff; |
| 386 | actcapi_listen_req(card); |
| 387 | return 0; |
| 388 | case ISDN_CMD_CLREAZ: |
| 389 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 390 | return -ENODEV; |
| 391 | if (!(chan = find_channel(card, c->arg & 0x0f))) |
| 392 | break; |
| 393 | chan->eazmask = 0; |
| 394 | actcapi_listen_req(card); |
| 395 | return 0; |
| 396 | case ISDN_CMD_SETL2: |
| 397 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 398 | return -ENODEV; |
| 399 | if (!(chan = find_channel(card, c->arg & 0x0f))) |
| 400 | break; |
| 401 | chan->l2prot = (c->arg >> 8); |
| 402 | return 0; |
| 403 | case ISDN_CMD_SETL3: |
| 404 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 405 | return -ENODEV; |
| 406 | if ((c->arg >> 8) != ISDN_PROTO_L3_TRANS) { |
| 407 | printk(KERN_WARNING "L3 protocol unknown\n"); |
| 408 | return -1; |
| 409 | } |
| 410 | if (!(chan = find_channel(card, c->arg & 0x0f))) |
| 411 | break; |
| 412 | chan->l3prot = (c->arg >> 8); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static int |
| 420 | act2000_sendbuf(act2000_card *card, int channel, int ack, struct sk_buff *skb) |
| 421 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 422 | struct sk_buff *xmit_skb; |
| 423 | int len; |
| 424 | act2000_chan *chan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | actcapi_msg *msg; |
| 426 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 427 | if (!(chan = find_channel(card, channel))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return -1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 429 | if (chan->fsm_state != ACT2000_STATE_ACTIVE) |
| 430 | return -1; |
| 431 | len = skb->len; |
| 432 | if ((chan->queued + len) >= ACT2000_MAX_QUEUED) |
| 433 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (!len) |
| 435 | return 0; |
| 436 | if (skb_headroom(skb) < 19) { |
| 437 | printk(KERN_WARNING "act2000_sendbuf: Headroom only %d\n", |
| 438 | skb_headroom(skb)); |
| 439 | xmit_skb = alloc_skb(len + 19, GFP_ATOMIC); |
| 440 | if (!xmit_skb) { |
| 441 | printk(KERN_WARNING "act2000_sendbuf: Out of memory\n"); |
| 442 | return 0; |
| 443 | } |
| 444 | skb_reserve(xmit_skb, 19); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 445 | skb_copy_from_linear_data(skb, skb_put(xmit_skb, len), len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } else { |
| 447 | xmit_skb = skb_clone(skb, GFP_ATOMIC); |
| 448 | if (!xmit_skb) { |
| 449 | printk(KERN_WARNING "act2000_sendbuf: Out of memory\n"); |
| 450 | return 0; |
| 451 | } |
| 452 | } |
| 453 | dev_kfree_skb(skb); |
| 454 | msg = (actcapi_msg *)skb_push(xmit_skb, 19); |
| 455 | msg->hdr.len = 19 + len; |
| 456 | msg->hdr.applicationID = 1; |
| 457 | msg->hdr.cmd.cmd = 0x86; |
| 458 | msg->hdr.cmd.subcmd = 0x00; |
| 459 | msg->hdr.msgnum = actcapi_nextsmsg(card); |
| 460 | msg->msg.data_b3_req.datalen = len; |
| 461 | msg->msg.data_b3_req.blocknr = (msg->hdr.msgnum & 0xff); |
| 462 | msg->msg.data_b3_req.fakencci = MAKE_NCCI(chan->plci, 0, chan->ncci); |
| 463 | msg->msg.data_b3_req.flags = ack; /* Will be set to 0 on actual sending */ |
| 464 | actcapi_debug_msg(xmit_skb, 1); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 465 | chan->queued += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | skb_queue_tail(&card->sndq, xmit_skb); |
| 467 | act2000_schedule_tx(card); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 468 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
| 472 | /* Read the Status-replies from the Interface */ |
| 473 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 474 | act2000_readstatus(u_char __user *buf, int len, act2000_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 476 | int count; |
| 477 | u_char __user *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 479 | for (p = buf, count = 0; count < len; p++, count++) { |
| 480 | if (card->status_buf_read == card->status_buf_write) |
| 481 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | put_user(*card->status_buf_read++, p); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 483 | if (card->status_buf_read > card->status_buf_end) |
| 484 | card->status_buf_read = card->status_buf; |
| 485 | } |
| 486 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Find card with given driverId |
| 491 | */ |
| 492 | static inline act2000_card * |
| 493 | act2000_findcard(int driverid) |
| 494 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 495 | act2000_card *p = cards; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 497 | while (p) { |
| 498 | if (p->myid == driverid) |
| 499 | return p; |
| 500 | p = p->next; |
| 501 | } |
| 502 | return (act2000_card *) 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* |
| 506 | * Wrapper functions for interface to linklevel |
| 507 | */ |
| 508 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 509 | if_command(isdn_ctrl *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 511 | act2000_card *card = act2000_findcard(c->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 513 | if (card) |
| 514 | return (act2000_command(card, c)); |
| 515 | printk(KERN_ERR |
| 516 | "act2000: if_command %d called with invalid driverId %d!\n", |
| 517 | c->command, c->driver); |
| 518 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | static int |
| 522 | if_writecmd(const u_char __user *buf, int len, int id, int channel) |
| 523 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 524 | act2000_card *card = act2000_findcard(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 526 | if (card) { |
| 527 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 528 | return -ENODEV; |
| 529 | return (len); |
| 530 | } |
| 531 | printk(KERN_ERR |
| 532 | "act2000: if_writecmd called with invalid driverId!\n"); |
| 533 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 537 | if_readstatus(u_char __user *buf, int len, int id, int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 539 | act2000_card *card = act2000_findcard(id); |
| 540 | |
| 541 | if (card) { |
| 542 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 543 | return -ENODEV; |
| 544 | return (act2000_readstatus(buf, len, card)); |
| 545 | } |
| 546 | printk(KERN_ERR |
| 547 | "act2000: if_readstatus called with invalid driverId!\n"); |
| 548 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static int |
| 552 | if_sendbuf(int id, int channel, int ack, struct sk_buff *skb) |
| 553 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 554 | act2000_card *card = act2000_findcard(id); |
| 555 | |
| 556 | if (card) { |
| 557 | if (!(card->flags & ACT2000_FLAGS_RUNNING)) |
| 558 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | return (act2000_sendbuf(card, channel, ack, skb)); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 560 | } |
| 561 | printk(KERN_ERR |
| 562 | "act2000: if_sendbuf called with invalid driverId!\n"); |
| 563 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
| 567 | /* |
| 568 | * Allocate a new card-struct, initialize it |
| 569 | * link it into cards-list. |
| 570 | */ |
| 571 | static void |
| 572 | act2000_alloccard(int bus, int port, int irq, char *id) |
| 573 | { |
| 574 | int i; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 575 | act2000_card *card; |
| 576 | if (!(card = kzalloc(sizeof(act2000_card), GFP_KERNEL))) { |
| 577 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | "act2000: (%s) Could not allocate card-struct.\n", id); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 579 | return; |
| 580 | } |
| 581 | spin_lock_init(&card->lock); |
| 582 | spin_lock_init(&card->mnlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | skb_queue_head_init(&card->sndq); |
| 584 | skb_queue_head_init(&card->rcvq); |
| 585 | skb_queue_head_init(&card->ackq); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 586 | INIT_WORK(&card->snd_tq, act2000_transmit); |
| 587 | INIT_WORK(&card->rcv_tq, actcapi_dispatch); |
| 588 | INIT_WORK(&card->poll_tq, act2000_receive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | init_timer(&card->ptimer); |
| 590 | card->interface.owner = THIS_MODULE; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 591 | card->interface.channels = ACT2000_BCH; |
| 592 | card->interface.maxbufsize = 4000; |
| 593 | card->interface.command = if_command; |
| 594 | card->interface.writebuf_skb = if_sendbuf; |
| 595 | card->interface.writecmd = if_writecmd; |
| 596 | card->interface.readstat = if_readstatus; |
| 597 | card->interface.features = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | ISDN_FEATURE_L2_X75I | |
| 599 | ISDN_FEATURE_L2_HDLC | |
| 600 | ISDN_FEATURE_L3_TRANS | |
| 601 | ISDN_FEATURE_P_UNKNOWN; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 602 | card->interface.hl_hdrlen = 20; |
| 603 | card->ptype = ISDN_PTYPE_EURO; |
| 604 | strlcpy(card->interface.id, id, sizeof(card->interface.id)); |
| 605 | for (i = 0; i < ACT2000_BCH; i++) { |
| 606 | card->bch[i].plci = 0x8000; |
| 607 | card->bch[i].ncci = 0x8000; |
| 608 | card->bch[i].l2prot = ISDN_PROTO_L2_X75I; |
| 609 | card->bch[i].l3prot = ISDN_PROTO_L3_TRANS; |
| 610 | } |
| 611 | card->myid = -1; |
| 612 | card->bus = bus; |
| 613 | card->port = port; |
| 614 | card->irq = irq; |
| 615 | card->next = cards; |
| 616 | cards = card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /* |
| 620 | * register card at linklevel |
| 621 | */ |
| 622 | static int |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 623 | act2000_registercard(act2000_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 625 | switch (card->bus) { |
| 626 | case ACT2000_BUS_ISA: |
| 627 | break; |
| 628 | case ACT2000_BUS_MCA: |
| 629 | case ACT2000_BUS_PCMCIA: |
| 630 | default: |
| 631 | printk(KERN_WARNING |
| 632 | "act2000: Illegal BUS type %d\n", |
| 633 | card->bus); |
| 634 | return -1; |
| 635 | } |
| 636 | if (!register_isdn(&card->interface)) { |
| 637 | printk(KERN_WARNING |
| 638 | "act2000: Unable to register %s\n", |
| 639 | card->interface.id); |
| 640 | return -1; |
| 641 | } |
| 642 | card->myid = card->interface.channels; |
| 643 | sprintf(card->regname, "act2000-isdn (%s)", card->interface.id); |
| 644 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 648 | unregister_card(act2000_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 650 | isdn_ctrl cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 652 | cmd.command = ISDN_STAT_UNLOAD; |
| 653 | cmd.driver = card->myid; |
| 654 | card->interface.statcallb(&cmd); |
| 655 | switch (card->bus) { |
| 656 | case ACT2000_BUS_ISA: |
| 657 | act2000_isa_release(card); |
| 658 | break; |
| 659 | case ACT2000_BUS_MCA: |
| 660 | case ACT2000_BUS_PCMCIA: |
| 661 | default: |
| 662 | printk(KERN_WARNING |
| 663 | "act2000: Invalid BUS type %d\n", |
| 664 | card->bus); |
| 665 | break; |
| 666 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static int |
| 670 | act2000_addcard(int bus, int port, int irq, char *id) |
| 671 | { |
| 672 | act2000_card *p; |
| 673 | act2000_card *q = NULL; |
| 674 | int initialized; |
| 675 | int added = 0; |
| 676 | int failed = 0; |
| 677 | int i; |
| 678 | |
| 679 | if (!bus) |
| 680 | bus = ACT2000_BUS_ISA; |
| 681 | if (port != -1) { |
| 682 | /* Port defined, do fixed setup */ |
| 683 | act2000_alloccard(bus, port, irq, id); |
| 684 | } else { |
| 685 | /* No port defined, perform autoprobing. |
| 686 | * This may result in more than one card detected. |
| 687 | */ |
| 688 | switch (bus) { |
Karsten Keil | ba2d6cc | 2009-07-24 18:26:08 +0200 | [diff] [blame] | 689 | case ACT2000_BUS_ISA: |
| 690 | for (i = 0; i < ARRAY_SIZE(act2000_isa_ports); i++) |
| 691 | if (act2000_isa_detect(act2000_isa_ports[i])) { |
| 692 | printk(KERN_INFO "act2000: Detected " |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 693 | "ISA card at port 0x%x\n", |
| 694 | act2000_isa_ports[i]); |
Karsten Keil | ba2d6cc | 2009-07-24 18:26:08 +0200 | [diff] [blame] | 695 | act2000_alloccard(bus, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 696 | act2000_isa_ports[i], irq, id); |
Karsten Keil | ba2d6cc | 2009-07-24 18:26:08 +0200 | [diff] [blame] | 697 | } |
| 698 | break; |
| 699 | case ACT2000_BUS_MCA: |
| 700 | case ACT2000_BUS_PCMCIA: |
| 701 | default: |
| 702 | printk(KERN_WARNING |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 703 | "act2000: addcard: Invalid BUS type %d\n", bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | if (!cards) |
| 707 | return 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 708 | p = cards; |
| 709 | while (p) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | initialized = 0; |
| 711 | if (!p->interface.statcallb) { |
| 712 | /* Not yet registered. |
| 713 | * Try to register and activate it. |
| 714 | */ |
| 715 | added++; |
| 716 | switch (p->bus) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 717 | case ACT2000_BUS_ISA: |
| 718 | if (act2000_isa_detect(p->port)) { |
| 719 | if (act2000_registercard(p)) |
| 720 | break; |
| 721 | if (act2000_isa_config_port(p, p->port)) { |
| 722 | printk(KERN_WARNING |
| 723 | "act2000: Could not request port 0x%04x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | p->port); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 725 | unregister_card(p); |
| 726 | p->interface.statcallb = NULL; |
| 727 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 729 | if (act2000_isa_config_irq(p, p->irq)) { |
| 730 | printk(KERN_INFO |
| 731 | "act2000: No IRQ available, fallback to polling\n"); |
| 732 | /* Fall back to polled operation */ |
| 733 | p->irq = 0; |
| 734 | } |
| 735 | printk(KERN_INFO |
| 736 | "act2000: ISA" |
| 737 | "-type card at port " |
| 738 | "0x%04x ", |
| 739 | p->port); |
| 740 | if (p->irq) |
| 741 | printk("irq %d\n", p->irq); |
| 742 | else |
| 743 | printk("polled\n"); |
| 744 | initialized = 1; |
| 745 | } |
| 746 | break; |
| 747 | case ACT2000_BUS_MCA: |
| 748 | case ACT2000_BUS_PCMCIA: |
| 749 | default: |
| 750 | printk(KERN_WARNING |
| 751 | "act2000: addcard: Invalid BUS type %d\n", |
| 752 | p->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | } else |
| 755 | /* Card already initialized */ |
| 756 | initialized = 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 757 | if (initialized) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | /* Init OK, next card ... */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 759 | q = p; |
| 760 | p = p->next; |
| 761 | } else { |
| 762 | /* Init failed, remove card from list, free memory */ |
| 763 | printk(KERN_WARNING |
| 764 | "act2000: Initialization of %s failed\n", |
| 765 | p->interface.id); |
| 766 | if (q) { |
| 767 | q->next = p->next; |
| 768 | kfree(p); |
| 769 | p = q->next; |
| 770 | } else { |
| 771 | cards = p->next; |
| 772 | kfree(p); |
| 773 | p = cards; |
| 774 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | failed++; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 776 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 778 | return (added - failed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | #define DRIVERNAME "IBM Active 2000 ISDN driver" |
| 782 | |
| 783 | static int __init act2000_init(void) |
| 784 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 785 | printk(KERN_INFO "%s\n", DRIVERNAME); |
| 786 | if (!cards) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | act2000_addcard(act_bus, act_port, act_irq, act_id); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 788 | if (!cards) |
| 789 | printk(KERN_INFO "act2000: No cards defined yet\n"); |
| 790 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static void __exit act2000_exit(void) |
| 794 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 795 | act2000_card *card = cards; |
| 796 | act2000_card *last; |
| 797 | while (card) { |
| 798 | unregister_card(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | del_timer(&card->ptimer); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 800 | card = card->next; |
| 801 | } |
| 802 | card = cards; |
| 803 | while (card) { |
| 804 | last = card; |
| 805 | card = card->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | act2000_clear_msn(last); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 807 | kfree(last); |
| 808 | } |
| 809 | printk(KERN_INFO "%s unloaded\n", DRIVERNAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | module_init(act2000_init); |
| 813 | module_exit(act2000_exit); |