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_transport PORTABLE C */ |
37 |
|
|
/* 6.1.10 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function is the transport layer for all protocols. It perform */ |
45 |
|
|
/* the error recovery and retries if needed. */ |
46 |
|
|
/* */ |
47 |
|
|
/* It's for RTOS mode only. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* storage Pointer to storage class */ |
52 |
|
|
/* data_pointer Pointer to data */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* Completion Status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* (ux_host_class_storage_transport) Class storage transport */ |
61 |
|
|
/* _ux_host_class_storage_device_reset Reset device */ |
62 |
|
|
/* _ux_host_class_storage_request_sense Class request sense */ |
63 |
|
|
/* _ux_host_stack_endpoint_reset Reset endpoint */ |
64 |
|
|
/* */ |
65 |
|
|
/* CALLED BY */ |
66 |
|
|
/* */ |
67 |
|
|
/* Storage Class */ |
68 |
|
|
/* */ |
69 |
|
|
/* RELEASE HISTORY */ |
70 |
|
|
/* */ |
71 |
|
|
/* DATE NAME DESCRIPTION */ |
72 |
|
|
/* */ |
73 |
|
|
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ |
74 |
|
|
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ |
75 |
|
|
/* resulting in version 6.1 */ |
76 |
|
|
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ |
77 |
|
|
/* refined macros names, */ |
78 |
|
|
/* resulting in version 6.1.10 */ |
79 |
|
|
/* */ |
80 |
|
|
/**************************************************************************/ |
81 |
|
2624 |
UINT _ux_host_class_storage_transport(UX_HOST_CLASS_STORAGE *storage, UCHAR *data_pointer) |
82 |
|
|
{ |
83 |
|
|
#if defined(UX_HOST_STANDALONE) |
84 |
|
|
UX_PARAMETER_NOT_USED(storage); |
85 |
|
|
UX_PARAMETER_NOT_USED(data_pointer); |
86 |
|
|
return(UX_FUNCTION_NOT_SUPPORTED); |
87 |
|
|
#else |
88 |
|
|
|
89 |
|
|
UINT status; |
90 |
|
|
UINT csw_status; |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
/* Reset the sense code. */ |
94 |
|
2624 |
storage -> ux_host_class_storage_sense_code = UX_SUCCESS; |
95 |
|
|
|
96 |
|
|
/* Send the command to the appropriate transport. */ |
97 |
|
2624 |
status = storage -> ux_host_class_storage_transport(storage, data_pointer); |
98 |
|
|
|
99 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
100 |
|
|
/* The treatment of errors is different according to the protocol used. BO and CB belong |
101 |
|
|
to the CSW group. CBI is separate. */ |
102 |
|
|
if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceProtocol != UX_HOST_CLASS_STORAGE_PROTOCOL_CBI) |
103 |
|
|
{ |
104 |
|
|
#endif |
105 |
|
|
|
106 |
|
|
/* Check the status. */ |
107 |
✓✓ |
2624 |
if (status != UX_SUCCESS) |
108 |
|
|
|
109 |
|
|
/* There was a more serious error. Just give up! */ |
110 |
|
280 |
return(status); |
111 |
|
|
|
112 |
|
|
/* The command transfer was OK but maybe we have a CSW error. */ |
113 |
|
2344 |
csw_status = storage -> ux_host_class_storage_csw[UX_HOST_CLASS_STORAGE_CSW_STATUS]; |
114 |
✓✓ |
2344 |
if (csw_status == 0) |
115 |
|
2150 |
return(UX_SUCCESS); |
116 |
|
|
|
117 |
|
|
/* Check for a command failure. If so, we need to sense the error with |
118 |
|
|
a REQUEST SENSE command. */ |
119 |
|
194 |
status = _ux_host_class_storage_request_sense(storage); |
120 |
|
|
|
121 |
|
|
/* If we have an transport failure here, we are in trouble! The storage device is in |
122 |
|
|
an unstable state and should be reset completely. */ |
123 |
✓✓ |
194 |
if (status != UX_SUCCESS) |
124 |
|
|
{ |
125 |
|
|
|
126 |
|
|
/* Reset device. */ |
127 |
|
3 |
_ux_host_class_storage_device_reset(storage); |
128 |
|
3 |
return(status); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
/* The sense code is saved in the device instance. We can return safely. */ |
132 |
|
191 |
return(UX_SUCCESS); |
133 |
|
|
|
134 |
|
|
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT |
135 |
|
|
} |
136 |
|
|
else |
137 |
|
|
{ |
138 |
|
|
|
139 |
|
|
switch (status) |
140 |
|
|
{ |
141 |
|
|
|
142 |
|
|
case UX_SUCCESS: |
143 |
|
|
return(UX_SUCCESS); |
144 |
|
|
|
145 |
|
|
case UX_TRANSFER_STALLED: |
146 |
|
|
|
147 |
|
|
/* The endpoint was halted by a stall condition and needs to be reset. */ |
148 |
|
|
_ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_in_endpoint); |
149 |
|
|
|
150 |
|
|
/* The endpoint was halted by a stall condition and needs to be reset. */ |
151 |
|
|
_ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_out_endpoint); |
152 |
|
|
|
153 |
|
|
/* Check for a command failure. If so, we need to sense the error with |
154 |
|
|
a REQUEST SENSE command. */ |
155 |
|
|
status = _ux_host_class_storage_request_sense(storage); |
156 |
|
|
return(status); |
157 |
|
|
|
158 |
|
|
default: |
159 |
|
|
|
160 |
|
|
/* There was a more serious error. Just give up! */ |
161 |
|
|
return(status); |
162 |
|
|
} |
163 |
|
|
} |
164 |
|
|
#endif |
165 |
|
|
#endif |
166 |
|
|
} |