1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 1997 Wu Ching Chen
4 * 2.1.x update (C) 1998 Krzysztof G. Baranowski
5 * 2.5.x update (C) 2002 Red Hat
6 * 2.6.x update (C) 2004 Red Hat
8 * Marcelo Tosatti <marcelo@conectiva.com.br> : SMP fixes
10 * Wu Ching Chen : NULL pointer fixes 2000/06/02
12 * enable 32 bit fifo transfer
13 * support cdrom & remove device run ultra speed
14 * fix disconnect bug 2000/12/21
15 * support atp880 chip lvd u160 2001/05/15
16 * fix prd table bug 2001/09/12 (7.1)
18 * atp885 support add by ACARD Hao Ping Lian 2005/01/05
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/string.h>
26 #include <linux/ioport.h>
27 #include <linux/delay.h>
28 #include <linux/proc_fs.h>
29 #include <linux/spinlock.h>
30 #include <linux/pci.h>
31 #include <linux/blkdev.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/slab.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_cmnd.h>
38 #include <scsi/scsi_device.h>
39 #include <scsi/scsi_host.h>
43 static const struct scsi_host_template atp870u_template;
44 static void send_s870(struct atp_unit *dev,unsigned char c);
45 static void atp_is(struct atp_unit *dev, unsigned char c, bool wide_chip,
46 unsigned char lvdmode);
48 static inline void atp_writeb_base(struct atp_unit *atp, u8 reg, u8 val)
50 outb(val, atp->baseport + reg);
53 static inline void atp_writew_base(struct atp_unit *atp, u8 reg, u16 val)
55 outw(val, atp->baseport + reg);
58 static inline void atp_writeb_io(struct atp_unit *atp, u8 channel, u8 reg, u8 val)
60 outb(val, atp->ioport[channel] + reg);
63 static inline void atp_writew_io(struct atp_unit *atp, u8 channel, u8 reg, u16 val)
65 outw(val, atp->ioport[channel] + reg);
68 static inline void atp_writeb_pci(struct atp_unit *atp, u8 channel, u8 reg, u8 val)
70 outb(val, atp->pciport[channel] + reg);
73 static inline void atp_writel_pci(struct atp_unit *atp, u8 channel, u8 reg, u32 val)
75 outl(val, atp->pciport[channel] + reg);
78 static inline u8 atp_readb_base(struct atp_unit *atp, u8 reg)
80 return inb(atp->baseport + reg);
83 static inline u16 atp_readw_base(struct atp_unit *atp, u8 reg)
85 return inw(atp->baseport + reg);
88 static inline u32 atp_readl_base(struct atp_unit *atp, u8 reg)
90 return inl(atp->baseport + reg);
93 static inline u8 atp_readb_io(struct atp_unit *atp, u8 channel, u8 reg)
95 return inb(atp->ioport[channel] + reg);
98 static inline u16 atp_readw_io(struct atp_unit *atp, u8 channel, u8 reg)
100 return inw(atp->ioport[channel] + reg);
103 static inline u8 atp_readb_pci(struct atp_unit *atp, u8 channel, u8 reg)
105 return inb(atp->pciport[channel] + reg);
108 static inline bool is880(struct atp_unit *atp)
110 return atp->pdev->device == ATP880_DEVID1 ||
111 atp->pdev->device == ATP880_DEVID2;
114 static inline bool is885(struct atp_unit *atp)
116 return atp->pdev->device == ATP885_DEVID;
119 static irqreturn_t atp870u_intr_handle(int irq, void *dev_id)
122 unsigned short int id;
123 unsigned char i, j, c, target_id, lun,cmdp;
125 struct scsi_cmnd *workreq;
126 unsigned long adrcnt, k;
130 struct Scsi_Host *host = dev_id;
131 struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
133 for (c = 0; c < 2; c++) {
134 j = atp_readb_io(dev, c, 0x1f);
142 printk("atp870u_intr_handle enter\n");
145 cmdp = atp_readb_io(dev, c, 0x10);
146 if (dev->working[c] != 0) {
148 if ((atp_readb_io(dev, c, 0x16) & 0x80) == 0)
149 atp_writeb_io(dev, c, 0x16,
150 (atp_readb_io(dev, c, 0x16) | 0x80));
152 if ((atp_readb_pci(dev, c, 0x00) & 0x08) != 0)
154 for (k=0; k < 1000; k++) {
155 if ((atp_readb_pci(dev, c, 2) & 0x08) == 0)
157 if ((atp_readb_pci(dev, c, 2) & 0x01) == 0)
161 atp_writeb_pci(dev, c, 0, 0x00);
163 i = atp_readb_io(dev, c, 0x17);
166 atp_writeb_pci(dev, c, 2, 0x06);
168 target_id = atp_readb_io(dev, c, 0x15);
171 * Remap wide devices onto id numbers
174 if ((target_id & 0x40) != 0) {
175 target_id = (target_id & 0x07) | 0x08;
180 if ((j & 0x40) != 0) {
181 if (dev->last_cmd[c] == 0xff) {
182 dev->last_cmd[c] = target_id;
184 dev->last_cmd[c] |= 0x40;
187 dev->r1f[c][target_id] |= j;
189 printk("atp870u_intr_handle status = %x\n",i);
192 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
193 dev->last_cmd[c] = 0xff;
197 ((unsigned char *) &adrcnt)[2] =
198 atp_readb_io(dev, c, 0x12);
199 ((unsigned char *) &adrcnt)[1] =
200 atp_readb_io(dev, c, 0x13);
201 ((unsigned char *) &adrcnt)[0] =
202 atp_readb_io(dev, c, 0x14);
203 if (dev->id[c][target_id].last_len != adrcnt) {
204 k = dev->id[c][target_id].last_len;
206 dev->id[c][target_id].tran_len = k;
207 dev->id[c][target_id].last_len = adrcnt;
210 printk("dev->id[c][target_id].last_len = %d "
211 "dev->id[c][target_id].tran_len = %d\n",
212 dev->id[c][target_id].last_len,
213 dev->id[c][target_id].tran_len);
220 if (dev->wide_id[c] != 0) {
221 atp_writeb_io(dev, c, 0x1b, 0x01);
222 while ((atp_readb_io(dev, c, 0x1b) & 0x01) != 0x01)
223 atp_writeb_io(dev, c, 0x1b, 0x01);
226 * Issue more commands
228 spin_lock_irqsave(dev->host->host_lock, flags);
229 if (((dev->quhd[c] != dev->quend[c]) ||
230 (dev->last_cmd[c] != 0xff)) &&
231 (dev->in_snd[c] == 0)) {
233 printk("Call sent_s870\n");
237 spin_unlock_irqrestore(dev->host->host_lock, flags);
243 printk("Status 0x85 return\n");
249 dev->last_cmd[c] |= 0x40;
255 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
256 dev->last_cmd[c] = 0xff;
259 ((unsigned char *) &adrcnt)[2] =
260 atp_readb_io(dev, c, 0x12);
261 ((unsigned char *) &adrcnt)[1] =
262 atp_readb_io(dev, c, 0x13);
263 ((unsigned char *) &adrcnt)[0] =
264 atp_readb_io(dev, c, 0x14);
265 k = dev->id[c][target_id].last_len;
267 dev->id[c][target_id].tran_len = k;
268 dev->id[c][target_id].last_len = adrcnt;
269 atp_writeb_io(dev, c, 0x10, 0x41);
270 atp_writeb_io(dev, c, 0x18, 0x08);
276 if ((i == 0x4c) || (i == 0x4d) || (i == 0x8c) || (i == 0x8d)) {
277 if ((i == 0x4c) || (i == 0x8c))
283 if ((i == 0x80) || (i == 0x8f)) {
285 printk(KERN_DEBUG "Device reselect\n");
288 if (cmdp == 0x44 || i == 0x80)
289 lun = atp_readb_io(dev, c, 0x1d) & 0x07;
291 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
292 dev->last_cmd[c] = 0xff;
296 printk("cmdp = 0x41\n");
299 ((unsigned char *) &adrcnt)[2] =
300 atp_readb_io(dev, c, 0x12);
301 ((unsigned char *) &adrcnt)[1] =
302 atp_readb_io(dev, c, 0x13);
303 ((unsigned char *) &adrcnt)[0] =
304 atp_readb_io(dev, c, 0x14);
305 k = dev->id[c][target_id].last_len;
307 dev->id[c][target_id].tran_len = k;
308 dev->id[c][target_id].last_len = adrcnt;
309 atp_writeb_io(dev, c, 0x18, 0x08);
314 printk("cmdp != 0x41\n");
316 atp_writeb_io(dev, c, 0x10, 0x46);
317 dev->id[c][target_id].dirct = 0x00;
318 atp_writeb_io(dev, c, 0x12, 0x00);
319 atp_writeb_io(dev, c, 0x13, 0x00);
320 atp_writeb_io(dev, c, 0x14, 0x00);
321 atp_writeb_io(dev, c, 0x18, 0x08);
326 if (dev->last_cmd[c] != 0xff) {
327 dev->last_cmd[c] |= 0x40;
330 j = atp_readb_base(dev, 0x29) & 0xfe;
331 atp_writeb_base(dev, 0x29, j);
333 atp_writeb_io(dev, c, 0x10, 0x45);
335 target_id = atp_readb_io(dev, c, 0x16);
337 * Remap wide identifiers
339 if ((target_id & 0x10) != 0) {
340 target_id = (target_id & 0x07) | 0x08;
345 atp_writeb_io(dev, c, 0x10, 0x45);
346 workreq = dev->id[c][target_id].curr_req;
348 scmd_printk(KERN_DEBUG, workreq, "CDB");
349 for (l = 0; l < workreq->cmd_len; l++)
350 printk(KERN_DEBUG " %x",workreq->cmnd[l]);
354 atp_writeb_io(dev, c, 0x0f, lun);
355 atp_writeb_io(dev, c, 0x11, dev->id[c][target_id].devsp);
356 adrcnt = dev->id[c][target_id].tran_len;
357 k = dev->id[c][target_id].last_len;
359 atp_writeb_io(dev, c, 0x12, ((unsigned char *) &k)[2]);
360 atp_writeb_io(dev, c, 0x13, ((unsigned char *) &k)[1]);
361 atp_writeb_io(dev, c, 0x14, ((unsigned char *) &k)[0]);
363 printk("k %x, k[0] 0x%x k[1] 0x%x k[2] 0x%x\n", k,
364 atp_readb_io(dev, c, 0x14),
365 atp_readb_io(dev, c, 0x13),
366 atp_readb_io(dev, c, 0x12));
371 j = (j & 0x07) | 0x40;
374 j |= dev->id[c][target_id].dirct;
375 atp_writeb_io(dev, c, 0x15, j);
376 atp_writeb_io(dev, c, 0x16, 0x80);
378 /* enable 32 bit fifo transfer */
380 i = atp_readb_pci(dev, c, 1) & 0xf3;
381 //j=workreq->cmnd[0];
382 if ((workreq->cmnd[0] == READ_6) ||
383 (workreq->cmnd[0] == READ_10) ||
384 (workreq->cmnd[0] == WRITE_6) ||
385 (workreq->cmnd[0] == WRITE_10)) {
388 atp_writeb_pci(dev, c, 1, i);
389 } else if (is880(dev)) {
390 if ((workreq->cmnd[0] == READ_6) ||
391 (workreq->cmnd[0] == READ_10) ||
392 (workreq->cmnd[0] == WRITE_6) ||
393 (workreq->cmnd[0] == WRITE_10))
394 atp_writeb_base(dev, 0x3b,
395 (atp_readb_base(dev, 0x3b) & 0x3f) | 0xc0);
397 atp_writeb_base(dev, 0x3b,
398 atp_readb_base(dev, 0x3b) & 0x3f);
400 if ((workreq->cmnd[0] == READ_6) ||
401 (workreq->cmnd[0] == READ_10) ||
402 (workreq->cmnd[0] == WRITE_6) ||
403 (workreq->cmnd[0] == WRITE_10))
404 atp_writeb_base(dev, 0x3a,
405 (atp_readb_base(dev, 0x3a) & 0xf3) | 0x08);
407 atp_writeb_base(dev, 0x3a,
408 atp_readb_base(dev, 0x3a) & 0xf3);
412 id = id << target_id;
414 * Is this a wide device
416 if ((id & dev->wide_id[c]) != 0) {
419 atp_writeb_io(dev, c, 0x1b, j);
420 while ((atp_readb_io(dev, c, 0x1b) & 0x01) != j)
421 atp_writeb_io(dev, c, 0x1b, j);
422 if (dev->id[c][target_id].last_len == 0) {
423 atp_writeb_io(dev, c, 0x18, 0x08);
426 printk("dev->id[c][target_id].last_len = 0\n");
431 printk("target_id = %d adrcnt = %d\n",target_id,adrcnt);
433 prd = dev->id[c][target_id].prd_pos;
434 while (adrcnt != 0) {
435 id = ((unsigned short int *)prd)[2];
442 ((unsigned short int *)prd)[2] =
443 (unsigned short int)(k - adrcnt);
444 ((unsigned long *)prd)[0] += adrcnt;
446 dev->id[c][target_id].prd_pos = prd;
449 dev->id[c][target_id].prdaddr += 0x08;
452 dev->id[c][target_id].prd_pos = prd;
456 atp_writel_pci(dev, c, 0x04, dev->id[c][target_id].prdaddr);
458 printk("dev->id[%d][%d].prdaddr 0x%8x\n",
459 c, target_id, dev->id[c][target_id].prdaddr);
462 atp_writeb_pci(dev, c, 2, 0x06);
463 atp_writeb_pci(dev, c, 2, 0x00);
466 * Check transfer direction
468 if (dev->id[c][target_id].dirct != 0) {
469 atp_writeb_io(dev, c, 0x18, 0x08);
470 atp_writeb_pci(dev, c, 0, 0x01);
473 printk("status 0x80 return dirct != 0\n");
477 atp_writeb_io(dev, c, 0x18, 0x08);
478 atp_writeb_pci(dev, c, 0, 0x09);
481 printk("status 0x80 return dirct = 0\n");
487 * Current scsi request on this target
490 workreq = dev->id[c][target_id].curr_req;
492 if (i == 0x42 || i == 0x16) {
493 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
494 dev->last_cmd[c] = 0xff;
497 workreq->result = atp_readb_io(dev, c, 0x0f);
498 if (((dev->r1f[c][target_id] & 0x10) != 0) && is885(dev)) {
499 printk(KERN_WARNING "AEC67162 CRC ERROR !\n");
500 workreq->result = SAM_STAT_CHECK_CONDITION;
503 workreq->result = SAM_STAT_CHECK_CONDITION;
506 j = atp_readb_base(dev, 0x29) | 0x01;
507 atp_writeb_base(dev, 0x29, j);
510 * Complete the command
512 scsi_dma_unmap(workreq);
514 spin_lock_irqsave(dev->host->host_lock, flags);
517 printk("workreq->scsi_done\n");
520 * Clear it off the queue
522 dev->id[c][target_id].curr_req = NULL;
524 spin_unlock_irqrestore(dev->host->host_lock, flags);
528 if (dev->wide_id[c] != 0) {
529 atp_writeb_io(dev, c, 0x1b, 0x01);
530 while ((atp_readb_io(dev, c, 0x1b) & 0x01) != 0x01)
531 atp_writeb_io(dev, c, 0x1b, 0x01);
534 * If there is stuff to send and nothing going then send it
536 spin_lock_irqsave(dev->host->host_lock, flags);
537 if (((dev->last_cmd[c] != 0xff) ||
538 (dev->quhd[c] != dev->quend[c])) &&
539 (dev->in_snd[c] == 0)) {
541 printk("Call sent_s870(scsi_done)\n");
545 spin_unlock_irqrestore(dev->host->host_lock, flags);
549 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
550 dev->last_cmd[c] = 0xff;
557 atp_writel_pci(dev, c, 4, dev->id[c][target_id].prdaddr);
558 atp_writeb_pci(dev, c, 2, 0x06);
559 atp_writeb_pci(dev, c, 2, 0x00);
560 atp_writeb_io(dev, c, 0x10, 0x41);
562 k = dev->id[c][target_id].last_len;
563 atp_writeb_io(dev, c, 0x12,
564 ((unsigned char *) (&k))[2]);
565 atp_writeb_io(dev, c, 0x13,
566 ((unsigned char *) (&k))[1]);
567 atp_writeb_io(dev, c, 0x14,
568 ((unsigned char *) (&k))[0]);
569 dev->id[c][target_id].dirct = 0x00;
571 dev->id[c][target_id].dirct = 0x00;
573 atp_writeb_io(dev, c, 0x18, 0x08);
574 atp_writeb_pci(dev, c, 0, 0x09);
579 atp_writel_pci(dev, c, 4, dev->id[c][target_id].prdaddr);
580 atp_writeb_pci(dev, c, 2, 0x06);
581 atp_writeb_pci(dev, c, 2, 0x00);
582 atp_writeb_io(dev, c, 0x10, 0x41);
584 k = dev->id[c][target_id].last_len;
585 atp_writeb_io(dev, c, 0x12,
586 ((unsigned char *) (&k))[2]);
587 atp_writeb_io(dev, c, 0x13,
588 ((unsigned char *) (&k))[1]);
589 atp_writeb_io(dev, c, 0x14,
590 ((unsigned char *) (&k))[0]);
592 atp_writeb_io(dev, c, 0x15,
593 atp_readb_io(dev, c, 0x15) | 0x20);
594 dev->id[c][target_id].dirct = 0x20;
595 atp_writeb_io(dev, c, 0x18, 0x08);
596 atp_writeb_pci(dev, c, 0, 0x01);
601 atp_writeb_io(dev, c, 0x10, 0x30);
603 atp_writeb_io(dev, c, 0x10, 0x46);
604 dev->id[c][target_id].dirct = 0x00;
605 atp_writeb_io(dev, c, 0x12, 0x00);
606 atp_writeb_io(dev, c, 0x13, 0x00);
607 atp_writeb_io(dev, c, 0x14, 0x00);
608 atp_writeb_io(dev, c, 0x18, 0x08);
615 * atp870u_queuecommand_lck - Queue SCSI command
616 * @req_p: request block
618 * Queue a command to the ATP queue. Called with the host lock held.
620 static int atp870u_queuecommand_lck(struct scsi_cmnd *req_p)
622 void (*done)(struct scsi_cmnd *) = scsi_done;
625 struct atp_unit *dev;
626 struct Scsi_Host *host;
628 c = scmd_channel(req_p);
629 req_p->sense_buffer[0]=0;
630 scsi_set_resid(req_p, 0);
631 if (scmd_channel(req_p) > 1) {
632 req_p->result = DID_BAD_TARGET << 16;
635 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
640 host = req_p->device->host;
641 dev = (struct atp_unit *)&host->hostdata;
644 m = m << scmd_id(req_p);
647 * Fake a timeout for missing targets
650 if ((m & dev->active_id[c]) == 0) {
651 req_p->result = DID_BAD_TARGET << 16;
660 if (dev->quend[c] >= qcnt) {
667 if (dev->quhd[c] == dev->quend[c]) {
668 if (dev->quend[c] == 0) {
669 dev->quend[c] = qcnt;
672 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
675 req_p->result = DID_BUS_BUSY << 16;
679 dev->quereq[c][dev->quend[c]] = req_p;
681 printk("dev->ioport[c] = %x atp_readb_io(dev, c, 0x1c) = %x "
682 "dev->in_int[%d] = %d dev->in_snd[%d] = %d\n",
683 dev->ioport[c], atp_readb_io(dev, c, 0x1c), c,
684 dev->in_int[c],c,dev->in_snd[c]);
686 if ((atp_readb_io(dev, c, 0x1c) == 0) &&
687 (dev->in_int[c] == 0) &&
688 (dev->in_snd[c] == 0)) {
690 printk("Call sent_s870(atp870u_queuecommand)\n");
695 printk("atp870u_queuecommand : exit\n");
700 static DEF_SCSI_QCMD(atp870u_queuecommand)
703 * send_s870 - send a command to the controller
705 * On entry there is work queued to be done. We move some of that work to the
708 * Caller holds the host lock.
710 static void send_s870(struct atp_unit *dev, unsigned char c)
712 struct scsi_cmnd *workreq = NULL;
714 unsigned char j, target_id;
716 unsigned short int w;
717 unsigned long l, bttl = 0;
718 unsigned long sg_count;
720 if (dev->in_snd[c] != 0) {
722 printk("cmnd in_snd\n");
727 printk("Sent_s870 enter\n");
730 if ((dev->last_cmd[c] != 0xff) && ((dev->last_cmd[c] & 0x40) != 0)) {
731 dev->last_cmd[c] &= 0x0f;
732 workreq = dev->id[c][dev->last_cmd[c]].curr_req;
734 dev->last_cmd[c] = 0xff;
735 if (dev->quhd[c] == dev->quend[c]) {
742 if ((dev->last_cmd[c] != 0xff) && (dev->working[c] != 0)) {
749 if (dev->quhd[c] >= qcnt)
751 workreq = dev->quereq[c][dev->quhd[c]];
752 if (dev->id[c][scmd_id(workreq)].curr_req != NULL) {
758 dev->id[c][scmd_id(workreq)].curr_req = workreq;
759 dev->last_cmd[c] = scmd_id(workreq);
761 if ((atp_readb_io(dev, c, 0x1f) & 0xb0) != 0 ||
762 atp_readb_io(dev, c, 0x1c) != 0) {
764 printk("Abort to Send\n");
766 dev->last_cmd[c] |= 0x40;
771 printk("OK to Send\n");
772 scmd_printk(KERN_DEBUG, workreq, "CDB");
773 for(i=0;i<workreq->cmd_len;i++) {
774 printk(" %x",workreq->cmnd[i]);
778 l = scsi_bufflen(workreq);
781 j = atp_readb_base(dev, 0x29) & 0xfe;
782 atp_writeb_base(dev, 0x29, j);
783 dev->r1f[c][scmd_id(workreq)] = 0;
786 if (workreq->cmnd[0] == READ_CAPACITY) {
790 if (workreq->cmnd[0] == TEST_UNIT_READY) {
795 target_id = scmd_id(workreq);
802 if ((w & dev->wide_id[c]) != 0) {
805 atp_writeb_io(dev, c, 0x1b, j);
806 while ((atp_readb_io(dev, c, 0x1b) & 0x01) != j) {
807 atp_writeb_pci(dev, c, 0x1b, j);
809 printk("send_s870 while loop 1\n");
816 atp_writeb_io(dev, c, 0x00, workreq->cmd_len);
817 atp_writeb_io(dev, c, 0x01, 0x2c);
819 atp_writeb_io(dev, c, 0x02, 0x7f);
821 atp_writeb_io(dev, c, 0x02, 0xcf);
822 for (i = 0; i < workreq->cmd_len; i++)
823 atp_writeb_io(dev, c, 0x03 + i, workreq->cmnd[i]);
824 atp_writeb_io(dev, c, 0x0f, workreq->device->lun);
828 atp_writeb_io(dev, c, 0x11, dev->id[c][target_id].devsp);
830 printk("dev->id[%d][%d].devsp = %2x\n",c,target_id,
831 dev->id[c][target_id].devsp);
834 sg_count = scsi_dma_map(workreq);
836 * Write transfer size
838 atp_writeb_io(dev, c, 0x12, ((unsigned char *) (&l))[2]);
839 atp_writeb_io(dev, c, 0x13, ((unsigned char *) (&l))[1]);
840 atp_writeb_io(dev, c, 0x14, ((unsigned char *) (&l))[0]);
842 dev->id[c][j].last_len = l;
843 dev->id[c][j].tran_len = 0;
845 printk("dev->id[%2d][%2d].last_len = %d\n",c,j,dev->id[c][j].last_len);
850 if ((j & 0x08) != 0) {
851 j = (j & 0x07) | 0x40;
854 * Check transfer direction
856 if (workreq->sc_data_direction == DMA_TO_DEVICE)
857 atp_writeb_io(dev, c, 0x15, j | 0x20);
859 atp_writeb_io(dev, c, 0x15, j);
860 atp_writeb_io(dev, c, 0x16, atp_readb_io(dev, c, 0x16) | 0x80);
861 atp_writeb_io(dev, c, 0x16, 0x80);
862 dev->id[c][target_id].dirct = 0;
864 if (atp_readb_io(dev, c, 0x1c) == 0) {
866 printk("change SCSI_CMD_REG 0x08\n");
868 atp_writeb_io(dev, c, 0x18, 0x08);
870 dev->last_cmd[c] |= 0x40;
874 prd = dev->id[c][target_id].prd_table;
875 dev->id[c][target_id].prd_pos = prd;
878 * Now write the request list. Either as scatter/gather or as
883 struct scatterlist *sgpnt;
885 scsi_for_each_sg(workreq, sgpnt, sg_count, j) {
886 bttl = sg_dma_address(sgpnt);
889 printk("1. bttl %x, l %x\n",bttl, l);
891 while (l > 0x10000) {
892 (((u16 *) (prd))[i + 3]) = 0x0000;
893 (((u16 *) (prd))[i + 2]) = 0x0000;
894 (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
899 (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
900 (((u16 *) (prd))[i + 2]) = cpu_to_le16(l);
901 (((u16 *) (prd))[i + 3]) = 0;
904 (((u16 *) (prd))[i - 1]) = cpu_to_le16(0x8000);
906 printk("prd %4x %4x %4x %4x\n",
907 (((unsigned short int *)prd)[0]),
908 (((unsigned short int *)prd)[1]),
909 (((unsigned short int *)prd)[2]),
910 (((unsigned short int *)prd)[3]));
911 printk("2. bttl %x, l %x\n",bttl, l);
915 printk("send_s870: prdaddr_2 0x%8x target_id %d\n",
916 dev->id[c][target_id].prdaddr,target_id);
918 dev->id[c][target_id].prdaddr = dev->id[c][target_id].prd_bus;
919 atp_writel_pci(dev, c, 4, dev->id[c][target_id].prdaddr);
920 atp_writeb_pci(dev, c, 2, 0x06);
921 atp_writeb_pci(dev, c, 2, 0x00);
923 j = atp_readb_pci(dev, c, 1) & 0xf3;
924 if ((workreq->cmnd[0] == READ_6) ||
925 (workreq->cmnd[0] == READ_10) ||
926 (workreq->cmnd[0] == WRITE_6) ||
927 (workreq->cmnd[0] == WRITE_10)) {
930 atp_writeb_pci(dev, c, 1, j);
931 } else if (is880(dev)) {
932 if ((workreq->cmnd[0] == READ_6) ||
933 (workreq->cmnd[0] == READ_10) ||
934 (workreq->cmnd[0] == WRITE_6) ||
935 (workreq->cmnd[0] == WRITE_10))
936 atp_writeb_base(dev, 0x3b,
937 (atp_readb_base(dev, 0x3b) & 0x3f) | 0xc0);
939 atp_writeb_base(dev, 0x3b,
940 atp_readb_base(dev, 0x3b) & 0x3f);
942 if ((workreq->cmnd[0] == READ_6) ||
943 (workreq->cmnd[0] == READ_10) ||
944 (workreq->cmnd[0] == WRITE_6) ||
945 (workreq->cmnd[0] == WRITE_10))
946 atp_writeb_base(dev, 0x3a,
947 (atp_readb_base(dev, 0x3a) & 0xf3) | 0x08);
949 atp_writeb_base(dev, 0x3a,
950 atp_readb_base(dev, 0x3a) & 0xf3);
953 if(workreq->sc_data_direction == DMA_TO_DEVICE) {
954 dev->id[c][target_id].dirct = 0x20;
955 if (atp_readb_io(dev, c, 0x1c) == 0) {
956 atp_writeb_io(dev, c, 0x18, 0x08);
957 atp_writeb_pci(dev, c, 0, 0x01);
959 printk( "start DMA(to target)\n");
962 dev->last_cmd[c] |= 0x40;
967 if (atp_readb_io(dev, c, 0x1c) == 0) {
968 atp_writeb_io(dev, c, 0x18, 0x08);
969 atp_writeb_pci(dev, c, 0, 0x09);
971 printk( "start DMA(to host)\n");
974 dev->last_cmd[c] |= 0x40;
981 static unsigned char fun_scam(struct atp_unit *dev, unsigned short int *val)
983 unsigned short int i, k;
986 atp_writew_io(dev, 0, 0x1c, *val);
987 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
988 k = atp_readw_io(dev, 0, 0x1c);
989 j = (unsigned char) (k >> 8);
990 if ((k & 0x8000) != 0) /* DB7 all release? */
993 *val |= 0x4000; /* assert DB6 */
994 atp_writew_io(dev, 0, 0x1c, *val);
995 *val &= 0xdfff; /* assert DB5 */
996 atp_writew_io(dev, 0, 0x1c, *val);
997 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
998 if ((atp_readw_io(dev, 0, 0x1c) & 0x2000) != 0) /* DB5 all release? */
1001 *val |= 0x8000; /* no DB4-0, assert DB7 */
1003 atp_writew_io(dev, 0, 0x1c, *val);
1004 *val &= 0xbfff; /* release DB6 */
1005 atp_writew_io(dev, 0, 0x1c, *val);
1006 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
1007 if ((atp_readw_io(dev, 0, 0x1c) & 0x4000) != 0) /* DB6 all release? */
1014 static void tscam(struct Scsi_Host *host, bool wide_chip, u8 scam_on)
1017 unsigned char i, j, k;
1019 unsigned short int m, assignid_map, val;
1020 unsigned char mbuf[33], quintet[2];
1021 struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
1022 static unsigned char g2q_tab[8] = {
1023 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1026 /* I can't believe we need this before we've even done anything. Remove it
1027 * and see if anyone bitches.
1028 for (i = 0; i < 0x10; i++) {
1033 atp_writeb_io(dev, 0, 1, 0x08);
1034 atp_writeb_io(dev, 0, 2, 0x7f);
1035 atp_writeb_io(dev, 0, 0x11, 0x20);
1037 if ((scam_on & 0x40) == 0) {
1041 m <<= dev->host_id[0];
1048 atp_writeb_io(dev, 0, 0x02, 0x02); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1049 atp_writeb_io(dev, 0, 0x03, 0);
1050 atp_writeb_io(dev, 0, 0x04, 0);
1051 atp_writeb_io(dev, 0, 0x05, 0);
1052 atp_writeb_io(dev, 0, 0x06, 0);
1053 atp_writeb_io(dev, 0, 0x07, 0);
1054 atp_writeb_io(dev, 0, 0x08, 0);
1056 for (i = 0; i < j; i++) {
1059 if ((m & assignid_map) != 0) {
1062 atp_writeb_io(dev, 0, 0x0f, 0);
1063 atp_writeb_io(dev, 0, 0x12, 0);
1064 atp_writeb_io(dev, 0, 0x13, 0);
1065 atp_writeb_io(dev, 0, 0x14, 0);
1067 k = (i & 0x07) | 0x40;
1071 atp_writeb_io(dev, 0, 0x15, k);
1073 atp_writeb_io(dev, 0, 0x1b, 0x01);
1075 atp_writeb_io(dev, 0, 0x1b, 0x00);
1077 atp_writeb_io(dev, 0, 0x18, 0x09);
1079 while ((atp_readb_io(dev, 0, 0x1f) & 0x80) == 0x00)
1081 k = atp_readb_io(dev, 0, 0x17);
1082 if ((k == 0x85) || (k == 0x42))
1085 atp_writeb_io(dev, 0, 0x10, 0x41);
1086 } while (k != 0x16);
1087 if ((k == 0x85) || (k == 0x42))
1092 atp_writeb_io(dev, 0, 0x02, 0x7f);
1093 atp_writeb_io(dev, 0, 0x1b, 0x02);
1097 val = 0x0080; /* bsy */
1098 atp_writew_io(dev, 0, 0x1c, val);
1099 val |= 0x0040; /* sel */
1100 atp_writew_io(dev, 0, 0x1c, val);
1101 val |= 0x0004; /* msg */
1102 atp_writew_io(dev, 0, 0x1c, val);
1103 udelay(2); /* 2 deskew delay(45ns*2=90ns) */
1104 val &= 0x007f; /* no bsy */
1105 atp_writew_io(dev, 0, 0x1c, val);
1107 val &= 0x00fb; /* after 1ms no msg */
1108 atp_writew_io(dev, 0, 0x1c, val);
1109 while ((atp_readb_io(dev, 0, 0x1c) & 0x04) != 0)
1113 for (n = 0; n < 0x30000; n++)
1114 if ((atp_readb_io(dev, 0, 0x1c) & 0x80) != 0) /* bsy ? */
1117 for (n = 0; n < 0x30000; n++)
1118 if ((atp_readb_io(dev, 0, 0x1c) & 0x81) == 0x0081) {
1120 val |= 0x8003; /* io,cd,db7 */
1121 atp_writew_io(dev, 0, 0x1c, val);
1123 val &= 0x00bf; /* no sel */
1124 atp_writew_io(dev, 0, 0x1c, val);
1130 * The funny division into multiple delays is to accomodate
1131 * arches like ARM where udelay() multiplies its argument by
1132 * a large number to initialize a loop counter. To avoid
1133 * overflow, the maximum supported udelay is 2000 microseconds.
1135 * XXX it would be more polite to find a way to use msleep()
1139 if ((atp_readb_io(dev, 0, 0x1c) & 0x80) == 0x00) { /* bsy ? */
1140 atp_writew_io(dev, 0, 0x1c, 0);
1141 atp_writeb_io(dev, 0, 0x1b, 0);
1142 atp_writeb_io(dev, 0, 0x15, 0);
1143 atp_writeb_io(dev, 0, 0x18, 0x09);
1144 while ((atp_readb_io(dev, 0, 0x1f) & 0x80) == 0)
1146 atp_readb_io(dev, 0, 0x17);
1149 val &= 0x00ff; /* synchronization */
1151 fun_scam(dev, &val);
1153 val &= 0x00ff; /* isolation */
1155 fun_scam(dev, &val);
1161 if ((atp_readw_io(dev, 0, 0x1c) & 0x2000) == 0)
1164 val &= 0x00ff; /* get ID_STRING */
1166 k = fun_scam(dev, &val);
1167 if ((k & 0x03) == 0)
1171 if ((k & 0x02) != 0)
1180 /* isolation complete.. */
1182 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1185 if ((j & 0x20) != 0) { /* bit5=1:ID up to 7 */
1188 if ((j & 0x06) != 0) { /* IDvalid? */
1193 if ((m & assignid_map) == 0)
1201 if ((m & assignid_map) != 0) { /* srch from max acceptable ID# */
1202 k = i; /* max acceptable ID# */
1206 if ((m & assignid_map) == 0)
1217 quintet[0] = 0x38; /* 1st dft ID<8 */
1219 quintet[0] = 0x31; /* 1st ID>=8 */
1222 quintet[1] = g2q_tab[k];
1224 val &= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1225 m = quintet[0] << 8;
1227 fun_scam(dev, &val);
1228 val &= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1229 m = quintet[1] << 8;
1231 fun_scam(dev, &val);
1236 static void atp870u_free_tables(struct Scsi_Host *host)
1238 struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
1240 for (j=0; j < 2; j++) {
1241 for (k = 0; k < 16; k++) {
1242 if (!atp_dev->id[j][k].prd_table)
1244 dma_free_coherent(&atp_dev->pdev->dev, 1024,
1245 atp_dev->id[j][k].prd_table,
1246 atp_dev->id[j][k].prd_bus);
1247 atp_dev->id[j][k].prd_table = NULL;
1252 static int atp870u_init_tables(struct Scsi_Host *host)
1254 struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
1256 for(c=0;c < 2;c++) {
1258 atp_dev->id[c][k].prd_table =
1259 dma_alloc_coherent(&atp_dev->pdev->dev, 1024,
1260 &(atp_dev->id[c][k].prd_bus),
1262 if (!atp_dev->id[c][k].prd_table) {
1263 printk("atp870u_init_tables fail\n");
1264 atp870u_free_tables(host);
1267 atp_dev->id[c][k].prdaddr = atp_dev->id[c][k].prd_bus;
1268 atp_dev->id[c][k].devsp=0x20;
1269 atp_dev->id[c][k].devtype = 0x7f;
1270 atp_dev->id[c][k].curr_req = NULL;
1273 atp_dev->active_id[c] = 0;
1274 atp_dev->wide_id[c] = 0;
1275 atp_dev->host_id[c] = 0x07;
1276 atp_dev->quhd[c] = 0;
1277 atp_dev->quend[c] = 0;
1278 atp_dev->last_cmd[c] = 0xff;
1279 atp_dev->in_snd[c] = 0;
1280 atp_dev->in_int[c] = 0;
1282 for (k = 0; k < qcnt; k++) {
1283 atp_dev->quereq[c][k] = NULL;
1285 for (k = 0; k < 16; k++) {
1286 atp_dev->id[c][k].curr_req = NULL;
1287 atp_dev->sp[c][k] = 0x04;
1293 static void atp_set_host_id(struct atp_unit *atp, u8 c, u8 host_id)
1295 atp_writeb_io(atp, c, 0, host_id | 0x08);
1296 atp_writeb_io(atp, c, 0x18, 0);
1297 while ((atp_readb_io(atp, c, 0x1f) & 0x80) == 0)
1299 atp_readb_io(atp, c, 0x17);
1300 atp_writeb_io(atp, c, 1, 8);
1301 atp_writeb_io(atp, c, 2, 0x7f);
1302 atp_writeb_io(atp, c, 0x11, 0x20);
1305 static void atp870_init(struct Scsi_Host *shpnt)
1307 struct atp_unit *atpdev = shost_priv(shpnt);
1308 struct pci_dev *pdev = atpdev->pdev;
1309 unsigned char k, host_id;
1312 (pdev->device == PCI_DEVICE_ID_ARTOP_AEC7610 &&
1313 pdev->revision == 4) ||
1314 (pdev->device == PCI_DEVICE_ID_ARTOP_AEC7612UW) ||
1315 (pdev->device == PCI_DEVICE_ID_ARTOP_AEC7612SUW);
1317 pci_read_config_byte(pdev, 0x49, &host_id);
1319 dev_info(&pdev->dev, "ACARD AEC-671X PCI Ultra/W SCSI-2/3 "
1320 "Host Adapter: IO:%lx, IRQ:%d.\n",
1321 shpnt->io_port, shpnt->irq);
1323 atpdev->ioport[0] = shpnt->io_port;
1324 atpdev->pciport[0] = shpnt->io_port + 0x20;
1326 atpdev->host_id[0] = host_id;
1327 scam_on = atp_readb_pci(atpdev, 0, 2);
1328 atpdev->global_map[0] = atp_readb_base(atpdev, 0x2d);
1329 atpdev->ultra_map[0] = atp_readw_base(atpdev, 0x2e);
1331 if (atpdev->ultra_map[0] == 0) {
1333 atpdev->global_map[0] = 0x20;
1334 atpdev->ultra_map[0] = 0xffff;
1337 if (pdev->revision > 0x07) /* check if atp876 chip */
1338 atp_writeb_base(atpdev, 0x3e, 0x00); /* enable terminator */
1340 k = (atp_readb_base(atpdev, 0x3a) & 0xf3) | 0x10;
1341 atp_writeb_base(atpdev, 0x3a, k);
1342 atp_writeb_base(atpdev, 0x3a, k & 0xdf);
1344 atp_writeb_base(atpdev, 0x3a, k);
1346 atp_set_host_id(atpdev, 0, host_id);
1348 tscam(shpnt, wide_chip, scam_on);
1349 atp_writeb_base(atpdev, 0x3a, atp_readb_base(atpdev, 0x3a) | 0x10);
1350 atp_is(atpdev, 0, wide_chip, 0);
1351 atp_writeb_base(atpdev, 0x3a, atp_readb_base(atpdev, 0x3a) & 0xef);
1352 atp_writeb_base(atpdev, 0x3b, atp_readb_base(atpdev, 0x3b) | 0x20);
1353 shpnt->max_id = wide_chip ? 16 : 8;
1354 shpnt->this_id = host_id;
1357 static void atp880_init(struct Scsi_Host *shpnt)
1359 struct atp_unit *atpdev = shost_priv(shpnt);
1360 struct pci_dev *pdev = atpdev->pdev;
1361 unsigned char k, m, host_id;
1364 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
1366 atpdev->ioport[0] = shpnt->io_port + 0x40;
1367 atpdev->pciport[0] = shpnt->io_port + 0x28;
1369 host_id = atp_readb_base(atpdev, 0x39) >> 4;
1371 dev_info(&pdev->dev, "ACARD AEC-67160 PCI Ultra3 LVD "
1372 "Host Adapter: IO:%lx, IRQ:%d.\n",
1373 shpnt->io_port, shpnt->irq);
1374 atpdev->host_id[0] = host_id;
1376 atpdev->global_map[0] = atp_readb_base(atpdev, 0x35);
1377 atpdev->ultra_map[0] = atp_readw_base(atpdev, 0x3c);
1380 while (n < 0x4000) {
1382 atp_writew_base(atpdev, 0x34, n);
1384 if (atp_readb_base(atpdev, 0x30) == 0xff)
1387 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30);
1388 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31);
1389 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32);
1390 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33);
1391 atp_writew_base(atpdev, 0x34, n);
1393 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30);
1394 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31);
1395 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32);
1396 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33);
1397 atp_writew_base(atpdev, 0x34, n);
1399 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30);
1400 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31);
1401 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32);
1402 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33);
1403 atp_writew_base(atpdev, 0x34, n);
1405 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x30);
1406 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x31);
1407 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x32);
1408 atpdev->sp[0][m++] = atp_readb_base(atpdev, 0x33);
1411 atp_writew_base(atpdev, 0x34, 0);
1412 atpdev->ultra_map[0] = 0;
1413 atpdev->async[0] = 0;
1414 for (k = 0; k < 16; k++) {
1416 if (atpdev->sp[0][k] > 1)
1417 atpdev->ultra_map[0] |= n;
1419 if (atpdev->sp[0][k] == 0)
1420 atpdev->async[0] |= n;
1422 atpdev->async[0] = ~(atpdev->async[0]);
1423 atp_writeb_base(atpdev, 0x35, atpdev->global_map[0]);
1425 k = atp_readb_base(atpdev, 0x38) & 0x80;
1426 atp_writeb_base(atpdev, 0x38, k);
1427 atp_writeb_base(atpdev, 0x3b, 0x20);
1429 atp_writeb_base(atpdev, 0x3b, 0);
1431 atp_readb_io(atpdev, 0, 0x1b);
1432 atp_readb_io(atpdev, 0, 0x17);
1434 atp_set_host_id(atpdev, 0, host_id);
1436 tscam(shpnt, true, atp_readb_base(atpdev, 0x22));
1437 atp_is(atpdev, 0, true, atp_readb_base(atpdev, 0x3f) & 0x40);
1438 atp_writeb_base(atpdev, 0x38, 0xb0);
1440 shpnt->this_id = host_id;
1443 static void atp885_init(struct Scsi_Host *shpnt)
1445 struct atp_unit *atpdev = shost_priv(shpnt);
1446 struct pci_dev *pdev = atpdev->pdev;
1447 unsigned char k, m, c;
1449 unsigned char setupdata[2][16];
1451 dev_info(&pdev->dev, "ACARD AEC-67162 PCI Ultra3 LVD "
1452 "Host Adapter: IO:%lx, IRQ:%d.\n",
1453 shpnt->io_port, shpnt->irq);
1455 atpdev->ioport[0] = shpnt->io_port + 0x80;
1456 atpdev->ioport[1] = shpnt->io_port + 0xc0;
1457 atpdev->pciport[0] = shpnt->io_port + 0x40;
1458 atpdev->pciport[1] = shpnt->io_port + 0x50;
1460 c = atp_readb_base(atpdev, 0x29);
1461 atp_writeb_base(atpdev, 0x29, c | 0x04);
1464 while (n < 0x2000) {
1465 atp_writew_base(atpdev, 0x3c, n);
1466 if (atp_readl_base(atpdev, 0x38) == 0xffffffff)
1468 for (m = 0; m < 2; m++) {
1469 atpdev->global_map[m] = 0;
1470 for (k = 0; k < 4; k++) {
1471 atp_writew_base(atpdev, 0x3c, n++);
1472 ((u32 *)&setupdata[m][0])[k] =
1473 atp_readl_base(atpdev, 0x38);
1475 for (k = 0; k < 4; k++) {
1476 atp_writew_base(atpdev, 0x3c, n++);
1477 ((u32 *)&atpdev->sp[m][0])[k] =
1478 atp_readl_base(atpdev, 0x38);
1483 c = atp_readb_base(atpdev, 0x29);
1484 atp_writeb_base(atpdev, 0x29, c & 0xfb);
1485 for (c = 0; c < 2; c++) {
1486 atpdev->ultra_map[c] = 0;
1487 atpdev->async[c] = 0;
1488 for (k = 0; k < 16; k++) {
1490 if (atpdev->sp[c][k] > 1)
1491 atpdev->ultra_map[c] |= n;
1493 if (atpdev->sp[c][k] == 0)
1494 atpdev->async[c] |= n;
1496 atpdev->async[c] = ~(atpdev->async[c]);
1498 if (atpdev->global_map[c] == 0) {
1499 k = setupdata[c][1];
1500 if ((k & 0x40) != 0)
1501 atpdev->global_map[c] |= 0x20;
1503 atpdev->global_map[c] |= k;
1504 if ((setupdata[c][2] & 0x04) != 0)
1505 atpdev->global_map[c] |= 0x08;
1506 atpdev->host_id[c] = setupdata[c][0] & 0x07;
1510 k = atp_readb_base(atpdev, 0x28) & 0x8f;
1512 atp_writeb_base(atpdev, 0x28, k);
1513 atp_writeb_pci(atpdev, 0, 1, 0x80);
1514 atp_writeb_pci(atpdev, 1, 1, 0x80);
1516 atp_writeb_pci(atpdev, 0, 1, 0);
1517 atp_writeb_pci(atpdev, 1, 1, 0);
1519 atp_readb_io(atpdev, 0, 0x1b);
1520 atp_readb_io(atpdev, 0, 0x17);
1521 atp_readb_io(atpdev, 1, 0x1b);
1522 atp_readb_io(atpdev, 1, 0x17);
1524 k = atpdev->host_id[0];
1526 k = (k & 0x07) | 0x40;
1527 atp_set_host_id(atpdev, 0, k);
1529 k = atpdev->host_id[1];
1531 k = (k & 0x07) | 0x40;
1532 atp_set_host_id(atpdev, 1, k);
1534 msleep(600); /* this delay used to be called tscam_885() */
1535 dev_info(&pdev->dev, "Scanning Channel A SCSI Device ...\n");
1536 atp_is(atpdev, 0, true, atp_readb_io(atpdev, 0, 0x1b) >> 7);
1537 atp_writeb_io(atpdev, 0, 0x16, 0x80);
1538 dev_info(&pdev->dev, "Scanning Channel B SCSI Device ...\n");
1539 atp_is(atpdev, 1, true, atp_readb_io(atpdev, 1, 0x1b) >> 7);
1540 atp_writeb_io(atpdev, 1, 0x16, 0x80);
1541 k = atp_readb_base(atpdev, 0x28) & 0xcf;
1543 atp_writeb_base(atpdev, 0x28, k);
1544 k = atp_readb_base(atpdev, 0x1f) | 0x80;
1545 atp_writeb_base(atpdev, 0x1f, k);
1546 k = atp_readb_base(atpdev, 0x29) | 0x01;
1547 atp_writeb_base(atpdev, 0x29, k);
1549 shpnt->max_lun = (atpdev->global_map[0] & 0x07) + 1;
1550 shpnt->max_channel = 1;
1551 shpnt->this_id = atpdev->host_id[0];
1554 /* return non-zero on detection */
1555 static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1557 struct Scsi_Host *shpnt = NULL;
1558 struct atp_unit *atpdev;
1561 if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610 && pdev->revision < 2) {
1562 dev_err(&pdev->dev, "ATP850S chips (AEC6710L/F cards) are not supported.\n");
1566 err = pci_enable_device(pdev);
1570 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
1571 printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
1573 goto disable_device;
1576 err = pci_request_regions(pdev, "atp870u");
1578 goto disable_device;
1579 pci_set_master(pdev);
1582 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
1584 goto release_region;
1586 atpdev = shost_priv(shpnt);
1588 atpdev->host = shpnt;
1589 atpdev->pdev = pdev;
1590 pci_set_drvdata(pdev, atpdev);
1592 shpnt->io_port = pci_resource_start(pdev, 0);
1593 shpnt->io_port &= 0xfffffff8;
1594 shpnt->n_io_port = pci_resource_len(pdev, 0);
1595 atpdev->baseport = shpnt->io_port;
1596 shpnt->unique_id = shpnt->io_port;
1597 shpnt->irq = pdev->irq;
1599 err = atp870u_init_tables(shpnt);
1601 dev_err(&pdev->dev, "Unable to allocate tables for Acard controller\n");
1607 else if (is885(atpdev))
1612 err = request_irq(shpnt->irq, atp870u_intr_handle, IRQF_SHARED, "atp870u", shpnt);
1614 dev_err(&pdev->dev, "Unable to allocate IRQ %d.\n", shpnt->irq);
1618 err = scsi_add_host(shpnt, &pdev->dev);
1621 scsi_scan_host(shpnt);
1626 free_irq(shpnt->irq, shpnt);
1628 atp870u_free_tables(shpnt);
1630 scsi_host_put(shpnt);
1632 pci_release_regions(pdev);
1634 pci_disable_device(pdev);
1639 /* The abort command does not leave the device in a clean state where
1640 it is available to be used again. Until this gets worked out, we will
1641 leave it commented out. */
1643 static int atp870u_abort(struct scsi_cmnd * SCpnt)
1645 unsigned char j, k, c;
1646 struct scsi_cmnd *workrequ;
1647 struct atp_unit *dev;
1648 struct Scsi_Host *host;
1649 host = SCpnt->device->host;
1651 dev = (struct atp_unit *)&host->hostdata;
1652 c = scmd_channel(SCpnt);
1653 printk(" atp870u: abort Channel = %x \n", c);
1654 printk("working=%x last_cmd=%x ", dev->working[c], dev->last_cmd[c]);
1655 printk(" quhdu=%x quendu=%x ", dev->quhd[c], dev->quend[c]);
1656 for (j = 0; j < 0x18; j++) {
1657 printk(" r%2x=%2x", j, atp_readb_io(dev, c, j));
1659 printk(" r1c=%2x", atp_readb_io(dev, c, 0x1c));
1660 printk(" r1f=%2x in_snd=%2x ", atp_readb_io(dev, c, 0x1f), dev->in_snd[c]);
1661 printk(" d00=%2x", atp_readb_pci(dev, c, 0x00));
1662 printk(" d02=%2x", atp_readb_pci(dev, c, 0x02));
1664 if (dev->id[c][j].curr_req != NULL) {
1665 workrequ = dev->id[c][j].curr_req;
1666 printk("\n que cdb= ");
1667 for (k=0; k < workrequ->cmd_len; k++) {
1668 printk(" %2x ",workrequ->cmnd[k]);
1670 printk(" last_lenu= %x ",(unsigned int)dev->id[c][j].last_len);
1676 static const char *atp870u_info(struct Scsi_Host *notused)
1678 static char buffer[128];
1680 strcpy(buffer, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
1685 static int atp870u_show_info(struct seq_file *m, struct Scsi_Host *HBAptr)
1687 seq_puts(m, "ACARD AEC-671X Driver Version: 2.6+ac\n\n"
1688 "Adapter Configuration:\n");
1689 seq_printf(m, " Base IO: %#.4lx\n", HBAptr->io_port);
1690 seq_printf(m, " IRQ: %d\n", HBAptr->irq);
1695 static int atp870u_biosparam(struct scsi_device *disk, struct block_device *dev,
1696 sector_t capacity, int *ip)
1698 int heads, sectors, cylinders;
1702 cylinders = (unsigned long)capacity / (heads * sectors);
1703 if (cylinders > 1024) {
1706 cylinders = (unsigned long)capacity / (heads * sectors);
1715 static void atp870u_remove (struct pci_dev *pdev)
1717 struct atp_unit *devext = pci_get_drvdata(pdev);
1718 struct Scsi_Host *pshost = devext->host;
1720 scsi_remove_host(pshost);
1721 free_irq(pshost->irq, pshost);
1722 pci_release_regions(pdev);
1723 pci_disable_device(pdev);
1724 atp870u_free_tables(pshost);
1725 scsi_host_put(pshost);
1727 MODULE_LICENSE("GPL");
1729 static const struct scsi_host_template atp870u_template = {
1730 .module = THIS_MODULE,
1731 .name = "atp870u" /* name */,
1732 .proc_name = "atp870u",
1733 .show_info = atp870u_show_info,
1734 .info = atp870u_info /* info */,
1735 .queuecommand = atp870u_queuecommand /* queuecommand */,
1736 .eh_abort_handler = atp870u_abort /* abort */,
1737 .bios_param = atp870u_biosparam /* biosparm */,
1738 .can_queue = qcnt /* can_queue */,
1739 .this_id = 7 /* SCSI ID */,
1740 .sg_tablesize = ATP870U_SCATTER /*SG_ALL*/,
1741 .max_sectors = ATP870U_MAX_SECTORS,
1744 static struct pci_device_id atp870u_id_table[] = {
1745 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP885_DEVID) },
1746 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID1) },
1747 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID2) },
1748 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7610) },
1749 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612UW) },
1750 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612U) },
1751 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612S) },
1752 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612D) },
1753 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612SUW) },
1754 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_8060) },
1758 MODULE_DEVICE_TABLE(pci, atp870u_id_table);
1760 static struct pci_driver atp870u_driver = {
1761 .id_table = atp870u_id_table,
1763 .probe = atp870u_probe,
1764 .remove = atp870u_remove,
1767 module_pci_driver(atp870u_driver);
1769 static void atp_is(struct atp_unit *dev, unsigned char c, bool wide_chip,
1770 unsigned char lvdmode)
1772 unsigned char i, j, k, rmb, n;
1773 unsigned short int m;
1774 static unsigned char mbuf[512];
1775 static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1776 static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1777 static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1778 unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1779 static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1780 static unsigned char synw_870[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1781 unsigned char synuw[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1782 static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
1783 static unsigned char u3[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1785 for (i = 0; i < 16; i++) {
1786 if (!wide_chip && (i > 7))
1790 if ((m & dev->active_id[c]) != 0) {
1793 if (i == dev->host_id[c]) {
1794 printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[c]);
1797 atp_writeb_io(dev, c, 0x1b, wide_chip ? 0x01 : 0x00);
1798 atp_writeb_io(dev, c, 1, 0x08);
1799 atp_writeb_io(dev, c, 2, 0x7f);
1800 atp_writeb_io(dev, c, 3, satn[0]);
1801 atp_writeb_io(dev, c, 4, satn[1]);
1802 atp_writeb_io(dev, c, 5, satn[2]);
1803 atp_writeb_io(dev, c, 6, satn[3]);
1804 atp_writeb_io(dev, c, 7, satn[4]);
1805 atp_writeb_io(dev, c, 8, satn[5]);
1806 atp_writeb_io(dev, c, 0x0f, 0);
1807 atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp);
1808 atp_writeb_io(dev, c, 0x12, 0);
1809 atp_writeb_io(dev, c, 0x13, satn[6]);
1810 atp_writeb_io(dev, c, 0x14, satn[7]);
1812 if ((j & 0x08) != 0) {
1813 j = (j & 0x07) | 0x40;
1815 atp_writeb_io(dev, c, 0x15, j);
1816 atp_writeb_io(dev, c, 0x18, satn[8]);
1818 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
1821 if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e)
1824 while (atp_readb_io(dev, c, 0x17) != 0x8e)
1827 dev->active_id[c] |= m;
1829 atp_writeb_io(dev, c, 0x10, 0x30);
1830 if (is885(dev) || is880(dev))
1831 atp_writeb_io(dev, c, 0x14, 0x00);
1832 else /* result of is870() merge - is this a bug? */
1833 atp_writeb_io(dev, c, 0x04, 0x00);
1836 atp_writeb_io(dev, c, 0x18, 0x08);
1838 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
1841 j = atp_readb_io(dev, c, 0x17);
1843 atp_writeb_io(dev, c, 0x10, 0x41);
1847 atp_writeb_io(dev, c, 3, inqd[0]);
1848 atp_writeb_io(dev, c, 4, inqd[1]);
1849 atp_writeb_io(dev, c, 5, inqd[2]);
1850 atp_writeb_io(dev, c, 6, inqd[3]);
1851 atp_writeb_io(dev, c, 7, inqd[4]);
1852 atp_writeb_io(dev, c, 8, inqd[5]);
1853 atp_writeb_io(dev, c, 0x0f, 0);
1854 atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp);
1855 atp_writeb_io(dev, c, 0x12, 0);
1856 atp_writeb_io(dev, c, 0x13, inqd[6]);
1857 atp_writeb_io(dev, c, 0x14, inqd[7]);
1858 atp_writeb_io(dev, c, 0x18, inqd[8]);
1860 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
1863 if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e)
1866 while (atp_readb_io(dev, c, 0x17) != 0x8e)
1870 atp_writeb_io(dev, c, 0x1b, 0x00);
1872 atp_writeb_io(dev, c, 0x18, 0x08);
1875 k = atp_readb_io(dev, c, 0x1f);
1876 if ((k & 0x01) != 0) {
1877 mbuf[j++] = atp_readb_io(dev, c, 0x19);
1880 if ((k & 0x80) == 0) {
1883 j = atp_readb_io(dev, c, 0x17);
1887 atp_writeb_io(dev, c, 0x10, 0x46);
1888 atp_writeb_io(dev, c, 0x12, 0);
1889 atp_writeb_io(dev, c, 0x13, 0);
1890 atp_writeb_io(dev, c, 0x14, 0);
1891 atp_writeb_io(dev, c, 0x18, 0x08);
1893 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
1896 if (atp_readb_io(dev, c, 0x17) != 0x16)
1901 printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
1902 dev->id[c][i].devtype = mbuf[0];
1907 if ((mbuf[7] & 0x60) == 0) {
1910 if (is885(dev) || is880(dev)) {
1911 if ((i < 8) && ((dev->global_map[c] & 0x20) == 0))
1913 } else { /* result of is870() merge - is this a bug? */
1914 if ((dev->global_map[c] & 0x20) == 0)
1920 if (dev->sp[c][i] != 0x04) // force u2
1925 atp_writeb_io(dev, c, 0x1b, 0x01);
1926 atp_writeb_io(dev, c, 3, satn[0]);
1927 atp_writeb_io(dev, c, 4, satn[1]);
1928 atp_writeb_io(dev, c, 5, satn[2]);
1929 atp_writeb_io(dev, c, 6, satn[3]);
1930 atp_writeb_io(dev, c, 7, satn[4]);
1931 atp_writeb_io(dev, c, 8, satn[5]);
1932 atp_writeb_io(dev, c, 0x0f, 0);
1933 atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp);
1934 atp_writeb_io(dev, c, 0x12, 0);
1935 atp_writeb_io(dev, c, 0x13, satn[6]);
1936 atp_writeb_io(dev, c, 0x14, satn[7]);
1937 atp_writeb_io(dev, c, 0x18, satn[8]);
1939 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
1942 if (atp_readb_io(dev, c, 0x17) != 0x11 && atp_readb_io(dev, c, 0x17) != 0x8e)
1945 while (atp_readb_io(dev, c, 0x17) != 0x8e)
1950 atp_writeb_io(dev, c, 0x14, 0x09);
1951 atp_writeb_io(dev, c, 0x18, 0x20);
1953 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) {
1954 if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0)
1955 atp_writeb_io(dev, c, 0x19, u3[j++]);
1959 while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00)
1962 j = atp_readb_io(dev, c, 0x17) & 0x0f;
1974 atp_writeb_io(dev, c, 0x18, 0x20);
1975 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) {
1976 if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0)
1977 atp_writeb_io(dev, c, 0x19, 0);
1980 j = atp_readb_io(dev, c, 0x17) & 0x0f;
1992 atp_writeb_io(dev, c, 0x14, 0x09);
1993 atp_writeb_io(dev, c, 0x18, 0x20);
1996 j = atp_readb_io(dev, c, 0x1f);
1997 if ((j & 0x01) != 0) {
1998 mbuf[k++] = atp_readb_io(dev, c, 0x19);
2001 if ((j & 0x80) == 0x00) {
2004 j = atp_readb_io(dev, c, 0x17) & 0x0f;
2016 atp_writeb_io(dev, c, 0x10, 0x30);
2017 atp_writeb_io(dev, c, 0x14, 0x00);
2018 atp_writeb_io(dev, c, 0x18, 0x08);
2020 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00);
2022 j = atp_readb_io(dev, c, 0x17);
2029 if (mbuf[0] != 0x01) {
2032 if (mbuf[1] != 0x06) {
2035 if (mbuf[2] != 0x04) {
2038 if (mbuf[3] == 0x09) {
2041 dev->wide_id[c] |= m;
2042 dev->id[c][i].devsp = 0xce;
2044 printk("dev->id[%2d][%2d].devsp = %2x\n",
2045 c, i, dev->id[c][i].devsp);
2050 atp_writeb_io(dev, c, 0x1b, 0x01);
2051 atp_writeb_io(dev, c, 3, satn[0]);
2052 atp_writeb_io(dev, c, 4, satn[1]);
2053 atp_writeb_io(dev, c, 5, satn[2]);
2054 atp_writeb_io(dev, c, 6, satn[3]);
2055 atp_writeb_io(dev, c, 7, satn[4]);
2056 atp_writeb_io(dev, c, 8, satn[5]);
2057 atp_writeb_io(dev, c, 0x0f, 0);
2058 atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp);
2059 atp_writeb_io(dev, c, 0x12, 0);
2060 atp_writeb_io(dev, c, 0x13, satn[6]);
2061 atp_writeb_io(dev, c, 0x14, satn[7]);
2062 atp_writeb_io(dev, c, 0x18, satn[8]);
2064 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
2067 if (atp_readb_io(dev, c, 0x17) != 0x11 &&
2068 atp_readb_io(dev, c, 0x17) != 0x8e)
2071 while (atp_readb_io(dev, c, 0x17) != 0x8e)
2076 atp_writeb_io(dev, c, 0x14, 0x05);
2077 atp_writeb_io(dev, c, 0x18, 0x20);
2079 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) {
2080 if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0)
2081 atp_writeb_io(dev, c, 0x19, wide[j++]);
2085 while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00)
2088 j = atp_readb_io(dev, c, 0x17) & 0x0f;
2100 atp_writeb_io(dev, c, 0x18, 0x20);
2101 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) {
2102 if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0)
2103 atp_writeb_io(dev, c, 0x19, 0);
2106 j = atp_readb_io(dev, c, 0x17) & 0x0f;
2118 atp_writeb_io(dev, c, 0x14, 0xff);
2119 atp_writeb_io(dev, c, 0x18, 0x20);
2122 j = atp_readb_io(dev, c, 0x1f);
2123 if ((j & 0x01) != 0) {
2124 mbuf[k++] = atp_readb_io(dev, c, 0x19);
2127 if ((j & 0x80) == 0x00) {
2130 j = atp_readb_io(dev, c, 0x17) & 0x0f;
2142 atp_writeb_io(dev, c, 0x10, 0x30);
2143 atp_writeb_io(dev, c, 0x14, 0x00);
2144 atp_writeb_io(dev, c, 0x18, 0x08);
2146 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
2149 j = atp_readb_io(dev, c, 0x17);
2156 if (mbuf[0] != 0x01) {
2159 if (mbuf[1] != 0x02) {
2162 if (mbuf[2] != 0x03) {
2165 if (mbuf[3] != 0x01) {
2170 dev->wide_id[c] |= m;
2172 if ((dev->id[c][i].devtype == 0x00) ||
2173 (dev->id[c][i].devtype == 0x07) ||
2174 ((dev->id[c][i].devtype == 0x05) && ((n & 0x10) != 0))) {
2177 if ((dev->async[c] & m) != 0) {
2183 if ((!is885(dev) && !is880(dev)) || (dev->sp[c][i] == 0x02)) {
2187 if (dev->sp[c][i] >= 0x03) {
2193 if ((m & dev->wide_id[c]) != 0) {
2196 atp_writeb_io(dev, c, 0x1b, j);
2197 atp_writeb_io(dev, c, 3, satn[0]);
2198 atp_writeb_io(dev, c, 4, satn[1]);
2199 atp_writeb_io(dev, c, 5, satn[2]);
2200 atp_writeb_io(dev, c, 6, satn[3]);
2201 atp_writeb_io(dev, c, 7, satn[4]);
2202 atp_writeb_io(dev, c, 8, satn[5]);
2203 atp_writeb_io(dev, c, 0x0f, 0);
2204 atp_writeb_io(dev, c, 0x11, dev->id[c][i].devsp);
2205 atp_writeb_io(dev, c, 0x12, 0);
2206 atp_writeb_io(dev, c, 0x13, satn[6]);
2207 atp_writeb_io(dev, c, 0x14, satn[7]);
2208 atp_writeb_io(dev, c, 0x18, satn[8]);
2210 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
2213 if (atp_readb_io(dev, c, 0x17) != 0x11 &&
2214 atp_readb_io(dev, c, 0x17) != 0x8e)
2217 while (atp_readb_io(dev, c, 0x17) != 0x8e)
2222 atp_writeb_io(dev, c, 0x14, 0x06);
2223 atp_writeb_io(dev, c, 0x18, 0x20);
2225 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0) {
2226 if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0) {
2227 if ((m & dev->wide_id[c]) != 0) {
2228 if (is885(dev) || is880(dev)) {
2229 if ((m & dev->ultra_map[c]) != 0) {
2230 atp_writeb_io(dev, c, 0x19, synuw[j++]);
2232 atp_writeb_io(dev, c, 0x19, synw[j++]);
2235 atp_writeb_io(dev, c, 0x19, synw_870[j++]);
2237 if ((m & dev->ultra_map[c]) != 0) {
2238 atp_writeb_io(dev, c, 0x19, synu[j++]);
2240 atp_writeb_io(dev, c, 0x19, synn[j++]);
2246 while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00)
2249 j = atp_readb_io(dev, c, 0x17) & 0x0f;
2261 atp_writeb_io(dev, c, 0x18, 0x20);
2262 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00) {
2263 if ((atp_readb_io(dev, c, 0x1f) & 0x01) != 0x00)
2264 atp_writeb_io(dev, c, 0x19, 0x00);
2267 j = atp_readb_io(dev, c, 0x17);
2283 if (is885(dev) || is880(dev))
2284 atp_writeb_io(dev, c, 0x14, 0x06);
2286 atp_writeb_io(dev, c, 0x14, 0xff);
2287 atp_writeb_io(dev, c, 0x18, 0x20);
2290 j = atp_readb_io(dev, c, 0x1f);
2291 if ((j & 0x01) != 0x00) {
2292 mbuf[k++] = atp_readb_io(dev, c, 0x19);
2295 if ((j & 0x80) == 0x00) {
2299 while ((atp_readb_io(dev, c, 0x17) & 0x80) == 0x00);
2301 j = atp_readb_io(dev, c, 0x17);
2317 atp_writeb_io(dev, c, 0x10, 0x30);
2319 atp_writeb_io(dev, c, 0x14, 0x00);
2320 atp_writeb_io(dev, c, 0x18, 0x08);
2322 while ((atp_readb_io(dev, c, 0x1f) & 0x80) == 0x00)
2325 j = atp_readb_io(dev, c, 0x17);
2329 if (mbuf[0] != 0x01) {
2332 if (mbuf[1] != 0x03) {
2335 if (mbuf[4] == 0x00) {
2338 if (mbuf[3] > 0x64) {
2341 if (is885(dev) || is880(dev)) {
2342 if (mbuf[4] > 0x0e) {
2346 if (mbuf[4] > 0x0c) {
2350 dev->id[c][i].devsp = mbuf[4];
2351 if (is885(dev) || is880(dev))
2352 if (mbuf[3] < 0x0c) {
2356 if ((mbuf[3] < 0x0d) && (rmb == 0)) {
2360 if (mbuf[3] < 0x1a) {
2364 if (mbuf[3] < 0x33) {
2368 if (mbuf[3] < 0x4c) {
2374 dev->id[c][i].devsp = (dev->id[c][i].devsp & 0x0f) | j;
2376 printk("dev->id[%2d][%2d].devsp = %2x\n",
2377 c,i,dev->id[c][i].devsp);