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) | (CHECK_CONDITION << 1);
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 response_que_value = 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);
541 static int tw_aen_read_queue(TW_Device_Extension *tw_dev, int request_id)
551 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
554 tw_decode_bits(tw_dev, status_reg_value, 1);
557 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
561 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
569 command_que_value = tw_dev->command_packet_physical_address[request_id];
575 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
579 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
584 param_value = tw_dev->alignment_physical_address[request_id];
595 tw_dev->srb[request_id] = NULL; /* Flag internal command */
596 tw_dev->state[request_id] = TW_S_POSTED;
597 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
607 static int tw_aen_complete(TW_Device_Extension *tw_dev, int request_id)
614 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
618 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
624 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: INFO: AEN queue overflow.\n", tw_dev->host->host_no);
629 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: %s%d.\n", tw_dev->host->host_no, tw_aen_string[aen & 0xff], aen >> 8);
632 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: %s.\n", tw_dev->host->host_no, tw_aen_string[aen & 0xff]);
635 printk(KERN_WARNING "3w-xxxx: scsi%d: Received AEN %d.\n", tw_dev->host->host_no, aen);
639 tw_dev->aen_count++;
642 tw_dev->aen_queue[tw_dev->aen_tail] = aen;
643 if (tw_dev->aen_tail == TW_Q_LENGTH - 1) {
644 tw_dev->aen_tail = TW_Q_START;
646 tw_dev->aen_tail = tw_dev->aen_tail + 1;
648 if (tw_dev->aen_head == tw_dev->aen_tail) {
649 if (tw_dev->aen_head == TW_Q_LENGTH - 1) {
650 tw_dev->aen_head = TW_Q_START;
652 tw_dev->aen_head = tw_dev->aen_head + 1;
656 error = tw_aen_read_queue(tw_dev, request_id);
658 printk(KERN_WARNING "3w-xxxx: scsi%d: Error completing AEN.\n", tw_dev->host->host_no);
659 tw_dev->state[request_id] = TW_S_COMPLETED;
660 tw_state_request_finish(tw_dev, request_id);
663 tw_dev->state[request_id] = TW_S_COMPLETED;
664 tw_state_request_finish(tw_dev, request_id);
671 static int tw_aen_drain_queue(TW_Device_Extension *tw_dev)
688 if (tw_poll_status(tw_dev, TW_STATUS_ATTENTION_INTERRUPT | TW_STATUS_MICROCONTROLLER_READY, 30)) {
692 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev);
695 tw_empty_response_que(tw_dev);
698 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
702 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
710 command_que_value = tw_dev->command_packet_physical_address[request_id];
717 if (tw_dev->alignment_virtual_address[request_id] == NULL) {
721 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
726 param_value = tw_dev->alignment_physical_address[request_id];
737 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
740 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
741 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
753 tw_decode_sense(tw_dev, request_id, 0);
779 tw_dev->aen_count++;
797 tw_dev->aen_count++;
803 tw_dev->aen_queue[tw_dev->aen_tail] = aen;
804 if (tw_dev->aen_tail == TW_Q_LENGTH - 1) {
805 tw_dev->aen_tail = TW_Q_START;
807 tw_dev->aen_tail = tw_dev->aen_tail + 1;
809 if (tw_dev->aen_head == tw_dev->aen_tail) {
810 if (tw_dev->aen_head == TW_Q_LENGTH - 1) {
811 tw_dev->aen_head = TW_Q_START;
813 tw_dev->aen_head = tw_dev->aen_head + 1;
829 static int tw_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
837 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
844 if ((unsigned long)cpu_addr % (tw_dev->tw_pci_dev->device == TW_DEVICE_ID ? TW_ALIGNMENT_6000 : TW_ALIGNMENT_7000)) {
846 dma_free_coherent(&tw_dev->tw_pci_dev->dev, size * TW_Q_LENGTH,
856 tw_dev->command_packet_physical_address[i] = dma_handle+(i*size);
857 tw_dev->command_packet_virtual_address[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
860 tw_dev->alignment_physical_address[i] = dma_handle+(i*size);
861 tw_dev->alignment_virtual_address[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
886 TW_Device_Extension *tw_dev = tw_device_extension_list[iminor(inode)];
894 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
913 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, &dma_handle, GFP_KERNEL);
936 spin_lock_irqsave(tw_dev->host->host_lock, flags);
937 if (tw_dev->aen_head == tw_dev->aen_tail) {
940 tw_aen_code = tw_dev->aen_queue[tw_dev->aen_head];
941 if (tw_dev->aen_head == TW_Q_LENGTH - 1) {
942 tw_dev->aen_head = TW_Q_START;
944 tw_dev->aen_head = tw_dev->aen_head + 1;
947 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
952 spin_lock_irqsave(tw_dev->host->host_lock, flags);
954 tw_state_request_start(tw_dev, &request_id);
957 tw_dev->srb[request_id] = NULL;
960 tw_dev->chrdev_request_id = request_id;
980 memcpy(tw_dev->command_packet_virtual_address[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command));
983 tw_post_command_packet(tw_dev, request_id);
984 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
989 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
992 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
994 printk(KERN_WARNING "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cmd);
996 if (tw_reset_device_extension(tw_dev)) {
997 printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_no);
1003 memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virtual_address[request_id], sizeof(TW_Command));
1006 spin_lock_irqsave(tw_dev->host->host_lock, flags);
1007 tw_dev->posted_request_count--;
1008 tw_dev->state[request_id] = TW_S_COMPLETED;
1009 tw_state_request_finish(tw_dev, request_id);
1010 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1023 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle);
1025 mutex_unlock(&tw_dev->ioctl_lock);
1059 static void tw_free_device_extension(TW_Device_Extension *tw_dev)
1064 if (tw_dev->command_packet_virtual_address[0])
1065 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
1067 tw_dev->command_packet_virtual_address[0],
1068 tw_dev->command_packet_physical_address[0]);
1070 if (tw_dev->alignment_virtual_address[0])
1071 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
1073 tw_dev->alignment_virtual_address[0],
1074 tw_dev->alignment_physical_address[0]);
1078 static int tw_initconnection(TW_Device_Extension *tw_dev, int message_credits)
1088 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
1093 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1102 command_que_value = tw_dev->command_packet_physical_address[request_id];
1110 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1113 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
1114 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1124 tw_decode_sense(tw_dev, request_id, 0);
1132 static int tw_setfeature(TW_Device_Extension *tw_dev, int parm, int param_size,
1143 if (tw_dev->command_packet_virtual_address[request_id] == NULL) {
1147 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
1149 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1157 param_value = tw_dev->alignment_physical_address[request_id];
1160 tw_dev->state[request_id] = TW_S_COMPLETED;
1161 tw_state_request_finish(tw_dev, request_id);
1162 tw_dev->srb[request_id]->result = (DID_OK << 16);
1163 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
1172 command_que_value = tw_dev->command_packet_physical_address[request_id];
1179 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1182 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) {
1183 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1193 tw_decode_sense(tw_dev, request_id, 0);
1202 static int tw_reset_sequence(TW_Device_Extension *tw_dev)
1210 TW_SOFT_RESET(tw_dev);
1212 error = tw_aen_drain_queue(tw_dev);
1214 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN drain failed, retrying.\n", tw_dev->host->host_no);
1220 if (tw_check_errors(tw_dev)) {
1221 printk(KERN_WARNING "3w-xxxx: scsi%d: Controller errors found, retrying.\n", tw_dev->host->host_no);
1231 printk(KERN_WARNING "3w-xxxx: scsi%d: Controller errors, card not responding, check all cabling.\n", tw_dev->host->host_no);
1235 error = tw_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS);
1237 printk(KERN_WARNING "3w-xxxx: scsi%d: Connection initialization failed.\n", tw_dev->host->host_no);
1241 error = tw_setfeature(tw_dev, 2, 1, &c);
1250 static int tw_initialize_device_extension(TW_Device_Extension *tw_dev)
1257 error = tw_allocate_memory(tw_dev, sizeof(TW_Command), 0);
1264 error = tw_allocate_memory(tw_dev, sizeof(TW_Sector), 1);
1271 tw_dev->free_queue[i] = i;
1272 tw_dev->state[i] = TW_S_INITIAL;
1275 tw_dev->pending_head = TW_Q_START;
1276 tw_dev->pending_tail = TW_Q_START;
1277 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1279 mutex_init(&tw_dev->ioctl_lock);
1280 init_waitqueue_head(&tw_dev->ioctl_wqueue);
1286 static int tw_reset_device_extension(TW_Device_Extension *tw_dev)
1294 set_bit(TW_IN_RESET, &tw_dev->flags);
1295 TW_DISABLE_INTERRUPTS(tw_dev);
1296 TW_MASK_COMMAND_INTERRUPT(tw_dev);
1297 spin_lock_irqsave(tw_dev->host->host_lock, flags);
1301 if ((tw_dev->state[i] != TW_S_FINISHED) &&
1302 (tw_dev->state[i] != TW_S_INITIAL) &&
1303 (tw_dev->state[i] != TW_S_COMPLETED)) {
1304 srb = tw_dev->srb[i];
1315 tw_dev->free_queue[i] = i;
1316 tw_dev->state[i] = TW_S_INITIAL;
1318 tw_dev->free_head = TW_Q_START;
1319 tw_dev->free_tail = TW_Q_START;
1320 tw_dev->posted_request_count = 0;
1321 tw_dev->pending_request_count = 0;
1322 tw_dev->pending_head = TW_Q_START;
1323 tw_dev->pending_tail = TW_Q_START;
1324 tw_dev->reset_print = 0;
1326 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1328 if (tw_reset_sequence(tw_dev)) {
1329 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset sequence failed.\n", tw_dev->host->host_no);
1333 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1334 clear_bit(TW_IN_RESET, &tw_dev->flags);
1335 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1345 TW_Device_Extension *tw_dev;
1348 tw_dev = (TW_Device_Extension *)sdev->host->hostdata;
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 tw_dev->srb[request_id]->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 tw_dev->srb[request_id]->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);
1928 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1931 if (test_bit(TW_IN_RESET, &tw_dev->flags))
1938 tw_state_request_start(tw_dev, &request_id);
1941 tw_dev->srb[request_id] = SCpnt;
1949 retval = tw_scsiop_read_write(tw_dev, request_id);
1953 retval = tw_scsiop_test_unit_ready(tw_dev, request_id);
1957 retval = tw_scsiop_inquiry(tw_dev, request_id);
1961 retval = tw_scsiop_read_capacity(tw_dev, request_id);
1965 retval = tw_scsiop_request_sense(tw_dev, request_id);
1969 retval = tw_scsiop_mode_sense(tw_dev, request_id);
1973 retval = tw_scsiop_synchronize_cache(tw_dev, request_id);
1979 printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command);
1980 tw_dev->state[request_id] = TW_S_COMPLETED;
1981 tw_state_request_finish(tw_dev, request_id);
1988 tw_dev->state[request_id] = TW_S_COMPLETED;
1989 tw_state_request_finish(tw_dev, request_id);
2004 TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance;
2011 spin_lock(tw_dev->host->host_lock);
2014 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
2023 if (test_bit(TW_IN_RESET, &tw_dev->flags))
2029 if (tw_decode_bits(tw_dev, status_reg_value, 1)) {
2030 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
2038 TW_CLEAR_HOST_INTERRUPT(tw_dev);
2044 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev);
2045 tw_state_request_start(tw_dev, &request_id);
2046 error = tw_aen_read_queue(tw_dev, request_id);
2048 printk(KERN_WARNING "3w-xxxx: scsi%d: Error reading aen queue.\n", tw_dev->host->host_no);
2049 tw_dev->state[request_id] = TW_S_COMPLETED;
2050 tw_state_request_finish(tw_dev, request_id);
2057 while (tw_dev->pending_request_count > 0) {
2058 request_id = tw_dev->pending_queue[tw_dev->pending_head];
2059 if (tw_dev->state[request_id] != TW_S_PENDING) {
2060 printk(KERN_WARNING "3w-xxxx: scsi%d: Found request id that wasn't pending.\n", tw_dev->host->host_no);
2063 if (tw_post_command_packet(tw_dev, request_id)==0) {
2064 if (tw_dev->pending_head == TW_Q_LENGTH-1) {
2065 tw_dev->pending_head = TW_Q_START;
2067 tw_dev->pending_head = tw_dev->pending_head + 1;
2069 tw_dev->pending_request_count--;
2076 if (tw_dev->pending_request_count == 0)
2077 TW_MASK_COMMAND_INTERRUPT(tw_dev);
2085 response_que.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
2087 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id];
2093 if (tw_dev->srb[request_id] == NULL) {
2094 tw_decode_sense(tw_dev, request_id, 0);
2096 error = tw_decode_sense(tw_dev, request_id, 1);
2101 if (tw_dev->state[request_id] != TW_S_POSTED) {
2102 if (tw_dev->srb[request_id] != NULL) {
2103 printk(KERN_WARNING "3w-xxxx: scsi%d: Received a request id that wasn't posted.\n", tw_dev->host->host_no);
2111 if (tw_dev->srb[request_id] == NULL) {
2114 if (request_id != tw_dev->chrdev_request_id) {
2115 retval = tw_aen_complete(tw_dev, request_id);
2117 printk(KERN_WARNING "3w-xxxx: scsi%d: Error completing aen.\n", tw_dev->host->host_no);
2120 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
2121 wake_up(&tw_dev->ioctl_wqueue);
2124 switch (tw_dev->srb[request_id]->cmnd[0]) {
2135 error = tw_scsiop_test_unit_ready_complete(tw_dev, request_id);
2139 error = tw_scsiop_inquiry_complete(tw_dev, request_id);
2143 error = tw_scsiop_read_capacity_complete(tw_dev, request_id);
2147 error = tw_scsiop_mode_sense_complete(tw_dev, request_id);
2159 tw_dev->srb[request_id]->result = (DID_OK << 16);
2165 tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
2170 scsi_dma_unmap(tw_dev->srb[request_id]);
2171 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
2172 tw_dev->state[request_id] = TW_S_COMPLETED;
2173 tw_state_request_finish(tw_dev, request_id);
2174 tw_dev->posted_request_count--;
2179 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev));
2182 if (tw_decode_bits(tw_dev, status_reg_value, 1)) {
2183 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
2191 spin_unlock(tw_dev->host->host_lock);
2196 static void __tw_shutdown(TW_Device_Extension *tw_dev)
2199 TW_DISABLE_INTERRUPTS(tw_dev);
2202 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2204 printk(KERN_WARNING "3w-xxxx: Shutting down host %d.\n", tw_dev->host->host_no);
2207 if (tw_initconnection(tw_dev, 1)) {
2214 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
2221 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2223 __tw_shutdown(tw_dev);
2257 TW_Device_Extension *tw_dev;
2280 tw_dev = (TW_Device_Extension *)host->hostdata;
2283 tw_dev->host = host;
2284 tw_dev->tw_pci_dev = pdev;
2286 if (tw_initialize_device_extension(tw_dev)) {
2300 tw_dev->base_addr = pci_resource_start(pdev, 0);
2301 if (!tw_dev->base_addr) {
2308 TW_DISABLE_INTERRUPTS(tw_dev);
2311 if (tw_reset_sequence(tw_dev)) {
2333 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);
2336 retval = request_irq(pdev->irq, tw_interrupt, IRQF_SHARED, "3w-xxxx", tw_dev);
2342 tw_device_extension_list[tw_device_extension_count] = tw_dev;
2346 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
2362 tw_free_device_extension(tw_dev);
2374 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2376 scsi_remove_host(tw_dev->host);
2385 __tw_shutdown(tw_dev);
2391 tw_free_device_extension(tw_dev);
2393 scsi_host_put(tw_dev->host);