1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0+
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * USB Networking Link Interface
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net>
6*4882a593Smuzhiyun * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
9*4882a593Smuzhiyun * it under the terms of the GNU General Public License as published by
10*4882a593Smuzhiyun * the Free Software Foundation; either version 2 of the License, or
11*4882a593Smuzhiyun * (at your option) any later version.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful,
14*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*4882a593Smuzhiyun * GNU General Public License for more details.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License
19*4882a593Smuzhiyun * along with this program; if not, write to the Free Software
20*4882a593Smuzhiyun * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*4882a593Smuzhiyun */
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #ifndef __LINUX_USB_USBNET_H
24*4882a593Smuzhiyun #define __LINUX_USB_USBNET_H
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #include <linux/android_kabi.h>
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /* interface from usbnet core to each USB networking link we handle */
29*4882a593Smuzhiyun struct usbnet {
30*4882a593Smuzhiyun /* housekeeping */
31*4882a593Smuzhiyun struct usb_device *udev;
32*4882a593Smuzhiyun struct usb_interface *intf;
33*4882a593Smuzhiyun const struct driver_info *driver_info;
34*4882a593Smuzhiyun const char *driver_name;
35*4882a593Smuzhiyun void *driver_priv;
36*4882a593Smuzhiyun wait_queue_head_t wait;
37*4882a593Smuzhiyun struct mutex phy_mutex;
38*4882a593Smuzhiyun unsigned char suspend_count;
39*4882a593Smuzhiyun unsigned char pkt_cnt, pkt_err;
40*4882a593Smuzhiyun unsigned short rx_qlen, tx_qlen;
41*4882a593Smuzhiyun unsigned can_dma_sg:1;
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /* i/o info: pipes etc */
44*4882a593Smuzhiyun unsigned in, out;
45*4882a593Smuzhiyun struct usb_host_endpoint *status;
46*4882a593Smuzhiyun unsigned maxpacket;
47*4882a593Smuzhiyun struct timer_list delay;
48*4882a593Smuzhiyun const char *padding_pkt;
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun /* protocol/interface state */
51*4882a593Smuzhiyun struct net_device *net;
52*4882a593Smuzhiyun int msg_enable;
53*4882a593Smuzhiyun unsigned long data[5];
54*4882a593Smuzhiyun u32 xid;
55*4882a593Smuzhiyun u32 hard_mtu; /* count any extra framing */
56*4882a593Smuzhiyun size_t rx_urb_size; /* size for rx urbs */
57*4882a593Smuzhiyun struct mii_if_info mii;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* various kinds of pending driver work */
60*4882a593Smuzhiyun struct sk_buff_head rxq;
61*4882a593Smuzhiyun struct sk_buff_head txq;
62*4882a593Smuzhiyun struct sk_buff_head done;
63*4882a593Smuzhiyun struct sk_buff_head rxq_pause;
64*4882a593Smuzhiyun struct urb *interrupt;
65*4882a593Smuzhiyun unsigned interrupt_count;
66*4882a593Smuzhiyun struct mutex interrupt_mutex;
67*4882a593Smuzhiyun struct usb_anchor deferred;
68*4882a593Smuzhiyun struct tasklet_struct bh;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun struct pcpu_sw_netstats __percpu *stats64;
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun struct work_struct kevent;
73*4882a593Smuzhiyun unsigned long flags;
74*4882a593Smuzhiyun # define EVENT_TX_HALT 0
75*4882a593Smuzhiyun # define EVENT_RX_HALT 1
76*4882a593Smuzhiyun # define EVENT_RX_MEMORY 2
77*4882a593Smuzhiyun # define EVENT_STS_SPLIT 3
78*4882a593Smuzhiyun # define EVENT_LINK_RESET 4
79*4882a593Smuzhiyun # define EVENT_RX_PAUSED 5
80*4882a593Smuzhiyun # define EVENT_DEV_ASLEEP 6
81*4882a593Smuzhiyun # define EVENT_DEV_OPEN 7
82*4882a593Smuzhiyun # define EVENT_DEVICE_REPORT_IDLE 8
83*4882a593Smuzhiyun # define EVENT_NO_RUNTIME_PM 9
84*4882a593Smuzhiyun # define EVENT_RX_KILL 10
85*4882a593Smuzhiyun # define EVENT_LINK_CHANGE 11
86*4882a593Smuzhiyun # define EVENT_SET_RX_MODE 12
87*4882a593Smuzhiyun # define EVENT_NO_IP_ALIGN 13
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
90*4882a593Smuzhiyun ANDROID_KABI_RESERVE(2);
91*4882a593Smuzhiyun ANDROID_KABI_RESERVE(3);
92*4882a593Smuzhiyun ANDROID_KABI_RESERVE(4);
93*4882a593Smuzhiyun };
94*4882a593Smuzhiyun
driver_of(struct usb_interface * intf)95*4882a593Smuzhiyun static inline struct usb_driver *driver_of(struct usb_interface *intf)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun return to_usb_driver(intf->dev.driver);
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /* interface from the device/framing level "minidriver" to core */
101*4882a593Smuzhiyun struct driver_info {
102*4882a593Smuzhiyun char *description;
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun int flags;
105*4882a593Smuzhiyun /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
106*4882a593Smuzhiyun #define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
107*4882a593Smuzhiyun #define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
108*4882a593Smuzhiyun #define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
109*4882a593Smuzhiyun #define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun #define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
112*4882a593Smuzhiyun #define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun #define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
115*4882a593Smuzhiyun #define FLAG_WLAN 0x0080 /* use "wlan%d" names */
116*4882a593Smuzhiyun #define FLAG_AVOID_UNLINK_URBS 0x0100 /* don't unlink urbs at usbnet_stop() */
117*4882a593Smuzhiyun #define FLAG_SEND_ZLP 0x0200 /* hw requires ZLPs are sent */
118*4882a593Smuzhiyun #define FLAG_WWAN 0x0400 /* use "wwan%d" names */
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun #define FLAG_LINK_INTR 0x0800 /* updates link (carrier) status */
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun #define FLAG_POINTTOPOINT 0x1000 /* possibly use "usb%d" names */
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun * Indicates to usbnet, that USB driver accumulates multiple IP packets.
126*4882a593Smuzhiyun * Affects statistic (counters) and short packet handling.
127*4882a593Smuzhiyun */
128*4882a593Smuzhiyun #define FLAG_MULTI_PACKET 0x2000
129*4882a593Smuzhiyun #define FLAG_RX_ASSEMBLE 0x4000 /* rx packets may span >1 frames */
130*4882a593Smuzhiyun #define FLAG_NOARP 0x8000 /* device can't do ARP */
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun /* init device ... can sleep, or cause probe() failure */
133*4882a593Smuzhiyun int (*bind)(struct usbnet *, struct usb_interface *);
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun /* cleanup device ... can sleep, but can't fail */
136*4882a593Smuzhiyun void (*unbind)(struct usbnet *, struct usb_interface *);
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /* reset device ... can sleep */
139*4882a593Smuzhiyun int (*reset)(struct usbnet *);
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun /* stop device ... can sleep */
142*4882a593Smuzhiyun int (*stop)(struct usbnet *);
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun /* see if peer is connected ... can sleep */
145*4882a593Smuzhiyun int (*check_connect)(struct usbnet *);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /* (dis)activate runtime power management */
148*4882a593Smuzhiyun int (*manage_power)(struct usbnet *, int);
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun /* for status polling */
151*4882a593Smuzhiyun void (*status)(struct usbnet *, struct urb *);
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun /* link reset handling, called from defer_kevent */
154*4882a593Smuzhiyun int (*link_reset)(struct usbnet *);
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun /* fixup rx packet (strip framing) */
157*4882a593Smuzhiyun int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /* fixup tx packet (add framing) */
160*4882a593Smuzhiyun struct sk_buff *(*tx_fixup)(struct usbnet *dev,
161*4882a593Smuzhiyun struct sk_buff *skb, gfp_t flags);
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun /* recover from timeout */
164*4882a593Smuzhiyun void (*recover)(struct usbnet *dev);
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun /* early initialization code, can sleep. This is for minidrivers
167*4882a593Smuzhiyun * having 'subminidrivers' that need to do extra initialization
168*4882a593Smuzhiyun * right after minidriver have initialized hardware. */
169*4882a593Smuzhiyun int (*early_init)(struct usbnet *dev);
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun /* called by minidriver when receiving indication */
172*4882a593Smuzhiyun void (*indication)(struct usbnet *dev, void *ind, int indlen);
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun /* rx mode change (device changes address list filtering) */
175*4882a593Smuzhiyun void (*set_rx_mode)(struct usbnet *dev);
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /* for new devices, use the descriptor-reading code instead */
178*4882a593Smuzhiyun int in; /* rx endpoint */
179*4882a593Smuzhiyun int out; /* tx endpoint */
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun unsigned long data; /* Misc driver specific data */
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
184*4882a593Smuzhiyun ANDROID_KABI_RESERVE(2);
185*4882a593Smuzhiyun };
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /* Minidrivers are just drivers using the "usbnet" core as a powerful
188*4882a593Smuzhiyun * network-specific subroutine library ... that happens to do pretty
189*4882a593Smuzhiyun * much everything except custom framing and chip-specific stuff.
190*4882a593Smuzhiyun */
191*4882a593Smuzhiyun extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *);
192*4882a593Smuzhiyun extern int usbnet_suspend(struct usb_interface *, pm_message_t);
193*4882a593Smuzhiyun extern int usbnet_resume(struct usb_interface *);
194*4882a593Smuzhiyun extern void usbnet_disconnect(struct usb_interface *);
195*4882a593Smuzhiyun extern void usbnet_device_suggests_idle(struct usbnet *dev);
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun extern int usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
198*4882a593Smuzhiyun u16 value, u16 index, void *data, u16 size);
199*4882a593Smuzhiyun extern int usbnet_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
200*4882a593Smuzhiyun u16 value, u16 index, const void *data, u16 size);
201*4882a593Smuzhiyun extern int usbnet_read_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype,
202*4882a593Smuzhiyun u16 value, u16 index, void *data, u16 size);
203*4882a593Smuzhiyun extern int usbnet_write_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype,
204*4882a593Smuzhiyun u16 value, u16 index, const void *data, u16 size);
205*4882a593Smuzhiyun extern int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype,
206*4882a593Smuzhiyun u16 value, u16 index, const void *data, u16 size);
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun /* Drivers that reuse some of the standard USB CDC infrastructure
209*4882a593Smuzhiyun * (notably, using multiple interfaces according to the CDC
210*4882a593Smuzhiyun * union descriptor) get some helper code.
211*4882a593Smuzhiyun */
212*4882a593Smuzhiyun struct cdc_state {
213*4882a593Smuzhiyun struct usb_cdc_header_desc *header;
214*4882a593Smuzhiyun struct usb_cdc_union_desc *u;
215*4882a593Smuzhiyun struct usb_cdc_ether_desc *ether;
216*4882a593Smuzhiyun struct usb_interface *control;
217*4882a593Smuzhiyun struct usb_interface *data;
218*4882a593Smuzhiyun };
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun extern void usbnet_cdc_update_filter(struct usbnet *dev);
221*4882a593Smuzhiyun extern int usbnet_generic_cdc_bind(struct usbnet *, struct usb_interface *);
222*4882a593Smuzhiyun extern int usbnet_ether_cdc_bind(struct usbnet *dev, struct usb_interface *intf);
223*4882a593Smuzhiyun extern int usbnet_cdc_bind(struct usbnet *, struct usb_interface *);
224*4882a593Smuzhiyun extern void usbnet_cdc_unbind(struct usbnet *, struct usb_interface *);
225*4882a593Smuzhiyun extern void usbnet_cdc_status(struct usbnet *, struct urb *);
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun /* CDC and RNDIS support the same host-chosen packet filters for IN transfers */
228*4882a593Smuzhiyun #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
229*4882a593Smuzhiyun |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
230*4882a593Smuzhiyun |USB_CDC_PACKET_TYPE_PROMISCUOUS \
231*4882a593Smuzhiyun |USB_CDC_PACKET_TYPE_DIRECTED)
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun /* we record the state for each of our queued skbs */
235*4882a593Smuzhiyun enum skb_state {
236*4882a593Smuzhiyun illegal = 0,
237*4882a593Smuzhiyun tx_start, tx_done,
238*4882a593Smuzhiyun rx_start, rx_done, rx_cleanup,
239*4882a593Smuzhiyun unlink_start
240*4882a593Smuzhiyun };
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun struct skb_data { /* skb->cb is one of these */
243*4882a593Smuzhiyun struct urb *urb;
244*4882a593Smuzhiyun struct usbnet *dev;
245*4882a593Smuzhiyun enum skb_state state;
246*4882a593Smuzhiyun long length;
247*4882a593Smuzhiyun unsigned long packets;
248*4882a593Smuzhiyun };
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun /* Drivers that set FLAG_MULTI_PACKET must call this in their
251*4882a593Smuzhiyun * tx_fixup method before returning an skb.
252*4882a593Smuzhiyun */
253*4882a593Smuzhiyun static inline void
usbnet_set_skb_tx_stats(struct sk_buff * skb,unsigned long packets,long bytes_delta)254*4882a593Smuzhiyun usbnet_set_skb_tx_stats(struct sk_buff *skb,
255*4882a593Smuzhiyun unsigned long packets, long bytes_delta)
256*4882a593Smuzhiyun {
257*4882a593Smuzhiyun struct skb_data *entry = (struct skb_data *) skb->cb;
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun entry->packets = packets;
260*4882a593Smuzhiyun entry->length = bytes_delta;
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun extern int usbnet_open(struct net_device *net);
264*4882a593Smuzhiyun extern int usbnet_stop(struct net_device *net);
265*4882a593Smuzhiyun extern netdev_tx_t usbnet_start_xmit(struct sk_buff *skb,
266*4882a593Smuzhiyun struct net_device *net);
267*4882a593Smuzhiyun extern void usbnet_tx_timeout(struct net_device *net, unsigned int txqueue);
268*4882a593Smuzhiyun extern int usbnet_change_mtu(struct net_device *net, int new_mtu);
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *);
271*4882a593Smuzhiyun extern int usbnet_get_ethernet_addr(struct usbnet *, int);
272*4882a593Smuzhiyun extern void usbnet_defer_kevent(struct usbnet *, int);
273*4882a593Smuzhiyun extern void usbnet_skb_return(struct usbnet *, struct sk_buff *);
274*4882a593Smuzhiyun extern void usbnet_unlink_rx_urbs(struct usbnet *);
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun extern void usbnet_pause_rx(struct usbnet *);
277*4882a593Smuzhiyun extern void usbnet_resume_rx(struct usbnet *);
278*4882a593Smuzhiyun extern void usbnet_purge_paused_rxq(struct usbnet *);
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun extern int usbnet_get_link_ksettings(struct net_device *net,
281*4882a593Smuzhiyun struct ethtool_link_ksettings *cmd);
282*4882a593Smuzhiyun extern int usbnet_set_link_ksettings(struct net_device *net,
283*4882a593Smuzhiyun const struct ethtool_link_ksettings *cmd);
284*4882a593Smuzhiyun extern u32 usbnet_get_link(struct net_device *net);
285*4882a593Smuzhiyun extern u32 usbnet_get_msglevel(struct net_device *);
286*4882a593Smuzhiyun extern void usbnet_set_msglevel(struct net_device *, u32);
287*4882a593Smuzhiyun extern void usbnet_set_rx_mode(struct net_device *net);
288*4882a593Smuzhiyun extern void usbnet_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
289*4882a593Smuzhiyun extern int usbnet_nway_reset(struct net_device *net);
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun extern int usbnet_manage_power(struct usbnet *, int);
292*4882a593Smuzhiyun extern void usbnet_link_change(struct usbnet *, bool, bool);
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun extern int usbnet_status_start(struct usbnet *dev, gfp_t mem_flags);
295*4882a593Smuzhiyun extern void usbnet_status_stop(struct usbnet *dev);
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun extern void usbnet_update_max_qlen(struct usbnet *dev);
298*4882a593Smuzhiyun extern void usbnet_get_stats64(struct net_device *dev,
299*4882a593Smuzhiyun struct rtnl_link_stats64 *stats);
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun #endif /* __LINUX_USB_USBNET_H */
302