diff options
Diffstat (limited to 'drivers/tty/n_gsm.c')
-rw-r--r-- | drivers/tty/n_gsm.c | 154 |
1 files changed, 81 insertions, 73 deletions
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 5256087dd81b..11a25fa7d76b 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c | |||
@@ -19,7 +19,7 @@ | |||
19 | * | 19 | * |
20 | * TO DO: | 20 | * TO DO: |
21 | * Mostly done: ioctls for setting modes/timing | 21 | * Mostly done: ioctls for setting modes/timing |
22 | * Partly done: hooks so you can pull off frames to non tty devs | 22 | * Partly done: hooks so you can pull off frames to non tty devs |
23 | * Restart DLCI 0 when it closes ? | 23 | * Restart DLCI 0 when it closes ? |
24 | * Test basic encoding | 24 | * Test basic encoding |
25 | * Improve the tx engine | 25 | * Improve the tx engine |
@@ -73,8 +73,10 @@ module_param(debug, int, 0600); | |||
73 | #define T2 (2 * HZ) | 73 | #define T2 (2 * HZ) |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | /* Semi-arbitary buffer size limits. 0710 is normally run with 32-64 byte | 76 | /* |
77 | limits so this is plenty */ | 77 | * Semi-arbitary buffer size limits. 0710 is normally run with 32-64 byte |
78 | * limits so this is plenty | ||
79 | */ | ||
78 | #define MAX_MRU 512 | 80 | #define MAX_MRU 512 |
79 | #define MAX_MTU 512 | 81 | #define MAX_MTU 512 |
80 | 82 | ||
@@ -290,7 +292,7 @@ static spinlock_t gsm_mux_lock; | |||
290 | #define MDM_DV 0x40 | 292 | #define MDM_DV 0x40 |
291 | 293 | ||
292 | #define GSM0_SOF 0xF9 | 294 | #define GSM0_SOF 0xF9 |
293 | #define GSM1_SOF 0x7E | 295 | #define GSM1_SOF 0x7E |
294 | #define GSM1_ESCAPE 0x7D | 296 | #define GSM1_ESCAPE 0x7D |
295 | #define GSM1_ESCAPE_BITS 0x20 | 297 | #define GSM1_ESCAPE_BITS 0x20 |
296 | #define XON 0x11 | 298 | #define XON 0x11 |
@@ -433,61 +435,63 @@ static void gsm_print_packet(const char *hdr, int addr, int cr, | |||
433 | if (!(debug & 1)) | 435 | if (!(debug & 1)) |
434 | return; | 436 | return; |
435 | 437 | ||
436 | printk(KERN_INFO "%s %d) %c: ", hdr, addr, "RC"[cr]); | 438 | pr_info("%s %d) %c: ", hdr, addr, "RC"[cr]); |
437 | 439 | ||
438 | switch (control & ~PF) { | 440 | switch (control & ~PF) { |
439 | case SABM: | 441 | case SABM: |
440 | printk(KERN_CONT "SABM"); | 442 | pr_cont("SABM"); |
441 | break; | 443 | break; |
442 | case UA: | 444 | case UA: |
443 | printk(KERN_CONT "UA"); | 445 | pr_cont("UA"); |
444 | break; | 446 | break; |
445 | case DISC: | 447 | case DISC: |
446 | printk(KERN_CONT "DISC"); | 448 | pr_cont("DISC"); |
447 | break; | 449 | break; |
448 | case DM: | 450 | case DM: |
449 | printk(KERN_CONT "DM"); | 451 | pr_cont("DM"); |
450 | break; | 452 | break; |
451 | case UI: | 453 | case UI: |
452 | printk(KERN_CONT "UI"); | 454 | pr_cont("UI"); |
453 | break; | 455 | break; |
454 | case UIH: | 456 | case UIH: |
455 | printk(KERN_CONT "UIH"); | 457 | pr_cont("UIH"); |
456 | break; | 458 | break; |
457 | default: | 459 | default: |
458 | if (!(control & 0x01)) { | 460 | if (!(control & 0x01)) { |
459 | printk(KERN_CONT "I N(S)%d N(R)%d", | 461 | pr_cont("I N(S)%d N(R)%d", |
460 | (control & 0x0E) >> 1, (control & 0xE)>> 5); | 462 | (control & 0x0E) >> 1, (control & 0xE) >> 5); |
461 | } else switch (control & 0x0F) { | 463 | } else switch (control & 0x0F) { |
462 | case RR: | 464 | case RR: |
463 | printk("RR(%d)", (control & 0xE0) >> 5); | 465 | pr_cont("RR(%d)", (control & 0xE0) >> 5); |
464 | break; | 466 | break; |
465 | case RNR: | 467 | case RNR: |
466 | printk("RNR(%d)", (control & 0xE0) >> 5); | 468 | pr_cont("RNR(%d)", (control & 0xE0) >> 5); |
467 | break; | 469 | break; |
468 | case REJ: | 470 | case REJ: |
469 | printk("REJ(%d)", (control & 0xE0) >> 5); | 471 | pr_cont("REJ(%d)", (control & 0xE0) >> 5); |
470 | break; | 472 | break; |
471 | default: | 473 | default: |
472 | printk(KERN_CONT "[%02X]", control); | 474 | pr_cont("[%02X]", control); |
473 | } | 475 | } |
474 | } | 476 | } |
475 | 477 | ||
476 | if (control & PF) | 478 | if (control & PF) |
477 | printk(KERN_CONT "(P)"); | 479 | pr_cont("(P)"); |
478 | else | 480 | else |
479 | printk(KERN_CONT "(F)"); | 481 | pr_cont("(F)"); |
480 | 482 | ||
481 | if (dlen) { | 483 | if (dlen) { |
482 | int ct = 0; | 484 | int ct = 0; |
483 | while (dlen--) { | 485 | while (dlen--) { |
484 | if (ct % 8 == 0) | 486 | if (ct % 8 == 0) { |
485 | printk(KERN_CONT "\n "); | 487 | pr_cont("\n"); |
486 | printk(KERN_CONT "%02X ", *data++); | 488 | pr_debug(" "); |
489 | } | ||
490 | pr_cont("%02X ", *data++); | ||
487 | ct++; | 491 | ct++; |
488 | } | 492 | } |
489 | } | 493 | } |
490 | printk(KERN_CONT "\n"); | 494 | pr_cont("\n"); |
491 | } | 495 | } |
492 | 496 | ||
493 | 497 | ||
@@ -526,11 +530,13 @@ static void hex_packet(const unsigned char *p, int len) | |||
526 | { | 530 | { |
527 | int i; | 531 | int i; |
528 | for (i = 0; i < len; i++) { | 532 | for (i = 0; i < len; i++) { |
529 | if (i && (i % 16) == 0) | 533 | if (i && (i % 16) == 0) { |
530 | printk("\n"); | 534 | pr_cont("\n"); |
531 | printk("%02X ", *p++); | 535 | pr_debug(""); |
536 | } | ||
537 | pr_cont("%02X ", *p++); | ||
532 | } | 538 | } |
533 | printk("\n"); | 539 | pr_cont("\n"); |
534 | } | 540 | } |
535 | 541 | ||
536 | /** | 542 | /** |
@@ -680,7 +686,7 @@ static void gsm_data_kick(struct gsm_mux *gsm) | |||
680 | } | 686 | } |
681 | 687 | ||
682 | if (debug & 4) { | 688 | if (debug & 4) { |
683 | printk("gsm_data_kick: \n"); | 689 | pr_debug("gsm_data_kick:\n"); |
684 | hex_packet(gsm->txframe, len); | 690 | hex_packet(gsm->txframe, len); |
685 | } | 691 | } |
686 | 692 | ||
@@ -1233,7 +1239,7 @@ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, | |||
1233 | } | 1239 | } |
1234 | 1240 | ||
1235 | /** | 1241 | /** |
1236 | * gsm_control_transmit - send control packet | 1242 | * gsm_control_transmit - send control packet |
1237 | * @gsm: gsm mux | 1243 | * @gsm: gsm mux |
1238 | * @ctrl: frame to send | 1244 | * @ctrl: frame to send |
1239 | * | 1245 | * |
@@ -1363,7 +1369,7 @@ static void gsm_dlci_close(struct gsm_dlci *dlci) | |||
1363 | { | 1369 | { |
1364 | del_timer(&dlci->t1); | 1370 | del_timer(&dlci->t1); |
1365 | if (debug & 8) | 1371 | if (debug & 8) |
1366 | printk("DLCI %d goes closed.\n", dlci->addr); | 1372 | pr_debug("DLCI %d goes closed.\n", dlci->addr); |
1367 | dlci->state = DLCI_CLOSED; | 1373 | dlci->state = DLCI_CLOSED; |
1368 | if (dlci->addr != 0) { | 1374 | if (dlci->addr != 0) { |
1369 | struct tty_struct *tty = tty_port_tty_get(&dlci->port); | 1375 | struct tty_struct *tty = tty_port_tty_get(&dlci->port); |
@@ -1394,7 +1400,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci) | |||
1394 | /* This will let a tty open continue */ | 1400 | /* This will let a tty open continue */ |
1395 | dlci->state = DLCI_OPEN; | 1401 | dlci->state = DLCI_OPEN; |
1396 | if (debug & 8) | 1402 | if (debug & 8) |
1397 | printk("DLCI %d goes open.\n", dlci->addr); | 1403 | pr_debug("DLCI %d goes open.\n", dlci->addr); |
1398 | wake_up(&dlci->gsm->event); | 1404 | wake_up(&dlci->gsm->event); |
1399 | } | 1405 | } |
1400 | 1406 | ||
@@ -1496,29 +1502,29 @@ static void gsm_dlci_data(struct gsm_dlci *dlci, u8 *data, int len) | |||
1496 | unsigned int modem = 0; | 1502 | unsigned int modem = 0; |
1497 | 1503 | ||
1498 | if (debug & 16) | 1504 | if (debug & 16) |
1499 | printk("%d bytes for tty %p\n", len, tty); | 1505 | pr_debug("%d bytes for tty %p\n", len, tty); |
1500 | if (tty) { | 1506 | if (tty) { |
1501 | switch (dlci->adaption) { | 1507 | switch (dlci->adaption) { |
1502 | /* Unsupported types */ | 1508 | /* Unsupported types */ |
1503 | /* Packetised interruptible data */ | 1509 | /* Packetised interruptible data */ |
1504 | case 4: | 1510 | case 4: |
1505 | break; | 1511 | break; |
1506 | /* Packetised uininterruptible voice/data */ | 1512 | /* Packetised uininterruptible voice/data */ |
1507 | case 3: | 1513 | case 3: |
1508 | break; | 1514 | break; |
1509 | /* Asynchronous serial with line state in each frame */ | 1515 | /* Asynchronous serial with line state in each frame */ |
1510 | case 2: | 1516 | case 2: |
1511 | while (gsm_read_ea(&modem, *data++) == 0) { | 1517 | while (gsm_read_ea(&modem, *data++) == 0) { |
1512 | len--; | 1518 | len--; |
1513 | if (len == 0) | 1519 | if (len == 0) |
1514 | return; | 1520 | return; |
1515 | } | 1521 | } |
1516 | gsm_process_modem(tty, dlci, modem); | 1522 | gsm_process_modem(tty, dlci, modem); |
1517 | /* Line state will go via DLCI 0 controls only */ | 1523 | /* Line state will go via DLCI 0 controls only */ |
1518 | case 1: | 1524 | case 1: |
1519 | default: | 1525 | default: |
1520 | tty_insert_flip_string(tty, data, len); | 1526 | tty_insert_flip_string(tty, data, len); |
1521 | tty_flip_buffer_push(tty); | 1527 | tty_flip_buffer_push(tty); |
1522 | } | 1528 | } |
1523 | tty_kref_put(tty); | 1529 | tty_kref_put(tty); |
1524 | } | 1530 | } |
@@ -1656,7 +1662,7 @@ static void gsm_queue(struct gsm_mux *gsm) | |||
1656 | if (gsm->fcs != GOOD_FCS) { | 1662 | if (gsm->fcs != GOOD_FCS) { |
1657 | gsm->bad_fcs++; | 1663 | gsm->bad_fcs++; |
1658 | if (debug & 4) | 1664 | if (debug & 4) |
1659 | printk("BAD FCS %02x\n", gsm->fcs); | 1665 | pr_debug("BAD FCS %02x\n", gsm->fcs); |
1660 | return; | 1666 | return; |
1661 | } | 1667 | } |
1662 | address = gsm->address >> 1; | 1668 | address = gsm->address >> 1; |
@@ -1890,7 +1896,7 @@ static void gsm1_receive(struct gsm_mux *gsm, unsigned char c) | |||
1890 | gsm->state = GSM_DATA; | 1896 | gsm->state = GSM_DATA; |
1891 | break; | 1897 | break; |
1892 | case GSM_DATA: /* Data */ | 1898 | case GSM_DATA: /* Data */ |
1893 | if (gsm->count > gsm->mru ) { /* Allow one for the FCS */ | 1899 | if (gsm->count > gsm->mru) { /* Allow one for the FCS */ |
1894 | gsm->state = GSM_OVERRUN; | 1900 | gsm->state = GSM_OVERRUN; |
1895 | gsm->bad_size++; | 1901 | gsm->bad_size++; |
1896 | } else | 1902 | } else |
@@ -2085,7 +2091,7 @@ static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len) | |||
2085 | return -ENOSPC; | 2091 | return -ENOSPC; |
2086 | } | 2092 | } |
2087 | if (debug & 4) { | 2093 | if (debug & 4) { |
2088 | printk("-->%d bytes out\n", len); | 2094 | pr_debug("-->%d bytes out\n", len); |
2089 | hex_packet(data, len); | 2095 | hex_packet(data, len); |
2090 | } | 2096 | } |
2091 | gsm->tty->ops->write(gsm->tty, data, len); | 2097 | gsm->tty->ops->write(gsm->tty, data, len); |
@@ -2142,7 +2148,7 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp, | |||
2142 | char flags; | 2148 | char flags; |
2143 | 2149 | ||
2144 | if (debug & 4) { | 2150 | if (debug & 4) { |
2145 | printk("Inbytes %dd\n", count); | 2151 | pr_debug("Inbytes %dd\n", count); |
2146 | hex_packet(cp, count); | 2152 | hex_packet(cp, count); |
2147 | } | 2153 | } |
2148 | 2154 | ||
@@ -2159,7 +2165,7 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp, | |||
2159 | gsm->error(gsm, *dp, flags); | 2165 | gsm->error(gsm, *dp, flags); |
2160 | break; | 2166 | break; |
2161 | default: | 2167 | default: |
2162 | printk(KERN_ERR "%s: unknown flag %d\n", | 2168 | WARN_ONCE("%s: unknown flag %d\n", |
2163 | tty_name(tty, buf), flags); | 2169 | tty_name(tty, buf), flags); |
2164 | break; | 2170 | break; |
2165 | } | 2171 | } |
@@ -2354,7 +2360,7 @@ static int gsmld_config(struct tty_struct *tty, struct gsm_mux *gsm, | |||
2354 | int need_restart = 0; | 2360 | int need_restart = 0; |
2355 | 2361 | ||
2356 | /* Stuff we don't support yet - UI or I frame transport, windowing */ | 2362 | /* Stuff we don't support yet - UI or I frame transport, windowing */ |
2357 | if ((c->adaption !=1 && c->adaption != 2) || c->k) | 2363 | if ((c->adaption != 1 && c->adaption != 2) || c->k) |
2358 | return -EOPNOTSUPP; | 2364 | return -EOPNOTSUPP; |
2359 | /* Check the MRU/MTU range looks sane */ | 2365 | /* Check the MRU/MTU range looks sane */ |
2360 | if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8) | 2366 | if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8) |
@@ -2448,7 +2454,7 @@ static int gsmld_ioctl(struct tty_struct *tty, struct file *file, | |||
2448 | c.i = 1; | 2454 | c.i = 1; |
2449 | else | 2455 | else |
2450 | c.i = 2; | 2456 | c.i = 2; |
2451 | printk("Ftype %d i %d\n", gsm->ftype, c.i); | 2457 | pr_debug("Ftype %d i %d\n", gsm->ftype, c.i); |
2452 | c.mru = gsm->mru; | 2458 | c.mru = gsm->mru; |
2453 | c.mtu = gsm->mtu; | 2459 | c.mtu = gsm->mtu; |
2454 | c.k = 0; | 2460 | c.k = 0; |
@@ -2742,14 +2748,15 @@ static int __init gsm_init(void) | |||
2742 | /* Fill in our line protocol discipline, and register it */ | 2748 | /* Fill in our line protocol discipline, and register it */ |
2743 | int status = tty_register_ldisc(N_GSM0710, &tty_ldisc_packet); | 2749 | int status = tty_register_ldisc(N_GSM0710, &tty_ldisc_packet); |
2744 | if (status != 0) { | 2750 | if (status != 0) { |
2745 | printk(KERN_ERR "n_gsm: can't register line discipline (err = %d)\n", status); | 2751 | pr_err("n_gsm: can't register line discipline (err = %d)\n", |
2752 | status); | ||
2746 | return status; | 2753 | return status; |
2747 | } | 2754 | } |
2748 | 2755 | ||
2749 | gsm_tty_driver = alloc_tty_driver(256); | 2756 | gsm_tty_driver = alloc_tty_driver(256); |
2750 | if (!gsm_tty_driver) { | 2757 | if (!gsm_tty_driver) { |
2751 | tty_unregister_ldisc(N_GSM0710); | 2758 | tty_unregister_ldisc(N_GSM0710); |
2752 | printk(KERN_ERR "gsm_init: tty allocation failed.\n"); | 2759 | pr_err("gsm_init: tty allocation failed.\n"); |
2753 | return -EINVAL; | 2760 | return -EINVAL; |
2754 | } | 2761 | } |
2755 | gsm_tty_driver->owner = THIS_MODULE; | 2762 | gsm_tty_driver->owner = THIS_MODULE; |
@@ -2760,7 +2767,7 @@ static int __init gsm_init(void) | |||
2760 | gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; | 2767 | gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
2761 | gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; | 2768 | gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; |
2762 | gsm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | 2769 | gsm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV |
2763 | | TTY_DRIVER_HARDWARE_BREAK; | 2770 | | TTY_DRIVER_HARDWARE_BREAK; |
2764 | gsm_tty_driver->init_termios = tty_std_termios; | 2771 | gsm_tty_driver->init_termios = tty_std_termios; |
2765 | /* Fixme */ | 2772 | /* Fixme */ |
2766 | gsm_tty_driver->init_termios.c_lflag &= ~ECHO; | 2773 | gsm_tty_driver->init_termios.c_lflag &= ~ECHO; |
@@ -2771,10 +2778,11 @@ static int __init gsm_init(void) | |||
2771 | if (tty_register_driver(gsm_tty_driver)) { | 2778 | if (tty_register_driver(gsm_tty_driver)) { |
2772 | put_tty_driver(gsm_tty_driver); | 2779 | put_tty_driver(gsm_tty_driver); |
2773 | tty_unregister_ldisc(N_GSM0710); | 2780 | tty_unregister_ldisc(N_GSM0710); |
2774 | printk(KERN_ERR "gsm_init: tty registration failed.\n"); | 2781 | pr_err("gsm_init: tty registration failed.\n"); |
2775 | return -EBUSY; | 2782 | return -EBUSY; |
2776 | } | 2783 | } |
2777 | printk(KERN_INFO "gsm_init: loaded as %d,%d.\n", gsm_tty_driver->major, gsm_tty_driver->minor_start); | 2784 | pr_debug("gsm_init: loaded as %d,%d.\n", |
2785 | gsm_tty_driver->major, gsm_tty_driver->minor_start); | ||
2778 | return 0; | 2786 | return 0; |
2779 | } | 2787 | } |
2780 | 2788 | ||
@@ -2782,10 +2790,10 @@ static void __exit gsm_exit(void) | |||
2782 | { | 2790 | { |
2783 | int status = tty_unregister_ldisc(N_GSM0710); | 2791 | int status = tty_unregister_ldisc(N_GSM0710); |
2784 | if (status != 0) | 2792 | if (status != 0) |
2785 | printk(KERN_ERR "n_gsm: can't unregister line discipline (err = %d)\n", status); | 2793 | pr_err("n_gsm: can't unregister line discipline (err = %d)\n", |
2794 | status); | ||
2786 | tty_unregister_driver(gsm_tty_driver); | 2795 | tty_unregister_driver(gsm_tty_driver); |
2787 | put_tty_driver(gsm_tty_driver); | 2796 | put_tty_driver(gsm_tty_driver); |
2788 | printk(KERN_INFO "gsm_init: unloaded.\n"); | ||
2789 | } | 2797 | } |
2790 | 2798 | ||
2791 | module_init(gsm_init); | 2799 | module_init(gsm_init); |