2 * Copyright (C) 1997 Wu Ching Chen
3 * 2.1.x update (C) 1998 Krzysztof G. Baranowski
4 * 2.5.x update (C) 2002 Red Hat
5 * 2.6.x update (C) 2004 Red Hat
7 * Marcelo Tosatti <marcelo@conectiva.com.br> : SMP fixes
9 * Wu Ching Chen : NULL pointer fixes 2000/06/02
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)
17 * atp885 support add by ACARD Hao Ping Lian 2005/01/05
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>
31 #include <linux/dma-mapping.h>
32 #include <linux/slab.h>
35 #include <scsi/scsi.h>
36 #include <scsi/scsi_cmnd.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
42 static struct scsi_host_template atp870u_template
;
43 static void send_s870(struct atp_unit
*dev
,unsigned char c
);
44 static void is885(struct atp_unit
*dev
, unsigned char c
);
45 static void tscam_885(void);
47 static inline void atp_writeb_base(struct atp_unit
*atp
, u8 reg
, u8 val
)
49 outb(val
, atp
->baseport
+ reg
);
52 static inline void atp_writeb_io(struct atp_unit
*atp
, u8 channel
, u8 reg
, u8 val
)
54 outb(val
, atp
->ioport
[channel
] + reg
);
57 static inline void atp_writew_io(struct atp_unit
*atp
, u8 channel
, u8 reg
, u16 val
)
59 outw(val
, atp
->ioport
[channel
] + reg
);
62 static inline void atp_writeb_pci(struct atp_unit
*atp
, u8 channel
, u8 reg
, u8 val
)
64 outb(val
, atp
->pciport
[channel
] + reg
);
67 static inline void atp_writel_pci(struct atp_unit
*atp
, u8 channel
, u8 reg
, u32 val
)
69 outl(val
, atp
->pciport
[channel
] + reg
);
72 static inline u8
atp_readb_base(struct atp_unit
*atp
, u8 reg
)
74 return inb(atp
->baseport
+ reg
);
77 static inline u8
atp_readb_io(struct atp_unit
*atp
, u8 channel
, u8 reg
)
79 return inb(atp
->ioport
[channel
] + reg
);
82 static inline u16
atp_readw_io(struct atp_unit
*atp
, u8 channel
, u8 reg
)
84 return inw(atp
->ioport
[channel
] + reg
);
87 static inline u8
atp_readb_pci(struct atp_unit
*atp
, u8 channel
, u8 reg
)
89 return inb(atp
->pciport
[channel
] + reg
);
92 static irqreturn_t
atp870u_intr_handle(int irq
, void *dev_id
)
95 unsigned short int id
;
96 unsigned char i
, j
, c
, target_id
, lun
,cmdp
;
98 struct scsi_cmnd
*workreq
;
99 unsigned long adrcnt
, k
;
103 struct Scsi_Host
*host
= dev_id
;
104 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
106 for (c
= 0; c
< 2; c
++) {
107 j
= atp_readb_io(dev
, c
, 0x1f);
115 printk("atp870u_intr_handle enter\n");
118 cmdp
= atp_readb_io(dev
, c
, 0x10);
119 if (dev
->working
[c
] != 0) {
120 if (dev
->dev_id
== ATP885_DEVID
) {
121 if ((atp_readb_io(dev
, c
, 0x16) & 0x80) == 0)
122 atp_writeb_io(dev
, c
, 0x16, (atp_readb_io(dev
, c
, 0x16) | 0x80));
124 if ((atp_readb_pci(dev
, c
, 0x00) & 0x08) != 0)
126 for (k
=0; k
< 1000; k
++) {
127 if ((atp_readb_pci(dev
, c
, 2) & 0x08) == 0)
129 if ((atp_readb_pci(dev
, c
, 2) & 0x01) == 0)
133 atp_writeb_pci(dev
, c
, 0, 0x00);
135 i
= atp_readb_io(dev
, c
, 0x17);
137 if (dev
->dev_id
== ATP885_DEVID
)
138 atp_writeb_pci(dev
, c
, 2, 0x06);
140 target_id
= atp_readb_io(dev
, c
, 0x15);
143 * Remap wide devices onto id numbers
146 if ((target_id
& 0x40) != 0) {
147 target_id
= (target_id
& 0x07) | 0x08;
152 if ((j
& 0x40) != 0) {
153 if (dev
->last_cmd
[c
] == 0xff) {
154 dev
->last_cmd
[c
] = target_id
;
156 dev
->last_cmd
[c
] |= 0x40;
158 if (dev
->dev_id
== ATP885_DEVID
)
159 dev
->r1f
[c
][target_id
] |= j
;
161 printk("atp870u_intr_handle status = %x\n",i
);
164 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
165 dev
->last_cmd
[c
] = 0xff;
167 if (dev
->dev_id
== ATP885_DEVID
) {
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);
172 if (dev
->id
[c
][target_id
].last_len
!= adrcnt
)
174 k
= dev
->id
[c
][target_id
].last_len
;
176 dev
->id
[c
][target_id
].tran_len
= k
;
177 dev
->id
[c
][target_id
].last_len
= adrcnt
;
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
);
187 if (dev
->wide_id
[c
] != 0) {
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);
193 * Issue more commands
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)) {
199 printk("Call sent_s870\n");
203 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
209 printk("Status 0x85 return\n");
215 dev
->last_cmd
[c
] |= 0x40;
221 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
222 dev
->last_cmd
[c
] = 0xff;
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);
228 k
= dev
->id
[c
][target_id
].last_len
;
230 dev
->id
[c
][target_id
].tran_len
= k
;
231 dev
->id
[c
][target_id
].last_len
= adrcnt
;
232 atp_writeb_io(dev
, c
, 0x10, 0x41);
233 atp_writeb_io(dev
, c
, 0x18, 0x08);
238 if (dev
->dev_id
== ATP885_DEVID
) {
239 if ((i
== 0x4c) || (i
== 0x4d) || (i
== 0x8c) || (i
== 0x8d)) {
240 if ((i
== 0x4c) || (i
== 0x8c))
247 if ((i
== 0x80) || (i
== 0x8f)) {
249 printk(KERN_DEBUG
"Device reselect\n");
252 if (cmdp
== 0x44 || i
== 0x80)
253 lun
= atp_readb_io(dev
, c
, 0x1d) & 0x07;
255 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
256 dev
->last_cmd
[c
] = 0xff;
260 printk("cmdp = 0x41\n");
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);
266 k
= dev
->id
[c
][target_id
].last_len
;
268 dev
->id
[c
][target_id
].tran_len
= k
;
269 dev
->id
[c
][target_id
].last_len
= adrcnt
;
270 atp_writeb_io(dev
, c
, 0x18, 0x08);
275 printk("cmdp != 0x41\n");
277 atp_writeb_io(dev
, c
, 0x10, 0x46);
278 dev
->id
[c
][target_id
].dirct
= 0x00;
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);
287 if (dev
->last_cmd
[c
] != 0xff) {
288 dev
->last_cmd
[c
] |= 0x40;
290 if (dev
->dev_id
== ATP885_DEVID
) {
291 j
= atp_readb_base(dev
, 0x29) & 0xfe;
292 atp_writeb_base(dev
, 0x29, j
);
294 atp_writeb_io(dev
, c
, 0x10, 0x45);
296 target_id
= atp_readb_io(dev
, c
, 0x16);
298 * Remap wide identifiers
300 if ((target_id
& 0x10) != 0) {
301 target_id
= (target_id
& 0x07) | 0x08;
305 if (dev
->dev_id
== ATP885_DEVID
)
306 atp_writeb_io(dev
, c
, 0x10, 0x45);
307 workreq
= dev
->id
[c
][target_id
].curr_req
;
309 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
310 for (l
= 0; l
< workreq
->cmd_len
; l
++)
311 printk(KERN_DEBUG
" %x",workreq
->cmnd
[l
]);
315 atp_writeb_io(dev
, c
, 0x0f, lun
);
316 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][target_id
].devsp
);
317 adrcnt
= dev
->id
[c
][target_id
].tran_len
;
318 k
= dev
->id
[c
][target_id
].last_len
;
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]);
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));
329 j
= (j
& 0x07) | 0x40;
332 j
|= dev
->id
[c
][target_id
].dirct
;
333 atp_writeb_io(dev
, c
, 0x15, j
);
334 atp_writeb_io(dev
, c
, 0x16, 0x80);
336 /* enable 32 bit fifo transfer */
337 if (dev
->dev_id
== ATP885_DEVID
) {
338 i
= atp_readb_pci(dev
, c
, 1) & 0xf3;
339 //j=workreq->cmnd[0];
340 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
343 atp_writeb_pci(dev
, c
, 1, i
);
344 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
345 (dev
->dev_id
== ATP880_DEVID2
) ) {
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);
349 atp_writeb_base(dev
, 0x3b, atp_readb_base(dev
, 0x3b) & 0x3f);
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);
354 atp_writeb_io(dev
, c
, 0x3a, atp_readb_io(dev
, c
, 0x3a) & 0xf3);
358 id
= id
<< target_id
;
360 * Is this a wide device
362 if ((id
& dev
->wide_id
[c
]) != 0) {
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
);
368 if (dev
->id
[c
][target_id
].last_len
== 0) {
369 atp_writeb_io(dev
, c
, 0x18, 0x08);
372 printk("dev->id[c][target_id].last_len = 0\n");
377 printk("target_id = %d adrcnt = %d\n",target_id
,adrcnt
);
379 prd
= dev
->id
[c
][target_id
].prd_pos
;
380 while (adrcnt
!= 0) {
381 id
= ((unsigned short int *)prd
)[2];
388 ((unsigned short int *)prd
)[2] = (unsigned short int)
390 ((unsigned long *)prd
)[0] += adrcnt
;
392 dev
->id
[c
][target_id
].prd_pos
= prd
;
395 dev
->id
[c
][target_id
].prdaddr
+= 0x08;
398 dev
->id
[c
][target_id
].prd_pos
= prd
;
402 atp_writel_pci(dev
, c
, 0x04, dev
->id
[c
][target_id
].prdaddr
);
404 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c
, target_id
, dev
->id
[c
][target_id
].prdaddr
);
406 if (dev
->dev_id
!= ATP885_DEVID
) {
407 atp_writeb_pci(dev
, c
, 2, 0x06);
408 atp_writeb_pci(dev
, c
, 2, 0x00);
411 * Check transfer direction
413 if (dev
->id
[c
][target_id
].dirct
!= 0) {
414 atp_writeb_io(dev
, c
, 0x18, 0x08);
415 atp_writeb_pci(dev
, c
, 0, 0x01);
418 printk("status 0x80 return dirct != 0\n");
422 atp_writeb_io(dev
, c
, 0x18, 0x08);
423 atp_writeb_pci(dev
, c
, 0, 0x09);
426 printk("status 0x80 return dirct = 0\n");
432 * Current scsi request on this target
435 workreq
= dev
->id
[c
][target_id
].curr_req
;
437 if (i
== 0x42 || i
== 0x16) {
438 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
439 dev
->last_cmd
[c
] = 0xff;
442 workreq
->result
= atp_readb_io(dev
, c
, 0x0f);
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;
448 workreq
->result
= 0x02;
450 if (dev
->dev_id
== ATP885_DEVID
) {
451 j
= atp_readb_base(dev
, 0x29) | 0x01;
452 atp_writeb_base(dev
, 0x29, j
);
455 * Complete the command
457 scsi_dma_unmap(workreq
);
459 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
460 (*workreq
->scsi_done
) (workreq
);
462 printk("workreq->scsi_done\n");
465 * Clear it off the queue
467 dev
->id
[c
][target_id
].curr_req
= NULL
;
469 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
473 if (dev
->wide_id
[c
] != 0) {
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);
479 * If there is stuff to send and nothing going then send it
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)) {
485 printk("Call sent_s870(scsi_done)\n");
489 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
493 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
494 dev
->last_cmd
[c
] = 0xff;
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);
505 if (dev
->dev_id
== ATP885_DEVID
) {
506 k
= dev
->id
[c
][target_id
].last_len
;
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]);
510 dev
->id
[c
][target_id
].dirct
= 0x00;
512 dev
->id
[c
][target_id
].dirct
= 0x00;
514 atp_writeb_io(dev
, c
, 0x18, 0x08);
515 atp_writeb_pci(dev
, c
, 0, 0x09);
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);
524 if (dev
->dev_id
== ATP885_DEVID
) {
525 k
= dev
->id
[c
][target_id
].last_len
;
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]);
530 atp_writeb_io(dev
, c
, 0x15, atp_readb_io(dev
, c
, 0x15) | 0x20);
531 dev
->id
[c
][target_id
].dirct
= 0x20;
532 atp_writeb_io(dev
, c
, 0x18, 0x08);
533 atp_writeb_pci(dev
, c
, 0, 0x01);
538 atp_writeb_io(dev
, c
, 0x10, 0x30);
540 atp_writeb_io(dev
, c
, 0x10, 0x46);
541 dev
->id
[c
][target_id
].dirct
= 0x00;
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);
552 * atp870u_queuecommand - Queue SCSI command
553 * @req_p: request block
554 * @done: completion function
556 * Queue a command to the ATP queue. Called with the host lock held.
558 static int atp870u_queuecommand_lck(struct scsi_cmnd
*req_p
,
559 void (*done
) (struct scsi_cmnd
*))
563 struct atp_unit
*dev
;
564 struct Scsi_Host
*host
;
566 c
= scmd_channel(req_p
);
567 req_p
->sense_buffer
[0]=0;
568 scsi_set_resid(req_p
, 0);
569 if (scmd_channel(req_p
) > 1) {
570 req_p
->result
= 0x00040000;
573 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
578 host
= req_p
->device
->host
;
579 dev
= (struct atp_unit
*)&host
->hostdata
;
584 m
= m
<< scmd_id(req_p
);
587 * Fake a timeout for missing targets
590 if ((m
& dev
->active_id
[c
]) == 0) {
591 req_p
->result
= 0x00040000;
597 req_p
->scsi_done
= done
;
600 printk( "atp870u_queuecommand: done can't be NULL\n");
611 if (dev
->quend
[c
] >= qcnt
) {
618 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
619 if (dev
->quend
[c
] == 0) {
620 dev
->quend
[c
] = qcnt
;
623 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
626 req_p
->result
= 0x00020000;
630 dev
->quereq
[c
][dev
->quend
[c
]] = req_p
;
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
]);
634 if ((atp_readb_io(dev
, c
, 0x1c) == 0) && (dev
->in_int
[c
] == 0) && (dev
->in_snd
[c
] == 0)) {
636 printk("Call sent_s870(atp870u_queuecommand)\n");
641 printk("atp870u_queuecommand : exit\n");
646 static DEF_SCSI_QCMD(atp870u_queuecommand
)
649 * send_s870 - send a command to the controller
652 * On entry there is work queued to be done. We move some of that work to the
655 * Caller holds the host lock.
657 static void send_s870(struct atp_unit
*dev
,unsigned char c
)
659 struct scsi_cmnd
*workreq
= NULL
;
661 unsigned char j
, target_id
;
663 unsigned short int w
;
664 unsigned long l
, bttl
= 0;
665 unsigned long sg_count
;
667 if (dev
->in_snd
[c
] != 0) {
669 printk("cmnd in_snd\n");
674 printk("Sent_s870 enter\n");
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
;
681 dev
->last_cmd
[c
] = 0xff;
682 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
689 if ((dev
->last_cmd
[c
] != 0xff) && (dev
->working
[c
] != 0)) {
696 if (dev
->quhd
[c
] >= qcnt
)
698 workreq
= dev
->quereq
[c
][dev
->quhd
[c
]];
699 if (dev
->id
[c
][scmd_id(workreq
)].curr_req
!= NULL
) {
705 dev
->id
[c
][scmd_id(workreq
)].curr_req
= workreq
;
706 dev
->last_cmd
[c
] = scmd_id(workreq
);
708 if ((atp_readb_io(dev
, c
, 0x1f) & 0xb0) != 0 || atp_readb_io(dev
, c
, 0x1c) != 0) {
710 printk("Abort to Send\n");
712 dev
->last_cmd
[c
] |= 0x40;
717 printk("OK to Send\n");
718 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
719 for(i
=0;i
<workreq
->cmd_len
;i
++) {
720 printk(" %x",workreq
->cmnd
[i
]);
724 l
= scsi_bufflen(workreq
);
726 if (dev
->dev_id
== ATP885_DEVID
) {
727 j
= atp_readb_base(dev
, 0x29) & 0xfe;
728 atp_writeb_base(dev
, 0x29, j
);
729 dev
->r1f
[c
][scmd_id(workreq
)] = 0;
732 if (workreq
->cmnd
[0] == READ_CAPACITY
) {
736 if (workreq
->cmnd
[0] == 0x00) {
741 target_id
= scmd_id(workreq
);
748 if ((w
& dev
->wide_id
[c
]) != 0) {
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
);
755 printk("send_s870 while loop 1\n");
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);
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
);
774 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][target_id
].devsp
);
776 printk("dev->id[%d][%d].devsp = %2x\n",c
,target_id
,dev
->id
[c
][target_id
].devsp
);
779 sg_count
= scsi_dma_map(workreq
);
781 * Write transfer size
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]);
787 dev
->id
[c
][j
].last_len
= l
;
788 dev
->id
[c
][j
].tran_len
= 0;
790 printk("dev->id[%2d][%2d].last_len = %d\n",c
,j
,dev
->id
[c
][j
].last_len
);
795 if ((j
& 0x08) != 0) {
796 j
= (j
& 0x07) | 0x40;
799 * Check transfer direction
801 if (workreq
->sc_data_direction
== DMA_TO_DEVICE
)
802 atp_writeb_io(dev
, c
, 0x15, j
| 0x20);
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);
807 dev
->id
[c
][target_id
].dirct
= 0;
809 if (atp_readb_io(dev
, c
, 0x1c) == 0) {
811 printk("change SCSI_CMD_REG 0x08\n");
813 atp_writeb_io(dev
, c
, 0x18, 0x08);
815 dev
->last_cmd
[c
] |= 0x40;
819 prd
= dev
->id
[c
][target_id
].prd_table
;
820 dev
->id
[c
][target_id
].prd_pos
= prd
;
823 * Now write the request list. Either as scatter/gather or as
828 struct scatterlist
*sgpnt
;
830 scsi_for_each_sg(workreq
, sgpnt
, sg_count
, j
) {
831 bttl
= sg_dma_address(sgpnt
);
834 printk("1. bttl %x, l %x\n",bttl
, l
);
836 while (l
> 0x10000) {
837 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
838 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
839 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
844 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
845 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
846 (((u16
*) (prd
))[i
+ 3]) = 0;
849 (((u16
*) (prd
))[i
- 1]) = cpu_to_le16(0x8000);
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
);
856 printk("send_s870: prdaddr_2 0x%8x target_id %d\n", dev
->id
[c
][target_id
].prdaddr
,target_id
);
858 dev
->id
[c
][target_id
].prdaddr
= dev
->id
[c
][target_id
].prd_bus
;
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);
862 if (dev
->dev_id
== ATP885_DEVID
) {
863 j
= atp_readb_pci(dev
, c
, 1) & 0xf3;
864 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) ||
865 (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
868 atp_writeb_pci(dev
, c
, 1, j
);
869 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
870 (dev
->dev_id
== ATP880_DEVID2
)) {
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);
874 atp_writeb_base(dev
, 0x3b, atp_readb_base(dev
, 0x3b) & 0x3f);
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);
879 atp_writeb_io(dev
, c
, 0x3a, atp_readb_io(dev
, c
, 0x3a) & 0xf3);
882 if(workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
883 dev
->id
[c
][target_id
].dirct
= 0x20;
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);
888 printk( "start DMA(to target)\n");
891 dev
->last_cmd
[c
] |= 0x40;
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);
900 printk( "start DMA(to host)\n");
903 dev
->last_cmd
[c
] |= 0x40;
910 static unsigned char fun_scam(struct atp_unit
*dev
, unsigned short int *val
)
912 unsigned short int i
, k
;
915 atp_writew_io(dev
, 0, 0x1c, *val
);
916 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
917 k
= atp_readw_io(dev
, 0, 0x1c);
918 j
= (unsigned char) (k
>> 8);
919 if ((k
& 0x8000) != 0) /* DB7 all release? */
922 *val
|= 0x4000; /* assert DB6 */
923 atp_writew_io(dev
, 0, 0x1c, *val
);
924 *val
&= 0xdfff; /* assert DB5 */
925 atp_writew_io(dev
, 0, 0x1c, *val
);
926 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
927 if ((atp_readw_io(dev
, 0, 0x1c) & 0x2000) != 0) /* DB5 all release? */
930 *val
|= 0x8000; /* no DB4-0, assert DB7 */
932 atp_writew_io(dev
, 0, 0x1c, *val
);
933 *val
&= 0xbfff; /* release DB6 */
934 atp_writew_io(dev
, 0, 0x1c, *val
);
935 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
936 if ((atp_readw_io(dev
, 0, 0x1c) & 0x4000) != 0) /* DB6 all release? */
943 static void tscam(struct Scsi_Host
*host
)
946 unsigned char i
, j
, k
;
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
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++) {
962 atp_writeb_io(dev
, 0, 1, 0x08);
963 atp_writeb_io(dev
, 0, 2, 0x7f);
964 atp_writeb_io(dev
, 0, 0x11, 0x20);
966 if ((dev
->scam_on
& 0x40) == 0) {
970 m
<<= dev
->host_id
[0];
972 if (dev
->chip_ver
< 4) {
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);
985 for (i
= 0; i
< j
; i
++) {
988 if ((m
& assignid_map
) != 0) {
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);
996 k
= (i
& 0x07) | 0x40;
1000 atp_writeb_io(dev
, 0, 0x15, k
);
1001 if (dev
->chip_ver
== 4)
1002 atp_writeb_io(dev
, 0, 0x1b, 0x01);
1004 atp_writeb_io(dev
, 0, 0x1b, 0x00);
1006 atp_writeb_io(dev
, 0, 0x18, 0x09);
1008 while ((atp_readb_io(dev
, 0, 0x1f) & 0x80) == 0x00)
1010 k
= atp_readb_io(dev
, 0, 0x17);
1011 if ((k
== 0x85) || (k
== 0x42))
1014 atp_writeb_io(dev
, 0, 0x10, 0x41);
1015 } while (k
!= 0x16);
1016 if ((k
== 0x85) || (k
== 0x42))
1021 atp_writeb_io(dev
, 0, 0x02, 0x7f);
1022 atp_writeb_io(dev
, 0, 0x1b, 0x02);
1026 val
= 0x0080; /* bsy */
1027 atp_writew_io(dev
, 0, 0x1c, val
);
1028 val
|= 0x0040; /* sel */
1029 atp_writew_io(dev
, 0, 0x1c, val
);
1030 val
|= 0x0004; /* msg */
1031 atp_writew_io(dev
, 0, 0x1c, val
);
1032 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1033 val
&= 0x007f; /* no bsy */
1034 atp_writew_io(dev
, 0, 0x1c, val
);
1036 val
&= 0x00fb; /* after 1ms no msg */
1037 atp_writew_io(dev
, 0, 0x1c, val
);
1038 while ((atp_readb_io(dev
, 0, 0x1c) & 0x04) != 0)
1042 for (n
= 0; n
< 0x30000; n
++)
1043 if ((atp_readb_io(dev
, 0, 0x1c) & 0x80) != 0) /* bsy ? */
1046 for (n
= 0; n
< 0x30000; n
++)
1047 if ((atp_readb_io(dev
, 0, 0x1c) & 0x81) == 0x0081) {
1049 val
|= 0x8003; /* io,cd,db7 */
1050 atp_writew_io(dev
, 0, 0x1c, val
);
1052 val
&= 0x00bf; /* no sel */
1053 atp_writew_io(dev
, 0, 0x1c, val
);
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.
1064 * XXX it would be more polite to find a way to use msleep()
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)
1075 atp_readb_io(dev
, 0, 0x17);
1078 val
&= 0x00ff; /* synchronization */
1080 fun_scam(dev
, &val
);
1082 val
&= 0x00ff; /* isolation */
1084 fun_scam(dev
, &val
);
1090 if ((atp_readw_io(dev
, 0, 0x1c) & 0x2000) == 0)
1093 val
&= 0x00ff; /* get ID_STRING */
1095 k
= fun_scam(dev
, &val
);
1096 if ((k
& 0x03) == 0)
1100 if ((k
& 0x02) != 0)
1109 /* isolation complete.. */
1111 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1114 if ((j
& 0x20) != 0) { /* bit5=1:ID up to 7 */
1117 if ((j
& 0x06) != 0) { /* IDvalid? */
1122 if ((m
& assignid_map
) == 0)
1130 if ((m
& assignid_map
) != 0) { /* srch from max acceptable ID# */
1131 k
= i
; /* max acceptable ID# */
1135 if ((m
& assignid_map
) == 0)
1146 quintet
[0] = 0x38; /* 1st dft ID<8 */
1148 quintet
[0] = 0x31; /* 1st ID>=8 */
1151 quintet
[1] = g2q_tab
[k
];
1153 val
&= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1154 m
= quintet
[0] << 8;
1156 fun_scam(dev
, &val
);
1157 val
&= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1158 m
= quintet
[1] << 8;
1160 fun_scam(dev
, &val
);
1165 static void is870(struct atp_unit
*dev
, unsigned char c
)
1167 unsigned char i
, j
, k
, rmb
, n
;
1168 unsigned short int m
;
1169 static unsigned char mbuf
[512];
1170 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1171 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1172 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1173 static unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1174 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1175 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1177 atp_writeb_io(dev
, c
, 0x3a, atp_readb_io(dev
, c
, 0x3a) | 0x10);
1179 for (i
= 0; i
< 16; i
++) {
1180 if ((dev
->chip_ver
!= 4) && (i
> 7)) {
1185 if ((m
& dev
->active_id
[c
]) != 0) {
1188 if (i
== dev
->host_id
[c
]) {
1189 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
1192 if (dev
->chip_ver
== 4) {
1193 atp_writeb_io(dev
, c
, 0x1b, 0x01);
1195 atp_writeb_io(dev
, c
, 0x1b, 0x00);
1197 atp_writeb_io(dev
, c
, 1, 0x08);
1198 atp_writeb_io(dev
, c
, 2, 0x7f);
1199 atp_writeb_io(dev
, c
, 3, satn
[0]);
1200 atp_writeb_io(dev
, c
, 4, satn
[1]);
1201 atp_writeb_io(dev
, c
, 5, satn
[2]);
1202 atp_writeb_io(dev
, c
, 6, satn
[3]);
1203 atp_writeb_io(dev
, c
, 7, satn
[4]);
1204 atp_writeb_io(dev
, c
, 8, satn
[5]);
1205 atp_writeb_io(dev
, c
, 0x0f, 0);
1206 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1207 atp_writeb_io(dev
, c
, 0x12, 0);
1208 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1209 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1211 if ((j
& 0x08) != 0) {
1212 j
= (j
& 0x07) | 0x40;
1214 atp_writeb_io(dev
, c
, 0x15, j
);
1215 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1217 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1220 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1223 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1226 dev
->active_id
[c
] |= m
;
1228 atp_writeb_io(dev
, c
, 0x10, 0x30);
1229 atp_writeb_io(dev
, c
, 0x04, 0x00);
1232 atp_writeb_io(dev
, c
, 0x18, 0x08);
1234 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1237 j
= atp_readb_io(dev
, c
, 0x17);
1239 atp_writeb_io(dev
, c
, 0x10, 0x41);
1243 atp_writeb_io(dev
, c
, 3, inqd
[0]);
1244 atp_writeb_io(dev
, c
, 4, inqd
[1]);
1245 atp_writeb_io(dev
, c
, 5, inqd
[2]);
1246 atp_writeb_io(dev
, c
, 6, inqd
[3]);
1247 atp_writeb_io(dev
, c
, 7, inqd
[4]);
1248 atp_writeb_io(dev
, c
, 8, inqd
[5]);
1249 atp_writeb_io(dev
, c
, 0x0f, 0);
1250 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1251 atp_writeb_io(dev
, c
, 0x12, 0);
1252 atp_writeb_io(dev
, c
, 0x13, inqd
[6]);
1253 atp_writeb_io(dev
, c
, 0x14, inqd
[7]);
1254 atp_writeb_io(dev
, c
, 0x18, inqd
[8]);
1256 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1259 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1262 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1265 if (dev
->chip_ver
== 4)
1266 atp_writeb_io(dev
, c
, 0x1b, 0x00);
1268 atp_writeb_io(dev
, c
, 0x18, 0x08);
1271 k
= atp_readb_io(dev
, c
, 0x1f);
1272 if ((k
& 0x01) != 0) {
1273 mbuf
[j
++] = atp_readb_io(dev
, c
, 0x19);
1276 if ((k
& 0x80) == 0) {
1279 j
= atp_readb_io(dev
, c
, 0x17);
1283 atp_writeb_io(dev
, c
, 0x10, 0x46);
1284 atp_writeb_io(dev
, c
, 0x12, 0);
1285 atp_writeb_io(dev
, c
, 0x13, 0);
1286 atp_writeb_io(dev
, c
, 0x14, 0);
1287 atp_writeb_io(dev
, c
, 0x18, 0x08);
1289 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1292 if (atp_readb_io(dev
, c
, 0x17) != 0x16)
1297 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1298 dev
->id
[c
][i
].devtype
= mbuf
[0];
1301 if (dev
->chip_ver
!= 4) {
1304 if ((mbuf
[7] & 0x60) == 0) {
1307 if ((dev
->global_map
[c
] & 0x20) == 0) {
1310 atp_writeb_io(dev
, c
, 0x1b, 0x01);
1311 atp_writeb_io(dev
, c
, 3, satn
[0]);
1312 atp_writeb_io(dev
, c
, 4, satn
[1]);
1313 atp_writeb_io(dev
, c
, 5, satn
[2]);
1314 atp_writeb_io(dev
, c
, 6, satn
[3]);
1315 atp_writeb_io(dev
, c
, 7, satn
[4]);
1316 atp_writeb_io(dev
, c
, 8, satn
[5]);
1317 atp_writeb_io(dev
, c
, 0x0f, 0);
1318 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1319 atp_writeb_io(dev
, c
, 0x12, 0);
1320 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1321 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1322 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1324 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1327 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1330 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1335 atp_writeb_io(dev
, c
, 0x14, 0x05);
1336 atp_writeb_io(dev
, c
, 0x18, 0x20);
1338 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1339 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1340 atp_writeb_io(dev
, c
, 0x19, wide
[j
++]);
1343 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
1346 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1358 atp_writeb_io(dev
, c
, 0x18, 0x20);
1359 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1360 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1361 atp_writeb_io(dev
, c
, 0x19, 0);
1363 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1375 atp_writeb_io(dev
, c
, 0x14, 0xff);
1376 atp_writeb_io(dev
, c
, 0x18, 0x20);
1379 j
= atp_readb_io(dev
, c
, 0x1f);
1380 if ((j
& 0x01) != 0) {
1381 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
1384 if ((j
& 0x80) == 0x00) {
1387 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1399 atp_writeb_io(dev
, c
, 0x10, 0x30);
1400 atp_writeb_io(dev
, c
, 0x14, 0x00);
1401 atp_writeb_io(dev
, c
, 0x18, 0x08);
1403 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1406 j
= atp_readb_io(dev
, c
, 0x17);
1413 if (mbuf
[0] != 0x01) {
1416 if (mbuf
[1] != 0x02) {
1419 if (mbuf
[2] != 0x03) {
1422 if (mbuf
[3] != 0x01) {
1427 dev
->wide_id
[c
] |= m
;
1429 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) || ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
1435 if ((m
& dev
->wide_id
[c
]) != 0) {
1438 atp_writeb_io(dev
, c
, 0x1b, j
);
1439 atp_writeb_io(dev
, c
, 3, satn
[0]);
1440 atp_writeb_io(dev
, c
, 4, satn
[1]);
1441 atp_writeb_io(dev
, c
, 5, satn
[2]);
1442 atp_writeb_io(dev
, c
, 6, satn
[3]);
1443 atp_writeb_io(dev
, c
, 7, satn
[4]);
1444 atp_writeb_io(dev
, c
, 8, satn
[5]);
1445 atp_writeb_io(dev
, c
, 0x0f, 0);
1446 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1447 atp_writeb_io(dev
, c
, 0x12, 0);
1448 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1449 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1450 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1452 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1455 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1458 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1463 atp_writeb_io(dev
, c
, 0x14, 0x06);
1464 atp_writeb_io(dev
, c
, 0x18, 0x20);
1466 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1467 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0) {
1468 if ((m
& dev
->wide_id
[c
]) != 0) {
1469 atp_writeb_io(dev
, c
, 0x19, synw
[j
++]);
1471 if ((m
& dev
->ultra_map
[c
]) != 0) {
1472 atp_writeb_io(dev
, c
, 0x19, synu
[j
++]);
1474 atp_writeb_io(dev
, c
, 0x19, synn
[j
++]);
1480 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
1483 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1495 atp_writeb_io(dev
, c
, 0x18, 0x20);
1496 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00) {
1497 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0x00)
1498 atp_writeb_io(dev
, c
, 0x19, 0x00);
1500 j
= atp_readb_io(dev
, c
, 0x17);
1516 atp_writeb_io(dev
, c
, 0x14, 0xff);
1517 atp_writeb_io(dev
, c
, 0x18, 0x20);
1520 j
= atp_readb_io(dev
, c
, 0x1f);
1521 if ((j
& 0x01) != 0x00) {
1522 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
1525 if ((j
& 0x80) == 0x00) {
1529 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
1532 j
= atp_readb_io(dev
, c
, 0x17);
1548 atp_writeb_io(dev
, c
, 0x10, 0x30);
1550 atp_writeb_io(dev
, c
, 0x14, 0x00);
1551 atp_writeb_io(dev
, c
, 0x18, 0x08);
1553 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1556 j
= atp_readb_io(dev
, c
, 0x17);
1560 if (mbuf
[0] != 0x01) {
1563 if (mbuf
[1] != 0x03) {
1566 if (mbuf
[4] == 0x00) {
1569 if (mbuf
[3] > 0x64) {
1572 if (mbuf
[4] > 0x0c) {
1575 dev
->id
[c
][i
].devsp
= mbuf
[4];
1576 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
1580 if (mbuf
[3] < 0x1a) {
1584 if (mbuf
[3] < 0x33) {
1588 if (mbuf
[3] < 0x4c) {
1594 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
1596 atp_writeb_io(dev
, c
, 0x3a, atp_readb_io(dev
, c
, 0x3a) & 0xef);
1599 static void is880(struct atp_unit
*dev
, unsigned char c
)
1601 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
1602 unsigned short int m
;
1603 static unsigned char mbuf
[512];
1604 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1605 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1606 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1607 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1608 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1609 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1610 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1611 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1613 lvdmode
= atp_readb_base(dev
, 0x3f) & 0x40;
1615 for (i
= 0; i
< 16; i
++) {
1618 if ((m
& dev
->active_id
[c
]) != 0) {
1621 if (i
== dev
->host_id
[c
]) {
1622 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
1625 atp_writeb_io(dev
, c
, 0x1b, 0x01);
1626 atp_writeb_io(dev
, c
, 1, 0x08);
1627 atp_writeb_io(dev
, c
, 2, 0x7f);
1628 atp_writeb_io(dev
, c
, 3, satn
[0]);
1629 atp_writeb_io(dev
, c
, 4, satn
[1]);
1630 atp_writeb_io(dev
, c
, 5, satn
[2]);
1631 atp_writeb_io(dev
, c
, 6, satn
[3]);
1632 atp_writeb_io(dev
, c
, 7, satn
[4]);
1633 atp_writeb_io(dev
, c
, 8, satn
[5]);
1634 atp_writeb_io(dev
, c
, 0x0f, 0);
1635 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1636 atp_writeb_io(dev
, c
, 0x12, 0);
1637 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1638 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1640 if ((j
& 0x08) != 0) {
1641 j
= (j
& 0x07) | 0x40;
1643 atp_writeb_io(dev
, c
, 0x15, j
);
1644 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1646 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1649 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1652 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1655 dev
->active_id
[c
] |= m
;
1657 atp_writeb_io(dev
, c
, 0x10, 0x30);
1658 atp_writeb_io(dev
, c
, 0x14, 0x00);
1661 atp_writeb_io(dev
, c
, 0x18, 0x08);
1663 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1666 j
= atp_readb_io(dev
, c
, 0x17);
1668 atp_writeb_io(dev
, c
, 0x10, 0x41);
1672 atp_writeb_io(dev
, c
, 3, inqd
[0]);
1673 atp_writeb_io(dev
, c
, 4, inqd
[1]);
1674 atp_writeb_io(dev
, c
, 5, inqd
[2]);
1675 atp_writeb_io(dev
, c
, 6, inqd
[3]);
1676 atp_writeb_io(dev
, c
, 7, inqd
[4]);
1677 atp_writeb_io(dev
, c
, 8, inqd
[5]);
1678 atp_writeb_io(dev
, c
, 0x0f, 0);
1679 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1680 atp_writeb_io(dev
, c
, 0x12, 0);
1681 atp_writeb_io(dev
, c
, 0x13, inqd
[6]);
1682 atp_writeb_io(dev
, c
, 0x14, inqd
[7]);
1683 atp_writeb_io(dev
, c
, 0x18, inqd
[8]);
1685 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1688 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1691 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1694 atp_writeb_io(dev
, c
, 0x1b, 0x00);
1695 atp_writeb_io(dev
, c
, 0x18, 0x08);
1698 k
= atp_readb_io(dev
, c
, 0x1f);
1699 if ((k
& 0x01) != 0) {
1700 mbuf
[j
++] = atp_readb_io(dev
, c
, 0x19);
1703 if ((k
& 0x80) == 0) {
1706 j
= atp_readb_io(dev
, c
, 0x17);
1710 atp_writeb_io(dev
, c
, 0x10, 0x46);
1711 atp_writeb_io(dev
, c
, 0x12, 0);
1712 atp_writeb_io(dev
, c
, 0x13, 0);
1713 atp_writeb_io(dev
, c
, 0x14, 0);
1714 atp_writeb_io(dev
, c
, 0x18, 0x08);
1716 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1719 if (atp_readb_io(dev
, c
, 0x17) != 0x16)
1724 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1725 dev
->id
[c
][i
].devtype
= mbuf
[0];
1728 if ((mbuf
[7] & 0x60) == 0) {
1731 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
1737 if (dev
->sp
[c
][i
] != 0x04) // force u2
1742 atp_writeb_io(dev
, c
, 0x1b, 0x01);
1743 atp_writeb_io(dev
, c
, 3, satn
[0]);
1744 atp_writeb_io(dev
, c
, 4, satn
[1]);
1745 atp_writeb_io(dev
, c
, 5, satn
[2]);
1746 atp_writeb_io(dev
, c
, 6, satn
[3]);
1747 atp_writeb_io(dev
, c
, 7, satn
[4]);
1748 atp_writeb_io(dev
, c
, 8, satn
[5]);
1749 atp_writeb_io(dev
, c
, 0x0f, 0);
1750 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1751 atp_writeb_io(dev
, c
, 0x12, 0);
1752 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1753 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1754 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1756 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1759 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1762 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1767 atp_writeb_io(dev
, c
, 0x14, 0x09);
1768 atp_writeb_io(dev
, c
, 0x18, 0x20);
1770 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1771 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1772 atp_writeb_io(dev
, c
, 0x19, u3
[j
++]);
1775 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
1778 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1790 atp_writeb_io(dev
, c
, 0x18, 0x20);
1791 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1792 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1793 atp_writeb_io(dev
, c
, 0x19, 0);
1795 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1807 atp_writeb_io(dev
, c
, 0x14, 0x09);
1808 atp_writeb_io(dev
, c
, 0x18, 0x20);
1811 j
= atp_readb_io(dev
, c
, 0x1f);
1812 if ((j
& 0x01) != 0) {
1813 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
1816 if ((j
& 0x80) == 0x00) {
1819 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1831 atp_writeb_io(dev
, c
, 0x10, 0x30);
1832 atp_writeb_io(dev
, c
, 0x14, 0x00);
1833 atp_writeb_io(dev
, c
, 0x18, 0x08);
1835 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1838 j
= atp_readb_io(dev
, c
, 0x17);
1845 if (mbuf
[0] != 0x01) {
1848 if (mbuf
[1] != 0x06) {
1851 if (mbuf
[2] != 0x04) {
1854 if (mbuf
[3] == 0x09) {
1857 dev
->wide_id
[c
] |= m
;
1858 dev
->id
[c
][i
].devsp
= 0xce;
1862 atp_writeb_io(dev
, c
, 0x1b, 0x01);
1863 atp_writeb_io(dev
, c
, 3, satn
[0]);
1864 atp_writeb_io(dev
, c
, 4, satn
[1]);
1865 atp_writeb_io(dev
, c
, 5, satn
[2]);
1866 atp_writeb_io(dev
, c
, 6, satn
[3]);
1867 atp_writeb_io(dev
, c
, 7, satn
[4]);
1868 atp_writeb_io(dev
, c
, 8, satn
[5]);
1869 atp_writeb_io(dev
, c
, 0x0f, 0);
1870 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1871 atp_writeb_io(dev
, c
, 0x12, 0);
1872 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1873 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1874 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1876 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1879 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1882 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1887 atp_writeb_io(dev
, c
, 0x14, 0x05);
1888 atp_writeb_io(dev
, c
, 0x18, 0x20);
1890 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1891 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1892 atp_writeb_io(dev
, c
, 0x19, wide
[j
++]);
1895 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
1898 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1910 atp_writeb_io(dev
, c
, 0x18, 0x20);
1911 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1912 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1913 atp_writeb_io(dev
, c
, 0x19, 0);
1915 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1927 atp_writeb_io(dev
, c
, 0x14, 0xff);
1928 atp_writeb_io(dev
, c
, 0x18, 0x20);
1931 j
= atp_readb_io(dev
, c
, 0x1f);
1932 if ((j
& 0x01) != 0) {
1933 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
1936 if ((j
& 0x80) == 0x00) {
1939 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1951 atp_writeb_io(dev
, c
, 0x10, 0x30);
1952 atp_writeb_io(dev
, c
, 0x14, 0x00);
1953 atp_writeb_io(dev
, c
, 0x18, 0x08);
1955 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1958 j
= atp_readb_io(dev
, c
, 0x17);
1965 if (mbuf
[0] != 0x01) {
1968 if (mbuf
[1] != 0x02) {
1971 if (mbuf
[2] != 0x03) {
1974 if (mbuf
[3] != 0x01) {
1979 dev
->wide_id
[c
] |= m
;
1981 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) || ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
1984 if ((dev
->async
[c
] & m
) != 0) {
1990 if (dev
->sp
[c
][i
] == 0x02) {
1994 if (dev
->sp
[c
][i
] >= 0x03) {
2000 if ((m
& dev
->wide_id
[c
]) != 0) {
2003 atp_writeb_io(dev
, c
, 0x1b, j
);
2004 atp_writeb_io(dev
, c
, 3, satn
[0]);
2005 atp_writeb_io(dev
, c
, 4, satn
[1]);
2006 atp_writeb_io(dev
, c
, 5, satn
[2]);
2007 atp_writeb_io(dev
, c
, 6, satn
[3]);
2008 atp_writeb_io(dev
, c
, 7, satn
[4]);
2009 atp_writeb_io(dev
, c
, 8, satn
[5]);
2010 atp_writeb_io(dev
, c
, 0x0f, 0);
2011 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
2012 atp_writeb_io(dev
, c
, 0x12, 0);
2013 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
2014 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
2015 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
2017 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2020 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
2023 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
2028 atp_writeb_io(dev
, c
, 0x14, 0x06);
2029 atp_writeb_io(dev
, c
, 0x18, 0x20);
2031 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
2032 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0) {
2033 if ((m
& dev
->wide_id
[c
]) != 0) {
2034 if ((m
& dev
->ultra_map
[c
]) != 0) {
2035 atp_writeb_io(dev
, c
, 0x19, synuw
[j
++]);
2037 atp_writeb_io(dev
, c
, 0x19, synw
[j
++]);
2040 if ((m
& dev
->ultra_map
[c
]) != 0) {
2041 atp_writeb_io(dev
, c
, 0x19, synu
[j
++]);
2043 atp_writeb_io(dev
, c
, 0x19, synn
[j
++]);
2049 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
2052 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
2064 atp_writeb_io(dev
, c
, 0x18, 0x20);
2065 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00) {
2066 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0x00)
2067 atp_writeb_io(dev
, c
, 0x19, 0x00);
2069 j
= atp_readb_io(dev
, c
, 0x17);
2085 atp_writeb_io(dev
, c
, 0x14, 0x06);
2086 atp_writeb_io(dev
, c
, 0x18, 0x20);
2089 j
= atp_readb_io(dev
, c
, 0x1f);
2090 if ((j
& 0x01) != 0x00) {
2091 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
2094 if ((j
& 0x80) == 0x00) {
2098 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
2101 j
= atp_readb_io(dev
, c
, 0x17);
2117 atp_writeb_io(dev
, c
, 0x10, 0x30);
2119 atp_writeb_io(dev
, c
, 0x14, 0x00);
2120 atp_writeb_io(dev
, c
, 0x18, 0x08);
2122 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2125 j
= atp_readb_io(dev
, c
, 0x17);
2129 if (mbuf
[0] != 0x01) {
2132 if (mbuf
[1] != 0x03) {
2135 if (mbuf
[4] == 0x00) {
2138 if (mbuf
[3] > 0x64) {
2141 if (mbuf
[4] > 0x0e) {
2144 dev
->id
[c
][i
].devsp
= mbuf
[4];
2145 if (mbuf
[3] < 0x0c) {
2149 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
2153 if (mbuf
[3] < 0x1a) {
2157 if (mbuf
[3] < 0x33) {
2161 if (mbuf
[3] < 0x4c) {
2167 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
2171 static void atp870u_free_tables(struct Scsi_Host
*host
)
2173 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2175 for (j
=0; j
< 2; j
++) {
2176 for (k
= 0; k
< 16; k
++) {
2177 if (!atp_dev
->id
[j
][k
].prd_table
)
2179 pci_free_consistent(atp_dev
->pdev
, 1024, atp_dev
->id
[j
][k
].prd_table
, atp_dev
->id
[j
][k
].prd_bus
);
2180 atp_dev
->id
[j
][k
].prd_table
= NULL
;
2185 static int atp870u_init_tables(struct Scsi_Host
*host
)
2187 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2189 for(c
=0;c
< 2;c
++) {
2191 atp_dev
->id
[c
][k
].prd_table
= pci_alloc_consistent(atp_dev
->pdev
, 1024, &(atp_dev
->id
[c
][k
].prd_bus
));
2192 if (!atp_dev
->id
[c
][k
].prd_table
) {
2193 printk("atp870u_init_tables fail\n");
2194 atp870u_free_tables(host
);
2197 atp_dev
->id
[c
][k
].prdaddr
= atp_dev
->id
[c
][k
].prd_bus
;
2198 atp_dev
->id
[c
][k
].devsp
=0x20;
2199 atp_dev
->id
[c
][k
].devtype
= 0x7f;
2200 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2203 atp_dev
->active_id
[c
] = 0;
2204 atp_dev
->wide_id
[c
] = 0;
2205 atp_dev
->host_id
[c
] = 0x07;
2206 atp_dev
->quhd
[c
] = 0;
2207 atp_dev
->quend
[c
] = 0;
2208 atp_dev
->last_cmd
[c
] = 0xff;
2209 atp_dev
->in_snd
[c
] = 0;
2210 atp_dev
->in_int
[c
] = 0;
2212 for (k
= 0; k
< qcnt
; k
++) {
2213 atp_dev
->quereq
[c
][k
] = NULL
;
2215 for (k
= 0; k
< 16; k
++) {
2216 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2217 atp_dev
->sp
[c
][k
] = 0x04;
2223 /* return non-zero on detection */
2224 static int atp870u_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2226 unsigned char k
, m
, c
;
2227 unsigned long flags
;
2228 unsigned int base_io
, error
,n
;
2229 unsigned char host_id
;
2230 struct Scsi_Host
*shpnt
= NULL
;
2231 struct atp_unit
*atpdev
, *p
;
2232 unsigned char setupdata
[2][16];
2235 atpdev
= kzalloc(sizeof(*atpdev
), GFP_KERNEL
);
2239 if (pci_enable_device(pdev
))
2242 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
2243 printk(KERN_INFO
"atp870u: use 32bit DMA mask.\n");
2245 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
2250 * It's probably easier to weed out some revisions like
2251 * this than via the PCI device table
2253 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
) {
2254 atpdev
->chip_ver
= pdev
->revision
;
2255 if (atpdev
->chip_ver
< 2)
2259 switch (ent
->device
) {
2260 case PCI_DEVICE_ID_ARTOP_AEC7612UW
:
2261 case PCI_DEVICE_ID_ARTOP_AEC7612SUW
:
2265 atpdev
->chip_ver
= 0x04;
2269 base_io
= pci_resource_start(pdev
, 0);
2270 base_io
&= 0xfffffff8;
2271 atpdev
->baseport
= base_io
;
2273 if ((ent
->device
== ATP880_DEVID1
)||(ent
->device
== ATP880_DEVID2
)) {
2274 atpdev
->chip_ver
= pdev
->revision
;
2275 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
2277 host_id
= inb(base_io
+ 0x39);
2280 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2281 " IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2282 atpdev
->ioport
[0] = base_io
+ 0x40;
2283 atpdev
->pciport
[0] = base_io
+ 0x28;
2284 atpdev
->dev_id
= ent
->device
;
2285 atpdev
->host_id
[0] = host_id
;
2287 atpdev
->scam_on
= inb(base_io
+ 0x22);
2288 atpdev
->global_map
[0] = inb(base_io
+ 0x35);
2289 atpdev
->ultra_map
[0] = inw(base_io
+ 0x3c);
2297 outw(n
, base_io
+ 0x34);
2299 if (inb(base_io
+ 0x30) == 0xff)
2302 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2303 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2304 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2305 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2306 outw(n
, base_io
+ 0x34);
2308 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2309 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2310 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2311 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2312 outw(n
, base_io
+ 0x34);
2314 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2315 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2316 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2317 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2318 outw(n
, base_io
+ 0x34);
2320 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2321 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2322 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2323 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2327 outw(0, base_io
+ 0x34);
2328 atpdev
->ultra_map
[0] = 0;
2329 atpdev
->async
[0] = 0;
2330 for (k
= 0; k
< 16; k
++) {
2333 if (atpdev
->sp
[0][k
] > 1) {
2334 atpdev
->ultra_map
[0] |= n
;
2336 if (atpdev
->sp
[0][k
] == 0)
2337 atpdev
->async
[0] |= n
;
2340 atpdev
->async
[0] = ~(atpdev
->async
[0]);
2341 outb(atpdev
->global_map
[0], base_io
+ 0x35);
2343 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2347 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2349 atpdev
->host
= shpnt
;
2350 atpdev
->pdev
= pdev
;
2351 pci_set_drvdata(pdev
, p
);
2352 memcpy(p
, atpdev
, sizeof(*atpdev
));
2353 if (atp870u_init_tables(shpnt
) < 0) {
2354 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
2358 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp880i", shpnt
)) {
2359 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2363 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2364 k
= inb(base_io
+ 0x38) & 0x80;
2365 outb(k
, base_io
+ 0x38);
2366 outb(0x20, base_io
+ 0x3b);
2368 outb(0, base_io
+ 0x3b);
2370 inb(base_io
+ 0x5b);
2371 inb(base_io
+ 0x57);
2372 outb((host_id
| 0x08), base_io
+ 0x40);
2373 outb(0, base_io
+ 0x58);
2374 while ((inb(base_io
+ 0x5f) & 0x80) == 0)
2376 inb(base_io
+ 0x57);
2377 outb(8, base_io
+ 0x41);
2378 outb(0x7f, base_io
+ 0x42);
2379 outb(0x20, base_io
+ 0x51);
2383 outb(0xb0, base_io
+ 0x38);
2385 shpnt
->this_id
= host_id
;
2386 shpnt
->unique_id
= base_io
;
2387 shpnt
->io_port
= base_io
;
2388 shpnt
->n_io_port
= 0x60; /* Number of bytes of I/O space used */
2389 shpnt
->irq
= pdev
->irq
;
2390 } else if (ent
->device
== ATP885_DEVID
) {
2391 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2392 , base_io
, pdev
->irq
);
2394 atpdev
->pdev
= pdev
;
2395 atpdev
->dev_id
= ent
->device
;
2396 atpdev
->ioport
[0] = base_io
+ 0x80;
2397 atpdev
->ioport
[1] = base_io
+ 0xc0;
2398 atpdev
->pciport
[0] = base_io
+ 0x40;
2399 atpdev
->pciport
[1] = base_io
+ 0x50;
2401 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2405 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2407 atpdev
->host
= shpnt
;
2408 atpdev
->pdev
= pdev
;
2409 pci_set_drvdata(pdev
, p
);
2410 memcpy(p
, atpdev
, sizeof(struct atp_unit
));
2411 if (atp870u_init_tables(shpnt
) < 0)
2415 printk("request_irq() shpnt %p hostdata %p\n", shpnt
, p
);
2417 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870u", shpnt
)) {
2418 printk(KERN_ERR
"Unable to allocate IRQ for Acard controller.\n");
2422 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2424 c
=inb(base_io
+ 0x29);
2425 outb((c
| 0x04),base_io
+ 0x29);
2432 outw(n
,base_io
+ 0x3c);
2433 if (inl(base_io
+ 0x38) == 0xffffffff) {
2436 for (m
=0; m
< 2; m
++) {
2437 p
->global_map
[m
]= 0;
2438 for (k
=0; k
< 4; k
++) {
2439 outw(n
++,base_io
+ 0x3c);
2440 ((unsigned long *)&setupdata
[m
][0])[k
]=inl(base_io
+ 0x38);
2442 for (k
=0; k
< 4; k
++) {
2443 outw(n
++,base_io
+ 0x3c);
2444 ((unsigned long *)&p
->sp
[m
][0])[k
]=inl(base_io
+ 0x38);
2451 printk( "Flash Read OK\n");
2453 c
=inb(base_io
+ 0x29);
2454 outb((c
& 0xfb),base_io
+ 0x29);
2455 for (c
=0;c
< 2;c
++) {
2458 for (k
=0; k
< 16; k
++) {
2461 if (p
->sp
[c
][k
] > 1) {
2462 p
->ultra_map
[c
] |= n
;
2464 if (p
->sp
[c
][k
] == 0) {
2469 p
->async
[c
] = ~(p
->async
[c
]);
2471 if (p
->global_map
[c
] == 0) {
2473 if ((k
& 0x40) != 0)
2474 p
->global_map
[c
] |= 0x20;
2476 p
->global_map
[c
] |= k
;
2477 if ((setupdata
[c
][2] & 0x04) != 0)
2478 p
->global_map
[c
] |= 0x08;
2479 p
->host_id
[c
] = setupdata
[c
][0] & 0x07;
2483 k
= inb(base_io
+ 0x28) & 0x8f;
2485 outb(k
, base_io
+ 0x28);
2486 outb(0x80, base_io
+ 0x41);
2487 outb(0x80, base_io
+ 0x51);
2489 outb(0, base_io
+ 0x41);
2490 outb(0, base_io
+ 0x51);
2492 inb(base_io
+ 0x9b);
2493 inb(base_io
+ 0x97);
2494 inb(base_io
+ 0xdb);
2495 inb(base_io
+ 0xd7);
2498 k
= (k
& 0x07) | 0x40;
2500 outb(k
, base_io
+ 0x80);
2501 outb(0, base_io
+ 0x98);
2503 while ((inb(base_io
+ 0x9f) & 0x80) == 0)
2506 inb(base_io
+ 0x97);
2507 outb(8, base_io
+ 0x81);
2508 outb(0x7f, base_io
+ 0x82);
2509 outb(0x20, base_io
+ 0x91);
2513 k
= (k
& 0x07) | 0x40;
2515 outb(k
, base_io
+ 0xc0);
2516 outb(0, base_io
+ 0xd8);
2518 while ((inb(base_io
+ 0xdf) & 0x80) == 0)
2521 inb(base_io
+ 0xd7);
2522 outb(8, base_io
+ 0xc1);
2523 outb(0x7f, base_io
+ 0xc2);
2524 outb(0x20, base_io
+ 0xd1);
2527 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
2529 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
2532 k
= inb(base_io
+ 0x28) & 0xcf;
2534 outb(k
, base_io
+ 0x28);
2535 k
= inb(base_io
+ 0x1f) | 0x80;
2536 outb(k
, base_io
+ 0x1f);
2537 k
= inb(base_io
+ 0x29) | 0x01;
2538 outb(k
, base_io
+ 0x29);
2540 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2543 shpnt
->max_lun
= (p
->global_map
[0] & 0x07) + 1;
2544 shpnt
->max_channel
= 1;
2545 shpnt
->this_id
= p
->host_id
[0];
2546 shpnt
->unique_id
= base_io
;
2547 shpnt
->io_port
= base_io
;
2548 shpnt
->n_io_port
= 0xff; /* Number of bytes of I/O space used */
2549 shpnt
->irq
= pdev
->irq
;
2552 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
2554 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2555 "IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2557 atpdev
->ioport
[0] = base_io
;
2558 atpdev
->pciport
[0] = base_io
+ 0x20;
2559 atpdev
->dev_id
= ent
->device
;
2561 atpdev
->host_id
[0] = host_id
;
2562 atpdev
->scam_on
= inb(base_io
+ 0x22);
2563 atpdev
->global_map
[0] = inb(base_io
+ 0x2d);
2564 atpdev
->ultra_map
[0] = inw(base_io
+ 0x2e);
2566 if (atpdev
->ultra_map
[0] == 0) {
2567 atpdev
->scam_on
= 0x00;
2568 atpdev
->global_map
[0] = 0x20;
2569 atpdev
->ultra_map
[0] = 0xffff;
2572 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2576 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2578 atpdev
->host
= shpnt
;
2579 atpdev
->pdev
= pdev
;
2580 pci_set_drvdata(pdev
, p
);
2581 memcpy(p
, atpdev
, sizeof(*atpdev
));
2582 if (atp870u_init_tables(shpnt
) < 0)
2585 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870i", shpnt
)) {
2586 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2590 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2591 if (atpdev
->chip_ver
> 0x07) { /* check if atp876 chip then enable terminator */
2592 outb(0x00, base_io
+ 0x3e);
2595 k
= (inb(base_io
+ 0x3a) & 0xf3) | 0x10;
2596 outb(k
, base_io
+ 0x3a);
2597 outb((k
& 0xdf), base_io
+ 0x3a);
2599 outb(k
, base_io
+ 0x3a);
2601 outb((host_id
| 0x08), base_io
+ 0);
2602 outb(0, base_io
+ 0x18);
2603 while ((inb(base_io
+ 0x1f) & 0x80) == 0)
2606 inb(base_io
+ 0x17);
2607 outb(8, base_io
+ 1);
2608 outb(0x7f, base_io
+ 2);
2609 outb(0x20, base_io
+ 0x11);
2613 outb((inb(base_io
+ 0x3a) & 0xef), base_io
+ 0x3a);
2614 outb((inb(base_io
+ 0x3b) | 0x20), base_io
+ 0x3b);
2615 if (atpdev
->chip_ver
== 4)
2619 shpnt
->this_id
= host_id
;
2620 shpnt
->unique_id
= base_io
;
2621 shpnt
->io_port
= base_io
;
2622 shpnt
->n_io_port
= 0x40; /* Number of bytes of I/O space used */
2623 shpnt
->irq
= pdev
->irq
;
2625 spin_unlock_irqrestore(shpnt
->host_lock
, flags
);
2626 if(ent
->device
==ATP885_DEVID
) {
2627 if(!request_region(base_io
, 0xff, "atp870u")) /* Register the IO ports that we use */
2628 goto request_io_fail
;
2629 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
2630 if(!request_region(base_io
, 0x60, "atp870u")) /* Register the IO ports that we use */
2631 goto request_io_fail
;
2633 if(!request_region(base_io
, 0x40, "atp870u")) /* Register the IO ports that we use */
2634 goto request_io_fail
;
2637 if (scsi_add_host(shpnt
, &pdev
->dev
))
2639 scsi_scan_host(shpnt
);
2641 printk("atp870u_prob : exit\n");
2646 printk("atp870u_prob:scsi_add_fail\n");
2647 if(ent
->device
==ATP885_DEVID
) {
2648 release_region(base_io
, 0xff);
2649 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
2650 release_region(base_io
, 0x60);
2652 release_region(base_io
, 0x40);
2655 printk("atp870u_prob:request_io_fail\n");
2656 free_irq(pdev
->irq
, shpnt
);
2658 printk("atp870u_prob:free_table\n");
2659 atp870u_free_tables(shpnt
);
2661 printk("atp870u_prob:unregister\n");
2662 scsi_host_put(shpnt
);
2672 /* The abort command does not leave the device in a clean state where
2673 it is available to be used again. Until this gets worked out, we will
2674 leave it commented out. */
2676 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
2678 unsigned char j
, k
, c
;
2679 struct scsi_cmnd
*workrequ
;
2680 struct atp_unit
*dev
;
2681 struct Scsi_Host
*host
;
2682 host
= SCpnt
->device
->host
;
2684 dev
= (struct atp_unit
*)&host
->hostdata
;
2685 c
= scmd_channel(SCpnt
);
2686 printk(" atp870u: abort Channel = %x \n", c
);
2687 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
2688 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
2689 for (j
= 0; j
< 0x18; j
++) {
2690 printk(" r%2x=%2x", j
, atp_readb_io(dev
, c
, j
));
2692 printk(" r1c=%2x", atp_readb_io(dev
, c
, 0x1c));
2693 printk(" r1f=%2x in_snd=%2x ", atp_readb_io(dev
, c
, 0x1f), dev
->in_snd
[c
]);
2694 printk(" d00=%2x", atp_readb_pci(dev
, c
, 0x00));
2695 printk(" d02=%2x", atp_readb_pci(dev
, c
, 0x02));
2697 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
2698 workrequ
= dev
->id
[c
][j
].curr_req
;
2699 printk("\n que cdb= ");
2700 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
2701 printk(" %2x ",workrequ
->cmnd
[k
]);
2703 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
2709 static const char *atp870u_info(struct Scsi_Host
*notused
)
2711 static char buffer
[128];
2713 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
2718 static int atp870u_show_info(struct seq_file
*m
, struct Scsi_Host
*HBAptr
)
2720 seq_puts(m
, "ACARD AEC-671X Driver Version: 2.6+ac\n\n"
2721 "Adapter Configuration:\n");
2722 seq_printf(m
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
2723 seq_printf(m
, " IRQ: %d\n", HBAptr
->irq
);
2728 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
2729 sector_t capacity
, int *ip
)
2731 int heads
, sectors
, cylinders
;
2735 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
2736 if (cylinders
> 1024) {
2739 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
2748 static void atp870u_remove (struct pci_dev
*pdev
)
2750 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
2751 struct Scsi_Host
*pshost
= devext
->host
;
2754 scsi_remove_host(pshost
);
2755 printk(KERN_INFO
"free_irq : %d\n",pshost
->irq
);
2756 free_irq(pshost
->irq
, pshost
);
2757 release_region(pshost
->io_port
, pshost
->n_io_port
);
2758 printk(KERN_INFO
"atp870u_free_tables : %p\n",pshost
);
2759 atp870u_free_tables(pshost
);
2760 printk(KERN_INFO
"scsi_host_put : %p\n",pshost
);
2761 scsi_host_put(pshost
);
2763 MODULE_LICENSE("GPL");
2765 static struct scsi_host_template atp870u_template
= {
2766 .module
= THIS_MODULE
,
2767 .name
= "atp870u" /* name */,
2768 .proc_name
= "atp870u",
2769 .show_info
= atp870u_show_info
,
2770 .info
= atp870u_info
/* info */,
2771 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
2772 .eh_abort_handler
= atp870u_abort
/* abort */,
2773 .bios_param
= atp870u_biosparam
/* biosparm */,
2774 .can_queue
= qcnt
/* can_queue */,
2775 .this_id
= 7 /* SCSI ID */,
2776 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
2777 .use_clustering
= ENABLE_CLUSTERING
,
2778 .max_sectors
= ATP870U_MAX_SECTORS
,
2781 static struct pci_device_id atp870u_id_table
[] = {
2782 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
2783 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
2784 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
2785 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
2786 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
2787 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
2788 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
2789 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
2790 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
2791 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
2795 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
2797 static struct pci_driver atp870u_driver
= {
2798 .id_table
= atp870u_id_table
,
2800 .probe
= atp870u_probe
,
2801 .remove
= atp870u_remove
,
2804 static int __init
atp870u_init(void)
2807 printk("atp870u_init: Entry\n");
2809 return pci_register_driver(&atp870u_driver
);
2812 static void __exit
atp870u_exit(void)
2815 printk("atp870u_exit: Entry\n");
2817 pci_unregister_driver(&atp870u_driver
);
2820 static void tscam_885(void)
2824 for (i
= 0; i
< 0x2; i
++) {
2832 static void is885(struct atp_unit
*dev
, unsigned char c
)
2834 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
2835 unsigned short int m
;
2836 static unsigned char mbuf
[512];
2837 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
2838 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
2839 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
2840 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
2841 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
2842 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
2843 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
2844 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
2846 lvdmode
= atp_readb_io(dev
, c
, 0x1b) >> 7;
2848 for (i
= 0; i
< 16; i
++) {
2851 if ((m
& dev
->active_id
[c
]) != 0) {
2854 if (i
== dev
->host_id
[c
]) {
2855 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
2858 atp_writeb_io(dev
, c
, 0x1b, 0x01);
2859 atp_writeb_io(dev
, c
, 1, 0x08);
2860 atp_writeb_io(dev
, c
, 2, 0x7f);
2861 atp_writeb_io(dev
, c
, 3, satn
[0]);
2862 atp_writeb_io(dev
, c
, 4, satn
[1]);
2863 atp_writeb_io(dev
, c
, 5, satn
[2]);
2864 atp_writeb_io(dev
, c
, 6, satn
[3]);
2865 atp_writeb_io(dev
, c
, 7, satn
[4]);
2866 atp_writeb_io(dev
, c
, 8, satn
[5]);
2867 atp_writeb_io(dev
, c
, 0x0f, 0);
2868 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
2869 atp_writeb_io(dev
, c
, 0x12, 0);
2870 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
2871 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
2873 if ((j
& 0x08) != 0) {
2874 j
= (j
& 0x07) | 0x40;
2876 atp_writeb_io(dev
, c
, 0x15, j
);
2877 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
2879 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2882 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
2885 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
2888 dev
->active_id
[c
] |= m
;
2890 atp_writeb_io(dev
, c
, 0x10, 0x30);
2891 atp_writeb_io(dev
, c
, 0x14, 0x00);
2894 atp_writeb_io(dev
, c
, 0x18, 0x08);
2896 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2899 j
= atp_readb_io(dev
, c
, 0x17);
2901 atp_writeb_io(dev
, c
, 0x10, 0x41);
2905 atp_writeb_io(dev
, c
, 3, inqd
[0]);
2906 atp_writeb_io(dev
, c
, 4, inqd
[1]);
2907 atp_writeb_io(dev
, c
, 5, inqd
[2]);
2908 atp_writeb_io(dev
, c
, 6, inqd
[3]);
2909 atp_writeb_io(dev
, c
, 7, inqd
[4]);
2910 atp_writeb_io(dev
, c
, 8, inqd
[5]);
2911 atp_writeb_io(dev
, c
, 0x0f, 0);
2912 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
2913 atp_writeb_io(dev
, c
, 0x12, 0);
2914 atp_writeb_io(dev
, c
, 0x13, inqd
[6]);
2915 atp_writeb_io(dev
, c
, 0x14, inqd
[7]);
2916 atp_writeb_io(dev
, c
, 0x18, inqd
[8]);
2918 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2921 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
2924 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
2927 atp_writeb_io(dev
, c
, 0x1b, 0x00);
2928 atp_writeb_io(dev
, c
, 0x18, 0x08);
2931 k
= atp_readb_io(dev
, c
, 0x1f);
2932 if ((k
& 0x01) != 0) {
2933 mbuf
[j
++] = atp_readb_io(dev
, c
, 0x19);
2936 if ((k
& 0x80) == 0) {
2939 j
= atp_readb_io(dev
, c
, 0x17);
2943 atp_writeb_io(dev
, c
, 0x10, 0x46);
2944 atp_writeb_io(dev
, c
, 0x12, 0);
2945 atp_writeb_io(dev
, c
, 0x13, 0);
2946 atp_writeb_io(dev
, c
, 0x14, 0);
2947 atp_writeb_io(dev
, c
, 0x18, 0x08);
2949 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2952 if (atp_readb_io(dev
, c
, 0x17) != 0x16)
2957 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
2958 dev
->id
[c
][i
].devtype
= mbuf
[0];
2961 if ((mbuf
[7] & 0x60) == 0) {
2964 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
2970 if (dev
->sp
[c
][i
] != 0x04) // force u2
2975 atp_writeb_io(dev
, c
, 0x1b, 0x01);
2976 atp_writeb_io(dev
, c
, 3, satn
[0]);
2977 atp_writeb_io(dev
, c
, 4, satn
[1]);
2978 atp_writeb_io(dev
, c
, 5, satn
[2]);
2979 atp_writeb_io(dev
, c
, 6, satn
[3]);
2980 atp_writeb_io(dev
, c
, 7, satn
[4]);
2981 atp_writeb_io(dev
, c
, 8, satn
[5]);
2982 atp_writeb_io(dev
, c
, 0x0f, 0);
2983 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
2984 atp_writeb_io(dev
, c
, 0x12, 0);
2985 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
2986 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
2987 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
2989 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2992 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
2995 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
3000 atp_writeb_io(dev
, c
, 0x14, 0x09);
3001 atp_writeb_io(dev
, c
, 0x18, 0x20);
3003 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
3004 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
3005 atp_writeb_io(dev
, c
, 0x19, u3
[j
++]);
3009 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
3012 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
3024 atp_writeb_io(dev
, c
, 0x18, 0x20);
3025 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
3026 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
3027 atp_writeb_io(dev
, c
, 0x19, 0);
3030 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
3042 atp_writeb_io(dev
, c
, 0x14, 0x09);
3043 atp_writeb_io(dev
, c
, 0x18, 0x20);
3046 j
= atp_readb_io(dev
, c
, 0x1f);
3047 if ((j
& 0x01) != 0) {
3048 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
3051 if ((j
& 0x80) == 0x00) {
3054 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
3066 atp_writeb_io(dev
, c
, 0x10, 0x30);
3067 atp_writeb_io(dev
, c
, 0x14, 0x00);
3068 atp_writeb_io(dev
, c
, 0x18, 0x08);
3070 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00);
3072 j
= atp_readb_io(dev
, c
, 0x17);
3079 if (mbuf
[0] != 0x01) {
3082 if (mbuf
[1] != 0x06) {
3085 if (mbuf
[2] != 0x04) {
3088 if (mbuf
[3] == 0x09) {
3091 dev
->wide_id
[c
] |= m
;
3092 dev
->id
[c
][i
].devsp
= 0xce;
3094 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3099 atp_writeb_io(dev
, c
, 0x1b, 0x01);
3100 atp_writeb_io(dev
, c
, 3, satn
[0]);
3101 atp_writeb_io(dev
, c
, 4, satn
[1]);
3102 atp_writeb_io(dev
, c
, 5, satn
[2]);
3103 atp_writeb_io(dev
, c
, 6, satn
[3]);
3104 atp_writeb_io(dev
, c
, 7, satn
[4]);
3105 atp_writeb_io(dev
, c
, 8, satn
[5]);
3106 atp_writeb_io(dev
, c
, 0x0f, 0);
3107 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
3108 atp_writeb_io(dev
, c
, 0x12, 0);
3109 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
3110 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
3111 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
3113 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
3116 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
3119 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
3124 atp_writeb_io(dev
, c
, 0x14, 0x05);
3125 atp_writeb_io(dev
, c
, 0x18, 0x20);
3127 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
3128 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
3129 atp_writeb_io(dev
, c
, 0x19, wide
[j
++]);
3133 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
3136 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
3148 atp_writeb_io(dev
, c
, 0x18, 0x20);
3149 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
3150 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
3151 atp_writeb_io(dev
, c
, 0x19, 0);
3154 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
3166 atp_writeb_io(dev
, c
, 0x14, 0xff);
3167 atp_writeb_io(dev
, c
, 0x18, 0x20);
3170 j
= atp_readb_io(dev
, c
, 0x1f);
3171 if ((j
& 0x01) != 0) {
3172 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
3175 if ((j
& 0x80) == 0x00) {
3178 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
3190 atp_writeb_io(dev
, c
, 0x10, 0x30);
3191 atp_writeb_io(dev
, c
, 0x14, 0x00);
3192 atp_writeb_io(dev
, c
, 0x18, 0x08);
3194 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
3197 j
= atp_readb_io(dev
, c
, 0x17);
3204 if (mbuf
[0] != 0x01) {
3207 if (mbuf
[1] != 0x02) {
3210 if (mbuf
[2] != 0x03) {
3213 if (mbuf
[3] != 0x01) {
3218 dev
->wide_id
[c
] |= m
;
3220 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) || ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
3223 if ((dev
->async
[c
] & m
) != 0) {
3229 if (dev
->sp
[c
][i
] == 0x02) {
3233 if (dev
->sp
[c
][i
] >= 0x03) {
3239 if ((m
& dev
->wide_id
[c
]) != 0) {
3242 atp_writeb_io(dev
, c
, 0x1b, j
);
3243 atp_writeb_io(dev
, c
, 3, satn
[0]);
3244 atp_writeb_io(dev
, c
, 4, satn
[1]);
3245 atp_writeb_io(dev
, c
, 5, satn
[2]);
3246 atp_writeb_io(dev
, c
, 6, satn
[3]);
3247 atp_writeb_io(dev
, c
, 7, satn
[4]);
3248 atp_writeb_io(dev
, c
, 8, satn
[5]);
3249 atp_writeb_io(dev
, c
, 0x0f, 0);
3250 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
3251 atp_writeb_io(dev
, c
, 0x12, 0);
3252 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
3253 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
3254 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
3256 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
3259 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
3262 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
3267 atp_writeb_io(dev
, c
, 0x14, 0x06);
3268 atp_writeb_io(dev
, c
, 0x18, 0x20);
3270 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
3271 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0) {
3272 if ((m
& dev
->wide_id
[c
]) != 0) {
3273 if ((m
& dev
->ultra_map
[c
]) != 0) {
3274 atp_writeb_io(dev
, c
, 0x19, synuw
[j
++]);
3276 atp_writeb_io(dev
, c
, 0x19, synw
[j
++]);
3279 if ((m
& dev
->ultra_map
[c
]) != 0) {
3280 atp_writeb_io(dev
, c
, 0x19, synu
[j
++]);
3282 atp_writeb_io(dev
, c
, 0x19, synn
[j
++]);
3288 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
3291 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
3303 atp_writeb_io(dev
, c
, 0x18, 0x20);
3304 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00) {
3305 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0x00)
3306 atp_writeb_io(dev
, c
, 0x19, 0x00);
3309 j
= atp_readb_io(dev
, c
, 0x17);
3325 atp_writeb_io(dev
, c
, 0x14, 0x06);
3326 atp_writeb_io(dev
, c
, 0x18, 0x20);
3329 j
= atp_readb_io(dev
, c
, 0x1f);
3330 if ((j
& 0x01) != 0x00) {
3331 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
3334 if ((j
& 0x80) == 0x00) {
3338 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00);
3340 j
= atp_readb_io(dev
, c
, 0x17);
3356 atp_writeb_io(dev
, c
, 0x10, 0x30);
3358 atp_writeb_io(dev
, c
, 0x14, 0x00);
3359 atp_writeb_io(dev
, c
, 0x18, 0x08);
3361 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
3364 j
= atp_readb_io(dev
, c
, 0x17);
3368 if (mbuf
[0] != 0x01) {
3371 if (mbuf
[1] != 0x03) {
3374 if (mbuf
[4] == 0x00) {
3377 if (mbuf
[3] > 0x64) {
3380 if (mbuf
[4] > 0x0e) {
3383 dev
->id
[c
][i
].devsp
= mbuf
[4];
3384 if (mbuf
[3] < 0x0c) {
3388 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
3392 if (mbuf
[3] < 0x1a) {
3396 if (mbuf
[3] < 0x33) {
3400 if (mbuf
[3] < 0x4c) {
3406 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
3408 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3411 atp_writeb_io(dev
, c
, 0x16, 0x80);
3414 module_init(atp870u_init
);
3415 module_exit(atp870u_exit
);