[PATCH] char/isicom: Other little changes

Move some code from one place to another. Get rid of ugly ifdefs in code in
next p[patches, so here create functions and macros to enable it. Rename some
functions and align some code to 80 chars.

Signed-off-by: Jiri Slaby <xslaby@fi.muni.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Jiri Slaby and committed by
Linus Torvalds
aaa246ea 8070e35c

+80 -84
+80 -81
drivers/char/isicom.c
··· 135 135 136 136 #include <linux/isicom.h> 137 137 138 + #define InterruptTheCard(base) outw(0, (base) + 0xc) 139 + #define ClearInterrupt(base) inw((base) + 0x0a) 140 + 141 + #ifdef DEBUG 142 + #define pr_dbg(str...) printk(KERN_DEBUG "ISICOM: " str) 143 + #define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c)) 144 + #else 145 + #define pr_dbg(str...) do { } while (0) 146 + #define isicom_paranoia_check(a, b, c) 0 147 + #endif 148 + 138 149 static struct pci_device_id isicom_pci_tbl[] = { 139 150 { VENDOR_ID, 0x2028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 140 151 { VENDOR_ID, 0x2051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, ··· 172 161 static void isicom_start(struct tty_struct *tty); 173 162 174 163 static unsigned char *tmp_buf; 175 - static DECLARE_MUTEX(tmp_buf_sem); 176 164 177 165 /* baud index mappings from linux defns to isi */ 178 166 ··· 609 599 * 610 600 */ 611 601 612 - static inline int isicom_paranoia_check(struct isi_port const *port, char *name, 613 - const char *routine) 602 + static inline int __isicom_paranoia_check(struct isi_port const *port, 603 + char *name, const char *routine) 614 604 { 615 - #ifdef ISICOM_DEBUG 616 - static const char *badmagic = 617 - KERN_WARNING "ISICOM: Warning: bad isicom magic for dev %s in %s.\n"; 618 - static const char *badport = 619 - KERN_WARNING "ISICOM: Warning: NULL isicom port for dev %s in %s.\n"; 620 605 if (!port) { 621 - printk(badport, name, routine); 606 + printk(KERN_WARNING "ISICOM: Warning: bad isicom magic for " 607 + "dev %s in %s.\n", name, routine); 622 608 return 1; 623 609 } 624 610 if (port->magic != ISICOM_MAGIC) { 625 - printk(badmagic, name, routine); 611 + printk(KERN_WARNING "ISICOM: Warning: NULL isicom port for " 612 + "dev %s in %s.\n", name, routine); 626 613 return 1; 627 614 } 628 - #endif 615 + 629 616 return 0; 630 617 } 631 618 ··· 681 674 unlock_card(&isi_card[card]); 682 675 continue; 683 676 } 684 - #ifdef ISICOM_DEBUG 685 - printk(KERN_DEBUG "ISICOM: txing %d bytes, port%d.\n", 686 - txcount, port->channel+1); 687 - #endif 688 - outw((port->channel << isi_card[card].shift_count) | txcount 689 - , base); 677 + pr_dbg("txing %d bytes, port%d.\n", txcount, 678 + port->channel + 1); 679 + outw((port->channel << isi_card[card].shift_count) | txcount, 680 + base); 690 681 residue = NO; 691 682 wrd = 0; 692 683 while (1) { ··· 730 725 731 726 /* schedule another tx for hopefully in about 10ms */ 732 727 sched_again: 733 - if (!re_schedule) 734 - return; 728 + if (!re_schedule) { 729 + re_schedule = 2; 730 + return; 731 + } 732 + 735 733 init_timer(&tx); 736 734 tx.expires = jiffies + HZ/100; 737 735 tx.data = 0; ··· 838 830 if (port->status & ISI_DCD) { 839 831 if (!(header & ISI_DCD)) { 840 832 /* Carrier has been lost */ 841 - #ifdef ISICOM_DEBUG 842 - printk(KERN_DEBUG "ISICOM: interrupt: DCD->low.\n"); 843 - #endif 833 + pr_dbg("interrupt: DCD->low.\n"); 844 834 port->status &= ~ISI_DCD; 845 835 schedule_work(&port->hangup_tq); 846 836 } ··· 846 840 else { 847 841 if (header & ISI_DCD) { 848 842 /* Carrier has been detected */ 849 - #ifdef ISICOM_DEBUG 850 - printk(KERN_DEBUG "ISICOM: interrupt: DCD->high.\n"); 851 - #endif 843 + pr_dbg("interrupt: DCD->high.\n"); 852 844 port->status |= ISI_DCD; 853 845 wake_up_interruptible(&port->open_wait); 854 846 } ··· 903 899 break; 904 900 905 901 case 2: /* Statistics */ 906 - printk(KERN_DEBUG "ISICOM: isicom_interrupt: stats!!!.\n"); 902 + pr_dbg("isicom_interrupt: stats!!!.\n"); 907 903 break; 908 904 909 905 default: 910 - printk(KERN_WARNING "ISICOM: Intr: Unknown code in status packet.\n"); 906 + pr_dbg("Intr: Unknown code in status packet.\n"); 911 907 break; 912 908 } 913 909 } 914 910 else { /* Data Packet */ 915 911 916 912 count = tty_prepare_flip_string(tty, &rp, byte_count & ~1); 917 - #ifdef ISICOM_DEBUG 918 - printk(KERN_DEBUG "ISICOM: Intr: Can rx %d of %d bytes.\n", 919 - count, byte_count); 920 - #endif 913 + pr_dbg("Intr: Can rx %d of %d bytes.\n", count, byte_count); 921 914 word_count = count >> 1; 922 915 insw(base, rp, word_count); 923 916 byte_count -= (word_count << 1); ··· 923 922 byte_count -= 2; 924 923 } 925 924 if (byte_count > 0) { 926 - printk(KERN_DEBUG "ISICOM: Intr(0x%lx:%d): Flip buffer overflow! dropping bytes...\n", 927 - base, channel+1); 925 + pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping " 926 + "bytes...\n", base, channel + 1); 928 927 while(byte_count > 0) { /* drain out unread xtra data */ 929 928 inw(base); 930 929 byte_count -= 2; ··· 1117 1116 /* block if port is in the process of being closed */ 1118 1117 1119 1118 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 1120 - #ifdef ISICOM_DEBUG 1121 - printk(KERN_DEBUG "ISICOM: block_til_ready: close in progress.\n"); 1122 - #endif 1119 + pr_dbg("block_til_ready: close in progress.\n"); 1123 1120 interruptible_sleep_on(&port->close_wait); 1124 1121 if (port->flags & ASYNC_HUP_NOTIFY) 1125 1122 return -EAGAIN; ··· 1128 1129 /* if non-blocking mode is set ... */ 1129 1130 1130 1131 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { 1131 - #ifdef ISICOM_DEBUG 1132 - printk(KERN_DEBUG "ISICOM: block_til_ready: non-block mode.\n"); 1133 - #endif 1132 + pr_dbg("block_til_ready: non-block mode.\n"); 1134 1133 port->flags |= ASYNC_NORMAL_ACTIVE; 1135 1134 return 0; 1136 1135 } ··· 1268 1271 set_bit(TTY_IO_ERROR, &tty->flags); 1269 1272 1270 1273 if (--card->count < 0) { 1271 - printk(KERN_DEBUG "ISICOM: isicom_shutdown_port: bad board(0x%lx) count %d.\n", 1274 + pr_dbg("isicom_shutdown_port: bad board(0x%lx) count %d.\n", 1272 1275 card->base, card->count); 1273 1276 card->count = 0; 1274 1277 } ··· 1291 1294 if (isicom_paranoia_check(port, tty->name, "isicom_close")) 1292 1295 return; 1293 1296 1294 - #ifdef ISICOM_DEBUG 1295 - printk(KERN_DEBUG "ISICOM: Close start!!!.\n"); 1296 - #endif 1297 + pr_dbg("Close start!!!.\n"); 1297 1298 1298 1299 spin_lock_irqsave(&card->card_lock, flags); 1299 1300 if (tty_hung_up_p(filp)) { ··· 1342 1347 if (port->blocked_open) { 1343 1348 spin_unlock_irqrestore(&card->card_lock, flags); 1344 1349 if (port->close_delay) { 1345 - #ifdef ISICOM_DEBUG 1346 - printk(KERN_DEBUG "ISICOM: scheduling until time out.\n"); 1347 - #endif 1350 + pr_dbg("scheduling until time out.\n"); 1348 1351 msleep_interruptible(jiffies_to_msecs(port->close_delay)); 1349 1352 } 1350 1353 spin_lock_irqsave(&card->card_lock, flags); ··· 1779 1786 .tiocmset = isicom_tiocmset, 1780 1787 }; 1781 1788 1782 - static int __devinit register_drivers(void) 1789 + static int __devinit isicom_register_tty_driver(void) 1783 1790 { 1784 - int error; 1791 + int error = -ENOMEM; 1785 1792 1786 1793 /* tty driver structure initialization */ 1787 1794 isicom_normal = alloc_tty_driver(PORT_COUNT); 1788 1795 if (!isicom_normal) 1789 - return -ENOMEM; 1796 + goto end; 1790 1797 1791 - isicom_normal->owner = THIS_MODULE; 1792 - isicom_normal->name = "ttyM"; 1793 - isicom_normal->devfs_name = "isicom/"; 1794 - isicom_normal->major = ISICOM_NMAJOR; 1795 - isicom_normal->minor_start = 0; 1796 - isicom_normal->type = TTY_DRIVER_TYPE_SERIAL; 1797 - isicom_normal->subtype = SERIAL_TYPE_NORMAL; 1798 - isicom_normal->init_termios = tty_std_termios; 1799 - isicom_normal->init_termios.c_cflag = 1800 - B9600 | CS8 | CREAD | HUPCL |CLOCAL; 1801 - isicom_normal->flags = TTY_DRIVER_REAL_RAW; 1798 + isicom_normal->owner = THIS_MODULE; 1799 + isicom_normal->name = "ttyM"; 1800 + isicom_normal->devfs_name = "isicom/"; 1801 + isicom_normal->major = ISICOM_NMAJOR; 1802 + isicom_normal->minor_start = 0; 1803 + isicom_normal->type = TTY_DRIVER_TYPE_SERIAL; 1804 + isicom_normal->subtype = SERIAL_TYPE_NORMAL; 1805 + isicom_normal->init_termios = tty_std_termios; 1806 + isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | 1807 + CLOCAL; 1808 + isicom_normal->flags = TTY_DRIVER_REAL_RAW; 1802 1809 tty_set_operations(isicom_normal, &isicom_ops); 1803 1810 1804 - if ((error=tty_register_driver(isicom_normal))!=0) { 1805 - printk(KERN_DEBUG "ISICOM: Couldn't register the dialin driver, error=%d\n", 1811 + if ((error = tty_register_driver(isicom_normal))) { 1812 + pr_dbg("Couldn't register the dialin driver, error=%d\n", 1806 1813 error); 1807 1814 put_tty_driver(isicom_normal); 1808 - return error; 1809 1815 } 1810 - return 0; 1816 + end: 1817 + return error; 1811 1818 } 1812 1819 1813 - static void unregister_drivers(void) 1820 + static void isicom_unregister_tty_driver(void) 1814 1821 { 1815 - int error = tty_unregister_driver(isicom_normal); 1816 - if (error) 1817 - printk(KERN_DEBUG "ISICOM: couldn't unregister normal driver error=%d.\n",error); 1822 + int error; 1823 + 1824 + if ((error = tty_unregister_driver(isicom_normal))) 1825 + pr_dbg("couldn't unregister normal driver, error=%d.\n", error); 1826 + 1818 1827 put_tty_driver(isicom_normal); 1819 1828 } 1820 1829 ··· 1886 1891 free_page((unsigned long)tmp_buf); 1887 1892 return 0; 1888 1893 } 1889 - if (register_drivers()) 1894 + if (isicom_register_tty_driver()) 1890 1895 { 1891 1896 unregister_ioregion(); 1892 1897 free_page((unsigned long)tmp_buf); ··· 1894 1899 } 1895 1900 if (!register_isr()) 1896 1901 { 1897 - unregister_drivers(); 1902 + isicom_unregister_tty_driver(); 1898 1903 /* ioports already uregistered in register_isr */ 1899 1904 free_page((unsigned long)tmp_buf); 1900 1905 return 0; ··· 1930 1935 1931 1936 static int io[4]; 1932 1937 static int irq[4]; 1933 - 1934 - MODULE_AUTHOR("MultiTech"); 1935 - MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); 1936 - MODULE_LICENSE("GPL"); 1937 - module_param_array(io, int, NULL, 0); 1938 - MODULE_PARM_DESC(io, "I/O ports for the cards"); 1939 - module_param_array(irq, int, NULL, 0); 1940 - MODULE_PARM_DESC(irq, "Interrupts for the cards"); 1941 1938 1942 1939 static int __devinit isicom_setup(void) 1943 1940 { ··· 2034 2047 2035 2048 static void __exit isicom_exit(void) 2036 2049 { 2050 + unsigned int index = 0; 2051 + 2037 2052 re_schedule = 0; 2038 - /* FIXME */ 2039 - msleep(1000); 2053 + 2054 + while (re_schedule != 2 && index++ < 100) 2055 + msleep(10); 2056 + 2040 2057 unregister_isr(); 2041 - unregister_drivers(); 2058 + isicom_unregister_tty_driver(); 2042 2059 unregister_ioregion(); 2043 2060 if (tmp_buf) 2044 2061 free_page((unsigned long)tmp_buf); ··· 2052 2061 2053 2062 module_init(isicom_setup); 2054 2063 module_exit(isicom_exit); 2064 + 2065 + MODULE_AUTHOR("MultiTech"); 2066 + MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); 2067 + MODULE_LICENSE("GPL"); 2068 + module_param_array(io, int, NULL, 0); 2069 + MODULE_PARM_DESC(io, "I/O ports for the cards"); 2070 + module_param_array(irq, int, NULL, 0); 2071 + MODULE_PARM_DESC(irq, "Interrupts for the cards");
-3
include/linux/isicom.h
··· 98 98 #define ISICOM_INITIATE_XONXOFF 0x04 99 99 #define ISICOM_RESPOND_XONXOFF 0x08 100 100 101 - #define InterruptTheCard(base) (outw(0,(base)+0xc)) 102 - #define ClearInterrupt(base) (inw((base)+0x0a)) 103 - 104 101 #define BOARD(line) (((line) >> 4) & 0x3) 105 102 106 103 /* isi kill queue bitmap */