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
9 * Wu Ching Chen : NULL pointer fixes 2000/06/02
11 * enable 32 bit fifo transfer
12 * support cdrom & remove device run ultra speed
13 * fix disconnect bug 2000/12/21
14 * support atp880 chip lvd u160 2001/05/15
15 * fix prd table bug 2001/09/12 (7.1)
17 * atp885 support add by ACARD Hao Ping Lian 2005/01/05
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/string.h>
25 #include <linux/ioport.h>
26 #include <linux/delay.h>
27 #include <linux/proc_fs.h>
28 #include <linux/spinlock.h>
29 #include <linux/pci.h>
30 #include <linux/blkdev.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/slab.h>
35 #include <scsi/scsi.h>
36 #include <scsi/scsi_cmnd.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
42 static struct scsi_host_template atp870u_template;
43 static void send_s870(struct atp_unit *dev,unsigned char c);
44 static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c);
45 static void tscam_885(void);
47 static irqreturn_t atp870u_intr_handle(int irq, void *dev_id)
50 unsigned short int tmpcip, id;
51 unsigned char i, j, c, target_id, lun,cmdp;
53 struct scsi_cmnd *workreq;
54 unsigned int workport, tmport, tmport1;
55 unsigned long adrcnt, k;
60 struct Scsi_Host *host = dev_id;
61 struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
63 for (c = 0; c < 2; c++) {
64 tmport = dev->ioport[c] + 0x1f;
75 printk("atp870u_intr_handle enter\n");
78 cmdp = inb(dev->ioport[c] + 0x10);
79 workport = dev->ioport[c];
80 if (dev->working[c] != 0) {
81 if (dev->dev_id == ATP885_DEVID) {
82 tmport1 = workport + 0x16;
83 if ((inb(tmport1) & 0x80) == 0)
84 outb((inb(tmport1) | 0x80), tmport1);
86 tmpcip = dev->pciport[c];
87 if ((inb(tmpcip) & 0x08) != 0)
90 for (k=0; k < 1000; k++) {
91 if ((inb(tmpcip) & 0x08) == 0) {
94 if ((inb(tmpcip) & 0x01) == 0) {
100 tmpcip = dev->pciport[c];
106 if (dev->dev_id == ATP885_DEVID) {
113 target_id = inb(tmport);
117 * Remap wide devices onto id numbers
120 if ((target_id & 0x40) != 0) {
121 target_id = (target_id & 0x07) | 0x08;
126 if ((j & 0x40) != 0) {
127 if (dev->last_cmd[c] == 0xff) {
128 dev->last_cmd[c] = target_id;
130 dev->last_cmd[c] |= 0x40;
132 if (dev->dev_id == ATP885_DEVID)
133 dev->r1f[c][target_id] |= j;
135 printk("atp870u_intr_handle status = %x\n",i);
138 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
139 dev->last_cmd[c] = 0xff;
141 if (dev->dev_id == ATP885_DEVID) {
144 ((unsigned char *) &adrcnt)[2] = inb(tmport++);
145 ((unsigned char *) &adrcnt)[1] = inb(tmport++);
146 ((unsigned char *) &adrcnt)[0] = inb(tmport);
147 if (dev->id[c][target_id].last_len != adrcnt)
149 k = dev->id[c][target_id].last_len;
151 dev->id[c][target_id].tran_len = k;
152 dev->id[c][target_id].last_len = adrcnt;
155 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);
162 if (dev->wide_id[c] != 0) {
163 tmport = workport + 0x1b;
165 while ((inb(tmport) & 0x01) != 0x01) {
170 * Issue more commands
172 spin_lock_irqsave(dev->host->host_lock, flags);
173 if (((dev->quhd[c] != dev->quend[c]) || (dev->last_cmd[c] != 0xff)) &&
174 (dev->in_snd[c] == 0)) {
176 printk("Call sent_s870\n");
180 spin_unlock_irqrestore(dev->host->host_lock, flags);
186 printk("Status 0x85 return\n");
192 dev->last_cmd[c] |= 0x40;
198 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
199 dev->last_cmd[c] = 0xff;
203 ((unsigned char *) &adrcnt)[2] = inb(tmport++);
204 ((unsigned char *) &adrcnt)[1] = inb(tmport++);
205 ((unsigned char *) &adrcnt)[0] = inb(tmport);
206 k = dev->id[c][target_id].last_len;
208 dev->id[c][target_id].tran_len = k;
209 dev->id[c][target_id].last_len = adrcnt;
218 if (dev->dev_id == ATP885_DEVID) {
219 if ((i == 0x4c) || (i == 0x4d) || (i == 0x8c) || (i == 0x8d)) {
220 if ((i == 0x4c) || (i == 0x8c))
227 if ((i == 0x80) || (i == 0x8f)) {
229 printk(KERN_DEBUG "Device reselect\n");
233 if (cmdp == 0x44 || i==0x80) {
235 lun = inb(tmport) & 0x07;
237 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
238 dev->last_cmd[c] = 0xff;
242 printk("cmdp = 0x41\n");
246 ((unsigned char *) &adrcnt)[2] = inb(tmport++);
247 ((unsigned char *) &adrcnt)[1] = inb(tmport++);
248 ((unsigned char *) &adrcnt)[0] = inb(tmport);
249 k = dev->id[c][target_id].last_len;
251 dev->id[c][target_id].tran_len = k;
252 dev->id[c][target_id].last_len = adrcnt;
259 printk("cmdp != 0x41\n");
262 dev->id[c][target_id].dirct = 0x00;
264 outb(0x00, tmport++);
265 outb(0x00, tmport++);
266 outb(0x00, tmport++);
273 if (dev->last_cmd[c] != 0xff) {
274 dev->last_cmd[c] |= 0x40;
276 if (dev->dev_id == ATP885_DEVID) {
277 j = inb(dev->baseport + 0x29) & 0xfe;
278 outb(j, dev->baseport + 0x29);
279 tmport = workport + 0x16;
281 tmport = workport + 0x10;
286 target_id = inb(tmport);
288 * Remap wide identifiers
290 if ((target_id & 0x10) != 0) {
291 target_id = (target_id & 0x07) | 0x08;
295 if (dev->dev_id == ATP885_DEVID) {
296 tmport = workport + 0x10;
299 workreq = dev->id[c][target_id].curr_req;
301 scmd_printk(KERN_DEBUG, workreq, "CDB");
302 for (l = 0; l < workreq->cmd_len; l++)
303 printk(KERN_DEBUG " %x",workreq->cmnd[l]);
307 tmport = workport + 0x0f;
310 outb(dev->id[c][target_id].devsp, tmport++);
311 adrcnt = dev->id[c][target_id].tran_len;
312 k = dev->id[c][target_id].last_len;
314 outb(((unsigned char *) &k)[2], tmport++);
315 outb(((unsigned char *) &k)[1], tmport++);
316 outb(((unsigned char *) &k)[0], tmport++);
318 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));
323 j = (j & 0x07) | 0x40;
326 j |= dev->id[c][target_id].dirct;
330 /* enable 32 bit fifo transfer */
331 if (dev->dev_id == ATP885_DEVID) {
332 tmpcip = dev->pciport[c] + 1;
333 i=inb(tmpcip) & 0xf3;
334 //j=workreq->cmnd[0];
335 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
339 } else if ((dev->dev_id == ATP880_DEVID1) ||
340 (dev->dev_id == ATP880_DEVID2) ) {
341 tmport = workport - 0x05;
342 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
343 outb((unsigned char) ((inb(tmport) & 0x3f) | 0xc0), tmport);
345 outb((unsigned char) (inb(tmport) & 0x3f), tmport);
348 tmport = workport + 0x3a;
349 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
350 outb((unsigned char) ((inb(tmport) & 0xf3) | 0x08), tmport);
352 outb((unsigned char) (inb(tmport) & 0xf3), tmport);
355 tmport = workport + 0x1b;
358 id = id << target_id;
360 * Is this a wide device
362 if ((id & dev->wide_id[c]) != 0) {
366 while ((inb(tmport) & 0x01) != j) {
369 if (dev->id[c][target_id].last_len == 0) {
370 tmport = workport + 0x18;
374 printk("dev->id[c][target_id].last_len = 0\n");
379 printk("target_id = %d adrcnt = %d\n",target_id,adrcnt);
381 prd = dev->id[c][target_id].prd_pos;
382 while (adrcnt != 0) {
383 id = ((unsigned short int *)prd)[2];
390 ((unsigned short int *)prd)[2] = (unsigned short int)
392 ((unsigned long *)prd)[0] += adrcnt;
394 dev->id[c][target_id].prd_pos = prd;
397 dev->id[c][target_id].prdaddr += 0x08;
400 dev->id[c][target_id].prd_pos = prd;
404 tmpcip = dev->pciport[c] + 0x04;
405 outl(dev->id[c][target_id].prdaddr, tmpcip);
407 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c, target_id, dev->id[c][target_id].prdaddr);
409 if (dev->dev_id == ATP885_DEVID) {
417 tmport = workport + 0x18;
419 * Check transfer direction
421 if (dev->id[c][target_id].dirct != 0) {
426 printk("status 0x80 return dirct != 0\n");
434 printk("status 0x80 return dirct = 0\n");
440 * Current scsi request on this target
443 workreq = dev->id[c][target_id].curr_req;
446 if ((dev->last_cmd[c] & 0xf0) != 0x40)
448 dev->last_cmd[c] = 0xff;
451 workreq->result = errstus;
455 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
456 dev->last_cmd[c] = 0xff;
460 errstus = inb(tmport);
461 if (((dev->r1f[c][target_id] & 0x10) != 0)&&(dev->dev_id==ATP885_DEVID)) {
462 printk(KERN_WARNING "AEC67162 CRC ERROR !\n");
465 workreq->result = errstus;
467 if (dev->dev_id == ATP885_DEVID) {
468 j = inb(dev->baseport + 0x29) | 0x01;
469 outb(j, dev->baseport + 0x29);
472 * Complete the command
474 scsi_dma_unmap(workreq);
476 spin_lock_irqsave(dev->host->host_lock, flags);
477 (*workreq->scsi_done) (workreq);
479 printk("workreq->scsi_done\n");
482 * Clear it off the queue
484 dev->id[c][target_id].curr_req = NULL;
486 spin_unlock_irqrestore(dev->host->host_lock, flags);
490 if (dev->wide_id[c] != 0) {
491 tmport = workport + 0x1b;
493 while ((inb(tmport) & 0x01) != 0x01) {
498 * If there is stuff to send and nothing going then send it
500 spin_lock_irqsave(dev->host->host_lock, flags);
501 if (((dev->last_cmd[c] != 0xff) || (dev->quhd[c] != dev->quend[c])) &&
502 (dev->in_snd[c] == 0)) {
504 printk("Call sent_s870(scsi_done)\n");
508 spin_unlock_irqrestore(dev->host->host_lock, flags);
512 if ((dev->last_cmd[c] & 0xf0) != 0x40) {
513 dev->last_cmd[c] = 0xff;
521 outl(dev->id[c][target_id].prdaddr, tmpcip);
526 tmport = workport + 0x10;
528 if (dev->dev_id == ATP885_DEVID) {
530 k = dev->id[c][target_id].last_len;
531 outb((unsigned char) (((unsigned char *) (&k))[2]), tmport++);
532 outb((unsigned char) (((unsigned char *) (&k))[1]), tmport++);
533 outb((unsigned char) (((unsigned char *) (&k))[0]), tmport);
534 dev->id[c][target_id].dirct = 0x00;
537 dev->id[c][target_id].dirct = 0x00;
547 outl(dev->id[c][target_id].prdaddr, tmpcip);
552 tmport = workport + 0x10;
554 if (dev->dev_id == ATP885_DEVID) {
556 k = dev->id[c][target_id].last_len;
557 outb((unsigned char) (((unsigned char *) (&k))[2]), tmport++);
558 outb((unsigned char) (((unsigned char *) (&k))[1]), tmport++);
559 outb((unsigned char) (((unsigned char *) (&k))[0]), tmport++);
563 outb((unsigned char) (inb(tmport) | 0x20), tmport);
564 dev->id[c][target_id].dirct = 0x20;
577 dev->id[c][target_id].dirct = 0x00;
579 outb(0x00, tmport++);
580 outb(0x00, tmport++);
581 outb(0x00, tmport++);
587 // tmport = workport + 0x17;
589 // dev->working[c] = 0;
596 printk("atp870u_intr_handle exit\n");
601 * atp870u_queuecommand - Queue SCSI command
602 * @req_p: request block
603 * @done: completion function
605 * Queue a command to the ATP queue. Called with the host lock held.
607 static int atp870u_queuecommand_lck(struct scsi_cmnd *req_p,
608 void (*done) (struct scsi_cmnd *))
611 unsigned int tmport,m;
612 struct atp_unit *dev;
613 struct Scsi_Host *host;
615 c = scmd_channel(req_p);
616 req_p->sense_buffer[0]=0;
617 scsi_set_resid(req_p, 0);
618 if (scmd_channel(req_p) > 1) {
619 req_p->result = 0x00040000;
622 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
627 host = req_p->device->host;
628 dev = (struct atp_unit *)&host->hostdata;
633 m = m << scmd_id(req_p);
636 * Fake a timeout for missing targets
639 if ((m & dev->active_id[c]) == 0) {
640 req_p->result = 0x00040000;
646 req_p->scsi_done = done;
649 printk( "atp870u_queuecommand: done can't be NULL\n");
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 = 0x00020000;
679 dev->quereq[c][dev->quend[c]] = req_p;
680 tmport = dev->ioport[c] + 0x1c;
682 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]);
684 if ((inb(tmport) == 0) && (dev->in_int[c] == 0) && (dev->in_snd[c] == 0)) {
686 printk("Call sent_s870(atp870u_queuecommand)\n");
691 printk("atp870u_queuecommand : exit\n");
696 static DEF_SCSI_QCMD(atp870u_queuecommand)
699 * send_s870 - send a command to the controller
702 * On entry there is work queued to be done. We move some of that work to the
705 * Caller holds the host lock.
707 static void send_s870(struct atp_unit *dev,unsigned char c)
710 struct scsi_cmnd *workreq;
712 unsigned char j, target_id;
714 unsigned short int tmpcip, w;
715 unsigned long l, bttl = 0;
716 unsigned int workport;
717 unsigned long sg_count;
719 if (dev->in_snd[c] != 0) {
721 printk("cmnd in_snd\n");
726 printk("Sent_s870 enter\n");
729 if ((dev->last_cmd[c] != 0xff) && ((dev->last_cmd[c] & 0x40) != 0)) {
730 dev->last_cmd[c] &= 0x0f;
731 workreq = dev->id[c][dev->last_cmd[c]].curr_req;
732 if (workreq != NULL) { /* check NULL pointer */
735 dev->last_cmd[c] = 0xff;
736 if (dev->quhd[c] == dev->quend[c]) {
741 if ((dev->last_cmd[c] != 0xff) && (dev->working[c] != 0)) {
748 if (dev->quhd[c] >= qcnt) {
751 workreq = dev->quereq[c][dev->quhd[c]];
752 if (dev->id[c][scmd_id(workreq)].curr_req == NULL) {
753 dev->id[c][scmd_id(workreq)].curr_req = workreq;
754 dev->last_cmd[c] = scmd_id(workreq);
762 workport = dev->ioport[c];
763 tmport = workport + 0x1f;
764 if ((inb(tmport) & 0xb0) != 0) {
767 tmport = workport + 0x1c;
768 if (inb(tmport) == 0) {
773 printk("Abort to Send\n");
775 dev->last_cmd[c] |= 0x40;
780 printk("OK to Send\n");
781 scmd_printk(KERN_DEBUG, workreq, "CDB");
782 for(i=0;i<workreq->cmd_len;i++) {
783 printk(" %x",workreq->cmnd[i]);
787 l = scsi_bufflen(workreq);
789 if (dev->dev_id == ATP885_DEVID) {
790 j = inb(dev->baseport + 0x29) & 0xfe;
791 outb(j, dev->baseport + 0x29);
792 dev->r1f[c][scmd_id(workreq)] = 0;
795 if (workreq->cmnd[0] == READ_CAPACITY) {
799 if (workreq->cmnd[0] == 0x00) {
803 tmport = workport + 0x1b;
805 target_id = scmd_id(workreq);
812 if ((w & dev->wide_id[c]) != 0) {
816 while ((inb(tmport) & 0x01) != j) {
819 printk("send_s870 while loop 1\n");
827 outb(workreq->cmd_len, tmport++);
828 outb(0x2c, tmport++);
829 if (dev->dev_id == ATP885_DEVID) {
830 outb(0x7f, tmport++);
832 outb(0xcf, tmport++);
834 for (i = 0; i < workreq->cmd_len; i++) {
835 outb(workreq->cmnd[i], tmport++);
837 tmport = workport + 0x0f;
838 outb(workreq->device->lun, tmport);
843 outb(dev->id[c][target_id].devsp, tmport++);
845 printk("dev->id[%d][%d].devsp = %2x\n",c,target_id,dev->id[c][target_id].devsp);
848 sg_count = scsi_dma_map(workreq);
850 * Write transfer size
852 outb((unsigned char) (((unsigned char *) (&l))[2]), tmport++);
853 outb((unsigned char) (((unsigned char *) (&l))[1]), tmport++);
854 outb((unsigned char) (((unsigned char *) (&l))[0]), tmport++);
856 dev->id[c][j].last_len = l;
857 dev->id[c][j].tran_len = 0;
859 printk("dev->id[%2d][%2d].last_len = %d\n",c,j,dev->id[c][j].last_len);
864 if ((j & 0x08) != 0) {
865 j = (j & 0x07) | 0x40;
868 * Check transfer direction
870 if (workreq->sc_data_direction == DMA_TO_DEVICE) {
871 outb((unsigned char) (j | 0x20), tmport++);
875 outb((unsigned char) (inb(tmport) | 0x80), tmport);
877 tmport = workport + 0x1c;
878 dev->id[c][target_id].dirct = 0;
880 if (inb(tmport) == 0) {
881 tmport = workport + 0x18;
883 printk("change SCSI_CMD_REG 0x08\n");
887 dev->last_cmd[c] |= 0x40;
892 tmpcip = dev->pciport[c];
893 prd = dev->id[c][target_id].prd_table;
894 dev->id[c][target_id].prd_pos = prd;
897 * Now write the request list. Either as scatter/gather or as
902 struct scatterlist *sgpnt;
904 scsi_for_each_sg(workreq, sgpnt, sg_count, j) {
905 bttl = sg_dma_address(sgpnt);
908 printk("1. bttl %x, l %x\n",bttl, l);
910 while (l > 0x10000) {
911 (((u16 *) (prd))[i + 3]) = 0x0000;
912 (((u16 *) (prd))[i + 2]) = 0x0000;
913 (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
918 (((u32 *) (prd))[i >> 1]) = cpu_to_le32(bttl);
919 (((u16 *) (prd))[i + 2]) = cpu_to_le16(l);
920 (((u16 *) (prd))[i + 3]) = 0;
923 (((u16 *) (prd))[i - 1]) = cpu_to_le16(0x8000);
925 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]));
926 printk("2. bttl %x, l %x\n",bttl, l);
931 printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev->id[c][target_id].prdaddr,tmpcip,target_id);
933 dev->id[c][target_id].prdaddr = dev->id[c][target_id].prd_bus;
934 outl(dev->id[c][target_id].prdaddr, tmpcip);
938 if (dev->dev_id == ATP885_DEVID) {
940 j=inb(tmpcip) & 0xf3;
941 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) ||
942 (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
947 } else if ((dev->dev_id == ATP880_DEVID1) ||
948 (dev->dev_id == ATP880_DEVID2)) {
950 tmport = workport - 0x05;
951 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
952 outb((unsigned char) ((inb(tmport) & 0x3f) | 0xc0), tmport);
954 outb((unsigned char) (inb(tmport) & 0x3f), tmport);
958 tmport = workport + 0x3a;
959 if ((workreq->cmnd[0] == 0x08) || (workreq->cmnd[0] == 0x28) || (workreq->cmnd[0] == 0x0a) || (workreq->cmnd[0] == 0x2a)) {
960 outb((inb(tmport) & 0xf3) | 0x08, tmport);
962 outb(inb(tmport) & 0xf3, tmport);
965 tmport = workport + 0x1c;
967 if(workreq->sc_data_direction == DMA_TO_DEVICE) {
968 dev->id[c][target_id].dirct = 0x20;
969 if (inb(tmport) == 0) {
970 tmport = workport + 0x18;
974 printk( "start DMA(to target)\n");
977 dev->last_cmd[c] |= 0x40;
982 if (inb(tmport) == 0) {
983 tmport = workport + 0x18;
987 printk( "start DMA(to host)\n");
990 dev->last_cmd[c] |= 0x40;
997 static unsigned char fun_scam(struct atp_unit *dev, unsigned short int *val)
1000 unsigned short int i, k;
1003 tmport = dev->ioport[0] + 0x1c;
1006 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
1008 j = (unsigned char) (k >> 8);
1009 if ((k & 0x8000) != 0) { /* DB7 all release? */
1013 *val |= 0x4000; /* assert DB6 */
1015 *val &= 0xdfff; /* assert DB5 */
1018 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
1019 if ((inw(tmport) & 0x2000) != 0) { /* DB5 all release? */
1023 *val |= 0x8000; /* no DB4-0, assert DB7 */
1026 *val &= 0xbfff; /* release DB6 */
1029 for (i = 0; i < 10; i++) { /* stable >= bus settle delay(400 ns) */
1030 if ((inw(tmport) & 0x4000) != 0) { /* DB6 all release? */
1038 static void tscam(struct Scsi_Host *host)
1041 unsigned int tmport;
1042 unsigned char i, j, k;
1044 unsigned short int m, assignid_map, val;
1045 unsigned char mbuf[33], quintet[2];
1046 struct atp_unit *dev = (struct atp_unit *)&host->hostdata;
1047 static unsigned char g2q_tab[8] = {
1048 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1051 /* I can't believe we need this before we've even done anything. Remove it
1052 * and see if anyone bitches.
1053 for (i = 0; i < 0x10; i++) {
1058 tmport = dev->ioport[0] + 1;
1059 outb(0x08, tmport++);
1061 tmport = dev->ioport[0] + 0x11;
1064 if ((dev->scam_on & 0x40) == 0) {
1068 m <<= dev->host_id[0];
1070 if (dev->chip_ver < 4) {
1075 tmport = dev->ioport[0] + 0x02;
1076 outb(0x02, tmport++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1084 for (i = 0; i < j; i++) {
1087 if ((m & assignid_map) != 0) {
1090 tmport = dev->ioport[0] + 0x0f;
1097 k = (i & 0x07) | 0x40;
1102 tmport = dev->ioport[0] + 0x1b;
1103 if (dev->chip_ver == 4) {
1109 tmport = dev->ioport[0] + 0x18;
1113 while ((inb(tmport) & 0x80) == 0x00)
1118 if ((k == 0x85) || (k == 0x42)) {
1121 tmport = dev->ioport[0] + 0x10;
1128 tmport = dev->ioport[0] + 0x02;
1130 tmport = dev->ioport[0] + 0x1b;
1135 val = 0x0080; /* bsy */
1136 tmport = dev->ioport[0] + 0x1c;
1138 val |= 0x0040; /* sel */
1140 val |= 0x0004; /* msg */
1142 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1143 val &= 0x007f; /* no bsy */
1146 val &= 0x00fb; /* after 1ms no msg */
1149 if ((inb(tmport) & 0x04) != 0) {
1154 for (n = 0; n < 0x30000; n++) {
1155 if ((inb(tmport) & 0x80) != 0) { /* bsy ? */
1161 for (n = 0; n < 0x30000; n++) {
1162 if ((inb(tmport) & 0x81) == 0x0081) {
1169 val |= 0x8003; /* io,cd,db7 */
1172 val &= 0x00bf; /* no sel */
1177 if ((inb(tmport) & 0x80) == 0x00) { /* bsy ? */
1180 tmport = dev->ioport[0] + 0x15;
1185 while ((inb(tmport) & 0x80) == 0)
1191 val &= 0x00ff; /* synchronization */
1193 fun_scam(dev, &val);
1195 val &= 0x00ff; /* isolation */
1197 fun_scam(dev, &val);
1202 if ((inw(tmport) & 0x2000) == 0) {
1206 val &= 0x00ff; /* get ID_STRING */
1208 k = fun_scam(dev, &val);
1209 if ((k & 0x03) == 0) {
1214 if ((k & 0x02) != 0) {
1225 TCM_5: /* isolation complete.. */
1227 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1230 if ((j & 0x20) != 0) { /* bit5=1:ID up to 7 */
1233 if ((j & 0x06) == 0) { /* IDvalid? */
1240 if ((m & assignid_map) == 0) {
1247 G2Q5: /* srch from max acceptable ID# */
1248 k = i; /* max acceptable ID# */
1252 if ((m & assignid_map) == 0) {
1259 G2Q_QUIN: /* k=binID#, */
1262 quintet[0] = 0x38; /* 1st dft ID<8 */
1264 quintet[0] = 0x31; /* 1st ID>=8 */
1267 quintet[1] = g2q_tab[k];
1269 val &= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1270 m = quintet[0] << 8;
1272 fun_scam(dev, &val);
1273 val &= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1274 m = quintet[1] << 8;
1276 fun_scam(dev, &val);
1282 static void is870(struct atp_unit *dev, unsigned int wkport)
1284 unsigned int tmport;
1285 unsigned char i, j, k, rmb, n;
1286 unsigned short int m;
1287 static unsigned char mbuf[512];
1288 static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1289 static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1290 static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1291 static unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1292 static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1293 static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
1295 tmport = wkport + 0x3a;
1296 outb((unsigned char) (inb(tmport) | 0x10), tmport);
1298 for (i = 0; i < 16; i++) {
1299 if ((dev->chip_ver != 4) && (i > 7)) {
1304 if ((m & dev->active_id[0]) != 0) {
1307 if (i == dev->host_id[0]) {
1308 printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
1311 tmport = wkport + 0x1b;
1312 if (dev->chip_ver == 4) {
1317 tmport = wkport + 1;
1318 outb(0x08, tmport++);
1319 outb(0x7f, tmport++);
1320 outb(satn[0], tmport++);
1321 outb(satn[1], tmport++);
1322 outb(satn[2], tmport++);
1323 outb(satn[3], tmport++);
1324 outb(satn[4], tmport++);
1325 outb(satn[5], tmport++);
1329 outb(dev->id[0][i].devsp, tmport++);
1331 outb(satn[6], tmport++);
1332 outb(satn[7], tmport++);
1334 if ((j & 0x08) != 0) {
1335 j = (j & 0x07) | 0x40;
1339 outb(satn[8], tmport);
1342 while ((inb(tmport) & 0x80) == 0x00)
1346 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1349 while (inb(tmport) != 0x8e)
1352 dev->active_id[0] |= m;
1354 tmport = wkport + 0x10;
1356 tmport = wkport + 0x04;
1360 tmport = wkport + 0x18;
1363 while ((inb(tmport) & 0x80) == 0x00)
1368 tmport = wkport + 0x10;
1373 tmport = wkport + 3;
1374 outb(inqd[0], tmport++);
1375 outb(inqd[1], tmport++);
1376 outb(inqd[2], tmport++);
1377 outb(inqd[3], tmport++);
1378 outb(inqd[4], tmport++);
1379 outb(inqd[5], tmport);
1383 outb(dev->id[0][i].devsp, tmport++);
1385 outb(inqd[6], tmport++);
1386 outb(inqd[7], tmport++);
1388 outb(inqd[8], tmport);
1391 while ((inb(tmport) & 0x80) == 0x00)
1395 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1398 while (inb(tmport) != 0x8e)
1401 tmport = wkport + 0x1b;
1402 if (dev->chip_ver == 4)
1405 tmport = wkport + 0x18;
1411 if ((k & 0x01) != 0) {
1413 mbuf[j++] = inb(tmport);
1417 if ((k & 0x80) == 0) {
1425 tmport = wkport + 0x10;
1435 while ((inb(tmport) & 0x80) == 0x00)
1439 if (inb(tmport) != 0x16) {
1444 printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
1445 dev->id[0][i].devtype = mbuf[0];
1448 if (dev->chip_ver != 4) {
1451 if ((mbuf[7] & 0x60) == 0) {
1454 if ((dev->global_map[0] & 0x20) == 0) {
1457 tmport = wkport + 0x1b;
1459 tmport = wkport + 3;
1460 outb(satn[0], tmport++);
1461 outb(satn[1], tmport++);
1462 outb(satn[2], tmport++);
1463 outb(satn[3], tmport++);
1464 outb(satn[4], tmport++);
1465 outb(satn[5], tmport++);
1469 outb(dev->id[0][i].devsp, tmport++);
1471 outb(satn[6], tmport++);
1472 outb(satn[7], tmport++);
1474 outb(satn[8], tmport);
1477 while ((inb(tmport) & 0x80) == 0x00)
1481 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1484 while (inb(tmport) != 0x8e)
1489 tmport = wkport + 0x14;
1495 while ((inb(tmport) & 0x80) == 0) {
1496 if ((inb(tmport) & 0x01) != 0) {
1498 outb(wide[j++], tmport);
1504 while ((inb(tmport) & 0x80) == 0x00)
1507 j = inb(tmport) & 0x0f;
1519 tmport = wkport + 0x18;
1522 while ((inb(tmport) & 0x80) == 0) {
1523 if ((inb(tmport) & 0x01) != 0) {
1530 j = inb(tmport) & 0x0f;
1542 tmport = wkport + 0x14;
1550 if ((j & 0x01) != 0) {
1552 mbuf[k++] = inb(tmport);
1556 if ((j & 0x80) == 0x00) {
1560 j = inb(tmport) & 0x0f;
1572 tmport = wkport + 0x10;
1574 tmport = wkport + 0x14;
1580 while ((inb(tmport) & 0x80) == 0x00)
1591 if (mbuf[0] != 0x01) {
1594 if (mbuf[1] != 0x02) {
1597 if (mbuf[2] != 0x03) {
1600 if (mbuf[3] != 0x01) {
1605 dev->wide_id[0] |= m;
1607 if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
1612 tmport = wkport + 0x1b;
1614 if ((m & dev->wide_id[0]) != 0) {
1618 tmport = wkport + 3;
1619 outb(satn[0], tmport++);
1620 outb(satn[1], tmport++);
1621 outb(satn[2], tmport++);
1622 outb(satn[3], tmport++);
1623 outb(satn[4], tmport++);
1624 outb(satn[5], tmport++);
1628 outb(dev->id[0][i].devsp, tmport++);
1630 outb(satn[6], tmport++);
1631 outb(satn[7], tmport++);
1633 outb(satn[8], tmport);
1636 while ((inb(tmport) & 0x80) == 0x00)
1640 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1643 while (inb(tmport) != 0x8e)
1648 tmport = wkport + 0x14;
1654 while ((inb(tmport) & 0x80) == 0) {
1655 if ((inb(tmport) & 0x01) != 0) {
1657 if ((m & dev->wide_id[0]) != 0) {
1658 outb(synw[j++], tmport);
1660 if ((m & dev->ultra_map[0]) != 0) {
1661 outb(synu[j++], tmport);
1663 outb(synn[j++], tmport);
1671 while ((inb(tmport) & 0x80) == 0x00)
1674 j = inb(tmport) & 0x0f;
1686 tmport = wkport + 0x18;
1689 while ((inb(tmport) & 0x80) == 0x00) {
1690 if ((inb(tmport) & 0x01) != 0x00) {
1713 tmport = wkport + 0x14;
1721 if ((j & 0x01) != 0x00) {
1723 mbuf[k++] = inb(tmport);
1727 if ((j & 0x80) == 0x00) {
1732 while ((inb(tmport) & 0x80) == 0x00)
1751 tmport = wkport + 0x10;
1754 tmport = wkport + 0x14;
1760 while ((inb(tmport) & 0x80) == 0x00)
1768 if (mbuf[0] != 0x01) {
1771 if (mbuf[1] != 0x03) {
1774 if (mbuf[4] == 0x00) {
1777 if (mbuf[3] > 0x64) {
1780 if (mbuf[4] > 0x0c) {
1783 dev->id[0][i].devsp = mbuf[4];
1784 if ((mbuf[3] < 0x0d) && (rmb == 0)) {
1788 if (mbuf[3] < 0x1a) {
1792 if (mbuf[3] < 0x33) {
1796 if (mbuf[3] < 0x4c) {
1802 dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
1804 tmport = wkport + 0x3a;
1805 outb((unsigned char) (inb(tmport) & 0xef), tmport);
1808 static void is880(struct atp_unit *dev, unsigned int wkport)
1810 unsigned int tmport;
1811 unsigned char i, j, k, rmb, n, lvdmode;
1812 unsigned short int m;
1813 static unsigned char mbuf[512];
1814 static unsigned char satn[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1815 static unsigned char inqd[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1816 static unsigned char synn[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1817 unsigned char synu[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1818 static unsigned char synw[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1819 unsigned char synuw[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1820 static unsigned char wide[6] = { 0x80, 1, 2, 3, 1, 0 };
1821 static unsigned char u3[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1823 lvdmode = inb(wkport + 0x3f) & 0x40;
1825 for (i = 0; i < 16; i++) {
1828 if ((m & dev->active_id[0]) != 0) {
1831 if (i == dev->host_id[0]) {
1832 printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[0]);
1835 tmport = wkport + 0x5b;
1837 tmport = wkport + 0x41;
1838 outb(0x08, tmport++);
1839 outb(0x7f, tmport++);
1840 outb(satn[0], tmport++);
1841 outb(satn[1], tmport++);
1842 outb(satn[2], tmport++);
1843 outb(satn[3], tmport++);
1844 outb(satn[4], tmport++);
1845 outb(satn[5], tmport++);
1849 outb(dev->id[0][i].devsp, tmport++);
1851 outb(satn[6], tmport++);
1852 outb(satn[7], tmport++);
1854 if ((j & 0x08) != 0) {
1855 j = (j & 0x07) | 0x40;
1859 outb(satn[8], tmport);
1862 while ((inb(tmport) & 0x80) == 0x00)
1866 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1869 while (inb(tmport) != 0x8e)
1872 dev->active_id[0] |= m;
1874 tmport = wkport + 0x50;
1876 tmport = wkport + 0x54;
1880 tmport = wkport + 0x58;
1884 while ((inb(tmport) & 0x80) == 0x00)
1890 tmport = wkport + 0x50;
1895 tmport = wkport + 0x43;
1896 outb(inqd[0], tmport++);
1897 outb(inqd[1], tmport++);
1898 outb(inqd[2], tmport++);
1899 outb(inqd[3], tmport++);
1900 outb(inqd[4], tmport++);
1901 outb(inqd[5], tmport);
1905 outb(dev->id[0][i].devsp, tmport++);
1907 outb(inqd[6], tmport++);
1908 outb(inqd[7], tmport++);
1910 outb(inqd[8], tmport);
1913 while ((inb(tmport) & 0x80) == 0x00)
1917 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
1920 while (inb(tmport) != 0x8e)
1923 tmport = wkport + 0x5b;
1925 tmport = wkport + 0x58;
1931 if ((k & 0x01) != 0) {
1933 mbuf[j++] = inb(tmport);
1937 if ((k & 0x80) == 0) {
1945 tmport = wkport + 0x50;
1954 while ((inb(tmport) & 0x80) == 0x00)
1958 if (inb(tmport) != 0x16)
1963 printk(KERN_INFO " ID: %2d %s\n", i, &mbuf[8]);
1964 dev->id[0][i].devtype = mbuf[0];
1967 if ((mbuf[7] & 0x60) == 0) {
1970 if ((i < 8) && ((dev->global_map[0] & 0x20) == 0)) {
1976 if (dev->sp[0][i] != 0x04) // force u2
1981 tmport = wkport + 0x5b;
1983 tmport = wkport + 0x43;
1984 outb(satn[0], tmport++);
1985 outb(satn[1], tmport++);
1986 outb(satn[2], tmport++);
1987 outb(satn[3], tmport++);
1988 outb(satn[4], tmport++);
1989 outb(satn[5], tmport++);
1993 outb(dev->id[0][i].devsp, tmport++);
1995 outb(satn[6], tmport++);
1996 outb(satn[7], tmport++);
1998 outb(satn[8], tmport);
2001 while ((inb(tmport) & 0x80) == 0x00)
2006 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
2009 while (inb(tmport) != 0x8e)
2014 tmport = wkport + 0x54;
2020 while ((inb(tmport) & 0x80) == 0) {
2021 if ((inb(tmport) & 0x01) != 0) {
2023 outb(u3[j++], tmport);
2029 while ((inb(tmport) & 0x80) == 0x00)
2032 j = inb(tmport) & 0x0f;
2044 tmport = wkport + 0x58;
2047 while ((inb(tmport) & 0x80) == 0) {
2048 if ((inb(tmport) & 0x01) != 0) {
2055 j = inb(tmport) & 0x0f;
2067 tmport = wkport + 0x54;
2075 if ((j & 0x01) != 0) {
2077 mbuf[k++] = inb(tmport);
2081 if ((j & 0x80) == 0x00) {
2085 j = inb(tmport) & 0x0f;
2097 tmport = wkport + 0x50;
2099 tmport = wkport + 0x54;
2105 while ((inb(tmport) & 0x80) == 0x00)
2116 if (mbuf[0] != 0x01) {
2119 if (mbuf[1] != 0x06) {
2122 if (mbuf[2] != 0x04) {
2125 if (mbuf[3] == 0x09) {
2128 dev->wide_id[0] |= m;
2129 dev->id[0][i].devsp = 0xce;
2133 tmport = wkport + 0x5b;
2135 tmport = wkport + 0x43;
2136 outb(satn[0], tmport++);
2137 outb(satn[1], tmport++);
2138 outb(satn[2], tmport++);
2139 outb(satn[3], tmport++);
2140 outb(satn[4], tmport++);
2141 outb(satn[5], tmport++);
2145 outb(dev->id[0][i].devsp, tmport++);
2147 outb(satn[6], tmport++);
2148 outb(satn[7], tmport++);
2150 outb(satn[8], tmport);
2153 while ((inb(tmport) & 0x80) == 0x00)
2157 if (inb(tmport) != 0x11 && inb(tmport) != 0x8e)
2160 while (inb(tmport) != 0x8e)
2165 tmport = wkport + 0x54;
2171 while ((inb(tmport) & 0x80) == 0) {
2172 if ((inb(tmport) & 0x01) != 0) {
2174 outb(wide[j++], tmport);
2179 while ((inb(tmport) & 0x80) == 0x00)
2182 j = inb(tmport) & 0x0f;
2194 tmport = wkport + 0x58;
2197 while ((inb(tmport) & 0x80) == 0) {
2198 if ((inb(tmport) & 0x01) != 0) {
2205 j = inb(tmport) & 0x0f;
2217 tmport = wkport + 0x54;
2225 if ((j & 0x01) != 0) {
2227 mbuf[k++] = inb(tmport);
2231 if ((j & 0x80) == 0x00) {
2235 j = inb(tmport) & 0x0f;
2247 tmport = wkport + 0x50;
2249 tmport = wkport + 0x54;
2255 while ((inb(tmport) & 0x80) == 0x00)
2266 if (mbuf[0] != 0x01) {
2269 if (mbuf[1] != 0x02) {
2272 if (mbuf[2] != 0x03) {
2275 if (mbuf[3] != 0x01) {
2280 dev->wide_id[0] |= m;
2282 if ((dev->id[0][i].devtype == 0x00) || (dev->id[0][i].devtype == 0x07) || ((dev->id[0][i].devtype == 0x05) && ((n & 0x10) != 0))) {
2285 if ((dev->async[0] & m) != 0) {
2291 if (dev->sp[0][i] == 0x02) {
2295 if (dev->sp[0][i] >= 0x03) {
2300 tmport = wkport + 0x5b;
2302 if ((m & dev->wide_id[0]) != 0) {
2306 tmport = wkport + 0x43;
2307 outb(satn[0], tmport++);
2308 outb(satn[1], tmport++);
2309 outb(satn[2], tmport++);
2310 outb(satn[3], tmport++);
2311 outb(satn[4], tmport++);
2312 outb(satn[5], tmport++);
2316 outb(dev->id[0][i].devsp, tmport++);
2318 outb(satn[6], tmport++);
2319 outb(satn[7], tmport++);
2321 outb(satn[8], tmport);
2324 while ((inb(tmport) & 0x80) == 0x00)
2328 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
2331 while (inb(tmport) != 0x8e)
2336 tmport = wkport + 0x54;
2342 while ((inb(tmport) & 0x80) == 0) {
2343 if ((inb(tmport) & 0x01) != 0) {
2345 if ((m & dev->wide_id[0]) != 0) {
2346 if ((m & dev->ultra_map[0]) != 0) {
2347 outb(synuw[j++], tmport);
2349 outb(synw[j++], tmport);
2352 if ((m & dev->ultra_map[0]) != 0) {
2353 outb(synu[j++], tmport);
2355 outb(synn[j++], tmport);
2363 while ((inb(tmport) & 0x80) == 0x00)
2366 j = inb(tmport) & 0x0f;
2378 tmport = wkport + 0x58;
2381 while ((inb(tmport) & 0x80) == 0x00) {
2382 if ((inb(tmport) & 0x01) != 0x00) {
2405 tmport = wkport + 0x54;
2413 if ((j & 0x01) != 0x00) {
2415 mbuf[k++] = inb(tmport);
2419 if ((j & 0x80) == 0x00) {
2424 while ((inb(tmport) & 0x80) == 0x00)
2443 tmport = wkport + 0x50;
2446 tmport = wkport + 0x54;
2452 while ((inb(tmport) & 0x80) == 0x00)
2460 if (mbuf[0] != 0x01) {
2463 if (mbuf[1] != 0x03) {
2466 if (mbuf[4] == 0x00) {
2469 if (mbuf[3] > 0x64) {
2472 if (mbuf[4] > 0x0e) {
2475 dev->id[0][i].devsp = mbuf[4];
2476 if (mbuf[3] < 0x0c) {
2480 if ((mbuf[3] < 0x0d) && (rmb == 0)) {
2484 if (mbuf[3] < 0x1a) {
2488 if (mbuf[3] < 0x33) {
2492 if (mbuf[3] < 0x4c) {
2498 dev->id[0][i].devsp = (dev->id[0][i].devsp & 0x0f) | j;
2502 static void atp870u_free_tables(struct Scsi_Host *host)
2504 struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
2506 for (j=0; j < 2; j++) {
2507 for (k = 0; k < 16; k++) {
2508 if (!atp_dev->id[j][k].prd_table)
2510 pci_free_consistent(atp_dev->pdev, 1024, atp_dev->id[j][k].prd_table, atp_dev->id[j][k].prd_bus);
2511 atp_dev->id[j][k].prd_table = NULL;
2516 static int atp870u_init_tables(struct Scsi_Host *host)
2518 struct atp_unit *atp_dev = (struct atp_unit *)&host->hostdata;
2520 for(c=0;c < 2;c++) {
2522 atp_dev->id[c][k].prd_table = pci_alloc_consistent(atp_dev->pdev, 1024, &(atp_dev->id[c][k].prd_bus));
2523 if (!atp_dev->id[c][k].prd_table) {
2524 printk("atp870u_init_tables fail\n");
2525 atp870u_free_tables(host);
2528 atp_dev->id[c][k].prdaddr = atp_dev->id[c][k].prd_bus;
2529 atp_dev->id[c][k].devsp=0x20;
2530 atp_dev->id[c][k].devtype = 0x7f;
2531 atp_dev->id[c][k].curr_req = NULL;
2534 atp_dev->active_id[c] = 0;
2535 atp_dev->wide_id[c] = 0;
2536 atp_dev->host_id[c] = 0x07;
2537 atp_dev->quhd[c] = 0;
2538 atp_dev->quend[c] = 0;
2539 atp_dev->last_cmd[c] = 0xff;
2540 atp_dev->in_snd[c] = 0;
2541 atp_dev->in_int[c] = 0;
2543 for (k = 0; k < qcnt; k++) {
2544 atp_dev->quereq[c][k] = NULL;
2546 for (k = 0; k < 16; k++) {
2547 atp_dev->id[c][k].curr_req = NULL;
2548 atp_dev->sp[c][k] = 0x04;
2554 /* return non-zero on detection */
2555 static int atp870u_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2557 unsigned char k, m, c;
2558 unsigned long flags;
2559 unsigned int base_io, tmport, error,n;
2560 unsigned char host_id;
2561 struct Scsi_Host *shpnt = NULL;
2562 struct atp_unit *atpdev, *p;
2563 unsigned char setupdata[2][16];
2566 atpdev = kzalloc(sizeof(*atpdev), GFP_KERNEL);
2570 if (pci_enable_device(pdev))
2573 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2574 printk(KERN_INFO "atp870u: use 32bit DMA mask.\n");
2576 printk(KERN_ERR "atp870u: DMA mask required but not available.\n");
2581 * It's probably easier to weed out some revisions like
2582 * this than via the PCI device table
2584 if (ent->device == PCI_DEVICE_ID_ARTOP_AEC7610) {
2585 atpdev->chip_ver = pdev->revision;
2586 if (atpdev->chip_ver < 2)
2590 switch (ent->device) {
2591 case PCI_DEVICE_ID_ARTOP_AEC7612UW:
2592 case PCI_DEVICE_ID_ARTOP_AEC7612SUW:
2596 atpdev->chip_ver = 0x04;
2600 base_io = pci_resource_start(pdev, 0);
2601 base_io &= 0xfffffff8;
2603 if ((ent->device == ATP880_DEVID1)||(ent->device == ATP880_DEVID2)) {
2604 atpdev->chip_ver = pdev->revision;
2605 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);//JCC082803
2607 host_id = inb(base_io + 0x39);
2610 printk(KERN_INFO " ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2611 " IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
2612 atpdev->ioport[0] = base_io + 0x40;
2613 atpdev->pciport[0] = base_io + 0x28;
2614 atpdev->dev_id = ent->device;
2615 atpdev->host_id[0] = host_id;
2617 tmport = base_io + 0x22;
2618 atpdev->scam_on = inb(tmport);
2620 atpdev->global_map[0] = inb(tmport);
2622 atpdev->ultra_map[0] = inw(tmport);
2630 outw(n, base_io + 0x34);
2632 if (inb(base_io + 0x30) == 0xff)
2635 atpdev->sp[0][m++] = inb(base_io + 0x30);
2636 atpdev->sp[0][m++] = inb(base_io + 0x31);
2637 atpdev->sp[0][m++] = inb(base_io + 0x32);
2638 atpdev->sp[0][m++] = inb(base_io + 0x33);
2639 outw(n, base_io + 0x34);
2641 atpdev->sp[0][m++] = inb(base_io + 0x30);
2642 atpdev->sp[0][m++] = inb(base_io + 0x31);
2643 atpdev->sp[0][m++] = inb(base_io + 0x32);
2644 atpdev->sp[0][m++] = inb(base_io + 0x33);
2645 outw(n, base_io + 0x34);
2647 atpdev->sp[0][m++] = inb(base_io + 0x30);
2648 atpdev->sp[0][m++] = inb(base_io + 0x31);
2649 atpdev->sp[0][m++] = inb(base_io + 0x32);
2650 atpdev->sp[0][m++] = inb(base_io + 0x33);
2651 outw(n, base_io + 0x34);
2653 atpdev->sp[0][m++] = inb(base_io + 0x30);
2654 atpdev->sp[0][m++] = inb(base_io + 0x31);
2655 atpdev->sp[0][m++] = inb(base_io + 0x32);
2656 atpdev->sp[0][m++] = inb(base_io + 0x33);
2660 outw(0, base_io + 0x34);
2661 atpdev->ultra_map[0] = 0;
2662 atpdev->async[0] = 0;
2663 for (k = 0; k < 16; k++) {
2666 if (atpdev->sp[0][k] > 1) {
2667 atpdev->ultra_map[0] |= n;
2669 if (atpdev->sp[0][k] == 0)
2670 atpdev->async[0] |= n;
2673 atpdev->async[0] = ~(atpdev->async[0]);
2674 outb(atpdev->global_map[0], base_io + 0x35);
2676 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2680 p = (struct atp_unit *)&shpnt->hostdata;
2682 atpdev->host = shpnt;
2683 atpdev->pdev = pdev;
2684 pci_set_drvdata(pdev, p);
2685 memcpy(p, atpdev, sizeof(*atpdev));
2686 if (atp870u_init_tables(shpnt) < 0) {
2687 printk(KERN_ERR "Unable to allocate tables for Acard controller\n");
2691 if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp880i", shpnt)) {
2692 printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
2696 spin_lock_irqsave(shpnt->host_lock, flags);
2697 tmport = base_io + 0x38;
2698 k = inb(tmport) & 0x80;
2705 tmport = base_io + 0x5b;
2709 tmport = base_io + 0x40;
2710 outb((host_id | 0x08), tmport);
2714 while ((inb(tmport) & 0x80) == 0)
2718 tmport = base_io + 0x41;
2721 tmport = base_io + 0x51;
2726 tmport = base_io + 0x38;
2729 shpnt->this_id = host_id;
2730 shpnt->unique_id = base_io;
2731 shpnt->io_port = base_io;
2732 shpnt->n_io_port = 0x60; /* Number of bytes of I/O space used */
2733 shpnt->irq = pdev->irq;
2734 } else if (ent->device == ATP885_DEVID) {
2735 printk(KERN_INFO " ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2736 , base_io, pdev->irq);
2738 atpdev->pdev = pdev;
2739 atpdev->dev_id = ent->device;
2740 atpdev->baseport = base_io;
2741 atpdev->ioport[0] = base_io + 0x80;
2742 atpdev->ioport[1] = base_io + 0xc0;
2743 atpdev->pciport[0] = base_io + 0x40;
2744 atpdev->pciport[1] = base_io + 0x50;
2746 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2750 p = (struct atp_unit *)&shpnt->hostdata;
2752 atpdev->host = shpnt;
2753 atpdev->pdev = pdev;
2754 pci_set_drvdata(pdev, p);
2755 memcpy(p, atpdev, sizeof(struct atp_unit));
2756 if (atp870u_init_tables(shpnt) < 0)
2760 printk("request_irq() shpnt %p hostdata %p\n", shpnt, p);
2762 if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870u", shpnt)) {
2763 printk(KERN_ERR "Unable to allocate IRQ for Acard controller.\n");
2767 spin_lock_irqsave(shpnt->host_lock, flags);
2769 c=inb(base_io + 0x29);
2770 outb((c | 0x04),base_io + 0x29);
2777 outw(n,base_io + 0x3c);
2778 if (inl(base_io + 0x38) == 0xffffffff) {
2781 for (m=0; m < 2; m++) {
2782 p->global_map[m]= 0;
2783 for (k=0; k < 4; k++) {
2784 outw(n++,base_io + 0x3c);
2785 ((unsigned long *)&setupdata[m][0])[k]=inl(base_io + 0x38);
2787 for (k=0; k < 4; k++) {
2788 outw(n++,base_io + 0x3c);
2789 ((unsigned long *)&p->sp[m][0])[k]=inl(base_io + 0x38);
2796 printk( "Flash Read OK\n");
2798 c=inb(base_io + 0x29);
2799 outb((c & 0xfb),base_io + 0x29);
2800 for (c=0;c < 2;c++) {
2803 for (k=0; k < 16; k++) {
2806 if (p->sp[c][k] > 1) {
2807 p->ultra_map[c] |= n;
2809 if (p->sp[c][k] == 0) {
2814 p->async[c] = ~(p->async[c]);
2816 if (p->global_map[c] == 0) {
2818 if ((k & 0x40) != 0)
2819 p->global_map[c] |= 0x20;
2821 p->global_map[c] |= k;
2822 if ((setupdata[c][2] & 0x04) != 0)
2823 p->global_map[c] |= 0x08;
2824 p->host_id[c] = setupdata[c][0] & 0x07;
2828 k = inb(base_io + 0x28) & 0x8f;
2830 outb(k, base_io + 0x28);
2831 outb(0x80, base_io + 0x41);
2832 outb(0x80, base_io + 0x51);
2834 outb(0, base_io + 0x41);
2835 outb(0, base_io + 0x51);
2837 inb(base_io + 0x9b);
2838 inb(base_io + 0x97);
2839 inb(base_io + 0xdb);
2840 inb(base_io + 0xd7);
2841 tmport = base_io + 0x80;
2844 k = (k & 0x07) | 0x40;
2851 while ((inb(tmport) & 0x80) == 0)
2856 tmport = base_io + 0x81;
2859 tmport = base_io + 0x91;
2862 tmport = base_io + 0xc0;
2865 k = (k & 0x07) | 0x40;
2872 while ((inb(tmport) & 0x80) == 0)
2877 tmport = base_io + 0xc1;
2880 tmport = base_io + 0xd1;
2884 printk(KERN_INFO " Scanning Channel A SCSI Device ...\n");
2885 is885(p, base_io + 0x80, 0);
2886 printk(KERN_INFO " Scanning Channel B SCSI Device ...\n");
2887 is885(p, base_io + 0xc0, 1);
2889 k = inb(base_io + 0x28) & 0xcf;
2891 outb(k, base_io + 0x28);
2892 k = inb(base_io + 0x1f) | 0x80;
2893 outb(k, base_io + 0x1f);
2894 k = inb(base_io + 0x29) | 0x01;
2895 outb(k, base_io + 0x29);
2897 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2900 shpnt->max_lun = (p->global_map[0] & 0x07) + 1;
2901 shpnt->max_channel = 1;
2902 shpnt->this_id = p->host_id[0];
2903 shpnt->unique_id = base_io;
2904 shpnt->io_port = base_io;
2905 shpnt->n_io_port = 0xff; /* Number of bytes of I/O space used */
2906 shpnt->irq = pdev->irq;
2909 error = pci_read_config_byte(pdev, 0x49, &host_id);
2911 printk(KERN_INFO " ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2912 "IO:%x, IRQ:%d.\n", count, base_io, pdev->irq);
2914 atpdev->ioport[0] = base_io;
2915 atpdev->pciport[0] = base_io + 0x20;
2916 atpdev->dev_id = ent->device;
2918 atpdev->host_id[0] = host_id;
2919 tmport = base_io + 0x22;
2920 atpdev->scam_on = inb(tmport);
2922 atpdev->global_map[0] = inb(tmport++);
2923 atpdev->ultra_map[0] = inw(tmport);
2925 if (atpdev->ultra_map[0] == 0) {
2926 atpdev->scam_on = 0x00;
2927 atpdev->global_map[0] = 0x20;
2928 atpdev->ultra_map[0] = 0xffff;
2931 shpnt = scsi_host_alloc(&atp870u_template, sizeof(struct atp_unit));
2935 p = (struct atp_unit *)&shpnt->hostdata;
2937 atpdev->host = shpnt;
2938 atpdev->pdev = pdev;
2939 pci_set_drvdata(pdev, p);
2940 memcpy(p, atpdev, sizeof(*atpdev));
2941 if (atp870u_init_tables(shpnt) < 0)
2944 if (request_irq(pdev->irq, atp870u_intr_handle, IRQF_SHARED, "atp870i", shpnt)) {
2945 printk(KERN_ERR "Unable to allocate IRQ%d for Acard controller.\n", pdev->irq);
2949 spin_lock_irqsave(shpnt->host_lock, flags);
2950 if (atpdev->chip_ver > 0x07) { /* check if atp876 chip then enable terminator */
2951 tmport = base_io + 0x3e;
2955 tmport = base_io + 0x3a;
2956 k = (inb(tmport) & 0xf3) | 0x10;
2958 outb((k & 0xdf), tmport);
2963 outb((host_id | 0x08), tmport);
2967 while ((inb(tmport) & 0x80) == 0)
2972 tmport = base_io + 1;
2975 tmport = base_io + 0x11;
2980 tmport = base_io + 0x3a;
2981 outb((inb(tmport) & 0xef), tmport);
2983 outb((inb(tmport) | 0x20), tmport);
2984 if (atpdev->chip_ver == 4)
2988 shpnt->this_id = host_id;
2989 shpnt->unique_id = base_io;
2990 shpnt->io_port = base_io;
2991 shpnt->n_io_port = 0x40; /* Number of bytes of I/O space used */
2992 shpnt->irq = pdev->irq;
2994 spin_unlock_irqrestore(shpnt->host_lock, flags);
2995 if(ent->device==ATP885_DEVID) {
2996 if(!request_region(base_io, 0xff, "atp870u")) /* Register the IO ports that we use */
2997 goto request_io_fail;
2998 } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
2999 if(!request_region(base_io, 0x60, "atp870u")) /* Register the IO ports that we use */
3000 goto request_io_fail;
3002 if(!request_region(base_io, 0x40, "atp870u")) /* Register the IO ports that we use */
3003 goto request_io_fail;
3006 if (scsi_add_host(shpnt, &pdev->dev))
3008 scsi_scan_host(shpnt);
3010 printk("atp870u_prob : exit\n");
3015 printk("atp870u_prob:scsi_add_fail\n");
3016 if(ent->device==ATP885_DEVID) {
3017 release_region(base_io, 0xff);
3018 } else if((ent->device==ATP880_DEVID1)||(ent->device==ATP880_DEVID2)) {
3019 release_region(base_io, 0x60);
3021 release_region(base_io, 0x40);
3024 printk("atp870u_prob:request_io_fail\n");
3025 free_irq(pdev->irq, shpnt);
3027 printk("atp870u_prob:free_table\n");
3028 atp870u_free_tables(shpnt);
3030 printk("atp870u_prob:unregister\n");
3031 scsi_host_put(shpnt);
3041 /* The abort command does not leave the device in a clean state where
3042 it is available to be used again. Until this gets worked out, we will
3043 leave it commented out. */
3045 static int atp870u_abort(struct scsi_cmnd * SCpnt)
3047 unsigned char j, k, c;
3048 struct scsi_cmnd *workrequ;
3049 unsigned int tmport;
3050 struct atp_unit *dev;
3051 struct Scsi_Host *host;
3052 host = SCpnt->device->host;
3054 dev = (struct atp_unit *)&host->hostdata;
3055 c = scmd_channel(SCpnt);
3056 printk(" atp870u: abort Channel = %x \n", c);
3057 printk("working=%x last_cmd=%x ", dev->working[c], dev->last_cmd[c]);
3058 printk(" quhdu=%x quendu=%x ", dev->quhd[c], dev->quend[c]);
3059 tmport = dev->ioport[c];
3060 for (j = 0; j < 0x18; j++) {
3061 printk(" r%2x=%2x", j, inb(tmport++));
3064 printk(" r1c=%2x", inb(tmport));
3066 printk(" r1f=%2x in_snd=%2x ", inb(tmport), dev->in_snd[c]);
3067 tmport= dev->pciport[c];
3068 printk(" d00=%2x", inb(tmport));
3070 printk(" d02=%2x", inb(tmport));
3072 if (dev->id[c][j].curr_req != NULL) {
3073 workrequ = dev->id[c][j].curr_req;
3074 printk("\n que cdb= ");
3075 for (k=0; k < workrequ->cmd_len; k++) {
3076 printk(" %2x ",workrequ->cmnd[k]);
3078 printk(" last_lenu= %x ",(unsigned int)dev->id[c][j].last_len);
3084 static const char *atp870u_info(struct Scsi_Host *notused)
3086 static char buffer[128];
3088 strcpy(buffer, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3093 #define BLS buffer + len + size
3094 static int atp870u_proc_info(struct Scsi_Host *HBAptr, char *buffer,
3095 char **start, off_t offset, int length, int inout)
3097 static u8 buff[512];
3106 memset(buff, 0, sizeof(buff));
3107 size += sprintf(BLS, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3112 size += sprintf(BLS, "\n");
3113 size += sprintf(BLS, "Adapter Configuration:\n");
3114 size += sprintf(BLS, " Base IO: %#.4lx\n", HBAptr->io_port);
3115 size += sprintf(BLS, " IRQ: %d\n", HBAptr->irq);
3119 *start = buffer + (offset - begin); /* Start of wanted data */
3120 len -= (offset - begin); /* Start slop */
3122 len = length; /* Ending slop */
3128 static int atp870u_biosparam(struct scsi_device *disk, struct block_device *dev,
3129 sector_t capacity, int *ip)
3131 int heads, sectors, cylinders;
3135 cylinders = (unsigned long)capacity / (heads * sectors);
3136 if (cylinders > 1024) {
3139 cylinders = (unsigned long)capacity / (heads * sectors);
3148 static void atp870u_remove (struct pci_dev *pdev)
3150 struct atp_unit *devext = pci_get_drvdata(pdev);
3151 struct Scsi_Host *pshost = devext->host;
3154 scsi_remove_host(pshost);
3155 printk(KERN_INFO "free_irq : %d\n",pshost->irq);
3156 free_irq(pshost->irq, pshost);
3157 release_region(pshost->io_port, pshost->n_io_port);
3158 printk(KERN_INFO "atp870u_free_tables : %p\n",pshost);
3159 atp870u_free_tables(pshost);
3160 printk(KERN_INFO "scsi_host_put : %p\n",pshost);
3161 scsi_host_put(pshost);
3162 printk(KERN_INFO "pci_set_drvdata : %p\n",pdev);
3163 pci_set_drvdata(pdev, NULL);
3165 MODULE_LICENSE("GPL");
3167 static struct scsi_host_template atp870u_template = {
3168 .module = THIS_MODULE,
3169 .name = "atp870u" /* name */,
3170 .proc_name = "atp870u",
3171 .proc_info = atp870u_proc_info,
3172 .info = atp870u_info /* info */,
3173 .queuecommand = atp870u_queuecommand /* queuecommand */,
3174 .eh_abort_handler = atp870u_abort /* abort */,
3175 .bios_param = atp870u_biosparam /* biosparm */,
3176 .can_queue = qcnt /* can_queue */,
3177 .this_id = 7 /* SCSI ID */,
3178 .sg_tablesize = ATP870U_SCATTER /*SG_ALL*/ /*SG_NONE*/,
3179 .cmd_per_lun = ATP870U_CMDLUN /* commands per lun */,
3180 .use_clustering = ENABLE_CLUSTERING,
3181 .max_sectors = ATP870U_MAX_SECTORS,
3184 static struct pci_device_id atp870u_id_table[] = {
3185 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP885_DEVID) },
3186 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID1) },
3187 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, ATP880_DEVID2) },
3188 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7610) },
3189 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612UW) },
3190 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612U) },
3191 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612S) },
3192 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612D) },
3193 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_AEC7612SUW) },
3194 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_8060) },
3198 MODULE_DEVICE_TABLE(pci, atp870u_id_table);
3200 static struct pci_driver atp870u_driver = {
3201 .id_table = atp870u_id_table,
3203 .probe = atp870u_probe,
3204 .remove = __devexit_p(atp870u_remove),
3207 static int __init atp870u_init(void)
3210 printk("atp870u_init: Entry\n");
3212 return pci_register_driver(&atp870u_driver);
3215 static void __exit atp870u_exit(void)
3218 printk("atp870u_exit: Entry\n");
3220 pci_unregister_driver(&atp870u_driver);
3223 static void tscam_885(void)
3227 for (i = 0; i < 0x2; i++) {
3235 static void is885(struct atp_unit *dev, unsigned int wkport,unsigned char c)
3237 unsigned int tmport;
3238 unsigned char i, j, k, rmb, n, lvdmode;
3239 unsigned short int m;
3240 static unsigned char mbuf[512];
3241 static unsigned char satn[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3242 static unsigned char inqd[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3243 static unsigned char synn[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3244 unsigned char synu[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3245 static unsigned char synw[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3246 unsigned char synuw[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3247 static unsigned char wide[6] = {0x80, 1, 2, 3, 1, 0};
3248 static unsigned char u3[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3250 lvdmode=inb(wkport + 0x1b) >> 7;
3252 for (i = 0; i < 16; i++) {
3255 if ((m & dev->active_id[c]) != 0) {
3258 if (i == dev->host_id[c]) {
3259 printk(KERN_INFO " ID: %2d Host Adapter\n", dev->host_id[c]);
3262 tmport = wkport + 0x1b;
3264 tmport = wkport + 0x01;
3265 outb(0x08, tmport++);
3266 outb(0x7f, tmport++);
3267 outb(satn[0], tmport++);
3268 outb(satn[1], tmport++);
3269 outb(satn[2], tmport++);
3270 outb(satn[3], tmport++);
3271 outb(satn[4], tmport++);
3272 outb(satn[5], tmport++);
3276 outb(dev->id[c][i].devsp, tmport++);
3279 outb(satn[6], tmport++);
3280 outb(satn[7], tmport++);
3282 if ((j & 0x08) != 0) {
3283 j = (j & 0x07) | 0x40;
3287 outb(satn[8], tmport);
3290 while ((inb(tmport) & 0x80) == 0x00)
3293 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3296 while (inb(tmport) != 0x8e)
3298 dev->active_id[c] |= m;
3300 tmport = wkport + 0x10;
3302 tmport = wkport + 0x14;
3306 tmport = wkport + 0x18;
3309 while ((inb(tmport) & 0x80) == 0x00)
3314 tmport = wkport + 0x10;
3319 tmport = wkport + 0x03;
3320 outb(inqd[0], tmport++);
3321 outb(inqd[1], tmport++);
3322 outb(inqd[2], tmport++);
3323 outb(inqd[3], tmport++);
3324 outb(inqd[4], tmport++);
3325 outb(inqd[5], tmport);
3329 outb(dev->id[c][i].devsp, tmport++);
3331 outb(inqd[6], tmport++);
3332 outb(inqd[7], tmport++);
3334 outb(inqd[8], tmport);
3336 while ((inb(tmport) & 0x80) == 0x00)
3339 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3342 while (inb(tmport) != 0x8e)
3344 tmport = wkport + 0x1b;
3346 tmport = wkport + 0x18;
3352 if ((k & 0x01) != 0) {
3354 mbuf[j++] = inb(tmport);
3358 if ((k & 0x80) == 0) {
3366 tmport = wkport + 0x10;
3375 while ((inb(tmport) & 0x80) == 0x00)
3378 if (inb(tmport) != 0x16) {
3383 printk( KERN_INFO" ID: %2d %s\n", i, &mbuf[8]);
3384 dev->id[c][i].devtype = mbuf[0];
3387 if ((mbuf[7] & 0x60) == 0) {
3390 if ((i < 8) && ((dev->global_map[c] & 0x20) == 0)) {
3396 if (dev->sp[c][i] != 0x04) { // force u2
3400 tmport = wkport + 0x1b;
3402 tmport = wkport + 0x03;
3403 outb(satn[0], tmport++);
3404 outb(satn[1], tmport++);
3405 outb(satn[2], tmport++);
3406 outb(satn[3], tmport++);
3407 outb(satn[4], tmport++);
3408 outb(satn[5], tmport++);
3412 outb(dev->id[c][i].devsp, tmport++);
3414 outb(satn[6], tmport++);
3415 outb(satn[7], tmport++);
3417 outb(satn[8], tmport);
3420 while ((inb(tmport) & 0x80) == 0x00)
3423 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3426 while (inb(tmport) != 0x8e)
3430 tmport = wkport + 0x14;
3436 while ((inb(tmport) & 0x80) == 0) {
3437 if ((inb(tmport) & 0x01) != 0) {
3439 outb(u3[j++], tmport);
3445 while ((inb(tmport) & 0x80) == 0x00)
3447 j = inb(tmport) & 0x0f;
3459 tmport = wkport + 0x18;
3462 while ((inb(tmport) & 0x80) == 0) {
3463 if ((inb(tmport) & 0x01) != 0) {
3471 j = inb(tmport) & 0x0f;
3483 tmport = wkport + 0x14;
3491 if ((j & 0x01) != 0) {
3493 mbuf[k++] = inb(tmport);
3497 if ((j & 0x80) == 0x00) {
3501 j = inb(tmport) & 0x0f;
3513 tmport = wkport + 0x10;
3515 tmport = wkport + 0x14;
3520 while ((inb(tmport) & 0x80) == 0x00);
3529 if (mbuf[0] != 0x01) {
3532 if (mbuf[1] != 0x06) {
3535 if (mbuf[2] != 0x04) {
3538 if (mbuf[3] == 0x09) {
3541 dev->wide_id[c] |= m;
3542 dev->id[c][i].devsp = 0xce;
3544 printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
3549 tmport = wkport + 0x1b;
3551 tmport = wkport + 0x03;
3552 outb(satn[0], tmport++);
3553 outb(satn[1], tmport++);
3554 outb(satn[2], tmport++);
3555 outb(satn[3], tmport++);
3556 outb(satn[4], tmport++);
3557 outb(satn[5], tmport++);
3561 outb(dev->id[c][i].devsp, tmport++);
3563 outb(satn[6], tmport++);
3564 outb(satn[7], tmport++);
3566 outb(satn[8], tmport);
3569 while ((inb(tmport) & 0x80) == 0x00)
3572 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3575 while (inb(tmport) != 0x8e)
3579 tmport = wkport + 0x14;
3585 while ((inb(tmport) & 0x80) == 0) {
3586 if ((inb(tmport) & 0x01) != 0) {
3588 outb(wide[j++], tmport);
3594 while ((inb(tmport) & 0x80) == 0x00)
3596 j = inb(tmport) & 0x0f;
3608 tmport = wkport + 0x18;
3611 while ((inb(tmport) & 0x80) == 0) {
3612 if ((inb(tmport) & 0x01) != 0) {
3620 j = inb(tmport) & 0x0f;
3632 tmport = wkport + 0x14;
3640 if ((j & 0x01) != 0) {
3642 mbuf[k++] = inb(tmport);
3646 if ((j & 0x80) == 0x00) {
3650 j = inb(tmport) & 0x0f;
3662 tmport = wkport + 0x10;
3664 tmport = wkport + 0x14;
3669 while ((inb(tmport) & 0x80) == 0x00)
3679 if (mbuf[0] != 0x01) {
3682 if (mbuf[1] != 0x02) {
3685 if (mbuf[2] != 0x03) {
3688 if (mbuf[3] != 0x01) {
3693 dev->wide_id[c] |= m;
3695 if ((dev->id[c][i].devtype == 0x00) || (dev->id[c][i].devtype == 0x07) ||
3696 ((dev->id[c][i].devtype == 0x05) && ((n & 0x10) != 0))) {
3699 if ((dev->async[c] & m) != 0) {
3705 if (dev->sp[c][i] == 0x02) {
3709 if (dev->sp[c][i] >= 0x03) {
3714 tmport = wkport + 0x1b;
3716 if ((m & dev->wide_id[c]) != 0) {
3720 tmport = wkport + 0x03;
3721 outb(satn[0], tmport++);
3722 outb(satn[1], tmport++);
3723 outb(satn[2], tmport++);
3724 outb(satn[3], tmport++);
3725 outb(satn[4], tmport++);
3726 outb(satn[5], tmport++);
3730 outb(dev->id[c][i].devsp, tmport++);
3732 outb(satn[6], tmport++);
3733 outb(satn[7], tmport++);
3735 outb(satn[8], tmport);
3738 while ((inb(tmport) & 0x80) == 0x00)
3741 if ((inb(tmport) != 0x11) && (inb(tmport) != 0x8e)) {
3744 while (inb(tmport) != 0x8e)
3748 tmport = wkport + 0x14;
3754 while ((inb(tmport) & 0x80) == 0) {
3755 if ((inb(tmport) & 0x01) != 0) {
3757 if ((m & dev->wide_id[c]) != 0) {
3758 if ((m & dev->ultra_map[c]) != 0) {
3759 outb(synuw[j++], tmport);
3761 outb(synw[j++], tmport);
3764 if ((m & dev->ultra_map[c]) != 0) {
3765 outb(synu[j++], tmport);
3767 outb(synn[j++], tmport);
3774 while ((inb(tmport) & 0x80) == 0x00)
3776 j = inb(tmport) & 0x0f;
3788 tmport = wkport + 0x18;
3791 while ((inb(tmport) & 0x80) == 0x00) {
3792 if ((inb(tmport) & 0x01) != 0x00) {
3816 tmport = wkport + 0x14;
3824 if ((j & 0x01) != 0x00) {
3826 mbuf[k++] = inb(tmport);
3830 if ((j & 0x80) == 0x00) {
3834 while ((inb(tmport) & 0x80) == 0x00);
3851 tmport = wkport + 0x10;
3854 tmport = wkport + 0x14;
3859 while ((inb(tmport) & 0x80) == 0x00)
3866 if (mbuf[0] != 0x01) {
3869 if (mbuf[1] != 0x03) {
3872 if (mbuf[4] == 0x00) {
3875 if (mbuf[3] > 0x64) {
3878 if (mbuf[4] > 0x0e) {
3881 dev->id[c][i].devsp = mbuf[4];
3882 if (mbuf[3] < 0x0c){
3886 if ((mbuf[3] < 0x0d) && (rmb == 0)) {
3890 if (mbuf[3] < 0x1a) {
3894 if (mbuf[3] < 0x33) {
3898 if (mbuf[3] < 0x4c) {
3904 dev->id[c][i].devsp = (dev->id[c][i].devsp & 0x0f) | j;
3906 printk("dev->id[%2d][%2d].devsp = %2x\n",c,i,dev->id[c][i].devsp);
3909 tmport = wkport + 0x16;
3913 module_init(atp870u_init);
3914 module_exit(atp870u_exit);