Merge tag 'v3.10.105' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / usb / gadget / u_ether.h
CommitLineData
2b3d942c
DB
1/*
2 * u_ether.h -- interface to USB gadget "ethernet link" utilities
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
2b3d942c
DB
12 */
13
14#ifndef __U_ETHER_H
15#define __U_ETHER_H
16
17#include <linux/err.h>
18#include <linux/if_ether.h>
19#include <linux/usb/composite.h>
20#include <linux/usb/cdc.h>
21
da741b8c
DB
22#include "gadget_chips.h"
23
d6a01439 24struct eth_dev;
da741b8c 25
2b3d942c
DB
26/*
27 * This represents the USB side of an "ethernet" link, managed by a USB
28 * function which provides control and (maybe) framing. Two functions
45fe3b8e
DB
29 * in different configurations could share the same ethernet link/netdev,
30 * using different host interaction models.
2b3d942c 31 *
45fe3b8e
DB
32 * There is a current limitation that only one instance of this link may
33 * be present in any given configuration. When that's a problem, network
34 * layer facilities can be used to package multiple logical links on this
35 * single "physical" one.
2b3d942c
DB
36 */
37struct gether {
38 struct usb_function func;
39
40 /* updated by gether_{connect,disconnect} */
41 struct eth_dev *ioport;
42
43 /* endpoints handle full and/or high speeds */
44 struct usb_ep *in_ep;
45 struct usb_ep *out_ep;
46
2b3d942c
DB
47 bool is_zlp_ok;
48
49 u16 cdc_filter;
50
9b39e9dd 51 /* hooks for added framing, as needed for RNDIS and EEM. */
2b3d942c 52 u32 header_len;
5c1168db
YK
53 /* NCM requires fixed size bundles */
54 bool is_fixed;
55 u32 fixed_out_len;
56 u32 fixed_in_len;
6fa3eb70
S
57
58 unsigned ul_max_pkts_per_xfer;
59 unsigned dl_max_pkts_per_xfer;
60 unsigned dl_max_transfer_len;
61 bool multi_pkt_xfer;
9b39e9dd
BN
62 struct sk_buff *(*wrap)(struct gether *port,
63 struct sk_buff *skb);
64 int (*unwrap)(struct gether *port,
65 struct sk_buff *skb,
66 struct sk_buff_head *list);
2b3d942c
DB
67
68 /* called on network open/close */
69 void (*open)(struct gether *);
70 void (*close)(struct gether *);
6fa3eb70 71 struct rndis_packet_msg_type *header;
2b3d942c
DB
72};
73
74#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
75 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
76 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
77 |USB_CDC_PACKET_TYPE_DIRECTED)
78
036e98b2 79/* variant of gether_setup that allows customizing network device name */
d6a01439 80struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
036e98b2 81 const char *netname);
2b3d942c
DB
82
83/* netdev setup/teardown as directed by the gadget driver */
036e98b2
ML
84/* gether_setup - initialize one ethernet-over-usb link
85 * @g: gadget to associated with these links
86 * @ethaddr: NULL, or a buffer in which the ethernet address of the
87 * host side of the link is recorded
88 * Context: may sleep
89 *
90 * This sets up the single network link that may be exported by a
91 * gadget driver using this framework. The link layer addresses are
92 * set up using module parameters.
93 *
94 * Returns negative errno, or zero on success
95 */
d6a01439
SAS
96static inline struct eth_dev *gether_setup(struct usb_gadget *g,
97 u8 ethaddr[ETH_ALEN])
036e98b2
ML
98{
99 return gether_setup_name(g, ethaddr, "usb");
100}
101
d6a01439 102void gether_cleanup(struct eth_dev *dev);
2b3d942c
DB
103
104/* connect/disconnect is handled by individual functions */
105struct net_device *gether_connect(struct gether *);
106void gether_disconnect(struct gether *);
107
da741b8c
DB
108/* Some controllers can't support CDC Ethernet (ECM) ... */
109static inline bool can_support_ecm(struct usb_gadget *gadget)
110{
111 if (!gadget_supports_altsettings(gadget))
112 return false;
113
da741b8c
DB
114 /* Everything else is *presumably* fine ... but this is a bit
115 * chancy, so be **CERTAIN** there are no hardware issues with
116 * your controller. Add it above if it can't handle CDC.
117 */
118 return true;
119}
120
8a40819e 121/* each configuration may bind one instance of an ethernet link */
d6a01439
SAS
122int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
123 struct eth_dev *dev);
124int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
125 struct eth_dev *dev);
126int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
127 struct eth_dev *dev);
128int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev);
8a40819e 129
396cda90 130#ifdef USB_ETH_RNDIS
45fe3b8e 131
1fbfeff9 132int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
d6a01439 133 u32 vendorID, const char *manufacturer, struct eth_dev *dev);
45fe3b8e
DB
134
135#else
136
137static inline int
1fbfeff9 138rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
d6a01439 139 u32 vendorID, const char *manufacturer, struct eth_dev *dev)
45fe3b8e
DB
140{
141 return 0;
142}
143
144#endif
145
1fbfeff9
BG
146/**
147 * rndis_bind_config - add RNDIS network link to a configuration
148 * @c: the configuration to support the network link
149 * @ethaddr: a buffer in which the ethernet address of the host side
150 * side of the link was recorded
151 * Context: single threaded during gadget setup
152 *
153 * Returns zero on success, else negative errno.
154 *
155 * Caller must have called @gether_setup(). Caller is also responsible
156 * for calling @gether_cleanup() before module unload.
157 */
158static inline int rndis_bind_config(struct usb_configuration *c,
d6a01439 159 u8 ethaddr[ETH_ALEN], struct eth_dev *dev)
1fbfeff9 160{
d6a01439 161 return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev);
1fbfeff9
BG
162}
163
164
2b3d942c 165#endif /* __U_ETHER_H */