Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * USB Networking Link Interface
0004  *
0005  * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net>
0006  * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
0007  */
0008 
0009 #ifndef __LINUX_USB_USBNET_H
0010 #define __LINUX_USB_USBNET_H
0011 
0012 #include <linux/mii.h>
0013 #include <linux/netdevice.h>
0014 #include <linux/skbuff.h>
0015 #include <linux/types.h>
0016 #include <linux/usb.h>
0017 
0018 /* interface from usbnet core to each USB networking link we handle */
0019 struct usbnet {
0020     /* housekeeping */
0021     struct usb_device   *udev;
0022     struct usb_interface    *intf;
0023     const struct driver_info *driver_info;
0024     const char      *driver_name;
0025     void            *driver_priv;
0026     wait_queue_head_t   wait;
0027     struct mutex        phy_mutex;
0028     unsigned char       suspend_count;
0029     unsigned char       pkt_cnt, pkt_err;
0030     unsigned short      rx_qlen, tx_qlen;
0031     unsigned        can_dma_sg:1;
0032 
0033     /* i/o info: pipes etc */
0034     unsigned        in, out;
0035     struct usb_host_endpoint *status;
0036     unsigned        maxpacket;
0037     struct timer_list   delay;
0038     const char      *padding_pkt;
0039 
0040     /* protocol/interface state */
0041     struct net_device   *net;
0042     int         msg_enable;
0043     unsigned long       data[5];
0044     u32         xid;
0045     u32         hard_mtu;   /* count any extra framing */
0046     size_t          rx_urb_size;    /* size for rx urbs */
0047     struct mii_if_info  mii;
0048     long            rx_speed;   /* If MII not used */
0049     long            tx_speed;   /* If MII not used */
0050 #       define SPEED_UNSET  -1
0051 
0052     /* various kinds of pending driver work */
0053     struct sk_buff_head rxq;
0054     struct sk_buff_head txq;
0055     struct sk_buff_head done;
0056     struct sk_buff_head rxq_pause;
0057     struct urb      *interrupt;
0058     unsigned        interrupt_count;
0059     struct mutex        interrupt_mutex;
0060     struct usb_anchor   deferred;
0061     struct tasklet_struct   bh;
0062 
0063     struct work_struct  kevent;
0064     unsigned long       flags;
0065 #       define EVENT_TX_HALT    0
0066 #       define EVENT_RX_HALT    1
0067 #       define EVENT_RX_MEMORY  2
0068 #       define EVENT_STS_SPLIT  3
0069 #       define EVENT_LINK_RESET 4
0070 #       define EVENT_RX_PAUSED  5
0071 #       define EVENT_DEV_ASLEEP 6
0072 #       define EVENT_DEV_OPEN   7
0073 #       define EVENT_DEVICE_REPORT_IDLE 8
0074 #       define EVENT_NO_RUNTIME_PM  9
0075 #       define EVENT_RX_KILL    10
0076 #       define EVENT_LINK_CHANGE    11
0077 #       define EVENT_SET_RX_MODE    12
0078 #       define EVENT_NO_IP_ALIGN    13
0079 };
0080 
0081 static inline struct usb_driver *driver_of(struct usb_interface *intf)
0082 {
0083     return to_usb_driver(intf->dev.driver);
0084 }
0085 
0086 /* interface from the device/framing level "minidriver" to core */
0087 struct driver_info {
0088     char        *description;
0089 
0090     int     flags;
0091 /* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
0092 #define FLAG_FRAMING_NC 0x0001      /* guard against device dropouts */
0093 #define FLAG_FRAMING_GL 0x0002      /* genelink batches packets */
0094 #define FLAG_FRAMING_Z  0x0004      /* zaurus adds a trailer */
0095 #define FLAG_FRAMING_RN 0x0008      /* RNDIS batches, plus huge header */
0096 
0097 #define FLAG_NO_SETINT  0x0010      /* device can't set_interface() */
0098 #define FLAG_ETHER  0x0020      /* maybe use "eth%d" names */
0099 
0100 #define FLAG_FRAMING_AX 0x0040      /* AX88772/178 packets */
0101 #define FLAG_WLAN   0x0080      /* use "wlan%d" names */
0102 #define FLAG_AVOID_UNLINK_URBS 0x0100   /* don't unlink urbs at usbnet_stop() */
0103 #define FLAG_SEND_ZLP   0x0200      /* hw requires ZLPs are sent */
0104 #define FLAG_WWAN   0x0400      /* use "wwan%d" names */
0105 
0106 #define FLAG_LINK_INTR  0x0800      /* updates link (carrier) status */
0107 
0108 #define FLAG_POINTTOPOINT 0x1000    /* possibly use "usb%d" names */
0109 
0110 /*
0111  * Indicates to usbnet, that USB driver accumulates multiple IP packets.
0112  * Affects statistic (counters) and short packet handling.
0113  */
0114 #define FLAG_MULTI_PACKET   0x2000
0115 #define FLAG_RX_ASSEMBLE    0x4000  /* rx packets may span >1 frames */
0116 #define FLAG_NOARP      0x8000  /* device can't do ARP */
0117 
0118     /* init device ... can sleep, or cause probe() failure */
0119     int (*bind)(struct usbnet *, struct usb_interface *);
0120 
0121     /* cleanup device ... can sleep, but can't fail */
0122     void    (*unbind)(struct usbnet *, struct usb_interface *);
0123 
0124     /* reset device ... can sleep */
0125     int (*reset)(struct usbnet *);
0126 
0127     /* stop device ... can sleep */
0128     int (*stop)(struct usbnet *);
0129 
0130     /* see if peer is connected ... can sleep */
0131     int (*check_connect)(struct usbnet *);
0132 
0133     /* (dis)activate runtime power management */
0134     int (*manage_power)(struct usbnet *, int);
0135 
0136     /* for status polling */
0137     void    (*status)(struct usbnet *, struct urb *);
0138 
0139     /* link reset handling, called from defer_kevent */
0140     int (*link_reset)(struct usbnet *);
0141 
0142     /* fixup rx packet (strip framing) */
0143     int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
0144 
0145     /* fixup tx packet (add framing) */
0146     struct sk_buff  *(*tx_fixup)(struct usbnet *dev,
0147                 struct sk_buff *skb, gfp_t flags);
0148 
0149     /* recover from timeout */
0150     void    (*recover)(struct usbnet *dev);
0151 
0152     /* early initialization code, can sleep. This is for minidrivers
0153      * having 'subminidrivers' that need to do extra initialization
0154      * right after minidriver have initialized hardware. */
0155     int (*early_init)(struct usbnet *dev);
0156 
0157     /* called by minidriver when receiving indication */
0158     void    (*indication)(struct usbnet *dev, void *ind, int indlen);
0159 
0160     /* rx mode change (device changes address list filtering) */
0161     void    (*set_rx_mode)(struct usbnet *dev);
0162 
0163     /* for new devices, use the descriptor-reading code instead */
0164     int     in;     /* rx endpoint */
0165     int     out;        /* tx endpoint */
0166 
0167     unsigned long   data;       /* Misc driver specific data */
0168 };
0169 
0170 /* Minidrivers are just drivers using the "usbnet" core as a powerful
0171  * network-specific subroutine library ... that happens to do pretty
0172  * much everything except custom framing and chip-specific stuff.
0173  */
0174 extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *);
0175 extern int usbnet_suspend(struct usb_interface *, pm_message_t);
0176 extern int usbnet_resume(struct usb_interface *);
0177 extern void usbnet_disconnect(struct usb_interface *);
0178 extern void usbnet_device_suggests_idle(struct usbnet *dev);
0179 
0180 extern int usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
0181             u16 value, u16 index, void *data, u16 size);
0182 extern int usbnet_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
0183             u16 value, u16 index, const void *data, u16 size);
0184 extern int usbnet_read_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype,
0185             u16 value, u16 index, void *data, u16 size);
0186 extern int usbnet_write_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype,
0187             u16 value, u16 index, const void *data, u16 size);
0188 extern int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype,
0189             u16 value, u16 index, const void *data, u16 size);
0190 
0191 /* Drivers that reuse some of the standard USB CDC infrastructure
0192  * (notably, using multiple interfaces according to the CDC
0193  * union descriptor) get some helper code.
0194  */
0195 struct cdc_state {
0196     struct usb_cdc_header_desc  *header;
0197     struct usb_cdc_union_desc   *u;
0198     struct usb_cdc_ether_desc   *ether;
0199     struct usb_interface        *control;
0200     struct usb_interface        *data;
0201 };
0202 
0203 extern void usbnet_cdc_update_filter(struct usbnet *dev);
0204 extern int usbnet_generic_cdc_bind(struct usbnet *, struct usb_interface *);
0205 extern int usbnet_ether_cdc_bind(struct usbnet *dev, struct usb_interface *intf);
0206 extern int usbnet_cdc_bind(struct usbnet *, struct usb_interface *);
0207 extern void usbnet_cdc_unbind(struct usbnet *, struct usb_interface *);
0208 extern void usbnet_cdc_status(struct usbnet *, struct urb *);
0209 extern int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb);
0210 
0211 /* CDC and RNDIS support the same host-chosen packet filters for IN transfers */
0212 #define DEFAULT_FILTER  (USB_CDC_PACKET_TYPE_BROADCAST \
0213             |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
0214             |USB_CDC_PACKET_TYPE_PROMISCUOUS \
0215             |USB_CDC_PACKET_TYPE_DIRECTED)
0216 
0217 
0218 /* we record the state for each of our queued skbs */
0219 enum skb_state {
0220     illegal = 0,
0221     tx_start, tx_done,
0222     rx_start, rx_done, rx_cleanup,
0223     unlink_start
0224 };
0225 
0226 struct skb_data {   /* skb->cb is one of these */
0227     struct urb      *urb;
0228     struct usbnet       *dev;
0229     enum skb_state      state;
0230     long            length;
0231     unsigned long       packets;
0232 };
0233 
0234 /* Drivers that set FLAG_MULTI_PACKET must call this in their
0235  * tx_fixup method before returning an skb.
0236  */
0237 static inline void
0238 usbnet_set_skb_tx_stats(struct sk_buff *skb,
0239             unsigned long packets, long bytes_delta)
0240 {
0241     struct skb_data *entry = (struct skb_data *) skb->cb;
0242 
0243     entry->packets = packets;
0244     entry->length = bytes_delta;
0245 }
0246 
0247 extern int usbnet_open(struct net_device *net);
0248 extern int usbnet_stop(struct net_device *net);
0249 extern netdev_tx_t usbnet_start_xmit(struct sk_buff *skb,
0250                      struct net_device *net);
0251 extern void usbnet_tx_timeout(struct net_device *net, unsigned int txqueue);
0252 extern int usbnet_change_mtu(struct net_device *net, int new_mtu);
0253 
0254 extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *);
0255 extern int usbnet_get_ethernet_addr(struct usbnet *, int);
0256 extern void usbnet_defer_kevent(struct usbnet *, int);
0257 extern void usbnet_skb_return(struct usbnet *, struct sk_buff *);
0258 extern void usbnet_unlink_rx_urbs(struct usbnet *);
0259 
0260 extern void usbnet_pause_rx(struct usbnet *);
0261 extern void usbnet_resume_rx(struct usbnet *);
0262 extern void usbnet_purge_paused_rxq(struct usbnet *);
0263 
0264 extern int usbnet_get_link_ksettings_mii(struct net_device *net,
0265                      struct ethtool_link_ksettings *cmd);
0266 extern int usbnet_set_link_ksettings_mii(struct net_device *net,
0267                      const struct ethtool_link_ksettings *cmd);
0268 extern int usbnet_get_link_ksettings_internal(struct net_device *net,
0269                      struct ethtool_link_ksettings *cmd);
0270 extern u32 usbnet_get_link(struct net_device *net);
0271 extern u32 usbnet_get_msglevel(struct net_device *);
0272 extern void usbnet_set_msglevel(struct net_device *, u32);
0273 extern void usbnet_set_rx_mode(struct net_device *net);
0274 extern void usbnet_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
0275 extern int usbnet_nway_reset(struct net_device *net);
0276 
0277 extern int usbnet_manage_power(struct usbnet *, int);
0278 extern void usbnet_link_change(struct usbnet *, bool, bool);
0279 
0280 extern int usbnet_status_start(struct usbnet *dev, gfp_t mem_flags);
0281 extern void usbnet_status_stop(struct usbnet *dev);
0282 
0283 extern void usbnet_update_max_qlen(struct usbnet *dev);
0284 
0285 #endif /* __LINUX_USB_USBNET_H */