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. |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 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 | |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 22 | #include "gadget_chips.h" |
| 23 | |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 24 | struct eth_dev; |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 25 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 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 |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 29 | * in different configurations could share the same ethernet link/netdev, |
| 30 | * using different host interaction models. |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 31 | * |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 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. |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 36 | */ |
| 37 | struct 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 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 47 | bool is_zlp_ok; |
| 48 | |
| 49 | u16 cdc_filter; |
| 50 | |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 51 | /* hooks for added framing, as needed for RNDIS and EEM. */ |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 52 | u32 header_len; |
Yauheni Kaliuta | 5c1168d | 2010-12-08 13:12:04 +0200 | [diff] [blame] | 53 | /* NCM requires fixed size bundles */ |
| 54 | bool is_fixed; |
| 55 | u32 fixed_out_len; |
| 56 | u32 fixed_in_len; |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 57 | struct sk_buff *(*wrap)(struct gether *port, |
| 58 | struct sk_buff *skb); |
| 59 | int (*unwrap)(struct gether *port, |
| 60 | struct sk_buff *skb, |
| 61 | struct sk_buff_head *list); |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 62 | |
| 63 | /* called on network open/close */ |
| 64 | void (*open)(struct gether *); |
| 65 | void (*close)(struct gether *); |
| 66 | }; |
| 67 | |
| 68 | #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \ |
| 69 | |USB_CDC_PACKET_TYPE_ALL_MULTICAST \ |
| 70 | |USB_CDC_PACKET_TYPE_PROMISCUOUS \ |
| 71 | |USB_CDC_PACKET_TYPE_DIRECTED) |
| 72 | |
Mike Lockwood | 036e98b | 2012-05-10 10:08:02 +0200 | [diff] [blame] | 73 | /* variant of gether_setup that allows customizing network device name */ |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 74 | struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], |
Mike Lockwood | 036e98b | 2012-05-10 10:08:02 +0200 | [diff] [blame] | 75 | const char *netname); |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 76 | |
| 77 | /* netdev setup/teardown as directed by the gadget driver */ |
Mike Lockwood | 036e98b | 2012-05-10 10:08:02 +0200 | [diff] [blame] | 78 | /* gether_setup - initialize one ethernet-over-usb link |
| 79 | * @g: gadget to associated with these links |
| 80 | * @ethaddr: NULL, or a buffer in which the ethernet address of the |
| 81 | * host side of the link is recorded |
| 82 | * Context: may sleep |
| 83 | * |
| 84 | * This sets up the single network link that may be exported by a |
| 85 | * gadget driver using this framework. The link layer addresses are |
| 86 | * set up using module parameters. |
| 87 | * |
| 88 | * Returns negative errno, or zero on success |
| 89 | */ |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 90 | static inline struct eth_dev *gether_setup(struct usb_gadget *g, |
| 91 | u8 ethaddr[ETH_ALEN]) |
Mike Lockwood | 036e98b | 2012-05-10 10:08:02 +0200 | [diff] [blame] | 92 | { |
| 93 | return gether_setup_name(g, ethaddr, "usb"); |
| 94 | } |
| 95 | |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 96 | void gether_cleanup(struct eth_dev *dev); |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 97 | |
| 98 | /* connect/disconnect is handled by individual functions */ |
| 99 | struct net_device *gether_connect(struct gether *); |
| 100 | void gether_disconnect(struct gether *); |
| 101 | |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 102 | /* Some controllers can't support CDC Ethernet (ECM) ... */ |
| 103 | static inline bool can_support_ecm(struct usb_gadget *gadget) |
| 104 | { |
| 105 | if (!gadget_supports_altsettings(gadget)) |
| 106 | return false; |
| 107 | |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 108 | /* Everything else is *presumably* fine ... but this is a bit |
| 109 | * chancy, so be **CERTAIN** there are no hardware issues with |
| 110 | * your controller. Add it above if it can't handle CDC. |
| 111 | */ |
| 112 | return true; |
| 113 | } |
| 114 | |
David Brownell | 8a40819 | 2008-06-19 18:19:32 -0700 | [diff] [blame] | 115 | /* each configuration may bind one instance of an ethernet link */ |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 116 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
| 117 | struct eth_dev *dev); |
| 118 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
| 119 | struct eth_dev *dev); |
| 120 | int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
| 121 | struct eth_dev *dev); |
| 122 | int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev); |
David Brownell | 8a40819 | 2008-06-19 18:19:32 -0700 | [diff] [blame] | 123 | |
Michal Nazarewicz | 396cda9 | 2009-11-30 10:55:40 +0100 | [diff] [blame] | 124 | #ifdef USB_ETH_RNDIS |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 125 | |
Benoit Goby | 1fbfeff | 2012-05-10 10:08:04 +0200 | [diff] [blame] | 126 | int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 127 | u32 vendorID, const char *manufacturer, struct eth_dev *dev); |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 128 | |
| 129 | #else |
| 130 | |
| 131 | static inline int |
Benoit Goby | 1fbfeff | 2012-05-10 10:08:04 +0200 | [diff] [blame] | 132 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 133 | u32 vendorID, const char *manufacturer, struct eth_dev *dev) |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 134 | { |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | #endif |
| 139 | |
Benoit Goby | 1fbfeff | 2012-05-10 10:08:04 +0200 | [diff] [blame] | 140 | /** |
| 141 | * rndis_bind_config - add RNDIS network link to a configuration |
| 142 | * @c: the configuration to support the network link |
| 143 | * @ethaddr: a buffer in which the ethernet address of the host side |
| 144 | * side of the link was recorded |
| 145 | * Context: single threaded during gadget setup |
| 146 | * |
| 147 | * Returns zero on success, else negative errno. |
| 148 | * |
| 149 | * Caller must have called @gether_setup(). Caller is also responsible |
| 150 | * for calling @gether_cleanup() before module unload. |
| 151 | */ |
| 152 | static inline int rndis_bind_config(struct usb_configuration *c, |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 153 | u8 ethaddr[ETH_ALEN], struct eth_dev *dev) |
Benoit Goby | 1fbfeff | 2012-05-10 10:08:04 +0200 | [diff] [blame] | 154 | { |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 155 | return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev); |
Benoit Goby | 1fbfeff | 2012-05-10 10:08:04 +0200 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 159 | #endif /* __U_ETHER_H */ |