1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef USB_INTERFACE_POOL_H 17 #define USB_INTERFACE_POOL_H 18 19 #include "usb_session.h" 20 #include "usb_ddk_device.h" 21 #include "usb_ddk_request.h" 22 #include "usb_interface.h" 23 #include "usb_raw_api_library.h" 24 25 #define INTERFACE_POOL_ID_MAX (128) 26 27 typedef enum { 28 USB_PIPE_INDEX_TYPE, 29 USB_PIPE_DIRECTION_TYPE 30 } UsbPipeQueryParaType; 31 32 typedef enum { 33 USB_INTERFACE_INTERFACE_INDEX_TYPE, 34 USB_INTERFACE_ALT_SETTINGS_TYPE 35 } UsbInterfaceQueryParaType; 36 37 typedef enum { 38 USB_POOL_NORMAL_TYPE, 39 USB_POOL_OBJECT_ID_TYPE 40 } UsbPoolQueryParaType; 41 42 typedef enum { 43 USB_POOL_PROCESS_RUNNING, 44 USB_POOL_PROCESS_STOP, 45 USB_POOL_PROCESS_STOPED 46 } UsbPoolProcessStatusType; 47 48 struct UsbInterfaceHandleEntity { 49 struct UsbDeviceHandle *devHandle; 50 uint8_t interfaceIndex; 51 }; 52 struct UsbSdkInterface { 53 struct UsbInterface interface; 54 int32_t parentObjectId; 55 struct DListHead pipeList; 56 struct OsalMutex listLock; 57 UsbInterfaceStatus status; 58 uint8_t altSettingId; 59 struct UsbSession *session; 60 OsalAtomic refCount; 61 }; 62 63 struct UsbInterfacePool { 64 struct UsbObject object; 65 struct UsbSession *session; 66 struct OsalMutex mutex; 67 struct DListHead interfaceList; 68 struct OsalMutex interfaceLock; 69 OsalAtomic refCount; 70 uint8_t busNum; 71 uint8_t devAddr; 72 OsalAtomic ioRefCount; 73 struct OsalThread ioSendProcess; 74 struct OsalThread ioAsyncReceiveProcess; 75 struct UsbMessageQueue submitRequestQueue; 76 UsbRawTidType ioProcessTid; 77 UsbPoolProcessStatusType ioProcessStopStatus; 78 struct OsalMutex ioStopLock; 79 struct UsbDevice *device; 80 }; 81 82 struct UsbPipeQueryPara { 83 UsbPipeQueryParaType type; 84 union { 85 uint8_t pipeId; 86 UsbPipeDirection pipeDirection; 87 }; 88 }; 89 90 struct UsbInterfaceQueryPara { 91 UsbInterfaceQueryParaType type; 92 uint8_t interfaceIndex; 93 uint8_t altSettingId; 94 }; 95 96 struct UsbPoolQueryPara { 97 UsbPoolQueryParaType type; 98 union { 99 struct { 100 uint8_t busNum; 101 uint8_t usbAddr; 102 }; 103 int32_t objectId; 104 }; 105 }; 106 107 struct UsbIfRequest { 108 struct UsbRequest request; 109 struct UsbHostRequest *hostRequest; 110 bool isSyncReq; 111 }__attribute__((aligned(4))); 112 113 int32_t UsbIfCreatPipeObj(const struct UsbSdkInterface *interfaceObj, struct UsbPipe **pipeObj); 114 int32_t UsbIfCreatInterfaceObj(const struct UsbInterfacePool *interfacePool, struct UsbSdkInterface **interfaceObj); 115 HDF_STATUS UsbIfDestroyInterfaceObj(const struct UsbInterfacePool *interfacePool, const struct UsbSdkInterface *interfaceObj); 116 int UsbIfCreatInterfacePool(const struct UsbSession *session, uint8_t busNum, uint8_t devAddr, 117 struct UsbInterfacePool **interfacePool); 118 119 #endif /* USB_INTERFACE_POOL_H */ 120