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