Lines Matching refs:tw_dev
121 static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header);
122 static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id);
124 static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id);
127 static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host);
128 static void twa_free_request_id(TW_Device_Extension *tw_dev,int request_id);
129 static void twa_get_request_id(TW_Device_Extension *tw_dev, int *request_id);
130 static int twa_initconnection(TW_Device_Extension *tw_dev, int message_credits,
140 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);
141 static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds);
142 static int twa_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds);
143 static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id, char internal);
144 static int twa_reset_device_extension(TW_Device_Extension *tw_dev);
145 static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset);
146 static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
149 static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id);
159 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
163 spin_lock_irqsave(tw_dev->host->host_lock, flags);
176 tw_dev->posted_request_count,
177 tw_dev->max_posted_request_count,
178 tw_dev->pending_request_count,
179 tw_dev->max_pending_request_count,
180 tw_dev->sgl_entries,
181 tw_dev->max_sgl_entries,
182 tw_dev->sector_count,
183 tw_dev->max_sector_count,
184 tw_dev->num_resets,
185 tw_dev->aen_count);
186 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
226 static int twa_aen_complete(TW_Device_Extension *tw_dev, int request_id)
234 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
235 tw_dev->posted_request_count--;
237 full_command_packet = tw_dev->command_packet_virt[request_id];
243 if (twa_aen_read_queue(tw_dev, request_id))
256 twa_aen_sync_time(tw_dev, request_id);
260 twa_aen_queue_event(tw_dev, header);
263 if (twa_aen_read_queue(tw_dev, request_id))
272 tw_dev->state[request_id] = TW_S_COMPLETED;
273 twa_free_request_id(tw_dev, request_id);
274 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags);
280 static int twa_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset)
296 full_command_packet = tw_dev->command_packet_virt[request_id];
307 sglist[0].address = tw_dev->generic_buffer_phys[request_id];
310 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Found unaligned address during AEN drain");
315 tw_dev->srb[request_id] = NULL;
319 if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
320 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2, "Error posting request sense");
325 if (twa_poll_response(tw_dev, request_id, 30)) {
326 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "No valid response while draining AEN queue");
327 tw_dev->posted_request_count--;
331 tw_dev->posted_request_count--;
332 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
358 twa_aen_queue_event(tw_dev, header);
366 tw_dev->state[request_id] = TW_S_INITIAL;
371 static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header)
379 tw_dev->aen_count++;
382 event = tw_dev->event_queue[tw_dev->error_index];
386 if (tw_dev->host) {
387 sprintf(host, " scsi%d:", tw_dev->host->host_no);
389 tw_dev->aen_clobber = 1;
401 event->sequence_id = tw_dev->error_sequence_id;
402 tw_dev->error_sequence_id++;
418 tw_dev->aen_count--;
420 if ((tw_dev->error_index + 1) == TW_Q_LENGTH)
421 tw_dev->event_queue_wrapped = 1;
422 tw_dev->error_index = (tw_dev->error_index + 1 ) % TW_Q_LENGTH;
426 static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id)
433 full_command_packet = tw_dev->command_packet_virt[request_id];
444 sglist[0].address = tw_dev->generic_buffer_phys[request_id];
447 tw_dev->srb[request_id] = NULL;
450 if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
451 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x4, "Post failed while reading AEN queue");
474 static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id)
483 full_command_packet = tw_dev->command_packet_virt[request_id];
488 command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
494 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id];
509 tw_dev->srb[request_id] = NULL;
512 twa_post_command_packet(tw_dev, request_id, 1);
516 static int twa_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
523 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
526 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed");
531 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x6, "Failed to allocate correctly aligned memory");
532 dma_free_coherent(&tw_dev->tw_pci_dev->dev, size * TW_Q_LENGTH,
542 tw_dev->command_packet_phys[i] = dma_handle+(i*size);
543 tw_dev->command_packet_virt[i] = (TW_Command_Full *)((unsigned char *)cpu_addr + (i*size));
546 tw_dev->generic_buffer_phys[i] = dma_handle+(i*size);
547 tw_dev->generic_buffer_virt[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
572 static int twa_check_srl(TW_Device_Extension *tw_dev, int *flashed)
579 if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS,
585 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "Initconnection failed while checking SRL");
589 tw_dev->tw_compat_info.working_srl = fw_on_ctlr_srl;
590 tw_dev->tw_compat_info.working_branch = fw_on_ctlr_branch;
591 tw_dev->tw_compat_info.working_build = fw_on_ctlr_build;
595 if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS,
602 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Initconnection (base mode) failed while checking SRL");
607 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x32, "Firmware and driver incompatibility: please upgrade firmware");
609 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x33, "Firmware and driver incompatibility: please upgrade driver");
613 tw_dev->tw_compat_info.working_srl = TW_BASE_FW_SRL;
614 tw_dev->tw_compat_info.working_branch = TW_BASE_FW_BRANCH;
615 tw_dev->tw_compat_info.working_build = TW_BASE_FW_BUILD;
619 strlcpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION,
620 sizeof(tw_dev->tw_compat_info.driver_version));
621 tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL;
622 tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
623 tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD;
624 tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL;
625 tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH;
626 tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD;
627 tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl;
628 tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch;
629 tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build;
653 TW_Device_Extension *tw_dev = twa_device_extension_list[iminor(inode)];
660 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
679 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);
694 spin_lock_irqsave(tw_dev->host->host_lock, flags);
695 twa_get_request_id(tw_dev, &request_id);
698 tw_dev->srb[request_id] = NULL;
701 tw_dev->chrdev_request_id = request_id;
706 twa_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted);
708 memcpy(tw_dev->command_packet_virt[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command_Full));
711 twa_post_command_packet(tw_dev, request_id, 1);
712 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
717 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
720 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
723 tw_dev->host->host_no, TW_DRIVER, 0x37,
726 twa_reset_device_extension(tw_dev);
731 memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virt[request_id], sizeof(TW_Command_Full));
734 spin_lock_irqsave(tw_dev->host->host_lock, flags);
735 tw_dev->posted_request_count--;
736 tw_dev->state[request_id] = TW_S_COMPLETED;
737 twa_free_request_id(tw_dev, request_id);
738 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
744 memcpy(tw_compat_info, &tw_dev->tw_compat_info, sizeof(TW_Compatibility_Info));
747 if (tw_dev->event_queue_wrapped) {
748 if (tw_dev->aen_clobber) {
750 tw_dev->aen_clobber = 0;
754 if (!tw_dev->error_index) {
760 event_index = (tw_dev->error_index - 1 + TW_Q_LENGTH) % TW_Q_LENGTH;
761 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
762 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
765 if (tw_dev->event_queue_wrapped) {
766 if (tw_dev->aen_clobber) {
768 tw_dev->aen_clobber = 0;
771 event_index = tw_dev->error_index;
773 if (!tw_dev->error_index) {
780 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
781 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
788 if (tw_dev->event_queue_wrapped) {
789 if (tw_dev->aen_clobber) {
791 tw_dev->aen_clobber = 0;
793 start_index = tw_dev->error_index;
795 if (!tw_dev->error_index) {
801 event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id + 1) % TW_Q_LENGTH;
803 if (!(tw_dev->event_queue[event_index]->sequence_id > sequence_id)) {
805 tw_dev->aen_clobber = 1;
809 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
810 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
817 if (tw_dev->event_queue_wrapped) {
818 if (tw_dev->aen_clobber) {
820 tw_dev->aen_clobber = 0;
822 start_index = tw_dev->error_index;
824 if (!tw_dev->error_index) {
830 event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id - 1) % TW_Q_LENGTH;
832 if (!(tw_dev->event_queue[event_index]->sequence_id < sequence_id)) {
834 tw_dev->aen_clobber = 1;
838 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
839 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
845 if ((tw_lock->force_flag == 1) || (tw_dev->ioctl_sem_lock == 0) ||
846 ktime_after(current_time, tw_dev->ioctl_time)) {
847 tw_dev->ioctl_sem_lock = 1;
848 tw_dev->ioctl_time = ktime_add_ms(current_time, tw_lock->timeout_msec);
853 tw_lock->time_remaining_msec = ktime_ms_delta(tw_dev->ioctl_time, current_time);
857 if (tw_dev->ioctl_sem_lock == 1) {
858 tw_dev->ioctl_sem_lock = 0;
874 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, cpu_addr, dma_handle);
876 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 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
1036 tw_dev->command_packet_virt[0],
1037 tw_dev->command_packet_phys[0]);
1039 if (tw_dev->generic_buffer_virt[0])
1040 dma_free_coherent(&tw_dev->tw_pci_dev->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]))
1358 tw_dev->state[request_id] = TW_S_COMPLETED;
1359 twa_free_request_id(tw_dev, request_id);
1360 tw_dev->posted_request_count--;
1364 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1366 if (twa_decode_bits(tw_dev, status_reg_value)) {
1367 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1375 spin_unlock(tw_dev->host->host_lock);
1380 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)
1406 if (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)
1419 static int twa_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds)
1423 TW_Command_Full *full_command_packet = tw_dev->command_packet_virt[request_id];
1425 if (twa_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, seconds) == 0) {
1426 response_queue.value = readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1429 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1e, "Found unexpected request id while polling for response");
1435 twa_fill_sense(tw_dev, request_id, 0, 0);
1442 twa_fill_sense(tw_dev, request_id, 0, 0);
1456 static int twa_poll_status(TW_Device_Extension *tw_dev, u32 flag, int seconds)
1462 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1466 twa_decode_bits(tw_dev, status_reg_value);
1469 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1472 twa_decode_bits(tw_dev, status_reg_value);
1485 static int twa_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds)
1491 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1495 twa_decode_bits(tw_dev, status_reg_value);
1498 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1500 twa_decode_bits(tw_dev, status_reg_value);
1513 static int twa_post_command_packet(TW_Device_Extension *tw_dev, int request_id, char internal)
1519 command_que_value = tw_dev->command_packet_phys[request_id];
1522 if ((tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) ||
1523 (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)) {
1525 writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev));
1528 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1531 twa_decode_bits(tw_dev, status_reg_value);
1533 if (((tw_dev->pending_request_count > 0) && (tw_dev->state[request_id] != TW_S_PENDING)) || (status_reg_value & TW_STATUS_COMMAND_QUEUE_FULL)) {
1542 if (tw_dev->state[request_id] != TW_S_PENDING) {
1543 tw_dev->state[request_id] = TW_S_PENDING;
1544 tw_dev->pending_request_count++;
1545 if (tw_dev->pending_request_count > tw_dev->max_pending_request_count) {
1546 tw_dev->max_pending_request_count = tw_dev->pending_request_count;
1548 tw_dev->pending_queue[tw_dev->pending_tail] = request_id;
1549 tw_dev->pending_tail = (tw_dev->pending_tail + 1) % TW_Q_LENGTH;
1551 TW_UNMASK_COMMAND_INTERRUPT(tw_dev);
1554 if ((tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9650SE) ||
1555 (tw_dev->tw_pci_dev->device == PCI_DEVICE_ID_3WARE_9690SA)) {
1557 writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR_LARGE(tw_dev) + 0x4);
1561 writel((u32)command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1562 writel((u32)((u64)command_que_value >> 32), TW_COMMAND_QUEUE_REG_ADDR(tw_dev) + 0x4);
1564 writel(TW_COMMAND_OFFSET + command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev));
1567 tw_dev->state[request_id] = TW_S_POSTED;
1568 tw_dev->posted_request_count++;
1569 if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) {
1570 tw_dev->max_posted_request_count = tw_dev->posted_request_count;
1579 static int twa_reset_device_extension(TW_Device_Extension *tw_dev)
1585 set_bit(TW_IN_RESET, &tw_dev->flags);
1586 TW_DISABLE_INTERRUPTS(tw_dev);
1587 TW_MASK_COMMAND_INTERRUPT(tw_dev);
1588 spin_lock_irqsave(tw_dev->host->host_lock, flags);
1592 if ((tw_dev->state[i] != TW_S_FINISHED) &&
1593 (tw_dev->state[i] != TW_S_INITIAL) &&
1594 (tw_dev->state[i] != TW_S_COMPLETED)) {
1595 if (tw_dev->srb[i]) {
1596 struct scsi_cmnd *cmd = tw_dev->srb[i];
1608 tw_dev->free_queue[i] = i;
1609 tw_dev->state[i] = TW_S_INITIAL;
1611 tw_dev->free_head = TW_Q_START;
1612 tw_dev->free_tail = TW_Q_START;
1613 tw_dev->posted_request_count = 0;
1614 tw_dev->pending_request_count = 0;
1615 tw_dev->pending_head = TW_Q_START;
1616 tw_dev->pending_tail = TW_Q_START;
1617 tw_dev->reset_print = 0;
1619 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1621 if (twa_reset_sequence(tw_dev, 1))
1624 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1625 clear_bit(TW_IN_RESET, &tw_dev->flags);
1626 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1634 static int twa_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset)
1640 TW_SOFT_RESET(tw_dev);
1642 if (twa_empty_response_queue_large(tw_dev)) {
1643 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x36, "Response queue (large) empty failed during reset sequence");
1651 if (twa_poll_status(tw_dev, TW_STATUS_MICROCONTROLLER_READY | (do_soft_reset == 1 ? TW_STATUS_ATTENTION_INTERRUPT : 0), 60)) {
1652 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1f, "Microcontroller not ready during reset sequence");
1659 if (twa_empty_response_queue(tw_dev)) {
1660 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x20, "Response queue empty failed during reset sequence");
1669 if (twa_check_srl(tw_dev, &flashed)) {
1670 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x21, "Compatibility check failed during reset sequence");
1682 if (twa_aen_drain_queue(tw_dev, soft_reset)) {
1683 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x22, "AEN drain failed during reset sequence");
1701 TW_Device_Extension *tw_dev;
1703 tw_dev = (TW_Device_Extension *)sdev->host->hostdata;
1725 TW_Device_Extension *tw_dev = NULL;
1728 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1730 tw_dev->num_resets++;
1737 mutex_lock(&tw_dev->ioctl_lock);
1740 if (twa_reset_device_extension(tw_dev)) {
1741 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2b, "Controller reset failed during scsi host reset");
1747 mutex_unlock(&tw_dev->ioctl_lock);
1755 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1758 if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
1764 if ((SCpnt->device->lun != 0) && (tw_dev->tw_compat_info.working_srl < TW_FW_SRL_LUNS_SUPPORTED)) {
1775 twa_get_request_id(tw_dev, &request_id);
1778 tw_dev->srb[request_id] = SCpnt;
1780 retval = twa_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL);
1785 twa_free_request_id(tw_dev, request_id);
1792 tw_dev->state[request_id] = TW_S_COMPLETED;
1793 twa_free_request_id(tw_dev, request_id);
1803 static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
1815 if (tw_dev->srb[request_id]) {
1816 srb = tw_dev->srb[request_id];
1822 full_command_packet = tw_dev->command_packet_virt[request_id];
1857 tw_dev->generic_buffer_virt[request_id],
1859 command_packet->sg_list[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
1870 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2e, "Found unaligned sgl address during execute scsi");
1875 command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id])));
1883 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2f, "Found unaligned sgl address during internal post");
1899 tw_dev->sector_count = num_sectors;
1900 if (tw_dev->sector_count > tw_dev->max_sector_count)
1901 tw_dev->max_sector_count = tw_dev->sector_count;
1905 tw_dev->sgl_entries = scsi_sg_count(tw_dev->srb[request_id]);
1906 if (tw_dev->sgl_entries > tw_dev->max_sgl_entries)
1907 tw_dev->max_sgl_entries = tw_dev->sgl_entries;
1912 retval = twa_post_command_packet(tw_dev, request_id, 0);
1914 twa_post_command_packet(tw_dev, request_id, 1);
1922 static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id)
1924 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1930 void *buf = tw_dev->generic_buffer_virt[request_id];
1938 static void __twa_shutdown(TW_Device_Extension *tw_dev)
1941 TW_DISABLE_INTERRUPTS(tw_dev);
1944 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
1946 printk(KERN_WARNING "3w-9xxx: Shutting down host %d.\n", tw_dev->host->host_no);
1949 if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
1950 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x31, "Connection shutdown failed");
1956 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1963 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
1965 __twa_shutdown(tw_dev);
2010 TW_Device_Extension *tw_dev;
2038 tw_dev = (TW_Device_Extension *)host->hostdata;
2041 tw_dev->host = host;
2042 tw_dev->tw_pci_dev = pdev;
2044 if (twa_initialize_device_extension(tw_dev)) {
2045 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x25, "Failed to initialize device extension");
2053 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x26, "Failed to get mem region");
2066 tw_dev->base_addr = ioremap(mem_addr, mem_len);
2067 if (!tw_dev->base_addr) {
2068 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x35, "Failed to ioremap");
2074 TW_DISABLE_INTERRUPTS(tw_dev);
2077 if (twa_reset_sequence(tw_dev, 0)) {
2092 host->max_lun = TW_MAX_LUNS(tw_dev->tw_compat_info.working_srl);
2098 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x27, "scsi add host failed");
2108 (char *)twa_get_param(tw_dev, 0, TW_VERSION_TABLE,
2110 (char *)twa_get_param(tw_dev, 1, TW_VERSION_TABLE,
2112 le32_to_cpu(*(int *)twa_get_param(tw_dev, 2, TW_INFORMATION_TABLE,
2118 set_bit(TW_USING_MSI, &tw_dev->flags);
2121 retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev);
2123 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x30, "Error requesting IRQ");
2127 twa_device_extension_list[twa_device_extension_count] = tw_dev;
2131 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
2143 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2147 iounmap(tw_dev->base_addr);
2151 twa_free_device_extension(tw_dev);
2163 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2165 scsi_remove_host(tw_dev->host);
2174 __twa_shutdown(tw_dev);
2177 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2181 iounmap(tw_dev->base_addr);
2187 twa_free_device_extension(tw_dev);
2189 scsi_host_put(tw_dev->host);
2199 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2201 printk(KERN_WARNING "3w-9xxx: Suspending host %d.\n", tw_dev->host->host_no);
2203 TW_DISABLE_INTERRUPTS(tw_dev);
2204 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2206 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2210 if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
2211 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x38, "Connection shutdown failed during suspend");
2215 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
2229 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2231 printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", tw_dev->host->host_no);
2238 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x39, "Enable device failed during resume");
2255 if (twa_reset_sequence(tw_dev, 0)) {
2261 retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev);
2263 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x42, "Error requesting IRQ during resume");
2269 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2273 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);