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