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_interface.h" 22 #include "usb_ddk_request.h" 23 #include "usb_raw_api_library.h" 24 25 #define INTERFACE_POOL_ID_MAX (128) 26 #define INTERFACE_REFCOUNT_UNFORCE (1) 27 28 typedef enum { 29 USB_PIPE_INDEX_TYPE, 30 USB_PIPE_DIRECTION_TYPE 31 } UsbPipeQueryParaType; 32 33 typedef enum { 34 USB_INTERFACE_INTERFACE_INDEX_TYPE, 35 USB_INTERFACE_ALT_SETTINGS_TYPE 36 } UsbInterfaceQueryParaType; 37 38 typedef enum { 39 USB_POOL_NORMAL_TYPE, 40 USB_POOL_OBJECT_ID_TYPE 41 } UsbPoolQueryParaType; 42 43 typedef enum { 44 USB_POOL_PROCESS_RUNNING, 45 USB_POOL_PROCESS_STOP, 46 USB_POOL_PROCESS_STOPED 47 } UsbPoolProcessStatusType; 48 49 struct UsbInterfaceHandleEntity { 50 struct UsbDeviceHandle *devHandle; 51 uint8_t interfaceIndex; 52 }; 53 struct UsbSdkInterface { 54 struct UsbInterface interface; 55 int32_t parentObjectId; 56 struct DListHead pipeList; 57 struct OsalMutex listLock; 58 UsbInterfaceStatus status; 59 uint8_t altSettingId; 60 struct UsbSession *session; 61 OsalAtomic refCount; 62 bool forceDetachKernelDriver; 63 }; 64 65 struct UsbInterfacePool { 66 struct UsbObject object; 67 struct UsbSession *session; 68 struct OsalMutex mutex; 69 struct DListHead interfaceList; 70 struct OsalMutex interfaceLock; 71 OsalAtomic refCount; 72 uint8_t busNum; 73 uint8_t devAddr; 74 OsalAtomic ioRefCount; 75 struct OsalThread ioSendProcess; 76 struct OsalThread ioAsyncReceiveProcess; 77 struct UsbMessageQueue submitRequestQueue; 78 UsbRawTidType ioProcessTid; 79 UsbPoolProcessStatusType ioProcessStopStatus; 80 struct OsalMutex ioStopLock; 81 struct UsbDevice *device; 82 }; 83 84 struct UsbPipeQueryPara { 85 UsbPipeQueryParaType type; 86 union { 87 uint8_t pipeId; 88 UsbPipeDirection pipeDirection; 89 }; 90 }; 91 92 struct UsbInterfaceQueryPara { 93 UsbInterfaceQueryParaType type; 94 uint8_t interfaceIndex; 95 uint8_t altSettingId; 96 }; 97 98 struct UsbPoolQueryPara { 99 UsbPoolQueryParaType type; 100 union { 101 struct { 102 uint8_t busNum; 103 uint8_t usbAddr; 104 }; 105 int32_t objectId; 106 }; 107 }; 108 109 struct UsbIfRequest { 110 struct UsbRequest request; 111 struct UsbHostRequest *hostRequest; 112 bool isSyncReq; 113 }__attribute__((aligned(4))); 114 115 int32_t UsbIfCreatPipeObj(const struct UsbSdkInterface *interfaceObj, struct UsbPipe **pipeObj); 116 int32_t UsbIfCreatInterfaceObj(const struct UsbInterfacePool *interfacePool, struct UsbSdkInterface **interfaceObj); 117 HDF_STATUS UsbIfDestroyInterfaceObj( 118 const struct UsbInterfacePool *interfacePool, const struct UsbSdkInterface *interfaceObj); 119 int32_t UsbIfCreatInterfacePool(const struct UsbSession *session, uint8_t busNum, uint8_t devAddr, 120 struct UsbInterfacePool **interfacePool); 121 122 #endif /* USB_INTERFACE_POOL_H */ 123