1 /*
2  * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef HDF_NET_USB_ADAPTER_H
10 #define HDF_NET_USB_ADAPTER_H
11 
12 #include "osal_mutex.h"
13 #include "hdf_log.h"
14 #include "hdf_usb_net_manager.h"
15 
16 #define MODULE_PARAM module_param
17 #define HARCH_LOG_TAG "[-net-hdf-]"
18 #define HARCH_NET_INFO_PRINT(fmt, ...) \
19 do { \
20     if (0) { \
21         HDF_LOGI(HARCH_LOG_TAG"[%{public}s][%{public}d]:" fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);} \
22 } while (0)
23 
24 typedef struct pcpu_sw_netstats     PcpuSwNetstats;
25 typedef struct net_device           NetDevice;
26 typedef struct timer_list           TimerList;
27 typedef struct work_struct          WorkStruct;
28 typedef struct tasklet_struct       TaskletStruct;
29 typedef struct device_type          DeviceType;
30 typedef struct ethtool_ops          EthtoolOps;
31 typedef struct rndis_data_hdr       RndisDataHdr;
32 typedef struct sk_buff              SkBuff;
33 typedef struct sk_buff_head         SkBuffHead;
34 typedef struct net_device_ops       NetDeviceOps;
35 
36 struct rndis_data_hdr {
37     __le32    msg_type;        /* RNDIS_MSG_PACKET */
38     __le32    msg_len;        /* rndis_data_hdr + data_len + pad */
39     __le32    data_offset;        /* 36 -- right after header */
40     __le32    data_len;        /* ... real packet size */
41 
42     __le32    oob_data_offset;    /* zero */
43     __le32    oob_data_len;        /* zero */
44     __le32    num_oob;        /* zero */
45     __le32    packet_data_offset;    /* zero */
46 
47     __le32    packet_data_len;    /* zero */
48     __le32    vc_handle;        /* zero */
49     __le32    reserved;        /* zero */
50 } __attribute__ ((packed));
51 
52 struct UsbnetAdapter {
53     struct IDeviceIoService service;
54     struct HdfDeviceObject *deviceObject;
55     unsigned        canDmaSg : 1;
56     NetDevice       *net;
57     int32_t         msg_enable;
58     struct UsbnetTransInfo usbnetInfo;
59     struct OsalMutex sendSkbClock;
60 
61     unsigned char pktCnt, pktErr;
62 
63     /* various kinds of pending driver work */
64     wait_queue_head_t    wait;
65     TimerList           delay;
66 
67     SkBuffHead    rxq;
68     SkBuffHead    txq;
69 
70     SkBuffHead    done;
71     SkBuffHead    rxqPause;
72     TaskletStruct  bh;
73 
74     struct pcpu_sw_netstats __percpu *stats64;
75 
76     WorkStruct    kevent;
77     WorkStruct    TxCompleteWorkqueue;
78     WorkStruct    RxCompleteWorkqueue;
79     unsigned int        txLen;
80     unsigned int        rxLen;
81     unsigned long       flags;
82 #        define EVENT_TX_HALT       0
83 #        define EVENT_RX_HALT       1
84 #        define EVENT_RX_MEMORY     2
85 #        define EVENT_STS_SPLIT     3
86 #        define EVENT_LINK_RESET    4
87 #        define EVENT_RX_PAUSED     5
88 #        define EVENT_DEV_ASLEEP    6
89 #        define EVENT_DEV_OPEN      7
90 #        define EVENT_DEVICE_REPORT_IDLE    8
91 #        define EVENT_NO_RUNTIME_PM         9
92 #        define EVENT_RX_KILL               10
93 #        define EVENT_LINK_CHANGE           11
94 #        define EVENT_SET_RX_MODE           12
95 #        define EVENT_NO_IP_ALIGN           13
96 };
97 
98 /* we record the state for each of our queued skbs */
99 enum SkbState {
100     ILLEGAL = 0,
101     TX_START,
102     TX_DONE,
103     RX_START,
104     RX_DONE,
105     RX_CLEANUP,
106     UNLINK_START
107 };
108 
109 struct SkbData {    /* skb->cb is one of these */
110     enum SkbState       state;
111     long                length;
112     unsigned long       packets;
113 };
114 
115 #endif
116