David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 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. |
| 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 Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 31 | #include "gadget_chips.h" |
| 32 | |
| 33 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 34 | /* |
| 35 | * This represents the USB side of an "ethernet" link, managed by a USB |
| 36 | * function which provides control and (maybe) framing. Two functions |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 37 | * in different configurations could share the same ethernet link/netdev, |
| 38 | * using different host interaction models. |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 39 | * |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 40 | * There is a current limitation that only one instance of this link may |
| 41 | * be present in any given configuration. When that's a problem, network |
| 42 | * layer facilities can be used to package multiple logical links on this |
| 43 | * single "physical" one. |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 44 | */ |
| 45 | struct gether { |
| 46 | struct usb_function func; |
| 47 | |
| 48 | /* updated by gether_{connect,disconnect} */ |
| 49 | struct eth_dev *ioport; |
| 50 | |
| 51 | /* endpoints handle full and/or high speeds */ |
| 52 | struct usb_ep *in_ep; |
| 53 | struct usb_ep *out_ep; |
| 54 | |
| 55 | /* descriptors match device speed at gether_connect() time */ |
| 56 | struct usb_endpoint_descriptor *in; |
| 57 | struct usb_endpoint_descriptor *out; |
| 58 | |
| 59 | bool is_zlp_ok; |
| 60 | |
| 61 | u16 cdc_filter; |
| 62 | |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame^] | 63 | /* hooks for added framing, as needed for RNDIS and EEM. */ |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 64 | u32 header_len; |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame^] | 65 | struct sk_buff *(*wrap)(struct gether *port, |
| 66 | struct sk_buff *skb); |
| 67 | int (*unwrap)(struct gether *port, |
| 68 | struct sk_buff *skb, |
| 69 | struct sk_buff_head *list); |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 70 | |
| 71 | /* called on network open/close */ |
| 72 | void (*open)(struct gether *); |
| 73 | void (*close)(struct gether *); |
| 74 | }; |
| 75 | |
| 76 | #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \ |
| 77 | |USB_CDC_PACKET_TYPE_ALL_MULTICAST \ |
| 78 | |USB_CDC_PACKET_TYPE_PROMISCUOUS \ |
| 79 | |USB_CDC_PACKET_TYPE_DIRECTED) |
| 80 | |
| 81 | |
| 82 | /* netdev setup/teardown as directed by the gadget driver */ |
| 83 | int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]); |
| 84 | void gether_cleanup(void); |
| 85 | |
| 86 | /* connect/disconnect is handled by individual functions */ |
| 87 | struct net_device *gether_connect(struct gether *); |
| 88 | void gether_disconnect(struct gether *); |
| 89 | |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 90 | /* Some controllers can't support CDC Ethernet (ECM) ... */ |
| 91 | static inline bool can_support_ecm(struct usb_gadget *gadget) |
| 92 | { |
| 93 | if (!gadget_supports_altsettings(gadget)) |
| 94 | return false; |
| 95 | |
| 96 | /* SA1100 can do ECM, *without* status endpoint ... but we'll |
| 97 | * only use it in non-ECM mode for backwards compatibility |
| 98 | * (and since we currently require a status endpoint) |
| 99 | */ |
| 100 | if (gadget_is_sa1100(gadget)) |
| 101 | return false; |
| 102 | |
| 103 | /* Everything else is *presumably* fine ... but this is a bit |
| 104 | * chancy, so be **CERTAIN** there are no hardware issues with |
| 105 | * your controller. Add it above if it can't handle CDC. |
| 106 | */ |
| 107 | return true; |
| 108 | } |
| 109 | |
David Brownell | 8a40819 | 2008-06-19 18:19:32 -0700 | [diff] [blame] | 110 | /* each configuration may bind one instance of an ethernet link */ |
| 111 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 112 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame^] | 113 | int eem_bind_config(struct usb_configuration *c); |
David Brownell | 8a40819 | 2008-06-19 18:19:32 -0700 | [diff] [blame] | 114 | |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 115 | #ifdef CONFIG_USB_ETH_RNDIS |
| 116 | |
| 117 | int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
| 118 | |
| 119 | #else |
| 120 | |
| 121 | static inline int |
| 122 | rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) |
| 123 | { |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | #endif |
| 128 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 129 | #endif /* __U_ETHER_H */ |