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 |
|
|
/** Device 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_device_class_storage.h" |
30 |
|
|
#include "ux_device_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_device_class_storage_test_ready PORTABLE C */ |
38 |
|
|
/* 6.1.10 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function tests if the SCSI slave device is ready. */ |
46 |
|
|
/* The status function of the storage devices is called. If there is */ |
47 |
|
|
/* an error, the request sense parameters are set for the host to */ |
48 |
|
|
/* investigate. */ |
49 |
|
|
/* */ |
50 |
|
|
/* INPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* storage Pointer to storage class */ |
53 |
|
|
/* lun Logical unit number */ |
54 |
|
|
/* endpoint_in Pointer to IN endpoint */ |
55 |
|
|
/* endpoint_out Pointer to OUT endpoint */ |
56 |
|
|
/* cbwcb Pointer to CBWCB */ |
57 |
|
|
/* */ |
58 |
|
|
/* OUTPUT */ |
59 |
|
|
/* */ |
60 |
|
|
/* Completion Status */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLS */ |
63 |
|
|
/* */ |
64 |
|
|
/* (ux_slave_class_storage_media_status) Get media status */ |
65 |
|
|
/* */ |
66 |
|
|
/* CALLED BY */ |
67 |
|
|
/* */ |
68 |
|
|
/* Device Storage Class */ |
69 |
|
|
/* */ |
70 |
|
|
/**************************************************************************/ |
71 |
|
369 |
UINT _ux_device_class_storage_test_ready(UX_SLAVE_CLASS_STORAGE *storage, ULONG lun, UX_SLAVE_ENDPOINT *endpoint_in, |
72 |
|
|
UX_SLAVE_ENDPOINT *endpoint_out, UCHAR * cbwcb) |
73 |
|
|
{ |
74 |
|
|
|
75 |
|
|
UINT status; |
76 |
|
|
ULONG media_status; |
77 |
|
|
|
78 |
|
|
UX_PARAMETER_NOT_USED(endpoint_in); |
79 |
|
|
UX_PARAMETER_NOT_USED(endpoint_out); |
80 |
|
|
UX_PARAMETER_NOT_USED(cbwcb); |
81 |
|
|
|
82 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
83 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_TEST_READY, storage, lun, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0) |
84 |
|
|
|
85 |
✗✓ |
369 |
if (storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_medium_loaded_status == 0) |
86 |
|
|
{ |
87 |
|
|
/* Media not loaded. Set NOT READY sense code. */ |
88 |
|
|
storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_request_sense_status = |
89 |
|
|
UX_DEVICE_CLASS_STORAGE_SENSE_STATUS(UX_SLAVE_CLASS_STORAGE_SENSE_KEY_NOT_READY, |
90 |
|
|
UX_SLAVE_CLASS_STORAGE_SENSE_CODE_NOT_PRESENT, 0x00); |
91 |
|
|
|
92 |
|
|
/* Return CSW with failure. */ |
93 |
|
|
storage -> ux_slave_class_storage_csw_status = UX_SLAVE_CLASS_STORAGE_CSW_FAILED; |
94 |
|
|
|
95 |
|
|
/* Return completion status. */ |
96 |
|
|
return(UX_SUCCESS); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/* Obtain the status of the device. */ |
100 |
|
369 |
status = storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_media_status(storage, lun, |
101 |
|
|
storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_media_id, &media_status); |
102 |
|
|
|
103 |
|
|
/* Set the sense/code/qualifier codes for the REQUEST_SENSE command. */ |
104 |
|
369 |
storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_request_sense_status = media_status; |
105 |
|
|
|
106 |
|
|
/* Return CSW with success/error. */ |
107 |
|
369 |
storage -> ux_slave_class_storage_csw_status = (status == UX_SUCCESS) ? |
108 |
|
369 |
UX_SLAVE_CLASS_STORAGE_CSW_PASSED : UX_SLAVE_CLASS_STORAGE_CSW_FAILED; |
109 |
|
369 |
status = UX_SUCCESS; |
110 |
|
|
|
111 |
|
|
#if !defined(UX_DEVICE_STANDALONE) |
112 |
|
|
|
113 |
|
|
/* Case (9) Ho > Dn. */ |
114 |
✓✓ |
369 |
if (storage -> ux_slave_class_storage_host_length) |
115 |
|
|
{ |
116 |
|
1 |
_ux_device_stack_endpoint_stall(endpoint_out); |
117 |
|
1 |
storage -> ux_slave_class_storage_csw_residue = storage -> ux_slave_class_storage_host_length; |
118 |
|
|
} |
119 |
|
|
#endif |
120 |
|
|
|
121 |
|
|
/* Return completion status. */ |
122 |
|
369 |
return(status); |
123 |
|
|
} |