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