blob: 8abf197ab4028be1e9afe2a2e6bc75dbca779970 [file] [log] [blame]
David Brownell2b3d9422008-06-19 18:19:28 -07001/*
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.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __U_ETHER_H
24#define __U_ETHER_H
25
26#include <linux/err.h>
27#include <linux/if_ether.h>
28#include <linux/usb/composite.h>
29#include <linux/usb/cdc.h>
30
David Brownellda741b82008-06-19 18:19:46 -070031#include "gadget_chips.h"
32
33
David Brownell2b3d9422008-06-19 18:19:28 -070034/*
35 * This represents the USB side of an "ethernet" link, managed by a USB
36 * function which provides control and (maybe) framing. Two functions
37 * in different configurations could share the same ethernet link/netdev.
38 *
39 * There is currently a limitation that one instance of this function
40 * may be present in any given configuration.
41 */
42struct gether {
43 struct usb_function func;
44
45 /* updated by gether_{connect,disconnect} */
46 struct eth_dev *ioport;
47
48 /* endpoints handle full and/or high speeds */
49 struct usb_ep *in_ep;
50 struct usb_ep *out_ep;
51
52 /* descriptors match device speed at gether_connect() time */
53 struct usb_endpoint_descriptor *in;
54 struct usb_endpoint_descriptor *out;
55
56 bool is_zlp_ok;
57
58 u16 cdc_filter;
59
60 /* hooks for added framing, as needed for RNDIS and EEM.
61 * we currently don't support multiple frames per SKB.
62 */
63 u32 header_len;
64 struct sk_buff *(*wrap)(struct sk_buff *skb);
65 int (*unwrap)(struct sk_buff *skb);
66
67 /* called on network open/close */
68 void (*open)(struct gether *);
69 void (*close)(struct gether *);
70};
71
72#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
73 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
74 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
75 |USB_CDC_PACKET_TYPE_DIRECTED)
76
77
78/* netdev setup/teardown as directed by the gadget driver */
79int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]);
80void gether_cleanup(void);
81
82/* connect/disconnect is handled by individual functions */
83struct net_device *gether_connect(struct gether *);
84void gether_disconnect(struct gether *);
85
David Brownellda741b82008-06-19 18:19:46 -070086/* Some controllers can't support CDC Ethernet (ECM) ... */
87static inline bool can_support_ecm(struct usb_gadget *gadget)
88{
89 if (!gadget_supports_altsettings(gadget))
90 return false;
91
92 /* SA1100 can do ECM, *without* status endpoint ... but we'll
93 * only use it in non-ECM mode for backwards compatibility
94 * (and since we currently require a status endpoint)
95 */
96 if (gadget_is_sa1100(gadget))
97 return false;
98
99 /* Everything else is *presumably* fine ... but this is a bit
100 * chancy, so be **CERTAIN** there are no hardware issues with
101 * your controller. Add it above if it can't handle CDC.
102 */
103 return true;
104}
105
David Brownell8a408192008-06-19 18:19:32 -0700106/* each configuration may bind one instance of an ethernet link */
107int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
David Brownellda741b82008-06-19 18:19:46 -0700108int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
David Brownell8a408192008-06-19 18:19:32 -0700109
David Brownell2b3d9422008-06-19 18:19:28 -0700110#endif /* __U_ETHER_H */