1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** USBX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** Storage Class */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
/* Include necessary system files. */ |
24 |
|
|
|
25 |
|
|
#define UX_SOURCE_CODE |
26 |
|
|
|
27 |
|
|
#include "ux_api.h" |
28 |
|
|
#include "ux_host_class_storage.h" |
29 |
|
|
#include "ux_host_stack.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _ux_host_class_storage_media_recovery_sense_get PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function will send a MODE_SENSE command to recover from a read */ |
45 |
|
|
/* and write error. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* storage Pointer to storage class */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* Completion Status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _ux_host_class_storage_cbw_initialize Initialize CBW */ |
58 |
|
|
/* _ux_host_class_storage_transport Send command */ |
59 |
|
|
/* _ux_utility_memory_allocate Allocate memory block */ |
60 |
|
|
/* _ux_utility_memory_free Release memory block */ |
61 |
|
|
/* _ux_utility_short_put_big_endian Put short value */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* Storage Class */ |
66 |
|
|
/* */ |
67 |
|
|
/* RELEASE HISTORY */ |
68 |
|
|
/* */ |
69 |
|
|
/* DATE NAME DESCRIPTION */ |
70 |
|
|
/* */ |
71 |
|
|
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ |
72 |
|
|
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ |
73 |
|
|
/* resulting in version 6.1 */ |
74 |
|
|
/* */ |
75 |
|
|
/**************************************************************************/ |
76 |
|
4 |
UINT _ux_host_class_storage_media_recovery_sense_get(UX_HOST_CLASS_STORAGE *storage) |
77 |
|
|
{ |
78 |
|
|
|
79 |
|
|
UINT status; |
80 |
|
|
UCHAR *cbw; |
81 |
|
|
UCHAR *mode_sense_response; |
82 |
|
|
UINT command_length; |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
/* Use a pointer for the cbw, easier to manipulate. */ |
86 |
|
4 |
cbw = (UCHAR *) storage -> ux_host_class_storage_cbw; |
87 |
|
|
|
88 |
|
|
/* Get the Write Command Length. */ |
89 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
90 |
|
|
if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass == UX_HOST_CLASS_STORAGE_SUBCLASS_UFI) |
91 |
|
|
command_length = UX_HOST_CLASS_STORAGE_MODE_SENSE_COMMAND_LENGTH_UFI; |
92 |
|
|
else |
93 |
|
|
command_length = UX_HOST_CLASS_STORAGE_MODE_SENSE_COMMAND_LENGTH_SBC; |
94 |
|
|
#else |
95 |
|
4 |
command_length = UX_HOST_CLASS_STORAGE_MODE_SENSE_COMMAND_LENGTH_SBC; |
96 |
|
|
#endif |
97 |
|
|
|
98 |
|
|
/* Initialize the CBW for this command. */ |
99 |
|
4 |
_ux_host_class_storage_cbw_initialize(storage, UX_HOST_CLASS_STORAGE_DATA_IN, UX_HOST_CLASS_STORAGE_MODE_SENSE_TP_PAGE, command_length); |
100 |
|
|
|
101 |
|
|
/* Prepare the MODE_SENSE command block. Distinguish between SUBCLASSES. */ |
102 |
✓✓ |
4 |
switch (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass) |
103 |
|
|
{ |
104 |
|
|
|
105 |
|
3 |
case UX_HOST_CLASS_STORAGE_SUBCLASS_RBC : |
106 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
107 |
|
|
case UX_HOST_CLASS_STORAGE_SUBCLASS_UFI : |
108 |
|
|
#endif |
109 |
|
3 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_CB + UX_HOST_CLASS_STORAGE_MODE_SENSE_OPERATION) = UX_HOST_CLASS_STORAGE_SCSI_MODE_SENSE; |
110 |
|
3 |
break; |
111 |
|
|
|
112 |
|
1 |
default : |
113 |
|
1 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_CB + UX_HOST_CLASS_STORAGE_MODE_SENSE_OPERATION) = UX_HOST_CLASS_STORAGE_SCSI_MODE_SENSE_SHORT; |
114 |
|
1 |
break; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
/* We ask for a specific page page but we put the buffer to maximum size. */ |
118 |
|
4 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_CB + UX_HOST_CLASS_STORAGE_MODE_SENSE_PC_PAGE_CODE) = UX_HOST_CLASS_STORAGE_MODE_SENSE_TP_PAGE; |
119 |
|
|
|
120 |
|
|
/* Store the length of the Mode Sense Response. */ |
121 |
|
4 |
_ux_utility_short_put_big_endian(cbw + UX_HOST_CLASS_STORAGE_CBW_CB + UX_HOST_CLASS_STORAGE_MODE_SENSE_PARAMETER_LIST_LENGTH, UX_HOST_CLASS_STORAGE_MODE_SENSE_ALL_PAGE_LENGTH); |
122 |
|
|
|
123 |
|
|
/* Obtain a block of memory for the answer. */ |
124 |
|
4 |
mode_sense_response = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_STORAGE_MODE_SENSE_ALL_PAGE_LENGTH); |
125 |
✓✓ |
4 |
if (mode_sense_response == UX_NULL) |
126 |
|
1 |
return(UX_MEMORY_INSUFFICIENT); |
127 |
|
|
|
128 |
|
|
/* Send the command to transport layer. */ |
129 |
|
3 |
status = _ux_host_class_storage_transport(storage, mode_sense_response); |
130 |
|
|
|
131 |
|
|
/* Free the memory resource used for the command response. */ |
132 |
|
3 |
_ux_utility_memory_free(mode_sense_response); |
133 |
|
|
|
134 |
|
|
/* Return completion status. */ |
135 |
|
3 |
return(status); |
136 |
|
|
} |
137 |
|
|
|