• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 };
40 
41 struct UsbEcm {
42     struct UsbEcmDevice         *ecm;
43     struct OsalMutex            lock;
44 
45     struct DListHead            readPool;
46     struct DListHead            readQueue;
47     int32_t                     readStarted;
48     int32_t                     readAllocated;
49     struct DataFifo             readFifo;
50     struct DListHead            writePool;
51     int32_t                     writeStarted;
52     int32_t                     writeAllocated;
53     struct DataFifo             writeFifo;
54     bool                        writeBusy;
55     struct OsalMutex            lockRW;
56     struct OsalMutex            lockReadFifo;
57     struct OsalMutex            lockWriteFifo;
58     int                         refCount;
59 };
60 
61 struct UsbEcmPipe {
62     uint8_t                     id;
63     uint16_t                    maxPacketSize;
64     struct UsbFnInterface       *ctrlIface;
65 };
66 
67 struct UsbEcmInterface {
68     struct UsbFnInterface       *fn;
69     UsbFnInterfaceHandle                   handle;
70 };
71 
72 struct UsbEcmDevice {
73     struct IDeviceIoService     service;
74     struct HdfDeviceObject      *device;
75     struct UsbFnDevice          *fnDev;
76     struct UsbEcmInterface      ctrlIface;
77     struct UsbEcmInterface      dataIface;
78     struct UsbEcmPipe           notifyPipe;
79     struct UsbEcmPipe           dataInPipe;
80     struct UsbEcmPipe           dataOutPipe;
81     uint8_t ctrlId;
82     uint8_t dataId;
83     struct OsalMutex            lock;
84     char                        *udcName;
85     struct UsbEcm            *port;
86 
87     struct UsbFnRequest         *notifyReq;
88     struct UsbFnRequest         *ep0Req;
89     uint8_t              notifyState;
90     bool                isOpen;
91 };
92 
93 #endif /* U_ECM_H */
94