Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1997 Wu Ching Chen |
| 3 | * 2.1.x update (C) 1998 Krzysztof G. Baranowski |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 4 | * 2.5.x update (C) 2002 Red Hat |
| 5 | * 2.6.x update (C) 2004 Red Hat |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Marcelo Tosatti <marcelo@conectiva.com.br> : SMP fixes |
| 8 | * |
| 9 | * Wu Ching Chen : NULL pointer fixes 2000/06/02 |
| 10 | * support atp876 chip |
| 11 | * enable 32 bit fifo transfer |
| 12 | * support cdrom & remove device run ultra speed |
| 13 | * fix disconnect bug 2000/12/21 |
| 14 | * support atp880 chip lvd u160 2001/05/15 |
| 15 | * fix prd table bug 2001/09/12 (7.1) |
| 16 | * |
| 17 | * atp885 support add by ACARD Hao Ping Lian 2005/01/05 |
| 18 | */ |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/string.h> |
| 25 | #include <linux/ioport.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/proc_fs.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/pci.h> |
| 30 | #include <linux/blkdev.h> |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 31 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/io.h> |
| 34 | |
| 35 | #include <scsi/scsi.h> |
| 36 | #include <scsi/scsi_cmnd.h> |
| 37 | #include <scsi/scsi_device.h> |
| 38 | #include <scsi/scsi_host.h> |
| 39 | |
| 40 | #include "atp870u.h" |
| 41 | |
| 42 | static struct scsi_host_template atp870u_template; |
| 43 | static void send_s870(struct atp_unit *dev,unsigned char c); |
Ondrej Zary | 4192a40 | 2015-11-17 19:24:06 +0100 | [diff] [blame] | 44 | static void atp_is(struct atp_unit *dev, unsigned char c, bool wide_chip, unsigned char lvdmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 46 | static inline void atp_writeb_base(struct atp_unit *atp, u8 reg, u8 val) |
| 47 | { |
| 48 | outb(val, atp->baseport + reg); |
| 49 | } |
| 50 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 51 | static inline void atp_writew_base(struct atp_unit *atp, u8 reg, u16 val) |
| 52 | { |
| 53 | outw(val, atp->baseport + reg); |
| 54 | } |
| 55 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 56 | static inline void atp_writeb_io(struct atp_unit *atp, u8 channel, u8 reg, u8 val) |
| 57 | { |
| 58 | outb(val, atp->ioport[channel] + reg); |
| 59 | } |
| 60 | |
| 61 | static inline void atp_writew_io(struct atp_unit *atp, u8 channel, u8 reg, u16 val) |
| 62 | { |
| 63 | outw(val, atp->ioport[channel] + reg); |
| 64 | } |
| 65 | |
| 66 | static inline void atp_writeb_pci(struct atp_unit *atp, u8 channel, u8 reg, u8 val) |
| 67 | { |
| 68 | outb(val, atp->pciport[channel] + reg); |
| 69 | } |
| 70 | |
| 71 | static inline void atp_writel_pci(struct atp_unit *atp, u8 channel, u8 reg, u32 val) |
| 72 | { |
| 73 | outl(val, atp->pciport[channel] + reg); |
| 74 | } |
| 75 | |
| 76 | static inline u8 atp_readb_base(struct atp_unit *atp, u8 reg) |
| 77 | { |
| 78 | return inb(atp->baseport + reg); |
| 79 | } |
| 80 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 81 | static inline u16 atp_readw_base(struct atp_unit *atp, u8 reg) |
| 82 | { |
| 83 | return inw(atp->baseport + reg); |
| 84 | } |
| 85 | |
| 86 | static inline u32 atp_readl_base(struct atp_unit *atp, u8 reg) |
| 87 | { |
| 88 | return inl(atp->baseport + reg); |
| 89 | } |
| 90 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 91 | static inline u8 atp_readb_io(struct atp_unit *atp, u8 channel, u8 reg) |
| 92 | { |
| 93 | return inb(atp->ioport[channel] + reg); |
| 94 | } |
| 95 | |
| 96 | static inline u16 atp_readw_io(struct atp_unit *atp, u8 channel, u8 reg) |
| 97 | { |
| 98 | return inw(atp->ioport[channel] + reg); |
| 99 | } |
| 100 | |
| 101 | static inline u8 atp_readb_pci(struct atp_unit *atp, u8 channel, u8 reg) |
| 102 | { |
| 103 | return inb(atp->pciport[channel] + reg); |
| 104 | } |
| 105 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 106 | static irqreturn_t atp870u_intr_handle(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
| 108 | unsigned long flags; |
Ondrej Zary | bc0fe4c | 2015-11-17 19:23:47 +0100 | [diff] [blame] | 109 | unsigned short int id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | unsigned char i, j, c, target_id, lun,cmdp; |
| 111 | unsigned char *prd; |
| 112 | struct scsi_cmnd *workreq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | unsigned long adrcnt, k; |
| 114 | #ifdef ED_DBGP |
| 115 | unsigned long l; |
| 116 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | struct Scsi_Host *host = dev_id; |
| 118 | struct atp_unit *dev = (struct atp_unit *)&host->hostdata; |
| 119 | |
| 120 | for (c = 0; c < 2; c++) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 121 | j = atp_readb_io(dev, c, 0x1f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | if ((j & 0x80) != 0) |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 123 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | dev->in_int[c] = 0; |
| 125 | } |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 126 | if ((j & 0x80) == 0) |
| 127 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | #ifdef ED_DBGP |
| 129 | printk("atp870u_intr_handle enter\n"); |
| 130 | #endif |
| 131 | dev->in_int[c] = 1; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 132 | cmdp = atp_readb_io(dev, c, 0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | if (dev->working[c] != 0) { |
| 134 | if (dev->dev_id == ATP885_DEVID) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 135 | if ((atp_readb_io(dev, c, 0x16) & 0x80) == 0) |
| 136 | atp_writeb_io(dev, c, 0x16, (atp_readb_io(dev, c, 0x16) | 0x80)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 138 | if ((atp_readb_pci(dev, c, 0x00) & 0x08) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | for (k=0; k < 1000; k++) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 141 | if ((atp_readb_pci(dev, c, 2) & 0x08) == 0) |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 142 | break; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 143 | if ((atp_readb_pci(dev, c, 2) & 0x01) == 0) |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 144 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 147 | atp_writeb_pci(dev, c, 0, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 149 | i = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Ondrej Zary | bc0fe4c | 2015-11-17 19:23:47 +0100 | [diff] [blame] | 151 | if (dev->dev_id == ATP885_DEVID) |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 152 | atp_writeb_pci(dev, c, 2, 0x06); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 154 | target_id = atp_readb_io(dev, c, 0x15); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * Remap wide devices onto id numbers |
| 158 | */ |
| 159 | |
| 160 | if ((target_id & 0x40) != 0) { |
| 161 | target_id = (target_id & 0x07) | 0x08; |
| 162 | } else { |
| 163 | target_id &= 0x07; |
| 164 | } |
| 165 | |
| 166 | if ((j & 0x40) != 0) { |
| 167 | if (dev->last_cmd[c] == 0xff) { |
| 168 | dev->last_cmd[c] = target_id; |
| 169 | } |
| 170 | dev->last_cmd[c] |= 0x40; |
| 171 | } |
| 172 | if (dev->dev_id == ATP885_DEVID) |
| 173 | dev->r1f[c][target_id] |= j; |
| 174 | #ifdef ED_DBGP |
| 175 | printk("atp870u_intr_handle status = %x\n",i); |
| 176 | #endif |
| 177 | if (i == 0x85) { |
| 178 | if ((dev->last_cmd[c] & 0xf0) != 0x40) { |
| 179 | dev->last_cmd[c] = 0xff; |
| 180 | } |
| 181 | if (dev->dev_id == ATP885_DEVID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | adrcnt = 0; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 183 | ((unsigned char *) &adrcnt)[2] = atp_readb_io(dev, c, 0x12); |
| 184 | ((unsigned char *) &adrcnt)[1] = atp_readb_io(dev, c, 0x13); |
| 185 | ((unsigned char *) &adrcnt)[0] = atp_readb_io(dev, c, 0x14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | if (dev->id[c][target_id].last_len != adrcnt) |
| 187 | { |
| 188 | k = dev->id[c][target_id].last_len; |
| 189 | k -= adrcnt; |
| 190 | dev->id[c][target_id].tran_len = k; |
| 191 | dev->id[c][target_id].last_len = adrcnt; |
| 192 | } |
| 193 | #ifdef ED_DBGP |
Ondrej Zary | 3a38e53 | 2015-11-17 19:23:39 +0100 | [diff] [blame] | 194 | printk("dev->id[c][target_id].last_len = %d dev->id[c][target_id].tran_len = %d\n",dev->id[c][target_id].last_len,dev->id[c][target_id].tran_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #endif |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * Flip wide |
| 200 | */ |
| 201 | if (dev->wide_id[c] != 0) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 202 | atp_writeb_io(dev, c, 0x1b, 0x01); |
| 203 | while ((atp_readb_io(dev, c, 0x1b) & 0x01) != 0x01) |
| 204 | atp_writeb_io(dev, c, 0x1b, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | /* |
| 207 | * Issue more commands |
| 208 | */ |
| 209 | spin_lock_irqsave(dev->host->host_lock, flags); |
| 210 | if (((dev->quhd[c] != dev->quend[c]) || (dev->last_cmd[c] != 0xff)) && |
| 211 | (dev->in_snd[c] == 0)) { |
| 212 | #ifdef ED_DBGP |
| 213 | printk("Call sent_s870\n"); |
| 214 | #endif |
| 215 | send_s870(dev,c); |
| 216 | } |
| 217 | spin_unlock_irqrestore(dev->host->host_lock, flags); |
| 218 | /* |
| 219 | * Done |
| 220 | */ |
| 221 | dev->in_int[c] = 0; |
| 222 | #ifdef ED_DBGP |
| 223 | printk("Status 0x85 return\n"); |
| 224 | #endif |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 225 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | if (i == 0x40) { |
| 229 | dev->last_cmd[c] |= 0x40; |
| 230 | dev->in_int[c] = 0; |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 231 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | if (i == 0x21) { |
| 235 | if ((dev->last_cmd[c] & 0xf0) != 0x40) { |
| 236 | dev->last_cmd[c] = 0xff; |
| 237 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | adrcnt = 0; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 239 | ((unsigned char *) &adrcnt)[2] = atp_readb_io(dev, c, 0x12); |
| 240 | ((unsigned char *) &adrcnt)[1] = atp_readb_io(dev, c, 0x13); |
| 241 | ((unsigned char *) &adrcnt)[0] = atp_readb_io(dev, c, 0x14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | k = dev->id[c][target_id].last_len; |
| 243 | k -= adrcnt; |
| 244 | dev->id[c][target_id].tran_len = k; |
| 245 | dev->id[c][target_id].last_len = adrcnt; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 246 | atp_writeb_io(dev, c, 0x10, 0x41); |
| 247 | atp_writeb_io(dev, c, 0x18, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | dev->in_int[c] = 0; |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 249 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | if (dev->dev_id == ATP885_DEVID) { |
| 253 | if ((i == 0x4c) || (i == 0x4d) || (i == 0x8c) || (i == 0x8d)) { |
| 254 | if ((i == 0x4c) || (i == 0x8c)) |
| 255 | i=0x48; |
| 256 | else |
| 257 | i=0x49; |
| 258 | } |
| 259 | |
| 260 | } |
| 261 | if ((i == 0x80) || (i == 0x8f)) { |
| 262 | #ifdef ED_DBGP |
| 263 | printk(KERN_DEBUG "Device reselect\n"); |
| 264 | #endif |
| 265 | lun = 0; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 266 | if (cmdp == 0x44 || i == 0x80) |
| 267 | lun = atp_readb_io(dev, c, 0x1d) & 0x07; |
| 268 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if ((dev->last_cmd[c] & 0xf0) != 0x40) { |
| 270 | dev->last_cmd[c] = 0xff; |
| 271 | } |
| 272 | if (cmdp == 0x41) { |
| 273 | #ifdef ED_DBGP |
| 274 | printk("cmdp = 0x41\n"); |
| 275 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | adrcnt = 0; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 277 | ((unsigned char *) &adrcnt)[2] = atp_readb_io(dev, c, 0x12); |
| 278 | ((unsigned char *) &adrcnt)[1] = atp_readb_io(dev, c, 0x13); |
| 279 | ((unsigned char *) &adrcnt)[0] = atp_readb_io(dev, c, 0x14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | k = dev->id[c][target_id].last_len; |
| 281 | k -= adrcnt; |
| 282 | dev->id[c][target_id].tran_len = k; |
| 283 | dev->id[c][target_id].last_len = adrcnt; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 284 | atp_writeb_io(dev, c, 0x18, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | dev->in_int[c] = 0; |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 286 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } else { |
| 288 | #ifdef ED_DBGP |
| 289 | printk("cmdp != 0x41\n"); |
| 290 | #endif |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 291 | atp_writeb_io(dev, c, 0x10, 0x46); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | dev->id[c][target_id].dirct = 0x00; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 293 | atp_writeb_io(dev, c, 0x12, 0x00); |
| 294 | atp_writeb_io(dev, c, 0x13, 0x00); |
| 295 | atp_writeb_io(dev, c, 0x14, 0x00); |
| 296 | atp_writeb_io(dev, c, 0x18, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | dev->in_int[c] = 0; |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 298 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | if (dev->last_cmd[c] != 0xff) { |
| 302 | dev->last_cmd[c] |= 0x40; |
| 303 | } |
| 304 | if (dev->dev_id == ATP885_DEVID) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 305 | j = atp_readb_base(dev, 0x29) & 0xfe; |
| 306 | atp_writeb_base(dev, 0x29, j); |
Ondrej Zary | 3a38e53 | 2015-11-17 19:23:39 +0100 | [diff] [blame] | 307 | } else |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 308 | atp_writeb_io(dev, c, 0x10, 0x45); |
Ondrej Zary | 3a38e53 | 2015-11-17 19:23:39 +0100 | [diff] [blame] | 309 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 310 | target_id = atp_readb_io(dev, c, 0x16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | /* |
| 312 | * Remap wide identifiers |
| 313 | */ |
| 314 | if ((target_id & 0x10) != 0) { |
| 315 | target_id = (target_id & 0x07) | 0x08; |
| 316 | } else { |
| 317 | target_id &= 0x07; |
| 318 | } |
Ondrej Zary | 3a38e53 | 2015-11-17 19:23:39 +0100 | [diff] [blame] | 319 | if (dev->dev_id == ATP885_DEVID) |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 320 | atp_writeb_io(dev, c, 0x10, 0x45); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | workreq = dev->id[c][target_id].curr_req; |
| 322 | #ifdef ED_DBGP |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 323 | scmd_printk(KERN_DEBUG, workreq, "CDB"); |
| 324 | for (l = 0; l < workreq->cmd_len; l++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | printk(KERN_DEBUG " %x",workreq->cmnd[l]); |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 326 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | #endif |
| 328 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 329 | atp_writeb_io(dev, c, 0x0f, lun); |
| 330 | atp_writeb_io(dev, c, 0x11, dev->id[c][target_id].devsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | adrcnt = dev->id[c][target_id].tran_len; |
| 332 | k = dev->id[c][target_id].last_len; |
| 333 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 334 | atp_writeb_io(dev, c, 0x12, ((unsigned char *) &k)[2]); |
| 335 | atp_writeb_io(dev, c, 0x13, ((unsigned char *) &k)[1]); |
| 336 | atp_writeb_io(dev, c, 0x14, ((unsigned char *) &k)[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | #ifdef ED_DBGP |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 338 | printk("k %x, k[0] 0x%x k[1] 0x%x k[2] 0x%x\n", k, atp_readb_io(dev, c, 0x14), atp_readb_io(dev, c, 0x13), atp_readb_io(dev, c, 0x12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | #endif |
| 340 | /* Remap wide */ |
| 341 | j = target_id; |
| 342 | if (target_id > 7) { |
| 343 | j = (j & 0x07) | 0x40; |
| 344 | } |
| 345 | /* Add direction */ |
| 346 | j |= dev->id[c][target_id].dirct; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 347 | atp_writeb_io(dev, c, 0x15, j); |
| 348 | atp_writeb_io(dev, c, 0x16, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | /* enable 32 bit fifo transfer */ |
| 351 | if (dev->dev_id == ATP885_DEVID) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 352 | i = atp_readb_pci(dev, c, 1) & 0xf3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | //j=workreq->cmnd[0]; |
| 354 | if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) { |
| 355 | i |= 0x0c; |
| 356 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 357 | atp_writeb_pci(dev, c, 1, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } else if ((dev->dev_id == ATP880_DEVID1) || |
| 359 | (dev->dev_id == ATP880_DEVID2) ) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 360 | if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) |
| 361 | atp_writeb_base(dev, 0x3b, (atp_readb_base(dev, 0x3b) & 0x3f) | 0xc0); |
| 362 | else |
| 363 | atp_writeb_base(dev, 0x3b, atp_readb_base(dev, 0x3b) & 0x3f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } else { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 365 | if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) |
Ondrej Zary | c751d9f | 2015-11-17 19:24:09 +0100 | [diff] [blame] | 366 | atp_writeb_base(dev, 0x3a, (atp_readb_base(dev, 0x3a) & 0xf3) | 0x08); |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 367 | else |
Ondrej Zary | c751d9f | 2015-11-17 19:24:09 +0100 | [diff] [blame] | 368 | atp_writeb_base(dev, 0x3a, atp_readb_base(dev, 0x3a) & 0xf3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | j = 0; |
| 371 | id = 1; |
| 372 | id = id << target_id; |
| 373 | /* |
| 374 | * Is this a wide device |
| 375 | */ |
| 376 | if ((id & dev->wide_id[c]) != 0) { |
| 377 | j |= 0x01; |
| 378 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 379 | atp_writeb_io(dev, c, 0x1b, j); |
| 380 | while ((atp_readb_io(dev, c, 0x1b) & 0x01) != j) |
| 381 | atp_writeb_io(dev, c, 0x1b, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if (dev->id[c][target_id].last_len == 0) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 383 | atp_writeb_io(dev, c, 0x18, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | dev->in_int[c] = 0; |
| 385 | #ifdef ED_DBGP |
| 386 | printk("dev->id[c][target_id].last_len = 0\n"); |
| 387 | #endif |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 388 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | #ifdef ED_DBGP |
| 391 | printk("target_id = %d adrcnt = %d\n",target_id,adrcnt); |
| 392 | #endif |
| 393 | prd = dev->id[c][target_id].prd_pos; |
| 394 | while (adrcnt != 0) { |
| 395 | id = ((unsigned short int *)prd)[2]; |
| 396 | if (id == 0) { |
| 397 | k = 0x10000; |
| 398 | } else { |
| 399 | k = id; |
| 400 | } |
| 401 | if (k > adrcnt) { |
| 402 | ((unsigned short int *)prd)[2] = (unsigned short int) |
| 403 | (k - adrcnt); |
| 404 | ((unsigned long *)prd)[0] += adrcnt; |
| 405 | adrcnt = 0; |
| 406 | dev->id[c][target_id].prd_pos = prd; |
| 407 | } else { |
| 408 | adrcnt -= k; |
| 409 | dev->id[c][target_id].prdaddr += 0x08; |
| 410 | prd += 0x08; |
| 411 | if (adrcnt == 0) { |
| 412 | dev->id[c][target_id].prd_pos = prd; |
| 413 | } |
| 414 | } |
| 415 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 416 | atp_writel_pci(dev, c, 0x04, dev->id[c][target_id].prdaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | #ifdef ED_DBGP |
| 418 | printk("dev->id[%d][%d].prdaddr 0x%8x\n", c, target_id, dev->id[c][target_id].prdaddr); |
| 419 | #endif |
Ondrej Zary | bc0fe4c | 2015-11-17 19:23:47 +0100 | [diff] [blame] | 420 | if (dev->dev_id != ATP885_DEVID) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 421 | atp_writeb_pci(dev, c, 2, 0x06); |
| 422 | atp_writeb_pci(dev, c, 2, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /* |
| 425 | * Check transfer direction |
| 426 | */ |
| 427 | if (dev->id[c][target_id].dirct != 0) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 428 | atp_writeb_io(dev, c, 0x18, 0x08); |
| 429 | atp_writeb_pci(dev, c, 0, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | dev->in_int[c] = 0; |
| 431 | #ifdef ED_DBGP |
| 432 | printk("status 0x80 return dirct != 0\n"); |
| 433 | #endif |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 434 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 436 | atp_writeb_io(dev, c, 0x18, 0x08); |
| 437 | atp_writeb_pci(dev, c, 0, 0x09); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | dev->in_int[c] = 0; |
| 439 | #ifdef ED_DBGP |
| 440 | printk("status 0x80 return dirct = 0\n"); |
| 441 | #endif |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 442 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /* |
| 446 | * Current scsi request on this target |
| 447 | */ |
| 448 | |
| 449 | workreq = dev->id[c][target_id].curr_req; |
| 450 | |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 451 | if (i == 0x42 || i == 0x16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | if ((dev->last_cmd[c] & 0xf0) != 0x40) { |
| 453 | dev->last_cmd[c] = 0xff; |
| 454 | } |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 455 | if (i == 0x16) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 456 | workreq->result = atp_readb_io(dev, c, 0x0f); |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 457 | if (((dev->r1f[c][target_id] & 0x10) != 0)&&(dev->dev_id==ATP885_DEVID)) { |
| 458 | printk(KERN_WARNING "AEC67162 CRC ERROR !\n"); |
| 459 | workreq->result = 0x02; |
| 460 | } |
| 461 | } else |
| 462 | workreq->result = 0x02; |
| 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | if (dev->dev_id == ATP885_DEVID) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 465 | j = atp_readb_base(dev, 0x29) | 0x01; |
| 466 | atp_writeb_base(dev, 0x29, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | /* |
| 469 | * Complete the command |
| 470 | */ |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 471 | scsi_dma_unmap(workreq); |
| 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | spin_lock_irqsave(dev->host->host_lock, flags); |
| 474 | (*workreq->scsi_done) (workreq); |
| 475 | #ifdef ED_DBGP |
| 476 | printk("workreq->scsi_done\n"); |
| 477 | #endif |
| 478 | /* |
| 479 | * Clear it off the queue |
| 480 | */ |
| 481 | dev->id[c][target_id].curr_req = NULL; |
| 482 | dev->working[c]--; |
| 483 | spin_unlock_irqrestore(dev->host->host_lock, flags); |
| 484 | /* |
| 485 | * Take it back wide |
| 486 | */ |
| 487 | if (dev->wide_id[c] != 0) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 488 | atp_writeb_io(dev, c, 0x1b, 0x01); |
| 489 | while ((atp_readb_io(dev, c, 0x1b) & 0x01) != 0x01) |
| 490 | atp_writeb_io(dev, c, 0x1b, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | /* |
| 493 | * If there is stuff to send and nothing going then send it |
| 494 | */ |
| 495 | spin_lock_irqsave(dev->host->host_lock, flags); |
| 496 | if (((dev->last_cmd[c] != 0xff) || (dev->quhd[c] != dev->quend[c])) && |
| 497 | (dev->in_snd[c] == 0)) { |
| 498 | #ifdef ED_DBGP |
| 499 | printk("Call sent_s870(scsi_done)\n"); |
| 500 | #endif |
| 501 | send_s870(dev,c); |
| 502 | } |
| 503 | spin_unlock_irqrestore(dev->host->host_lock, flags); |
| 504 | dev->in_int[c] = 0; |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 505 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | if ((dev->last_cmd[c] & 0xf0) != 0x40) { |
| 508 | dev->last_cmd[c] = 0xff; |
| 509 | } |
| 510 | if (i == 0x4f) { |
| 511 | i = 0x89; |
| 512 | } |
| 513 | i &= 0x0f; |
| 514 | if (i == 0x09) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 515 | atp_writel_pci(dev, c, 4, dev->id[c][target_id].prdaddr); |
| 516 | atp_writeb_pci(dev, c, 2, 0x06); |
| 517 | atp_writeb_pci(dev, c, 2, 0x00); |
| 518 | atp_writeb_io(dev, c, 0x10, 0x41); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (dev->dev_id == ATP885_DEVID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | k = dev->id[c][target_id].last_len; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 521 | atp_writeb_io(dev, c, 0x12, ((unsigned char *) (&k))[2]); |
| 522 | atp_writeb_io(dev, c, 0x13, ((unsigned char *) (&k))[1]); |
| 523 | atp_writeb_io(dev, c, 0x14, ((unsigned char *) (&k))[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | dev->id[c][target_id].dirct = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } else { |
| 526 | dev->id[c][target_id].dirct = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 528 | atp_writeb_io(dev, c, 0x18, 0x08); |
| 529 | atp_writeb_pci(dev, c, 0, 0x09); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | dev->in_int[c] = 0; |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 531 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | if (i == 0x08) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 534 | atp_writel_pci(dev, c, 4, dev->id[c][target_id].prdaddr); |
| 535 | atp_writeb_pci(dev, c, 2, 0x06); |
| 536 | atp_writeb_pci(dev, c, 2, 0x00); |
| 537 | atp_writeb_io(dev, c, 0x10, 0x41); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | if (dev->dev_id == ATP885_DEVID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | k = dev->id[c][target_id].last_len; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 540 | atp_writeb_io(dev, c, 0x12, ((unsigned char *) (&k))[2]); |
| 541 | atp_writeb_io(dev, c, 0x13, ((unsigned char *) (&k))[1]); |
| 542 | atp_writeb_io(dev, c, 0x14, ((unsigned char *) (&k))[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 544 | atp_writeb_io(dev, c, 0x15, atp_readb_io(dev, c, 0x15) | 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | dev->id[c][target_id].dirct = 0x20; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 546 | atp_writeb_io(dev, c, 0x18, 0x08); |
| 547 | atp_writeb_pci(dev, c, 0, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | dev->in_int[c] = 0; |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 549 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 551 | if (i == 0x0a) |
| 552 | atp_writeb_io(dev, c, 0x10, 0x30); |
| 553 | else |
| 554 | atp_writeb_io(dev, c, 0x10, 0x46); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | dev->id[c][target_id].dirct = 0x00; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 556 | atp_writeb_io(dev, c, 0x12, 0x00); |
| 557 | atp_writeb_io(dev, c, 0x13, 0x00); |
| 558 | atp_writeb_io(dev, c, 0x14, 0x00); |
| 559 | atp_writeb_io(dev, c, 0x18, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
Ondrej Zary | 78614ec | 2015-11-17 19:23:49 +0100 | [diff] [blame] | 561 | dev->in_int[c] = 0; |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return IRQ_HANDLED; |
| 564 | } |
| 565 | /** |
| 566 | * atp870u_queuecommand - Queue SCSI command |
| 567 | * @req_p: request block |
| 568 | * @done: completion function |
| 569 | * |
| 570 | * Queue a command to the ATP queue. Called with the host lock held. |
| 571 | */ |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 572 | static int atp870u_queuecommand_lck(struct scsi_cmnd *req_p, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | void (*done) (struct scsi_cmnd *)) |
| 574 | { |
| 575 | unsigned char c; |
Ondrej Zary | 3b83646 | 2015-11-17 19:23:40 +0100 | [diff] [blame] | 576 | unsigned int m; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | struct atp_unit *dev; |
| 578 | struct Scsi_Host *host; |
| 579 | |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 580 | c = scmd_channel(req_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | req_p->sense_buffer[0]=0; |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 582 | scsi_set_resid(req_p, 0); |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 583 | if (scmd_channel(req_p) > 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | req_p->result = 0x00040000; |
| 585 | done(req_p); |
| 586 | #ifdef ED_DBGP |
| 587 | printk("atp870u_queuecommand : req_p->device->channel > 1\n"); |
| 588 | #endif |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | host = req_p->device->host; |
| 593 | dev = (struct atp_unit *)&host->hostdata; |
| 594 | |
| 595 | |
| 596 | |
| 597 | m = 1; |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 598 | m = m << scmd_id(req_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | /* |
| 601 | * Fake a timeout for missing targets |
| 602 | */ |
| 603 | |
| 604 | if ((m & dev->active_id[c]) == 0) { |
| 605 | req_p->result = 0x00040000; |
| 606 | done(req_p); |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | if (done) { |
| 611 | req_p->scsi_done = done; |
| 612 | } else { |
| 613 | #ifdef ED_DBGP |
| 614 | printk( "atp870u_queuecommand: done can't be NULL\n"); |
| 615 | #endif |
| 616 | req_p->result = 0; |
| 617 | done(req_p); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * Count new command |
| 623 | */ |
| 624 | dev->quend[c]++; |
| 625 | if (dev->quend[c] >= qcnt) { |
| 626 | dev->quend[c] = 0; |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * Check queue state |
| 631 | */ |
| 632 | if (dev->quhd[c] == dev->quend[c]) { |
| 633 | if (dev->quend[c] == 0) { |
| 634 | dev->quend[c] = qcnt; |
| 635 | } |
| 636 | #ifdef ED_DBGP |
| 637 | printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n"); |
| 638 | #endif |
| 639 | dev->quend[c]--; |
| 640 | req_p->result = 0x00020000; |
| 641 | done(req_p); |
| 642 | return 0; |
| 643 | } |
| 644 | dev->quereq[c][dev->quend[c]] = req_p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | #ifdef ED_DBGP |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 646 | printk("dev->ioport[c] = %x atp_readb_io(dev, c, 0x1c) = %x dev->in_int[%d] = %d dev->in_snd[%d] = %d\n",dev->ioport[c],atp_readb_io(dev, c, 0x1c),c,dev->in_int[c],c,dev->in_snd[c]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | #endif |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 648 | if ((atp_readb_io(dev, c, 0x1c) == 0) && (dev->in_int[c] == 0) && (dev->in_snd[c] == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | #ifdef ED_DBGP |
| 650 | printk("Call sent_s870(atp870u_queuecommand)\n"); |
| 651 | #endif |
| 652 | send_s870(dev,c); |
| 653 | } |
| 654 | #ifdef ED_DBGP |
| 655 | printk("atp870u_queuecommand : exit\n"); |
| 656 | #endif |
| 657 | return 0; |
| 658 | } |
| 659 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 660 | static DEF_SCSI_QCMD(atp870u_queuecommand) |
| 661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | /** |
| 663 | * send_s870 - send a command to the controller |
| 664 | * @host: host |
| 665 | * |
| 666 | * On entry there is work queued to be done. We move some of that work to the |
| 667 | * controller itself. |
| 668 | * |
| 669 | * Caller holds the host lock. |
| 670 | */ |
| 671 | static void send_s870(struct atp_unit *dev,unsigned char c) |
| 672 | { |
Ondrej Zary | 468b896 | 2015-11-17 19:23:50 +0100 | [diff] [blame] | 673 | struct scsi_cmnd *workreq = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | unsigned int i;//,k; |
| 675 | unsigned char j, target_id; |
| 676 | unsigned char *prd; |
Ondrej Zary | c2bab40 | 2015-11-17 19:23:48 +0100 | [diff] [blame] | 677 | unsigned short int w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | unsigned long l, bttl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | unsigned long sg_count; |
| 680 | |
| 681 | if (dev->in_snd[c] != 0) { |
| 682 | #ifdef ED_DBGP |
| 683 | printk("cmnd in_snd\n"); |
| 684 | #endif |
| 685 | return; |
| 686 | } |
| 687 | #ifdef ED_DBGP |
| 688 | printk("Sent_s870 enter\n"); |
| 689 | #endif |
| 690 | dev->in_snd[c] = 1; |
| 691 | if ((dev->last_cmd[c] != 0xff) && ((dev->last_cmd[c] & 0x40) != 0)) { |
| 692 | dev->last_cmd[c] &= 0x0f; |
| 693 | workreq = dev->id[c][dev->last_cmd[c]].curr_req; |
Ondrej Zary | 468b896 | 2015-11-17 19:23:50 +0100 | [diff] [blame] | 694 | if (!workreq) { |
| 695 | dev->last_cmd[c] = 0xff; |
| 696 | if (dev->quhd[c] == dev->quend[c]) { |
| 697 | dev->in_snd[c] = 0; |
| 698 | return; |
| 699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } |
| 701 | } |
Ondrej Zary | 468b896 | 2015-11-17 19:23:50 +0100 | [diff] [blame] | 702 | if (!workreq) { |
| 703 | if ((dev->last_cmd[c] != 0xff) && (dev->working[c] != 0)) { |
| 704 | dev->in_snd[c] = 0; |
| 705 | return; |
| 706 | } |
| 707 | dev->working[c]++; |
| 708 | j = dev->quhd[c]; |
| 709 | dev->quhd[c]++; |
| 710 | if (dev->quhd[c] >= qcnt) |
| 711 | dev->quhd[c] = 0; |
| 712 | workreq = dev->quereq[c][dev->quhd[c]]; |
| 713 | if (dev->id[c][scmd_id(workreq)].curr_req != NULL) { |
| 714 | dev->quhd[c] = j; |
| 715 | dev->working[c]--; |
| 716 | dev->in_snd[c] = 0; |
| 717 | return; |
| 718 | } |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 719 | dev->id[c][scmd_id(workreq)].curr_req = workreq; |
| 720 | dev->last_cmd[c] = scmd_id(workreq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 722 | if ((atp_readb_io(dev, c, 0x1f) & 0xb0) != 0 || atp_readb_io(dev, c, 0x1c) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | #ifdef ED_DBGP |
Ondrej Zary | 468b896 | 2015-11-17 19:23:50 +0100 | [diff] [blame] | 724 | printk("Abort to Send\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | #endif |
Ondrej Zary | 468b896 | 2015-11-17 19:23:50 +0100 | [diff] [blame] | 726 | dev->last_cmd[c] |= 0x40; |
| 727 | dev->in_snd[c] = 0; |
| 728 | return; |
| 729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | #ifdef ED_DBGP |
| 731 | printk("OK to Send\n"); |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 732 | scmd_printk(KERN_DEBUG, workreq, "CDB"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | for(i=0;i<workreq->cmd_len;i++) { |
| 734 | printk(" %x",workreq->cmnd[i]); |
| 735 | } |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 736 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | #endif |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 738 | l = scsi_bufflen(workreq); |
| 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | if (dev->dev_id == ATP885_DEVID) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 741 | j = atp_readb_base(dev, 0x29) & 0xfe; |
| 742 | atp_writeb_base(dev, 0x29, j); |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 743 | dev->r1f[c][scmd_id(workreq)] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | if (workreq->cmnd[0] == READ_CAPACITY) { |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 747 | if (l > 8) |
| 748 | l = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | if (workreq->cmnd[0] == 0x00) { |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 751 | l = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | j = 0; |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 755 | target_id = scmd_id(workreq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | /* |
| 758 | * Wide ? |
| 759 | */ |
| 760 | w = 1; |
| 761 | w = w << target_id; |
| 762 | if ((w & dev->wide_id[c]) != 0) { |
| 763 | j |= 0x01; |
| 764 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 765 | atp_writeb_io(dev, c, 0x1b, j); |
| 766 | while ((atp_readb_io(dev, c, 0x1b) & 0x01) != j) { |
| 767 | atp_writeb_pci(dev, c, 0x1b, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | #ifdef ED_DBGP |
| 769 | printk("send_s870 while loop 1\n"); |
| 770 | #endif |
| 771 | } |
| 772 | /* |
| 773 | * Write the command |
| 774 | */ |
| 775 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 776 | atp_writeb_io(dev, c, 0x00, workreq->cmd_len); |
| 777 | atp_writeb_io(dev, c, 0x01, 0x2c); |
| 778 | if (dev->dev_id == ATP885_DEVID) |
| 779 | atp_writeb_io(dev, c, 0x02, 0x7f); |
| 780 | else |
| 781 | atp_writeb_io(dev, c, 0x02, 0xcf); |
| 782 | for (i = 0; i < workreq->cmd_len; i++) |
| 783 | atp_writeb_io(dev, c, 0x03 + i, workreq->cmnd[i]); |
| 784 | atp_writeb_io(dev, c, 0x0f, workreq->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | /* |
| 786 | * Write the target |
| 787 | */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 788 | atp_writeb_io(dev, c, 0x11, dev->id[c][target_id].devsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | #ifdef ED_DBGP |
| 790 | printk("dev->id[%d][%d].devsp = %2x\n",c,target_id,dev->id[c][target_id].devsp); |
| 791 | #endif |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 792 | |
| 793 | sg_count = scsi_dma_map(workreq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | /* |
| 795 | * Write transfer size |
| 796 | */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 797 | atp_writeb_io(dev, c, 0x12, ((unsigned char *) (&l))[2]); |
| 798 | atp_writeb_io(dev, c, 0x13, ((unsigned char *) (&l))[1]); |
| 799 | atp_writeb_io(dev, c, 0x14, ((unsigned char *) (&l))[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | j = target_id; |
| 801 | dev->id[c][j].last_len = l; |
| 802 | dev->id[c][j].tran_len = 0; |
| 803 | #ifdef ED_DBGP |
| 804 | printk("dev->id[%2d][%2d].last_len = %d\n",c,j,dev->id[c][j].last_len); |
| 805 | #endif |
| 806 | /* |
| 807 | * Flip the wide bits |
| 808 | */ |
| 809 | if ((j & 0x08) != 0) { |
| 810 | j = (j & 0x07) | 0x40; |
| 811 | } |
| 812 | /* |
| 813 | * Check transfer direction |
| 814 | */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 815 | if (workreq->sc_data_direction == DMA_TO_DEVICE) |
| 816 | atp_writeb_io(dev, c, 0x15, j | 0x20); |
| 817 | else |
| 818 | atp_writeb_io(dev, c, 0x15, j); |
| 819 | atp_writeb_io(dev, c, 0x16, atp_readb_io(dev, c, 0x16) | 0x80); |
| 820 | atp_writeb_io(dev, c, 0x16, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | dev->id[c][target_id].dirct = 0; |
| 822 | if (l == 0) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 823 | if (atp_readb_io(dev, c, 0x1c) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | #ifdef ED_DBGP |
| 825 | printk("change SCSI_CMD_REG 0x08\n"); |
| 826 | #endif |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 827 | atp_writeb_io(dev, c, 0x18, 0x08); |
| 828 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | dev->last_cmd[c] |= 0x40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | dev->in_snd[c] = 0; |
| 831 | return; |
| 832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | prd = dev->id[c][target_id].prd_table; |
| 834 | dev->id[c][target_id].prd_pos = prd; |
| 835 | |
| 836 | /* |
| 837 | * Now write the request list. Either as scatter/gather or as |
| 838 | * a linear chain. |
| 839 | */ |
| 840 | |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 841 | if (l) { |
| 842 | struct scatterlist *sgpnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | i = 0; |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 844 | scsi_for_each_sg(workreq, sgpnt, sg_count, j) { |
| 845 | bttl = sg_dma_address(sgpnt); |
| 846 | l=sg_dma_len(sgpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | #ifdef ED_DBGP |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 848 | printk("1. bttl %x, l %x\n",bttl, l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | #endif |
Boaz Harrosh | fe7ed98 | 2007-09-09 21:06:23 +0300 | [diff] [blame] | 850 | while (l > 0x10000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | (((u16 *) (prd))[i + 3]) = 0x0000; |
| 852 | (((u16 *) (prd))[i + 2]) = 0x0000; |
| 853 | (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl); |
| 854 | l -= 0x10000; |
| 855 | bttl += 0x10000; |
| 856 | i += 0x04; |
| 857 | } |
| 858 | (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl); |
| 859 | (((u16 *) (prd))[i + 2]) = cpu_to_le16(l); |
| 860 | (((u16 *) (prd))[i + 3]) = 0; |
| 861 | i += 0x04; |
| 862 | } |
| 863 | (((u16 *) (prd))[i - 1]) = cpu_to_le16(0x8000); |
| 864 | #ifdef ED_DBGP |
| 865 | printk("prd %4x %4x %4x %4x\n",(((unsigned short int *)prd)[0]),(((unsigned short int *)prd)[1]),(((unsigned short int *)prd)[2]),(((unsigned short int *)prd)[3])); |
| 866 | printk("2. bttl %x, l %x\n",bttl, l); |
| 867 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | #ifdef ED_DBGP |
Ondrej Zary | c2bab40 | 2015-11-17 19:23:48 +0100 | [diff] [blame] | 870 | printk("send_s870: prdaddr_2 0x%8x target_id %d\n", dev->id[c][target_id].prdaddr,target_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | #endif |
James Bottomley | b568355 | 2005-09-15 08:59:36 -0500 | [diff] [blame] | 872 | dev->id[c][target_id].prdaddr = dev->id[c][target_id].prd_bus; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 873 | atp_writel_pci(dev, c, 4, dev->id[c][target_id].prdaddr); |
| 874 | atp_writeb_pci(dev, c, 2, 0x06); |
| 875 | atp_writeb_pci(dev, c, 2, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | if (dev->dev_id == ATP885_DEVID) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 877 | j = atp_readb_pci(dev, c, 1) & 0xf3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || |
| 879 | (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) { |
| 880 | j |= 0x0c; |
| 881 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 882 | atp_writeb_pci(dev, c, 1, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } else if ((dev->dev_id == ATP880_DEVID1) || |
| 884 | (dev->dev_id == ATP880_DEVID2)) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 885 | if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) |
| 886 | atp_writeb_base(dev, 0x3b, (atp_readb_base(dev, 0x3b) & 0x3f) | 0xc0); |
| 887 | else |
| 888 | atp_writeb_base(dev, 0x3b, atp_readb_base(dev, 0x3b) & 0x3f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } else { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 890 | if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) |
Ondrej Zary | c751d9f | 2015-11-17 19:24:09 +0100 | [diff] [blame] | 891 | atp_writeb_base(dev, 0x3a, (atp_readb_base(dev, 0x3a) & 0xf3) | 0x08); |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 892 | else |
Ondrej Zary | c751d9f | 2015-11-17 19:24:09 +0100 | [diff] [blame] | 893 | atp_writeb_base(dev, 0x3a, atp_readb_base(dev, 0x3a) & 0xf3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | if(workreq->sc_data_direction == DMA_TO_DEVICE) { |
| 897 | dev->id[c][target_id].dirct = 0x20; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 898 | if (atp_readb_io(dev, c, 0x1c) == 0) { |
| 899 | atp_writeb_io(dev, c, 0x18, 0x08); |
| 900 | atp_writeb_pci(dev, c, 0, 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | #ifdef ED_DBGP |
| 902 | printk( "start DMA(to target)\n"); |
| 903 | #endif |
| 904 | } else { |
| 905 | dev->last_cmd[c] |= 0x40; |
| 906 | } |
| 907 | dev->in_snd[c] = 0; |
| 908 | return; |
| 909 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 910 | if (atp_readb_io(dev, c, 0x1c) == 0) { |
| 911 | atp_writeb_io(dev, c, 0x18, 0x08); |
| 912 | atp_writeb_pci(dev, c, 0, 0x09); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | #ifdef ED_DBGP |
| 914 | printk( "start DMA(to host)\n"); |
| 915 | #endif |
| 916 | } else { |
| 917 | dev->last_cmd[c] |= 0x40; |
| 918 | } |
| 919 | dev->in_snd[c] = 0; |
| 920 | return; |
| 921 | |
| 922 | } |
| 923 | |
| 924 | static unsigned char fun_scam(struct atp_unit *dev, unsigned short int *val) |
| 925 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | unsigned short int i, k; |
| 927 | unsigned char j; |
| 928 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 929 | atp_writew_io(dev, 0, 0x1c, *val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 931 | k = atp_readw_io(dev, 0, 0x1c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | j = (unsigned char) (k >> 8); |
Ondrej Zary | 832e9ac | 2015-11-17 19:23:51 +0100 | [diff] [blame] | 933 | if ((k & 0x8000) != 0) /* DB7 all release? */ |
| 934 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | *val |= 0x4000; /* assert DB6 */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 937 | atp_writew_io(dev, 0, 0x1c, *val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | *val &= 0xdfff; /* assert DB5 */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 939 | atp_writew_io(dev, 0, 0x1c, *val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 941 | if ((atp_readw_io(dev, 0, 0x1c) & 0x2000) != 0) /* DB5 all release? */ |
Ondrej Zary | 832e9ac | 2015-11-17 19:23:51 +0100 | [diff] [blame] | 942 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
| 944 | *val |= 0x8000; /* no DB4-0, assert DB7 */ |
| 945 | *val &= 0xe0ff; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 946 | atp_writew_io(dev, 0, 0x1c, *val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | *val &= 0xbfff; /* release DB6 */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 948 | atp_writew_io(dev, 0, 0x1c, *val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 950 | if ((atp_readw_io(dev, 0, 0x1c) & 0x4000) != 0) /* DB6 all release? */ |
Ondrej Zary | 832e9ac | 2015-11-17 19:23:51 +0100 | [diff] [blame] | 951 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | return j; |
| 955 | } |
| 956 | |
| 957 | static void tscam(struct Scsi_Host *host) |
| 958 | { |
| 959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | unsigned char i, j, k; |
| 961 | unsigned long n; |
| 962 | unsigned short int m, assignid_map, val; |
| 963 | unsigned char mbuf[33], quintet[2]; |
| 964 | struct atp_unit *dev = (struct atp_unit *)&host->hostdata; |
| 965 | static unsigned char g2q_tab[8] = { |
| 966 | 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27 |
| 967 | }; |
| 968 | |
| 969 | /* I can't believe we need this before we've even done anything. Remove it |
| 970 | * and see if anyone bitches. |
| 971 | for (i = 0; i < 0x10; i++) { |
| 972 | udelay(0xffff); |
| 973 | } |
| 974 | */ |
| 975 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 976 | atp_writeb_io(dev, 0, 1, 0x08); |
| 977 | atp_writeb_io(dev, 0, 2, 0x7f); |
| 978 | atp_writeb_io(dev, 0, 0x11, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | if ((dev->scam_on & 0x40) == 0) { |
| 981 | return; |
| 982 | } |
| 983 | m = 1; |
| 984 | m <<= dev->host_id[0]; |
| 985 | j = 16; |
| 986 | if (dev->chip_ver < 4) { |
| 987 | m |= 0xff00; |
| 988 | j = 8; |
| 989 | } |
| 990 | assignid_map = m; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 991 | atp_writeb_io(dev, 0, 0x02, 0x02); /* 2*2=4ms,3EH 2/32*3E=3.9ms */ |
| 992 | atp_writeb_io(dev, 0, 0x03, 0); |
| 993 | atp_writeb_io(dev, 0, 0x04, 0); |
| 994 | atp_writeb_io(dev, 0, 0x05, 0); |
| 995 | atp_writeb_io(dev, 0, 0x06, 0); |
| 996 | atp_writeb_io(dev, 0, 0x07, 0); |
| 997 | atp_writeb_io(dev, 0, 0x08, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
| 999 | for (i = 0; i < j; i++) { |
| 1000 | m = 1; |
| 1001 | m = m << i; |
| 1002 | if ((m & assignid_map) != 0) { |
| 1003 | continue; |
| 1004 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1005 | atp_writeb_io(dev, 0, 0x0f, 0); |
| 1006 | atp_writeb_io(dev, 0, 0x12, 0); |
| 1007 | atp_writeb_io(dev, 0, 0x13, 0); |
| 1008 | atp_writeb_io(dev, 0, 0x14, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | if (i > 7) { |
| 1010 | k = (i & 0x07) | 0x40; |
| 1011 | } else { |
| 1012 | k = i; |
| 1013 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1014 | atp_writeb_io(dev, 0, 0x15, k); |
| 1015 | if (dev->chip_ver == 4) |
| 1016 | atp_writeb_io(dev, 0, 0x1b, 0x01); |
| 1017 | else |
| 1018 | atp_writeb_io(dev, 0, 0x1b, 0x00); |
Ondrej Zary | 58c4d04 | 2015-11-17 19:23:52 +0100 | [diff] [blame] | 1019 | do { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1020 | atp_writeb_io(dev, 0, 0x18, 0x09); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1022 | while ((atp_readb_io(dev, 0, 0x1f) & 0x80) == 0x00) |
Ondrej Zary | 58c4d04 | 2015-11-17 19:23:52 +0100 | [diff] [blame] | 1023 | cpu_relax(); |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1024 | k = atp_readb_io(dev, 0, 0x17); |
Ondrej Zary | 58c4d04 | 2015-11-17 19:23:52 +0100 | [diff] [blame] | 1025 | if ((k == 0x85) || (k == 0x42)) |
| 1026 | break; |
| 1027 | if (k != 0x16) |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1028 | atp_writeb_io(dev, 0, 0x10, 0x41); |
Ondrej Zary | 58c4d04 | 2015-11-17 19:23:52 +0100 | [diff] [blame] | 1029 | } while (k != 0x16); |
| 1030 | if ((k == 0x85) || (k == 0x42)) |
| 1031 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | assignid_map |= m; |
| 1033 | |
| 1034 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1035 | atp_writeb_io(dev, 0, 0x02, 0x7f); |
| 1036 | atp_writeb_io(dev, 0, 0x1b, 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1038 | udelay(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
| 1040 | val = 0x0080; /* bsy */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1041 | atp_writew_io(dev, 0, 0x1c, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | val |= 0x0040; /* sel */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1043 | atp_writew_io(dev, 0, 0x1c, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | val |= 0x0004; /* msg */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1045 | atp_writew_io(dev, 0, 0x1c, val); |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1046 | udelay(2); /* 2 deskew delay(45ns*2=90ns) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | val &= 0x007f; /* no bsy */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1048 | atp_writew_io(dev, 0, 0x1c, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | mdelay(128); |
| 1050 | val &= 0x00fb; /* after 1ms no msg */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1051 | atp_writew_io(dev, 0, 0x1c, val); |
| 1052 | while ((atp_readb_io(dev, 0, 0x1c) & 0x04) != 0) |
Ondrej Zary | 58c4d04 | 2015-11-17 19:23:52 +0100 | [diff] [blame] | 1053 | ; |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1054 | udelay(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | udelay(100); |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1056 | for (n = 0; n < 0x30000; n++) |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1057 | if ((atp_readb_io(dev, 0, 0x1c) & 0x80) != 0) /* bsy ? */ |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1058 | break; |
| 1059 | if (n < 0x30000) |
| 1060 | for (n = 0; n < 0x30000; n++) |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1061 | if ((atp_readb_io(dev, 0, 0x1c) & 0x81) == 0x0081) { |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1062 | udelay(2); |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1063 | val |= 0x8003; /* io,cd,db7 */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1064 | atp_writew_io(dev, 0, 0x1c, val); |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1065 | udelay(2); |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1066 | val &= 0x00bf; /* no sel */ |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1067 | atp_writew_io(dev, 0, 0x1c, val); |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1068 | udelay(2); |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1069 | break; |
| 1070 | } |
| 1071 | while (1) { |
Martin Michlmayr | 0f6d93a | 2012-10-04 17:11:25 -0700 | [diff] [blame] | 1072 | /* |
| 1073 | * The funny division into multiple delays is to accomodate |
| 1074 | * arches like ARM where udelay() multiplies its argument by |
| 1075 | * a large number to initialize a loop counter. To avoid |
| 1076 | * overflow, the maximum supported udelay is 2000 microseconds. |
| 1077 | * |
| 1078 | * XXX it would be more polite to find a way to use msleep() |
| 1079 | */ |
| 1080 | mdelay(2); |
| 1081 | udelay(48); |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1082 | if ((atp_readb_io(dev, 0, 0x1c) & 0x80) == 0x00) { /* bsy ? */ |
| 1083 | atp_writew_io(dev, 0, 0x1c, 0); |
| 1084 | atp_writeb_io(dev, 0, 0x1b, 0); |
| 1085 | atp_writeb_io(dev, 0, 0x15, 0); |
| 1086 | atp_writeb_io(dev, 0, 0x18, 0x09); |
| 1087 | while ((atp_readb_io(dev, 0, 0x1f) & 0x80) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | cpu_relax(); |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1089 | atp_readb_io(dev, 0, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | return; |
| 1091 | } |
| 1092 | val &= 0x00ff; /* synchronization */ |
| 1093 | val |= 0x3f00; |
| 1094 | fun_scam(dev, &val); |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1095 | udelay(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | val &= 0x00ff; /* isolation */ |
| 1097 | val |= 0x2000; |
| 1098 | fun_scam(dev, &val); |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1099 | udelay(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | i = 8; |
| 1101 | j = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1103 | while (1) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1104 | if ((atp_readw_io(dev, 0, 0x1c) & 0x2000) == 0) |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1105 | continue; |
Ondrej Zary | 2bbbac4 | 2015-11-17 19:24:08 +0100 | [diff] [blame] | 1106 | udelay(2); |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1107 | val &= 0x00ff; /* get ID_STRING */ |
| 1108 | val |= 0x2000; |
| 1109 | k = fun_scam(dev, &val); |
| 1110 | if ((k & 0x03) == 0) |
| 1111 | break; |
| 1112 | mbuf[j] <<= 0x01; |
| 1113 | mbuf[j] &= 0xfe; |
| 1114 | if ((k & 0x02) != 0) |
| 1115 | mbuf[j] |= 0x01; |
| 1116 | i--; |
| 1117 | if (i > 0) |
| 1118 | continue; |
| 1119 | j++; |
| 1120 | i = 8; |
| 1121 | } |
| 1122 | |
| 1123 | /* isolation complete.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | /* mbuf[32]=0; |
| 1125 | printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */ |
| 1126 | i = 15; |
| 1127 | j = mbuf[0]; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1128 | if ((j & 0x20) != 0) { /* bit5=1:ID up to 7 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | i = 7; |
| 1130 | } |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1131 | if ((j & 0x06) != 0) { /* IDvalid? */ |
| 1132 | k = mbuf[1]; |
| 1133 | while (1) { |
| 1134 | m = 1; |
| 1135 | m <<= k; |
| 1136 | if ((m & assignid_map) == 0) |
| 1137 | break; |
| 1138 | if (k > 0) |
| 1139 | k--; |
| 1140 | else |
| 1141 | break; |
| 1142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1144 | if ((m & assignid_map) != 0) { /* srch from max acceptable ID# */ |
| 1145 | k = i; /* max acceptable ID# */ |
| 1146 | while (1) { |
| 1147 | m = 1; |
| 1148 | m <<= k; |
| 1149 | if ((m & assignid_map) == 0) |
| 1150 | break; |
| 1151 | if (k > 0) |
| 1152 | k--; |
| 1153 | else |
| 1154 | break; |
| 1155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | } |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1157 | /* k=binID#, */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | assignid_map |= m; |
| 1159 | if (k < 8) { |
| 1160 | quintet[0] = 0x38; /* 1st dft ID<8 */ |
| 1161 | } else { |
| 1162 | quintet[0] = 0x31; /* 1st ID>=8 */ |
| 1163 | } |
| 1164 | k &= 0x07; |
| 1165 | quintet[1] = g2q_tab[k]; |
| 1166 | |
| 1167 | val &= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */ |
| 1168 | m = quintet[0] << 8; |
| 1169 | val |= m; |
| 1170 | fun_scam(dev, &val); |
| 1171 | val &= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */ |
| 1172 | m = quintet[1] << 8; |
| 1173 | val |= m; |
| 1174 | fun_scam(dev, &val); |
| 1175 | |
Ondrej Zary | c7fcc08 | 2015-11-17 19:23:53 +0100 | [diff] [blame] | 1176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | static void atp870u_free_tables(struct Scsi_Host *host) |
| 1180 | { |
| 1181 | struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata; |
| 1182 | int j, k; |
| 1183 | for (j=0; j < 2; j++) { |
| 1184 | for (k = 0; k < 16; k++) { |
| 1185 | if (!atp_dev->id[j][k].prd_table) |
| 1186 | continue; |
James Bottomley | b568355 | 2005-09-15 08:59:36 -0500 | [diff] [blame] | 1187 | pci_free_consistent(atp_dev->pdev, 1024, atp_dev->id[j][k].prd_table, atp_dev->id[j][k].prd_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | atp_dev->id[j][k].prd_table = NULL; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | static int atp870u_init_tables(struct Scsi_Host *host) |
| 1194 | { |
| 1195 | struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata; |
| 1196 | int c,k; |
| 1197 | for(c=0;c < 2;c++) { |
| 1198 | for(k=0;k<16;k++) { |
James Bottomley | b568355 | 2005-09-15 08:59:36 -0500 | [diff] [blame] | 1199 | atp_dev->id[c][k].prd_table = pci_alloc_consistent(atp_dev->pdev, 1024, &(atp_dev->id[c][k].prd_bus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | if (!atp_dev->id[c][k].prd_table) { |
| 1201 | printk("atp870u_init_tables fail\n"); |
| 1202 | atp870u_free_tables(host); |
| 1203 | return -ENOMEM; |
| 1204 | } |
James Bottomley | b568355 | 2005-09-15 08:59:36 -0500 | [diff] [blame] | 1205 | atp_dev->id[c][k].prdaddr = atp_dev->id[c][k].prd_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | atp_dev->id[c][k].devsp=0x20; |
| 1207 | atp_dev->id[c][k].devtype = 0x7f; |
| 1208 | atp_dev->id[c][k].curr_req = NULL; |
| 1209 | } |
| 1210 | |
| 1211 | atp_dev->active_id[c] = 0; |
| 1212 | atp_dev->wide_id[c] = 0; |
| 1213 | atp_dev->host_id[c] = 0x07; |
| 1214 | atp_dev->quhd[c] = 0; |
| 1215 | atp_dev->quend[c] = 0; |
| 1216 | atp_dev->last_cmd[c] = 0xff; |
| 1217 | atp_dev->in_snd[c] = 0; |
| 1218 | atp_dev->in_int[c] = 0; |
| 1219 | |
| 1220 | for (k = 0; k < qcnt; k++) { |
| 1221 | atp_dev->quereq[c][k] = NULL; |
| 1222 | } |
| 1223 | for (k = 0; k < 16; k++) { |
| 1224 | atp_dev->id[c][k].curr_req = NULL; |
| 1225 | atp_dev->sp[c][k] = 0x04; |
| 1226 | } |
| 1227 | } |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
Ondrej Zary | 6a1961b | 2015-11-17 19:24:10 +0100 | [diff] [blame] | 1231 | static void atp_set_host_id(struct atp_unit *atp, u8 c, u8 host_id) |
| 1232 | { |
| 1233 | atp_writeb_io(atp, c, 0, host_id | 0x08); |
| 1234 | atp_writeb_io(atp, c, 0x18, 0); |
| 1235 | while ((atp_readb_io(atp, c, 0x1f) & 0x80) == 0) |
| 1236 | mdelay(1); |
| 1237 | atp_readb_io(atp, c, 0x17); |
| 1238 | atp_writeb_io(atp, c, 1, 8); |
| 1239 | atp_writeb_io(atp, c, 2, 0x7f); |
| 1240 | atp_writeb_io(atp, c, 0x11, 0x20); |
| 1241 | } |
| 1242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | /* return non-zero on detection */ |
| 1244 | static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1245 | { |
| 1246 | unsigned char k, m, c; |
| 1247 | unsigned long flags; |
Ondrej Zary | 493c520 | 2015-11-17 19:23:44 +0100 | [diff] [blame] | 1248 | unsigned int base_io, error,n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | unsigned char host_id; |
| 1250 | struct Scsi_Host *shpnt = NULL; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1251 | struct atp_unit *atpdev, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | unsigned char setupdata[2][16]; |
| 1253 | int count = 0; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1254 | |
| 1255 | atpdev = kzalloc(sizeof(*atpdev), GFP_KERNEL); |
| 1256 | if (!atpdev) |
| 1257 | return -ENOMEM; |
| 1258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | if (pci_enable_device(pdev)) |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1260 | goto err_eio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Ondrej Zary | 34a2c35 | 2015-11-17 19:24:11 +0100 | [diff] [blame] | 1262 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | printk(KERN_ERR "atp870u: DMA mask required but not available.\n"); |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1264 | goto err_eio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | /* |
| 1268 | * It's probably easier to weed out some revisions like |
| 1269 | * this than via the PCI device table |
| 1270 | */ |
| 1271 | if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) { |
Sergei Shtylyov | 7d7311c | 2012-03-14 22:04:30 +0300 | [diff] [blame] | 1272 | atpdev->chip_ver = pdev->revision; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1273 | if (atpdev->chip_ver < 2) |
| 1274 | goto err_eio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | switch (ent->device) { |
| 1278 | case PCI_DEVICE_ID_ARTOP_AEC7612UW: |
| 1279 | case PCI_DEVICE_ID_ARTOP_AEC7612SUW: |
| 1280 | case ATP880_DEVID1: |
| 1281 | case ATP880_DEVID2: |
| 1282 | case ATP885_DEVID: |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1283 | atpdev->chip_ver = 0x04; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | default: |
| 1285 | break; |
| 1286 | } |
| 1287 | base_io = pci_resource_start(pdev, 0); |
| 1288 | base_io &= 0xfffffff8; |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1289 | atpdev->baseport = base_io; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) { |
Sergei Shtylyov | 7d7311c | 2012-03-14 22:04:30 +0300 | [diff] [blame] | 1292 | atpdev->chip_ver = pdev->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803 |
| 1294 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1295 | atpdev->ioport[0] = base_io + 0x40; |
| 1296 | atpdev->pciport[0] = base_io + 0x28; |
| 1297 | |
| 1298 | host_id = atp_readb_base(atpdev, 0x39); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | host_id >>= 0x04; |
| 1300 | |
| 1301 | printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d" |
| 1302 | " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq); |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1303 | atpdev->dev_id = ent->device; |
| 1304 | atpdev->host_id[0] = host_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1306 | atpdev->scam_on = atp_readb_base(atpdev, 0x22); |
| 1307 | atpdev->global_map[0] = atp_readb_base(atpdev, 0x35); |
| 1308 | atpdev->ultra_map[0] = atp_readw_base(atpdev, 0x3c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
| 1310 | n = 0x3f09; |
| 1311 | next_fblk_880: |
| 1312 | if (n >= 0x4000) |
| 1313 | goto flash_ok_880; |
| 1314 | |
| 1315 | m = 0; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1316 | atp_writew_base(atpdev, 0x34, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | n += 0x0002; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1318 | if (atp_readb_base(atpdev, 0x30) == 0xff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | goto flash_ok_880; |
| 1320 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1321 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30); |
| 1322 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31); |
| 1323 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32); |
| 1324 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33); |
| 1325 | atp_writew_base(atpdev, 0x34, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | n += 0x0002; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1327 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30); |
| 1328 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31); |
| 1329 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32); |
| 1330 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33); |
| 1331 | atp_writew_base(atpdev, 0x34, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | n += 0x0002; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1333 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30); |
| 1334 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31); |
| 1335 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32); |
| 1336 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33); |
| 1337 | atp_writew_base(atpdev, 0x34, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | n += 0x0002; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1339 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30); |
| 1340 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31); |
| 1341 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32); |
| 1342 | atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | n += 0x0018; |
| 1344 | goto next_fblk_880; |
| 1345 | flash_ok_880: |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1346 | atp_writew_base(atpdev, 0x34, 0); |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1347 | atpdev->ultra_map[0] = 0; |
| 1348 | atpdev->async[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | for (k = 0; k < 16; k++) { |
| 1350 | n = 1; |
| 1351 | n = n << k; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1352 | if (atpdev->sp[0][k] > 1) { |
| 1353 | atpdev->ultra_map[0] |= n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | } else { |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1355 | if (atpdev->sp[0][k] == 0) |
| 1356 | atpdev->async[0] |= n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } |
| 1358 | } |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1359 | atpdev->async[0] = ~(atpdev->async[0]); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1360 | atp_writeb_base(atpdev, 0x35, atpdev->global_map[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | |
| 1362 | shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit)); |
| 1363 | if (!shpnt) |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1364 | goto err_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
| 1366 | p = (struct atp_unit *)&shpnt->hostdata; |
| 1367 | |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1368 | atpdev->host = shpnt; |
| 1369 | atpdev->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | pci_set_drvdata(pdev, p); |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1371 | memcpy(p, atpdev, sizeof(*atpdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | if (atp870u_init_tables(shpnt) < 0) { |
| 1373 | printk(KERN_ERR "Unable to allocate tables for Acard controller\n"); |
| 1374 | goto unregister; |
| 1375 | } |
| 1376 | |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 1377 | if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp880i", shpnt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq); |
| 1379 | goto free_tables; |
| 1380 | } |
| 1381 | |
| 1382 | spin_lock_irqsave(shpnt->host_lock, flags); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1383 | k = atp_readb_base(p, 0x38) & 0x80; |
| 1384 | atp_writeb_base(p, 0x38, k); |
| 1385 | atp_writeb_base(p, 0x3b, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | mdelay(32); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1387 | atp_writeb_base(p, 0x3b, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | mdelay(32); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1389 | atp_readb_io(p, 0, 0x1b); |
| 1390 | atp_readb_io(p, 0, 0x17); |
Ondrej Zary | 6a1961b | 2015-11-17 19:24:10 +0100 | [diff] [blame] | 1391 | |
| 1392 | atp_set_host_id(p, 0, host_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
| 1394 | tscam(shpnt); |
Ondrej Zary | 4192a40 | 2015-11-17 19:24:06 +0100 | [diff] [blame] | 1395 | atp_is(p, 0, true, atp_readb_base(p, 0x3f) & 0x40); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1396 | atp_writeb_base(p, 0x38, 0xb0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | shpnt->max_id = 16; |
| 1398 | shpnt->this_id = host_id; |
| 1399 | shpnt->unique_id = base_io; |
| 1400 | shpnt->io_port = base_io; |
| 1401 | shpnt->n_io_port = 0x60; /* Number of bytes of I/O space used */ |
| 1402 | shpnt->irq = pdev->irq; |
| 1403 | } else if (ent->device == ATP885_DEVID) { |
| 1404 | printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n" |
| 1405 | , base_io, pdev->irq); |
| 1406 | |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1407 | atpdev->pdev = pdev; |
| 1408 | atpdev->dev_id = ent->device; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1409 | atpdev->ioport[0] = base_io + 0x80; |
| 1410 | atpdev->ioport[1] = base_io + 0xc0; |
| 1411 | atpdev->pciport[0] = base_io + 0x40; |
| 1412 | atpdev->pciport[1] = base_io + 0x50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
| 1414 | shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit)); |
| 1415 | if (!shpnt) |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1416 | goto err_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
| 1418 | p = (struct atp_unit *)&shpnt->hostdata; |
| 1419 | |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1420 | atpdev->host = shpnt; |
| 1421 | atpdev->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | pci_set_drvdata(pdev, p); |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1423 | memcpy(p, atpdev, sizeof(struct atp_unit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | if (atp870u_init_tables(shpnt) < 0) |
| 1425 | goto unregister; |
| 1426 | |
| 1427 | #ifdef ED_DBGP |
| 1428 | printk("request_irq() shpnt %p hostdata %p\n", shpnt, p); |
| 1429 | #endif |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 1430 | if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870u", shpnt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | printk(KERN_ERR "Unable to allocate IRQ for Acard controller.\n"); |
| 1432 | goto free_tables; |
| 1433 | } |
| 1434 | |
| 1435 | spin_lock_irqsave(shpnt->host_lock, flags); |
| 1436 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1437 | c = atp_readb_base(p, 0x29); |
| 1438 | atp_writeb_base(p, 0x29, c | 0x04); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
| 1440 | n=0x1f80; |
| 1441 | next_fblk_885: |
| 1442 | if (n >= 0x2000) { |
| 1443 | goto flash_ok_885; |
| 1444 | } |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1445 | atp_writew_base(p, 0x3c, n); |
| 1446 | if (atp_readl_base(p, 0x38) == 0xffffffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | goto flash_ok_885; |
| 1448 | } |
| 1449 | for (m=0; m < 2; m++) { |
| 1450 | p->global_map[m]= 0; |
| 1451 | for (k=0; k < 4; k++) { |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1452 | atp_writew_base(p, 0x3c, n++); |
| 1453 | ((unsigned long *)&setupdata[m][0])[k] = atp_readl_base(p, 0x38); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | } |
| 1455 | for (k=0; k < 4; k++) { |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1456 | atp_writew_base(p, 0x3c, n++); |
| 1457 | ((unsigned long *)&p->sp[m][0])[k] = atp_readl_base(p, 0x38); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | } |
| 1459 | n += 8; |
| 1460 | } |
| 1461 | goto next_fblk_885; |
| 1462 | flash_ok_885: |
| 1463 | #ifdef ED_DBGP |
| 1464 | printk( "Flash Read OK\n"); |
| 1465 | #endif |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1466 | c = atp_readb_base(p, 0x29); |
| 1467 | atp_writeb_base(p, 0x29, c & 0xfb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | for (c=0;c < 2;c++) { |
| 1469 | p->ultra_map[c]=0; |
| 1470 | p->async[c] = 0; |
| 1471 | for (k=0; k < 16; k++) { |
| 1472 | n=1; |
| 1473 | n = n << k; |
| 1474 | if (p->sp[c][k] > 1) { |
| 1475 | p->ultra_map[c] |= n; |
| 1476 | } else { |
| 1477 | if (p->sp[c][k] == 0) { |
| 1478 | p->async[c] |= n; |
| 1479 | } |
| 1480 | } |
| 1481 | } |
| 1482 | p->async[c] = ~(p->async[c]); |
| 1483 | |
| 1484 | if (p->global_map[c] == 0) { |
| 1485 | k=setupdata[c][1]; |
| 1486 | if ((k & 0x40) != 0) |
| 1487 | p->global_map[c] |= 0x20; |
| 1488 | k &= 0x07; |
| 1489 | p->global_map[c] |= k; |
| 1490 | if ((setupdata[c][2] & 0x04) != 0) |
| 1491 | p->global_map[c] |= 0x08; |
| 1492 | p->host_id[c] = setupdata[c][0] & 0x07; |
| 1493 | } |
| 1494 | } |
| 1495 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1496 | k = atp_readb_base(p, 0x28) & 0x8f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | k |= 0x10; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1498 | atp_writeb_base(p, 0x28, k); |
| 1499 | atp_writeb_pci(p, 0, 1, 0x80); |
| 1500 | atp_writeb_pci(p, 1, 1, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | mdelay(100); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1502 | atp_writeb_pci(p, 0, 1, 0); |
| 1503 | atp_writeb_pci(p, 1, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | mdelay(1000); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1505 | atp_readb_io(p, 0, 0x1b); |
| 1506 | atp_readb_io(p, 0, 0x17); |
| 1507 | atp_readb_io(p, 1, 0x1b); |
| 1508 | atp_readb_io(p, 1, 0x17); |
Ondrej Zary | 6a1961b | 2015-11-17 19:24:10 +0100 | [diff] [blame] | 1509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | k=p->host_id[0]; |
| 1511 | if (k > 7) |
| 1512 | k = (k & 0x07) | 0x40; |
Ondrej Zary | 6a1961b | 2015-11-17 19:24:10 +0100 | [diff] [blame] | 1513 | atp_set_host_id(p, 0, k); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | k=p->host_id[1]; |
| 1516 | if (k > 7) |
| 1517 | k = (k & 0x07) | 0x40; |
Ondrej Zary | 6a1961b | 2015-11-17 19:24:10 +0100 | [diff] [blame] | 1518 | atp_set_host_id(p, 1, k); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | |
Ondrej Zary | c4ad92b | 2015-11-17 19:24:12 +0100 | [diff] [blame] | 1520 | mdelay(600); /* this delay used to be called tscam_885() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | printk(KERN_INFO " Scanning Channel A SCSI Device ...\n"); |
Ondrej Zary | 4192a40 | 2015-11-17 19:24:06 +0100 | [diff] [blame] | 1522 | atp_is(p, 0, true, atp_readb_io(p, 0, 0x1b) >> 7); |
Ondrej Zary | fa50b30 | 2015-11-17 19:24:00 +0100 | [diff] [blame] | 1523 | atp_writeb_io(p, 0, 0x16, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | printk(KERN_INFO " Scanning Channel B SCSI Device ...\n"); |
Ondrej Zary | 4192a40 | 2015-11-17 19:24:06 +0100 | [diff] [blame] | 1525 | atp_is(p, 1, true, atp_readb_io(p, 1, 0x1b) >> 7); |
Ondrej Zary | fa50b30 | 2015-11-17 19:24:00 +0100 | [diff] [blame] | 1526 | atp_writeb_io(p, 1, 0x16, 0x80); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1527 | k = atp_readb_base(p, 0x28) & 0xcf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | k |= 0xc0; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1529 | atp_writeb_base(p, 0x28, k); |
| 1530 | k = atp_readb_base(p, 0x1f) | 0x80; |
| 1531 | atp_writeb_base(p, 0x1f, k); |
| 1532 | k = atp_readb_base(p, 0x29) | 0x01; |
| 1533 | atp_writeb_base(p, 0x29, k); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | #ifdef ED_DBGP |
| 1535 | //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]); |
| 1536 | #endif |
| 1537 | shpnt->max_id = 16; |
| 1538 | shpnt->max_lun = (p->global_map[0] & 0x07) + 1; |
| 1539 | shpnt->max_channel = 1; |
| 1540 | shpnt->this_id = p->host_id[0]; |
| 1541 | shpnt->unique_id = base_io; |
| 1542 | shpnt->io_port = base_io; |
| 1543 | shpnt->n_io_port = 0xff; /* Number of bytes of I/O space used */ |
| 1544 | shpnt->irq = pdev->irq; |
| 1545 | |
| 1546 | } else { |
| 1547 | error = pci_read_config_byte(pdev, 0x49, &host_id); |
| 1548 | |
| 1549 | printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d " |
| 1550 | "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq); |
| 1551 | |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1552 | atpdev->ioport[0] = base_io; |
| 1553 | atpdev->pciport[0] = base_io + 0x20; |
| 1554 | atpdev->dev_id = ent->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | host_id &= 0x07; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1556 | atpdev->host_id[0] = host_id; |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1557 | atpdev->scam_on = atp_readb_pci(atpdev, 0, 2); |
| 1558 | atpdev->global_map[0] = atp_readb_base(atpdev, 0x2d); |
| 1559 | atpdev->ultra_map[0] = atp_readw_base(atpdev, 0x2e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1561 | if (atpdev->ultra_map[0] == 0) { |
| 1562 | atpdev->scam_on = 0x00; |
| 1563 | atpdev->global_map[0] = 0x20; |
| 1564 | atpdev->ultra_map[0] = 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit)); |
| 1568 | if (!shpnt) |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1569 | goto err_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
| 1571 | p = (struct atp_unit *)&shpnt->hostdata; |
| 1572 | |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1573 | atpdev->host = shpnt; |
| 1574 | atpdev->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | pci_set_drvdata(pdev, p); |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1576 | memcpy(p, atpdev, sizeof(*atpdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | if (atp870u_init_tables(shpnt) < 0) |
| 1578 | goto unregister; |
| 1579 | |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 1580 | if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870i", shpnt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq); |
| 1582 | goto free_tables; |
| 1583 | } |
| 1584 | |
| 1585 | spin_lock_irqsave(shpnt->host_lock, flags); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1586 | if (atpdev->chip_ver > 0x07) /* check if atp876 chip then enable terminator */ |
| 1587 | atp_writeb_base(p, 0x3e, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1589 | k = (atp_readb_base(p, 0x3a) & 0xf3) | 0x10; |
| 1590 | atp_writeb_base(p, 0x3a, k); |
| 1591 | atp_writeb_base(p, 0x3a, k & 0xdf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | mdelay(32); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1593 | atp_writeb_base(p, 0x3a, k); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | mdelay(32); |
Ondrej Zary | 6a1961b | 2015-11-17 19:24:10 +0100 | [diff] [blame] | 1595 | atp_set_host_id(p, 0, host_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
| 1597 | tscam(shpnt); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1598 | atp_writeb_base(p, 0x3a, atp_readb_base(p, 0x3a) | 0x10); |
Ondrej Zary | 4192a40 | 2015-11-17 19:24:06 +0100 | [diff] [blame] | 1599 | atp_is(p, 0, p->chip_ver == 4, 0); |
Ondrej Zary | d804bb2 | 2015-11-17 19:24:07 +0100 | [diff] [blame] | 1600 | atp_writeb_base(p, 0x3a, atp_readb_base(p, 0x3a) & 0xef); |
| 1601 | atp_writeb_base(p, 0x3b, atp_readb_base(p, 0x3b) | 0x20); |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1602 | if (atpdev->chip_ver == 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | shpnt->max_id = 16; |
| 1604 | else |
Hannes Reinecke | 2b89dad | 2006-05-23 10:29:28 +0200 | [diff] [blame] | 1605 | shpnt->max_id = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | shpnt->this_id = host_id; |
| 1607 | shpnt->unique_id = base_io; |
| 1608 | shpnt->io_port = base_io; |
| 1609 | shpnt->n_io_port = 0x40; /* Number of bytes of I/O space used */ |
| 1610 | shpnt->irq = pdev->irq; |
| 1611 | } |
| 1612 | spin_unlock_irqrestore(shpnt->host_lock, flags); |
| 1613 | if(ent->device==ATP885_DEVID) { |
| 1614 | if(!request_region(base_io, 0xff, "atp870u")) /* Register the IO ports that we use */ |
| 1615 | goto request_io_fail; |
| 1616 | } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) { |
| 1617 | if(!request_region(base_io, 0x60, "atp870u")) /* Register the IO ports that we use */ |
| 1618 | goto request_io_fail; |
| 1619 | } else { |
| 1620 | if(!request_region(base_io, 0x40, "atp870u")) /* Register the IO ports that we use */ |
| 1621 | goto request_io_fail; |
| 1622 | } |
| 1623 | count++; |
| 1624 | if (scsi_add_host(shpnt, &pdev->dev)) |
| 1625 | goto scsi_add_fail; |
| 1626 | scsi_scan_host(shpnt); |
| 1627 | #ifdef ED_DBGP |
| 1628 | printk("atp870u_prob : exit\n"); |
| 1629 | #endif |
| 1630 | return 0; |
| 1631 | |
| 1632 | scsi_add_fail: |
| 1633 | printk("atp870u_prob:scsi_add_fail\n"); |
| 1634 | if(ent->device==ATP885_DEVID) { |
| 1635 | release_region(base_io, 0xff); |
| 1636 | } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) { |
| 1637 | release_region(base_io, 0x60); |
| 1638 | } else { |
| 1639 | release_region(base_io, 0x40); |
| 1640 | } |
| 1641 | request_io_fail: |
| 1642 | printk("atp870u_prob:request_io_fail\n"); |
| 1643 | free_irq(pdev->irq, shpnt); |
| 1644 | free_tables: |
| 1645 | printk("atp870u_prob:free_table\n"); |
| 1646 | atp870u_free_tables(shpnt); |
| 1647 | unregister: |
| 1648 | printk("atp870u_prob:unregister\n"); |
| 1649 | scsi_host_put(shpnt); |
| 1650 | return -1; |
Randy Dunlap | dc6a78f | 2006-06-27 22:01:28 -0700 | [diff] [blame] | 1651 | err_eio: |
| 1652 | kfree(atpdev); |
| 1653 | return -EIO; |
| 1654 | err_nomem: |
| 1655 | kfree(atpdev); |
| 1656 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /* The abort command does not leave the device in a clean state where |
| 1660 | it is available to be used again. Until this gets worked out, we will |
| 1661 | leave it commented out. */ |
| 1662 | |
| 1663 | static int atp870u_abort(struct scsi_cmnd * SCpnt) |
| 1664 | { |
| 1665 | unsigned char j, k, c; |
| 1666 | struct scsi_cmnd *workrequ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | struct atp_unit *dev; |
| 1668 | struct Scsi_Host *host; |
| 1669 | host = SCpnt->device->host; |
| 1670 | |
| 1671 | dev = (struct atp_unit *)&host->hostdata; |
Jeff Garzik | 422c0d6 | 2005-10-24 18:05:09 -0400 | [diff] [blame] | 1672 | c = scmd_channel(SCpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | printk(" atp870u: abort Channel = %x \n", c); |
| 1674 | printk("working=%x last_cmd=%x ", dev->working[c], dev->last_cmd[c]); |
| 1675 | printk(" quhdu=%x quendu=%x ", dev->quhd[c], dev->quend[c]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | for (j = 0; j < 0x18; j++) { |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1677 | printk(" r%2x=%2x", j, atp_readb_io(dev, c, j)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | } |
Ondrej Zary | 6a3cebb | 2015-11-17 19:23:54 +0100 | [diff] [blame] | 1679 | printk(" r1c=%2x", atp_readb_io(dev, c, 0x1c)); |
| 1680 | printk(" r1f=%2x in_snd=%2x ", atp_readb_io(dev, c, 0x1f), dev->in_snd[c]); |
| 1681 | printk(" d00=%2x", atp_readb_pci(dev, c, 0x00)); |
| 1682 | printk(" d02=%2x", atp_readb_pci(dev, c, 0x02)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | for(j=0;j<16;j++) { |
| 1684 | if (dev->id[c][j].curr_req != NULL) { |
| 1685 | workrequ = dev->id[c][j].curr_req; |
| 1686 | printk("\n que cdb= "); |
| 1687 | for (k=0; k < workrequ->cmd_len; k++) { |
| 1688 | printk(" %2x ",workrequ->cmnd[k]); |
| 1689 | } |
| 1690 | printk(" last_lenu= %x ",(unsigned int)dev->id[c][j].last_len); |
| 1691 | } |
| 1692 | } |
| 1693 | return SUCCESS; |
| 1694 | } |
| 1695 | |
| 1696 | static const char *atp870u_info(struct Scsi_Host *notused) |
| 1697 | { |
| 1698 | static char buffer[128]; |
| 1699 | |
| 1700 | strcpy(buffer, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac "); |
| 1701 | |
| 1702 | return buffer; |
| 1703 | } |
| 1704 | |
Al Viro | d773e42 | 2013-03-31 03:26:26 -0400 | [diff] [blame] | 1705 | static int atp870u_show_info(struct seq_file *m, struct Scsi_Host *HBAptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | { |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 1707 | seq_puts(m, "ACARD AEC-671X Driver Version: 2.6+ac\n\n" |
| 1708 | "Adapter Configuration:\n"); |
Al Viro | d773e42 | 2013-03-31 03:26:26 -0400 | [diff] [blame] | 1709 | seq_printf(m, " Base IO: %#.4lx\n", HBAptr->io_port); |
| 1710 | seq_printf(m, " IRQ: %d\n", HBAptr->irq); |
| 1711 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | |
| 1715 | static int atp870u_biosparam(struct scsi_device *disk, struct block_device *dev, |
| 1716 | sector_t capacity, int *ip) |
| 1717 | { |
| 1718 | int heads, sectors, cylinders; |
| 1719 | |
| 1720 | heads = 64; |
| 1721 | sectors = 32; |
| 1722 | cylinders = (unsigned long)capacity / (heads * sectors); |
| 1723 | if (cylinders > 1024) { |
| 1724 | heads = 255; |
| 1725 | sectors = 63; |
| 1726 | cylinders = (unsigned long)capacity / (heads * sectors); |
| 1727 | } |
| 1728 | ip[0] = heads; |
| 1729 | ip[1] = sectors; |
| 1730 | ip[2] = cylinders; |
| 1731 | |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
| 1735 | static void atp870u_remove (struct pci_dev *pdev) |
| 1736 | { |
| 1737 | struct atp_unit *devext = pci_get_drvdata(pdev); |
| 1738 | struct Scsi_Host *pshost = devext->host; |
| 1739 | |
| 1740 | |
| 1741 | scsi_remove_host(pshost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | free_irq(pshost->irq, pshost); |
| 1743 | release_region(pshost->io_port, pshost->n_io_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | atp870u_free_tables(pshost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | scsi_host_put(pshost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | } |
| 1747 | MODULE_LICENSE("GPL"); |
| 1748 | |
| 1749 | static struct scsi_host_template atp870u_template = { |
| 1750 | .module = THIS_MODULE, |
| 1751 | .name = "atp870u" /* name */, |
| 1752 | .proc_name = "atp870u", |
Al Viro | d773e42 | 2013-03-31 03:26:26 -0400 | [diff] [blame] | 1753 | .show_info = atp870u_show_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | .info = atp870u_info /* info */, |
| 1755 | .queuecommand = atp870u_queuecommand /* queuecommand */, |
| 1756 | .eh_abort_handler = atp870u_abort /* abort */, |
| 1757 | .bios_param = atp870u_biosparam /* biosparm */, |
| 1758 | .can_queue = qcnt /* can_queue */, |
| 1759 | .this_id = 7 /* SCSI ID */, |
| 1760 | .sg_tablesize = ATP870U_SCATTER /*SG_ALL*/ /*SG_NONE*/, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | .use_clustering = ENABLE_CLUSTERING, |
| 1762 | .max_sectors = ATP870U_MAX_SECTORS, |
| 1763 | }; |
| 1764 | |
| 1765 | static struct pci_device_id atp870u_id_table[] = { |
| 1766 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP885_DEVID) }, |
| 1767 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID1) }, |
| 1768 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID2) }, |
| 1769 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7610) }, |
| 1770 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612UW) }, |
| 1771 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612U) }, |
| 1772 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612S) }, |
| 1773 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612D) }, |
| 1774 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612SUW) }, |
| 1775 | { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_8060) }, |
| 1776 | { 0, }, |
| 1777 | }; |
| 1778 | |
| 1779 | MODULE_DEVICE_TABLE(pci, atp870u_id_table); |
| 1780 | |
| 1781 | static struct pci_driver atp870u_driver = { |
| 1782 | .id_table = atp870u_id_table, |
| 1783 | .name = "atp870u", |
| 1784 | .probe = atp870u_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1785 | .remove = atp870u_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | }; |
| 1787 | |
Ondrej Zary | 1ccd7d6 | 2015-11-17 19:24:13 +0100 | [diff] [blame^] | 1788 | module_pci_driver(atp870u_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Ondrej Zary | 4192a40 | 2015-11-17 19:24:06 +0100 | [diff] [blame] | 1790 | static void atp_is(struct atp_unit *dev, unsigned char c, bool wide_chip, unsigned char lvdmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | { |
Ondrej Zary | fa50b30 | 2015-11-17 19:24:00 +0100 | [diff] [blame] | 1792 | unsigned char i, j, k, rmb, n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | unsigned short int m; |
| 1794 | static unsigned char mbuf[512]; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1795 | static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 }; |
| 1796 | static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 }; |
| 1797 | static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e }; |
| 1798 | unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e }; |
| 1799 | static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x19, 0x0e }; |
Ondrej Zary | 460da918 | 2015-11-17 19:24:03 +0100 | [diff] [blame] | 1800 | static unsigned char synw_870[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 }; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1801 | unsigned char synuw[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e }; |
| 1802 | static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 }; |
| 1803 | static unsigned char u3[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | for (i = 0; i < 16; i++) { |
Ondrej Zary | 197fb8d | 2015-11-17 19:24:02 +0100 | [diff] [blame] | 1806 | if (!wide_chip && (i > 7)) |
| 1807 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | m = 1; |
| 1809 | m = m << i; |
| 1810 | if ((m & dev->active_id[c]) != 0) { |
| 1811 | continue; |
| 1812 | } |
| 1813 | if (i == dev->host_id[c]) { |
| 1814 | printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[c]); |
| 1815 | continue; |
| 1816 | } |
Ondrej Zary | 197fb8d | 2015-11-17 19:24:02 +0100 | [diff] [blame] | 1817 | atp_writeb_io(dev, c, 0x1b, wide_chip ? 0x01 : 0x00); |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1818 | atp_writeb_io(dev, c, 1, 0x08); |
| 1819 | atp_writeb_io(dev, c, 2, 0x7f); |
| 1820 | atp_writeb_io(dev, c, 3, satn[0]); |
| 1821 | atp_writeb_io(dev, c, 4, satn[1]); |
| 1822 | atp_writeb_io(dev, c, 5, satn[2]); |
| 1823 | atp_writeb_io(dev, c, 6, satn[3]); |
| 1824 | atp_writeb_io(dev, c, 7, satn[4]); |
| 1825 | atp_writeb_io(dev, c, 8, satn[5]); |
| 1826 | atp_writeb_io(dev, c, 0x0f, 0); |
| 1827 | atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp); |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1828 | atp_writeb_io(dev, c, 0x12, 0); |
| 1829 | atp_writeb_io(dev, c, 0x13, satn[6]); |
| 1830 | atp_writeb_io(dev, c, 0x14, satn[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | j = i; |
| 1832 | if ((j & 0x08) != 0) { |
| 1833 | j = (j & 0x07) | 0x40; |
| 1834 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1835 | atp_writeb_io(dev, c, 0x15, j); |
| 1836 | atp_writeb_io(dev, c, 0x18, satn[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1838 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1840 | |
| 1841 | if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | continue; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1843 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1844 | while (atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | dev->active_id[c] |= m; |
| 1848 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1849 | atp_writeb_io(dev, c, 0x10, 0x30); |
Ondrej Zary | 460da918 | 2015-11-17 19:24:03 +0100 | [diff] [blame] | 1850 | if (dev->dev_id == ATP885_DEVID || dev->dev_id == ATP880_DEVID1 || dev->dev_id == ATP880_DEVID2) |
| 1851 | atp_writeb_io(dev, c, 0x14, 0x00); |
| 1852 | else /* result of is870() merge - is this a bug? */ |
| 1853 | atp_writeb_io(dev, c, 0x04, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | |
| 1855 | phase_cmd: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1856 | atp_writeb_io(dev, c, 0x18, 0x08); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1857 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1858 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1860 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1861 | j = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | if (j != 0x16) { |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1863 | atp_writeb_io(dev, c, 0x10, 0x41); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | goto phase_cmd; |
| 1865 | } |
| 1866 | sel_ok: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1867 | atp_writeb_io(dev, c, 3, inqd[0]); |
| 1868 | atp_writeb_io(dev, c, 4, inqd[1]); |
| 1869 | atp_writeb_io(dev, c, 5, inqd[2]); |
| 1870 | atp_writeb_io(dev, c, 6, inqd[3]); |
| 1871 | atp_writeb_io(dev, c, 7, inqd[4]); |
| 1872 | atp_writeb_io(dev, c, 8, inqd[5]); |
| 1873 | atp_writeb_io(dev, c, 0x0f, 0); |
| 1874 | atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp); |
| 1875 | atp_writeb_io(dev, c, 0x12, 0); |
| 1876 | atp_writeb_io(dev, c, 0x13, inqd[6]); |
| 1877 | atp_writeb_io(dev, c, 0x14, inqd[7]); |
| 1878 | atp_writeb_io(dev, c, 0x18, inqd[8]); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1879 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1880 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1882 | |
| 1883 | if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | continue; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1885 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1886 | while (atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1888 | |
Ondrej Zary | 197fb8d | 2015-11-17 19:24:02 +0100 | [diff] [blame] | 1889 | if (wide_chip) |
| 1890 | atp_writeb_io(dev, c, 0x1b, 0x00); |
| 1891 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1892 | atp_writeb_io(dev, c, 0x18, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | j = 0; |
| 1894 | rd_inq_data: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1895 | k = atp_readb_io(dev, c, 0x1f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | if ((k & 0x01) != 0) { |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1897 | mbuf[j++] = atp_readb_io(dev, c, 0x19); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | goto rd_inq_data; |
| 1899 | } |
| 1900 | if ((k & 0x80) == 0) { |
| 1901 | goto rd_inq_data; |
| 1902 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1903 | j = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | if (j == 0x16) { |
| 1905 | goto inq_ok; |
| 1906 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1907 | atp_writeb_io(dev, c, 0x10, 0x46); |
| 1908 | atp_writeb_io(dev, c, 0x12, 0); |
| 1909 | atp_writeb_io(dev, c, 0x13, 0); |
| 1910 | atp_writeb_io(dev, c, 0x14, 0); |
| 1911 | atp_writeb_io(dev, c, 0x18, 0x08); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1912 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1913 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1915 | |
| 1916 | if (atp_readb_io(dev, c, 0x17) != 0x16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | goto sel_ok; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | inq_ok: |
| 1920 | mbuf[36] = 0; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1921 | printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | dev->id[c][i].devtype = mbuf[0]; |
| 1923 | rmb = mbuf[1]; |
| 1924 | n = mbuf[7]; |
Ondrej Zary | 197fb8d | 2015-11-17 19:24:02 +0100 | [diff] [blame] | 1925 | if (!wide_chip) |
| 1926 | goto not_wide; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | if ((mbuf[7] & 0x60) == 0) { |
| 1928 | goto not_wide; |
| 1929 | } |
Ondrej Zary | 197fb8d | 2015-11-17 19:24:02 +0100 | [diff] [blame] | 1930 | if (dev->dev_id == ATP885_DEVID || dev->dev_id == ATP880_DEVID1 || dev->dev_id == ATP880_DEVID2) { |
| 1931 | if ((i < 8) && ((dev->global_map[c] & 0x20) == 0)) |
| 1932 | goto not_wide; |
| 1933 | } else { /* result of is870() merge - is this a bug? */ |
| 1934 | if ((dev->global_map[c] & 0x20) == 0) |
| 1935 | goto not_wide; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | } |
| 1937 | if (lvdmode == 0) { |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1938 | goto chg_wide; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | } |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1940 | if (dev->sp[c][i] != 0x04) // force u2 |
| 1941 | { |
| 1942 | goto chg_wide; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1945 | atp_writeb_io(dev, c, 0x1b, 0x01); |
| 1946 | atp_writeb_io(dev, c, 3, satn[0]); |
| 1947 | atp_writeb_io(dev, c, 4, satn[1]); |
| 1948 | atp_writeb_io(dev, c, 5, satn[2]); |
| 1949 | atp_writeb_io(dev, c, 6, satn[3]); |
| 1950 | atp_writeb_io(dev, c, 7, satn[4]); |
| 1951 | atp_writeb_io(dev, c, 8, satn[5]); |
| 1952 | atp_writeb_io(dev, c, 0x0f, 0); |
| 1953 | atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp); |
| 1954 | atp_writeb_io(dev, c, 0x12, 0); |
| 1955 | atp_writeb_io(dev, c, 0x13, satn[6]); |
| 1956 | atp_writeb_io(dev, c, 0x14, satn[7]); |
| 1957 | atp_writeb_io(dev, c, 0x18, satn[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1959 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1961 | |
| 1962 | if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | continue; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1964 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1965 | while (atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | try_u3: |
| 1969 | j = 0; |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1970 | atp_writeb_io(dev, c, 0x14, 0x09); |
| 1971 | atp_writeb_io(dev, c, 0x18, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1973 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) { |
| 1974 | if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0) |
| 1975 | atp_writeb_io(dev, c, 0x19, u3[j++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | cpu_relax(); |
| 1977 | } |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1978 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1979 | while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 1981 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1982 | j = atp_readb_io(dev, c, 0x17) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | if (j == 0x0f) { |
| 1984 | goto u3p_in; |
| 1985 | } |
| 1986 | if (j == 0x0a) { |
| 1987 | goto u3p_cmd; |
| 1988 | } |
| 1989 | if (j == 0x0e) { |
| 1990 | goto try_u3; |
| 1991 | } |
| 1992 | continue; |
| 1993 | u3p_out: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 1994 | atp_writeb_io(dev, c, 0x18, 0x20); |
| 1995 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) { |
| 1996 | if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0) |
| 1997 | atp_writeb_io(dev, c, 0x19, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | cpu_relax(); |
| 1999 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2000 | j = atp_readb_io(dev, c, 0x17) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | if (j == 0x0f) { |
| 2002 | goto u3p_in; |
| 2003 | } |
| 2004 | if (j == 0x0a) { |
| 2005 | goto u3p_cmd; |
| 2006 | } |
| 2007 | if (j == 0x0e) { |
| 2008 | goto u3p_out; |
| 2009 | } |
| 2010 | continue; |
| 2011 | u3p_in: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2012 | atp_writeb_io(dev, c, 0x14, 0x09); |
| 2013 | atp_writeb_io(dev, c, 0x18, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | k = 0; |
| 2015 | u3p_in1: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2016 | j = atp_readb_io(dev, c, 0x1f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | if ((j & 0x01) != 0) { |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2018 | mbuf[k++] = atp_readb_io(dev, c, 0x19); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | goto u3p_in1; |
| 2020 | } |
| 2021 | if ((j & 0x80) == 0x00) { |
| 2022 | goto u3p_in1; |
| 2023 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2024 | j = atp_readb_io(dev, c, 0x17) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | if (j == 0x0f) { |
| 2026 | goto u3p_in; |
| 2027 | } |
| 2028 | if (j == 0x0a) { |
| 2029 | goto u3p_cmd; |
| 2030 | } |
| 2031 | if (j == 0x0e) { |
| 2032 | goto u3p_out; |
| 2033 | } |
| 2034 | continue; |
| 2035 | u3p_cmd: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2036 | atp_writeb_io(dev, c, 0x10, 0x30); |
| 2037 | atp_writeb_io(dev, c, 0x14, 0x00); |
| 2038 | atp_writeb_io(dev, c, 0x18, 0x08); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2039 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2040 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2041 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2042 | j = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | if (j != 0x16) { |
| 2044 | if (j == 0x4e) { |
| 2045 | goto u3p_out; |
| 2046 | } |
| 2047 | continue; |
| 2048 | } |
| 2049 | if (mbuf[0] != 0x01) { |
| 2050 | goto chg_wide; |
| 2051 | } |
| 2052 | if (mbuf[1] != 0x06) { |
| 2053 | goto chg_wide; |
| 2054 | } |
| 2055 | if (mbuf[2] != 0x04) { |
| 2056 | goto chg_wide; |
| 2057 | } |
| 2058 | if (mbuf[3] == 0x09) { |
| 2059 | m = 1; |
| 2060 | m = m << i; |
| 2061 | dev->wide_id[c] |= m; |
| 2062 | dev->id[c][i].devsp = 0xce; |
| 2063 | #ifdef ED_DBGP |
| 2064 | printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp); |
| 2065 | #endif |
| 2066 | continue; |
| 2067 | } |
| 2068 | chg_wide: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2069 | atp_writeb_io(dev, c, 0x1b, 0x01); |
| 2070 | atp_writeb_io(dev, c, 3, satn[0]); |
| 2071 | atp_writeb_io(dev, c, 4, satn[1]); |
| 2072 | atp_writeb_io(dev, c, 5, satn[2]); |
| 2073 | atp_writeb_io(dev, c, 6, satn[3]); |
| 2074 | atp_writeb_io(dev, c, 7, satn[4]); |
| 2075 | atp_writeb_io(dev, c, 8, satn[5]); |
| 2076 | atp_writeb_io(dev, c, 0x0f, 0); |
| 2077 | atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp); |
| 2078 | atp_writeb_io(dev, c, 0x12, 0); |
| 2079 | atp_writeb_io(dev, c, 0x13, satn[6]); |
| 2080 | atp_writeb_io(dev, c, 0x14, satn[7]); |
| 2081 | atp_writeb_io(dev, c, 0x18, satn[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2083 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2085 | |
| 2086 | if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | continue; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2088 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2089 | while (atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | try_wide: |
| 2093 | j = 0; |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2094 | atp_writeb_io(dev, c, 0x14, 0x05); |
| 2095 | atp_writeb_io(dev, c, 0x18, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2097 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) { |
| 2098 | if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0) |
| 2099 | atp_writeb_io(dev, c, 0x19, wide[j++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | cpu_relax(); |
| 2101 | } |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2102 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2103 | while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2105 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2106 | j = atp_readb_io(dev, c, 0x17) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | if (j == 0x0f) { |
| 2108 | goto widep_in; |
| 2109 | } |
| 2110 | if (j == 0x0a) { |
| 2111 | goto widep_cmd; |
| 2112 | } |
| 2113 | if (j == 0x0e) { |
| 2114 | goto try_wide; |
| 2115 | } |
| 2116 | continue; |
| 2117 | widep_out: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2118 | atp_writeb_io(dev, c, 0x18, 0x20); |
| 2119 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) { |
| 2120 | if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0) |
| 2121 | atp_writeb_io(dev, c, 0x19, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | cpu_relax(); |
| 2123 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2124 | j = atp_readb_io(dev, c, 0x17) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | if (j == 0x0f) { |
| 2126 | goto widep_in; |
| 2127 | } |
| 2128 | if (j == 0x0a) { |
| 2129 | goto widep_cmd; |
| 2130 | } |
| 2131 | if (j == 0x0e) { |
| 2132 | goto widep_out; |
| 2133 | } |
| 2134 | continue; |
| 2135 | widep_in: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2136 | atp_writeb_io(dev, c, 0x14, 0xff); |
| 2137 | atp_writeb_io(dev, c, 0x18, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | k = 0; |
| 2139 | widep_in1: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2140 | j = atp_readb_io(dev, c, 0x1f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | if ((j & 0x01) != 0) { |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2142 | mbuf[k++] = atp_readb_io(dev, c, 0x19); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | goto widep_in1; |
| 2144 | } |
| 2145 | if ((j & 0x80) == 0x00) { |
| 2146 | goto widep_in1; |
| 2147 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2148 | j = atp_readb_io(dev, c, 0x17) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | if (j == 0x0f) { |
| 2150 | goto widep_in; |
| 2151 | } |
| 2152 | if (j == 0x0a) { |
| 2153 | goto widep_cmd; |
| 2154 | } |
| 2155 | if (j == 0x0e) { |
| 2156 | goto widep_out; |
| 2157 | } |
| 2158 | continue; |
| 2159 | widep_cmd: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2160 | atp_writeb_io(dev, c, 0x10, 0x30); |
| 2161 | atp_writeb_io(dev, c, 0x14, 0x00); |
| 2162 | atp_writeb_io(dev, c, 0x18, 0x08); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2163 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2164 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2166 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2167 | j = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | if (j != 0x16) { |
| 2169 | if (j == 0x4e) { |
| 2170 | goto widep_out; |
| 2171 | } |
| 2172 | continue; |
| 2173 | } |
| 2174 | if (mbuf[0] != 0x01) { |
| 2175 | goto not_wide; |
| 2176 | } |
| 2177 | if (mbuf[1] != 0x02) { |
| 2178 | goto not_wide; |
| 2179 | } |
| 2180 | if (mbuf[2] != 0x03) { |
| 2181 | goto not_wide; |
| 2182 | } |
| 2183 | if (mbuf[3] != 0x01) { |
| 2184 | goto not_wide; |
| 2185 | } |
| 2186 | m = 1; |
| 2187 | m = m << i; |
| 2188 | dev->wide_id[c] |= m; |
| 2189 | not_wide: |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2190 | if ((dev->id[c][i].devtype == 0x00) || (dev->id[c][i].devtype == 0x07) || ((dev->id[c][i].devtype == 0x05) && ((n & 0x10) != 0))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | m = 1; |
| 2192 | m = m << i; |
| 2193 | if ((dev->async[c] & m) != 0) { |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2194 | goto set_sync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | continue; |
| 2198 | set_sync: |
Ondrej Zary | 460da918 | 2015-11-17 19:24:03 +0100 | [diff] [blame] | 2199 | if ((dev->dev_id != ATP885_DEVID && dev->dev_id != ATP880_DEVID1 && dev->dev_id != ATP880_DEVID2) || (dev->sp[c][i] == 0x02)) { |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2200 | synu[4] = 0x0c; |
| 2201 | synuw[4] = 0x0c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | } else { |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2203 | if (dev->sp[c][i] >= 0x03) { |
| 2204 | synu[4] = 0x0a; |
| 2205 | synuw[4] = 0x0a; |
| 2206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | j = 0; |
| 2209 | if ((m & dev->wide_id[c]) != 0) { |
| 2210 | j |= 0x01; |
| 2211 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2212 | atp_writeb_io(dev, c, 0x1b, j); |
| 2213 | atp_writeb_io(dev, c, 3, satn[0]); |
| 2214 | atp_writeb_io(dev, c, 4, satn[1]); |
| 2215 | atp_writeb_io(dev, c, 5, satn[2]); |
| 2216 | atp_writeb_io(dev, c, 6, satn[3]); |
| 2217 | atp_writeb_io(dev, c, 7, satn[4]); |
| 2218 | atp_writeb_io(dev, c, 8, satn[5]); |
| 2219 | atp_writeb_io(dev, c, 0x0f, 0); |
| 2220 | atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp); |
| 2221 | atp_writeb_io(dev, c, 0x12, 0); |
| 2222 | atp_writeb_io(dev, c, 0x13, satn[6]); |
| 2223 | atp_writeb_io(dev, c, 0x14, satn[7]); |
| 2224 | atp_writeb_io(dev, c, 0x18, satn[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2226 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2228 | |
| 2229 | if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | continue; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2231 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2232 | while (atp_readb_io(dev, c, 0x17) != 0x8e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | try_sync: |
| 2236 | j = 0; |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2237 | atp_writeb_io(dev, c, 0x14, 0x06); |
| 2238 | atp_writeb_io(dev, c, 0x18, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2240 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) { |
| 2241 | if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | if ((m & dev->wide_id[c]) != 0) { |
Ondrej Zary | 460da918 | 2015-11-17 19:24:03 +0100 | [diff] [blame] | 2243 | if (dev->dev_id == ATP885_DEVID || dev->dev_id == ATP880_DEVID1 || dev->dev_id == ATP880_DEVID2) { |
| 2244 | if ((m & dev->ultra_map[c]) != 0) { |
| 2245 | atp_writeb_io(dev, c, 0x19, synuw[j++]); |
| 2246 | } else { |
| 2247 | atp_writeb_io(dev, c, 0x19, synw[j++]); |
| 2248 | } |
| 2249 | } else |
| 2250 | atp_writeb_io(dev, c, 0x19, synw_870[j++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | } else { |
| 2252 | if ((m & dev->ultra_map[c]) != 0) { |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2253 | atp_writeb_io(dev, c, 0x19, synu[j++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | } else { |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2255 | atp_writeb_io(dev, c, 0x19, synn[j++]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | } |
| 2257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | } |
| 2259 | } |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2260 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2261 | while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2263 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2264 | j = atp_readb_io(dev, c, 0x17) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | if (j == 0x0f) { |
| 2266 | goto phase_ins; |
| 2267 | } |
| 2268 | if (j == 0x0a) { |
| 2269 | goto phase_cmds; |
| 2270 | } |
| 2271 | if (j == 0x0e) { |
| 2272 | goto try_sync; |
| 2273 | } |
| 2274 | continue; |
| 2275 | phase_outs: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2276 | atp_writeb_io(dev, c, 0x18, 0x20); |
| 2277 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) { |
| 2278 | if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0x00) |
| 2279 | atp_writeb_io(dev, c, 0x19, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | cpu_relax(); |
| 2281 | } |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2282 | j = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | if (j == 0x85) { |
| 2284 | goto tar_dcons; |
| 2285 | } |
| 2286 | j &= 0x0f; |
| 2287 | if (j == 0x0f) { |
| 2288 | goto phase_ins; |
| 2289 | } |
| 2290 | if (j == 0x0a) { |
| 2291 | goto phase_cmds; |
| 2292 | } |
| 2293 | if (j == 0x0e) { |
| 2294 | goto phase_outs; |
| 2295 | } |
| 2296 | continue; |
| 2297 | phase_ins: |
Ondrej Zary | 460da918 | 2015-11-17 19:24:03 +0100 | [diff] [blame] | 2298 | if (dev->dev_id == ATP885_DEVID || dev->dev_id == ATP880_DEVID1 || dev->dev_id == ATP880_DEVID2) |
| 2299 | atp_writeb_io(dev, c, 0x14, 0x06); |
| 2300 | else |
| 2301 | atp_writeb_io(dev, c, 0x14, 0xff); |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2302 | atp_writeb_io(dev, c, 0x18, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | k = 0; |
| 2304 | phase_ins1: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2305 | j = atp_readb_io(dev, c, 0x1f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | if ((j & 0x01) != 0x00) { |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2307 | mbuf[k++] = atp_readb_io(dev, c, 0x19); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | goto phase_ins1; |
| 2309 | } |
| 2310 | if ((j & 0x80) == 0x00) { |
| 2311 | goto phase_ins1; |
| 2312 | } |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2313 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2314 | while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2315 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2316 | j = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | if (j == 0x85) { |
| 2318 | goto tar_dcons; |
| 2319 | } |
| 2320 | j &= 0x0f; |
| 2321 | if (j == 0x0f) { |
| 2322 | goto phase_ins; |
| 2323 | } |
| 2324 | if (j == 0x0a) { |
| 2325 | goto phase_cmds; |
| 2326 | } |
| 2327 | if (j == 0x0e) { |
| 2328 | goto phase_outs; |
| 2329 | } |
| 2330 | continue; |
| 2331 | phase_cmds: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2332 | atp_writeb_io(dev, c, 0x10, 0x30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | tar_dcons: |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2334 | atp_writeb_io(dev, c, 0x14, 0x00); |
| 2335 | atp_writeb_io(dev, c, 0x18, 0x08); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2336 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2337 | while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | cpu_relax(); |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2339 | |
Ondrej Zary | 5d2a5a4 | 2015-11-17 19:23:57 +0100 | [diff] [blame] | 2340 | j = atp_readb_io(dev, c, 0x17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | if (j != 0x16) { |
| 2342 | continue; |
| 2343 | } |
| 2344 | if (mbuf[0] != 0x01) { |
| 2345 | continue; |
| 2346 | } |
| 2347 | if (mbuf[1] != 0x03) { |
| 2348 | continue; |
| 2349 | } |
| 2350 | if (mbuf[4] == 0x00) { |
| 2351 | continue; |
| 2352 | } |
| 2353 | if (mbuf[3] > 0x64) { |
| 2354 | continue; |
| 2355 | } |
Ondrej Zary | 460da918 | 2015-11-17 19:24:03 +0100 | [diff] [blame] | 2356 | if (dev->dev_id == ATP885_DEVID || dev->dev_id == ATP880_DEVID1 || dev->dev_id == ATP880_DEVID2) { |
| 2357 | if (mbuf[4] > 0x0e) { |
| 2358 | mbuf[4] = 0x0e; |
| 2359 | } |
| 2360 | } else { |
| 2361 | if (mbuf[4] > 0x0c) { |
| 2362 | mbuf[4] = 0x0c; |
| 2363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | dev->id[c][i].devsp = mbuf[4]; |
Ondrej Zary | 460da918 | 2015-11-17 19:24:03 +0100 | [diff] [blame] | 2366 | if (dev->dev_id == ATP885_DEVID || dev->dev_id == ATP880_DEVID1 || dev->dev_id == ATP880_DEVID2) |
| 2367 | if (mbuf[3] < 0x0c) { |
| 2368 | j = 0xb0; |
| 2369 | goto set_syn_ok; |
| 2370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | if ((mbuf[3] < 0x0d) && (rmb == 0)) { |
| 2372 | j = 0xa0; |
| 2373 | goto set_syn_ok; |
| 2374 | } |
| 2375 | if (mbuf[3] < 0x1a) { |
| 2376 | j = 0x20; |
| 2377 | goto set_syn_ok; |
| 2378 | } |
| 2379 | if (mbuf[3] < 0x33) { |
| 2380 | j = 0x40; |
| 2381 | goto set_syn_ok; |
| 2382 | } |
| 2383 | if (mbuf[3] < 0x4c) { |
| 2384 | j = 0x50; |
| 2385 | goto set_syn_ok; |
| 2386 | } |
| 2387 | j = 0x60; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2388 | set_syn_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | dev->id[c][i].devsp = (dev->id[c][i].devsp & 0x0f) | j; |
Ondrej Zary | 80b52a7 | 2015-11-17 19:23:58 +0100 | [diff] [blame] | 2390 | #ifdef ED_DBGP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp); |
| 2392 | #endif |
| 2393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | } |