Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /* rio_linux.c -- Linux driver for the Specialix RIO series cards. |
| 3 | * |
| 4 | * |
| 5 | * (C) 1999 R.E.Wolff@BitWizard.nl |
| 6 | * |
| 7 | * Specialix pays for the development and support of this driver. |
| 8 | * Please DO contact support@specialix.co.uk if you require |
| 9 | * support. But please read the documentation (rio.txt) first. |
| 10 | * |
| 11 | * |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License as |
| 15 | * published by the Free Software Foundation; either version 2 of |
| 16 | * the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be |
| 19 | * useful, but WITHOUT ANY WARRANTY; without even the implied |
| 20 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 21 | * PURPOSE. See the GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public |
| 24 | * License along with this program; if not, write to the Free |
| 25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, |
| 26 | * USA. |
| 27 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * */ |
| 29 | |
| 30 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/kdev_t.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/sched.h> |
| 35 | #include <linux/ioport.h> |
| 36 | #include <linux/interrupt.h> |
| 37 | #include <linux/errno.h> |
| 38 | #include <linux/tty.h> |
| 39 | #include <linux/tty_flip.h> |
| 40 | #include <linux/mm.h> |
| 41 | #include <linux/serial.h> |
| 42 | #include <linux/fcntl.h> |
| 43 | #include <linux/major.h> |
| 44 | #include <linux/delay.h> |
| 45 | #include <linux/pci.h> |
| 46 | #include <linux/slab.h> |
Alexey Dobriyan | 405f557 | 2009-07-11 22:08:37 +0400 | [diff] [blame] | 47 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/miscdevice.h> |
| 49 | #include <linux/init.h> |
| 50 | |
| 51 | #include <linux/generic_serial.h> |
| 52 | #include <asm/uaccess.h> |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include "linux_compat.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include "pkt.h" |
| 56 | #include "daemon.h" |
| 57 | #include "rio.h" |
| 58 | #include "riospace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "cmdpkt.h" |
| 60 | #include "map.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include "rup.h" |
| 62 | #include "port.h" |
| 63 | #include "riodrvr.h" |
| 64 | #include "rioinfo.h" |
| 65 | #include "func.h" |
| 66 | #include "errors.h" |
| 67 | #include "pci.h" |
| 68 | |
| 69 | #include "parmmap.h" |
| 70 | #include "unixrup.h" |
| 71 | #include "board.h" |
| 72 | #include "host.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #include "phb.h" |
| 74 | #include "link.h" |
| 75 | #include "cmdblk.h" |
| 76 | #include "route.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #include "cirrus.h" |
| 78 | #include "rioioctl.h" |
| 79 | #include "param.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #include "protsts.h" |
| 81 | #include "rioboard.h" |
| 82 | |
| 83 | |
| 84 | #include "rio_linux.h" |
| 85 | |
| 86 | /* I don't think that this driver can handle more than 512 ports on |
| 87 | one machine. Specialix specifies max 4 boards in one machine. I don't |
| 88 | know why. If you want to try anyway you'll have to increase the number |
| 89 | of boards in rio.h. You'll have to allocate more majors if you need |
| 90 | more than 512 ports.... */ |
| 91 | |
| 92 | #ifndef RIO_NORMAL_MAJOR0 |
| 93 | /* This allows overriding on the compiler commandline, or in a "major.h" |
| 94 | include or something like that */ |
| 95 | #define RIO_NORMAL_MAJOR0 154 |
| 96 | #define RIO_NORMAL_MAJOR1 156 |
| 97 | #endif |
| 98 | |
| 99 | #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 |
| 100 | #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000 |
| 101 | #endif |
| 102 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 103 | #ifndef RIO_WINDOW_LEN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | #define RIO_WINDOW_LEN 0x10000 |
| 105 | #endif |
| 106 | |
| 107 | |
| 108 | /* Configurable options: |
| 109 | (Don't be too sure that it'll work if you toggle them) */ |
| 110 | |
| 111 | /* Am I paranoid or not ? ;-) */ |
| 112 | #undef RIO_PARANOIA_CHECK |
| 113 | |
| 114 | |
| 115 | /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000 |
| 116 | Hz, but it is user configurable. I don't recommend going above 1000 |
| 117 | Hz. The interrupt ratelimit might trigger if the interrupt is |
| 118 | shared with a very active other device. |
| 119 | undef this if you want to disable the check.... |
| 120 | */ |
| 121 | #define IRQ_RATE_LIMIT 200 |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | /* These constants are derived from SCO Source */ |
| 125 | static struct Conf |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 126 | RIOConf = { |
| 127 | /* locator */ "RIO Config here", |
| 128 | /* startuptime */ HZ * 2, |
| 129 | /* how long to wait for card to run */ |
| 130 | /* slowcook */ 0, |
| 131 | /* TRUE -> always use line disc. */ |
| 132 | /* intrpolltime */ 1, |
| 133 | /* The frequency of OUR polls */ |
| 134 | /* breakinterval */ 25, |
| 135 | /* x10 mS XXX: units seem to be 1ms not 10! -- REW */ |
| 136 | /* timer */ 10, |
| 137 | /* mS */ |
| 138 | /* RtaLoadBase */ 0x7000, |
| 139 | /* HostLoadBase */ 0x7C00, |
| 140 | /* XpHz */ 5, |
| 141 | /* number of Xprint hits per second */ |
| 142 | /* XpCps */ 120, |
| 143 | /* Xprint characters per second */ |
| 144 | /* XpOn */ "\033d#", |
| 145 | /* start Xprint for a wyse 60 */ |
| 146 | /* XpOff */ "\024", |
| 147 | /* end Xprint for a wyse 60 */ |
| 148 | /* MaxXpCps */ 2000, |
| 149 | /* highest Xprint speed */ |
| 150 | /* MinXpCps */ 10, |
| 151 | /* slowest Xprint speed */ |
| 152 | /* SpinCmds */ 1, |
| 153 | /* non-zero for mega fast boots */ |
| 154 | /* First Addr */ 0x0A0000, |
| 155 | /* First address to look at */ |
| 156 | /* Last Addr */ 0xFF0000, |
| 157 | /* Last address looked at */ |
| 158 | /* BufferSize */ 1024, |
| 159 | /* Bytes per port of buffering */ |
| 160 | /* LowWater */ 256, |
| 161 | /* how much data left before wakeup */ |
| 162 | /* LineLength */ 80, |
| 163 | /* how wide is the console? */ |
| 164 | /* CmdTimeout */ HZ, |
| 165 | /* how long a close command may take */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | /* Function prototypes */ |
| 172 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 173 | static void rio_disable_tx_interrupts(void *ptr); |
| 174 | static void rio_enable_tx_interrupts(void *ptr); |
| 175 | static void rio_disable_rx_interrupts(void *ptr); |
| 176 | static void rio_enable_rx_interrupts(void *ptr); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 177 | static int rio_carrier_raised(struct tty_port *port); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 178 | static void rio_shutdown_port(void *ptr); |
| 179 | static int rio_set_real_termios(void *ptr); |
| 180 | static void rio_hungup(void *ptr); |
| 181 | static void rio_close(void *ptr); |
| 182 | static int rio_chars_in_buffer(void *ptr); |
Alan Cox | f6759fd | 2008-07-25 01:48:14 -0700 | [diff] [blame] | 183 | static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | static int rio_init_drivers(void); |
| 185 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 186 | static void my_hd(void *addr, int len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | static struct tty_driver *rio_driver, *rio_driver2; |
| 189 | |
| 190 | /* The name "p" is a bit non-descript. But that's what the rio-lynxos |
| 191 | sources use all over the place. */ |
| 192 | struct rio_info *p; |
| 193 | |
| 194 | int rio_debug; |
| 195 | |
| 196 | |
| 197 | /* You can have the driver poll your card. |
| 198 | - Set rio_poll to 1 to poll every timer tick (10ms on Intel). |
| 199 | This is used when the card cannot use an interrupt for some reason. |
| 200 | */ |
| 201 | static int rio_poll = 1; |
| 202 | |
| 203 | |
| 204 | /* These are the only open spaces in my computer. Yours may have more |
| 205 | or less.... */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 206 | static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Tobias Klauser | fe97107 | 2006-01-09 20:54:02 -0800 | [diff] [blame] | 208 | #define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | |
| 211 | /* Set the mask to all-ones. This alas, only supports 32 interrupts. |
| 212 | Some architectures may need more. -- Changed to LONG to |
| 213 | support up to 64 bits on 64bit architectures. -- REW 20/06/99 */ |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 214 | static long rio_irqmask = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>"); |
| 217 | MODULE_DESCRIPTION("RIO driver"); |
| 218 | MODULE_LICENSE("GPL"); |
| 219 | module_param(rio_poll, int, 0); |
| 220 | module_param(rio_debug, int, 0644); |
| 221 | module_param(rio_irqmask, long, 0); |
| 222 | |
| 223 | static struct real_driver rio_real_driver = { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 224 | rio_disable_tx_interrupts, |
| 225 | rio_enable_tx_interrupts, |
| 226 | rio_disable_rx_interrupts, |
| 227 | rio_enable_rx_interrupts, |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 228 | rio_shutdown_port, |
| 229 | rio_set_real_termios, |
| 230 | rio_chars_in_buffer, |
| 231 | rio_close, |
| 232 | rio_hungup, |
| 233 | NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /* |
| 237 | * Firmware loader driver specific routines |
| 238 | * |
| 239 | */ |
| 240 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 241 | static const struct file_operations rio_fw_fops = { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 242 | .owner = THIS_MODULE, |
Alan Cox | f6759fd | 2008-07-25 01:48:14 -0700 | [diff] [blame] | 243 | .unlocked_ioctl = rio_fw_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | static struct miscdevice rio_fw_device = { |
| 247 | RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops |
| 248 | }; |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | #ifdef RIO_PARANOIA_CHECK |
| 255 | |
| 256 | /* This doesn't work. Who's paranoid around here? Not me! */ |
| 257 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 258 | static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 261 | static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n"; |
| 262 | static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 264 | if (!port) { |
| 265 | printk(badinfo, name, routine); |
| 266 | return 1; |
| 267 | } |
| 268 | if (port->magic != RIO_MAGIC) { |
| 269 | printk(badmagic, name, routine); |
| 270 | return 1; |
| 271 | } |
| 272 | |
| 273 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | #else |
| 276 | #define rio_paranoia_check(a,b,c) 0 |
| 277 | #endif |
| 278 | |
| 279 | |
| 280 | #ifdef DEBUG |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 281 | static void my_hd(void *ad, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 283 | int i, j, ch; |
| 284 | unsigned char *addr = ad; |
| 285 | |
| 286 | for (i = 0; i < len; i += 16) { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 287 | rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 288 | for (j = 0; j < 16; j++) { |
| 289 | rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : ""); |
| 290 | } |
| 291 | for (j = 0; j < 16; j++) { |
| 292 | ch = addr[j + i]; |
| 293 | rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch)); |
| 294 | } |
| 295 | rio_dprintk(RIO_DEBUG_PARAM, "\n"); |
| 296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | #else |
| 299 | #define my_hd(ad,len) do{/* nothing*/ } while (0) |
| 300 | #endif |
| 301 | |
| 302 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 303 | /* Delay a number of jiffies, allowing a signal to interrupt */ |
| 304 | int RIODelay(struct Port *PortP, int njiffies) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 306 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 308 | rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies); |
| 309 | msleep_interruptible(jiffies_to_msecs(njiffies)); |
| 310 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 312 | if (signal_pending(current)) |
| 313 | return RIO_FAIL; |
| 314 | else |
| 315 | return !RIO_FAIL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 319 | /* Delay a number of jiffies, disallowing a signal to interrupt */ |
| 320 | int RIODelay_ni(struct Port *PortP, int njiffies) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 322 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 324 | rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies); |
| 325 | msleep(jiffies_to_msecs(njiffies)); |
| 326 | func_exit(); |
| 327 | return !RIO_FAIL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Al Viro | 38d0d00 | 2006-05-27 00:15:09 -0400 | [diff] [blame] | 330 | void rio_copy_to_card(void *from, void __iomem *to, int len) |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 331 | { |
Al Viro | ae5b28a | 2006-05-27 01:48:08 -0400 | [diff] [blame] | 332 | rio_copy_toio(to, from, len); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | int rio_minor(struct tty_struct *tty) |
| 336 | { |
Roel Kluin | 1f85449 | 2009-04-06 17:35:34 +0100 | [diff] [blame] | 337 | return tty->index + ((tty->driver == rio_driver) ? 0 : 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 340 | static int rio_set_real_termios(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 342 | return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 346 | static void rio_reset_interrupt(struct Host *HostP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 348 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 350 | switch (HostP->Type) { |
| 351 | case RIO_AT: |
| 352 | case RIO_MCA: |
| 353 | case RIO_PCI: |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 354 | writeb(0xFF, &HostP->ResetInt); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 357 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 361 | static irqreturn_t rio_interrupt(int irq, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 363 | struct Host *HostP; |
| 364 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 366 | HostP = ptr; /* &p->RIOHosts[(long)ptr]; */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 367 | rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 369 | /* AAargh! The order in which to do these things is essential and |
| 370 | not trivial. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 372 | - hardware twiddling goes before "recursive". Otherwise when we |
| 373 | poll the card, and a recursive interrupt happens, we won't |
| 374 | ack the card, so it might keep on interrupting us. (especially |
| 375 | level sensitive interrupt systems like PCI). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 377 | - Rate limit goes before hardware twiddling. Otherwise we won't |
| 378 | catch a card that has gone bonkers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 380 | - The "initialized" test goes after the hardware twiddling. Otherwise |
| 381 | the card will stick us in the interrupt routine again. |
| 382 | |
| 383 | - The initialized test goes before recursive. |
| 384 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 386 | rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n"); |
| 387 | if (HostP->Ivec == irq) { |
| 388 | /* Tell the card we've noticed the interrupt. */ |
| 389 | rio_reset_interrupt(HostP); |
| 390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 392 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) |
| 393 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 395 | if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 396 | printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 397 | return IRQ_HANDLED; |
| 398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 400 | RIOServiceHost(p, HostP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 402 | rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 404 | clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks); |
| 405 | rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec); |
| 406 | func_exit(); |
| 407 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 411 | static void rio_pollfunc(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 413 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 415 | rio_interrupt(0, &p->RIOHosts[data]); |
Jiri Slaby | 40565f1 | 2007-02-12 00:52:31 -0800 | [diff] [blame] | 416 | mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 418 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | |
| 422 | /* ********************************************************************** * |
| 423 | * Here are the routines that actually * |
| 424 | * interface with the generic_serial driver * |
| 425 | * ********************************************************************** */ |
| 426 | |
| 427 | /* Ehhm. I don't know how to fiddle with interrupts on the Specialix |
| 428 | cards. .... Hmm. Ok I figured it out. You don't. -- REW */ |
| 429 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 430 | static void rio_disable_tx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 432 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 434 | /* port->gs.port.flags &= ~GS_TX_INTEN; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 436 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 440 | static void rio_enable_tx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 442 | struct Port *PortP = ptr; |
| 443 | /* int hn; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 445 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 447 | /* hn = PortP->HostP - p->RIOHosts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 449 | rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn); |
| 450 | rio_interrupt (-1,(void *) hn, NULL); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 452 | RIOTxEnable((char *) PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 454 | /* |
| 455 | * In general we cannot count on "tx empty" interrupts, although |
| 456 | * the interrupt routine seems to be able to tell the difference. |
| 457 | */ |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 458 | PortP->gs.port.flags &= ~GS_TX_INTEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 460 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 464 | static void rio_disable_rx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 466 | func_enter(); |
| 467 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 470 | static void rio_enable_rx_interrupts(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 472 | /* struct rio_port *port = ptr; */ |
| 473 | func_enter(); |
| 474 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | |
| 478 | /* Jeez. Isn't this simple? */ |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 479 | static int rio_carrier_raised(struct tty_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 481 | struct Port *PortP = container_of(port, struct Port, gs.port); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 482 | int rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 484 | func_enter(); |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 485 | rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 487 | rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv); |
| 488 | |
| 489 | func_exit(); |
| 490 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | |
| 494 | /* Jeez. Isn't this simple? Actually, we can sync with the actual port |
| 495 | by just pushing stuff into the queue going to the port... */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 496 | static int rio_chars_in_buffer(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 498 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 500 | func_exit(); |
| 501 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | |
| 505 | /* Nothing special here... */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 506 | static void rio_shutdown_port(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 508 | struct Port *PortP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 510 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 512 | PortP = (struct Port *) ptr; |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 513 | PortP->gs.port.tty = NULL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 514 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | |
| 518 | /* I haven't the foggiest why the decrement use count has to happen |
| 519 | here. The whole linux serial drivers stuff needs to be redesigned. |
| 520 | My guess is that this is a hack to minimize the impact of a bug |
| 521 | elsewhere. Thinking about it some more. (try it sometime) Try |
| 522 | running minicom on a serial port that is driven by a modularized |
| 523 | driver. Have the modem hangup. Then remove the driver module. Then |
| 524 | exit minicom. I expect an "oops". -- REW */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 525 | static void rio_hungup(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 527 | struct Port *PortP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 529 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 531 | PortP = (struct Port *) ptr; |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 532 | PortP->gs.port.tty = NULL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 533 | |
| 534 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | |
| 538 | /* The standard serial_close would become shorter if you'd wrap it like |
| 539 | this. |
| 540 | rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;} |
| 541 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 542 | static void rio_close(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 544 | struct Port *PortP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 546 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 548 | PortP = (struct Port *) ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 550 | riotclose(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 552 | if (PortP->gs.port.count) { |
| 553 | printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count); |
| 554 | PortP->gs.port.count = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Alan Cox | b5391e2 | 2008-07-16 21:55:20 +0100 | [diff] [blame] | 557 | PortP->gs.port.tty = NULL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 558 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | |
| 562 | |
Alan Cox | f6759fd | 2008-07-25 01:48:14 -0700 | [diff] [blame] | 563 | static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 565 | int rc = 0; |
| 566 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 568 | /* The "dev" argument isn't used. */ |
Alan Cox | f6759fd | 2008-07-25 01:48:14 -0700 | [diff] [blame] | 569 | lock_kernel(); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 570 | rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN)); |
Alan Cox | f6759fd | 2008-07-25 01:48:14 -0700 | [diff] [blame] | 571 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 573 | func_exit(); |
| 574 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 577 | extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 579 | static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 581 | void __user *argp = (void __user *)arg; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 582 | int rc; |
| 583 | struct Port *PortP; |
| 584 | int ival; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 586 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 588 | PortP = (struct Port *) tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 590 | rc = 0; |
| 591 | switch (cmd) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 592 | case TIOCSSOFTCAR: |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 593 | if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 594 | tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0); |
| 595 | } |
| 596 | break; |
| 597 | case TIOCGSERIAL: |
| 598 | rc = -EFAULT; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 599 | if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct))) |
| 600 | rc = gs_getserial(&PortP->gs, argp); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 601 | break; |
| 602 | case TCSBRK: |
| 603 | if (PortP->State & RIO_DELETED) { |
| 604 | rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n"); |
| 605 | rc = -EIO; |
| 606 | } else { |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 607 | if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) == |
| 608 | RIO_FAIL) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 609 | rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); |
| 610 | rc = -EIO; |
| 611 | } |
| 612 | } |
| 613 | break; |
| 614 | case TCSBRKP: |
| 615 | if (PortP->State & RIO_DELETED) { |
| 616 | rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n"); |
| 617 | rc = -EIO; |
| 618 | } else { |
| 619 | int l; |
| 620 | l = arg ? arg * 100 : 250; |
| 621 | if (l > 255) |
| 622 | l = 255; |
Jiri Slaby | d6f6341 | 2008-04-30 00:53:57 -0700 | [diff] [blame] | 623 | if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, |
| 624 | arg ? arg * 100 : 250) == RIO_FAIL) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 625 | rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); |
| 626 | rc = -EIO; |
| 627 | } |
| 628 | } |
| 629 | break; |
| 630 | case TIOCSSERIAL: |
| 631 | rc = -EFAULT; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 632 | if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct))) |
| 633 | rc = gs_setserial(&PortP->gs, argp); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 634 | break; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 635 | default: |
| 636 | rc = -ENOIOCTLCMD; |
| 637 | break; |
| 638 | } |
| 639 | func_exit(); |
| 640 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
| 644 | /* The throttle/unthrottle scheme for the Specialix card is different |
| 645 | * from other drivers and deserves some explanation. |
| 646 | * The Specialix hardware takes care of XON/XOFF |
| 647 | * and CTS/RTS flow control itself. This means that all we have to |
| 648 | * do when signalled by the upper tty layer to throttle/unthrottle is |
| 649 | * to make a note of it here. When we come to read characters from the |
| 650 | * rx buffers on the card (rio_receive_chars()) we look to see if the |
| 651 | * upper layer can accept more (as noted here in rio_rx_throt[]). |
| 652 | * If it can't we simply don't remove chars from the cards buffer. |
| 653 | * When the tty layer can accept chars, we again note that here and when |
| 654 | * rio_receive_chars() is called it will remove them from the cards buffer. |
| 655 | * The card will notice that a ports buffer has drained below some low |
| 656 | * water mark and will unflow control the line itself, using whatever |
| 657 | * flow control scheme is in use for that port. -- Simon Allen |
| 658 | */ |
| 659 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 660 | static void rio_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 662 | struct Port *port = (struct Port *) tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 664 | func_enter(); |
| 665 | /* If the port is using any type of input flow |
| 666 | * control then throttle the port. |
| 667 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 669 | if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) { |
| 670 | port->State |= RIO_THROTTLE_RX; |
| 671 | } |
| 672 | |
| 673 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 677 | static void rio_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 679 | struct Port *port = (struct Port *) tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 681 | func_enter(); |
| 682 | /* Always unthrottle even if flow control is not enabled on |
| 683 | * this port in case we disabled flow control while the port |
| 684 | * was throttled |
| 685 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 687 | port->State &= ~RIO_THROTTLE_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 689 | func_exit(); |
| 690 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | /* ********************************************************************** * |
| 698 | * Here are the initialization routines. * |
| 699 | * ********************************************************************** */ |
| 700 | |
| 701 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 702 | static struct vpd_prom *get_VPD_PROM(struct Host *hp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 704 | static struct vpd_prom vpdp; |
| 705 | char *p; |
| 706 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 708 | func_enter(); |
| 709 | rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 711 | p = (char *) &vpdp; |
| 712 | for (i = 0; i < sizeof(struct vpd_prom); i++) |
| 713 | *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2); |
| 714 | /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 716 | /* Terminate the identifier string. |
| 717 | *** requires one extra byte in struct vpd_prom *** */ |
| 718 | *p++ = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 720 | if (rio_debug & RIO_DEBUG_PROBE) |
| 721 | my_hd((char *) &vpdp, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 723 | func_exit(); |
| 724 | |
| 725 | return &vpdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 728 | static const struct tty_operations rio_ops = { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 729 | .open = riotopen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | .close = gs_close, |
| 731 | .write = gs_write, |
| 732 | .put_char = gs_put_char, |
| 733 | .flush_chars = gs_flush_chars, |
| 734 | .write_room = gs_write_room, |
| 735 | .chars_in_buffer = gs_chars_in_buffer, |
| 736 | .flush_buffer = gs_flush_buffer, |
| 737 | .ioctl = rio_ioctl, |
| 738 | .throttle = rio_throttle, |
| 739 | .unthrottle = rio_unthrottle, |
| 740 | .set_termios = gs_set_termios, |
| 741 | .stop = gs_stop, |
| 742 | .start = gs_start, |
| 743 | .hangup = gs_hangup, |
| 744 | }; |
| 745 | |
| 746 | static int rio_init_drivers(void) |
| 747 | { |
| 748 | int error = -ENOMEM; |
| 749 | |
| 750 | rio_driver = alloc_tty_driver(256); |
| 751 | if (!rio_driver) |
| 752 | goto out; |
| 753 | rio_driver2 = alloc_tty_driver(256); |
| 754 | if (!rio_driver2) |
| 755 | goto out1; |
| 756 | |
| 757 | func_enter(); |
| 758 | |
| 759 | rio_driver->owner = THIS_MODULE; |
| 760 | rio_driver->driver_name = "specialix_rio"; |
| 761 | rio_driver->name = "ttySR"; |
| 762 | rio_driver->major = RIO_NORMAL_MAJOR0; |
| 763 | rio_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 764 | rio_driver->subtype = SERIAL_TYPE_NORMAL; |
| 765 | rio_driver->init_termios = tty_std_termios; |
| 766 | rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
| 767 | rio_driver->flags = TTY_DRIVER_REAL_RAW; |
| 768 | tty_set_operations(rio_driver, &rio_ops); |
| 769 | |
| 770 | rio_driver2->owner = THIS_MODULE; |
| 771 | rio_driver2->driver_name = "specialix_rio"; |
| 772 | rio_driver2->name = "ttySR"; |
| 773 | rio_driver2->major = RIO_NORMAL_MAJOR1; |
| 774 | rio_driver2->type = TTY_DRIVER_TYPE_SERIAL; |
| 775 | rio_driver2->subtype = SERIAL_TYPE_NORMAL; |
| 776 | rio_driver2->init_termios = tty_std_termios; |
| 777 | rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
| 778 | rio_driver2->flags = TTY_DRIVER_REAL_RAW; |
| 779 | tty_set_operations(rio_driver2, &rio_ops); |
| 780 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 781 | rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
| 783 | if ((error = tty_register_driver(rio_driver))) |
| 784 | goto out2; |
| 785 | if ((error = tty_register_driver(rio_driver2))) |
| 786 | goto out3; |
| 787 | func_exit(); |
| 788 | return 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 789 | out3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | tty_unregister_driver(rio_driver); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 791 | out2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | put_tty_driver(rio_driver2); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 793 | out1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | put_tty_driver(rio_driver); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 795 | out: |
| 796 | printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | return 1; |
| 798 | } |
| 799 | |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 800 | static const struct tty_port_operations rio_port_ops = { |
| 801 | .carrier_raised = rio_carrier_raised, |
| 802 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 804 | static int rio_init_datastructures(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 806 | int i; |
| 807 | struct Port *port; |
| 808 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 810 | /* Many drivers statically allocate the maximum number of ports |
| 811 | There is no reason not to allocate them dynamically. Is there? -- REW */ |
| 812 | /* However, the RIO driver allows users to configure their first |
| 813 | RTA as the ports numbered 504-511. We therefore need to allocate |
| 814 | the whole range. :-( -- REW */ |
| 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | #define RI_SZ sizeof(struct rio_info) |
| 817 | #define HOST_SZ sizeof(struct Host) |
| 818 | #define PORT_SZ sizeof(struct Port *) |
| 819 | #define TMIO_SZ sizeof(struct termios *) |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 820 | rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 821 | |
Alan Cox | d0c9873 | 2009-01-02 13:45:12 +0000 | [diff] [blame] | 822 | if (!(p = kzalloc(RI_SZ, GFP_KERNEL))) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 823 | goto free0; |
Alan Cox | d0c9873 | 2009-01-02 13:45:12 +0000 | [diff] [blame] | 824 | if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL))) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 825 | goto free1; |
Alan Cox | d0c9873 | 2009-01-02 13:45:12 +0000 | [diff] [blame] | 826 | if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL))) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 827 | goto free2; |
| 828 | p->RIOConf = RIOConf; |
| 829 | rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
| 831 | #if 1 |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 832 | for (i = 0; i < RIO_PORTS; i++) { |
Alan Cox | d0c9873 | 2009-01-02 13:45:12 +0000 | [diff] [blame] | 833 | port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 834 | if (!port) { |
| 835 | goto free6; |
| 836 | } |
| 837 | rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped); |
Alan Cox | 31f3593 | 2009-01-02 13:45:05 +0000 | [diff] [blame] | 838 | tty_port_init(&port->gs.port); |
| 839 | port->gs.port.ops = &rio_port_ops; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 840 | port->PortNum = i; |
| 841 | port->gs.magic = RIO_MAGIC; |
| 842 | port->gs.close_delay = HZ / 2; |
| 843 | port->gs.closing_wait = 30 * HZ; |
| 844 | port->gs.rd = &rio_real_driver; |
| 845 | spin_lock_init(&port->portSem); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 846 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | #else |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 848 | /* We could postpone initializing them to when they are configured. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | #endif |
| 850 | |
| 851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 853 | if (rio_debug & RIO_DEBUG_INIT) { |
| 854 | my_hd(&rio_real_driver, sizeof(rio_real_driver)); |
| 855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 857 | |
| 858 | func_exit(); |
| 859 | return 0; |
| 860 | |
| 861 | free6:for (i--; i >= 0; i--) |
| 862 | kfree(p->RIOPortp[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | /*free5: |
| 864 | free4: |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 865 | free3:*/ kfree(p->RIOPortp); |
| 866 | free2:kfree(p->RIOHosts); |
| 867 | free1: |
| 868 | rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp); |
| 869 | kfree(p); |
| 870 | free0: |
| 871 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 874 | static void __exit rio_release_drivers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 876 | func_enter(); |
| 877 | tty_unregister_driver(rio_driver2); |
| 878 | tty_unregister_driver(rio_driver); |
| 879 | put_tty_driver(rio_driver2); |
| 880 | put_tty_driver(rio_driver); |
| 881 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
| 885 | #ifdef CONFIG_PCI |
| 886 | /* This was written for SX, but applies to RIO too... |
| 887 | (including bugs....) |
| 888 | |
| 889 | There is another bit besides Bit 17. Turning that bit off |
| 890 | (on boards shipped with the fix in the eeprom) results in a |
| 891 | hang on the next access to the card. |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 892 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
| 894 | /******************************************************** |
| 895 | * Setting bit 17 in the CNTRL register of the PLX 9050 * |
| 896 | * chip forces a retry on writes while a read is pending.* |
| 897 | * This is to prevent the card locking up on Intel Xeon * |
| 898 | * multiprocessor systems with the NX chipset. -- NV * |
| 899 | ********************************************************/ |
| 900 | |
| 901 | /* Newer cards are produced with this bit set from the configuration |
| 902 | EEprom. As the bit is read/write for the CPU, we can fix it here, |
| 903 | if we detect that it isn't set correctly. -- REW */ |
| 904 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 905 | static void fix_rio_pci(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 907 | unsigned long hwbase; |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 908 | unsigned char __iomem *rebase; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 909 | unsigned int t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | #define CNTRL_REG_OFFSET 0x50 |
| 912 | #define CNTRL_REG_GOODVALUE 0x18260000 |
| 913 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 914 | hwbase = pci_resource_start(pdev, 0); |
| 915 | rebase = ioremap(hwbase, 0x80); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 916 | t = readl(rebase + CNTRL_REG_OFFSET); |
| 917 | if (t != CNTRL_REG_GOODVALUE) { |
| 918 | printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE); |
| 919 | writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET); |
| 920 | } |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 921 | iounmap(rebase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
| 923 | #endif |
| 924 | |
| 925 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 926 | static int __init rio_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 928 | int found = 0; |
| 929 | int i; |
| 930 | struct Host *hp; |
| 931 | int retval; |
| 932 | struct vpd_prom *vpdp; |
| 933 | int okboard; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | #ifdef CONFIG_PCI |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 936 | struct pci_dev *pdev = NULL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 937 | unsigned short tshort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | #endif |
| 939 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 940 | func_enter(); |
| 941 | rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 943 | if (abs((long) (&rio_debug) - rio_debug) < 0x10000) { |
| 944 | printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug); |
| 945 | rio_debug = -1; |
| 946 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 948 | if (misc_register(&rio_fw_device) < 0) { |
| 949 | printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n"); |
| 950 | return -EIO; |
| 951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 953 | retval = rio_init_datastructures(); |
| 954 | if (retval < 0) { |
| 955 | misc_deregister(&rio_fw_device); |
| 956 | return retval; |
| 957 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | #ifdef CONFIG_PCI |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 959 | /* First look for the JET devices: */ |
| 960 | while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) { |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 961 | u32 tint; |
| 962 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 963 | if (pci_enable_device(pdev)) |
| 964 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 966 | /* Specialix has a whole bunch of cards with |
| 967 | 0x2000 as the device ID. They say its because |
| 968 | the standard requires it. Stupid standard. */ |
| 969 | /* It seems that reading a word doesn't work reliably on 2.0. |
| 970 | Also, reading a non-aligned dword doesn't work. So we read the |
| 971 | whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID) |
| 972 | ourselves */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 973 | pci_read_config_dword(pdev, 0x2c, &tint); |
| 974 | tshort = (tint >> 16) & 0xffff; |
| 975 | rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint); |
| 976 | if (tshort != 0x0100) { |
| 977 | rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort); |
| 978 | continue; |
| 979 | } |
| 980 | rio_dprintk(RIO_DEBUG_PROBE, "cp1\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 982 | hp = &p->RIOHosts[p->RIONumHosts]; |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 983 | hp->PaddrP = pci_resource_start(pdev, 2); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 984 | hp->Ivec = pdev->irq; |
| 985 | if (((1 << hp->Ivec) & rio_irqmask) == 0) |
| 986 | hp->Ivec = 0; |
| 987 | hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 988 | hp->CardP = (struct DpRam __iomem *) hp->Caddr; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 989 | hp->Type = RIO_PCI; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 990 | hp->Copy = rio_copy_to_card; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 991 | hp->Mode = RIO_PCI_BOOT_FROM_RAM; |
| 992 | spin_lock_init(&hp->HostLock); |
| 993 | rio_reset_interrupt(hp); |
| 994 | rio_start_card_running(hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 996 | rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr); |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 997 | if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 998 | rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n"); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 999 | writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1000 | p->RIOHosts[p->RIONumHosts].UniqueNum = |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 1001 | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) | |
| 1002 | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1003 | rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1005 | fix_rio_pci(pdev); |
Jiri Slaby | 86fbf14 | 2006-10-21 10:24:01 -0700 | [diff] [blame] | 1006 | |
| 1007 | p->RIOHosts[p->RIONumHosts].pdev = pdev; |
| 1008 | pci_dev_get(pdev); |
| 1009 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 1010 | p->RIOLastPCISearch = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1011 | p->RIONumHosts++; |
| 1012 | found++; |
| 1013 | } else { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1014 | iounmap(p->RIOHosts[p->RIONumHosts].Caddr); |
Amol Lad | 8684265 | 2006-12-06 20:35:19 -0800 | [diff] [blame] | 1015 | p->RIOHosts[p->RIONumHosts].Caddr = NULL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1016 | } |
| 1017 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1019 | /* Then look for the older PCI card.... : */ |
| 1020 | |
| 1021 | /* These older PCI cards have problems (only byte-mode access is |
| 1022 | supported), which makes them a bit awkward to support. |
| 1023 | They also have problems sharing interrupts. Be careful. |
| 1024 | (The driver now refuses to share interrupts for these |
| 1025 | cards. This should be sufficient). |
| 1026 | */ |
| 1027 | |
| 1028 | /* Then look for the older RIO/PCI devices: */ |
| 1029 | while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) { |
| 1030 | if (pci_enable_device(pdev)) |
| 1031 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
| 1033 | #ifdef CONFIG_RIO_OLDPCI |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1034 | hp = &p->RIOHosts[p->RIONumHosts]; |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 1035 | hp->PaddrP = pci_resource_start(pdev, 0); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1036 | hp->Ivec = pdev->irq; |
| 1037 | if (((1 << hp->Ivec) & rio_irqmask) == 0) |
| 1038 | hp->Ivec = 0; |
| 1039 | hp->Ivec |= 0x8000; /* Mark as non-sharable */ |
| 1040 | hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1041 | hp->CardP = (struct DpRam __iomem *) hp->Caddr; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1042 | hp->Type = RIO_PCI; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 1043 | hp->Copy = rio_copy_to_card; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1044 | hp->Mode = RIO_PCI_BOOT_FROM_RAM; |
| 1045 | spin_lock_init(&hp->HostLock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1047 | rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec); |
| 1048 | rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1050 | rio_reset_interrupt(hp); |
| 1051 | rio_start_card_running(hp); |
| 1052 | rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr); |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 1053 | if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) { |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 1054 | writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1055 | p->RIOHosts[p->RIONumHosts].UniqueNum = |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 1056 | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) | |
| 1057 | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1058 | rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
Jiri Slaby | 86fbf14 | 2006-10-21 10:24:01 -0700 | [diff] [blame] | 1060 | p->RIOHosts[p->RIONumHosts].pdev = pdev; |
| 1061 | pci_dev_get(pdev); |
| 1062 | |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 1063 | p->RIOLastPCISearch = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1064 | p->RIONumHosts++; |
| 1065 | found++; |
| 1066 | } else { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1067 | iounmap(p->RIOHosts[p->RIONumHosts].Caddr); |
Amol Lad | 8684265 | 2006-12-06 20:35:19 -0800 | [diff] [blame] | 1068 | p->RIOHosts[p->RIONumHosts].Caddr = NULL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1069 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | #else |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1071 | printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | #endif |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1073 | } |
| 1074 | #endif /* PCI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1076 | /* Now probe for ISA cards... */ |
| 1077 | for (i = 0; i < NR_RIO_ADDRS; i++) { |
| 1078 | hp = &p->RIOHosts[p->RIONumHosts]; |
| 1079 | hp->PaddrP = rio_probe_addrs[i]; |
| 1080 | /* There was something about the IRQs of these cards. 'Forget what.--REW */ |
| 1081 | hp->Ivec = 0; |
| 1082 | hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1083 | hp->CardP = (struct DpRam __iomem *) hp->Caddr; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1084 | hp->Type = RIO_AT; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame] | 1085 | hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL |
| 1086 | * -- YES! this is now a normal copy. Only the |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1087 | * old PCI card uses the special PCI copy. |
| 1088 | * Moreover, the ISA card will work with the |
| 1089 | * special PCI copy anyway. -- REW */ |
| 1090 | hp->Mode = 0; |
| 1091 | spin_lock_init(&hp->HostLock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1093 | vpdp = get_VPD_PROM(hp); |
| 1094 | rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n"); |
| 1095 | okboard = 0; |
| 1096 | if ((strncmp(vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) { |
| 1097 | /* Board is present... */ |
Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 1098 | if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1099 | /* ... and feeling fine!!!! */ |
| 1100 | rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); |
| 1101 | if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) { |
| 1102 | rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum); |
| 1103 | okboard++; |
| 1104 | found++; |
| 1105 | } |
| 1106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
Amol Lad | 8684265 | 2006-12-06 20:35:19 -0800 | [diff] [blame] | 1108 | if (!okboard) { |
Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 1109 | iounmap(hp->Caddr); |
Amol Lad | 8684265 | 2006-12-06 20:35:19 -0800 | [diff] [blame] | 1110 | hp->Caddr = NULL; |
| 1111 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1112 | } |
| 1113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
| 1115 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1116 | for (i = 0; i < p->RIONumHosts; i++) { |
| 1117 | hp = &p->RIOHosts[i]; |
| 1118 | if (hp->Ivec) { |
Thomas Gleixner | 5d8c8a2 | 2006-07-01 19:29:41 -0700 | [diff] [blame] | 1119 | int mode = IRQF_SHARED; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1120 | if (hp->Ivec & 0x8000) { |
| 1121 | mode = 0; |
| 1122 | hp->Ivec &= 0x7fff; |
| 1123 | } |
| 1124 | rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode); |
| 1125 | retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp); |
| 1126 | rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval); |
| 1127 | if (retval) { |
| 1128 | printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec); |
| 1129 | hp->Ivec = 0; |
| 1130 | } |
| 1131 | rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec); |
| 1132 | if (hp->Ivec != 0) { |
| 1133 | rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n"); |
| 1134 | hp->Mode |= RIO_PCI_INT_ENABLE; |
| 1135 | } else |
Willy Tarreau | 88dacbe | 2007-02-17 18:57:09 +0100 | [diff] [blame] | 1136 | hp->Mode &= ~RIO_PCI_INT_ENABLE; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1137 | rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode); |
| 1138 | rio_start_card_running(hp); |
| 1139 | } |
| 1140 | /* Init the timer "always" to make sure that it can safely be |
| 1141 | deleted when we unload... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | |
Jiri Slaby | 40565f1 | 2007-02-12 00:52:31 -0800 | [diff] [blame] | 1143 | setup_timer(&hp->timer, rio_pollfunc, i); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1144 | if (!hp->Ivec) { |
| 1145 | rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll); |
Jiri Slaby | 40565f1 | 2007-02-12 00:52:31 -0800 | [diff] [blame] | 1146 | mod_timer(&hp->timer, jiffies + rio_poll); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1147 | } |
| 1148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1150 | if (found) { |
| 1151 | rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found); |
| 1152 | rio_init_drivers(); |
| 1153 | } else { |
| 1154 | /* deregister the misc device we created earlier */ |
| 1155 | misc_deregister(&rio_fw_device); |
| 1156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1158 | func_exit(); |
| 1159 | return found ? 0 : -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1163 | static void __exit rio_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1165 | int i; |
| 1166 | struct Host *hp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1168 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1170 | for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) { |
| 1171 | RIOHostReset(hp->Type, hp->CardP, hp->Slot); |
| 1172 | if (hp->Ivec) { |
| 1173 | free_irq(hp->Ivec, hp); |
| 1174 | rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec); |
| 1175 | } |
| 1176 | /* It is safe/allowed to del_timer a non-active timer */ |
Jiri Slaby | 40565f1 | 2007-02-12 00:52:31 -0800 | [diff] [blame] | 1177 | del_timer_sync(&hp->timer); |
Amol Lad | 8684265 | 2006-12-06 20:35:19 -0800 | [diff] [blame] | 1178 | if (hp->Caddr) |
| 1179 | iounmap(hp->Caddr); |
Jiri Slaby | 86fbf14 | 2006-10-21 10:24:01 -0700 | [diff] [blame] | 1180 | if (hp->Type == RIO_PCI) |
| 1181 | pci_dev_put(hp->pdev); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | if (misc_deregister(&rio_fw_device) < 0) { |
| 1185 | printk(KERN_INFO "rio: couldn't deregister control-device\n"); |
| 1186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
| 1188 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1189 | rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1191 | rio_release_drivers(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1193 | /* Release dynamically allocated memory */ |
| 1194 | kfree(p->RIOPortp); |
| 1195 | kfree(p->RIOHosts); |
| 1196 | kfree(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 1198 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | module_init(rio_init); |
| 1202 | module_exit(rio_exit); |