Lines Matching refs:tw_dev

235 static int tw_reset_device_extension(TW_Device_Extension *tw_dev);
255 static int tw_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value, int print_host)
262 sprintf(host, " scsi%d:", tw_dev->host->host_no);
268 outl(TW_CONTROL_CLEAR_PARITY_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
273 outl(TW_CONTROL_CLEAR_PCI_ABORT, TW_CONTROL_REG_ADDR(tw_dev));
274 pci_write_config_word(tw_dev->tw_pci_dev, PCI_STATUS, TW_PCI_CLEAR_PCI_ABORT);
279 outl(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
284 outl(TW_CONTROL_CLEAR_SBUF_WRITE_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
288 if (tw_dev->reset_print == 0) {
290 tw_dev->reset_print = 1;
299 static int tw_poll_status(TW_Device_Extension *tw_dev, u32 flag, int seconds)
305 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
309 tw_decode_bits(tw_dev, status_reg_value, 0);
312 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
315 tw_decode_bits(tw_dev, status_reg_value, 0);
328 static int tw_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds)
334 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
338 tw_decode_bits(tw_dev, status_reg_value, 0);
341 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
344 tw_decode_bits(tw_dev, status_reg_value, 0);
357 static int tw_post_command_packet(TW_Device_Extension *tw_dev, int request_id)
363 command_que_value = tw_dev->command_packet_physical_address[request_id];
364 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
368 tw_decode_bits(tw_dev, status_reg_value, 1);
373 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
374 tw_dev->state[request_id] = TW_S_POSTED;
375 tw_dev->posted_request_count++;
376 if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) {
377 tw_dev->max_posted_request_count = tw_dev->posted_request_count;
381 if (tw_dev->state[request_id] != TW_S_PENDING) {
382 tw_dev->state[request_id] = TW_S_PENDING;
383 tw_dev->pending_request_count++;
384 if (tw_dev->pending_request_count > tw_dev->max_pending_request_count) {
385 tw_dev->max_pending_request_count = tw_dev->pending_request_count;
387 tw_dev->pending_queue[tw_dev->pending_tail] = request_id;
388 if (tw_dev->pending_tail == TW_Q_LENGTH-1) {
389 tw_dev->pending_tail = TW_Q_START;
391 tw_dev->pending_tail = tw_dev->pending_tail + 1;
394 TW_UNMASK_COMMAND_INTERRUPT(tw_dev);
401 static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill_sense)
407 command = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
409 printk(KERN_WARNING "3w-xxxx: scsi%d: Command failed: status = 0x%x, flags = 0x%x, unit #%d.\n", tw_dev->host->host_no, command->status, command->flags, TW_UNIT_OUT(command->unit__hostid));
418 tw_dev->srb[request_id]->sense_buffer[0] = (0x1 << 7 | 0x70);
421 tw_dev->srb[request_id]->sense_buffer[2] = tw_sense_table[i][1];
424 tw_dev->srb[request_id]->sense_buffer[7] = 0xa; /* 10 bytes */
427 tw_dev->srb[request_id]->sense_buffer[12] = tw_sense_table[i][2];
430 tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3];
432 tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
446 static int tw_check_errors(TW_Device_Extension *tw_dev)
450 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
453 tw_decode_bits(tw_dev, status_reg_value, 0);
461 static void tw_empty_response_que(TW_Device_Extension *tw_dev)
465 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
468 inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
469 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
474 static void tw_state_request_finish(TW_Device_Extension *tw_dev, int request_id)
476 tw_dev->free_queue[tw_dev->free_tail] = request_id;
477 tw_dev->state[request_id] = TW_S_FINISHED;
478 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH;
482 static void tw_state_request_start(TW_Device_Extension *tw_dev, int *request_id)
484 *request_id = tw_dev->free_queue[tw_dev->free_head];
485 tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH;
486 tw_dev->state[*request_id] = TW_S_STARTED;
494 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
498 spin_lock_irqsave(tw_dev->host->host_lock, flags);
511 tw_dev->posted_request_count,
512 tw_dev->max_posted_request_count,
513 tw_dev->pending_request_count,
514 tw_dev->max_pending_request_count,
515 tw_dev->sgl_entries,
516 tw_dev->max_sgl_entries,
517 tw_dev->sector_count,
518 tw_dev->max_sector_count,
519 tw_dev->num_resets,
520 tw_dev->aen_count);
521 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
543 static int tw_aen_read_queue(TW_Device_Extension *tw_dev, int request_id)
553 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
556 tw_decode_bits(tw_dev, status_reg_value, 1);
559 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
563 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
571 command_que_value = tw_dev->command_packet_physical_address[request_id];
577 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
581 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
586 param_value = tw_dev->alignment_physical_address[request_id];
597 tw_dev->srb[request_id] = NULL; /* Flag internal command */
598 tw_dev->state[request_id] = TW_S_POSTED;
599 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
609 static int tw_aen_complete(TW_Device_Extension *tw_dev, int request_id)
616 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
620 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
626 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: INFO: AEN queue overflow.\n", tw_dev->host->host_no);
631 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: %s%d.\n", tw_dev->host->host_no, tw_aen_string[aen & 0xff], aen >> 8);
634 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: %s.\n", tw_dev->host->host_no, tw_aen_string[aen & 0xff]);
637 printk(KERN_WARNING "3w-xxxx: scsi%d: Received AEN %d.\n", tw_dev->host->host_no, aen);
641 tw_dev->aen_count++;
644 tw_dev->aen_queue[tw_dev->aen_tail] = aen;
645 if (tw_dev->aen_tail == TW_Q_LENGTH - 1) {
646 tw_dev->aen_tail = TW_Q_START;
648 tw_dev->aen_tail = tw_dev->aen_tail + 1;
650 if (tw_dev->aen_head == tw_dev->aen_tail) {
651 if (tw_dev->aen_head == TW_Q_LENGTH - 1) {
652 tw_dev->aen_head = TW_Q_START;
654 tw_dev->aen_head = tw_dev->aen_head + 1;
658 error = tw_aen_read_queue(tw_dev, request_id);
660 printk(KERN_WARNING "3w-xxxx: scsi%d: Error completing AEN.\n", tw_dev->host->host_no);
661 tw_dev->state[request_id] = TW_S_COMPLETED;
662 tw_state_request_finish(tw_dev, request_id);
665 tw_dev->state[request_id] = TW_S_COMPLETED;
666 tw_state_request_finish(tw_dev, request_id);
673 static int tw_aen_drain_queue(TW_Device_Extension *tw_dev)
690 if (tw_poll_status(tw_dev, TW_STATUS_ATTENTION_INTERRUPT | TW_STATUS_MICROCONTROLLER_READY, 30)) {
694 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev);
697 tw_empty_response_que(tw_dev);
700 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
704 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
712 command_que_value = tw_dev->command_packet_physical_address[request_id];
719 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
723 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
728 param_value = tw_dev->alignment_physical_address[request_id];
739 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
742 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
743 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
755 tw_decode_sense(tw_dev, request_id, 0);
781 tw_dev->aen_count++;
799 tw_dev->aen_count++;
805 tw_dev->aen_queue[tw_dev->aen_tail] = aen;
806 if (tw_dev->aen_tail == TW_Q_LENGTH - 1) {
807 tw_dev->aen_tail = TW_Q_START;
809 tw_dev->aen_tail = tw_dev->aen_tail + 1;
811 if (tw_dev->aen_head == tw_dev->aen_tail) {
812 if (tw_dev->aen_head == TW_Q_LENGTH - 1) {
813 tw_dev->aen_head = TW_Q_START;
815 tw_dev->aen_head = tw_dev->aen_head + 1;
831 static int tw_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
839 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
846 if ((unsigned long)cpu_addr % (tw_dev->tw_pci_dev->device == TW_DEVICE_ID ? TW_ALIGNMENT_6000 : TW_ALIGNMENT_7000)) {
848 dma_free_coherent(&tw_dev->tw_pci_dev->dev, size * TW_Q_LENGTH,
858 tw_dev->command_packet_physical_address[i] = dma_handle+(i*size);
859 tw_dev->command_packet_virtual_address[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
862 tw_dev->alignment_physical_address[i] = dma_handle+(i*size);
863 tw_dev->alignment_virtual_address[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
888 TW_Device_Extension *tw_dev = tw_device_extension_list[iminor(inode)];
896 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
915 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_New_Ioctl), &dma_handle, GFP_KERNEL);
938 spin_lock_irqsave(tw_dev->host->host_lock, flags);
939 if (tw_dev->aen_head == tw_dev->aen_tail) {
942 tw_aen_code = tw_dev->aen_queue[tw_dev->aen_head];
943 if (tw_dev->aen_head == TW_Q_LENGTH - 1) {
944 tw_dev->aen_head = TW_Q_START;
946 tw_dev->aen_head = tw_dev->aen_head + 1;
949 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
954 spin_lock_irqsave(tw_dev->host->host_lock, flags);
956 tw_state_request_start(tw_dev, &request_id);
959 tw_dev->srb[request_id] = NULL;
962 tw_dev->chrdev_request_id = request_id;
982 memcpy(tw_dev->command_packet_virtual_address[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command));
985 tw_post_command_packet(tw_dev, request_id);
986 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
991 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
994 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
996 printk(KERN_WARNING "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cmd);
998 if (tw_reset_device_extension(tw_dev)) {
999 printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_no);
1005 memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virtual_address[request_id], sizeof(TW_Command));
1008 spin_lock_irqsave(tw_dev->host->host_lock, flags);
1009 tw_dev->posted_request_count--;
1010 tw_dev->state[request_id] = TW_S_COMPLETED;
1011 tw_state_request_finish(tw_dev, request_id);
1012 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1025 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_New_Ioctl), cpu_addr, dma_handle);
1027 mutex_unlock(&tw_dev->ioctl_lock);
1061 static void tw_free_device_extension(TW_Device_Extension *tw_dev)
1066 if (tw_dev->command_packet_virtual_address[0])
1067 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
1069 tw_dev->command_packet_virtual_address[0],
1070 tw_dev->command_packet_physical_address[0]);
1072 if (tw_dev->alignment_virtual_address[0])
1073 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
1075 tw_dev->alignment_virtual_address[0],
1076 tw_dev->alignment_physical_address[0]);
1080 static int tw_initconnection(TW_Device_Extension *tw_dev, int message_credits)
1090 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
1095 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1104 command_que_value = tw_dev->command_packet_physical_address[request_id];
1112 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1115 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
1116 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1126 tw_decode_sense(tw_dev, request_id, 0);
1134 static int tw_setfeature(TW_Device_Extension *tw_dev, int parm, int param_size,
1145 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
1149 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1151 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1159 param_value = tw_dev->alignment_physical_address[request_id];
1162 tw_dev->state[request_id] = TW_S_COMPLETED;
1163 tw_state_request_finish(tw_dev, request_id);
1164 tw_dev->srb[request_id]->result = (DID_OK << 16);
1165 scsi_done(tw_dev->srb[request_id]);
1174 command_que_value = tw_dev->command_packet_physical_address[request_id];
1181 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1184 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
1185 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1195 tw_decode_sense(tw_dev, request_id, 0);
1204 static int tw_reset_sequence(TW_Device_Extension *tw_dev)
1212 TW_SOFT_RESET(tw_dev);
1214 error = tw_aen_drain_queue(tw_dev);
1216 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN drain failed, retrying.\n", tw_dev->host->host_no);
1222 if (tw_check_errors(tw_dev)) {
1223 printk(KERN_WARNING "3w-xxxx: scsi%d: Controller errors found, retrying.\n", tw_dev->host->host_no);
1233 printk(KERN_WARNING "3w-xxxx: scsi%d: Controller errors, card not responding, check all cabling.\n", tw_dev->host->host_no);
1237 error = tw_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS);
1239 printk(KERN_WARNING "3w-xxxx: scsi%d: Connection initialization failed.\n", tw_dev->host->host_no);
1243 error = tw_setfeature(tw_dev, 2, 1, &c);
1252 static int tw_initialize_device_extension(TW_Device_Extension *tw_dev)
1259 error = tw_allocate_memory(tw_dev, sizeof(TW_Command), 0);
1266 error = tw_allocate_memory(tw_dev, sizeof(TW_Sector), 1);
1273 tw_dev->free_queue[i] = i;
1274 tw_dev->state[i] = TW_S_INITIAL;
1277 tw_dev->pending_head = TW_Q_START;
1278 tw_dev->pending_tail = TW_Q_START;
1279 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1281 mutex_init(&tw_dev->ioctl_lock);
1282 init_waitqueue_head(&tw_dev->ioctl_wqueue);
1288 static int tw_reset_device_extension(TW_Device_Extension *tw_dev)
1296 set_bit(TW_IN_RESET, &tw_dev->flags);
1297 TW_DISABLE_INTERRUPTS(tw_dev);
1298 TW_MASK_COMMAND_INTERRUPT(tw_dev);
1299 spin_lock_irqsave(tw_dev->host->host_lock, flags);
1303 if ((tw_dev->state[i] != TW_S_FINISHED) &&
1304 (tw_dev->state[i] != TW_S_INITIAL) &&
1305 (tw_dev->state[i] != TW_S_COMPLETED)) {
1306 srb = tw_dev->srb[i];
1317 tw_dev->free_queue[i] = i;
1318 tw_dev->state[i] = TW_S_INITIAL;
1320 tw_dev->free_head = TW_Q_START;
1321 tw_dev->free_tail = TW_Q_START;
1322 tw_dev->posted_request_count = 0;
1323 tw_dev->pending_request_count = 0;
1324 tw_dev->pending_head = TW_Q_START;
1325 tw_dev->pending_tail = TW_Q_START;
1326 tw_dev->reset_print = 0;
1328 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1330 if (tw_reset_sequence(tw_dev)) {
1331 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset sequence failed.\n", tw_dev->host->host_no);
1335 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1336 clear_bit(TW_IN_RESET, &tw_dev->flags);
1337 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1371 TW_Device_Extension *tw_dev=NULL;
1374 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1376 tw_dev->num_resets++;
1383 mutex_lock(&tw_dev->ioctl_lock);
1386 if (tw_reset_device_extension(tw_dev)) {
1387 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset failed.\n", tw_dev->host->host_no);
1393 mutex_unlock(&tw_dev->ioctl_lock);
1398 static int tw_scsiop_inquiry(TW_Device_Extension *tw_dev, int request_id)
1408 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1422 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
1426 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1431 param_value = tw_dev->alignment_physical_address[request_id];
1439 command_que_value = tw_dev->command_packet_physical_address[request_id];
1446 tw_post_command_packet(tw_dev, request_id);
1451 static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
1454 scsi_sg_copy_from_buffer(tw_dev->srb[request_id], data, len);
1458 static int tw_scsiop_inquiry_complete(TW_Device_Extension *tw_dev, int request_id)
1472 sprintf(&request_buffer[16], "Logical Disk %-2d ", tw_dev->srb[request_id]->device->id);
1474 tw_transfer_internal(tw_dev, request_id, request_buffer,
1477 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1484 if (is_unit_present[tw_dev->srb[request_id]->device->id] & TW_UNIT_ONLINE) {
1485 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 1;
1487 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 0;
1488 tw_dev->srb[request_id]->result = (DID_BAD_TARGET << 16);
1496 static int tw_scsiop_mode_sense(TW_Device_Extension *tw_dev, int request_id)
1506 if (tw_dev->srb[request_id]->cmnd[2] != 0x8) {
1507 tw_dev->state[request_id] = TW_S_COMPLETED;
1508 tw_state_request_finish(tw_dev, request_id);
1509 tw_dev->srb[request_id]->result = (DID_OK << 16);
1510 scsi_done(tw_dev->srb[request_id]);
1515 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1531 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
1536 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1538 param->table_id = TW_UNIT_INFORMATION_TABLE_BASE + tw_dev->srb[request_id]->device->id;
1541 param_value = tw_dev->alignment_physical_address[request_id];
1549 command_que_value = tw_dev->command_packet_physical_address[request_id];
1556 tw_post_command_packet(tw_dev, request_id);
1562 static int tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int request_id)
1570 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1588 tw_transfer_internal(tw_dev, request_id, request_buffer,
1595 static int tw_scsiop_read_capacity(TW_Device_Extension *tw_dev, int request_id)
1605 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1615 command_packet->unit__hostid = TW_UNITHOST_IN(0, tw_dev->srb[request_id]->device->id);
1621 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
1625 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1628 tw_dev->srb[request_id]->device->id;
1631 param_value = tw_dev->alignment_physical_address[request_id];
1639 command_que_value = tw_dev->command_packet_physical_address[request_id];
1646 tw_post_command_packet(tw_dev, request_id);
1652 static int tw_scsiop_read_capacity_complete(TW_Device_Extension *tw_dev, int request_id)
1662 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1689 tw_transfer_internal(tw_dev, request_id, buff, sizeof(buff));
1695 static int tw_scsiop_read_write(TW_Device_Extension *tw_dev, int request_id)
1706 srb = tw_dev->srb[request_id];
1715 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1747 tw_dev->sector_count = num_sectors;
1748 if (tw_dev->sector_count > tw_dev->max_sector_count)
1749 tw_dev->max_sector_count = tw_dev->sector_count;
1759 scsi_for_each_sg(tw_dev->srb[request_id], sg, use_sg, i) {
1766 tw_dev->sgl_entries = scsi_sg_count(tw_dev->srb[request_id]);
1767 if (tw_dev->sgl_entries > tw_dev->max_sgl_entries)
1768 tw_dev->max_sgl_entries = tw_dev->sgl_entries;
1770 command_que_value = tw_dev->command_packet_physical_address[request_id];
1777 tw_post_command_packet(tw_dev, request_id);
1783 static int tw_scsiop_request_sense(TW_Device_Extension *tw_dev, int request_id)
1793 tw_transfer_internal(tw_dev, request_id, request_buffer,
1796 tw_dev->state[request_id] = TW_S_COMPLETED;
1797 tw_state_request_finish(tw_dev, request_id);
1800 tw_dev->srb[request_id]->result = (DID_ERROR << 16);
1801 scsi_done(tw_dev->srb[request_id]);
1807 static int tw_scsiop_synchronize_cache(TW_Device_Extension *tw_dev, int request_id)
1815 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1826 command_packet->unit__hostid = TW_UNITHOST_IN(0, tw_dev->srb[request_id]->device->id);
1830 command_que_value = tw_dev->command_packet_physical_address[request_id];
1837 tw_post_command_packet(tw_dev, request_id);
1843 static int tw_scsiop_test_unit_ready(TW_Device_Extension *tw_dev, int request_id)
1853 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1867 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
1871 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1876 param_value = tw_dev->alignment_physical_address[request_id];
1884 command_que_value = tw_dev->command_packet_physical_address[request_id];
1891 tw_post_command_packet(tw_dev, request_id);
1897 static int tw_scsiop_test_unit_ready_complete(TW_Device_Extension *tw_dev, int request_id)
1904 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1911 if (is_unit_present[tw_dev->srb[request_id]->device->id] & TW_UNIT_ONLINE) {
1912 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 1;
1914 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 0;
1915 tw_dev->srb[request_id]->result = (DID_BAD_TARGET << 16);
1929 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1932 if (test_bit(TW_IN_RESET, &tw_dev->flags))
1936 tw_state_request_start(tw_dev, &request_id);
1939 tw_dev->srb[request_id] = SCpnt;
1947 retval = tw_scsiop_read_write(tw_dev, request_id);
1951 retval = tw_scsiop_test_unit_ready(tw_dev, request_id);
1955 retval = tw_scsiop_inquiry(tw_dev, request_id);
1959 retval = tw_scsiop_read_capacity(tw_dev, request_id);
1963 retval = tw_scsiop_request_sense(tw_dev, request_id);
1967 retval = tw_scsiop_mode_sense(tw_dev, request_id);
1971 retval = tw_scsiop_synchronize_cache(tw_dev, request_id);
1977 printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command);
1978 tw_dev->state[request_id] = TW_S_COMPLETED;
1979 tw_state_request_finish(tw_dev, request_id);
1985 tw_dev->state[request_id] = TW_S_COMPLETED;
1986 tw_state_request_finish(tw_dev, request_id);
2001 TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance;
2008 spin_lock(tw_dev->host->host_lock);
2011 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
2020 if (test_bit(TW_IN_RESET, &tw_dev->flags))
2026 if (tw_decode_bits(tw_dev, status_reg_value, 1)) {
2027 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
2035 TW_CLEAR_HOST_INTERRUPT(tw_dev);
2041 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev);
2042 tw_state_request_start(tw_dev, &request_id);
2043 error = tw_aen_read_queue(tw_dev, request_id);
2045 printk(KERN_WARNING "3w-xxxx: scsi%d: Error reading aen queue.\n", tw_dev->host->host_no);
2046 tw_dev->state[request_id] = TW_S_COMPLETED;
2047 tw_state_request_finish(tw_dev, request_id);
2054 while (tw_dev->pending_request_count > 0) {
2055 request_id = tw_dev->pending_queue[tw_dev->pending_head];
2056 if (tw_dev->state[request_id] != TW_S_PENDING) {
2057 printk(KERN_WARNING "3w-xxxx: scsi%d: Found request id that wasn't pending.\n", tw_dev->host->host_no);
2060 if (tw_post_command_packet(tw_dev, request_id)==0) {
2061 if (tw_dev->pending_head == TW_Q_LENGTH-1) {
2062 tw_dev->pending_head = TW_Q_START;
2064 tw_dev->pending_head = tw_dev->pending_head + 1;
2066 tw_dev->pending_request_count--;
2073 if (tw_dev->pending_request_count == 0)
2074 TW_MASK_COMMAND_INTERRUPT(tw_dev);
2082 response_que.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
2084 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
2090 if (tw_dev->srb[request_id] == NULL) {
2091 tw_decode_sense(tw_dev, request_id, 0);
2093 error = tw_decode_sense(tw_dev, request_id, 1);
2098 if (tw_dev->state[request_id] != TW_S_POSTED) {
2099 if (tw_dev->srb[request_id] != NULL) {
2100 printk(KERN_WARNING "3w-xxxx: scsi%d: Received a request id that wasn't posted.\n", tw_dev->host->host_no);
2108 if (tw_dev->srb[request_id] == NULL) {
2111 if (request_id != tw_dev->chrdev_request_id) {
2112 retval = tw_aen_complete(tw_dev, request_id);
2114 printk(KERN_WARNING "3w-xxxx: scsi%d: Error completing aen.\n", tw_dev->host->host_no);
2117 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
2118 wake_up(&tw_dev->ioctl_wqueue);
2121 switch (tw_dev->srb[request_id]->cmnd[0]) {
2132 error = tw_scsiop_test_unit_ready_complete(tw_dev, request_id);
2136 error = tw_scsiop_inquiry_complete(tw_dev, request_id);
2140 error = tw_scsiop_read_capacity_complete(tw_dev, request_id);
2144 error = tw_scsiop_mode_sense_complete(tw_dev, request_id);
2156 tw_dev->srb[request_id]->result = (DID_OK << 16);
2162 tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
2167 scsi_dma_unmap(tw_dev->srb[request_id]);
2168 scsi_done(tw_dev->srb[request_id]);
2169 tw_dev->state[request_id] = TW_S_COMPLETED;
2170 tw_state_request_finish(tw_dev, request_id);
2171 tw_dev->posted_request_count--;
2176 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
2179 if (tw_decode_bits(tw_dev, status_reg_value, 1)) {
2180 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
2188 spin_unlock(tw_dev->host->host_lock);
2193 static void __tw_shutdown(TW_Device_Extension *tw_dev)
2196 TW_DISABLE_INTERRUPTS(tw_dev);
2199 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2201 printk(KERN_WARNING "3w-xxxx: Shutting down host %d.\n", tw_dev->host->host_no);
2204 if (tw_initconnection(tw_dev, 1)) {
2211 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
2218 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2220 __tw_shutdown(tw_dev);
2254 TW_Device_Extension *tw_dev;
2277 tw_dev = (TW_Device_Extension *)host->hostdata;
2280 tw_dev->host = host;
2281 tw_dev->tw_pci_dev = pdev;
2283 if (tw_initialize_device_extension(tw_dev)) {
2297 tw_dev->base_addr = pci_resource_start(pdev, 0);
2298 if (!tw_dev->base_addr) {
2305 TW_DISABLE_INTERRUPTS(tw_dev);
2308 if (tw_reset_sequence(tw_dev)) {
2330 printk(KERN_WARNING "3w-xxxx: scsi%d: Found a 3ware Storage Controller at 0x%x, IRQ: %d.\n", host->host_no, tw_dev->base_addr, pdev->irq);
2333 retval = request_irq(pdev->irq, tw_interrupt, IRQF_SHARED, "3w-xxxx", tw_dev);
2339 tw_device_extension_list[tw_device_extension_count] = tw_dev;
2343 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
2359 tw_free_device_extension(tw_dev);
2371 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2373 scsi_remove_host(tw_dev->host);
2382 __tw_shutdown(tw_dev);
2388 tw_free_device_extension(tw_dev);
2390 scsi_host_put(tw_dev->host);