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>
33 #include <asm/system.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 struct scsi_host_template atp870u_template;
44 static void send_s870(struct atp_unit *dev,unsigned char c);
45 static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c);
46 static void tscam_885(void);
48 static irqreturn_t atp870u_intr_handle(int irq, void *dev_id)
51 unsigned short int tmpcip, id;
52 unsigned char i, j, c, target_id, lun,cmdp;
54 struct scsi_cmnd *workreq;
55 unsigned int workport, tmport, tmport1;
56 unsigned long adrcnt, k;
61 struct Scsi_Host *host = dev_id;
62 struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
64 for (c = 0; c < 2; c++) {
65 tmport = dev->ioport[c] + 0x1f;
76 printk("atp870u_intr_handle enter\n");
79 cmdp = inb(dev->ioport[c] + 0x10);
80 workport = dev->ioport[c];
81 if (dev->working[c] != 0) {
82 if (dev->dev_id == ATP885_DEVID) {
83 tmport1 = workport + 0x16;
84 if ((inb(tmport1) & 0x80) == 0)
85 outb((inb(tmport1) | 0x80), tmport1);
87 tmpcip = dev->pciport[c];
88 if ((inb(tmpcip) & 0x08) != 0)
91 for (k=0; k < 1000; k++) {
92 if ((inb(tmpcip) & 0x08) == 0) {
95 if ((inb(tmpcip) & 0x01) == 0) {
101 tmpcip = dev->pciport[c];
107 if (dev->dev_id == ATP885_DEVID) {
114 target_id = inb(tmport);
118 * Remap wide devices onto id numbers
121 if ((target_id & 0x40) != 0) {
122 target_id = (target_id & 0x07) | 0x08;
127 if ((j & 0x40) != 0) {
128 if (dev->last_cmd[c] == 0xff) {
129 dev->last_cmd[c] = target_id;
131 dev->last_cmd[c] |= 0x40;
133 if (dev->dev_id == ATP885_DEVID)
134 dev->r1f[c][target_id] |= j;
136 printk("atp870u_intr_handle status = %x\n",i);
139 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
140 dev->last_cmd[c] = 0xff;
142 if (dev->dev_id == ATP885_DEVID) {
145 ((unsigned char *) &adrcnt)[2] = inb(tmport++);
146 ((unsigned char *) &adrcnt)[1] = inb(tmport++);
147 ((unsigned char *) &adrcnt)[0] = inb(tmport);
148 if (dev->id[c][target_id].last_len != adrcnt)
150 k = dev->id[c][target_id].last_len;
152 dev->id[c][target_id].tran_len = k;
153 dev->id[c][target_id].last_len = adrcnt;
156 printk("tmport = %x dev->id[c][target_id].last_len = %d dev->id[c][target_id].tran_len = %d\n",tmport,dev->id[c][target_id].last_len,dev->id[c][target_id].tran_len);
163 if (dev->wide_id[c] != 0) {
164 tmport = workport + 0x1b;
166 while ((inb(tmport) & 0x01) != 0x01) {
171 * Issue more commands
173 spin_lock_irqsave(dev->host->host_lock, flags);
174 if (((dev->quhd[c] != dev->quend[c]) || (dev->last_cmd[c] != 0xff)) &&
175 (dev->in_snd[c] == 0)) {
177 printk("Call sent_s870\n");
181 spin_unlock_irqrestore(dev->host->host_lock, flags);
187 printk("Status 0x85 return\n");
193 dev->last_cmd[c] |= 0x40;
199 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
200 dev->last_cmd[c] = 0xff;
204 ((unsigned char *) &adrcnt)[2] = inb(tmport++);
205 ((unsigned char *) &adrcnt)[1] = inb(tmport++);
206 ((unsigned char *) &adrcnt)[0] = inb(tmport);
207 k = dev->id[c][target_id].last_len;
209 dev->id[c][target_id].tran_len = k;
210 dev->id[c][target_id].last_len = adrcnt;
219 if (dev->dev_id == ATP885_DEVID) {
220 if ((i == 0x4c) || (i == 0x4d) || (i == 0x8c) || (i == 0x8d)) {
221 if ((i == 0x4c) || (i == 0x8c))
228 if ((i == 0x80) || (i == 0x8f)) {
230 printk(KERN_DEBUG "Device reselect\n");
234 if (cmdp == 0x44 || i==0x80) {
236 lun = inb(tmport) & 0x07;
238 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
239 dev->last_cmd[c] = 0xff;
243 printk("cmdp = 0x41\n");
247 ((unsigned char *) &adrcnt)[2] = inb(tmport++);
248 ((unsigned char *) &adrcnt)[1] = inb(tmport++);
249 ((unsigned char *) &adrcnt)[0] = inb(tmport);
250 k = dev->id[c][target_id].last_len;
252 dev->id[c][target_id].tran_len = k;
253 dev->id[c][target_id].last_len = adrcnt;
260 printk("cmdp != 0x41\n");
263 dev->id[c][target_id].dirct = 0x00;
265 outb(0x00, tmport++);
266 outb(0x00, tmport++);
267 outb(0x00, tmport++);
274 if (dev->last_cmd[c] != 0xff) {
275 dev->last_cmd[c] |= 0x40;
277 if (dev->dev_id == ATP885_DEVID) {
278 j = inb(dev->baseport + 0x29) & 0xfe;
279 outb(j, dev->baseport + 0x29);
280 tmport = workport + 0x16;
282 tmport = workport + 0x10;
287 target_id = inb(tmport);
289 * Remap wide identifiers
291 if ((target_id & 0x10) != 0) {
292 target_id = (target_id & 0x07) | 0x08;
296 if (dev->dev_id == ATP885_DEVID) {
297 tmport = workport + 0x10;
300 workreq = dev->id[c][target_id].curr_req;
302 scmd_printk(KERN_DEBUG, workreq, "CDB");
303 for (l = 0; l < workreq->cmd_len; l++)
304 printk(KERN_DEBUG " %x",workreq->cmnd[l]);
308 tmport = workport + 0x0f;
311 outb(dev->id[c][target_id].devsp, tmport++);
312 adrcnt = dev->id[c][target_id].tran_len;
313 k = dev->id[c][target_id].last_len;
315 outb(((unsigned char *) &k)[2], tmport++);
316 outb(((unsigned char *) &k)[1], tmport++);
317 outb(((unsigned char *) &k)[0], tmport++);
319 printk("k %x, k[0] 0x%x k[1] 0x%x k[2] 0x%x\n", k, inb(tmport-1), inb(tmport-2), inb(tmport-3));
324 j = (j & 0x07) | 0x40;
327 j |= dev->id[c][target_id].dirct;
331 /* enable 32 bit fifo transfer */
332 if (dev->dev_id == ATP885_DEVID) {
333 tmpcip = dev->pciport[c] + 1;
334 i=inb(tmpcip) & 0xf3;
335 //j=workreq->cmnd[0];
336 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
340 } else if ((dev->dev_id == ATP880_DEVID1) ||
341 (dev->dev_id == ATP880_DEVID2) ) {
342 tmport = workport - 0x05;
343 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
344 outb((unsigned char) ((inb(tmport) & 0x3f) | 0xc0), tmport);
346 outb((unsigned char) (inb(tmport) & 0x3f), tmport);
349 tmport = workport + 0x3a;
350 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
351 outb((unsigned char) ((inb(tmport) & 0xf3) | 0x08), tmport);
353 outb((unsigned char) (inb(tmport) & 0xf3), tmport);
356 tmport = workport + 0x1b;
359 id = id << target_id;
361 * Is this a wide device
363 if ((id & dev->wide_id[c]) != 0) {
367 while ((inb(tmport) & 0x01) != j) {
370 if (dev->id[c][target_id].last_len == 0) {
371 tmport = workport + 0x18;
375 printk("dev->id[c][target_id].last_len = 0\n");
380 printk("target_id = %d adrcnt = %d\n",target_id,adrcnt);
382 prd = dev->id[c][target_id].prd_pos;
383 while (adrcnt != 0) {
384 id = ((unsigned short int *)prd)[2];
391 ((unsigned short int *)prd)[2] = (unsigned short int)
393 ((unsigned long *)prd)[0] += adrcnt;
395 dev->id[c][target_id].prd_pos = prd;
398 dev->id[c][target_id].prdaddr += 0x08;
401 dev->id[c][target_id].prd_pos = prd;
405 tmpcip = dev->pciport[c] + 0x04;
406 outl(dev->id[c][target_id].prdaddr, tmpcip);
408 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c, target_id, dev->id[c][target_id].prdaddr);
410 if (dev->dev_id == ATP885_DEVID) {
418 tmport = workport + 0x18;
420 * Check transfer direction
422 if (dev->id[c][target_id].dirct != 0) {
427 printk("status 0x80 return dirct != 0\n");
435 printk("status 0x80 return dirct = 0\n");
441 * Current scsi request on this target
444 workreq = dev->id[c][target_id].curr_req;
447 if ((dev->last_cmd[c] & 0xf0) != 0x40)
449 dev->last_cmd[c] = 0xff;
452 workreq->result = errstus;
456 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
457 dev->last_cmd[c] = 0xff;
461 errstus = inb(tmport);
462 if (((dev->r1f[c][target_id] & 0x10) != 0)&&(dev->dev_id==ATP885_DEVID)) {
463 printk(KERN_WARNING "AEC67162 CRC ERROR !\n");
466 workreq->result = errstus;
468 if (dev->dev_id == ATP885_DEVID) {
469 j = inb(dev->baseport + 0x29) | 0x01;
470 outb(j, dev->baseport + 0x29);
473 * Complete the command
475 scsi_dma_unmap(workreq);
477 spin_lock_irqsave(dev->host->host_lock, flags);
478 (*workreq->scsi_done) (workreq);
480 printk("workreq->scsi_done\n");
483 * Clear it off the queue
485 dev->id[c][target_id].curr_req = NULL;
487 spin_unlock_irqrestore(dev->host->host_lock, flags);
491 if (dev->wide_id[c] != 0) {
492 tmport = workport + 0x1b;
494 while ((inb(tmport) & 0x01) != 0x01) {
499 * If there is stuff to send and nothing going then send it
501 spin_lock_irqsave(dev->host->host_lock, flags);
502 if (((dev->last_cmd[c] != 0xff) || (dev->quhd[c] != dev->quend[c])) &&
503 (dev->in_snd[c] == 0)) {
505 printk("Call sent_s870(scsi_done)\n");
509 spin_unlock_irqrestore(dev->host->host_lock, flags);
513 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
514 dev->last_cmd[c] = 0xff;
522 outl(dev->id[c][target_id].prdaddr, tmpcip);
527 tmport = workport + 0x10;
529 if (dev->dev_id == ATP885_DEVID) {
531 k = dev->id[c][target_id].last_len;
532 outb((unsigned char) (((unsigned char *) (&k))[2]), tmport++);
533 outb((unsigned char) (((unsigned char *) (&k))[1]), tmport++);
534 outb((unsigned char) (((unsigned char *) (&k))[0]), tmport);
535 dev->id[c][target_id].dirct = 0x00;
538 dev->id[c][target_id].dirct = 0x00;
548 outl(dev->id[c][target_id].prdaddr, tmpcip);
553 tmport = workport + 0x10;
555 if (dev->dev_id == ATP885_DEVID) {
557 k = dev->id[c][target_id].last_len;
558 outb((unsigned char) (((unsigned char *) (&k))[2]), tmport++);
559 outb((unsigned char) (((unsigned char *) (&k))[1]), tmport++);
560 outb((unsigned char) (((unsigned char *) (&k))[0]), tmport++);
564 outb((unsigned char) (inb(tmport) | 0x20), tmport);
565 dev->id[c][target_id].dirct = 0x20;
578 dev->id[c][target_id].dirct = 0x00;
580 outb(0x00, tmport++);
581 outb(0x00, tmport++);
582 outb(0x00, tmport++);
588 // tmport = workport + 0x17;
590 // dev->working[c] = 0;
597 printk("atp870u_intr_handle exit\n");
602 * atp870u_queuecommand - Queue SCSI command
603 * @req_p: request block
604 * @done: completion function
606 * Queue a command to the ATP queue. Called with the host lock held.
608 static int atp870u_queuecommand_lck(struct scsi_cmnd *req_p,
609 void (*done) (struct scsi_cmnd *))
612 unsigned int tmport,m;
613 struct atp_unit *dev;
614 struct Scsi_Host *host;
616 c = scmd_channel(req_p);
617 req_p->sense_buffer[0]=0;
618 scsi_set_resid(req_p, 0);
619 if (scmd_channel(req_p) > 1) {
620 req_p->result = 0x00040000;
623 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
628 host = req_p->device->host;
629 dev = (struct atp_unit *)&host->hostdata;
634 m = m << scmd_id(req_p);
637 * Fake a timeout for missing targets
640 if ((m & dev->active_id[c]) == 0) {
641 req_p->result = 0x00040000;
647 req_p->scsi_done = done;
650 printk( "atp870u_queuecommand: done can't be NULL\n");
661 if (dev->quend[c] >= qcnt) {
668 if (dev->quhd[c] == dev->quend[c]) {
669 if (dev->quend[c] == 0) {
670 dev->quend[c] = qcnt;
673 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
676 req_p->result = 0x00020000;
680 dev->quereq[c][dev->quend[c]] = req_p;
681 tmport = dev->ioport[c] + 0x1c;
683 printk("dev->ioport[c] = %x inb(tmport) = %x dev->in_int[%d] = %d dev->in_snd[%d] = %d\n",dev->ioport[c],inb(tmport),c,dev->in_int[c],c,dev->in_snd[c]);
685 if ((inb(tmport) == 0) && (dev->in_int[c] == 0) && (dev->in_snd[c] == 0)) {
687 printk("Call sent_s870(atp870u_queuecommand)\n");
692 printk("atp870u_queuecommand : exit\n");
697 static DEF_SCSI_QCMD(atp870u_queuecommand)
700 * send_s870 - send a command to the controller
703 * On entry there is work queued to be done. We move some of that work to the
706 * Caller holds the host lock.
708 static void send_s870(struct atp_unit *dev,unsigned char c)
711 struct scsi_cmnd *workreq;
713 unsigned char j, target_id;
715 unsigned short int tmpcip, w;
716 unsigned long l, bttl = 0;
717 unsigned int workport;
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;
733 if (workreq != NULL) { /* check NULL pointer */
736 dev->last_cmd[c] = 0xff;
737 if (dev->quhd[c] == dev->quend[c]) {
742 if ((dev->last_cmd[c] != 0xff) && (dev->working[c] != 0)) {
749 if (dev->quhd[c] >= qcnt) {
752 workreq = dev->quereq[c][dev->quhd[c]];
753 if (dev->id[c][scmd_id(workreq)].curr_req == NULL) {
754 dev->id[c][scmd_id(workreq)].curr_req = workreq;
755 dev->last_cmd[c] = scmd_id(workreq);
763 workport = dev->ioport[c];
764 tmport = workport + 0x1f;
765 if ((inb(tmport) & 0xb0) != 0) {
768 tmport = workport + 0x1c;
769 if (inb(tmport) == 0) {
774 printk("Abort to Send\n");
776 dev->last_cmd[c] |= 0x40;
781 printk("OK to Send\n");
782 scmd_printk(KERN_DEBUG, workreq, "CDB");
783 for(i=0;i<workreq->cmd_len;i++) {
784 printk(" %x",workreq->cmnd[i]);
788 l = scsi_bufflen(workreq);
790 if (dev->dev_id == ATP885_DEVID) {
791 j = inb(dev->baseport + 0x29) & 0xfe;
792 outb(j, dev->baseport + 0x29);
793 dev->r1f[c][scmd_id(workreq)] = 0;
796 if (workreq->cmnd[0] == READ_CAPACITY) {
800 if (workreq->cmnd[0] == 0x00) {
804 tmport = workport + 0x1b;
806 target_id = scmd_id(workreq);
813 if ((w & dev->wide_id[c]) != 0) {
817 while ((inb(tmport) & 0x01) != j) {
820 printk("send_s870 while loop 1\n");
828 outb(workreq->cmd_len, tmport++);
829 outb(0x2c, tmport++);
830 if (dev->dev_id == ATP885_DEVID) {
831 outb(0x7f, tmport++);
833 outb(0xcf, tmport++);
835 for (i = 0; i < workreq->cmd_len; i++) {
836 outb(workreq->cmnd[i], tmport++);
838 tmport = workport + 0x0f;
839 outb(workreq->device->lun, tmport);
844 outb(dev->id[c][target_id].devsp, tmport++);
846 printk("dev->id[%d][%d].devsp = %2x\n",c,target_id,dev->id[c][target_id].devsp);
849 sg_count = scsi_dma_map(workreq);
851 * Write transfer size
853 outb((unsigned char) (((unsigned char *) (&l))[2]), tmport++);
854 outb((unsigned char) (((unsigned char *) (&l))[1]), tmport++);
855 outb((unsigned char) (((unsigned char *) (&l))[0]), tmport++);
857 dev->id[c][j].last_len = l;
858 dev->id[c][j].tran_len = 0;
860 printk("dev->id[%2d][%2d].last_len = %d\n",c,j,dev->id[c][j].last_len);
865 if ((j & 0x08) != 0) {
866 j = (j & 0x07) | 0x40;
869 * Check transfer direction
871 if (workreq->sc_data_direction == DMA_TO_DEVICE) {
872 outb((unsigned char) (j | 0x20), tmport++);
876 outb((unsigned char) (inb(tmport) | 0x80), tmport);
878 tmport = workport + 0x1c;
879 dev->id[c][target_id].dirct = 0;
881 if (inb(tmport) == 0) {
882 tmport = workport + 0x18;
884 printk("change SCSI_CMD_REG 0x08\n");
888 dev->last_cmd[c] |= 0x40;
893 tmpcip = dev->pciport[c];
894 prd = dev->id[c][target_id].prd_table;
895 dev->id[c][target_id].prd_pos = prd;
898 * Now write the request list. Either as scatter/gather or as
903 struct scatterlist *sgpnt;
905 scsi_for_each_sg(workreq, sgpnt, sg_count, j) {
906 bttl = sg_dma_address(sgpnt);
909 printk("1. bttl %x, l %x\n",bttl, l);
911 while (l > 0x10000) {
912 (((u16 *) (prd))[i + 3]) = 0x0000;
913 (((u16 *) (prd))[i + 2]) = 0x0000;
914 (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
919 (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
920 (((u16 *) (prd))[i + 2]) = cpu_to_le16(l);
921 (((u16 *) (prd))[i + 3]) = 0;
924 (((u16 *) (prd))[i - 1]) = cpu_to_le16(0x8000);
926 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]));
927 printk("2. bttl %x, l %x\n",bttl, l);
932 printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev->id[c][target_id].prdaddr,tmpcip,target_id);
934 dev->id[c][target_id].prdaddr = dev->id[c][target_id].prd_bus;
935 outl(dev->id[c][target_id].prdaddr, tmpcip);
939 if (dev->dev_id == ATP885_DEVID) {
941 j=inb(tmpcip) & 0xf3;
942 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) ||
943 (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
948 } else if ((dev->dev_id == ATP880_DEVID1) ||
949 (dev->dev_id == ATP880_DEVID2)) {
951 tmport = workport - 0x05;
952 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
953 outb((unsigned char) ((inb(tmport) & 0x3f) | 0xc0), tmport);
955 outb((unsigned char) (inb(tmport) & 0x3f), tmport);
959 tmport = workport + 0x3a;
960 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
961 outb((inb(tmport) & 0xf3) | 0x08, tmport);
963 outb(inb(tmport) & 0xf3, tmport);
966 tmport = workport + 0x1c;
968 if(workreq->sc_data_direction == DMA_TO_DEVICE) {
969 dev->id[c][target_id].dirct = 0x20;
970 if (inb(tmport) == 0) {
971 tmport = workport + 0x18;
975 printk( "start DMA(to target)\n");
978 dev->last_cmd[c] |= 0x40;
983 if (inb(tmport) == 0) {
984 tmport = workport + 0x18;
988 printk( "start DMA(to host)\n");
991 dev->last_cmd[c] |= 0x40;
998 static unsigned char fun_scam(struct atp_unit *dev, unsigned short int *val)
1000 unsigned int tmport;
1001 unsigned short int i, k;
1004 tmport = dev->ioport[0] + 0x1c;
1007 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
1009 j = (unsigned char) (k >> 8);
1010 if ((k & 0x8000) != 0) { /* DB7 all release? */
1014 *val |= 0x4000; /* assert DB6 */
1016 *val &= 0xdfff; /* assert DB5 */
1019 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
1020 if ((inw(tmport) & 0x2000) != 0) { /* DB5 all release? */
1024 *val |= 0x8000; /* no DB4-0, assert DB7 */
1027 *val &= 0xbfff; /* release DB6 */
1030 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
1031 if ((inw(tmport) & 0x4000) != 0) { /* DB6 all release? */
1039 static void tscam(struct Scsi_Host *host)
1042 unsigned int tmport;
1043 unsigned char i, j, k;
1045 unsigned short int m, assignid_map, val;
1046 unsigned char mbuf[33], quintet[2];
1047 struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
1048 static unsigned char g2q_tab[8] = {
1049 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1052 /* I can't believe we need this before we've even done anything. Remove it
1053 * and see if anyone bitches.
1054 for (i = 0; i < 0x10; i++) {
1059 tmport = dev->ioport[0] + 1;
1060 outb(0x08, tmport++);
1062 tmport = dev->ioport[0] + 0x11;
1065 if ((dev->scam_on & 0x40) == 0) {
1069 m <<= dev->host_id[0];
1071 if (dev->chip_ver < 4) {
1076 tmport = dev->ioport[0] + 0x02;
1077 outb(0x02, tmport++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1085 for (i = 0; i < j; i++) {
1088 if ((m & assignid_map) != 0) {
1091 tmport = dev->ioport[0] + 0x0f;
1098 k = (i & 0x07) | 0x40;
1103 tmport = dev->ioport[0] + 0x1b;
1104 if (dev->chip_ver == 4) {
1110 tmport = dev->ioport[0] + 0x18;
1114 while ((inb(tmport) & 0x80) == 0x00)
1119 if ((k == 0x85) || (k == 0x42)) {
1122 tmport = dev->ioport[0] + 0x10;
1129 tmport = dev->ioport[0] + 0x02;
1131 tmport = dev->ioport[0] + 0x1b;
1136 val = 0x0080; /* bsy */
1137 tmport = dev->ioport[0] + 0x1c;
1139 val |= 0x0040; /* sel */
1141 val |= 0x0004; /* msg */
1143 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1144 val &= 0x007f; /* no bsy */
1147 val &= 0x00fb; /* after 1ms no msg */
1150 if ((inb(tmport) & 0x04) != 0) {
1155 for (n = 0; n < 0x30000; n++) {
1156 if ((inb(tmport) & 0x80) != 0) { /* bsy ? */
1162 for (n = 0; n < 0x30000; n++) {
1163 if ((inb(tmport) & 0x81) == 0x0081) {
1170 val |= 0x8003; /* io,cd,db7 */
1173 val &= 0x00bf; /* no sel */
1178 * The funny division into multiple delays is to accomodate
1179 * arches like ARM where udelay() multiplies its argument by
1180 * a large number to initialize a loop counter. To avoid
1181 * overflow, the maximum supported udelay is 2000 microseconds.
1183 * XXX it would be more polite to find a way to use msleep()
1187 if ((inb(tmport) & 0x80) == 0x00) { /* bsy ? */
1190 tmport = dev->ioport[0] + 0x15;
1195 while ((inb(tmport) & 0x80) == 0)
1201 val &= 0x00ff; /* synchronization */
1203 fun_scam(dev, &val);
1205 val &= 0x00ff; /* isolation */
1207 fun_scam(dev, &val);
1212 if ((inw(tmport) & 0x2000) == 0) {
1216 val &= 0x00ff; /* get ID_STRING */
1218 k = fun_scam(dev, &val);
1219 if ((k & 0x03) == 0) {
1224 if ((k & 0x02) != 0) {
1235 TCM_5: /* isolation complete.. */
1237 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1240 if ((j & 0x20) != 0) { /* bit5=1:ID up to 7 */
1243 if ((j & 0x06) == 0) { /* IDvalid? */
1250 if ((m & assignid_map) == 0) {
1257 G2Q5: /* srch from max acceptable ID# */
1258 k = i; /* max acceptable ID# */
1262 if ((m & assignid_map) == 0) {
1269 G2Q_QUIN: /* k=binID#, */
1272 quintet[0] = 0x38; /* 1st dft ID<8 */
1274 quintet[0] = 0x31; /* 1st ID>=8 */
1277 quintet[1] = g2q_tab[k];
1279 val &= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1280 m = quintet[0] << 8;
1282 fun_scam(dev, &val);
1283 val &= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1284 m = quintet[1] << 8;
1286 fun_scam(dev, &val);
1292 static void is870(struct atp_unit *dev, unsigned int wkport)
1294 unsigned int tmport;
1295 unsigned char i, j, k, rmb, n;
1296 unsigned short int m;
1297 static unsigned char mbuf[512];
1298 static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1299 static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1300 static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1301 static unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1302 static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1303 static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
1305 tmport = wkport + 0x3a;
1306 outb((unsigned char) (inb(tmport) | 0x10), tmport);
1308 for (i = 0; i < 16; i++) {
1309 if ((dev->chip_ver != 4) && (i > 7)) {
1314 if ((m & dev->active_id[0]) != 0) {
1317 if (i == dev->host_id[0]) {
1318 printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
1321 tmport = wkport + 0x1b;
1322 if (dev->chip_ver == 4) {
1327 tmport = wkport + 1;
1328 outb(0x08, tmport++);
1329 outb(0x7f, tmport++);
1330 outb(satn[0], tmport++);
1331 outb(satn[1], tmport++);
1332 outb(satn[2], tmport++);
1333 outb(satn[3], tmport++);
1334 outb(satn[4], tmport++);
1335 outb(satn[5], tmport++);
1339 outb(dev->id[0][i].devsp, tmport++);
1341 outb(satn[6], tmport++);
1342 outb(satn[7], tmport++);
1344 if ((j & 0x08) != 0) {
1345 j = (j & 0x07) | 0x40;
1349 outb(satn[8], tmport);
1352 while ((inb(tmport) & 0x80) == 0x00)
1356 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1359 while (inb(tmport) != 0x8e)
1362 dev->active_id[0] |= m;
1364 tmport = wkport + 0x10;
1366 tmport = wkport + 0x04;
1370 tmport = wkport + 0x18;
1373 while ((inb(tmport) & 0x80) == 0x00)
1378 tmport = wkport + 0x10;
1383 tmport = wkport + 3;
1384 outb(inqd[0], tmport++);
1385 outb(inqd[1], tmport++);
1386 outb(inqd[2], tmport++);
1387 outb(inqd[3], tmport++);
1388 outb(inqd[4], tmport++);
1389 outb(inqd[5], tmport);
1393 outb(dev->id[0][i].devsp, tmport++);
1395 outb(inqd[6], tmport++);
1396 outb(inqd[7], tmport++);
1398 outb(inqd[8], tmport);
1401 while ((inb(tmport) & 0x80) == 0x00)
1405 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1408 while (inb(tmport) != 0x8e)
1411 tmport = wkport + 0x1b;
1412 if (dev->chip_ver == 4)
1415 tmport = wkport + 0x18;
1421 if ((k & 0x01) != 0) {
1423 mbuf[j++] = inb(tmport);
1427 if ((k & 0x80) == 0) {
1435 tmport = wkport + 0x10;
1445 while ((inb(tmport) & 0x80) == 0x00)
1449 if (inb(tmport) != 0x16) {
1454 printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
1455 dev->id[0][i].devtype = mbuf[0];
1458 if (dev->chip_ver != 4) {
1461 if ((mbuf[7] & 0x60) == 0) {
1464 if ((dev->global_map[0] & 0x20) == 0) {
1467 tmport = wkport + 0x1b;
1469 tmport = wkport + 3;
1470 outb(satn[0], tmport++);
1471 outb(satn[1], tmport++);
1472 outb(satn[2], tmport++);
1473 outb(satn[3], tmport++);
1474 outb(satn[4], tmport++);
1475 outb(satn[5], tmport++);
1479 outb(dev->id[0][i].devsp, tmport++);
1481 outb(satn[6], tmport++);
1482 outb(satn[7], tmport++);
1484 outb(satn[8], tmport);
1487 while ((inb(tmport) & 0x80) == 0x00)
1491 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1494 while (inb(tmport) != 0x8e)
1499 tmport = wkport + 0x14;
1505 while ((inb(tmport) & 0x80) == 0) {
1506 if ((inb(tmport) & 0x01) != 0) {
1508 outb(wide[j++], tmport);
1514 while ((inb(tmport) & 0x80) == 0x00)
1517 j = inb(tmport) & 0x0f;
1529 tmport = wkport + 0x18;
1532 while ((inb(tmport) & 0x80) == 0) {
1533 if ((inb(tmport) & 0x01) != 0) {
1540 j = inb(tmport) & 0x0f;
1552 tmport = wkport + 0x14;
1560 if ((j & 0x01) != 0) {
1562 mbuf[k++] = inb(tmport);
1566 if ((j & 0x80) == 0x00) {
1570 j = inb(tmport) & 0x0f;
1582 tmport = wkport + 0x10;
1584 tmport = wkport + 0x14;
1590 while ((inb(tmport) & 0x80) == 0x00)
1601 if (mbuf[0] != 0x01) {
1604 if (mbuf[1] != 0x02) {
1607 if (mbuf[2] != 0x03) {
1610 if (mbuf[3] != 0x01) {
1615 dev->wide_id[0] |= m;
1617 if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
1622 tmport = wkport + 0x1b;
1624 if ((m & dev->wide_id[0]) != 0) {
1628 tmport = wkport + 3;
1629 outb(satn[0], tmport++);
1630 outb(satn[1], tmport++);
1631 outb(satn[2], tmport++);
1632 outb(satn[3], tmport++);
1633 outb(satn[4], tmport++);
1634 outb(satn[5], tmport++);
1638 outb(dev->id[0][i].devsp, tmport++);
1640 outb(satn[6], tmport++);
1641 outb(satn[7], tmport++);
1643 outb(satn[8], tmport);
1646 while ((inb(tmport) & 0x80) == 0x00)
1650 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1653 while (inb(tmport) != 0x8e)
1658 tmport = wkport + 0x14;
1664 while ((inb(tmport) & 0x80) == 0) {
1665 if ((inb(tmport) & 0x01) != 0) {
1667 if ((m & dev->wide_id[0]) != 0) {
1668 outb(synw[j++], tmport);
1670 if ((m & dev->ultra_map[0]) != 0) {
1671 outb(synu[j++], tmport);
1673 outb(synn[j++], tmport);
1681 while ((inb(tmport) & 0x80) == 0x00)
1684 j = inb(tmport) & 0x0f;
1696 tmport = wkport + 0x18;
1699 while ((inb(tmport) & 0x80) == 0x00) {
1700 if ((inb(tmport) & 0x01) != 0x00) {
1723 tmport = wkport + 0x14;
1731 if ((j & 0x01) != 0x00) {
1733 mbuf[k++] = inb(tmport);
1737 if ((j & 0x80) == 0x00) {
1742 while ((inb(tmport) & 0x80) == 0x00)
1761 tmport = wkport + 0x10;
1764 tmport = wkport + 0x14;
1770 while ((inb(tmport) & 0x80) == 0x00)
1778 if (mbuf[0] != 0x01) {
1781 if (mbuf[1] != 0x03) {
1784 if (mbuf[4] == 0x00) {
1787 if (mbuf[3] > 0x64) {
1790 if (mbuf[4] > 0x0c) {
1793 dev->id[0][i].devsp = mbuf[4];
1794 if ((mbuf[3] < 0x0d) && (rmb == 0)) {
1798 if (mbuf[3] < 0x1a) {
1802 if (mbuf[3] < 0x33) {
1806 if (mbuf[3] < 0x4c) {
1812 dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
1814 tmport = wkport + 0x3a;
1815 outb((unsigned char) (inb(tmport) & 0xef), tmport);
1818 static void is880(struct atp_unit *dev, unsigned int wkport)
1820 unsigned int tmport;
1821 unsigned char i, j, k, rmb, n, lvdmode;
1822 unsigned short int m;
1823 static unsigned char mbuf[512];
1824 static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1825 static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1826 static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1827 unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1828 static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1829 unsigned char synuw[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1830 static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
1831 static unsigned char u3[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1833 lvdmode = inb(wkport + 0x3f) & 0x40;
1835 for (i = 0; i < 16; i++) {
1838 if ((m & dev->active_id[0]) != 0) {
1841 if (i == dev->host_id[0]) {
1842 printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
1845 tmport = wkport + 0x5b;
1847 tmport = wkport + 0x41;
1848 outb(0x08, tmport++);
1849 outb(0x7f, tmport++);
1850 outb(satn[0], tmport++);
1851 outb(satn[1], tmport++);
1852 outb(satn[2], tmport++);
1853 outb(satn[3], tmport++);
1854 outb(satn[4], tmport++);
1855 outb(satn[5], tmport++);
1859 outb(dev->id[0][i].devsp, tmport++);
1861 outb(satn[6], tmport++);
1862 outb(satn[7], tmport++);
1864 if ((j & 0x08) != 0) {
1865 j = (j & 0x07) | 0x40;
1869 outb(satn[8], tmport);
1872 while ((inb(tmport) & 0x80) == 0x00)
1876 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1879 while (inb(tmport) != 0x8e)
1882 dev->active_id[0] |= m;
1884 tmport = wkport + 0x50;
1886 tmport = wkport + 0x54;
1890 tmport = wkport + 0x58;
1894 while ((inb(tmport) & 0x80) == 0x00)
1900 tmport = wkport + 0x50;
1905 tmport = wkport + 0x43;
1906 outb(inqd[0], tmport++);
1907 outb(inqd[1], tmport++);
1908 outb(inqd[2], tmport++);
1909 outb(inqd[3], tmport++);
1910 outb(inqd[4], tmport++);
1911 outb(inqd[5], tmport);
1915 outb(dev->id[0][i].devsp, tmport++);
1917 outb(inqd[6], tmport++);
1918 outb(inqd[7], tmport++);
1920 outb(inqd[8], tmport);
1923 while ((inb(tmport) & 0x80) == 0x00)
1927 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1930 while (inb(tmport) != 0x8e)
1933 tmport = wkport + 0x5b;
1935 tmport = wkport + 0x58;
1941 if ((k & 0x01) != 0) {
1943 mbuf[j++] = inb(tmport);
1947 if ((k & 0x80) == 0) {
1955 tmport = wkport + 0x50;
1964 while ((inb(tmport) & 0x80) == 0x00)
1968 if (inb(tmport) != 0x16)
1973 printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
1974 dev->id[0][i].devtype = mbuf[0];
1977 if ((mbuf[7] & 0x60) == 0) {
1980 if ((i < 8) && ((dev->global_map[0] & 0x20) == 0)) {
1986 if (dev->sp[0][i] != 0x04) // force u2
1991 tmport = wkport + 0x5b;
1993 tmport = wkport + 0x43;
1994 outb(satn[0], tmport++);
1995 outb(satn[1], tmport++);
1996 outb(satn[2], tmport++);
1997 outb(satn[3], tmport++);
1998 outb(satn[4], tmport++);
1999 outb(satn[5], tmport++);
2003 outb(dev->id[0][i].devsp, tmport++);
2005 outb(satn[6], tmport++);
2006 outb(satn[7], tmport++);
2008 outb(satn[8], tmport);
2011 while ((inb(tmport) & 0x80) == 0x00)
2016 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
2019 while (inb(tmport) != 0x8e)
2024 tmport = wkport + 0x54;
2030 while ((inb(tmport) & 0x80) == 0) {
2031 if ((inb(tmport) & 0x01) != 0) {
2033 outb(u3[j++], tmport);
2039 while ((inb(tmport) & 0x80) == 0x00)
2042 j = inb(tmport) & 0x0f;
2054 tmport = wkport + 0x58;
2057 while ((inb(tmport) & 0x80) == 0) {
2058 if ((inb(tmport) & 0x01) != 0) {
2065 j = inb(tmport) & 0x0f;
2077 tmport = wkport + 0x54;
2085 if ((j & 0x01) != 0) {
2087 mbuf[k++] = inb(tmport);
2091 if ((j & 0x80) == 0x00) {
2095 j = inb(tmport) & 0x0f;
2107 tmport = wkport + 0x50;
2109 tmport = wkport + 0x54;
2115 while ((inb(tmport) & 0x80) == 0x00)
2126 if (mbuf[0] != 0x01) {
2129 if (mbuf[1] != 0x06) {
2132 if (mbuf[2] != 0x04) {
2135 if (mbuf[3] == 0x09) {
2138 dev->wide_id[0] |= m;
2139 dev->id[0][i].devsp = 0xce;
2143 tmport = wkport + 0x5b;
2145 tmport = wkport + 0x43;
2146 outb(satn[0], tmport++);
2147 outb(satn[1], tmport++);
2148 outb(satn[2], tmport++);
2149 outb(satn[3], tmport++);
2150 outb(satn[4], tmport++);
2151 outb(satn[5], tmport++);
2155 outb(dev->id[0][i].devsp, tmport++);
2157 outb(satn[6], tmport++);
2158 outb(satn[7], tmport++);
2160 outb(satn[8], tmport);
2163 while ((inb(tmport) & 0x80) == 0x00)
2167 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
2170 while (inb(tmport) != 0x8e)
2175 tmport = wkport + 0x54;
2181 while ((inb(tmport) & 0x80) == 0) {
2182 if ((inb(tmport) & 0x01) != 0) {
2184 outb(wide[j++], tmport);
2189 while ((inb(tmport) & 0x80) == 0x00)
2192 j = inb(tmport) & 0x0f;
2204 tmport = wkport + 0x58;
2207 while ((inb(tmport) & 0x80) == 0) {
2208 if ((inb(tmport) & 0x01) != 0) {
2215 j = inb(tmport) & 0x0f;
2227 tmport = wkport + 0x54;
2235 if ((j & 0x01) != 0) {
2237 mbuf[k++] = inb(tmport);
2241 if ((j & 0x80) == 0x00) {
2245 j = inb(tmport) & 0x0f;
2257 tmport = wkport + 0x50;
2259 tmport = wkport + 0x54;
2265 while ((inb(tmport) & 0x80) == 0x00)
2276 if (mbuf[0] != 0x01) {
2279 if (mbuf[1] != 0x02) {
2282 if (mbuf[2] != 0x03) {
2285 if (mbuf[3] != 0x01) {
2290 dev->wide_id[0] |= m;
2292 if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
2295 if ((dev->async[0] & m) != 0) {
2301 if (dev->sp[0][i] == 0x02) {
2305 if (dev->sp[0][i] >= 0x03) {
2310 tmport = wkport + 0x5b;
2312 if ((m & dev->wide_id[0]) != 0) {
2316 tmport = wkport + 0x43;
2317 outb(satn[0], tmport++);
2318 outb(satn[1], tmport++);
2319 outb(satn[2], tmport++);
2320 outb(satn[3], tmport++);
2321 outb(satn[4], tmport++);
2322 outb(satn[5], tmport++);
2326 outb(dev->id[0][i].devsp, tmport++);
2328 outb(satn[6], tmport++);
2329 outb(satn[7], tmport++);
2331 outb(satn[8], tmport);
2334 while ((inb(tmport) & 0x80) == 0x00)
2338 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
2341 while (inb(tmport) != 0x8e)
2346 tmport = wkport + 0x54;
2352 while ((inb(tmport) & 0x80) == 0) {
2353 if ((inb(tmport) & 0x01) != 0) {
2355 if ((m & dev->wide_id[0]) != 0) {
2356 if ((m & dev->ultra_map[0]) != 0) {
2357 outb(synuw[j++], tmport);
2359 outb(synw[j++], tmport);
2362 if ((m & dev->ultra_map[0]) != 0) {
2363 outb(synu[j++], tmport);
2365 outb(synn[j++], tmport);
2373 while ((inb(tmport) & 0x80) == 0x00)
2376 j = inb(tmport) & 0x0f;
2388 tmport = wkport + 0x58;
2391 while ((inb(tmport) & 0x80) == 0x00) {
2392 if ((inb(tmport) & 0x01) != 0x00) {
2415 tmport = wkport + 0x54;
2423 if ((j & 0x01) != 0x00) {
2425 mbuf[k++] = inb(tmport);
2429 if ((j & 0x80) == 0x00) {
2434 while ((inb(tmport) & 0x80) == 0x00)
2453 tmport = wkport + 0x50;
2456 tmport = wkport + 0x54;
2462 while ((inb(tmport) & 0x80) == 0x00)
2470 if (mbuf[0] != 0x01) {
2473 if (mbuf[1] != 0x03) {
2476 if (mbuf[4] == 0x00) {
2479 if (mbuf[3] > 0x64) {
2482 if (mbuf[4] > 0x0e) {
2485 dev->id[0][i].devsp = mbuf[4];
2486 if (mbuf[3] < 0x0c) {
2490 if ((mbuf[3] < 0x0d) && (rmb == 0)) {
2494 if (mbuf[3] < 0x1a) {
2498 if (mbuf[3] < 0x33) {
2502 if (mbuf[3] < 0x4c) {
2508 dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
2512 static void atp870u_free_tables(struct Scsi_Host *host)
2514 struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
2516 for (j=0; j < 2; j++) {
2517 for (k = 0; k < 16; k++) {
2518 if (!atp_dev->id[j][k].prd_table)
2520 pci_free_consistent(atp_dev->pdev, 1024, atp_dev->id[j][k].prd_table, atp_dev->id[j][k].prd_bus);
2521 atp_dev->id[j][k].prd_table = NULL;
2526 static int atp870u_init_tables(struct Scsi_Host *host)
2528 struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
2530 for(c=0;c < 2;c++) {
2532 atp_dev->id[c][k].prd_table = pci_alloc_consistent(atp_dev->pdev, 1024, &(atp_dev->id[c][k].prd_bus));
2533 if (!atp_dev->id[c][k].prd_table) {
2534 printk("atp870u_init_tables fail\n");
2535 atp870u_free_tables(host);
2538 atp_dev->id[c][k].prdaddr = atp_dev->id[c][k].prd_bus;
2539 atp_dev->id[c][k].devsp=0x20;
2540 atp_dev->id[c][k].devtype = 0x7f;
2541 atp_dev->id[c][k].curr_req = NULL;
2544 atp_dev->active_id[c] = 0;
2545 atp_dev->wide_id[c] = 0;
2546 atp_dev->host_id[c] = 0x07;
2547 atp_dev->quhd[c] = 0;
2548 atp_dev->quend[c] = 0;
2549 atp_dev->last_cmd[c] = 0xff;
2550 atp_dev->in_snd[c] = 0;
2551 atp_dev->in_int[c] = 0;
2553 for (k = 0; k < qcnt; k++) {
2554 atp_dev->quereq[c][k] = NULL;
2556 for (k = 0; k < 16; k++) {
2557 atp_dev->id[c][k].curr_req = NULL;
2558 atp_dev->sp[c][k] = 0x04;
2564 /* return non-zero on detection */
2565 static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2567 unsigned char k, m, c;
2568 unsigned long flags;
2569 unsigned int base_io, tmport, error,n;
2570 unsigned char host_id;
2571 struct Scsi_Host *shpnt = NULL;
2572 struct atp_unit *atpdev, *p;
2573 unsigned char setupdata[2][16];
2576 atpdev = kzalloc(sizeof(*atpdev), GFP_KERNEL);
2580 if (pci_enable_device(pdev))
2583 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2584 printk(KERN_INFO "atp870u: use 32bit DMA mask.\n");
2586 printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
2591 * It's probably easier to weed out some revisions like
2592 * this than via the PCI device table
2594 if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) {
2595 error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atpdev->chip_ver);
2596 if (atpdev->chip_ver < 2)
2600 switch (ent->device) {
2601 case PCI_DEVICE_ID_ARTOP_AEC7612UW:
2602 case PCI_DEVICE_ID_ARTOP_AEC7612SUW:
2606 atpdev->chip_ver = 0x04;
2610 base_io = pci_resource_start(pdev, 0);
2611 base_io &= 0xfffffff8;
2613 if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) {
2614 error = pci_read_config_byte(pdev, PCI_CLASS_REVISION, &atpdev->chip_ver);
2615 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803
2617 host_id = inb(base_io + 0x39);
2620 printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2621 " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
2622 atpdev->ioport[0] = base_io + 0x40;
2623 atpdev->pciport[0] = base_io + 0x28;
2624 atpdev->dev_id = ent->device;
2625 atpdev->host_id[0] = host_id;
2627 tmport = base_io + 0x22;
2628 atpdev->scam_on = inb(tmport);
2630 atpdev->global_map[0] = inb(tmport);
2632 atpdev->ultra_map[0] = inw(tmport);
2640 outw(n, base_io + 0x34);
2642 if (inb(base_io + 0x30) == 0xff)
2645 atpdev->sp[0][m++] = inb(base_io + 0x30);
2646 atpdev->sp[0][m++] = inb(base_io + 0x31);
2647 atpdev->sp[0][m++] = inb(base_io + 0x32);
2648 atpdev->sp[0][m++] = inb(base_io + 0x33);
2649 outw(n, base_io + 0x34);
2651 atpdev->sp[0][m++] = inb(base_io + 0x30);
2652 atpdev->sp[0][m++] = inb(base_io + 0x31);
2653 atpdev->sp[0][m++] = inb(base_io + 0x32);
2654 atpdev->sp[0][m++] = inb(base_io + 0x33);
2655 outw(n, base_io + 0x34);
2657 atpdev->sp[0][m++] = inb(base_io + 0x30);
2658 atpdev->sp[0][m++] = inb(base_io + 0x31);
2659 atpdev->sp[0][m++] = inb(base_io + 0x32);
2660 atpdev->sp[0][m++] = inb(base_io + 0x33);
2661 outw(n, base_io + 0x34);
2663 atpdev->sp[0][m++] = inb(base_io + 0x30);
2664 atpdev->sp[0][m++] = inb(base_io + 0x31);
2665 atpdev->sp[0][m++] = inb(base_io + 0x32);
2666 atpdev->sp[0][m++] = inb(base_io + 0x33);
2670 outw(0, base_io + 0x34);
2671 atpdev->ultra_map[0] = 0;
2672 atpdev->async[0] = 0;
2673 for (k = 0; k < 16; k++) {
2676 if (atpdev->sp[0][k] > 1) {
2677 atpdev->ultra_map[0] |= n;
2679 if (atpdev->sp[0][k] == 0)
2680 atpdev->async[0] |= n;
2683 atpdev->async[0] = ~(atpdev->async[0]);
2684 outb(atpdev->global_map[0], base_io + 0x35);
2686 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2690 p = (struct atp_unit *)&shpnt->hostdata;
2692 atpdev->host = shpnt;
2693 atpdev->pdev = pdev;
2694 pci_set_drvdata(pdev, p);
2695 memcpy(p, atpdev, sizeof(*atpdev));
2696 if (atp870u_init_tables(shpnt) < 0) {
2697 printk(KERN_ERR "Unable to allocate tables for Acard controller\n");
2701 if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp880i", shpnt)) {
2702 printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
2706 spin_lock_irqsave(shpnt->host_lock, flags);
2707 tmport = base_io + 0x38;
2708 k = inb(tmport) & 0x80;
2715 tmport = base_io + 0x5b;
2719 tmport = base_io + 0x40;
2720 outb((host_id | 0x08), tmport);
2724 while ((inb(tmport) & 0x80) == 0)
2728 tmport = base_io + 0x41;
2731 tmport = base_io + 0x51;
2736 tmport = base_io + 0x38;
2739 shpnt->this_id = host_id;
2740 shpnt->unique_id = base_io;
2741 shpnt->io_port = base_io;
2742 shpnt->n_io_port = 0x60; /* Number of bytes of I/O space used */
2743 shpnt->irq = pdev->irq;
2744 } else if (ent->device == ATP885_DEVID) {
2745 printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2746 , base_io, pdev->irq);
2748 atpdev->pdev = pdev;
2749 atpdev->dev_id = ent->device;
2750 atpdev->baseport = base_io;
2751 atpdev->ioport[0] = base_io + 0x80;
2752 atpdev->ioport[1] = base_io + 0xc0;
2753 atpdev->pciport[0] = base_io + 0x40;
2754 atpdev->pciport[1] = base_io + 0x50;
2756 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2760 p = (struct atp_unit *)&shpnt->hostdata;
2762 atpdev->host = shpnt;
2763 atpdev->pdev = pdev;
2764 pci_set_drvdata(pdev, p);
2765 memcpy(p, atpdev, sizeof(struct atp_unit));
2766 if (atp870u_init_tables(shpnt) < 0)
2770 printk("request_irq() shpnt %p hostdata %p\n", shpnt, p);
2772 if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870u", shpnt)) {
2773 printk(KERN_ERR "Unable to allocate IRQ for Acard controller.\n");
2777 spin_lock_irqsave(shpnt->host_lock, flags);
2779 c=inb(base_io + 0x29);
2780 outb((c | 0x04),base_io + 0x29);
2787 outw(n,base_io + 0x3c);
2788 if (inl(base_io + 0x38) == 0xffffffff) {
2791 for (m=0; m < 2; m++) {
2792 p->global_map[m]= 0;
2793 for (k=0; k < 4; k++) {
2794 outw(n++,base_io + 0x3c);
2795 ((unsigned long *)&setupdata[m][0])[k]=inl(base_io + 0x38);
2797 for (k=0; k < 4; k++) {
2798 outw(n++,base_io + 0x3c);
2799 ((unsigned long *)&p->sp[m][0])[k]=inl(base_io + 0x38);
2806 printk( "Flash Read OK\n");
2808 c=inb(base_io + 0x29);
2809 outb((c & 0xfb),base_io + 0x29);
2810 for (c=0;c < 2;c++) {
2813 for (k=0; k < 16; k++) {
2816 if (p->sp[c][k] > 1) {
2817 p->ultra_map[c] |= n;
2819 if (p->sp[c][k] == 0) {
2824 p->async[c] = ~(p->async[c]);
2826 if (p->global_map[c] == 0) {
2828 if ((k & 0x40) != 0)
2829 p->global_map[c] |= 0x20;
2831 p->global_map[c] |= k;
2832 if ((setupdata[c][2] & 0x04) != 0)
2833 p->global_map[c] |= 0x08;
2834 p->host_id[c] = setupdata[c][0] & 0x07;
2838 k = inb(base_io + 0x28) & 0x8f;
2840 outb(k, base_io + 0x28);
2841 outb(0x80, base_io + 0x41);
2842 outb(0x80, base_io + 0x51);
2844 outb(0, base_io + 0x41);
2845 outb(0, base_io + 0x51);
2847 inb(base_io + 0x9b);
2848 inb(base_io + 0x97);
2849 inb(base_io + 0xdb);
2850 inb(base_io + 0xd7);
2851 tmport = base_io + 0x80;
2854 k = (k & 0x07) | 0x40;
2861 while ((inb(tmport) & 0x80) == 0)
2866 tmport = base_io + 0x81;
2869 tmport = base_io + 0x91;
2872 tmport = base_io + 0xc0;
2875 k = (k & 0x07) | 0x40;
2882 while ((inb(tmport) & 0x80) == 0)
2887 tmport = base_io + 0xc1;
2890 tmport = base_io + 0xd1;
2894 printk(KERN_INFO " Scanning Channel A SCSI Device ...\n");
2895 is885(p, base_io + 0x80, 0);
2896 printk(KERN_INFO " Scanning Channel B SCSI Device ...\n");
2897 is885(p, base_io + 0xc0, 1);
2899 k = inb(base_io + 0x28) & 0xcf;
2901 outb(k, base_io + 0x28);
2902 k = inb(base_io + 0x1f) | 0x80;
2903 outb(k, base_io + 0x1f);
2904 k = inb(base_io + 0x29) | 0x01;
2905 outb(k, base_io + 0x29);
2907 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2910 shpnt->max_lun = (p->global_map[0] & 0x07) + 1;
2911 shpnt->max_channel = 1;
2912 shpnt->this_id = p->host_id[0];
2913 shpnt->unique_id = base_io;
2914 shpnt->io_port = base_io;
2915 shpnt->n_io_port = 0xff; /* Number of bytes of I/O space used */
2916 shpnt->irq = pdev->irq;
2919 error = pci_read_config_byte(pdev, 0x49, &host_id);
2921 printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2922 "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
2924 atpdev->ioport[0] = base_io;
2925 atpdev->pciport[0] = base_io + 0x20;
2926 atpdev->dev_id = ent->device;
2928 atpdev->host_id[0] = host_id;
2929 tmport = base_io + 0x22;
2930 atpdev->scam_on = inb(tmport);
2932 atpdev->global_map[0] = inb(tmport++);
2933 atpdev->ultra_map[0] = inw(tmport);
2935 if (atpdev->ultra_map[0] == 0) {
2936 atpdev->scam_on = 0x00;
2937 atpdev->global_map[0] = 0x20;
2938 atpdev->ultra_map[0] = 0xffff;
2941 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2945 p = (struct atp_unit *)&shpnt->hostdata;
2947 atpdev->host = shpnt;
2948 atpdev->pdev = pdev;
2949 pci_set_drvdata(pdev, p);
2950 memcpy(p, atpdev, sizeof(*atpdev));
2951 if (atp870u_init_tables(shpnt) < 0)
2954 if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870i", shpnt)) {
2955 printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
2959 spin_lock_irqsave(shpnt->host_lock, flags);
2960 if (atpdev->chip_ver > 0x07) { /* check if atp876 chip then enable terminator */
2961 tmport = base_io + 0x3e;
2965 tmport = base_io + 0x3a;
2966 k = (inb(tmport) & 0xf3) | 0x10;
2968 outb((k & 0xdf), tmport);
2973 outb((host_id | 0x08), tmport);
2977 while ((inb(tmport) & 0x80) == 0)
2982 tmport = base_io + 1;
2985 tmport = base_io + 0x11;
2990 tmport = base_io + 0x3a;
2991 outb((inb(tmport) & 0xef), tmport);
2993 outb((inb(tmport) | 0x20), tmport);
2994 if (atpdev->chip_ver == 4)
2998 shpnt->this_id = host_id;
2999 shpnt->unique_id = base_io;
3000 shpnt->io_port = base_io;
3001 shpnt->n_io_port = 0x40; /* Number of bytes of I/O space used */
3002 shpnt->irq = pdev->irq;
3004 spin_unlock_irqrestore(shpnt->host_lock, flags);
3005 if(ent->device==ATP885_DEVID) {
3006 if(!request_region(base_io, 0xff, "atp870u")) /* Register the IO ports that we use */
3007 goto request_io_fail;
3008 } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
3009 if(!request_region(base_io, 0x60, "atp870u")) /* Register the IO ports that we use */
3010 goto request_io_fail;
3012 if(!request_region(base_io, 0x40, "atp870u")) /* Register the IO ports that we use */
3013 goto request_io_fail;
3016 if (scsi_add_host(shpnt, &pdev->dev))
3018 scsi_scan_host(shpnt);
3020 printk("atp870u_prob : exit\n");
3025 printk("atp870u_prob:scsi_add_fail\n");
3026 if(ent->device==ATP885_DEVID) {
3027 release_region(base_io, 0xff);
3028 } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
3029 release_region(base_io, 0x60);
3031 release_region(base_io, 0x40);
3034 printk("atp870u_prob:request_io_fail\n");
3035 free_irq(pdev->irq, shpnt);
3037 printk("atp870u_prob:free_table\n");
3038 atp870u_free_tables(shpnt);
3040 printk("atp870u_prob:unregister\n");
3041 scsi_host_put(shpnt);
3051 /* The abort command does not leave the device in a clean state where
3052 it is available to be used again. Until this gets worked out, we will
3053 leave it commented out. */
3055 static int atp870u_abort(struct scsi_cmnd * SCpnt)
3057 unsigned char j, k, c;
3058 struct scsi_cmnd *workrequ;
3059 unsigned int tmport;
3060 struct atp_unit *dev;
3061 struct Scsi_Host *host;
3062 host = SCpnt->device->host;
3064 dev = (struct atp_unit *)&host->hostdata;
3065 c = scmd_channel(SCpnt);
3066 printk(" atp870u: abort Channel = %x \n", c);
3067 printk("working=%x last_cmd=%x ", dev->working[c], dev->last_cmd[c]);
3068 printk(" quhdu=%x quendu=%x ", dev->quhd[c], dev->quend[c]);
3069 tmport = dev->ioport[c];
3070 for (j = 0; j < 0x18; j++) {
3071 printk(" r%2x=%2x", j, inb(tmport++));
3074 printk(" r1c=%2x", inb(tmport));
3076 printk(" r1f=%2x in_snd=%2x ", inb(tmport), dev->in_snd[c]);
3077 tmport= dev->pciport[c];
3078 printk(" d00=%2x", inb(tmport));
3080 printk(" d02=%2x", inb(tmport));
3082 if (dev->id[c][j].curr_req != NULL) {
3083 workrequ = dev->id[c][j].curr_req;
3084 printk("\n que cdb= ");
3085 for (k=0; k < workrequ->cmd_len; k++) {
3086 printk(" %2x ",workrequ->cmnd[k]);
3088 printk(" last_lenu= %x ",(unsigned int)dev->id[c][j].last_len);
3094 static const char *atp870u_info(struct Scsi_Host *notused)
3096 static char buffer[128];
3098 strcpy(buffer, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3103 #define BLS buffer + len + size
3104 static int atp870u_proc_info(struct Scsi_Host *HBAptr, char *buffer,
3105 char **start, off_t offset, int length, int inout)
3107 static u8 buff[512];
3116 memset(buff, 0, sizeof(buff));
3117 size += sprintf(BLS, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3122 size += sprintf(BLS, "\n");
3123 size += sprintf(BLS, "Adapter Configuration:\n");
3124 size += sprintf(BLS, " Base IO: %#.4lx\n", HBAptr->io_port);
3125 size += sprintf(BLS, " IRQ: %d\n", HBAptr->irq);
3129 *start = buffer + (offset - begin); /* Start of wanted data */
3130 len -= (offset - begin); /* Start slop */
3132 len = length; /* Ending slop */
3138 static int atp870u_biosparam(struct scsi_device *disk, struct block_device *dev,
3139 sector_t capacity, int *ip)
3141 int heads, sectors, cylinders;
3145 cylinders = (unsigned long)capacity / (heads * sectors);
3146 if (cylinders > 1024) {
3149 cylinders = (unsigned long)capacity / (heads * sectors);
3158 static void atp870u_remove (struct pci_dev *pdev)
3160 struct atp_unit *devext = pci_get_drvdata(pdev);
3161 struct Scsi_Host *pshost = devext->host;
3164 scsi_remove_host(pshost);
3165 printk(KERN_INFO "free_irq : %d\n",pshost->irq);
3166 free_irq(pshost->irq, pshost);
3167 release_region(pshost->io_port, pshost->n_io_port);
3168 printk(KERN_INFO "atp870u_free_tables : %p\n",pshost);
3169 atp870u_free_tables(pshost);
3170 printk(KERN_INFO "scsi_host_put : %p\n",pshost);
3171 scsi_host_put(pshost);
3172 printk(KERN_INFO "pci_set_drvdata : %p\n",pdev);
3173 pci_set_drvdata(pdev, NULL);
3175 MODULE_LICENSE("GPL");
3177 static struct scsi_host_template atp870u_template = {
3178 .module = THIS_MODULE,
3179 .name = "atp870u" /* name */,
3180 .proc_name = "atp870u",
3181 .proc_info = atp870u_proc_info,
3182 .info = atp870u_info /* info */,
3183 .queuecommand = atp870u_queuecommand /* queuecommand */,
3184 .eh_abort_handler = atp870u_abort /* abort */,
3185 .bios_param = atp870u_biosparam /* biosparm */,
3186 .can_queue = qcnt /* can_queue */,
3187 .this_id = 7 /* SCSI ID */,
3188 .sg_tablesize = ATP870U_SCATTER /*SG_ALL*/ /*SG_NONE*/,
3189 .cmd_per_lun = ATP870U_CMDLUN /* commands per lun */,
3190 .use_clustering = ENABLE_CLUSTERING,
3191 .max_sectors = ATP870U_MAX_SECTORS,
3194 static struct pci_device_id atp870u_id_table[] = {
3195 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP885_DEVID) },
3196 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID1) },
3197 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID2) },
3198 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7610) },
3199 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612UW) },
3200 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612U) },
3201 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612S) },
3202 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612D) },
3203 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612SUW) },
3204 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_8060) },
3208 MODULE_DEVICE_TABLE(pci, atp870u_id_table);
3210 static struct pci_driver atp870u_driver = {
3211 .id_table = atp870u_id_table,
3213 .probe = atp870u_probe,
3214 .remove = __devexit_p(atp870u_remove),
3217 static int __init atp870u_init(void)
3220 printk("atp870u_init: Entry\n");
3222 return pci_register_driver(&atp870u_driver);
3225 static void __exit atp870u_exit(void)
3228 printk("atp870u_exit: Entry\n");
3230 pci_unregister_driver(&atp870u_driver);
3233 static void tscam_885(void)
3237 for (i = 0; i < 0x2; i++) {
3245 static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c)
3247 unsigned int tmport;
3248 unsigned char i, j, k, rmb, n, lvdmode;
3249 unsigned short int m;
3250 static unsigned char mbuf[512];
3251 static unsigned char satn[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3252 static unsigned char inqd[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3253 static unsigned char synn[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3254 unsigned char synu[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3255 static unsigned char synw[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3256 unsigned char synuw[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3257 static unsigned char wide[6] = {0x80, 1, 2, 3, 1, 0};
3258 static unsigned char u3[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3260 lvdmode=inb(wkport + 0x1b) >> 7;
3262 for (i = 0; i < 16; i++) {
3265 if ((m & dev->active_id[c]) != 0) {
3268 if (i == dev->host_id[c]) {
3269 printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[c]);
3272 tmport = wkport + 0x1b;
3274 tmport = wkport + 0x01;
3275 outb(0x08, tmport++);
3276 outb(0x7f, tmport++);
3277 outb(satn[0], tmport++);
3278 outb(satn[1], tmport++);
3279 outb(satn[2], tmport++);
3280 outb(satn[3], tmport++);
3281 outb(satn[4], tmport++);
3282 outb(satn[5], tmport++);
3286 outb(dev->id[c][i].devsp, tmport++);
3289 outb(satn[6], tmport++);
3290 outb(satn[7], tmport++);
3292 if ((j & 0x08) != 0) {
3293 j = (j & 0x07) | 0x40;
3297 outb(satn[8], tmport);
3300 while ((inb(tmport) & 0x80) == 0x00)
3303 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3306 while (inb(tmport) != 0x8e)
3308 dev->active_id[c] |= m;
3310 tmport = wkport + 0x10;
3312 tmport = wkport + 0x14;
3316 tmport = wkport + 0x18;
3319 while ((inb(tmport) & 0x80) == 0x00)
3324 tmport = wkport + 0x10;
3329 tmport = wkport + 0x03;
3330 outb(inqd[0], tmport++);
3331 outb(inqd[1], tmport++);
3332 outb(inqd[2], tmport++);
3333 outb(inqd[3], tmport++);
3334 outb(inqd[4], tmport++);
3335 outb(inqd[5], tmport);
3339 outb(dev->id[c][i].devsp, tmport++);
3341 outb(inqd[6], tmport++);
3342 outb(inqd[7], tmport++);
3344 outb(inqd[8], tmport);
3346 while ((inb(tmport) & 0x80) == 0x00)
3349 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3352 while (inb(tmport) != 0x8e)
3354 tmport = wkport + 0x1b;
3356 tmport = wkport + 0x18;
3362 if ((k & 0x01) != 0) {
3364 mbuf[j++] = inb(tmport);
3368 if ((k & 0x80) == 0) {
3376 tmport = wkport + 0x10;
3385 while ((inb(tmport) & 0x80) == 0x00)
3388 if (inb(tmport) != 0x16) {
3393 printk( KERN_INFO" ID: %2d %s\n", i, &mbuf[8]);
3394 dev->id[c][i].devtype = mbuf[0];
3397 if ((mbuf[7] & 0x60) == 0) {
3400 if ((i < 8) && ((dev->global_map[c] & 0x20) == 0)) {
3406 if (dev->sp[c][i] != 0x04) { // force u2
3410 tmport = wkport + 0x1b;
3412 tmport = wkport + 0x03;
3413 outb(satn[0], tmport++);
3414 outb(satn[1], tmport++);
3415 outb(satn[2], tmport++);
3416 outb(satn[3], tmport++);
3417 outb(satn[4], tmport++);
3418 outb(satn[5], tmport++);
3422 outb(dev->id[c][i].devsp, tmport++);
3424 outb(satn[6], tmport++);
3425 outb(satn[7], tmport++);
3427 outb(satn[8], tmport);
3430 while ((inb(tmport) & 0x80) == 0x00)
3433 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3436 while (inb(tmport) != 0x8e)
3440 tmport = wkport + 0x14;
3446 while ((inb(tmport) & 0x80) == 0) {
3447 if ((inb(tmport) & 0x01) != 0) {
3449 outb(u3[j++], tmport);
3455 while ((inb(tmport) & 0x80) == 0x00)
3457 j = inb(tmport) & 0x0f;
3469 tmport = wkport + 0x18;
3472 while ((inb(tmport) & 0x80) == 0) {
3473 if ((inb(tmport) & 0x01) != 0) {
3481 j = inb(tmport) & 0x0f;
3493 tmport = wkport + 0x14;
3501 if ((j & 0x01) != 0) {
3503 mbuf[k++] = inb(tmport);
3507 if ((j & 0x80) == 0x00) {
3511 j = inb(tmport) & 0x0f;
3523 tmport = wkport + 0x10;
3525 tmport = wkport + 0x14;
3530 while ((inb(tmport) & 0x80) == 0x00);
3539 if (mbuf[0] != 0x01) {
3542 if (mbuf[1] != 0x06) {
3545 if (mbuf[2] != 0x04) {
3548 if (mbuf[3] == 0x09) {
3551 dev->wide_id[c] |= m;
3552 dev->id[c][i].devsp = 0xce;
3554 printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
3559 tmport = wkport + 0x1b;
3561 tmport = wkport + 0x03;
3562 outb(satn[0], tmport++);
3563 outb(satn[1], tmport++);
3564 outb(satn[2], tmport++);
3565 outb(satn[3], tmport++);
3566 outb(satn[4], tmport++);
3567 outb(satn[5], tmport++);
3571 outb(dev->id[c][i].devsp, tmport++);
3573 outb(satn[6], tmport++);
3574 outb(satn[7], tmport++);
3576 outb(satn[8], tmport);
3579 while ((inb(tmport) & 0x80) == 0x00)
3582 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3585 while (inb(tmport) != 0x8e)
3589 tmport = wkport + 0x14;
3595 while ((inb(tmport) & 0x80) == 0) {
3596 if ((inb(tmport) & 0x01) != 0) {
3598 outb(wide[j++], tmport);
3604 while ((inb(tmport) & 0x80) == 0x00)
3606 j = inb(tmport) & 0x0f;
3618 tmport = wkport + 0x18;
3621 while ((inb(tmport) & 0x80) == 0) {
3622 if ((inb(tmport) & 0x01) != 0) {
3630 j = inb(tmport) & 0x0f;
3642 tmport = wkport + 0x14;
3650 if ((j & 0x01) != 0) {
3652 mbuf[k++] = inb(tmport);
3656 if ((j & 0x80) == 0x00) {
3660 j = inb(tmport) & 0x0f;
3672 tmport = wkport + 0x10;
3674 tmport = wkport + 0x14;
3679 while ((inb(tmport) & 0x80) == 0x00)
3689 if (mbuf[0] != 0x01) {
3692 if (mbuf[1] != 0x02) {
3695 if (mbuf[2] != 0x03) {
3698 if (mbuf[3] != 0x01) {
3703 dev->wide_id[c] |= m;
3705 if ((dev->id[c][i].devtype == 0x00) || (dev->id[c][i].devtype == 0x07) ||
3706 ((dev->id[c][i].devtype == 0x05) && ((n & 0x10) != 0))) {
3709 if ((dev->async[c] & m) != 0) {
3715 if (dev->sp[c][i] == 0x02) {
3719 if (dev->sp[c][i] >= 0x03) {
3724 tmport = wkport + 0x1b;
3726 if ((m & dev->wide_id[c]) != 0) {
3730 tmport = wkport + 0x03;
3731 outb(satn[0], tmport++);
3732 outb(satn[1], tmport++);
3733 outb(satn[2], tmport++);
3734 outb(satn[3], tmport++);
3735 outb(satn[4], tmport++);
3736 outb(satn[5], tmport++);
3740 outb(dev->id[c][i].devsp, tmport++);
3742 outb(satn[6], tmport++);
3743 outb(satn[7], tmport++);
3745 outb(satn[8], tmport);
3748 while ((inb(tmport) & 0x80) == 0x00)
3751 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3754 while (inb(tmport) != 0x8e)
3758 tmport = wkport + 0x14;
3764 while ((inb(tmport) & 0x80) == 0) {
3765 if ((inb(tmport) & 0x01) != 0) {
3767 if ((m & dev->wide_id[c]) != 0) {
3768 if ((m & dev->ultra_map[c]) != 0) {
3769 outb(synuw[j++], tmport);
3771 outb(synw[j++], tmport);
3774 if ((m & dev->ultra_map[c]) != 0) {
3775 outb(synu[j++], tmport);
3777 outb(synn[j++], tmport);
3784 while ((inb(tmport) & 0x80) == 0x00)
3786 j = inb(tmport) & 0x0f;
3798 tmport = wkport + 0x18;
3801 while ((inb(tmport) & 0x80) == 0x00) {
3802 if ((inb(tmport) & 0x01) != 0x00) {
3826 tmport = wkport + 0x14;
3834 if ((j & 0x01) != 0x00) {
3836 mbuf[k++] = inb(tmport);
3840 if ((j & 0x80) == 0x00) {
3844 while ((inb(tmport) & 0x80) == 0x00);
3861 tmport = wkport + 0x10;
3864 tmport = wkport + 0x14;
3869 while ((inb(tmport) & 0x80) == 0x00)
3876 if (mbuf[0] != 0x01) {
3879 if (mbuf[1] != 0x03) {
3882 if (mbuf[4] == 0x00) {
3885 if (mbuf[3] > 0x64) {
3888 if (mbuf[4] > 0x0e) {
3891 dev->id[c][i].devsp = mbuf[4];
3892 if (mbuf[3] < 0x0c){
3896 if ((mbuf[3] < 0x0d) && (rmb == 0)) {
3900 if (mbuf[3] < 0x1a) {
3904 if (mbuf[3] < 0x33) {
3908 if (mbuf[3] < 0x4c) {
3914 dev->id[c][i].devsp = (dev->id[c][i].devsp & 0x0f) | j;
3916 printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
3919 tmport = wkport + 0x16;
3923 module_init(atp870u_init);
3924 module_exit(atp870u_exit);