Lines Matching +full:host +full:- +full:command

2    3w-sas.c -- LSI 3ware SAS/SATA-RAID Controller device driver for Linux.
20 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
39 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
43 LSI 3ware 9750 6Gb/s SAS/SATA-RAID
49 -------
50 3.26.02.000 - Initial driver release.
72 #include "3w-sas.h"
79 static int twl_major = -1;
84 MODULE_DESCRIPTION ("LSI 3ware SAS/SATA-RAID Linux Driver");
104 TW_Device_Extension *tw_dev = (TW_Device_Extension *)shost->hostdata; in twl_sysfs_aen_read()
109 return -EACCES; in twl_sysfs_aen_read()
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()
140 return -EACCES; in twl_sysfs_compat_info()
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()
163 struct Scsi_Host *host = class_to_shost(dev); in twl_show_stats() local
164 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_show_stats()
168 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_show_stats()
169 len = sysfs_emit(buf, "3w-sas Driver version: %s\n" in twl_show_stats()
176 "SCSI Host Resets: %4d\n" 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()
200 /* Host attributes initializer */
228 char host[16]; in twl_aen_queue_event() local
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()
236 host[0] = '\0'; 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()
240 aen = le16_to_cpu(header->status_block.error); in twl_aen_queue_event()
243 event->severity = TW_SEV_OUT(header->status_block.severity__reserved); in twl_aen_queue_event()
244 /* event->time_stamp_sec overflows in y2106 */ in twl_aen_queue_event()
245 local_time = (u32)(ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60)); in twl_aen_queue_event()
246 event->time_stamp_sec = local_time; in twl_aen_queue_event()
247 event->aen_code = aen; in twl_aen_queue_event()
248 event->retrieved = TW_AEN_NOT_RETRIEVED; 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()
253 error_str = &(header->err_specific_desc[strlen(header->err_specific_desc)+1]); in twl_aen_queue_event()
255 header->err_specific_desc[sizeof(header->err_specific_desc) - 1] = '\0'; in twl_aen_queue_event()
256 event->parameter_len = strlen(header->err_specific_desc); in twl_aen_queue_event()
257 …memcpy(event->parameter_data, header->err_specific_desc, event->parameter_len + 1 + strlen(error_s… in twl_aen_queue_event()
258 if (event->severity != TW_AEN_SEVERITY_DEBUG) in twl_aen_queue_event()
259 printk(KERN_WARNING "3w-sas:%s AEN: %s (0x%02X:0x%04X): %s:%s.\n", in twl_aen_queue_event()
260 host, in twl_aen_queue_event()
261 twl_aen_severity_lookup(TW_SEV_OUT(header->status_block.severity__reserved)), in twl_aen_queue_event()
263 header->err_specific_desc); 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()
270 /* This function will attempt to post a command packet to the board */
275 command_que_value = tw_dev->command_packet_phys[request_id]; 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()
303 if (tw_dev->srb[request_id]) in twl_scsiop_execute_scsi()
304 srb = tw_dev->srb[request_id]; in twl_scsiop_execute_scsi()
306 /* Initialize command packet */ in twl_scsiop_execute_scsi()
307 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_scsiop_execute_scsi()
308 full_command_packet->header.header_desc.size_header = 128; in twl_scsiop_execute_scsi()
309 full_command_packet->header.status_block.error = 0; in twl_scsiop_execute_scsi()
310 full_command_packet->header.status_block.severity__reserved = 0; in twl_scsiop_execute_scsi()
312 command_packet = &full_command_packet->command.newcommand; in twl_scsiop_execute_scsi()
313 command_packet->status = 0; in twl_scsiop_execute_scsi()
314 command_packet->opcode__reserved = TW_OPRES_IN(0, TW_OP_EXECUTE_SCSI); in twl_scsiop_execute_scsi()
318 memcpy(command_packet->cdb, srb->cmnd, TW_MAX_CDB_LEN); in twl_scsiop_execute_scsi()
320 memcpy(command_packet->cdb, cdb, TW_MAX_CDB_LEN); in twl_scsiop_execute_scsi()
323 command_packet->unit = srb->device->id; in twl_scsiop_execute_scsi()
324 command_packet->request_id__lunl = in twl_scsiop_execute_scsi()
325 cpu_to_le16(TW_REQ_LUN_IN(srb->device->lun, request_id)); in twl_scsiop_execute_scsi()
327 command_packet->request_id__lunl = in twl_scsiop_execute_scsi()
329 command_packet->unit = 0; in twl_scsiop_execute_scsi()
332 command_packet->sgl_offset = 16; in twl_scsiop_execute_scsi()
342 command_packet->sg_list[i].address = TW_CPU_TO_SGL(sg_dma_address(sg)); in twl_scsiop_execute_scsi()
343 command_packet->sg_list[i].length = TW_CPU_TO_SGL(sg_dma_len(sg)); in twl_scsiop_execute_scsi()
345 …command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_cou… in twl_scsiop_execute_scsi()
350 command_packet->sg_list[i].address = TW_CPU_TO_SGL(sglistarg[i].address); in twl_scsiop_execute_scsi()
351 command_packet->sg_list[i].length = TW_CPU_TO_SGL(sglistarg[i].length); in twl_scsiop_execute_scsi()
353 command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN(0, use_sg)); 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()
366 /* Now post the command to the board */ in twl_scsiop_execute_scsi()
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()
394 /* Mark internal command */ in twl_aen_read_queue()
395 tw_dev->srb[request_id] = NULL; in twl_aen_read_queue()
397 /* Now post the command packet */ 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()
407 /* This function will sync firmware time with the host time */
416 /* Fill out the command packet */ in twl_aen_sync_time()
417 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_sync_time()
419 command_packet = &full_command_packet->command.oldcommand; in twl_aen_sync_time()
420 command_packet->opcode__sgloffset = TW_OPSGL_IN(2, TW_OP_SET_PARAM); in twl_aen_sync_time()
421 command_packet->request_id = 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()
423 command_packet->byte8_offset.param.sgl[0].length = TW_CPU_TO_SGL(TW_SECTOR_SIZE); in twl_aen_sync_time()
424 command_packet->size = TW_COMMAND_SIZE; in twl_aen_sync_time()
425 command_packet->byte6_offset.parameter_count = cpu_to_le16(1); in twl_aen_sync_time()
428 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; in twl_aen_sync_time()
430 param->table_id = cpu_to_le16(TW_TIMEKEEP_TABLE | 0x8000); /* Controller time keep table */ in twl_aen_sync_time()
431 param->parameter_id = cpu_to_le16(0x3); /* SchedulerTime */ in twl_aen_sync_time()
432 param->parameter_size_bytes = cpu_to_le16(4); in twl_aen_sync_time()
436 local_time = (ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60)); in twl_aen_sync_time()
437 div_u64_rem(local_time - (3 * 86400), 604800, &schedulertime); in twl_aen_sync_time()
440 memcpy(param->data, &schedulertime, sizeof(u32)); in twl_aen_sync_time()
442 /* Mark internal command */ in twl_aen_sync_time()
443 tw_dev->srb[request_id] = NULL; in twl_aen_sync_time()
445 /* Now post the command */ in twl_aen_sync_time()
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()
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()
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()
476 aen = le16_to_cpu(header->status_block.error); in twl_aen_complete()
477 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_aen_complete()
478 command_packet = &full_command_packet->command.oldcommand; in twl_aen_complete()
481 if (TW_OP_OUT(command_packet->opcode__sgloffset) == TW_OP_SET_PARAM) { in twl_aen_complete()
512 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_aen_complete()
514 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); in twl_aen_complete()
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()
584 /* Mark internal command */ in twl_aen_drain_queue()
585 tw_dev->srb[request_id] = NULL; in twl_aen_drain_queue()
588 /* Send command to the board */ in twl_aen_drain_queue()
590 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x3, "Error posting request sense"); 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()
603 aen = le16_to_cpu(header->status_block.error); in twl_aen_drain_queue()
636 tw_dev->state[request_id] = TW_S_INITIAL; in twl_aen_drain_queue()
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()
688 if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) { in twl_load_sgl()
689 newcommand = &full_command_packet->command.newcommand; in twl_load_sgl()
690 newcommand->request_id__lunl = in twl_load_sgl()
691 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id)); in twl_load_sgl()
693 newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache)); in twl_load_sgl()
694 newcommand->sg_list[0].length = TW_CPU_TO_SGL(length); in twl_load_sgl()
696 newcommand->sgl_entries__lunh = in twl_load_sgl()
697 cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->sgl_entries__lunh), length ? 1 : 0)); in twl_load_sgl()
699 oldcommand = &full_command_packet->command.oldcommand; in twl_load_sgl()
700 oldcommand->request_id = request_id; in twl_load_sgl()
702 if (TW_SGL_OUT(oldcommand->opcode__sgloffset)) { in twl_load_sgl()
704 …sgl = (TW_SG_Entry_ISO *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry_ISO)/4) + pae +… in twl_load_sgl()
705 sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache)); in twl_load_sgl()
706 sgl->length = TW_CPU_TO_SGL(length); in twl_load_sgl()
707 oldcommand->size += pae; in twl_load_sgl()
708 oldcommand->size += sizeof(dma_addr_t) > 4 ? 1 : 0; in twl_load_sgl()
726 int retval = -EFAULT; in twl_chrdev_ioctl()
732 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { in twl_chrdev_ioctl()
733 retval = -EINTR; in twl_chrdev_ioctl()
737 /* First copy down the driver command */ in twl_chrdev_ioctl()
743 retval = -EINVAL; in twl_chrdev_ioctl()
751 …cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_Io… in twl_chrdev_ioctl()
753 retval = -ENOMEM; in twl_chrdev_ioctl()
766 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
769 /* Flag internal command */ 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()
775 full_command_packet = (TW_Command_Full *)&tw_ioctl->firmware_command; in twl_chrdev_ioctl()
777 /* Load request id and sglist for both command types */ 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()
782 /* Now post the command packet to the controller */ in twl_chrdev_ioctl()
784 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
788 /* Now wait for command to complete */ 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()
794 …printk(KERN_WARNING "3w-sas: scsi%d: WARNING: (0x%02X:0x%04X): Character ioctl (0x%x) timed out, r… in twl_chrdev_ioctl()
795 tw_dev->host->host_no, TW_DRIVER, 0x6, in twl_chrdev_ioctl()
797 retval = -EIO; in twl_chrdev_ioctl()
802 /* Now copy in the command packet response */ 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()
810 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_chrdev_ioctl()
813 retval = -ENOTTY; in twl_chrdev_ioctl()
822 …dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_Ioctl_Buf_Apac… in twl_chrdev_ioctl()
824 mutex_unlock(&tw_dev->ioctl_lock); in twl_chrdev_ioctl()
834 int retval = -ENODEV; in twl_chrdev_open()
837 retval = -EACCES; in twl_chrdev_open()
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()
870 error_str = &(header->err_specific_desc[strlen(header->err_specific_desc) + 1]); in twl_fill_sense()
873 error = le16_to_cpu(header->status_block.error); in twl_fill_sense()
876 printk(KERN_WARNING "3w-sas: scsi%d: ERROR: (0x%02X:0x%04X): %s:%s.\n", in twl_fill_sense()
877 tw_dev->host->host_no, in twl_fill_sense()
879 header->status_block.error, in twl_fill_sense()
881 header->err_specific_desc); in twl_fill_sense()
883 printk(KERN_WARNING "3w-sas: ERROR: (0x%02X:0x%04X): %s:%s.\n", in twl_fill_sense()
885 header->status_block.error, in twl_fill_sense()
887 header->err_specific_desc); 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()
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()
932 /* Setup the command packet */ in twl_get_param()
933 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_get_param()
935 command_packet = &full_command_packet->command.oldcommand; in twl_get_param()
937 command_packet->opcode__sgloffset = TW_OPSGL_IN(2, TW_OP_GET_PARAM); in twl_get_param()
938 command_packet->size = TW_COMMAND_SIZE; in twl_get_param()
939 command_packet->request_id = request_id; in twl_get_param()
940 command_packet->byte6_offset.block_count = cpu_to_le16(1); in twl_get_param()
943 param = (TW_Param_Apache *)tw_dev->generic_buffer_virt[request_id]; in twl_get_param()
945 param->table_id = cpu_to_le16(table_id | 0x8000); in twl_get_param()
946 param->parameter_id = cpu_to_le16(parameter_id); in twl_get_param()
947 param->parameter_size_bytes = cpu_to_le16(parameter_size_bytes); 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()
950 command_packet->byte8_offset.param.sgl[0].length = TW_CPU_TO_SGL(TW_SECTOR_SIZE); in twl_get_param()
952 /* Post the command packet to the board */ in twl_get_param()
957 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x7, "No valid response during get param") in twl_get_param()
959 retval = (void *)&(param->data[0]); 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()
967 /* This function will send an initconnection command to controller */
983 /* Initialize InitConnection command packet */ in twl_initconnection()
984 full_command_packet = tw_dev->command_packet_virt[request_id]; in twl_initconnection()
986 full_command_packet->header.header_desc.size_header = 128; in twl_initconnection()
988 tw_initconnect = (TW_Initconnect *)&full_command_packet->command.oldcommand; in twl_initconnection()
989 tw_initconnect->opcode__reserved = TW_OPRES_IN(0, TW_OP_INIT_CONNECTION); in twl_initconnection()
990 tw_initconnect->request_id = request_id; in twl_initconnection()
991 tw_initconnect->message_credits = cpu_to_le16(message_credits); in twl_initconnection()
992 tw_initconnect->features = set_features; in twl_initconnection()
994 /* Turn on 64-bit sgl support if we need to */ in twl_initconnection()
995 tw_initconnect->features |= sizeof(dma_addr_t) > 4 ? 1 : 0; in twl_initconnection()
997 tw_initconnect->features = cpu_to_le32(tw_initconnect->features); in twl_initconnection()
1000 tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE_EXTENDED; in twl_initconnection()
1001 tw_initconnect->fw_srl = cpu_to_le16(current_fw_srl); in twl_initconnection()
1002 tw_initconnect->fw_arch_id = cpu_to_le16(current_fw_arch_id); in twl_initconnection()
1003 tw_initconnect->fw_branch = cpu_to_le16(current_fw_branch); in twl_initconnection()
1004 tw_initconnect->fw_build = cpu_to_le16(current_fw_build); in twl_initconnection()
1006 tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE; in twl_initconnection()
1008 /* Send command packet to the board */ in twl_initconnection()
1013 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x8, "No valid response during init connection"); in twl_initconnection()
1016 *fw_on_ctlr_srl = le16_to_cpu(tw_initconnect->fw_srl); in twl_initconnection()
1017 *fw_on_ctlr_arch_id = le16_to_cpu(tw_initconnect->fw_arch_id); in twl_initconnection()
1018 *fw_on_ctlr_branch = le16_to_cpu(tw_initconnect->fw_branch); in twl_initconnection()
1019 *fw_on_ctlr_build = le16_to_cpu(tw_initconnect->fw_build); in twl_initconnection()
1020 *init_connect_result = le32_to_cpu(tw_initconnect->result); in twl_initconnection()
1025 tw_dev->posted_request_count--; in twl_initconnection()
1026 tw_dev->state[request_id] = TW_S_INITIAL; in twl_initconnection()
1036 /* Initialize command packet buffers */ in twl_initialize_device_extension()
1038 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x9, "Command packet memory allocation failed"); in twl_initialize_device_extension()
1044 TW_PRINTK(tw_dev->host, TW_DRIVER, 0xa, "Generic memory allocation failed"); 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()
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()
1100 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_handle_attention_interrupt()
1102 clear_bit(TW_IN_ATTENTION_LOOP, &tw_dev->flags); in twl_handle_attention_interrupt()
1128 spin_lock(tw_dev->host->host_lock); in twl_interrupt()
1130 /* Read host interrupt status */ in twl_interrupt()
1140 if (test_bit(TW_IN_RESET, &tw_dev->flags)) in twl_interrupt()
1163 /* Check for command packet error */ 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()
1172 if (request_id != tw_dev->chrdev_request_id) 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()
1178 /* Now re-post the sense buffer */ 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()
1198 /* Check for internal command completion */ 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()
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()
1211 cmd->result = (DID_OK << 16); in twl_interrupt()
1214 if ((scsi_sg_count(cmd) <= 1) && (full_command_packet->command.newcommand.status == 0)) { in twl_interrupt()
1215 …if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_i… in twl_interrupt()
1216 …scsi_set_resid(cmd, scsi_bufflen(cmd) - full_command_packet->command.newcommand.sg_list[0].length); in twl_interrupt()
1222 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_interrupt()
1224 tw_dev->posted_request_count--; in twl_interrupt()
1232 spin_unlock(tw_dev->host->host_lock); in twl_interrupt()
1276 … TW_PRINTK(tw_dev->host, TW_DRIVER, 0x10, "Controller never went non-ready during reset sequence"); in twl_reset_sequence()
1281 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x11, "Controller not ready during reset sequence"); 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()
1305 /* Check status for over-run after each write */ in twl_reset_sequence()
1314 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x13, "Bad controller status after loading sense buffers"); in twl_reset_sequence()
1322 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x14, "AEN drain failed during reset sequence"); in twl_reset_sequence()
1329 strscpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, in twl_reset_sequence()
1330 sizeof(tw_dev->tw_compat_info.driver_version)); in twl_reset_sequence()
1331 tw_dev->tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL; in twl_reset_sequence()
1332 tw_dev->tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH; in twl_reset_sequence()
1333 tw_dev->tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD; in twl_reset_sequence()
1334 tw_dev->tw_compat_info.driver_srl_low = TW_BASE_FW_SRL; in twl_reset_sequence()
1335 tw_dev->tw_compat_info.driver_branch_low = TW_BASE_FW_BRANCH; in twl_reset_sequence()
1336 tw_dev->tw_compat_info.driver_build_low = TW_BASE_FW_BUILD; in twl_reset_sequence()
1337 tw_dev->tw_compat_info.fw_on_ctlr_srl = fw_on_ctlr_srl; in twl_reset_sequence()
1338 tw_dev->tw_compat_info.fw_on_ctlr_branch = fw_on_ctlr_branch; in twl_reset_sequence()
1339 tw_dev->tw_compat_info.fw_on_ctlr_build = fw_on_ctlr_build; in twl_reset_sequence()
1357 scsi_block_requests(tw_dev->host); in twl_reset_device_extension()
1359 set_bit(TW_IN_RESET, &tw_dev->flags); in twl_reset_device_extension()
1363 spin_lock_irqsave(tw_dev->host->host_lock, flags); in twl_reset_device_extension()
1367 if ((tw_dev->state[i] != TW_S_FINISHED) && in twl_reset_device_extension()
1368 (tw_dev->state[i] != TW_S_INITIAL) && in twl_reset_device_extension()
1369 (tw_dev->state[i] != TW_S_COMPLETED)) { in twl_reset_device_extension()
1370 struct scsi_cmnd *cmd = tw_dev->srb[i]; in twl_reset_device_extension()
1373 cmd->result = (DID_RESET << 16); in twl_reset_device_extension()
1382 tw_dev->free_queue[i] = i; in twl_reset_device_extension()
1383 tw_dev->state[i] = TW_S_INITIAL; in twl_reset_device_extension()
1385 tw_dev->free_head = TW_Q_START; in twl_reset_device_extension()
1386 tw_dev->free_tail = TW_Q_START; in twl_reset_device_extension()
1387 tw_dev->posted_request_count = 0; in twl_reset_device_extension()
1389 spin_unlock_irqrestore(tw_dev->host->host_lock, flags); in twl_reset_device_extension()
1396 clear_bit(TW_IN_RESET, &tw_dev->flags); in twl_reset_device_extension()
1397 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE; in twl_reset_device_extension()
1402 scsi_unblock_requests(tw_dev->host); in twl_reset_device_extension()
1432 tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in twl_scsi_eh_reset()
1434 tw_dev->num_resets++; in twl_scsi_eh_reset()
1436 sdev_printk(KERN_WARNING, SCpnt->device, in twl_scsi_eh_reset()
1437 "WARNING: (0x%02X:0x%04X): Command (0x%x) timed out, resetting card.\n", in twl_scsi_eh_reset()
1438 TW_DRIVER, 0x2c, SCpnt->cmnd[0]); in twl_scsi_eh_reset()
1441 mutex_lock(&tw_dev->ioctl_lock); in twl_scsi_eh_reset()
1445 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x15, "Controller reset failed during scsi host reset"); in twl_scsi_eh_reset()
1451 mutex_unlock(&tw_dev->ioctl_lock); in twl_scsi_eh_reset()
1460 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; in twl_scsi_queue_lck()
1463 if (test_bit(TW_IN_RESET, &tw_dev->flags)) { in twl_scsi_queue_lck()
1471 /* Save the scsi command for use by the ISR */ in twl_scsi_queue_lck()
1472 tw_dev->srb[request_id] = SCpnt; in twl_scsi_queue_lck()
1476 tw_dev->state[request_id] = TW_S_COMPLETED; in twl_scsi_queue_lck()
1478 SCpnt->result = (DID_ERROR << 16); in twl_scsi_queue_lck()
1495 free_irq(tw_dev->tw_pci_dev->irq, tw_dev); in DEF_SCSI_QCMD()
1497 printk(KERN_WARNING "3w-sas: Shutting down host %d.\n", tw_dev->host->host_no); in DEF_SCSI_QCMD()
1501 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x16, "Connection shutdown failed"); in DEF_SCSI_QCMD()
1503 printk(KERN_WARNING "3w-sas: Shutdown complete.\n"); in DEF_SCSI_QCMD()
1513 struct Scsi_Host *host = pci_get_drvdata(pdev); in twl_shutdown() local
1516 if (!host) in twl_shutdown()
1519 tw_dev = (TW_Device_Extension *)host->hostdata; in twl_shutdown()
1521 if (tw_dev->online) in twl_shutdown()
1525 /* This function configures unit settings when a unit is coming on-line */
1529 blk_queue_rq_timeout(sdev->request_queue, 60 * HZ); in twl_slave_configure()
1536 .name = "3w-sas",
1541 .can_queue = TW_Q_LENGTH-2,
1543 .this_id = -1,
1555 struct Scsi_Host *host = NULL; in twl_probe() local
1557 int retval = -ENODEV; in twl_probe()
1562 TW_PRINTK(host, TW_DRIVER, 0x17, "Failed to enable pci device"); in twl_probe()
1569 retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in twl_probe()
1571 TW_PRINTK(host, TW_DRIVER, 0x18, "Failed to set dma mask"); in twl_probe()
1572 retval = -ENODEV; in twl_probe()
1576 host = scsi_host_alloc(&driver_template, sizeof(TW_Device_Extension)); in twl_probe()
1577 if (!host) { in twl_probe()
1578 TW_PRINTK(host, TW_DRIVER, 0x19, "Failed to allocate memory for device extension"); in twl_probe()
1579 retval = -ENOMEM; in twl_probe()
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()
1589 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1a, "Failed to initialize device extension"); in twl_probe()
1590 retval = -ENOMEM; in twl_probe()
1595 retval = pci_request_regions(pdev, "3w-sas"); 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()
1605 retval = -ENOMEM; in twl_probe()
1614 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1d, "Controller reset failed during probe"); in twl_probe()
1615 retval = -ENOMEM; in twl_probe()
1619 /* Set host specific parameters */ in twl_probe()
1620 host->max_id = TW_MAX_UNITS; in twl_probe()
1621 host->max_cmd_len = TW_MAX_CDB_LEN; in twl_probe()
1622 host->max_lun = TW_MAX_LUNS; in twl_probe()
1623 host->max_channel = 0; in twl_probe()
1626 retval = scsi_add_host(host, &pdev->dev); in twl_probe()
1628 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1e, "scsi add host failed"); in twl_probe()
1632 pci_set_drvdata(pdev, host); in twl_probe()
1634 printk(KERN_WARNING "3w-sas: scsi%d: Found an LSI 3ware %s Controller at 0x%llx, IRQ: %d.\n", in twl_probe()
1635 host->host_no, in twl_probe()
1638 (u64)pci_resource_start(pdev, 1), pdev->irq); in twl_probe()
1645 printk(KERN_WARNING "3w-sas: scsi%d: Firmware %s, BIOS %s, Phys: %d.\n", in twl_probe()
1646 host->host_no, 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()
1667 /* Re-enable interrupts on the card */ in twl_probe()
1670 /* Finally, scan the host */ in twl_probe()
1671 scsi_scan_host(host); in twl_probe()
1674 if (sysfs_create_bin_file(&host->shost_dev.kobj, &twl_sysfs_aen_read_attr)) in twl_probe()
1675 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x20, "Failed to create sysfs binary file: 3ware_aen_read"); in twl_probe()
1676 if (sysfs_create_bin_file(&host->shost_dev.kobj, &twl_sysfs_compat_info_attr)) in twl_probe()
1677 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x21, "Failed to create sysfs binary file: 3ware_compat_info"); in twl_probe()
1679 if (twl_major == -1) { in twl_probe()
1681 TW_PRINTK(host, TW_DRIVER, 0x22, "Failed to register character device"); in twl_probe()
1683 tw_dev->online = 1; in twl_probe()
1687 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_probe()
1689 scsi_remove_host(host); in twl_probe()
1691 iounmap(tw_dev->base_addr); in twl_probe()
1696 scsi_host_put(host); in twl_probe()
1706 struct Scsi_Host *host = pci_get_drvdata(pdev); in twl_remove() local
1709 if (!host) in twl_remove()
1712 tw_dev = (TW_Device_Extension *)host->hostdata; in twl_remove()
1714 if (!tw_dev->online) in twl_remove()
1718 sysfs_remove_bin_file(&host->shost_dev.kobj, &twl_sysfs_aen_read_attr); in twl_remove()
1719 sysfs_remove_bin_file(&host->shost_dev.kobj, &twl_sysfs_compat_info_attr); in twl_remove()
1721 scsi_remove_host(tw_dev->host); in twl_remove()
1726 twl_major = -1; 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()
1745 scsi_host_put(tw_dev->host); in twl_remove()
1747 twl_device_extension_count--; in twl_remove()
1753 struct Scsi_Host *host = dev_get_drvdata(dev); in twl_suspend() local
1754 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_suspend()
1756 printk(KERN_WARNING "3w-sas: Suspending host %d.\n", tw_dev->host->host_no); in twl_suspend()
1760 free_irq(tw_dev->tw_pci_dev->irq, tw_dev); in twl_suspend()
1764 TW_PRINTK(tw_dev->host, TW_DRIVER, 0x23, "Connection shutdown failed during suspend"); in twl_suspend()
1766 printk(KERN_WARNING "3w-sas: Suspend complete.\n"); in twl_suspend()
1780 struct Scsi_Host *host = pci_get_drvdata(pdev); in twl_resume() local
1781 TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata; in twl_resume()
1783 printk(KERN_WARNING "3w-sas: Resuming host %d.\n", tw_dev->host->host_no); in twl_resume()
1786 retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in twl_resume()
1788 TW_PRINTK(host, TW_DRIVER, 0x25, "Failed to set dma mask during resume"); in twl_resume()
1789 retval = -ENODEV; in twl_resume()
1795 retval = -ENODEV; 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()
1803 retval = -ENODEV; in twl_resume()
1808 if (test_bit(TW_USING_MSI, &tw_dev->flags)) in twl_resume()
1811 /* Re-enable interrupts on the card */ in twl_resume()
1814 printk(KERN_WARNING "3w-sas: Resume complete.\n"); in twl_resume()
1818 scsi_remove_host(host); in twl_resume()
1834 .name = "3w-sas",
1845 …printk(KERN_INFO "LSI 3ware SAS/SATA-RAID Controller device driver for Linux v%s.\n", TW_DRIVER_VE… in twl_init()