blob: 8012357e98aac343775e8ae6af7b8ec5e5a9114e [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.
David Brownell2b3d9422008-06-19 18:19:28 -070012 */
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
David Brownellda741b82008-06-19 18:19:46 -070022#include "gadget_chips.h"
23
24
David Brownell2b3d9422008-06-19 18:19:28 -070025/*
26 * This represents the USB side of an "ethernet" link, managed by a USB
27 * function which provides control and (maybe) framing. Two functions
David Brownell45fe3b82008-06-19 18:20:04 -070028 * in different configurations could share the same ethernet link/netdev,
29 * using different host interaction models.
David Brownell2b3d9422008-06-19 18:19:28 -070030 *
David Brownell45fe3b82008-06-19 18:20:04 -070031 * There is a current limitation that only one instance of this link may
32 * be present in any given configuration. When that's a problem, network
33 * layer facilities can be used to package multiple logical links on this
34 * single "physical" one.
David Brownell2b3d9422008-06-19 18:19:28 -070035 */
36struct gether {
37 struct usb_function func;
38
39 /* updated by gether_{connect,disconnect} */
40 struct eth_dev *ioport;
41
42 /* endpoints handle full and/or high speeds */
43 struct usb_ep *in_ep;
44 struct usb_ep *out_ep;
45
David Brownell2b3d9422008-06-19 18:19:28 -070046 bool is_zlp_ok;
47
48 u16 cdc_filter;
49
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -050050 /* hooks for added framing, as needed for RNDIS and EEM. */
David Brownell2b3d9422008-06-19 18:19:28 -070051 u32 header_len;
Yauheni Kaliuta5c1168d2010-12-08 13:12:04 +020052 /* NCM requires fixed size bundles */
53 bool is_fixed;
54 u32 fixed_out_len;
55 u32 fixed_in_len;
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -050056 struct sk_buff *(*wrap)(struct gether *port,
57 struct sk_buff *skb);
58 int (*unwrap)(struct gether *port,
59 struct sk_buff *skb,
60 struct sk_buff_head *list);
David Brownell2b3d9422008-06-19 18:19:28 -070061
62 /* called on network open/close */
63 void (*open)(struct gether *);
64 void (*close)(struct gether *);
65};
66
67#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
68 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
69 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
70 |USB_CDC_PACKET_TYPE_DIRECTED)
71
72
73/* netdev setup/teardown as directed by the gadget driver */
74int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]);
75void gether_cleanup(void);
76
77/* connect/disconnect is handled by individual functions */
78struct net_device *gether_connect(struct gether *);
79void gether_disconnect(struct gether *);
80
David Brownellda741b82008-06-19 18:19:46 -070081/* Some controllers can't support CDC Ethernet (ECM) ... */
82static inline bool can_support_ecm(struct usb_gadget *gadget)
83{
84 if (!gadget_supports_altsettings(gadget))
85 return false;
86
David Brownellda741b82008-06-19 18:19:46 -070087 /* Everything else is *presumably* fine ... but this is a bit
88 * chancy, so be **CERTAIN** there are no hardware issues with
89 * your controller. Add it above if it can't handle CDC.
90 */
91 return true;
92}
93
David Brownell8a408192008-06-19 18:19:32 -070094/* each configuration may bind one instance of an ethernet link */
95int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
David Brownellda741b82008-06-19 18:19:46 -070096int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
Yauheni Kaliuta9f6ce422010-12-08 13:12:05 +020097int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -050098int eem_bind_config(struct usb_configuration *c);
David Brownell8a408192008-06-19 18:19:32 -070099
Michal Nazarewicz396cda92009-11-30 10:55:40 +0100100#ifdef USB_ETH_RNDIS
David Brownell45fe3b82008-06-19 18:20:04 -0700101
102int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
103
104#else
105
106static inline int
107rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
108{
109 return 0;
110}
111
112#endif
113
David Brownell2b3d9422008-06-19 18:19:28 -0700114#endif /* __U_ETHER_H */