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 U_ECM_H 17 #define U_ECM_H 18 19 #include "hdf_base.h" 20 #include "hdf_device_desc.h" 21 #include "osal_atomic.h" 22 #include "osal_mutex.h" 23 #include "usb_ddk.h" 24 #include "usb_object.h" 25 #include "usbfn_request.h" 26 #include "data_fifo.h" 27 28 enum EcmNotifyState { 29 ECM_NOTIFY_NONE, /* don't notify */ 30 ECM_NOTIFY_CONNECT, /* issue CONNECT next */ 31 ECM_NOTIFY_SPEED, /* issue SPEED_CHANGE next */ 32 }; 33 34 enum UsbEcmCmd { 35 USB_ECM_OPEN = 0, 36 USB_ECM_CLOSE, 37 USB_ECM_READ, 38 USB_ECM_WRITE, 39 USB_ECM_INIT = 100, 40 USB_ECM_RELEASE = 101, 41 }; 42 43 struct UsbEcm { 44 struct UsbEcmDevice *ecm; 45 struct OsalMutex lock; 46 47 struct DListHead readPool; 48 struct DListHead readQueue; 49 int32_t readStarted; 50 int32_t readAllocated; 51 struct DataFifo readFifo; 52 struct DListHead writePool; 53 int32_t writeStarted; 54 int32_t writeAllocated; 55 struct DataFifo writeFifo; 56 bool writeBusy; 57 struct OsalMutex lockRW; 58 struct OsalMutex lockReadFifo; 59 struct OsalMutex lockWriteFifo; 60 int32_t refCount; 61 }; 62 63 struct UsbEcmPipe { 64 uint8_t id; 65 uint16_t maxPacketSize; 66 struct UsbFnInterface *ctrlIface; 67 }; 68 69 struct UsbEcmInterface { 70 struct UsbFnInterface *fn; 71 UsbFnInterfaceHandle handle; 72 }; 73 74 struct UsbEcmDevice { 75 struct IDeviceIoService service; 76 struct HdfDeviceObject *device; 77 struct UsbFnDevice *fnDev; 78 struct UsbEcmInterface ctrlIface; 79 struct UsbEcmInterface dataIface; 80 struct UsbEcmPipe notifyPipe; 81 struct UsbEcmPipe dataInPipe; 82 struct UsbEcmPipe dataOutPipe; 83 uint8_t ctrlId; 84 uint8_t dataId; 85 struct OsalMutex lock; 86 char *udcName; 87 struct UsbEcm *port; 88 89 struct UsbFnRequest *notifyReq; 90 struct UsbFnRequest *ep0Req; 91 uint8_t notifyState; 92 bool isOpen; 93 bool initFlag; 94 }; 95 96 #endif /* U_ECM_H */ 97