/* -*- linux-c -*- * Copyright (c) 2004-2006 Winbond Electronics Corp. All rights reserved. * * The contents of this file are subject to the Open * Software License version 1.1 that can be found at * http://www.opensource.org/licenses/osl-1.1.txt and is included herein * by reference. * * Alternatively, the contents of this file may be used under the terms * of the GNU General Public License version 2 (the "GPL") as distributed * in the kernel source COPYING file, in which case the provisions of * the GPL are applicable instead of the above. If you wish to allow * the use of your version of this file only under the terms of the * GPL and not to allow others to use your version of this file under * the OSL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the GPL. * If you do not delete the provisions above, a recipient may use your * version of this file under either the OSL or the GPL. * Maintained by: Weiming Shuai Jin Yuan Mu Dezheng Shen $Author: sjin $ $Id: wbscsi.h,v 1.5.2.5 2006/06/22 06:06:13 sjin Exp $ --- don't modify lines above --- Description: Enviornments: (1) RedHat 9 on 32-bit Intel UP/32-bit Intel dual-core (2) Fedora Core 4 (2.6.11) on 32-bit Intel/32-bit Intel dual-core/64-bit AMD/64-bit Intel dual-core (3) RedHat Enterprise Workstatin Rel 4 UP2 (2.6.9) on 32-bit Intel 32-bit Intel dual-core/64-bit AMD/64-bit Intel dual-core */ #ifndef _WB_SCSI_H_ #define _WB_SCSI_H_ #include "wbdebug.h" #include #include #include #include #include #include #include #include // for initializing the host #define WB_MAX_TARGETS 1 #define WB_MAX_LUNS 1 #define WB_MAX_SECTORS 64 #define WB_UNCHECKED_ISA_DMA 0 // don't make this larger than 8, possible values // are 0, 2, 4, 8 #define WB_SG_TABLE_SIZE 64 #define WB_LOGICAL_BLK_SIZE 512 // in bytes #define WB_CMD_RESULT( x, y, c ) (((x)<< 16 ) | ((y) << 8 ) | ((c) << 1) ) #define WB_COMPUTE_START_LBA(cmd) (((unsigned int)cmd->cmnd[2] << 24 ) + \ ((unsigned int)cmd->cmnd[3] << 16 ) + \ ((unsigned int)cmd->cmnd[4] << 8) + \ ((unsigned int)cmd->cmnd[5] )); #define WB_COMPUTE_NUM_BLK(cmd) (((unsigned short)cmd->cmnd[7] << 8 ) + \ ((unsigned short)cmd->cmnd[8] )) typedef struct scsi_cmnd Scsi_Cmnd; typedef struct scsi_host_template Scsi_Host_Template; typedef struct scsi_device Scsi_Device; // this wrapper is only used for SCSI read/write command typedef struct tag_wb_scsi_cmd_wrapper { struct tag_wb_scsi_cmd_wrapper *nextCmd; Scsi_Cmnd *cmd; } wb_scsi_cmd_wrapper_t; //Inquiry Data Format refer to INQUIRYDATA in src typedef struct tag_wb_scsi_inquiry_data { unsigned char dev_type; unsigned char dev_type_modifier:7; unsigned char removable_medium:1; unsigned char ver; unsigned char response_data_format; unsigned char additional_len; unsigned char reserved[2]; unsigned char soft_reset:1; unsigned char cmd_queue:1; unsigned char reserved2:1; unsigned char linked_cmds:1; unsigned char sync:1; unsigned char wide16b:1; unsigned char wide32b:1; unsigned char relative_addr:1; unsigned char vendor_id[8]; unsigned char prod_id[16]; unsigned char prod_rev_level[4]; } wb_scsi_inquiry_data_t; // Read Capacity Data Format typedef struct tag_wb_scsi_capacity { unsigned int lba; unsigned int len; } wb_scsi_capacity_t; // Sense Data Format - Mode Page Header typedef struct tag_wb_scsi_mode_page_header { unsigned char data_len; unsigned char medium_type; unsigned char dev_spec_param; unsigned char blk_desc_len; } __attribute__ ((packed)) wb_scsi_mode_page_header_t; typedef struct tag_wb_host_data_t { unsigned char medium_valid; unsigned char notice_upper_scsi_layer; #define WB_SYS_STATE_TEST ( 1 ) #define WB_SYS_STATE_RMMOD ( 1 << 1 ) #define WB_SYS_STATE_RMMOD_ACK ( 1 << 2 ) #define WB_SYS_STATE_QUEUE_CMD_OK ( 1 << 3 ) volatile unsigned int sys_state; wb_scsi_cmd_wrapper_t space_cmd_wrapper; wb_scsi_cmd_wrapper_t *cmd_wrapper; //help thread wait queue struct semaphore space_semaphore; struct semaphore *semaphore; // the extra 4096 handles w528 DMA bug char scratch[WB_SG_TABLE_SIZE * 512 + 4096]; } wb_host_data_t; static int __init wb_init_host_data(wb_host_data_t * host_data); static void wb_stop_helper_kernel_thread(wb_host_data_t * host_data); static void wb_copy_sgtable_to_scratch(Scsi_Cmnd * cmd, char *scratch); static void wb_copy_scratch_to_sgtable(char *scratch, Scsi_Cmnd * cmd); static void wb_make_sense_buffer(Scsi_Cmnd *, int, int, int); static void wb_chk_valid_medium(wb_host_data_t * hostData); static int wb_unit_ready(Scsi_Cmnd *); static int wb_helper_kernel_thread(void *param); static int wb_process_scsi_cmd(Scsi_Cmnd * cmd); // execute scsi cmd static void wb_scsi_test_unit_ready(Scsi_Cmnd *); static void wb_scsi_inquiry(Scsi_Cmnd *); static void wb_scsi_start_stop(Scsi_Cmnd *); static void wb_scsi_mode_sense(Scsi_Cmnd *); static void wb_scsi_read_capacity(Scsi_Cmnd *); static void wb_scsi_allow_medium_removal(Scsi_Cmnd *); static void wb_scsi_read_wrt(Scsi_Cmnd *, unsigned char readCmd); static void wb_scsi_request_sense(Scsi_Cmnd *); static void wb_scsi_format_unit(Scsi_Cmnd *); // entry functions static void *__init wb_detect(Scsi_Host_Template *); static int __exit wb_release(struct Scsi_Host *); //static int wb_ioctl(Scsi_Device *dev,int cmd,void *arg); static const char *wb_info(struct Scsi_Host *); static int wb_queue_cmd(Scsi_Cmnd *, void (*done) (Scsi_Cmnd *)); static int wb_eh_abort(Scsi_Cmnd *); static int wb_eh_reset(Scsi_Cmnd *); //FIXME, remember to copy this function from Chsun0's memory stick codes //static int wb_bios_param(Scsi_Device *,struct block_device *,sector_t, int[]); #define WB_DRIVER { \ info: wb_info, \ queuecommand: wb_queue_cmd, \ eh_abort_handler:wb_eh_abort, \ eh_host_reset_handler:wb_eh_reset, \ can_queue: 1, \ this_id: -1, \ sg_tablesize: WB_SG_TABLE_SIZE, \ cmd_per_lun: 1, \ present: 0, \ unchecked_isa_dma: WB_UNCHECKED_ISA_DMA, \ use_clustering: ENABLE_CLUSTERING, \ module: THIS_MODULE, \ } #endif /* _WB_SCSI_H_ */