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);
228 static int twa_aen_complete(TW_Device_Extension *tw_dev, int request_id)
236 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
237 tw_dev->posted_request_count--;
239 full_command_packet = tw_dev->command_packet_virt[request_id];
245 if (twa_aen_read_queue(tw_dev, request_id))
258 twa_aen_sync_time(tw_dev, request_id);
262 twa_aen_queue_event(tw_dev, header);
265 if (twa_aen_read_queue(tw_dev, request_id))
274 tw_dev->state[request_id] = TW_S_COMPLETED;
275 twa_free_request_id(tw_dev, request_id);
276 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags);
282 static int twa_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset)
298 full_command_packet = tw_dev->command_packet_virt[request_id];
309 sglist[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
311 if (tw_dev->generic_buffer_phys[request_id] & TW_ALIGNMENT_9000_SGL) {
312 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Found unaligned address during AEN drain");
317 tw_dev->srb[request_id] = NULL;
321 if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
322 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2, "Error posting request sense");
327 if (twa_poll_response(tw_dev, request_id, 30)) {
328 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "No valid response while draining AEN queue");
329 tw_dev->posted_request_count--;
333 tw_dev->posted_request_count--;
334 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id];
360 twa_aen_queue_event(tw_dev, header);
368 tw_dev->state[request_id] = TW_S_INITIAL;
373 static void twa_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header)
381 tw_dev->aen_count++;
384 event = tw_dev->event_queue[tw_dev->error_index];
388 if (tw_dev->host) {
389 sprintf(host, " scsi%d:", tw_dev->host->host_no);
391 tw_dev->aen_clobber = 1;
403 event->sequence_id = tw_dev->error_sequence_id;
404 tw_dev->error_sequence_id++;
420 tw_dev->aen_count--;
422 if ((tw_dev->error_index + 1) == TW_Q_LENGTH)
423 tw_dev->event_queue_wrapped = 1;
424 tw_dev->error_index = (tw_dev->error_index + 1 ) % TW_Q_LENGTH;
428 static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id)
435 full_command_packet = tw_dev->command_packet_virt[request_id];
446 sglist[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
449 tw_dev->srb[request_id] = NULL;
452 if (twa_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) {
453 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x4, "Post failed while reading AEN queue");
476 static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id)
485 full_command_packet = tw_dev->command_packet_virt[request_id];
490 command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
496 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id];
510 tw_dev->srb[request_id] = NULL;
513 twa_post_command_packet(tw_dev, request_id, 1);
517 static int twa_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
524 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
527 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed");
532 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x6, "Failed to allocate correctly aligned memory");
533 dma_free_coherent(&tw_dev->tw_pci_dev->dev, size * TW_Q_LENGTH,
543 tw_dev->command_packet_phys[i] = dma_handle+(i*size);
544 tw_dev->command_packet_virt[i] = (TW_Command_Full *)((unsigned char *)cpu_addr + (i*size));
547 tw_dev->generic_buffer_phys[i] = dma_handle+(i*size);
548 tw_dev->generic_buffer_virt[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size));
573 static int twa_check_srl(TW_Device_Extension *tw_dev, int *flashed)
580 if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS,
586 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "Initconnection failed while checking SRL");
590 tw_dev->tw_compat_info.working_srl = fw_on_ctlr_srl;
591 tw_dev->tw_compat_info.working_branch = fw_on_ctlr_branch;
592 tw_dev->tw_compat_info.working_build = fw_on_ctlr_build;
596 if (twa_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS,
603 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Initconnection (base mode) failed while checking SRL");
608 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x32, "Firmware and driver incompatibility: please upgrade firmware");
610 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x33, "Firmware and driver incompatibility: please upgrade driver");
614 tw_dev->tw_compat_info.working_srl = TW_BASE_FW_SRL;
615 tw_dev->tw_compat_info.working_branch = TW_BASE_FW_BRANCH;
616 tw_dev->tw_compat_info.working_build = TW_BASE_FW_BUILD;
620 strscpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION,
621 sizeof(tw_dev->tw_compat_info.driver_version));
622 tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL;
623 tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
624 tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD;
625 tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL;
626 tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH;
627 tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD;
628 tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl;
629 tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch;
630 tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build;
654 TW_Device_Extension *tw_dev = twa_device_extension_list[iminor(inode)];
661 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
680 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
697 spin_lock_irqsave(tw_dev->host->host_lock, flags);
698 twa_get_request_id(tw_dev, &request_id);
701 tw_dev->srb[request_id] = NULL;
704 tw_dev->chrdev_request_id = request_id;
709 twa_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted);
711 memcpy(tw_dev->command_packet_virt[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command_Full));
714 twa_post_command_packet(tw_dev, request_id, 1);
715 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
720 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
723 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
726 tw_dev->host->host_no, TW_DRIVER, 0x37,
729 twa_reset_device_extension(tw_dev);
734 memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virt[request_id], sizeof(TW_Command_Full));
737 spin_lock_irqsave(tw_dev->host->host_lock, flags);
738 tw_dev->posted_request_count--;
739 tw_dev->state[request_id] = TW_S_COMPLETED;
740 twa_free_request_id(tw_dev, request_id);
741 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
747 memcpy(tw_compat_info, &tw_dev->tw_compat_info, sizeof(TW_Compatibility_Info));
750 if (tw_dev->event_queue_wrapped) {
751 if (tw_dev->aen_clobber) {
753 tw_dev->aen_clobber = 0;
757 if (!tw_dev->error_index) {
763 event_index = (tw_dev->error_index - 1 + TW_Q_LENGTH) % TW_Q_LENGTH;
764 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
765 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
768 if (tw_dev->event_queue_wrapped) {
769 if (tw_dev->aen_clobber) {
771 tw_dev->aen_clobber = 0;
774 event_index = tw_dev->error_index;
776 if (!tw_dev->error_index) {
783 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
784 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
791 if (tw_dev->event_queue_wrapped) {
792 if (tw_dev->aen_clobber) {
794 tw_dev->aen_clobber = 0;
796 start_index = tw_dev->error_index;
798 if (!tw_dev->error_index) {
804 event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id + 1) % TW_Q_LENGTH;
806 if (!(tw_dev->event_queue[event_index]->sequence_id > sequence_id)) {
808 tw_dev->aen_clobber = 1;
812 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
813 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
820 if (tw_dev->event_queue_wrapped) {
821 if (tw_dev->aen_clobber) {
823 tw_dev->aen_clobber = 0;
825 start_index = tw_dev->error_index;
827 if (!tw_dev->error_index) {
833 event_index = (start_index + sequence_id - tw_dev->event_queue[start_index]->sequence_id - 1) % TW_Q_LENGTH;
835 if (!(tw_dev->event_queue[event_index]->sequence_id < sequence_id)) {
837 tw_dev->aen_clobber = 1;
841 memcpy(tw_ioctl->data_buffer, tw_dev->event_queue[event_index], sizeof(TW_Event));
842 tw_dev->event_queue[event_index]->retrieved = TW_AEN_RETRIEVED;
848 if ((tw_lock->force_flag == 1) || (tw_dev->ioctl_sem_lock == 0) ||
849 ktime_after(current_time, tw_dev->ioctl_time)) {
850 tw_dev->ioctl_sem_lock = 1;
851 tw_dev->ioctl_time = ktime_add_ms(current_time, tw_lock->timeout_msec);
856 tw_lock->time_remaining_msec = ktime_ms_delta(tw_dev->ioctl_time, current_time);
860 if (tw_dev->ioctl_sem_lock == 1) {
861 tw_dev->ioctl_sem_lock = 0;
877 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
881 mutex_unlock(&tw_dev->ioctl_lock);
908 static int twa_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value)
914 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xc, "PCI Parity Error: clearing");
915 writel(TW_CONTROL_CLEAR_PARITY_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
919 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xd, "PCI Abort: clearing");
920 writel(TW_CONTROL_CLEAR_PCI_ABORT, TW_CONTROL_REG_ADDR(tw_dev));
921 pci_write_config_word(tw_dev->tw_pci_dev, PCI_STATUS, TW_PCI_CLEAR_PCI_ABORT);
925 if (((tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9650SE) &&
926 (tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9690SA)) ||
927 (!test_bit(TW_IN_RESET, &tw_dev->flags)))
928 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Controller Queue Error: clearing");
929 writel(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev));
933 if (tw_dev->reset_print == 0) {
934 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Microcontroller Error: clearing");
935 tw_dev->reset_print = 1;
945 static int twa_empty_response_queue(TW_Device_Extension *tw_dev)
950 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
953 readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
954 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
966 static int twa_empty_response_queue_large(TW_Device_Extension *tw_dev)
972 if (tw_dev->tw_pci_dev->device != PCI_DEVICE_ID_3WARE_9000) {
975 response_que_value = readl(TW_RESPONSE_QUEUE_REG_ADDR_LARGE(tw_dev));
990 static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_sense, int print_host)
997 full_command_packet = tw_dev->command_packet_virt[request_id];
1007 tw_dev->host->host_no,
1019 memcpy(tw_dev->srb[request_id]->sense_buffer, full_command_packet->header.sense_data, TW_SENSE_DATA_LENGTH);
1020 tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
1030 static void twa_free_device_extension(TW_Device_Extension *tw_dev)
1032 if (tw_dev->command_packet_virt[0])
1033 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
1035 tw_dev->command_packet_virt[0],
1036 tw_dev->command_packet_phys[0]);
1038 if (tw_dev->generic_buffer_virt[0])
1039 dma_free_coherent(&tw_dev->tw_pci_dev->dev,
1041 tw_dev->generic_buffer_virt[0],
1042 tw_dev->generic_buffer_phys[0]);
1044 kfree(tw_dev->event_queue[0]);
1048 static void twa_free_request_id(TW_Device_Extension *tw_dev, int request_id)
1050 tw_dev->free_queue[tw_dev->free_tail] = request_id;
1051 tw_dev->state[request_id] = TW_S_FINISHED;
1052 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH;
1056 static void *twa_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter_id, int parameter_size_bytes)
1064 full_command_packet = tw_dev->command_packet_virt[request_id];
1074 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id];
1080 command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
1084 twa_post_command_packet(tw_dev, request_id, 1);
1087 if (twa_poll_response(tw_dev, request_id, 30))
1088 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x13, "No valid response during get param")
1092 tw_dev->posted_request_count--;
1093 tw_dev->state[request_id] = TW_S_INITIAL;
1099 static void twa_get_request_id(TW_Device_Extension *tw_dev, int *request_id)
1101 *request_id = tw_dev->free_queue[tw_dev->free_head];
1102 tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH;
1103 tw_dev->state[*request_id] = TW_S_STARTED;
1107 static int twa_initconnection(TW_Device_Extension *tw_dev, int message_credits,
1123 full_command_packet = tw_dev->command_packet_virt[request_id];
1147 twa_post_command_packet(tw_dev, request_id, 1);
1150 if (twa_poll_response(tw_dev, request_id, 30)) {
1151 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x15, "No valid response during init connection");
1163 tw_dev->posted_request_count--;
1164 tw_dev->state[request_id] = TW_S_INITIAL;
1170 static int twa_initialize_device_extension(TW_Device_Extension *tw_dev)
1175 if (twa_allocate_memory(tw_dev, sizeof(TW_Command_Full), 0)) {
1176 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x16, "Command packet memory allocation failed");
1181 if (twa_allocate_memory(tw_dev, TW_SECTOR_SIZE, 1)) {
1182 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x17, "Generic memory allocation failed");
1187 tw_dev->event_queue[0] = kcalloc(TW_Q_LENGTH, sizeof(TW_Event), GFP_KERNEL);
1188 if (!tw_dev->event_queue[0]) {
1189 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x18, "Event info memory allocation failed");
1195 tw_dev->event_queue[i] = (TW_Event *)((unsigned char *)tw_dev->event_queue[0] + (i * sizeof(TW_Event)));
1196 tw_dev->free_queue[i] = i;
1197 tw_dev->state[i] = TW_S_INITIAL;
1200 tw_dev->pending_head = TW_Q_START;
1201 tw_dev->pending_tail = TW_Q_START;
1202 tw_dev->free_head = TW_Q_START;
1203 tw_dev->free_tail = TW_Q_START;
1204 tw_dev->error_sequence_id = 1;
1205 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1207 mutex_init(&tw_dev->ioctl_lock);
1208 init_waitqueue_head(&tw_dev->ioctl_wqueue);
1222 TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance;
1226 spin_lock(tw_dev->host->host_lock);
1229 status_reg_value = readl(TW_STATUS_REG_ADDR(tw_dev));
1238 if (test_bit(TW_IN_RESET, &tw_dev->flags))
1243 if (twa_decode_bits(tw_dev, status_reg_value)) {
1244 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1251 TW_CLEAR_HOST_INTERRUPT(tw_dev);
1255 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev);
1256 if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags))) {
1257 twa_get_request_id(tw_dev, &request_id);
1259 error = twa_aen_read_queue(tw_dev, request_id);
1261 tw_dev->state[request_id] = TW_S_COMPLETED;
1262 twa_free_request_id(tw_dev, request_id);
1263 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags);
1270 TW_MASK_COMMAND_INTERRUPT(tw_dev);
1272 while (tw_dev->pending_request_count > 0) {
1273 request_id = tw_dev->pending_queue[tw_dev->pending_head];
1274 if (tw_dev->state[request_id] != TW_S_PENDING) {
1275 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x19, "Found request id that wasn't pending");
1276 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1279 if (twa_post_command_packet(tw_dev, request_id, 1)==0) {
1280 tw_dev->pending_head = (tw_dev->pending_head + 1) % TW_Q_LENGTH;
1281 tw_dev->pending_request_count--;
1295 response_que.value = readl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev));
1297 full_command_packet = tw_dev->command_packet_virt[request_id];
1301 if (tw_dev->srb[request_id] != NULL) {
1302 error = twa_fill_sense(tw_dev, request_id, 1, 1);
1305 if (request_id != tw_dev->chrdev_request_id) {
1306 error = twa_fill_sense(tw_dev, request_id, 0, 1);
1312 if (tw_dev->state[request_id] != TW_S_POSTED) {
1313 if (tw_dev->srb[request_id] != NULL) {
1314 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Received a request id that wasn't posted");
1315 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1321 if (tw_dev->srb[request_id] == NULL) {
1322 if (request_id != tw_dev->chrdev_request_id) {
1323 if (twa_aen_complete(tw_dev, request_id))
1324 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1b, "Error completing AEN during attention interrupt");
1326 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1327 wake_up(&tw_dev->ioctl_wqueue);
1332 cmd = tw_dev->srb[request_id];
1334 twa_scsiop_execute_scsi_complete(tw_dev, 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");
1722 TW_Device_Extension *tw_dev = NULL;
1725 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1727 tw_dev->num_resets++;
1734 mutex_lock(&tw_dev->ioctl_lock);
1737 if (twa_reset_device_extension(tw_dev)) {
1738 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2b, "Controller reset failed during scsi host reset");
1744 mutex_unlock(&tw_dev->ioctl_lock);
1753 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
1756 if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
1762 if ((SCpnt->device->lun != 0) && (tw_dev->tw_compat_info.working_srl < TW_FW_SRL_LUNS_SUPPORTED)) {
1770 twa_get_request_id(tw_dev, &request_id);
1773 tw_dev->srb[request_id] = SCpnt;
1775 retval = twa_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL);
1780 twa_free_request_id(tw_dev, request_id);
1787 tw_dev->state[request_id] = TW_S_COMPLETED;
1788 twa_free_request_id(tw_dev, request_id);
1798 static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id,
1810 if (tw_dev->srb[request_id])
1811 srb = tw_dev->srb[request_id];
1814 full_command_packet = tw_dev->command_packet_virt[request_id];
1849 tw_dev->generic_buffer_virt[request_id],
1851 command_packet->sg_list[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);
1862 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2e, "Found unaligned sgl address during execute scsi");
1867 command_packet->sgl_entries__lunh = TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id]));
1875 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2f, "Found unaligned sgl address during internal post");
1891 tw_dev->sector_count = num_sectors;
1892 if (tw_dev->sector_count > tw_dev->max_sector_count)
1893 tw_dev->max_sector_count = tw_dev->sector_count;
1897 tw_dev->sgl_entries = scsi_sg_count(tw_dev->srb[request_id]);
1898 if (tw_dev->sgl_entries > tw_dev->max_sgl_entries)
1899 tw_dev->max_sgl_entries = tw_dev->sgl_entries;
1904 retval = twa_post_command_packet(tw_dev, request_id, 0);
1906 twa_post_command_packet(tw_dev, request_id, 1);
1914 static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int request_id)
1916 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1922 void *buf = tw_dev->generic_buffer_virt[request_id];
1930 static void __twa_shutdown(TW_Device_Extension *tw_dev)
1933 TW_DISABLE_INTERRUPTS(tw_dev);
1936 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
1938 printk(KERN_WARNING "3w-9xxx: Shutting down host %d.\n", tw_dev->host->host_no);
1941 if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
1942 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x31, "Connection shutdown failed");
1948 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
1955 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
1957 __twa_shutdown(tw_dev);
2001 TW_Device_Extension *tw_dev;
2029 tw_dev = (TW_Device_Extension *)host->hostdata;
2032 tw_dev->host = host;
2033 tw_dev->tw_pci_dev = pdev;
2035 if (twa_initialize_device_extension(tw_dev)) {
2036 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x25, "Failed to initialize device extension");
2044 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x26, "Failed to get mem region");
2057 tw_dev->base_addr = ioremap(mem_addr, mem_len);
2058 if (!tw_dev->base_addr) {
2059 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x35, "Failed to ioremap");
2065 TW_DISABLE_INTERRUPTS(tw_dev);
2068 if (twa_reset_sequence(tw_dev, 0)) {
2083 host->max_lun = TW_MAX_LUNS(tw_dev->tw_compat_info.working_srl);
2089 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x27, "scsi add host failed");
2099 (char *)twa_get_param(tw_dev, 0, TW_VERSION_TABLE,
2101 (char *)twa_get_param(tw_dev, 1, TW_VERSION_TABLE,
2103 le32_to_cpu(*(__le32 *)twa_get_param(tw_dev, 2, TW_INFORMATION_TABLE,
2109 set_bit(TW_USING_MSI, &tw_dev->flags);
2112 retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev);
2114 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x30, "Error requesting IRQ");
2118 twa_device_extension_list[twa_device_extension_count] = tw_dev;
2122 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
2134 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2138 iounmap(tw_dev->base_addr);
2142 twa_free_device_extension(tw_dev);
2154 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2156 scsi_remove_host(tw_dev->host);
2165 __twa_shutdown(tw_dev);
2168 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2172 iounmap(tw_dev->base_addr);
2178 twa_free_device_extension(tw_dev);
2180 scsi_host_put(tw_dev->host);
2190 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2192 printk(KERN_WARNING "3w-9xxx: Suspending host %d.\n", tw_dev->host->host_no);
2194 TW_DISABLE_INTERRUPTS(tw_dev);
2195 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2197 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2201 if (twa_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) {
2202 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x38, "Connection shutdown failed during suspend");
2206 TW_CLEAR_ALL_INTERRUPTS(tw_dev);
2217 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
2219 printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", tw_dev->host->host_no);
2233 if (twa_reset_sequence(tw_dev, 0)) {
2239 retval = request_irq(pdev->irq, twa_interrupt, IRQF_SHARED, "3w-9xxx", tw_dev);
2241 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x42, "Error requesting IRQ during resume");
2247 if (test_bit(TW_USING_MSI, &tw_dev->flags))
2251 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);