1 /* $Id: atp870u.c,v 1.4 2005/12/12 06:25:19 axl Exp $
2 * linux/kernel/atp86x.c
4 * Copyright (C) 2003-04 ACARD
5 * Modified by Jason Wu from aec6285.c to support ATP865 chip
8 * 1. Modify atp86x_detect()
11 * 1. Change file name from AEC6885.X to atp86x.c and .h
12 * 2. Change routine name from aec6285 to atp86x
14 * 1. Modify atp86x_detect()
15 * (1) 865: init chip registers.
17 * 1. Modify atp86x_detect()
18 * (1) is865: scan device
21 * (1) display the correct debug message of idenfity device command
24 * (1) display more correct debug message of idenfity device command
25 * (2) display "UDMA xxx" after inquiry string..
26 * 2. Modify atp86x_release()
27 * (1) If 865, release region is different to 867.
29 * 1. disable "DETECT_DEBUG" and "IS865_DEBUG"
30 * 2. Modify atp86x_queuecommand()
33 * 1. S860IO(): display more debug messages
34 * 2. BuildSrb& RAID05: don't change ..
35 * 3. Noiocmd: don't change ..
36 * 4. SendSCSI: second argument: baseioaddress[0]= channel 0, baseioaddress[1] = channel 1
38 * 1. atp86x_intr_handle
40 * 1. Change version string.
41 * 2. atp86x_abort: change nothing..
45 * 1. S3init: change name to ATP867init
46 * 2. ATP865init: init the ATP865 chip.
47 * 3. ATP865init: should send 3x6 software reset first.
49 * 1. Define ATP865 chip number= 0x0008,0x0009 and ATP867=0x000A
50 * 2. ATP865: If chip version <= A3, should run UDMA100 only.
51 * 3. Print out not supported commands...
52 * (1) IO commands: 0x28,0x2a,0x08,0x0a,0x2b,0x0b,0x35,0x2f,0x1b
53 * (2) No IO commands: 0x1a, 0x12, 0x25, 0x03
54 * (3) Always status good: 0x00, 0x15, 0x55, 0x1e, 0x04
55 * (4) Always status check condition: All others.
56 * Sense key : 05/20/00 not supported commands?
59 * 1. Inquiry EVPD support:
60 * (1) Other pages: return 05/24/00
61 * 2. ISR: Error handling: Sense key table implementation.
62 * (1) CRC Error: print out the debug message for release mode
63 * (2) Media Error: read/write/verify commands
65 * (4) Invalid address: read/write/seek/verify commands
66 * 3. Bad sector: sense key with bad sector LBA info
67 * 4. Command 0x2E support!
68 * 5. Sense key should be enough for each HDD.( [8] for each card [16] for each buffer)
71 * 1. IXP425: Big Endian problem
72 * (1) Inquiry: First 8 bytes should be filled in byte-unit. -> DONE
73 * (2) Read Capacity: block length should be filled in byte-unit. ->DONE
74 * (3) Read Capacity: Capacity Wrong! (identify command should get capacity in byte-unit)->DONE
75 * 2. IXP425: Big Endian problem
76 * (1) RAID05: use byte-unit to fill PRD table. -> DONE
77 * (2) Send SCSI: IDE command and PCI control should be seperated.
78 * -> Sendnorm: UCHAR for blkno, UCHAR pcicmd, UCHAR cmd. -> DONE
79 * (3) BuildSrb: Transfer counter should be set in byte-unit. -> DONE
82 * 1. IXP425: Test if allocate memory use GFP_ATOMIC parameter.
83 * 2. IXP42X_DEBUG_MSG = ON
86 * 1. IXP425: Test if allocate memory use GFP_ATOMIC|GFP_DMA parameter.
87 * 2. IXP42X_DEBUG_MSG = OFF
90 * 1. IXP425: Send SCSI: IDE command and PCI control should be seperated.
91 * -> Sendbigd: USHORT for blkno, UCHAR pcicmd, UCHAR cmd. ->DONE
92 * 2. IXP425: Is865 Bug: Inquiry command: first 8 bytes not modified.
93 * 3. IXP425: is867 Bug:
94 * Read Capacity: Capacity Wrong! (identify command should get capacity in byte-unit)->DONE
96 * 1. Function get_disk_err_LBA: Bug! Bad sector LBA error for 48-bit LBA mode.
100 * 1.IXP425: Try to allocate memory by pci_alloc_consistent() and pci_free_consistent
103 * 1.ATP867: PowerOn: I2C delay too long?
106 * 1. IXP425: Big-Endian: Mode sense problem: #define MODESENSE_DEBUG -> DONE
109 * 1. IXP42X_DEBUG -> IXP42X_SUPPORT
110 * 2. Queue count: enlarge to max 128 queues per card.
113 * 1. Inquiry EVPD page 80 : serial number support.
114 * 2. Invalid address check: for Read/Write/seek/verify commands.
115 * 3. Reassign block command support.
116 * 4. Abort: function not implement
117 * 5. Reset: function should be well tested
118 * 6. Sendbigd: Should clear HOB first.
119 * 7. Save Flags? Cli? Restore Flags? -> Protect sections that prevent the queue function fails.
120 * 8. ATP867: PowerOn: WD HDD -> UDMA 133?? Bugs?
121 * ata66? is66? iswd? If the first driver=133, the next drive will become 133?
122 * 9. Mode select (6) not supported.
125 #define DEBUG_UDMA // Always set to indicate the UDMA mode for HDDs
126 #define IXP42X_SUPPORT // IXP Big-Endian problem fixed
127 //#define MODESENSE_DEBUG
129 //#define IXP42X_DEBUG_MSG
130 //#define DETECT_DEBUG
131 //#define IS865_DEBUG
132 //#define QUEUECOMMAND_DEBUG
134 //#define RESET_DEBUG
135 //#define DEBUG_SENSEKEY
137 #include <linux/module.h>
139 #include <linux/kernel.h>
140 #include <linux/types.h>
141 #include <linux/string.h>
142 #include <linux/ioport.h>
143 #include <linux/delay.h>
144 #include <linux/sched.h>
145 #include <linux/proc_fs.h>
146 #include <linux/spinlock.h>
147 #include <asm/system.h>
149 #include <linux/pci.h>
150 #include <linux/blk.h>
157 #include<linux/stat.h>
159 #define UCHAR unsigned char
160 #define USHORT unsigned short
161 #define ULONG unsigned long
162 #define PUCHAR unsigned char *
163 #define PUSHORT unsigned short *
164 #define PULONG unsigned long *
167 #define Inpb(x,y) inb((x + y))
168 #define Outpb(x,y,z) outb(z, (x + y))
169 #define Inpw(x,y) inw((x + y))
170 #define Outpw(x,y,z) outw(z, (x + y))
171 #define Inpl(x,y) inl((x + y))
172 #define Outpl(x,y,z) outl(z, (x + y))
174 static unsigned char admaxu = 3;
175 static unsigned int irqnumu[4] = {0, 0, 0, 0};
178 #ifdef IXP42X_SUPPORT
189 struct hw_device_ext {
190 struct hw_lu_ext lsrb[4][qcnt1];
191 struct hw_lu_ext *Cplsrb[4];
192 struct hw_lu_ext *plsrb[4][qcnt1];
193 struct pci_dev *pdev;
195 ULONG BaseIoAddress[4];
196 ULONG BaseIoAddresm[4];
199 Scsi_Cmnd * QSrb[4][qcnt1];
201 ULONG que_hd[4],que_end[4],bigdrv[8];
212 // UCHAR sensdok[14];
213 // UCHAR inqdat[8][38];
214 UCHAR inqdat[8][56]; //axl+
215 // add for smart read =================//
218 struct timer_list AdapterTimer;
221 //======================================//
222 UCHAR dev_id,chipver,ata66;
223 UCHAR host_id,c_mask;
226 ULONG SamwiseBaseIoAddress;
227 UCHAR SamwiseHDSelect;
230 // add for smart read =================//
231 USHORT smart_buf[256];
232 void smart_timer(ULONG para);
233 //======================================//
235 static struct Scsi_Host *a867host[4] = {NULL, NULL, NULL, NULL};
236 static struct hw_device_ext dev_ext[4];
238 int S860Io(struct hw_device_ext * devext, Scsi_Cmnd * Srb);
239 int BuildSrb(struct hw_device_ext * devext, struct hw_lu_ext * srbp, Scsi_Cmnd * Srb);
240 int Raid05(struct hw_device_ext * devext, struct hw_lu_ext * srbp, Scsi_Cmnd * Srb);
241 int SendScsi(struct hw_device_ext * devext, Scsi_Cmnd * Srb, ULONG Ch);
242 #ifdef IXP42X_SUPPORT
243 void Sendnorm(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, UCHAR wkblkno, UCHAR pcicmd, UCHAR cmd);
244 void Sendbigd(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, USHORT wkblkno, UCHAR pcicmd, UCHAR cmd);
246 void Sendnorm(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, USHORT wkblkno, USHORT cmd);
247 void Sendbigd(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, USHORT wkblkno, USHORT cmd);
249 void Noiocmd(struct hw_device_ext * devext, Scsi_Cmnd * Srb);
251 int i2cwrite(ULONG baseIoAddress, UCHAR Rindex, UCHAR Rval);
252 int i2cread(ULONG baseIoAddress, UCHAR Rindex, PUCHAR Rval);
254 void ATP867init(struct hw_device_ext * devext);
255 void ATP865init(struct hw_device_ext * devext);
256 int fill_sensekey_buf(struct hw_device_ext * devext, UCHAR tid);
259 int get_disk_err_LBA(struct hw_device_ext * devext, UCHAR tid)
261 ULONG baseIoAddress= devext->BaseIoAddress[tid>>1];
262 ULONG baseIoAddress2= devext->BaseIoAddress[(tid>>1)+2];
265 if (devext->bigdrv[tid] == 0)
272 tmp = Inpb(baseIoAddress,0x3);
273 devext->dskerr_LBA[tid] = tmp;
274 #ifdef DEBUG_SENSEKEY
275 printk("28-bit LBA 1X3 = %2X",tmp);
277 tmp = Inpb(baseIoAddress,0x4);
278 devext->dskerr_LBA[tid] |= (tmp<<8);
279 #ifdef DEBUG_SENSEKEY
280 printk("1X4 = %2X",tmp);
282 tmp = Inpb(baseIoAddress,0x5);
283 devext->dskerr_LBA[tid] |= (tmp<<16);
284 #ifdef DEBUG_SENSEKEY
285 printk("1X5 = %2X",tmp);
287 tmp = Inpb(baseIoAddress,0x6);
288 devext->dskerr_LBA[tid] |= ((tmp<<24) & 0x0F);
289 #ifdef DEBUG_SENSEKEY
290 printk("1X6 = %2X \n",tmp);
295 // HOB=0: 1X3=LBA(7:0) 1X4= LBA(15:8) 1X5=LBA(23:16)
296 // HOB=1: 1X3=LBA(31:24) 1X4=LBA(39:32) 1X5=LBA(47:40)
297 outb(0x00, baseIoAddress2+2);
298 #ifdef DEBUG_SENSEKEY
299 printk("48-bit Error LBA HOB = 0\n",tmp);
301 tmp = Inpb(baseIoAddress,0x3);
302 devext->dskerr_LBA[tid] = tmp;
303 #ifdef DEBUG_SENSEKEY
304 printk("1X3 = %2X",tmp);
306 tmp = Inpb(baseIoAddress,0x4);
307 devext->dskerr_LBA[tid] |= (tmp<<8);
308 #ifdef DEBUG_SENSEKEY
309 printk("1X4 = %2X",tmp);
311 tmp = Inpb(baseIoAddress,0x5);
312 devext->dskerr_LBA[tid] |= (tmp<<16);
313 #ifdef DEBUG_SENSEKEY
314 printk("1X5 = %2X\n",tmp);
316 outb(0x80, baseIoAddress2+2);
317 #ifdef DEBUG_SENSEKEY
318 printk("48-bit Error LBA HOB = 1\n",tmp);
320 tmp = Inpb(baseIoAddress,0x3);
321 devext->dskerr_LBA[tid] |= (tmp<<24);
322 #ifdef DEBUG_SENSEKEY
323 printk("2nd 1X3 = %2X",tmp);
325 tmp = Inpb(baseIoAddress,0x4);
326 #ifdef DEBUG_SENSEKEY
327 printk("2nd 1X4 = %2X",tmp);
329 tmp = Inpb(baseIoAddress,0x5);
330 #ifdef DEBUG_SENSEKEY
331 printk("2nd 1X5 = %2X\n",tmp);
333 outb(0x00, baseIoAddress2+2);
334 tmp = Inpb(baseIoAddress,0x6);
336 #ifdef DEBUG_SENSEKEY
337 printk("1X6 = %2X LBA=%8lX\n",tmp,devext->dskerr_LBA[tid]);
342 static void atp86x_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
344 struct hw_device_ext *devext = dev_id;
356 unsigned short Value16;
357 unsigned char* pData;
359 pData = &smart_buf[0];
361 for (h = 0; h < 4; h++) {
362 if (irq == irqnumu[h]) {
369 if (devext->dev_id == ATP867_DEVID1)
371 baseIoAddress = devext->BaseIoAddress[0];
373 if ((Inpb(baseIoAddress,0x2a) & devext->c_mask) != 0)
375 i=Inpb(baseIoAddress,0x2a) & devext->c_mask;
376 for (k=0; k < 4; k++)
380 baseIoAddress = devext->BaseIoAddress[k];
381 i2cread(baseIoAddress,0x41,&l);
382 i2cread(baseIoAddress,0x42,&l);
383 i2cread(baseIoAddress,0x40,&l);
384 i2cread(baseIoAddress,0x41,&l);
385 i2cread(baseIoAddress,0x42,&l);
386 Outpb(baseIoAddress,0x43,0x20);
390 baseIoAddress = devext->BaseIoAddress[0];
393 intn=Inpb(baseIoAddress,0x2a) & 0x0f;
395 for (Ch=0 ;Ch < 4; Ch++)
401 baseIoAddress = devext->BaseIoAddress[Ch];
402 baseIoAddresm = devext->BaseIoAddresm[Ch];
404 if (devext->CSrb[Ch] != 0)
406 CSrb=devext->CSrb[Ch];
411 Inpb(baseIoAddress,7);
412 Outpb(baseIoAddresm,2,0x06);
419 for (Ch=0 ;Ch < 2; Ch++)
422 baseIoAddress = devext->BaseIoAddresm[Ch];
423 intn=Inpb(baseIoAddress,2) & 0x06;
425 printk("865INTR:Ch = %2lX intn = %2X \n",Ch,intn);
428 if ((intn & 0x04) != 0)
430 baseIoAddress = devext->BaseIoAddress[Ch];
431 baseIoAddresm = devext->BaseIoAddresm[Ch];
433 if (devext->CSrb[Ch] != 0)
435 CSrb=devext->CSrb[Ch];
440 Inpb(baseIoAddress,7);
441 Outpb(baseIoAddresm,2,0x06);
451 printk("86XINTR:do_irq3: target = %2X \n",CSrb->target);
453 TargetId=CSrb->target;
454 Outpb(baseIoAddresm,0,0);
455 i=Inpb(baseIoAddress,7);
456 Outpb(baseIoAddresm,2,0x06);
458 // add for smart read =================//
459 if (CSrb->cmnd[0] == 0xB0)
461 //printk("Smart Read Interrupt,status:%02X",i);
462 if ((i == 0x58) || (i == 0x48))
464 for (x = 0 ; x < 256 ; x++)
466 Value16 = Inpw(baseIoAddress,0);
467 *(pData+(x<<1)) = (unsigned char)Value16;
468 *(pData+(x<<1)+1) = (unsigned char)(Value16>>8);
474 devext->hd_status[TargetId]=0x51;
476 devext->dskerr[TargetId]=0xB0; // 0B/00/00 aborted command
478 i = Inpb(baseIoAddress,7);
479 //printk(",status:%02X\n",i);
480 devext->FG_SmartRead = 0;
481 goto interrupt_keep_going;
483 //======================================//
484 if ((i != 0x50) && (i != 0x40))
486 k=Inpb(baseIoAddress,1);
487 //#ifdef DEBUG_SENSEKEY
488 printk("\nATP86X: Ch %2lX ID %2X Error: status=%2X error reg=%2X\n",Ch,TargetId,i,k);
492 #ifdef DEBUG_SENSEKEY
493 printk("ATP86X: CRC Error:");
495 devext->dskerr[TargetId]=0x48; // 04/08/03 CRC Error
499 #ifdef DEBUG_SENSEKEY
500 printk("ATP86X: Media Error:");
502 if (CSrb->cmnd[0]==0x0A || CSrb->cmnd[0]==0x2A || CSrb->cmnd[0]==0x2E)
504 devext->dskerr[TargetId]=0x3C; // 03/0C/00 Write Error
505 // Get Error LBA here and fill into dskerr_LBA[TargetId] 48-bit or 28-bit
506 get_disk_err_LBA(devext,TargetId);
508 else if (CSrb->cmnd[0]==0x08 || CSrb->cmnd[0]==0x28 || CSrb->cmnd[0]==0x2F ||
509 CSrb->cmnd[0]==0x0B || CSrb->cmnd[0]==0x2B )
511 devext->dskerr[TargetId]=0x31; // 03/11/00 Read Error
512 // Get Error LBA here and fill into dskerr_LBA[TargetId] 48-bit or 28-bit
513 get_disk_err_LBA(devext,TargetId);
515 else devext->dskerr[TargetId]=0xB0; // 0B/00/00 aborted command
519 // devext->dskerr[TargetId]=0x51;
520 devext->dskerr[TargetId]=0xB0; // 0B/00/00 aborted command
522 #ifdef DEBUG_SENSEKEY
524 for (i=0;i<CSrb->cmd_len;i++ )
525 printk("%2X ",CSrb->cmnd[i]);
528 devext->hd_status[TargetId]=0x51;
535 // add for smart read =================//
536 interrupt_keep_going:
537 //======================================//
539 spin_lock_irqsave(&io_request_lock, flags);
540 (*CSrb->scsi_done) (CSrb);
542 if (devext->que_hd[Ch] != devext->que_end[Ch])
544 if ((devext->que_hd[Ch] += 1) > qcnt1 - 1)
546 devext->que_hd[Ch]=0;
548 devext->CSrb[Ch]=devext->QSrb[Ch][devext->que_hd[Ch]];
549 devext->Cplsrb[Ch]=devext->plsrb[Ch][devext->que_hd[Ch]];
550 SendScsi(devext,devext->CSrb[Ch],Ch);
552 spin_unlock_irqrestore(&io_request_lock, flags);
557 int atp86x_queuecommand(Scsi_Cmnd * req_p, void (*done) (Scsi_Cmnd *))
561 struct hw_device_ext *devext;
563 for (h = 0; h <= admaxu; h++) {
564 if (req_p->host == a867host[h]) {
571 printk(KERN_WARNING "atp86x_queuecommand: done can't be NULL\n");
576 if (req_p->channel != 0) {
577 req_p->result = 0x00040000;
583 devext = &dev_ext[h];
584 req_p->scsi_done = done;
586 if (!S860Io(devext,req_p))
588 restore_flags(flags);
591 if (devext->in_int == 0)
593 Ch = (ULONG)(req_p->target >> 1);
594 if ((devext->CSrb[Ch] == 0) &&
595 (devext->que_hd[Ch] != devext->que_end[Ch]))
597 if ( devext->que_hd[Ch] == qcnt1 - 1 )
599 devext->que_hd[Ch]=0;
603 devext->que_hd[Ch]++;
605 devext->CSrb[Ch]=devext->QSrb[Ch][devext->que_hd[Ch]];
606 devext->Cplsrb[Ch]=devext->plsrb[Ch][devext->que_hd[Ch]];
607 SendScsi(devext,devext->CSrb[Ch],Ch);
610 restore_flags(flags);
614 int S860Io(struct hw_device_ext * devext, Scsi_Cmnd * Srb)
616 struct hw_lu_ext *srbp;
618 #ifdef QUEUECOMMAND_DEBUG
619 printk("S860IO: Srb->lun= %2X devext->dev_id= %2X\n",Srb->lun,devext->dev_id);
623 Srb->result = 0x00040000;
628 if (devext->dev_id == ATP867_DEVID1)
630 if ((t > 7) || (devext->cap[t] == 0))
632 Srb->result = 0x00040000;
639 #ifdef QUEUECOMMAND_DEBUG
640 printk("S860IO: t= %2X devext->cap[t]= %8lX\n",t,devext->cap[t]);
642 if ((t > 4) || (devext->cap[t] == 0))
644 Srb->result = 0x00040000;
649 #ifdef QUEUECOMMAND_DEBUG
650 printk("S860IO: Srb->cmnd[0] = %2X hd_status[t]= %2X\n",Srb->cmnd[0],devext->hd_status[t]);
653 if ((j == 0x28) || (j == 0x2a) || (j == 0x2e)|| (j == 0x08) ||
654 (j == 0x0a) || (j == 0x2b) || (j == 0x0b) ||
655 (j == 0x35) || (j == 0x2f) || (j == 0x1b))
657 if (devext->hd_status[t] == 0x7f)
665 if ((devext->que_end[i] += 1) > qcnt1 - 1)
667 devext->que_end[i]=0;
669 devext->QSrb[i][devext->que_end[i]]=Srb;
670 srbp=devext->plsrb[i][devext->que_end[i]];
671 BuildSrb(devext, srbp ,Srb);
682 int BuildSrb(struct hw_device_ext * devext, struct hw_lu_ext * srbp, Scsi_Cmnd * Srb)
685 if (Srb->cmd_len == 0x06)
687 ((PUCHAR)&srbp->wslba)[0]=Srb->cmnd[3];
688 ((PUCHAR)&srbp->wslba)[1]=Srb->cmnd[2];
689 ((PUCHAR)&srbp->wslba)[2]=Srb->cmnd[1];
690 ((PUCHAR)&srbp->wslba)[3]=Srb->cmnd[0];
691 srbp->wslba &= 0x000fffff;
692 srbp->wsblkno=Srb->cmnd[4];
693 srbp->wsblkno &=0x00ff;
697 ((PUCHAR)&srbp->wslba)[0]=Srb->cmnd[5];
698 ((PUCHAR)&srbp->wslba)[1]=Srb->cmnd[4];
699 ((PUCHAR)&srbp->wslba)[2]=Srb->cmnd[3];
700 ((PUCHAR)&srbp->wslba)[3]=Srb->cmnd[2];
701 #ifdef IXP42X_SUPPORT
702 srbp->wsblkno = Srb->cmnd[8];
703 if (Srb->cmnd[7]!=0) srbp->wsblkno |= (USHORT)(Srb->cmnd[7]<<8);
705 ((PUCHAR)&srbp->wsblkno)[0]=Srb->cmnd[8];
706 ((PUCHAR)&srbp->wsblkno)[1]=Srb->cmnd[7];
709 #ifdef IXP42X_DEBUG_MSG
710 printk("BuildSrb: c[0]=%2X c[1]=%2X c[2]=%2X c[3]=%2X c[4]=%2X c[5]=%2x lba=%8lx\n",Srb->cmnd[0],Srb->cmnd[1],
711 Srb->cmnd[2],Srb->cmnd[3],Srb->cmnd[4],Srb->cmnd[5],srbp->wslba);
712 printk("BuildSrb: c[6]=%2X c[7]=%2X c[8]=%2X blkno=%4X\n",Srb->cmnd[6],Srb->cmnd[7],Srb->cmnd[8],srbp->wsblkno);
714 return (Raid05(devext,srbp,Srb));
717 int Raid05(struct hw_device_ext * devext, struct hw_lu_ext * srbp, Scsi_Cmnd * Srb)
722 #ifdef IXP42X_DEBUG_MSG
725 struct scatterlist *sgpnt;
728 sgpnt = (struct scatterlist *) Srb->request_buffer;
732 for (i = 0; i < Srb->use_sg; i++)
734 if (sgpnt[i].length == 0 || Srb->use_sg > ATP86X_SCATTER)
736 panic("Foooooooood fight!");
738 leng += sgpnt[i].length;
741 leng = Srb->request_bufflen;
743 if ((leng != 0x00) && (Srb->cmnd[0] != 0x2f))
751 baddr = virt_to_bus(sgpnt[i].address);
752 maplen = sgpnt[i++].length;
754 baddr = virt_to_bus(Srb->request_buffer);
755 maplen = Srb->request_bufflen;
761 #ifdef IXP42X_SUPPORT
762 srbp->prd[l1]=(UCHAR)baddr;
763 srbp->prd[l1+1]=(UCHAR)(baddr>>8);
764 srbp->prd[l1+2]=(UCHAR)(baddr>>16);
765 srbp->prd[l1+3]=(UCHAR)(baddr>>24);
768 ((PULONG)srbp->prd)[l1++]=baddr;
771 #ifdef IXP42X_DEBUG_MSG
772 printk("RAID05: Srb->use_sg = %4X l1=%2lX maplen=%8lX baddr=%8lX\n",Srb->use_sg,l1,maplen,baddr);
774 if ( maplen > 0x10000 )
776 #ifdef IXP42X_SUPPORT
783 ((PULONG)srbp->prd)[l1++]=0;
788 #ifdef IXP42X_SUPPORT
789 srbp->prd[l1]=(UCHAR)baddr;
790 srbp->prd[l1+1]=(UCHAR)(baddr>>8);
791 srbp->prd[l1+2]=(UCHAR)(baddr>>16);
792 srbp->prd[l1+3]=(UCHAR)(baddr>>24);
795 ((PULONG)srbp->prd)[l1++]=baddr;
800 #ifdef IXP42X_SUPPORT
801 srbp->prd[l1]=(UCHAR)maplen;
802 srbp->prd[l1+1]=(UCHAR)(maplen>>8);
807 ((PULONG)srbp->prd)[l1++]=maplen;
810 #ifdef IXP42X_SUPPORT
814 l1=((l1 << 2) - 2) >> 1;
815 ((PUSHORT)srbp->prd)[l1]=0x8000;
818 #ifdef IXP42X_DEBUG_MSG
819 for (l1=0;l1<=Srb->use_sg;l1++)
821 printk("l1= %2lX ",l1);
822 for (l2=l1*8;l2<(l1*8+8);l2++)
824 printk("[%2lX]= %2X ",l2,(UCHAR) (srbp->prd[l2]));
832 int SendScsi(struct hw_device_ext * devext, Scsi_Cmnd * Srb, ULONG Ch)
834 ULONG baseIoAddress = devext->BaseIoAddress[Ch];
835 ULONG baseIoAddresm = devext->BaseIoAddresm[Ch];
836 struct hw_lu_ext * srbp;
838 #ifndef IXP42X_SUPPORT
843 #ifdef QUEUECOMMAND_DEBUG
844 printk("SendSCSI: Ch=%2lX Tarrget=%2X CDB[0]= %2X \n",Ch,Srb->target,Srb->cmnd[0]);
846 srbp=devext->Cplsrb[Ch];
848 Outpb(baseIoAddresm,2,0x06);
850 t = (ULONG)Srb->target;
859 Outpb(baseIoAddress,6,devno);
860 // add for smart read =================//
861 if (Srb->cmnd[0] == 0xB0)
863 Outpb(baseIoAddress,1,0xD0);
864 Outpb(baseIoAddress,4,0x4F);
865 Outpb(baseIoAddress,5,0xC2);
866 Outpb(baseIoAddress,7,0xB0);
869 //=====================================//
870 if ((Srb->cmnd[0] == 0x28) || (Srb->cmnd[0] == 0x2a) || (Srb->cmnd[0] == 0x2e) ||
871 (Srb->cmnd[0] == 0x08) || (Srb->cmnd[0] == 0x0a))
873 Outpl(baseIoAddresm,4,srbp->prdaddr);
874 #ifdef IXP42X_SUPPORT
875 if (devext->bigdrv[t] == 0)
877 if ((Srb->cmnd[0] == 0x2a) || (Srb->cmnd[0] == 0x0a) || (Srb->cmnd[0] == 0x2e))
879 Sendnorm(baseIoAddress,baseIoAddresm,srbp->wslba,(UCHAR)srbp->wsblkno,0x01,0xca);
883 Sendnorm(baseIoAddress,baseIoAddresm,srbp->wslba,(UCHAR)srbp->wsblkno,0x09,0xc8);
888 if ((Srb->cmnd[0] == 0x2a) || (Srb->cmnd[0] == 0x0a)|| (Srb->cmnd[0] == 0x2e))
890 Sendbigd(baseIoAddress,baseIoAddresm,srbp->wslba,srbp->wsblkno,0x01,0x35);
894 Sendbigd(baseIoAddress,baseIoAddresm,srbp->wslba,srbp->wsblkno,0x09,0x25);
898 if (devext->bigdrv[t] == 0)
900 if ((Srb->cmnd[0] == 0x2a) || (Srb->cmnd[0] == 0x0a) || (Srb->cmnd[0] == 0x2e))
908 Sendnorm(baseIoAddress,baseIoAddresm,srbp->wslba,srbp->wsblkno,k);
912 if ((Srb->cmnd[0] == 0x2a) || (Srb->cmnd[0] == 0x0a)|| (Srb->cmnd[0] == 0x2e))
920 Sendbigd(baseIoAddress,baseIoAddresm,srbp->wslba,srbp->wsblkno,k);
927 if (Srb->cmnd[0] == 0x35)
929 if (devext->bigdrv[t] == 0)
931 Outpb(baseIoAddress,7,0xe7);
935 Outpb(baseIoAddress,7,0xea);
940 if (Srb->cmnd[0] == 0x1b)
942 if (Srb->cmnd[4] == 0x00)
944 #ifdef IXP42X_SUPPORT
945 Sendnorm(baseIoAddress,baseIoAddresm,0,0,0x00,0xe0);
947 Sendnorm(baseIoAddress,baseIoAddresm,0,0,0x00e0);
952 #ifdef IXP42X_SUPPORT
953 Sendnorm(baseIoAddress,baseIoAddresm,0,0x40,0x00,0x40);
955 Sendnorm(baseIoAddress,baseIoAddresm,0,0x40,0x40);
961 if ((Srb->cmnd[0] == 0x0b) || (Srb->cmnd[0] == 0x2b))
963 if (devext->bigdrv[t] == 0)
965 #ifdef IXP42X_SUPPORT
966 Sendnorm(baseIoAddress,baseIoAddresm,srbp->wslba,1,0x00,0x70);
968 Sendnorm(baseIoAddress,baseIoAddresm,srbp->wslba,1,0x70);
973 #ifdef IXP42X_SUPPORT
974 Sendbigd(baseIoAddress,baseIoAddresm,srbp->wslba,1,0X00,0x42);
976 Sendbigd(baseIoAddress,baseIoAddresm,srbp->wslba,1,0x42);
982 if (Srb->cmnd[0] == 0x2f)
984 if (devext->bigdrv[t] == 0)
986 #ifdef IXP42X_SUPPORT
987 Sendnorm(baseIoAddress,baseIoAddresm,srbp->wslba,(UCHAR) srbp->wsblkno,0x00,0x40);
989 Sendnorm(baseIoAddress,baseIoAddresm,srbp->wslba,srbp->wsblkno,0x40);
994 #ifdef IXP42X_SUPPORT
995 Sendbigd(baseIoAddress,baseIoAddresm,srbp->wslba,srbp->wsblkno,0x00,0x42);
997 Sendbigd(baseIoAddress,baseIoAddresm,srbp->wslba,srbp->wsblkno,0x42);
1004 #ifdef IXP42X_SUPPORT
1005 void Sendnorm(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, UCHAR wkblkno, UCHAR pcicmd, UCHAR cmd)
1009 outb(wkblkno, baseIoAddress + 2);
1010 #ifdef IXP42X_DEBUG_MSG
1011 printk("Sendnorm: 1X2 wkblkno=%2X \n",wkblkno);
1013 outb(((PUCHAR)&wklba)[0], baseIoAddress+3);
1014 #ifdef IXP42X_DEBUG_MSG
1015 printk("Sendnorm: 1X3 = %2X \n",((PUCHAR)&wklba)[0]);
1017 outb(((PUCHAR)&wklba)[1], baseIoAddress+4);
1018 #ifdef IXP42X_DEBUG_MSG
1019 printk("Sendnorm: 1X4 = %2X \n",((PUCHAR)&wklba)[1]);
1021 outb(((PUCHAR)&wklba)[2], baseIoAddress+5);
1022 #ifdef IXP42X_DEBUG_MSG
1023 printk("Sendnorm: 1X5 = %2X \n",((PUCHAR)&wklba)[2]);
1025 i=((PUCHAR)&wklba)[3] & 0x0f;
1027 outb((UCHAR)((inb(baseIoAddress+6) & 0xf0) | i), baseIoAddress+6);
1028 #ifdef IXP42X_DEBUG_MSG
1029 printk("Sendnorm: 1X6 = %2X \n",inb(baseIoAddress+6));
1031 outb(cmd, baseIoAddress+7);
1032 #ifdef IXP42X_DEBUG_MSG
1033 printk("Sendnorm: 1X7 = %2X \n",cmd);
1035 outb(pcicmd, baseIoAddresm);
1036 #ifdef IXP42X_DEBUG_MSG
1037 printk("Sendnorm: PCI cmd = %2X \n",pcicmd);
1042 void Sendbigd(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, USHORT wkblkno, UCHAR pcicmd, UCHAR cmd)
1044 // outb(((PUCHAR)&wkblkno)[1], baseIoAddress+2);
1045 outb((UCHAR)(wkblkno>>8),baseIoAddress+2);
1046 #ifdef IXP42X_DEBUG_MSG
1047 printk("Sendbigd: 1X2 =%2X wkblkno=%2X\n",(UCHAR)(wkblkno>>8),wkblkno);
1049 // outb(((PUCHAR)&wkblkno)[0], baseIoAddress+2);
1050 outb((UCHAR)(wkblkno),baseIoAddress+2);
1051 #ifdef IXP42X_DEBUG_MSG
1052 printk("Sendbigd: 1X2 =%2X wkblkno=%2X\n",(UCHAR)(wkblkno),wkblkno);
1054 outb(((PUCHAR)&wklba)[3], baseIoAddress+3);
1055 #ifdef IXP42X_DEBUG_MSG
1056 printk("Sendbigd: 1X3 =%2X \n",((PUCHAR)&wklba)[3]);
1058 outb(0, baseIoAddress+4);
1059 #ifdef IXP42X_DEBUG_MSG
1060 printk("Sendbigd: 1X4 =0 \n");
1062 outb(0, baseIoAddress+5);
1063 #ifdef IXP42X_DEBUG_MSG
1064 printk("Sendbigd: 1X5 =0 \n");
1066 outb(((PUCHAR)&wklba)[0], baseIoAddress+3);
1067 #ifdef IXP42X_DEBUG_MSG
1068 printk("Sendbigd: 1X3 =%2X \n",((PUCHAR)&wklba)[0]);
1070 outb(((PUCHAR)&wklba)[1], baseIoAddress+4);
1071 #ifdef IXP42X_DEBUG_MSG
1072 printk("Sendbigd: 1X4 =%2X \n",((PUCHAR)&wklba)[1]);
1074 outb(((PUCHAR)&wklba)[2], baseIoAddress+5);
1075 #ifdef IXP42X_DEBUG_MSG
1076 printk("Sendbigd: 1X5 =%2X \n",((PUCHAR)&wklba)[2]);
1078 outb(cmd, baseIoAddress+7);
1079 #ifdef IXP42X_DEBUG_MSG
1080 printk("Sendbigd: 1X7 =%2X \n",cmd);
1082 outb(pcicmd, baseIoAddresm);
1083 #ifdef IXP42X_DEBUG_MSG
1084 printk("Sendbigd: pcicmd =%2X \n",pcicmd);
1091 void Sendnorm(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, USHORT wkblkno, USHORT cmd)
1095 outb((UCHAR)wkblkno, baseIoAddress + 2);
1096 outb(((PUCHAR)&wklba)[0], baseIoAddress+3);
1097 outb(((PUCHAR)&wklba)[1], baseIoAddress+4);
1098 outb(((PUCHAR)&wklba)[2], baseIoAddress+5);
1099 i=((PUCHAR)&wklba)[3] & 0x0f;
1100 outb((UCHAR)((inb(baseIoAddress+6) & 0xf0) | i), baseIoAddress+6);
1101 outb(((PUCHAR)&cmd)[0], baseIoAddress+7);
1102 outb(((PUCHAR)&cmd)[1], baseIoAddresm);
1105 void Sendbigd(ULONG baseIoAddress, ULONG baseIoAddresm, ULONG wklba, USHORT wkblkno, USHORT cmd)
1107 outb(((PUCHAR)&wkblkno)[1], baseIoAddress+2);
1108 outb(((PUCHAR)&wkblkno)[0], baseIoAddress+2);
1109 outb(((PUCHAR)&wklba)[3], baseIoAddress+3);
1110 outb(0, baseIoAddress+4);
1111 outb(0, baseIoAddress+5);
1112 outb(((PUCHAR)&wklba)[0], baseIoAddress+3);
1113 outb(((PUCHAR)&wklba)[1], baseIoAddress+4);
1114 outb(((PUCHAR)&wklba)[2], baseIoAddress+5);
1115 outb(((PUCHAR)&cmd)[0], baseIoAddress+7);
1116 outb(((PUCHAR)&cmd)[1], baseIoAddresm);
1124 static void internal_done(Scsi_Cmnd * SCpnt)
1126 SCpnt->SCp.Status++;
1129 int atp86x_command(Scsi_Cmnd * SCpnt)
1132 atp86x_queuecommand(SCpnt, internal_done);
1134 SCpnt->SCp.Status = 0;
1135 while (!SCpnt->SCp.Status)
1137 return SCpnt->result;
1140 int fill_sensekey_buf(struct hw_device_ext * devext, UCHAR tid)
1143 static UCHAR sensd[16]= {0xF0,0,0x03,0,0,0,0,0x8,0,0,0,0,0x11,0x00,0,0};
1144 static UCHAR sensdw[16]= {0xF0,0,0x03,0,0,0,0,0x8,0,0,0,0,0x0C,0x00,0,0};
1145 static UCHAR sensda[16]= {0x70,0,0x05,0,0,0,0,0x8,0,0,0,0,0x20,0x00,0,0};
1146 static UCHAR sensdif[16]= {0x70,0,0x05,0,0,0,0,0x8,0,0,0,0,0x24,0x00,0,0};
1147 static UCHAR sensdip[16]= {0x70,0,0x05,0,0,0,0,0x8,0,0,0,0,0x26,0x00,0,0};
1148 static UCHAR sensdor[16]= {0xF0,0,0x05,0,0,0,0,0x8,0,0,0,0,0x1A,0x00,0,0};
1149 static UCHAR sensdcrc[16]={0x70,0,0x04,0,0,0,0,0x8,0,0,0,0,0x08,0x03,0,0};
1150 static UCHAR sensdabt[16]={0x70,0,0x0B,0,0,0,0,0x8,0,0,0,0,0x00,0x00,0,0};
1151 static UCHAR sensdok[16]= {0x70,0,0x00,0,0,0,0,0x8,0,0,0,0,0x00,0x00,0,0};
1153 switch (devext->dskerr[tid])
1158 devext->sensd[tid][i]=sensda[i];
1164 devext->sensd[tid][i]=sensdif[i];
1170 devext->sensd[tid][i]=sensdip[i];
1176 devext->sensd[tid][i]=sensdor[i];
1182 devext->sensd[tid][i]=sensd[i];
1185 devext->sensd[tid][3]=(UCHAR)((devext->dskerr_LBA[tid]>>24));
1186 devext->sensd[tid][4]=(UCHAR)((devext->dskerr_LBA[tid]>>16));
1187 devext->sensd[tid][5]=(UCHAR)((devext->dskerr_LBA[tid]>>8));
1188 devext->sensd[tid][6]=(UCHAR)(devext->dskerr_LBA[tid]);
1193 devext->sensd[tid][i]=sensdw[i];
1199 devext->sensd[tid][i]=sensdcrc[i];
1205 devext->sensd[tid][i]=sensdok[i];
1212 devext->sensd[tid][i]=sensdabt[i];
1216 #ifdef DEBUG_SENSEKEY
1217 printk("TID %2X SenseKey=",tid);
1220 printk("%2X ",devext->sensd[tid][i]);
1228 unsigned char EnableSMART(struct hw_device_ext * devext)
1230 unsigned char Value8;
1232 Outpb(devext->SamwiseBaseIoAddress, 6, devext->SamwiseHDSelect);
1235 Value8 = Inpb(devext->SamwiseBaseIoAddress, 7);
1236 if((Value8 & 0x88) != 0x00)
1241 /* ATA Identify device command */
1242 Outpb(devext->SamwiseBaseIoAddress, 1, 0xd8);
1243 Outpb(devext->SamwiseBaseIoAddress, 4, 0x4f);
1244 Outpb(devext->SamwiseBaseIoAddress, 5, 0xc2);
1245 Outpb(devext->SamwiseBaseIoAddress, 7, 0xb0);
1250 Value8 = Inpb(devext->SamwiseBaseIoAddress, 7);
1251 if((Value8 & 0x80) == 0 )
1257 if ((Value8 & 0x01) == 0x01 )
1262 if ((Value8 & 0xf8) == 0x58 )
1268 }//end EnableSMART()
1271 void Noiocmd(struct hw_device_ext * devext, Scsi_Cmnd * Srb)
1277 struct scatterlist *sgpnt;
1278 //#ifdef MODESENSE_DEBUG
1279 // printk("Noiocmd: CDB=%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",Srb->cmnd[0],Srb->cmnd[1],
1280 // Srb->cmnd[2],Srb->cmnd[3],Srb->cmnd[4],Srb->cmnd[5],Srb->cmnd[6],Srb->cmnd[7],
1281 // Srb->cmnd[8],Srb->cmnd[9]);
1283 sgpnt = (struct scatterlist *) Srb->request_buffer;
1286 saddr = sgpnt[0].address;
1288 saddr=Srb->request_buffer;
1294 #ifdef MODESENSE_DEBUG
1295 printk("Noiocmd: Mode Sense(6): Page=%2X, length=%2X cap=%8lX\n",Srb->cmnd[2],Srb->cmnd[4],
1299 #ifdef IXP42X_SUPPORT
1300 devext->page0[4]=(UCHAR)(l>>24);
1301 devext->page0[5]=(UCHAR)(l>>16);
1302 devext->page0[6]=(UCHAR)(l>>8);
1303 devext->page0[7]=(UCHAR)(l);
1304 devext->page1[4]=(UCHAR)(l>>24);
1305 devext->page1[5]=(UCHAR)(l>>16);
1306 devext->page1[6]=(UCHAR)(l>>8);
1307 devext->page1[7]=(UCHAR)(l);
1308 devext->page1c[4]=(UCHAR)(l>>24);
1309 devext->page1c[5]=(UCHAR)(l>>16);
1310 devext->page1c[6]=(UCHAR)(l>>8);
1311 devext->page1c[7]=(UCHAR)(l);
1314 ((PUCHAR)&l)[0]=((PUCHAR)&l)[3];
1317 ((PUCHAR)&l)[1]=((PUCHAR)&l)[2];
1319 ((PULONG)&devext->page0[4])[0]=l;
1320 ((PULONG)&devext->page1[4])[0]=l;
1321 ((PULONG)&devext->page1c[4])[0]=l;
1324 #ifdef MODESENSE_DEBUG
1325 printk("Noiocm: Mode Sense(6): Page data[4]=%2X %2X %2X %2X\n",devext->page0[4],
1326 devext->page0[5],devext->page0[6],devext->page0[7]);
1329 if ((Srb->cmnd[2] & 0x3f) == 0)
1335 memcpy(saddr,&devext->page0[0],j);
1339 if ((Srb->cmnd[2] & 0x3f) == 1)
1345 memcpy(saddr,&devext->page1[0],j);
1349 if ((Srb->cmnd[2] & 0x3f) == 0x1c)
1355 memcpy(saddr,&devext->page1c[0],j);
1359 if ((Srb->cmnd[2] & 0x3f) == 0x3f)
1366 memcpy(saddr,&devext->page1[0],i);
1368 memcpy(saddr,&c[0],1);
1376 memcpy(saddr,&devext->page1c[12],i);
1384 memcpy(saddr,&devext->page0[0],i);
1398 switch(Srb->cmnd[3])
1401 if (Srb->cmnd[1] & 0x01)
1403 devext->dskerr[t]=0x54;
1404 goto print_autosens; // EVPD not supported
1411 memcpy(saddr,&devext->inqdat[t][0],j);
1416 memcpy(saddr, smart_buf, sizeof(smart_buf));
1425 unsigned char cStatus;
1426 Srb->result = EnableSMART(devext);
1427 // printk("EnableSMART cStatus %x\n",Srb->result);
1428 if(Srb->result == 0)
1430 devext->inqdat[t][38] = 1;
1438 #ifdef IXP42X_SUPPORT
1439 c[0]= (UCHAR) (devext->cap[t]>>24);
1440 c[1]= (UCHAR) (devext->cap[t]>>16);
1441 c[2]= (UCHAR) (devext->cap[t]>>8);
1442 c[3]= (UCHAR) (devext->cap[t]);
1445 c[6]= 0x02; // block length = 512 bytes
1448 c[0]=((PUCHAR)(&devext->cap[t]))[3];
1449 c[1]=((PUCHAR)(&devext->cap[t]))[2];
1450 c[2]=((PUCHAR)(&devext->cap[t]))[1];
1451 c[3]=((PUCHAR)(&devext->cap[t]))[0];
1452 ((PULONG)&c[4])[0]=0x00020000;
1454 memcpy(saddr,&c[0],8);
1460 #ifdef DEBUG_SENSEKEY
1461 printk("ATP86X: Request sense command comes!\n");
1468 fill_sensekey_buf(devext,t);
1469 memcpy(saddr,&devext->sensd[t][0],j);
1470 devext->dskerr[t]=0;
1475 if ((j != 0x00) && (j != 0x15) && (j != 0x55) &&
1476 (j != 0x1e) && (j != 0x04))
1478 //printk("Noiocmd: NOT 'TUR' 'Mode Select(6)' 'Mode Select(10)' 'PAMR' 'FORMAT UNIT'\n");
1480 devext->dskerr[t]=0x50;
1483 #ifdef DEBUG_SENSEKEY
1484 printk("ATP86X: Not supported CDB = ");
1485 for (j=0;j<Srb->cmd_len;j++ )
1486 printk("%2X ",Srb->cmnd[j]);
1494 void is867(struct hw_device_ext * devext)
1496 ULONG baseIoAddress = devext->BaseIoAddress[0];
1498 UCHAR i,j,k,l,ata66,is66,iswd;
1502 /* Port 4A: IDE0 8 bit IO ports speed */
1503 Outpb(baseIoAddress,0x4a,0x43);
1504 Outpb(baseIoAddress,0x5a,0x43);
1505 Outpb(baseIoAddress,0x6a,0x43);
1506 Outpb(baseIoAddress,0x7a,0x43);
1509 devext->ata66=ata66;
1510 /* Port 48: IDE0 master DATA PIO/NDMA speed : 0aaarrrr
1511 Port 49: IDE0 slave DATA PIO/NDMA speed : 0aaarrrr
1512 Port 4B: IDE0 UDMA mode (default 00H)
1514 bit6-4 :slave-IDE UDMA MODE#
1524 bit2-0 :master-IDE UDMA MODE#
1534 Outpb(baseIoAddress,0x48,0x31);
1535 Outpb(baseIoAddress,0x49,0x31);
1536 Outpb(baseIoAddress,0x4b,0x00);
1537 Outpb(baseIoAddress,0x58,0x31);
1538 Outpb(baseIoAddress,0x59,0x31);
1539 Outpb(baseIoAddress,0x5b,0x00);
1540 Outpb(baseIoAddress,0x68,0x31);
1541 Outpb(baseIoAddress,0x69,0x31);
1542 Outpb(baseIoAddress,0x6b,0x00);
1543 Outpb(baseIoAddress,0x78,0x31);
1544 Outpb(baseIoAddress,0x79,0x31);
1545 Outpb(baseIoAddress,0x7b,0x00);
1546 /* cbuf[0]: UDMA mode value for port 0x4B IDE0
1547 cbuf[1]: UDMA mode value for port 0x5B IDE1
1548 cbuf[2]: UDMA mode value for port 0x6B IDE2
1549 cbuf[3]: UDMA mode value for port 0x7B IDE3
1556 /* Scan device for master/slave of 4 channels */
1557 for ( i = 0 ; i < 8 ; i++ )
1559 /* j = out to 1X6 value , i=xx0: Master 0xA0 or i=xx1: Slave 0xB0 */
1560 baseIoAddress=devext->BaseIoAddress[i >> 1];
1562 if ((i & 0x01) != 0)
1566 Outpb(baseIoAddress,6,j);
1568 /* k = in from 1X7 value */
1569 k=Inpb(baseIoAddress,7);
1570 if ((k & 0x88) != 0x00)
1572 devext->hd_status[i]=0x7f;
1575 /* ATA Identify device command */
1576 Outpb(baseIoAddress,7,0xec);
1579 l=Inpb(baseIoAddress,7);
1580 if ((l & 0x80) != 0 )
1584 if ((l & 0x01) == 0x01 )
1586 devext->hd_status[i]=0x7f;
1589 if ((l & 0xf8) != 0x58 )
1591 devext->hd_status[i]=0x7f;
1594 for (m=0; m < 0x100; m++)
1596 mbuf[m]=Inpw(baseIoAddress,0);
1600 k=Inpb(baseIoAddress,7);
1601 /* active_id = device exists */
1604 devext->active_id |= k;
1606 /* device type =0, capacity = word 60:61 (28-bit LBA) or word 100:101 (48-bit LBA) */
1607 devext->devtype[i]=0;
1608 #ifdef IXP42X_SUPPORT
1609 devext->cap[i] = mbuf[61]<<16;
1610 devext->cap[i] |= mbuf[60];
1612 devext->cap[i]=((PULONG)&mbuf[60])[0];
1614 if (devext->cap[i] == 0x0fffffff)
1616 if ((mbuf[100] != 0) || (mbuf[101] != 0) ||
1617 (mbuf[102] != 0) || (mbuf[103] != 0))
1619 devext->bigdrv[i]=1;
1620 #ifdef IXP42X_SUPPORT
1621 devext->cap[i] = mbuf[101]<<16;
1622 devext->cap[i] |= mbuf[100];
1624 devext->cap[i]=((PULONG)&mbuf[100])[0];
1626 r=((PULONG)&mbuf[102])[0];
1629 devext->cap[i]=0xffffffff;
1633 /* capacity -2?? why ??*/
1634 devext->cap[i] -= 2;
1635 /* fill inquiry data from byte 8 to byte 8+ 14*2 */
1637 for ( l=27; l < 41; l++ )
1639 ((PUSHORT)&devext->inqdat[i][0])[k++]=(USHORT)((((PUCHAR)&mbuf[l])[0] << 8) | ((PUCHAR)&mbuf[l])[1]);
1641 /* fill inquiry data from byte 0 to byte 7 */
1642 #ifdef IXP42X_SUPPORT
1643 devext->inqdat[i][0]= 0x00;
1644 devext->inqdat[i][1]= 0x00;
1645 devext->inqdat[i][2]= 0x02;
1646 devext->inqdat[i][3]= 0x02;
1647 devext->inqdat[i][4]= 0x7D;
1648 devext->inqdat[i][5]= 0x00;
1649 devext->inqdat[i][6]= 0x00;
1650 devext->inqdat[i][7]= 0x32;
1652 ((PULONG)(&devext->inqdat[i][0]))[0]=0x02020000;
1653 ((PULONG)(&devext->inqdat[i][0]))[1]=0x3200007d;
1655 devext->inqdat[i][36]=0;
1656 printk(KERN_INFO " ID: %2d %s ", i, &devext->inqdat[i][8]);
1663 /* fill PIO/DMA/UDMA speed table and set feature to drive here */
1666 Outpb(baseIoAddress,1,0x03);
1667 /* Identify device word 88:
1669 V 14 1 = Ultra DMA mode 6 is selected
1670 0 = Ultra DMA mode 6 is not selected
1671 V 13 1 = Ultra DMA mode 5 is selected
1672 0 = Ultra DMA mode 5 is not selected
1673 V 12 1 = Ultra DMA mode 4 is selected
1674 0 = Ultra DMA mode 4 is not selected
1675 V 11 1 = Ultra DMA mode 3 is selected
1676 0 = Ultra DMA mode 3 is not selected
1677 V 10 1 = Ultra DMA mode 2 is selected
1678 0 = Ultra DMA mode 2 is not selected
1679 V 9 1 = Ultra DMA mode 1 is selected
1680 0 = Ultra DMA mode 1 is not selected
1681 V 8 1 = Ultra DMA mode 0 is selected
1682 0 = Ultra DMA mode 0 is not selected
1684 F 6 1 = Ultra DMA mode 6 and below are supported
1685 F 5 1 = Ultra DMA mode 5 and below are supported
1686 F 4 1 = Ultra DMA mode 4 and below are supported
1687 F 3 1 = Ultra DMA mode 3 and below are supported
1688 F 2 1 = Ultra DMA mode 2 and below are supported
1689 F 1 1 = Ultra DMA mode 1 and below are supported
1690 F 0 1 = Ultra DMA mode 0 is supported
1692 if ((mbuf[88] & 0x0018) == 0)
1694 if ((iswd == 0) && ((mbuf[88] & 0x007f) != 0))
1697 Outpb(baseIoAddress,2,0x42);
1699 printk("UDMA2 (33)\n");
1705 /* Multiword DMA mode 0-2 */
1706 k=(UCHAR)(mbuf[63] & 0x0007);
1711 printk("Mw-DMA %2X\n",k);
1714 Outpb(baseIoAddress,2,k);
1726 if (((i < 2) && ((ata66 & 0x01) == 0)) ||
1727 ((i > 1) && ((ata66 & 0x02) == 0)))
1729 if ((mbuf[88] & 0x0020) == 0)
1732 Outpb(baseIoAddress,2,0x44);
1735 printk("UDMA4 (66)\n");
1741 if ((mbuf[88] & 0x0040) == 0)
1744 Outpb(baseIoAddress,2,0x45);
1746 printk("UDMA5 (100)\n");
1753 Outpb(baseIoAddress,2,0x46);
1755 printk("UDMA6 (133)\n");
1763 Outpb(baseIoAddress,2,0x42);
1765 printk("UDMA2 (33)\n");
1769 /* set feature UDMA or NDMA mode */
1770 Outpb(baseIoAddress,7,0xef);
1772 k=Inpb(baseIoAddress,7);
1773 while ((k & 0x80) != 0)
1775 k=Inpb(baseIoAddress,7);
1777 if ((k & 0xf9) == 0x50)
1934 baseIoAddress=devext->BaseIoAddress[0];
1935 Outpb(baseIoAddress,0x4b,cbuf[0]);
1936 Outpb(baseIoAddress,0x5b,cbuf[1]);
1937 Outpb(baseIoAddress,0x6b,cbuf[2]);
1938 Outpb(baseIoAddress,0x7b,cbuf[3]);
1942 void is865(struct hw_device_ext * devext,struct pci_dev *pdev)
1944 ULONG baseIoAddress = devext->BaseIoAddress[0];
1946 UCHAR i,j,k,l,ata66,is66,iswd;
1951 devext->ata66=ata66;
1952 /* config +40+00: IDE0 master DATA PIO/NDMA speed : 0aaarrrr
1953 config +40+01: IDE0 slave DATA PIO/NDMA speed : 0aaarrrr
1954 config +40+02: IDE1 master DATA PIO/NDMA speed : 0aaarrrr
1955 config +40+03: IDE1 slave DATA PIO/NDMA speed : 0aaarrrr
1956 config +40+04: IDE0 UDMA mode (default 00H)
1957 config +40+05: IDE1 UDMA mode (default 00H)
1959 bit6-4 :slave-IDE UDMA MODE#
1968 bit2-0 :master-IDE UDMA MODE#
1978 printk("is865: write PIO/DMA speed: 40,41,42,43=0x31. 44,45 =0 \n");
1980 pci_write_config_byte(pdev, 0x40, 0x31);
1981 pci_write_config_byte(pdev, 0x41, 0x31);
1982 pci_write_config_byte(pdev, 0x42, 0x31);
1983 pci_write_config_byte(pdev, 0x43, 0x31);
1984 pci_write_config_byte(pdev, 0x44, 0x00);
1985 pci_write_config_byte(pdev, 0x45, 0x00);
1987 /* cbuf[0]: UDMA mode value for port 0x4B IDE0
1988 cbuf[1]: UDMA mode value for port 0x5B IDE1
1989 cbuf[2]: UDMA mode value for port 0x6B IDE2
1990 cbuf[3]: UDMA mode value for port 0x7B IDE3
1997 printk("is865: scan 4 devices of 2 channels\n");
1999 /* Scan device for master/slave of 2 channels */
2000 for ( i = 0 ; i < 4 ; i++ )
2002 /* j = out to 1X6 value , i=xx0: Master 0xA0 or i=xx1: Slave 0xB0 */
2003 if (i<2) baseIoAddress=devext->BaseIoAddress[0];
2004 else baseIoAddress=devext->BaseIoAddress[1];
2006 if ((i & 0x01) != 0)
2011 printk("is865: i=%2X out %2X to port %4lX \n",i,j,(unsigned long)(baseIoAddress+6));
2013 Outpb(baseIoAddress,6,j);
2015 /* k = in from 1X7 value */
2016 k=Inpb(baseIoAddress,7);
2018 printk("is865: i=%2X in port %4lX = %2X\n",i,(unsigned long)(baseIoAddress+7),k);
2020 if ((k & 0x88) != 0x00)
2022 devext->hd_status[i]=0x7f;
2027 printk("is865: i=%2X out 0xEC to port %4lX \n",i,(unsigned long)(baseIoAddress+7));
2029 /* ATA Identify device command */
2030 Outpb(baseIoAddress,7,0xec);
2033 l=Inpb(baseIoAddress,7);
2035 printk("is865: i=%2X in port %4lX = %2X\n",i,(unsigned long)(baseIoAddress+7),l);
2037 if ((l & 0x80) != 0 )
2041 if ((l & 0x01) == 0x01 )
2043 devext->hd_status[i]=0x7f;
2047 if ((l & 0xf8) != 0x58 )
2049 devext->hd_status[i]=0x7f;
2053 for (m=0; m < 0x100; m++)
2055 mbuf[m]=Inpw(baseIoAddress,0);
2059 k=Inpb(baseIoAddress,7);
2060 /* active_id = device exists */
2063 devext->active_id |= k;
2065 printk("is865: Check 512bytes identify data\n");
2067 /* device type =0, capacity = word 60:61 (28-bit LBA) or word 100:101 (48-bit LBA) */
2068 devext->devtype[i]=0;
2069 #ifdef IXP42X_SUPPORT
2070 devext->cap[i] = mbuf[61]<<16;
2071 devext->cap[i] |= mbuf[60];
2073 devext->cap[i]=((PULONG)&mbuf[60])[0];
2075 if (devext->cap[i] == 0x0fffffff)
2077 if ((mbuf[100] != 0) || (mbuf[101] != 0) ||
2078 (mbuf[102] != 0) || (mbuf[103] != 0))
2080 devext->bigdrv[i]=1;
2081 #ifdef IXP42X_SUPPORT
2082 devext->cap[i] = mbuf[101]<<16;
2083 devext->cap[i] |= mbuf[100];
2085 devext->cap[i]=((PULONG)&mbuf[100])[0];
2087 r=((PULONG)&mbuf[102])[0];
2090 devext->cap[i]=0xffffffff;
2094 /* capacity -2?? why ??*/
2095 devext->cap[i] -= 2;
2098 printk("is865: capacity[%2x] = %8lX\n",i,devext->cap[i]);
2100 /* fill inquiry data from byte 8 to byte 8+ 14*2 */
2102 for ( l=27; l < 41; l++ )
2104 ((PUSHORT)&devext->inqdat[i][0])[k++]=(USHORT)((((PUCHAR)&mbuf[l])[0] << 8) | ((PUCHAR)&mbuf[l])[1]);
2106 /* fill inquiry data from byte 0 to byte 7 */
2107 #ifdef IXP42X_SUPPORT
2108 devext->inqdat[i][0]= 0x00;
2109 devext->inqdat[i][1]= 0x00;
2110 devext->inqdat[i][2]= 0x02;
2111 devext->inqdat[i][3]= 0x02;
2112 devext->inqdat[i][4]= 0x7D;
2113 devext->inqdat[i][5]= 0x00;
2114 devext->inqdat[i][6]= 0x00;
2115 devext->inqdat[i][7]= 0x32;
2117 ((PULONG)(&devext->inqdat[i][0]))[0]=0x02020000;
2118 ((PULONG)(&devext->inqdat[i][0]))[1]=0x3200007d;
2120 devext->inqdat[i][36]=0;
2122 devext->inqdat[i][37] = 0;
2123 devext->inqdat[i][38] = 0;
2124 if((mbuf[83] & 0x4000) == 0x4000)
2126 if((mbuf[82] & 0x01) == 0x01)
2128 devext->inqdat[i][37] = 1;
2129 if((mbuf[85] & 0x01) == 0x01)
2131 devext->inqdat[i][38] = 1;
2136 devext->SamwiseBaseIoAddress = baseIoAddress;
2137 devext->SamwiseHDSelect = j;
2138 // printk("\n %x %x", devext->SamwiseBaseIoAddress, devext->SamwiseHDSelect);
2140 printk(KERN_INFO " ID: %2d %s ", i, &devext->inqdat[i][8]);
2147 /* fill PIO/DMA/UDMA speed table and set feature to drive here */
2150 Outpb(baseIoAddress,1,0x03);
2151 /* Identify device word 88:
2153 V 14 1 = Ultra DMA mode 6 is selected
2154 0 = Ultra DMA mode 6 is not selected
2155 V 13 1 = Ultra DMA mode 5 is selected
2156 0 = Ultra DMA mode 5 is not selected
2157 V 12 1 = Ultra DMA mode 4 is selected
2158 0 = Ultra DMA mode 4 is not selected
2159 V 11 1 = Ultra DMA mode 3 is selected
2160 0 = Ultra DMA mode 3 is not selected
2161 V 10 1 = Ultra DMA mode 2 is selected
2162 0 = Ultra DMA mode 2 is not selected
2163 V 9 1 = Ultra DMA mode 1 is selected
2164 0 = Ultra DMA mode 1 is not selected
2165 V 8 1 = Ultra DMA mode 0 is selected
2166 0 = Ultra DMA mode 0 is not selected
2168 F 6 1 = Ultra DMA mode 6 and below are supported
2169 F 5 1 = Ultra DMA mode 5 and below are supported
2170 F 4 1 = Ultra DMA mode 4 and below are supported
2171 F 3 1 = Ultra DMA mode 3 and below are supported
2172 F 2 1 = Ultra DMA mode 2 and below are supported
2173 F 1 1 = Ultra DMA mode 1 and below are supported
2174 F 0 1 = Ultra DMA mode 0 is supported
2176 if ((mbuf[88] & 0x0018) == 0)
2178 if ((iswd == 0) && ((mbuf[88] & 0x007f) != 0))
2181 Outpb(baseIoAddress,2,0x42);
2183 printk("UDMA2 (33)\n");
2189 /* Multiword DMA mode 0-2 */
2190 k=(UCHAR)(mbuf[63] & 0x0007);
2195 printk("MwDMA %2X\n",k);
2198 Outpb(baseIoAddress,2,k);
2209 if (((i < 2) && ((ata66 & 0x01) == 0)) ||
2210 ((i > 1) && ((ata66 & 0x02) == 0)))
2212 if ((mbuf[88] & 0x0020) == 0)
2215 Outpb(baseIoAddress,2,0x44);
2218 printk("UDMA4 (66)\n");
2224 if ((devext->chipver <=3) || ((mbuf[88] & 0x0040) == 0))
2227 Outpb(baseIoAddress,2,0x45);
2229 printk("UDMA5 (100)\n");
2236 Outpb(baseIoAddress,2,0x46);
2238 printk("UDMA6 (133)\n");
2246 Outpb(baseIoAddress,2,0x42);
2248 printk("UDMA2 (33)\n");
2253 printk("is865: Set Featur: enable UDMA or NDMA\n");
2255 /* set feature UDMA or NDMA mode */
2256 Outpb(baseIoAddress,7,0xef);
2258 k=Inpb(baseIoAddress,7);
2259 while ((k & 0x80) != 0)
2261 k=Inpb(baseIoAddress,7);
2263 if ((k & 0xf9) == 0x50)
2349 printk("is865: End : enable UDMA 44= %2x ,45= %2x \n",cbuf[0],cbuf[1]);
2351 pci_write_config_byte(pdev, 0x44, cbuf[0]);
2352 pci_write_config_byte(pdev, 0x45, cbuf[1]);
2358 /* return non-zero on detection */
2359 int atp86x_detect(Scsi_Host_Template * tpnt)
2363 ULONG baseIoAddress;
2364 unsigned int base_io, error;
2366 struct pci_dev *pdev[5];
2369 struct Scsi_Host *shpnt = NULL;
2370 struct hw_device_ext *devext;
2380 static USHORT devid[4] = { ATP865_DEVID1,ATP865_DEVID2,ATP867_DEVID1, 0};
2381 static UCHAR page0[16]={0x0d,0,0,8,0,0,0,0,0,0,2,0,0,0,0,0};
2382 static UCHAR page1[24]={0x17,0,0,8,0,0,0,0,0,0,2,0,0x81,0x0a,0xc0,0x08,0x18,0x0a,0,0,0,0,0,0};
2383 static UCHAR page1c[24]={0x17,0,0,8,0,0,0,0,0,0,2,0,0x9c,0x0a,0,3,0,0,0,0,0,0,0,1};
2386 printk(KERN_INFO "atp86x_detect: \n");
2387 if (!pci_present()) {
2388 printk(KERN_INFO" NO PCI SUPPORT.\n");
2391 tpnt->proc_name = "atp86x";
2393 for (h = 0; h < 4; h++) {
2394 devext = &dev_ext[h];
2395 for (k=0; k < sizeof(struct hw_device_ext); k++) {
2396 ((PUCHAR)devext)[k] = 0;
2399 devext->host_id = 0x08;
2401 for (k=0; k < 8 ; k++) {
2402 devext->devtype[k] = 0x7f;
2405 for (k=0; k < 16 ; k++) {
2406 devext->page0[k]=page0[k];
2408 for (k=0; k < 24 ; k++) {
2409 devext->page1[k]=page1[k];
2410 devext->page1c[k]=page1c[k];
2412 for (j=0; j < 8; j++)
2414 for (k=0; k < 16 ; k++) {
2415 devext->sensd[j][k]=0x0;
2417 devext->dskerr_LBA[j]=0;
2420 for (j=0; j < 4; j++)
2422 for (k=0; k < qcnt1; k++)
2424 devext->plsrb[j][k]=&devext->lsrb[j][k];
2425 #ifdef IXP42X_SUPPORT
2426 // devext->lsrb[j][k].prd = kmalloc(256, GFP_ATOMIC|GFP_DMA);
2427 devext->lsrb[j][k].prd = pci_alloc_consistent(hwif->pci_dev,
2429 &(devext->lsrb[j][k].prdaddr));
2432 devext->lsrb[j][k].prd = kmalloc(256, GFP_KERNEL);
2433 devext->lsrb[j][k].prdaddr=(ULONG)virt_to_bus(devext->lsrb[j][k].prd);
2442 while (devid[h] != 0) {
2443 pdev[4] = pci_find_device(0x1191, devid[h], pdev[4]);
2444 if (pdev[4] == NULL || pci_enable_device(pdev[4])) {
2449 dev_id[4] = devid[h];
2451 error = pci_read_config_byte(pdev[4], 0x08, &chip_ver[4]);
2452 // printk("Chip version = %2X\n",chip_ver[4]);
2453 // pci_write_config_byte(pdev[4], 0x0D, 22);
2454 pci_write_config_byte(pdev[4], 0x0D, 0x80);//JCC082803
2455 pdev[tmpcnt] = pdev[4];
2456 chip_ver[tmpcnt] = chip_ver[4];
2457 dev_id[tmpcnt] = dev_id[4];
2467 for (h = 0; h < 4; h++) {
2468 devext = &dev_ext[h];
2469 if (pdev[h]==NULL) {
2472 devext->pdev=pdev[h];
2473 for (j=0; j < 4; j++)
2475 for (k=0; k < qcnt1; k++)
2477 devext->plsrb[j][k]=&devext->lsrb[j][k];
2478 #ifdef IXP42X_SUPPORT
2479 // devext->lsrb[j][k].prd = kmalloc(256, GFP_ATOMIC|GFP_DMA);
2480 devext->lsrb[j][k].prd = pci_alloc_consistent(pdev[h],
2481 256, &(devext->lsrb[j][k].prdaddr));
2483 devext->lsrb[j][k].prd = kmalloc(256, GFP_KERNEL);
2484 devext->lsrb[j][k].prdaddr=(ULONG)virt_to_bus(devext->lsrb[j][k].prd);
2488 /* Found an atp86x */
2490 base_io = pci_resource_start(pdev[h], 0);
2493 base_io &= 0xfffffff8;
2494 //#ifdef DETECT_DEBUG
2495 // printk("atp86x: dev_id[%d] = %X base_io = %X .\n",h, dev_id[h], base_io);
2497 if (dev_id[h] ==0x0A)
2499 if (check_region(base_io,0x80) != 0)
2504 printk(KERN_INFO " ACARD ATP-867 PCI ATA133 4-Channels Host Adapter: %d IO:%X, IRQ:%d.\n"
2506 devext->pdev = pdev[h];
2507 devext->chipver = chip_ver[h];
2508 // printk("Chip version = %2X\n",devext->chipver);
2509 devext->dev_id = dev_id[h];
2510 devext->BaseIoAddress[0] = base_io;
2511 devext->BaseIoAddress[1] = base_io + 0x10;
2512 devext->BaseIoAddress[2] = base_io + 0x20;
2513 devext->BaseIoAddress[3] = base_io + 0x30;
2514 devext->BaseIoAddresm[0] = base_io + 0x40;
2515 devext->BaseIoAddresm[1] = base_io + 0x50;
2516 devext->BaseIoAddresm[2] = base_io + 0x60;
2517 devext->BaseIoAddresm[3] = base_io + 0x70;
2521 devext->pdev = pdev[h];
2522 devext->dev_id = dev_id[h];
2523 devext->chipver = chip_ver[h];
2525 if (check_region(base_io,0x8) != 0)
2529 printk(KERN_INFO " ACARD ATP-865 PCI ATA133 2-Channels Host Adapter: %d IO:%X, IRQ:%d.\n"
2531 // printk("Chip version = %2X\n",devext->chipver);
2532 devext->BaseIoAddress[0] = base_io;
2533 base_io = pci_resource_start(pdev[h],1);
2535 printk("atp865: dev_id[%d] = %04X base_io 1 = %04X .\n",h, dev_id[h], base_io);
2537 if (check_region(base_io,0x3) != 0)
2541 devext->BaseIoAddress[2] = base_io +2;
2542 base_io = pci_resource_start(pdev[h],2);
2544 printk("atp865: dev_id[%d] = %04X base_io 2 = %04X .\n",h, dev_id[h], base_io);
2546 if (check_region(base_io,0x8) != 0)
2550 devext->BaseIoAddress[1] = base_io ;
2551 base_io = pci_resource_start(pdev[h],3);
2553 printk("atp865: dev_id[%d] = %04X base_io 3 = %04X .\n",h, dev_id[h], base_io);
2555 if (check_region(base_io,0x3) != 0)
2559 devext->BaseIoAddress[3] = base_io +2;
2560 base_io = pci_resource_start(pdev[h],4);
2562 printk("atp865: dev_id[%d] = %04X base_io 4 = %04X .\n",h, dev_id[h], base_io);
2564 if (check_region(base_io,0x10) != 0)
2568 devext->BaseIoAddresm[0] = base_io ;
2569 devext->BaseIoAddresm[1] = base_io + 0x08;
2570 devext->BaseIoAddresm[2] = base_io + 0x02;
2571 devext->BaseIoAddresm[3] = base_io + 0x0A;
2576 shpnt = scsi_register(tpnt, 4);
2579 printk(KERN_INFO "scsi_register failure!!\n");
2585 if (request_irq(irq, atp86x_intr_handle, SA_SHIRQ, "atp86x", devext)) {
2586 printk(KERN_ERR "Unable to allocate IRQ for Acard controller.\n");
2590 if (dev_id[h] ==0x0A)
2593 printk("atp867: Out 0x10 to port 0x28 \n");
2595 j=Inpb(base_io,0x28);
2597 Outpb(base_io,0x28,j);
2599 printk("atp867: is867 enter \n");
2603 printk("atp867: is867 exit \n");
2604 printk("atp867: clear bit4,5 and set bit 6,7 to port 0x28 \n");
2606 j=Inpb(base_io,0x28);
2609 Outpb(base_io,0x28,j);
2611 printk("atp867: clear bit0-3 to port 0x29 \n");
2613 baseIoAddress = devext->BaseIoAddress[0];
2614 Outpb(baseIoAddress,0x29,(UCHAR)
2615 (Inpb(baseIoAddress,0x29) & 0xe0));
2618 printk("atp867: I2C init \n");
2620 for (t=0; t < 4; t++)
2622 baseIoAddress = devext->BaseIoAddress[t];
2626 Outpb(baseIoAddress,0x0e,0x08);
2627 i2cwrite(baseIoAddress,0x4e,0x80);
2628 i2cread(baseIoAddress,0x4f,&j);
2629 i2cwrite(baseIoAddress,0x4e,0x00);
2630 i2cread(baseIoAddress,0x4f,&n);
2631 i2cread(baseIoAddress,0x58,&l);
2632 if ((j == 0x5c) && (n == 0xa3) && (l == 0x40))
2636 devext->c_mask |= j;
2637 i2cread(baseIoAddress,0x41,&j);
2638 i2cread(baseIoAddress,0x42,&j);
2639 i2cwrite(baseIoAddress,0x43,0xf8);
2640 i2cwrite(baseIoAddress,0x44,0x0e);
2641 i2cwrite(baseIoAddress,0x2b,0xff);
2642 i2cwrite(baseIoAddress,0x2c,0x3e);
2643 i2cwrite(baseIoAddress,0x2f,0xff);
2644 i2cwrite(baseIoAddress,0x30,0x3e);
2645 i2cwrite(baseIoAddress,0x33,0xff);
2646 i2cwrite(baseIoAddress,0x34,0x3e);
2647 i2cwrite(baseIoAddress,0x4d,0xc0);
2648 i2cread(baseIoAddress,0x40,&j);
2649 i2cread(baseIoAddress,0x41,&j);
2650 i2cread(baseIoAddress,0x42,&j);
2651 i2cread(baseIoAddress,0x43,&j);
2652 i2cread(baseIoAddress,0x44,&j);
2653 i2cread(baseIoAddress,0x2b,&j);
2654 i2cread(baseIoAddress,0x2c,&j);
2655 i2cread(baseIoAddress,0x2f,&j);
2656 i2cread(baseIoAddress,0x30,&j);
2657 i2cread(baseIoAddress,0x33,&j);
2658 i2cread(baseIoAddress,0x34,&j);
2659 i2cread(baseIoAddress,0x4d,&j);
2660 i2cwrite(baseIoAddress,0x40,0x43);
2661 Outpb(baseIoAddress,0x0e,0x08);
2662 i2cread(baseIoAddress,0x41,&j);
2663 i2cread(baseIoAddress,0x42,&j);
2664 if (devext->hd_status[t << 1] == 0)
2666 Outpb(baseIoAddress,0x43,0x84);
2670 Outpb(baseIoAddress,0x43,0x80);
2672 Outpb(baseIoAddress,0x0e,0x08);
2673 Outpb(baseIoAddress,0x43,0x20);
2674 baseIoAddress = devext->BaseIoAddress[0];
2675 Outpb(baseIoAddress,0x29,(UCHAR)
2676 (Inpb(baseIoAddress,0x29) | 0x10));
2680 baseIoAddress = devext->BaseIoAddress[0];
2682 printk("atp867: Out 0x06 to port 0x42,0x52,0x62,0x72\n");
2684 Outpb(base_io,0x42,0x06);
2685 Outpb(base_io,0x52,0x06);
2686 Outpb(base_io,0x62,0x06);
2687 Outpb(base_io,0x72,0x06);
2689 else // of device_id = 0x0A
2692 printk("atp865: scan device start here\n");
2695 /* PCI config + 0x40 + 0xA: bit 0: 1= disable INTA */
2697 printk("atp865: read config + 0x4A\n");
2699 pci_read_config_byte(pdev[h], 0x4A, &j);
2701 printk("atp865: read config + 0x4A = %X\n",j);
2704 pci_write_config_byte(pdev[h], 0x4A, j);
2706 printk("atp865: write config + 0x4A = %X\n",j);
2708 is865(devext,pdev[h]);
2709 //// ATP865init(devext);
2710 /* PCI config + 0x40 + 0xA: bit 0: 0= enable INTA
2711 bit 7: 1= enable PCI bus master
2714 printk("atp865: read config + 0x4A\n");
2716 pci_read_config_byte(pdev[h], 0x4A, &j);
2718 printk("atp865: read config + 0x4A = %X\n",j);
2722 pci_write_config_byte(pdev[h], 0x4A, j);
2724 printk("atp865: write config + 0x4A = %X\n",j);
2726 /* disable pre-read or post write , delayed IRQ */
2727 pci_write_config_byte(pdev[h], 0x4B, 0);
2729 printk("atp865: write config + 0x4B = 0\n");
2731 /* Pre-read counter must be 0x000200 4C,4D,4E - 14,15,16*/
2732 pci_write_config_byte(pdev[h], 0x4C, 0);
2734 printk("atp865: write config + 0x4C = 0\n");
2736 pci_write_config_byte(pdev[h], 0x4D, 0x02);
2738 printk("atp865: write config + 0x4D = 0x02\n");
2740 pci_write_config_byte(pdev[h], 0x4E, 0);
2742 printk("atp865: write config + 0x4E = 0\n");
2744 pci_write_config_byte(pdev[h], 0x14, 0);
2746 printk("atp865: write config + 0x14 = 0\n");
2748 pci_write_config_byte(pdev[h], 0x15, 0x02);
2750 printk("atp865: write config + 0x15 = 0x02\n");
2752 pci_write_config_byte(pdev[h], 0x16, 0);
2754 printk("atp865: write config + 0x16 = 0\n");
2757 baseIoAddress = devext->BaseIoAddress[0];
2759 /* Clear Latched IRQ bit and DMA error bit for each channel */
2760 /* set both drives DMA mode for each channel? */
2761 base_io = devext->BaseIoAddresm[0];
2763 printk("atp865: write io= %X , 0x66\n", base_io+0x2);
2764 printk("atp865: write io= %X , 0x66\n", base_io+0xA);
2766 Outpb(base_io,0x2,0x66);
2767 Outpb(base_io,0xA,0x66);
2769 printk("atp865: scan device end here\n");
2773 a867host[h] = shpnt;
2775 shpnt->this_id = 0x08;
2776 shpnt->unique_id = base_io;
2777 shpnt->io_port = base_io;
2778 shpnt->n_io_port = 0x80; /* Number of bytes of I/O space used */
2780 restore_flags(flags);
2781 if (dev_id[h] ==0x0A)
2784 printk("atp867: request region: base_io , 0x80\n");
2786 request_region(base_io, 0x80, "atp86x"); /* Register the IO ports that we use */
2791 printk("atp865: request region: devext->BaseIoAddress[0] , 0x8\n");
2793 request_region(devext->BaseIoAddress[0], 0x8, "atp86x"); /* Register the IO ports that we use */
2795 printk("atp865: request region: devext->BaseIoAddress[1] , 0x3\n");
2797 request_region(devext->BaseIoAddress[2], 0x3, "atp86x"); /* Register the IO ports that we use */
2799 printk("atp865: request region: devext->BaseIoAddress[2] , 0x8\n");
2801 request_region(devext->BaseIoAddress[1], 0x8, "atp86x"); /* Register the IO ports that we use */
2803 printk("atp865: request region: devext->BaseIoAddress[3] , 0x3\n");
2805 request_region(devext->BaseIoAddress[3], 0x3, "atp86x"); /* Register the IO ports that we use */
2807 printk("atp865: request region: devext->BaseIoAddresm[0] , 0x10\n");
2809 request_region(devext->BaseIoAddresm[0], 0x10, "atp86x"); /* Register the IO ports that we use */
2812 // add for smart read =================//
2813 init_timer(&(devext->AdapterTimer));
2814 (devext->AdapterTimer).expires = jiffies + 100; // active per second
2815 (devext->AdapterTimer).data = (ULONG)(devext);
2816 (devext->AdapterTimer).function = smart_timer;
2817 add_timer(&(devext->AdapterTimer));
2818 //======================================//
2823 scsi_unregister(shpnt);
2824 restore_flags(flags);
2834 int i2cwrite(ULONG baseIoAddress, UCHAR Rindex, UCHAR Rval)
2838 Outpb(baseIoAddress,0x43,0x81);
2842 for (i=0; i < 8; i++)
2845 Outpb(baseIoAddress,0x43,j);
2848 if ((k & 0x80) != 0)
2853 Outpb(baseIoAddress,0x43,j);
2856 Outpb(baseIoAddress,0x43,j);
2860 Outpb(baseIoAddress,0x43,j);
2863 Outpb(baseIoAddress,0x43,j);
2865 Outpb(baseIoAddress,0x43,j);
2867 l=Inpb(baseIoAddress,0x43);
2869 Outpb(baseIoAddress,0x43,j);
2871 if ((l & 0x02) != 0)
2873 Outpb(baseIoAddress,0x43,1);
2876 for (i=0; i < 8; i++)
2879 if ((Rindex & 0x80) != 0)
2884 Outpb(baseIoAddress,0x43,j);
2887 Outpb(baseIoAddress,0x43,j);
2890 Outpb(baseIoAddress,0x43,j);
2894 Outpb(baseIoAddress,0x43,j);
2896 Outpb(baseIoAddress,0x43,j);
2898 l=Inpb(baseIoAddress,0x43);
2900 Outpb(baseIoAddress,0x43,j);
2902 if ((l & 0x02) != 0)
2904 Outpb(baseIoAddress,0x43,1);
2907 for (i=0; i < 8; i++)
2910 if ((Rval & 0x80) != 0)
2915 Outpb(baseIoAddress,0x43,j);
2918 Outpb(baseIoAddress,0x43,j);
2921 Outpb(baseIoAddress,0x43,j);
2925 Outpb(baseIoAddress,0x43,j);
2927 Outpb(baseIoAddress,0x43,j);
2929 l=Inpb(baseIoAddress,0x43);
2931 Outpb(baseIoAddress,0x43,j);
2933 Outpb(baseIoAddress,0x43,1);
2934 if ((l & 0x02) != 0)
2941 int i2cread(ULONG baseIoAddress, UCHAR Rindex, PUCHAR Rval)
2945 Outpb(baseIoAddress,0x43,0x81);
2949 for (i=0; i < 8; i++)
2952 Outpb(baseIoAddress,0x43,j);
2955 if ((k & 0x80) != 0)
2960 Outpb(baseIoAddress,0x43,j);
2963 Outpb(baseIoAddress,0x43,j);
2967 Outpb(baseIoAddress,0x43,j);
2970 Outpb(baseIoAddress,0x43,j);
2972 Outpb(baseIoAddress,0x43,j);
2974 l=Inpb(baseIoAddress,0x43);
2976 Outpb(baseIoAddress,0x43,j);
2978 if ((l & 0x02) != 0)
2980 Outpb(baseIoAddress,0x43,1);
2983 for (i=0; i < 8; i++)
2986 if ((Rindex & 0x80) != 0)
2991 Outpb(baseIoAddress,0x43,j);
2994 Outpb(baseIoAddress,0x43,j);
2997 Outpb(baseIoAddress,0x43,j);
3001 Outpb(baseIoAddress,0x43,j);
3003 Outpb(baseIoAddress,0x43,j);
3005 l=Inpb(baseIoAddress,0x43);
3007 Outpb(baseIoAddress,0x43,j);
3010 Outpb(baseIoAddress,0x43,j);
3012 if ((l & 0x02) != 0)
3014 Outpb(baseIoAddress,0x43,1);
3018 Outpb(baseIoAddress,0x43,0x81);
3022 for (i=0; i < 8; i++)
3025 Outpb(baseIoAddress,0x43,j);
3028 if ((k & 0x80) != 0)
3033 Outpb(baseIoAddress,0x43,j);
3036 Outpb(baseIoAddress,0x43,j);
3040 Outpb(baseIoAddress,0x43,j);
3043 Outpb(baseIoAddress,0x43,j);
3045 Outpb(baseIoAddress,0x43,j);
3047 l=Inpb(baseIoAddress,0x43);
3049 Outpb(baseIoAddress,0x43,j);
3051 if ((l & 0x02) != 0)
3053 Outpb(baseIoAddress,0x43,1);
3057 for (i=0; i < 8; i++)
3061 Outpb(baseIoAddress,0x43,j);
3063 l=Inpb(baseIoAddress,0x43);
3064 if ((l & 0x02) != 0)
3069 Outpb(baseIoAddress,0x43,j);
3073 Outpb(baseIoAddress,0x43,j);
3076 Outpb(baseIoAddress,0x43,j);
3079 Outpb(baseIoAddress,0x43,j);
3082 Outpb(baseIoAddress,0x43,j);
3085 Outpb(baseIoAddress,0x43,j);
3088 Outpb(baseIoAddress,0x43,j);
3089 Outpb(baseIoAddress,0x43,1);
3094 /* The abort command does not leave the device in a clean state where
3095 it is available to be used again. Until this gets worked out, we will
3096 leave it commented out. */
3098 int atp86x_abort(Scsi_Cmnd * SCpnt)
3102 struct hw_device_ext *devext;
3104 for (h = 0; h <= admaxu; h++) {
3105 if (SCpnt->host == a867host[h]) {
3109 panic("Abort host not found !");
3112 printk(KERN_DEBUG "c0=%x c1=%x c2=%x c3=%x ", (u_int)devext->CSrb[0],
3113 (u_int)devext->CSrb[1],(u_int)devext->CSrb[2],(u_int)devext->CSrb[3]);
3114 tmport=devext->BaseIoAddress[0];
3115 printk(KERN_DEBUG " r%2x=%2x", 0x2a, inb(tmport+0x2a));
3116 return (SCSI_ABORT_SNOOZE);
3119 int atp86x_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
3125 ULONG baseIoAddress;
3126 struct hw_device_ext *devext;
3128 * See if a bus reset was suggested.
3130 for (h = 0; h <= admaxu; h++) {
3131 if (SCpnt->host == a867host[h]) {
3135 panic("Reset bus host not found !");
3138 if (devext->dev_id == ATP867_DEVID1)
3140 // BaseIO+0x28: bit 4=1 disable INTA
3141 baseIoAddress = devext->BaseIoAddress[0];
3142 Outpb(baseIoAddress,0x28,(UCHAR)
3143 (Inpb(baseIoAddress,0x28) | 0x10));
3144 // Stop PCI transfer for all channels
3145 Outpb(baseIoAddress,0x40,0);
3146 Outpb(baseIoAddress,0x50,0);
3147 Outpb(baseIoAddress,0x60,0);
3148 Outpb(baseIoAddress,0x70,0);
3150 if (devext->c_mask != 0)
3153 for (k=0; k < 4; k++)
3155 if ((i & 0x10) != 0)
3157 baseIoAddress = devext->BaseIoAddress[k];
3158 i2cread(baseIoAddress,0x41,&l);
3159 i2cread(baseIoAddress,0x42,&l);
3160 i2cread(baseIoAddress,0x40,&l);
3161 i2cread(baseIoAddress,0x41,&l);
3162 i2cread(baseIoAddress,0x42,&l);
3163 Outpb(baseIoAddress,0x43,0x20);
3167 baseIoAddress = devext->BaseIoAddress[0];
3170 baseIoAddress = devext->BaseIoAddress[0];
3172 // Enable Master IDE PreRead
3173 Outpb(baseIoAddress,0x41,(UCHAR)
3174 (Inpb(baseIoAddress,0x41) | 0x10));
3175 Outpb(baseIoAddress,0x51,(UCHAR)
3176 (Inpb(baseIoAddress,0x51) | 0x10));
3177 Outpb(baseIoAddress,0x61,(UCHAR)
3178 (Inpb(baseIoAddress,0x61) | 0x10));
3179 Outpb(baseIoAddress,0x71,(UCHAR)
3180 (Inpb(baseIoAddress,0x71) | 0x10));
3182 // Disable Master IDE PreRead
3183 Outpb(baseIoAddress,0x41,(UCHAR)
3184 (Inpb(baseIoAddress,0x41) & 0xef));
3185 Outpb(baseIoAddress,0x51,(UCHAR)
3186 (Inpb(baseIoAddress,0x51) & 0xef));
3187 Outpb(baseIoAddress,0x61,(UCHAR)
3188 (Inpb(baseIoAddress,0x61) & 0xef));
3189 Outpb(baseIoAddress,0x71,(UCHAR)
3190 (Inpb(baseIoAddress,0x71) & 0xef));
3196 // CFG_base+0x40+0x0A: bit 0 =1 disable INTA
3197 pci_read_config_byte(devext->pdev, 0x4A, &j);
3199 printk("865RESET: Read: config+0x4A= %2X\n",j);
3202 pci_write_config_byte(devext->pdev, 0x4A, j);
3204 printk("865RESET: Write: config+0x4A= %2X\n",j);
3207 // Stop PCI transfer for all channels
3208 Outpb(devext->BaseIoAddresm[0],0,0);
3209 Outpb(devext->BaseIoAddresm[1],0,0);
3211 printk("865RESET: Write: IO%4lX and %4lX=0\n",devext->BaseIoAddresm[0],devext->BaseIoAddresm[1]);
3213 /* disable pre-read or post write , delayed IRQ */
3214 pci_write_config_byte(devext->pdev, 0x4B, 0);
3216 /* Pre-read counter must be 0x000200 4C,4D,4E - 14,15,16*/
3217 pci_write_config_byte(devext->pdev, 0x4C, 0);
3218 pci_write_config_byte(devext->pdev, 0x4D, 0x02);
3219 pci_write_config_byte(devext->pdev, 0x4E, 0);
3220 pci_write_config_byte(devext->pdev, 0x14, 0);
3221 pci_write_config_byte(devext->pdev, 0x15, 0x02);
3222 pci_write_config_byte(devext->pdev, 0x16, 0);
3226 /* PCI config + 0x40 + 0xA: bit 0: 0= enable INTA
3227 bit 7: 1= enable PCI bus master
3230 printk("atp865: read config + 0x4A\n");
3232 pci_read_config_byte(devext->pdev, 0x4A, &j);
3234 printk("atp865: read config + 0x4A = %X\n",j);
3238 pci_write_config_byte(devext->pdev, 0x4A, j);
3240 /* // Enable Master IDE PreRead
3241 Outpb(baseIoAddress,0x41,(UCHAR)
3242 (Inpb(baseIoAddress,0x41) | 0x10));
3243 Outpb(baseIoAddress,0x51,(UCHAR)
3244 (Inpb(baseIoAddress,0x51) | 0x10));
3245 Outpb(baseIoAddress,0x61,(UCHAR)
3246 (Inpb(baseIoAddress,0x61) | 0x10));
3247 Outpb(baseIoAddress,0x71,(UCHAR)
3248 (Inpb(baseIoAddress,0x71) | 0x10));
3250 // Disable Master IDE PreRead
3251 Outpb(baseIoAddress,0x41,(UCHAR)
3252 (Inpb(baseIoAddress,0x41) & 0xef));
3253 Outpb(baseIoAddress,0x51,(UCHAR)
3254 (Inpb(baseIoAddress,0x51) & 0xef));
3255 Outpb(baseIoAddress,0x61,(UCHAR)
3256 (Inpb(baseIoAddress,0x61) & 0xef));
3257 Outpb(baseIoAddress,0x71,(UCHAR)
3258 (Inpb(baseIoAddress,0x71) & 0xef));
3265 for (i=0; i < 4 ; i++) {
3267 devext->que_hd[i]=0;
3268 devext->que_end[i]=0;
3272 SCpnt->result = 0x00080000;
3273 SCpnt->scsi_done(SCpnt);
3274 return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET); */
3275 return (SCSI_RESET_SNOOZE);
3278 void ATP867init(struct hw_device_ext * devext)
3280 ULONG baseIoAddress = devext->BaseIoAddress[0];
3281 ULONG baseIoAddresm = devext->BaseIoAddresm[0];
3282 UCHAR i,j,k,l,ata66,is66,iswd;
3290 Outpb(baseIoAddress,0x28,(UCHAR)
3291 (Inpb(baseIoAddress,0x28) | 0x10));
3293 if (devext->chipver < 0x10)
3295 Outpb(baseIoAddress,0x3f,0x08);
3299 Outpb(baseIoAddress,0x3f,0x0a);
3301 Outpb(baseIoAddress,0x4a,0x43);
3302 Outpb(baseIoAddress,0x5a,0x43);
3303 Outpb(baseIoAddress,0x6a,0x43);
3304 Outpb(baseIoAddress,0x7a,0x43);
3305 ata66=devext->ata66;
3306 Outpb(baseIoAddress,0x48,0x31);
3307 Outpb(baseIoAddress,0x49,0x31);
3308 Outpb(baseIoAddress,0x4b,0x00);
3309 Outpb(baseIoAddress,0x58,0x31);
3310 Outpb(baseIoAddress,0x59,0x31);
3311 Outpb(baseIoAddress,0x5b,0x00);
3312 Outpb(baseIoAddress,0x68,0x31);
3313 Outpb(baseIoAddress,0x69,0x31);
3314 Outpb(baseIoAddress,0x6b,0x00);
3315 Outpb(baseIoAddress,0x78,0x31);
3316 Outpb(baseIoAddress,0x79,0x31);
3317 Outpb(baseIoAddress,0x7b,0x00);
3323 for ( i = 0 ; i < 8 ; i++ )
3325 baseIoAddress=devext->BaseIoAddress[i >> 1];
3327 if ((i & 0x01) != 0)
3331 Outpb(baseIoAddress,6,j);
3333 k=Inpb(baseIoAddress,7);
3334 if ((k & 0x88) != 0x00)
3336 devext->hd_status[i]=0x7f;
3341 l=Inpb(baseIoAddress,7);
3342 if ((l & 0x80) != 0 )
3346 Outpb(baseIoAddress,7,0xec);
3349 l=Inpb(baseIoAddress,7);
3350 if ((l & 0x80) != 0 )
3354 if ((l & 0x01) == 0x01 )
3356 devext->hd_status[i]=0x7f;
3360 if ((l & 0xf8) != 0x58 )
3362 devext->hd_status[i]=0x7f;
3366 for (m=0; m < 0x100; m++)
3368 mbuf[m]=Inpw(baseIoAddress,0);
3374 Outpb(baseIoAddress,1,0x03);
3375 if ((mbuf[88] & 0x0018) == 0)
3377 if ((iswd == 0) && ((mbuf[88] & 0x007f) != 0))
3379 Outpb(baseIoAddress,2,0x42);
3384 k=(UCHAR)(mbuf[63] & 0x0007);
3389 Outpb(baseIoAddress,2,k);
3400 if (((i < 2) && ((ata66 & 0x01) == 0)) ||
3401 ((i > 1) && ((ata66 & 0x02) == 0)))
3403 if ((mbuf[88] & 0x0020) == 0)
3405 Outpb(baseIoAddress,2,0x44);
3410 if ((mbuf[88] & 0x0040) == 0)
3413 Outpb(baseIoAddress,2,0x45);
3418 Outpb(baseIoAddress,2,0x46);
3424 Outpb(baseIoAddress,2,0x42);
3427 Outpb(baseIoAddress,7,0xef);
3429 k=Inpb(baseIoAddress,7);
3430 while ((k & 0x80) != 0)
3432 k=Inpb(baseIoAddress,7);
3434 if ((k & 0xf9) == 0x50)
3591 baseIoAddress=devext->BaseIoAddress[0];
3592 Outpb(baseIoAddress,0x4b,cbuf[0]);
3593 Outpb(baseIoAddress,0x5b,cbuf[1]);
3594 Outpb(baseIoAddress,0x6b,cbuf[2]);
3595 Outpb(baseIoAddress,0x7b,cbuf[3]);
3597 j=Inpb(baseIoAddress,0x28);
3600 Outpb(baseIoAddress,0x28,j);
3601 Outpb(baseIoAddress,0x29,(UCHAR)
3602 (Inpb(baseIoAddress,0x29) & 0xe0));
3605 for (i=0; i < 4; i++)
3607 baseIoAddress = devext->BaseIoAddress[i];
3611 Outpb(baseIoAddress,0x0e,0x08);
3612 i2cwrite(baseIoAddress,0x4e,0x80);
3613 i2cread(baseIoAddress,0x4f,&j);
3614 i2cwrite(baseIoAddress,0x4e,0x00);
3615 i2cread(baseIoAddress,0x4f,&n);
3616 i2cread(baseIoAddress,0x58,&l);
3617 if ((j == 0x5c) && (n == 0xa3) && (l == 0x40))
3621 devext->c_mask |= j;
3622 i2cread(baseIoAddress,0x41,&j);
3623 i2cread(baseIoAddress,0x42,&j);
3624 i2cwrite(baseIoAddress,0x43,0xf8);
3625 i2cwrite(baseIoAddress,0x44,0x0e);
3626 i2cwrite(baseIoAddress,0x2b,0xff);
3627 i2cwrite(baseIoAddress,0x2c,0x3e);
3628 i2cwrite(baseIoAddress,0x2f,0xff);
3629 i2cwrite(baseIoAddress,0x30,0x3e);
3630 i2cwrite(baseIoAddress,0x33,0xff);
3631 i2cwrite(baseIoAddress,0x34,0x3e);
3632 i2cwrite(baseIoAddress,0x4d,0xc0);
3633 i2cread(baseIoAddress,0x40,&j);
3634 i2cread(baseIoAddress,0x41,&j);
3635 i2cread(baseIoAddress,0x42,&j);
3636 i2cread(baseIoAddress,0x43,&j);
3637 i2cread(baseIoAddress,0x44,&j);
3638 i2cread(baseIoAddress,0x2b,&j);
3639 i2cread(baseIoAddress,0x2c,&j);
3640 i2cread(baseIoAddress,0x2f,&j);
3641 i2cread(baseIoAddress,0x30,&j);
3642 i2cread(baseIoAddress,0x33,&j);
3643 i2cread(baseIoAddress,0x34,&j);
3644 i2cwrite(baseIoAddress,0x40,0x43);
3645 Outpb(baseIoAddress,0x0e,0x08);
3646 i2cread(baseIoAddress,0x41,&j);
3647 i2cread(baseIoAddress,0x42,&j);
3648 if (devext->hd_status[i << 1] == 0)
3650 Outpb(baseIoAddress,0x43,0x84);
3654 Outpb(baseIoAddress,0x43,0x80);
3656 Outpb(baseIoAddress,0x0e,0x08);
3657 Outpb(baseIoAddress,0x43,0x20);
3658 baseIoAddress = devext->BaseIoAddress[0];
3659 Outpb(baseIoAddress,0x29,(UCHAR)
3660 (Inpb(baseIoAddress,0x29) | 0x10));
3664 baseIoAddress=devext->BaseIoAddress[0];
3666 Outpb(baseIoAddresm,2,0x06);
3667 Outpb(baseIoAddresm,0x12,0x06);
3668 Outpb(baseIoAddresm,0x22,0x06);
3669 Outpb(baseIoAddresm,0x32,0x06);
3670 Outpb(baseIoAddress,0x28,(UCHAR)
3671 (Inpb(baseIoAddress,0x28) & 0xef));
3675 void ATP865init(struct hw_device_ext * devext)
3677 // ULONG baseIoAddress = devext->BaseIoAddress[1];
3678 // ULONG baseIoAddresm = devext->BaseIoAddresm[0];
3679 // UCHAR i,j,k,l,n,ata66,is66,iswd;
3681 // USHORT m,mbuf[256];
3685 printk("865RESET: Should h/w or s/w reset IDE first.\n");
3688 Outpb(devext->BaseIoAddress[0],6,0xA0);
3689 Outpb(devext->BaseIoAddress[2],2,0x04);
3690 Outpb(devext->BaseIoAddress[0],6,0xB0);
3691 Outpb(devext->BaseIoAddress[2],2,0x04);
3692 Outpb(devext->BaseIoAddress[1],6,0xA0);
3693 Outpb(devext->BaseIoAddress[3],2,0x04);
3694 Outpb(devext->BaseIoAddress[1],6,0xB0);
3695 Outpb(devext->BaseIoAddress[3],2,0x04);
3697 Outpb(devext->BaseIoAddress[0],6,0xA0);
3698 Outpb(devext->BaseIoAddress[2],2,0x00);
3699 Outpb(devext->BaseIoAddress[0],6,0xB0);
3700 Outpb(devext->BaseIoAddress[2],2,0x00);
3701 Outpb(devext->BaseIoAddress[1],6,0xA0);
3702 Outpb(devext->BaseIoAddress[3],2,0x00);
3703 Outpb(devext->BaseIoAddress[1],6,0xB0);
3704 Outpb(devext->BaseIoAddress[3],2,0x00);
3706 Outpb(devext->BaseIoAddress[0],6,0xA0);
3707 Inpb(devext->BaseIoAddress[0],0x7);
3708 Outpb(devext->BaseIoAddress[0],6,0xB0);
3709 Inpb(devext->BaseIoAddress[0],0x7);
3710 Outpb(devext->BaseIoAddress[1],6,0xA0);
3711 Inpb(devext->BaseIoAddress[1],0x7);
3712 Outpb(devext->BaseIoAddress[1],6,0xB0);
3713 Inpb(devext->BaseIoAddress[1],0x7);
3715 printk("865RESET: init routine not ready, use is865() instead.\n");
3717 is865(devext,devext->pdev);
3722 const char *atp86x_info(struct Scsi_Host *notused)
3724 static char buffer[128];
3726 strcpy(buffer, "ACARD ATP86X PCI ATA133 Adapter Driver Ver: 0.78 Date: 2004/01/15\n");
3728 notused->ide_hdd = 1; //+Wilson05112005, IDE Bridge exist
3733 int atp86x_set_info(char *buffer, int length, struct Scsi_Host *HBAptr)
3735 return -ENOSYS; /* Currently this is a no-op */
3738 #define BLS buffer + len + size
3739 int atp86x_proc_info(char *buffer, char **start, off_t offset, int length,
3740 int hostno, int inout)
3742 struct Scsi_Host *HBAptr;
3743 static u8 buff[512];
3751 for (i = 0; i < 4; i++) {
3752 if ((HBAptr = a867host[i]) != NULL) {
3753 if (HBAptr->host_no == hostno) {
3760 if (HBAptr == NULL) {
3761 size += sprintf(BLS, "Can't find adapter for host number %d\n", hostno);
3767 if (inout == TRUE) { /* Has data been written to the file? */
3768 return (atp86x_set_info(buffer, length, HBAptr));
3771 memset(buff, 0, sizeof(buff));
3773 size += sprintf(BLS, "ACARD ATP86X PCI ATA133 Adapter Driver Ver: 0.78 Date: 2004/01/15\n");
3778 size += sprintf(BLS, "\n");
3779 size += sprintf(BLS, "Adapter Configuration:\n");
3780 size += sprintf(BLS, " Base IO: %#.4lx\n", HBAptr->io_port);
3781 size += sprintf(BLS, " IRQ: %d\n", HBAptr->irq);
3787 *start = buffer + (offset - begin); /* Start of wanted data */
3788 len -= (offset - begin); /* Start slop */
3790 len = length; /* Ending slop */
3797 int atp86x_biosparam(Scsi_Disk * disk, kdev_t dev, int *ip)
3799 int heads, sectors, cylinders;
3803 cylinders = disk->capacity / (heads * sectors);
3805 if (cylinders > 1024) {
3808 cylinders = disk->capacity / (heads * sectors);
3817 int atp86x_release (struct Scsi_Host *pshost)
3820 struct hw_device_ext *devext;
3822 for (h = 0; h <= admaxu; h++)
3824 if (pshost == a867host[h]) {
3825 devext = &dev_ext[h];
3826 free_irq (pshost->irq, devext);
3827 if (devext->dev_id == ATP867_DEVID1)
3828 release_region (pshost->io_port, pshost->n_io_port);
3831 release_region(devext->BaseIoAddress[0], 0x8); /* Register the IO ports that we use */
3832 release_region(devext->BaseIoAddress[2], 0x3); /* Register the IO ports that we use */
3833 release_region(devext->BaseIoAddress[1], 0x8); /* Register the IO ports that we use */
3834 release_region(devext->BaseIoAddress[3], 0x3); /* Register the IO ports that we use */
3835 release_region(devext->BaseIoAddresm[0], 0x10); /* Register the IO ports that we use */
3837 scsi_unregister(pshost);
3840 for(k=0;k < qcnt1;k++)
3842 #ifdef IXP42X_SUPPORT
3843 pci_free_consistent(devext->pdev, 256,
3844 devext->lsrb[i][k].prd, devext->lsrb[i][k].prdaddr);
3846 kfree(devext->lsrb[i][k].prd);
3850 // add for smart read =================//
3851 devext->FG_TimerStop = 1;
3853 del_timer_sync(&(devext->AdapterTimer));
3854 //======================================//
3858 panic("atp86x: bad scsi host passed.\n");
3860 // add for smart read =================//
3861 void smart_timer(ULONG para)
3863 struct hw_device_ext * devext;
3864 Scsi_Cmnd *pScsiCmd;
3866 devext = (struct hw_device_ext *)para;
3867 if ( (devext->FG_SmartRead == 0)
3868 &&(devext->cap[0] != 0)
3869 &&(devext->hd_status[0] != 0x7f)
3871 { // if smart read command not send to channel queue of hard disk yet
3872 // printk("send smart read command\n");
3873 pScsiCmd = &(devext->SmartSrb);
3874 pScsiCmd->cmnd[0] = 0xB0;
3876 pScsiCmd->target = 0;
3877 pScsiCmd->scsi_done = internal_done;
3878 if ((devext->que_end[0] += 1) > qcnt1 - 1)
3880 devext->que_end[0]=0;
3882 devext->QSrb[0][devext->que_end[0]] = pScsiCmd;
3883 devext->FG_SmartRead = 1;
3884 if (devext->in_int == 0)
3886 if ( (devext->CSrb[0] == 0) &&
3887 (devext->que_hd[0] != devext->que_end[0]) )
3889 if ( devext->que_hd[0] == qcnt1 - 1 )
3891 devext->que_hd[0]=0;
3894 devext->que_hd[0]++;
3896 devext->CSrb[0]=devext->QSrb[0][devext->que_hd[0]];
3897 devext->Cplsrb[0]=devext->plsrb[0][devext->que_hd[0]];
3898 SendScsi(devext,devext->CSrb[0],0);
3903 if( !(devext->FG_TimerStop) )
3905 (devext->AdapterTimer).expires = jiffies + HZ*30;
3906 add_timer(&(devext->AdapterTimer));
3909 //======================================//
3910 MODULE_LICENSE("GPL");
3912 static Scsi_Host_Template driver_template = {
3915 proc_info: atp86x_proc_info,
3917 detect: atp86x_detect,
3918 release: atp86x_release,
3920 command: atp86x_command,
3921 queuecommand: atp86x_queuecommand,
3922 eh_strategy_handler: NULL,
3923 eh_abort_handler: NULL,
3924 eh_device_reset_handler: NULL,
3925 eh_bus_reset_handler: NULL,
3926 eh_host_reset_handler: NULL,
3927 abort: atp86x_abort,
3928 reset: atp86x_reset,
3930 bios_param: atp86x_biosparam,
3931 can_queue: qcnt, /* max simultaneous cmds */
3932 this_id: 8, /* scsi id of host adapter */
3933 sg_tablesize: ATP86X_SCATTER, /* max scatter-gather cmds */
3934 cmd_per_lun: ATP86X_CMDLUN, /* cmds per lun (linked cmds) */
3935 present: 0, /* number of xxx's present */
3936 unchecked_isa_dma: 0, /* no memory DMA restrictions */
3937 use_clustering: ENABLE_CLUSTERING,
3940 #include "scsi_module.c"