Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PCBIT-D interface with isdn4linux |
| 3 | * |
| 4 | * Copyright (C) 1996 Universidade de Lisboa |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Written by Pedro Roque Marques (roque@di.fc.ul.pt) |
| 7 | * |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 8 | * This software may be used and distributed according to the terms of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * the GNU General Public License, incorporated herein by reference. |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Fixes: |
| 14 | * |
| 15 | * Nuno Grilo <l38486@alfa.ist.utl.pt> |
| 16 | * fixed msn_list NULL pointer dereference. |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | |
| 25 | #include <linux/types.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 26 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/skbuff.h> |
| 32 | |
| 33 | #include <linux/isdnif.h> |
| 34 | #include <asm/string.h> |
| 35 | #include <asm/io.h> |
| 36 | #include <linux/ioport.h> |
| 37 | |
| 38 | #include "pcbit.h" |
| 39 | #include "edss1.h" |
| 40 | #include "layer2.h" |
| 41 | #include "capi.h" |
| 42 | |
| 43 | |
| 44 | extern ushort last_ref_num; |
| 45 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 46 | static int pcbit_ioctl(isdn_ctrl *ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 48 | static char *pcbit_devname[MAX_PCBIT_CARDS] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | "pcbit0", |
| 50 | "pcbit1", |
| 51 | "pcbit2", |
| 52 | "pcbit3" |
| 53 | }; |
| 54 | |
| 55 | /* |
| 56 | * prototypes |
| 57 | */ |
| 58 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 59 | static int pcbit_command(isdn_ctrl *ctl); |
| 60 | static int pcbit_stat(u_char __user *buf, int len, int, int); |
Adrian Bunk | 886cca3 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 61 | static int pcbit_xmit(int driver, int chan, int ack, struct sk_buff *skb); |
| 62 | static int pcbit_writecmd(const u_char __user *, int, int, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 64 | static int set_protocol_running(struct pcbit_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | static void pcbit_clear_msn(struct pcbit_dev *dev); |
| 67 | static void pcbit_set_msn(struct pcbit_dev *dev, char *list); |
| 68 | static int pcbit_check_msn(struct pcbit_dev *dev, char *msn); |
| 69 | |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | int pcbit_init_dev(int board, int mem_base, int irq) |
| 72 | { |
| 73 | struct pcbit_dev *dev; |
| 74 | isdn_if *dev_if; |
| 75 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 76 | if ((dev = kzalloc(sizeof(struct pcbit_dev), GFP_KERNEL)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | printk("pcbit_init: couldn't malloc pcbit_dev struct\n"); |
| 79 | return -ENOMEM; |
| 80 | } |
| 81 | |
| 82 | dev_pcbit[board] = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | init_waitqueue_head(&dev->set_running_wq); |
| 84 | spin_lock_init(&dev->lock); |
| 85 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 86 | if (mem_base >= 0xA0000 && mem_base <= 0xFFFFF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | dev->ph_mem = mem_base; |
| 88 | if (!request_mem_region(dev->ph_mem, 4096, "PCBIT mem")) { |
| 89 | printk(KERN_WARNING |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 90 | "PCBIT: memory region %lx-%lx already in use\n", |
| 91 | dev->ph_mem, dev->ph_mem + 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | kfree(dev); |
| 93 | dev_pcbit[board] = NULL; |
| 94 | return -EACCES; |
| 95 | } |
| 96 | dev->sh_mem = ioremap(dev->ph_mem, 4096); |
| 97 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 98 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
| 100 | printk("memory address invalid"); |
| 101 | kfree(dev); |
| 102 | dev_pcbit[board] = NULL; |
| 103 | return -EACCES; |
| 104 | } |
| 105 | |
Burman Yan | 41f9693 | 2006-12-08 02:39:35 -0800 | [diff] [blame] | 106 | dev->b1 = kzalloc(sizeof(struct pcbit_chan), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | if (!dev->b1) { |
| 108 | printk("pcbit_init: couldn't malloc pcbit_chan struct\n"); |
| 109 | iounmap(dev->sh_mem); |
| 110 | release_mem_region(dev->ph_mem, 4096); |
| 111 | kfree(dev); |
| 112 | return -ENOMEM; |
| 113 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 114 | |
Burman Yan | 41f9693 | 2006-12-08 02:39:35 -0800 | [diff] [blame] | 115 | dev->b2 = kzalloc(sizeof(struct pcbit_chan), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | if (!dev->b2) { |
| 117 | printk("pcbit_init: couldn't malloc pcbit_chan struct\n"); |
| 118 | kfree(dev->b1); |
| 119 | iounmap(dev->sh_mem); |
| 120 | release_mem_region(dev->ph_mem, 4096); |
| 121 | kfree(dev); |
| 122 | return -ENOMEM; |
| 123 | } |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | dev->b2->id = 1; |
| 126 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 127 | INIT_WORK(&dev->qdelivery, pcbit_deliver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * interrupts |
| 131 | */ |
| 132 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 133 | if (request_irq(irq, &pcbit_irq_handler, 0, pcbit_devname[board], dev) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
| 135 | kfree(dev->b1); |
| 136 | kfree(dev->b2); |
| 137 | iounmap(dev->sh_mem); |
| 138 | release_mem_region(dev->ph_mem, 4096); |
| 139 | kfree(dev); |
| 140 | dev_pcbit[board] = NULL; |
| 141 | return -EIO; |
| 142 | } |
| 143 | |
| 144 | dev->irq = irq; |
| 145 | |
| 146 | /* next frame to be received */ |
| 147 | dev->rcv_seq = 0; |
| 148 | dev->send_seq = 0; |
| 149 | dev->unack_seq = 0; |
| 150 | |
| 151 | dev->hl_hdrlen = 16; |
| 152 | |
| 153 | dev_if = kmalloc(sizeof(isdn_if), GFP_KERNEL); |
| 154 | |
| 155 | if (!dev_if) { |
| 156 | free_irq(irq, dev); |
| 157 | kfree(dev->b1); |
| 158 | kfree(dev->b2); |
| 159 | iounmap(dev->sh_mem); |
| 160 | release_mem_region(dev->ph_mem, 4096); |
| 161 | kfree(dev); |
| 162 | dev_pcbit[board] = NULL; |
| 163 | return -EIO; |
| 164 | } |
| 165 | |
| 166 | dev->dev_if = dev_if; |
| 167 | |
| 168 | dev_if->owner = THIS_MODULE; |
| 169 | |
| 170 | dev_if->channels = 2; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 171 | |
| 172 | dev_if->features = (ISDN_FEATURE_P_EURO | ISDN_FEATURE_L3_TRANS | |
| 173 | ISDN_FEATURE_L2_HDLC | ISDN_FEATURE_L2_TRANS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | dev_if->writebuf_skb = pcbit_xmit; |
| 176 | dev_if->hl_hdrlen = 16; |
| 177 | |
| 178 | dev_if->maxbufsize = MAXBUFSIZE; |
| 179 | dev_if->command = pcbit_command; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | dev_if->writecmd = pcbit_writecmd; |
| 182 | dev_if->readstat = pcbit_stat; |
| 183 | |
| 184 | |
| 185 | strcpy(dev_if->id, pcbit_devname[board]); |
| 186 | |
| 187 | if (!register_isdn(dev_if)) { |
| 188 | free_irq(irq, dev); |
| 189 | kfree(dev->b1); |
| 190 | kfree(dev->b2); |
| 191 | iounmap(dev->sh_mem); |
| 192 | release_mem_region(dev->ph_mem, 4096); |
| 193 | kfree(dev); |
| 194 | dev_pcbit[board] = NULL; |
| 195 | return -EIO; |
| 196 | } |
| 197 | |
| 198 | dev->id = dev_if->channels; |
| 199 | |
| 200 | |
| 201 | dev->l2_state = L2_DOWN; |
| 202 | dev->free = 511; |
| 203 | |
| 204 | /* |
| 205 | * set_protocol_running(dev); |
| 206 | */ |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | #ifdef MODULE |
| 212 | void pcbit_terminate(int board) |
| 213 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 214 | struct pcbit_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | dev = dev_pcbit[board]; |
| 217 | |
| 218 | if (dev) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 219 | /* unregister_isdn(dev->dev_if); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | free_irq(dev->irq, dev); |
| 221 | pcbit_clear_msn(dev); |
| 222 | kfree(dev->dev_if); |
| 223 | if (dev->b1->fsm_timer.function) |
| 224 | del_timer(&dev->b1->fsm_timer); |
| 225 | if (dev->b2->fsm_timer.function) |
| 226 | del_timer(&dev->b2->fsm_timer); |
| 227 | kfree(dev->b1); |
| 228 | kfree(dev->b2); |
| 229 | iounmap(dev->sh_mem); |
| 230 | release_mem_region(dev->ph_mem, 4096); |
| 231 | kfree(dev); |
| 232 | } |
| 233 | } |
| 234 | #endif |
| 235 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 236 | static int pcbit_command(isdn_ctrl *ctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 238 | struct pcbit_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | struct pcbit_chan *chan; |
| 240 | struct callb_data info; |
| 241 | |
| 242 | dev = finddev(ctl->driver); |
| 243 | |
| 244 | if (!dev) |
| 245 | { |
| 246 | printk("pcbit_command: unknown device\n"); |
| 247 | return -1; |
| 248 | } |
| 249 | |
| 250 | chan = (ctl->arg & 0x0F) ? dev->b2 : dev->b1; |
| 251 | |
| 252 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 253 | switch (ctl->command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | case ISDN_CMD_IOCTL: |
| 255 | return pcbit_ioctl(ctl); |
| 256 | break; |
| 257 | case ISDN_CMD_DIAL: |
| 258 | info.type = EV_USR_SETUP_REQ; |
| 259 | info.data.setup.CalledPN = (char *) &ctl->parm.setup.phone; |
| 260 | pcbit_fsm_event(dev, chan, EV_USR_SETUP_REQ, &info); |
| 261 | break; |
| 262 | case ISDN_CMD_ACCEPTD: |
| 263 | pcbit_fsm_event(dev, chan, EV_USR_SETUP_RESP, NULL); |
| 264 | break; |
| 265 | case ISDN_CMD_ACCEPTB: |
| 266 | printk("ISDN_CMD_ACCEPTB - not really needed\n"); |
| 267 | break; |
| 268 | case ISDN_CMD_HANGUP: |
| 269 | pcbit_fsm_event(dev, chan, EV_USR_RELEASE_REQ, NULL); |
| 270 | break; |
| 271 | case ISDN_CMD_SETL2: |
| 272 | chan->proto = (ctl->arg >> 8); |
| 273 | break; |
| 274 | case ISDN_CMD_CLREAZ: |
| 275 | pcbit_clear_msn(dev); |
| 276 | break; |
| 277 | case ISDN_CMD_SETEAZ: |
| 278 | pcbit_set_msn(dev, ctl->parm.num); |
| 279 | break; |
| 280 | case ISDN_CMD_SETL3: |
| 281 | if ((ctl->arg >> 8) != ISDN_PROTO_L3_TRANS) |
| 282 | printk(KERN_DEBUG "L3 protocol unknown\n"); |
| 283 | break; |
| 284 | default: |
| 285 | printk(KERN_DEBUG "pcbit_command: unknown command\n"); |
| 286 | break; |
| 287 | }; |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Another Hack :-( |
| 294 | * on some conditions the board stops sending TDATA_CONFs |
| 295 | * let's see if we can turn around the problem |
| 296 | */ |
| 297 | |
| 298 | #ifdef BLOCK_TIMER |
| 299 | static void pcbit_block_timer(unsigned long data) |
| 300 | { |
| 301 | struct pcbit_chan *chan; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 302 | struct pcbit_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | isdn_ctrl ictl; |
| 304 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 305 | chan = (struct pcbit_chan *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | dev = chan2dev(chan); |
| 308 | |
| 309 | if (dev == NULL) { |
| 310 | printk(KERN_DEBUG "pcbit: chan2dev failed\n"); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | del_timer(&chan->block_timer); |
| 315 | chan->block_timer.function = NULL; |
| 316 | |
| 317 | #ifdef DEBUG |
| 318 | printk(KERN_DEBUG "pcbit_block_timer\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 319 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | chan->queued = 0; |
| 321 | ictl.driver = dev->id; |
| 322 | ictl.command = ISDN_STAT_BSENT; |
| 323 | ictl.arg = chan->id; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 324 | dev->dev_if->statcallb(&ictl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
| 326 | #endif |
| 327 | |
Adrian Bunk | 886cca3 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 328 | static int pcbit_xmit(int driver, int chnum, int ack, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
| 330 | ushort hdrlen; |
| 331 | int refnum, len; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 332 | struct pcbit_chan *chan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | struct pcbit_dev *dev; |
| 334 | |
| 335 | dev = finddev(driver); |
| 336 | if (dev == NULL) |
| 337 | { |
| 338 | printk("finddev returned NULL"); |
| 339 | return -1; |
| 340 | } |
| 341 | |
| 342 | chan = chnum ? dev->b2 : dev->b1; |
| 343 | |
| 344 | |
| 345 | if (chan->fsm_state != ST_ACTIVE) |
| 346 | return -1; |
| 347 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 348 | if (chan->queued >= MAX_QUEUED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | #ifdef DEBUG_QUEUE |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 351 | printk(KERN_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | "pcbit: %d packets already in queue - write fails\n", |
| 353 | chan->queued); |
| 354 | #endif |
| 355 | /* |
| 356 | * packet stays on the head of the device queue |
| 357 | * since dev_start_xmit will fail |
| 358 | * see net/core/dev.c |
| 359 | */ |
| 360 | #ifdef BLOCK_TIMER |
| 361 | if (chan->block_timer.function == NULL) { |
| 362 | init_timer(&chan->block_timer); |
| 363 | chan->block_timer.function = &pcbit_block_timer; |
| 364 | chan->block_timer.data = (long) chan; |
| 365 | chan->block_timer.expires = jiffies + 1 * HZ; |
| 366 | add_timer(&chan->block_timer); |
| 367 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 368 | #endif |
| 369 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | |
| 373 | chan->queued++; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 374 | |
| 375 | len = skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | hdrlen = capi_tdata_req(chan, skb); |
| 378 | |
| 379 | refnum = last_ref_num++ & 0x7fffU; |
| 380 | chan->s_refnum = refnum; |
| 381 | |
| 382 | pcbit_l2_write(dev, MSG_TDATA_REQ, refnum, skb, hdrlen); |
| 383 | |
| 384 | return len; |
| 385 | } |
| 386 | |
Adrian Bunk | 886cca3 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 387 | static int pcbit_writecmd(const u_char __user *buf, int len, int driver, int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 389 | struct pcbit_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | int i, j; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 391 | const u_char *loadbuf; |
| 392 | u_char *ptr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | u_char *cbuf; |
| 394 | |
| 395 | int errstat; |
| 396 | |
| 397 | dev = finddev(driver); |
| 398 | |
| 399 | if (!dev) |
| 400 | { |
| 401 | printk("pcbit_writecmd: couldn't find device"); |
| 402 | return -ENODEV; |
| 403 | } |
| 404 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 405 | switch (dev->l2_state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | case L2_LWMODE: |
| 407 | /* check (size <= rdp_size); write buf into board */ |
| 408 | if (len < 0 || len > BANK4 + 1 || len > 1024) |
| 409 | { |
| 410 | printk("pcbit_writecmd: invalid length %d\n", len); |
| 411 | return -EINVAL; |
| 412 | } |
| 413 | |
Julia Lawall | 024cb8a | 2010-05-21 22:26:42 +0000 | [diff] [blame] | 414 | cbuf = memdup_user(buf, len); |
| 415 | if (IS_ERR(cbuf)) |
| 416 | return PTR_ERR(cbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | memcpy_toio(dev->sh_mem, cbuf, len); |
| 419 | kfree(cbuf); |
| 420 | return len; |
| 421 | case L2_FWMODE: |
| 422 | /* this is the hard part */ |
| 423 | /* dumb board */ |
| 424 | /* get it into kernel space */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 425 | if ((ptr = kmalloc(len, GFP_KERNEL)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return -ENOMEM; |
| 427 | if (copy_from_user(ptr, buf, len)) { |
| 428 | kfree(ptr); |
| 429 | return -EFAULT; |
| 430 | } |
| 431 | loadbuf = ptr; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | errstat = 0; |
| 434 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 435 | for (i = 0; i < len; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 437 | for (j = 0; j < LOAD_RETRY; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | if (!(readb(dev->sh_mem + dev->loadptr))) |
| 439 | break; |
| 440 | |
| 441 | if (j == LOAD_RETRY) |
| 442 | { |
| 443 | errstat = -ETIME; |
| 444 | printk("TIMEOUT i=%d\n", i); |
| 445 | break; |
| 446 | } |
| 447 | writeb(loadbuf[i], dev->sh_mem + dev->loadptr + 1); |
| 448 | writeb(0x01, dev->sh_mem + dev->loadptr); |
| 449 | |
| 450 | dev->loadptr += 2; |
| 451 | if (dev->loadptr > LOAD_ZONE_END) |
| 452 | dev->loadptr = LOAD_ZONE_START; |
| 453 | } |
| 454 | kfree(ptr); |
| 455 | |
| 456 | return errstat ? errstat : len; |
| 457 | default: |
| 458 | return -EBUSY; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * demultiplexing of messages |
| 464 | * |
| 465 | */ |
| 466 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 467 | void pcbit_l3_receive(struct pcbit_dev *dev, ulong msg, |
| 468 | struct sk_buff *skb, |
| 469 | ushort hdr_len, ushort refnum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
| 471 | struct pcbit_chan *chan; |
| 472 | struct sk_buff *skb2; |
| 473 | unsigned short len; |
| 474 | struct callb_data cbdata; |
| 475 | int complete, err; |
| 476 | isdn_ctrl ictl; |
| 477 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 478 | switch (msg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
| 480 | case MSG_TDATA_IND: |
| 481 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 482 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | "CAPI header: unknown channel id\n"); |
| 484 | break; |
| 485 | } |
| 486 | chan->r_refnum = skb->data[7]; |
| 487 | skb_pull(skb, 8); |
| 488 | |
| 489 | dev->dev_if->rcvcallb_skb(dev->id, chan->id, skb); |
| 490 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 491 | if (capi_tdata_resp(chan, &skb2) > 0) |
| 492 | pcbit_l2_write(dev, MSG_TDATA_RESP, refnum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | skb2, skb2->len); |
| 494 | return; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 495 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | case MSG_TDATA_CONF: |
| 497 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 498 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | "CAPI header: unknown channel id\n"); |
| 500 | break; |
| 501 | } |
| 502 | |
| 503 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 504 | if ((*((ushort *)(skb->data + 2))) != 0) { |
| 505 | printk(KERN_DEBUG "TDATA_CONF error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | #endif |
| 508 | #ifdef BLOCK_TIMER |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 509 | if (chan->queued == MAX_QUEUED) { |
| 510 | del_timer(&chan->block_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | chan->block_timer.function = NULL; |
| 512 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 513 | |
| 514 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | chan->queued--; |
| 516 | |
| 517 | ictl.driver = dev->id; |
| 518 | ictl.command = ISDN_STAT_BSENT; |
| 519 | ictl.arg = chan->id; |
| 520 | dev->dev_if->statcallb(&ictl); |
| 521 | break; |
| 522 | |
| 523 | case MSG_CONN_IND: |
| 524 | /* |
| 525 | * channel: 1st not used will do |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 526 | * if both are used we're in trouble |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | */ |
| 528 | |
| 529 | if (!dev->b1->fsm_state) |
| 530 | chan = dev->b1; |
| 531 | else if (!dev->b2->fsm_state) |
| 532 | chan = dev->b2; |
| 533 | else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 534 | printk(KERN_INFO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | "Incoming connection: no channels available"); |
| 536 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 537 | if ((len = capi_disc_req(*(ushort *)(skb->data), &skb2, CAUSE_NOCHAN)) > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | pcbit_l2_write(dev, MSG_DISC_REQ, refnum, skb2, len); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 539 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | cbdata.data.setup.CalledPN = NULL; |
| 543 | cbdata.data.setup.CallingPN = NULL; |
| 544 | |
| 545 | capi_decode_conn_ind(chan, skb, &cbdata); |
| 546 | cbdata.type = EV_NET_SETUP; |
| 547 | |
| 548 | pcbit_fsm_event(dev, chan, EV_NET_SETUP, NULL); |
| 549 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 550 | if (pcbit_check_msn(dev, cbdata.data.setup.CallingPN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | pcbit_fsm_event(dev, chan, EV_USR_PROCED_REQ, &cbdata); |
| 552 | else |
| 553 | pcbit_fsm_event(dev, chan, EV_USR_RELEASE_REQ, NULL); |
| 554 | |
Jesper Juhl | 3c7208f | 2005-11-07 01:01:29 -0800 | [diff] [blame] | 555 | kfree(cbdata.data.setup.CalledPN); |
| 556 | kfree(cbdata.data.setup.CallingPN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | case MSG_CONN_CONF: |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 560 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | * We should be able to find the channel by the message |
| 562 | * reference number. The current version of the firmware |
| 563 | * doesn't sent the ref number correctly. |
| 564 | */ |
| 565 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 566 | printk(KERN_DEBUG "refnum=%04x b1=%04x b2=%04x\n", refnum, |
| 567 | dev->b1->s_refnum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | dev->b2->s_refnum); |
| 569 | #endif |
| 570 | /* We just try to find a channel in the right state */ |
| 571 | |
| 572 | if (dev->b1->fsm_state == ST_CALL_INIT) |
| 573 | chan = dev->b1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 574 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | if (dev->b2->s_refnum == ST_CALL_INIT) |
| 576 | chan = dev->b2; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 577 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | chan = NULL; |
| 579 | printk(KERN_WARNING "Connection Confirm - no channel in Call Init state\n"); |
| 580 | break; |
| 581 | } |
| 582 | } |
| 583 | if (capi_decode_conn_conf(chan, skb, &complete)) { |
| 584 | printk(KERN_DEBUG "conn_conf indicates error\n"); |
| 585 | pcbit_fsm_event(dev, chan, EV_ERROR, NULL); |
| 586 | } |
| 587 | else |
| 588 | if (complete) |
| 589 | pcbit_fsm_event(dev, chan, EV_NET_CALL_PROC, NULL); |
| 590 | else |
| 591 | pcbit_fsm_event(dev, chan, EV_NET_SETUP_ACK, NULL); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 592 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | case MSG_CONN_ACTV_IND: |
| 594 | |
| 595 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 596 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | "CAPI header: unknown channel id\n"); |
| 598 | break; |
| 599 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | if (capi_decode_conn_actv_ind(chan, skb)) { |
| 602 | printk("error in capi_decode_conn_actv_ind\n"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 603 | /* pcbit_fsm_event(dev, chan, EV_ERROR, NULL); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | break; |
| 605 | } |
| 606 | chan->r_refnum = refnum; |
| 607 | pcbit_fsm_event(dev, chan, EV_NET_CONN, NULL); |
| 608 | break; |
| 609 | case MSG_CONN_ACTV_CONF: |
| 610 | |
| 611 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 612 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | "CAPI header: unknown channel id\n"); |
| 614 | break; |
| 615 | } |
| 616 | |
| 617 | if (capi_decode_conn_actv_conf(chan, skb) == 0) |
| 618 | pcbit_fsm_event(dev, chan, EV_NET_CONN_ACK, NULL); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | else |
| 621 | printk(KERN_DEBUG "decode_conn_actv_conf failed\n"); |
| 622 | break; |
| 623 | |
| 624 | case MSG_SELP_CONF: |
| 625 | |
| 626 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 627 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | "CAPI header: unknown channel id\n"); |
| 629 | break; |
| 630 | } |
| 631 | |
| 632 | if (!(err = capi_decode_sel_proto_conf(chan, skb))) |
| 633 | pcbit_fsm_event(dev, chan, EV_NET_SELP_RESP, NULL); |
| 634 | else { |
| 635 | /* Error */ |
| 636 | printk("error %d - capi_decode_sel_proto_conf\n", err); |
| 637 | } |
| 638 | break; |
| 639 | case MSG_ACT_TRANSP_CONF: |
| 640 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 641 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | "CAPI header: unknown channel id\n"); |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | if (!capi_decode_actv_trans_conf(chan, skb)) |
| 647 | pcbit_fsm_event(dev, chan, EV_NET_ACTV_RESP, NULL); |
| 648 | break; |
| 649 | |
| 650 | case MSG_DISC_IND: |
| 651 | |
| 652 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 653 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | "CAPI header: unknown channel id\n"); |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | if (!capi_decode_disc_ind(chan, skb)) |
| 659 | pcbit_fsm_event(dev, chan, EV_NET_DISC, NULL); |
| 660 | else |
| 661 | printk(KERN_WARNING "capi_decode_disc_ind - error\n"); |
| 662 | break; |
| 663 | case MSG_DISC_CONF: |
| 664 | if (!(chan = capi_channel(dev, skb))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 665 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | "CAPI header: unknown channel id\n"); |
| 667 | break; |
| 668 | } |
| 669 | |
| 670 | if (!capi_decode_disc_ind(chan, skb)) |
| 671 | pcbit_fsm_event(dev, chan, EV_NET_RELEASE, NULL); |
| 672 | else |
| 673 | printk(KERN_WARNING "capi_decode_disc_conf - error\n"); |
| 674 | break; |
| 675 | case MSG_INFO_IND: |
| 676 | #ifdef DEBUG |
| 677 | printk(KERN_DEBUG "received Info Indication - discarded\n"); |
| 678 | #endif |
| 679 | break; |
| 680 | #ifdef DEBUG |
| 681 | case MSG_DEBUG_188: |
| 682 | capi_decode_debug_188(skb->data, skb->len); |
| 683 | break; |
| 684 | |
| 685 | default: |
| 686 | printk(KERN_DEBUG "pcbit_l3_receive: unknown message %08lx\n", |
| 687 | msg); |
| 688 | break; |
| 689 | #endif |
| 690 | } |
| 691 | |
| 692 | kfree_skb(skb); |
| 693 | |
| 694 | } |
| 695 | |
| 696 | /* |
| 697 | * Single statbuf |
| 698 | * should be a statbuf per device |
| 699 | */ |
| 700 | |
| 701 | static char statbuf[STATBUF_LEN]; |
| 702 | static int stat_st = 0; |
| 703 | static int stat_end = 0; |
| 704 | |
Adrian Bunk | 886cca3 | 2005-06-25 14:58:35 -0700 | [diff] [blame] | 705 | static int pcbit_stat(u_char __user *buf, int len, int driver, int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
| 707 | int stat_count; |
| 708 | stat_count = stat_end - stat_st; |
| 709 | |
| 710 | if (stat_count < 0) |
| 711 | stat_count = STATBUF_LEN - stat_st + stat_end; |
| 712 | |
| 713 | /* FIXME: should we sleep and wait for more cookies ? */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 714 | if (len > stat_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | len = stat_count; |
| 716 | |
| 717 | if (stat_st < stat_end) |
| 718 | { |
Jeff Garzik | 7786ce1 | 2006-10-17 00:10:40 -0700 | [diff] [blame] | 719 | if (copy_to_user(buf, statbuf + stat_st, len)) |
| 720 | return -EFAULT; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 721 | stat_st += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |
| 723 | else |
| 724 | { |
| 725 | if (len > STATBUF_LEN - stat_st) |
| 726 | { |
Jeff Garzik | 7786ce1 | 2006-10-17 00:10:40 -0700 | [diff] [blame] | 727 | if (copy_to_user(buf, statbuf + stat_st, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 728 | STATBUF_LEN - stat_st)) |
Jeff Garzik | 7786ce1 | 2006-10-17 00:10:40 -0700 | [diff] [blame] | 729 | return -EFAULT; |
| 730 | if (copy_to_user(buf, statbuf, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 731 | len - (STATBUF_LEN - stat_st))) |
Jeff Garzik | 7786ce1 | 2006-10-17 00:10:40 -0700 | [diff] [blame] | 732 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | stat_st = len - (STATBUF_LEN - stat_st); |
| 735 | } |
| 736 | else |
| 737 | { |
Jeff Garzik | 7786ce1 | 2006-10-17 00:10:40 -0700 | [diff] [blame] | 738 | if (copy_to_user(buf, statbuf + stat_st, len)) |
| 739 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | stat_st += len; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | if (stat_st == STATBUF_LEN) |
| 744 | stat_st = 0; |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | if (stat_st == stat_end) |
| 749 | stat_st = stat_end = 0; |
| 750 | |
| 751 | return len; |
| 752 | } |
| 753 | |
| 754 | static void pcbit_logstat(struct pcbit_dev *dev, char *str) |
| 755 | { |
| 756 | int i; |
| 757 | isdn_ctrl ictl; |
| 758 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 759 | for (i = stat_end; i < strlen(str); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 761 | statbuf[i] = str[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | stat_end = (stat_end + 1) % STATBUF_LEN; |
| 763 | if (stat_end == stat_st) |
| 764 | stat_st = (stat_st + 1) % STATBUF_LEN; |
| 765 | } |
| 766 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 767 | ictl.command = ISDN_STAT_STAVAIL; |
| 768 | ictl.driver = dev->id; |
| 769 | ictl.arg = strlen(str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | dev->dev_if->statcallb(&ictl); |
| 771 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 772 | |
| 773 | void pcbit_state_change(struct pcbit_dev *dev, struct pcbit_chan *chan, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | unsigned short i, unsigned short ev, unsigned short f) |
| 775 | { |
| 776 | char buf[256]; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | sprintf(buf, "change on device: %d channel:%d\n%s -> %s -> %s\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 779 | dev->id, chan->id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | isdn_state_table[i], strisdnevent(ev), isdn_state_table[f] |
| 781 | ); |
| 782 | |
| 783 | #ifdef DEBUG |
| 784 | printk("%s", buf); |
| 785 | #endif |
| 786 | |
| 787 | pcbit_logstat(dev, buf); |
| 788 | } |
| 789 | |
| 790 | static void set_running_timeout(unsigned long ptr) |
| 791 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 792 | struct pcbit_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | #ifdef DEBUG |
| 795 | printk(KERN_DEBUG "set_running_timeout\n"); |
| 796 | #endif |
| 797 | dev = (struct pcbit_dev *) ptr; |
| 798 | |
Arnd Bergmann | e5b3fa1 | 2014-02-26 12:01:52 +0100 | [diff] [blame] | 799 | dev->l2_state = L2_DOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | wake_up_interruptible(&dev->set_running_wq); |
| 801 | } |
| 802 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 803 | static int set_protocol_running(struct pcbit_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
| 805 | isdn_ctrl ctl; |
| 806 | |
| 807 | init_timer(&dev->set_running_timer); |
| 808 | |
| 809 | dev->set_running_timer.function = &set_running_timeout; |
| 810 | dev->set_running_timer.data = (ulong) dev; |
| 811 | dev->set_running_timer.expires = jiffies + SET_RUN_TIMEOUT; |
| 812 | |
| 813 | /* kick it */ |
| 814 | |
| 815 | dev->l2_state = L2_STARTING; |
| 816 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 817 | writeb((0x80U | ((dev->rcv_seq & 0x07) << 3) | (dev->send_seq & 0x07)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | dev->sh_mem + BANK4); |
| 819 | |
| 820 | add_timer(&dev->set_running_timer); |
| 821 | |
Arnd Bergmann | e5b3fa1 | 2014-02-26 12:01:52 +0100 | [diff] [blame] | 822 | wait_event(dev->set_running_wq, dev->l2_state == L2_RUNNING || |
| 823 | dev->l2_state == L2_DOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | del_timer(&dev->set_running_timer); |
| 826 | |
| 827 | if (dev->l2_state == L2_RUNNING) |
| 828 | { |
| 829 | printk(KERN_DEBUG "pcbit: running\n"); |
| 830 | |
| 831 | dev->unack_seq = dev->send_seq; |
| 832 | |
| 833 | dev->writeptr = dev->sh_mem; |
| 834 | dev->readptr = dev->sh_mem + BANK2; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 835 | |
| 836 | /* tell the good news to the upper layer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | ctl.driver = dev->id; |
| 838 | ctl.command = ISDN_STAT_RUN; |
| 839 | |
| 840 | dev->dev_if->statcallb(&ctl); |
| 841 | } |
| 842 | else |
| 843 | { |
| 844 | printk(KERN_DEBUG "pcbit: initialization failed\n"); |
| 845 | printk(KERN_DEBUG "pcbit: firmware not loaded\n"); |
| 846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | #ifdef DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 848 | printk(KERN_DEBUG "Bank3 = %02x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | readb(dev->sh_mem + BANK3)); |
| 850 | #endif |
| 851 | writeb(0x40, dev->sh_mem + BANK4); |
| 852 | |
| 853 | /* warn the upper layer */ |
| 854 | ctl.driver = dev->id; |
| 855 | ctl.command = ISDN_STAT_STOP; |
| 856 | |
| 857 | dev->dev_if->statcallb(&ctl); |
| 858 | |
| 859 | return -EL2HLT; /* Level 2 halted */ |
| 860 | } |
| 861 | |
| 862 | return 0; |
| 863 | } |
| 864 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 865 | static int pcbit_ioctl(isdn_ctrl *ctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 867 | struct pcbit_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | struct pcbit_ioctl *cmd; |
| 869 | |
| 870 | dev = finddev(ctl->driver); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | if (!dev) |
| 873 | { |
| 874 | printk(KERN_DEBUG "pcbit_ioctl: unknown device\n"); |
| 875 | return -ENODEV; |
| 876 | } |
| 877 | |
| 878 | cmd = (struct pcbit_ioctl *) ctl->parm.num; |
| 879 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 880 | switch (ctl->arg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | case PCBIT_IOCTL_GETSTAT: |
| 882 | cmd->info.l2_status = dev->l2_state; |
| 883 | break; |
| 884 | |
| 885 | case PCBIT_IOCTL_STRLOAD: |
| 886 | if (dev->l2_state == L2_RUNNING) |
| 887 | return -EBUSY; |
| 888 | |
| 889 | dev->unack_seq = dev->send_seq = dev->rcv_seq = 0; |
| 890 | |
| 891 | dev->writeptr = dev->sh_mem; |
| 892 | dev->readptr = dev->sh_mem + BANK2; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | dev->l2_state = L2_LOADING; |
| 895 | break; |
| 896 | |
| 897 | case PCBIT_IOCTL_LWMODE: |
| 898 | if (dev->l2_state != L2_LOADING) |
| 899 | return -EINVAL; |
| 900 | |
| 901 | dev->l2_state = L2_LWMODE; |
| 902 | break; |
| 903 | |
| 904 | case PCBIT_IOCTL_FWMODE: |
| 905 | if (dev->l2_state == L2_RUNNING) |
| 906 | return -EBUSY; |
| 907 | dev->loadptr = LOAD_ZONE_START; |
| 908 | dev->l2_state = L2_FWMODE; |
| 909 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 910 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | case PCBIT_IOCTL_ENDLOAD: |
| 912 | if (dev->l2_state == L2_RUNNING) |
| 913 | return -EBUSY; |
| 914 | dev->l2_state = L2_DOWN; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 915 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 917 | case PCBIT_IOCTL_SETBYTE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | if (dev->l2_state == L2_RUNNING) |
| 919 | return -EBUSY; |
| 920 | |
| 921 | /* check addr */ |
| 922 | if (cmd->info.rdp_byte.addr > BANK4) |
| 923 | return -EFAULT; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | writeb(cmd->info.rdp_byte.value, dev->sh_mem + cmd->info.rdp_byte.addr); |
| 926 | break; |
| 927 | case PCBIT_IOCTL_GETBYTE: |
| 928 | if (dev->l2_state == L2_RUNNING) |
| 929 | return -EBUSY; |
| 930 | |
| 931 | /* check addr */ |
| 932 | |
| 933 | if (cmd->info.rdp_byte.addr > BANK4) |
| 934 | { |
| 935 | printk("getbyte: invalid addr %04x\n", cmd->info.rdp_byte.addr); |
| 936 | return -EFAULT; |
| 937 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 938 | |
| 939 | cmd->info.rdp_byte.value = readb(dev->sh_mem + cmd->info.rdp_byte.addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 941 | case PCBIT_IOCTL_RUNNING: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | if (dev->l2_state == L2_RUNNING) |
| 943 | return -EBUSY; |
| 944 | return set_protocol_running(dev); |
| 945 | break; |
| 946 | case PCBIT_IOCTL_WATCH188: |
| 947 | if (dev->l2_state != L2_LOADING) |
| 948 | return -EINVAL; |
| 949 | pcbit_l2_write(dev, MSG_WATCH188, 0x0001, NULL, 0); |
| 950 | break; |
| 951 | case PCBIT_IOCTL_PING188: |
| 952 | if (dev->l2_state != L2_LOADING) |
| 953 | return -EINVAL; |
| 954 | pcbit_l2_write(dev, MSG_PING188_REQ, 0x0001, NULL, 0); |
| 955 | break; |
| 956 | case PCBIT_IOCTL_APION: |
| 957 | if (dev->l2_state != L2_LOADING) |
| 958 | return -EINVAL; |
| 959 | pcbit_l2_write(dev, MSG_API_ON, 0x0001, NULL, 0); |
| 960 | break; |
| 961 | case PCBIT_IOCTL_STOP: |
| 962 | dev->l2_state = L2_DOWN; |
| 963 | writeb(0x40, dev->sh_mem + BANK4); |
| 964 | dev->rcv_seq = 0; |
| 965 | dev->send_seq = 0; |
| 966 | dev->unack_seq = 0; |
| 967 | break; |
| 968 | default: |
| 969 | printk("error: unknown ioctl\n"); |
| 970 | break; |
| 971 | }; |
| 972 | return 0; |
| 973 | } |
| 974 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 975 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | * MSN list handling |
| 977 | * |
| 978 | * if null reject all calls |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 979 | * if first entry has null MSN accept all calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | */ |
| 981 | |
| 982 | static void pcbit_clear_msn(struct pcbit_dev *dev) |
| 983 | { |
| 984 | struct msn_entry *ptr, *back; |
| 985 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 986 | for (ptr = dev->msn_list; ptr;) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | { |
| 988 | back = ptr->next; |
| 989 | kfree(ptr); |
| 990 | ptr = back; |
| 991 | } |
| 992 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 993 | dev->msn_list = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | static void pcbit_set_msn(struct pcbit_dev *dev, char *list) |
| 997 | { |
| 998 | struct msn_entry *ptr; |
| 999 | struct msn_entry *back = NULL; |
| 1000 | char *cp, *sp; |
| 1001 | int len; |
| 1002 | |
| 1003 | if (strlen(list) == 0) { |
| 1004 | ptr = kmalloc(sizeof(struct msn_entry), GFP_ATOMIC); |
| 1005 | if (!ptr) { |
| 1006 | printk(KERN_WARNING "kmalloc failed\n"); |
| 1007 | return; |
| 1008 | } |
| 1009 | |
| 1010 | ptr->msn = NULL; |
| 1011 | |
| 1012 | ptr->next = dev->msn_list; |
| 1013 | dev->msn_list = ptr; |
| 1014 | |
| 1015 | return; |
| 1016 | } |
| 1017 | |
| 1018 | if (dev->msn_list) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1019 | for (back = dev->msn_list; back->next; back = back->next); |
| 1020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | sp = list; |
| 1022 | |
| 1023 | do { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1024 | cp = strchr(sp, ','); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | if (cp) |
| 1026 | len = cp - sp; |
| 1027 | else |
| 1028 | len = strlen(sp); |
| 1029 | |
| 1030 | ptr = kmalloc(sizeof(struct msn_entry), GFP_ATOMIC); |
| 1031 | |
| 1032 | if (!ptr) { |
| 1033 | printk(KERN_WARNING "kmalloc failed\n"); |
| 1034 | return; |
| 1035 | } |
| 1036 | ptr->next = NULL; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1037 | |
Dan Carpenter | 7bcc673 | 2014-07-31 18:30:11 +0300 | [diff] [blame] | 1038 | ptr->msn = kmalloc(len + 1, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | if (!ptr->msn) { |
| 1040 | printk(KERN_WARNING "kmalloc failed\n"); |
| 1041 | kfree(ptr); |
| 1042 | return; |
| 1043 | } |
| 1044 | |
Dan Carpenter | 7bcc673 | 2014-07-31 18:30:11 +0300 | [diff] [blame] | 1045 | memcpy(ptr->msn, sp, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | ptr->msn[len] = 0; |
| 1047 | |
| 1048 | #ifdef DEBUG |
| 1049 | printk(KERN_DEBUG "msn: %s\n", ptr->msn); |
| 1050 | #endif |
| 1051 | if (dev->msn_list == NULL) |
| 1052 | dev->msn_list = ptr; |
| 1053 | else |
| 1054 | back->next = ptr; |
| 1055 | back = ptr; |
| 1056 | sp += len; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1057 | } while (cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | /* |
| 1061 | * check if we do signal or reject an incoming call |
| 1062 | */ |
| 1063 | static int pcbit_check_msn(struct pcbit_dev *dev, char *msn) |
| 1064 | { |
| 1065 | struct msn_entry *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1067 | for (ptr = dev->msn_list; ptr; ptr = ptr->next) { |
| 1068 | |
| 1069 | if (ptr->msn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | return 1; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | if (strcmp(ptr->msn, msn) == 0) |
| 1073 | return 1; |
| 1074 | } |
| 1075 | |
| 1076 | return 0; |
| 1077 | } |