| /* |
| * Copyright (C) 2018 Synaptics Incorporated. All rights reserved. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation. |
| * |
| * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND |
| * SYNAPTICS EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, |
| * INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| * A PARTICULAR PURPOSE, AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY |
| * INTELLECTUAL PROPERTY RIGHTS. IN NO EVENT SHALL SYNAPTICS BE LIABLE |
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR |
| * CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THE USE |
| * OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED AND |
| * BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS |
| * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF |
| * COMPETENT JURISDICTION DOES NOT PERMIT THE DISCLAIMER OF DIRECT |
| * DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' TOTAL CUMULATIVE LIABILITY |
| * TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. DOLLARS. |
| */ |
| #ifndef __usb_mass_ufi_h__ |
| #define __usb_mass_ufi_h__ |
| |
| #include "diag_common.h" |
| |
| /* a should be two byte number */ |
| #define HIGH_BYTE(a) ((a) >> 8) |
| #define LOW_BYTE(a) ((a) & 0xFF) |
| |
| /* Operation code for the UFI Commands (floppy drives) */ |
| #define UFI_FORMAT_UNIT (0x04) |
| #define FORMAT_LUN_HEADER_BITS (0x17) |
| #define UFI_READ_CAPACITY (0x25) |
| #define READ_CAPCITY_LUN_HEADER_BITS (0x00) |
| #define UFI_READ_FORMAT_CAPACITY (0x23) |
| #define UFI_INQUIRY (0x12) |
| #define INQUIRY_LUN_HEADER_BITS (0x00) |
| #define UFI_MODE_SELECT (0x55) |
| #define MODE_SELECT_LUN_HEADER_BITS (0x10) |
| #define UFI_MODE_SENSE (0x5A) |
| #define MODE_SENSE_LUN_HEADER_BITS (0x00) |
| #define PAGE_CURRENT_VALUE (0x00) |
| #define PAGE_CHANGEABLE_VALUE (0x01) |
| #define PAGE_DEFAULT_VALUE (0x10) |
| #define PAGE_SAVED_VALUE (0x11) |
| |
| #define PAGE_CODE_ALL_PAGES (0x3F) |
| |
| #define UFI_PREVENT_ALLOW_MEDIUM_ROMVAL (0x1E) |
| #define UFI_READ10 (0x28) |
| #define READ10_LUN_HEADER_BITS (0x00) |
| #define UFI_READ12 (0xA8) |
| #define READ12_LUN_HEADER_BITS (0x00) |
| #define UFI_REQUEST_SENSE (0x03) |
| #define UFI_REZERO_UNIT (0x01) |
| #define UFI_SEEK10 (0x2B) |
| #define UFI_SEND_DIAGNOSTIC (0x1D) |
| #define SEND_DIAG_LUN_HEADER_BITS (0x00) |
| #define UFI_START_STOP (0x1B) |
| #define UFI_STOP_MEDIA (0x00) |
| #define UFI_START_MEDIA_AND_GET_FORMAT (0x01) |
| |
| #define UFI_TEST_UNIT_READY (0x00) |
| #define UFI_VERIFY (0x2F) |
| #define VERIFY_LUN_HEADER_BITS (0x00) |
| |
| #define UFI_WRITE10 (0x2A) |
| #define UFI_WRITE_LUN_HEADER_BITS (0x00) |
| #define UFI_WRITE12 (0xAA) |
| #define UFI_WRITE_AND_VERIFY (0x2E) |
| |
| #define DEFAULT_INTERLEAVE (0x00) |
| |
| /* Mass storage defs*/ |
| /* Constants */ |
| #define MAX_CBWCB_SIZE 16 |
| #define CBW_DIRECTION_IN 0x80 |
| #define CBW_DIRECTION_OUT 0x00 |
| #define MAX_RETRIAL_ATTEMPTS 3 |
| #define QUEUE_SIZE 16 /* Must be a power of 2 */ |
| #define DIRECTION_OUT 0x00 |
| #define DIRECTION_IN 0x80 |
| #define MASK_NON_DIRECTION_BITS 0x80 |
| |
| /* Command Status Wrapper Signature 'USBS'*/ |
| #define CBW_SIGNATURE 0x43425355 |
| #define CSW_SIGNATURE 0x53425355 |
| #define CSW_STATUS_GOOD 0x00 |
| #define CSW_STATUS_FAILED 0x01 |
| #define CSW_STATUS_PHASE_ERROR 0x02 |
| |
| #define CSW_SIZE 0x0D |
| #define CBW_SIZE 0x1F |
| #define GET_MAX_LUN 0xFE |
| #define MASS_STORAGE_RESET 0xFF |
| |
| // Some util funcs |
| #define utou32(b,n) {b[0] = n&0x0ff; \ |
| b[1] = (n>>8)&0x0ff; \ |
| b[2] = (n>>16)&0x0ff; \ |
| b[3] = (n>>24)&0x0ff;} |
| |
| #define utou32swap(b,n) {b[3] = n&0x0ff; \ |
| b[2] = (n>>8)&0x0ff; \ |
| b[1] = (n>>16)&0x0ff; \ |
| b[0] = (n>>24)&0x0ff;} |
| |
| #define transfer_low_nibble(val, dest) {dest = (dest&0xf0) | (val&0x0f);} |
| |
| #define USB_MASS_SENSE { int res; \ |
| dbg_printf(PRN_RES,"\t--MODE SENSE.."); \ |
| res = usb_mass_ufi_request_sense((uchar_ptr)USB_MASS_SENSE_DATA_BASE, \ |
| sizeof(REQ_SENSE_DATA_FORMAT)); \ |
| RETURN_ON_ERROR(res); \ |
| dbg_printf(PRN_RES, "OK\n"); \ |
| } |
| |
| /* USB Mass storage FORMAT UNIT Command information */ |
| typedef struct _DEFECT_LIST_HEADER |
| { |
| uint_8 RESERVED1; |
| uint_8 BBIT_INFO_HEADER; |
| #define DEFAULT_BIT_INFO (0xA0) |
| uint_8 BLENGTH_MSB; |
| uint_8 BLENGTH_LSB; |
| #define DEFAULT_LENGTH_MSB (0x00) |
| #define DEFAULT_LENGTH_LSB (0x08) |
| } DEFECT_LIST_HEADER, _PTR_ DEFECT_LIST_HEADER_PTR; |
| |
| typedef struct _FORMAT_CAPACITY_DESCRIPTOR |
| { |
| uint_8 NNUM_BLOCKS[4]; |
| uint_8 RESERVED; |
| uint_8 NBLOCK_LENGTH[3]; |
| } FORMAT_CAPACITY_DESCRIPTOR, _PTR_ FORMAT_CAPACITY_DESCRIPTOR_PTR; |
| |
| typedef struct _FORMAT_UNIT_PARAMETER_BLOCK |
| { |
| DEFECT_LIST_HEADER DEF_LIST_HEADER; |
| FORMAT_CAPACITY_DESCRIPTOR FMT_CAPACITY_DESC; |
| } FORMAT_UNIT_PARAMETER_BLOCK, _PTR_ FORMAT_UNIT_PARAMETER_BLOCK_PTR; |
| |
| |
| /* USB Mass storage READ CAPACITY Command information */ |
| |
| /* USB Mass storage Read10 Command information */ |
| typedef struct _MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO |
| { |
| uint_8 BLLBA[4]; /* Last Logical Block Address */ |
| uint_8 BLENGTH[4]; /*Block length */ |
| } MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO, |
| _PTR_ MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO_PTR; |
| |
| |
| /* USB Mass storage READ FORMAT CAPACITY Command information */ |
| |
| typedef struct _CAPACITY_LIST_HEADER { |
| uint_8 RESERVED[3]; |
| uint_8 BLENGTH[1]; /* Capacity list length */ |
| } CAPACITY_LIST_HEADER,_PTR_ CAPACITY_LIST_HEADER_PTR; |
| |
| |
| typedef struct _CURRENT_CAPACITY_DESCRIPTOR { |
| uint_8 NNUM_BLOCKS[4]; |
| uint_8 BDESC_CODE; /* Only last two bits are used */ |
| #define UNFORMATTED_MEDIA (0x01) |
| #define FORMATTED_MEDIA (0x02) |
| #define NO_MEDIA (0x03) |
| uint_8 NBLOCK_LENGTH[3]; |
| } CURRENT_CAPACITY_DESCRIPTOR,_PTR_ CURRENT_CAPACITY_DESCRIPTOR_PTR; |
| |
| |
| typedef struct _CAPACITY_LIST { |
| CAPACITY_LIST_HEADER LIST_HEADER; /* 4 bytes */ |
| CURRENT_CAPACITY_DESCRIPTOR CAPACITY_DESCRIPTOR; /* 8 bytes */ |
| FORMAT_CAPACITY_DESCRIPTOR FMT_CAPACITY_DESC; /* 8 bytes */ |
| } CAPACITY_LIST, _PTR_ CAPACITY_LIST_PTR; |
| |
| |
| /* USB Mass storage INQUIRY Command information */ |
| |
| typedef struct _INQUIRY_DATA_FORMAT |
| { |
| /*device type currently connected to Logical Unit */ |
| uint_8 BDEVICE_TYPE; |
| #define DIRECT_ACCESS_DEVICE (0x00) |
| #define NONE (0x1F) |
| |
| /*removable media bit only bit 7 is used. rest reserved*/ |
| uint_8 BRMB; |
| |
| /*ISO, ECMA, ANSI Version bits*/ |
| uint_8 BVERSION_SPEC; |
| #define DEFAULT_VERSION_SPEC (0x00) |
| |
| /*Response data format */ |
| uint_8 BRESP_DATA_FORMAt; |
| #define DEFAULT_RESNPOSE_FORMAT (0x01) |
| |
| /* length of parameters */ |
| uint_8 BADITIONAL_LENGTH; |
| #define DEFAULT_LENGTH (0x1F) |
| |
| uint_8 RESERVED1; |
| uint_8 RESERVED2; |
| uint_8 RESERVED3; |
| |
| uint_8 BVID[8]; /* Vendor Identification String */ |
| uint_8 BPID[16]; /* Product Identification String */ |
| uint_8 BPRODUCT_REV[4]; /* Product revision level */ |
| |
| } INQUIRY_DATA_FORMAT, _PTR_ INQUIRY_DATA_FORMAT_PTR; |
| |
| |
| /* USB Mass storage MODE SELECT Command information */ |
| typedef union _READ_WRITE_RECOVERY_PAGE { |
| uint_8 FIELDS[12]; |
| } READ_WRITE_RECOVERY_PAGE, _PTR_ READ_WRITE_RECOVERY_PAGE_PTR; |
| |
| |
| typedef union _MODE_SELECT_PAGE { |
| READ_WRITE_RECOVERY_PAGE READ_WRITE_PAGE; |
| } MODE_SELECT_PAGE, _PTR_ MODE_SELECT_PAGE_PTR; |
| |
| typedef struct _MODE_PARAM_HEADER { |
| uint_8 BLENGTH[2]; /* Mode Data Length */ |
| uint_8 BMEDIA_TYPE; /* Media type code */ |
| #define DEFAULT_MEDIA_TYPE (0x00) |
| #define DD_720KB (0x1E) |
| #define HD_125MB (0x93) |
| #define DD_144MB (0x94) |
| uint_8 WP_DPOFUA; |
| #define WP_DPOFUA_HEADER (0xEF) |
| } MODE_PARAM_HEADER,_PTR_ MODE_PARAM_HEADER_PTR; |
| |
| |
| typedef struct _MODE_SELECT_PARAMETER_LIST { |
| MODE_PARAM_HEADER MODE_PARAM_HEADER; |
| #define DEFAULT_NO_OF_PAGES (0x01) |
| MODE_SELECT_PAGE PAGES[DEFAULT_NO_OF_PAGES]; |
| } MODE_SELECT_PARAMETER_LIST, _PTR_ MODE_SELECT_PARAMETER_LIST_PTR; |
| |
| |
| |
| /* USB Mass storage REQUEST SENSE Command information */ |
| |
| typedef struct _REQ_SENSE_DATA_FORMAT |
| { |
| /* Valid and Error code*/ |
| uint_8 BERROR_CODE; /* 0 */ |
| #define REQUEST_SENSE_NOT_VALID (0x00) |
| #define REQUEST_SENSE_IS_VALID (0x01) |
| #define REQUEST_SENSE_ERROR_CODE (0x70) |
| uint_8 RESERVED1; /* 1 */ |
| uint_8 BSENSE_KEY; /* 2 Only lower 4 bits are used */ |
| uint_8 BINFO[4]; /* 3,4,5,6 Information data format */ |
| uint_8 BADITIONAL_LENGTH; /* 7 additional sense length */ |
| uint_8 RESERVED2[4]; /* 8,9,10,11*/ |
| uint_8 BADITIONAL_CODE; /* 12 Additional sense code */ |
| uint_8 BADITIONAL_QUALIFIEr; /* 13 Additional sense code qualifier */ |
| uint_8 RESERVED3[4]; /* 14,15,16,17*/ |
| } REQ_SENSE_DATA_FORMAT, _PTR_ REQ_SENSE_DATA_FORMAT_PTR; |
| |
| |
| /* USB Mass storage WRITE10 Command information */ |
| typedef struct _MASS_STORAGE_WRITE10_CMD_STRUCT_INFO { |
| uint_8 BLBA[4]; |
| uint_8 BTRANSFER_LENGTH[2]; |
| } MASS_STORAGE_WRITE10_CMD_STRUCT_INFO, |
| _PTR_ MASS_STORAGE_WRITE10_CMD_STRUCT_INFO_PTR; |
| |
| |
| /* USB Mass storage WRITE12 Command information */ |
| typedef struct _MASS_STORAGE_WRITE12_CMD_STRUCT_INFO { |
| uint_8 BLBA[4]; |
| uint_8 BTRANSFER_LENGTH; |
| } MASS_STORAGE_WRITE12_CMD_STRUCT_INFO, |
| _PTR_ MASS_STORAGE_WRITE12_CMD_STRUCT_INFO_PTR; |
| |
| /* USB Mass storage SEEK10 Command information */ |
| typedef struct MASS_STORAGE_SEEK10_STRUCT_INFO { |
| uint_8 BLBA[4]; |
| } MASS_STORAGE_SEEK10_STRUCT_INFO, _PTR_ MASS_STORAGE_SEEK10_STRUCT_INFO_PTR; |
| |
| /* USB Mass storage SEND DIAGNOSTIC Command information */ |
| typedef struct _MASS_STORAGE_SEND_DIAGNOSTIC_STRUCT_INFO { |
| boolean SELF_TEST; |
| } MASS_STORAGE_SEND_DIAGNOSTIC_STRUCT_INFO, |
| _PTR_ MASS_STORAGE_SEND_DIAGNOSTIC_STRUCT_INFO_PTR; |
| |
| /* USB Mass storage START-STOP UNIT Command information */ |
| typedef struct _MASS_STORAGE_START_STOP_UNIT_STRUCT_INFO { |
| boolean START; |
| boolean LOEJ; |
| } MASS_STORAGE_START_STOP_UNIT_STRUCT_INFO, |
| _PTR_ MASS_STORAGE_START_STOP_UNIT_STRUCT_INFO_PTR; |
| |
| /* USB Mass storage VERIFY Command information */ |
| typedef struct _MASS_STORAGE_VERIFY_CMD_STRUCT_INFO { |
| uint_8 BLBA[4]; |
| uint_8 BTRANSFER_LENGTH[2]; |
| } MASS_STORAGE_VERIFY_CMD_STRUCT_INFO, |
| _PTR_ MASS_STORAGE_VERIFY_CMD_STRUCT_INFO_PTR; |
| |
| |
| /* UFI commands */ |
| |
| /* Used by host-side to send the READ CAPACITY command */ |
| #define usb_mass_ufi_read_capacity( \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_READ_CAPACITY, \ |
| (g_mass_lun << 5) | READ_CAPCITY_LUN_HEADER_BITS, \ |
| 0, \ |
| 0, \ |
| CBW_DIRECTION_IN, \ |
| buf_ptr, \ |
| buf_len) |
| |
| |
| /* Used by host-side to send the FORMAT UNIT command */ |
| #define usb_mass_ufi_format_unit( \ |
| /* [IN] Track number to be formatted (see UFI specs) */ \ |
| /* uint_8 */ track_num, \ |
| \ |
| /* [IN] Interleave number (see UFI specs) */ \ |
| /* uint_8 */ interleave, \ |
| \ |
| /* [IN] command specific parameters (see UFI specs) */ \ |
| /* FORMAT_UNIT_PARAMETER_BLOCK_PTR */ format_ptr \ |
| ) \ |
| \ |
| mass_ufi_generif( \ |
| UFI_FORMAT_UNIT, \ |
| (g_mass_lun << 5) | FORMAT_LUN_HEADER_BITS, \ |
| (track_num << 24) | (HIGH_BYTE(interleave) << 16) | \ |
| (LOW_BYTE(interleave) << 8), \ |
| format_ptr ? (sizeof(FORMAT_LUN_HEADER_BITS) << 8) : 0, \ |
| CBW_DIRECTION_OUT, \ |
| (uchar_ptr)format_ptr, \ |
| format_ptr ? (sizeof(FORMAT_LUN_HEADER_BITS) << 8) : 0) |
| |
| |
| /* Used by host-side to send the FORMAT CAPACITY command */ |
| #define usb_mass_ufi_format_capacity( \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len \ |
| ) \ |
| \ |
| mass_ufi_generif( \ |
| UFI_READ_FORMAT_CAPACITY, \ |
| g_mass_lun << 5, \ |
| 0, \ |
| 0, \ |
| CBW_DIRECTION_IN, \ |
| buf_ptr, \ |
| buf_len) |
| |
| |
| /* |
| ** Used by host-side to send the INQUIRY command, to request information |
| ** regarding parameters of the UFI device itself |
| */ |
| #define usb_mass_ufi_inquiry( \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_INQUIRY, \ |
| (g_mass_lun << 5) | INQUIRY_LUN_HEADER_BITS, \ |
| (buf_len & 0xFF) << 8, \ |
| 0, \ |
| CBW_DIRECTION_IN, \ |
| buf_ptr, \ |
| buf_len) |
| |
| |
| /* Used by host-side to send the MODE SELECT command */ |
| #define usb_mass_ufi_mode_select( \ |
| /* [IN] command specific parameters (see UFI specs) */ \ |
| /*MODE_SELECT_PARAMETER_LIST_PTR*/ pMode_select_param \ |
| ) \ |
| usb_mass_ufi_generic( \ |
| UFI_MODE_SELECT, \ |
| (g_mass_lun << 5) | MODE_SELECT_LUN_HEADER_BITS, \ |
| 0, \ |
| pMode_select_param ? (sizeof(MODE_SELECT_PARAMETER_LIST) << 8) : 0, \ |
| CBW_DIRECTION_OUT, \ |
| (uchar_ptr)pMode_select_param, \ |
| pMode_select_param ? (sizeof(MODE_SELECT_PARAMETER_LIST) << 8) : 0) |
| |
| |
| |
| /* Used by host-side to send the MODE SENSE command */ |
| #define usb_mass_ufi_mode_sense( \ |
| /*[IN] Page control byte 2 bits */ \ |
| /* uint_8 */ bPC, \ |
| \ |
| /*[IN] Page code 6 bit */ \ |
| /* uint_8 */ bPage_code, \ |
| \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_MODE_SENSE, \ |
| (g_mass_lun << 5) | MODE_SENSE_LUN_HEADER_BITS, \ |
| ((bPC << 6)|(bPage_code & 0x3F)) << 24, \ |
| buf_ptr ? (buf_len << 8) : 0, \ |
| CBW_DIRECTION_IN, \ |
| buf_ptr, \ |
| buf_ptr ? buf_len : 0) |
| |
| |
| /* Used by host-side to send the PREVENT-ALLOW MEDIUM REMOVAL command */ |
| #define usb_mass_ufi_prevent_allow_medium_removal( \ |
| /* [IN] command specific parameters (see UFI specs) */ \ |
| /* uint_8 */ bPrevent /*1 or 0 values */ \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_PREVENT_ALLOW_MEDIUM_ROMVAL, \ |
| g_mass_lun << 5, \ |
| (bPrevent & 0x01) << 8, \ |
| 0, \ |
| CBW_DIRECTION_OUT, \ |
| NULL, \ |
| 0) |
| |
| |
| /* Used by host-side to send the READ(10) command, to get data from device */ |
| #define usb_mass_ufi_read_10( \ |
| /* [IN] Address of the block to be read */ \ |
| /* uint_32 */ bBlock_address, \ |
| \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len, \ |
| \ |
| /* [IN] the number of sectors to read */ \ |
| /* uint_32 */ num_of_sectors \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_READ10, \ |
| (g_mass_lun << 5) | READ10_LUN_HEADER_BITS, \ |
| bBlock_address, \ |
| num_of_sectors << 8, \ |
| CBW_DIRECTION_IN, \ |
| buf_ptr, \ |
| buf_len) |
| |
| |
| /* Used by host-side to send the READ(12) command, to get data from device */ |
| #define usb_mass_ufi_read_12( \ |
| /* [IN] Address of the block to be read */ \ |
| /* uint_32 */ bBlock_address, \ |
| \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len, \ |
| \ |
| /* [IN] number of sectors to read */ \ |
| /* uint_32 */ num_of_sectors \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_READ12, \ |
| (g_mass_lun << 5) | READ12_LUN_HEADER_BITS, \ |
| bBlock_address, \ |
| num_of_sectors, \ |
| CBW_DIRECTION_IN, \ |
| buf_ptr, \ |
| buf_len) |
| |
| |
| /* Used by host-side to send the REQUEST SENSE command */ |
| #define usb_mass_ufi_request_sense( \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len \ |
| ) \ |
| usb_mass_ufi_generic( \ |
| UFI_REQUEST_SENSE, \ |
| (g_mass_lun << 5), \ |
| (buf_len & 0xFF) << 8, \ |
| 0, \ |
| CBW_DIRECTION_IN, \ |
| (uchar_ptr)buf_ptr, \ |
| buf_len) |
| |
| |
| /* Used by host-side to send the REZERO UNIT command */ |
| #define usb_mass_ufi_rezero_unit( \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_REZERO_UNIT, \ |
| (g_mass_lun << 5), \ |
| 0, \ |
| 0, \ |
| CBW_DIRECTION_OUT, \ |
| NULL, \ |
| 0) |
| |
| |
| /* Used by host-side to send the SEEK command */ |
| #define usb_mass_ufi_seek_10( \ |
| /* [IN] block address (see UFI specs) */ \ |
| /* uint_32 */ bBlock_address \ |
| ) \ |
| usb_mass_ufi_generic( \ |
| UFI_SEEK10, \ |
| g_mass_lun << 5, \ |
| bBlock_address, \ |
| 0, \ |
| CBW_DIRECTION_OUT, \ |
| NULL, \ |
| 0) |
| |
| |
| /* Used by host-side to send the SEND DIAGNOSTIC command */ |
| #define usb_mass_ufi_send_diagnostic( \ |
| /* [IN] command specific parameters (see UFI specs) */ \ |
| /* uint_8 */ bSelf_test \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_SEND_DIAGNOSTIC, \ |
| ((g_mass_lun << 5) | SEND_DIAG_LUN_HEADER_BITS) | \ |
| ((bSelf_test & 0xFF) << 2), \ |
| 0, \ |
| 0, \ |
| CBW_DIRECTION_OUT, \ |
| NULL, \ |
| 0) |
| |
| |
| /* Used by host-side to send the START-STOP command */ |
| #define usb_mass_ufi_start_stop( \ |
| \ |
| /* Load Object Bit */ \ |
| /* uint_8 */ bLoej, \ |
| \ |
| /* Start Stop bit */ \ |
| /* uint_8 */ bStart \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_START_STOP, \ |
| (g_mass_lun << 5) | SEND_DIAG_LUN_HEADER_BITS, \ |
| (((bLoej << 1) | bStart) & 0x3) << 8, \ |
| 0, \ |
| CBW_DIRECTION_OUT, \ |
| NULL, \ |
| 0) |
| |
| |
| /* Used by host-side to send the TEST UNIT READY command */ |
| #define usb_mass_ufi_test_unit_ready( \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_TEST_UNIT_READY, \ |
| (g_mass_lun << 5), \ |
| 0, \ |
| 0, \ |
| CBW_DIRECTION_OUT, \ |
| NULL, \ |
| 0) |
| |
| |
| /* Used by host-side to send the VERIFY command */ |
| #define usb_mass_ufi_verify( \ |
| /* [IN] address of the block to verify */ \ |
| /* uint_32 */ bBlock_address, \ |
| \ |
| /* Length of the data to verify */ \ |
| /*uint_16 */ dLength \ |
| ) \ |
| \ |
| mass_ufi_generif( \ |
| UFI_VERIFY, \ |
| (g_mass_lun << 5) | VERIFY_LUN_HEADER_BITS, \ |
| bBlock_address, \ |
| dLength << 8, \ |
| CBW_DIRECTION_OUT, \ |
| NULL, \ |
| 0) |
| |
| |
| /* Used by host-side to send the WRITE(10) command, to send data to device */ |
| #define usb_mass_ufi_write_10( \ |
| /* [IN] Address of the block to be read */ \ |
| /* uint_32 */ bBlock_address, \ |
| \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len, \ |
| \ |
| /* [IN] number of sectors to write */ \ |
| /* uint_32 */ num_of_sectors \ |
| ) \ |
| \ |
| usb_mass_ufi_generic( \ |
| UFI_WRITE10, \ |
| (g_mass_lun << 5) | UFI_WRITE_LUN_HEADER_BITS, \ |
| bBlock_address, \ |
| num_of_sectors << 8, \ |
| CBW_DIRECTION_OUT, \ |
| buf_ptr, \ |
| buf_len) |
| |
| |
| /* Used by host-side to send the WRITE(12) command, to send data to device */ |
| #define usb_mass_ufi_write_12( \ |
| /* [IN] Address of the block to be read */ \ |
| /* uint_32 */ bBlock_address, \ |
| \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len, \ |
| \ |
| /* [IN] the number of sectors to write */ \ |
| /* uint_32 */ num_of_sectors \ |
| ) \ |
| \ |
| mass_ufi_generif( \ |
| UFI_WRITE12, \ |
| (g_mass_lun << 5) | UFI_WRITE_LUN_HEADER_BITS, \ |
| bBlock_address, \ |
| num_of_sectors, \ |
| CBW_DIRECTION_OUT, \ |
| buf_ptr, \ |
| buf_len); |
| |
| |
| /* Used by host-side to send the WRITE AND VERIFY command */ |
| #define usb_mass_ufi_write_and_verify( \ |
| /* [IN] Address of the block to be read */ \ |
| /* uint_32 */ bBlock_address, \ |
| \ |
| /* [IN] buffer to send or receive data*/ \ |
| /* pointer */ buf_ptr, \ |
| \ |
| /* [IN] length of the expected data */ \ |
| /* uint_32 */ buf_len, \ |
| \ |
| /* [IN] the number of sectors */ \ |
| /* uint_32 */ num_of_sectors \ |
| ) \ |
| \ |
| mass_ufi_generif( \ |
| UFI_WRITE_AND_VERIFY, \ |
| (g_mass_lun << 5) | UFI_WRITE_LUN_HEADER_BITS, \ |
| bBlock_address, \ |
| num_of_sectors << 8, \ |
| CBW_DIRECTION_OUT, \ |
| buf_ptr, \ |
| buf_len); |
| |
| |
| /* Prototypes */ |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| |
| extern int usb_mass_ufi_generic |
| ( |
| /* [IN] command object allocated by application*/ |
| // COMMAND_OBJECT_PTR cmd_ptr, |
| uint_8 opcode, |
| uint_8 lun, |
| uint_32 lbaddr, |
| uint_32 blen, |
| |
| uint_8 cbwflags, |
| |
| uchar_ptr buf, |
| uint_32 buf_len |
| ); |
| |
| |
| |
| |
| #ifdef __cplusplus |
| } |
| #endif |
| |
| |
| |
| #endif |
| |
| /* EOF */ |