Lines Matching refs:tw_dev
93 static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset);
104 TW_Device_Extension *tw_dev = (TW_Device_Extension *)shost->hostdata; in twl_sysfs_aen_read() local
111 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_sysfs_aen_read()
112 …ret = memory_read_from_buffer(outbuf, count, &offset, tw_dev->event_queue[0], sizeof(TW_Event) * T… in twl_sysfs_aen_read()
113 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_sysfs_aen_read()
135 TW_Device_Extension *tw_dev = (TW_Device_Extension *)shost->hostdata; in twl_sysfs_compat_info() local
142 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_sysfs_compat_info()
143 …ret = memory_read_from_buffer(outbuf, count, &offset, &tw_dev->tw_compat_info, sizeof(TW_Compatibi… in twl_sysfs_compat_info()
144 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_sysfs_compat_info()
164 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_show_stats() local
168 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_show_stats()
179 tw_dev->posted_request_count, in twl_show_stats()
180 tw_dev->max_posted_request_count, in twl_show_stats()
181 tw_dev->sgl_entries, in twl_show_stats()
182 tw_dev->max_sgl_entries, in twl_show_stats()
183 tw_dev->sector_count, in twl_show_stats()
184 tw_dev->max_sector_count, in twl_show_stats()
185 tw_dev->num_resets, in twl_show_stats()
186 tw_dev->aen_count); in twl_show_stats()
187 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_show_stats()
223 static void twl_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header) in twl_aen_queue_event() argument
231 tw_dev->aen_count++; in twl_aen_queue_event()
234 event = tw_dev->event_queue[tw_dev->error_index]; in twl_aen_queue_event()
237 if (tw_dev->host) in twl_aen_queue_event()
238 sprintf(host, " scsi%d:", tw_dev->host->host_no); in twl_aen_queue_event()
249 event->sequence_id = tw_dev->error_sequence_id; in twl_aen_queue_event()
250 tw_dev->error_sequence_id++; in twl_aen_queue_event()
265 tw_dev->aen_count--; in twl_aen_queue_event()
267 tw_dev->error_index = (tw_dev->error_index + 1 ) % TW_Q_LENGTH; in twl_aen_queue_event()
271 static int twl_post_command_packet(TW_Device_Extension *tw_dev, int request_id) in twl_post_command_packet() argument
275 command_que_value = tw_dev->command_packet_phys[request_id]; in twl_post_command_packet()
279 writel((u32)((u64)command_que_value >> 32), TWL_HIBQPH_REG_ADDR(tw_dev)); in twl_post_command_packet()
281 writel((u32)(command_que_value | TWL_PULL_MODE), TWL_HIBQPL_REG_ADDR(tw_dev)); in twl_post_command_packet()
283 tw_dev->state[request_id] = TW_S_POSTED; in twl_post_command_packet()
284 tw_dev->posted_request_count++; in twl_post_command_packet()
285 if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) in twl_post_command_packet()
286 tw_dev->max_posted_request_count = tw_dev->posted_request_count; in twl_post_command_packet()
292 static int twl_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, in twl_scsiop_execute_scsi() argument
303 if (tw_dev->srb[request_id]) in twl_scsiop_execute_scsi()
304 srb = tw_dev->srb[request_id]; in twl_scsiop_execute_scsi()
307 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_scsiop_execute_scsi()
345 …_lunh = cpu_to_le16(TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id]))… in twl_scsiop_execute_scsi()
358 tw_dev->sector_count = scsi_bufflen(srb) / 512; in twl_scsiop_execute_scsi()
359 if (tw_dev->sector_count > tw_dev->max_sector_count) in twl_scsiop_execute_scsi()
360 tw_dev->max_sector_count = tw_dev->sector_count; in twl_scsiop_execute_scsi()
361 tw_dev->sgl_entries = scsi_sg_count(srb); in twl_scsiop_execute_scsi()
362 if (tw_dev->sgl_entries > tw_dev->max_sgl_entries) in twl_scsiop_execute_scsi()
363 tw_dev->max_sgl_entries = tw_dev->sgl_entries; in twl_scsiop_execute_scsi()
367 retval = twl_post_command_packet(tw_dev, request_id); in twl_scsiop_execute_scsi()
374 static int twl_aen_read_queue(TW_Device_Extension *tw_dev, int request_id) in twl_aen_read_queue() argument
381 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_read_queue()
392 sglist[0].address = tw_dev->generic_buffer_phys[request_id]; in twl_aen_read_queue()
395 tw_dev->srb[request_id] = NULL; in twl_aen_read_queue()
398 if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) { in twl_aen_read_queue()
399 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2, "Post failed while reading AEN queue"); in twl_aen_read_queue()
408 static void twl_aen_sync_time(TW_Device_Extension *tw_dev, int request_id) in twl_aen_sync_time() argument
417 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_sync_time()
422 …command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[requ… in twl_aen_sync_time()
428 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; in twl_aen_sync_time()
443 tw_dev->srb[request_id] = NULL; in twl_aen_sync_time()
446 twl_post_command_packet(tw_dev, request_id); in twl_aen_sync_time()
450 static void twl_get_request_id(TW_Device_Extension *tw_dev, int *request_id) in twl_get_request_id() argument
452 *request_id = tw_dev->free_queue[tw_dev->free_head]; in twl_get_request_id()
453 tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH; in twl_get_request_id()
454 tw_dev->state[*request_id] = TW_S_STARTED; in twl_get_request_id()
458 static void twl_free_request_id(TW_Device_Extension *tw_dev, int request_id) in twl_free_request_id() argument
460 tw_dev->free_queue[tw_dev->free_tail] = request_id; in twl_free_request_id()
461 tw_dev->state[request_id] = TW_S_FINISHED; in twl_free_request_id()
462 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH; in twl_free_request_id()
466 static int twl_aen_complete(TW_Device_Extension *tw_dev, int request_id) in twl_aen_complete() argument
474 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id]; in twl_aen_complete()
475 tw_dev->posted_request_count--; in twl_aen_complete()
477 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_complete()
483 if (twl_aen_read_queue(tw_dev, request_id)) in twl_aen_complete()
496 twl_aen_sync_time(tw_dev, request_id); in twl_aen_complete()
500 twl_aen_queue_event(tw_dev, header); in twl_aen_complete()
503 if (twl_aen_read_queue(tw_dev, request_id)) in twl_aen_complete()
512 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_aen_complete()
513 twl_free_request_id(tw_dev, request_id); in twl_aen_complete()
514 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); in twl_aen_complete()
520 static int twl_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds) in twl_poll_response() argument
533 regh = readl(TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_poll_response()
534 regl = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_poll_response()
537 mfa = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_poll_response()
555 static int twl_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset) in twl_aen_drain_queue() argument
571 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_drain_queue()
582 sglist[0].address = tw_dev->generic_buffer_phys[request_id]; in twl_aen_drain_queue()
585 tw_dev->srb[request_id] = NULL; in twl_aen_drain_queue()
589 if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) { in twl_aen_drain_queue()
590 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "Error posting request sense"); in twl_aen_drain_queue()
595 if (twl_poll_response(tw_dev, request_id, 30)) { in twl_aen_drain_queue()
596 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x4, "No valid response while draining AEN queue"); in twl_aen_drain_queue()
597 tw_dev->posted_request_count--; in twl_aen_drain_queue()
601 tw_dev->posted_request_count--; in twl_aen_drain_queue()
602 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id]; in twl_aen_drain_queue()
628 twl_aen_queue_event(tw_dev, header); in twl_aen_drain_queue()
636 tw_dev->state[request_id] = TW_S_INITIAL; in twl_aen_drain_queue()
641 static int twl_allocate_memory(TW_Device_Extension *tw_dev, int size, int which) in twl_allocate_memory() argument
648 cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, in twl_allocate_memory()
652 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed"); in twl_allocate_memory()
659 tw_dev->command_packet_phys[i] = dma_handle+(i*size); in twl_allocate_memory()
660 tw_dev->command_packet_virt[i] = (TW_Command_Full *)((unsigned char *)cpu_addr + (i*size)); in twl_allocate_memory()
663 tw_dev->generic_buffer_phys[i] = dma_handle+(i*size); in twl_allocate_memory()
664 tw_dev->generic_buffer_virt[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size)); in twl_allocate_memory()
667 tw_dev->sense_buffer_phys[i] = dma_handle+(i*size); in twl_allocate_memory()
668 … tw_dev->sense_buffer_virt[i] = (TW_Command_Apache_Header *)((unsigned char *)cpu_addr + (i*size)); in twl_allocate_memory()
678 static void twl_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_command_packet, int req… in twl_load_sgl() argument
725 TW_Device_Extension *tw_dev = twl_device_extension_list[iminor(inode)]; in twl_chrdev_ioctl() local
732 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { in twl_chrdev_ioctl()
751 …cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioct… in twl_chrdev_ioctl()
766 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
767 twl_get_request_id(tw_dev, &request_id); in twl_chrdev_ioctl()
770 tw_dev->srb[request_id] = NULL; in twl_chrdev_ioctl()
773 tw_dev->chrdev_request_id = request_id; in twl_chrdev_ioctl()
778 twl_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted); in twl_chrdev_ioctl()
780 …memcpy(tw_dev->command_packet_virt[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command_F… in twl_chrdev_ioctl()
783 twl_post_command_packet(tw_dev, request_id); in twl_chrdev_ioctl()
784 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
789 …timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FR… in twl_chrdev_ioctl()
792 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { in twl_chrdev_ioctl()
795 tw_dev->host->host_no, TW_DRIVER, 0x6, in twl_chrdev_ioctl()
798 twl_reset_device_extension(tw_dev, 1); in twl_chrdev_ioctl()
803 …memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virt[request_id], sizeof(TW_Command_F… in twl_chrdev_ioctl()
806 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
807 tw_dev->posted_request_count--; in twl_chrdev_ioctl()
808 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_chrdev_ioctl()
809 twl_free_request_id(tw_dev, request_id); in twl_chrdev_ioctl()
810 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
822 …dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache… in twl_chrdev_ioctl()
824 mutex_unlock(&tw_dev->ioctl_lock); in twl_chrdev_ioctl()
859 static int twl_fill_sense(TW_Device_Extension *tw_dev, int i, int request_id, int copy_sense, int p… in twl_fill_sense() argument
866 header = tw_dev->sense_buffer_virt[i]; in twl_fill_sense()
867 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_fill_sense()
877 tw_dev->host->host_no, in twl_fill_sense()
891 memcpy(tw_dev->srb[request_id]->sense_buffer, header->sense_data, TW_SENSE_DATA_LENGTH); in twl_fill_sense()
892 tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1); in twl_fill_sense()
900 static void twl_free_device_extension(TW_Device_Extension *tw_dev) in twl_free_device_extension() argument
902 if (tw_dev->command_packet_virt[0]) in twl_free_device_extension()
903 dma_free_coherent(&tw_dev->tw_pci_dev->dev, in twl_free_device_extension()
905 tw_dev->command_packet_virt[0], in twl_free_device_extension()
906 tw_dev->command_packet_phys[0]); in twl_free_device_extension()
908 if (tw_dev->generic_buffer_virt[0]) in twl_free_device_extension()
909 dma_free_coherent(&tw_dev->tw_pci_dev->dev, in twl_free_device_extension()
911 tw_dev->generic_buffer_virt[0], in twl_free_device_extension()
912 tw_dev->generic_buffer_phys[0]); in twl_free_device_extension()
914 if (tw_dev->sense_buffer_virt[0]) in twl_free_device_extension()
915 dma_free_coherent(&tw_dev->tw_pci_dev->dev, in twl_free_device_extension()
918 tw_dev->sense_buffer_virt[0], in twl_free_device_extension()
919 tw_dev->sense_buffer_phys[0]); in twl_free_device_extension()
921 kfree(tw_dev->event_queue[0]); in twl_free_device_extension()
925 static void *twl_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter… in twl_get_param() argument
933 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_get_param()
943 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; in twl_get_param()
949 …command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[requ… in twl_get_param()
953 twl_post_command_packet(tw_dev, request_id); in twl_get_param()
956 if (twl_poll_response(tw_dev, request_id, 30)) in twl_get_param()
957 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "No valid response during get param") in twl_get_param()
961 tw_dev->posted_request_count--; in twl_get_param()
962 tw_dev->state[request_id] = TW_S_INITIAL; in twl_get_param()
968 static int twl_initconnection(TW_Device_Extension *tw_dev, int message_credits, in twl_initconnection() argument
984 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_initconnection()
1009 twl_post_command_packet(tw_dev, request_id); in twl_initconnection()
1012 if (twl_poll_response(tw_dev, request_id, 30)) { in twl_initconnection()
1013 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x8, "No valid response during init connection"); in twl_initconnection()
1025 tw_dev->posted_request_count--; in twl_initconnection()
1026 tw_dev->state[request_id] = TW_S_INITIAL; in twl_initconnection()
1032 static int twl_initialize_device_extension(TW_Device_Extension *tw_dev) in twl_initialize_device_extension() argument
1037 if (twl_allocate_memory(tw_dev, sizeof(TW_Command_Full), 0)) { in twl_initialize_device_extension()
1038 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x9, "Command packet memory allocation failed"); in twl_initialize_device_extension()
1043 if (twl_allocate_memory(tw_dev, TW_SECTOR_SIZE, 1)) { in twl_initialize_device_extension()
1044 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Generic memory allocation failed"); in twl_initialize_device_extension()
1049 if (twl_allocate_memory(tw_dev, sizeof(TW_Command_Apache_Header), 2)) { in twl_initialize_device_extension()
1050 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xb, "Sense buffer allocation failed"); in twl_initialize_device_extension()
1055 tw_dev->event_queue[0] = kcalloc(TW_Q_LENGTH, sizeof(TW_Event), GFP_KERNEL); in twl_initialize_device_extension()
1056 if (!tw_dev->event_queue[0]) { in twl_initialize_device_extension()
1057 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xc, "Event info memory allocation failed"); in twl_initialize_device_extension()
1062 …tw_dev->event_queue[i] = (TW_Event *)((unsigned char *)tw_dev->event_queue[0] + (i * sizeof(TW_Eve… in twl_initialize_device_extension()
1063 tw_dev->free_queue[i] = i; in twl_initialize_device_extension()
1064 tw_dev->state[i] = TW_S_INITIAL; in twl_initialize_device_extension()
1067 tw_dev->free_head = TW_Q_START; in twl_initialize_device_extension()
1068 tw_dev->free_tail = TW_Q_START; in twl_initialize_device_extension()
1069 tw_dev->error_sequence_id = 1; in twl_initialize_device_extension()
1070 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in twl_initialize_device_extension()
1072 mutex_init(&tw_dev->ioctl_lock); in twl_initialize_device_extension()
1073 init_waitqueue_head(&tw_dev->ioctl_wqueue); in twl_initialize_device_extension()
1081 static int twl_handle_attention_interrupt(TW_Device_Extension *tw_dev) in twl_handle_attention_interrupt() argument
1087 doorbell = readl(TWL_HOBDB_REG_ADDR(tw_dev)); in twl_handle_attention_interrupt()
1091 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xd, "Microcontroller Error: clearing"); in twl_handle_attention_interrupt()
1097 if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags))) { in twl_handle_attention_interrupt()
1098 twl_get_request_id(tw_dev, &request_id); in twl_handle_attention_interrupt()
1099 if (twl_aen_read_queue(tw_dev, request_id)) { in twl_handle_attention_interrupt()
1100 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_handle_attention_interrupt()
1101 twl_free_request_id(tw_dev, request_id); in twl_handle_attention_interrupt()
1102 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); in twl_handle_attention_interrupt()
1110 TWL_CLEAR_DB_INTERRUPT(tw_dev); in twl_handle_attention_interrupt()
1113 readl(TWL_HOBDBC_REG_ADDR(tw_dev)); in twl_handle_attention_interrupt()
1121 TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance; in twl_interrupt() local
1128 spin_lock(tw_dev->host->host_lock); in twl_interrupt()
1131 reg = readl(TWL_HISTAT_REG_ADDR(tw_dev)); in twl_interrupt()
1140 if (test_bit(TW_IN_RESET, &tw_dev->flags)) in twl_interrupt()
1145 if (twl_handle_attention_interrupt(tw_dev)) { in twl_interrupt()
1146 TWL_MASK_INTERRUPTS(tw_dev); in twl_interrupt()
1154 regh = readl(TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_interrupt()
1155 regl = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_interrupt()
1158 mfa = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_interrupt()
1166 if (tw_dev->sense_buffer_phys[i] == mfa) { in twl_interrupt()
1167 request_id = le16_to_cpu(tw_dev->sense_buffer_virt[i]->header_desc.request_id); in twl_interrupt()
1168 if (tw_dev->srb[request_id] != NULL) in twl_interrupt()
1169 error = twl_fill_sense(tw_dev, i, request_id, 1, 1); in twl_interrupt()
1172 if (request_id != tw_dev->chrdev_request_id) in twl_interrupt()
1173 error = twl_fill_sense(tw_dev, i, request_id, 0, 1); in twl_interrupt()
1175 …memcpy(tw_dev->command_packet_virt[request_id], tw_dev->sense_buffer_virt[i], sizeof(TW_Command_Ap… in twl_interrupt()
1179 writel((u32)((u64)tw_dev->sense_buffer_phys[i] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_interrupt()
1180 writel((u32)tw_dev->sense_buffer_phys[i], TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_interrupt()
1187 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_interrupt()
1190 if (tw_dev->state[request_id] != TW_S_POSTED) { in twl_interrupt()
1191 if (tw_dev->srb[request_id] != NULL) { in twl_interrupt()
1192 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Received a request id that wasn't posted"); in twl_interrupt()
1193 TWL_MASK_INTERRUPTS(tw_dev); in twl_interrupt()
1199 if (tw_dev->srb[request_id] == NULL) { in twl_interrupt()
1200 if (request_id != tw_dev->chrdev_request_id) { in twl_interrupt()
1201 if (twl_aen_complete(tw_dev, request_id)) in twl_interrupt()
1202 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xf, "Error completing AEN during attention interrupt"); in twl_interrupt()
1204 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in twl_interrupt()
1205 wake_up(&tw_dev->ioctl_wqueue); in twl_interrupt()
1208 cmd = tw_dev->srb[request_id]; in twl_interrupt()
1215 …if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_i… in twl_interrupt()
1222 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_interrupt()
1223 twl_free_request_id(tw_dev, request_id); in twl_interrupt()
1224 tw_dev->posted_request_count--; in twl_interrupt()
1228 reg = readl(TWL_HISTAT_REG_ADDR(tw_dev)); in twl_interrupt()
1232 spin_unlock(tw_dev->host->host_lock); in twl_interrupt()
1237 static int twl_poll_register(TW_Device_Extension *tw_dev, void *reg, u32 value, u32 result, int sec… in twl_poll_register() argument
1258 static int twl_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset) in twl_reset_sequence() argument
1272 TWL_SOFT_RESET(tw_dev); in twl_reset_sequence()
1275 if (twl_poll_register(tw_dev, TWL_SCRPD3_REG_ADDR(tw_dev), TWL_CONTROLLER_READY, 0x0, 30)) { in twl_reset_sequence()
1276 … TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Controller never went non-ready during reset sequence"); in twl_reset_sequence()
1280 …if (twl_poll_register(tw_dev, TWL_SCRPD3_REG_ADDR(tw_dev), TWL_CONTROLLER_READY, TWL_CONTROLLER_RE… in twl_reset_sequence()
1281 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x11, "Controller not ready during reset sequence"); in twl_reset_sequence()
1288 if (twl_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS, in twl_reset_sequence()
1294 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x12, "Initconnection failed while checking SRL"); in twl_reset_sequence()
1302 writel((u32)((u64)tw_dev->sense_buffer_phys[i] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_reset_sequence()
1303 writel((u32)tw_dev->sense_buffer_phys[i], TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_reset_sequence()
1306 status = readl(TWL_STATUS_REG_ADDR(tw_dev)); in twl_reset_sequence()
1312 status = readl(TWL_STATUS_REG_ADDR(tw_dev)); in twl_reset_sequence()
1314 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x13, "Bad controller status after loading sense buffers"); in twl_reset_sequence()
1321 if (twl_aen_drain_queue(tw_dev, soft_reset)) { in twl_reset_sequence()
1322 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x14, "AEN drain failed during reset sequence"); in twl_reset_sequence()
1329 strncpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, strlen(TW_DRIVER_VERSION)); in twl_reset_sequence()
1330 tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL; in twl_reset_sequence()
1331 tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH; in twl_reset_sequence()
1332 tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD; in twl_reset_sequence()
1333 tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL; in twl_reset_sequence()
1334 tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH; in twl_reset_sequence()
1335 tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD; in twl_reset_sequence()
1336 tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl; in twl_reset_sequence()
1337 tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch; in twl_reset_sequence()
1338 tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build; in twl_reset_sequence()
1349 static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset) in twl_reset_device_extension() argument
1356 scsi_block_requests(tw_dev->host); in twl_reset_device_extension()
1358 set_bit(TW_IN_RESET, &tw_dev->flags); in twl_reset_device_extension()
1359 TWL_MASK_INTERRUPTS(tw_dev); in twl_reset_device_extension()
1360 TWL_CLEAR_DB_INTERRUPT(tw_dev); in twl_reset_device_extension()
1362 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_reset_device_extension()
1366 if ((tw_dev->state[i] != TW_S_FINISHED) && in twl_reset_device_extension()
1367 (tw_dev->state[i] != TW_S_INITIAL) && in twl_reset_device_extension()
1368 (tw_dev->state[i] != TW_S_COMPLETED)) { in twl_reset_device_extension()
1369 struct scsi_cmnd *cmd = tw_dev->srb[i]; in twl_reset_device_extension()
1381 tw_dev->free_queue[i] = i; in twl_reset_device_extension()
1382 tw_dev->state[i] = TW_S_INITIAL; in twl_reset_device_extension()
1384 tw_dev->free_head = TW_Q_START; in twl_reset_device_extension()
1385 tw_dev->free_tail = TW_Q_START; in twl_reset_device_extension()
1386 tw_dev->posted_request_count = 0; in twl_reset_device_extension()
1388 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_reset_device_extension()
1390 if (twl_reset_sequence(tw_dev, 1)) in twl_reset_device_extension()
1393 TWL_UNMASK_INTERRUPTS(tw_dev); in twl_reset_device_extension()
1395 clear_bit(TW_IN_RESET, &tw_dev->flags); in twl_reset_device_extension()
1396 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in twl_reset_device_extension()
1401 scsi_unblock_requests(tw_dev->host); in twl_reset_device_extension()
1428 TW_Device_Extension *tw_dev = NULL; in twl_scsi_eh_reset() local
1431 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in twl_scsi_eh_reset()
1433 tw_dev->num_resets++; in twl_scsi_eh_reset()
1440 mutex_lock(&tw_dev->ioctl_lock); in twl_scsi_eh_reset()
1443 if (twl_reset_device_extension(tw_dev, 0)) { in twl_scsi_eh_reset()
1444 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x15, "Controller reset failed during scsi host reset"); in twl_scsi_eh_reset()
1450 mutex_unlock(&tw_dev->ioctl_lock); in twl_scsi_eh_reset()
1459 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in twl_scsi_queue_lck() local
1462 if (test_bit(TW_IN_RESET, &tw_dev->flags)) { in twl_scsi_queue_lck()
1468 twl_get_request_id(tw_dev, &request_id); in twl_scsi_queue_lck()
1471 tw_dev->srb[request_id] = SCpnt; in twl_scsi_queue_lck()
1473 retval = twl_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL); in twl_scsi_queue_lck()
1475 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_scsi_queue_lck()
1476 twl_free_request_id(tw_dev, request_id); in twl_scsi_queue_lck()
1488 static void __twl_shutdown(TW_Device_Extension *tw_dev) in DEF_SCSI_QCMD()
1491 TWL_MASK_INTERRUPTS(tw_dev); in DEF_SCSI_QCMD()
1494 free_irq(tw_dev->tw_pci_dev->irq, tw_dev); in DEF_SCSI_QCMD()
1496 printk(KERN_WARNING "3w-sas: Shutting down host %d.\n", tw_dev->host->host_no); in DEF_SCSI_QCMD()
1499 if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) { in DEF_SCSI_QCMD()
1500 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x16, "Connection shutdown failed"); in DEF_SCSI_QCMD()
1506 TWL_CLEAR_DB_INTERRUPT(tw_dev); in DEF_SCSI_QCMD()
1513 TW_Device_Extension *tw_dev; in twl_shutdown() local
1518 tw_dev = (TW_Device_Extension *)host->hostdata; in twl_shutdown()
1520 if (tw_dev->online) in twl_shutdown()
1521 __twl_shutdown(tw_dev); in twl_shutdown()
1556 TW_Device_Extension *tw_dev; in twl_probe() local
1582 tw_dev = shost_priv(host); in twl_probe()
1585 tw_dev->host = host; in twl_probe()
1586 tw_dev->tw_pci_dev = pdev; in twl_probe()
1588 if (twl_initialize_device_extension(tw_dev)) { in twl_probe()
1589 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Failed to initialize device extension"); in twl_probe()
1597 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1b, "Failed to get mem region"); in twl_probe()
1602 tw_dev->base_addr = pci_iomap(pdev, 1, 0); in twl_probe()
1603 if (!tw_dev->base_addr) { in twl_probe()
1604 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1c, "Failed to ioremap"); in twl_probe()
1610 TWL_MASK_INTERRUPTS(tw_dev); in twl_probe()
1613 if (twl_reset_sequence(tw_dev, 0)) { in twl_probe()
1614 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1d, "Controller reset failed during probe"); in twl_probe()
1628 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1e, "scsi add host failed"); in twl_probe()
1636 (char *)twl_get_param(tw_dev, 1, TW_VERSION_TABLE, in twl_probe()
1640 ptr_phycount = twl_get_param(tw_dev, 2, TW_PARAM_PHY_SUMMARY_TABLE, in twl_probe()
1647 (char *)twl_get_param(tw_dev, 1, TW_VERSION_TABLE, in twl_probe()
1649 (char *)twl_get_param(tw_dev, 2, TW_VERSION_TABLE, in twl_probe()
1655 set_bit(TW_USING_MSI, &tw_dev->flags); in twl_probe()
1658 retval = request_irq(pdev->irq, twl_interrupt, IRQF_SHARED, "3w-sas", tw_dev); in twl_probe()
1660 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1f, "Error requesting IRQ"); in twl_probe()
1664 twl_device_extension_list[twl_device_extension_count] = tw_dev; in twl_probe()
1668 TWL_UNMASK_INTERRUPTS(tw_dev); in twl_probe()
1675 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x20, "Failed to create sysfs binary file: 3ware_aen_read"); in twl_probe()
1677 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x21, "Failed to create sysfs binary file: 3ware_compat_info"); in twl_probe()
1683 tw_dev->online = 1; in twl_probe()
1687 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_probe()
1691 iounmap(tw_dev->base_addr); in twl_probe()
1695 twl_free_device_extension(tw_dev); in twl_probe()
1707 TW_Device_Extension *tw_dev; in twl_remove() local
1712 tw_dev = (TW_Device_Extension *)host->hostdata; in twl_remove()
1714 if (!tw_dev->online) in twl_remove()
1721 scsi_remove_host(tw_dev->host); in twl_remove()
1730 __twl_shutdown(tw_dev); in twl_remove()
1733 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_remove()
1737 iounmap(tw_dev->base_addr); in twl_remove()
1743 twl_free_device_extension(tw_dev); in twl_remove()
1745 scsi_host_put(tw_dev->host); in twl_remove()
1754 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_suspend() local
1756 printk(KERN_WARNING "3w-sas: Suspending host %d.\n", tw_dev->host->host_no); in twl_suspend()
1758 TWL_MASK_INTERRUPTS(tw_dev); in twl_suspend()
1760 free_irq(tw_dev->tw_pci_dev->irq, tw_dev); in twl_suspend()
1763 if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) { in twl_suspend()
1764 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x23, "Connection shutdown failed during suspend"); in twl_suspend()
1770 TWL_CLEAR_DB_INTERRUPT(tw_dev); in twl_suspend()
1781 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_resume() local
1783 printk(KERN_WARNING "3w-sas: Resuming host %d.\n", tw_dev->host->host_no); in twl_resume()
1794 if (twl_reset_sequence(tw_dev, 0)) { in twl_resume()
1800 retval = request_irq(pdev->irq, twl_interrupt, IRQF_SHARED, "3w-sas", tw_dev); in twl_resume()
1802 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x26, "Error requesting IRQ during resume"); in twl_resume()
1808 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_resume()
1812 TWL_UNMASK_INTERRUPTS(tw_dev); in twl_resume()