Lines Matching refs:tw_dev

235 static int tw_reset_device_extension(TW_Device_Extension *tw_dev);
255 static int tw_decode_bits(TW_Device_Extension *tw_dev, u32 status_reg_value, int print_host) in tw_decode_bits() argument
262 sprintf(host, " scsi%d:", tw_dev->host->host_no); in tw_decode_bits()
268 outl(TW_CONTROL_CLEAR_PARITY_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); in tw_decode_bits()
273 outl(TW_CONTROL_CLEAR_PCI_ABORT, TW_CONTROL_REG_ADDR(tw_dev)); in tw_decode_bits()
274 pci_write_config_word(tw_dev->tw_pci_dev, PCI_STATUS, TW_PCI_CLEAR_PCI_ABORT); in tw_decode_bits()
279 outl(TW_CONTROL_CLEAR_QUEUE_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); in tw_decode_bits()
284 outl(TW_CONTROL_CLEAR_SBUF_WRITE_ERROR, TW_CONTROL_REG_ADDR(tw_dev)); in tw_decode_bits()
288 if (tw_dev->reset_print == 0) { in tw_decode_bits()
290 tw_dev->reset_print = 1; in tw_decode_bits()
299 static int tw_poll_status(TW_Device_Extension *tw_dev, u32 flag, int seconds) in tw_poll_status() argument
305 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_poll_status()
309 tw_decode_bits(tw_dev, status_reg_value, 0); in tw_poll_status()
312 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_poll_status()
315 tw_decode_bits(tw_dev, status_reg_value, 0); in tw_poll_status()
328 static int tw_poll_status_gone(TW_Device_Extension *tw_dev, u32 flag, int seconds) in tw_poll_status_gone() argument
334 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_poll_status_gone()
338 tw_decode_bits(tw_dev, status_reg_value, 0); in tw_poll_status_gone()
341 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_poll_status_gone()
344 tw_decode_bits(tw_dev, status_reg_value, 0); in tw_poll_status_gone()
357 static int tw_post_command_packet(TW_Device_Extension *tw_dev, int request_id) in tw_post_command_packet() argument
363 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_post_command_packet()
364 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_post_command_packet()
368 tw_decode_bits(tw_dev, status_reg_value, 1); in tw_post_command_packet()
373 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); in tw_post_command_packet()
374 tw_dev->state[request_id] = TW_S_POSTED; in tw_post_command_packet()
375 tw_dev->posted_request_count++; in tw_post_command_packet()
376 if (tw_dev->posted_request_count > tw_dev->max_posted_request_count) { in tw_post_command_packet()
377 tw_dev->max_posted_request_count = tw_dev->posted_request_count; in tw_post_command_packet()
381 if (tw_dev->state[request_id] != TW_S_PENDING) { in tw_post_command_packet()
382 tw_dev->state[request_id] = TW_S_PENDING; in tw_post_command_packet()
383 tw_dev->pending_request_count++; in tw_post_command_packet()
384 if (tw_dev->pending_request_count > tw_dev->max_pending_request_count) { in tw_post_command_packet()
385 tw_dev->max_pending_request_count = tw_dev->pending_request_count; in tw_post_command_packet()
387 tw_dev->pending_queue[tw_dev->pending_tail] = request_id; in tw_post_command_packet()
388 if (tw_dev->pending_tail == TW_Q_LENGTH-1) { in tw_post_command_packet()
389 tw_dev->pending_tail = TW_Q_START; in tw_post_command_packet()
391 tw_dev->pending_tail = tw_dev->pending_tail + 1; in tw_post_command_packet()
394 TW_UNMASK_COMMAND_INTERRUPT(tw_dev); in tw_post_command_packet()
401 static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill_sense) in tw_decode_sense() argument
407 command = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_decode_sense()
409 …xxxx: scsi%d: Command failed: status = 0x%x, flags = 0x%x, unit #%d.\n", tw_dev->host->host_no, co… in tw_decode_sense()
418 tw_dev->srb[request_id]->sense_buffer[0] = (0x1 << 7 | 0x70); in tw_decode_sense()
421 tw_dev->srb[request_id]->sense_buffer[2] = tw_sense_table[i][1]; in tw_decode_sense()
424 tw_dev->srb[request_id]->sense_buffer[7] = 0xa; /* 10 bytes */ in tw_decode_sense()
427 tw_dev->srb[request_id]->sense_buffer[12] = tw_sense_table[i][2]; in tw_decode_sense()
430 tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3]; in tw_decode_sense()
432 tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); in tw_decode_sense()
446 static int tw_check_errors(TW_Device_Extension *tw_dev) in tw_check_errors() argument
450 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_check_errors()
453 tw_decode_bits(tw_dev, status_reg_value, 0); in tw_check_errors()
461 static void tw_empty_response_que(TW_Device_Extension *tw_dev) in tw_empty_response_que() argument
465 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_empty_response_que()
468 response_que_value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); in tw_empty_response_que()
469 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_empty_response_que()
474 static void tw_state_request_finish(TW_Device_Extension *tw_dev, int request_id) in tw_state_request_finish() argument
476 tw_dev->free_queue[tw_dev->free_tail] = request_id; in tw_state_request_finish()
477 tw_dev->state[request_id] = TW_S_FINISHED; in tw_state_request_finish()
478 tw_dev->free_tail = (tw_dev->free_tail + 1) % TW_Q_LENGTH; in tw_state_request_finish()
482 static void tw_state_request_start(TW_Device_Extension *tw_dev, int *request_id) in tw_state_request_start() argument
484 *request_id = tw_dev->free_queue[tw_dev->free_head]; in tw_state_request_start()
485 tw_dev->free_head = (tw_dev->free_head + 1) % TW_Q_LENGTH; in tw_state_request_start()
486 tw_dev->state[*request_id] = TW_S_STARTED; in tw_state_request_start()
494 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in tw_show_stats() local
498 spin_lock_irqsave(tw_dev->host->host_lock, flags); in tw_show_stats()
511 tw_dev->posted_request_count, in tw_show_stats()
512 tw_dev->max_posted_request_count, in tw_show_stats()
513 tw_dev->pending_request_count, in tw_show_stats()
514 tw_dev->max_pending_request_count, in tw_show_stats()
515 tw_dev->sgl_entries, in tw_show_stats()
516 tw_dev->max_sgl_entries, in tw_show_stats()
517 tw_dev->sector_count, in tw_show_stats()
518 tw_dev->max_sector_count, in tw_show_stats()
519 tw_dev->num_resets, in tw_show_stats()
520 tw_dev->aen_count); in tw_show_stats()
521 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in tw_show_stats()
554 static int tw_aen_read_queue(TW_Device_Extension *tw_dev, int request_id) in tw_aen_read_queue() argument
564 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in tw_aen_read_queue()
567 tw_decode_bits(tw_dev, status_reg_value, 1); in tw_aen_read_queue()
570 if (tw_dev->command_packet_virtual_address[request_id] == NULL) { in tw_aen_read_queue()
574 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_aen_read_queue()
582 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_aen_read_queue()
588 if (tw_dev->alignment_virtual_address[request_id] == NULL) { in tw_aen_read_queue()
592 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_aen_read_queue()
597 param_value = tw_dev->alignment_physical_address[request_id]; in tw_aen_read_queue()
608 tw_dev->srb[request_id] = NULL; /* Flag internal command */ in tw_aen_read_queue()
609 tw_dev->state[request_id] = TW_S_POSTED; in tw_aen_read_queue()
610 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); in tw_aen_read_queue()
620 static int tw_aen_complete(TW_Device_Extension *tw_dev, int request_id) in tw_aen_complete() argument
627 if (tw_dev->alignment_virtual_address[request_id] == NULL) { in tw_aen_complete()
631 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_aen_complete()
637 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: INFO: AEN queue overflow.\n", tw_dev->host->host_no); in tw_aen_complete()
642 …printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: %s%d.\n", tw_dev->host->host_no, tw_aen_string[aen & 0x… in tw_aen_complete()
645 …printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: %s.\n", tw_dev->host->host_no, tw_aen_string[aen & 0xff… in tw_aen_complete()
648 printk(KERN_WARNING "3w-xxxx: scsi%d: Received AEN %d.\n", tw_dev->host->host_no, aen); in tw_aen_complete()
652 tw_dev->aen_count++; in tw_aen_complete()
655 tw_dev->aen_queue[tw_dev->aen_tail] = aen; in tw_aen_complete()
656 if (tw_dev->aen_tail == TW_Q_LENGTH - 1) { in tw_aen_complete()
657 tw_dev->aen_tail = TW_Q_START; in tw_aen_complete()
659 tw_dev->aen_tail = tw_dev->aen_tail + 1; in tw_aen_complete()
661 if (tw_dev->aen_head == tw_dev->aen_tail) { in tw_aen_complete()
662 if (tw_dev->aen_head == TW_Q_LENGTH - 1) { in tw_aen_complete()
663 tw_dev->aen_head = TW_Q_START; in tw_aen_complete()
665 tw_dev->aen_head = tw_dev->aen_head + 1; in tw_aen_complete()
669 error = tw_aen_read_queue(tw_dev, request_id); in tw_aen_complete()
671 printk(KERN_WARNING "3w-xxxx: scsi%d: Error completing AEN.\n", tw_dev->host->host_no); in tw_aen_complete()
672 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_aen_complete()
673 tw_state_request_finish(tw_dev, request_id); in tw_aen_complete()
676 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_aen_complete()
677 tw_state_request_finish(tw_dev, request_id); in tw_aen_complete()
684 static int tw_aen_drain_queue(TW_Device_Extension *tw_dev) in tw_aen_drain_queue() argument
701 if (tw_poll_status(tw_dev, TW_STATUS_ATTENTION_INTERRUPT | TW_STATUS_MICROCONTROLLER_READY, 30)) { in tw_aen_drain_queue()
705 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev); in tw_aen_drain_queue()
708 tw_empty_response_que(tw_dev); in tw_aen_drain_queue()
711 if (tw_dev->command_packet_virtual_address[request_id] == NULL) { in tw_aen_drain_queue()
715 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_aen_drain_queue()
723 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_aen_drain_queue()
730 if (tw_dev->alignment_virtual_address[request_id] == NULL) { in tw_aen_drain_queue()
734 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_aen_drain_queue()
739 param_value = tw_dev->alignment_physical_address[request_id]; in tw_aen_drain_queue()
750 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); in tw_aen_drain_queue()
753 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) { in tw_aen_drain_queue()
754 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); in tw_aen_drain_queue()
766 tw_decode_sense(tw_dev, request_id, 0); in tw_aen_drain_queue()
792 tw_dev->aen_count++; in tw_aen_drain_queue()
810 tw_dev->aen_count++; in tw_aen_drain_queue()
816 tw_dev->aen_queue[tw_dev->aen_tail] = aen; in tw_aen_drain_queue()
817 if (tw_dev->aen_tail == TW_Q_LENGTH - 1) { in tw_aen_drain_queue()
818 tw_dev->aen_tail = TW_Q_START; in tw_aen_drain_queue()
820 tw_dev->aen_tail = tw_dev->aen_tail + 1; in tw_aen_drain_queue()
822 if (tw_dev->aen_head == tw_dev->aen_tail) { in tw_aen_drain_queue()
823 if (tw_dev->aen_head == TW_Q_LENGTH - 1) { in tw_aen_drain_queue()
824 tw_dev->aen_head = TW_Q_START; in tw_aen_drain_queue()
826 tw_dev->aen_head = tw_dev->aen_head + 1; in tw_aen_drain_queue()
842 static int tw_allocate_memory(TW_Device_Extension *tw_dev, int size, int which) in tw_allocate_memory() argument
850 cpu_addr = pci_alloc_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, &dma_handle); in tw_allocate_memory()
856 …if ((unsigned long)cpu_addr % (tw_dev->tw_pci_dev->device == TW_DEVICE_ID ? TW_ALIGNMENT_6000 : TW… in tw_allocate_memory()
858 pci_free_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, cpu_addr, dma_handle); in tw_allocate_memory()
867 tw_dev->command_packet_physical_address[i] = dma_handle+(i*size); in tw_allocate_memory()
868tw_dev->command_packet_virtual_address[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size)… in tw_allocate_memory()
871 tw_dev->alignment_physical_address[i] = dma_handle+(i*size); in tw_allocate_memory()
872 tw_dev->alignment_virtual_address[i] = (unsigned long *)((unsigned char *)cpu_addr + (i*size)); in tw_allocate_memory()
897 TW_Device_Extension *tw_dev = tw_device_extension_list[iminor(inode)]; in tw_chrdev_ioctl() local
905 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { in tw_chrdev_ioctl()
924 …cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_… in tw_chrdev_ioctl()
947 spin_lock_irqsave(tw_dev->host->host_lock, flags); in tw_chrdev_ioctl()
948 if (tw_dev->aen_head == tw_dev->aen_tail) { in tw_chrdev_ioctl()
951 tw_aen_code = tw_dev->aen_queue[tw_dev->aen_head]; in tw_chrdev_ioctl()
952 if (tw_dev->aen_head == TW_Q_LENGTH - 1) { in tw_chrdev_ioctl()
953 tw_dev->aen_head = TW_Q_START; in tw_chrdev_ioctl()
955 tw_dev->aen_head = tw_dev->aen_head + 1; in tw_chrdev_ioctl()
958 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in tw_chrdev_ioctl()
963 spin_lock_irqsave(tw_dev->host->host_lock, flags); in tw_chrdev_ioctl()
965 tw_state_request_start(tw_dev, &request_id); in tw_chrdev_ioctl()
968 tw_dev->srb[request_id] = NULL; in tw_chrdev_ioctl()
971 tw_dev->chrdev_request_id = request_id; in tw_chrdev_ioctl()
991 …memcpy(tw_dev->command_packet_virtual_address[request_id], &(tw_ioctl->firmware_command), sizeof(T… in tw_chrdev_ioctl()
994 tw_post_command_packet(tw_dev, request_id); in tw_chrdev_ioctl()
995 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in tw_chrdev_ioctl()
1000 …timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FR… in tw_chrdev_ioctl()
1003 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { in tw_chrdev_ioctl()
1005 … "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cm… in tw_chrdev_ioctl()
1007 if (tw_reset_device_extension(tw_dev)) { in tw_chrdev_ioctl()
1008 …printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_… in tw_chrdev_ioctl()
1014 …memcpy(&(tw_ioctl->firmware_command), tw_dev->command_packet_virtual_address[request_id], sizeof(T… in tw_chrdev_ioctl()
1017 spin_lock_irqsave(tw_dev->host->host_lock, flags); in tw_chrdev_ioctl()
1018 tw_dev->posted_request_count--; in tw_chrdev_ioctl()
1019 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_chrdev_ioctl()
1020 tw_state_request_finish(tw_dev, request_id); in tw_chrdev_ioctl()
1021 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in tw_chrdev_ioctl()
1034 …dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, … in tw_chrdev_ioctl()
1036 mutex_unlock(&tw_dev->ioctl_lock); in tw_chrdev_ioctl()
1066 static void tw_free_device_extension(TW_Device_Extension *tw_dev) in tw_free_device_extension() argument
1071 if (tw_dev->command_packet_virtual_address[0]) in tw_free_device_extension()
1072 …pci_free_consistent(tw_dev->tw_pci_dev, sizeof(TW_Command)*TW_Q_LENGTH, tw_dev->command_packet_vir… in tw_free_device_extension()
1074 if (tw_dev->alignment_virtual_address[0]) in tw_free_device_extension()
1075 …pci_free_consistent(tw_dev->tw_pci_dev, sizeof(TW_Sector)*TW_Q_LENGTH, tw_dev->alignment_virtual_a… in tw_free_device_extension()
1079 static int tw_initconnection(TW_Device_Extension *tw_dev, int message_credits) in tw_initconnection() argument
1089 if (tw_dev->command_packet_virtual_address[request_id] == NULL) { in tw_initconnection()
1094 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_initconnection()
1103 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_initconnection()
1111 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); in tw_initconnection()
1114 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) { in tw_initconnection()
1115 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); in tw_initconnection()
1125 tw_decode_sense(tw_dev, request_id, 0); in tw_initconnection()
1133 static int tw_setfeature(TW_Device_Extension *tw_dev, int parm, int param_size, in tw_setfeature() argument
1144 if (tw_dev->command_packet_virtual_address[request_id] == NULL) { in tw_setfeature()
1148 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_setfeature()
1150 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_setfeature()
1158 param_value = tw_dev->alignment_physical_address[request_id]; in tw_setfeature()
1161 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_setfeature()
1162 tw_state_request_finish(tw_dev, request_id); in tw_setfeature()
1163 tw_dev->srb[request_id]->result = (DID_OK << 16); in tw_setfeature()
1164 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]); in tw_setfeature()
1173 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_setfeature()
1180 outl(command_que_value, TW_COMMAND_QUEUE_REG_ADDR(tw_dev)); in tw_setfeature()
1183 if (tw_poll_status_gone(tw_dev, TW_STATUS_RESPONSE_QUEUE_EMPTY, 30) == 0) { in tw_setfeature()
1184 response_queue.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); in tw_setfeature()
1194 tw_decode_sense(tw_dev, request_id, 0); in tw_setfeature()
1203 static int tw_reset_sequence(TW_Device_Extension *tw_dev) in tw_reset_sequence() argument
1211 TW_SOFT_RESET(tw_dev); in tw_reset_sequence()
1213 error = tw_aen_drain_queue(tw_dev); in tw_reset_sequence()
1215 printk(KERN_WARNING "3w-xxxx: scsi%d: AEN drain failed, retrying.\n", tw_dev->host->host_no); in tw_reset_sequence()
1221 if (tw_check_errors(tw_dev)) { in tw_reset_sequence()
1222 …printk(KERN_WARNING "3w-xxxx: scsi%d: Controller errors found, retrying.\n", tw_dev->host->host_no… in tw_reset_sequence()
1232 …xxx: scsi%d: Controller errors, card not responding, check all cabling.\n", tw_dev->host->host_no); in tw_reset_sequence()
1236 error = tw_initconnection(tw_dev, TW_INIT_MESSAGE_CREDITS); in tw_reset_sequence()
1238 …printk(KERN_WARNING "3w-xxxx: scsi%d: Connection initialization failed.\n", tw_dev->host->host_no); in tw_reset_sequence()
1242 error = tw_setfeature(tw_dev, 2, 1, &c); in tw_reset_sequence()
1251 static int tw_initialize_device_extension(TW_Device_Extension *tw_dev) in tw_initialize_device_extension() argument
1258 error = tw_allocate_memory(tw_dev, sizeof(TW_Command), 0); in tw_initialize_device_extension()
1265 error = tw_allocate_memory(tw_dev, sizeof(TW_Sector), 1); in tw_initialize_device_extension()
1272 tw_dev->free_queue[i] = i; in tw_initialize_device_extension()
1273 tw_dev->state[i] = TW_S_INITIAL; in tw_initialize_device_extension()
1276 tw_dev->pending_head = TW_Q_START; in tw_initialize_device_extension()
1277 tw_dev->pending_tail = TW_Q_START; in tw_initialize_device_extension()
1278 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in tw_initialize_device_extension()
1280 mutex_init(&tw_dev->ioctl_lock); in tw_initialize_device_extension()
1281 init_waitqueue_head(&tw_dev->ioctl_wqueue); in tw_initialize_device_extension()
1313 static int tw_reset_device_extension(TW_Device_Extension *tw_dev) in tw_reset_device_extension() argument
1321 set_bit(TW_IN_RESET, &tw_dev->flags); in tw_reset_device_extension()
1322 TW_DISABLE_INTERRUPTS(tw_dev); in tw_reset_device_extension()
1323 TW_MASK_COMMAND_INTERRUPT(tw_dev); in tw_reset_device_extension()
1324 spin_lock_irqsave(tw_dev->host->host_lock, flags); in tw_reset_device_extension()
1328 if ((tw_dev->state[i] != TW_S_FINISHED) && in tw_reset_device_extension()
1329 (tw_dev->state[i] != TW_S_INITIAL) && in tw_reset_device_extension()
1330 (tw_dev->state[i] != TW_S_COMPLETED)) { in tw_reset_device_extension()
1331 srb = tw_dev->srb[i]; in tw_reset_device_extension()
1334 tw_dev->srb[i]->scsi_done(tw_dev->srb[i]); in tw_reset_device_extension()
1335 tw_unmap_scsi_data(tw_dev->tw_pci_dev, tw_dev->srb[i]); in tw_reset_device_extension()
1342 tw_dev->free_queue[i] = i; in tw_reset_device_extension()
1343 tw_dev->state[i] = TW_S_INITIAL; in tw_reset_device_extension()
1345 tw_dev->free_head = TW_Q_START; in tw_reset_device_extension()
1346 tw_dev->free_tail = TW_Q_START; in tw_reset_device_extension()
1347 tw_dev->posted_request_count = 0; in tw_reset_device_extension()
1348 tw_dev->pending_request_count = 0; in tw_reset_device_extension()
1349 tw_dev->pending_head = TW_Q_START; in tw_reset_device_extension()
1350 tw_dev->pending_tail = TW_Q_START; in tw_reset_device_extension()
1351 tw_dev->reset_print = 0; in tw_reset_device_extension()
1353 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in tw_reset_device_extension()
1355 if (tw_reset_sequence(tw_dev)) { in tw_reset_device_extension()
1356 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset sequence failed.\n", tw_dev->host->host_no); in tw_reset_device_extension()
1360 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev); in tw_reset_device_extension()
1361 clear_bit(TW_IN_RESET, &tw_dev->flags); in tw_reset_device_extension()
1362 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in tw_reset_device_extension()
1372 TW_Device_Extension *tw_dev; in tw_scsi_biosparam() local
1375 tw_dev = (TW_Device_Extension *)sdev->host->hostdata; in tw_scsi_biosparam()
1398 TW_Device_Extension *tw_dev=NULL; in tw_scsi_eh_reset() local
1401 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in tw_scsi_eh_reset()
1403 tw_dev->num_resets++; in tw_scsi_eh_reset()
1410 mutex_lock(&tw_dev->ioctl_lock); in tw_scsi_eh_reset()
1413 if (tw_reset_device_extension(tw_dev)) { in tw_scsi_eh_reset()
1414 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset failed.\n", tw_dev->host->host_no); in tw_scsi_eh_reset()
1420 mutex_unlock(&tw_dev->ioctl_lock); in tw_scsi_eh_reset()
1425 static int tw_scsiop_inquiry(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_inquiry() argument
1435 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_scsiop_inquiry()
1449 if (tw_dev->alignment_virtual_address[request_id] == NULL) { in tw_scsiop_inquiry()
1453 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_inquiry()
1458 param_value = tw_dev->alignment_physical_address[request_id]; in tw_scsiop_inquiry()
1466 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_scsiop_inquiry()
1473 tw_post_command_packet(tw_dev, request_id); in tw_scsiop_inquiry()
1478 static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id, in tw_transfer_internal() argument
1481 scsi_sg_copy_from_buffer(tw_dev->srb[request_id], data, len); in tw_transfer_internal()
1485 static int tw_scsiop_inquiry_complete(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_inquiry_complete() argument
1499 sprintf(&request_buffer[16], "Logical Disk %-2d ", tw_dev->srb[request_id]->device->id); in tw_scsiop_inquiry_complete()
1501 tw_transfer_internal(tw_dev, request_id, request_buffer, in tw_scsiop_inquiry_complete()
1504 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_inquiry_complete()
1511 if (is_unit_present[tw_dev->srb[request_id]->device->id] & TW_UNIT_ONLINE) { in tw_scsiop_inquiry_complete()
1512 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 1; in tw_scsiop_inquiry_complete()
1514 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 0; in tw_scsiop_inquiry_complete()
1515 tw_dev->srb[request_id]->result = (DID_BAD_TARGET << 16); in tw_scsiop_inquiry_complete()
1523 static int tw_scsiop_mode_sense(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_mode_sense() argument
1533 if (tw_dev->srb[request_id]->cmnd[2] != 0x8) { in tw_scsiop_mode_sense()
1534 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_scsiop_mode_sense()
1535 tw_state_request_finish(tw_dev, request_id); in tw_scsiop_mode_sense()
1536 tw_dev->srb[request_id]->result = (DID_OK << 16); in tw_scsiop_mode_sense()
1537 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]); in tw_scsiop_mode_sense()
1542 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_scsiop_mode_sense()
1558 if (tw_dev->alignment_virtual_address[request_id] == NULL) { in tw_scsiop_mode_sense()
1563 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_mode_sense()
1565 param->table_id = TW_UNIT_INFORMATION_TABLE_BASE + tw_dev->srb[request_id]->device->id; in tw_scsiop_mode_sense()
1568 param_value = tw_dev->alignment_physical_address[request_id]; in tw_scsiop_mode_sense()
1576 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_scsiop_mode_sense()
1583 tw_post_command_packet(tw_dev, request_id); in tw_scsiop_mode_sense()
1589 static int tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_mode_sense_complete() argument
1597 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_mode_sense_complete()
1615 tw_transfer_internal(tw_dev, request_id, request_buffer, in tw_scsiop_mode_sense_complete()
1622 static int tw_scsiop_read_capacity(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_read_capacity() argument
1632 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_scsiop_read_capacity()
1642 command_packet->unit__hostid = TW_UNITHOST_IN(0, tw_dev->srb[request_id]->device->id); in tw_scsiop_read_capacity()
1648 if (tw_dev->alignment_virtual_address[request_id] == NULL) { in tw_scsiop_read_capacity()
1652 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_read_capacity()
1655 tw_dev->srb[request_id]->device->id; in tw_scsiop_read_capacity()
1658 param_value = tw_dev->alignment_physical_address[request_id]; in tw_scsiop_read_capacity()
1666 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_scsiop_read_capacity()
1673 tw_post_command_packet(tw_dev, request_id); in tw_scsiop_read_capacity()
1679 static int tw_scsiop_read_capacity_complete(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_read_capacity_complete() argument
1689 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_read_capacity_complete()
1716 tw_transfer_internal(tw_dev, request_id, buff, sizeof(buff)); in tw_scsiop_read_capacity_complete()
1722 static int tw_scsiop_read_write(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_read_write() argument
1733 srb = tw_dev->srb[request_id]; in tw_scsiop_read_write()
1742 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_scsiop_read_write()
1774 tw_dev->sector_count = num_sectors; in tw_scsiop_read_write()
1775 if (tw_dev->sector_count > tw_dev->max_sector_count) in tw_scsiop_read_write()
1776 tw_dev->max_sector_count = tw_dev->sector_count; in tw_scsiop_read_write()
1782 use_sg = tw_map_scsi_sg_data(tw_dev->tw_pci_dev, tw_dev->srb[request_id]); in tw_scsiop_read_write()
1786 scsi_for_each_sg(tw_dev->srb[request_id], sg, use_sg, i) { in tw_scsiop_read_write()
1793 tw_dev->sgl_entries = scsi_sg_count(tw_dev->srb[request_id]); in tw_scsiop_read_write()
1794 if (tw_dev->sgl_entries > tw_dev->max_sgl_entries) in tw_scsiop_read_write()
1795 tw_dev->max_sgl_entries = tw_dev->sgl_entries; in tw_scsiop_read_write()
1797 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_scsiop_read_write()
1804 tw_post_command_packet(tw_dev, request_id); in tw_scsiop_read_write()
1810 static int tw_scsiop_request_sense(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_request_sense() argument
1820 tw_transfer_internal(tw_dev, request_id, request_buffer, in tw_scsiop_request_sense()
1823 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_scsiop_request_sense()
1824 tw_state_request_finish(tw_dev, request_id); in tw_scsiop_request_sense()
1827 tw_dev->srb[request_id]->result = (DID_ERROR << 16); in tw_scsiop_request_sense()
1828 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]); in tw_scsiop_request_sense()
1834 static int tw_scsiop_synchronize_cache(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_synchronize_cache() argument
1842 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_scsiop_synchronize_cache()
1853 command_packet->unit__hostid = TW_UNITHOST_IN(0, tw_dev->srb[request_id]->device->id); in tw_scsiop_synchronize_cache()
1857 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_scsiop_synchronize_cache()
1864 tw_post_command_packet(tw_dev, request_id); in tw_scsiop_synchronize_cache()
1870 static int tw_scsiop_test_unit_ready(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_test_unit_ready() argument
1880 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in tw_scsiop_test_unit_ready()
1894 if (tw_dev->alignment_virtual_address[request_id] == NULL) { in tw_scsiop_test_unit_ready()
1898 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_test_unit_ready()
1903 param_value = tw_dev->alignment_physical_address[request_id]; in tw_scsiop_test_unit_ready()
1911 command_que_value = tw_dev->command_packet_physical_address[request_id]; in tw_scsiop_test_unit_ready()
1918 tw_post_command_packet(tw_dev, request_id); in tw_scsiop_test_unit_ready()
1924 static int tw_scsiop_test_unit_ready_complete(TW_Device_Extension *tw_dev, int request_id) in tw_scsiop_test_unit_ready_complete() argument
1931 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; in tw_scsiop_test_unit_ready_complete()
1938 if (is_unit_present[tw_dev->srb[request_id]->device->id] & TW_UNIT_ONLINE) { in tw_scsiop_test_unit_ready_complete()
1939 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 1; in tw_scsiop_test_unit_ready_complete()
1941 tw_dev->is_unit_present[tw_dev->srb[request_id]->device->id] = 0; in tw_scsiop_test_unit_ready_complete()
1942 tw_dev->srb[request_id]->result = (DID_BAD_TARGET << 16); in tw_scsiop_test_unit_ready_complete()
1955 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in tw_scsi_queue_lck() local
1958 if (test_bit(TW_IN_RESET, &tw_dev->flags)) in tw_scsi_queue_lck()
1965 tw_state_request_start(tw_dev, &request_id); in tw_scsi_queue_lck()
1968 tw_dev->srb[request_id] = SCpnt; in tw_scsi_queue_lck()
1979 retval = tw_scsiop_read_write(tw_dev, request_id); in tw_scsi_queue_lck()
1983 retval = tw_scsiop_test_unit_ready(tw_dev, request_id); in tw_scsi_queue_lck()
1987 retval = tw_scsiop_inquiry(tw_dev, request_id); in tw_scsi_queue_lck()
1991 retval = tw_scsiop_read_capacity(tw_dev, request_id); in tw_scsi_queue_lck()
1995 retval = tw_scsiop_request_sense(tw_dev, request_id); in tw_scsi_queue_lck()
1999 retval = tw_scsiop_mode_sense(tw_dev, request_id); in tw_scsi_queue_lck()
2003 retval = tw_scsiop_synchronize_cache(tw_dev, request_id); in tw_scsi_queue_lck()
2009 …printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command… in tw_scsi_queue_lck()
2010 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_scsi_queue_lck()
2011 tw_state_request_finish(tw_dev, request_id); in tw_scsi_queue_lck()
2017 tw_dev->state[request_id] = TW_S_COMPLETED; in tw_scsi_queue_lck()
2018 tw_state_request_finish(tw_dev, request_id); in tw_scsi_queue_lck()
2033 TW_Device_Extension *tw_dev = (TW_Device_Extension *)dev_instance; in DEF_SCSI_QCMD() local
2040 spin_lock(tw_dev->host->host_lock); in DEF_SCSI_QCMD()
2043 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in DEF_SCSI_QCMD()
2052 if (test_bit(TW_IN_RESET, &tw_dev->flags)) in DEF_SCSI_QCMD()
2058 if (tw_decode_bits(tw_dev, status_reg_value, 1)) { in DEF_SCSI_QCMD()
2059 TW_CLEAR_ALL_INTERRUPTS(tw_dev); in DEF_SCSI_QCMD()
2067 TW_CLEAR_HOST_INTERRUPT(tw_dev); in DEF_SCSI_QCMD()
2073 TW_CLEAR_ATTENTION_INTERRUPT(tw_dev); in DEF_SCSI_QCMD()
2074 tw_state_request_start(tw_dev, &request_id); in DEF_SCSI_QCMD()
2075 error = tw_aen_read_queue(tw_dev, request_id); in DEF_SCSI_QCMD()
2077 printk(KERN_WARNING "3w-xxxx: scsi%d: Error reading aen queue.\n", tw_dev->host->host_no); in DEF_SCSI_QCMD()
2078 tw_dev->state[request_id] = TW_S_COMPLETED; in DEF_SCSI_QCMD()
2079 tw_state_request_finish(tw_dev, request_id); in DEF_SCSI_QCMD()
2086 while (tw_dev->pending_request_count > 0) { in DEF_SCSI_QCMD()
2087 request_id = tw_dev->pending_queue[tw_dev->pending_head]; in DEF_SCSI_QCMD()
2088 if (tw_dev->state[request_id] != TW_S_PENDING) { in DEF_SCSI_QCMD()
2089 …printk(KERN_WARNING "3w-xxxx: scsi%d: Found request id that wasn't pending.\n", tw_dev->host->host… in DEF_SCSI_QCMD()
2092 if (tw_post_command_packet(tw_dev, request_id)==0) { in DEF_SCSI_QCMD()
2093 if (tw_dev->pending_head == TW_Q_LENGTH-1) { in DEF_SCSI_QCMD()
2094 tw_dev->pending_head = TW_Q_START; in DEF_SCSI_QCMD()
2096 tw_dev->pending_head = tw_dev->pending_head + 1; in DEF_SCSI_QCMD()
2098 tw_dev->pending_request_count--; in DEF_SCSI_QCMD()
2105 if (tw_dev->pending_request_count == 0) in DEF_SCSI_QCMD()
2106 TW_MASK_COMMAND_INTERRUPT(tw_dev); in DEF_SCSI_QCMD()
2114 response_que.value = inl(TW_RESPONSE_QUEUE_REG_ADDR(tw_dev)); in DEF_SCSI_QCMD()
2116 command_packet = (TW_Command *)tw_dev->command_packet_virtual_address[request_id]; in DEF_SCSI_QCMD()
2122 if (tw_dev->srb[request_id] == NULL) { in DEF_SCSI_QCMD()
2123 tw_decode_sense(tw_dev, request_id, 0); in DEF_SCSI_QCMD()
2125 error = tw_decode_sense(tw_dev, request_id, 1); in DEF_SCSI_QCMD()
2130 if (tw_dev->state[request_id] != TW_S_POSTED) { in DEF_SCSI_QCMD()
2131 if (tw_dev->srb[request_id] != NULL) { in DEF_SCSI_QCMD()
2132 …printk(KERN_WARNING "3w-xxxx: scsi%d: Received a request id that wasn't posted.\n", tw_dev->host->… in DEF_SCSI_QCMD()
2140 if (tw_dev->srb[request_id] == NULL) { in DEF_SCSI_QCMD()
2143 if (request_id != tw_dev->chrdev_request_id) { in DEF_SCSI_QCMD()
2144 retval = tw_aen_complete(tw_dev, request_id); in DEF_SCSI_QCMD()
2146 printk(KERN_WARNING "3w-xxxx: scsi%d: Error completing aen.\n", tw_dev->host->host_no); in DEF_SCSI_QCMD()
2149 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in DEF_SCSI_QCMD()
2150 wake_up(&tw_dev->ioctl_wqueue); in DEF_SCSI_QCMD()
2153 switch (tw_dev->srb[request_id]->cmnd[0]) { in DEF_SCSI_QCMD()
2164 error = tw_scsiop_test_unit_ready_complete(tw_dev, request_id); in DEF_SCSI_QCMD()
2168 error = tw_scsiop_inquiry_complete(tw_dev, request_id); in DEF_SCSI_QCMD()
2172 error = tw_scsiop_read_capacity_complete(tw_dev, request_id); in DEF_SCSI_QCMD()
2176 error = tw_scsiop_mode_sense_complete(tw_dev, request_id); in DEF_SCSI_QCMD()
2188 tw_dev->srb[request_id]->result = (DID_OK << 16); in DEF_SCSI_QCMD()
2194 tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); in DEF_SCSI_QCMD()
2199 tw_dev->state[request_id] = TW_S_COMPLETED; in DEF_SCSI_QCMD()
2200 tw_state_request_finish(tw_dev, request_id); in DEF_SCSI_QCMD()
2201 tw_dev->posted_request_count--; in DEF_SCSI_QCMD()
2202 tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]); in DEF_SCSI_QCMD()
2204 tw_unmap_scsi_data(tw_dev->tw_pci_dev, tw_dev->srb[request_id]); in DEF_SCSI_QCMD()
2209 status_reg_value = inl(TW_STATUS_REG_ADDR(tw_dev)); in DEF_SCSI_QCMD()
2212 if (tw_decode_bits(tw_dev, status_reg_value, 1)) { in DEF_SCSI_QCMD()
2213 TW_CLEAR_ALL_INTERRUPTS(tw_dev); in DEF_SCSI_QCMD()
2221 spin_unlock(tw_dev->host->host_lock); in DEF_SCSI_QCMD()
2226 static void __tw_shutdown(TW_Device_Extension *tw_dev) in __tw_shutdown() argument
2229 TW_DISABLE_INTERRUPTS(tw_dev); in __tw_shutdown()
2232 free_irq(tw_dev->tw_pci_dev->irq, tw_dev); in __tw_shutdown()
2234 printk(KERN_WARNING "3w-xxxx: Shutting down host %d.\n", tw_dev->host->host_no); in __tw_shutdown()
2237 if (tw_initconnection(tw_dev, 1)) { in __tw_shutdown()
2244 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev); in __tw_shutdown()
2251 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in tw_shutdown() local
2253 __tw_shutdown(tw_dev); in tw_shutdown()
2287 TW_Device_Extension *tw_dev; in tw_probe() local
2310 tw_dev = (TW_Device_Extension *)host->hostdata; in tw_probe()
2313 tw_dev->host = host; in tw_probe()
2314 tw_dev->tw_pci_dev = pdev; in tw_probe()
2316 if (tw_initialize_device_extension(tw_dev)) { in tw_probe()
2329 tw_dev->base_addr = pci_resource_start(pdev, 0); in tw_probe()
2330 if (!tw_dev->base_addr) { in tw_probe()
2336 TW_DISABLE_INTERRUPTS(tw_dev); in tw_probe()
2339 if (tw_reset_sequence(tw_dev)) in tw_probe()
2359 …d: Found a 3ware Storage Controller at 0x%x, IRQ: %d.\n", host->host_no, tw_dev->base_addr, pdev->… in tw_probe()
2362 retval = request_irq(pdev->irq, tw_interrupt, IRQF_SHARED, "3w-xxxx", tw_dev); in tw_probe()
2368 tw_device_extension_list[tw_device_extension_count] = tw_dev; in tw_probe()
2372 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev); in tw_probe()
2388 tw_free_device_extension(tw_dev); in tw_probe()
2400 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in tw_remove() local
2402 scsi_remove_host(tw_dev->host); in tw_remove()
2411 __tw_shutdown(tw_dev); in tw_remove()
2417 tw_free_device_extension(tw_dev); in tw_remove()
2419 scsi_host_put(tw_dev->host); in tw_remove()