Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or |
| 3 | * modify it under the terms of the GNU General Public License |
| 4 | * as published by the Free Software Foundation; either version |
| 5 | * 2 of the License, or (at your option) any later version. |
| 6 | * |
| 7 | * Original driver code supplied by Multi-Tech |
| 8 | * |
| 9 | * Changes |
| 10 | * 1/9/98 alan@redhat.com Merge to 2.0.x kernel tree |
| 11 | * Obtain and use official major/minors |
| 12 | * Loader switched to a misc device |
| 13 | * (fixed range check bug as a side effect) |
| 14 | * Printk clean up |
| 15 | * 9/12/98 alan@redhat.com Rough port to 2.1.x |
| 16 | * |
| 17 | * 10/6/99 sameer Merged the ISA and PCI drivers to |
| 18 | * a new unified driver. |
| 19 | * |
| 20 | * 3/9/99 sameer Added support for ISI4616 cards. |
| 21 | * |
| 22 | * 16/9/99 sameer We do not force RTS low anymore. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 23 | * This is to prevent the firmware |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * from getting confused. |
| 25 | * |
| 26 | * 26/10/99 sameer Cosmetic changes:The driver now |
| 27 | * dumps the Port Count information |
| 28 | * along with I/O address and IRQ. |
| 29 | * |
| 30 | * 13/12/99 sameer Fixed the problem with IRQ sharing. |
| 31 | * |
| 32 | * 10/5/00 sameer Fixed isicom_shutdown_board() |
| 33 | * to not lower DTR on all the ports |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 34 | * when the last port on the card is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * closed. |
| 36 | * |
| 37 | * 10/5/00 sameer Signal mask setup command added |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 38 | * to isicom_setup_port and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * isicom_shutdown_port. |
| 40 | * |
| 41 | * 24/5/00 sameer The driver is now SMP aware. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 42 | * |
| 43 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * 27/11/00 Vinayak P Risbud Fixed the Driver Crash Problem |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 45 | * |
| 46 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * 03/01/01 anil .s Added support for resetting the |
| 48 | * internal modems on ISI cards. |
| 49 | * |
| 50 | * 08/02/01 anil .s Upgraded the driver for kernel |
| 51 | * 2.4.x |
| 52 | * |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 53 | * 11/04/01 Kevin Fixed firmware load problem with |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * ISIHP-4X card |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 55 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | * 30/04/01 anil .s Fixed the remote login through |
| 57 | * ISI port problem. Now the link |
| 58 | * does not go down before password |
| 59 | * prompt. |
| 60 | * |
| 61 | * 03/05/01 anil .s Fixed the problem with IRQ sharing |
| 62 | * among ISI-PCI cards. |
| 63 | * |
| 64 | * 03/05/01 anil .s Added support to display the version |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 65 | * info during insmod as well as module |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * listing by lsmod. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 67 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * 10/05/01 anil .s Done the modifications to the source |
| 69 | * file and Install script so that the |
| 70 | * same installation can be used for |
| 71 | * 2.2.x and 2.4.x kernel. |
| 72 | * |
| 73 | * 06/06/01 anil .s Now we drop both dtr and rts during |
| 74 | * shutdown_port as well as raise them |
| 75 | * during isicom_config_port. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 76 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * 09/06/01 acme@conectiva.com.br use capable, not suser, do |
| 78 | * restore_flags on failure in |
| 79 | * isicom_send_break, verify put_user |
| 80 | * result |
| 81 | * |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 82 | * 11/02/03 ranjeeth Added support for 230 Kbps and 460 Kbps |
| 83 | * Baud index extended to 21 |
| 84 | * |
| 85 | * 20/03/03 ranjeeth Made to work for Linux Advanced server. |
| 86 | * Taken care of license warning. |
| 87 | * |
| 88 | * 10/12/03 Ravindra Made to work for Fedora Core 1 of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | * Red Hat Distribution |
| 90 | * |
| 91 | * 06/01/05 Alan Cox Merged the ISI and base kernel strands |
| 92 | * into a single 2.6 driver |
| 93 | * |
| 94 | * *********************************************************** |
| 95 | * |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 96 | * To use this driver you also need the support package. You |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * can find this in RPM format on |
| 98 | * ftp://ftp.linux.org.uk/pub/linux/alan |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 99 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * You can find the original tools for this direct from Multitech |
| 101 | * ftp://ftp.multitech.com/ISI-Cards/ |
| 102 | * |
| 103 | * Having installed the cards the module options (/etc/modprobe.conf) |
| 104 | * |
| 105 | * options isicom io=card1,card2,card3,card4 irq=card1,card2,card3,card4 |
| 106 | * |
| 107 | * Omit those entries for boards you don't have installed. |
| 108 | * |
| 109 | * TODO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | * Merge testing |
| 111 | * 64-bit verification |
| 112 | */ |
| 113 | |
| 114 | #include <linux/module.h> |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame^] | 115 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #include <linux/kernel.h> |
| 117 | #include <linux/tty.h> |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 118 | #include <linux/tty_flip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | #include <linux/termios.h> |
| 120 | #include <linux/fs.h> |
| 121 | #include <linux/sched.h> |
| 122 | #include <linux/serial.h> |
| 123 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #include <linux/interrupt.h> |
| 125 | #include <linux/timer.h> |
| 126 | #include <linux/delay.h> |
| 127 | #include <linux/ioport.h> |
| 128 | |
| 129 | #include <asm/uaccess.h> |
| 130 | #include <asm/io.h> |
| 131 | #include <asm/system.h> |
| 132 | |
| 133 | #include <linux/pci.h> |
| 134 | |
| 135 | #include <linux/isicom.h> |
| 136 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 137 | #define InterruptTheCard(base) outw(0, (base) + 0xc) |
| 138 | #define ClearInterrupt(base) inw((base) + 0x0a) |
| 139 | |
| 140 | #ifdef DEBUG |
| 141 | #define pr_dbg(str...) printk(KERN_DEBUG "ISICOM: " str) |
| 142 | #define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c)) |
| 143 | #else |
| 144 | #define pr_dbg(str...) do { } while (0) |
| 145 | #define isicom_paranoia_check(a, b, c) 0 |
| 146 | #endif |
| 147 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 148 | static int isicom_probe(struct pci_dev *, const struct pci_device_id *); |
| 149 | static void __devexit isicom_remove(struct pci_dev *); |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | static struct pci_device_id isicom_pci_tbl[] = { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 152 | { PCI_DEVICE(VENDOR_ID, 0x2028) }, |
| 153 | { PCI_DEVICE(VENDOR_ID, 0x2051) }, |
| 154 | { PCI_DEVICE(VENDOR_ID, 0x2052) }, |
| 155 | { PCI_DEVICE(VENDOR_ID, 0x2053) }, |
| 156 | { PCI_DEVICE(VENDOR_ID, 0x2054) }, |
| 157 | { PCI_DEVICE(VENDOR_ID, 0x2055) }, |
| 158 | { PCI_DEVICE(VENDOR_ID, 0x2056) }, |
| 159 | { PCI_DEVICE(VENDOR_ID, 0x2057) }, |
| 160 | { PCI_DEVICE(VENDOR_ID, 0x2058) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { 0 } |
| 162 | }; |
| 163 | MODULE_DEVICE_TABLE(pci, isicom_pci_tbl); |
| 164 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 165 | static struct pci_driver isicom_driver = { |
| 166 | .name = "isicom", |
| 167 | .id_table = isicom_pci_tbl, |
| 168 | .probe = isicom_probe, |
| 169 | .remove = __devexit_p(isicom_remove) |
| 170 | }; |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | static int prev_card = 3; /* start servicing isi_card[0] */ |
| 173 | static struct tty_driver *isicom_normal; |
| 174 | |
| 175 | static struct timer_list tx; |
| 176 | static char re_schedule = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | static void isicom_tx(unsigned long _data); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 179 | static void isicom_start(struct tty_struct *tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* baud index mappings from linux defns to isi */ |
| 182 | |
| 183 | static signed char linuxb_to_isib[] = { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 184 | -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | struct isi_board { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 188 | unsigned long base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | unsigned char irq; |
| 190 | unsigned char port_count; |
| 191 | unsigned short status; |
| 192 | unsigned short port_status; /* each bit represents a single port */ |
| 193 | unsigned short shift_count; |
| 194 | struct isi_port * ports; |
| 195 | signed char count; |
| 196 | unsigned char isa; |
| 197 | spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */ |
| 198 | unsigned long flags; |
| 199 | }; |
| 200 | |
| 201 | struct isi_port { |
| 202 | unsigned short magic; |
| 203 | unsigned int flags; |
| 204 | int count; |
| 205 | int blocked_open; |
| 206 | int close_delay; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 207 | u16 channel; |
| 208 | u16 status; |
| 209 | u16 closing_wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | struct isi_board * card; |
| 211 | struct tty_struct * tty; |
| 212 | wait_queue_head_t close_wait; |
| 213 | wait_queue_head_t open_wait; |
| 214 | struct work_struct hangup_tq; |
| 215 | struct work_struct bh_tqueue; |
| 216 | unsigned char * xmit_buf; |
| 217 | int xmit_head; |
| 218 | int xmit_tail; |
| 219 | int xmit_cnt; |
| 220 | }; |
| 221 | |
| 222 | static struct isi_board isi_card[BOARD_COUNT]; |
| 223 | static struct isi_port isi_ports[PORT_COUNT]; |
| 224 | |
| 225 | /* |
| 226 | * Locking functions for card level locking. We need to own both |
| 227 | * the kernel lock for the card and have the card in a position that |
| 228 | * it wants to talk. |
| 229 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | static int lock_card(struct isi_board *card) |
| 232 | { |
| 233 | char retries; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 234 | unsigned long base = card->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | for (retries = 0; retries < 100; retries++) { |
| 237 | spin_lock_irqsave(&card->card_lock, card->flags); |
| 238 | if (inw(base + 0xe) & 0x1) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 239 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } else { |
| 241 | spin_unlock_irqrestore(&card->card_lock, card->flags); |
| 242 | udelay(1000); /* 1ms */ |
| 243 | } |
| 244 | } |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 245 | printk(KERN_WARNING "ISICOM: Failed to lock Card (0x%lx)\n", card->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | return 0; /* Failed to aquire the card! */ |
| 247 | } |
| 248 | |
| 249 | static int lock_card_at_interrupt(struct isi_board *card) |
| 250 | { |
| 251 | unsigned char retries; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 252 | unsigned long base = card->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | for (retries = 0; retries < 200; retries++) { |
| 255 | spin_lock_irqsave(&card->card_lock, card->flags); |
| 256 | |
| 257 | if (inw(base + 0xe) & 0x1) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 258 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | else |
| 260 | spin_unlock_irqrestore(&card->card_lock, card->flags); |
| 261 | } |
| 262 | /* Failing in interrupt is an acceptable event */ |
| 263 | return 0; /* Failed to aquire the card! */ |
| 264 | } |
| 265 | |
| 266 | static void unlock_card(struct isi_board *card) |
| 267 | { |
| 268 | spin_unlock_irqrestore(&card->card_lock, card->flags); |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * ISI Card specific ops ... |
| 273 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 274 | |
| 275 | static void raise_dtr(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 277 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 278 | unsigned long base = card->base; |
| 279 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | if (!lock_card(card)) |
| 282 | return; |
| 283 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 284 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | outw(0x0504, base); |
| 286 | InterruptTheCard(base); |
| 287 | port->status |= ISI_DTR; |
| 288 | unlock_card(card); |
| 289 | } |
| 290 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 291 | static inline void drop_dtr(struct isi_port *port) |
| 292 | { |
| 293 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 294 | unsigned long base = card->base; |
| 295 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | if (!lock_card(card)) |
| 298 | return; |
| 299 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 300 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | outw(0x0404, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 302 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | port->status &= ~ISI_DTR; |
| 304 | unlock_card(card); |
| 305 | } |
| 306 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 307 | static inline void raise_rts(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 309 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 310 | unsigned long base = card->base; |
| 311 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | if (!lock_card(card)) |
| 314 | return; |
| 315 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 316 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | outw(0x0a04, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 318 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | port->status |= ISI_RTS; |
| 320 | unlock_card(card); |
| 321 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 322 | static inline void drop_rts(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 324 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 325 | unsigned long base = card->base; |
| 326 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | if (!lock_card(card)) |
| 329 | return; |
| 330 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 331 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | outw(0x0804, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 333 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | port->status &= ~ISI_RTS; |
| 335 | unlock_card(card); |
| 336 | } |
| 337 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 338 | static inline void raise_dtr_rts(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 340 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 341 | unsigned long base = card->base; |
| 342 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | if (!lock_card(card)) |
| 345 | return; |
| 346 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 347 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | outw(0x0f04, base); |
| 349 | InterruptTheCard(base); |
| 350 | port->status |= (ISI_DTR | ISI_RTS); |
| 351 | unlock_card(card); |
| 352 | } |
| 353 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 354 | static void drop_dtr_rts(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 356 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 357 | unsigned long base = card->base; |
| 358 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | if (!lock_card(card)) |
| 361 | return; |
| 362 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 363 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | outw(0x0c04, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 365 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | port->status &= ~(ISI_RTS | ISI_DTR); |
| 367 | unlock_card(card); |
| 368 | } |
| 369 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 370 | static inline void kill_queue(struct isi_port *port, short queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 372 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 373 | unsigned long base = card->base; |
| 374 | u16 channel = port->channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | if (!lock_card(card)) |
| 377 | return; |
| 378 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 379 | outw(0x8000 | (channel << card->shift_count) | 0x02, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | outw((queue << 8) | 0x06, base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 381 | InterruptTheCard(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | unlock_card(card); |
| 383 | } |
| 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* |
| 386 | * ISICOM Driver specific routines ... |
| 387 | * |
| 388 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 389 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 390 | static inline int __isicom_paranoia_check(struct isi_port const *port, |
| 391 | char *name, const char *routine) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | if (!port) { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 394 | printk(KERN_WARNING "ISICOM: Warning: bad isicom magic for " |
| 395 | "dev %s in %s.\n", name, routine); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | return 1; |
| 397 | } |
| 398 | if (port->magic != ISICOM_MAGIC) { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 399 | printk(KERN_WARNING "ISICOM: Warning: NULL isicom port for " |
| 400 | "dev %s in %s.\n", name, routine); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | return 1; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 402 | } |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | return 0; |
| 405 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | /* |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 408 | * Transmitter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | * |
| 410 | * We shovel data into the card buffers on a regular basis. The card |
| 411 | * will do the rest of the work for us. |
| 412 | */ |
| 413 | |
| 414 | static void isicom_tx(unsigned long _data) |
| 415 | { |
| 416 | short count = (BOARD_COUNT-1), card, base; |
| 417 | short txcount, wrd, residue, word_count, cnt; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 418 | struct isi_port *port; |
| 419 | struct tty_struct *tty; |
| 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* find next active board */ |
| 422 | card = (prev_card + 1) & 0x0003; |
| 423 | while(count-- > 0) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 424 | if (isi_card[card].status & BOARD_ACTIVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | break; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 426 | card = (card + 1) & 0x0003; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | if (!(isi_card[card].status & BOARD_ACTIVE)) |
| 429 | goto sched_again; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | prev_card = card; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | count = isi_card[card].port_count; |
| 434 | port = isi_card[card].ports; |
| 435 | base = isi_card[card].base; |
| 436 | for (;count > 0;count--, port++) { |
| 437 | if (!lock_card_at_interrupt(&isi_card[card])) |
| 438 | continue; |
| 439 | /* port not active or tx disabled to force flow control */ |
| 440 | if (!(port->flags & ASYNC_INITIALIZED) || |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 441 | !(port->status & ISI_TXOK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | unlock_card(&isi_card[card]); |
| 443 | continue; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | tty = port->tty; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 446 | |
| 447 | |
| 448 | if (tty == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | unlock_card(&isi_card[card]); |
| 450 | continue; |
| 451 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | txcount = min_t(short, TX_SIZE, port->xmit_cnt); |
| 454 | if (txcount <= 0 || tty->stopped || tty->hw_stopped) { |
| 455 | unlock_card(&isi_card[card]); |
| 456 | continue; |
| 457 | } |
| 458 | if (!(inw(base + 0x02) & (1 << port->channel))) { |
| 459 | unlock_card(&isi_card[card]); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 460 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 462 | pr_dbg("txing %d bytes, port%d.\n", txcount, |
| 463 | port->channel + 1); |
| 464 | outw((port->channel << isi_card[card].shift_count) | txcount, |
| 465 | base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | residue = NO; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 467 | wrd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | while (1) { |
| 469 | cnt = min_t(int, txcount, (SERIAL_XMIT_SIZE - port->xmit_tail)); |
| 470 | if (residue == YES) { |
| 471 | residue = NO; |
| 472 | if (cnt > 0) { |
| 473 | wrd |= (port->xmit_buf[port->xmit_tail] << 8); |
| 474 | port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1); |
| 475 | port->xmit_cnt--; |
| 476 | txcount--; |
| 477 | cnt--; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 478 | outw(wrd, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
| 480 | else { |
| 481 | outw(wrd, base); |
| 482 | break; |
| 483 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 484 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | if (cnt <= 0) break; |
| 486 | word_count = cnt >> 1; |
| 487 | outsw(base, port->xmit_buf+port->xmit_tail, word_count); |
| 488 | port->xmit_tail = (port->xmit_tail + (word_count << 1)) & |
| 489 | (SERIAL_XMIT_SIZE - 1); |
| 490 | txcount -= (word_count << 1); |
| 491 | port->xmit_cnt -= (word_count << 1); |
| 492 | if (cnt & 0x0001) { |
| 493 | residue = YES; |
| 494 | wrd = port->xmit_buf[port->xmit_tail]; |
| 495 | port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1); |
| 496 | port->xmit_cnt--; |
| 497 | txcount--; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | InterruptTheCard(base); |
| 502 | if (port->xmit_cnt <= 0) |
| 503 | port->status &= ~ISI_TXOK; |
| 504 | if (port->xmit_cnt <= WAKEUP_CHARS) |
| 505 | schedule_work(&port->bh_tqueue); |
| 506 | unlock_card(&isi_card[card]); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 509 | /* schedule another tx for hopefully in about 10ms */ |
| 510 | sched_again: |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 511 | if (!re_schedule) { |
| 512 | re_schedule = 2; |
| 513 | return; |
| 514 | } |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | init_timer(&tx); |
| 517 | tx.expires = jiffies + HZ/100; |
| 518 | tx.data = 0; |
| 519 | tx.function = isicom_tx; |
| 520 | add_timer(&tx); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 521 | |
| 522 | return; |
| 523 | } |
| 524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | /* Interrupt handlers */ |
| 526 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 527 | |
| 528 | static void isicom_bottomhalf(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 530 | struct isi_port *port = (struct isi_port *) data; |
| 531 | struct tty_struct *tty = port->tty; |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | if (!tty) |
| 534 | return; |
| 535 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 536 | tty_wakeup(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | wake_up_interruptible(&tty->write_wait); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | /* |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 541 | * Main interrupt handler routine |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 543 | |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 544 | static irqreturn_t isicom_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 546 | struct isi_board *card = dev_id; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 547 | struct isi_port *port; |
| 548 | struct tty_struct *tty; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 549 | unsigned long base; |
| 550 | u16 header, word_count, count, channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | short byte_count; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 552 | unsigned char *rp; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | if (!card || !(card->status & FIRMWARE_LOADED)) |
| 555 | return IRQ_NONE; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | base = card->base; |
| 558 | spin_lock(&card->card_lock); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | if (card->isa == NO) { |
| 561 | /* |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 562 | * disable any interrupts from the PCI card and lower the |
| 563 | * interrupt line |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | */ |
| 565 | outw(0x8000, base+0x04); |
| 566 | ClearInterrupt(base); |
| 567 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | inw(base); /* get the dummy word out */ |
| 570 | header = inw(base); |
| 571 | channel = (header & 0x7800) >> card->shift_count; |
| 572 | byte_count = header & 0xff; |
| 573 | |
| 574 | if (channel + 1 > card->port_count) { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 575 | printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): %d(channel) > port_count.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | base, channel+1); |
| 577 | if (card->isa) |
| 578 | ClearInterrupt(base); |
| 579 | else |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 580 | outw(0x0000, base+0x04); /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | spin_unlock(&card->card_lock); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 582 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | port = card->ports + channel; |
| 585 | if (!(port->flags & ASYNC_INITIALIZED)) { |
| 586 | if (card->isa) |
| 587 | ClearInterrupt(base); |
| 588 | else |
| 589 | outw(0x0000, base+0x04); /* enable interrupts */ |
| 590 | return IRQ_HANDLED; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | tty = port->tty; |
| 594 | if (tty == NULL) { |
| 595 | word_count = byte_count >> 1; |
| 596 | while(byte_count > 1) { |
| 597 | inw(base); |
| 598 | byte_count -= 2; |
| 599 | } |
| 600 | if (byte_count & 0x01) |
| 601 | inw(base); |
| 602 | if (card->isa == YES) |
| 603 | ClearInterrupt(base); |
| 604 | else |
| 605 | outw(0x0000, base+0x04); /* enable interrupts */ |
| 606 | spin_unlock(&card->card_lock); |
| 607 | return IRQ_HANDLED; |
| 608 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | if (header & 0x8000) { /* Status Packet */ |
| 611 | header = inw(base); |
| 612 | switch(header & 0xff) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 613 | case 0: /* Change in EIA signals */ |
| 614 | |
| 615 | if (port->flags & ASYNC_CHECK_CD) { |
| 616 | if (port->status & ISI_DCD) { |
| 617 | if (!(header & ISI_DCD)) { |
| 618 | /* Carrier has been lost */ |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 619 | pr_dbg("interrupt: DCD->low.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | port->status &= ~ISI_DCD; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 621 | schedule_work(&port->hangup_tq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | else { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 625 | if (header & ISI_DCD) { |
| 626 | /* Carrier has been detected */ |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 627 | pr_dbg("interrupt: DCD->high.\n"); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 628 | port->status |= ISI_DCD; |
| 629 | wake_up_interruptible(&port->open_wait); |
| 630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 632 | } |
| 633 | else { |
| 634 | if (header & ISI_DCD) |
| 635 | port->status |= ISI_DCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | else |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 637 | port->status &= ~ISI_DCD; |
| 638 | } |
| 639 | |
| 640 | if (port->flags & ASYNC_CTS_FLOW) { |
| 641 | if (port->tty->hw_stopped) { |
| 642 | if (header & ISI_CTS) { |
| 643 | port->tty->hw_stopped = 0; |
| 644 | /* start tx ing */ |
| 645 | port->status |= (ISI_TXOK | ISI_CTS); |
| 646 | schedule_work(&port->bh_tqueue); |
| 647 | } |
| 648 | } |
| 649 | else { |
| 650 | if (!(header & ISI_CTS)) { |
| 651 | port->tty->hw_stopped = 1; |
| 652 | /* stop tx ing */ |
| 653 | port->status &= ~(ISI_TXOK | ISI_CTS); |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | else { |
| 658 | if (header & ISI_CTS) |
| 659 | port->status |= ISI_CTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | else |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 661 | port->status &= ~ISI_CTS; |
| 662 | } |
| 663 | |
| 664 | if (header & ISI_DSR) |
| 665 | port->status |= ISI_DSR; |
| 666 | else |
| 667 | port->status &= ~ISI_DSR; |
| 668 | |
| 669 | if (header & ISI_RI) |
| 670 | port->status |= ISI_RI; |
| 671 | else |
| 672 | port->status &= ~ISI_RI; |
| 673 | |
| 674 | break; |
| 675 | |
| 676 | case 1: /* Received Break !!! */ |
| 677 | tty_insert_flip_char(tty, 0, TTY_BREAK); |
| 678 | if (port->flags & ASYNC_SAK) |
| 679 | do_SAK(tty); |
| 680 | tty_flip_buffer_push(tty); |
| 681 | break; |
| 682 | |
| 683 | case 2: /* Statistics */ |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 684 | pr_dbg("isicom_interrupt: stats!!!.\n"); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 685 | break; |
| 686 | |
| 687 | default: |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 688 | pr_dbg("Intr: Unknown code in status packet.\n"); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 689 | break; |
| 690 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | else { /* Data Packet */ |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 693 | |
| 694 | count = tty_prepare_flip_string(tty, &rp, byte_count & ~1); |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 695 | pr_dbg("Intr: Can rx %d of %d bytes.\n", count, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | word_count = count >> 1; |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 697 | insw(base, rp, word_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | byte_count -= (word_count << 1); |
| 699 | if (count & 0x0001) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 700 | tty_insert_flip_char(tty, inw(base) & 0xff, TTY_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | byte_count -= 2; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | if (byte_count > 0) { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 704 | pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping " |
| 705 | "bytes...\n", base, channel + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | while(byte_count > 0) { /* drain out unread xtra data */ |
| 707 | inw(base); |
| 708 | byte_count -= 2; |
| 709 | } |
| 710 | } |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 711 | tty_flip_buffer_push(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | if (card->isa == YES) |
| 714 | ClearInterrupt(base); |
| 715 | else |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 716 | outw(0x0000, base+0x04); /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | return IRQ_HANDLED; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 718 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 720 | static void isicom_config_port(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 722 | struct isi_board *card = port->card; |
| 723 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | unsigned long baud; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 725 | unsigned long base = card->base; |
| 726 | u16 channel_setup, channel = port->channel, |
| 727 | shift_count = card->shift_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | unsigned char flow_ctrl; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | if (!(tty = port->tty) || !tty->termios) |
| 731 | return; |
| 732 | baud = C_BAUD(tty); |
| 733 | if (baud & CBAUDEX) { |
| 734 | baud &= ~CBAUDEX; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | /* if CBAUDEX bit is on and the baud is set to either 50 or 75 |
| 737 | * then the card is programmed for 57.6Kbps or 115Kbps |
| 738 | * respectively. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 739 | */ |
| 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | if (baud < 1 || baud > 2) |
| 742 | port->tty->termios->c_cflag &= ~CBAUDEX; |
| 743 | else |
| 744 | baud += 15; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | if (baud == 15) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 747 | |
| 748 | /* the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | * by the set_serial_info ioctl ... this is done by |
| 750 | * the 'setserial' utility. |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 751 | */ |
| 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 754 | baud++; /* 57.6 Kbps */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 756 | baud +=2; /* 115 Kbps */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | if (linuxb_to_isib[baud] == -1) { |
| 759 | /* hang up */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 760 | drop_dtr(port); |
| 761 | return; |
| 762 | } |
| 763 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | raise_dtr(port); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | if (lock_card(card)) { |
| 767 | outw(0x8000 | (channel << shift_count) |0x03, base); |
| 768 | outw(linuxb_to_isib[baud] << 8 | 0x03, base); |
| 769 | channel_setup = 0; |
| 770 | switch(C_CSIZE(tty)) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 771 | case CS5: |
| 772 | channel_setup |= ISICOM_CS5; |
| 773 | break; |
| 774 | case CS6: |
| 775 | channel_setup |= ISICOM_CS6; |
| 776 | break; |
| 777 | case CS7: |
| 778 | channel_setup |= ISICOM_CS7; |
| 779 | break; |
| 780 | case CS8: |
| 781 | channel_setup |= ISICOM_CS8; |
| 782 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | if (C_CSTOPB(tty)) |
| 786 | channel_setup |= ISICOM_2SB; |
| 787 | if (C_PARENB(tty)) { |
| 788 | channel_setup |= ISICOM_EVPAR; |
| 789 | if (C_PARODD(tty)) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 790 | channel_setup |= ISICOM_ODPAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 792 | outw(channel_setup, base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | InterruptTheCard(base); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 794 | unlock_card(card); |
| 795 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | if (C_CLOCAL(tty)) |
| 797 | port->flags &= ~ASYNC_CHECK_CD; |
| 798 | else |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 799 | port->flags |= ASYNC_CHECK_CD; |
| 800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | /* flow control settings ...*/ |
| 802 | flow_ctrl = 0; |
| 803 | port->flags &= ~ASYNC_CTS_FLOW; |
| 804 | if (C_CRTSCTS(tty)) { |
| 805 | port->flags |= ASYNC_CTS_FLOW; |
| 806 | flow_ctrl |= ISICOM_CTSRTS; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 807 | } |
| 808 | if (I_IXON(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | flow_ctrl |= ISICOM_RESPOND_XONXOFF; |
| 810 | if (I_IXOFF(tty)) |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 811 | flow_ctrl |= ISICOM_INITIATE_XONXOFF; |
| 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | if (lock_card(card)) { |
| 814 | outw(0x8000 | (channel << shift_count) |0x04, base); |
| 815 | outw(flow_ctrl << 8 | 0x05, base); |
| 816 | outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base); |
| 817 | InterruptTheCard(base); |
| 818 | unlock_card(card); |
| 819 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | /* rx enabled -> enable port for rx on the card */ |
| 822 | if (C_CREAD(tty)) { |
| 823 | card->port_status |= (1 << channel); |
| 824 | outw(card->port_status, base + 0x02); |
| 825 | } |
| 826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 828 | /* open et all */ |
| 829 | |
| 830 | static inline void isicom_setup_board(struct isi_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | { |
| 832 | int channel; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 833 | struct isi_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | spin_lock_irqsave(&bp->card_lock, flags); |
| 837 | if (bp->status & BOARD_ACTIVE) { |
| 838 | spin_unlock_irqrestore(&bp->card_lock, flags); |
| 839 | return; |
| 840 | } |
| 841 | port = bp->ports; |
| 842 | bp->status |= BOARD_ACTIVE; |
| 843 | spin_unlock_irqrestore(&bp->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 844 | for (channel = 0; channel < bp->port_count; channel++, port++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | drop_dtr_rts(port); |
| 846 | return; |
| 847 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 848 | |
| 849 | static int isicom_setup_port(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 851 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | if (port->flags & ASYNC_INITIALIZED) { |
| 855 | return 0; |
| 856 | } |
| 857 | if (!port->xmit_buf) { |
| 858 | unsigned long page; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | if (!(page = get_zeroed_page(GFP_KERNEL))) |
| 861 | return -ENOMEM; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | if (port->xmit_buf) { |
| 864 | free_page(page); |
| 865 | return -ERESTARTSYS; |
| 866 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 867 | port->xmit_buf = (unsigned char *) page; |
| 868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | spin_lock_irqsave(&card->card_lock, flags); |
| 871 | if (port->tty) |
| 872 | clear_bit(TTY_IO_ERROR, &port->tty->flags); |
| 873 | if (port->count == 1) |
| 874 | card->count++; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | /* discard any residual data */ |
| 879 | kill_queue(port, ISICOM_KILLTX | ISICOM_KILLRX); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | isicom_config_port(port); |
| 882 | port->flags |= ASYNC_INITIALIZED; |
| 883 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | static int block_til_ready(struct tty_struct *tty, struct file *filp, struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 890 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | int do_clocal = 0, retval; |
| 892 | unsigned long flags; |
| 893 | DECLARE_WAITQUEUE(wait, current); |
| 894 | |
| 895 | /* block if port is in the process of being closed */ |
| 896 | |
| 897 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 898 | pr_dbg("block_til_ready: close in progress.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | interruptible_sleep_on(&port->close_wait); |
| 900 | if (port->flags & ASYNC_HUP_NOTIFY) |
| 901 | return -EAGAIN; |
| 902 | else |
| 903 | return -ERESTARTSYS; |
| 904 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | /* if non-blocking mode is set ... */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 909 | pr_dbg("block_til_ready: non-block mode.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | port->flags |= ASYNC_NORMAL_ACTIVE; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | if (C_CLOCAL(tty)) |
| 915 | do_clocal = 1; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 916 | |
| 917 | /* block waiting for DCD to be asserted, and while |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | callout dev is busy */ |
| 919 | retval = 0; |
| 920 | add_wait_queue(&port->open_wait, &wait); |
| 921 | |
| 922 | spin_lock_irqsave(&card->card_lock, flags); |
| 923 | if (!tty_hung_up_p(filp)) |
| 924 | port->count--; |
| 925 | port->blocked_open++; |
| 926 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | while (1) { |
| 929 | raise_dtr_rts(port); |
| 930 | |
| 931 | set_current_state(TASK_INTERRUPTIBLE); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 932 | if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | if (port->flags & ASYNC_HUP_NOTIFY) |
| 934 | retval = -EAGAIN; |
| 935 | else |
| 936 | retval = -ERESTARTSYS; |
| 937 | break; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | if (!(port->flags & ASYNC_CLOSING) && |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 940 | (do_clocal || (port->status & ISI_DCD))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | break; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 942 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | if (signal_pending(current)) { |
| 944 | retval = -ERESTARTSYS; |
| 945 | break; |
| 946 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 947 | schedule(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | } |
| 949 | set_current_state(TASK_RUNNING); |
| 950 | remove_wait_queue(&port->open_wait, &wait); |
| 951 | spin_lock_irqsave(&card->card_lock, flags); |
| 952 | if (!tty_hung_up_p(filp)) |
| 953 | port->count++; |
| 954 | port->blocked_open--; |
| 955 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 956 | if (retval) |
| 957 | return retval; |
| 958 | port->flags |= ASYNC_NORMAL_ACTIVE; |
| 959 | return 0; |
| 960 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 961 | |
| 962 | static int isicom_open(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 964 | struct isi_port *port; |
| 965 | struct isi_board *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | unsigned int line, board; |
| 967 | int error; |
| 968 | |
| 969 | line = tty->index; |
| 970 | if (line < 0 || line > PORT_COUNT-1) |
| 971 | return -ENODEV; |
| 972 | board = BOARD(line); |
| 973 | card = &isi_card[board]; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | if (!(card->status & FIRMWARE_LOADED)) |
| 976 | return -ENODEV; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | /* open on a port greater than the port count for the card !!! */ |
| 979 | if (line > ((board * 16) + card->port_count - 1)) |
| 980 | return -ENODEV; |
| 981 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 982 | port = &isi_ports[line]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | if (isicom_paranoia_check(port, tty->name, "isicom_open")) |
| 984 | return -ENODEV; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 985 | |
| 986 | isicom_setup_board(card); |
| 987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | port->count++; |
| 989 | tty->driver_data = port; |
| 990 | port->tty = tty; |
| 991 | if ((error = isicom_setup_port(port))!=0) |
| 992 | return error; |
| 993 | if ((error = block_til_ready(tty, filp, port))!=0) |
| 994 | return error; |
| 995 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 996 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | /* close et all */ |
| 1000 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1001 | static inline void isicom_shutdown_board(struct isi_board *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
| 1003 | unsigned long flags; |
| 1004 | |
| 1005 | spin_lock_irqsave(&bp->card_lock, flags); |
| 1006 | if (bp->status & BOARD_ACTIVE) { |
| 1007 | bp->status &= ~BOARD_ACTIVE; |
| 1008 | } |
| 1009 | spin_unlock_irqrestore(&bp->card_lock, flags); |
| 1010 | } |
| 1011 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1012 | static void isicom_shutdown_port(struct isi_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1014 | struct isi_board *card = port->card; |
| 1015 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | tty = port->tty; |
| 1019 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1020 | spin_lock_irqsave(&card->card_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | if (!(port->flags & ASYNC_INITIALIZED)) { |
| 1022 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 1023 | return; |
| 1024 | } |
| 1025 | if (port->xmit_buf) { |
| 1026 | free_page((unsigned long) port->xmit_buf); |
| 1027 | port->xmit_buf = NULL; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | port->flags &= ~ASYNC_INITIALIZED; |
| 1030 | /* 3rd October 2000 : Vinayak P Risbud */ |
| 1031 | port->tty = NULL; |
| 1032 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | /*Fix done by Anil .S on 30-04-2001 |
| 1035 | remote login through isi port has dtr toggle problem |
| 1036 | due to which the carrier drops before the password prompt |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1037 | appears on the remote end. Now we drop the dtr only if the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | HUPCL(Hangup on close) flag is set for the tty*/ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1039 | |
| 1040 | if (C_HUPCL(tty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | /* drop dtr on this port */ |
| 1042 | drop_dtr(port); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1043 | |
| 1044 | /* any other port uninits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | if (tty) |
| 1046 | set_bit(TTY_IO_ERROR, &tty->flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | if (--card->count < 0) { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1049 | pr_dbg("isicom_shutdown_port: bad board(0x%lx) count %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | card->base, card->count); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1051 | card->count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | /* last port was closed , shutdown that boad too */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1055 | if (C_HUPCL(tty)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | if (!card->count) |
| 1057 | isicom_shutdown_board(card); |
| 1058 | } |
| 1059 | } |
| 1060 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1061 | static void isicom_close(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1063 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1064 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | if (!port) |
| 1068 | return; |
| 1069 | if (isicom_paranoia_check(port, tty->name, "isicom_close")) |
| 1070 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1071 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1072 | pr_dbg("Close start!!!.\n"); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | spin_lock_irqsave(&card->card_lock, flags); |
| 1075 | if (tty_hung_up_p(filp)) { |
| 1076 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 1077 | return; |
| 1078 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | if (tty->count == 1 && port->count != 1) { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1081 | printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port count" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | "tty->count = 1 port count = %d.\n", |
| 1083 | card->base, port->count); |
| 1084 | port->count = 1; |
| 1085 | } |
| 1086 | if (--port->count < 0) { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1087 | printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port count for" |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1088 | "channel%d = %d", card->base, port->channel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | port->count); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1090 | port->count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | if (port->count) { |
| 1094 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 1095 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | port->flags |= ASYNC_CLOSING; |
| 1098 | tty->closing = 1; |
| 1099 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) |
| 1102 | tty_wait_until_sent(tty, port->closing_wait); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1103 | /* indicate to the card that no more data can be received |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | on this port */ |
| 1105 | spin_lock_irqsave(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1106 | if (port->flags & ASYNC_INITIALIZED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | card->port_status &= ~(1 << port->channel); |
| 1108 | outw(card->port_status, card->base + 0x02); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | isicom_shutdown_port(port); |
| 1111 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | if (tty->driver->flush_buffer) |
| 1114 | tty->driver->flush_buffer(tty); |
| 1115 | tty_ldisc_flush(tty); |
| 1116 | |
| 1117 | spin_lock_irqsave(&card->card_lock, flags); |
| 1118 | tty->closing = 0; |
| 1119 | |
| 1120 | if (port->blocked_open) { |
| 1121 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 1122 | if (port->close_delay) { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1123 | pr_dbg("scheduling until time out.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | msleep_interruptible(jiffies_to_msecs(port->close_delay)); |
| 1125 | } |
| 1126 | spin_lock_irqsave(&card->card_lock, flags); |
| 1127 | wake_up_interruptible(&port->open_wait); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); |
| 1130 | wake_up_interruptible(&port->close_wait); |
| 1131 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 1132 | } |
| 1133 | |
| 1134 | /* write et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1135 | static int isicom_write(struct tty_struct *tty, const unsigned char *buf, |
| 1136 | int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1138 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1139 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | unsigned long flags; |
| 1141 | int cnt, total = 0; |
| 1142 | |
| 1143 | if (isicom_paranoia_check(port, tty->name, "isicom_write")) |
| 1144 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1145 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1146 | if (!tty || !port->xmit_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | spin_lock_irqsave(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1150 | |
| 1151 | while(1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1153 | SERIAL_XMIT_SIZE - port->xmit_head)); |
| 1154 | if (cnt <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | break; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | memcpy(port->xmit_buf + port->xmit_head, buf, cnt); |
| 1158 | port->xmit_head = (port->xmit_head + cnt) & (SERIAL_XMIT_SIZE - 1); |
| 1159 | port->xmit_cnt += cnt; |
| 1160 | buf += cnt; |
| 1161 | count -= cnt; |
| 1162 | total += cnt; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped) |
| 1165 | port->status |= ISI_TXOK; |
| 1166 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1167 | return total; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /* put_char et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1171 | static void isicom_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1173 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1174 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | if (isicom_paranoia_check(port, tty->name, "isicom_put_char")) |
| 1178 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | if (!tty || !port->xmit_buf) |
| 1181 | return; |
| 1182 | |
| 1183 | spin_lock_irqsave(&card->card_lock, flags); |
| 1184 | if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { |
| 1185 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 1186 | return; |
| 1187 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | port->xmit_buf[port->xmit_head++] = ch; |
| 1190 | port->xmit_head &= (SERIAL_XMIT_SIZE - 1); |
| 1191 | port->xmit_cnt++; |
| 1192 | spin_unlock_irqrestore(&card->card_lock, flags); |
| 1193 | } |
| 1194 | |
| 1195 | /* flush_chars et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1196 | static void isicom_flush_chars(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1198 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | if (isicom_paranoia_check(port, tty->name, "isicom_flush_chars")) |
| 1201 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || !port->xmit_buf) |
| 1204 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | /* this tells the transmitter to consider this port for |
| 1207 | data output to the card ... that's the best we can do. */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1208 | port->status |= ISI_TXOK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /* write_room et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1212 | static int isicom_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1214 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | int free; |
| 1216 | |
| 1217 | if (isicom_paranoia_check(port, tty->name, "isicom_write_room")) |
| 1218 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | free = SERIAL_XMIT_SIZE - port->xmit_cnt - 1; |
| 1221 | if (free < 0) |
| 1222 | free = 0; |
| 1223 | return free; |
| 1224 | } |
| 1225 | |
| 1226 | /* chars_in_buffer et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1227 | static int isicom_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1229 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | if (isicom_paranoia_check(port, tty->name, "isicom_chars_in_buffer")) |
| 1231 | return 0; |
| 1232 | return port->xmit_cnt; |
| 1233 | } |
| 1234 | |
| 1235 | /* ioctl et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1236 | static inline void isicom_send_break(struct isi_port *port, unsigned long length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1238 | struct isi_board *card = port->card; |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1239 | unsigned long base = card->base; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1240 | |
| 1241 | if (!lock_card(card)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base); |
| 1245 | outw((length & 0xff) << 8 | 0x00, base); |
| 1246 | outw((length & 0xff00), base); |
| 1247 | InterruptTheCard(base); |
| 1248 | |
| 1249 | unlock_card(card); |
| 1250 | } |
| 1251 | |
| 1252 | static int isicom_tiocmget(struct tty_struct *tty, struct file *file) |
| 1253 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1254 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | /* just send the port status */ |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1256 | u16 status = port->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
| 1258 | if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) |
| 1259 | return -ENODEV; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | return ((status & ISI_RTS) ? TIOCM_RTS : 0) | |
| 1262 | ((status & ISI_DTR) ? TIOCM_DTR : 0) | |
| 1263 | ((status & ISI_DCD) ? TIOCM_CAR : 0) | |
| 1264 | ((status & ISI_DSR) ? TIOCM_DSR : 0) | |
| 1265 | ((status & ISI_CTS) ? TIOCM_CTS : 0) | |
| 1266 | ((status & ISI_RI ) ? TIOCM_RI : 0); |
| 1267 | } |
| 1268 | |
| 1269 | static int isicom_tiocmset(struct tty_struct *tty, struct file *file, |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1270 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1272 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) |
| 1275 | return -ENODEV; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | if (set & TIOCM_RTS) |
| 1278 | raise_rts(port); |
| 1279 | if (set & TIOCM_DTR) |
| 1280 | raise_dtr(port); |
| 1281 | |
| 1282 | if (clear & TIOCM_RTS) |
| 1283 | drop_rts(port); |
| 1284 | if (clear & TIOCM_DTR) |
| 1285 | drop_dtr(port); |
| 1286 | |
| 1287 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1288 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1290 | static int isicom_set_serial_info(struct isi_port *port, |
| 1291 | struct serial_struct __user *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | { |
| 1293 | struct serial_struct newinfo; |
| 1294 | int reconfig_port; |
| 1295 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1296 | if (copy_from_user(&newinfo, info, sizeof(newinfo))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | return -EFAULT; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1298 | |
| 1299 | reconfig_port = ((port->flags & ASYNC_SPD_MASK) != |
| 1300 | (newinfo.flags & ASYNC_SPD_MASK)); |
| 1301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | if (!capable(CAP_SYS_ADMIN)) { |
| 1303 | if ((newinfo.close_delay != port->close_delay) || |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1304 | (newinfo.closing_wait != port->closing_wait) || |
| 1305 | ((newinfo.flags & ~ASYNC_USR_MASK) != |
| 1306 | (port->flags & ~ASYNC_USR_MASK))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | return -EPERM; |
| 1308 | port->flags = ((port->flags & ~ ASYNC_USR_MASK) | |
| 1309 | (newinfo.flags & ASYNC_USR_MASK)); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | else { |
| 1312 | port->close_delay = newinfo.close_delay; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1313 | port->closing_wait = newinfo.closing_wait; |
| 1314 | port->flags = ((port->flags & ~ASYNC_FLAGS) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | (newinfo.flags & ASYNC_FLAGS)); |
| 1316 | } |
| 1317 | if (reconfig_port) { |
| 1318 | isicom_config_port(port); |
| 1319 | } |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1323 | static int isicom_get_serial_info(struct isi_port *port, |
| 1324 | struct serial_struct __user *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | { |
| 1326 | struct serial_struct out_info; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | memset(&out_info, 0, sizeof(out_info)); |
| 1329 | /* out_info.type = ? */ |
| 1330 | out_info.line = port - isi_ports; |
| 1331 | out_info.port = port->card->base; |
| 1332 | out_info.irq = port->card->irq; |
| 1333 | out_info.flags = port->flags; |
| 1334 | /* out_info.baud_base = ? */ |
| 1335 | out_info.close_delay = port->close_delay; |
| 1336 | out_info.closing_wait = port->closing_wait; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1337 | if (copy_to_user(info, &out_info, sizeof(out_info))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | return -EFAULT; |
| 1339 | return 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1342 | static int isicom_ioctl(struct tty_struct *tty, struct file *filp, |
| 1343 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1345 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | void __user *argp = (void __user *)arg; |
| 1347 | int retval; |
| 1348 | |
| 1349 | if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) |
| 1350 | return -ENODEV; |
| 1351 | |
| 1352 | switch(cmd) { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1353 | case TCSBRK: |
| 1354 | retval = tty_check_change(tty); |
| 1355 | if (retval) |
| 1356 | return retval; |
| 1357 | tty_wait_until_sent(tty, 0); |
| 1358 | if (!arg) |
| 1359 | isicom_send_break(port, HZ/4); |
| 1360 | return 0; |
| 1361 | |
| 1362 | case TCSBRKP: |
| 1363 | retval = tty_check_change(tty); |
| 1364 | if (retval) |
| 1365 | return retval; |
| 1366 | tty_wait_until_sent(tty, 0); |
| 1367 | isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4); |
| 1368 | return 0; |
| 1369 | |
| 1370 | case TIOCGSOFTCAR: |
| 1371 | return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp); |
| 1372 | |
| 1373 | case TIOCSSOFTCAR: |
| 1374 | if (get_user(arg, (unsigned long __user *) argp)) |
| 1375 | return -EFAULT; |
| 1376 | tty->termios->c_cflag = |
| 1377 | ((tty->termios->c_cflag & ~CLOCAL) | |
| 1378 | (arg ? CLOCAL : 0)); |
| 1379 | return 0; |
| 1380 | |
| 1381 | case TIOCGSERIAL: |
| 1382 | return isicom_get_serial_info(port, argp); |
| 1383 | |
| 1384 | case TIOCSSERIAL: |
| 1385 | return isicom_set_serial_info(port, argp); |
| 1386 | |
| 1387 | default: |
| 1388 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | } |
| 1390 | return 0; |
| 1391 | } |
| 1392 | |
| 1393 | /* set_termios et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1394 | static void isicom_set_termios(struct tty_struct *tty, |
| 1395 | struct termios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1397 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | if (isicom_paranoia_check(port, tty->name, "isicom_set_termios")) |
| 1400 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | if (tty->termios->c_cflag == old_termios->c_cflag && |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1403 | tty->termios->c_iflag == old_termios->c_iflag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | isicom_config_port(port); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | if ((old_termios->c_cflag & CRTSCTS) && |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1409 | !(tty->termios->c_cflag & CRTSCTS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | tty->hw_stopped = 0; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1411 | isicom_start(tty); |
| 1412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /* throttle et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1416 | static void isicom_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1418 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1419 | struct isi_board *card = port->card; |
| 1420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | if (isicom_paranoia_check(port, tty->name, "isicom_throttle")) |
| 1422 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | /* tell the card that this port cannot handle any more data for now */ |
| 1425 | card->port_status &= ~(1 << port->channel); |
| 1426 | outw(card->port_status, card->base + 0x02); |
| 1427 | } |
| 1428 | |
| 1429 | /* unthrottle et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1430 | static void isicom_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1432 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1433 | struct isi_board *card = port->card; |
| 1434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | if (isicom_paranoia_check(port, tty->name, "isicom_unthrottle")) |
| 1436 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | /* tell the card that this port is ready to accept more data */ |
| 1439 | card->port_status |= (1 << port->channel); |
| 1440 | outw(card->port_status, card->base + 0x02); |
| 1441 | } |
| 1442 | |
| 1443 | /* stop et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1444 | static void isicom_stop(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1446 | struct isi_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | |
| 1448 | if (isicom_paranoia_check(port, tty->name, "isicom_stop")) |
| 1449 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | /* this tells the transmitter not to consider this port for |
| 1452 | data output to the card. */ |
| 1453 | port->status &= ~ISI_TXOK; |
| 1454 | } |
| 1455 | |
| 1456 | /* start et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1457 | static void isicom_start(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1459 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | if (isicom_paranoia_check(port, tty->name, "isicom_start")) |
| 1462 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | /* this tells the transmitter to consider this port for |
| 1465 | data output to the card. */ |
| 1466 | port->status |= ISI_TXOK; |
| 1467 | } |
| 1468 | |
| 1469 | /* hangup et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1470 | static void do_isicom_hangup(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1472 | struct isi_port *port = data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1473 | struct tty_struct *tty; |
| 1474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | tty = port->tty; |
| 1476 | if (tty) |
| 1477 | tty_hangup(tty); |
| 1478 | } |
| 1479 | |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1480 | static void isicom_hangup(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1482 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | if (isicom_paranoia_check(port, tty->name, "isicom_hangup")) |
| 1485 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | isicom_shutdown_port(port); |
| 1488 | port->count = 0; |
| 1489 | port->flags &= ~ASYNC_NORMAL_ACTIVE; |
| 1490 | port->tty = NULL; |
| 1491 | wake_up_interruptible(&port->open_wait); |
| 1492 | } |
| 1493 | |
| 1494 | /* flush_buffer et all */ |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1495 | static void isicom_flush_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | { |
Jiri Slaby | 8070e35 | 2006-01-09 20:54:22 -0800 | [diff] [blame] | 1497 | struct isi_port *port = tty->driver_data; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1498 | struct isi_board *card = port->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | unsigned long flags; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | if (isicom_paranoia_check(port, tty->name, "isicom_flush_buffer")) |
| 1502 | return; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | spin_lock_irqsave(&card->card_lock, flags); |
| 1505 | port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; |
| 1506 | spin_unlock_irqrestore(&card->card_lock, flags); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | wake_up_interruptible(&tty->write_wait); |
| 1509 | tty_wakeup(tty); |
| 1510 | } |
| 1511 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1512 | /* |
| 1513 | * Driver init and deinit functions |
| 1514 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1516 | static int __devinit isicom_register_ioregion(struct pci_dev *pdev, |
| 1517 | const unsigned int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1519 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1520 | |
| 1521 | if (!board->base) |
| 1522 | return -EINVAL; |
| 1523 | |
| 1524 | if (!request_region(board->base, 16, ISICOM_NAME)) { |
| 1525 | dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d " |
| 1526 | "will be disabled.\n", board->base, board->base + 15, |
| 1527 | index + 1); |
| 1528 | return -EBUSY; |
| 1529 | } |
| 1530 | |
| 1531 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1534 | static void isicom_unregister_ioregion(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1536 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1537 | |
| 1538 | if (!board->base) |
| 1539 | return; |
| 1540 | |
| 1541 | release_region(board->base, 16); |
| 1542 | dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx released.\n", |
| 1543 | board->base, board->base + 15); |
| 1544 | board->base = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | static struct tty_operations isicom_ops = { |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1548 | .open = isicom_open, |
| 1549 | .close = isicom_close, |
| 1550 | .write = isicom_write, |
| 1551 | .put_char = isicom_put_char, |
| 1552 | .flush_chars = isicom_flush_chars, |
| 1553 | .write_room = isicom_write_room, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | .chars_in_buffer = isicom_chars_in_buffer, |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1555 | .ioctl = isicom_ioctl, |
| 1556 | .set_termios = isicom_set_termios, |
| 1557 | .throttle = isicom_throttle, |
| 1558 | .unthrottle = isicom_unthrottle, |
| 1559 | .stop = isicom_stop, |
| 1560 | .start = isicom_start, |
| 1561 | .hangup = isicom_hangup, |
| 1562 | .flush_buffer = isicom_flush_buffer, |
| 1563 | .tiocmget = isicom_tiocmget, |
| 1564 | .tiocmset = isicom_tiocmset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | }; |
| 1566 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1567 | static int __devinit isicom_register_tty_driver(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1569 | int error = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
| 1571 | /* tty driver structure initialization */ |
| 1572 | isicom_normal = alloc_tty_driver(PORT_COUNT); |
| 1573 | if (!isicom_normal) |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1574 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1576 | isicom_normal->owner = THIS_MODULE; |
| 1577 | isicom_normal->name = "ttyM"; |
| 1578 | isicom_normal->devfs_name = "isicom/"; |
| 1579 | isicom_normal->major = ISICOM_NMAJOR; |
| 1580 | isicom_normal->minor_start = 0; |
| 1581 | isicom_normal->type = TTY_DRIVER_TYPE_SERIAL; |
| 1582 | isicom_normal->subtype = SERIAL_TYPE_NORMAL; |
| 1583 | isicom_normal->init_termios = tty_std_termios; |
| 1584 | isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | |
| 1585 | CLOCAL; |
| 1586 | isicom_normal->flags = TTY_DRIVER_REAL_RAW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | tty_set_operations(isicom_normal, &isicom_ops); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1588 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1589 | if ((error = tty_register_driver(isicom_normal))) { |
| 1590 | pr_dbg("Couldn't register the dialin driver, error=%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | error); |
| 1592 | put_tty_driver(isicom_normal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1594 | end: |
| 1595 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1598 | static void isicom_unregister_tty_driver(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 1600 | int error; |
| 1601 | |
| 1602 | if ((error = tty_unregister_driver(isicom_normal))) |
| 1603 | pr_dbg("couldn't unregister normal driver, error=%d.\n", error); |
| 1604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | put_tty_driver(isicom_normal); |
| 1606 | } |
| 1607 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1608 | static int __devinit isicom_register_isr(struct pci_dev *pdev, |
| 1609 | const unsigned int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1611 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1612 | unsigned long irqflags = SA_INTERRUPT; |
| 1613 | int retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1615 | if (!board->base) |
| 1616 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1618 | if (board->isa == NO) |
| 1619 | irqflags |= SA_SHIRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1621 | retval = request_irq(board->irq, isicom_interrupt, irqflags, |
| 1622 | ISICOM_NAME, board); |
| 1623 | if (retval < 0) |
| 1624 | dev_warn(&pdev->dev, "Could not install handler at Irq %d. " |
| 1625 | "Card%d will be disabled.\n", board->irq, index + 1); |
| 1626 | else |
| 1627 | retval = 0; |
| 1628 | end: |
| 1629 | return retval; |
| 1630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1632 | static int __devinit reset_card(struct pci_dev *pdev, |
| 1633 | const unsigned int card, unsigned int *signature) |
| 1634 | { |
| 1635 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1636 | unsigned long base = board->base; |
| 1637 | unsigned int portcount = 0; |
| 1638 | int retval = 0; |
| 1639 | |
| 1640 | dev_dbg(&pdev->dev, "ISILoad:Resetting Card%d at 0x%lx\n", card + 1, |
| 1641 | base); |
| 1642 | |
| 1643 | inw(base + 0x8); |
| 1644 | |
| 1645 | mdelay(10); |
| 1646 | |
| 1647 | outw(0, base + 0x8); /* Reset */ |
| 1648 | |
| 1649 | msleep(3000); |
| 1650 | |
| 1651 | *signature = inw(base + 0x4) & 0xff; |
| 1652 | |
| 1653 | if (board->isa == YES) { |
| 1654 | if (!(inw(base + 0xe) & 0x1) || (inw(base + 0x2))) { |
| 1655 | dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n", |
| 1656 | inw(base + 0x2), inw(base + 0xe)); |
| 1657 | dev_err(&pdev->dev, "ISILoad:ISA Card%d reset failure " |
| 1658 | "(Possible bad I/O Port Address 0x%lx).\n", |
| 1659 | card + 1, base); |
| 1660 | retval = -EIO; |
| 1661 | goto end; |
| 1662 | } |
| 1663 | } else { |
| 1664 | portcount = inw(base + 0x2); |
| 1665 | if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) && |
| 1666 | (portcount != 4) && (portcount != 8))) { |
| 1667 | dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n", |
| 1668 | inw(base + 0x2), inw(base + 0xe)); |
| 1669 | dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure " |
| 1670 | "(Possible bad I/O Port Address 0x%lx).\n", |
| 1671 | card + 1, base); |
| 1672 | retval = -EIO; |
| 1673 | goto end; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1677 | switch (*signature) { |
| 1678 | case 0xa5: |
| 1679 | case 0xbb: |
| 1680 | case 0xdd: |
| 1681 | board->port_count = (board->isa == NO && portcount == 4) ? 4 : |
| 1682 | 8; |
| 1683 | board->shift_count = 12; |
| 1684 | break; |
| 1685 | case 0xcc: |
| 1686 | board->port_count = 16; |
| 1687 | board->shift_count = 11; |
| 1688 | break; |
| 1689 | default: |
| 1690 | dev_warn(&pdev->dev, "ISILoad:Card%d reset failure (Possible " |
| 1691 | "bad I/O Port Address 0x%lx).\n", card + 1, base); |
| 1692 | dev_dbg(&pdev->dev, "Sig=0x%lx\n", signature); |
| 1693 | retval = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | } |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1695 | dev_info(&pdev->dev, "-Done\n"); |
| 1696 | |
| 1697 | end: |
| 1698 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame^] | 1701 | static inline int WaitTillCardIsFree(u16 base) |
| 1702 | { |
| 1703 | unsigned long count = 0; |
| 1704 | |
| 1705 | while (!(inw(base + 0xe) & 0x1) && count++ < 100) |
| 1706 | msleep(5); |
| 1707 | |
| 1708 | return !(inw(base + 0xe) & 0x1); |
| 1709 | } |
| 1710 | |
| 1711 | static int __devinit load_firmware(struct pci_dev *pdev, |
| 1712 | const unsigned int index, const unsigned int signature) |
| 1713 | { |
| 1714 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1715 | const struct firmware *fw; |
| 1716 | unsigned long base = board->base; |
| 1717 | unsigned int a; |
| 1718 | u16 word_count, status; |
| 1719 | int retval = -EIO; |
| 1720 | char *name; |
| 1721 | u8 *data; |
| 1722 | |
| 1723 | struct stframe { |
| 1724 | u16 addr; |
| 1725 | u16 count; |
| 1726 | u8 data[0]; |
| 1727 | } *frame; |
| 1728 | |
| 1729 | switch (signature) { |
| 1730 | case 0xa5: |
| 1731 | name = "isi608.bin"; |
| 1732 | break; |
| 1733 | case 0xbb: |
| 1734 | name = "isi608em.bin"; |
| 1735 | break; |
| 1736 | case 0xcc: |
| 1737 | name = "isi616em.bin"; |
| 1738 | break; |
| 1739 | case 0xdd: |
| 1740 | name = "isi4608.bin"; |
| 1741 | break; |
| 1742 | case 0xee: |
| 1743 | name = "isi4616.bin"; |
| 1744 | break; |
| 1745 | default: |
| 1746 | dev_err(&pdev->dev, "Unknown signature.\n"); |
| 1747 | goto end; |
| 1748 | } |
| 1749 | |
| 1750 | retval = request_firmware(&fw, name, &pdev->dev); |
| 1751 | if (retval) |
| 1752 | goto end; |
| 1753 | |
| 1754 | for (frame = (struct stframe *)fw->data; |
| 1755 | frame < (struct stframe *)(fw->data + fw->size); |
| 1756 | frame++) { |
| 1757 | if (WaitTillCardIsFree(base)) |
| 1758 | goto errrelfw; |
| 1759 | |
| 1760 | outw(0xf0, base); /* start upload sequence */ |
| 1761 | outw(0x00, base); |
| 1762 | outw(frame->addr, base); /* lsb of address */ |
| 1763 | |
| 1764 | word_count = frame->count / 2 + frame->count % 2; |
| 1765 | outw(word_count, base); |
| 1766 | InterruptTheCard(base); |
| 1767 | |
| 1768 | udelay(100); /* 0x2f */ |
| 1769 | |
| 1770 | if (WaitTillCardIsFree(base)) |
| 1771 | goto errrelfw; |
| 1772 | |
| 1773 | if ((status = inw(base + 0x4)) != 0) { |
| 1774 | dev_warn(&pdev->dev, "Card%d rejected load header:\n" |
| 1775 | "Address:0x%x\nCount:0x%x\nStatus:0x%x\n", |
| 1776 | index + 1, frame->addr, frame->count, status); |
| 1777 | goto errrelfw; |
| 1778 | } |
| 1779 | outsw(base, frame->data, word_count); |
| 1780 | |
| 1781 | InterruptTheCard(base); |
| 1782 | |
| 1783 | udelay(50); /* 0x0f */ |
| 1784 | |
| 1785 | if (WaitTillCardIsFree(base)) |
| 1786 | goto errrelfw; |
| 1787 | |
| 1788 | if ((status = inw(base + 0x4)) != 0) { |
| 1789 | dev_err(&pdev->dev, "Card%d got out of sync.Card " |
| 1790 | "Status:0x%x\n", index + 1, status); |
| 1791 | goto errrelfw; |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | retval = -EIO; |
| 1796 | |
| 1797 | if (WaitTillCardIsFree(base)) |
| 1798 | goto errrelfw; |
| 1799 | |
| 1800 | outw(0xf2, base); |
| 1801 | outw(0x800, base); |
| 1802 | outw(0x0, base); |
| 1803 | outw(0x0, base); |
| 1804 | InterruptTheCard(base); |
| 1805 | outw(0x0, base + 0x4); /* for ISI4608 cards */ |
| 1806 | |
| 1807 | /* XXX: should we test it by reading it back and comparing with original like |
| 1808 | * in load firmware package? */ |
| 1809 | for (frame = (struct stframe*)fw->data; |
| 1810 | frame < (struct stframe*)(fw->data + fw->size); |
| 1811 | frame++) { |
| 1812 | if (WaitTillCardIsFree(base)) |
| 1813 | goto errrelfw; |
| 1814 | |
| 1815 | outw(0xf1, base); /* start download sequence */ |
| 1816 | outw(0x00, base); |
| 1817 | outw(frame->addr, base); /* lsb of address */ |
| 1818 | |
| 1819 | word_count = (frame->count >> 1) + frame->count % 2; |
| 1820 | outw(word_count + 1, base); |
| 1821 | InterruptTheCard(base); |
| 1822 | |
| 1823 | udelay(50); /* 0xf */ |
| 1824 | |
| 1825 | if (WaitTillCardIsFree(base)) |
| 1826 | goto errrelfw; |
| 1827 | |
| 1828 | if ((status = inw(base + 0x4)) != 0) { |
| 1829 | dev_warn(&pdev->dev, "Card%d rejected verify header:\n" |
| 1830 | "Address:0x%x\nCount:0x%x\nStatus: 0x%x\n", |
| 1831 | index + 1, frame->addr, frame->count, status); |
| 1832 | goto errrelfw; |
| 1833 | } |
| 1834 | |
| 1835 | data = kmalloc(word_count * 2, GFP_KERNEL); |
| 1836 | inw(base); |
| 1837 | insw(base, data, word_count); |
| 1838 | InterruptTheCard(base); |
| 1839 | |
| 1840 | for (a = 0; a < frame->count; a++) |
| 1841 | if (data[a] != frame->data[a]) { |
| 1842 | kfree(data); |
| 1843 | dev_err(&pdev->dev, "Card%d, firmware upload " |
| 1844 | "failed\n", index + 1); |
| 1845 | goto errrelfw; |
| 1846 | } |
| 1847 | kfree(data); |
| 1848 | |
| 1849 | udelay(50); /* 0xf */ |
| 1850 | |
| 1851 | if (WaitTillCardIsFree(base)) |
| 1852 | goto errrelfw; |
| 1853 | |
| 1854 | if ((status = inw(base + 0x4)) != 0) { |
| 1855 | dev_err(&pdev->dev, "Card%d verify got out of sync. " |
| 1856 | "Card Status:0x%x\n", index + 1, status); |
| 1857 | goto errrelfw; |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | board->status |= FIRMWARE_LOADED; |
| 1862 | retval = 0; |
| 1863 | |
| 1864 | errrelfw: |
| 1865 | release_firmware(fw); |
| 1866 | end: |
| 1867 | return retval; |
| 1868 | } |
| 1869 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1870 | /* |
| 1871 | * Insmod can set static symbols so keep these static |
| 1872 | */ |
| 1873 | static int io[4]; |
| 1874 | static int irq[4]; |
| 1875 | static int card; |
| 1876 | |
| 1877 | static int __devinit isicom_probe(struct pci_dev *pdev, |
| 1878 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | { |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1880 | unsigned int ioaddr, signature, index; |
| 1881 | int retval = -EPERM; |
| 1882 | u8 pciirq; |
| 1883 | struct isi_board *board = NULL; |
| 1884 | |
| 1885 | if (card >= BOARD_COUNT) |
| 1886 | goto err; |
| 1887 | |
| 1888 | ioaddr = pci_resource_start(pdev, 3); |
| 1889 | /* i.e at offset 0x1c in the PCI configuration register space. */ |
| 1890 | pciirq = pdev->irq; |
| 1891 | dev_info(&pdev->dev, "ISI PCI Card(Device ID 0x%x)\n", ent->device); |
| 1892 | |
| 1893 | /* allot the first empty slot in the array */ |
| 1894 | for (index = 0; index < BOARD_COUNT; index++) |
| 1895 | if (isi_card[index].base == 0) { |
| 1896 | board = &isi_card[index]; |
| 1897 | break; |
| 1898 | } |
| 1899 | |
| 1900 | board->base = ioaddr; |
| 1901 | board->irq = pciirq; |
| 1902 | board->isa = NO; |
| 1903 | card++; |
| 1904 | |
| 1905 | pci_set_drvdata(pdev, board); |
| 1906 | |
| 1907 | retval = isicom_register_ioregion(pdev, index); |
| 1908 | if (retval < 0) |
| 1909 | goto err; |
| 1910 | |
| 1911 | retval = isicom_register_isr(pdev, index); |
| 1912 | if (retval < 0) |
| 1913 | goto errunrr; |
| 1914 | |
| 1915 | retval = reset_card(pdev, index, &signature); |
| 1916 | if (retval < 0) |
| 1917 | goto errunri; |
| 1918 | |
Jiri Slaby | e65c1db | 2006-01-09 20:54:25 -0800 | [diff] [blame^] | 1919 | retval = load_firmware(pdev, index, signature); |
| 1920 | if (retval < 0) |
| 1921 | goto errunri; |
| 1922 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1923 | return 0; |
| 1924 | |
| 1925 | errunri: |
| 1926 | free_irq(board->irq, board); |
| 1927 | errunrr: |
| 1928 | isicom_unregister_ioregion(pdev); |
| 1929 | err: |
| 1930 | board->base = 0; |
| 1931 | return retval; |
| 1932 | } |
| 1933 | |
| 1934 | static void __devexit isicom_remove(struct pci_dev *pdev) |
| 1935 | { |
| 1936 | struct isi_board *board = pci_get_drvdata(pdev); |
| 1937 | |
| 1938 | free_irq(board->irq, board); |
| 1939 | isicom_unregister_ioregion(pdev); |
| 1940 | } |
| 1941 | |
| 1942 | static int __devinit isicom_setup(void) |
| 1943 | { |
| 1944 | int retval, idx, channel; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1945 | struct isi_port *port; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1946 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1947 | card = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | memset(isi_ports, 0, sizeof(isi_ports)); |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1949 | |
| 1950 | for(idx = 0; idx < BOARD_COUNT; idx++) { |
| 1951 | port = &isi_ports[idx * 16]; |
| 1952 | isi_card[idx].ports = port; |
| 1953 | spin_lock_init(&isi_card[idx].card_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | for (channel = 0; channel < 16; channel++, port++) { |
| 1955 | port->magic = ISICOM_MAGIC; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1956 | port->card = &isi_card[idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | port->channel = channel; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1958 | port->close_delay = 50 * HZ/100; |
| 1959 | port->closing_wait = 3000 * HZ/100; |
| 1960 | INIT_WORK(&port->hangup_tq, do_isicom_hangup, port); |
| 1961 | INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port); |
| 1962 | port->status = 0; |
| 1963 | init_waitqueue_head(&port->open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | init_waitqueue_head(&port->close_wait); |
| 1965 | /* . . . */ |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1966 | } |
| 1967 | isi_card[idx].base = 0; |
| 1968 | isi_card[idx].irq = 0; |
| 1969 | |
| 1970 | if (!io[idx]) |
| 1971 | continue; |
| 1972 | |
| 1973 | if (irq[idx] == 2 || irq[idx] == 3 || irq[idx] == 4 || |
| 1974 | irq[idx] == 5 || irq[idx] == 7 || |
| 1975 | irq[idx] == 10 || irq[idx] == 11 || |
| 1976 | irq[idx] == 12 || irq[idx] == 15) { |
| 1977 | printk(KERN_ERR "ISICOM: ISA not supported yet.\n"); |
| 1978 | retval = -EINVAL; |
| 1979 | goto error; |
| 1980 | } else |
| 1981 | printk(KERN_ERR "ISICOM: Irq %d unsupported. " |
| 1982 | "Disabling Card%d...\n", irq[idx], idx + 1); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1985 | retval = isicom_register_tty_driver(); |
| 1986 | if (retval < 0) |
| 1987 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 1989 | retval = pci_register_driver(&isicom_driver); |
| 1990 | if (retval < 0) { |
| 1991 | printk(KERN_ERR "ISICOM: Unable to register pci driver.\n"); |
| 1992 | goto errtty; |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 1993 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | init_timer(&tx); |
| 1996 | tx.expires = jiffies + 1; |
| 1997 | tx.data = 0; |
| 1998 | tx.function = isicom_tx; |
| 1999 | re_schedule = 1; |
| 2000 | add_timer(&tx); |
Jiri Slaby | d8d16e4 | 2006-01-09 20:54:21 -0800 | [diff] [blame] | 2001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | return 0; |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 2003 | errtty: |
| 2004 | isicom_unregister_tty_driver(); |
| 2005 | error: |
| 2006 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | static void __exit isicom_exit(void) |
| 2010 | { |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 2011 | unsigned int index = 0; |
| 2012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | re_schedule = 0; |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 2014 | |
| 2015 | while (re_schedule != 2 && index++ < 100) |
| 2016 | msleep(10); |
| 2017 | |
Jiri Slaby | 9ac0948 | 2006-01-09 20:54:24 -0800 | [diff] [blame] | 2018 | pci_unregister_driver(&isicom_driver); |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 2019 | isicom_unregister_tty_driver(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | module_init(isicom_setup); |
| 2023 | module_exit(isicom_exit); |
Jiri Slaby | aaa246e | 2006-01-09 20:54:23 -0800 | [diff] [blame] | 2024 | |
| 2025 | MODULE_AUTHOR("MultiTech"); |
| 2026 | MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); |
| 2027 | MODULE_LICENSE("GPL"); |
| 2028 | module_param_array(io, int, NULL, 0); |
| 2029 | MODULE_PARM_DESC(io, "I/O ports for the cards"); |
| 2030 | module_param_array(irq, int, NULL, 0); |
| 2031 | MODULE_PARM_DESC(irq, "Interrupts for the cards"); |