1 /*!
2     \file    usbh_msc_scsi.h
3     \brief   header file for usbh_msc_scsi.c
4 
5     \version 2020-08-04, V1.1.0, firmware for GD32VF103
6 */
7 
8 /*
9     Copyright (c) 2020, GigaDevice Semiconductor Inc.
10 
11     Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
13 
14     1. Redistributions of source code must retain the above copyright notice, this
15        list of conditions and the following disclaimer.
16     2. Redistributions in binary form must reproduce the above copyright notice,
17        this list of conditions and the following disclaimer in the documentation
18        and/or other materials provided with the distribution.
19     3. Neither the name of the copyright holder nor the names of its contributors
20        may be used to endorse or promote products derived from this software without
21        specific prior written permission.
22 
23     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 OF SUCH DAMAGE.
33 */
34 
35 #ifndef __USBH_MSC_SCSI_H
36 #define __USBH_MSC_SCSI_H
37 
38 #include "msc_scsi.h"
39 #include "usbh_enum.h"
40 
41 /* capacity data */
42 typedef struct
43 {
44     uint32_t block_nbr;
45     uint16_t block_size;
46 } scsi_capacity;
47 
48 /* inquiry data */
49 typedef struct
50 {
51     uint8_t peripheral_qualifier;
52     uint8_t device_type;
53     uint8_t removable_media;
54     uint8_t vendor_id[9];
55     uint8_t product_id[17];
56     uint8_t revision_id[5];
57 } scsi_std_inquiry_data;
58 
59 typedef struct
60 {
61     uint32_t msc_capacity;
62     uint32_t msc_sense_key;
63     uint16_t msc_page_len;
64     uint8_t msc_write_protect;
65 }usbh_msc_parameter;
66 
67 #define DESC_REQUEST_SENSE                   0x00U
68 #define ALLOCATION_LENGTH_REQUEST_SENSE      63U
69 #define XFER_LEN_MODE_SENSE6                 63U
70 
71 #define MASK_MODE_SENSE_WRITE_PROTECT        0x80U
72 #define MODE_SENSE_PAGE_CONTROL_FIELD        0x00U
73 #define MODE_SENSE_PAGE_CODE                 0x3FU
74 #define DISK_WRITE_PROTECTED                 0x01U
75 
76 /* function declarations */
77 /* send 'Inquiry' command to the device */
78 usbh_status usbh_msc_scsi_inquiry (usbh_host *puhost, uint8_t lun, scsi_std_inquiry_data *inquiry);
79 /* send 'Test unit ready' command to the device */
80 usbh_status usbh_msc_test_unitready (usbh_host *puhost, uint8_t lun);
81 /* send the read capacity command to the device */
82 usbh_status usbh_msc_read_capacity10 (usbh_host *puhost, uint8_t lun, scsi_capacity *capacity);
83 /* send the mode sense6 command to the device */
84 usbh_status usbh_msc_mode_sense6 (usbh_host *puhost, uint8_t lun);
85 /* send the Request Sense command to the device */
86 usbh_status usbh_msc_request_sense (usbh_host *puhost, uint8_t lun, msc_scsi_sense *sense_data);
87 /* send the write10 command to the device */
88 usbh_status usbh_msc_write10 (usbh_host *puhost,
89                               uint8_t lun,
90                               uint8_t *data_buf,
91                               uint32_t addr,
92                               uint32_t byte_num);
93 /* send the read10 command to the device */
94 usbh_status usbh_msc_read10 (usbh_host *puhost,
95                              uint8_t lun,
96                              uint8_t *data_buf,
97                              uint32_t addr,
98                              uint32_t byte_num);
99 
100 #endif /* __USBH_MSC_SCSI_H */
101