aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/istallion.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2009-01-02 08:46:50 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-02 13:19:40 -0500
commita6614999e800cf3a134ce93ea46ef837e3c0e76e (patch)
tree56b0a29ed004a284561a4c3ff3ee52075acabb65 /drivers/char/istallion.c
parent7834909f1eb96ba7c49ca2b9e3a69b500a2cff76 (diff)
tty: Introduce some close helpers for ports
Again this is a lot of common code we can unify Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/istallion.c')
-rw-r--r--drivers/char/istallion.c78
1 files changed, 29 insertions, 49 deletions
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 4c69ab97339a..5c3dc6b8411c 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -767,7 +767,7 @@ static int stli_parsebrd(struct stlconf *confp, char **argp)
767 break; 767 break;
768 } 768 }
769 if (i == ARRAY_SIZE(stli_brdstr)) { 769 if (i == ARRAY_SIZE(stli_brdstr)) {
770 printk("STALLION: unknown board name, %s?\n", argp[0]); 770 printk(KERN_WARNING "istallion: unknown board name, %s?\n", argp[0]);
771 return 0; 771 return 0;
772 } 772 }
773 773
@@ -855,21 +855,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
855 return; 855 return;
856 port = &portp->port; 856 port = &portp->port;
857 857
858 spin_lock_irqsave(&port->lock, flags); 858 if (tty_port_close_start(port, tty, filp) == 0)
859 if (tty_hung_up_p(filp)) {
860 spin_unlock_irqrestore(&port->lock, flags);
861 return;
862 }
863 if (tty->count == 1 && port->count != 1)
864 port->count = 1;
865 if (port->count-- > 1) {
866 spin_unlock_irqrestore(&port->lock, flags);
867 return; 859 return;
868 }
869
870 port->flags |= ASYNC_CLOSING;
871 tty->closing = 1;
872 spin_unlock_irqrestore(&port->lock, flags);
873 860
874/* 861/*
875 * May want to wait for data to drain before closing. The BUSY flag 862 * May want to wait for data to drain before closing. The BUSY flag
@@ -882,6 +869,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
882 stli_flushchars(tty); 869 stli_flushchars(tty);
883 spin_unlock_irqrestore(&stli_lock, flags); 870 spin_unlock_irqrestore(&stli_lock, flags);
884 871
872 /* We end up doing this twice for the moment. This needs looking at
873 eventually. Note we still use portp->closing_wait as a result */
885 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) 874 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
886 tty_wait_until_sent(tty, portp->closing_wait); 875 tty_wait_until_sent(tty, portp->closing_wait);
887 876
@@ -905,17 +894,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
905 set_bit(ST_DOFLUSHRX, &portp->state); 894 set_bit(ST_DOFLUSHRX, &portp->state);
906 stli_flushbuffer(tty); 895 stli_flushbuffer(tty);
907 896
908 tty->closing = 0; 897 tty_port_close_end(port, tty);
909 tty_port_tty_set(&portp->port, NULL); 898 tty_port_tty_set(port, NULL);
910
911 if (port->blocked_open) {
912 if (portp->close_delay)
913 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
914 wake_up_interruptible(&port->open_wait);
915 }
916
917 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
918 wake_up_interruptible(&port->close_wait);
919} 899}
920 900
921/*****************************************************************************/ 901/*****************************************************************************/
@@ -1482,7 +1462,7 @@ static int stli_getserial(struct stliport *portp, struct serial_struct __user *s
1482 sio.irq = 0; 1462 sio.irq = 0;
1483 sio.flags = portp->port.flags; 1463 sio.flags = portp->port.flags;
1484 sio.baud_base = portp->baud_base; 1464 sio.baud_base = portp->baud_base;
1485 sio.close_delay = portp->close_delay; 1465 sio.close_delay = portp->port.close_delay;
1486 sio.closing_wait = portp->closing_wait; 1466 sio.closing_wait = portp->closing_wait;
1487 sio.custom_divisor = portp->custom_divisor; 1467 sio.custom_divisor = portp->custom_divisor;
1488 sio.xmit_fifo_size = 0; 1468 sio.xmit_fifo_size = 0;
@@ -1514,7 +1494,7 @@ static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *s
1514 return -EFAULT; 1494 return -EFAULT;
1515 if (!capable(CAP_SYS_ADMIN)) { 1495 if (!capable(CAP_SYS_ADMIN)) {
1516 if ((sio.baud_base != portp->baud_base) || 1496 if ((sio.baud_base != portp->baud_base) ||
1517 (sio.close_delay != portp->close_delay) || 1497 (sio.close_delay != portp->port.close_delay) ||
1518 ((sio.flags & ~ASYNC_USR_MASK) != 1498 ((sio.flags & ~ASYNC_USR_MASK) !=
1519 (portp->port.flags & ~ASYNC_USR_MASK))) 1499 (portp->port.flags & ~ASYNC_USR_MASK)))
1520 return -EPERM; 1500 return -EPERM;
@@ -1523,7 +1503,7 @@ static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *s
1523 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) | 1503 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
1524 (sio.flags & ASYNC_USR_MASK); 1504 (sio.flags & ASYNC_USR_MASK);
1525 portp->baud_base = sio.baud_base; 1505 portp->baud_base = sio.baud_base;
1526 portp->close_delay = sio.close_delay; 1506 portp->port.close_delay = sio.close_delay;
1527 portp->closing_wait = sio.closing_wait; 1507 portp->closing_wait = sio.closing_wait;
1528 portp->custom_divisor = sio.custom_divisor; 1508 portp->custom_divisor = sio.custom_divisor;
1529 1509
@@ -2065,7 +2045,7 @@ static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigne
2065 unsigned char __iomem *bits; 2045 unsigned char __iomem *bits;
2066 2046
2067 if (test_bit(ST_CMDING, &portp->state)) { 2047 if (test_bit(ST_CMDING, &portp->state)) {
2068 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n", 2048 printk(KERN_ERR "istallion: command already busy, cmd=%x!\n",
2069 (int) cmd); 2049 (int) cmd);
2070 return; 2050 return;
2071 } 2051 }
@@ -2625,7 +2605,7 @@ static int stli_initports(struct stlibrd *brdp)
2625 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { 2605 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2626 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL); 2606 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
2627 if (!portp) { 2607 if (!portp) {
2628 printk("STALLION: failed to allocate port structure\n"); 2608 printk(KERN_WARNING "istallion: failed to allocate port structure\n");
2629 continue; 2609 continue;
2630 } 2610 }
2631 tty_port_init(&portp->port); 2611 tty_port_init(&portp->port);
@@ -2635,7 +2615,7 @@ static int stli_initports(struct stlibrd *brdp)
2635 portp->brdnr = brdp->brdnr; 2615 portp->brdnr = brdp->brdnr;
2636 portp->panelnr = panelnr; 2616 portp->panelnr = panelnr;
2637 portp->baud_base = STL_BAUDBASE; 2617 portp->baud_base = STL_BAUDBASE;
2638 portp->close_delay = STL_CLOSEDELAY; 2618 portp->port.close_delay = STL_CLOSEDELAY;
2639 portp->closing_wait = 30 * HZ; 2619 portp->closing_wait = 30 * HZ;
2640 init_waitqueue_head(&portp->port.open_wait); 2620 init_waitqueue_head(&portp->port.open_wait);
2641 init_waitqueue_head(&portp->port.close_wait); 2621 init_waitqueue_head(&portp->port.close_wait);
@@ -2692,7 +2672,7 @@ static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offse
2692 unsigned char val; 2672 unsigned char val;
2693 2673
2694 if (offset > brdp->memsize) { 2674 if (offset > brdp->memsize) {
2695 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2675 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2696 "range at line=%d(%d), brd=%d\n", 2676 "range at line=%d(%d), brd=%d\n",
2697 (int) offset, line, __LINE__, brdp->brdnr); 2677 (int) offset, line, __LINE__, brdp->brdnr);
2698 ptr = NULL; 2678 ptr = NULL;
@@ -2766,7 +2746,7 @@ static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long off
2766 unsigned char val; 2746 unsigned char val;
2767 2747
2768 if (offset > brdp->memsize) { 2748 if (offset > brdp->memsize) {
2769 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2749 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2770 "range at line=%d(%d), brd=%d\n", 2750 "range at line=%d(%d), brd=%d\n",
2771 (int) offset, line, __LINE__, brdp->brdnr); 2751 (int) offset, line, __LINE__, brdp->brdnr);
2772 ptr = NULL; 2752 ptr = NULL;
@@ -2818,7 +2798,7 @@ static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long off
2818 unsigned char val; 2798 unsigned char val;
2819 2799
2820 if (offset > brdp->memsize) { 2800 if (offset > brdp->memsize) {
2821 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2801 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2822 "range at line=%d(%d), brd=%d\n", 2802 "range at line=%d(%d), brd=%d\n",
2823 (int) offset, line, __LINE__, brdp->brdnr); 2803 (int) offset, line, __LINE__, brdp->brdnr);
2824 ptr = NULL; 2804 ptr = NULL;
@@ -2863,7 +2843,7 @@ static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long of
2863 unsigned char val; 2843 unsigned char val;
2864 2844
2865 if (offset > brdp->memsize) { 2845 if (offset > brdp->memsize) {
2866 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2846 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2867 "range at line=%d(%d), board=%d\n", 2847 "range at line=%d(%d), board=%d\n",
2868 (int) offset, line, __LINE__, brdp->brdnr); 2848 (int) offset, line, __LINE__, brdp->brdnr);
2869 ptr = NULL; 2849 ptr = NULL;
@@ -2928,7 +2908,7 @@ static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offse
2928 void __iomem *ptr; 2908 void __iomem *ptr;
2929 2909
2930 if (offset > brdp->memsize) { 2910 if (offset > brdp->memsize) {
2931 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2911 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2932 "range at line=%d(%d), brd=%d\n", 2912 "range at line=%d(%d), brd=%d\n",
2933 (int) offset, line, __LINE__, brdp->brdnr); 2913 (int) offset, line, __LINE__, brdp->brdnr);
2934 ptr = NULL; 2914 ptr = NULL;
@@ -2994,7 +2974,7 @@ static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offs
2994 unsigned char val; 2974 unsigned char val;
2995 2975
2996 if (offset > brdp->memsize) { 2976 if (offset > brdp->memsize) {
2997 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2977 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2998 "range at line=%d(%d), brd=%d\n", 2978 "range at line=%d(%d), brd=%d\n",
2999 (int) offset, line, __LINE__, brdp->brdnr); 2979 (int) offset, line, __LINE__, brdp->brdnr);
3000 ptr = NULL; 2980 ptr = NULL;
@@ -3433,7 +3413,7 @@ static int stli_startbrd(struct stlibrd *brdp)
3433#endif 3413#endif
3434 3414
3435 if (nrdevs < (brdp->nrports + 1)) { 3415 if (nrdevs < (brdp->nrports + 1)) {
3436 printk(KERN_ERR "STALLION: slave failed to allocate memory for " 3416 printk(KERN_ERR "istallion: slave failed to allocate memory for "
3437 "all devices, devices=%d\n", nrdevs); 3417 "all devices, devices=%d\n", nrdevs);
3438 brdp->nrports = nrdevs - 1; 3418 brdp->nrports = nrdevs - 1;
3439 } 3419 }
@@ -3443,13 +3423,13 @@ static int stli_startbrd(struct stlibrd *brdp)
3443 brdp->bitsize = (nrdevs + 7) / 8; 3423 brdp->bitsize = (nrdevs + 7) / 8;
3444 memoff = readl(&hdrp->memp); 3424 memoff = readl(&hdrp->memp);
3445 if (memoff > brdp->memsize) { 3425 if (memoff > brdp->memsize) {
3446 printk(KERN_ERR "STALLION: corrupted shared memory region?\n"); 3426 printk(KERN_ERR "istallion: corrupted shared memory region?\n");
3447 rc = -EIO; 3427 rc = -EIO;
3448 goto stli_donestartup; 3428 goto stli_donestartup;
3449 } 3429 }
3450 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff); 3430 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3451 if (readw(&memp->dtype) != TYP_ASYNCTRL) { 3431 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
3452 printk(KERN_ERR "STALLION: no slave control device found\n"); 3432 printk(KERN_ERR "istallion: no slave control device found\n");
3453 goto stli_donestartup; 3433 goto stli_donestartup;
3454 } 3434 }
3455 memp++; 3435 memp++;
@@ -3534,7 +3514,7 @@ static int __devinit stli_brdinit(struct stlibrd *brdp)
3534 retval = stli_initonb(brdp); 3514 retval = stli_initonb(brdp);
3535 break; 3515 break;
3536 default: 3516 default:
3537 printk(KERN_ERR "STALLION: board=%d is unknown board " 3517 printk(KERN_ERR "istallion: board=%d is unknown board "
3538 "type=%d\n", brdp->brdnr, brdp->brdtype); 3518 "type=%d\n", brdp->brdnr, brdp->brdtype);
3539 retval = -ENODEV; 3519 retval = -ENODEV;
3540 } 3520 }
@@ -3543,7 +3523,7 @@ static int __devinit stli_brdinit(struct stlibrd *brdp)
3543 return retval; 3523 return retval;
3544 3524
3545 stli_initports(brdp); 3525 stli_initports(brdp);
3546 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x " 3526 printk(KERN_INFO "istallion: %s found, board=%d io=%x mem=%x "
3547 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype], 3527 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3548 brdp->brdnr, brdp->iobase, (int) brdp->memaddr, 3528 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3549 brdp->nrpanels, brdp->nrports); 3529 brdp->nrpanels, brdp->nrports);
@@ -3637,7 +3617,7 @@ static int stli_eisamemprobe(struct stlibrd *brdp)
3637 if (! foundit) { 3617 if (! foundit) {
3638 brdp->memaddr = 0; 3618 brdp->memaddr = 0;
3639 brdp->membase = NULL; 3619 brdp->membase = NULL;
3640 printk(KERN_ERR "STALLION: failed to probe shared memory " 3620 printk(KERN_ERR "istallion: failed to probe shared memory "
3641 "region for %s in EISA slot=%d\n", 3621 "region for %s in EISA slot=%d\n",
3642 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12)); 3622 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3643 return -ENODEV; 3623 return -ENODEV;
@@ -3782,7 +3762,7 @@ static int __devinit stli_pciprobe(struct pci_dev *pdev,
3782 mutex_lock(&stli_brdslock); 3762 mutex_lock(&stli_brdslock);
3783 brdnr = stli_getbrdnr(); 3763 brdnr = stli_getbrdnr();
3784 if (brdnr < 0) { 3764 if (brdnr < 0) {
3785 printk(KERN_INFO "STALLION: too many boards found, " 3765 printk(KERN_INFO "istallion: too many boards found, "
3786 "maximum supported %d\n", STL_MAXBRDS); 3766 "maximum supported %d\n", STL_MAXBRDS);
3787 mutex_unlock(&stli_brdslock); 3767 mutex_unlock(&stli_brdslock);
3788 retval = -EIO; 3768 retval = -EIO;
@@ -3854,7 +3834,7 @@ static struct stlibrd *stli_allocbrd(void)
3854 3834
3855 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL); 3835 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
3856 if (!brdp) { 3836 if (!brdp) {
3857 printk(KERN_ERR "STALLION: failed to allocate memory " 3837 printk(KERN_ERR "istallion: failed to allocate memory "
3858 "(size=%Zd)\n", sizeof(struct stlibrd)); 3838 "(size=%Zd)\n", sizeof(struct stlibrd));
3859 return NULL; 3839 return NULL;
3860 } 3840 }
@@ -4493,7 +4473,7 @@ static int __init istallion_module_init(void)
4493 4473
4494 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); 4474 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4495 if (!stli_txcookbuf) { 4475 if (!stli_txcookbuf) {
4496 printk(KERN_ERR "STALLION: failed to allocate memory " 4476 printk(KERN_ERR "istallion: failed to allocate memory "
4497 "(size=%d)\n", STLI_TXBUFSIZE); 4477 "(size=%d)\n", STLI_TXBUFSIZE);
4498 retval = -ENOMEM; 4478 retval = -ENOMEM;
4499 goto err; 4479 goto err;
@@ -4518,7 +4498,7 @@ static int __init istallion_module_init(void)
4518 4498
4519 retval = tty_register_driver(stli_serial); 4499 retval = tty_register_driver(stli_serial);
4520 if (retval) { 4500 if (retval) {
4521 printk(KERN_ERR "STALLION: failed to register serial driver\n"); 4501 printk(KERN_ERR "istallion: failed to register serial driver\n");
4522 goto err_ttyput; 4502 goto err_ttyput;
4523 } 4503 }
4524 4504
@@ -4532,7 +4512,7 @@ static int __init istallion_module_init(void)
4532 */ 4512 */
4533 retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem); 4513 retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem);
4534 if (retval) { 4514 if (retval) {
4535 printk(KERN_ERR "STALLION: failed to register serial memory " 4515 printk(KERN_ERR "istallion: failed to register serial memory "
4536 "device\n"); 4516 "device\n");
4537 goto err_deinit; 4517 goto err_deinit;
4538 } 4518 }