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