Lines Matching refs:tw_dev

96 static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset);
107 TW_Device_Extension *tw_dev = (TW_Device_Extension *)shost->hostdata; in twl_sysfs_aen_read() local
114 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_sysfs_aen_read()
115 …ret = memory_read_from_buffer(outbuf, count, &offset, tw_dev->event_queue[0], sizeof(TW_Event) * T… in twl_sysfs_aen_read()
116 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_sysfs_aen_read()
138 TW_Device_Extension *tw_dev = (TW_Device_Extension *)shost->hostdata; in twl_sysfs_compat_info() local
145 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_sysfs_compat_info()
146 …ret = memory_read_from_buffer(outbuf, count, &offset, &tw_dev->tw_compat_info, sizeof(TW_Compatibi… in twl_sysfs_compat_info()
147 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_sysfs_compat_info()
167 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_show_stats() local
171 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_show_stats()
182 tw_dev->posted_request_count, in twl_show_stats()
183 tw_dev->max_posted_request_count, in twl_show_stats()
184 tw_dev->sgl_entries, in twl_show_stats()
185 tw_dev->max_sgl_entries, in twl_show_stats()
186 tw_dev->sector_count, in twl_show_stats()
187 tw_dev->max_sector_count, in twl_show_stats()
188 tw_dev->num_resets, in twl_show_stats()
189 tw_dev->aen_count); in twl_show_stats()
190 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_show_stats()
237 static void twl_aen_queue_event(TW_Device_Extension *tw_dev, TW_Command_Apache_Header *header) in twl_aen_queue_event() argument
246 tw_dev->aen_count++; in twl_aen_queue_event()
249 event = tw_dev->event_queue[tw_dev->error_index]; in twl_aen_queue_event()
252 if (tw_dev->host) in twl_aen_queue_event()
253 sprintf(host, " scsi%d:", tw_dev->host->host_no); in twl_aen_queue_event()
264 event->sequence_id = tw_dev->error_sequence_id; in twl_aen_queue_event()
265 tw_dev->error_sequence_id++; in twl_aen_queue_event()
280 tw_dev->aen_count--; in twl_aen_queue_event()
282 tw_dev->error_index = (tw_dev->error_index + 1 ) % TW_Q_LENGTH; in twl_aen_queue_event()
286 static int twl_post_command_packet(TW_Device_Extension *tw_dev, int request_id) in twl_post_command_packet() argument
290 command_que_value = tw_dev->command_packet_phys[request_id]; in twl_post_command_packet()
294 writel((u32)((u64)command_que_value >> 32), TWL_HIBQPH_REG_ADDR(tw_dev)); in twl_post_command_packet()
296 writel((u32)(command_que_value | TWL_PULL_MODE), TWL_HIBQPL_REG_ADDR(tw_dev)); in twl_post_command_packet()
298 tw_dev->state[request_id] = TW_S_POSTED; in twl_post_command_packet()
299 tw_dev->posted_request_count++; in twl_post_command_packet()
300 if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) in twl_post_command_packet()
301 tw_dev->max_posted_request_count = tw_dev->posted_request_count; in twl_post_command_packet()
307 static int twl_map_scsi_sg_data(TW_Device_Extension *tw_dev, int request_id) in twl_map_scsi_sg_data() argument
310 struct scsi_cmnd *cmd = tw_dev->srb[request_id]; in twl_map_scsi_sg_data()
316 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Failed to map scatter gather list"); in twl_map_scsi_sg_data()
327 static int twl_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, char *cdb, int use_… in twl_scsiop_execute_scsi() argument
336 if (tw_dev->srb[request_id]) { in twl_scsiop_execute_scsi()
337 srb = tw_dev->srb[request_id]; in twl_scsiop_execute_scsi()
343 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_scsiop_execute_scsi()
373 sg_count = twl_map_scsi_sg_data(tw_dev, request_id); in twl_scsiop_execute_scsi()
381 …_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()
394 tw_dev->sector_count = scsi_bufflen(srb) / 512; in twl_scsiop_execute_scsi()
395 if (tw_dev->sector_count > tw_dev->max_sector_count) in twl_scsiop_execute_scsi()
396 tw_dev->max_sector_count = tw_dev->sector_count; in twl_scsiop_execute_scsi()
397 tw_dev->sgl_entries = scsi_sg_count(srb); in twl_scsiop_execute_scsi()
398 if (tw_dev->sgl_entries > tw_dev->max_sgl_entries) in twl_scsiop_execute_scsi()
399 tw_dev->max_sgl_entries = tw_dev->sgl_entries; in twl_scsiop_execute_scsi()
403 retval = twl_post_command_packet(tw_dev, request_id); in twl_scsiop_execute_scsi()
410 static int twl_aen_read_queue(TW_Device_Extension *tw_dev, int request_id) in twl_aen_read_queue() argument
417 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_read_queue()
428 sglist[0].address = tw_dev->generic_buffer_phys[request_id]; in twl_aen_read_queue()
431 tw_dev->srb[request_id] = NULL; in twl_aen_read_queue()
434 if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) { in twl_aen_read_queue()
435 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2, "Post failed while reading AEN queue"); in twl_aen_read_queue()
444 static void twl_aen_sync_time(TW_Device_Extension *tw_dev, int request_id) in twl_aen_sync_time() argument
454 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_sync_time()
459 …command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[requ… in twl_aen_sync_time()
465 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; in twl_aen_sync_time()
481 tw_dev->srb[request_id] = NULL; in twl_aen_sync_time()
484 twl_post_command_packet(tw_dev, request_id); in twl_aen_sync_time()
488 static void twl_get_request_id(TW_Device_Extension *tw_dev, int *request_id) in twl_get_request_id() argument
490 *request_id = tw_dev->free_queue[tw_dev->free_head]; in twl_get_request_id()
491 tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH; in twl_get_request_id()
492 tw_dev->state[*request_id] = TW_S_STARTED; in twl_get_request_id()
496 static void twl_free_request_id(TW_Device_Extension *tw_dev, int request_id) in twl_free_request_id() argument
498 tw_dev->free_queue[tw_dev->free_tail] = request_id; in twl_free_request_id()
499 tw_dev->state[request_id] = TW_S_FINISHED; in twl_free_request_id()
500 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH; in twl_free_request_id()
504 static int twl_aen_complete(TW_Device_Extension *tw_dev, int request_id) in twl_aen_complete() argument
512 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id]; in twl_aen_complete()
513 tw_dev->posted_request_count--; in twl_aen_complete()
515 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_complete()
521 if (twl_aen_read_queue(tw_dev, request_id)) in twl_aen_complete()
534 twl_aen_sync_time(tw_dev, request_id); in twl_aen_complete()
538 twl_aen_queue_event(tw_dev, header); in twl_aen_complete()
541 if (twl_aen_read_queue(tw_dev, request_id)) in twl_aen_complete()
550 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_aen_complete()
551 twl_free_request_id(tw_dev, request_id); in twl_aen_complete()
552 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); in twl_aen_complete()
558 static int twl_poll_response(TW_Device_Extension *tw_dev, int request_id, int seconds) in twl_poll_response() argument
571 regh = readl(TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_poll_response()
572 regl = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_poll_response()
575 mfa = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_poll_response()
593 static int twl_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset) in twl_aen_drain_queue() argument
609 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_drain_queue()
620 sglist[0].address = tw_dev->generic_buffer_phys[request_id]; in twl_aen_drain_queue()
623 tw_dev->srb[request_id] = NULL; in twl_aen_drain_queue()
627 if (twl_scsiop_execute_scsi(tw_dev, request_id, cdb, 1, sglist)) { in twl_aen_drain_queue()
628 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "Error posting request sense"); in twl_aen_drain_queue()
633 if (twl_poll_response(tw_dev, request_id, 30)) { in twl_aen_drain_queue()
634 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x4, "No valid response while draining AEN queue"); in twl_aen_drain_queue()
635 tw_dev->posted_request_count--; in twl_aen_drain_queue()
639 tw_dev->posted_request_count--; in twl_aen_drain_queue()
640 header = (TW_Command_Apache_Header *)tw_dev->generic_buffer_virt[request_id]; in twl_aen_drain_queue()
666 twl_aen_queue_event(tw_dev, header); in twl_aen_drain_queue()
674 tw_dev->state[request_id] = TW_S_INITIAL; in twl_aen_drain_queue()
679 static int twl_allocate_memory(TW_Device_Extension *tw_dev, int size, int which) in twl_allocate_memory() argument
686 cpu_addr = pci_alloc_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, &dma_handle); in twl_allocate_memory()
688 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed"); in twl_allocate_memory()
697 tw_dev->command_packet_phys[i] = dma_handle+(i*size); in twl_allocate_memory()
698 tw_dev->command_packet_virt[i] = (TW_Command_Full *)((unsigned char *)cpu_addr + (i*size)); in twl_allocate_memory()
701 tw_dev->generic_buffer_phys[i] = dma_handle+(i*size); in twl_allocate_memory()
702 tw_dev->generic_buffer_virt[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size)); in twl_allocate_memory()
705 tw_dev->sense_buffer_phys[i] = dma_handle+(i*size); in twl_allocate_memory()
706tw_dev->sense_buffer_virt[i] = (TW_Command_Apache_Header *)((unsigned char *)cpu_addr + (i*size)); in twl_allocate_memory()
716 static void twl_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_command_packet, int req… in twl_load_sgl() argument
763 TW_Device_Extension *tw_dev = twl_device_extension_list[iminor(inode)]; in twl_chrdev_ioctl() local
770 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { in twl_chrdev_ioctl()
789 …cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioct… in twl_chrdev_ioctl()
804 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
805 twl_get_request_id(tw_dev, &request_id); in twl_chrdev_ioctl()
808 tw_dev->srb[request_id] = NULL; in twl_chrdev_ioctl()
811 tw_dev->chrdev_request_id = request_id; in twl_chrdev_ioctl()
816 twl_load_sgl(tw_dev, full_command_packet, request_id, dma_handle, data_buffer_length_adjusted); in twl_chrdev_ioctl()
818 …memcpy(tw_dev->command_packet_virt[request_id], &(tw_ioctl->firmware_command), sizeof(TW_Command_F… in twl_chrdev_ioctl()
821 twl_post_command_packet(tw_dev, request_id); in twl_chrdev_ioctl()
822 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
827 …timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FR… in twl_chrdev_ioctl()
830 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { in twl_chrdev_ioctl()
833 tw_dev->host->host_no, TW_DRIVER, 0x6, in twl_chrdev_ioctl()
836 twl_reset_device_extension(tw_dev, 1); in twl_chrdev_ioctl()
841 …memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virt[request_id], sizeof(TW_Command_F… in twl_chrdev_ioctl()
844 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
845 tw_dev->posted_request_count--; in twl_chrdev_ioctl()
846 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_chrdev_ioctl()
847 twl_free_request_id(tw_dev, request_id); in twl_chrdev_ioctl()
848 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
860 …dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache… in twl_chrdev_ioctl()
862 mutex_unlock(&tw_dev->ioctl_lock); in twl_chrdev_ioctl()
897 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
905 header = tw_dev->sense_buffer_virt[i]; in twl_fill_sense()
906 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_fill_sense()
916 tw_dev->host->host_no, in twl_fill_sense()
930 memcpy(tw_dev->srb[request_id]->sense_buffer, header->sense_data, TW_SENSE_DATA_LENGTH); in twl_fill_sense()
931 tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1); in twl_fill_sense()
939 static void twl_free_device_extension(TW_Device_Extension *tw_dev) in twl_free_device_extension() argument
941 if (tw_dev->command_packet_virt[0]) in twl_free_device_extension()
942 pci_free_consistent(tw_dev->tw_pci_dev, in twl_free_device_extension()
944 tw_dev->command_packet_virt[0], in twl_free_device_extension()
945 tw_dev->command_packet_phys[0]); in twl_free_device_extension()
947 if (tw_dev->generic_buffer_virt[0]) in twl_free_device_extension()
948 pci_free_consistent(tw_dev->tw_pci_dev, in twl_free_device_extension()
950 tw_dev->generic_buffer_virt[0], in twl_free_device_extension()
951 tw_dev->generic_buffer_phys[0]); in twl_free_device_extension()
953 if (tw_dev->sense_buffer_virt[0]) in twl_free_device_extension()
954 pci_free_consistent(tw_dev->tw_pci_dev, in twl_free_device_extension()
957 tw_dev->sense_buffer_virt[0], in twl_free_device_extension()
958 tw_dev->sense_buffer_phys[0]); in twl_free_device_extension()
960 kfree(tw_dev->event_queue[0]); in twl_free_device_extension()
964 static void *twl_get_param(TW_Device_Extension *tw_dev, int request_id, int table_id, int parameter… in twl_get_param() argument
972 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_get_param()
982 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; in twl_get_param()
988 …command_packet->byte8_offset.param.sgl[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[requ… in twl_get_param()
992 twl_post_command_packet(tw_dev, request_id); in twl_get_param()
995 if (twl_poll_response(tw_dev, request_id, 30)) in twl_get_param()
996 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "No valid response during get param") in twl_get_param()
1000 tw_dev->posted_request_count--; in twl_get_param()
1001 tw_dev->state[request_id] = TW_S_INITIAL; in twl_get_param()
1007 static int twl_initconnection(TW_Device_Extension *tw_dev, int message_credits, in twl_initconnection() argument
1023 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_initconnection()
1048 twl_post_command_packet(tw_dev, request_id); in twl_initconnection()
1051 if (twl_poll_response(tw_dev, request_id, 30)) { in twl_initconnection()
1052 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x8, "No valid response during init connection"); in twl_initconnection()
1064 tw_dev->posted_request_count--; in twl_initconnection()
1065 tw_dev->state[request_id] = TW_S_INITIAL; in twl_initconnection()
1071 static int twl_initialize_device_extension(TW_Device_Extension *tw_dev) in twl_initialize_device_extension() argument
1076 if (twl_allocate_memory(tw_dev, sizeof(TW_Command_Full), 0)) { in twl_initialize_device_extension()
1077 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x9, "Command packet memory allocation failed"); in twl_initialize_device_extension()
1082 if (twl_allocate_memory(tw_dev, TW_SECTOR_SIZE, 1)) { in twl_initialize_device_extension()
1083 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Generic memory allocation failed"); in twl_initialize_device_extension()
1088 if (twl_allocate_memory(tw_dev, sizeof(TW_Command_Apache_Header), 2)) { in twl_initialize_device_extension()
1089 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xb, "Sense buffer allocation failed"); in twl_initialize_device_extension()
1094 tw_dev->event_queue[0] = kcalloc(TW_Q_LENGTH, sizeof(TW_Event), GFP_KERNEL); in twl_initialize_device_extension()
1095 if (!tw_dev->event_queue[0]) { in twl_initialize_device_extension()
1096 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xc, "Event info memory allocation failed"); in twl_initialize_device_extension()
1101tw_dev->event_queue[i] = (TW_Event *)((unsigned char *)tw_dev->event_queue[0] + (i * sizeof(TW_Eve… in twl_initialize_device_extension()
1102 tw_dev->free_queue[i] = i; in twl_initialize_device_extension()
1103 tw_dev->state[i] = TW_S_INITIAL; in twl_initialize_device_extension()
1106 tw_dev->free_head = TW_Q_START; in twl_initialize_device_extension()
1107 tw_dev->free_tail = TW_Q_START; in twl_initialize_device_extension()
1108 tw_dev->error_sequence_id = 1; in twl_initialize_device_extension()
1109 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in twl_initialize_device_extension()
1111 mutex_init(&tw_dev->ioctl_lock); in twl_initialize_device_extension()
1112 init_waitqueue_head(&tw_dev->ioctl_wqueue); in twl_initialize_device_extension()
1120 static void twl_unmap_scsi_data(TW_Device_Extension *tw_dev, int request_id) in twl_unmap_scsi_data() argument
1122 struct scsi_cmnd *cmd = tw_dev->srb[request_id]; in twl_unmap_scsi_data()
1129 static int twl_handle_attention_interrupt(TW_Device_Extension *tw_dev) in twl_handle_attention_interrupt() argument
1135 doorbell = readl(TWL_HOBDB_REG_ADDR(tw_dev)); in twl_handle_attention_interrupt()
1139 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xd, "Microcontroller Error: clearing"); in twl_handle_attention_interrupt()
1145 if (!(test_and_set_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags))) { in twl_handle_attention_interrupt()
1146 twl_get_request_id(tw_dev, &request_id); in twl_handle_attention_interrupt()
1147 if (twl_aen_read_queue(tw_dev, request_id)) { in twl_handle_attention_interrupt()
1148 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_handle_attention_interrupt()
1149 twl_free_request_id(tw_dev, request_id); in twl_handle_attention_interrupt()
1150 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); in twl_handle_attention_interrupt()
1158 TWL_CLEAR_DB_INTERRUPT(tw_dev); in twl_handle_attention_interrupt()
1161 readl(TWL_HOBDBC_REG_ADDR(tw_dev)); in twl_handle_attention_interrupt()
1169 TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance; in twl_interrupt() local
1176 spin_lock(tw_dev->host->host_lock); in twl_interrupt()
1179 reg = readl(TWL_HISTAT_REG_ADDR(tw_dev)); in twl_interrupt()
1188 if (test_bit(TW_IN_RESET, &tw_dev->flags)) in twl_interrupt()
1193 if (twl_handle_attention_interrupt(tw_dev)) { in twl_interrupt()
1194 TWL_MASK_INTERRUPTS(tw_dev); in twl_interrupt()
1202 regh = readl(TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_interrupt()
1203 regl = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_interrupt()
1206 mfa = readl(TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_interrupt()
1214 if (tw_dev->sense_buffer_phys[i] == mfa) { in twl_interrupt()
1215 request_id = le16_to_cpu(tw_dev->sense_buffer_virt[i]->header_desc.request_id); in twl_interrupt()
1216 if (tw_dev->srb[request_id] != NULL) in twl_interrupt()
1217 error = twl_fill_sense(tw_dev, i, request_id, 1, 1); in twl_interrupt()
1220 if (request_id != tw_dev->chrdev_request_id) in twl_interrupt()
1221 error = twl_fill_sense(tw_dev, i, request_id, 0, 1); in twl_interrupt()
1223 …memcpy(tw_dev->command_packet_virt[request_id], tw_dev->sense_buffer_virt[i], sizeof(TW_Command_Ap… in twl_interrupt()
1227 writel((u32)((u64)tw_dev->sense_buffer_phys[i] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_interrupt()
1228 writel((u32)tw_dev->sense_buffer_phys[i], TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_interrupt()
1235 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_interrupt()
1238 if (tw_dev->state[request_id] != TW_S_POSTED) { in twl_interrupt()
1239 if (tw_dev->srb[request_id] != NULL) { in twl_interrupt()
1240 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xe, "Received a request id that wasn't posted"); in twl_interrupt()
1241 TWL_MASK_INTERRUPTS(tw_dev); in twl_interrupt()
1247 if (tw_dev->srb[request_id] == NULL) { in twl_interrupt()
1248 if (request_id != tw_dev->chrdev_request_id) { in twl_interrupt()
1249 if (twl_aen_complete(tw_dev, request_id)) in twl_interrupt()
1250 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xf, "Error completing AEN during attention interrupt"); in twl_interrupt()
1252 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in twl_interrupt()
1253 wake_up(&tw_dev->ioctl_wqueue); in twl_interrupt()
1256 cmd = tw_dev->srb[request_id]; in twl_interrupt()
1263 …if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_i… in twl_interrupt()
1268 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_interrupt()
1269 twl_free_request_id(tw_dev, request_id); in twl_interrupt()
1270 tw_dev->posted_request_count--; in twl_interrupt()
1271 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]); in twl_interrupt()
1272 twl_unmap_scsi_data(tw_dev, request_id); in twl_interrupt()
1276 reg = readl(TWL_HISTAT_REG_ADDR(tw_dev)); in twl_interrupt()
1280 spin_unlock(tw_dev->host->host_lock); in twl_interrupt()
1285 static int twl_poll_register(TW_Device_Extension *tw_dev, void *reg, u32 value, u32 result, int sec… in twl_poll_register() argument
1306 static int twl_reset_sequence(TW_Device_Extension *tw_dev, int soft_reset) in twl_reset_sequence() argument
1320 TWL_SOFT_RESET(tw_dev); in twl_reset_sequence()
1323 if (twl_poll_register(tw_dev, TWL_SCRPD3_REG_ADDR(tw_dev), TWL_CONTROLLER_READY, 0x0, 30)) { in twl_reset_sequence()
1324 … TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Controller never went non-ready during reset sequence"); in twl_reset_sequence()
1328 …if (twl_poll_register(tw_dev, TWL_SCRPD3_REG_ADDR(tw_dev), TWL_CONTROLLER_READY, TWL_CONTROLLER_RE… in twl_reset_sequence()
1329 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x11, "Controller not ready during reset sequence"); in twl_reset_sequence()
1336 if (twl_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS, in twl_reset_sequence()
1342 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x12, "Initconnection failed while checking SRL"); in twl_reset_sequence()
1350 writel((u32)((u64)tw_dev->sense_buffer_phys[i] >> 32), TWL_HOBQPH_REG_ADDR(tw_dev)); in twl_reset_sequence()
1351 writel((u32)tw_dev->sense_buffer_phys[i], TWL_HOBQPL_REG_ADDR(tw_dev)); in twl_reset_sequence()
1354 status = readl(TWL_STATUS_REG_ADDR(tw_dev)); in twl_reset_sequence()
1360 status = readl(TWL_STATUS_REG_ADDR(tw_dev)); in twl_reset_sequence()
1362 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x13, "Bad controller status after loading sense buffers"); in twl_reset_sequence()
1369 if (twl_aen_drain_queue(tw_dev, soft_reset)) { in twl_reset_sequence()
1370 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x14, "AEN drain failed during reset sequence"); in twl_reset_sequence()
1377 strncpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, strlen(TW_DRIVER_VERSION)); in twl_reset_sequence()
1378 tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL; in twl_reset_sequence()
1379 tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH; in twl_reset_sequence()
1380 tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD; in twl_reset_sequence()
1381 tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL; in twl_reset_sequence()
1382 tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH; in twl_reset_sequence()
1383 tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD; in twl_reset_sequence()
1384 tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl; in twl_reset_sequence()
1385 tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch; in twl_reset_sequence()
1386 tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build; in twl_reset_sequence()
1397 static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset) in twl_reset_device_extension() argument
1404 scsi_block_requests(tw_dev->host); in twl_reset_device_extension()
1406 set_bit(TW_IN_RESET, &tw_dev->flags); in twl_reset_device_extension()
1407 TWL_MASK_INTERRUPTS(tw_dev); in twl_reset_device_extension()
1408 TWL_CLEAR_DB_INTERRUPT(tw_dev); in twl_reset_device_extension()
1410 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_reset_device_extension()
1414 if ((tw_dev->state[i] != TW_S_FINISHED) && in twl_reset_device_extension()
1415 (tw_dev->state[i] != TW_S_INITIAL) && in twl_reset_device_extension()
1416 (tw_dev->state[i] != TW_S_COMPLETED)) { in twl_reset_device_extension()
1417 if (tw_dev->srb[i]) { in twl_reset_device_extension()
1418 tw_dev->srb[i]->result = (DID_RESET << 16); in twl_reset_device_extension()
1419 tw_dev->srb[i]->scsi_done(tw_dev->srb[i]); in twl_reset_device_extension()
1420 twl_unmap_scsi_data(tw_dev, i); in twl_reset_device_extension()
1427 tw_dev->free_queue[i] = i; in twl_reset_device_extension()
1428 tw_dev->state[i] = TW_S_INITIAL; in twl_reset_device_extension()
1430 tw_dev->free_head = TW_Q_START; in twl_reset_device_extension()
1431 tw_dev->free_tail = TW_Q_START; in twl_reset_device_extension()
1432 tw_dev->posted_request_count = 0; in twl_reset_device_extension()
1434 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_reset_device_extension()
1436 if (twl_reset_sequence(tw_dev, 1)) in twl_reset_device_extension()
1439 TWL_UNMASK_INTERRUPTS(tw_dev); in twl_reset_device_extension()
1441 clear_bit(TW_IN_RESET, &tw_dev->flags); in twl_reset_device_extension()
1442 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in twl_reset_device_extension()
1447 scsi_unblock_requests(tw_dev->host); in twl_reset_device_extension()
1455 TW_Device_Extension *tw_dev; in twl_scsi_biosparam() local
1457 tw_dev = (TW_Device_Extension *)sdev->host->hostdata; in twl_scsi_biosparam()
1477 TW_Device_Extension *tw_dev = NULL; in twl_scsi_eh_reset() local
1480 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in twl_scsi_eh_reset()
1482 tw_dev->num_resets++; in twl_scsi_eh_reset()
1489 mutex_lock(&tw_dev->ioctl_lock); in twl_scsi_eh_reset()
1492 if (twl_reset_device_extension(tw_dev, 0)) { in twl_scsi_eh_reset()
1493 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x15, "Controller reset failed during scsi host reset"); in twl_scsi_eh_reset()
1499 mutex_unlock(&tw_dev->ioctl_lock); in twl_scsi_eh_reset()
1507 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in twl_scsi_queue_lck() local
1510 if (test_bit(TW_IN_RESET, &tw_dev->flags)) { in twl_scsi_queue_lck()
1519 twl_get_request_id(tw_dev, &request_id); in twl_scsi_queue_lck()
1522 tw_dev->srb[request_id] = SCpnt; in twl_scsi_queue_lck()
1527 retval = twl_scsiop_execute_scsi(tw_dev, request_id, NULL, 0, NULL); in twl_scsi_queue_lck()
1529 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_scsi_queue_lck()
1530 twl_free_request_id(tw_dev, request_id); in twl_scsi_queue_lck()
1542 static void __twl_shutdown(TW_Device_Extension *tw_dev) in DEF_SCSI_QCMD()
1545 TWL_MASK_INTERRUPTS(tw_dev); in DEF_SCSI_QCMD()
1548 free_irq(tw_dev->tw_pci_dev->irq, tw_dev); in DEF_SCSI_QCMD()
1550 printk(KERN_WARNING "3w-sas: Shutting down host %d.\n", tw_dev->host->host_no); in DEF_SCSI_QCMD()
1553 if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) { in DEF_SCSI_QCMD()
1554 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x16, "Connection shutdown failed"); in DEF_SCSI_QCMD()
1560 TWL_CLEAR_DB_INTERRUPT(tw_dev); in DEF_SCSI_QCMD()
1567 TW_Device_Extension *tw_dev; in twl_shutdown() local
1572 tw_dev = (TW_Device_Extension *)host->hostdata; in twl_shutdown()
1574 if (tw_dev->online) in twl_shutdown()
1575 __twl_shutdown(tw_dev); in twl_shutdown()
1610 TW_Device_Extension *tw_dev; in twl_probe() local
1638 tw_dev = shost_priv(host); in twl_probe()
1641 tw_dev->host = host; in twl_probe()
1642 tw_dev->tw_pci_dev = pdev; in twl_probe()
1644 if (twl_initialize_device_extension(tw_dev)) { in twl_probe()
1645 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Failed to initialize device extension"); in twl_probe()
1652 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1b, "Failed to get mem region"); in twl_probe()
1657 tw_dev->base_addr = pci_iomap(pdev, 1, 0); in twl_probe()
1658 if (!tw_dev->base_addr) { in twl_probe()
1659 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1c, "Failed to ioremap"); in twl_probe()
1664 TWL_MASK_INTERRUPTS(tw_dev); in twl_probe()
1667 if (twl_reset_sequence(tw_dev, 0)) { in twl_probe()
1668 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1d, "Controller reset failed during probe"); in twl_probe()
1681 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1e, "scsi add host failed"); in twl_probe()
1689 (char *)twl_get_param(tw_dev, 1, TW_VERSION_TABLE, in twl_probe()
1693 ptr_phycount = twl_get_param(tw_dev, 2, TW_PARAM_PHY_SUMMARY_TABLE, in twl_probe()
1700 (char *)twl_get_param(tw_dev, 1, TW_VERSION_TABLE, in twl_probe()
1702 (char *)twl_get_param(tw_dev, 2, TW_VERSION_TABLE, in twl_probe()
1708 set_bit(TW_USING_MSI, &tw_dev->flags); in twl_probe()
1711 retval = request_irq(pdev->irq, twl_interrupt, IRQF_SHARED, "3w-sas", tw_dev); in twl_probe()
1713 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1f, "Error requesting IRQ"); in twl_probe()
1717 twl_device_extension_list[twl_device_extension_count] = tw_dev; in twl_probe()
1721 TWL_UNMASK_INTERRUPTS(tw_dev); in twl_probe()
1728 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x20, "Failed to create sysfs binary file: 3ware_aen_read"); in twl_probe()
1730 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x21, "Failed to create sysfs binary file: 3ware_compat_info"); in twl_probe()
1736 tw_dev->online = 1; in twl_probe()
1740 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_probe()
1744 iounmap(tw_dev->base_addr); in twl_probe()
1748 twl_free_device_extension(tw_dev); in twl_probe()
1760 TW_Device_Extension *tw_dev; in twl_remove() local
1765 tw_dev = (TW_Device_Extension *)host->hostdata; in twl_remove()
1767 if (!tw_dev->online) in twl_remove()
1774 scsi_remove_host(tw_dev->host); in twl_remove()
1783 __twl_shutdown(tw_dev); in twl_remove()
1786 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_remove()
1790 iounmap(tw_dev->base_addr); in twl_remove()
1796 twl_free_device_extension(tw_dev); in twl_remove()
1798 scsi_host_put(tw_dev->host); in twl_remove()
1808 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_suspend() local
1810 printk(KERN_WARNING "3w-sas: Suspending host %d.\n", tw_dev->host->host_no); in twl_suspend()
1812 TWL_MASK_INTERRUPTS(tw_dev); in twl_suspend()
1814 free_irq(tw_dev->tw_pci_dev->irq, tw_dev); in twl_suspend()
1817 if (twl_initconnection(tw_dev, 1, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL)) { in twl_suspend()
1818 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x23, "Connection shutdown failed during suspend"); in twl_suspend()
1824 TWL_CLEAR_DB_INTERRUPT(tw_dev); in twl_suspend()
1838 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_resume() local
1840 printk(KERN_WARNING "3w-sas: Resuming host %d.\n", tw_dev->host->host_no); in twl_resume()
1847 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x24, "Enable device failed during resume"); in twl_resume()
1864 if (twl_reset_sequence(tw_dev, 0)) { in twl_resume()
1870 retval = request_irq(pdev->irq, twl_interrupt, IRQF_SHARED, "3w-sas", tw_dev); in twl_resume()
1872 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x26, "Error requesting IRQ during resume"); in twl_resume()
1878 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_resume()
1882 TWL_UNMASK_INTERRUPTS(tw_dev); in twl_resume()