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