• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/scsi/

Lines Matching defs:tw_dev

124 static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header);
125 static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id);
127 static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id);
130 static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host);
131 static void twa_free_request_id(TW_Device_Extension *tw_dev,int request_id);
132 static void twa_get_request_id(TW_Device_Extension *tw_dev, int *request_id);
133 static int twa_initconnection(TW_Device_Extension *tw_dev, int message_credits,
143 static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_command_packet, int request_id, dma_addr_t dma_handle, int length);
144 static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds);
145 static int twa_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds);
146 static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id, char internal);
147 static int twa_reset_device_extension(TW_Device_Extension *tw_dev);
148 static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset);
149 static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry *sglistarg);
150 static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id);
152 static void twa_unmap_scsi_data(TW_Device_Extension *tw_dev, int request_id);
161 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
165 spin_lock_irqsave(tw_dev->host->host_lock, flags);
178 tw_dev->posted_request_count,
179 tw_dev->max_posted_request_count,
180 tw_dev->pending_request_count,
181 tw_dev->max_pending_request_count,
182 tw_dev->sgl_entries,
183 tw_dev->max_sgl_entries,
184 tw_dev->sector_count,
185 tw_dev->max_sector_count,
186 tw_dev->num_resets,
187 tw_dev->aen_count);
188 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
229 static int twa_aen_complete(TW_Device_Extension *tw_dev, int request_id)
237 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
238 tw_dev->posted_request_count--;
240 full_command_packet = tw_dev->command_packet_virt[request_id];
246 if (twa_aen_read_queue(tw_dev, request_id))
259 twa_aen_sync_time(tw_dev, request_id);
263 twa_aen_queue_event(tw_dev, header);
266 if (twa_aen_read_queue(tw_dev, request_id))
275 tw_dev->state[request_id] = TW_S_COMPLETED;
276 twa_free_request_id(tw_dev, request_id);
277 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags);
283 static int twa_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset)
299 full_command_packet = tw_dev->command_packet_virt[request_id];
310 sglist[0].address = tw_dev->generic_buffer_phys[request_id];
313 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Found unaligned address during AEN drain");
318 tw_dev->srb[request_id] = NULL;
322 if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
323 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2, "Error posting request sense");
328 if (twa_poll_response(tw_dev, request_id, 30)) {
329 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "No valid response while draining AEN queue");
330 tw_dev->posted_request_count--;
334 tw_dev->posted_request_count--;
335 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
361 twa_aen_queue_event(tw_dev, header);
369 tw_dev->state[request_id] = TW_S_INITIAL;
374 static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header)
383 tw_dev->aen_count++;
386 event = tw_dev->event_queue[tw_dev->error_index];
390 if (tw_dev->host) {
391 sprintf(host, " scsi%d:", tw_dev->host->host_no);
393 tw_dev->aen_clobber = 1;
405 event->sequence_id = tw_dev->error_sequence_id;
406 tw_dev->error_sequence_id++;
422 tw_dev->aen_count--;
424 if ((tw_dev->error_index + 1) == TW_Q_LENGTH)
425 tw_dev->event_queue_wrapped = 1;
426 tw_dev->error_index = (tw_dev->error_index + 1 ) % TW_Q_LENGTH;
430 static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id)
437 full_command_packet = tw_dev->command_packet_virt[request_id];
448 sglist[0].address = tw_dev->generic_buffer_phys[request_id];
451 tw_dev->srb[request_id] = NULL;
454 if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
455 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x4, "Post failed while reading AEN queue");
478 static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id)
488 full_command_packet = tw_dev->command_packet_virt[request_id];
493 command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
499 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id];
515 tw_dev->srb[request_id] = NULL;
518 twa_post_command_packet(tw_dev, request_id, 1);
522 static int twa_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
529 cpu_addr = pci_alloc_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, &dma_handle);
531 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed");
536 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x6, "Failed to allocate correctly aligned memory");
537 pci_free_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, cpu_addr, dma_handle);
546 tw_dev->command_packet_phys[i] = dma_handle+(i*size);
547 tw_dev->command_packet_virt[i] = (TW_Command_Full *)((unsigned char *)cpu_addr + (i*size));
550 tw_dev->generic_buffer_phys[i] = dma_handle+(i*size);
551 tw_dev->generic_buffer_virt[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
576 static int twa_check_srl(TW_Device_Extension *tw_dev, int *flashed)
583 if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS,
589 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "Initconnection failed while checking SRL");
593 tw_dev->tw_compat_info.working_srl = fw_on_ctlr_srl;
594 tw_dev->tw_compat_info.working_branch = fw_on_ctlr_branch;
595 tw_dev->tw_compat_info.working_build = fw_on_ctlr_build;
599 if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS,
606 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Initconnection (base mode) failed while checking SRL");
611 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x32, "Firmware and driver incompatibility: please upgrade firmware");
613 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x33, "Firmware and driver incompatibility: please upgrade driver");
617 tw_dev->tw_compat_info.working_srl = TW_BASE_FW_SRL;
618 tw_dev->tw_compat_info.working_branch = TW_BASE_FW_BRANCH;
619 tw_dev->tw_compat_info.working_build = TW_BASE_FW_BUILD;
623 strncpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, strlen(TW_DRIVER_VERSION));
624 tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL;
625 tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
626 tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD;
627 tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL;
628 tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH;
629 tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD;
630 tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl;
631 tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch;
632 tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build;
657 TW_Device_Extension *tw_dev = twa_device_extension_list[iminor(inode)];
664 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
683 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, &dma_handle, GFP_KERNEL);
698 spin_lock_irqsave(tw_dev->host->host_lock, flags);
699 twa_get_request_id(tw_dev, &request_id);
702 tw_dev->srb[request_id] = NULL;
705 tw_dev->chrdev_request_id = request_id;
710 twa_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted);
712 memcpy(tw_dev->command_packet_virt[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command_Full));
715 twa_post_command_packet(tw_dev, request_id, 1);
716 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
721 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
724 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
727 tw_dev->host->host_no, TW_DRIVER, 0x37,
730 twa_reset_device_extension(tw_dev);
735 memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virt[request_id], sizeof(TW_Command_Full));
738 spin_lock_irqsave(tw_dev->host->host_lock, flags);
739 tw_dev->posted_request_count--;
740 tw_dev->state[request_id] = TW_S_COMPLETED;
741 twa_free_request_id(tw_dev, request_id);
742 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
748 memcpy(tw_compat_info, &tw_dev->tw_compat_info, sizeof(TW_Compatibility_Info));
751 if (tw_dev->event_queue_wrapped) {
752 if (tw_dev->aen_clobber) {
754 tw_dev->aen_clobber = 0;
758 if (!tw_dev->error_index) {
764 event_index = (tw_dev->error_index - 1 + TW_Q_LENGTH) % TW_Q_LENGTH;
765 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
766 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
769 if (tw_dev->event_queue_wrapped) {
770 if (tw_dev->aen_clobber) {
772 tw_dev->aen_clobber = 0;
775 event_index = tw_dev->error_index;
777 if (!tw_dev->error_index) {
784 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
785 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
792 if (tw_dev->event_queue_wrapped) {
793 if (tw_dev->aen_clobber) {
795 tw_dev->aen_clobber = 0;
797 start_index = tw_dev->error_index;
799 if (!tw_dev->error_index) {
805 event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id + 1) % TW_Q_LENGTH;
807 if (!(tw_dev->event_queue[event_index]->sequence_id > sequence_id)) {
809 tw_dev->aen_clobber = 1;
813 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
814 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
821 if (tw_dev->event_queue_wrapped) {
822 if (tw_dev->aen_clobber) {
824 tw_dev->aen_clobber = 0;
826 start_index = tw_dev->error_index;
828 if (!tw_dev->error_index) {
834 event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id - 1) % TW_Q_LENGTH;
836 if (!(tw_dev->event_queue[event_index]->sequence_id < sequence_id)) {
838 tw_dev->aen_clobber = 1;
842 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
843 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
850 if ((tw_lock->force_flag == 1) || (tw_dev->ioctl_sem_lock == 0) || (current_time_ms >= tw_dev->ioctl_msec)) {
851 tw_dev->ioctl_sem_lock = 1;
852 tw_dev->ioctl_msec = current_time_ms + tw_lock->timeout_msec;
857 tw_lock->time_remaining_msec = tw_dev->ioctl_msec - current_time_ms;
861 if (tw_dev->ioctl_sem_lock == 1) {
862 tw_dev->ioctl_sem_lock = 0;
878 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, cpu_addr, dma_handle);
880 mutex_unlock(&tw_dev->ioctl_lock);
903 static int twa_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value)
909 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xc, "PCI Parity Error: clearing");
910 writel(TW_CONTROL_CLEAR_PARITY_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
914 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xd, "PCI Abort: clearing");
915 writel(TW_CONTROL_CLEAR_PCI_ABORT, TW_CONTROL_REG_ADDR(tw_dev));
916 pci_write_config_word(tw_dev->tw_pci_dev, PCI_STATUS, TW_PCI_CLEAR_PCI_ABORT);
920 if (((tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9650SE) &&
921 (tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9690SA)) ||
922 (!test_bit(TW_IN_RESET, &tw_dev->flags)))
923 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Controller Queue Error: clearing");
924 writel(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
928 if (tw_dev->reset_print == 0) {
929 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Microcontroller Error: clearing");
930 tw_dev->reset_print = 1;
940 static int twa_empty_response_queue(TW_Device_Extension *tw_dev)
945 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
948 response_que_value = readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
949 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
961 static int twa_empty_response_queue_large(TW_Device_Extension *tw_dev)
967 if (tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9000) {
970 response_que_value = readl(TW_RESPONSE_QUEUE_REG_ADDR_LARGE(tw_dev));
985 static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host)
992 full_command_packet = tw_dev->command_packet_virt[request_id];
1002 tw_dev->host->host_no,
1020 memcpy(tw_dev->srb[request_id]->sense_buffer, full_command_packet->header.sense_data, TW_SENSE_DATA_LENGTH);
1021 tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
1031 static void twa_free_device_extension(TW_Device_Extension *tw_dev)
1033 if (tw_dev->command_packet_virt[0])
1034 pci_free_consistent(tw_dev->tw_pci_dev,
1036 tw_dev->command_packet_virt[0],
1037 tw_dev->command_packet_phys[0]);
1039 if (tw_dev->generic_buffer_virt[0])
1040 pci_free_consistent(tw_dev->tw_pci_dev,
1042 tw_dev->generic_buffer_virt[0],
1043 tw_dev->generic_buffer_phys[0]);
1045 kfree(tw_dev->event_queue[0]);
1049 static void twa_free_request_id(TW_Device_Extension *tw_dev, int request_id)
1051 tw_dev->free_queue[tw_dev->free_tail] = request_id;
1052 tw_dev->state[request_id] = TW_S_FINISHED;
1053 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH;
1057 static void *twa_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter_id, int parameter_size_bytes)
1065 full_command_packet = tw_dev->command_packet_virt[request_id];
1075 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id];
1081 command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
1085 twa_post_command_packet(tw_dev, request_id, 1);
1088 if (twa_poll_response(tw_dev, request_id, 30))
1089 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x13, "No valid response during get param")
1093 tw_dev->posted_request_count--;
1094 tw_dev->state[request_id] = TW_S_INITIAL;
1100 static void twa_get_request_id(TW_Device_Extension *tw_dev, int *request_id)
1102 *request_id = tw_dev->free_queue[tw_dev->free_head];
1103 tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH;
1104 tw_dev->state[*request_id] = TW_S_STARTED;
1108 static int twa_initconnection(TW_Device_Extension *tw_dev, int message_credits,
1124 full_command_packet = tw_dev->command_packet_virt[request_id];
1149 twa_post_command_packet(tw_dev, request_id, 1);
1152 if (twa_poll_response(tw_dev, request_id, 30)) {
1153 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x15, "No valid response during init connection");
1165 tw_dev->posted_request_count--;
1166 tw_dev->state[request_id] = TW_S_INITIAL;
1172 static int twa_initialize_device_extension(TW_Device_Extension *tw_dev)
1177 if (twa_allocate_memory(tw_dev, sizeof(TW_Command_Full), 0)) {
1178 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x16, "Command packet memory allocation failed");
1183 if (twa_allocate_memory(tw_dev, TW_SECTOR_SIZE, 1)) {
1184 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x17, "Generic memory allocation failed");
1189 tw_dev->event_queue[0] = kcalloc(TW_Q_LENGTH, sizeof(TW_Event), GFP_KERNEL);
1190 if (!tw_dev->event_queue[0]) {
1191 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x18, "Event info memory allocation failed");
1197 tw_dev->event_queue[i] = (TW_Event *)((unsigned char *)tw_dev->event_queue[0] + (i * sizeof(TW_Event)));
1198 tw_dev->free_queue[i] = i;
1199 tw_dev->state[i] = TW_S_INITIAL;
1202 tw_dev->pending_head = TW_Q_START;
1203 tw_dev->pending_tail = TW_Q_START;
1204 tw_dev->free_head = TW_Q_START;
1205 tw_dev->free_tail = TW_Q_START;
1206 tw_dev->error_sequence_id = 1;
1207 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1209 mutex_init(&tw_dev->ioctl_lock);
1210 init_waitqueue_head(&tw_dev->ioctl_wqueue);
1224 TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance;
1228 spin_lock(tw_dev->host->host_lock);
1231 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1240 if (test_bit(TW_IN_RESET, &tw_dev->flags))
1245 if (twa_decode_bits(tw_dev, status_reg_value)) {
1246 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1253 TW_CLEAR_HOST_INTERRUPT(tw_dev);
1257 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev);
1258 if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags))) {
1259 twa_get_request_id(tw_dev, &request_id);
1261 error = twa_aen_read_queue(tw_dev, request_id);
1263 tw_dev->state[request_id] = TW_S_COMPLETED;
1264 twa_free_request_id(tw_dev, request_id);
1265 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags);
1272 TW_MASK_COMMAND_INTERRUPT(tw_dev);
1274 while (tw_dev->pending_request_count > 0) {
1275 request_id = tw_dev->pending_queue[tw_dev->pending_head];
1276 if (tw_dev->state[request_id] != TW_S_PENDING) {
1277 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x19, "Found request id that wasn't pending");
1278 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1281 if (twa_post_command_packet(tw_dev, request_id, 1)==0) {
1282 tw_dev->pending_head = (tw_dev->pending_head + 1) % TW_Q_LENGTH;
1283 tw_dev->pending_request_count--;
1297 response_que.value = readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1299 full_command_packet = tw_dev->command_packet_virt[request_id];
1303 if (tw_dev->srb[request_id] != NULL) {
1304 error = twa_fill_sense(tw_dev, request_id, 1, 1);
1307 if (request_id != tw_dev->chrdev_request_id) {
1308 error = twa_fill_sense(tw_dev, request_id, 0, 1);
1314 if (tw_dev->state[request_id] != TW_S_POSTED) {
1315 if (tw_dev->srb[request_id] != NULL) {
1316 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Received a request id that wasn't posted");
1317 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1323 if (tw_dev->srb[request_id] == NULL) {
1324 if (request_id != tw_dev->chrdev_request_id) {
1325 if (twa_aen_complete(tw_dev, request_id))
1326 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1b, "Error completing AEN during attention interrupt");
1328 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1329 wake_up(&tw_dev->ioctl_wqueue);
1334 cmd = tw_dev->srb[request_id];
1336 twa_scsiop_execute_scsi_complete(tw_dev, request_id);
1350 if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_id]))
1355 tw_dev->state[request_id] = TW_S_COMPLETED;
1356 twa_free_request_id(tw_dev, request_id);
1357 tw_dev->posted_request_count--;
1358 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
1359 twa_unmap_scsi_data(tw_dev, request_id);
1363 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1365 if (twa_decode_bits(tw_dev, status_reg_value)) {
1366 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1374 spin_unlock(tw_dev->host->host_lock);
1379 static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_command_packet, int request_id, dma_addr_t dma_handle, int length)
1405 if (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)
1418 static int twa_map_scsi_sg_data(TW_Device_Extension *tw_dev, int request_id)
1421 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1427 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1c, "Failed to map scatter gather list");
1438 static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds)
1442 TW_Command_Full *full_command_packet = tw_dev->command_packet_virt[request_id];
1444 if (twa_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, seconds) == 0) {
1445 response_queue.value = readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1448 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1e, "Found unexpected request id while polling for response");
1454 twa_fill_sense(tw_dev, request_id, 0, 0);
1461 twa_fill_sense(tw_dev, request_id, 0, 0);
1475 static int twa_poll_status(TW_Device_Extension *tw_dev, u32 flag, int seconds)
1481 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1485 twa_decode_bits(tw_dev, status_reg_value);
1488 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1491 twa_decode_bits(tw_dev, status_reg_value);
1504 static int twa_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds)
1510 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1514 twa_decode_bits(tw_dev, status_reg_value);
1517 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1519 twa_decode_bits(tw_dev, status_reg_value);
1532 static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id, char internal)
1538 command_que_value = tw_dev->command_packet_phys[request_id];
1541 if ((tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) ||
1542 (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)) {
1544 writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev));
1547 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1550 twa_decode_bits(tw_dev, status_reg_value);
1552 if (((tw_dev->pending_request_count > 0) && (tw_dev->state[request_id] != TW_S_PENDING)) || (status_reg_value & TW_STATUS_COMMAND_QUEUE_FULL)) {
1561 if (tw_dev->state[request_id] != TW_S_PENDING) {
1562 tw_dev->state[request_id] = TW_S_PENDING;
1563 tw_dev->pending_request_count++;
1564 if (tw_dev->pending_request_count > tw_dev->max_pending_request_count) {
1565 tw_dev->max_pending_request_count = tw_dev->pending_request_count;
1567 tw_dev->pending_queue[tw_dev->pending_tail] = request_id;
1568 tw_dev->pending_tail = (tw_dev->pending_tail + 1) % TW_Q_LENGTH;
1570 TW_UNMASK_COMMAND_INTERRUPT(tw_dev);
1573 if ((tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) ||
1574 (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)) {
1576 writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev) + 0x4);
1580 writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1581 writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR(tw_dev) + 0x4);
1583 writel(TW_COMMAND_OFFSET + command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1586 tw_dev->state[request_id] = TW_S_POSTED;
1587 tw_dev->posted_request_count++;
1588 if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) {
1589 tw_dev->max_posted_request_count = tw_dev->posted_request_count;
1598 static int twa_reset_device_extension(TW_Device_Extension *tw_dev)
1604 set_bit(TW_IN_RESET, &tw_dev->flags);
1605 TW_DISABLE_INTERRUPTS(tw_dev);
1606 TW_MASK_COMMAND_INTERRUPT(tw_dev);
1607 spin_lock_irqsave(tw_dev->host->host_lock, flags);
1611 if ((tw_dev->state[i] != TW_S_FINISHED) &&
1612 (tw_dev->state[i] != TW_S_INITIAL) &&
1613 (tw_dev->state[i] != TW_S_COMPLETED)) {
1614 if (tw_dev->srb[i]) {
1615 tw_dev->srb[i]->result = (DID_RESET << 16);
1616 tw_dev->srb[i]->scsi_done(tw_dev->srb[i]);
1617 twa_unmap_scsi_data(tw_dev, i);
1624 tw_dev->free_queue[i] = i;
1625 tw_dev->state[i] = TW_S_INITIAL;
1627 tw_dev->free_head = TW_Q_START;
1628 tw_dev->free_tail = TW_Q_START;
1629 tw_dev->posted_request_count = 0;
1630 tw_dev->pending_request_count = 0;
1631 tw_dev->pending_head = TW_Q_START;
1632 tw_dev->pending_tail = TW_Q_START;
1633 tw_dev->reset_print = 0;
1635 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1637 if (twa_reset_sequence(tw_dev, 1))
1640 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1641 clear_bit(TW_IN_RESET, &tw_dev->flags);
1642 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1650 static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset)
1656 TW_SOFT_RESET(tw_dev);
1658 if (twa_empty_response_queue_large(tw_dev)) {
1659 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x36, "Response queue (large) empty failed during reset sequence");
1667 if (twa_poll_status(tw_dev, TW_STATUS_MICROCONTROLLER_READY | (do_soft_reset == 1 ? TW_STATUS_ATTENTION_INTERRUPT : 0), 60)) {
1668 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1f, "Microcontroller not ready during reset sequence");
1675 if (twa_empty_response_queue(tw_dev)) {
1676 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x20, "Response queue empty failed during reset sequence");
1685 if (twa_check_srl(tw_dev, &flashed)) {
1686 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x21, "Compatibility check failed during reset sequence");
1698 if (twa_aen_drain_queue(tw_dev, soft_reset)) {
1699 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x22, "AEN drain failed during reset sequence");
1717 TW_Device_Extension *tw_dev;
1719 tw_dev = (TW_Device_Extension *)sdev->host->hostdata;
1741 TW_Device_Extension *tw_dev = NULL;
1744 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1746 tw_dev->num_resets++;
1753 mutex_lock(&tw_dev->ioctl_lock);
1756 if (twa_reset_device_extension(tw_dev)) {
1757 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2b, "Controller reset failed during scsi host reset");
1763 mutex_unlock(&tw_dev->ioctl_lock);
1771 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1774 if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
1780 if ((SCpnt->device->lun != 0) && (tw_dev->tw_compat_info.working_srl < TW_FW_SRL_LUNS_SUPPORTED)) {
1791 twa_get_request_id(tw_dev, &request_id);
1794 tw_dev->srb[request_id] = SCpnt;
1799 retval = twa_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL);
1802 twa_free_request_id(tw_dev, request_id);
1805 tw_dev->state[request_id] = TW_S_COMPLETED;
1806 twa_free_request_id(tw_dev, request_id);
1816 static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_sg, TW_SG_Entry *sglistarg)
1826 if (tw_dev->srb[request_id]) {
1827 srb = tw_dev->srb[request_id];
1833 full_command_packet = tw_dev->command_packet_virt[request_id];
1869 tw_dev->generic_buffer_virt[request_id],
1871 command_packet->sg_list[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
1874 sg_count = twa_map_scsi_sg_data(tw_dev, request_id);
1882 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2e, "Found unaligned sgl address during execute scsi");
1887 command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id])));
1895 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2f, "Found unaligned sgl address during internal post");
1911 tw_dev->sector_count = num_sectors;
1912 if (tw_dev->sector_count > tw_dev->max_sector_count)
1913 tw_dev->max_sector_count = tw_dev->sector_count;
1917 tw_dev->sgl_entries = scsi_sg_count(tw_dev->srb[request_id]);
1918 if (tw_dev->sgl_entries > tw_dev->max_sgl_entries)
1919 tw_dev->max_sgl_entries = tw_dev->sgl_entries;
1924 retval = twa_post_command_packet(tw_dev, request_id, 0);
1926 twa_post_command_packet(tw_dev, request_id, 1);
1934 static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id)
1936 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1942 void *buf = tw_dev->generic_buffer_virt[request_id];
1950 static void __twa_shutdown(TW_Device_Extension *tw_dev)
1953 TW_DISABLE_INTERRUPTS(tw_dev);
1956 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
1958 printk(KERN_WARNING "3w-9xxx: Shutting down host %d.\n", tw_dev->host->host_no);
1961 if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
1962 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x31, "Connection shutdown failed");
1968 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1975 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
1977 __twa_shutdown(tw_dev);
1991 static void twa_unmap_scsi_data(TW_Device_Extension *tw_dev, int request_id)
1993 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
2031 TW_Device_Extension *tw_dev;
2059 tw_dev = (TW_Device_Extension *)host->hostdata;
2062 tw_dev->host = host;
2063 tw_dev->tw_pci_dev = pdev;
2065 if (twa_initialize_device_extension(tw_dev)) {
2066 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x25, "Failed to initialize device extension");
2073 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x26, "Failed to get mem region");
2086 tw_dev->base_addr = ioremap(mem_addr, mem_len);
2087 if (!tw_dev->base_addr) {
2088 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x35, "Failed to ioremap");
2093 TW_DISABLE_INTERRUPTS(tw_dev);
2096 if (twa_reset_sequence(tw_dev, 0))
2109 host->max_lun = TW_MAX_LUNS(tw_dev->tw_compat_info.working_srl);
2115 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x27, "scsi add host failed");
2125 (char *)twa_get_param(tw_dev, 0, TW_VERSION_TABLE,
2127 (char *)twa_get_param(tw_dev, 1, TW_VERSION_TABLE,
2129 le32_to_cpu(*(int *)twa_get_param(tw_dev, 2, TW_INFORMATION_TABLE,
2135 set_bit(TW_USING_MSI, &tw_dev->flags);
2138 retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev);
2140 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x30, "Error requesting IRQ");
2144 twa_device_extension_list[twa_device_extension_count] = tw_dev;
2148 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
2160 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2164 iounmap(tw_dev->base_addr);
2168 twa_free_device_extension(tw_dev);
2180 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2182 scsi_remove_host(tw_dev->host);
2191 __twa_shutdown(tw_dev);
2194 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2198 iounmap(tw_dev->base_addr);
2204 twa_free_device_extension(tw_dev);
2206 scsi_host_put(tw_dev->host);
2216 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2218 printk(KERN_WARNING "3w-9xxx: Suspending host %d.\n", tw_dev->host->host_no);
2220 TW_DISABLE_INTERRUPTS(tw_dev);
2221 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2223 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2227 if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
2228 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x38, "Connection shutdown failed during suspend");
2232 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
2246 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2248 printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", tw_dev->host->host_no);
2255 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x39, "Enable device failed during resume");
2272 if (twa_reset_sequence(tw_dev, 0)) {
2278 retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev);
2280 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x42, "Error requesting IRQ during resume");
2286 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2290 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);