Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /************************************************************ |
| 2 | * * |
| 3 | * Linux EATA SCSI PIO driver * |
| 4 | * * |
| 5 | * based on the CAM document CAM/89-004 rev. 2.0c, * |
| 6 | * DPT's driver kit, some internal documents and source, * |
| 7 | * and several other Linux scsi drivers and kernel docs. * |
| 8 | * * |
| 9 | * The driver currently: * |
| 10 | * -supports all EATA-PIO boards * |
| 11 | * -only supports DASD devices * |
| 12 | * * |
| 13 | * (c)1993-96 Michael Neuffer, Alfred Arnold * |
| 14 | * neuffer@goofy.zdv.uni-mainz.de * |
| 15 | * a.arnold@kfa-juelich.de * |
| 16 | * * |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 17 | * Updated 2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> for * |
| 18 | * Linux 2.5.x and the newer locking and error handling * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * * |
| 20 | * This program is free software; you can redistribute it * |
| 21 | * and/or modify it under the terms of the GNU General * |
| 22 | * Public License as published by the Free Software * |
| 23 | * Foundation; either version 2 of the License, or * |
| 24 | * (at your option) any later version. * |
| 25 | * * |
| 26 | * This program is distributed in the hope that it will be * |
| 27 | * useful, but WITHOUT ANY WARRANTY; without even the * |
| 28 | * implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 29 | * PARTICULAR PURPOSE. See the GNU General Public License * |
| 30 | * for more details. * |
| 31 | * * |
| 32 | * You should have received a copy of the GNU General * |
| 33 | * Public License along with this kernel; if not, write to * |
| 34 | * the Free Software Foundation, Inc., 675 Mass Ave, * |
| 35 | * Cambridge, MA 02139, USA. * |
| 36 | * * |
| 37 | * For the avoidance of doubt the "preferred form" of this * |
| 38 | * code is one which is in an open non patent encumbered * |
| 39 | * format. Where cryptographic key signing forms part of * |
| 40 | * the process of creating an executable the information * |
| 41 | * including keys needed to generate an equivalently * |
| 42 | * functional executable are deemed to be part of the * |
| 43 | * source code are deemed to be part of the source code. * |
| 44 | * * |
| 45 | ************************************************************ |
| 46 | * last change: 2002/11/02 OS: Linux 2.5.45 * |
| 47 | ************************************************************/ |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/module.h> |
| 50 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/string.h> |
| 52 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <linux/in.h> |
| 54 | #include <linux/pci.h> |
| 55 | #include <linux/proc_fs.h> |
| 56 | #include <linux/interrupt.h> |
| 57 | #include <linux/blkdev.h> |
| 58 | #include <linux/spinlock.h> |
| 59 | #include <linux/delay.h> |
| 60 | |
| 61 | #include <asm/io.h> |
| 62 | |
| 63 | #include <scsi/scsi.h> |
| 64 | #include <scsi/scsi_cmnd.h> |
| 65 | #include <scsi/scsi_device.h> |
| 66 | #include <scsi/scsi_host.h> |
| 67 | |
| 68 | #include "eata_generic.h" |
| 69 | #include "eata_pio.h" |
| 70 | |
| 71 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 72 | static unsigned int ISAbases[MAXISA] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | 0x1F0, 0x170, 0x330, 0x230 |
| 74 | }; |
| 75 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 76 | static unsigned int ISAirqs[MAXISA] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | 14, 12, 15, 11 |
| 78 | }; |
| 79 | |
| 80 | static unsigned char EISAbases[] = { |
| 81 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 82 | 1, 1, 1, 1, 1, 1, 1, 1 |
| 83 | }; |
| 84 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 85 | static unsigned int registered_HBAs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | static struct Scsi_Host *last_HBA; |
| 87 | static struct Scsi_Host *first_HBA; |
| 88 | static unsigned char reg_IRQ[16]; |
| 89 | static unsigned char reg_IRQL[16]; |
| 90 | static unsigned long int_counter; |
| 91 | static unsigned long queue_counter; |
| 92 | |
| 93 | static struct scsi_host_template driver_template; |
| 94 | |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 95 | static int eata_pio_show_info(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 97 | seq_printf(m, "EATA (Extended Attachment) PIO driver version: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | "%d.%d%s\n",VER_MAJOR, VER_MINOR, VER_SUB); |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 99 | seq_printf(m, "queued commands: %10ld\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | "processed interrupts:%10ld\n", queue_counter, int_counter); |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 101 | seq_printf(m, "\nscsi%-2d: HBA %.10s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | shost->host_no, SD(shost)->name); |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 103 | seq_printf(m, "Firmware revision: v%s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | SD(shost)->revision); |
Rasmus Villemoes | 91c40f2 | 2014-12-03 00:10:52 +0100 | [diff] [blame] | 105 | seq_puts(m, "IO: PIO\n"); |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 106 | seq_printf(m, "Base IO : %#.4x\n", (u32) shost->base); |
| 107 | seq_printf(m, "Host Bus: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | (SD(shost)->bustype == 'P')?"PCI ": |
| 109 | (SD(shost)->bustype == 'E')?"EISA":"ISA "); |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 110 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static int eata_pio_release(struct Scsi_Host *sh) |
| 114 | { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 115 | hostdata *hd = SD(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | if (sh->irq && reg_IRQ[sh->irq] == 1) |
| 117 | free_irq(sh->irq, NULL); |
| 118 | else |
| 119 | reg_IRQ[sh->irq]--; |
| 120 | if (SD(sh)->channel == 0) { |
| 121 | if (sh->io_port && sh->n_io_port) |
| 122 | release_region(sh->io_port, sh->n_io_port); |
| 123 | } |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 124 | /* At this point the PCI reference can go */ |
| 125 | if (hd->pdev) |
| 126 | pci_dev_put(hd->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return 1; |
| 128 | } |
| 129 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 130 | static void IncStat(struct scsi_pointer *SCp, unsigned int Increment) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
| 132 | SCp->ptr += Increment; |
| 133 | if ((SCp->this_residual -= Increment) == 0) { |
| 134 | if ((--SCp->buffers_residual) == 0) |
| 135 | SCp->Status = 0; |
| 136 | else { |
| 137 | SCp->buffer++; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 138 | SCp->ptr = sg_virt(SCp->buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | SCp->this_residual = SCp->buffer->length; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 144 | static irqreturn_t eata_pio_int_handler(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 146 | static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | unsigned long flags; |
| 149 | struct Scsi_Host *dev = dev_id; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 150 | irqreturn_t ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | spin_lock_irqsave(dev->host_lock, flags); |
Alan Cox | a31baca | 2006-10-19 23:28:33 -0700 | [diff] [blame] | 153 | ret = eata_pio_int_handler(irq, dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | spin_unlock_irqrestore(dev->host_lock, flags); |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 155 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 158 | static irqreturn_t eata_pio_int_handler(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 160 | unsigned int eata_stat = 0xfffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | struct scsi_cmnd *cmd; |
| 162 | hostdata *hd; |
| 163 | struct eata_ccb *cp; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 164 | unsigned long base; |
| 165 | unsigned int x, z; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | struct Scsi_Host *sh; |
| 167 | unsigned short zwickel = 0; |
| 168 | unsigned char stat, odd; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 169 | irqreturn_t ret = IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) |
| 172 | { |
| 173 | if (sh->irq != irq) |
| 174 | continue; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 175 | if (inb(sh->base + HA_RSTATUS) & HA_SBUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | continue; |
| 177 | |
| 178 | int_counter++; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 179 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | hd = SD(sh); |
| 182 | |
| 183 | cp = &hd->ccb[0]; |
| 184 | cmd = cp->cmd; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 185 | base = cmd->device->host->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | do { |
| 188 | stat = inb(base + HA_RSTATUS); |
| 189 | if (stat & HA_SDRQ) { |
| 190 | if (cp->DataIn) { |
| 191 | z = 256; |
| 192 | odd = 0; |
| 193 | while ((cmd->SCp.Status) && ((z > 0) || (odd))) { |
| 194 | if (odd) { |
| 195 | *(cmd->SCp.ptr) = zwickel >> 8; |
| 196 | IncStat(&cmd->SCp, 1); |
| 197 | odd = 0; |
| 198 | } |
| 199 | x = min_t(unsigned int, z, cmd->SCp.this_residual / 2); |
| 200 | insw(base + HA_RDATA, cmd->SCp.ptr, x); |
| 201 | z -= x; |
| 202 | IncStat(&cmd->SCp, 2 * x); |
| 203 | if ((z > 0) && (cmd->SCp.this_residual == 1)) { |
| 204 | zwickel = inw(base + HA_RDATA); |
| 205 | *(cmd->SCp.ptr) = zwickel & 0xff; |
| 206 | IncStat(&cmd->SCp, 1); |
| 207 | z--; |
| 208 | odd = 1; |
| 209 | } |
| 210 | } |
| 211 | while (z > 0) { |
| 212 | zwickel = inw(base + HA_RDATA); |
| 213 | z--; |
| 214 | } |
| 215 | } else { /* cp->DataOut */ |
| 216 | |
| 217 | odd = 0; |
| 218 | z = 256; |
| 219 | while ((cmd->SCp.Status) && ((z > 0) || (odd))) { |
| 220 | if (odd) { |
| 221 | zwickel += *(cmd->SCp.ptr) << 8; |
| 222 | IncStat(&cmd->SCp, 1); |
| 223 | outw(zwickel, base + HA_RDATA); |
| 224 | z--; |
| 225 | odd = 0; |
| 226 | } |
| 227 | x = min_t(unsigned int, z, cmd->SCp.this_residual / 2); |
| 228 | outsw(base + HA_RDATA, cmd->SCp.ptr, x); |
| 229 | z -= x; |
| 230 | IncStat(&cmd->SCp, 2 * x); |
| 231 | if ((z > 0) && (cmd->SCp.this_residual == 1)) { |
| 232 | zwickel = *(cmd->SCp.ptr); |
| 233 | zwickel &= 0xff; |
| 234 | IncStat(&cmd->SCp, 1); |
| 235 | odd = 1; |
| 236 | } |
| 237 | } |
| 238 | while (z > 0 || odd) { |
| 239 | outw(zwickel, base + HA_RDATA); |
| 240 | z--; |
| 241 | odd = 0; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | while ((stat & HA_SDRQ) || ((stat & HA_SMORE) && hd->moresupport)); |
| 247 | |
| 248 | /* terminate handler if HBA goes busy again, i.e. transfers |
| 249 | * more data */ |
| 250 | |
| 251 | if (stat & HA_SBUSY) |
| 252 | break; |
| 253 | |
| 254 | /* OK, this is quite stupid, but I haven't found any correct |
| 255 | * way to get HBA&SCSI status so far */ |
| 256 | |
| 257 | if (!(inb(base + HA_RSTATUS) & HA_SERROR)) { |
| 258 | cmd->result = (DID_OK << 16); |
| 259 | hd->devflags |= (1 << cp->cp_id); |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 260 | } else if (hd->devflags & (1 << cp->cp_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | cmd->result = (DID_OK << 16) + 0x02; |
| 262 | else |
| 263 | cmd->result = (DID_NO_CONNECT << 16); |
| 264 | |
| 265 | if (cp->status == LOCKED) { |
| 266 | cp->status = FREE; |
| 267 | eata_stat = inb(base + HA_RSTATUS); |
| 268 | printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n"); |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 269 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | #if DBG_INTR2 |
| 272 | if (stat != 0x50) |
| 273 | printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat, cmd->result); |
| 274 | #endif |
| 275 | |
| 276 | cp->status = FREE; /* now we can release the slot */ |
| 277 | |
| 278 | cmd->scsi_done(cmd); |
| 279 | } |
| 280 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 281 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 284 | static inline unsigned int eata_pio_send_command(unsigned long base, unsigned char command) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 286 | unsigned int loop = 50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | while (inb(base + HA_RSTATUS) & HA_SBUSY) |
| 289 | if (--loop == 0) |
| 290 | return 1; |
| 291 | |
| 292 | /* Enable interrupts for HBA. It is not the best way to do it at this |
| 293 | * place, but I hope that it doesn't interfere with the IDE driver |
| 294 | * initialization this way */ |
| 295 | |
| 296 | outb(HA_CTRL_8HEADS, base + HA_CTRLREG); |
| 297 | |
| 298 | outb(command, base + HA_WCOMMAND); |
| 299 | return 0; |
| 300 | } |
| 301 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 302 | static int eata_pio_queue_lck(struct scsi_cmnd *cmd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | void (*done)(struct scsi_cmnd *)) |
| 304 | { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 305 | unsigned int x, y; |
| 306 | unsigned long base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | hostdata *hd; |
| 309 | struct Scsi_Host *sh; |
| 310 | struct eata_ccb *cp; |
| 311 | |
| 312 | queue_counter++; |
| 313 | |
| 314 | hd = HD(cmd); |
| 315 | sh = cmd->device->host; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 316 | base = sh->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | /* use only slot 0, as 2001 can handle only one cmd at a time */ |
| 319 | |
| 320 | y = x = 0; |
| 321 | |
| 322 | if (hd->ccb[y].status != FREE) { |
| 323 | |
| 324 | DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n", sh->can_queue, x, y)); |
| 325 | #if DEBUG_EATA |
| 326 | panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter, int_counter); |
| 327 | #else |
| 328 | panic(KERN_EMERG "eata_pio: run out of queue slots....\n"); |
| 329 | #endif |
| 330 | } |
| 331 | |
| 332 | cp = &hd->ccb[y]; |
| 333 | |
| 334 | memset(cp, 0, sizeof(struct eata_ccb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | cp->status = USED; /* claim free slot */ |
| 337 | |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 338 | DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 339 | "eata_pio_queue 0x%p, y %d\n", cmd, y)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | cmd->scsi_done = (void *) done; |
| 342 | |
| 343 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 344 | cp->DataOut = 1; /* Output mode */ |
| 345 | else |
| 346 | cp->DataIn = 0; /* Input mode */ |
| 347 | |
| 348 | cp->Interpret = (cmd->device->id == hd->hostid); |
Boaz Harrosh | 7410d84 | 2007-09-09 21:10:27 +0300 | [diff] [blame] | 349 | cp->cp_datalen = cpu_to_be32(scsi_bufflen(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | cp->Auto_Req_Sen = 0; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 351 | cp->cp_reqDMA = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | cp->reqlen = 0; |
| 353 | |
| 354 | cp->cp_id = cmd->device->id; |
| 355 | cp->cp_lun = cmd->device->lun; |
| 356 | cp->cp_dispri = 0; |
| 357 | cp->cp_identify = 1; |
| 358 | memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd)); |
| 359 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 360 | cp->cp_statDMA = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | cp->cp_viraddr = cp; |
| 363 | cp->cmd = cmd; |
| 364 | cmd->host_scribble = (char *) &hd->ccb[y]; |
| 365 | |
Boaz Harrosh | 7410d84 | 2007-09-09 21:10:27 +0300 | [diff] [blame] | 366 | if (!scsi_bufflen(cmd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | cmd->SCp.buffers_residual = 1; |
Boaz Harrosh | 7410d84 | 2007-09-09 21:10:27 +0300 | [diff] [blame] | 368 | cmd->SCp.ptr = NULL; |
| 369 | cmd->SCp.this_residual = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | cmd->SCp.buffer = NULL; |
| 371 | } else { |
Boaz Harrosh | 7410d84 | 2007-09-09 21:10:27 +0300 | [diff] [blame] | 372 | cmd->SCp.buffer = scsi_sglist(cmd); |
| 373 | cmd->SCp.buffers_residual = scsi_sg_count(cmd); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 374 | cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | cmd->SCp.this_residual = cmd->SCp.buffer->length; |
| 376 | } |
| 377 | cmd->SCp.Status = (cmd->SCp.this_residual != 0); /* TRUE as long as bytes |
| 378 | * are to transfer */ |
| 379 | |
| 380 | if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) { |
| 381 | cmd->result = DID_BUS_BUSY << 16; |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 382 | scmd_printk(KERN_NOTICE, cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 383 | "eata_pio_queue pid 0x%p, HBA busy, " |
| 384 | "returning DID_BUS_BUSY, done.\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | done(cmd); |
| 386 | cp->status = FREE; |
Alan Cox | 1a1d641 | 2007-09-20 15:15:27 +0100 | [diff] [blame] | 387 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | /* FIXME: timeout */ |
| 390 | while (!(inb(base + HA_RSTATUS) & HA_SDRQ)) |
| 391 | cpu_relax(); |
| 392 | outsw(base + HA_RDATA, cp, hd->cplen); |
| 393 | outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND); |
| 394 | for (x = 0; x < hd->cppadlen; x++) |
| 395 | outw(0, base + HA_RDATA); |
| 396 | |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 397 | DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 398 | "Queued base %#.4lx cmd: 0x%p " |
| 399 | "slot %d irq %d\n", sh->base, cmd, y, sh->irq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Alan Cox | 1a1d641 | 2007-09-20 15:15:27 +0100 | [diff] [blame] | 401 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 404 | static DEF_SCSI_QCMD(eata_pio_queue) |
| 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | static int eata_pio_abort(struct scsi_cmnd *cmd) |
| 407 | { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 408 | unsigned int loop = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 410 | DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 411 | "eata_pio_abort called pid: 0x%p\n", cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | while (inb(cmd->device->host->base + HA_RAUXSTAT) & HA_ABUSY) |
| 414 | if (--loop == 0) { |
| 415 | printk(KERN_WARNING "eata_pio: abort, timeout error.\n"); |
| 416 | return FAILED; |
| 417 | } |
| 418 | if (CD(cmd)->status == FREE) { |
| 419 | DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING\n")); |
| 420 | return FAILED; |
| 421 | } |
| 422 | if (CD(cmd)->status == USED) { |
| 423 | DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY\n")); |
| 424 | /* We want to sleep a bit more here */ |
| 425 | return FAILED; /* SNOOZE */ |
| 426 | } |
| 427 | if (CD(cmd)->status == RESET) { |
| 428 | printk(KERN_WARNING "eata_pio: abort, command reset error.\n"); |
| 429 | return FAILED; |
| 430 | } |
| 431 | if (CD(cmd)->status == LOCKED) { |
| 432 | DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot " "locked.\n")); |
| 433 | return FAILED; |
| 434 | } |
| 435 | panic("eata_pio: abort: invalid slot status\n"); |
| 436 | } |
| 437 | |
| 438 | static int eata_pio_host_reset(struct scsi_cmnd *cmd) |
| 439 | { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 440 | unsigned int x, limit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | unsigned char success = 0; |
| 442 | struct scsi_cmnd *sp; |
| 443 | struct Scsi_Host *host = cmd->device->host; |
| 444 | |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 445 | DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 446 | "eata_pio_reset called\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 448 | spin_lock_irq(host->host_lock); |
| 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if (HD(cmd)->state == RESET) { |
| 451 | printk(KERN_WARNING "eata_pio_reset: exit, already in reset.\n"); |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 452 | spin_unlock_irq(host->host_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | return FAILED; |
| 454 | } |
| 455 | |
| 456 | /* force all slots to be free */ |
| 457 | |
| 458 | for (x = 0; x < cmd->device->host->can_queue; x++) { |
| 459 | |
| 460 | if (HD(cmd)->ccb[x].status == FREE) |
| 461 | continue; |
| 462 | |
| 463 | sp = HD(cmd)->ccb[x].cmd; |
| 464 | HD(cmd)->ccb[x].status = RESET; |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 465 | printk(KERN_WARNING "eata_pio_reset: slot %d in reset.\n", x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | if (sp == NULL) |
| 468 | panic("eata_pio_reset: slot %d, sp==NULL.\n", x); |
| 469 | } |
| 470 | |
| 471 | /* hard reset the HBA */ |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 472 | outb(EATA_CMD_RESET, cmd->device->host->base + HA_WCOMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n")); |
| 475 | HD(cmd)->state = RESET; |
| 476 | |
| 477 | spin_unlock_irq(host->host_lock); |
| 478 | msleep(3000); |
| 479 | spin_lock_irq(host->host_lock); |
| 480 | |
| 481 | DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, " "loops %d.\n", limit)); |
| 482 | |
| 483 | for (x = 0; x < cmd->device->host->can_queue; x++) { |
| 484 | |
| 485 | /* Skip slots already set free by interrupt */ |
| 486 | if (HD(cmd)->ccb[x].status != RESET) |
| 487 | continue; |
| 488 | |
| 489 | sp = HD(cmd)->ccb[x].cmd; |
| 490 | sp->result = DID_RESET << 16; |
| 491 | |
| 492 | /* This mailbox is terminated */ |
| 493 | printk(KERN_WARNING "eata_pio_reset: reset ccb %d.\n", x); |
| 494 | HD(cmd)->ccb[x].status = FREE; |
| 495 | |
| 496 | sp->scsi_done(sp); |
| 497 | } |
| 498 | |
| 499 | HD(cmd)->state = 0; |
| 500 | |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 501 | spin_unlock_irq(host->host_lock); |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | if (success) { /* hmmm... */ |
| 504 | DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.\n")); |
| 505 | return SUCCESS; |
| 506 | } else { |
| 507 | DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.\n")); |
| 508 | return FAILED; |
| 509 | } |
| 510 | } |
| 511 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 512 | static char *get_pio_board_data(unsigned long base, unsigned int irq, unsigned int id, unsigned long cplen, unsigned short cppadlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
| 514 | struct eata_ccb cp; |
| 515 | static char buff[256]; |
| 516 | int z; |
| 517 | |
| 518 | memset(&cp, 0, sizeof(struct eata_ccb)); |
| 519 | memset(buff, 0, sizeof(buff)); |
| 520 | |
| 521 | cp.DataIn = 1; |
| 522 | cp.Interpret = 1; /* Interpret command */ |
| 523 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 524 | cp.cp_datalen = cpu_to_be32(254); |
| 525 | cp.cp_dataDMA = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | cp.cp_id = id; |
| 528 | cp.cp_lun = 0; |
| 529 | |
| 530 | cp.cp_cdb[0] = INQUIRY; |
| 531 | cp.cp_cdb[1] = 0; |
| 532 | cp.cp_cdb[2] = 0; |
| 533 | cp.cp_cdb[3] = 0; |
| 534 | cp.cp_cdb[4] = 254; |
| 535 | cp.cp_cdb[5] = 0; |
| 536 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 537 | if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) |
Alan Cox | 1a1d641 | 2007-09-20 15:15:27 +0100 | [diff] [blame] | 538 | return NULL; |
| 539 | |
| 540 | while (!(inb(base + HA_RSTATUS) & HA_SDRQ)) |
| 541 | cpu_relax(); |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | outsw(base + HA_RDATA, &cp, cplen); |
| 544 | outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND); |
| 545 | for (z = 0; z < cppadlen; z++) |
| 546 | outw(0, base + HA_RDATA); |
| 547 | |
Alan Cox | 1a1d641 | 2007-09-20 15:15:27 +0100 | [diff] [blame] | 548 | while (inb(base + HA_RSTATUS) & HA_SBUSY) |
| 549 | cpu_relax(); |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | if (inb(base + HA_RSTATUS) & HA_SERROR) |
Alan Cox | 1a1d641 | 2007-09-20 15:15:27 +0100 | [diff] [blame] | 552 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | else if (!(inb(base + HA_RSTATUS) & HA_SDRQ)) |
Alan Cox | 1a1d641 | 2007-09-20 15:15:27 +0100 | [diff] [blame] | 554 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | else { |
| 556 | insw(base + HA_RDATA, &buff, 127); |
| 557 | while (inb(base + HA_RSTATUS) & HA_SDRQ) |
| 558 | inw(base + HA_RDATA); |
Alan Cox | 1a1d641 | 2007-09-20 15:15:27 +0100 | [diff] [blame] | 559 | return buff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 563 | static int get_pio_conf_PIO(unsigned long base, struct get_conf *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
| 565 | unsigned long loop = HZ / 2; |
| 566 | int z; |
| 567 | unsigned short *p; |
| 568 | |
| 569 | if (!request_region(base, 9, "eata_pio")) |
| 570 | return 0; |
| 571 | |
| 572 | memset(buf, 0, sizeof(struct get_conf)); |
| 573 | |
| 574 | while (inb(base + HA_RSTATUS) & HA_SBUSY) |
| 575 | if (--loop == 0) |
| 576 | goto fail; |
| 577 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 578 | DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#lx\n", base)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG); |
| 580 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 581 | loop = 50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) { |
| 583 | while (!(inb(base + HA_RSTATUS) & HA_SDRQ)) |
| 584 | if (--loop == 0) |
| 585 | goto fail; |
| 586 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 587 | loop = 50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | *p = inw(base + HA_RDATA); |
| 589 | } |
| 590 | if (inb(base + HA_RSTATUS) & HA_SERROR) { |
| 591 | DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during " |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 592 | "transfer for HBA at %lx\n", base)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | goto fail; |
| 594 | } |
| 595 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 596 | if (cpu_to_be32(EATA_SIGNATURE) != buf->signature) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | goto fail; |
| 598 | |
| 599 | DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found " |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 600 | "at %#4lx EATA Level: %x\n", |
| 601 | base, (unsigned int) (buf->version))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
| 603 | while (inb(base + HA_RSTATUS) & HA_SDRQ) |
| 604 | inw(base + HA_RDATA); |
| 605 | |
| 606 | if (!ALLOW_DMA_BOARDS) { |
| 607 | for (z = 0; z < MAXISA; z++) |
| 608 | if (base == ISAbases[z]) { |
| 609 | buf->IRQ = ISAirqs[z]; |
| 610 | break; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | return 1; |
| 615 | |
| 616 | fail: |
| 617 | release_region(base, 9); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | static void print_pio_config(struct get_conf *gc) |
| 622 | { |
| 623 | printk("Please check values: (read config data)\n"); |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 624 | printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", be32_to_cpu(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support); |
| 625 | printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], be16_to_cpu(gc->queuesiz), be16_to_cpu(gc->SGsiz), gc->SECOND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest); |
| 627 | } |
| 628 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 629 | static unsigned int print_selftest(unsigned int base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | unsigned char buffer[512]; |
| 632 | #ifdef VERBOSE_SETUP |
| 633 | int z; |
| 634 | #endif |
| 635 | |
| 636 | printk("eata_pio: executing controller self test & setup...\n"); |
| 637 | while (inb(base + HA_RSTATUS) & HA_SBUSY); |
| 638 | outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND); |
| 639 | do { |
| 640 | while (inb(base + HA_RSTATUS) & HA_SBUSY) |
| 641 | /* nothing */ ; |
| 642 | if (inb(base + HA_RSTATUS) & HA_SDRQ) { |
| 643 | insw(base + HA_RDATA, &buffer, 256); |
| 644 | #ifdef VERBOSE_SETUP |
| 645 | /* no beeps please... */ |
| 646 | for (z = 0; z < 511 && buffer[z]; z++) |
| 647 | if (buffer[z] != 7) |
| 648 | printk("%c", buffer[z]); |
| 649 | #endif |
| 650 | } |
| 651 | } while (inb(base + HA_RSTATUS) & (HA_SBUSY | HA_SDRQ)); |
| 652 | |
| 653 | return (!(inb(base + HA_RSTATUS) & HA_SERROR)); |
| 654 | } |
| 655 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 656 | static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
| 658 | unsigned long size = 0; |
| 659 | char *buff; |
| 660 | unsigned long cplen; |
| 661 | unsigned short cppadlen; |
| 662 | struct Scsi_Host *sh; |
| 663 | hostdata *hd; |
| 664 | |
| 665 | DBG(DBG_REGISTER, print_pio_config(gc)); |
| 666 | |
| 667 | if (gc->DMA_support) { |
| 668 | printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base); |
| 669 | if (!ALLOW_DMA_BOARDS) |
| 670 | return 0; |
| 671 | } |
| 672 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 673 | if ((buff = get_pio_board_data(base, gc->IRQ, gc->scsi_id[3], cplen = (cpu_to_be32(gc->cplen) + 1) / 2, cppadlen = (cpu_to_be16(gc->cppadlen) + 1) / 2)) == NULL) { |
| 674 | printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | if (!print_selftest(base) && !ALLOW_DMA_BOARDS) { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 679 | printk("HBA at %#lx failed while performing self test & setup.\n", base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | return 0; |
| 681 | } |
| 682 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 683 | size = sizeof(hostdata) + (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
| 685 | sh = scsi_register(&driver_template, size); |
| 686 | if (sh == NULL) |
| 687 | return 0; |
| 688 | |
| 689 | if (!reg_IRQ[gc->IRQ]) { /* Interrupt already registered ? */ |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 690 | if (!request_irq(gc->IRQ, do_eata_pio_int_handler, 0, "EATA-PIO", sh)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | reg_IRQ[gc->IRQ]++; |
| 692 | if (!gc->IRQ_TR) |
| 693 | reg_IRQL[gc->IRQ] = 1; /* IRQ is edge triggered */ |
| 694 | } else { |
| 695 | printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ); |
| 696 | return 0; |
| 697 | } |
| 698 | } else { /* More than one HBA on this IRQ */ |
| 699 | if (reg_IRQL[gc->IRQ]) { |
| 700 | printk("Can't support more than one HBA on this IRQ,\n" " if the IRQ is edge triggered. Sorry.\n"); |
| 701 | return 0; |
| 702 | } else |
| 703 | reg_IRQ[gc->IRQ]++; |
| 704 | } |
| 705 | |
| 706 | hd = SD(sh); |
| 707 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 708 | memset(hd->ccb, 0, (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz))); |
| 709 | memset(hd->reads, 0, sizeof(hd->reads)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
| 711 | strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor)); |
| 712 | strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name)); |
| 713 | SD(sh)->revision[0] = buff[32]; |
| 714 | SD(sh)->revision[1] = buff[33]; |
| 715 | SD(sh)->revision[2] = buff[34]; |
| 716 | SD(sh)->revision[3] = '.'; |
| 717 | SD(sh)->revision[4] = buff[35]; |
| 718 | SD(sh)->revision[5] = 0; |
| 719 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 720 | switch (be32_to_cpu(gc->len)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | case 0x1c: |
| 722 | SD(sh)->EATA_revision = 'a'; |
| 723 | break; |
| 724 | case 0x1e: |
| 725 | SD(sh)->EATA_revision = 'b'; |
| 726 | break; |
| 727 | case 0x22: |
| 728 | SD(sh)->EATA_revision = 'c'; |
| 729 | break; |
| 730 | case 0x24: |
| 731 | SD(sh)->EATA_revision = 'z'; |
Dan Carpenter | b324f63 | 2016-05-04 09:13:41 +0300 | [diff] [blame] | 732 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | default: |
| 734 | SD(sh)->EATA_revision = '?'; |
| 735 | } |
| 736 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 737 | if (be32_to_cpu(gc->len) >= 0x22) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | if (gc->is_PCI) |
| 739 | hd->bustype = IS_PCI; |
| 740 | else if (gc->is_EISA) |
| 741 | hd->bustype = IS_EISA; |
| 742 | else |
| 743 | hd->bustype = IS_ISA; |
| 744 | } else { |
| 745 | if (buff[21] == '4') |
| 746 | hd->bustype = IS_PCI; |
| 747 | else if (buff[21] == '2') |
| 748 | hd->bustype = IS_EISA; |
| 749 | else |
| 750 | hd->bustype = IS_ISA; |
| 751 | } |
| 752 | |
| 753 | SD(sh)->cplen = cplen; |
| 754 | SD(sh)->cppadlen = cppadlen; |
| 755 | SD(sh)->hostid = gc->scsi_id[3]; |
| 756 | SD(sh)->devflags = 1 << gc->scsi_id[3]; |
| 757 | SD(sh)->moresupport = gc->MORE_support; |
| 758 | sh->unique_id = base; |
| 759 | sh->base = base; |
| 760 | sh->io_port = base; |
| 761 | sh->n_io_port = 9; |
| 762 | sh->irq = gc->IRQ; |
| 763 | sh->dma_channel = PIO; |
| 764 | sh->this_id = gc->scsi_id[3]; |
| 765 | sh->can_queue = 1; |
| 766 | sh->cmd_per_lun = 1; |
| 767 | sh->sg_tablesize = SG_ALL; |
| 768 | |
| 769 | hd->channel = 0; |
| 770 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 771 | hd->pdev = pci_dev_get(pdev); /* Keep a PCI reference */ |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | sh->max_id = 8; |
| 774 | sh->max_lun = 8; |
| 775 | |
| 776 | if (gc->SECOND) |
| 777 | hd->primary = 0; |
| 778 | else |
| 779 | hd->primary = 1; |
| 780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | hd->next = NULL; /* build a linked list of all HBAs */ |
| 782 | hd->prev = last_HBA; |
| 783 | if (hd->prev != NULL) |
| 784 | SD(hd->prev)->next = sh; |
| 785 | last_HBA = sh; |
| 786 | if (first_HBA == NULL) |
| 787 | first_HBA = sh; |
| 788 | registered_HBAs++; |
| 789 | return (1); |
| 790 | } |
| 791 | |
| 792 | static void find_pio_ISA(struct get_conf *buf) |
| 793 | { |
| 794 | int i; |
| 795 | |
| 796 | for (i = 0; i < MAXISA; i++) { |
| 797 | if (!ISAbases[i]) |
| 798 | continue; |
| 799 | if (!get_pio_conf_PIO(ISAbases[i], buf)) |
| 800 | continue; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 801 | if (!register_pio_HBA(ISAbases[i], buf, NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | release_region(ISAbases[i], 9); |
| 803 | else |
| 804 | ISAbases[i] = 0; |
| 805 | } |
| 806 | return; |
| 807 | } |
| 808 | |
| 809 | static void find_pio_EISA(struct get_conf *buf) |
| 810 | { |
| 811 | u32 base; |
| 812 | int i; |
| 813 | |
| 814 | #ifdef CHECKPAL |
| 815 | u8 pal1, pal2, pal3; |
| 816 | #endif |
| 817 | |
| 818 | for (i = 0; i < MAXEISA; i++) { |
| 819 | if (EISAbases[i]) { /* Still a possibility ? */ |
| 820 | |
| 821 | base = 0x1c88 + (i * 0x1000); |
| 822 | #ifdef CHECKPAL |
| 823 | pal1 = inb((u16) base - 8); |
| 824 | pal2 = inb((u16) base - 7); |
| 825 | pal3 = inb((u16) base - 6); |
| 826 | |
| 827 | if (((pal1 == 0x12) && (pal2 == 0x14)) || ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) || ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) { |
| 828 | DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: " "%x %x %x \n", (int) pal1, (int) pal2, (int) pal3)); |
| 829 | #endif |
| 830 | if (get_pio_conf_PIO(base, buf)) { |
| 831 | DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf)); |
| 832 | if (buf->IRQ) { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 833 | if (!register_pio_HBA(base, buf, NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | release_region(base, 9); |
| 835 | } else { |
| 836 | printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list\n"); |
| 837 | release_region(base, 9); |
| 838 | } |
| 839 | } |
| 840 | /* Nothing found here so we take it from the list */ |
| 841 | EISAbases[i] = 0; |
| 842 | #ifdef CHECKPAL |
| 843 | } |
| 844 | #endif |
| 845 | } |
| 846 | } |
| 847 | return; |
| 848 | } |
| 849 | |
| 850 | static void find_pio_PCI(struct get_conf *buf) |
| 851 | { |
| 852 | #ifndef CONFIG_PCI |
| 853 | printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n"); |
| 854 | #else |
| 855 | struct pci_dev *dev = NULL; |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 856 | unsigned long base, x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 858 | while ((dev = pci_get_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev))); |
| 860 | if (pci_enable_device(dev)) |
| 861 | continue; |
| 862 | pci_set_master(dev); |
| 863 | base = pci_resource_flags(dev, 0); |
| 864 | if (base & IORESOURCE_MEM) { |
| 865 | printk("eata_pio: invalid base address of device %s\n", pci_name(dev)); |
| 866 | continue; |
| 867 | } |
| 868 | base = pci_resource_start(dev, 0); |
| 869 | /* EISA tag there ? */ |
| 870 | if ((inb(base) == 0x12) && (inb(base + 1) == 0x14)) |
| 871 | continue; /* Jep, it's forced, so move on */ |
| 872 | base += 0x10; /* Now, THIS is the real address */ |
| 873 | if (base != 0x1f8) { |
| 874 | /* We didn't find it in the primary search */ |
| 875 | if (get_pio_conf_PIO(base, buf)) { |
| 876 | if (buf->FORCADR) { /* If the address is forced */ |
| 877 | release_region(base, 9); |
| 878 | continue; /* we'll find it later */ |
| 879 | } |
| 880 | |
| 881 | /* OK. We made it till here, so we can go now |
| 882 | * and register it. We only have to check and |
| 883 | * eventually remove it from the EISA and ISA list |
| 884 | */ |
| 885 | |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 886 | if (!register_pio_HBA(base, buf, dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | release_region(base, 9); |
| 888 | continue; |
| 889 | } |
| 890 | |
| 891 | if (base < 0x1000) { |
| 892 | for (x = 0; x < MAXISA; ++x) { |
| 893 | if (ISAbases[x] == base) { |
| 894 | ISAbases[x] = 0; |
| 895 | break; |
| 896 | } |
| 897 | } |
| 898 | } else if ((base & 0x0fff) == 0x0c88) { |
| 899 | x = (base >> 12) & 0x0f; |
| 900 | EISAbases[x] = 0; |
| 901 | } |
| 902 | } |
| 903 | #ifdef CHECK_BLINK |
| 904 | else if (check_blink_state(base)) { |
| 905 | printk("eata_pio: HBA is in BLINK state.\n" "Consult your HBAs manual to correct this.\n"); |
| 906 | } |
| 907 | #endif |
| 908 | } |
| 909 | } |
| 910 | #endif /* #ifndef CONFIG_PCI */ |
| 911 | } |
| 912 | |
| 913 | static int eata_pio_detect(struct scsi_host_template *tpnt) |
| 914 | { |
| 915 | struct Scsi_Host *HBA_ptr; |
| 916 | struct get_conf gc; |
| 917 | int i; |
| 918 | |
| 919 | find_pio_PCI(&gc); |
| 920 | find_pio_EISA(&gc); |
| 921 | find_pio_ISA(&gc); |
| 922 | |
Dan Carpenter | 127be35 | 2013-08-23 15:11:31 +0300 | [diff] [blame] | 923 | for (i = 0; i < MAXIRQ; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | if (reg_IRQ[i]) |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 925 | request_irq(i, do_eata_pio_int_handler, 0, "EATA-PIO", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
| 927 | HBA_ptr = first_HBA; |
| 928 | |
| 929 | if (registered_HBAs != 0) { |
| 930 | printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n" |
| 931 | "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n" " Alfred Arnold, a.arnold@kfa-juelich.de\n" "This release only supports DASD devices (harddisks)\n", VER_MAJOR, VER_MINOR, VER_SUB); |
| 932 | |
| 933 | printk("Registered HBAs:\n"); |
| 934 | printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n"); |
| 935 | for (i = 1; i <= registered_HBAs; i++) { |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 936 | printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4lx %2d %d %d %c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | " %2d %2d %2d\n", |
| 938 | HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision, |
| 939 | SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ? |
| 940 | "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ", |
Alan Cox | 1a68d41 | 2006-09-18 19:18:34 +0100 | [diff] [blame] | 941 | HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue, |
| 943 | HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun); |
| 944 | HBA_ptr = SD(HBA_ptr)->next; |
| 945 | } |
| 946 | } |
| 947 | return (registered_HBAs); |
| 948 | } |
| 949 | |
| 950 | static struct scsi_host_template driver_template = { |
| 951 | .proc_name = "eata_pio", |
| 952 | .name = "EATA (Extended Attachment) PIO driver", |
Al Viro | 8c98654 | 2013-03-31 03:18:35 -0400 | [diff] [blame] | 953 | .show_info = eata_pio_show_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | .detect = eata_pio_detect, |
| 955 | .release = eata_pio_release, |
| 956 | .queuecommand = eata_pio_queue, |
| 957 | .eh_abort_handler = eata_pio_abort, |
| 958 | .eh_host_reset_handler = eata_pio_host_reset, |
| 959 | .use_clustering = ENABLE_CLUSTERING, |
| 960 | }; |
| 961 | |
| 962 | MODULE_AUTHOR("Michael Neuffer, Alfred Arnold"); |
| 963 | MODULE_DESCRIPTION("EATA SCSI PIO driver"); |
| 964 | MODULE_LICENSE("GPL"); |
| 965 | |
| 966 | #include "scsi_module.c" |