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 | |
| 24 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 25 | /* |
| 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 Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 28 | * in different configurations could share the same ethernet link/netdev, |
| 29 | * using different host interaction models. |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 30 | * |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 31 | * 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 Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 35 | */ |
| 36 | struct 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 Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 46 | bool is_zlp_ok; |
| 47 | |
| 48 | u16 cdc_filter; |
| 49 | |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 50 | /* hooks for added framing, as needed for RNDIS and EEM. */ |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 51 | u32 header_len; |
Yauheni Kaliuta | 5c1168d | 2010-12-08 13:12:04 +0200 | [diff] [blame] | 52 | /* NCM requires fixed size bundles */ |
| 53 | bool is_fixed; |
| 54 | u32 fixed_out_len; |
| 55 | u32 fixed_in_len; |
Vamsi Krishna | 7f21ac8 | 2013-04-17 21:41:33 -0700 | [diff] [blame] | 56 | |
| 57 | unsigned ul_max_pkts_per_xfer; |
Vijayavardhan Vennapusa | c76dced | 2013-05-27 15:00:52 +0530 | [diff] [blame] | 58 | unsigned dl_max_pkts_per_xfer; |
Mayank Rana | 5b165cb | 2012-05-25 19:52:45 +0530 | [diff] [blame] | 59 | bool multi_pkt_xfer; |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 60 | struct sk_buff *(*wrap)(struct gether *port, |
| 61 | struct sk_buff *skb); |
| 62 | int (*unwrap)(struct gether *port, |
| 63 | struct sk_buff *skb, |
| 64 | struct sk_buff_head *list); |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 65 | |
| 66 | /* called on network open/close */ |
| 67 | void (*open)(struct gether *); |
| 68 | void (*close)(struct gether *); |
Mayank Rana | 9a42ad2 | 2013-09-30 16:51:14 +0530 | [diff] [blame] | 69 | struct rndis_packet_msg_type *header; |
| 70 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \ |
| 74 | |USB_CDC_PACKET_TYPE_ALL_MULTICAST \ |
| 75 | |USB_CDC_PACKET_TYPE_PROMISCUOUS \ |
| 76 | |USB_CDC_PACKET_TYPE_DIRECTED) |
| 77 | |
| 78 | |
| 79 | /* netdev setup/teardown as directed by the gadget driver */ |
| 80 | int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]); |
| 81 | void gether_cleanup(void); |
Mike Lockwood | 735d20e | 2011-08-12 14:35:42 -0700 | [diff] [blame] | 82 | /* variant of gether_setup that allows customizing network device name */ |
| 83 | int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], |
| 84 | const char *netname); |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 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 | |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 96 | /* Everything else is *presumably* fine ... but this is a bit |
| 97 | * chancy, so be **CERTAIN** there are no hardware issues with |
| 98 | * your controller. Add it above if it can't handle CDC. |
| 99 | */ |
| 100 | return true; |
| 101 | } |
| 102 | |
David Brownell | 8a40819 | 2008-06-19 18:19:32 -0700 | [diff] [blame] | 103 | /* each configuration may bind one instance of an ethernet link */ |
| 104 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
David Brownell | da741b8 | 2008-06-19 18:19:46 -0700 | [diff] [blame] | 105 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
Yauheni Kaliuta | 9f6ce42 | 2010-12-08 13:12:05 +0200 | [diff] [blame] | 106 | int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 107 | int eem_bind_config(struct usb_configuration *c); |
David Brownell | 8a40819 | 2008-06-19 18:19:32 -0700 | [diff] [blame] | 108 | |
Michal Nazarewicz | 396cda9 | 2009-11-30 10:55:40 +0100 | [diff] [blame] | 109 | #ifdef USB_ETH_RNDIS |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 110 | |
| 111 | int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); |
Benoit Goby | da8a44a | 2011-12-16 20:00:01 -0800 | [diff] [blame] | 112 | int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
| 113 | u32 vendorID, const char *manufacturer); |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 114 | |
| 115 | #else |
| 116 | |
| 117 | static inline int |
| 118 | rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) |
| 119 | { |
| 120 | return 0; |
| 121 | } |
| 122 | |
Benoit Goby | da8a44a | 2011-12-16 20:00:01 -0800 | [diff] [blame] | 123 | static inline int |
| 124 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
| 125 | u32 vendorID, const char *manufacturer) |
| 126 | { |
| 127 | return 0; |
| 128 | } |
| 129 | |
David Brownell | 45fe3b8 | 2008-06-19 18:20:04 -0700 | [diff] [blame] | 130 | #endif |
| 131 | |
David Brownell | 2b3d942 | 2008-06-19 18:19:28 -0700 | [diff] [blame] | 132 | #endif /* __U_ETHER_H */ |