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 atp_is(struct atp_unit
*dev
, unsigned char c
, bool wide_chip
, unsigned char lvdmode
);
46 static inline void atp_writeb_base(struct atp_unit
*atp
, u8 reg
, u8 val
)
48 outb(val
, atp
->baseport
+ reg
);
51 static inline void atp_writew_base(struct atp_unit
*atp
, u8 reg
, u16 val
)
53 outw(val
, atp
->baseport
+ reg
);
56 static inline void atp_writeb_io(struct atp_unit
*atp
, u8 channel
, u8 reg
, u8 val
)
58 outb(val
, atp
->ioport
[channel
] + reg
);
61 static inline void atp_writew_io(struct atp_unit
*atp
, u8 channel
, u8 reg
, u16 val
)
63 outw(val
, atp
->ioport
[channel
] + reg
);
66 static inline void atp_writeb_pci(struct atp_unit
*atp
, u8 channel
, u8 reg
, u8 val
)
68 outb(val
, atp
->pciport
[channel
] + reg
);
71 static inline void atp_writel_pci(struct atp_unit
*atp
, u8 channel
, u8 reg
, u32 val
)
73 outl(val
, atp
->pciport
[channel
] + reg
);
76 static inline u8
atp_readb_base(struct atp_unit
*atp
, u8 reg
)
78 return inb(atp
->baseport
+ reg
);
81 static inline u16
atp_readw_base(struct atp_unit
*atp
, u8 reg
)
83 return inw(atp
->baseport
+ reg
);
86 static inline u32
atp_readl_base(struct atp_unit
*atp
, u8 reg
)
88 return inl(atp
->baseport
+ reg
);
91 static inline u8
atp_readb_io(struct atp_unit
*atp
, u8 channel
, u8 reg
)
93 return inb(atp
->ioport
[channel
] + reg
);
96 static inline u16
atp_readw_io(struct atp_unit
*atp
, u8 channel
, u8 reg
)
98 return inw(atp
->ioport
[channel
] + reg
);
101 static inline u8
atp_readb_pci(struct atp_unit
*atp
, u8 channel
, u8 reg
)
103 return inb(atp
->pciport
[channel
] + reg
);
106 static inline bool is880(struct atp_unit
*atp
)
108 return atp
->pdev
->device
== ATP880_DEVID1
||
109 atp
->pdev
->device
== ATP880_DEVID2
;
112 static inline bool is885(struct atp_unit
*atp
)
114 return atp
->pdev
->device
== ATP885_DEVID
;
117 static irqreturn_t
atp870u_intr_handle(int irq
, void *dev_id
)
120 unsigned short int id
;
121 unsigned char i
, j
, c
, target_id
, lun
,cmdp
;
123 struct scsi_cmnd
*workreq
;
124 unsigned long adrcnt
, k
;
128 struct Scsi_Host
*host
= dev_id
;
129 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
131 for (c
= 0; c
< 2; c
++) {
132 j
= atp_readb_io(dev
, c
, 0x1f);
140 printk("atp870u_intr_handle enter\n");
143 cmdp
= atp_readb_io(dev
, c
, 0x10);
144 if (dev
->working
[c
] != 0) {
146 if ((atp_readb_io(dev
, c
, 0x16) & 0x80) == 0)
147 atp_writeb_io(dev
, c
, 0x16, (atp_readb_io(dev
, c
, 0x16) | 0x80));
149 if ((atp_readb_pci(dev
, c
, 0x00) & 0x08) != 0)
151 for (k
=0; k
< 1000; k
++) {
152 if ((atp_readb_pci(dev
, c
, 2) & 0x08) == 0)
154 if ((atp_readb_pci(dev
, c
, 2) & 0x01) == 0)
158 atp_writeb_pci(dev
, c
, 0, 0x00);
160 i
= atp_readb_io(dev
, c
, 0x17);
163 atp_writeb_pci(dev
, c
, 2, 0x06);
165 target_id
= atp_readb_io(dev
, c
, 0x15);
168 * Remap wide devices onto id numbers
171 if ((target_id
& 0x40) != 0) {
172 target_id
= (target_id
& 0x07) | 0x08;
177 if ((j
& 0x40) != 0) {
178 if (dev
->last_cmd
[c
] == 0xff) {
179 dev
->last_cmd
[c
] = target_id
;
181 dev
->last_cmd
[c
] |= 0x40;
184 dev
->r1f
[c
][target_id
] |= j
;
186 printk("atp870u_intr_handle status = %x\n",i
);
189 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
190 dev
->last_cmd
[c
] = 0xff;
194 ((unsigned char *) &adrcnt
)[2] = atp_readb_io(dev
, c
, 0x12);
195 ((unsigned char *) &adrcnt
)[1] = atp_readb_io(dev
, c
, 0x13);
196 ((unsigned char *) &adrcnt
)[0] = atp_readb_io(dev
, c
, 0x14);
197 if (dev
->id
[c
][target_id
].last_len
!= adrcnt
)
199 k
= dev
->id
[c
][target_id
].last_len
;
201 dev
->id
[c
][target_id
].tran_len
= k
;
202 dev
->id
[c
][target_id
].last_len
= adrcnt
;
205 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
);
212 if (dev
->wide_id
[c
] != 0) {
213 atp_writeb_io(dev
, c
, 0x1b, 0x01);
214 while ((atp_readb_io(dev
, c
, 0x1b) & 0x01) != 0x01)
215 atp_writeb_io(dev
, c
, 0x1b, 0x01);
218 * Issue more commands
220 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
221 if (((dev
->quhd
[c
] != dev
->quend
[c
]) || (dev
->last_cmd
[c
] != 0xff)) &&
222 (dev
->in_snd
[c
] == 0)) {
224 printk("Call sent_s870\n");
228 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
234 printk("Status 0x85 return\n");
240 dev
->last_cmd
[c
] |= 0x40;
246 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
247 dev
->last_cmd
[c
] = 0xff;
250 ((unsigned char *) &adrcnt
)[2] = atp_readb_io(dev
, c
, 0x12);
251 ((unsigned char *) &adrcnt
)[1] = atp_readb_io(dev
, c
, 0x13);
252 ((unsigned char *) &adrcnt
)[0] = atp_readb_io(dev
, c
, 0x14);
253 k
= dev
->id
[c
][target_id
].last_len
;
255 dev
->id
[c
][target_id
].tran_len
= k
;
256 dev
->id
[c
][target_id
].last_len
= adrcnt
;
257 atp_writeb_io(dev
, c
, 0x10, 0x41);
258 atp_writeb_io(dev
, c
, 0x18, 0x08);
264 if ((i
== 0x4c) || (i
== 0x4d) || (i
== 0x8c) || (i
== 0x8d)) {
265 if ((i
== 0x4c) || (i
== 0x8c))
272 if ((i
== 0x80) || (i
== 0x8f)) {
274 printk(KERN_DEBUG
"Device reselect\n");
277 if (cmdp
== 0x44 || i
== 0x80)
278 lun
= atp_readb_io(dev
, c
, 0x1d) & 0x07;
280 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
281 dev
->last_cmd
[c
] = 0xff;
285 printk("cmdp = 0x41\n");
288 ((unsigned char *) &adrcnt
)[2] = atp_readb_io(dev
, c
, 0x12);
289 ((unsigned char *) &adrcnt
)[1] = atp_readb_io(dev
, c
, 0x13);
290 ((unsigned char *) &adrcnt
)[0] = atp_readb_io(dev
, c
, 0x14);
291 k
= dev
->id
[c
][target_id
].last_len
;
293 dev
->id
[c
][target_id
].tran_len
= k
;
294 dev
->id
[c
][target_id
].last_len
= adrcnt
;
295 atp_writeb_io(dev
, c
, 0x18, 0x08);
300 printk("cmdp != 0x41\n");
302 atp_writeb_io(dev
, c
, 0x10, 0x46);
303 dev
->id
[c
][target_id
].dirct
= 0x00;
304 atp_writeb_io(dev
, c
, 0x12, 0x00);
305 atp_writeb_io(dev
, c
, 0x13, 0x00);
306 atp_writeb_io(dev
, c
, 0x14, 0x00);
307 atp_writeb_io(dev
, c
, 0x18, 0x08);
312 if (dev
->last_cmd
[c
] != 0xff) {
313 dev
->last_cmd
[c
] |= 0x40;
316 j
= atp_readb_base(dev
, 0x29) & 0xfe;
317 atp_writeb_base(dev
, 0x29, j
);
319 atp_writeb_io(dev
, c
, 0x10, 0x45);
321 target_id
= atp_readb_io(dev
, c
, 0x16);
323 * Remap wide identifiers
325 if ((target_id
& 0x10) != 0) {
326 target_id
= (target_id
& 0x07) | 0x08;
331 atp_writeb_io(dev
, c
, 0x10, 0x45);
332 workreq
= dev
->id
[c
][target_id
].curr_req
;
334 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
335 for (l
= 0; l
< workreq
->cmd_len
; l
++)
336 printk(KERN_DEBUG
" %x",workreq
->cmnd
[l
]);
340 atp_writeb_io(dev
, c
, 0x0f, lun
);
341 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][target_id
].devsp
);
342 adrcnt
= dev
->id
[c
][target_id
].tran_len
;
343 k
= dev
->id
[c
][target_id
].last_len
;
345 atp_writeb_io(dev
, c
, 0x12, ((unsigned char *) &k
)[2]);
346 atp_writeb_io(dev
, c
, 0x13, ((unsigned char *) &k
)[1]);
347 atp_writeb_io(dev
, c
, 0x14, ((unsigned char *) &k
)[0]);
349 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));
354 j
= (j
& 0x07) | 0x40;
357 j
|= dev
->id
[c
][target_id
].dirct
;
358 atp_writeb_io(dev
, c
, 0x15, j
);
359 atp_writeb_io(dev
, c
, 0x16, 0x80);
361 /* enable 32 bit fifo transfer */
363 i
= atp_readb_pci(dev
, c
, 1) & 0xf3;
364 //j=workreq->cmnd[0];
365 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
368 atp_writeb_pci(dev
, c
, 1, i
);
369 } else if (is880(dev
)) {
370 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a))
371 atp_writeb_base(dev
, 0x3b, (atp_readb_base(dev
, 0x3b) & 0x3f) | 0xc0);
373 atp_writeb_base(dev
, 0x3b, atp_readb_base(dev
, 0x3b) & 0x3f);
375 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a))
376 atp_writeb_base(dev
, 0x3a, (atp_readb_base(dev
, 0x3a) & 0xf3) | 0x08);
378 atp_writeb_base(dev
, 0x3a, atp_readb_base(dev
, 0x3a) & 0xf3);
382 id
= id
<< target_id
;
384 * Is this a wide device
386 if ((id
& dev
->wide_id
[c
]) != 0) {
389 atp_writeb_io(dev
, c
, 0x1b, j
);
390 while ((atp_readb_io(dev
, c
, 0x1b) & 0x01) != j
)
391 atp_writeb_io(dev
, c
, 0x1b, j
);
392 if (dev
->id
[c
][target_id
].last_len
== 0) {
393 atp_writeb_io(dev
, c
, 0x18, 0x08);
396 printk("dev->id[c][target_id].last_len = 0\n");
401 printk("target_id = %d adrcnt = %d\n",target_id
,adrcnt
);
403 prd
= dev
->id
[c
][target_id
].prd_pos
;
404 while (adrcnt
!= 0) {
405 id
= ((unsigned short int *)prd
)[2];
412 ((unsigned short int *)prd
)[2] = (unsigned short int)
414 ((unsigned long *)prd
)[0] += adrcnt
;
416 dev
->id
[c
][target_id
].prd_pos
= prd
;
419 dev
->id
[c
][target_id
].prdaddr
+= 0x08;
422 dev
->id
[c
][target_id
].prd_pos
= prd
;
426 atp_writel_pci(dev
, c
, 0x04, dev
->id
[c
][target_id
].prdaddr
);
428 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c
, target_id
, dev
->id
[c
][target_id
].prdaddr
);
431 atp_writeb_pci(dev
, c
, 2, 0x06);
432 atp_writeb_pci(dev
, c
, 2, 0x00);
435 * Check transfer direction
437 if (dev
->id
[c
][target_id
].dirct
!= 0) {
438 atp_writeb_io(dev
, c
, 0x18, 0x08);
439 atp_writeb_pci(dev
, c
, 0, 0x01);
442 printk("status 0x80 return dirct != 0\n");
446 atp_writeb_io(dev
, c
, 0x18, 0x08);
447 atp_writeb_pci(dev
, c
, 0, 0x09);
450 printk("status 0x80 return dirct = 0\n");
456 * Current scsi request on this target
459 workreq
= dev
->id
[c
][target_id
].curr_req
;
461 if (i
== 0x42 || i
== 0x16) {
462 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
463 dev
->last_cmd
[c
] = 0xff;
466 workreq
->result
= atp_readb_io(dev
, c
, 0x0f);
467 if (((dev
->r1f
[c
][target_id
] & 0x10) != 0) && is885(dev
)) {
468 printk(KERN_WARNING
"AEC67162 CRC ERROR !\n");
469 workreq
->result
= 0x02;
472 workreq
->result
= 0x02;
475 j
= atp_readb_base(dev
, 0x29) | 0x01;
476 atp_writeb_base(dev
, 0x29, j
);
479 * Complete the command
481 scsi_dma_unmap(workreq
);
483 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
484 (*workreq
->scsi_done
) (workreq
);
486 printk("workreq->scsi_done\n");
489 * Clear it off the queue
491 dev
->id
[c
][target_id
].curr_req
= NULL
;
493 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
497 if (dev
->wide_id
[c
] != 0) {
498 atp_writeb_io(dev
, c
, 0x1b, 0x01);
499 while ((atp_readb_io(dev
, c
, 0x1b) & 0x01) != 0x01)
500 atp_writeb_io(dev
, c
, 0x1b, 0x01);
503 * If there is stuff to send and nothing going then send it
505 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
506 if (((dev
->last_cmd
[c
] != 0xff) || (dev
->quhd
[c
] != dev
->quend
[c
])) &&
507 (dev
->in_snd
[c
] == 0)) {
509 printk("Call sent_s870(scsi_done)\n");
513 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
517 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
518 dev
->last_cmd
[c
] = 0xff;
525 atp_writel_pci(dev
, c
, 4, dev
->id
[c
][target_id
].prdaddr
);
526 atp_writeb_pci(dev
, c
, 2, 0x06);
527 atp_writeb_pci(dev
, c
, 2, 0x00);
528 atp_writeb_io(dev
, c
, 0x10, 0x41);
530 k
= dev
->id
[c
][target_id
].last_len
;
531 atp_writeb_io(dev
, c
, 0x12, ((unsigned char *) (&k
))[2]);
532 atp_writeb_io(dev
, c
, 0x13, ((unsigned char *) (&k
))[1]);
533 atp_writeb_io(dev
, c
, 0x14, ((unsigned char *) (&k
))[0]);
534 dev
->id
[c
][target_id
].dirct
= 0x00;
536 dev
->id
[c
][target_id
].dirct
= 0x00;
538 atp_writeb_io(dev
, c
, 0x18, 0x08);
539 atp_writeb_pci(dev
, c
, 0, 0x09);
544 atp_writel_pci(dev
, c
, 4, dev
->id
[c
][target_id
].prdaddr
);
545 atp_writeb_pci(dev
, c
, 2, 0x06);
546 atp_writeb_pci(dev
, c
, 2, 0x00);
547 atp_writeb_io(dev
, c
, 0x10, 0x41);
549 k
= dev
->id
[c
][target_id
].last_len
;
550 atp_writeb_io(dev
, c
, 0x12, ((unsigned char *) (&k
))[2]);
551 atp_writeb_io(dev
, c
, 0x13, ((unsigned char *) (&k
))[1]);
552 atp_writeb_io(dev
, c
, 0x14, ((unsigned char *) (&k
))[0]);
554 atp_writeb_io(dev
, c
, 0x15, atp_readb_io(dev
, c
, 0x15) | 0x20);
555 dev
->id
[c
][target_id
].dirct
= 0x20;
556 atp_writeb_io(dev
, c
, 0x18, 0x08);
557 atp_writeb_pci(dev
, c
, 0, 0x01);
562 atp_writeb_io(dev
, c
, 0x10, 0x30);
564 atp_writeb_io(dev
, c
, 0x10, 0x46);
565 dev
->id
[c
][target_id
].dirct
= 0x00;
566 atp_writeb_io(dev
, c
, 0x12, 0x00);
567 atp_writeb_io(dev
, c
, 0x13, 0x00);
568 atp_writeb_io(dev
, c
, 0x14, 0x00);
569 atp_writeb_io(dev
, c
, 0x18, 0x08);
576 * atp870u_queuecommand - Queue SCSI command
577 * @req_p: request block
578 * @done: completion function
580 * Queue a command to the ATP queue. Called with the host lock held.
582 static int atp870u_queuecommand_lck(struct scsi_cmnd
*req_p
,
583 void (*done
) (struct scsi_cmnd
*))
587 struct atp_unit
*dev
;
588 struct Scsi_Host
*host
;
590 c
= scmd_channel(req_p
);
591 req_p
->sense_buffer
[0]=0;
592 scsi_set_resid(req_p
, 0);
593 if (scmd_channel(req_p
) > 1) {
594 req_p
->result
= 0x00040000;
597 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
602 host
= req_p
->device
->host
;
603 dev
= (struct atp_unit
*)&host
->hostdata
;
608 m
= m
<< scmd_id(req_p
);
611 * Fake a timeout for missing targets
614 if ((m
& dev
->active_id
[c
]) == 0) {
615 req_p
->result
= 0x00040000;
621 req_p
->scsi_done
= done
;
624 printk( "atp870u_queuecommand: done can't be NULL\n");
635 if (dev
->quend
[c
] >= qcnt
) {
642 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
643 if (dev
->quend
[c
] == 0) {
644 dev
->quend
[c
] = qcnt
;
647 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
650 req_p
->result
= 0x00020000;
654 dev
->quereq
[c
][dev
->quend
[c
]] = req_p
;
656 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
]);
658 if ((atp_readb_io(dev
, c
, 0x1c) == 0) && (dev
->in_int
[c
] == 0) && (dev
->in_snd
[c
] == 0)) {
660 printk("Call sent_s870(atp870u_queuecommand)\n");
665 printk("atp870u_queuecommand : exit\n");
670 static DEF_SCSI_QCMD(atp870u_queuecommand
)
673 * send_s870 - send a command to the controller
676 * On entry there is work queued to be done. We move some of that work to the
679 * Caller holds the host lock.
681 static void send_s870(struct atp_unit
*dev
,unsigned char c
)
683 struct scsi_cmnd
*workreq
= NULL
;
685 unsigned char j
, target_id
;
687 unsigned short int w
;
688 unsigned long l
, bttl
= 0;
689 unsigned long sg_count
;
691 if (dev
->in_snd
[c
] != 0) {
693 printk("cmnd in_snd\n");
698 printk("Sent_s870 enter\n");
701 if ((dev
->last_cmd
[c
] != 0xff) && ((dev
->last_cmd
[c
] & 0x40) != 0)) {
702 dev
->last_cmd
[c
] &= 0x0f;
703 workreq
= dev
->id
[c
][dev
->last_cmd
[c
]].curr_req
;
705 dev
->last_cmd
[c
] = 0xff;
706 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
713 if ((dev
->last_cmd
[c
] != 0xff) && (dev
->working
[c
] != 0)) {
720 if (dev
->quhd
[c
] >= qcnt
)
722 workreq
= dev
->quereq
[c
][dev
->quhd
[c
]];
723 if (dev
->id
[c
][scmd_id(workreq
)].curr_req
!= NULL
) {
729 dev
->id
[c
][scmd_id(workreq
)].curr_req
= workreq
;
730 dev
->last_cmd
[c
] = scmd_id(workreq
);
732 if ((atp_readb_io(dev
, c
, 0x1f) & 0xb0) != 0 || atp_readb_io(dev
, c
, 0x1c) != 0) {
734 printk("Abort to Send\n");
736 dev
->last_cmd
[c
] |= 0x40;
741 printk("OK to Send\n");
742 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
743 for(i
=0;i
<workreq
->cmd_len
;i
++) {
744 printk(" %x",workreq
->cmnd
[i
]);
748 l
= scsi_bufflen(workreq
);
751 j
= atp_readb_base(dev
, 0x29) & 0xfe;
752 atp_writeb_base(dev
, 0x29, j
);
753 dev
->r1f
[c
][scmd_id(workreq
)] = 0;
756 if (workreq
->cmnd
[0] == READ_CAPACITY
) {
760 if (workreq
->cmnd
[0] == 0x00) {
765 target_id
= scmd_id(workreq
);
772 if ((w
& dev
->wide_id
[c
]) != 0) {
775 atp_writeb_io(dev
, c
, 0x1b, j
);
776 while ((atp_readb_io(dev
, c
, 0x1b) & 0x01) != j
) {
777 atp_writeb_pci(dev
, c
, 0x1b, j
);
779 printk("send_s870 while loop 1\n");
786 atp_writeb_io(dev
, c
, 0x00, workreq
->cmd_len
);
787 atp_writeb_io(dev
, c
, 0x01, 0x2c);
789 atp_writeb_io(dev
, c
, 0x02, 0x7f);
791 atp_writeb_io(dev
, c
, 0x02, 0xcf);
792 for (i
= 0; i
< workreq
->cmd_len
; i
++)
793 atp_writeb_io(dev
, c
, 0x03 + i
, workreq
->cmnd
[i
]);
794 atp_writeb_io(dev
, c
, 0x0f, workreq
->device
->lun
);
798 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][target_id
].devsp
);
800 printk("dev->id[%d][%d].devsp = %2x\n",c
,target_id
,dev
->id
[c
][target_id
].devsp
);
803 sg_count
= scsi_dma_map(workreq
);
805 * Write transfer size
807 atp_writeb_io(dev
, c
, 0x12, ((unsigned char *) (&l
))[2]);
808 atp_writeb_io(dev
, c
, 0x13, ((unsigned char *) (&l
))[1]);
809 atp_writeb_io(dev
, c
, 0x14, ((unsigned char *) (&l
))[0]);
811 dev
->id
[c
][j
].last_len
= l
;
812 dev
->id
[c
][j
].tran_len
= 0;
814 printk("dev->id[%2d][%2d].last_len = %d\n",c
,j
,dev
->id
[c
][j
].last_len
);
819 if ((j
& 0x08) != 0) {
820 j
= (j
& 0x07) | 0x40;
823 * Check transfer direction
825 if (workreq
->sc_data_direction
== DMA_TO_DEVICE
)
826 atp_writeb_io(dev
, c
, 0x15, j
| 0x20);
828 atp_writeb_io(dev
, c
, 0x15, j
);
829 atp_writeb_io(dev
, c
, 0x16, atp_readb_io(dev
, c
, 0x16) | 0x80);
830 atp_writeb_io(dev
, c
, 0x16, 0x80);
831 dev
->id
[c
][target_id
].dirct
= 0;
833 if (atp_readb_io(dev
, c
, 0x1c) == 0) {
835 printk("change SCSI_CMD_REG 0x08\n");
837 atp_writeb_io(dev
, c
, 0x18, 0x08);
839 dev
->last_cmd
[c
] |= 0x40;
843 prd
= dev
->id
[c
][target_id
].prd_table
;
844 dev
->id
[c
][target_id
].prd_pos
= prd
;
847 * Now write the request list. Either as scatter/gather or as
852 struct scatterlist
*sgpnt
;
854 scsi_for_each_sg(workreq
, sgpnt
, sg_count
, j
) {
855 bttl
= sg_dma_address(sgpnt
);
858 printk("1. bttl %x, l %x\n",bttl
, l
);
860 while (l
> 0x10000) {
861 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
862 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
863 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
868 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
869 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
870 (((u16
*) (prd
))[i
+ 3]) = 0;
873 (((u16
*) (prd
))[i
- 1]) = cpu_to_le16(0x8000);
875 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]));
876 printk("2. bttl %x, l %x\n",bttl
, l
);
880 printk("send_s870: prdaddr_2 0x%8x target_id %d\n", dev
->id
[c
][target_id
].prdaddr
,target_id
);
882 dev
->id
[c
][target_id
].prdaddr
= dev
->id
[c
][target_id
].prd_bus
;
883 atp_writel_pci(dev
, c
, 4, dev
->id
[c
][target_id
].prdaddr
);
884 atp_writeb_pci(dev
, c
, 2, 0x06);
885 atp_writeb_pci(dev
, c
, 2, 0x00);
887 j
= atp_readb_pci(dev
, c
, 1) & 0xf3;
888 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) ||
889 (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
892 atp_writeb_pci(dev
, c
, 1, j
);
893 } else if (is880(dev
)) {
894 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a))
895 atp_writeb_base(dev
, 0x3b, (atp_readb_base(dev
, 0x3b) & 0x3f) | 0xc0);
897 atp_writeb_base(dev
, 0x3b, atp_readb_base(dev
, 0x3b) & 0x3f);
899 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a))
900 atp_writeb_base(dev
, 0x3a, (atp_readb_base(dev
, 0x3a) & 0xf3) | 0x08);
902 atp_writeb_base(dev
, 0x3a, atp_readb_base(dev
, 0x3a) & 0xf3);
905 if(workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
906 dev
->id
[c
][target_id
].dirct
= 0x20;
907 if (atp_readb_io(dev
, c
, 0x1c) == 0) {
908 atp_writeb_io(dev
, c
, 0x18, 0x08);
909 atp_writeb_pci(dev
, c
, 0, 0x01);
911 printk( "start DMA(to target)\n");
914 dev
->last_cmd
[c
] |= 0x40;
919 if (atp_readb_io(dev
, c
, 0x1c) == 0) {
920 atp_writeb_io(dev
, c
, 0x18, 0x08);
921 atp_writeb_pci(dev
, c
, 0, 0x09);
923 printk( "start DMA(to host)\n");
926 dev
->last_cmd
[c
] |= 0x40;
933 static unsigned char fun_scam(struct atp_unit
*dev
, unsigned short int *val
)
935 unsigned short int i
, k
;
938 atp_writew_io(dev
, 0, 0x1c, *val
);
939 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
940 k
= atp_readw_io(dev
, 0, 0x1c);
941 j
= (unsigned char) (k
>> 8);
942 if ((k
& 0x8000) != 0) /* DB7 all release? */
945 *val
|= 0x4000; /* assert DB6 */
946 atp_writew_io(dev
, 0, 0x1c, *val
);
947 *val
&= 0xdfff; /* assert DB5 */
948 atp_writew_io(dev
, 0, 0x1c, *val
);
949 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
950 if ((atp_readw_io(dev
, 0, 0x1c) & 0x2000) != 0) /* DB5 all release? */
953 *val
|= 0x8000; /* no DB4-0, assert DB7 */
955 atp_writew_io(dev
, 0, 0x1c, *val
);
956 *val
&= 0xbfff; /* release DB6 */
957 atp_writew_io(dev
, 0, 0x1c, *val
);
958 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
959 if ((atp_readw_io(dev
, 0, 0x1c) & 0x4000) != 0) /* DB6 all release? */
966 static void tscam(struct Scsi_Host
*host
, bool wide_chip
, u8 scam_on
)
969 unsigned char i
, j
, k
;
971 unsigned short int m
, assignid_map
, val
;
972 unsigned char mbuf
[33], quintet
[2];
973 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
974 static unsigned char g2q_tab
[8] = {
975 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
978 /* I can't believe we need this before we've even done anything. Remove it
979 * and see if anyone bitches.
980 for (i = 0; i < 0x10; i++) {
985 atp_writeb_io(dev
, 0, 1, 0x08);
986 atp_writeb_io(dev
, 0, 2, 0x7f);
987 atp_writeb_io(dev
, 0, 0x11, 0x20);
989 if ((scam_on
& 0x40) == 0) {
993 m
<<= dev
->host_id
[0];
1000 atp_writeb_io(dev
, 0, 0x02, 0x02); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1001 atp_writeb_io(dev
, 0, 0x03, 0);
1002 atp_writeb_io(dev
, 0, 0x04, 0);
1003 atp_writeb_io(dev
, 0, 0x05, 0);
1004 atp_writeb_io(dev
, 0, 0x06, 0);
1005 atp_writeb_io(dev
, 0, 0x07, 0);
1006 atp_writeb_io(dev
, 0, 0x08, 0);
1008 for (i
= 0; i
< j
; i
++) {
1011 if ((m
& assignid_map
) != 0) {
1014 atp_writeb_io(dev
, 0, 0x0f, 0);
1015 atp_writeb_io(dev
, 0, 0x12, 0);
1016 atp_writeb_io(dev
, 0, 0x13, 0);
1017 atp_writeb_io(dev
, 0, 0x14, 0);
1019 k
= (i
& 0x07) | 0x40;
1023 atp_writeb_io(dev
, 0, 0x15, k
);
1025 atp_writeb_io(dev
, 0, 0x1b, 0x01);
1027 atp_writeb_io(dev
, 0, 0x1b, 0x00);
1029 atp_writeb_io(dev
, 0, 0x18, 0x09);
1031 while ((atp_readb_io(dev
, 0, 0x1f) & 0x80) == 0x00)
1033 k
= atp_readb_io(dev
, 0, 0x17);
1034 if ((k
== 0x85) || (k
== 0x42))
1037 atp_writeb_io(dev
, 0, 0x10, 0x41);
1038 } while (k
!= 0x16);
1039 if ((k
== 0x85) || (k
== 0x42))
1044 atp_writeb_io(dev
, 0, 0x02, 0x7f);
1045 atp_writeb_io(dev
, 0, 0x1b, 0x02);
1049 val
= 0x0080; /* bsy */
1050 atp_writew_io(dev
, 0, 0x1c, val
);
1051 val
|= 0x0040; /* sel */
1052 atp_writew_io(dev
, 0, 0x1c, val
);
1053 val
|= 0x0004; /* msg */
1054 atp_writew_io(dev
, 0, 0x1c, val
);
1055 udelay(2); /* 2 deskew delay(45ns*2=90ns) */
1056 val
&= 0x007f; /* no bsy */
1057 atp_writew_io(dev
, 0, 0x1c, val
);
1059 val
&= 0x00fb; /* after 1ms no msg */
1060 atp_writew_io(dev
, 0, 0x1c, val
);
1061 while ((atp_readb_io(dev
, 0, 0x1c) & 0x04) != 0)
1065 for (n
= 0; n
< 0x30000; n
++)
1066 if ((atp_readb_io(dev
, 0, 0x1c) & 0x80) != 0) /* bsy ? */
1069 for (n
= 0; n
< 0x30000; n
++)
1070 if ((atp_readb_io(dev
, 0, 0x1c) & 0x81) == 0x0081) {
1072 val
|= 0x8003; /* io,cd,db7 */
1073 atp_writew_io(dev
, 0, 0x1c, val
);
1075 val
&= 0x00bf; /* no sel */
1076 atp_writew_io(dev
, 0, 0x1c, val
);
1082 * The funny division into multiple delays is to accomodate
1083 * arches like ARM where udelay() multiplies its argument by
1084 * a large number to initialize a loop counter. To avoid
1085 * overflow, the maximum supported udelay is 2000 microseconds.
1087 * XXX it would be more polite to find a way to use msleep()
1091 if ((atp_readb_io(dev
, 0, 0x1c) & 0x80) == 0x00) { /* bsy ? */
1092 atp_writew_io(dev
, 0, 0x1c, 0);
1093 atp_writeb_io(dev
, 0, 0x1b, 0);
1094 atp_writeb_io(dev
, 0, 0x15, 0);
1095 atp_writeb_io(dev
, 0, 0x18, 0x09);
1096 while ((atp_readb_io(dev
, 0, 0x1f) & 0x80) == 0)
1098 atp_readb_io(dev
, 0, 0x17);
1101 val
&= 0x00ff; /* synchronization */
1103 fun_scam(dev
, &val
);
1105 val
&= 0x00ff; /* isolation */
1107 fun_scam(dev
, &val
);
1113 if ((atp_readw_io(dev
, 0, 0x1c) & 0x2000) == 0)
1116 val
&= 0x00ff; /* get ID_STRING */
1118 k
= fun_scam(dev
, &val
);
1119 if ((k
& 0x03) == 0)
1123 if ((k
& 0x02) != 0)
1132 /* isolation complete.. */
1134 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1137 if ((j
& 0x20) != 0) { /* bit5=1:ID up to 7 */
1140 if ((j
& 0x06) != 0) { /* IDvalid? */
1145 if ((m
& assignid_map
) == 0)
1153 if ((m
& assignid_map
) != 0) { /* srch from max acceptable ID# */
1154 k
= i
; /* max acceptable ID# */
1158 if ((m
& assignid_map
) == 0)
1169 quintet
[0] = 0x38; /* 1st dft ID<8 */
1171 quintet
[0] = 0x31; /* 1st ID>=8 */
1174 quintet
[1] = g2q_tab
[k
];
1176 val
&= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1177 m
= quintet
[0] << 8;
1179 fun_scam(dev
, &val
);
1180 val
&= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1181 m
= quintet
[1] << 8;
1183 fun_scam(dev
, &val
);
1188 static void atp870u_free_tables(struct Scsi_Host
*host
)
1190 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
1192 for (j
=0; j
< 2; j
++) {
1193 for (k
= 0; k
< 16; k
++) {
1194 if (!atp_dev
->id
[j
][k
].prd_table
)
1196 pci_free_consistent(atp_dev
->pdev
, 1024, atp_dev
->id
[j
][k
].prd_table
, atp_dev
->id
[j
][k
].prd_bus
);
1197 atp_dev
->id
[j
][k
].prd_table
= NULL
;
1202 static int atp870u_init_tables(struct Scsi_Host
*host
)
1204 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
1206 for(c
=0;c
< 2;c
++) {
1208 atp_dev
->id
[c
][k
].prd_table
= pci_alloc_consistent(atp_dev
->pdev
, 1024, &(atp_dev
->id
[c
][k
].prd_bus
));
1209 if (!atp_dev
->id
[c
][k
].prd_table
) {
1210 printk("atp870u_init_tables fail\n");
1211 atp870u_free_tables(host
);
1214 atp_dev
->id
[c
][k
].prdaddr
= atp_dev
->id
[c
][k
].prd_bus
;
1215 atp_dev
->id
[c
][k
].devsp
=0x20;
1216 atp_dev
->id
[c
][k
].devtype
= 0x7f;
1217 atp_dev
->id
[c
][k
].curr_req
= NULL
;
1220 atp_dev
->active_id
[c
] = 0;
1221 atp_dev
->wide_id
[c
] = 0;
1222 atp_dev
->host_id
[c
] = 0x07;
1223 atp_dev
->quhd
[c
] = 0;
1224 atp_dev
->quend
[c
] = 0;
1225 atp_dev
->last_cmd
[c
] = 0xff;
1226 atp_dev
->in_snd
[c
] = 0;
1227 atp_dev
->in_int
[c
] = 0;
1229 for (k
= 0; k
< qcnt
; k
++) {
1230 atp_dev
->quereq
[c
][k
] = NULL
;
1232 for (k
= 0; k
< 16; k
++) {
1233 atp_dev
->id
[c
][k
].curr_req
= NULL
;
1234 atp_dev
->sp
[c
][k
] = 0x04;
1240 static void atp_set_host_id(struct atp_unit
*atp
, u8 c
, u8 host_id
)
1242 atp_writeb_io(atp
, c
, 0, host_id
| 0x08);
1243 atp_writeb_io(atp
, c
, 0x18, 0);
1244 while ((atp_readb_io(atp
, c
, 0x1f) & 0x80) == 0)
1246 atp_readb_io(atp
, c
, 0x17);
1247 atp_writeb_io(atp
, c
, 1, 8);
1248 atp_writeb_io(atp
, c
, 2, 0x7f);
1249 atp_writeb_io(atp
, c
, 0x11, 0x20);
1252 /* return non-zero on detection */
1253 static int atp870u_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1255 unsigned char k
, m
, c
;
1256 unsigned int error
,n
;
1257 unsigned char host_id
;
1258 struct Scsi_Host
*shpnt
= NULL
;
1259 struct atp_unit
*atpdev
;
1260 unsigned char setupdata
[2][16];
1263 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
&& pdev
->revision
< 2) {
1264 dev_err(&pdev
->dev
, "ATP850S chips (AEC6710L/F cards) are not supported.\n");
1268 err
= pci_enable_device(pdev
);
1272 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1273 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
1275 goto disable_device
;
1278 err
= pci_request_regions(pdev
, "atp870u");
1280 goto disable_device
;
1281 pci_set_master(pdev
);
1284 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
1286 goto release_region
;
1288 atpdev
= shost_priv(shpnt
);
1290 atpdev
->host
= shpnt
;
1291 atpdev
->pdev
= pdev
;
1292 pci_set_drvdata(pdev
, atpdev
);
1294 shpnt
->io_port
= pci_resource_start(pdev
, 0);
1295 shpnt
->io_port
&= 0xfffffff8;
1296 shpnt
->n_io_port
= pci_resource_len(pdev
, 0);
1297 atpdev
->baseport
= shpnt
->io_port
;
1298 shpnt
->unique_id
= shpnt
->io_port
;
1299 shpnt
->irq
= pdev
->irq
;
1301 if (is880(atpdev
)) {
1302 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
1304 atpdev
->ioport
[0] = shpnt
->io_port
+ 0x40;
1305 atpdev
->pciport
[0] = shpnt
->io_port
+ 0x28;
1307 host_id
= atp_readb_base(atpdev
, 0x39);
1310 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter:"
1311 " IO:%lx, IRQ:%d.\n", shpnt
->io_port
, shpnt
->irq
);
1312 atpdev
->host_id
[0] = host_id
;
1314 atpdev
->global_map
[0] = atp_readb_base(atpdev
, 0x35);
1315 atpdev
->ultra_map
[0] = atp_readw_base(atpdev
, 0x3c);
1323 atp_writew_base(atpdev
, 0x34, n
);
1325 if (atp_readb_base(atpdev
, 0x30) == 0xff)
1328 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x30);
1329 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x31);
1330 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x32);
1331 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x33);
1332 atp_writew_base(atpdev
, 0x34, n
);
1334 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x30);
1335 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x31);
1336 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x32);
1337 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x33);
1338 atp_writew_base(atpdev
, 0x34, n
);
1340 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x30);
1341 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x31);
1342 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x32);
1343 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x33);
1344 atp_writew_base(atpdev
, 0x34, n
);
1346 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x30);
1347 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x31);
1348 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x32);
1349 atpdev
->sp
[0][m
++] = atp_readb_base(atpdev
, 0x33);
1353 atp_writew_base(atpdev
, 0x34, 0);
1354 atpdev
->ultra_map
[0] = 0;
1355 atpdev
->async
[0] = 0;
1356 for (k
= 0; k
< 16; k
++) {
1359 if (atpdev
->sp
[0][k
] > 1) {
1360 atpdev
->ultra_map
[0] |= n
;
1362 if (atpdev
->sp
[0][k
] == 0)
1363 atpdev
->async
[0] |= n
;
1366 atpdev
->async
[0] = ~(atpdev
->async
[0]);
1367 atp_writeb_base(atpdev
, 0x35, atpdev
->global_map
[0]);
1369 if (atp870u_init_tables(shpnt
) < 0) {
1370 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
1375 k
= atp_readb_base(atpdev
, 0x38) & 0x80;
1376 atp_writeb_base(atpdev
, 0x38, k
);
1377 atp_writeb_base(atpdev
, 0x3b, 0x20);
1379 atp_writeb_base(atpdev
, 0x3b, 0);
1381 atp_readb_io(atpdev
, 0, 0x1b);
1382 atp_readb_io(atpdev
, 0, 0x17);
1384 atp_set_host_id(atpdev
, 0, host_id
);
1386 tscam(shpnt
, true, atp_readb_base(atpdev
, 0x22));
1387 atp_is(atpdev
, 0, true, atp_readb_base(atpdev
, 0x3f) & 0x40);
1388 atp_writeb_base(atpdev
, 0x38, 0xb0);
1390 shpnt
->this_id
= host_id
;
1391 } else if (is885(atpdev
)) {
1392 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%lx, IRQ:%d.\n"
1393 , shpnt
->io_port
, shpnt
->irq
);
1395 atpdev
->pdev
= pdev
;
1396 atpdev
->ioport
[0] = shpnt
->io_port
+ 0x80;
1397 atpdev
->ioport
[1] = shpnt
->io_port
+ 0xc0;
1398 atpdev
->pciport
[0] = shpnt
->io_port
+ 0x40;
1399 atpdev
->pciport
[1] = shpnt
->io_port
+ 0x50;
1401 if (atp870u_init_tables(shpnt
) < 0) {
1406 c
= atp_readb_base(atpdev
, 0x29);
1407 atp_writeb_base(atpdev
, 0x29, c
| 0x04);
1414 atp_writew_base(atpdev
, 0x3c, n
);
1415 if (atp_readl_base(atpdev
, 0x38) == 0xffffffff) {
1418 for (m
=0; m
< 2; m
++) {
1419 atpdev
->global_map
[m
]= 0;
1420 for (k
=0; k
< 4; k
++) {
1421 atp_writew_base(atpdev
, 0x3c, n
++);
1422 ((unsigned long *)&setupdata
[m
][0])[k
] = atp_readl_base(atpdev
, 0x38);
1424 for (k
=0; k
< 4; k
++) {
1425 atp_writew_base(atpdev
, 0x3c, n
++);
1426 ((unsigned long *)&atpdev
->sp
[m
][0])[k
] = atp_readl_base(atpdev
, 0x38);
1433 printk( "Flash Read OK\n");
1435 c
= atp_readb_base(atpdev
, 0x29);
1436 atp_writeb_base(atpdev
, 0x29, c
& 0xfb);
1437 for (c
=0;c
< 2;c
++) {
1438 atpdev
->ultra_map
[c
]=0;
1439 atpdev
->async
[c
] = 0;
1440 for (k
=0; k
< 16; k
++) {
1443 if (atpdev
->sp
[c
][k
] > 1) {
1444 atpdev
->ultra_map
[c
] |= n
;
1446 if (atpdev
->sp
[c
][k
] == 0) {
1447 atpdev
->async
[c
] |= n
;
1451 atpdev
->async
[c
] = ~(atpdev
->async
[c
]);
1453 if (atpdev
->global_map
[c
] == 0) {
1455 if ((k
& 0x40) != 0)
1456 atpdev
->global_map
[c
] |= 0x20;
1458 atpdev
->global_map
[c
] |= k
;
1459 if ((setupdata
[c
][2] & 0x04) != 0)
1460 atpdev
->global_map
[c
] |= 0x08;
1461 atpdev
->host_id
[c
] = setupdata
[c
][0] & 0x07;
1465 k
= atp_readb_base(atpdev
, 0x28) & 0x8f;
1467 atp_writeb_base(atpdev
, 0x28, k
);
1468 atp_writeb_pci(atpdev
, 0, 1, 0x80);
1469 atp_writeb_pci(atpdev
, 1, 1, 0x80);
1471 atp_writeb_pci(atpdev
, 0, 1, 0);
1472 atp_writeb_pci(atpdev
, 1, 1, 0);
1474 atp_readb_io(atpdev
, 0, 0x1b);
1475 atp_readb_io(atpdev
, 0, 0x17);
1476 atp_readb_io(atpdev
, 1, 0x1b);
1477 atp_readb_io(atpdev
, 1, 0x17);
1479 k
=atpdev
->host_id
[0];
1481 k
= (k
& 0x07) | 0x40;
1482 atp_set_host_id(atpdev
, 0, k
);
1484 k
=atpdev
->host_id
[1];
1486 k
= (k
& 0x07) | 0x40;
1487 atp_set_host_id(atpdev
, 1, k
);
1489 mdelay(600); /* this delay used to be called tscam_885() */
1490 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
1491 atp_is(atpdev
, 0, true, atp_readb_io(atpdev
, 0, 0x1b) >> 7);
1492 atp_writeb_io(atpdev
, 0, 0x16, 0x80);
1493 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
1494 atp_is(atpdev
, 1, true, atp_readb_io(atpdev
, 1, 0x1b) >> 7);
1495 atp_writeb_io(atpdev
, 1, 0x16, 0x80);
1496 k
= atp_readb_base(atpdev
, 0x28) & 0xcf;
1498 atp_writeb_base(atpdev
, 0x28, k
);
1499 k
= atp_readb_base(atpdev
, 0x1f) | 0x80;
1500 atp_writeb_base(atpdev
, 0x1f, k
);
1501 k
= atp_readb_base(atpdev
, 0x29) | 0x01;
1502 atp_writeb_base(atpdev
, 0x29, k
);
1504 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
1507 shpnt
->max_lun
= (atpdev
->global_map
[0] & 0x07) + 1;
1508 shpnt
->max_channel
= 1;
1509 shpnt
->this_id
= atpdev
->host_id
[0];
1513 (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
&&
1514 pdev
->revision
== 4) ||
1515 (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7612UW
) ||
1516 (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7612SUW
);
1517 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
1519 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: "
1520 "IO:%lx, IRQ:%d.\n", shpnt
->io_port
, shpnt
->irq
);
1522 atpdev
->ioport
[0] = shpnt
->io_port
;
1523 atpdev
->pciport
[0] = shpnt
->io_port
+ 0x20;
1525 atpdev
->host_id
[0] = host_id
;
1526 scam_on
= atp_readb_pci(atpdev
, 0, 2);
1527 atpdev
->global_map
[0] = atp_readb_base(atpdev
, 0x2d);
1528 atpdev
->ultra_map
[0] = atp_readw_base(atpdev
, 0x2e);
1530 if (atpdev
->ultra_map
[0] == 0) {
1532 atpdev
->global_map
[0] = 0x20;
1533 atpdev
->ultra_map
[0] = 0xffff;
1537 if (atp870u_init_tables(shpnt
) < 0) {
1542 if (pdev
->revision
> 0x07) /* check if atp876 chip then enable terminator */
1543 atp_writeb_base(atpdev
, 0x3e, 0x00);
1545 k
= (atp_readb_base(atpdev
, 0x3a) & 0xf3) | 0x10;
1546 atp_writeb_base(atpdev
, 0x3a, k
);
1547 atp_writeb_base(atpdev
, 0x3a, k
& 0xdf);
1549 atp_writeb_base(atpdev
, 0x3a, k
);
1551 atp_set_host_id(atpdev
, 0, host_id
);
1554 tscam(shpnt
, wide_chip
, scam_on
);
1555 atp_writeb_base(atpdev
, 0x3a, atp_readb_base(atpdev
, 0x3a) | 0x10);
1556 atp_is(atpdev
, 0, wide_chip
, 0);
1557 atp_writeb_base(atpdev
, 0x3a, atp_readb_base(atpdev
, 0x3a) & 0xef);
1558 atp_writeb_base(atpdev
, 0x3b, atp_readb_base(atpdev
, 0x3b) | 0x20);
1559 shpnt
->max_id
= wide_chip
? 16 : 8;
1560 shpnt
->this_id
= host_id
;
1563 err
= request_irq(shpnt
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870u", shpnt
);
1565 dev_err(&pdev
->dev
, "Unable to allocate IRQ %d.\n", shpnt
->irq
);
1569 err
= scsi_add_host(shpnt
, &pdev
->dev
);
1572 scsi_scan_host(shpnt
);
1577 free_irq(shpnt
->irq
, shpnt
);
1579 atp870u_free_tables(shpnt
);
1581 scsi_host_put(shpnt
);
1583 pci_release_regions(pdev
);
1585 pci_disable_device(pdev
);
1590 /* The abort command does not leave the device in a clean state where
1591 it is available to be used again. Until this gets worked out, we will
1592 leave it commented out. */
1594 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
1596 unsigned char j
, k
, c
;
1597 struct scsi_cmnd
*workrequ
;
1598 struct atp_unit
*dev
;
1599 struct Scsi_Host
*host
;
1600 host
= SCpnt
->device
->host
;
1602 dev
= (struct atp_unit
*)&host
->hostdata
;
1603 c
= scmd_channel(SCpnt
);
1604 printk(" atp870u: abort Channel = %x \n", c
);
1605 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
1606 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
1607 for (j
= 0; j
< 0x18; j
++) {
1608 printk(" r%2x=%2x", j
, atp_readb_io(dev
, c
, j
));
1610 printk(" r1c=%2x", atp_readb_io(dev
, c
, 0x1c));
1611 printk(" r1f=%2x in_snd=%2x ", atp_readb_io(dev
, c
, 0x1f), dev
->in_snd
[c
]);
1612 printk(" d00=%2x", atp_readb_pci(dev
, c
, 0x00));
1613 printk(" d02=%2x", atp_readb_pci(dev
, c
, 0x02));
1615 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
1616 workrequ
= dev
->id
[c
][j
].curr_req
;
1617 printk("\n que cdb= ");
1618 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
1619 printk(" %2x ",workrequ
->cmnd
[k
]);
1621 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
1627 static const char *atp870u_info(struct Scsi_Host
*notused
)
1629 static char buffer
[128];
1631 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
1636 static int atp870u_show_info(struct seq_file
*m
, struct Scsi_Host
*HBAptr
)
1638 seq_puts(m
, "ACARD AEC-671X Driver Version: 2.6+ac\n\n"
1639 "Adapter Configuration:\n");
1640 seq_printf(m
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
1641 seq_printf(m
, " IRQ: %d\n", HBAptr
->irq
);
1646 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
1647 sector_t capacity
, int *ip
)
1649 int heads
, sectors
, cylinders
;
1653 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1654 if (cylinders
> 1024) {
1657 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
1666 static void atp870u_remove (struct pci_dev
*pdev
)
1668 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
1669 struct Scsi_Host
*pshost
= devext
->host
;
1672 scsi_remove_host(pshost
);
1673 free_irq(pshost
->irq
, pshost
);
1674 pci_release_regions(pdev
);
1675 pci_disable_device(pdev
);
1676 atp870u_free_tables(pshost
);
1677 scsi_host_put(pshost
);
1679 MODULE_LICENSE("GPL");
1681 static struct scsi_host_template atp870u_template
= {
1682 .module
= THIS_MODULE
,
1683 .name
= "atp870u" /* name */,
1684 .proc_name
= "atp870u",
1685 .show_info
= atp870u_show_info
,
1686 .info
= atp870u_info
/* info */,
1687 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
1688 .eh_abort_handler
= atp870u_abort
/* abort */,
1689 .bios_param
= atp870u_biosparam
/* biosparm */,
1690 .can_queue
= qcnt
/* can_queue */,
1691 .this_id
= 7 /* SCSI ID */,
1692 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
1693 .use_clustering
= ENABLE_CLUSTERING
,
1694 .max_sectors
= ATP870U_MAX_SECTORS
,
1697 static struct pci_device_id atp870u_id_table
[] = {
1698 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
1699 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
1700 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
1701 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
1702 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
1703 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
1704 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
1705 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
1706 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
1707 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
1711 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
1713 static struct pci_driver atp870u_driver
= {
1714 .id_table
= atp870u_id_table
,
1716 .probe
= atp870u_probe
,
1717 .remove
= atp870u_remove
,
1720 module_pci_driver(atp870u_driver
);
1722 static void atp_is(struct atp_unit
*dev
, unsigned char c
, bool wide_chip
, unsigned char lvdmode
)
1724 unsigned char i
, j
, k
, rmb
, n
;
1725 unsigned short int m
;
1726 static unsigned char mbuf
[512];
1727 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1728 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1729 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1730 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1731 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1732 static unsigned char synw_870
[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1733 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1734 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1735 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1737 for (i
= 0; i
< 16; i
++) {
1738 if (!wide_chip
&& (i
> 7))
1742 if ((m
& dev
->active_id
[c
]) != 0) {
1745 if (i
== dev
->host_id
[c
]) {
1746 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
1749 atp_writeb_io(dev
, c
, 0x1b, wide_chip
? 0x01 : 0x00);
1750 atp_writeb_io(dev
, c
, 1, 0x08);
1751 atp_writeb_io(dev
, c
, 2, 0x7f);
1752 atp_writeb_io(dev
, c
, 3, satn
[0]);
1753 atp_writeb_io(dev
, c
, 4, satn
[1]);
1754 atp_writeb_io(dev
, c
, 5, satn
[2]);
1755 atp_writeb_io(dev
, c
, 6, satn
[3]);
1756 atp_writeb_io(dev
, c
, 7, satn
[4]);
1757 atp_writeb_io(dev
, c
, 8, satn
[5]);
1758 atp_writeb_io(dev
, c
, 0x0f, 0);
1759 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1760 atp_writeb_io(dev
, c
, 0x12, 0);
1761 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1762 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1764 if ((j
& 0x08) != 0) {
1765 j
= (j
& 0x07) | 0x40;
1767 atp_writeb_io(dev
, c
, 0x15, j
);
1768 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1770 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1773 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1776 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1779 dev
->active_id
[c
] |= m
;
1781 atp_writeb_io(dev
, c
, 0x10, 0x30);
1782 if (is885(dev
) || is880(dev
))
1783 atp_writeb_io(dev
, c
, 0x14, 0x00);
1784 else /* result of is870() merge - is this a bug? */
1785 atp_writeb_io(dev
, c
, 0x04, 0x00);
1788 atp_writeb_io(dev
, c
, 0x18, 0x08);
1790 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1793 j
= atp_readb_io(dev
, c
, 0x17);
1795 atp_writeb_io(dev
, c
, 0x10, 0x41);
1799 atp_writeb_io(dev
, c
, 3, inqd
[0]);
1800 atp_writeb_io(dev
, c
, 4, inqd
[1]);
1801 atp_writeb_io(dev
, c
, 5, inqd
[2]);
1802 atp_writeb_io(dev
, c
, 6, inqd
[3]);
1803 atp_writeb_io(dev
, c
, 7, inqd
[4]);
1804 atp_writeb_io(dev
, c
, 8, inqd
[5]);
1805 atp_writeb_io(dev
, c
, 0x0f, 0);
1806 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1807 atp_writeb_io(dev
, c
, 0x12, 0);
1808 atp_writeb_io(dev
, c
, 0x13, inqd
[6]);
1809 atp_writeb_io(dev
, c
, 0x14, inqd
[7]);
1810 atp_writeb_io(dev
, c
, 0x18, inqd
[8]);
1812 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1815 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1818 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1822 atp_writeb_io(dev
, c
, 0x1b, 0x00);
1824 atp_writeb_io(dev
, c
, 0x18, 0x08);
1827 k
= atp_readb_io(dev
, c
, 0x1f);
1828 if ((k
& 0x01) != 0) {
1829 mbuf
[j
++] = atp_readb_io(dev
, c
, 0x19);
1832 if ((k
& 0x80) == 0) {
1835 j
= atp_readb_io(dev
, c
, 0x17);
1839 atp_writeb_io(dev
, c
, 0x10, 0x46);
1840 atp_writeb_io(dev
, c
, 0x12, 0);
1841 atp_writeb_io(dev
, c
, 0x13, 0);
1842 atp_writeb_io(dev
, c
, 0x14, 0);
1843 atp_writeb_io(dev
, c
, 0x18, 0x08);
1845 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1848 if (atp_readb_io(dev
, c
, 0x17) != 0x16)
1853 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1854 dev
->id
[c
][i
].devtype
= mbuf
[0];
1859 if ((mbuf
[7] & 0x60) == 0) {
1862 if (is885(dev
) || is880(dev
)) {
1863 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0))
1865 } else { /* result of is870() merge - is this a bug? */
1866 if ((dev
->global_map
[c
] & 0x20) == 0)
1872 if (dev
->sp
[c
][i
] != 0x04) // force u2
1877 atp_writeb_io(dev
, c
, 0x1b, 0x01);
1878 atp_writeb_io(dev
, c
, 3, satn
[0]);
1879 atp_writeb_io(dev
, c
, 4, satn
[1]);
1880 atp_writeb_io(dev
, c
, 5, satn
[2]);
1881 atp_writeb_io(dev
, c
, 6, satn
[3]);
1882 atp_writeb_io(dev
, c
, 7, satn
[4]);
1883 atp_writeb_io(dev
, c
, 8, satn
[5]);
1884 atp_writeb_io(dev
, c
, 0x0f, 0);
1885 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
1886 atp_writeb_io(dev
, c
, 0x12, 0);
1887 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
1888 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
1889 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
1891 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
1894 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
1897 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
1902 atp_writeb_io(dev
, c
, 0x14, 0x09);
1903 atp_writeb_io(dev
, c
, 0x18, 0x20);
1905 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1906 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1907 atp_writeb_io(dev
, c
, 0x19, u3
[j
++]);
1911 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
1914 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1926 atp_writeb_io(dev
, c
, 0x18, 0x20);
1927 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
1928 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
1929 atp_writeb_io(dev
, c
, 0x19, 0);
1932 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1944 atp_writeb_io(dev
, c
, 0x14, 0x09);
1945 atp_writeb_io(dev
, c
, 0x18, 0x20);
1948 j
= atp_readb_io(dev
, c
, 0x1f);
1949 if ((j
& 0x01) != 0) {
1950 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
1953 if ((j
& 0x80) == 0x00) {
1956 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
1968 atp_writeb_io(dev
, c
, 0x10, 0x30);
1969 atp_writeb_io(dev
, c
, 0x14, 0x00);
1970 atp_writeb_io(dev
, c
, 0x18, 0x08);
1972 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00);
1974 j
= atp_readb_io(dev
, c
, 0x17);
1981 if (mbuf
[0] != 0x01) {
1984 if (mbuf
[1] != 0x06) {
1987 if (mbuf
[2] != 0x04) {
1990 if (mbuf
[3] == 0x09) {
1993 dev
->wide_id
[c
] |= m
;
1994 dev
->id
[c
][i
].devsp
= 0xce;
1996 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
2001 atp_writeb_io(dev
, c
, 0x1b, 0x01);
2002 atp_writeb_io(dev
, c
, 3, satn
[0]);
2003 atp_writeb_io(dev
, c
, 4, satn
[1]);
2004 atp_writeb_io(dev
, c
, 5, satn
[2]);
2005 atp_writeb_io(dev
, c
, 6, satn
[3]);
2006 atp_writeb_io(dev
, c
, 7, satn
[4]);
2007 atp_writeb_io(dev
, c
, 8, satn
[5]);
2008 atp_writeb_io(dev
, c
, 0x0f, 0);
2009 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
2010 atp_writeb_io(dev
, c
, 0x12, 0);
2011 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
2012 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
2013 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
2015 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2018 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
2021 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
2026 atp_writeb_io(dev
, c
, 0x14, 0x05);
2027 atp_writeb_io(dev
, c
, 0x18, 0x20);
2029 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
2030 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
2031 atp_writeb_io(dev
, c
, 0x19, wide
[j
++]);
2035 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
2038 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
2050 atp_writeb_io(dev
, c
, 0x18, 0x20);
2051 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
2052 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0)
2053 atp_writeb_io(dev
, c
, 0x19, 0);
2056 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
2068 atp_writeb_io(dev
, c
, 0x14, 0xff);
2069 atp_writeb_io(dev
, c
, 0x18, 0x20);
2072 j
= atp_readb_io(dev
, c
, 0x1f);
2073 if ((j
& 0x01) != 0) {
2074 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
2077 if ((j
& 0x80) == 0x00) {
2080 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
2092 atp_writeb_io(dev
, c
, 0x10, 0x30);
2093 atp_writeb_io(dev
, c
, 0x14, 0x00);
2094 atp_writeb_io(dev
, c
, 0x18, 0x08);
2096 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2099 j
= atp_readb_io(dev
, c
, 0x17);
2106 if (mbuf
[0] != 0x01) {
2109 if (mbuf
[1] != 0x02) {
2112 if (mbuf
[2] != 0x03) {
2115 if (mbuf
[3] != 0x01) {
2120 dev
->wide_id
[c
] |= m
;
2122 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) || ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
2125 if ((dev
->async
[c
] & m
) != 0) {
2131 if ((!is885(dev
) && !is880(dev
)) || (dev
->sp
[c
][i
] == 0x02)) {
2135 if (dev
->sp
[c
][i
] >= 0x03) {
2141 if ((m
& dev
->wide_id
[c
]) != 0) {
2144 atp_writeb_io(dev
, c
, 0x1b, j
);
2145 atp_writeb_io(dev
, c
, 3, satn
[0]);
2146 atp_writeb_io(dev
, c
, 4, satn
[1]);
2147 atp_writeb_io(dev
, c
, 5, satn
[2]);
2148 atp_writeb_io(dev
, c
, 6, satn
[3]);
2149 atp_writeb_io(dev
, c
, 7, satn
[4]);
2150 atp_writeb_io(dev
, c
, 8, satn
[5]);
2151 atp_writeb_io(dev
, c
, 0x0f, 0);
2152 atp_writeb_io(dev
, c
, 0x11, dev
->id
[c
][i
].devsp
);
2153 atp_writeb_io(dev
, c
, 0x12, 0);
2154 atp_writeb_io(dev
, c
, 0x13, satn
[6]);
2155 atp_writeb_io(dev
, c
, 0x14, satn
[7]);
2156 atp_writeb_io(dev
, c
, 0x18, satn
[8]);
2158 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2161 if (atp_readb_io(dev
, c
, 0x17) != 0x11 && atp_readb_io(dev
, c
, 0x17) != 0x8e)
2164 while (atp_readb_io(dev
, c
, 0x17) != 0x8e)
2169 atp_writeb_io(dev
, c
, 0x14, 0x06);
2170 atp_writeb_io(dev
, c
, 0x18, 0x20);
2172 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0) {
2173 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0) {
2174 if ((m
& dev
->wide_id
[c
]) != 0) {
2175 if (is885(dev
) || is880(dev
)) {
2176 if ((m
& dev
->ultra_map
[c
]) != 0) {
2177 atp_writeb_io(dev
, c
, 0x19, synuw
[j
++]);
2179 atp_writeb_io(dev
, c
, 0x19, synw
[j
++]);
2182 atp_writeb_io(dev
, c
, 0x19, synw_870
[j
++]);
2184 if ((m
& dev
->ultra_map
[c
]) != 0) {
2185 atp_writeb_io(dev
, c
, 0x19, synu
[j
++]);
2187 atp_writeb_io(dev
, c
, 0x19, synn
[j
++]);
2193 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00)
2196 j
= atp_readb_io(dev
, c
, 0x17) & 0x0f;
2208 atp_writeb_io(dev
, c
, 0x18, 0x20);
2209 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00) {
2210 if ((atp_readb_io(dev
, c
, 0x1f) & 0x01) != 0x00)
2211 atp_writeb_io(dev
, c
, 0x19, 0x00);
2214 j
= atp_readb_io(dev
, c
, 0x17);
2230 if (is885(dev
) || is880(dev
))
2231 atp_writeb_io(dev
, c
, 0x14, 0x06);
2233 atp_writeb_io(dev
, c
, 0x14, 0xff);
2234 atp_writeb_io(dev
, c
, 0x18, 0x20);
2237 j
= atp_readb_io(dev
, c
, 0x1f);
2238 if ((j
& 0x01) != 0x00) {
2239 mbuf
[k
++] = atp_readb_io(dev
, c
, 0x19);
2242 if ((j
& 0x80) == 0x00) {
2246 while ((atp_readb_io(dev
, c
, 0x17) & 0x80) == 0x00);
2248 j
= atp_readb_io(dev
, c
, 0x17);
2264 atp_writeb_io(dev
, c
, 0x10, 0x30);
2266 atp_writeb_io(dev
, c
, 0x14, 0x00);
2267 atp_writeb_io(dev
, c
, 0x18, 0x08);
2269 while ((atp_readb_io(dev
, c
, 0x1f) & 0x80) == 0x00)
2272 j
= atp_readb_io(dev
, c
, 0x17);
2276 if (mbuf
[0] != 0x01) {
2279 if (mbuf
[1] != 0x03) {
2282 if (mbuf
[4] == 0x00) {
2285 if (mbuf
[3] > 0x64) {
2288 if (is885(dev
) || is880(dev
)) {
2289 if (mbuf
[4] > 0x0e) {
2293 if (mbuf
[4] > 0x0c) {
2297 dev
->id
[c
][i
].devsp
= mbuf
[4];
2298 if (is885(dev
) || is880(dev
))
2299 if (mbuf
[3] < 0x0c) {
2303 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
2307 if (mbuf
[3] < 0x1a) {
2311 if (mbuf
[3] < 0x33) {
2315 if (mbuf
[3] < 0x4c) {
2321 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
2323 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);