|
Line 0
Link Here
|
|
|
1 |
/* |
| 2 |
* linux/drivers/scsi/iteraid.c |
| 3 |
* |
| 4 |
* (C) Copyright 2002-2003 Integrated Technology Express, inc. |
| 5 |
* |
| 6 |
* Nov 11, 2002 Mark Lu file created. |
| 7 |
* |
| 8 |
* ITE IT8212 RAID controller device driver for Linux. |
| 9 |
* |
| 10 |
* This program is free software; you can redistribute it and/or modify it |
| 11 |
* under the terms of the GNU General Public License as published by the |
| 12 |
* Free Software Foundation; either version 2, or (at your option) any |
| 13 |
* later version. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, but |
| 16 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 |
* General Public License for more details. |
| 19 |
* |
| 20 |
* Revision 0.0 2002/12/05 15:12:12 root |
| 21 |
* Empty function bodies; detect() works. |
| 22 |
* |
| 23 |
* Revision 0.1 2002/12/17 19:21:37 root |
| 24 |
* First "dma thing doesn't work" version. |
| 25 |
* |
| 26 |
* Revision 0.3 2002/12/23 17:12:09 root |
| 27 |
* Rewrite the dma routines. Reference the ide-dma.c. |
| 28 |
* |
| 29 |
* Revision 0.4 2002/12/26 10:19:29 root |
| 30 |
* The dma read/write works, using some ways to prove it. But there is a |
| 31 |
* problem about the "unknown partition table". The fdisk is ok, but |
| 32 |
* after writing the created partitions, it still shows the "unknown |
| 33 |
* partition table" and i can't access the created partitions. |
| 34 |
* |
| 35 |
* Revision 0.5 2003/01/07 21:49:30 root |
| 36 |
* The problem of "unknown partition table" has been solved. |
| 37 |
* We must "ENABLE CLUSTERING". There is still a another problem about |
| 38 |
* the SCATTER/GATHER. |
| 39 |
* |
| 40 |
* Revision 0.6 2003/01/10 17:45:32 root |
| 41 |
* The SCATTER/GATHER problem has been solved. Now verify the read/write |
| 42 |
* function and make sure each RAID configurations are workable. If testing |
| 43 |
* is OK, then it will be a version 1.0..... |
| 44 |
* |
| 45 |
* Revision 1.0 2003/01/16 17:45:32 root |
| 46 |
* First release version. |
| 47 |
* |
| 48 |
* FixME 1: |
| 49 |
* In RedHat 7.3, if using SG_ALL, the SCSI will timeout. It looks like |
| 50 |
* an command is requested but the interrupt is not been asserted. So |
| 51 |
* try to add a watchdog timer to monitor the interrupts. But this kind |
| 52 |
* of situration will not happen in Mandrake 9.0 and also when using |
| 53 |
* SG_NONE in RedHat 7.3. |
| 54 |
* |
| 55 |
* FixME 2: |
| 56 |
* Module load problem in RedHat 7.3. |
| 57 |
* |
| 58 |
* Fixed: Compile in the graphic mode (GNOME or KDE) will fix the |
| 59 |
* module load problem. |
| 60 |
* |
| 61 |
* Revision 1.1 2003/02/10 10:32:21 root |
| 62 |
* Compile in the graphic mode (GNOME or KDE) will fix the |
| 63 |
* module load problem. |
| 64 |
* |
| 65 |
* Revision 1.2 2003/02/18 14:10:35 root |
| 66 |
* Fix the interrupt service routine for share irq problem. |
| 67 |
* |
| 68 |
* ATAPI support ---> schedule is three weeks. (2003/02/28) |
| 69 |
* |
| 70 |
* Revision 1.3 2003/02/27 |
| 71 |
* First relase ATAPI version. But there will be an error if no disc in the |
| 72 |
* CD-ROM. Because the commands like TEST_UNIT_READY and READ_CAPACITY will |
| 73 |
* get the error response. This situration in WINDOWS will be then send the |
| 74 |
* REQUEST SENSE command to the device but in Linux, it will never get |
| 75 |
* REQUEST SENSE command. So can we send by ourself??? |
| 76 |
* |
| 77 |
* 2003/03/05 root |
| 78 |
* |
| 79 |
* Note 1: |
| 80 |
* According to "The Linux SCSI Generic (sg) HOWTO", the device will respond |
| 81 |
* with a single byte value call the 'scsi_status'. GOOD is the scsi status |
| 82 |
* indicating everything has gone well. The most common other status is |
| 83 |
* CHECK CONDITION. In this latter case, the SCSI mid layer issues a REQUEST |
| 84 |
* SENSE SCSI command. The response of the REQUEST SENSE is 18 bytes or more |
| 85 |
* in length and is called the "sense buffer". It will indicate why the original |
| 86 |
* command may not have been executed. It is important to realize that a CHECK |
| 87 |
* CONDITION may very in severity from informative (e.g. command needed to be |
| 88 |
* retried before succeeding) to fatal (e.g. 'medium error' which often indicates |
| 89 |
* it is time to replace the disk). |
| 90 |
* |
| 91 |
* Note 2: |
| 92 |
* When using the ATAPI BIOS, we also do not need to set up the timimg in linux |
| 93 |
* driver. But it is necessary to write the timing routine in win system, cause it |
| 94 |
* has a s1, s2, s3 mode and devices wake up from these modes need to be initialized |
| 95 |
* again and do not pass through the BIOS. |
| 96 |
* |
| 97 |
* Note 3: |
| 98 |
* The 48-bit support and AP for RAID in linux will the next job. |
| 99 |
* |
| 100 |
* Revision 1.31 2003/03/14 09:40:35 root |
| 101 |
* Fix the error when no disc is on the CD-ROM and the audio cd is ready to play. |
| 102 |
* |
| 103 |
* 2003/04/08 root |
| 104 |
* The ioctl code sklection is finished. But there is a problem about |
| 105 |
* "Bad address" when copy_from_user() is called. |
| 106 |
* |
| 107 |
* Fixed: Use kmalloc() and kfree() to allocate the buffer instead of automatic |
| 108 |
* variables (use stack). The stack size is limited in kernel space. |
| 109 |
* |
| 110 |
* Revision 1.32 2003/04/14 18:20:23 root |
| 111 |
* Complete the IOCTLs code. |
| 112 |
* |
| 113 |
* The IOCTLs are listed below |
| 114 |
* =========================== |
| 115 |
* |
| 116 |
* (1) ITE_IOC_GET_IDENTIFY_DATA |
| 117 |
* |
| 118 |
* Return virtual drive 512 bytes identification data. |
| 119 |
* |
| 120 |
* (2) ITE_IOC_GET_PHY_DISK_STATUS |
| 121 |
* |
| 122 |
* Developer can decide to return 4 physical disk information in |
| 123 |
* 512 bytes (data structure should be defined) or 512 bytes |
| 124 |
* identification data of the physical disk specified by AP. |
| 125 |
* |
| 126 |
* (3) ITE_IOC_CREATE_DISK_ARRAY |
| 127 |
* |
| 128 |
* Create a new array and erase (or keep) boot sector. |
| 129 |
* |
| 130 |
* (4) ITE_IOC_REBUILD_START |
| 131 |
* |
| 132 |
* AP nees to specify target/source drive, starting LBA and length. |
| 133 |
* |
| 134 |
* (5) ITE_IOC_GET_REBUILD_STATUS |
| 135 |
* |
| 136 |
* Return rebuild percentage or last LBA No. |
| 137 |
* |
| 138 |
* (6) ITE_IOC_RESET_ADAPTER |
| 139 |
* |
| 140 |
* Reset the controller. |
| 141 |
* |
| 142 |
* Revision 1.33 2003/04/15 11:10:08 root |
| 143 |
* The 48-bit support. |
| 144 |
* |
| 145 |
* Revision 1.34 2003/04/20 13:20:38 root |
| 146 |
* Change some values in iteraid.h, so it will not hang in Red Hat Linux |
| 147 |
* and improve the performance. |
| 148 |
* |
| 149 |
* can_queue: 1 --------------------> can_queue: 124 |
| 150 |
* sg_tablesize: SG_NONE -----------> sg_tablesize: 16 |
| 151 |
* cmd_per_lun: 128 ----------------> cmd_per_lun: 1 |
| 152 |
* use_clustering: ENABLE_CLUSTER --> use_clustering: DISABLE_CLUSTER |
| 153 |
* |
| 154 |
* 2003/04/25 root |
| 155 |
* The code will hang on Gigabyte's motherboard when the sourth bridge is |
| 156 |
* sis 962L and 963. |
| 157 |
* |
| 158 |
* 2003/04/28 root |
| 159 |
* Fixed: Do not enable interrupt again when send each command in |
| 160 |
* IdeSendCommand() routine. |
| 161 |
* |
| 162 |
* TODO list: |
| 163 |
* |
| 164 |
* (1) Using the new error code handler instead of the old style. |
| 165 |
* Because the old one will not be used above kernl-2.5. |
| 166 |
* |
| 167 |
* (2) Rewrite the abort and reset functions. |
| 168 |
*/ |
| 169 |
|
| 170 |
#include <linux/module.h> |
| 171 |
|
| 172 |
MODULE_AUTHOR ("ITE,Inc."); |
| 173 |
MODULE_DESCRIPTION ("ITE IT8212 RAID Controller Linux Driver"); |
| 174 |
|
| 175 |
#include <linux/kernel.h> |
| 176 |
#include <linux/pci.h> |
| 177 |
#include <linux/time.h> |
| 178 |
#include <linux/proc_fs.h> |
| 179 |
#include <linux/sched.h> |
| 180 |
#include <linux/ioport.h> |
| 181 |
#include <linux/blk.h> |
| 182 |
#include <linux/hdreg.h> |
| 183 |
#include <linux/string.h> |
| 184 |
#include <linux/delay.h> |
| 185 |
#include <linux/reboot.h> |
| 186 |
#include <linux/spinlock.h> |
| 187 |
#include <linux/fs.h> |
| 188 |
|
| 189 |
#include <asm/errno.h> |
| 190 |
#include <asm/io.h> |
| 191 |
#include <asm/irq.h> |
| 192 |
#include <asm/uaccess.h> |
| 193 |
|
| 194 |
#include "sd.h" |
| 195 |
#include "scsi.h" |
| 196 |
#include "hosts.h" |
| 197 |
|
| 198 |
#include "iteraid.h" |
| 199 |
|
| 200 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,10) |
| 201 |
MODULE_LICENSE("GPL"); |
| 202 |
#endif |
| 203 |
|
| 204 |
#define MARK_DEBUG_DUMP_MEM 0 /* 1=Enable dump memory content */ |
| 205 |
#define MARK_DEBUG_BYPASS_MODE 0 /* 1=Enable use bypass mode */ |
| 206 |
|
| 207 |
#define PRD_BYTES 8 /* PRD table size */ |
| 208 |
#define PRD_ENTRIES (PAGE_SIZE / (2 * PRD_BYTES)) |
| 209 |
|
| 210 |
struct Scsi_Host * ite_vhost = 0; /* SCSI virtual host */ |
| 211 |
Scsi_Cmnd * it8212_req_last = 0; /* SRB request list */ |
| 212 |
|
| 213 |
unsigned int NumAdapters = 0; /* Adapters number */ |
| 214 |
PITE_ADAPTER ite_adapters[2]; /* How many adapters support */ |
| 215 |
|
| 216 |
static struct semaphore mimd_entry_mtx; |
| 217 |
|
| 218 |
static spinlock_t queue_request_lock = SPIN_LOCK_UNLOCKED; |
| 219 |
static spinlock_t io_request_lock = SPIN_LOCK_UNLOCKED; |
| 220 |
static spinlock_t gio_request_lock = SPIN_LOCK_UNLOCKED; |
| 221 |
|
| 222 |
static int driver_ver = 134; /* Current driver version */ |
| 223 |
|
| 224 |
/************************************************************************ |
| 225 |
* The File Operations structure for the ioctl interface of the driver. |
| 226 |
************************************************************************/ |
| 227 |
static struct file_operations itedev_fops = |
| 228 |
{ |
| 229 |
ioctl:itedev_ioctl_entry, |
| 230 |
open:itedev_open, |
| 231 |
release:itedev_close, |
| 232 |
}; |
| 233 |
|
| 234 |
#if (MARK_DEBUG_DUMP_MEM) |
| 235 |
/************************************************************************ |
| 236 |
* Dump buffer |
| 237 |
************************************************************************/ |
| 238 |
static void |
| 239 |
HexDump(unsigned char *buf, int length) |
| 240 |
{ |
| 241 |
|
| 242 |
unsigned int i = 0; |
| 243 |
unsigned int j = 0; |
| 244 |
printk("\n"); |
| 245 |
|
| 246 |
for (i = 0; i < length; i += 16) |
| 247 |
{ |
| 248 |
printk("%04X ", i); |
| 249 |
for (j = i; (j < i + 8) && (j < length); j++) |
| 250 |
{ |
| 251 |
printk(" %02X", buf[j]); |
| 252 |
} |
| 253 |
if (j == i + 8) printk("-"); |
| 254 |
for (j = i + 8; (j < i + 16) && (j < length); j++) |
| 255 |
{ |
| 256 |
printk("%02X ", buf[j]); |
| 257 |
} |
| 258 |
printk("\n"); |
| 259 |
} |
| 260 |
|
| 261 |
} /* end HexDump */ |
| 262 |
#endif |
| 263 |
|
| 264 |
/************************************************************************ |
| 265 |
* This routine maps ATAPI and IDE errors to specific SRB statuses. |
| 266 |
************************************************************************/ |
| 267 |
UCHAR |
| 268 |
MapError(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 269 |
{ |
| 270 |
|
| 271 |
UCHAR errorByte; |
| 272 |
UCHAR srbStatus; |
| 273 |
UCHAR scsiStatus; |
| 274 |
|
| 275 |
/* |
| 276 |
* Read the error register. |
| 277 |
*/ |
| 278 |
errorByte = inb(pChan->io_ports[IDE_ERROR_OFFSET]); |
| 279 |
printk("MapError: Error register is %x\n", errorByte); |
| 280 |
|
| 281 |
/* |
| 282 |
* If this is ATAPI error. |
| 283 |
*/ |
| 284 |
if (pChan->DeviceFlags[Srb->TargetId & 1] & DFLAGS_ATAPI_DEVICE) |
| 285 |
{ |
| 286 |
switch (errorByte >> 4) |
| 287 |
{ |
| 288 |
case SCSI_SENSE_NO_SENSE: |
| 289 |
printk("ATAPI: No sense information\n"); |
| 290 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 291 |
srbStatus = SRB_STATUS_ERROR; |
| 292 |
break; |
| 293 |
|
| 294 |
case SCSI_SENSE_RECOVERED_ERROR: |
| 295 |
printk("ATAPI: Recovered error\n"); |
| 296 |
scsiStatus = 0; |
| 297 |
srbStatus = SRB_STATUS_SUCCESS; |
| 298 |
break; |
| 299 |
|
| 300 |
case SCSI_SENSE_NOT_READY: |
| 301 |
printk("ATAPI: Device not ready\n"); |
| 302 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 303 |
srbStatus = SRB_STATUS_ERROR; |
| 304 |
break; |
| 305 |
|
| 306 |
case SCSI_SENSE_MEDIUM_ERROR: |
| 307 |
printk("ATAPI: Media error\n"); |
| 308 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 309 |
srbStatus = SRB_STATUS_ERROR; |
| 310 |
break; |
| 311 |
|
| 312 |
case SCSI_SENSE_HARDWARE_ERROR: |
| 313 |
printk("ATAPI: Hardware error\n"); |
| 314 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 315 |
srbStatus = SRB_STATUS_ERROR; |
| 316 |
break; |
| 317 |
|
| 318 |
case SCSI_SENSE_ILLEGAL_REQUEST: |
| 319 |
printk("ATAPI: Illegal request\n"); |
| 320 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 321 |
srbStatus = SRB_STATUS_ERROR; |
| 322 |
break; |
| 323 |
|
| 324 |
case SCSI_SENSE_UNIT_ATTENTION: |
| 325 |
printk("ATAPI: Unit attention\n"); |
| 326 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 327 |
srbStatus = SRB_STATUS_ERROR; |
| 328 |
break; |
| 329 |
|
| 330 |
case SCSI_SENSE_DATA_PROTECT: |
| 331 |
printk("ATAPI: Data protect\n"); |
| 332 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 333 |
srbStatus = SRB_STATUS_ERROR; |
| 334 |
break; |
| 335 |
|
| 336 |
case SCSI_SENSE_BLANK_CHECK: |
| 337 |
printk("ATAPI: Blank check\n"); |
| 338 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 339 |
srbStatus = SRB_STATUS_ERROR; |
| 340 |
break; |
| 341 |
|
| 342 |
case SCSI_SENSE_ABORTED_COMMAND: |
| 343 |
printk("ATAPI: Command Aborted\n"); |
| 344 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 345 |
srbStatus = SRB_STATUS_ERROR; |
| 346 |
break; |
| 347 |
|
| 348 |
default: |
| 349 |
printk("ATAPI: Invalid sense information\n"); |
| 350 |
scsiStatus = 0; |
| 351 |
srbStatus = SRB_STATUS_ERROR; |
| 352 |
break; |
| 353 |
} |
| 354 |
} |
| 355 |
/* |
| 356 |
* IF this is IDE error. |
| 357 |
*/ |
| 358 |
else |
| 359 |
{ |
| 360 |
scsiStatus = 0; |
| 361 |
srbStatus = SRB_STATUS_ERROR; |
| 362 |
|
| 363 |
/* |
| 364 |
* Save errorByte, to be used by SCSIOP_REQUEST_SENSE. |
| 365 |
*/ |
| 366 |
pChan->ReturningMediaStatus = errorByte; |
| 367 |
|
| 368 |
if (errorByte & IDE_ERROR_MEDIA_CHANGE_REQ) |
| 369 |
{ |
| 370 |
printk("IDE: Media change\n"); |
| 371 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 372 |
srbStatus = SRB_STATUS_ERROR; |
| 373 |
} |
| 374 |
else if (errorByte & IDE_ERROR_COMMAND_ABORTED) |
| 375 |
{ |
| 376 |
printk( "IDE: Command abort\n"); |
| 377 |
srbStatus = SRB_STATUS_ABORTED; |
| 378 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 379 |
|
| 380 |
if (Srb->SenseInfoBuffer) |
| 381 |
{ |
| 382 |
PSENSE_DATA senseBuffer = (PSENSE_DATA)Srb->SenseInfoBuffer; |
| 383 |
|
| 384 |
senseBuffer->ErrorCode = 0x70; |
| 385 |
senseBuffer->Valid = 1; |
| 386 |
senseBuffer->AdditionalSenseLength = 0xB; |
| 387 |
senseBuffer->SenseKey = SCSI_SENSE_ABORTED_COMMAND; |
| 388 |
senseBuffer->AdditionalSenseCode = 0; |
| 389 |
senseBuffer->AdditionalSenseCodeQualifier = 0; |
| 390 |
|
| 391 |
srbStatus |= SRB_STATUS_AUTOSENSE_VALID; |
| 392 |
} |
| 393 |
/* |
| 394 |
* pChan->ErrorCount++; |
| 395 |
*/ |
| 396 |
} |
| 397 |
else if (errorByte & IDE_ERROR_END_OF_MEDIA) |
| 398 |
{ |
| 399 |
printk("IDE: End of media\n"); |
| 400 |
|
| 401 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 402 |
srbStatus = SRB_STATUS_ERROR; |
| 403 |
|
| 404 |
if (!(pChan->DeviceFlags[Srb->TargetId & 1] & DFLAGS_MEDIA_STATUS_ENABLED)) |
| 405 |
{ |
| 406 |
/* |
| 407 |
* pChan->ErrorCount++; |
| 408 |
*/ |
| 409 |
} |
| 410 |
} |
| 411 |
else if (errorByte & IDE_ERROR_ILLEGAL_LENGTH) |
| 412 |
{ |
| 413 |
printk("IDE: Illegal length\n"); |
| 414 |
srbStatus = SRB_STATUS_INVALID_REQUEST; |
| 415 |
} |
| 416 |
else if (errorByte & IDE_ERROR_BAD_BLOCK) |
| 417 |
{ |
| 418 |
printk("IDE: Bad block\n"); |
| 419 |
|
| 420 |
srbStatus = SRB_STATUS_ERROR; |
| 421 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 422 |
|
| 423 |
if (Srb->SenseInfoBuffer) |
| 424 |
{ |
| 425 |
PSENSE_DATA senseBuffer = (PSENSE_DATA)Srb->SenseInfoBuffer; |
| 426 |
|
| 427 |
senseBuffer->ErrorCode = 0x70; |
| 428 |
senseBuffer->Valid = 1; |
| 429 |
senseBuffer->AdditionalSenseLength = 0xB; |
| 430 |
senseBuffer->SenseKey = SCSI_SENSE_MEDIUM_ERROR; |
| 431 |
senseBuffer->AdditionalSenseCode = 0; |
| 432 |
senseBuffer->AdditionalSenseCodeQualifier = 0; |
| 433 |
|
| 434 |
srbStatus |= SRB_STATUS_AUTOSENSE_VALID; |
| 435 |
} |
| 436 |
} |
| 437 |
else if (errorByte & IDE_ERROR_ID_NOT_FOUND) |
| 438 |
{ |
| 439 |
printk("IDE: Id not found\n"); |
| 440 |
|
| 441 |
srbStatus = SRB_STATUS_ERROR; |
| 442 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 443 |
|
| 444 |
if (Srb->SenseInfoBuffer) |
| 445 |
{ |
| 446 |
PSENSE_DATA senseBuffer = (PSENSE_DATA)Srb->SenseInfoBuffer; |
| 447 |
|
| 448 |
senseBuffer->ErrorCode = 0x70; |
| 449 |
senseBuffer->Valid = 1; |
| 450 |
senseBuffer->AdditionalSenseLength = 0xb; |
| 451 |
senseBuffer->SenseKey = SCSI_SENSE_MEDIUM_ERROR; |
| 452 |
senseBuffer->AdditionalSenseCode = 0; |
| 453 |
senseBuffer->AdditionalSenseCodeQualifier = 0; |
| 454 |
|
| 455 |
srbStatus |= SRB_STATUS_AUTOSENSE_VALID; |
| 456 |
} |
| 457 |
/* |
| 458 |
* pChan->ErrorCount++; |
| 459 |
*/ |
| 460 |
} |
| 461 |
else if (errorByte & IDE_ERROR_MEDIA_CHANGE) |
| 462 |
{ |
| 463 |
printk("IDE: Media change\n"); |
| 464 |
|
| 465 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 466 |
srbStatus = SRB_STATUS_ERROR; |
| 467 |
|
| 468 |
if (Srb->SenseInfoBuffer) |
| 469 |
{ |
| 470 |
PSENSE_DATA senseBuffer = (PSENSE_DATA)Srb->SenseInfoBuffer; |
| 471 |
|
| 472 |
senseBuffer->ErrorCode = 0x70; |
| 473 |
senseBuffer->Valid = 1; |
| 474 |
senseBuffer->AdditionalSenseLength = 0xb; |
| 475 |
senseBuffer->SenseKey = SCSI_SENSE_UNIT_ATTENTION; |
| 476 |
senseBuffer->AdditionalSenseCode = SCSI_ADSENSE_MEDIUM_CHANGED; |
| 477 |
senseBuffer->AdditionalSenseCodeQualifier = 0; |
| 478 |
|
| 479 |
srbStatus |= SRB_STATUS_AUTOSENSE_VALID; |
| 480 |
} |
| 481 |
} |
| 482 |
else if (errorByte & IDE_ERROR_DATA_ERROR) |
| 483 |
{ |
| 484 |
printk("IDE: Data error\n"); |
| 485 |
|
| 486 |
scsiStatus = SCSISTAT_CHECK_CONDITION; |
| 487 |
srbStatus = SRB_STATUS_ERROR; |
| 488 |
|
| 489 |
if (!(pChan->DeviceFlags[Srb->TargetId & 1] & DFLAGS_MEDIA_STATUS_ENABLED)) |
| 490 |
{ |
| 491 |
/* |
| 492 |
* pChan->ErrorCount++; |
| 493 |
*/ |
| 494 |
} |
| 495 |
|
| 496 |
/* |
| 497 |
* Build sense buffer. |
| 498 |
*/ |
| 499 |
if (Srb->SenseInfoBuffer) |
| 500 |
{ |
| 501 |
PSENSE_DATA senseBuffer = (PSENSE_DATA)Srb->SenseInfoBuffer; |
| 502 |
|
| 503 |
senseBuffer->ErrorCode = 0x70; |
| 504 |
senseBuffer->Valid = 1; |
| 505 |
senseBuffer->AdditionalSenseLength = 0xB; |
| 506 |
senseBuffer->SenseKey = SCSI_SENSE_MEDIUM_ERROR; |
| 507 |
senseBuffer->AdditionalSenseCode = 0; |
| 508 |
senseBuffer->AdditionalSenseCodeQualifier = 0; |
| 509 |
|
| 510 |
srbStatus |= SRB_STATUS_AUTOSENSE_VALID; |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
/* |
| 516 |
* Set SCSI status to indicate a check condition. |
| 517 |
*/ |
| 518 |
Srb->ScsiStatus = scsiStatus; |
| 519 |
|
| 520 |
return srbStatus; |
| 521 |
|
| 522 |
} /* end MapError */ |
| 523 |
|
| 524 |
/************************************************************************ |
| 525 |
* |
| 526 |
************************************************************************/ |
| 527 |
UCHAR |
| 528 |
RaidGetHighestBit(UCHAR Number) |
| 529 |
{ |
| 530 |
|
| 531 |
char bit; |
| 532 |
|
| 533 |
for (bit = 7; bit >= 0; bit--) |
| 534 |
{ |
| 535 |
if (Number & (1 << bit)) return bit; |
| 536 |
} |
| 537 |
|
| 538 |
return 0xFF; |
| 539 |
|
| 540 |
} /* end RaidGetHighestBit */ |
| 541 |
|
| 542 |
/************************************************************************ |
| 543 |
* Reset IDE controller or ATAPI device. |
| 544 |
************************************************************************/ |
| 545 |
BOOLEAN |
| 546 |
AtapiResetController(PChannel pChan) |
| 547 |
{ |
| 548 |
|
| 549 |
ULONG i; |
| 550 |
UCHAR status; |
| 551 |
ULONG dma_base = pChan->dma_base; |
| 552 |
BOOLEAN resetResult = FALSE; |
| 553 |
|
| 554 |
printk("AtapiResetController\n"); |
| 555 |
|
| 556 |
/* |
| 557 |
* Check and see if we are processing an internal srb. |
| 558 |
*/ |
| 559 |
if (pChan->OriginalSrb) |
| 560 |
{ |
| 561 |
pChan->CurrentSrb = pChan->OriginalSrb; |
| 562 |
pChan->OriginalSrb = NULL; |
| 563 |
} |
| 564 |
|
| 565 |
/* |
| 566 |
* To avoid unexpected interrupts occurs during reset procedure. |
| 567 |
* |
| 568 |
* 1. Stop bus master operation. |
| 569 |
*/ |
| 570 |
outb(0, dma_base); |
| 571 |
|
| 572 |
for (i = 0; i < 2; i++) |
| 573 |
{ |
| 574 |
outb((UCHAR)((i << 4) | 0xA0), pChan->io_ports[ATAPI_SELECT_OFFSET]); |
| 575 |
|
| 576 |
/* |
| 577 |
* 2. Clear interrupts if there is any. |
| 578 |
*/ |
| 579 |
GetBaseStatus(pChan, status); |
| 580 |
|
| 581 |
/* |
| 582 |
* 3. Disable interrupts. |
| 583 |
*/ |
| 584 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[ATAPI_CONTROL_OFFSET]); |
| 585 |
|
| 586 |
/* |
| 587 |
* 4. Clear interrupts again. |
| 588 |
*/ |
| 589 |
GetBaseStatus(pChan, status); |
| 590 |
} |
| 591 |
|
| 592 |
/* |
| 593 |
* Check if request is in progress. |
| 594 |
*/ |
| 595 |
if (pChan->CurrentSrb) |
| 596 |
{ |
| 597 |
/* |
| 598 |
* Complete outstanding request with SRB_STATUS_BUS_RESET. |
| 599 |
*/ |
| 600 |
|
| 601 |
/* |
| 602 |
* Clear request tracking fields. |
| 603 |
*/ |
| 604 |
pChan->CurrentSrb = NULL; |
| 605 |
pChan->WordsLeft = 0; |
| 606 |
pChan->DataBuffer = NULL; |
| 607 |
|
| 608 |
/* |
| 609 |
* Indicate ready for next request. |
| 610 |
*/ |
| 611 |
TaskDone(pChan, pChan->CurrentSrb); |
| 612 |
} |
| 613 |
|
| 614 |
/* |
| 615 |
* Clear expecting interrupt flag. |
| 616 |
*/ |
| 617 |
pChan->ExpectingInterrupt = FALSE; |
| 618 |
pChan->RDP = FALSE; |
| 619 |
|
| 620 |
resetResult = IT8212ResetAdapter(); |
| 621 |
|
| 622 |
for (i = 0; i < 4; i++) |
| 623 |
{ |
| 624 |
/* |
| 625 |
* Reenable interrupts. |
| 626 |
*/ |
| 627 |
outb((UCHAR)(((i & 1) << 4) | 0xA0), pChan->io_ports[ATAPI_SELECT_OFFSET]); |
| 628 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[ATAPI_CONTROL_OFFSET]); |
| 629 |
} |
| 630 |
|
| 631 |
return resetResult; |
| 632 |
|
| 633 |
} /* end AtapiResetController */ |
| 634 |
|
| 635 |
/************************************************************************ |
| 636 |
* IDE start read/write transfer |
| 637 |
************************************************************************/ |
| 638 |
void |
| 639 |
IdeStartTransfer |
| 640 |
( |
| 641 |
PChannel pChan, |
| 642 |
PSCSI_REQUEST_BLOCK Srb, |
| 643 |
ULONG startingSector, |
| 644 |
ULONG SectorNumber |
| 645 |
) |
| 646 |
{ |
| 647 |
|
| 648 |
UCHAR DiskId = (UCHAR) Srb->TargetId; |
| 649 |
UCHAR drvSelect; |
| 650 |
UCHAR bmClearStat; |
| 651 |
ULONG dma_base = pChan->dma_base; |
| 652 |
|
| 653 |
dprintk("IdeStartTransfer enter\n"); |
| 654 |
|
| 655 |
/* |
| 656 |
* Set watch dog timer to monitor interrupts. Timer will be removed |
| 657 |
* on DeviceInterrupt. |
| 658 |
*/ |
| 659 |
#if (0) |
| 660 |
SetWatchDogTimer(pChan); |
| 661 |
#endif |
| 662 |
|
| 663 |
/* |
| 664 |
* 48-bit support. |
| 665 |
*/ |
| 666 |
if ((startingSector + SectorNumber) > 0x0FFFFFFF) |
| 667 |
{ |
| 668 |
/* |
| 669 |
* Select drive and set LBA mode. |
| 670 |
*/ |
| 671 |
outb((UCHAR) (((DiskId & 0x1) << 4) | 0xA0 | 0x40), |
| 672 |
pChan->io_ports[IDE_SELECT_OFFSET]); |
| 673 |
|
| 674 |
/* |
| 675 |
* Sector count register. |
| 676 |
*/ |
| 677 |
outb((UCHAR) (SectorNumber >> 8), pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 678 |
outb((UCHAR) SectorNumber, pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 679 |
|
| 680 |
/* |
| 681 |
* LBA low register. |
| 682 |
*/ |
| 683 |
outb((UCHAR) (startingSector >> 24), pChan->io_ports[IDE_LOCYL_OFFSET]); |
| 684 |
outb((UCHAR) startingSector, pChan->io_ports[IDE_LOCYL_OFFSET]); |
| 685 |
|
| 686 |
/* |
| 687 |
* LBA mid register. |
| 688 |
*/ |
| 689 |
outb((UCHAR) 0, pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 690 |
outb((UCHAR) (startingSector >> 8), pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 691 |
|
| 692 |
/* |
| 693 |
* LBA high register. |
| 694 |
*/ |
| 695 |
outb((UCHAR) 0, pChan->io_ports[IDE_HCYL_OFFSET]); |
| 696 |
outb((UCHAR) (startingSector >> 16), pChan->io_ports[IDE_HCYL_OFFSET]); |
| 697 |
|
| 698 |
/* |
| 699 |
* Start the IDE read/write DMA command. |
| 700 |
*/ |
| 701 |
if (Srb->SrbFlags & SRB_FLAGS_DATA_IN) |
| 702 |
{ |
| 703 |
outb(IDE_COMMAND_READ_DMA_EXT, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 704 |
} |
| 705 |
else if (Srb->SrbFlags & SRB_FLAGS_DATA_OUT) |
| 706 |
{ |
| 707 |
outb(IDE_COMMAND_WRITE_DMA_EXT, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 708 |
} |
| 709 |
} |
| 710 |
/* |
| 711 |
* 28-bit addressing. |
| 712 |
*/ |
| 713 |
else |
| 714 |
{ |
| 715 |
/* |
| 716 |
* Select drive and set LBA mode. |
| 717 |
*/ |
| 718 |
drvSelect = (UCHAR) (startingSector >> 24); |
| 719 |
drvSelect = drvSelect | (((UCHAR) DiskId & 0x1) << 4) | 0x40 | 0xA0; |
| 720 |
|
| 721 |
outb(drvSelect, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 722 |
outb((UCHAR) SectorNumber, pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 723 |
outb((UCHAR) startingSector, pChan->io_ports[IDE_LOCYL_OFFSET]); |
| 724 |
outb((UCHAR)(startingSector >> 8), pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 725 |
outb((UCHAR)(startingSector >> 16), pChan->io_ports[IDE_HCYL_OFFSET]); |
| 726 |
|
| 727 |
/* |
| 728 |
* Start the IDE read/write DMA command. |
| 729 |
*/ |
| 730 |
if (Srb->SrbFlags & SRB_FLAGS_DATA_IN) |
| 731 |
{ |
| 732 |
outb(IDE_COMMAND_READ_DMA, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 733 |
} |
| 734 |
else if (Srb->SrbFlags & SRB_FLAGS_DATA_OUT) |
| 735 |
{ |
| 736 |
outb(IDE_COMMAND_WRITE_DMA, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 737 |
} |
| 738 |
} |
| 739 |
|
| 740 |
/* |
| 741 |
* Indicate expecting an interrupt. |
| 742 |
*/ |
| 743 |
pChan->ExpectingInterrupt = TRUE; |
| 744 |
|
| 745 |
/* |
| 746 |
* Setup PRD table physical address. |
| 747 |
*/ |
| 748 |
outl(pChan->dmatable_dma, dma_base + 4); |
| 749 |
|
| 750 |
/* |
| 751 |
* Read Bus Master status. |
| 752 |
*/ |
| 753 |
bmClearStat = inb(dma_base + 2); |
| 754 |
if (Srb->TargetId & 1) |
| 755 |
{ |
| 756 |
bmClearStat = bmClearStat | BM_DRV1_DMA_CAPABLE | |
| 757 |
BM_STAT_FLG_INT | BM_STAT_FLG_ERR; |
| 758 |
} |
| 759 |
else |
| 760 |
{ |
| 761 |
bmClearStat = bmClearStat | BM_DRV0_DMA_CAPABLE | |
| 762 |
BM_STAT_FLG_INT | BM_STAT_FLG_ERR; |
| 763 |
} |
| 764 |
|
| 765 |
outb(0, dma_base); |
| 766 |
|
| 767 |
/* |
| 768 |
* Clear INTR and ERROR flags. |
| 769 |
*/ |
| 770 |
outb(bmClearStat, dma_base + 2); |
| 771 |
|
| 772 |
/* |
| 773 |
* Start DMA read/write. |
| 774 |
*/ |
| 775 |
if (Srb->SrbFlags & SRB_FLAGS_DATA_IN) |
| 776 |
{ |
| 777 |
outb(BM_CMD_FLG_START | BM_CMD_FLG_WRTTOMEM, dma_base); |
| 778 |
} |
| 779 |
else if (Srb->SrbFlags & SRB_FLAGS_DATA_OUT) |
| 780 |
{ |
| 781 |
outb(BM_CMD_FLG_START | BM_CMD_FLG_WRTTODSK, dma_base); |
| 782 |
} |
| 783 |
|
| 784 |
dprintk("IdeStartTransfer exit\n"); |
| 785 |
|
| 786 |
} /* end IdeStartTransfer */ |
| 787 |
|
| 788 |
/************************************************************************ |
| 789 |
* IDE setup the PRD table |
| 790 |
************************************************************************/ |
| 791 |
static int |
| 792 |
IdeBuildSglist(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 793 |
{ |
| 794 |
|
| 795 |
int nents = 0; |
| 796 |
ULONG bytesRemaining = Srb->DataTransferLength; |
| 797 |
unsigned char * virt_addr = Srb->DataBuffer; |
| 798 |
struct scatterlist * sg = pChan->sg_table; |
| 799 |
|
| 800 |
if (Srb->SrbFlags & SRB_FLAGS_DATA_IN) |
| 801 |
{ |
| 802 |
pChan->sg_dma_direction = PCI_DMA_FROMDEVICE; |
| 803 |
} |
| 804 |
else |
| 805 |
{ |
| 806 |
pChan->sg_dma_direction = PCI_DMA_TODEVICE; |
| 807 |
} |
| 808 |
|
| 809 |
/* |
| 810 |
* The upper layer will never give the memory more than 64K bytes. |
| 811 |
*/ |
| 812 |
memset(&sg[nents], 0, sizeof(*sg)); |
| 813 |
sg[nents].address = virt_addr; |
| 814 |
sg[nents].length = bytesRemaining; |
| 815 |
nents++; |
| 816 |
|
| 817 |
return pci_map_sg(pChan->pPciDev, sg, nents, pChan->sg_dma_direction); |
| 818 |
|
| 819 |
} /* end IdeBuildSglist */ |
| 820 |
|
| 821 |
/************************************************************************ |
| 822 |
* Prepares a dma request |
| 823 |
************************************************************************/ |
| 824 |
static int |
| 825 |
IdeBuildDmaTable(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 826 |
{ |
| 827 |
unsigned int * table = pChan->dmatable_cpu; |
| 828 |
unsigned int count = 0; |
| 829 |
int i; |
| 830 |
struct scatterlist * sg; |
| 831 |
|
| 832 |
pChan->sg_nents = i = IdeBuildSglist(pChan, Srb); |
| 833 |
|
| 834 |
sg = pChan->sg_table; |
| 835 |
while (i && sg_dma_len(sg)) |
| 836 |
{ |
| 837 |
u32 cur_len; |
| 838 |
u32 cur_addr; |
| 839 |
|
| 840 |
cur_addr = sg_dma_address(sg); |
| 841 |
cur_len = sg_dma_len(sg); |
| 842 |
|
| 843 |
/* |
| 844 |
* Fill in the dma table, without crossing any 64kB boundaries. |
| 845 |
*/ |
| 846 |
while (cur_len) |
| 847 |
{ |
| 848 |
if (count++ >= PRD_ENTRIES) |
| 849 |
{ |
| 850 |
printk(KERN_WARNING "@@DMA table too small\n"); |
| 851 |
} |
| 852 |
else |
| 853 |
{ |
| 854 |
u32 xcount, bcount = 0x10000 - (cur_addr & 0xFFFF); |
| 855 |
|
| 856 |
if (bcount > cur_len) bcount = cur_len; |
| 857 |
*table++ = cpu_to_le32(cur_addr); |
| 858 |
xcount = bcount & 0xFFFF; |
| 859 |
if (xcount == 0x0000) |
| 860 |
{ |
| 861 |
/* |
| 862 |
* Most chipsets correctly interpret a length |
| 863 |
* of 0x0000 as 64KB, but at least one |
| 864 |
* (e.g. CS5530) misinterprets it as zero (!). |
| 865 |
* So here we break the 64KB entry into two |
| 866 |
* 32KB entries instead. |
| 867 |
*/ |
| 868 |
if (count++ >= PRD_ENTRIES) |
| 869 |
printk(KERN_WARNING "##DMA table too small\n"); |
| 870 |
|
| 871 |
*table++ = cpu_to_le32(0x8000); |
| 872 |
*table++ = cpu_to_le32(cur_addr + 0x8000); |
| 873 |
xcount = 0x8000; |
| 874 |
} |
| 875 |
*table++ = cpu_to_le32(xcount); |
| 876 |
cur_addr += bcount; |
| 877 |
cur_len -= bcount; |
| 878 |
} |
| 879 |
} |
| 880 |
sg++; |
| 881 |
i--; |
| 882 |
} |
| 883 |
|
| 884 |
if (count) |
| 885 |
{ |
| 886 |
*--table |= cpu_to_le32(0x80000000); |
| 887 |
return count; |
| 888 |
} |
| 889 |
else |
| 890 |
{ |
| 891 |
printk(KERN_WARNING "Empty DMA table?\n"); |
| 892 |
} |
| 893 |
|
| 894 |
return count; |
| 895 |
|
| 896 |
} /* end IdeBuildDmaTable */ |
| 897 |
|
| 898 |
/************************************************************************ |
| 899 |
* Prepares a dma scatter/gather request |
| 900 |
************************************************************************/ |
| 901 |
static void |
| 902 |
IdeBuildDmaSgTable(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 903 |
{ |
| 904 |
|
| 905 |
int use_sg = 0; |
| 906 |
int i; |
| 907 |
PPRD_TABLE_ENTRY pSG = (PPRD_TABLE_ENTRY)pChan->dmatable_cpu; |
| 908 |
struct scatterlist * sg = (struct scatterlist *)Srb->DataBuffer; |
| 909 |
|
| 910 |
if (Srb->SrbFlags & SRB_FLAGS_DATA_IN) |
| 911 |
{ |
| 912 |
pChan->sg_dma_direction = PCI_DMA_FROMDEVICE; |
| 913 |
} |
| 914 |
else |
| 915 |
{ |
| 916 |
pChan->sg_dma_direction = PCI_DMA_TODEVICE; |
| 917 |
} |
| 918 |
|
| 919 |
use_sg = pci_map_sg(pChan->pPciDev, Srb->DataBuffer, Srb->UseSg, pChan->sg_dma_direction); |
| 920 |
|
| 921 |
for (i = 0; i < use_sg; i++) |
| 922 |
{ |
| 923 |
pSG[i].PhysicalBaseAddress = sg_dma_address(&sg[i]); |
| 924 |
pSG[i].ByteCount = sg_dma_len(&sg[i]); |
| 925 |
pSG[i].EndOfTable = (i == use_sg - 1) ? SG_FLAG_EOT : 0; |
| 926 |
} |
| 927 |
|
| 928 |
} /* end IdeBuildDmaSgTable */ |
| 929 |
|
| 930 |
/************************************************************************ |
| 931 |
* Setup DMA table for channel |
| 932 |
************************************************************************/ |
| 933 |
static void |
| 934 |
IdeSetupDma(PChannel pChan, ULONG dma_base, USHORT num_ports) |
| 935 |
{ |
| 936 |
|
| 937 |
char * name0 = "CHANNEL0"; |
| 938 |
char * name1 = "CHANNEL1"; |
| 939 |
|
| 940 |
printk("Channel[%d] BM-DMA at 0x%04lX-0x%04lX\n", pChan->channel, dma_base, |
| 941 |
dma_base + num_ports - 1); |
| 942 |
|
| 943 |
/* |
| 944 |
* Check if this io space is used by other device. |
| 945 |
*/ |
| 946 |
if (check_region(dma_base, num_ports)) |
| 947 |
{ |
| 948 |
printk("Port addresses already in use.\n"); |
| 949 |
return; |
| 950 |
} |
| 951 |
|
| 952 |
/* |
| 953 |
* Request the io space (region). |
| 954 |
*/ |
| 955 |
if (pChan->channel == 0) |
| 956 |
{ |
| 957 |
request_region(dma_base, num_ports, name0); |
| 958 |
} |
| 959 |
else |
| 960 |
{ |
| 961 |
request_region(dma_base, num_ports, name1); |
| 962 |
} |
| 963 |
|
| 964 |
/* |
| 965 |
* Allocate IDE DMA buffer. |
| 966 |
*/ |
| 967 |
pChan->dmatable_cpu = pci_alloc_consistent(pChan->pPciDev, |
| 968 |
PRD_ENTRIES * PRD_BYTES, &pChan->dmatable_dma); |
| 969 |
|
| 970 |
if (pChan->dmatable_cpu == NULL) |
| 971 |
{ |
| 972 |
printk("Allocate prd table failed.\n"); |
| 973 |
return; |
| 974 |
} |
| 975 |
|
| 976 |
memset(pChan->dmatable_cpu, 0, PRD_ENTRIES * PRD_BYTES); |
| 977 |
|
| 978 |
/* |
| 979 |
* Allocate SCATTER/GATHER table buffer. |
| 980 |
*/ |
| 981 |
pChan->sg_table = kmalloc(sizeof(struct scatterlist) * PRD_ENTRIES, |
| 982 |
GFP_KERNEL); |
| 983 |
|
| 984 |
if (pChan->sg_table == NULL) |
| 985 |
{ |
| 986 |
printk("Allocate sg_table failed.\n"); |
| 987 |
pci_free_consistent(pChan->pPciDev, PRD_ENTRIES * PRD_BYTES, |
| 988 |
pChan->dmatable_cpu, pChan->dmatable_dma); |
| 989 |
return; |
| 990 |
} |
| 991 |
|
| 992 |
return; |
| 993 |
|
| 994 |
} /* end IdeSetupDma */ |
| 995 |
|
| 996 |
/************************************************************************ |
| 997 |
* |
| 998 |
************************************************************************/ |
| 999 |
void |
| 1000 |
IT8212ReconfigChannel(PChannel pChan, UCHAR ArrayId, UCHAR Operation) |
| 1001 |
{ |
| 1002 |
|
| 1003 |
UCHAR enableVirtualChannel; |
| 1004 |
struct pci_dev * pPciDev = pChan->pPciDev; |
| 1005 |
|
| 1006 |
pci_read_config_byte(pPciDev, 0x43, &enableVirtualChannel); |
| 1007 |
|
| 1008 |
if (Operation == DisableChannel) |
| 1009 |
{ |
| 1010 |
enableVirtualChannel &= ~(1 << ArrayId); |
| 1011 |
printk("IT8212ReconfigChannel: Disable channel %X\n", ArrayId); |
| 1012 |
} |
| 1013 |
else |
| 1014 |
{ |
| 1015 |
enableVirtualChannel |= ~(1 << ArrayId); |
| 1016 |
printk("IT8212ReconfigChannel: Enable channel %X\n", ArrayId); |
| 1017 |
} |
| 1018 |
|
| 1019 |
printk("IT8212ReconfigChannel: Channel enabled after set 0x%X\n", |
| 1020 |
enableVirtualChannel); |
| 1021 |
|
| 1022 |
/* |
| 1023 |
* Set enabled virtual channels. |
| 1024 |
*/ |
| 1025 |
pci_write_config_byte(pPciDev, 0x43, enableVirtualChannel); |
| 1026 |
|
| 1027 |
} /* end IT8212ReconfigChannel */ |
| 1028 |
|
| 1029 |
/************************************************************************ |
| 1030 |
* Get the chip status. This is a vendor specific command. According to |
| 1031 |
* all of the device configurations, the BIOS then can consider the |
| 1032 |
* existing RAID configuration reasonable. If the existing RAID configur- |
| 1033 |
* ation is not reasonable, or if there is NO existing RAID configuration |
| 1034 |
* , the BIOS can ask the user to setup the RAID configuration. Finally, |
| 1035 |
* the BIOS or AP should send the SET CHIP STATUS to every virtual device. |
| 1036 |
* Only after receiving SET CHIP STATUS command, the corresponding virtual |
| 1037 |
* device will be active. |
| 1038 |
************************************************************************/ |
| 1039 |
UCHAR |
| 1040 |
IT8212GetChipStatus(uioctl_t *ioc) |
| 1041 |
{ |
| 1042 |
|
| 1043 |
ULONG PriMasterIsNull = FALSE; |
| 1044 |
UCHAR statusByte; |
| 1045 |
UCHAR srbStatus; |
| 1046 |
PITE_ADAPTER pAdap; |
| 1047 |
PChannel pChan; |
| 1048 |
PHYSICAL_DISK_STATUS * pPhyDiskInfo; |
| 1049 |
|
| 1050 |
printk("IT8212GetChipStatus enter\n"); |
| 1051 |
|
| 1052 |
/* |
| 1053 |
* Only support one controller now! In the future, we can pass the |
| 1054 |
* argument (user ioctl structure) to know which controller need to be |
| 1055 |
* identified. |
| 1056 |
*/ |
| 1057 |
pAdap = ite_adapters[0]; |
| 1058 |
pChan = &pAdap->IDEChannel[0]; |
| 1059 |
|
| 1060 |
/* |
| 1061 |
* Allocate space for PHYSICAL_DISK_STATUS. |
| 1062 |
*/ |
| 1063 |
if ((pPhyDiskInfo = kmalloc(sizeof(PHYSICAL_DISK_STATUS) * 4, GFP_KERNEL)) == NULL) |
| 1064 |
{ |
| 1065 |
printk("error kmalloc on PHYSCIAL_DISK_STATUS.\n"); |
| 1066 |
return -ENOMEM; |
| 1067 |
} |
| 1068 |
|
| 1069 |
|
| 1070 |
/* |
| 1071 |
* Always send GET CHIP STATUS command to primary channel master device. |
| 1072 |
* Select device. |
| 1073 |
*/ |
| 1074 |
outb((UCHAR) 0xA0, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1075 |
|
| 1076 |
/* |
| 1077 |
* If primary master channel is not enabled, enable it. |
| 1078 |
*/ |
| 1079 |
statusByte = inb(pChan->io_ports[IDE_ALTERNATE_OFFSET]); |
| 1080 |
if (statusByte == 0) |
| 1081 |
{ |
| 1082 |
PriMasterIsNull = TRUE; |
| 1083 |
IT8212ReconfigChannel(pChan, 0, EnableChannel); |
| 1084 |
} |
| 1085 |
|
| 1086 |
/* |
| 1087 |
* Wait for device ready (Not BUSY and not DRQ) |
| 1088 |
*/ |
| 1089 |
WaitForDeviceReady(pChan, statusByte); |
| 1090 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 1091 |
(statusByte == 0)) |
| 1092 |
{ |
| 1093 |
printk("IT8212GetChipStatus: Disk[0] not ready. Status=0x%X\n", |
| 1094 |
statusByte); |
| 1095 |
srbStatus = SRB_STATUS_BUSY; |
| 1096 |
goto exit; |
| 1097 |
} |
| 1098 |
|
| 1099 |
/* |
| 1100 |
* Disable interrupt to avoid the unexpected interrupt. |
| 1101 |
*/ |
| 1102 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1103 |
|
| 1104 |
/* |
| 1105 |
* Issue the command. |
| 1106 |
*/ |
| 1107 |
outb(IDE_COMMAND_GET_CHIP_STATUS, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 1108 |
|
| 1109 |
/* |
| 1110 |
* Wait for BUSY = 0, DRQ = 1. |
| 1111 |
*/ |
| 1112 |
CheckBusyDrq(pChan, statusByte) |
| 1113 |
if (statusByte != 0x58) |
| 1114 |
{ |
| 1115 |
printk("IT8212GetChipStatus: Disk[0] return unexpected status after"); |
| 1116 |
printk("issue command. Status=0x%X\n", statusByte); |
| 1117 |
goto exit_error; |
| 1118 |
} |
| 1119 |
|
| 1120 |
/* |
| 1121 |
* Read the physical disk info. |
| 1122 |
*/ |
| 1123 |
ReadBuffer(pChan, (PUSHORT)pPhyDiskInfo, 256); |
| 1124 |
|
| 1125 |
/* |
| 1126 |
* Copy physical disk info to user area. |
| 1127 |
*/ |
| 1128 |
copy_to_user((PUSHORT)ioc->data, (PUSHORT)pPhyDiskInfo, 256); |
| 1129 |
|
| 1130 |
/* |
| 1131 |
* Check error. |
| 1132 |
*/ |
| 1133 |
WaitForCommandComplete(pChan, statusByte); |
| 1134 |
|
| 1135 |
if (statusByte != IDE_STATUS_IDLE) |
| 1136 |
{ |
| 1137 |
printk("IT8212GetChipStatus: Disk[0] return unexpected status after"); |
| 1138 |
printk("read data. Status=0x%X\n", statusByte); |
| 1139 |
goto exit_error; |
| 1140 |
} |
| 1141 |
|
| 1142 |
srbStatus = SRB_STATUS_SUCCESS; |
| 1143 |
goto exit; |
| 1144 |
|
| 1145 |
exit_error: |
| 1146 |
|
| 1147 |
/* |
| 1148 |
* If fail, hard reset to avoid the DRQ status pending. |
| 1149 |
*/ |
| 1150 |
srbStatus = SRB_STATUS_ERROR; |
| 1151 |
IdeHardReset(pChan, statusByte); |
| 1152 |
|
| 1153 |
exit: |
| 1154 |
|
| 1155 |
/* |
| 1156 |
* Reenable interrupt after command complete. |
| 1157 |
*/ |
| 1158 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1159 |
|
| 1160 |
/* |
| 1161 |
* If primary master is null, disable primary master channel before we leave. |
| 1162 |
*/ |
| 1163 |
if (PriMasterIsNull) |
| 1164 |
{ |
| 1165 |
IT8212ReconfigChannel(pChan, 0, DisableChannel); |
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
printk("IT8212GetChipStatus exit\n"); |
| 1170 |
|
| 1171 |
return srbStatus; |
| 1172 |
|
| 1173 |
} /* end IT8212GetChipStatus */ |
| 1174 |
|
| 1175 |
/************************************************************************ |
| 1176 |
* Erase the partition table. |
| 1177 |
************************************************************************/ |
| 1178 |
UCHAR |
| 1179 |
IT8212ErasePartition(uioctl_t *pioc) |
| 1180 |
{ |
| 1181 |
|
| 1182 |
UCHAR drvSelect; |
| 1183 |
UCHAR statusByte = 0; |
| 1184 |
UCHAR srbStatus; |
| 1185 |
UCHAR * buffer; |
| 1186 |
PRAID_CREATE_INFO createInfo = (PRAID_CREATE_INFO) pioc->data; |
| 1187 |
PITE_ADAPTER pAdap; |
| 1188 |
PChannel pChan; |
| 1189 |
|
| 1190 |
if (!createInfo->ErasePartition || (createInfo->RaidType == RAID_LEVEL_NODISK)) |
| 1191 |
return SRB_STATUS_SUCCESS; |
| 1192 |
|
| 1193 |
pAdap = ite_adapters[0]; |
| 1194 |
|
| 1195 |
if (createInfo->DiskArrayId < 2) pChan = &pAdap->IDEChannel[0]; |
| 1196 |
pChan = &pAdap->IDEChannel[1]; |
| 1197 |
|
| 1198 |
/* |
| 1199 |
* Allocate 512 bytes for buffer. |
| 1200 |
*/ |
| 1201 |
if ((buffer = kmalloc(512, GFP_KERNEL)) == NULL) |
| 1202 |
{ |
| 1203 |
printk("IT8212ErasePartition: error kmalloc.\n"); |
| 1204 |
return -ENOMEM; |
| 1205 |
} |
| 1206 |
|
| 1207 |
memset(buffer, 0, 512); |
| 1208 |
|
| 1209 |
/* |
| 1210 |
* Select device. |
| 1211 |
*/ |
| 1212 |
drvSelect = (((UCHAR) createInfo->DiskArrayId & 0x1) << 4) | 0xA0 | 0x40; |
| 1213 |
outb(drvSelect, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1214 |
|
| 1215 |
/* |
| 1216 |
* Wait for device ready (not BUSY and not DRQ). |
| 1217 |
*/ |
| 1218 |
WaitForDeviceReady(pChan, statusByte); |
| 1219 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 1220 |
(statusByte == 0)) |
| 1221 |
{ |
| 1222 |
printk("IT8212ErasePartition: Disk[%d] not ready. Status=0x%X\n", |
| 1223 |
createInfo->DiskArrayId, statusByte); |
| 1224 |
return SRB_STATUS_BUSY; |
| 1225 |
} |
| 1226 |
|
| 1227 |
/* |
| 1228 |
* Disable interrupt to avoid the unexpected interrupt. |
| 1229 |
*/ |
| 1230 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1231 |
|
| 1232 |
/* |
| 1233 |
* Write LBA 0 (1 sector). |
| 1234 |
*/ |
| 1235 |
outb(1, pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 1236 |
outb(0, pChan->io_ports[IDE_LOCYL_OFFSET]); |
| 1237 |
outb(0, pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 1238 |
outb(0, pChan->io_ports[IDE_HCYL_OFFSET]); |
| 1239 |
outb(drvSelect, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1240 |
outb(IDE_COMMAND_WRITE_SECTOR, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 1241 |
|
| 1242 |
/* |
| 1243 |
* Wait for BUSY = 0, DRQ = 1. |
| 1244 |
*/ |
| 1245 |
CheckBusyDrq(pChan, statusByte); |
| 1246 |
if (statusByte != 0x58) |
| 1247 |
{ |
| 1248 |
printk("IT8212ErasePartition: Disk[%d] error status. Status=0x%X\n", |
| 1249 |
createInfo->DiskArrayId, statusByte); |
| 1250 |
goto exit_error; |
| 1251 |
} |
| 1252 |
|
| 1253 |
/* |
| 1254 |
* Start erase partition table. |
| 1255 |
*/ |
| 1256 |
WriteBuffer(pChan, (PUSHORT)buffer, 256); |
| 1257 |
|
| 1258 |
/* |
| 1259 |
* Check error. |
| 1260 |
*/ |
| 1261 |
WaitForCommandComplete(pChan, statusByte); |
| 1262 |
|
| 1263 |
if (statusByte != IDE_STATUS_IDLE) |
| 1264 |
{ |
| 1265 |
printk("IT8212ErasePartition: Disk[%d] error status. Status=0x%X\n", |
| 1266 |
createInfo->DiskArrayId, statusByte); |
| 1267 |
goto exit_error; |
| 1268 |
} |
| 1269 |
|
| 1270 |
srbStatus = SRB_STATUS_SUCCESS; |
| 1271 |
goto exit; |
| 1272 |
|
| 1273 |
exit_error: |
| 1274 |
|
| 1275 |
/* |
| 1276 |
* If failed, hard reset to avoid the DRQ status pending. |
| 1277 |
*/ |
| 1278 |
IdeHardReset(pChan, statusByte); |
| 1279 |
srbStatus = SRB_STATUS_ERROR; |
| 1280 |
|
| 1281 |
exit: |
| 1282 |
|
| 1283 |
/* |
| 1284 |
* Reenable interrupt after command complete. |
| 1285 |
*/ |
| 1286 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1287 |
|
| 1288 |
return srbStatus; |
| 1289 |
|
| 1290 |
} /* end IT8212ErasePartition */ |
| 1291 |
|
| 1292 |
/************************************************************************ |
| 1293 |
* |
| 1294 |
************************************************************************/ |
| 1295 |
UCHAR |
| 1296 |
IT8212TruncateReduentSectors |
| 1297 |
( |
| 1298 |
ULONG OriginalSectorCount, |
| 1299 |
USHORT StripeSizeInKBytes |
| 1300 |
) |
| 1301 |
{ |
| 1302 |
|
| 1303 |
USHORT stripeSizeInSector; |
| 1304 |
|
| 1305 |
/* |
| 1306 |
* 0 means using default value (32 sectors). |
| 1307 |
*/ |
| 1308 |
if (StripeSizeInKBytes == 0) |
| 1309 |
{ |
| 1310 |
stripeSizeInSector = 64 * 2; |
| 1311 |
} |
| 1312 |
else |
| 1313 |
{ |
| 1314 |
stripeSizeInSector = StripeSizeInKBytes * 2; |
| 1315 |
} |
| 1316 |
|
| 1317 |
return ((OriginalSectorCount / stripeSizeInSector) * stripeSizeInSector); |
| 1318 |
|
| 1319 |
|
| 1320 |
} /* end IT8212TruncateReduentSectors */ |
| 1321 |
|
| 1322 |
/************************************************************************ |
| 1323 |
* |
| 1324 |
************************************************************************/ |
| 1325 |
ULONG |
| 1326 |
IT8212DiskArrayAddressableSector(PUCHAR DiskArrayCreateInfo) |
| 1327 |
{ |
| 1328 |
|
| 1329 |
PRAID_CREATE_INFO createInfo = (PRAID_CREATE_INFO) DiskArrayCreateInfo; |
| 1330 |
ULONG MinDiskCapacity; |
| 1331 |
ULONG ArrayCapacity; |
| 1332 |
UCHAR DiskNo; |
| 1333 |
UCHAR NumOfDisks; |
| 1334 |
|
| 1335 |
MinDiskCapacity = ArrayCapacity = NumOfDisks = 0; |
| 1336 |
|
| 1337 |
printk("createInfo->AddressableSectors[0] = 0x%lX\n", createInfo->AddressableSectors[0]); |
| 1338 |
printk("createInfo->AddressableSectors[1] = 0x%lX\n", createInfo->AddressableSectors[1]); |
| 1339 |
printk("createInfo->AddressableSectors[2] = 0x%lX\n", createInfo->AddressableSectors[2]); |
| 1340 |
printk("createInfo->AddressableSectors[3] = 0x%lX\n", createInfo->AddressableSectors[3]); |
| 1341 |
|
| 1342 |
for (DiskNo = 0; DiskNo < 4; DiskNo++) |
| 1343 |
{ |
| 1344 |
/* |
| 1345 |
* If disk exist. |
| 1346 |
*/ |
| 1347 |
if ((createInfo->ContainingDisks >> DiskNo) & 0x1) |
| 1348 |
{ |
| 1349 |
NumOfDisks += 1; |
| 1350 |
if (!MinDiskCapacity || (createInfo->AddressableSectors[DiskNo] < |
| 1351 |
MinDiskCapacity)) |
| 1352 |
{ |
| 1353 |
MinDiskCapacity = createInfo->AddressableSectors[DiskNo]; |
| 1354 |
} |
| 1355 |
} |
| 1356 |
} |
| 1357 |
|
| 1358 |
switch (createInfo->RaidType) |
| 1359 |
{ |
| 1360 |
/* |
| 1361 |
* Containing 2 or 3 or 4 disks. |
| 1362 |
*/ |
| 1363 |
case RAID_LEVEL_0: |
| 1364 |
MinDiskCapacity = IT8212TruncateReduentSectors(MinDiskCapacity - 2, |
| 1365 |
createInfo->StripeSize); |
| 1366 |
ArrayCapacity = MinDiskCapacity - 2; |
| 1367 |
break; |
| 1368 |
|
| 1369 |
/* |
| 1370 |
* Containing 2 disks. |
| 1371 |
*/ |
| 1372 |
case RAID_LEVEL_1: |
| 1373 |
ArrayCapacity = MinDiskCapacity - 2; |
| 1374 |
break; |
| 1375 |
|
| 1376 |
/* |
| 1377 |
* Containing 4 disks. |
| 1378 |
*/ |
| 1379 |
case RAID_LEVEL_10: |
| 1380 |
MinDiskCapacity = IT8212TruncateReduentSectors(MinDiskCapacity - 2, |
| 1381 |
createInfo->StripeSize); |
| 1382 |
ArrayCapacity = MinDiskCapacity * 2; |
| 1383 |
break; |
| 1384 |
|
| 1385 |
/* |
| 1386 |
* Containing 2, 3, or 4 disks. |
| 1387 |
*/ |
| 1388 |
case RAID_LEVEL_JBOD: |
| 1389 |
for (DiskNo = 0; DiskNo < 4; DiskNo++) |
| 1390 |
{ |
| 1391 |
if ((createInfo->ContainingDisks >> DiskNo) & 0x1) |
| 1392 |
{ |
| 1393 |
ArrayCapacity = ArrayCapacity + (createInfo->AddressableSectors[DiskNo] - 2); |
| 1394 |
} |
| 1395 |
} |
| 1396 |
break; |
| 1397 |
|
| 1398 |
/* |
| 1399 |
* Containing only 1 disk. |
| 1400 |
*/ |
| 1401 |
case RAID_LEVEL_NORMAL: |
| 1402 |
ArrayCapacity = MinDiskCapacity; |
| 1403 |
break; |
| 1404 |
|
| 1405 |
} |
| 1406 |
|
| 1407 |
return ArrayCapacity; |
| 1408 |
|
| 1409 |
} /* end IT8212DiskArrayAddressableSector */ |
| 1410 |
|
| 1411 |
/************************************************************************ |
| 1412 |
* Create a new array. |
| 1413 |
************************************************************************/ |
| 1414 |
UCHAR |
| 1415 |
IT8212CreateDiskArray(uioctl_t *pioc) |
| 1416 |
{ |
| 1417 |
|
| 1418 |
UCHAR i; |
| 1419 |
UCHAR subCommand = 0xFF; |
| 1420 |
UCHAR statusByte; |
| 1421 |
UCHAR dmaSupported; |
| 1422 |
UCHAR udmaSupported; |
| 1423 |
UCHAR srbStatus; |
| 1424 |
void * buffer; |
| 1425 |
ULONG UserAddressableSectors; |
| 1426 |
ULONG PriMasterIsNull = FALSE; |
| 1427 |
PRAID_CREATE_INFO createInfo = (PRAID_CREATE_INFO)pioc->data; |
| 1428 |
PIDENTIFY_DATA2 identifyData; |
| 1429 |
PIT8212_SET_CHIP_STATUS_INFO setChipStatus; |
| 1430 |
PITE_ADAPTER pAdap; |
| 1431 |
PChannel pChan; |
| 1432 |
|
| 1433 |
USHORT IT8212TimingTable[7] = |
| 1434 |
{ |
| 1435 |
0x3133, /* UDMA timimg register 01 */ |
| 1436 |
0x2121, /* UDMA timimg register 23 */ |
| 1437 |
0x9111, /* UDMA timimg register 45 */ |
| 1438 |
0x0091, /* UDMA timimg register 6 */ |
| 1439 |
0x3266, /* DMA timimg register 01 */ |
| 1440 |
0x0021, /* DMA timimg register 2 */ |
| 1441 |
0x0021 /* PIO timimg register */ |
| 1442 |
}; |
| 1443 |
|
| 1444 |
USHORT IT8212ClockTable[7] = |
| 1445 |
{ |
| 1446 |
0x0505, /* UDMA clock register 01 */ |
| 1447 |
0x0005, /* UDMA clock register 23 */ |
| 1448 |
0x0500, /* UDMA clock register 45 */ |
| 1449 |
0x0000, /* UDMA clock register 6 */ |
| 1450 |
0x0005, /* DMA clock register 01 */ |
| 1451 |
0x0005, /* DMA clock register 2 */ |
| 1452 |
0x0005 /* PIO clock register */ |
| 1453 |
}; |
| 1454 |
|
| 1455 |
switch (createInfo->RaidType) |
| 1456 |
{ |
| 1457 |
case RAID_LEVEL_0: |
| 1458 |
case RAID_LEVEL_1: |
| 1459 |
case RAID_LEVEL_10: |
| 1460 |
case RAID_LEVEL_JBOD: |
| 1461 |
case RAID_LEVEL_NORMAL: |
| 1462 |
subCommand = 0x50; |
| 1463 |
break; |
| 1464 |
|
| 1465 |
case RAID_LEVEL_NODISK: |
| 1466 |
subCommand = 0x48; |
| 1467 |
break; |
| 1468 |
} |
| 1469 |
|
| 1470 |
pAdap = ite_adapters[pioc->AdapterNo]; |
| 1471 |
if (pioc->DiskNo < 2) |
| 1472 |
{ |
| 1473 |
pChan = &pAdap->IDEChannel[0]; |
| 1474 |
} |
| 1475 |
else |
| 1476 |
{ |
| 1477 |
pChan = &pAdap->IDEChannel[1]; |
| 1478 |
} |
| 1479 |
|
| 1480 |
/* |
| 1481 |
* Allocate 512-bytes buffer. |
| 1482 |
*/ |
| 1483 |
if ((buffer = kmalloc(512, GFP_KERNEL)) == NULL) |
| 1484 |
{ |
| 1485 |
printk("IT8212CreateDiskArray: error kmalloc.\n"); |
| 1486 |
return -ENOMEM; |
| 1487 |
} |
| 1488 |
|
| 1489 |
identifyData = (PIDENTIFY_DATA2) buffer; |
| 1490 |
setChipStatus = (PIT8212_SET_CHIP_STATUS_INFO) (buffer + 256); |
| 1491 |
|
| 1492 |
/* |
| 1493 |
* Configure to RAID or NORMAL. |
| 1494 |
*/ |
| 1495 |
if (subCommand == 0x50) |
| 1496 |
{ |
| 1497 |
/* |
| 1498 |
* Zero identify data structure. |
| 1499 |
*/ |
| 1500 |
memset((PUCHAR) identifyData, 0, sizeof(IDENTIFY_DATA)); |
| 1501 |
|
| 1502 |
/* |
| 1503 |
* Fill up identify data. |
| 1504 |
*/ |
| 1505 |
memmove(identifyData->ModelNumber, createInfo->ModelNumber, 40); |
| 1506 |
memmove(identifyData->SerialNumber, &createInfo->SerialNumber, sizeof(RAID_SERIAL_NUMBER)); |
| 1507 |
|
| 1508 |
/* |
| 1509 |
* Set disk array virtual capacity. |
| 1510 |
*/ |
| 1511 |
UserAddressableSectors = IT8212DiskArrayAddressableSector(pioc->data); |
| 1512 |
|
| 1513 |
printk("IT8212CreateDiskArray: Array Capacity = %lX\n", UserAddressableSectors); |
| 1514 |
|
| 1515 |
identifyData->Capacity_48bit_LOW = UserAddressableSectors; |
| 1516 |
identifyData->Capacity_48bit_HIGH = 0; |
| 1517 |
|
| 1518 |
if (UserAddressableSectors > 0x0FFFFFFF) |
| 1519 |
{ |
| 1520 |
identifyData->UserAddressableSectors = 0x0FFFFFFF; |
| 1521 |
} |
| 1522 |
else |
| 1523 |
{ |
| 1524 |
identifyData->UserAddressableSectors = UserAddressableSectors; |
| 1525 |
} |
| 1526 |
|
| 1527 |
/* |
| 1528 |
* Get DMA supported mode and UDMA supported mode. |
| 1529 |
*/ |
| 1530 |
dmaSupported = udmaSupported =0xFF; |
| 1531 |
|
| 1532 |
for (i = 0; i < 4; i++) |
| 1533 |
{ |
| 1534 |
if ((createInfo->ContainingDisks >> i) & 1) |
| 1535 |
{ |
| 1536 |
dmaSupported &= (UCHAR) createInfo->DMASupported[i]; |
| 1537 |
udmaSupported &= (UCHAR) createInfo->UDMASupported[i]; |
| 1538 |
} |
| 1539 |
} |
| 1540 |
|
| 1541 |
identifyData->MultiWordDMASupport = dmaSupported; |
| 1542 |
identifyData->UltraDMASupport = udmaSupported; |
| 1543 |
|
| 1544 |
/* |
| 1545 |
* Fill up SET CHIP STATUS data (word 129 - 153) |
| 1546 |
*/ |
| 1547 |
setChipStatus->RaidType = createInfo->RaidType; |
| 1548 |
setChipStatus->ContainingDisks = createInfo->ContainingDisks; |
| 1549 |
setChipStatus->UltraDmaTiming01 = IT8212TimingTable[0]; |
| 1550 |
setChipStatus->UltraDmaTiming23 = IT8212TimingTable[1]; |
| 1551 |
setChipStatus->UltraDmaTiming45 = IT8212TimingTable[2]; |
| 1552 |
setChipStatus->UltraDmaTiming6 = IT8212TimingTable[3]; |
| 1553 |
setChipStatus->MultiWordDmaTiming01 = IT8212TimingTable[4]; |
| 1554 |
setChipStatus->UltraDmaTiming2 = IT8212TimingTable[5]; |
| 1555 |
setChipStatus->PioTiming4 = IT8212TimingTable[6]; |
| 1556 |
setChipStatus->AutoRebuildEnable = createInfo->AutoRebuildEnable; |
| 1557 |
setChipStatus->IdeClkUDma01 = IT8212ClockTable[0]; |
| 1558 |
setChipStatus->IdeClkUDma23 = IT8212ClockTable[1]; |
| 1559 |
setChipStatus->IdeClkUDma45 = IT8212ClockTable[2]; |
| 1560 |
setChipStatus->IdeClkUDma6 = IT8212ClockTable[3]; |
| 1561 |
setChipStatus->IdeClkMDma01 = IT8212ClockTable[4]; |
| 1562 |
setChipStatus->IdeClkMDma2 = IT8212ClockTable[5]; |
| 1563 |
setChipStatus->IdeClkPio4 = IT8212ClockTable[6]; |
| 1564 |
setChipStatus->StripeSize = createInfo->StripeSize; |
| 1565 |
setChipStatus->BootableDisk = createInfo->BootableDisk; |
| 1566 |
setChipStatus->CheckHotSwapInterval = 0; |
| 1567 |
setChipStatus->TargetSourceDisk = createInfo->TargetSourceDisk; |
| 1568 |
setChipStatus->RebuildBlockSize = 0; |
| 1569 |
setChipStatus->ResetInterval1 = 0; |
| 1570 |
setChipStatus->ResetInterval2 = 0; |
| 1571 |
setChipStatus->RebuildRetryTimes = 0; |
| 1572 |
setChipStatus->NewlyCreated = createInfo->NewlyCreated; |
| 1573 |
} |
| 1574 |
|
| 1575 |
/* |
| 1576 |
* There are some contrains of disk placement. AP will take care of it. |
| 1577 |
*/ |
| 1578 |
|
| 1579 |
/* |
| 1580 |
* This command should be sent to Virtual Primary Master. |
| 1581 |
*/ |
| 1582 |
|
| 1583 |
/* |
| 1584 |
* Select device. |
| 1585 |
*/ |
| 1586 |
outb((UCHAR) 0xA0, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1587 |
|
| 1588 |
/* |
| 1589 |
* If primary master channel is not enabled, enable it. |
| 1590 |
*/ |
| 1591 |
statusByte = inb(pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1592 |
if (statusByte == 0) |
| 1593 |
{ |
| 1594 |
PriMasterIsNull = TRUE; |
| 1595 |
IT8212ReconfigChannel(pChan, 0, EnableChannel); |
| 1596 |
} |
| 1597 |
|
| 1598 |
/* |
| 1599 |
* Wait for device ready (not BUSY and not DRQ) |
| 1600 |
*/ |
| 1601 |
WaitForDeviceReady(pChan, statusByte); |
| 1602 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 1603 |
(statusByte == 0)) |
| 1604 |
{ |
| 1605 |
printk("IT8212CreateDiskArray: Disk[0] not ready. status=0x%X\n", |
| 1606 |
statusByte); |
| 1607 |
srbStatus = SRB_STATUS_BUSY; |
| 1608 |
goto exit; |
| 1609 |
} |
| 1610 |
|
| 1611 |
/* |
| 1612 |
* Disable interrupt to avoid the unexpected interrupt. |
| 1613 |
*/ |
| 1614 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1615 |
|
| 1616 |
outb(subCommand, pChan->io_ports[IDE_FEATURE_OFFSET]); |
| 1617 |
outb(createInfo->DiskArrayId, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1618 |
outb(IDE_COMMAND_SET_CHIP_STATUS, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 1619 |
|
| 1620 |
/* |
| 1621 |
* No disk (no data command protocol) |
| 1622 |
*/ |
| 1623 |
if (subCommand == 0x48) |
| 1624 |
{ |
| 1625 |
WaitForCommandComplete(pChan, statusByte); |
| 1626 |
if (statusByte != IDE_STATUS_IDLE) |
| 1627 |
{ |
| 1628 |
printk("IT8212CreateDiskArray: Disk[0] return unexpected status after issue command.\n"); |
| 1629 |
goto exit_error; |
| 1630 |
} |
| 1631 |
|
| 1632 |
IT8212ReconfigChannel(pChan, createInfo->DiskArrayId, DisableChannel); |
| 1633 |
srbStatus = SRB_STATUS_SUCCESS; |
| 1634 |
goto exit; |
| 1635 |
} |
| 1636 |
|
| 1637 |
/* |
| 1638 |
* Create RAID (PIO data out command protocol). |
| 1639 |
*/ |
| 1640 |
if (subCommand == 0x50) |
| 1641 |
{ |
| 1642 |
/* |
| 1643 |
* Wait for BUSY=0, DRQ=1. |
| 1644 |
*/ |
| 1645 |
CheckBusyDrq(pChan, statusByte); |
| 1646 |
if (statusByte != 0x58) |
| 1647 |
{ |
| 1648 |
goto exit_error; |
| 1649 |
} |
| 1650 |
|
| 1651 |
IT8212ReconfigChannel(pChan, createInfo->DiskArrayId, EnableChannel); |
| 1652 |
srbStatus = SRB_STATUS_ERROR; |
| 1653 |
} |
| 1654 |
|
| 1655 |
exit_error: |
| 1656 |
|
| 1657 |
/* |
| 1658 |
* If fail, hard reset to avoid the DRQ pending. |
| 1659 |
*/ |
| 1660 |
IdeHardReset(pChan, statusByte); |
| 1661 |
srbStatus = SRB_STATUS_ERROR; |
| 1662 |
|
| 1663 |
exit: |
| 1664 |
|
| 1665 |
/* |
| 1666 |
* If primary master is null, and we are not configuring array 0. Disable |
| 1667 |
* primary master channel again. |
| 1668 |
*/ |
| 1669 |
if (PriMasterIsNull && createInfo->DiskArrayId) |
| 1670 |
{ |
| 1671 |
IT8212ReconfigChannel(pChan, 0 , DisableChannel); |
| 1672 |
} |
| 1673 |
|
| 1674 |
/* |
| 1675 |
* Reenable interrupt after command complete. |
| 1676 |
*/ |
| 1677 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1678 |
|
| 1679 |
return srbStatus; |
| 1680 |
|
| 1681 |
|
| 1682 |
} /* end IT8212CreateDiskArray */ |
| 1683 |
|
| 1684 |
/************************************************************************ |
| 1685 |
* Return "virtual" drive 512 bytes identification data. |
| 1686 |
************************************************************************/ |
| 1687 |
UCHAR |
| 1688 |
IT8212IssueIdentify(uioctl_t *pioc) |
| 1689 |
{ |
| 1690 |
|
| 1691 |
UCHAR channum; |
| 1692 |
UCHAR devnum; |
| 1693 |
UCHAR statusByte; |
| 1694 |
UCHAR srbStatus = 0; |
| 1695 |
PITE_ADAPTER pAdap; |
| 1696 |
PChannel pChan; |
| 1697 |
|
| 1698 |
/* |
| 1699 |
* Only support one adapter now! In the future, we can pass the argument |
| 1700 |
* to know which adapter need to be identified. |
| 1701 |
*/ |
| 1702 |
pAdap = ite_adapters[pioc->AdapterNo]; |
| 1703 |
|
| 1704 |
memset(pioc->data, 0, 512 * 4); |
| 1705 |
|
| 1706 |
/* |
| 1707 |
* Two channels per controller. |
| 1708 |
*/ |
| 1709 |
for (channum = 0; channum < pAdap->num_channels; channum++) |
| 1710 |
{ |
| 1711 |
pChan = &pAdap->IDEChannel[channum]; |
| 1712 |
|
| 1713 |
/* |
| 1714 |
* Two devices per channel. |
| 1715 |
*/ |
| 1716 |
for (devnum = 0; devnum < 2; devnum++) |
| 1717 |
{ |
| 1718 |
/* |
| 1719 |
* Select device. |
| 1720 |
*/ |
| 1721 |
outb((UCHAR)((devnum << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1722 |
|
| 1723 |
/* |
| 1724 |
* Check if disk online? |
| 1725 |
*/ |
| 1726 |
statusByte = inb(pChan->io_ports[IDE_ALTERNATE_OFFSET]); |
| 1727 |
if ((statusByte & 0x40) != 0x40) |
| 1728 |
{ |
| 1729 |
printk("IT8212IssueIdentify: Disk[%d] is offline\n", devnum + channum * 2); |
| 1730 |
continue; |
| 1731 |
} |
| 1732 |
|
| 1733 |
/* |
| 1734 |
* Wait for device ready (Not busy and not DRQ) |
| 1735 |
*/ |
| 1736 |
WaitForDeviceReady(pChan, statusByte); |
| 1737 |
|
| 1738 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 1739 |
(statusByte == 0)) |
| 1740 |
{ |
| 1741 |
printk("IT8212IssueIdentify: Disk[%d] not ready. Status=0x%X\n", |
| 1742 |
devnum + channum * 2, statusByte); |
| 1743 |
srbStatus = SRB_STATUS_BUSY; |
| 1744 |
goto exit; |
| 1745 |
} |
| 1746 |
|
| 1747 |
/* |
| 1748 |
* Disable interrupt to avoid the unexpected interrupt. |
| 1749 |
*/ |
| 1750 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1751 |
|
| 1752 |
/* |
| 1753 |
* Issue command. |
| 1754 |
*/ |
| 1755 |
outb(IDE_COMMAND_IDENTIFY, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 1756 |
|
| 1757 |
/* |
| 1758 |
* Wait for BUSY = 0 and DRQ = 1. |
| 1759 |
*/ |
| 1760 |
CheckBusyDrq(pChan, statusByte); |
| 1761 |
if (statusByte != 0x58) |
| 1762 |
{ |
| 1763 |
printk("IT8212IssueIndetify:Disk[%d] returns unexpedted status after issue command. status=0x%X\n", |
| 1764 |
devnum + channum * 2, statusByte); |
| 1765 |
goto error; |
| 1766 |
} |
| 1767 |
|
| 1768 |
/* |
| 1769 |
* Read the identify data. |
| 1770 |
*/ |
| 1771 |
ReadBuffer(pChan, (PUSHORT)&pChan->FullIdentifyData, 256); |
| 1772 |
|
| 1773 |
/* |
| 1774 |
* Then copy to user area. |
| 1775 |
* unsigned long copy_to_user(void *to, const void *from, unsigned long count). |
| 1776 |
*/ |
| 1777 |
copy_to_user((PUSHORT) (pioc->data + ((devnum + channum * 2) * 512)), |
| 1778 |
(PUSHORT)&pChan->FullIdentifyData, 256); |
| 1779 |
|
| 1780 |
/* |
| 1781 |
* Check error after reading data. |
| 1782 |
*/ |
| 1783 |
WaitForCommandComplete(pChan, statusByte); |
| 1784 |
if (statusByte != IDE_STATUS_IDLE) |
| 1785 |
{ |
| 1786 |
printk("IT8212IssueIdentify: Disk[%d] returns unexpected status after read data. status=0x%X\n", |
| 1787 |
devnum + channum * 2, statusByte); |
| 1788 |
goto error; |
| 1789 |
} |
| 1790 |
|
| 1791 |
} /* end for each device */ |
| 1792 |
|
| 1793 |
} /* end for each channel */ |
| 1794 |
|
| 1795 |
srbStatus = SRB_STATUS_SUCCESS; |
| 1796 |
goto exit; |
| 1797 |
|
| 1798 |
error: |
| 1799 |
|
| 1800 |
/* |
| 1801 |
* If failed, hard reset to avoid the IRQ pending. |
| 1802 |
*/ |
| 1803 |
IdeHardReset(pChan, statusByte); |
| 1804 |
srbStatus = SRB_STATUS_ERROR; |
| 1805 |
|
| 1806 |
exit: |
| 1807 |
|
| 1808 |
/* |
| 1809 |
* Reenable interrupt after command complete. |
| 1810 |
*/ |
| 1811 |
for (channum = 0; channum < pAdap->num_channels; channum++) |
| 1812 |
{ |
| 1813 |
pChan = &pAdap->IDEChannel[channum]; |
| 1814 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1815 |
} |
| 1816 |
|
| 1817 |
return srbStatus; |
| 1818 |
|
| 1819 |
} /* end IT8212IssueIdentify */ |
| 1820 |
|
| 1821 |
/************************************************************************ |
| 1822 |
* Reset the controller |
| 1823 |
************************************************************************/ |
| 1824 |
BOOLEAN |
| 1825 |
IT8212ResetAdapter(void) |
| 1826 |
{ |
| 1827 |
|
| 1828 |
BOOLEAN resetChannel[2]; |
| 1829 |
UCHAR channel; |
| 1830 |
UCHAR device; |
| 1831 |
UCHAR i; |
| 1832 |
UCHAR status[4]; |
| 1833 |
PChannel pChan; |
| 1834 |
PITE_ADAPTER pAdap = ite_adapters[0]; |
| 1835 |
|
| 1836 |
/* |
| 1837 |
* First, perform ATAPI softreset if ATAPI devices attached. |
| 1838 |
*/ |
| 1839 |
for (channel = 0; channel < 2; channel++) |
| 1840 |
{ |
| 1841 |
pChan = &pAdap->IDEChannel[channel]; |
| 1842 |
resetChannel[channel] = FALSE; |
| 1843 |
for (device = 0; device < 2; device++) |
| 1844 |
{ |
| 1845 |
if (pChan->DeviceFlags[device] & DFLAGS_DEVICE_PRESENT) |
| 1846 |
{ |
| 1847 |
if (pChan->DeviceFlags[device] & DFLAGS_ATAPI_DEVICE) |
| 1848 |
{ |
| 1849 |
printk("IT8212ResetAdapter: Perform ATAPI Soft Reset (%d, %d)\n", |
| 1850 |
channel, device); |
| 1851 |
AtapiSoftReset(pChan, device); |
| 1852 |
} |
| 1853 |
else |
| 1854 |
{ |
| 1855 |
resetChannel[channel] = TRUE; |
| 1856 |
} |
| 1857 |
} |
| 1858 |
} |
| 1859 |
} |
| 1860 |
|
| 1861 |
/* |
| 1862 |
* If ATA device present on this channel, perform channel reset. |
| 1863 |
*/ |
| 1864 |
for (channel = 0; channel < 2; channel++) |
| 1865 |
{ |
| 1866 |
if (resetChannel[channel]) |
| 1867 |
{ |
| 1868 |
printk("IT8212ResetAdapter: Reset channel %d\n", channel); |
| 1869 |
outb(IDE_DC_RESET_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1870 |
mdelay(50); |
| 1871 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1872 |
} |
| 1873 |
} |
| 1874 |
|
| 1875 |
/* |
| 1876 |
* Check device status after reset. |
| 1877 |
*/ |
| 1878 |
for (i = 0; i < 1000 * 1000; i++) |
| 1879 |
{ |
| 1880 |
for (channel = 0; channel < 2; channel++) |
| 1881 |
{ |
| 1882 |
for (device = 0; device < 2; device++) |
| 1883 |
{ |
| 1884 |
if (pChan->DeviceFlags[device] & DFLAGS_DEVICE_PRESENT) |
| 1885 |
{ |
| 1886 |
outb((UCHAR)((device << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1887 |
status[(channel * 2) + device] = inb(pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 1888 |
} |
| 1889 |
else |
| 1890 |
{ |
| 1891 |
status[(channel * 2) + device] = 0; |
| 1892 |
} |
| 1893 |
} |
| 1894 |
} |
| 1895 |
|
| 1896 |
/* |
| 1897 |
* ATA device should present status 0x50 after reset. |
| 1898 |
* ATAPI device should present status 0 after reset. |
| 1899 |
*/ |
| 1900 |
if ((status[0] != IDE_STATUS_IDLE && status[0] != 0x0) || (status[1] != IDE_STATUS_IDLE && status[1] != 0x0) || |
| 1901 |
(status[2] != IDE_STATUS_IDLE && status[2] != 0x0) || (status[3] != IDE_STATUS_IDLE && status[3] != 0x0)) |
| 1902 |
{ |
| 1903 |
udelay(30); |
| 1904 |
} |
| 1905 |
else |
| 1906 |
{ |
| 1907 |
break; |
| 1908 |
} |
| 1909 |
} |
| 1910 |
|
| 1911 |
if (i == 1000 * 1000) |
| 1912 |
{ |
| 1913 |
printk("IT8212ResetAdapter Fail!\n"); |
| 1914 |
printk("Device status after reset = [0x%x, 0x%x, 0x%x, 0x%x]\n", |
| 1915 |
status[0], status[1], status[2], status[3]); |
| 1916 |
return FALSE; |
| 1917 |
} |
| 1918 |
else |
| 1919 |
{ |
| 1920 |
printk("IT8212ResetAdapter Success!\n"); |
| 1921 |
return TRUE; |
| 1922 |
} |
| 1923 |
|
| 1924 |
} /* end IT8212ResetAdapter */ |
| 1925 |
|
| 1926 |
/************************************************************************ |
| 1927 |
* Rebuild disk array. |
| 1928 |
************************************************************************/ |
| 1929 |
UCHAR |
| 1930 |
IT8212Rebuild(uioctl_t *pioc) |
| 1931 |
{ |
| 1932 |
|
| 1933 |
UCHAR rebuildDirection; |
| 1934 |
UCHAR statusByte = 0; |
| 1935 |
PRAID_REBUILD_INFO apRebuildInfo = (PRAID_REBUILD_INFO) pioc->data; |
| 1936 |
PITE_ADAPTER pAdap; |
| 1937 |
PChannel pChan; |
| 1938 |
|
| 1939 |
rebuildDirection = (apRebuildInfo->Resume << 4) | (apRebuildInfo->DestDisk << 2) | |
| 1940 |
apRebuildInfo->SrcDisk; |
| 1941 |
|
| 1942 |
apRebuildInfo->Status = 0xFF; |
| 1943 |
|
| 1944 |
pAdap = ite_adapters[pioc->AdapterNo]; |
| 1945 |
if (pioc->DiskNo < 2) |
| 1946 |
{ |
| 1947 |
pChan = &pAdap->IDEChannel[0]; |
| 1948 |
} |
| 1949 |
else |
| 1950 |
{ |
| 1951 |
pChan = &pAdap->IDEChannel[1]; |
| 1952 |
} |
| 1953 |
|
| 1954 |
/* |
| 1955 |
* Selcet device. |
| 1956 |
*/ |
| 1957 |
outb((UCHAR)((apRebuildInfo->DiskArrayId & 0x1) << 4 | 0xA0), |
| 1958 |
pChan->io_ports[IDE_SELECT_OFFSET]); |
| 1959 |
|
| 1960 |
/* |
| 1961 |
* Wait for device ready (not BUSY and not DRQ). |
| 1962 |
*/ |
| 1963 |
WaitForDeviceReady(pChan, statusByte); |
| 1964 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 1965 |
(statusByte == 0)) |
| 1966 |
{ |
| 1967 |
apRebuildInfo->Status = REBUILD_ERR_DISK_BUSY; |
| 1968 |
printk("IT8212Rebuild: Disk[%d] not ready. Status=0x%X\n", |
| 1969 |
apRebuildInfo->DiskArrayId, statusByte); |
| 1970 |
return SRB_STATUS_BUSY; |
| 1971 |
} |
| 1972 |
|
| 1973 |
/* |
| 1974 |
* Disable interrupt to avoid the unexpected interrupt. |
| 1975 |
*/ |
| 1976 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1977 |
|
| 1978 |
/* |
| 1979 |
* Give a direction. |
| 1980 |
*/ |
| 1981 |
outb(rebuildDirection, pChan->io_ports[IDE_FEATURE_OFFSET]); |
| 1982 |
|
| 1983 |
/* |
| 1984 |
* Issue a REBUILD commmand. |
| 1985 |
*/ |
| 1986 |
outb(IDE_COMMAND_REBUILD, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 1987 |
|
| 1988 |
/* |
| 1989 |
* Check for errors. |
| 1990 |
*/ |
| 1991 |
WaitForCommandComplete(pChan, statusByte); |
| 1992 |
|
| 1993 |
/* |
| 1994 |
* Reenable interrupt after command complete. |
| 1995 |
*/ |
| 1996 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 1997 |
|
| 1998 |
if (statusByte != IDE_STATUS_IDLE) |
| 1999 |
{ |
| 2000 |
if (statusByte & IDE_STATUS_ERROR) |
| 2001 |
{ |
| 2002 |
apRebuildInfo->Status = inb(pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 2003 |
printk("IT8212Rebuild:Rebuild error. reason=0x%X\n", apRebuildInfo->Status); |
| 2004 |
} |
| 2005 |
return SRB_STATUS_ERROR; |
| 2006 |
} |
| 2007 |
|
| 2008 |
return SRB_STATUS_SUCCESS; |
| 2009 |
|
| 2010 |
} /* end IT8212Rebuild */ |
| 2011 |
|
| 2012 |
/************************************************************************ |
| 2013 |
* Switch to DMA mode if necessary. |
| 2014 |
* |
| 2015 |
* offset 0x50 = PCI Mode Control Register |
| 2016 |
* |
| 2017 |
* Bit 0 = PCI Mode Select (1=firmware mode, 0=transparent mode) |
| 2018 |
* Bit 1 = Primary Channel IDE Clock Frequency Select (1=50, 0=66) |
| 2019 |
* Bit 2 = Secondary Channel IDE Clock Freq Select (1=50, 0=66) |
| 2020 |
* Bit 3 = Primary Channel Dev 0 Transfer Mode (1=MultiWord DMA, 0=Ultra DMA) |
| 2021 |
* Bit 4 = Primary Channel Dev 1 Transfer Mode (1=MultiWord DMA, 0=Ultra DMA) |
| 2022 |
* Bit 5 = Secondary Channel Dev 0 Transfer Mode (1=MultiWord DMA, 0=Ultra DMA) |
| 2023 |
* Bit 6 = Secondary Channel Dev 1 Transfer Mode (1=MultiWord DMA, 0=Ultra DMA) |
| 2024 |
* Bit 7 = PCI Mode Reset |
| 2025 |
************************************************************************/ |
| 2026 |
VOID |
| 2027 |
IT8212SwitchDmaMode(PChannel pChan, UCHAR DeviceId) |
| 2028 |
{ |
| 2029 |
|
| 2030 |
UCHAR pciControl; |
| 2031 |
UCHAR channel; |
| 2032 |
UCHAR device; |
| 2033 |
UCHAR configByte = 0; |
| 2034 |
UCHAR RevisionID; |
| 2035 |
struct pci_dev * pPciDev = pChan->pPciDev; |
| 2036 |
|
| 2037 |
/* |
| 2038 |
* These tables are for performance issue. Better formance than lots |
| 2039 |
* of "Shifts". |
| 2040 |
*/ |
| 2041 |
UCHAR dmaModeV10[4] = {0x18, 0x18, 0x60, 0x60}; |
| 2042 |
UCHAR udmaModeV10[4] = {0xE7, 0xE7, 0x9F, 0x9F}; |
| 2043 |
UCHAR ideClock[4] = {0xFD, 0xFD, 0xFB, 0xFB}; |
| 2044 |
|
| 2045 |
#if (0) |
| 2046 |
UCHAR dmaMode[4] = {0x08, 0x10, 0x20, 0x40}; |
| 2047 |
UCHAR udmaMode[4] = {0xF7, 0xEF, 0xDF, 0xBF}; |
| 2048 |
#endif |
| 2049 |
|
| 2050 |
/* |
| 2051 |
* channel --> 0-1; device --> 0-1; DeviceId --> 0-3; |
| 2052 |
*/ |
| 2053 |
channel = DeviceId >> 1; |
| 2054 |
device = DeviceId & 1; |
| 2055 |
|
| 2056 |
/* |
| 2057 |
* Do nothing if the mode switch is unnecessary. |
| 2058 |
*/ |
| 2059 |
if (!pChan->DoSwitch || pChan->ActiveDevice == DeviceId) |
| 2060 |
{ |
| 2061 |
dprintk("Do not need to switch mode!\n"); |
| 2062 |
return; |
| 2063 |
} |
| 2064 |
|
| 2065 |
printk("IT8212SwitchDmaMode: Switch DMA mode for dev (%x)\n", |
| 2066 |
DeviceId); |
| 2067 |
|
| 2068 |
pci_read_config_byte(pPciDev, 0x50, &pciControl); |
| 2069 |
pci_read_config_byte(pPciDev, 0x08, &RevisionID); |
| 2070 |
|
| 2071 |
/* |
| 2072 |
* Running on MULTIWORD_DMA mode. |
| 2073 |
*/ |
| 2074 |
if (pChan->DmaType[device] == USE_MULTIWORD_DMA) |
| 2075 |
{ |
| 2076 |
/* |
| 2077 |
* Switch to DMA mode. |
| 2078 |
*/ |
| 2079 |
if (RevisionID == 0x10) |
| 2080 |
{ |
| 2081 |
configByte = pciControl | dmaModeV10[DeviceId]; |
| 2082 |
} |
| 2083 |
pci_write_config_byte(pPciDev, 0x50, configByte); |
| 2084 |
} |
| 2085 |
/* |
| 2086 |
* Running on ULTRA DMA mode. |
| 2087 |
*/ |
| 2088 |
else |
| 2089 |
{ |
| 2090 |
/* |
| 2091 |
* Select UDMA mode. |
| 2092 |
*/ |
| 2093 |
configByte = pciControl; |
| 2094 |
if (RevisionID == 0x10) |
| 2095 |
{ |
| 2096 |
configByte &= udmaModeV10[DeviceId]; |
| 2097 |
} |
| 2098 |
|
| 2099 |
/* |
| 2100 |
* Select IDE clock. |
| 2101 |
*/ |
| 2102 |
configByte = (configByte & ideClock[DeviceId]) | |
| 2103 |
(pChan->IdeClock[device] << (channel + 1)); |
| 2104 |
|
| 2105 |
pci_write_config_byte(pPciDev, 0x50, configByte); |
| 2106 |
|
| 2107 |
/* |
| 2108 |
* Set UDMA timing. |
| 2109 |
* |
| 2110 |
* offset 0x56 = PCI Mode Primary Device 0 Ultra DMA Timing Registers |
| 2111 |
* offset 0x57 = PCI Mode Primary Device 1 Ultra DMA Timing Registers |
| 2112 |
* offset 0x5A = PCI Mode Secondary Device 0 Ultra DMA Timing Registers |
| 2113 |
* offset 0x5B = PCI Mode Secondary Device 1 Ultra DMA Timing Registers |
| 2114 |
*/ |
| 2115 |
if (RevisionID == 0x10) |
| 2116 |
{ |
| 2117 |
configByte = pChan->UdmaTiming[device]; |
| 2118 |
pci_write_config_byte(pPciDev, (UCHAR) (0x56 + (channel * 4)), configByte); |
| 2119 |
pci_write_config_byte(pPciDev, (UCHAR) (0x56 + (channel * 4) + 1), configByte); |
| 2120 |
} |
| 2121 |
|
| 2122 |
/* |
| 2123 |
* Set PIO/DMA timing (Becasuse maybe the IDE clock is changed.) |
| 2124 |
*/ |
| 2125 |
configByte = pChan->PioDmaTiming[pChan->IdeClock[device]]; |
| 2126 |
pci_write_config_byte(pPciDev, (UCHAR) (0x54 + (channel * 4)), configByte); |
| 2127 |
} |
| 2128 |
|
| 2129 |
/* |
| 2130 |
* Record the Active device on this channel |
| 2131 |
*/ |
| 2132 |
pChan->ActiveDevice = device; |
| 2133 |
|
| 2134 |
} /* end IT8212SwitchDmaMode */ |
| 2135 |
|
| 2136 |
/************************************************************************ |
| 2137 |
* IT8212 read/write routines |
| 2138 |
************************************************************************/ |
| 2139 |
ULONG |
| 2140 |
IT8212ReadWrite(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 2141 |
{ |
| 2142 |
|
| 2143 |
UCHAR statusByte = 0; |
| 2144 |
ULONG startingSector; |
| 2145 |
ULONG sectorNumber; |
| 2146 |
ULONG capacity; |
| 2147 |
PITE_ADAPTER pAdap = ite_adapters[0]; |
| 2148 |
|
| 2149 |
/* |
| 2150 |
* Return error if overrun. |
| 2151 |
*/ |
| 2152 |
startingSector = ((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte3 | |
| 2153 |
((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte2 << 8 | |
| 2154 |
((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte1 << 16 | |
| 2155 |
((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte0 << 24; |
| 2156 |
|
| 2157 |
sectorNumber = (USHORT) ((Srb->DataTransferLength + 0x1FF) / 0x200); |
| 2158 |
|
| 2159 |
capacity = pChan->IdentifyData[Srb->TargetId & 0x1].UserAddressableSectors; |
| 2160 |
if (capacity == 0x0FFFFFFF) |
| 2161 |
{ |
| 2162 |
capacity = pChan->IdentifyData[Srb->TargetId].Capacity_48bit_LOW; |
| 2163 |
} |
| 2164 |
|
| 2165 |
if ((startingSector + sectorNumber - 1) > capacity) |
| 2166 |
{ |
| 2167 |
printk("IT8212ReadWrite: Disk[%d] over disk size.\n", Srb->TargetId); |
| 2168 |
printk("Capacity: %ld. Starting sector: %ld. Sector number: %ld\n", |
| 2169 |
capacity, startingSector, sectorNumber); |
| 2170 |
return SRB_STATUS_ERROR; |
| 2171 |
} |
| 2172 |
|
| 2173 |
/* |
| 2174 |
* Select device. |
| 2175 |
*/ |
| 2176 |
outb((UCHAR)((Srb->TargetId & 0x1) << 4 | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 2177 |
|
| 2178 |
/* |
| 2179 |
* Wait for device ready (Not Busy and Not DRQ). |
| 2180 |
*/ |
| 2181 |
WaitForDeviceReady(pChan, statusByte); |
| 2182 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 2183 |
(statusByte == 0)) |
| 2184 |
{ |
| 2185 |
printk("IT8212ReadWrite: Disk[%d] not ready. Status=0x%x\n", |
| 2186 |
Srb->TargetId, statusByte); |
| 2187 |
return SRB_STATUS_BUSY; |
| 2188 |
} |
| 2189 |
|
| 2190 |
/* |
| 2191 |
* First, switch to DMA or UDMA mode if running on bypass mode. |
| 2192 |
*/ |
| 2193 |
if (pAdap->bypass_mode) |
| 2194 |
{ |
| 2195 |
IT8212SwitchDmaMode(pChan, Srb->TargetId); |
| 2196 |
} |
| 2197 |
|
| 2198 |
/* |
| 2199 |
* Check the SCATTER/GATHER count. The upper will give the different |
| 2200 |
* memory address depend on whether use_sg is used or not. |
| 2201 |
*/ |
| 2202 |
if (Srb->UseSg == 0) |
| 2203 |
{ |
| 2204 |
IdeBuildDmaTable(pChan, Srb); |
| 2205 |
} |
| 2206 |
else |
| 2207 |
{ |
| 2208 |
IdeBuildDmaSgTable(pChan, Srb); |
| 2209 |
} |
| 2210 |
|
| 2211 |
/* |
| 2212 |
* Start transfer the data. |
| 2213 |
*/ |
| 2214 |
IdeStartTransfer(pChan, Srb, startingSector, sectorNumber); |
| 2215 |
|
| 2216 |
/* |
| 2217 |
* Wait for interrupt. |
| 2218 |
*/ |
| 2219 |
return SRB_STATUS_PENDING; |
| 2220 |
|
| 2221 |
} /* end IT8212ReadWrite */ |
| 2222 |
|
| 2223 |
/************************************************************************ |
| 2224 |
* Setup the transfer mode. |
| 2225 |
************************************************************************/ |
| 2226 |
VOID |
| 2227 |
IT8212SetTransferMode |
| 2228 |
( |
| 2229 |
PChannel pChan, |
| 2230 |
ULONG DiskId, |
| 2231 |
UCHAR TransferMode, |
| 2232 |
UCHAR ModeNumber |
| 2233 |
) |
| 2234 |
{ |
| 2235 |
|
| 2236 |
UCHAR statusByte = 0; |
| 2237 |
|
| 2238 |
/* |
| 2239 |
* Select device. |
| 2240 |
*/ |
| 2241 |
outb((UCHAR) ((DiskId & 0x1) << 4 | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 2242 |
|
| 2243 |
/* |
| 2244 |
* Wait for device ready (Not Busy and Not DRQ). |
| 2245 |
*/ |
| 2246 |
WaitForDeviceReady(pChan, statusByte); |
| 2247 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ)) |
| 2248 |
{ |
| 2249 |
printk("IT8212SetTransferMode: Disk[%ld] not ready. Status=0x%x\n", |
| 2250 |
DiskId, statusByte); |
| 2251 |
return; |
| 2252 |
} |
| 2253 |
|
| 2254 |
/* |
| 2255 |
* Feature number ==> 03 |
| 2256 |
* |
| 2257 |
* Mode contained in Sector Count Register. |
| 2258 |
* |
| 2259 |
* Bits(7:3) Bits(2:0) Mode |
| 2260 |
* |
| 2261 |
* 00000 000 PIO default mode |
| 2262 |
* 00000 001 PIO default mode, disable IORDY |
| 2263 |
* 00001 mode PIO flow control transfer mode |
| 2264 |
* 00010 mode Single Word DMA mode |
| 2265 |
* 00100 mode Multi-word DMA mode |
| 2266 |
* 01000 mode Ultra DMA mode |
| 2267 |
*/ |
| 2268 |
TransferMode |= ModeNumber; |
| 2269 |
|
| 2270 |
outb(0x03, pChan->io_ports[IDE_FEATURE_OFFSET]); |
| 2271 |
outb(TransferMode, pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 2272 |
outb(0, pChan->io_ports[IDE_HCYL_OFFSET]); |
| 2273 |
outb(0, pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 2274 |
outb(IDE_COMMAND_SET_FEATURE, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 2275 |
|
| 2276 |
/* |
| 2277 |
* Check error. |
| 2278 |
*/ |
| 2279 |
WaitForBaseCommandComplete(pChan, statusByte); |
| 2280 |
|
| 2281 |
if ((statusByte != IDE_STATUS_IDLE) && (statusByte != 0)) |
| 2282 |
{ |
| 2283 |
printk("IT8212SetTransferMode: Disk[%ld]", DiskId); |
| 2284 |
printk("return unexpected status after issue command. 0x%x\n", |
| 2285 |
statusByte); |
| 2286 |
} |
| 2287 |
|
| 2288 |
} /* end IT8212SetTransferMode */ |
| 2289 |
|
| 2290 |
/************************************************************************ |
| 2291 |
* Set the best transfer mode for device |
| 2292 |
************************************************************************/ |
| 2293 |
VOID |
| 2294 |
IT8212SetBestTransferMode(PITE_ADAPTER pAdap, PChannel pChan, UCHAR channel) |
| 2295 |
{ |
| 2296 |
|
| 2297 |
UCHAR i; |
| 2298 |
UCHAR k; |
| 2299 |
UCHAR transferMode; |
| 2300 |
UCHAR modeNumber; |
| 2301 |
UCHAR pciControl; |
| 2302 |
UCHAR device; |
| 2303 |
UCHAR configByte; |
| 2304 |
UCHAR cableStatus[2] = {CABLE_40_PIN, CABLE_40_PIN}; |
| 2305 |
UCHAR RevisionID; |
| 2306 |
struct pci_dev * pPciDev = pChan->pPciDev; |
| 2307 |
PIDENTIFY_DATA2 ideIdentifyData; |
| 2308 |
|
| 2309 |
/* |
| 2310 |
* UDMA timing table for 66MHz clock. |
| 2311 |
* UDMA timing table for 50MHz clock. |
| 2312 |
* Best of IDE clock in this mode. |
| 2313 |
*/ |
| 2314 |
UCHAR udmaTiming[3][7] = |
| 2315 |
{ |
| 2316 |
{0x44, 0x42, 0x31, 0x21, 0x11, 0x22, 0x11}, |
| 2317 |
{0x33, 0x31, 0x21, 0x21, 0x11, 0x11, 0x11}, |
| 2318 |
{IDE_CLOCK_66, IDE_CLOCK_50, IDE_CLOCK_66, IDE_CLOCK_66, IDE_CLOCK_66, IDE_CLOCK_50, IDE_CLOCK_66} |
| 2319 |
}; |
| 2320 |
|
| 2321 |
/* |
| 2322 |
* DMA timing table for 66 MHz clock. |
| 2323 |
* DMA timing table for 50 MHz clock. |
| 2324 |
*/ |
| 2325 |
UCHAR dmaTiming[2][3] = |
| 2326 |
{ |
| 2327 |
{0x88, 0x32, 0x31}, |
| 2328 |
{0x66, 0x22, 0x21} |
| 2329 |
}; |
| 2330 |
|
| 2331 |
/* |
| 2332 |
* PIO timing table for 66 MHz clock. |
| 2333 |
* PIO timing table for 50 MHz clock. |
| 2334 |
*/ |
| 2335 |
UCHAR pioTiming[2][5] = |
| 2336 |
{ |
| 2337 |
{0xAA, 0xA3, 0xA1, 0x33, 0x31}, |
| 2338 |
{0x88, 0x82, 0x81, 0x32, 0x21} |
| 2339 |
}; |
| 2340 |
|
| 2341 |
UCHAR pio_dma_timing[2][2][4] = |
| 2342 |
{ |
| 2343 |
{{0, 0, 0, 0}, {0, 0, 0, 0}}, |
| 2344 |
{{0, 0, 0, 0}, {0, 0, 0, 0}} |
| 2345 |
}; |
| 2346 |
|
| 2347 |
/* |
| 2348 |
* These tables are for performance issue. Better formance than lots |
| 2349 |
* of "Shifts". |
| 2350 |
*/ |
| 2351 |
//UCHAR dmaModeV10[4] = {0x18, 0x18, 0x60, 0x60}; |
| 2352 |
UCHAR udmaModeV10[4] = {0xE7, 0xE7, 0x9F, 0x9F}; |
| 2353 |
UCHAR dmaMode[4] = {0x08, 0x10, 0x20, 0x40}; |
| 2354 |
UCHAR udmaMode[4] = {0xF7, 0xEF, 0xDF, 0xBF}; |
| 2355 |
UCHAR ideClock[4] = {0xFD, 0xFD, 0xFB, 0xFB}; |
| 2356 |
|
| 2357 |
for (i = 0; i < 2; i++) |
| 2358 |
{ |
| 2359 |
/* |
| 2360 |
* The dafault of cable status is in PCI configuration 0x40. |
| 2361 |
*/ |
| 2362 |
cableStatus[i] = pChan->Cable80[i]; |
| 2363 |
|
| 2364 |
/* |
| 2365 |
* channel -->0 to 1. |
| 2366 |
* device -->0 or 1. |
| 2367 |
*/ |
| 2368 |
pChan->UseDma[i] = TRUE; |
| 2369 |
device = i & 1; |
| 2370 |
|
| 2371 |
if (!(pChan->DeviceFlags[i] & DFLAGS_DEVICE_PRESENT) || |
| 2372 |
(pChan->DeviceFlags[i] & DFLAGS_CONFIG_CHANGED)) |
| 2373 |
{ |
| 2374 |
pio_dma_timing[0][channel][device] = pio_dma_timing[0][channel][device + 2] = 0; |
| 2375 |
pio_dma_timing[1][channel][device] = pio_dma_timing[1][channel][device + 2] = 0; |
| 2376 |
continue; |
| 2377 |
} |
| 2378 |
|
| 2379 |
/* |
| 2380 |
* Set PIO Mode. |
| 2381 |
*/ |
| 2382 |
ideIdentifyData = &pChan->IdentifyData[i]; |
| 2383 |
if ((!(ideIdentifyData->ValidFieldIndicator & 0x02)) || (ideIdentifyData->AdvancedPIOModes == 0)) |
| 2384 |
{ |
| 2385 |
transferMode = PIO_FLOW_CONTROL; |
| 2386 |
modeNumber = 2; |
| 2387 |
} |
| 2388 |
else |
| 2389 |
{ |
| 2390 |
transferMode = PIO_FLOW_CONTROL; |
| 2391 |
modeNumber = RaidGetHighestBit((UCHAR) ideIdentifyData->AdvancedPIOModes) + 3; |
| 2392 |
} |
| 2393 |
|
| 2394 |
IT8212SetTransferMode(pChan, i, transferMode, modeNumber); |
| 2395 |
|
| 2396 |
/* |
| 2397 |
* Record the PIO timing for later use.(0 to 4) |
| 2398 |
*/ |
| 2399 |
pio_dma_timing[0][channel][device] = pioTiming[0][modeNumber]; |
| 2400 |
pio_dma_timing[1][channel][device] = pioTiming[1][modeNumber]; |
| 2401 |
|
| 2402 |
/* |
| 2403 |
* Get the best transfer mode (maybe Ultra DMA or Multi-Word DMA). |
| 2404 |
*/ |
| 2405 |
ideIdentifyData = &pChan->IdentifyData[i]; |
| 2406 |
if ((!(ideIdentifyData->ValidFieldIndicator & 0x04)) || (ideIdentifyData->UltraDMASupport == 0)) |
| 2407 |
{ |
| 2408 |
/* |
| 2409 |
* UltraDMA is not valid. |
| 2410 |
*/ |
| 2411 |
transferMode = MULTIWORD_DMA; |
| 2412 |
modeNumber = RaidGetHighestBit(ideIdentifyData->MultiWordDMASupport); |
| 2413 |
printk("The best transfer mode of Device[%d] is DMA-%d\n", i, modeNumber); |
| 2414 |
} |
| 2415 |
else |
| 2416 |
{ |
| 2417 |
transferMode = ULTRA_DMA; |
| 2418 |
modeNumber = RaidGetHighestBit(ideIdentifyData->UltraDMASupport); |
| 2419 |
printk("The best transfer mode of Device[%d] is Ultra-%d\n", i, modeNumber); |
| 2420 |
|
| 2421 |
/* |
| 2422 |
* If this is 40-pin cable. Limit to Ultra DMA mode 2. |
| 2423 |
*/ |
| 2424 |
# if (0) |
| 2425 |
if ((cableStatus[i] == CABLE_40_PIN) && (modeNumber > 2)) |
| 2426 |
{ |
| 2427 |
printk("Reduce trans mode of Device[%d] to Ultra-2 for cable issue.\n", i); |
| 2428 |
modeNumber = 0x02; |
| 2429 |
} |
| 2430 |
# endif |
| 2431 |
} |
| 2432 |
|
| 2433 |
IT8212SetTransferMode(pChan, i, transferMode, modeNumber); |
| 2434 |
|
| 2435 |
/* |
| 2436 |
* If running on ByPass mode, driver must take the responsibility to |
| 2437 |
* set the PIO/DMA/UDMA timing. |
| 2438 |
*/ |
| 2439 |
if (pAdap->bypass_mode) |
| 2440 |
{ |
| 2441 |
pci_read_config_byte(pPciDev, 0x50, &pciControl); |
| 2442 |
pci_read_config_byte(pPciDev, 0x08, &RevisionID); |
| 2443 |
|
| 2444 |
if (transferMode == ULTRA_DMA) |
| 2445 |
{ |
| 2446 |
/* |
| 2447 |
* Set this channel to UDMA mode (not only the device). |
| 2448 |
*/ |
| 2449 |
if (RevisionID == 0x10) |
| 2450 |
{ |
| 2451 |
configByte = pciControl & udmaModeV10[i + channel * 2]; |
| 2452 |
} |
| 2453 |
else |
| 2454 |
{ |
| 2455 |
configByte = pciControl & udmaMode[i + channel * 2]; |
| 2456 |
} |
| 2457 |
|
| 2458 |
/* |
| 2459 |
* Select IDE clock (50MHz or 66MHz). |
| 2460 |
*/ |
| 2461 |
configByte &= ideClock[i + channel * 2]; |
| 2462 |
configByte |= (udmaTiming[2][modeNumber] << (channel + 1)); |
| 2463 |
|
| 2464 |
pci_write_config_byte(pPciDev, 0x50, configByte); |
| 2465 |
|
| 2466 |
/* |
| 2467 |
* Set UDMA timing. |
| 2468 |
*/ |
| 2469 |
configByte = udmaTiming[udmaTiming[2][modeNumber]][modeNumber]; |
| 2470 |
if (modeNumber == 5 || modeNumber == 6) |
| 2471 |
{ |
| 2472 |
/* |
| 2473 |
* Enable UDMA mode 5/6 |
| 2474 |
*/ |
| 2475 |
configByte |= UDMA_MODE_5_6; |
| 2476 |
} |
| 2477 |
|
| 2478 |
/* |
| 2479 |
* Bug Bug. Fill these two fields into the same value. |
| 2480 |
*/ |
| 2481 |
if (RevisionID == 0x10) |
| 2482 |
{ |
| 2483 |
pci_write_config_byte(pPciDev, (UCHAR) (0x56 + (channel * 4)), configByte); |
| 2484 |
pci_write_config_byte(pPciDev, (UCHAR) (0x56 + (channel * 4) + 1), configByte); |
| 2485 |
} |
| 2486 |
else |
| 2487 |
{ |
| 2488 |
pci_write_config_byte(pPciDev, (UCHAR) (0x56 + (channel * 4) + device), configByte); |
| 2489 |
} |
| 2490 |
|
| 2491 |
/* |
| 2492 |
* Record the best UDMA mode for this device. |
| 2493 |
*/ |
| 2494 |
pChan->DmaType[i] = ULTRA_DMA; |
| 2495 |
pChan->IdeClock[i] = udmaTiming[2][modeNumber]; |
| 2496 |
pChan->UdmaTiming[i] = configByte; |
| 2497 |
} |
| 2498 |
else if (transferMode == MULTIWORD_DMA) |
| 2499 |
{ |
| 2500 |
/* |
| 2501 |
* If an ATAPI device with DMA mode, force it to run in PIO mode. |
| 2502 |
*/ |
| 2503 |
if (RevisionID == 0x10 && pChan->DeviceFlags[i] & DFLAGS_ATAPI_DEVICE) |
| 2504 |
{ |
| 2505 |
pChan->UseDma[i] = FALSE; |
| 2506 |
} |
| 2507 |
else |
| 2508 |
{ |
| 2509 |
/* |
| 2510 |
* Set this device to DMA mode. |
| 2511 |
*/ |
| 2512 |
configByte = pciControl | dmaMode[i + channel * 2]; |
| 2513 |
pci_write_config_byte(pPciDev, 0x50, configByte); |
| 2514 |
|
| 2515 |
/* |
| 2516 |
* Record DMA timing (for later use). |
| 2517 |
*/ |
| 2518 |
pio_dma_timing[0][channel][device + 2] = dmaTiming[0][modeNumber]; |
| 2519 |
pio_dma_timing[1][channel][device + 2] = dmaTiming[1][modeNumber]; |
| 2520 |
} |
| 2521 |
pChan->DmaType[i] = USE_MULTIWORD_DMA; |
| 2522 |
} |
| 2523 |
pChan->ActiveDevice = device; |
| 2524 |
} |
| 2525 |
} |
| 2526 |
|
| 2527 |
/* |
| 2528 |
* Because each channel owns one PIO/DMA timimg register only, so we |
| 2529 |
* must set the timing to the slowest one to fit all. Really stupid H/W! :( |
| 2530 |
*/ |
| 2531 |
if (pAdap->bypass_mode) |
| 2532 |
{ |
| 2533 |
/* |
| 2534 |
* Loop for the two IDE clocks (50 MHz and 66 MHz). |
| 2535 |
*/ |
| 2536 |
for (i = 0; i < 2; i++) |
| 2537 |
{ |
| 2538 |
configByte = 0; |
| 2539 |
for (k = 0; k < 4; k++) |
| 2540 |
{ |
| 2541 |
/* |
| 2542 |
* High part. |
| 2543 |
*/ |
| 2544 |
if ((pio_dma_timing[i][channel][k] & 0xF0) > (configByte & 0xF0)) |
| 2545 |
{ |
| 2546 |
configByte = (configByte & 0xF) | (pio_dma_timing[i][channel][k] & 0xF0); |
| 2547 |
} |
| 2548 |
|
| 2549 |
/* |
| 2550 |
* Low part. |
| 2551 |
*/ |
| 2552 |
if ((pio_dma_timing[i][channel][k] & 0xF) > (configByte & 0xF)) |
| 2553 |
{ |
| 2554 |
configByte = (configByte & 0xF0) | (pio_dma_timing[i][channel][k] & 0xF); |
| 2555 |
} |
| 2556 |
} |
| 2557 |
|
| 2558 |
/* |
| 2559 |
* Record the PIO/DMA timing for this channel. |
| 2560 |
*/ |
| 2561 |
pChan->PioDmaTiming[i] = configByte; |
| 2562 |
} |
| 2563 |
|
| 2564 |
/* |
| 2565 |
* Set PIO/DMA timing register for each channel. |
| 2566 |
*/ |
| 2567 |
configByte = pChan->PioDmaTiming[(pciControl >> (channel + 1)) & 1]; |
| 2568 |
if (configByte != 0) |
| 2569 |
{ |
| 2570 |
pci_write_config_byte(pPciDev, (UCHAR) (0x54 + (channel * 4)), configByte); |
| 2571 |
} |
| 2572 |
|
| 2573 |
/* |
| 2574 |
* Check shall we do switch between the two devices |
| 2575 |
*/ |
| 2576 |
for (i = 0; i < 2; i++) |
| 2577 |
{ |
| 2578 |
pChan->DoSwitch = TRUE; |
| 2579 |
|
| 2580 |
/* |
| 2581 |
* Master is not present |
| 2582 |
*/ |
| 2583 |
if (!(pChan->DeviceFlags[i] & DFLAGS_DEVICE_PRESENT) || (pChan->DeviceFlags[i] & DFLAGS_CONFIG_CHANGED)) |
| 2584 |
{ |
| 2585 |
printk("Channel %x: Master is not present. No switch mode.\n", channel); |
| 2586 |
pChan->DoSwitch = FALSE; |
| 2587 |
continue; |
| 2588 |
} |
| 2589 |
|
| 2590 |
/* |
| 2591 |
* Slave is not present |
| 2592 |
*/ |
| 2593 |
if (!(pChan->DeviceFlags[i + 1] & DFLAGS_DEVICE_PRESENT) || (pChan->DeviceFlags[i + 1] & DFLAGS_CONFIG_CHANGED)) |
| 2594 |
{ |
| 2595 |
printk("Channel %x: Slave is not present. No switch mode.\n", channel); |
| 2596 |
pChan->DoSwitch = FALSE; |
| 2597 |
continue; |
| 2598 |
} |
| 2599 |
|
| 2600 |
/* |
| 2601 |
* If both devices are running on DMA mode, no switch. |
| 2602 |
*/ |
| 2603 |
if (pChan->DmaType[i] == USE_MULTIWORD_DMA && pChan->DmaType[i + 1] == USE_MULTIWORD_DMA) |
| 2604 |
{ |
| 2605 |
printk("Channel %x: Run on DMA mode only. No switch mode.\n", channel); |
| 2606 |
pChan->DoSwitch = FALSE; |
| 2607 |
continue; |
| 2608 |
} |
| 2609 |
|
| 2610 |
/* |
| 2611 |
* No switch if the two devices are running on the same mode. |
| 2612 |
*/ |
| 2613 |
if ((pChan->DmaType[i] == pChan->DmaType[i + 1] ) && |
| 2614 |
(pChan->UdmaTiming[i] == pChan->UdmaTiming[i + 1]) && |
| 2615 |
(pChan->IdeClock[i] == pChan->IdeClock[i + 1] )) |
| 2616 |
{ |
| 2617 |
printk("Channel %x: Two dev run on the same mode. No switch mode.\n", channel); |
| 2618 |
pChan->DoSwitch = FALSE; |
| 2619 |
continue; |
| 2620 |
} |
| 2621 |
|
| 2622 |
printk("Channel %x: Switch mode if needed.\n", channel); |
| 2623 |
} |
| 2624 |
} |
| 2625 |
|
| 2626 |
} /* end IT8212SetBestTransferMode */ |
| 2627 |
|
| 2628 |
/************************************************************************ |
| 2629 |
* Initialize bypass(transparent) mode if BIOS is not ready |
| 2630 |
************************************************************************/ |
| 2631 |
BOOLEAN |
| 2632 |
IT8212InitBypassMode(struct pci_dev *pPciDev) |
| 2633 |
{ |
| 2634 |
|
| 2635 |
USHORT configWord = 0; |
| 2636 |
|
| 2637 |
/* |
| 2638 |
* 1.2. Reset local CPU, and set BIOS not ready. |
| 2639 |
*/ |
| 2640 |
pci_write_config_byte(pPciDev, 0x5E, 0x01); |
| 2641 |
|
| 2642 |
/* |
| 2643 |
* 3.4. Set to bypass mode, and reset PCI bus. |
| 2644 |
*/ |
| 2645 |
pci_write_config_byte(pPciDev, 0x50, 0x80); |
| 2646 |
pci_write_config_byte(pPciDev, 0x50, 0x00); |
| 2647 |
|
| 2648 |
/* |
| 2649 |
* 5. Set PIO timing register of primary register. |
| 2650 |
*/ |
| 2651 |
pci_write_config_byte(pPciDev, 0x54, 0xA3); |
| 2652 |
|
| 2653 |
/* |
| 2654 |
* 6. Set PIO timing register of secondary register. |
| 2655 |
*/ |
| 2656 |
pci_write_config_byte(pPciDev, 0x58, 0xA3); |
| 2657 |
|
| 2658 |
/* |
| 2659 |
* Testing. |
| 2660 |
*/ |
| 2661 |
pci_write_config_word(pPciDev, 0x4, 0x7); |
| 2662 |
|
| 2663 |
pci_read_config_word(pPciDev, 0x50, &configWord); |
| 2664 |
configWord = configWord | 0xA000; |
| 2665 |
pci_write_config_word(pPciDev, 0x40, configWord); |
| 2666 |
|
| 2667 |
pci_write_config_byte(pPciDev, 0x0D, 0x00); |
| 2668 |
pci_write_config_dword(pPciDev,0x4C, 0x02040204); |
| 2669 |
pci_write_config_byte(pPciDev, 0x42, 0x36); |
| 2670 |
|
| 2671 |
return TRUE; |
| 2672 |
|
| 2673 |
} /* end IT8212InitBypassMode */ |
| 2674 |
|
| 2675 |
/************************************************************************ |
| 2676 |
* This is the interrupt service routine for ATAPI IDE miniport driver. |
| 2677 |
* TURE if expecting an interrupt. |
| 2678 |
************************************************************************/ |
| 2679 |
BOOLEAN |
| 2680 |
IT8212Interrupt(PChannel pChan) |
| 2681 |
{ |
| 2682 |
|
| 2683 |
UCHAR statusByte = 0; |
| 2684 |
UCHAR bmstatus = 0; |
| 2685 |
ULONG i = 0; |
| 2686 |
ULONG bmbase = pChan->dma_base; |
| 2687 |
PSCSI_REQUEST_BLOCK Srb = pChan->CurrentSrb; |
| 2688 |
PITE_ADAPTER pAdap = ite_adapters[0]; |
| 2689 |
|
| 2690 |
if (!Srb || !pChan->ExpectingInterrupt) |
| 2691 |
{ |
| 2692 |
dprintk("!Suspicious Interrupt\n"); |
| 2693 |
|
| 2694 |
/* |
| 2695 |
* Clear interrupt by reading status register. |
| 2696 |
*/ |
| 2697 |
outb((UCHAR) 0xA0, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 2698 |
GetBaseStatus(pChan, statusByte); |
| 2699 |
outb((UCHAR) 0xB0, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 2700 |
GetBaseStatus(pChan, statusByte); |
| 2701 |
outb(bmbase + 2, (UCHAR) (inb(bmbase + 2) | BM_STAT_FLG_INT)); |
| 2702 |
|
| 2703 |
return FALSE; |
| 2704 |
} |
| 2705 |
|
| 2706 |
/* |
| 2707 |
* To handle share IRQ condition. |
| 2708 |
* If the interrupt is not ours, return FALSE. |
| 2709 |
*/ |
| 2710 |
bmstatus = inb(bmbase + 2); |
| 2711 |
if ((bmstatus & BM_STAT_FLG_INT) == 0) |
| 2712 |
{ |
| 2713 |
printk("IT8212Interrupt: Spurious interrupt (Interrupt bit is not on)\n"); |
| 2714 |
return FALSE; |
| 2715 |
} |
| 2716 |
|
| 2717 |
/* |
| 2718 |
* Bug Fix: All PIO access are blocked during bus master operation, so |
| 2719 |
* stop bus master operation before we try to access IDE registers. |
| 2720 |
*/ |
| 2721 |
if (pAdap->bypass_mode) |
| 2722 |
{ |
| 2723 |
outb(bmbase, 0); |
| 2724 |
} |
| 2725 |
|
| 2726 |
/* |
| 2727 |
* Clear interrupt by reading status. |
| 2728 |
*/ |
| 2729 |
GetBaseStatus(pChan, statusByte); |
| 2730 |
outb(bmbase + 2, (UCHAR) (bmstatus | BM_STAT_FLG_INT)); |
| 2731 |
|
| 2732 |
/* |
| 2733 |
* Handle ATAPI interrupt. |
| 2734 |
*/ |
| 2735 |
if (pChan->DeviceFlags[Srb->TargetId & 1] & DFLAGS_ATAPI_DEVICE) |
| 2736 |
{ |
| 2737 |
return AtapiInterrupt(pChan); |
| 2738 |
} |
| 2739 |
|
| 2740 |
pChan->ExpectingInterrupt = FALSE; |
| 2741 |
|
| 2742 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ)) |
| 2743 |
{ |
| 2744 |
/* |
| 2745 |
* Ensure BUSY and DRQ is non-asserted. |
| 2746 |
*/ |
| 2747 |
for (i = 0; i < 100; i++) |
| 2748 |
{ |
| 2749 |
GetBaseStatus(pChan, statusByte); |
| 2750 |
if (!(statusByte & IDE_STATUS_BUSY) && !(statusByte & IDE_STATUS_DRQ)) |
| 2751 |
{ |
| 2752 |
break; |
| 2753 |
} |
| 2754 |
mdelay(5); |
| 2755 |
} |
| 2756 |
|
| 2757 |
if (i == 100) |
| 2758 |
{ |
| 2759 |
printk("IT8212Interrupt: Disk[%x] return busy or drq status. Status = 0x%x\n", |
| 2760 |
Srb->TargetId, statusByte); |
| 2761 |
return FALSE; |
| 2762 |
} |
| 2763 |
} |
| 2764 |
|
| 2765 |
if (statusByte & IDE_STATUS_ERROR) |
| 2766 |
{ |
| 2767 |
/* |
| 2768 |
* Stop bus master operation. |
| 2769 |
*/ |
| 2770 |
outb(bmbase, 0); |
| 2771 |
|
| 2772 |
printk("IT8212Interrupt: ERROR!\n"); |
| 2773 |
|
| 2774 |
/* |
| 2775 |
* Map error to specific SRB status and handle request sense. |
| 2776 |
*/ |
| 2777 |
Srb->SrbStatus = MapError(pChan, Srb); |
| 2778 |
} |
| 2779 |
else |
| 2780 |
{ |
| 2781 |
Srb->SrbStatus = SRB_STATUS_SUCCESS; |
| 2782 |
} |
| 2783 |
|
| 2784 |
pChan->CurrentSrb = NULL; |
| 2785 |
|
| 2786 |
TaskDone(pChan, Srb); |
| 2787 |
|
| 2788 |
return TRUE; |
| 2789 |
|
| 2790 |
} /* end IT8212Interrupt */ |
| 2791 |
|
| 2792 |
/************************************************************************ |
| 2793 |
* This is the interrupt service routine for ATAPI IDE miniport driver. |
| 2794 |
* TRUE if expecting an interrupt. Remember the ATAPI io registers are |
| 2795 |
* different from IDE io registers and this is for each channel not for |
| 2796 |
* entire controller. |
| 2797 |
************************************************************************/ |
| 2798 |
BOOLEAN |
| 2799 |
AtapiInterrupt(PChannel pChan) |
| 2800 |
{ |
| 2801 |
|
| 2802 |
ULONG wordCount = 0; |
| 2803 |
ULONG wordsThisInterrupt = 256; |
| 2804 |
ULONG status; |
| 2805 |
ULONG i; |
| 2806 |
UCHAR statusByte; |
| 2807 |
UCHAR interruptReason; |
| 2808 |
PSCSI_REQUEST_BLOCK srb = pChan->CurrentSrb; |
| 2809 |
|
| 2810 |
/* |
| 2811 |
* Clear interrupt by reading status. |
| 2812 |
*/ |
| 2813 |
GetBaseStatus(pChan, statusByte); |
| 2814 |
|
| 2815 |
dprintk("AtapiInterrupt: Entered with status (%x)\n", statusByte); |
| 2816 |
|
| 2817 |
if (statusByte & IDE_STATUS_BUSY) |
| 2818 |
{ |
| 2819 |
/* |
| 2820 |
* Ensure BUSY is non-asserted. |
| 2821 |
*/ |
| 2822 |
for (i = 0; i < 10; i++) |
| 2823 |
{ |
| 2824 |
GetBaseStatus(pChan, statusByte); |
| 2825 |
if (!(statusByte & IDE_STATUS_BUSY)) |
| 2826 |
{ |
| 2827 |
break; |
| 2828 |
} |
| 2829 |
mdelay(5); |
| 2830 |
} |
| 2831 |
|
| 2832 |
if (i == 10) |
| 2833 |
{ |
| 2834 |
printk("AtapiInterrupt: BUSY on entry. Status %x\n", statusByte); |
| 2835 |
return FALSE; |
| 2836 |
} |
| 2837 |
} |
| 2838 |
|
| 2839 |
/* |
| 2840 |
* Check for error conditions. |
| 2841 |
*/ |
| 2842 |
if (statusByte & IDE_STATUS_ERROR) |
| 2843 |
{ |
| 2844 |
if (srb->Cdb[0] != SCSIOP_REQUEST_SENSE) |
| 2845 |
{ |
| 2846 |
/* |
| 2847 |
* Fail this request. |
| 2848 |
*/ |
| 2849 |
status = SRB_STATUS_ERROR; |
| 2850 |
goto CompleteRequest; |
| 2851 |
} |
| 2852 |
} |
| 2853 |
|
| 2854 |
/* |
| 2855 |
* Check reason for this interrupt. |
| 2856 |
*/ |
| 2857 |
interruptReason = (inb(pChan->io_ports[ATAPI_INTREASON_OFFSET]) & 0x3); |
| 2858 |
wordsThisInterrupt = 256; |
| 2859 |
|
| 2860 |
if (interruptReason == 0x1 && (statusByte & IDE_STATUS_DRQ)) |
| 2861 |
{ |
| 2862 |
/* |
| 2863 |
* Write the packet. |
| 2864 |
*/ |
| 2865 |
printk("AtapiInterrupt: Writing Atapi packet.\n"); |
| 2866 |
|
| 2867 |
/* |
| 2868 |
* Send CDB to device. |
| 2869 |
*/ |
| 2870 |
WriteBuffer(pChan, (PUSHORT)srb->Cdb, 6); |
| 2871 |
|
| 2872 |
return TRUE; |
| 2873 |
} |
| 2874 |
else if (interruptReason == 0x0 && (statusByte & IDE_STATUS_DRQ)) |
| 2875 |
{ |
| 2876 |
/* |
| 2877 |
* Write the data. |
| 2878 |
*/ |
| 2879 |
|
| 2880 |
/* |
| 2881 |
* Pick up bytes to transfer and convert to words. |
| 2882 |
*/ |
| 2883 |
wordCount = inb(pChan->io_ports[ATAPI_LCYL_OFFSET]); |
| 2884 |
wordCount |= inb(pChan->io_ports[ATAPI_HCYL_OFFSET]) << 8; |
| 2885 |
|
| 2886 |
/* |
| 2887 |
* Covert bytes to words. |
| 2888 |
*/ |
| 2889 |
wordCount >>= 1; |
| 2890 |
|
| 2891 |
if (wordCount != pChan->WordsLeft) |
| 2892 |
{ |
| 2893 |
printk( "AtapiInterrupt: %ld words requested; %ld words xferred\n", |
| 2894 |
pChan->WordsLeft, wordCount); |
| 2895 |
} |
| 2896 |
|
| 2897 |
/* |
| 2898 |
* Verify this makes sense. |
| 2899 |
*/ |
| 2900 |
if (wordCount > pChan->WordsLeft) |
| 2901 |
{ |
| 2902 |
wordCount = pChan->WordsLeft; |
| 2903 |
} |
| 2904 |
|
| 2905 |
/* |
| 2906 |
* Ensure that this is a write command. |
| 2907 |
*/ |
| 2908 |
if (srb->SrbFlags & SRB_FLAGS_DATA_OUT) |
| 2909 |
{ |
| 2910 |
dprintk("AtapiInterrupt: Write interrupt\n"); |
| 2911 |
WaitOnBusy(pChan, statusByte); |
| 2912 |
WriteBuffer(pChan, pChan->DataBuffer, wordCount); |
| 2913 |
|
| 2914 |
# if (0) |
| 2915 |
/* |
| 2916 |
* Translate ATAPI data back to SCSI data if needed (don't |
| 2917 |
* convert if the original command is SCSIOP_MODE_SELECT10) |
| 2918 |
*/ |
| 2919 |
if (srb->Cdb[0] == ATAPI_MODE_SELECT && pchan->ConvertCdb) |
| 2920 |
{ |
| 2921 |
Atapi2Scsi(pChan, srb, (char *)pChan->DataBuffer, wordCount << 1); |
| 2922 |
} |
| 2923 |
# endif |
| 2924 |
} |
| 2925 |
else |
| 2926 |
{ |
| 2927 |
printk("AtapiInterrupt: Int reason %x, but srb is for a write %p.\n", |
| 2928 |
interruptReason, srb); |
| 2929 |
|
| 2930 |
/* |
| 2931 |
* Fail this request. |
| 2932 |
*/ |
| 2933 |
status = SRB_STATUS_ERROR; |
| 2934 |
goto CompleteRequest; |
| 2935 |
} |
| 2936 |
|
| 2937 |
/* |
| 2938 |
* Advance data buffer pointer and bytes left. |
| 2939 |
*/ |
| 2940 |
pChan->DataBuffer += wordCount; |
| 2941 |
pChan->WordsLeft -= wordCount; |
| 2942 |
|
| 2943 |
return TRUE; |
| 2944 |
} |
| 2945 |
else if (interruptReason == 0x2 && (statusByte & IDE_STATUS_DRQ)) |
| 2946 |
{ |
| 2947 |
/* |
| 2948 |
* Pick up bytes to transfer and convert to words. |
| 2949 |
*/ |
| 2950 |
wordCount = inb(pChan->io_ports[ATAPI_LCYL_OFFSET]); |
| 2951 |
wordCount |= inb(pChan->io_ports[ATAPI_HCYL_OFFSET]) << 8; |
| 2952 |
|
| 2953 |
/* |
| 2954 |
* Covert bytes to words. |
| 2955 |
*/ |
| 2956 |
wordCount >>= 1; |
| 2957 |
if (wordCount != pChan->WordsLeft) |
| 2958 |
{ |
| 2959 |
printk("AtapiInterrupt: %ld words requested; %ld words xferred\n", |
| 2960 |
pChan->WordsLeft, wordCount); |
| 2961 |
} |
| 2962 |
|
| 2963 |
/* |
| 2964 |
* Verify this makes sense. |
| 2965 |
*/ |
| 2966 |
if (wordCount > pChan->WordsLeft) |
| 2967 |
{ |
| 2968 |
wordCount = pChan->WordsLeft; |
| 2969 |
} |
| 2970 |
|
| 2971 |
/* |
| 2972 |
* Ensure that this is a read command. |
| 2973 |
*/ |
| 2974 |
if (srb->SrbFlags & SRB_FLAGS_DATA_IN) |
| 2975 |
{ |
| 2976 |
dprintk("AtapiInterrupt: Read interrupt\n"); |
| 2977 |
WaitOnBusy(pChan, statusByte); |
| 2978 |
ReadBuffer(pChan, pChan->DataBuffer, wordCount); |
| 2979 |
|
| 2980 |
/* |
| 2981 |
* From Windows DDK |
| 2982 |
* You should typically set the ANSI-approved Version field, |
| 2983 |
* in the INQUIRY response, to at least 2. |
| 2984 |
*/ |
| 2985 |
if (srb->Cdb[0] == SCSIOP_INQUIRY) |
| 2986 |
{ |
| 2987 |
/* |
| 2988 |
* Maybe it's not necessary in Linux driver. |
| 2989 |
*/ |
| 2990 |
*((PUCHAR)pChan->DataBuffer + 2) = 2; |
| 2991 |
} |
| 2992 |
} |
| 2993 |
else |
| 2994 |
{ |
| 2995 |
printk("AtapiInterrupt: Int reason %x, but srb is for a read %p.\n", |
| 2996 |
interruptReason, srb); |
| 2997 |
|
| 2998 |
/* |
| 2999 |
* Fail this request. |
| 3000 |
*/ |
| 3001 |
status = SRB_STATUS_ERROR; |
| 3002 |
goto CompleteRequest; |
| 3003 |
} |
| 3004 |
|
| 3005 |
/* |
| 3006 |
* Advance data buffer pointer and bytes left. |
| 3007 |
*/ |
| 3008 |
pChan->DataBuffer += wordCount; |
| 3009 |
pChan->WordsLeft -= wordCount; |
| 3010 |
|
| 3011 |
/* |
| 3012 |
* Check for read command complete. |
| 3013 |
*/ |
| 3014 |
if (pChan->WordsLeft == 0) |
| 3015 |
{ |
| 3016 |
/* |
| 3017 |
* Work around to make many atapi devices return correct sector size |
| 3018 |
* of 2048. Also certain devices will have sector count == 0x00, check |
| 3019 |
* for that also. |
| 3020 |
*/ |
| 3021 |
if ((srb->Cdb[0] == 0x25) && |
| 3022 |
((pChan->IdentifyData[srb->TargetId & 1].GeneralConfiguration >> 8) & 0x1F) == 0x05) |
| 3023 |
{ |
| 3024 |
pChan->DataBuffer -= wordCount; |
| 3025 |
if (pChan->DataBuffer[0] == 0x00) |
| 3026 |
{ |
| 3027 |
*((ULONG *) &(pChan->DataBuffer[0])) = 0xFFFFFF7F; |
| 3028 |
} |
| 3029 |
|
| 3030 |
*((ULONG *) &(pChan->DataBuffer[2])) = 0x00080000; |
| 3031 |
pChan->DataBuffer += wordCount; |
| 3032 |
} |
| 3033 |
} |
| 3034 |
return TRUE; |
| 3035 |
} |
| 3036 |
else if (interruptReason == 0x3 && !(statusByte & IDE_STATUS_DRQ)) |
| 3037 |
{ |
| 3038 |
dprintk("Command Complete!\n"); |
| 3039 |
/* |
| 3040 |
* Command complete. |
| 3041 |
*/ |
| 3042 |
if (pChan->WordsLeft) |
| 3043 |
{ |
| 3044 |
status = SRB_STATUS_DATA_OVERRUN; |
| 3045 |
} |
| 3046 |
else |
| 3047 |
{ |
| 3048 |
status = SRB_STATUS_SUCCESS; |
| 3049 |
} |
| 3050 |
|
| 3051 |
CompleteRequest: |
| 3052 |
|
| 3053 |
if (status == SRB_STATUS_ERROR) |
| 3054 |
{ |
| 3055 |
/* |
| 3056 |
* Map error to specific SRB status and handle request sense. |
| 3057 |
*/ |
| 3058 |
printk("AtapiInterrupt error\n"); |
| 3059 |
|
| 3060 |
status = MapError(pChan, srb); |
| 3061 |
|
| 3062 |
/* |
| 3063 |
* Try to recover it.... 2003/02/27 |
| 3064 |
*/ |
| 3065 |
|
| 3066 |
|
| 3067 |
pChan->RDP = FALSE; |
| 3068 |
} |
| 3069 |
else |
| 3070 |
{ |
| 3071 |
/* |
| 3072 |
* Wait for busy to drop. |
| 3073 |
*/ |
| 3074 |
for (i = 0; i < 30; i++) |
| 3075 |
{ |
| 3076 |
GetStatus(pChan, statusByte); |
| 3077 |
if (!(statusByte & IDE_STATUS_BUSY)) |
| 3078 |
{ |
| 3079 |
break; |
| 3080 |
} |
| 3081 |
udelay(500); |
| 3082 |
} |
| 3083 |
|
| 3084 |
if (i == 30) |
| 3085 |
{ |
| 3086 |
/* |
| 3087 |
* Reset the controller. |
| 3088 |
*/ |
| 3089 |
printk("AtapiInterrupt: Resetting due to BSY still up - %x.\n", statusByte); |
| 3090 |
AtapiResetController(pChan); |
| 3091 |
return TRUE; |
| 3092 |
} |
| 3093 |
|
| 3094 |
/* |
| 3095 |
* Check to see if DRQ is still up. |
| 3096 |
*/ |
| 3097 |
if (statusByte & IDE_STATUS_DRQ) |
| 3098 |
{ |
| 3099 |
for (i = 0; i < 500; i++) |
| 3100 |
{ |
| 3101 |
GetStatus(pChan, statusByte); |
| 3102 |
if (!(statusByte & IDE_STATUS_DRQ)) |
| 3103 |
{ |
| 3104 |
break; |
| 3105 |
} |
| 3106 |
udelay(100); |
| 3107 |
} |
| 3108 |
|
| 3109 |
if (i == 500) |
| 3110 |
{ |
| 3111 |
/* |
| 3112 |
* Reset the controller. |
| 3113 |
*/ |
| 3114 |
printk("AtapiInterrupt: Resetting due to DRQ still up - %x\n", |
| 3115 |
statusByte); |
| 3116 |
AtapiResetController(pChan); |
| 3117 |
return TRUE; |
| 3118 |
} |
| 3119 |
} |
| 3120 |
} |
| 3121 |
|
| 3122 |
/* |
| 3123 |
* Clear interrupt expecting flag. |
| 3124 |
*/ |
| 3125 |
pChan->ExpectingInterrupt = FALSE; |
| 3126 |
|
| 3127 |
/* |
| 3128 |
* Sanity check that there is a current request. |
| 3129 |
*/ |
| 3130 |
if (srb != NULL) |
| 3131 |
{ |
| 3132 |
/* |
| 3133 |
* Set status in SRB. |
| 3134 |
*/ |
| 3135 |
srb->SrbStatus = (UCHAR)status; |
| 3136 |
|
| 3137 |
/* |
| 3138 |
* Check for underflow. |
| 3139 |
*/ |
| 3140 |
if (pChan->WordsLeft) |
| 3141 |
{ |
| 3142 |
/* |
| 3143 |
* Subtract out residual words and update if filemark hit, |
| 3144 |
* setmark hit , end of data, end of media... |
| 3145 |
*/ |
| 3146 |
if (!(pChan->DeviceFlags[srb->TargetId & 1] & DFLAGS_TAPE_DEVICE)) |
| 3147 |
{ |
| 3148 |
if (status == SRB_STATUS_DATA_OVERRUN) |
| 3149 |
{ |
| 3150 |
srb->DataTransferLength -= pChan->WordsLeft * 2; |
| 3151 |
} |
| 3152 |
else |
| 3153 |
{ |
| 3154 |
srb->DataTransferLength = 0; |
| 3155 |
} |
| 3156 |
} |
| 3157 |
else |
| 3158 |
{ |
| 3159 |
srb->DataTransferLength -= pChan->WordsLeft * 2; |
| 3160 |
} |
| 3161 |
} |
| 3162 |
|
| 3163 |
GetBaseStatus(pChan, statusByte); |
| 3164 |
if (pChan->RDP && !(statusByte & IDE_STATUS_DSC)) |
| 3165 |
{ |
| 3166 |
printk("-@@-\n"); |
| 3167 |
} |
| 3168 |
else |
| 3169 |
{ |
| 3170 |
/* |
| 3171 |
* Clear current SRB. Indicate ready for next request. |
| 3172 |
*/ |
| 3173 |
pChan->CurrentSrb = NULL; |
| 3174 |
TaskDone(pChan, srb); |
| 3175 |
} |
| 3176 |
} |
| 3177 |
else |
| 3178 |
{ |
| 3179 |
printk( "AtapiInterrupt: No SRB!\n"); |
| 3180 |
} |
| 3181 |
|
| 3182 |
return TRUE; |
| 3183 |
} |
| 3184 |
else |
| 3185 |
{ |
| 3186 |
/* |
| 3187 |
* Unexpected int. |
| 3188 |
*/ |
| 3189 |
printk("AtapiInterrupt: Unexpected interrupt. InterruptReason %x. Status %x.\n", |
| 3190 |
interruptReason, statusByte); |
| 3191 |
return FALSE; |
| 3192 |
} |
| 3193 |
|
| 3194 |
return TRUE; |
| 3195 |
|
| 3196 |
} /* end AtapiInterrupt */ |
| 3197 |
|
| 3198 |
/************************************************************************ |
| 3199 |
* IRQ handler |
| 3200 |
************************************************************************/ |
| 3201 |
static void |
| 3202 |
Irq_Handler(int irq, void *dev_id, struct pt_regs *regs) |
| 3203 |
{ |
| 3204 |
|
| 3205 |
UCHAR i; |
| 3206 |
UCHAR j; |
| 3207 |
ULONG flags; |
| 3208 |
|
| 3209 |
dprintk("Irq_Handler enter\n"); |
| 3210 |
|
| 3211 |
spin_lock_irqsave(&io_request_lock, flags); |
| 3212 |
|
| 3213 |
/* |
| 3214 |
* Scan for interrupt to process. |
| 3215 |
*/ |
| 3216 |
for (i = 0; i < NumAdapters; i++) |
| 3217 |
{ |
| 3218 |
PITE_ADAPTER pAdap = ite_adapters[i]; |
| 3219 |
if (pAdap->irq != irq) continue; |
| 3220 |
|
| 3221 |
for (j = 0; j < pAdap->num_channels; j++) |
| 3222 |
{ |
| 3223 |
IT8212Interrupt(&pAdap->IDEChannel[j]); |
| 3224 |
} |
| 3225 |
} |
| 3226 |
|
| 3227 |
spin_unlock_irqrestore(&io_request_lock, flags); |
| 3228 |
|
| 3229 |
dprintk("Irq_Handler exit\n"); |
| 3230 |
|
| 3231 |
} /* end Irq_Handler */ |
| 3232 |
|
| 3233 |
/************************************************************************ |
| 3234 |
* This routine handles IDE Verify. |
| 3235 |
************************************************************************/ |
| 3236 |
UCHAR |
| 3237 |
IdeVerify(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 3238 |
{ |
| 3239 |
|
| 3240 |
ULONG startingSector; |
| 3241 |
ULONG sectors; |
| 3242 |
ULONG endSector; |
| 3243 |
USHORT sectorCount; |
| 3244 |
UCHAR drvSelect; |
| 3245 |
UCHAR statusByte = 0; |
| 3246 |
|
| 3247 |
/* |
| 3248 |
* Select device |
| 3249 |
*/ |
| 3250 |
outb((UCHAR)((Srb->TargetId & 0x1) << 4 | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 3251 |
|
| 3252 |
/* |
| 3253 |
* Wait for device ready (Not BUSY and Not DRQ) |
| 3254 |
*/ |
| 3255 |
WaitForDeviceReady(pChan, statusByte); |
| 3256 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 3257 |
(statusByte == 0)) |
| 3258 |
{ |
| 3259 |
printk("IdeVerify: Disk[%d] not ready. Status=0x%x\n", |
| 3260 |
Srb->TargetId, statusByte); |
| 3261 |
return SRB_STATUS_BUSY; |
| 3262 |
} |
| 3263 |
|
| 3264 |
/* |
| 3265 |
* Get the starting sector number from CDB. |
| 3266 |
*/ |
| 3267 |
startingSector = ((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte3 | |
| 3268 |
((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte2 << 8 | |
| 3269 |
((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte1 << 16 | |
| 3270 |
((PCDB)Srb->Cdb)->CDB10.LogicalBlockByte0 << 24; |
| 3271 |
|
| 3272 |
sectorCount = (USHORT)(((PCDB)Srb->Cdb)->CDB10.TransferBlocksMsb << 8 | |
| 3273 |
((PCDB)Srb->Cdb)->CDB10.TransferBlocksLsb ); |
| 3274 |
|
| 3275 |
endSector = startingSector + sectorCount; |
| 3276 |
|
| 3277 |
/* |
| 3278 |
* Drive has these number sectors. |
| 3279 |
* |
| 3280 |
* 48-bit addressing. |
| 3281 |
*/ |
| 3282 |
if (endSector > 0x0FFFFFFF) |
| 3283 |
{ |
| 3284 |
sectors = pChan->IdentifyData[Srb->TargetId & 0x01].Capacity_48bit_LOW; |
| 3285 |
|
| 3286 |
printk("IdeVerify (48-bit): Starting sector %ld, Ending sector %ld\n", |
| 3287 |
startingSector, endSector); |
| 3288 |
|
| 3289 |
if (endSector > sectors) |
| 3290 |
{ |
| 3291 |
/* |
| 3292 |
* Too big, round down. |
| 3293 |
*/ |
| 3294 |
printk("IdeVerify: Truncating request to %lx blocks\n", sectors - startingSector - 1); |
| 3295 |
|
| 3296 |
outb((UCHAR)((sectors - startingSector - 1) >> 8), pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 3297 |
outb((UCHAR)(sectors - startingSector - 1), pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 3298 |
} |
| 3299 |
else |
| 3300 |
{ |
| 3301 |
/* |
| 3302 |
* Set up sector count register. Round up to next block. |
| 3303 |
*/ |
| 3304 |
if (sectorCount > 0xFFFF) |
| 3305 |
{ |
| 3306 |
sectorCount = (USHORT)0xFFFF; |
| 3307 |
} |
| 3308 |
|
| 3309 |
outb((UCHAR)(sectorCount >> 8), pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 3310 |
outb((UCHAR) sectorCount, pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 3311 |
} |
| 3312 |
|
| 3313 |
/* |
| 3314 |
* Indicate expecting an interrupt. |
| 3315 |
*/ |
| 3316 |
pChan->ExpectingInterrupt = TRUE; |
| 3317 |
|
| 3318 |
/* |
| 3319 |
* Set up LBA address |
| 3320 |
*/ |
| 3321 |
outb((UCHAR) (startingSector >> 24), pChan->io_ports[IDE_LOCYL_OFFSET]); |
| 3322 |
outb((UCHAR) startingSector, pChan->io_ports[IDE_LOCYL_OFFSET]); |
| 3323 |
outb((UCHAR) 0, pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 3324 |
outb((UCHAR) (startingSector >> 8), pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 3325 |
outb((UCHAR) 0, pChan->io_ports[IDE_HCYL_OFFSET]); |
| 3326 |
outb((UCHAR) (startingSector >> 16), pChan->io_ports[IDE_HCYL_OFFSET]); |
| 3327 |
|
| 3328 |
/* |
| 3329 |
* Send verify command. |
| 3330 |
*/ |
| 3331 |
outb(IDE_COMMAND_READ_VERIFY_EXT, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 3332 |
} |
| 3333 |
/* |
| 3334 |
* 28-bit addressing |
| 3335 |
*/ |
| 3336 |
else |
| 3337 |
{ |
| 3338 |
sectors = pChan->IdentifyData[Srb->TargetId & 0x01].UserAddressableSectors; |
| 3339 |
|
| 3340 |
printk("IdeVerify: Starting sector %ld, Ending sector %ld\n", |
| 3341 |
startingSector, endSector); |
| 3342 |
|
| 3343 |
if (endSector > sectors) |
| 3344 |
{ |
| 3345 |
/* |
| 3346 |
* Too big, round down. |
| 3347 |
*/ |
| 3348 |
printk("IdeVerify: Truncating request to %ld blocks\n", sectors - startingSector - 1); |
| 3349 |
outb((UCHAR)(sectors - startingSector - 1), pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 3350 |
} |
| 3351 |
else |
| 3352 |
{ |
| 3353 |
/* |
| 3354 |
* Set up sector count register. Round up to next block. |
| 3355 |
*/ |
| 3356 |
if (sectorCount > 0xFF) |
| 3357 |
{ |
| 3358 |
sectorCount = (USHORT)0xFF; |
| 3359 |
} |
| 3360 |
outb((UCHAR)sectorCount, pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 3361 |
} |
| 3362 |
|
| 3363 |
/* |
| 3364 |
* Indicate expecting an interrupt. |
| 3365 |
*/ |
| 3366 |
pChan->ExpectingInterrupt = TRUE; |
| 3367 |
|
| 3368 |
/* |
| 3369 |
* Set up LBA address |
| 3370 |
*/ |
| 3371 |
outb((UCHAR) startingSector, pChan->io_ports[IDE_LOCYL_OFFSET]); |
| 3372 |
outb((UCHAR) (startingSector >> 8), pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 3373 |
outb((UCHAR) (startingSector >> 16),pChan->io_ports[IDE_HCYL_OFFSET]); |
| 3374 |
|
| 3375 |
/* |
| 3376 |
* Select driver, set LBA mode, set LBA (27:27) |
| 3377 |
*/ |
| 3378 |
drvSelect = (UCHAR) (startingSector >> 24); |
| 3379 |
drvSelect = drvSelect | (((UCHAR) Srb->TargetId & 0x1) << 4) | 0xA0 | 0x40; |
| 3380 |
outb(drvSelect, pChan->io_ports[IDE_SELECT_OFFSET]); |
| 3381 |
|
| 3382 |
/* |
| 3383 |
* Send verify command. |
| 3384 |
*/ |
| 3385 |
outb(IDE_COMMAND_READ_VERIFY, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 3386 |
} |
| 3387 |
|
| 3388 |
/* |
| 3389 |
* Wait for interrupt. |
| 3390 |
*/ |
| 3391 |
return SRB_STATUS_PENDING; |
| 3392 |
|
| 3393 |
} /* end IdeVerify */ |
| 3394 |
|
| 3395 |
/************************************************************************ |
| 3396 |
* This function is used to copy memory with overlapped destination and |
| 3397 |
* source. I guess ScsiPortMoveMemory cannot handle this well. Can it? |
| 3398 |
************************************************************************/ |
| 3399 |
void |
| 3400 |
IT8212MoveMemory(PUCHAR DestAddr, PUCHAR SrcAddr, LONG ByteCount) |
| 3401 |
{ |
| 3402 |
|
| 3403 |
long i; |
| 3404 |
|
| 3405 |
dprintk("IT8212MoveMemory: DestAddr=0x%x, SrcAddr=0x%x, ByteCount=0x%x\n", |
| 3406 |
DestAddr, SrcAddr, ByteCount); |
| 3407 |
|
| 3408 |
if (DestAddr > SrcAddr) |
| 3409 |
{ |
| 3410 |
/* |
| 3411 |
* If Destination Area is in the back of the Source Area, copy from |
| 3412 |
* the end of the requested area. |
| 3413 |
*/ |
| 3414 |
for (i = (ByteCount - 1); i >= 0; i--) |
| 3415 |
{ |
| 3416 |
*(DestAddr + i) = *(SrcAddr + i); |
| 3417 |
} |
| 3418 |
} |
| 3419 |
else if (DestAddr < SrcAddr) |
| 3420 |
{ |
| 3421 |
/* |
| 3422 |
* If Destination Area is in the front of the Source Area, copy from |
| 3423 |
* the begin of the requested area. |
| 3424 |
*/ |
| 3425 |
for (i = 0; i < ByteCount; i++) |
| 3426 |
{ |
| 3427 |
*(DestAddr + i) = *(SrcAddr + i); |
| 3428 |
} |
| 3429 |
} |
| 3430 |
|
| 3431 |
} /* end IT8212MoveMemory */ |
| 3432 |
|
| 3433 |
/************************************************************************ |
| 3434 |
* Convert SCSI packet command to Atapi packet command. |
| 3435 |
************************************************************************/ |
| 3436 |
void |
| 3437 |
Scsi2Atapi(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 3438 |
{ |
| 3439 |
|
| 3440 |
dprintk("++++++++++ Scsi2Atapi (0x%X) ++++++++++\n", Srb->Cdb[0]); |
| 3441 |
dprintk("Srb->DataBuffer=0x%x\n", Srb->DataBuffer); |
| 3442 |
dprintk("Srb->DataTransferLength=0x%x\n", Srb->DataTransferLength); |
| 3443 |
dprintk("CDB=0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
| 3444 |
Srb->Cdb[0], Srb->Cdb[1], Srb->Cdb[2], Srb->Cdb[3], Srb->Cdb[4], Srb->Cdb[5], |
| 3445 |
Srb->Cdb[6], Srb->Cdb[7], Srb->Cdb[8], Srb->Cdb[9], Srb->Cdb[10], Srb->Cdb[11]); |
| 3446 |
|
| 3447 |
/* |
| 3448 |
* Change the cdb length. |
| 3449 |
*/ |
| 3450 |
Srb->CdbLength = 12; |
| 3451 |
|
| 3452 |
/* |
| 3453 |
* Because the block descripter and the header translation, we must |
| 3454 |
* adjust the requested length. |
| 3455 |
*/ |
| 3456 |
Srb->DataTransferLength -= 4; |
| 3457 |
|
| 3458 |
/* |
| 3459 |
* Record the original CDB for later restore. |
| 3460 |
*/ |
| 3461 |
memcpy(pChan->TempCdb, Srb->Cdb, MAXIMUM_CDB_SIZE); |
| 3462 |
|
| 3463 |
/* |
| 3464 |
* Indicate that we have performed Scsi2Atapi function. And we must |
| 3465 |
* restore the CDB back once the command complete. |
| 3466 |
*/ |
| 3467 |
pChan->ConvertCdb = TRUE; |
| 3468 |
|
| 3469 |
switch (Srb->Cdb[0]) |
| 3470 |
{ |
| 3471 |
/* |
| 3472 |
* Convert the command from SCSIOP_MODE_SENSE (0x1A) to |
| 3473 |
* SCSIOP_MODE_SENSE10 (0x5A). |
| 3474 |
*/ |
| 3475 |
case SCSIOP_MODE_SENSE: |
| 3476 |
{ |
| 3477 |
PSCSI_MODE_SENSE10 modeSense10 = (PSCSI_MODE_SENSE10) Srb->Cdb; |
| 3478 |
PSCSI_MODE_SENSE6 modeSense6 = (PSCSI_MODE_SENSE6) pChan->TempCdb; |
| 3479 |
|
| 3480 |
/* |
| 3481 |
* 1. Zero out the whole CDB. |
| 3482 |
*/ |
| 3483 |
memset((PUCHAR)modeSense10, 0, MAXIMUM_CDB_SIZE); |
| 3484 |
|
| 3485 |
/* |
| 3486 |
* 2. Fill in command code (SCSI_MODE_SENSE10). |
| 3487 |
*/ |
| 3488 |
modeSense10->OperationCode = ATAPI_MODE_SENSE; |
| 3489 |
modeSense10->Dbd = modeSense6->Dbd; |
| 3490 |
modeSense10->PageCode = modeSense6->PageCode; |
| 3491 |
modeSense10->Pc = modeSense6->Pc; |
| 3492 |
modeSense10->SubpageCode = modeSense6->SubpageCode; |
| 3493 |
modeSense10->AllocationLengthLsb = modeSense6->AllocationLength; |
| 3494 |
modeSense10->Control = modeSense6->Control; |
| 3495 |
|
| 3496 |
/* |
| 3497 |
* 3. Becasuse we will fake a block descripter (-8), and |
| 3498 |
* translate the header (+4), so the requested length |
| 3499 |
* should be modified. That is, -8+4=-4 bytes. |
| 3500 |
*/ |
| 3501 |
modeSense10->AllocationLengthLsb -= 4; |
| 3502 |
|
| 3503 |
break; |
| 3504 |
} |
| 3505 |
|
| 3506 |
/* |
| 3507 |
* Convert the command from SCSIOP_MODE_SELECT (0x15) to |
| 3508 |
* SCSIOP_MODE_SELECT10 (0x5A). |
| 3509 |
*/ |
| 3510 |
case SCSIOP_MODE_SELECT: |
| 3511 |
{ |
| 3512 |
UCHAR tempHeader[sizeof(PSCSI_MODE_PARAMETER_HEADER6)]; |
| 3513 |
USHORT byteCount; |
| 3514 |
PSCSI_MODE_PARAMETER_HEADER10 header10 = (PSCSI_MODE_PARAMETER_HEADER10)Srb->DataBuffer; |
| 3515 |
PSCSI_MODE_PARAMETER_HEADER6 header6 = (PSCSI_MODE_PARAMETER_HEADER6)tempHeader; |
| 3516 |
PSCSI_MODE_SELECT10 modeSelect10 = (PSCSI_MODE_SELECT10)Srb->Cdb; |
| 3517 |
PSCSI_MODE_SELECT6 modeSelect6 = (PSCSI_MODE_SELECT6)pChan->TempCdb; |
| 3518 |
|
| 3519 |
/* |
| 3520 |
* First, convert the command block. |
| 3521 |
*/ |
| 3522 |
|
| 3523 |
/* |
| 3524 |
* 1. Zero out the whole CDB. |
| 3525 |
*/ |
| 3526 |
memset((PUCHAR)modeSelect10, 0, MAXIMUM_CDB_SIZE); |
| 3527 |
|
| 3528 |
/* |
| 3529 |
* 2. Fill in command code (SCSI_MODE_SENSE10). |
| 3530 |
*/ |
| 3531 |
modeSelect10->OperationCode = ATAPI_MODE_SELECT; |
| 3532 |
modeSelect10->SPBit = modeSelect6->SPBit; |
| 3533 |
modeSelect10->PFBit = modeSelect6->PFBit; |
| 3534 |
modeSelect10->ParameterListLengthLsb = modeSelect6->ParameterListLength; |
| 3535 |
modeSelect10->Control = modeSelect6->Control; |
| 3536 |
|
| 3537 |
/* |
| 3538 |
* 3. Becasuse we will remove the block descripter (-8), and |
| 3539 |
* translate the header (+4), so the requested length should |
| 3540 |
* be modified. That is, -8+4=-4 bytes. |
| 3541 |
*/ |
| 3542 |
modeSelect10->ParameterListLengthLsb -= 4; |
| 3543 |
|
| 3544 |
/* |
| 3545 |
* Second, convert the parameter page format from SCSI to ATAPI. |
| 3546 |
*/ |
| 3547 |
|
| 3548 |
/* |
| 3549 |
* Remove the mode parameter data (except the header and the |
| 3550 |
* block descripter). |
| 3551 |
*/ |
| 3552 |
byteCount = modeSelect6->ParameterListLength - sizeof(SCSI_MODE_PARAMETER_HEADER6) - sizeof(SCSI_MODE_PARAMTER_BLOCK_DESCRIPTER); |
| 3553 |
if (byteCount > 0) |
| 3554 |
{ |
| 3555 |
IT8212MoveMemory( |
| 3556 |
(PUCHAR) header10 + sizeof(SCSI_MODE_PARAMETER_HEADER10), |
| 3557 |
(PUCHAR) header10 + sizeof(SCSI_MODE_PARAMETER_HEADER6) + sizeof(SCSI_MODE_PARAMTER_BLOCK_DESCRIPTER), |
| 3558 |
byteCount |
| 3559 |
); |
| 3560 |
} |
| 3561 |
|
| 3562 |
/* |
| 3563 |
* Keep the original header6 (4 bytes) in tempHeader for later use |
| 3564 |
*/ |
| 3565 |
memcpy(tempHeader, header10, sizeof(SCSI_MODE_PARAMETER_HEADER6)); |
| 3566 |
|
| 3567 |
/* |
| 3568 |
* Change the "mode parameter header(6)" to "mode parameter header(10)" |
| 3569 |
* Notice: Remove the block descripter in SCSI-2 command out. It |
| 3570 |
* won't be used in MMC. |
| 3571 |
*/ |
| 3572 |
memset((PUCHAR)header10, 0, sizeof(SCSI_MODE_PARAMETER_HEADER10)); |
| 3573 |
header10->ModeDataLengthLsb = header6->ModeDataLength; |
| 3574 |
header10->MediumType = header6->MediumType; |
| 3575 |
header10->DeviceSpecificParameter = header6->DeviceSpecificParameter; |
| 3576 |
header10->BlockDescriptorLengthLsb = header6->BlockDescriptorLength; |
| 3577 |
|
| 3578 |
/* |
| 3579 |
* ATAPI doesn't support block descripter, so remove it from the |
| 3580 |
* mode paramter. |
| 3581 |
*/ |
| 3582 |
header10->BlockDescriptorLengthLsb = 0; |
| 3583 |
|
| 3584 |
break; |
| 3585 |
} |
| 3586 |
} |
| 3587 |
|
| 3588 |
dprintk("Srb->DataTransferLength=0x%x\n", Srb->DataTransferLength); |
| 3589 |
dprintk("Final CDB=0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
| 3590 |
Srb->Cdb[0], Srb->Cdb[1], Srb->Cdb[2], Srb->Cdb[3], Srb->Cdb[4], Srb->Cdb[5], |
| 3591 |
Srb->Cdb[6], Srb->Cdb[7], Srb->Cdb[8], Srb->Cdb[9], Srb->Cdb[10], Srb->Cdb[11]); |
| 3592 |
dprintk("---------- Scsi2Atapi (0x%X) ----------\n", Srb->Cdb[0]); |
| 3593 |
|
| 3594 |
} /* end Scsi2Atapi */ |
| 3595 |
|
| 3596 |
/************************************************************************ |
| 3597 |
* Send ATAPI packet command to device. |
| 3598 |
************************************************************************/ |
| 3599 |
UCHAR |
| 3600 |
AtapiSendCommand(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 3601 |
{ |
| 3602 |
|
| 3603 |
ULONG bmAddress = pChan->dma_base; |
| 3604 |
ULONG i; |
| 3605 |
ULONG flags; |
| 3606 |
UCHAR statusByte; |
| 3607 |
UCHAR byteCountLow; |
| 3608 |
UCHAR byteCountHigh; |
| 3609 |
UCHAR useDMA; |
| 3610 |
UCHAR RevisionID = 0; |
| 3611 |
UCHAR bmClearStat; |
| 3612 |
PITE_ADAPTER pAdap = ite_adapters[0]; |
| 3613 |
|
| 3614 |
dprintk("AtapiSendCommand: Command 0x%X to Device %d\n", |
| 3615 |
Srb->Cdb[0], Srb->TargetId); |
| 3616 |
|
| 3617 |
/* |
| 3618 |
* Default use PIO mode. |
| 3619 |
*/ |
| 3620 |
useDMA = 0; |
| 3621 |
pChan->ConvertCdb = FALSE; |
| 3622 |
|
| 3623 |
/* |
| 3624 |
* Make sure command is to ATAPI device. |
| 3625 |
*/ |
| 3626 |
flags = pChan->DeviceFlags[Srb->TargetId & 1]; |
| 3627 |
if (flags & (DFLAGS_SANYO_ATAPI_CHANGER | DFLAGS_ATAPI_CHANGER)) |
| 3628 |
{ |
| 3629 |
if ((Srb->Lun) > (pChan->DiscsPresent[Srb->TargetId & 1] - 1)) |
| 3630 |
{ |
| 3631 |
/* |
| 3632 |
* Indicate no device found at this address. |
| 3633 |
*/ |
| 3634 |
return SRB_STATUS_SELECTION_TIMEOUT; |
| 3635 |
} |
| 3636 |
} |
| 3637 |
else if (Srb->Lun > 0) |
| 3638 |
{ |
| 3639 |
return SRB_STATUS_SELECTION_TIMEOUT; |
| 3640 |
} |
| 3641 |
|
| 3642 |
if (!(flags & DFLAGS_ATAPI_DEVICE)) |
| 3643 |
{ |
| 3644 |
return SRB_STATUS_SELECTION_TIMEOUT; |
| 3645 |
} |
| 3646 |
|
| 3647 |
/* |
| 3648 |
* Select device 0 or 1. |
| 3649 |
*/ |
| 3650 |
outb((UCHAR)(((Srb->TargetId & 0x1) << 4) | 0xA0), |
| 3651 |
pChan->io_ports[ATAPI_SELECT_OFFSET]); |
| 3652 |
|
| 3653 |
/* |
| 3654 |
* Try to enable interrupt again. (2003/02/25) |
| 3655 |
*/ |
| 3656 |
#if (0) |
| 3657 |
outb(0x00, pChan->io_ports[ATAPI_CONTROL_OFFSET]); |
| 3658 |
#endif |
| 3659 |
|
| 3660 |
/* |
| 3661 |
* Verify that controller is ready for next command. |
| 3662 |
*/ |
| 3663 |
GetStatus(pChan, statusByte); |
| 3664 |
|
| 3665 |
dprintk("AtapiSendCommand: Entered with status %x\n", statusByte); |
| 3666 |
|
| 3667 |
if (statusByte & IDE_STATUS_BUSY) |
| 3668 |
{ |
| 3669 |
printk("AtapiSendCommand: Device busy (%x)\n", statusByte); |
| 3670 |
return SRB_STATUS_BUSY; |
| 3671 |
} |
| 3672 |
|
| 3673 |
if (statusByte & IDE_STATUS_ERROR) |
| 3674 |
{ |
| 3675 |
if (Srb->Cdb[0] != SCSIOP_REQUEST_SENSE) |
| 3676 |
{ |
| 3677 |
printk("AtapiSendCommand: Error on entry: (%x)\n", statusByte); |
| 3678 |
|
| 3679 |
/* |
| 3680 |
* Read the error reg. to clear it and fail this request. |
| 3681 |
*/ |
| 3682 |
return MapError(pChan, Srb); |
| 3683 |
} |
| 3684 |
} |
| 3685 |
|
| 3686 |
/* |
| 3687 |
* If a tape drive doesn't have DSC set and the last command is |
| 3688 |
* restrictive, don't send the next command. See discussion of |
| 3689 |
* Restrictive Delayed Process commands in QIC-157. |
| 3690 |
*/ |
| 3691 |
if ((!(statusByte & IDE_STATUS_DSC)) && (flags & DFLAGS_TAPE_DEVICE) && pChan->RDP) |
| 3692 |
{ |
| 3693 |
mdelay(1); |
| 3694 |
printk("AtapiSendCommand: DSC not set. %x\n", statusByte); |
| 3695 |
return SRB_STATUS_BUSY; |
| 3696 |
} |
| 3697 |
|
| 3698 |
if (statusByte & IDE_STATUS_DRQ) |
| 3699 |
{ |
| 3700 |
printk("AtapiSendCommand: Enter with status (%x). Attempt to recover.\n", |
| 3701 |
statusByte); |
| 3702 |
|
| 3703 |
/* |
| 3704 |
* Try to drain the data that one preliminary device thinks that it has |
| 3705 |
* to transfer. Hopefully this random assertion of DRQ will not be present |
| 3706 |
* in production devices. |
| 3707 |
*/ |
| 3708 |
for (i = 0; i < 0x10000; i++) |
| 3709 |
{ |
| 3710 |
GetStatus(pChan, statusByte); |
| 3711 |
|
| 3712 |
if (statusByte & IDE_STATUS_DRQ) |
| 3713 |
{ |
| 3714 |
/* |
| 3715 |
* Note: The data register is always referenced as a 16-bit word. |
| 3716 |
*/ |
| 3717 |
inw(pChan->io_ports[ATAPI_DATA_OFFSET]); |
| 3718 |
} |
| 3719 |
else |
| 3720 |
{ |
| 3721 |
break; |
| 3722 |
} |
| 3723 |
} |
| 3724 |
|
| 3725 |
if (i == 0x10000) |
| 3726 |
{ |
| 3727 |
printk("AtapiSendCommand: DRQ still asserted.Status (%x)\n", statusByte); |
| 3728 |
printk("AtapiSendCommand: Issued soft reset to Atapi device. \n"); |
| 3729 |
|
| 3730 |
AtapiSoftReset(pChan, Srb->TargetId); |
| 3731 |
|
| 3732 |
/* |
| 3733 |
* Re-initialize Atapi device. |
| 3734 |
*/ |
| 3735 |
IssueIdentify(pChan, (Srb->TargetId & 1), IDE_COMMAND_ATAPI_IDENTIFY); |
| 3736 |
|
| 3737 |
/* |
| 3738 |
* Inform the port driver that the bus has been reset. |
| 3739 |
*/ |
| 3740 |
|
| 3741 |
/* |
| 3742 |
* Clean up device extension fields that AtapiStartIo won't. |
| 3743 |
*/ |
| 3744 |
pChan->ExpectingInterrupt = FALSE; |
| 3745 |
pChan->RDP = FALSE; |
| 3746 |
|
| 3747 |
return SRB_STATUS_BUS_RESET; |
| 3748 |
} |
| 3749 |
} |
| 3750 |
|
| 3751 |
if (flags & (DFLAGS_SANYO_ATAPI_CHANGER | DFLAGS_ATAPI_CHANGER)) |
| 3752 |
{ |
| 3753 |
/* |
| 3754 |
* As the cdrom driver sets the LUN field in the cdb, it must be removed. |
| 3755 |
*/ |
| 3756 |
Srb->Cdb[1] &= ~0xE0; |
| 3757 |
|
| 3758 |
if ((Srb->Cdb[0] == SCSIOP_TEST_UNIT_READY) && (flags & DFLAGS_SANYO_ATAPI_CHANGER)) |
| 3759 |
{ |
| 3760 |
/* |
| 3761 |
* Torisan changer. TUR's are overloaded to be platter switches. |
| 3762 |
*/ |
| 3763 |
Srb->Cdb[7] = Srb->Lun; |
| 3764 |
} |
| 3765 |
} |
| 3766 |
|
| 3767 |
/* |
| 3768 |
* Convert SCSI to ATAPI commands if needed |
| 3769 |
*/ |
| 3770 |
switch (Srb->Cdb[0]) |
| 3771 |
{ |
| 3772 |
case SCSIOP_MODE_SENSE: |
| 3773 |
case SCSIOP_MODE_SELECT: |
| 3774 |
if (flags & DFLAGS_ATAPI_DEVICE) |
| 3775 |
{ |
| 3776 |
Scsi2Atapi(pChan, Srb); |
| 3777 |
} |
| 3778 |
break; |
| 3779 |
} |
| 3780 |
|
| 3781 |
if (pChan->UseDma[Srb->TargetId & 1]) |
| 3782 |
{ |
| 3783 |
switch (Srb->Cdb[0]) |
| 3784 |
{ |
| 3785 |
case SCSIOP_READ: /* (0x28) */ |
| 3786 |
case 0xA8: /* READ(12) */ |
| 3787 |
case SCSIOP_READ_CD: |
| 3788 |
|
| 3789 |
if (Srb->DataTransferLength == 0) |
| 3790 |
{ |
| 3791 |
break; |
| 3792 |
} |
| 3793 |
|
| 3794 |
/* |
| 3795 |
* First, switch to DMA or UDMA mode if running on Bypass mode. |
| 3796 |
*/ |
| 3797 |
if (pAdap->bypass_mode) |
| 3798 |
{ |
| 3799 |
IT8212SwitchDmaMode(pChan, Srb->TargetId); |
| 3800 |
} |
| 3801 |
|
| 3802 |
/* |
| 3803 |
* Check the SCATTER/GATHER count. The upper will give the |
| 3804 |
* different memory address depend on whether use_sg is used |
| 3805 |
* or not. |
| 3806 |
*/ |
| 3807 |
if (Srb->UseSg == 0) |
| 3808 |
{ |
| 3809 |
IdeBuildDmaTable(pChan, Srb); |
| 3810 |
} |
| 3811 |
else |
| 3812 |
{ |
| 3813 |
IdeBuildDmaSgTable(pChan, Srb); |
| 3814 |
} |
| 3815 |
|
| 3816 |
bmClearStat = inb(bmAddress + 2); |
| 3817 |
if (Srb->TargetId & 0x01) |
| 3818 |
{ |
| 3819 |
bmClearStat = bmClearStat | BM_DRV1_DMA_CAPABLE | |
| 3820 |
BM_STAT_FLG_INT | BM_STAT_FLG_ERR; |
| 3821 |
} |
| 3822 |
else |
| 3823 |
{ |
| 3824 |
bmClearStat = bmClearStat | BM_DRV0_DMA_CAPABLE | |
| 3825 |
BM_STAT_FLG_INT | BM_STAT_FLG_ERR; |
| 3826 |
} |
| 3827 |
|
| 3828 |
useDMA = 1; |
| 3829 |
|
| 3830 |
outb(0, bmAddress); |
| 3831 |
|
| 3832 |
/* |
| 3833 |
* Setup PRD table physical address. |
| 3834 |
*/ |
| 3835 |
outl(pChan->dmatable_dma, bmAddress + 4); |
| 3836 |
|
| 3837 |
/* |
| 3838 |
* Clear the status. |
| 3839 |
*/ |
| 3840 |
outb(bmClearStat, bmAddress + 2); |
| 3841 |
|
| 3842 |
break; |
| 3843 |
} /* end switch (Srb->Cdb[0]) */ |
| 3844 |
} |
| 3845 |
|
| 3846 |
/* |
| 3847 |
* Set data buffer pointer and words left. |
| 3848 |
*/ |
| 3849 |
pChan->DataBuffer = (PUSHORT)Srb->DataBuffer; |
| 3850 |
|
| 3851 |
if (useDMA) |
| 3852 |
{ |
| 3853 |
pChan->WordsLeft = 0; |
| 3854 |
} |
| 3855 |
else |
| 3856 |
{ |
| 3857 |
pChan->WordsLeft = Srb->DataTransferLength / 2; |
| 3858 |
} |
| 3859 |
|
| 3860 |
outb((UCHAR)(((Srb->TargetId & 0x1) << 4) | 0xA0), |
| 3861 |
pChan->io_ports[ATAPI_SELECT_OFFSET]); |
| 3862 |
|
| 3863 |
WaitOnBusy(pChan, statusByte); |
| 3864 |
|
| 3865 |
/* |
| 3866 |
* Write transfer byte count to registers. |
| 3867 |
*/ |
| 3868 |
byteCountLow = (UCHAR)(Srb->DataTransferLength & 0xFF); |
| 3869 |
byteCountHigh = (UCHAR)(Srb->DataTransferLength >> 8); |
| 3870 |
|
| 3871 |
if (Srb->DataTransferLength >= 0x10000) |
| 3872 |
{ |
| 3873 |
byteCountLow = byteCountHigh = 0xFF; |
| 3874 |
} |
| 3875 |
|
| 3876 |
outb(byteCountLow, pChan->io_ports[ATAPI_LCYL_OFFSET]); |
| 3877 |
outb(byteCountHigh, pChan->io_ports[ATAPI_HCYL_OFFSET]); |
| 3878 |
outb(0, pChan->io_ports[ATAPI_INTREASON_OFFSET]); |
| 3879 |
outb(0, pChan->io_ports[ATAPI_UNUSED1_OFFSET]); |
| 3880 |
outb(useDMA, pChan->io_ports[ATAPI_FEATURE_OFFSET]); |
| 3881 |
|
| 3882 |
WaitOnBusy(pChan, statusByte); |
| 3883 |
|
| 3884 |
if (flags & DFLAGS_INT_DRQ) |
| 3885 |
{ |
| 3886 |
/* |
| 3887 |
* This device interrupts when ready to receive the packet. |
| 3888 |
* |
| 3889 |
* Write ATAPI packet command. |
| 3890 |
*/ |
| 3891 |
outb(IDE_COMMAND_ATAPI_PACKET, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 3892 |
|
| 3893 |
printk("AtapiSendCommand: Wait for int. to send packet. Status (%x)\n", |
| 3894 |
statusByte); |
| 3895 |
|
| 3896 |
pChan->ExpectingInterrupt = TRUE; |
| 3897 |
|
| 3898 |
return SRB_STATUS_PENDING; |
| 3899 |
} |
| 3900 |
else |
| 3901 |
{ |
| 3902 |
/* |
| 3903 |
* Write ATAPI packet command. |
| 3904 |
*/ |
| 3905 |
outb(IDE_COMMAND_ATAPI_PACKET, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 3906 |
|
| 3907 |
/* |
| 3908 |
* Wait for DRQ. |
| 3909 |
*/ |
| 3910 |
WaitOnBusy(pChan, statusByte); |
| 3911 |
WaitForDrq(pChan, statusByte); |
| 3912 |
|
| 3913 |
if (!(statusByte & IDE_STATUS_DRQ)) |
| 3914 |
{ |
| 3915 |
printk("AtapiSendCommand: DRQ never asserted (%x)\n", statusByte); |
| 3916 |
return SRB_STATUS_ERROR; |
| 3917 |
} |
| 3918 |
} |
| 3919 |
|
| 3920 |
/* |
| 3921 |
* Need to read status register. |
| 3922 |
*/ |
| 3923 |
GetBaseStatus(pChan, statusByte); |
| 3924 |
|
| 3925 |
/* |
| 3926 |
* Send CDB to device. |
| 3927 |
* After detecting DRQ, the host writes the 12 bytes(6 words) of Command |
| 3928 |
* to the Data Register. |
| 3929 |
*/ |
| 3930 |
WaitOnBusy(pChan, statusByte); |
| 3931 |
WriteBuffer(pChan, (PUSHORT)Srb->Cdb, 6); |
| 3932 |
|
| 3933 |
/* |
| 3934 |
* If running on DMA mode, start BUS MASTER operation. |
| 3935 |
*/ |
| 3936 |
if (useDMA) |
| 3937 |
{ |
| 3938 |
/* |
| 3939 |
* If SCSIOP_READ command is sent to an Audio CD, error will be |
| 3940 |
* returned. But the error will be blocked by our controller if bus |
| 3941 |
* master operation started. So wait for a short period to check if |
| 3942 |
* error occurs. If error occurs, don't start bus master operation. |
| 3943 |
*/ |
| 3944 |
if (RevisionID == 0x10) |
| 3945 |
{ |
| 3946 |
for (i = 0; i < 500; i++) |
| 3947 |
{ |
| 3948 |
udelay(1); |
| 3949 |
statusByte = inb(bmAddress + 2); |
| 3950 |
if (statusByte & BM_STAT_FLG_INT) |
| 3951 |
{ |
| 3952 |
/* |
| 3953 |
* If error occurs, give up this round. |
| 3954 |
*/ |
| 3955 |
printk("AtapiSendCommand: Command failed. Don't start bus master."); |
| 3956 |
printk("status=%x, i=%ld\n", statusByte, i); |
| 3957 |
|
| 3958 |
pChan->ExpectingInterrupt = TRUE; |
| 3959 |
return SRB_STATUS_PENDING; |
| 3960 |
} |
| 3961 |
} |
| 3962 |
} |
| 3963 |
|
| 3964 |
if (Srb->SrbFlags & SRB_FLAGS_DATA_IN) |
| 3965 |
{ |
| 3966 |
outb(BM_CMD_FLG_START | BM_CMD_FLG_WRTTOMEM, bmAddress); |
| 3967 |
} |
| 3968 |
else if (Srb->SrbFlags & SRB_FLAGS_DATA_OUT) |
| 3969 |
{ |
| 3970 |
outb(BM_CMD_FLG_START | BM_CMD_FLG_WRTTODSK, bmAddress); |
| 3971 |
} |
| 3972 |
} /* end if (useDMA) */ |
| 3973 |
|
| 3974 |
/* |
| 3975 |
* Indicate expecting an interrupt and wait for it. |
| 3976 |
*/ |
| 3977 |
pChan->ExpectingInterrupt = TRUE; |
| 3978 |
|
| 3979 |
return SRB_STATUS_PENDING; |
| 3980 |
|
| 3981 |
} /* end AtapiSendCommand */ |
| 3982 |
|
| 3983 |
/************************************************************************ |
| 3984 |
* Program ATA registers for IDE disk transfer. |
| 3985 |
************************************************************************/ |
| 3986 |
ULONG |
| 3987 |
IdeSendCommand(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 3988 |
{ |
| 3989 |
|
| 3990 |
UCHAR statusByte; |
| 3991 |
ULONG status; |
| 3992 |
ULONG i; |
| 3993 |
Scsi_Cmnd * pREQ; |
| 3994 |
unsigned char * request_buffer; |
| 3995 |
PINQUIRYDATA inquiryData; |
| 3996 |
|
| 3997 |
pREQ = Srb->pREQ; |
| 3998 |
status = SRB_STATUS_SUCCESS; |
| 3999 |
statusByte = 0; |
| 4000 |
|
| 4001 |
switch (Srb->Cdb[0]) |
| 4002 |
{ |
| 4003 |
case SCSIOP_INQUIRY: |
| 4004 |
dprintk("SCSIOP_INQUIRY\n"); |
| 4005 |
|
| 4006 |
/* |
| 4007 |
* Filter out all TIDs but 0 and 1 since this is an IDE interface |
| 4008 |
* which support up to two devices. |
| 4009 |
*/ |
| 4010 |
if ((pREQ->lun != 0) || |
| 4011 |
(!pChan->DeviceFlags[pREQ->target & 1] & DFLAGS_DEVICE_PRESENT)) |
| 4012 |
{ |
| 4013 |
/* |
| 4014 |
* Indicate no device found at this address. |
| 4015 |
*/ |
| 4016 |
status = SRB_STATUS_INVALID_TARGET_ID; |
| 4017 |
break; |
| 4018 |
} |
| 4019 |
else |
| 4020 |
{ |
| 4021 |
request_buffer = Srb->DataBuffer; |
| 4022 |
inquiryData = Srb->DataBuffer; |
| 4023 |
|
| 4024 |
/* |
| 4025 |
* Zero INQUIRY data structure. |
| 4026 |
*/ |
| 4027 |
memset(request_buffer, 0, Srb->DataTransferLength); |
| 4028 |
|
| 4029 |
/* |
| 4030 |
* Standard IDE interface only supports disks. |
| 4031 |
*/ |
| 4032 |
inquiryData->DeviceType = DIRECT_ACCESS_DEVICE; |
| 4033 |
|
| 4034 |
/* |
| 4035 |
* Device type modifer. |
| 4036 |
*/ |
| 4037 |
request_buffer[1] = 0; |
| 4038 |
|
| 4039 |
/* |
| 4040 |
* No ANSI/ISO compliance. |
| 4041 |
*/ |
| 4042 |
request_buffer[2] = 0; |
| 4043 |
|
| 4044 |
/* |
| 4045 |
* Additional length. |
| 4046 |
*/ |
| 4047 |
request_buffer[4] = 31; |
| 4048 |
memcpy(&request_buffer[8], "ITE ", 8); |
| 4049 |
memcpy(&request_buffer[16], "IT8212X ", 16); |
| 4050 |
memcpy(&request_buffer[32], "1.3", 3); |
| 4051 |
|
| 4052 |
/* |
| 4053 |
* Set the removable bit, if applicable. |
| 4054 |
*/ |
| 4055 |
if (pChan->DeviceFlags[pREQ->target & 1] & DFLAGS_REMOVABLE_DRIVE) |
| 4056 |
{ |
| 4057 |
inquiryData->RemovableMedia = 1; |
| 4058 |
} |
| 4059 |
|
| 4060 |
status = SRB_STATUS_SUCCESS; |
| 4061 |
} |
| 4062 |
|
| 4063 |
break; |
| 4064 |
|
| 4065 |
case SCSIOP_MODE_SENSE: |
| 4066 |
status = SRB_STATUS_INVALID_REQUEST; |
| 4067 |
break; |
| 4068 |
|
| 4069 |
case SCSIOP_TEST_UNIT_READY: |
| 4070 |
status = SRB_STATUS_SUCCESS; |
| 4071 |
break; |
| 4072 |
|
| 4073 |
case SCSIOP_READ_CAPACITY: |
| 4074 |
/* |
| 4075 |
* Claim 512 byte blocks (big-endian). |
| 4076 |
*/ |
| 4077 |
((PREAD_CAPACITY_DATA)Srb->DataBuffer)->BytesPerBlock = 0x20000; |
| 4078 |
|
| 4079 |
/* |
| 4080 |
* Calculate last sector. |
| 4081 |
*/ |
| 4082 |
if (pChan->IdentifyData[pREQ->target & 0x01].UserAddressableSectors == 0x0FFFFFFF) |
| 4083 |
{ |
| 4084 |
i = pChan->IdentifyData[pREQ->target & 0x01].Capacity_48bit_LOW - 1; |
| 4085 |
} |
| 4086 |
else |
| 4087 |
{ |
| 4088 |
i = pChan->IdentifyData[pREQ->target & 0x01].UserAddressableSectors - 1; |
| 4089 |
} |
| 4090 |
|
| 4091 |
((PREAD_CAPACITY_DATA)Srb->DataBuffer)->LogicalBlockAddress = |
| 4092 |
(((PUCHAR)&i)[0] << 24) | (((PUCHAR)&i)[1] << 16) | |
| 4093 |
(((PUCHAR)&i)[2] << 8) | ((PUCHAR)&i)[3]; |
| 4094 |
|
| 4095 |
status = SRB_STATUS_SUCCESS; |
| 4096 |
break; |
| 4097 |
|
| 4098 |
case SCSIOP_VERIFY: |
| 4099 |
status = IdeVerify(pChan, Srb); |
| 4100 |
break; |
| 4101 |
|
| 4102 |
case SCSIOP_READ: |
| 4103 |
case SCSIOP_WRITE: |
| 4104 |
status = IT8212ReadWrite(pChan, Srb); |
| 4105 |
break; |
| 4106 |
|
| 4107 |
case SCSIOP_START_STOP_UNIT: |
| 4108 |
/* |
| 4109 |
* Determine what type of operation we should perform |
| 4110 |
*/ |
| 4111 |
status = SRB_STATUS_SUCCESS; |
| 4112 |
break; |
| 4113 |
|
| 4114 |
case SCSIOP_REQUEST_SENSE: |
| 4115 |
/* |
| 4116 |
* This function makes sense buffers to report the results |
| 4117 |
* of the original GET_MEDIA_STATUS command |
| 4118 |
*/ |
| 4119 |
status = SRB_STATUS_INVALID_REQUEST; |
| 4120 |
break; |
| 4121 |
|
| 4122 |
default: |
| 4123 |
printk("IdeSendCommand: Unsupported command %x\n", Srb->Cdb[0]); |
| 4124 |
status = SRB_STATUS_INVALID_REQUEST; |
| 4125 |
} /* end switch */ |
| 4126 |
|
| 4127 |
return status; |
| 4128 |
|
| 4129 |
} /* end IdeSendCommand */ |
| 4130 |
|
| 4131 |
/************************************************************************ |
| 4132 |
* This routine is called from the SCSI port driver synchronized with |
| 4133 |
* the kernel to start an IO request. If the current SRB is busy, return |
| 4134 |
* FALSE, else return TURE. |
| 4135 |
************************************************************************/ |
| 4136 |
BOOLEAN |
| 4137 |
AtapiStartIo(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 4138 |
{ |
| 4139 |
|
| 4140 |
ULONG status = 0; |
| 4141 |
|
| 4142 |
/* |
| 4143 |
* Determine which function. |
| 4144 |
*/ |
| 4145 |
switch (Srb->Function) |
| 4146 |
{ |
| 4147 |
case SRB_FUNCTION_EXECUTE_SCSI: |
| 4148 |
/* |
| 4149 |
* Sanity check. Only one request can be outstanding on a |
| 4150 |
* controller. |
| 4151 |
*/ |
| 4152 |
if (pChan->CurrentSrb) |
| 4153 |
{ |
| 4154 |
printk("AtapiStartIo:Already have a request!\n"); |
| 4155 |
status = SRB_STATUS_BUSY; |
| 4156 |
Srb->SrbStatus = SRB_STATUS_BUSY; |
| 4157 |
goto busy; |
| 4158 |
} |
| 4159 |
|
| 4160 |
/* |
| 4161 |
* Indicate that a request is active on the controller. |
| 4162 |
*/ |
| 4163 |
pChan->CurrentSrb = Srb; |
| 4164 |
Srb->SrbStatus = SRB_STATUS_PENDING; |
| 4165 |
|
| 4166 |
/* |
| 4167 |
* Send command to device. |
| 4168 |
*/ |
| 4169 |
if (pChan->DeviceFlags[Srb->TargetId & 1] & DFLAGS_ATAPI_DEVICE) |
| 4170 |
{ |
| 4171 |
/* |
| 4172 |
* If this is ATAPI device. |
| 4173 |
*/ |
| 4174 |
status = AtapiSendCommand(pChan, Srb); |
| 4175 |
} |
| 4176 |
else if (pChan->DeviceFlags[Srb->TargetId & 1] & DFLAGS_DEVICE_PRESENT) |
| 4177 |
{ |
| 4178 |
/* |
| 4179 |
* If this is IDE device. |
| 4180 |
*/ |
| 4181 |
status = IdeSendCommand(pChan, Srb); |
| 4182 |
} |
| 4183 |
else |
| 4184 |
{ |
| 4185 |
/* |
| 4186 |
* Nothing else. |
| 4187 |
*/ |
| 4188 |
status = SRB_STATUS_SELECTION_TIMEOUT; |
| 4189 |
} |
| 4190 |
|
| 4191 |
break; |
| 4192 |
|
| 4193 |
case SRB_FUNCTION_IO_CONTROL: |
| 4194 |
/* |
| 4195 |
* IO control function. |
| 4196 |
*/ |
| 4197 |
printk("AtapiStartIo: IO control\n"); |
| 4198 |
break; |
| 4199 |
|
| 4200 |
default: |
| 4201 |
/* |
| 4202 |
* Indicate unsupported command. |
| 4203 |
*/ |
| 4204 |
status = SRB_STATUS_INVALID_REQUEST; |
| 4205 |
break; |
| 4206 |
|
| 4207 |
} /* end switch */ |
| 4208 |
|
| 4209 |
busy: |
| 4210 |
if (status != SRB_STATUS_PENDING) |
| 4211 |
{ |
| 4212 |
/* |
| 4213 |
* Set status in SRB. |
| 4214 |
*/ |
| 4215 |
Srb->SrbStatus = (UCHAR)status; |
| 4216 |
dprintk("AtapiStartIo: status=%lx\n", status); |
| 4217 |
TaskDone(pChan, Srb); |
| 4218 |
} |
| 4219 |
|
| 4220 |
return TRUE; |
| 4221 |
|
| 4222 |
} /* end AtapiStartIo */ |
| 4223 |
|
| 4224 |
/************************************************************************ |
| 4225 |
* Convert Scsi_Cmnd structure to SCSI_REQUEST_BLOCK |
| 4226 |
************************************************************************/ |
| 4227 |
void |
| 4228 |
MapRequest(Scsi_Cmnd * pREQ, PSCSI_REQUEST_BLOCK Srb) |
| 4229 |
{ |
| 4230 |
|
| 4231 |
Srb->Length = sizeof(SCSI_REQUEST_BLOCK); |
| 4232 |
Srb->CdbLength = pREQ->cmd_len; |
| 4233 |
Srb->TargetId = pREQ->target; |
| 4234 |
Srb->Lun = pREQ->lun; |
| 4235 |
Srb->UseSg = pREQ->use_sg; |
| 4236 |
|
| 4237 |
/* |
| 4238 |
* Copy the actual command from Scsi_Cmnd to CDB. |
| 4239 |
*/ |
| 4240 |
memcpy(Srb->Cdb, pREQ->cmnd, Srb->CdbLength); |
| 4241 |
|
| 4242 |
/* |
| 4243 |
* Always the SCSI_FUNCTION_EXECUTE_SCSI now. |
| 4244 |
*/ |
| 4245 |
Srb->Function = SRB_FUNCTION_EXECUTE_SCSI; |
| 4246 |
|
| 4247 |
Srb->SrbStatus = 0; |
| 4248 |
Srb->ScsiStatus = 0; |
| 4249 |
Srb->SenseInfoBufferLength = 16; |
| 4250 |
|
| 4251 |
/* |
| 4252 |
* The CDB's first byte is operation code. |
| 4253 |
*/ |
| 4254 |
if ((Srb->Cdb[0] == SCSIOP_WRITE6) || (Srb->Cdb[0] == SCSIOP_WRITE) || |
| 4255 |
(Srb->Cdb[0] == SCSIOP_MODE_SELECT10)) |
| 4256 |
{ |
| 4257 |
Srb->SrbFlags = SRB_FLAGS_DATA_OUT; |
| 4258 |
} |
| 4259 |
else |
| 4260 |
{ |
| 4261 |
Srb->SrbFlags = SRB_FLAGS_DATA_IN; |
| 4262 |
} |
| 4263 |
|
| 4264 |
Srb->TimeOutValue = 0; |
| 4265 |
Srb->SenseInfoBuffer = pREQ->sense_buffer; |
| 4266 |
|
| 4267 |
if (Srb->Cdb[0] == SCSIOP_REQUEST_SENSE) |
| 4268 |
{ |
| 4269 |
Srb->DataTransferLength = 0x40; |
| 4270 |
Srb->DataBuffer = pREQ->sense_buffer; |
| 4271 |
} |
| 4272 |
else |
| 4273 |
{ |
| 4274 |
Srb->DataTransferLength = pREQ->request_bufflen; |
| 4275 |
Srb->DataBuffer = pREQ->request_buffer; |
| 4276 |
} |
| 4277 |
|
| 4278 |
if (pREQ->use_sg) |
| 4279 |
{ |
| 4280 |
Srb->WorkingFlags |= SRB_WFLAGS_USE_SG; |
| 4281 |
} |
| 4282 |
|
| 4283 |
Srb->pREQ = pREQ; |
| 4284 |
|
| 4285 |
} /* end MapRequest */ |
| 4286 |
|
| 4287 |
/************************************************************************ |
| 4288 |
* Function: void ite_watch_timer(PChannel pChan) |
| 4289 |
* Description: WatchDog timer |
| 4290 |
* Returns: None |
| 4291 |
************************************************************************/ |
| 4292 |
void |
| 4293 |
ite_watch_timer(PChannel pChan) |
| 4294 |
{ |
| 4295 |
|
| 4296 |
unsigned long flags; |
| 4297 |
Scsi_Cmnd * pREQ; |
| 4298 |
PSCSI_REQUEST_BLOCK Srb; |
| 4299 |
|
| 4300 |
printk("ite_watch_timer enter\n"); |
| 4301 |
|
| 4302 |
spin_lock_irqsave (&io_request_lock, flags); |
| 4303 |
|
| 4304 |
Srb = pChan->CurrentSrb; |
| 4305 |
if (Srb) { pREQ = Srb->pREQ; } |
| 4306 |
else { pREQ = NULL; } |
| 4307 |
|
| 4308 |
spin_unlock_irqrestore (&io_request_lock, flags); |
| 4309 |
|
| 4310 |
printk("ite_watch_timer exit\n"); |
| 4311 |
|
| 4312 |
} /* end ite_watch_timer */ |
| 4313 |
|
| 4314 |
/************************************************************************ |
| 4315 |
* Function: void iteretry(PChannel pChan) |
| 4316 |
* Description: This function will be call after waitting 1 ticks (1 tick |
| 4317 |
* = 1/Hz second). It will execute retry operation. |
| 4318 |
* Returns: None |
| 4319 |
************************************************************************/ |
| 4320 |
void |
| 4321 |
iteretry(PChannel pChan) |
| 4322 |
{ |
| 4323 |
|
| 4324 |
Scsi_Cmnd * pREQ; |
| 4325 |
unsigned long flags; |
| 4326 |
|
| 4327 |
spin_lock_irqsave(&io_request_lock, flags); |
| 4328 |
|
| 4329 |
if (pChan->CurrentSrb) |
| 4330 |
{ |
| 4331 |
pREQ = pChan->CurrentSrb->pREQ; |
| 4332 |
printk("##iteretry##\n"); |
| 4333 |
TaskStart(pChan, pREQ); |
| 4334 |
} |
| 4335 |
|
| 4336 |
spin_unlock_irqrestore(&io_request_lock, flags); |
| 4337 |
|
| 4338 |
} /* end iteretry */ |
| 4339 |
|
| 4340 |
/************************************************************************ |
| 4341 |
* A task execution has been done. For OS request, we need to Notify OS |
| 4342 |
* and invoke next take which wait at queue |
| 4343 |
************************************************************************/ |
| 4344 |
void |
| 4345 |
TaskDone(PChannel pChan, PSCSI_REQUEST_BLOCK Srb) |
| 4346 |
{ |
| 4347 |
|
| 4348 |
Scsi_Cmnd * pREQ = Srb->pREQ; |
| 4349 |
|
| 4350 |
pChan->CurrentSrb = NULL; |
| 4351 |
pChan->RetryCount = 0; |
| 4352 |
|
| 4353 |
switch (SRB_STATUS(Srb->SrbStatus)) |
| 4354 |
{ |
| 4355 |
case SRB_STATUS_SUCCESS: |
| 4356 |
pREQ->result = (DID_OK << 16); |
| 4357 |
break; |
| 4358 |
|
| 4359 |
case SRB_STATUS_SELECTION_TIMEOUT: |
| 4360 |
pREQ->result = (DID_NO_CONNECT << 16); |
| 4361 |
break; |
| 4362 |
|
| 4363 |
case SRB_STATUS_BUSY: |
| 4364 |
pREQ->result = (DID_BUS_BUSY << 16); |
| 4365 |
break; |
| 4366 |
|
| 4367 |
case SRB_STATUS_BUS_RESET: |
| 4368 |
pREQ->result = (DID_RESET << 16); |
| 4369 |
break; |
| 4370 |
|
| 4371 |
case SRB_STATUS_INVALID_TARGET_ID: |
| 4372 |
case SRB_STATUS_INVALID_PATH_ID: |
| 4373 |
case SRB_STATUS_INVALID_LUN: |
| 4374 |
case SRB_STATUS_NO_HBA: |
| 4375 |
pREQ->result = (DID_BAD_TARGET << 16); |
| 4376 |
break; |
| 4377 |
|
| 4378 |
case SRB_STATUS_NO_DEVICE: |
| 4379 |
pREQ->result = (DID_BAD_TARGET << 16); |
| 4380 |
break; |
| 4381 |
|
| 4382 |
case SRB_STATUS_ERROR: |
| 4383 |
pREQ->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | |
| 4384 |
(CHECK_CONDITION << 1); |
| 4385 |
break; |
| 4386 |
} |
| 4387 |
|
| 4388 |
dprintk("TaskDone(pChan=%p, pREQ=%p, result=%x)\n", |
| 4389 |
pChan, pREQ, pREQ->result); |
| 4390 |
|
| 4391 |
/* |
| 4392 |
* Notify OS that this OS request has been done. |
| 4393 |
*/ |
| 4394 |
pREQ->scsi_done(pREQ); |
| 4395 |
|
| 4396 |
/* |
| 4397 |
* Check the queue again. |
| 4398 |
*/ |
| 4399 |
TaskQueue(); |
| 4400 |
|
| 4401 |
} /* end TaskDone */ |
| 4402 |
|
| 4403 |
/************************************************************************ |
| 4404 |
* Start a command, doing convert first. |
| 4405 |
************************************************************************/ |
| 4406 |
void |
| 4407 |
TaskStart(PChannel pChan, Scsi_Cmnd *pREQ) |
| 4408 |
{ |
| 4409 |
|
| 4410 |
PSCSI_REQUEST_BLOCK Srb; |
| 4411 |
|
| 4412 |
dprintk("TaskStart(pChan=%p, pREQ=%p)\n", pChan, pREQ); |
| 4413 |
|
| 4414 |
Srb = &pChan->_Srb; |
| 4415 |
|
| 4416 |
/* |
| 4417 |
* Clear the SRB structure. |
| 4418 |
*/ |
| 4419 |
memset(Srb, 0, sizeof(SCSI_REQUEST_BLOCK)); |
| 4420 |
|
| 4421 |
/* |
| 4422 |
* Convert Scsi_Cmnd structure to SCSI_REQUEST_BLOCK. |
| 4423 |
*/ |
| 4424 |
MapRequest(pREQ, Srb); |
| 4425 |
|
| 4426 |
/* |
| 4427 |
* Start IDE I/O command. |
| 4428 |
*/ |
| 4429 |
AtapiStartIo(pChan, Srb); |
| 4430 |
|
| 4431 |
} /* end TaskStart */ |
| 4432 |
|
| 4433 |
/************************************************************************ |
| 4434 |
* Check if queue is empty. If there are request in queue, transfer the |
| 4435 |
* request to HIM's request and execute the request. |
| 4436 |
************************************************************************/ |
| 4437 |
void |
| 4438 |
TaskQueue(void) |
| 4439 |
{ |
| 4440 |
|
| 4441 |
unsigned long flags; |
| 4442 |
Scsi_Cmnd * SCpnt; |
| 4443 |
PChannel pChan; |
| 4444 |
PITE_ADAPTER pAdap; |
| 4445 |
|
| 4446 |
check_next: |
| 4447 |
|
| 4448 |
if (it8212_req_last != NULL) |
| 4449 |
{ |
| 4450 |
spin_lock_irqsave(&queue_request_lock, flags); |
| 4451 |
SCpnt = (Scsi_Cmnd *)it8212_req_last->SCp.ptr; |
| 4452 |
|
| 4453 |
if (it8212_req_last == SCpnt) |
| 4454 |
{ |
| 4455 |
it8212_req_last = NULL; |
| 4456 |
} |
| 4457 |
else |
| 4458 |
{ |
| 4459 |
it8212_req_last->SCp.ptr = (char *)SCpnt->SCp.ptr; |
| 4460 |
} |
| 4461 |
spin_unlock_irqrestore(&queue_request_lock, flags); |
| 4462 |
|
| 4463 |
pAdap = ite_adapters[0]; |
| 4464 |
|
| 4465 |
if (SCpnt->target < 2) pChan = &pAdap->IDEChannel[0]; |
| 4466 |
else pChan = &pAdap->IDEChannel[1]; |
| 4467 |
|
| 4468 |
/* |
| 4469 |
* Check the command. |
| 4470 |
*/ |
| 4471 |
if (SCpnt->host) |
| 4472 |
{ |
| 4473 |
if (SCpnt->channel != 0 || SCpnt->target >= 4) |
| 4474 |
{ |
| 4475 |
/* |
| 4476 |
* Returns that we have a bad target. |
| 4477 |
*/ |
| 4478 |
dprintk("BAD TARGET\n"); |
| 4479 |
SCpnt->result = (DID_BAD_TARGET << 16); |
| 4480 |
SCpnt->scsi_done(SCpnt); |
| 4481 |
goto check_next; |
| 4482 |
} |
| 4483 |
} |
| 4484 |
|
| 4485 |
TaskStart(pChan, SCpnt); |
| 4486 |
return; |
| 4487 |
} |
| 4488 |
|
| 4489 |
} /* end TaskQueue */ |
| 4490 |
|
| 4491 |
/**************************************************************** |
| 4492 |
* Name: iteraid_queuecommand |
| 4493 |
* Description: Process a queued command from the SCSI manager. |
| 4494 |
* Parameters: SCpnt - Pointer to SCSI command structure. |
| 4495 |
* done - Pointer to done function to call. |
| 4496 |
* Returns: Status code. |
| 4497 |
****************************************************************/ |
| 4498 |
int |
| 4499 |
iteraid_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) |
| 4500 |
{ |
| 4501 |
|
| 4502 |
unsigned long flags; |
| 4503 |
|
| 4504 |
dprintk("##Queuecommand enter##\n"); |
| 4505 |
|
| 4506 |
/* |
| 4507 |
* Hooks the done routine. |
| 4508 |
*/ |
| 4509 |
SCpnt->scsi_done = (void *)done; |
| 4510 |
|
| 4511 |
spin_lock_irqsave(&queue_request_lock, flags); |
| 4512 |
if (it8212_req_last == NULL) |
| 4513 |
{ |
| 4514 |
SCpnt->SCp.ptr = (char *)SCpnt; |
| 4515 |
} |
| 4516 |
else |
| 4517 |
{ |
| 4518 |
SCpnt->SCp.ptr = it8212_req_last->SCp.ptr; |
| 4519 |
it8212_req_last->SCp.ptr = (char *)SCpnt; |
| 4520 |
} |
| 4521 |
it8212_req_last = SCpnt; |
| 4522 |
spin_unlock_irqrestore(&queue_request_lock, flags); |
| 4523 |
|
| 4524 |
spin_lock_irqsave(&gio_request_lock, flags); |
| 4525 |
TaskQueue(); |
| 4526 |
spin_unlock_irqrestore(&gio_request_lock, flags); |
| 4527 |
|
| 4528 |
dprintk("@@Queuecommand exit@@\n"); |
| 4529 |
|
| 4530 |
return 0; |
| 4531 |
|
| 4532 |
} /* end iteraid_queuecommand */ |
| 4533 |
|
| 4534 |
/**************************************************************** |
| 4535 |
* Name: internal_done :LOCAL |
| 4536 |
* Description: Done handler for non-queued commands |
| 4537 |
* Parameters: SCpnt - Pointer to SCSI command structure. |
| 4538 |
* Returns: Nothing. |
| 4539 |
****************************************************************/ |
| 4540 |
static void |
| 4541 |
internal_done(Scsi_Cmnd * SCpnt) |
| 4542 |
{ |
| 4543 |
|
| 4544 |
SCpnt->SCp.Status++; |
| 4545 |
|
| 4546 |
} /* end internal_done */ |
| 4547 |
|
| 4548 |
/**************************************************************** |
| 4549 |
* Name: iteraid_command |
| 4550 |
* Description: Process a command from the SCSI manager. |
| 4551 |
* Parameters: SCpnt - Pointer to SCSI command structure. |
| 4552 |
* Returns: Status code. |
| 4553 |
****************************************************************/ |
| 4554 |
int |
| 4555 |
iteraid_command(Scsi_Cmnd *SCpnt) |
| 4556 |
{ |
| 4557 |
|
| 4558 |
DWORD timeout; |
| 4559 |
|
| 4560 |
SCpnt->SCp.Status = 0; |
| 4561 |
iteraid_queuecommand(SCpnt, internal_done); |
| 4562 |
|
| 4563 |
/* |
| 4564 |
* Should be longer than hard-reset time. |
| 4565 |
*/ |
| 4566 |
timeout = jiffies + 60 * HZ; |
| 4567 |
while (!SCpnt->SCp.Status && time_before(jiffies, timeout)) |
| 4568 |
{ |
| 4569 |
barrier(); |
| 4570 |
} |
| 4571 |
|
| 4572 |
if (!SCpnt->SCp.Status) SCpnt->result = (DID_ERROR << 16); |
| 4573 |
|
| 4574 |
return SCpnt->result; |
| 4575 |
|
| 4576 |
} /* end iteraid_command */ |
| 4577 |
|
| 4578 |
/************************************************************************ |
| 4579 |
* Enables disables media status notification |
| 4580 |
************************************************************************/ |
| 4581 |
void |
| 4582 |
IdeMediaStatus(BOOLEAN EnableMSN, PChannel pChan, ULONG Device) |
| 4583 |
{ |
| 4584 |
|
| 4585 |
UCHAR statusByte; |
| 4586 |
UCHAR errorByte; |
| 4587 |
|
| 4588 |
statusByte = 0; |
| 4589 |
|
| 4590 |
if (EnableMSN == TRUE) |
| 4591 |
{ |
| 4592 |
/* |
| 4593 |
* If supported enable Media Status Notification support. |
| 4594 |
*/ |
| 4595 |
if ((pChan->DeviceFlags[Device] & DFLAGS_REMOVABLE_DRIVE)) |
| 4596 |
{ |
| 4597 |
outb((UCHAR) (0x95), pChan->io_ports[IDE_FEATURE_OFFSET]); |
| 4598 |
outb(IDE_COMMAND_ENABLE_MEDIA_STATUS, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 4599 |
|
| 4600 |
WaitOnBaseBusy(pChan, statusByte); |
| 4601 |
|
| 4602 |
if (statusByte & IDE_STATUS_ERROR) |
| 4603 |
{ |
| 4604 |
/* |
| 4605 |
* Read the error register. |
| 4606 |
*/ |
| 4607 |
errorByte = inb(pChan->io_ports[IDE_ERROR_OFFSET]); |
| 4608 |
|
| 4609 |
printk("Error enabling media status. Status %u, error byte %u\n", |
| 4610 |
statusByte, errorByte); |
| 4611 |
} |
| 4612 |
else |
| 4613 |
{ |
| 4614 |
pChan->DeviceFlags[Device] |= DFLAGS_MEDIA_STATUS_ENABLED; |
| 4615 |
printk("Media Status Notification Supported\n"); |
| 4616 |
pChan->ReturningMediaStatus = 0; |
| 4617 |
} |
| 4618 |
} |
| 4619 |
} |
| 4620 |
else /* end if EnableMSN == TRUE */ |
| 4621 |
{ |
| 4622 |
/* |
| 4623 |
* Disable if previously enabled. |
| 4624 |
*/ |
| 4625 |
if ((pChan->DeviceFlags[Device] & DFLAGS_MEDIA_STATUS_ENABLED)) |
| 4626 |
{ |
| 4627 |
outb((UCHAR)(0x31), pChan->io_ports[IDE_FEATURE_OFFSET]); |
| 4628 |
outb(IDE_COMMAND_ENABLE_MEDIA_STATUS, |
| 4629 |
pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 4630 |
|
| 4631 |
WaitOnBaseBusy(pChan, statusByte); |
| 4632 |
pChan->DeviceFlags[Device] &= ~DFLAGS_MEDIA_STATUS_ENABLED; |
| 4633 |
} |
| 4634 |
} |
| 4635 |
|
| 4636 |
} /* end IdeMediaStatus */ |
| 4637 |
|
| 4638 |
/************************************************************************ |
| 4639 |
* Add watchdog timer. |
| 4640 |
************************************************************************/ |
| 4641 |
void |
| 4642 |
SetWatchDogTimer(PChannel pChan) |
| 4643 |
{ |
| 4644 |
|
| 4645 |
pChan->watch_timer->expires = jiffies + 3 * HZ; |
| 4646 |
add_timer(pChan->watch_timer); |
| 4647 |
|
| 4648 |
} /* end SetWatchDogTimer */ |
| 4649 |
|
| 4650 |
/************************************************************************ |
| 4651 |
* Cancel the watchdog timer. |
| 4652 |
************************************************************************/ |
| 4653 |
void |
| 4654 |
CancelWatchDogTimer(PChannel pChan) |
| 4655 |
{ |
| 4656 |
|
| 4657 |
del_timer(pChan->watch_timer); |
| 4658 |
|
| 4659 |
} /* end CancelWatchDogTimer */ |
| 4660 |
|
| 4661 |
/************************************************************************ |
| 4662 |
* Issue IDENTIFY command to a device |
| 4663 |
* Either the standard (EC) or the ATAPI packet (A1) IDENTIFY. |
| 4664 |
************************************************************************/ |
| 4665 |
BOOLEAN |
| 4666 |
IssueIdentify(PChannel pChan, UCHAR DeviceNumber, UCHAR Command) |
| 4667 |
{ |
| 4668 |
|
| 4669 |
ULONG i, j; |
| 4670 |
UCHAR statusByte = 0; |
| 4671 |
|
| 4672 |
/* |
| 4673 |
* Check that the status register makes sense. |
| 4674 |
*/ |
| 4675 |
GetBaseStatus(pChan, statusByte); |
| 4676 |
|
| 4677 |
if (Command == IDE_COMMAND_IDENTIFY) |
| 4678 |
{ |
| 4679 |
/* |
| 4680 |
* Mask status byte ERROR bits. |
| 4681 |
*/ |
| 4682 |
statusByte &= ~(IDE_STATUS_ERROR | IDE_STATUS_INDEX); |
| 4683 |
|
| 4684 |
printk("IssueIdentify: Checking for IDE. Status (%x)\n", statusByte); |
| 4685 |
|
| 4686 |
/* |
| 4687 |
* Check if register value is reasonable. |
| 4688 |
*/ |
| 4689 |
if (statusByte != IDE_STATUS_IDLE) |
| 4690 |
{ |
| 4691 |
/* |
| 4692 |
* Reset the channel. |
| 4693 |
*/ |
| 4694 |
printk("IssueIdentify: Resetting channel.\n"); |
| 4695 |
IdeHardReset(pChan, statusByte); |
| 4696 |
|
| 4697 |
outb((UCHAR)((DeviceNumber << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 4698 |
GetBaseStatus(pChan, statusByte); |
| 4699 |
statusByte &= ~IDE_STATUS_INDEX; |
| 4700 |
|
| 4701 |
if (statusByte != IDE_STATUS_IDLE) |
| 4702 |
{ |
| 4703 |
/* |
| 4704 |
* Give up on this. |
| 4705 |
*/ |
| 4706 |
printk("IssueIdentify (IDE): Disk[%d] not ready. Status=0x%x\n", |
| 4707 |
DeviceNumber, statusByte); |
| 4708 |
return FALSE; |
| 4709 |
} |
| 4710 |
} |
| 4711 |
} |
| 4712 |
else |
| 4713 |
{ |
| 4714 |
dprintk("IssueIdentify: Checking for ATAPI. Status (%x)\n", statusByte); |
| 4715 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ)) |
| 4716 |
{ |
| 4717 |
/* |
| 4718 |
* Reset the device. |
| 4719 |
*/ |
| 4720 |
dprintk("IssueIdentify: Resetting device.\n"); |
| 4721 |
AtapiSoftReset(pChan, DeviceNumber); |
| 4722 |
|
| 4723 |
outb((UCHAR)((DeviceNumber << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 4724 |
GetBaseStatus(pChan, statusByte); |
| 4725 |
if (statusByte != 0) |
| 4726 |
{ |
| 4727 |
/* |
| 4728 |
* Give up on this. |
| 4729 |
*/ |
| 4730 |
printk("IssueIdentify (ATAPI): Disk[%d] not ready. Status=0x%x\n", DeviceNumber, statusByte); |
| 4731 |
return FALSE; |
| 4732 |
} |
| 4733 |
} |
| 4734 |
} |
| 4735 |
|
| 4736 |
for (j = 0; j < 2; j++) |
| 4737 |
{ |
| 4738 |
/* |
| 4739 |
* Wait for device ready (Not Busy and Not DRQ). |
| 4740 |
*/ |
| 4741 |
outb((UCHAR)((DeviceNumber << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 4742 |
WaitForDeviceReady(pChan, statusByte); |
| 4743 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ)) |
| 4744 |
{ |
| 4745 |
printk("IssueIdentify: Disk[%d] not ready. Status=0x%x\n", DeviceNumber, statusByte); |
| 4746 |
continue; |
| 4747 |
} |
| 4748 |
|
| 4749 |
/* |
| 4750 |
* Send IDENTIFY command. |
| 4751 |
*/ |
| 4752 |
outb(Command, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 4753 |
|
| 4754 |
/* |
| 4755 |
* Wait for DRQ. |
| 4756 |
*/ |
| 4757 |
WaitForBaseDrq(pChan, statusByte); |
| 4758 |
if (!(statusByte & IDE_STATUS_DRQ)) |
| 4759 |
{ |
| 4760 |
printk("IssueIdentify: Disk[%d] DRQ never asserted. Status=%x\n", DeviceNumber, statusByte); |
| 4761 |
|
| 4762 |
/* |
| 4763 |
* Give one more chance. |
| 4764 |
*/ |
| 4765 |
if (Command == IDE_COMMAND_IDENTIFY) |
| 4766 |
{ |
| 4767 |
IdeHardReset(pChan, statusByte); |
| 4768 |
} |
| 4769 |
else |
| 4770 |
{ |
| 4771 |
AtapiSoftReset(pChan, DeviceNumber); |
| 4772 |
} |
| 4773 |
} |
| 4774 |
else |
| 4775 |
{ |
| 4776 |
break; |
| 4777 |
} |
| 4778 |
} |
| 4779 |
|
| 4780 |
/* |
| 4781 |
* Check for error on really stupid master devices that assert random |
| 4782 |
* patterns of bits in the status register at the slave address. |
| 4783 |
*/ |
| 4784 |
outb((UCHAR)((DeviceNumber << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 4785 |
GetBaseStatus(pChan, statusByte); |
| 4786 |
if (statusByte & IDE_STATUS_ERROR) |
| 4787 |
{ |
| 4788 |
printk("IssueIdentify: Disk[%d] returns error status\n", DeviceNumber); |
| 4789 |
return FALSE; |
| 4790 |
} |
| 4791 |
|
| 4792 |
dprintk("IssueIdentify: Status before read words %x\n", statusByte); |
| 4793 |
|
| 4794 |
/* |
| 4795 |
* Suck out 256 words. After waiting for one model that asserts busy |
| 4796 |
* after receiving the Packet Identify command. |
| 4797 |
*/ |
| 4798 |
WaitOnBusy(pChan, statusByte); |
| 4799 |
|
| 4800 |
if (!(statusByte & IDE_STATUS_DRQ)) { return FALSE; } |
| 4801 |
|
| 4802 |
ReadBuffer(pChan, (PUSHORT)&pChan->FullIdentifyData, 256); |
| 4803 |
|
| 4804 |
/* |
| 4805 |
* Check out a few capabilities / limitations of the device. |
| 4806 |
* 01/29/2003 |
| 4807 |
*/ |
| 4808 |
if (pChan->FullIdentifyData.SpecialFunctionsEnabled & 1) |
| 4809 |
{ |
| 4810 |
/* |
| 4811 |
* Determine if this drive supports the MSN functions. |
| 4812 |
*/ |
| 4813 |
printk("Marking drive %x as removable. SFE = %x\n", |
| 4814 |
DeviceNumber, pChan->FullIdentifyData.SpecialFunctionsEnabled); |
| 4815 |
pChan->DeviceFlags[DeviceNumber] |= DFLAGS_REMOVABLE_DRIVE; |
| 4816 |
} |
| 4817 |
|
| 4818 |
memcpy(&pChan->IdentifyData[DeviceNumber], &pChan->FullIdentifyData, |
| 4819 |
sizeof(IDENTIFY_DATA2)); |
| 4820 |
|
| 4821 |
if (pChan->IdentifyData[DeviceNumber].GeneralConfiguration & 0x20 && |
| 4822 |
Command != IDE_COMMAND_IDENTIFY) |
| 4823 |
{ |
| 4824 |
/* |
| 4825 |
* This device interrupts with the assertion of DRQ after receiving |
| 4826 |
* Atapi Packet Command. |
| 4827 |
*/ |
| 4828 |
pChan->DeviceFlags[DeviceNumber] |= DFLAGS_INT_DRQ; |
| 4829 |
|
| 4830 |
dprintk(KERN_NOTICE "Device interrupts on assertion of DRQ.\n"); |
| 4831 |
} |
| 4832 |
else |
| 4833 |
{ |
| 4834 |
dprintk(KERN_NOTICE "Device does't interrupt on assertion of DRQ.\n"); |
| 4835 |
} |
| 4836 |
|
| 4837 |
if (((pChan->IdentifyData[DeviceNumber].GeneralConfiguration & 0xF00) |
| 4838 |
== 0x100) && Command != IDE_COMMAND_IDENTIFY) |
| 4839 |
{ |
| 4840 |
/* |
| 4841 |
* This is a tape. |
| 4842 |
*/ |
| 4843 |
pChan->DeviceFlags[DeviceNumber] |= DFLAGS_TAPE_DEVICE; |
| 4844 |
printk(KERN_NOTICE "IssueIdentify: Device is a tape drive.\n"); |
| 4845 |
} |
| 4846 |
else |
| 4847 |
{ |
| 4848 |
dprintk(KERN_NOTICE "IssueIdentify: Device is not a tape drive.\n"); |
| 4849 |
} |
| 4850 |
|
| 4851 |
/* |
| 4852 |
* Work around for some IDE and one model Atapi that will present more |
| 4853 |
* then 256 bytes for the Identify data. |
| 4854 |
*/ |
| 4855 |
WaitOnBaseBusy(pChan, statusByte); |
| 4856 |
|
| 4857 |
for (i = 0; i < 0x10000; i++) |
| 4858 |
{ |
| 4859 |
GetStatus(pChan, statusByte); |
| 4860 |
|
| 4861 |
if (statusByte & IDE_STATUS_DRQ) |
| 4862 |
{ |
| 4863 |
/* |
| 4864 |
* Suck out any remaining bytes and throw away. |
| 4865 |
*/ |
| 4866 |
inw(pChan->io_ports[IDE_DATA_OFFSET]); |
| 4867 |
} |
| 4868 |
else |
| 4869 |
{ |
| 4870 |
break; |
| 4871 |
} |
| 4872 |
} |
| 4873 |
|
| 4874 |
return TRUE; |
| 4875 |
|
| 4876 |
} /* end IssueIdentify() */ |
| 4877 |
|
| 4878 |
/************************************************************************ |
| 4879 |
* Check this is the IDE or ATAPI disk then identify it |
| 4880 |
************************************************************************/ |
| 4881 |
static BOOLEAN |
| 4882 |
iteraid_find_device(PChannel pChan, UCHAR channel) |
| 4883 |
{ |
| 4884 |
|
| 4885 |
BOOLEAN deviceResponded = FALSE; |
| 4886 |
UCHAR deviceNumber; |
| 4887 |
UCHAR signatureLow; |
| 4888 |
UCHAR signatureHigh; |
| 4889 |
UCHAR statusByte = 0; |
| 4890 |
|
| 4891 |
|
| 4892 |
/* |
| 4893 |
* Clear expecting interrupt flag and current SRB field. |
| 4894 |
*/ |
| 4895 |
pChan->ExpectingInterrupt = FALSE; |
| 4896 |
pChan->CurrentSrb = NULL; |
| 4897 |
|
| 4898 |
/* |
| 4899 |
* Search for devices in each channel. |
| 4900 |
*/ |
| 4901 |
for (deviceNumber = 0; deviceNumber < 2; deviceNumber++) |
| 4902 |
{ |
| 4903 |
/* |
| 4904 |
* Select the device. |
| 4905 |
*/ |
| 4906 |
outb((UCHAR)((deviceNumber << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 4907 |
|
| 4908 |
/* |
| 4909 |
* Disable interrupts during initialization. |
| 4910 |
*/ |
| 4911 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 4912 |
|
| 4913 |
/* |
| 4914 |
* Check here for some SCSI adapters that incorporate IDE emulation. |
| 4915 |
*/ |
| 4916 |
statusByte = inb(pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 4917 |
|
| 4918 |
/* |
| 4919 |
* Do soft reset on selected device. (AtapiSoftReset) |
| 4920 |
*/ |
| 4921 |
AtapiSoftReset(pChan, deviceNumber); |
| 4922 |
WaitOnBusy(pChan, statusByte); |
| 4923 |
|
| 4924 |
signatureLow = inb(pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 4925 |
signatureHigh = inb(pChan->io_ports[IDE_HCYL_OFFSET]); |
| 4926 |
|
| 4927 |
if (signatureLow == 0x14 && signatureHigh == 0xEB) |
| 4928 |
{ |
| 4929 |
/* |
| 4930 |
* ATAPI signature found. Issue ATAPI packet identify command. |
| 4931 |
*/ |
| 4932 |
if (IssueIdentify(pChan, deviceNumber, IDE_COMMAND_ATAPI_IDENTIFY)) |
| 4933 |
{ |
| 4934 |
/* |
| 4935 |
* Indicate ATAPI device. |
| 4936 |
*/ |
| 4937 |
printk("iteraid_find_device: Channel %x Device %x is ATAPI.\n", |
| 4938 |
channel, deviceNumber); |
| 4939 |
|
| 4940 |
pChan->DeviceFlags[deviceNumber] |= DFLAGS_ATAPI_DEVICE; |
| 4941 |
pChan->DeviceFlags[deviceNumber] |= DFLAGS_DEVICE_PRESENT; |
| 4942 |
pChan->DeviceFlags[deviceNumber] &= ~DFLAGS_CONFIG_CHANGED; |
| 4943 |
|
| 4944 |
deviceResponded = TRUE; |
| 4945 |
|
| 4946 |
GetStatus(pChan, statusByte); |
| 4947 |
if (statusByte & IDE_STATUS_ERROR) |
| 4948 |
{ |
| 4949 |
AtapiSoftReset(pChan, deviceNumber); |
| 4950 |
} |
| 4951 |
} |
| 4952 |
else |
| 4953 |
{ |
| 4954 |
/* |
| 4955 |
* Indicate no working device. |
| 4956 |
*/ |
| 4957 |
printk("iteraid_find_device: Channel %x Device %x not respond.\n", |
| 4958 |
channel, deviceNumber); |
| 4959 |
pChan->DeviceFlags[deviceNumber] &= ~DFLAGS_DEVICE_PRESENT; |
| 4960 |
} |
| 4961 |
} |
| 4962 |
else |
| 4963 |
{ |
| 4964 |
/* |
| 4965 |
* Select the device. |
| 4966 |
*/ |
| 4967 |
outb((UCHAR)((deviceNumber << 4) | 0xA0), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 4968 |
|
| 4969 |
/* |
| 4970 |
* Check here for some SCSI adapters that incorporate IDE emulation. |
| 4971 |
*/ |
| 4972 |
GetStatus(pChan, statusByte); |
| 4973 |
|
| 4974 |
/* |
| 4975 |
* No Disk. |
| 4976 |
*/ |
| 4977 |
if (statusByte == 0xFF || statusByte == 0x7F || statusByte == 0x0) |
| 4978 |
{ |
| 4979 |
dprintk("FindDevices: Cannot find IDE device. status = %x\n", statusByte); |
| 4980 |
continue; |
| 4981 |
} |
| 4982 |
|
| 4983 |
/* |
| 4984 |
* Issue IDE Identify. If an ATAPI device is actually present, |
| 4985 |
* the signature will be asserted, and the drive will be |
| 4986 |
* recognized as such. |
| 4987 |
*/ |
| 4988 |
if (IssueIdentify(pChan, deviceNumber, IDE_COMMAND_IDENTIFY)) |
| 4989 |
{ |
| 4990 |
/* |
| 4991 |
* IDE drive found. |
| 4992 |
*/ |
| 4993 |
dprintk(KERN_WARNING "FindDevices: Device %u is IDE\n", |
| 4994 |
(channel * 2) + deviceNumber); |
| 4995 |
|
| 4996 |
pChan->DeviceFlags[deviceNumber] |= DFLAGS_DEVICE_PRESENT; |
| 4997 |
pChan->DeviceFlags[deviceNumber] &= ~DFLAGS_ATAPI_DEVICE; |
| 4998 |
pChan->DeviceFlags[deviceNumber] &= ~DFLAGS_CONFIG_CHANGED; |
| 4999 |
|
| 5000 |
deviceResponded = TRUE; |
| 5001 |
} |
| 5002 |
else |
| 5003 |
{ |
| 5004 |
dprintk(KERN_WARNING "FindDevices: Device %u is not present\n", |
| 5005 |
(channel * 2) + deviceNumber); |
| 5006 |
pChan->DeviceFlags[deviceNumber] &= ~DFLAGS_DEVICE_PRESENT; |
| 5007 |
} |
| 5008 |
} |
| 5009 |
} |
| 5010 |
|
| 5011 |
return deviceResponded; |
| 5012 |
|
| 5013 |
} /* end iteraid_find_device */ |
| 5014 |
|
| 5015 |
/************************************************************************ |
| 5016 |
* IDE disk hardware initialize |
| 5017 |
************************************************************************/ |
| 5018 |
BOOLEAN |
| 5019 |
AtapiHwInitialize(PITE_ADAPTER pAdap, PChannel pChan, UCHAR channel) |
| 5020 |
{ |
| 5021 |
|
| 5022 |
UCHAR i; |
| 5023 |
UCHAR statusByte = 0; |
| 5024 |
|
| 5025 |
/* |
| 5026 |
* For two devices in this channel. |
| 5027 |
*/ |
| 5028 |
for (i = 0; i < 2; i++) |
| 5029 |
{ |
| 5030 |
/* |
| 5031 |
* only check in Fireware mode. |
| 5032 |
*/ |
| 5033 |
if (pAdap->bypass_mode == FALSE) |
| 5034 |
{ |
| 5035 |
outb((UCHAR) (0xA0 | ((UCHAR) i << 4)), pChan->io_ports[IDE_SELECT_OFFSET]); |
| 5036 |
|
| 5037 |
/* |
| 5038 |
* Check if card at this address. |
| 5039 |
*/ |
| 5040 |
outb(0xAA, pChan->io_ports[IDE_MIDCYL_OFFSET]); |
| 5041 |
|
| 5042 |
/* |
| 5043 |
* Check if indentifier can be read back. |
| 5044 |
*/ |
| 5045 |
if ((statusByte = inb(pChan->io_ports[IDE_MIDCYL_OFFSET])) != 0xAA) |
| 5046 |
{ |
| 5047 |
printk("AtapiHwInitialize: Identifier read back from (%x, %x) = %x\n", |
| 5048 |
channel, i, statusByte); |
| 5049 |
|
| 5050 |
/* |
| 5051 |
* ***** Dont free it....For later use ***** |
| 5052 |
* ScsiPortFreeDeviceBase(HwDeviceExtension, ioSpace1); |
| 5053 |
*/ |
| 5054 |
continue; |
| 5055 |
} |
| 5056 |
|
| 5057 |
printk("AtapiHwInitialize: Found ATA device (%x, %x)n", channel, i); |
| 5058 |
} |
| 5059 |
|
| 5060 |
} |
| 5061 |
|
| 5062 |
return TRUE; |
| 5063 |
|
| 5064 |
} /* end AtapiHwInitialize */ |
| 5065 |
|
| 5066 |
/************************************************************************ |
| 5067 |
* Initialize a adapter, return 0 means success |
| 5068 |
************************************************************************/ |
| 5069 |
static int |
| 5070 |
iteraid_init(PITE_ADAPTER pAdap, struct pci_dev *pPciDev) |
| 5071 |
{ |
| 5072 |
|
| 5073 |
unsigned char z; |
| 5074 |
unsigned char i; |
| 5075 |
unsigned char j; |
| 5076 |
unsigned int set_irq; |
| 5077 |
USHORT control_addr; /* Control reg base address */ |
| 5078 |
USHORT base_addr; /* IDE I/O port base address */ |
| 5079 |
USHORT bm_base_addr; /* Bus Master base address */ |
| 5080 |
PChannel pChan; /* Use for each channel */ |
| 5081 |
|
| 5082 |
/* |
| 5083 |
* Common settings. |
| 5084 |
*/ |
| 5085 |
pAdap->pci_bus = pPciDev->bus->number; |
| 5086 |
pAdap->devfn = pPciDev->devfn; |
| 5087 |
pAdap->irq = pPciDev->irq; |
| 5088 |
pAdap->irqOwned = 0; |
| 5089 |
|
| 5090 |
printk(KERN_NOTICE "iteraid_init: Found Controller: %s\n", pAdap->name); |
| 5091 |
|
| 5092 |
/* |
| 5093 |
* Allocate buffer for IDE channles (One IT8212 supports two channels) |
| 5094 |
*/ |
| 5095 |
pAdap->IDEChannel = |
| 5096 |
(PChannel)kmalloc(sizeof(Channel) * pAdap->num_channels, GFP_ATOMIC); |
| 5097 |
|
| 5098 |
if (pAdap->IDEChannel == 0) |
| 5099 |
{ |
| 5100 |
printk("iteraid_init: kmalloc() failed for channels.\n"); |
| 5101 |
return -1; |
| 5102 |
} |
| 5103 |
|
| 5104 |
memset(pAdap->IDEChannel, 0, sizeof(Channel) * pAdap->num_channels); |
| 5105 |
|
| 5106 |
set_irq = 1; |
| 5107 |
for (i = 0; i < NumAdapters; i++) |
| 5108 |
{ |
| 5109 |
if (ite_adapters[i]->irqOwned == pAdap->irq) set_irq = 0; |
| 5110 |
} |
| 5111 |
|
| 5112 |
/* |
| 5113 |
* Request the irq (share irq) and hook the interrupt service routine. |
| 5114 |
*/ |
| 5115 |
if (set_irq) |
| 5116 |
{ |
| 5117 |
if (request_irq(pAdap->irq, Irq_Handler, SA_SHIRQ, PROC_DIR_NAME, pAdap) < 0) |
| 5118 |
{ |
| 5119 |
printk("Unable to allocate IRQ for %s\n", pAdap->name); |
| 5120 |
return -1; |
| 5121 |
} |
| 5122 |
pAdap->irqOwned = pAdap->irq; |
| 5123 |
} |
| 5124 |
|
| 5125 |
/* |
| 5126 |
* Get the IDE port and DMA registers. |
| 5127 |
*/ |
| 5128 |
for (i = 0; i < pAdap->num_channels; i++) |
| 5129 |
{ |
| 5130 |
/* |
| 5131 |
* Reference the book "LINUX DEVICE DRIVER 2nd", Page 484 |
| 5132 |
* unsigned long pci_resource_start(struct pci_dev *dev, int bar); |
| 5133 |
* |
| 5134 |
* This function returns the first address (memory address or I/O |
| 5135 |
* port number) associated with one of the six PCI I/O regions. The |
| 5136 |
* region is selected by the integer bar (the base address register) |
| 5137 |
* ranging from 0 to 5, inclusive. |
| 5138 |
*/ |
| 5139 |
base_addr = pci_resource_start(pPciDev, i * 2); |
| 5140 |
bm_base_addr = pci_resource_start(pPciDev, 4); |
| 5141 |
|
| 5142 |
pChan = &pAdap->IDEChannel[i]; |
| 5143 |
|
| 5144 |
if (i == 0) |
| 5145 |
{ |
| 5146 |
control_addr = pci_resource_start(pPciDev, 1); |
| 5147 |
pChan->dma_base = bm_base_addr; |
| 5148 |
} |
| 5149 |
else |
| 5150 |
{ |
| 5151 |
control_addr = pci_resource_start(pPciDev, 3); |
| 5152 |
pChan->dma_base = bm_base_addr + 8; |
| 5153 |
} |
| 5154 |
|
| 5155 |
for (j = 0; j <= IDE_STATUS_OFFSET; j++) |
| 5156 |
{ |
| 5157 |
pChan->io_ports[j] = base_addr; |
| 5158 |
base_addr += 1; |
| 5159 |
} |
| 5160 |
|
| 5161 |
pChan->io_ports[IDE_CONTROL_OFFSET] = control_addr + 2; |
| 5162 |
} |
| 5163 |
|
| 5164 |
/* |
| 5165 |
* Initialize channels. |
| 5166 |
*/ |
| 5167 |
for (z = 0; z < pAdap->num_channels; z++) |
| 5168 |
{ |
| 5169 |
pChan = &pAdap->IDEChannel[z]; |
| 5170 |
pChan->pPciDev = pPciDev; |
| 5171 |
pChan->channel = z; |
| 5172 |
|
| 5173 |
/* |
| 5174 |
* This section should be masked off if BIOS is ready. |
| 5175 |
*/ |
| 5176 |
# if (MARK_DEBUG_BYPASS_MODE) |
| 5177 |
/* |
| 5178 |
* BIOS is not ready, so I change to ByPass Mode by myself. |
| 5179 |
*/ |
| 5180 |
pAdap->bypass_mode = TRUE; |
| 5181 |
|
| 5182 |
/* |
| 5183 |
* Change to bypass mode. |
| 5184 |
*/ |
| 5185 |
IT8212InitBypassMode(pPciDev); |
| 5186 |
# endif |
| 5187 |
|
| 5188 |
/* |
| 5189 |
* Hardware initialize. |
| 5190 |
*/ |
| 5191 |
# if (0) |
| 5192 |
AtapiHwInitialize(pAdap, pChan, z); |
| 5193 |
# endif |
| 5194 |
|
| 5195 |
/* |
| 5196 |
* Find and identify the IDE or ATAPI device. |
| 5197 |
*/ |
| 5198 |
iteraid_find_device(pChan, z); |
| 5199 |
|
| 5200 |
/* |
| 5201 |
* Set the best transfer mode. |
| 5202 |
*/ |
| 5203 |
IT8212SetBestTransferMode(pAdap, pChan, z); |
| 5204 |
|
| 5205 |
/* |
| 5206 |
* Set Scatter/Gather List buffer for the channel. |
| 5207 |
*/ |
| 5208 |
IdeSetupDma(pChan, pChan->dma_base, 8); |
| 5209 |
|
| 5210 |
/* |
| 5211 |
* Setup retry timer. |
| 5212 |
*/ |
| 5213 |
pChan->retry_timer = |
| 5214 |
(struct timer_list *)kmalloc(sizeof(struct timer_list) * 2, GFP_ATOMIC); |
| 5215 |
|
| 5216 |
if (pChan->retry_timer == NULL) |
| 5217 |
{ |
| 5218 |
printk("Allocate retry_timer failed\n"); |
| 5219 |
return -1; |
| 5220 |
} |
| 5221 |
|
| 5222 |
init_timer(pChan->retry_timer); |
| 5223 |
pChan->retry_timer->function = (void (*)(ULONG))iteretry; |
| 5224 |
pChan->retry_timer->data = (ULONG)pChan; |
| 5225 |
|
| 5226 |
pChan->watch_timer = pChan->retry_timer + 1; |
| 5227 |
init_timer(pChan->watch_timer); |
| 5228 |
pChan->watch_timer->function = (void (*)(ULONG))ite_watch_timer; |
| 5229 |
pChan->watch_timer->data = (ULONG)pChan; |
| 5230 |
} |
| 5231 |
|
| 5232 |
return 0; |
| 5233 |
|
| 5234 |
} /* end iteraid_init */ |
| 5235 |
|
| 5236 |
/************************************************************************ |
| 5237 |
* This function will find and initialize any cards |
| 5238 |
************************************************************************/ |
| 5239 |
int |
| 5240 |
iteraid_detect(Scsi_Host_Template *tpnt) |
| 5241 |
{ |
| 5242 |
|
| 5243 |
int major = 0; |
| 5244 |
UCHAR i; |
| 5245 |
UCHAR j; |
| 5246 |
UCHAR mode = 0; |
| 5247 |
PChannel pChan; |
| 5248 |
PITE_ADAPTER pAdap; |
| 5249 |
struct pci_dev * pPciDev; |
| 5250 |
|
| 5251 |
/* |
| 5252 |
* Check if the kernel has PCI interface compiled in. |
| 5253 |
*/ |
| 5254 |
if (!pci_present()) |
| 5255 |
{ |
| 5256 |
printk("iteraid_detect: No pci interface present.\n"); |
| 5257 |
return 0; |
| 5258 |
} |
| 5259 |
|
| 5260 |
/* |
| 5261 |
* Search ITE IT8212 chip. |
| 5262 |
*/ |
| 5263 |
pPciDev = NULL; |
| 5264 |
while ((pPciDev = pci_find_device(ITE_VENDOR_ID, ITE_DEVICE_ID, pPciDev))) |
| 5265 |
{ |
| 5266 |
if (PCI_FUNC(pPciDev->devfn)) continue; |
| 5267 |
|
| 5268 |
/* |
| 5269 |
* Allocate memory for Adapter. |
| 5270 |
*/ |
| 5271 |
pAdap = (PITE_ADAPTER)kmalloc(sizeof(ITE_ADAPTER), GFP_ATOMIC); |
| 5272 |
|
| 5273 |
if (pAdap == NULL) |
| 5274 |
{ |
| 5275 |
printk("iteraid_detect: kmalloc() failed for card.\n"); |
| 5276 |
continue; |
| 5277 |
} |
| 5278 |
|
| 5279 |
memset(pAdap, 0, sizeof(ITE_ADAPTER)); |
| 5280 |
|
| 5281 |
pAdap->name = CONTROLLER_NAME_IT8212; |
| 5282 |
pAdap->num_channels = 2; |
| 5283 |
pAdap->pci_dev = pPciDev; |
| 5284 |
|
| 5285 |
/* |
| 5286 |
* Check if we are in bypass(transparent) or firmware mode. |
| 5287 |
*/ |
| 5288 |
pci_read_config_byte(pPciDev, 0x50, &mode); |
| 5289 |
if (mode & 1) { dprintk("Firmware mode\n"); pAdap->bypass_mode = FALSE; } |
| 5290 |
else { dprintk("Bypass mode\n"); pAdap->bypass_mode = TRUE; } |
| 5291 |
|
| 5292 |
if (iteraid_init(pAdap, pPciDev) == 0) |
| 5293 |
{ |
| 5294 |
ite_adapters[NumAdapters++] = pAdap; |
| 5295 |
} |
| 5296 |
} |
| 5297 |
|
| 5298 |
/* |
| 5299 |
* Reenable interrupt after initialization. 2003/04/28 |
| 5300 |
*/ |
| 5301 |
for (i = 0; i < NumAdapters; i++) |
| 5302 |
{ |
| 5303 |
pAdap = ite_adapters[i]; |
| 5304 |
for (j = 0; j < pAdap->num_channels; j++) |
| 5305 |
{ |
| 5306 |
pChan = &pAdap->IDEChannel[j]; |
| 5307 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 5308 |
} |
| 5309 |
} |
| 5310 |
|
| 5311 |
if (NumAdapters) |
| 5312 |
{ |
| 5313 |
/* |
| 5314 |
* Register a virtual host. |
| 5315 |
*/ |
| 5316 |
ite_vhost = scsi_register(tpnt, 0); |
| 5317 |
|
| 5318 |
ite_vhost->io_port = 0; |
| 5319 |
ite_vhost->n_io_port = 0; |
| 5320 |
ite_vhost->max_channel = 0; |
| 5321 |
ite_vhost->max_id = MAX_DEVICES; |
| 5322 |
ite_vhost->max_lun = 1; |
| 5323 |
scsi_set_pci_device(ite_vhost, pPciDev); |
| 5324 |
|
| 5325 |
/* |
| 5326 |
* Register the driver as a character device, for applications to |
| 5327 |
* acess it for ioctls. Ideally, this should go in the init_module() |
| 5328 |
* routine, but since it is hidden in the file "scsi_module.c" ( |
| 5329 |
* included in the end), we define it here. First argument (major) |
| 5330 |
* to register_chrdev implies a dynamic major number allocation. |
| 5331 |
*/ |
| 5332 |
major = register_chrdev(0, "itedev", &itedev_fops); |
| 5333 |
|
| 5334 |
/* |
| 5335 |
* Register the Shutdown Notification hook in the kernel. |
| 5336 |
*/ |
| 5337 |
|
| 5338 |
/* |
| 5339 |
* Initialize ioctl semphore. |
| 5340 |
*/ |
| 5341 |
init_MUTEX(&mimd_entry_mtx); |
| 5342 |
} |
| 5343 |
|
| 5344 |
return 1; |
| 5345 |
|
| 5346 |
} /* end iteraid_detect() */ |
| 5347 |
|
| 5348 |
/************************************************************************ |
| 5349 |
* Name: iteraid_release |
| 5350 |
* Description: Release resources allocated for a single each adapter. |
| 5351 |
* Parameters: pshost - Pointer to SCSI command structure. |
| 5352 |
* Returns: zero. |
| 5353 |
************************************************************************/ |
| 5354 |
int |
| 5355 |
iteraid_release(struct Scsi_Host *pshost) |
| 5356 |
{ |
| 5357 |
|
| 5358 |
int i; |
| 5359 |
int j; |
| 5360 |
PITE_ADAPTER pAdap; |
| 5361 |
|
| 5362 |
for (i = 0; i < NumAdapters; i++) |
| 5363 |
{ |
| 5364 |
pAdap = ite_adapters[i]; |
| 5365 |
|
| 5366 |
if (pAdap->irqOwned) free_irq(pAdap->irq, pAdap); |
| 5367 |
|
| 5368 |
for (j = 0; j < pAdap->num_channels; j++) |
| 5369 |
{ |
| 5370 |
kfree(pAdap->IDEChannel[j].retry_timer); |
| 5371 |
} |
| 5372 |
if (pAdap->IDEChannel != NULL) { kfree(pAdap->IDEChannel); } |
| 5373 |
if (pAdap != NULL) { kfree(pAdap); } |
| 5374 |
} |
| 5375 |
|
| 5376 |
scsi_unregister(pshost); |
| 5377 |
|
| 5378 |
return 0; |
| 5379 |
|
| 5380 |
} /* end iteraid_Release */ |
| 5381 |
|
| 5382 |
/************************************************************************ |
| 5383 |
* Name: iteraid_old_abort |
| 5384 |
* Description: Process the Abort command from the SCSI manager. |
| 5385 |
* Parameters: SCpnt - Pointer to SCSI command structure. |
| 5386 |
* Returns: Always snooze(A short sleep). |
| 5387 |
************************************************************************/ |
| 5388 |
int |
| 5389 |
iteraid_old_abort(Scsi_Cmnd *SCpnt) |
| 5390 |
{ |
| 5391 |
|
| 5392 |
return SCSI_ABORT_SNOOZE; |
| 5393 |
|
| 5394 |
} /* end iteraid_old_abort */ |
| 5395 |
|
| 5396 |
/************************************************************************ |
| 5397 |
* Name: iteraid_old_reset |
| 5398 |
* Description: Process the Reset command from the SCSI manager. |
| 5399 |
* Parameters: SCpnt - Pointer to SCSI command structure. |
| 5400 |
* flags - Flags about the reset command |
| 5401 |
* Returns: No active command at this time, so this means |
| 5402 |
* that each time we got some kind of response the |
| 5403 |
* last time through. Tell the mid-level code to |
| 5404 |
* request sense information in order to decide what |
| 5405 |
* to do next. |
| 5406 |
************************************************************************/ |
| 5407 |
int |
| 5408 |
iteraid_old_reset(Scsi_Cmnd *SCpnt, unsigned int reset_flags) |
| 5409 |
{ |
| 5410 |
|
| 5411 |
return SCSI_RESET_SUCCESS; |
| 5412 |
|
| 5413 |
} /* end iteraid_old_reset */ |
| 5414 |
|
| 5415 |
/************************************************************************ |
| 5416 |
* Name: iteraid_biosparam |
| 5417 |
* Description: Process the biosparam request from the SCSI manager to |
| 5418 |
* return C/H/S data. |
| 5419 |
* Parameters: disk - Pointer to SCSI disk structure. |
| 5420 |
* dev - Major/minor number from kernel. |
| 5421 |
* geom - Pointer to integer array to place geometry data. |
| 5422 |
* Returns: zero. |
| 5423 |
************************************************************************/ |
| 5424 |
int |
| 5425 |
iteraid_biosparam(Scsi_Disk *disk, kdev_t dev, int geom[]) |
| 5426 |
{ |
| 5427 |
|
| 5428 |
int heads, sectors, cylinders; |
| 5429 |
|
| 5430 |
/* |
| 5431 |
* Default heads (64) & sectors (32) |
| 5432 |
* Handle extended translation size for logical drives > 1Gb |
| 5433 |
*/ |
| 5434 |
if (disk->capacity >= 0x200000) |
| 5435 |
{ |
| 5436 |
heads = 255; |
| 5437 |
sectors = 63; |
| 5438 |
} |
| 5439 |
else |
| 5440 |
{ |
| 5441 |
heads = 64; |
| 5442 |
sectors = 32; |
| 5443 |
} |
| 5444 |
|
| 5445 |
cylinders = disk->capacity / (heads * sectors); |
| 5446 |
|
| 5447 |
/* |
| 5448 |
* Return result |
| 5449 |
*/ |
| 5450 |
geom[0] = heads; |
| 5451 |
geom[1] = sectors; |
| 5452 |
geom[2] = cylinders; |
| 5453 |
|
| 5454 |
return 0; |
| 5455 |
|
| 5456 |
} /* end iteraid_biosparam */ |
| 5457 |
|
| 5458 |
/************************************************************************ |
| 5459 |
* |
| 5460 |
************************************************************************/ |
| 5461 |
int |
| 5462 |
iteraid_proc_info |
| 5463 |
( |
| 5464 |
char * buffer, |
| 5465 |
char ** start, |
| 5466 |
off_t offset, |
| 5467 |
int length, |
| 5468 |
int host_no, |
| 5469 |
int inout |
| 5470 |
) |
| 5471 |
{ |
| 5472 |
|
| 5473 |
return 0; |
| 5474 |
|
| 5475 |
} /* end iteraid_proc_info */ |
| 5476 |
|
| 5477 |
/************************************************************************ |
| 5478 |
* |
| 5479 |
************************************************************************/ |
| 5480 |
static int |
| 5481 |
itedev_open(struct inode *inode, struct file *filep) |
| 5482 |
{ |
| 5483 |
|
| 5484 |
MOD_INC_USE_COUNT; |
| 5485 |
|
| 5486 |
return 0; |
| 5487 |
|
| 5488 |
} /* end itedev_open */ |
| 5489 |
|
| 5490 |
/************************************************************************ |
| 5491 |
* IOCTL code entry. |
| 5492 |
************************************************************************/ |
| 5493 |
static int |
| 5494 |
itedev_ioctl_entry |
| 5495 |
( |
| 5496 |
struct inode * inode, |
| 5497 |
struct file * filep, |
| 5498 |
unsigned int cmd, |
| 5499 |
unsigned long arg |
| 5500 |
) |
| 5501 |
{ |
| 5502 |
|
| 5503 |
int ret = -1; |
| 5504 |
|
| 5505 |
/* |
| 5506 |
* We do not allow parallel ioctls to the driver as of now. |
| 5507 |
*/ |
| 5508 |
down(&mimd_entry_mtx); |
| 5509 |
ret = itedev_ioctl(inode, filep, cmd, arg); |
| 5510 |
up(&mimd_entry_mtx); |
| 5511 |
|
| 5512 |
return ret; |
| 5513 |
|
| 5514 |
} /* end itedev_ioctl_entry */ |
| 5515 |
|
| 5516 |
/************************************************************************ |
| 5517 |
* Real IOCTL code. |
| 5518 |
************************************************************************/ |
| 5519 |
static int |
| 5520 |
itedev_ioctl |
| 5521 |
( |
| 5522 |
struct inode * inode, |
| 5523 |
struct file * filep, |
| 5524 |
unsigned int cmd, |
| 5525 |
unsigned long arg |
| 5526 |
) |
| 5527 |
{ |
| 5528 |
|
| 5529 |
UCHAR diskArrayId; |
| 5530 |
UCHAR statusByte = 0; |
| 5531 |
UCHAR srbStatus; |
| 5532 |
UCHAR progress; |
| 5533 |
UCHAR status; |
| 5534 |
uioctl_t * pioc; |
| 5535 |
PITE_ADAPTER pAdap; |
| 5536 |
PChannel pChan; |
| 5537 |
|
| 5538 |
printk("itedev_ioctl enter\n"); |
| 5539 |
|
| 5540 |
/* |
| 5541 |
* Extract the type and number bitfield. |
| 5542 |
*/ |
| 5543 |
if (_IOC_TYPE(cmd) != ITE_IOCMAGIC) |
| 5544 |
return -EINVAL; |
| 5545 |
|
| 5546 |
/* |
| 5547 |
* Allocate space for ioctl data structure. |
| 5548 |
*/ |
| 5549 |
if ((pioc = kmalloc(sizeof(uioctl_t), GFP_KERNEL)) == NULL) |
| 5550 |
{ |
| 5551 |
printk("itedev_ioctl: error kmalloc on ioctl\n"); |
| 5552 |
return -ENOMEM; |
| 5553 |
} |
| 5554 |
|
| 5555 |
/* |
| 5556 |
* Get the user ioctl structure. |
| 5557 |
*/ |
| 5558 |
if (copy_from_user(pioc, (uioctl_t *)arg, sizeof(uioctl_t))) |
| 5559 |
{ |
| 5560 |
kfree(pioc); |
| 5561 |
return -EFAULT; |
| 5562 |
} |
| 5563 |
|
| 5564 |
/* |
| 5565 |
* Check which command to do. |
| 5566 |
*/ |
| 5567 |
switch (cmd) |
| 5568 |
{ |
| 5569 |
case ITE_IOC_GET_IDENTIFY_DATA: |
| 5570 |
printk("ITE_IOCGIDENTIFY\n"); |
| 5571 |
|
| 5572 |
/* |
| 5573 |
* Get the virtual device identify data. |
| 5574 |
*/ |
| 5575 |
status = IT8212IssueIdentify(pioc); |
| 5576 |
|
| 5577 |
return 0; |
| 5578 |
|
| 5579 |
case ITE_IOC_GET_PHY_DISK_STATUS: |
| 5580 |
printk("ITE_IOC_GET_PHY_DISK_STATUS\n"); |
| 5581 |
|
| 5582 |
/* |
| 5583 |
* Get the physical disk status. |
| 5584 |
*/ |
| 5585 |
status = IT8212GetChipStatus(pioc); |
| 5586 |
|
| 5587 |
return 0; |
| 5588 |
|
| 5589 |
case ITE_IOC_CREATE_DISK_ARRAY: |
| 5590 |
printk("ITE_IOC_CREATE_DISK_ARRAY\n"); |
| 5591 |
|
| 5592 |
/* |
| 5593 |
* Create disk array. |
| 5594 |
*/ |
| 5595 |
status = IT8212CreateDiskArray(pioc); |
| 5596 |
|
| 5597 |
if (status != SRB_STATUS_SUCCESS) return status; |
| 5598 |
|
| 5599 |
status = IT8212ErasePartition(pioc); |
| 5600 |
|
| 5601 |
return 0; |
| 5602 |
|
| 5603 |
case ITE_IOC_REBUILD_START: |
| 5604 |
printk("ITE_IOC_REBUILD_START\n"); |
| 5605 |
|
| 5606 |
/* |
| 5607 |
* Rebuild array. |
| 5608 |
*/ |
| 5609 |
status = IT8212Rebuild(pioc); |
| 5610 |
|
| 5611 |
return 0; |
| 5612 |
|
| 5613 |
case ITE_IOC_GET_REBUILD_STATUS: |
| 5614 |
printk("ITE_IOC_GET_REBUILD_STATUS\n"); |
| 5615 |
|
| 5616 |
pAdap = ite_adapters[pioc->AdapterNo]; |
| 5617 |
|
| 5618 |
/* |
| 5619 |
* Get the rebuild disk ID. |
| 5620 |
*/ |
| 5621 |
diskArrayId = pioc->DiskNo; |
| 5622 |
|
| 5623 |
/* |
| 5624 |
* Select channel. |
| 5625 |
*/ |
| 5626 |
if (diskArrayId < 2) |
| 5627 |
{ |
| 5628 |
pChan = &pAdap->IDEChannel[0]; |
| 5629 |
} |
| 5630 |
else |
| 5631 |
{ |
| 5632 |
pChan = &pAdap->IDEChannel[1]; |
| 5633 |
} |
| 5634 |
|
| 5635 |
/* |
| 5636 |
* Select device. |
| 5637 |
*/ |
| 5638 |
outb(((UCHAR) (diskArrayId << 4) | 0xA0), |
| 5639 |
pChan->io_ports[IDE_SELECT_OFFSET]); |
| 5640 |
|
| 5641 |
/* |
| 5642 |
* Wait for device ready (not BUSY and not DRQ). |
| 5643 |
*/ |
| 5644 |
WaitForDeviceReady(pChan, statusByte); |
| 5645 |
if ((statusByte & IDE_STATUS_BUSY) || (statusByte & IDE_STATUS_DRQ) || |
| 5646 |
(statusByte == 0)) |
| 5647 |
{ |
| 5648 |
printk("IT8212GetRebuildStatus: Disk[%d] busy. Status=0x%X\n", |
| 5649 |
diskArrayId, statusByte); |
| 5650 |
srbStatus = SRB_STATUS_BUSY; |
| 5651 |
goto exit; |
| 5652 |
} |
| 5653 |
|
| 5654 |
/* |
| 5655 |
* Disable interrupt to avoid the unexpected interrupt. |
| 5656 |
*/ |
| 5657 |
outb(IDE_DC_DISABLE_INTERRUPTS, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 5658 |
|
| 5659 |
/* |
| 5660 |
* Issue command. |
| 5661 |
*/ |
| 5662 |
outb(IDE_COMMAND_REBUILD_STATUS, pChan->io_ports[IDE_COMMAND_OFFSET]); |
| 5663 |
|
| 5664 |
/* |
| 5665 |
* Check error. |
| 5666 |
*/ |
| 5667 |
WaitForCommandComplete(pChan, statusByte); |
| 5668 |
|
| 5669 |
/* |
| 5670 |
* Reenable interrupt after command complete. |
| 5671 |
*/ |
| 5672 |
outb(IDE_DC_REENABLE_CONTROLLER, pChan->io_ports[IDE_CONTROL_OFFSET]); |
| 5673 |
|
| 5674 |
if (statusByte != IDE_STATUS_IDLE) |
| 5675 |
{ |
| 5676 |
srbStatus = SRB_STATUS_ERROR; |
| 5677 |
goto exit; |
| 5678 |
} |
| 5679 |
|
| 5680 |
progress = inb(pChan->io_ports[IDE_NSECTOR_OFFSET]); |
| 5681 |
srbStatus = SRB_STATUS_SUCCESS; |
| 5682 |
|
| 5683 |
/* |
| 5684 |
* Put the rebuld status to user space. |
| 5685 |
*/ |
| 5686 |
put_user(progress, (UCHAR *)arg); |
| 5687 |
|
| 5688 |
exit: |
| 5689 |
|
| 5690 |
return 0; |
| 5691 |
|
| 5692 |
case ITE_IOC_RESET_ADAPTER: |
| 5693 |
printk("ITE_IOC_RESET_ADAPTER\n"); |
| 5694 |
|
| 5695 |
/* |
| 5696 |
* Reset the adapter. |
| 5697 |
*/ |
| 5698 |
status = IT8212ResetAdapter(); |
| 5699 |
|
| 5700 |
/* |
| 5701 |
* Return TURE or FALSE to user space. |
| 5702 |
*/ |
| 5703 |
put_user(status, (UCHAR *)arg); |
| 5704 |
|
| 5705 |
return 0; |
| 5706 |
|
| 5707 |
case ITE_IOC_GET_DRIVER_VERSION: |
| 5708 |
printk("ITE_IOC_GET_DRIVER_VERSION\n"); |
| 5709 |
|
| 5710 |
/* |
| 5711 |
* Get the current driver version. |
| 5712 |
*/ |
| 5713 |
put_user(driver_ver, (int *)arg); |
| 5714 |
|
| 5715 |
return 0; |
| 5716 |
|
| 5717 |
default: |
| 5718 |
return -EINVAL; |
| 5719 |
|
| 5720 |
} /* end switch */ |
| 5721 |
|
| 5722 |
|
| 5723 |
} /* end itedev_ioctl */ |
| 5724 |
|
| 5725 |
/************************************************************************ |
| 5726 |
* |
| 5727 |
************************************************************************/ |
| 5728 |
static int |
| 5729 |
itedev_close(struct inode *inode, struct file *filep) |
| 5730 |
{ |
| 5731 |
|
| 5732 |
#ifdef MODULE |
| 5733 |
MOD_DEC_USE_COUNT; |
| 5734 |
#endif |
| 5735 |
|
| 5736 |
return 0; |
| 5737 |
|
| 5738 |
} /* end itedev_close */ |
| 5739 |
|
| 5740 |
/* |
| 5741 |
* To make our driver a SCSI module, we have to include some magic at the |
| 5742 |
* end of the file. This generates the init_module and clean_module code |
| 5743 |
* nedded for a SCSI device, rather than having the author replicate it |
| 5744 |
* each time a new driver is written. |
| 5745 |
*/ |
| 5746 |
static Scsi_Host_Template driver_template = ITERAID; |
| 5747 |
#include "scsi_module.c" |