2020-03-28 19:11:15 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2008-06-20 09:19:28 +08:00
|
|
|
/*
|
|
|
|
* u_ether.h -- interface to USB gadget "ethernet link" utilities
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2005,2008 David Brownell
|
|
|
|
* Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __U_ETHER_H
|
|
|
|
#define __U_ETHER_H
|
|
|
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/usb/composite.h>
|
|
|
|
#include <linux/usb/cdc.h>
|
2014-07-08 01:33:18 +08:00
|
|
|
#include <linux/netdevice.h>
|
2008-06-20 09:19:28 +08:00
|
|
|
|
usb: gadget: u_ether: convert into module
u_ether.c has been #include'd by all gadgets which implement
USB Ethernet functions. In order to add configfs support,
the f_ecm.c, f_eem.c, f_ncm.c, f_subset.c, f_rndis.c need to be
converted into modules and must not be #include'd. Consequently,
the u_ether.c needs to be a module too, in a manner similar
to u_serial.c. The resulting module should not take any parameters,
so they are pushed to the current users of it, that is ether.c,
g_ffs.c, multi.c, ncm.c, nokia.c.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2013-05-23 15:22:03 +08:00
|
|
|
#define QMULT_DEFAULT 5
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dev_addr: initial value
|
|
|
|
* changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx"
|
|
|
|
* host_addr: this address is invisible to ifconfig
|
|
|
|
*/
|
|
|
|
#define USB_ETHERNET_MODULE_PARAMETERS() \
|
|
|
|
static unsigned qmult = QMULT_DEFAULT; \
|
|
|
|
module_param(qmult, uint, S_IRUGO|S_IWUSR); \
|
|
|
|
MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");\
|
|
|
|
\
|
|
|
|
static char *dev_addr; \
|
|
|
|
module_param(dev_addr, charp, S_IRUGO); \
|
|
|
|
MODULE_PARM_DESC(dev_addr, "Device Ethernet Address"); \
|
|
|
|
\
|
|
|
|
static char *host_addr; \
|
|
|
|
module_param(host_addr, charp, S_IRUGO); \
|
|
|
|
MODULE_PARM_DESC(host_addr, "Host Ethernet Address")
|
|
|
|
|
2012-12-24 04:10:12 +08:00
|
|
|
struct eth_dev;
|
2008-06-20 09:19:46 +08:00
|
|
|
|
2008-06-20 09:19:28 +08:00
|
|
|
/*
|
|
|
|
* This represents the USB side of an "ethernet" link, managed by a USB
|
|
|
|
* function which provides control and (maybe) framing. Two functions
|
2008-06-20 09:20:04 +08:00
|
|
|
* in different configurations could share the same ethernet link/netdev,
|
|
|
|
* using different host interaction models.
|
2008-06-20 09:19:28 +08:00
|
|
|
*
|
2008-06-20 09:20:04 +08:00
|
|
|
* There is a current limitation that only one instance of this link may
|
|
|
|
* be present in any given configuration. When that's a problem, network
|
|
|
|
* layer facilities can be used to package multiple logical links on this
|
|
|
|
* single "physical" one.
|
2008-06-20 09:19:28 +08:00
|
|
|
*/
|
|
|
|
struct gether {
|
|
|
|
struct usb_function func;
|
|
|
|
|
|
|
|
/* updated by gether_{connect,disconnect} */
|
|
|
|
struct eth_dev *ioport;
|
|
|
|
|
|
|
|
/* endpoints handle full and/or high speeds */
|
|
|
|
struct usb_ep *in_ep;
|
|
|
|
struct usb_ep *out_ep;
|
|
|
|
|
|
|
|
bool is_zlp_ok;
|
|
|
|
|
|
|
|
u16 cdc_filter;
|
|
|
|
|
2009-08-14 23:04:22 +08:00
|
|
|
/* hooks for added framing, as needed for RNDIS and EEM. */
|
2008-06-20 09:19:28 +08:00
|
|
|
u32 header_len;
|
2010-12-08 19:12:04 +08:00
|
|
|
/* NCM requires fixed size bundles */
|
|
|
|
bool is_fixed;
|
|
|
|
u32 fixed_out_len;
|
|
|
|
u32 fixed_in_len;
|
2014-07-08 01:33:18 +08:00
|
|
|
bool supports_multi_frame;
|
2009-08-14 23:04:22 +08:00
|
|
|
struct sk_buff *(*wrap)(struct gether *port,
|
|
|
|
struct sk_buff *skb);
|
|
|
|
int (*unwrap)(struct gether *port,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
struct sk_buff_head *list);
|
2008-06-20 09:19:28 +08:00
|
|
|
|
|
|
|
/* called on network open/close */
|
|
|
|
void (*open)(struct gether *);
|
|
|
|
void (*close)(struct gether *);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
|
|
|
|
|USB_CDC_PACKET_TYPE_ALL_MULTICAST \
|
|
|
|
|USB_CDC_PACKET_TYPE_PROMISCUOUS \
|
|
|
|
|USB_CDC_PACKET_TYPE_DIRECTED)
|
|
|
|
|
2012-05-10 16:08:02 +08:00
|
|
|
/* variant of gether_setup that allows customizing network device name */
|
usb: gadget: u_ether: convert into module
u_ether.c has been #include'd by all gadgets which implement
USB Ethernet functions. In order to add configfs support,
the f_ecm.c, f_eem.c, f_ncm.c, f_subset.c, f_rndis.c need to be
converted into modules and must not be #include'd. Consequently,
the u_ether.c needs to be a module too, in a manner similar
to u_serial.c. The resulting module should not take any parameters,
so they are pushed to the current users of it, that is ether.c,
g_ffs.c, multi.c, ncm.c, nokia.c.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2013-05-23 15:22:03 +08:00
|
|
|
struct eth_dev *gether_setup_name(struct usb_gadget *g,
|
|
|
|
const char *dev_addr, const char *host_addr,
|
|
|
|
u8 ethaddr[ETH_ALEN], unsigned qmult, const char *netname);
|
2008-06-20 09:19:28 +08:00
|
|
|
|
|
|
|
/* netdev setup/teardown as directed by the gadget driver */
|
2012-05-10 16:08:02 +08:00
|
|
|
/* gether_setup - initialize one ethernet-over-usb link
|
|
|
|
* @g: gadget to associated with these links
|
|
|
|
* @ethaddr: NULL, or a buffer in which the ethernet address of the
|
|
|
|
* host side of the link is recorded
|
|
|
|
* Context: may sleep
|
|
|
|
*
|
|
|
|
* This sets up the single network link that may be exported by a
|
|
|
|
* gadget driver using this framework. The link layer addresses are
|
|
|
|
* set up using module parameters.
|
|
|
|
*
|
2013-11-14 16:42:11 +08:00
|
|
|
* Returns a eth_dev pointer on success, or an ERR_PTR on failure
|
2012-05-10 16:08:02 +08:00
|
|
|
*/
|
2012-12-24 04:10:12 +08:00
|
|
|
static inline struct eth_dev *gether_setup(struct usb_gadget *g,
|
usb: gadget: u_ether: convert into module
u_ether.c has been #include'd by all gadgets which implement
USB Ethernet functions. In order to add configfs support,
the f_ecm.c, f_eem.c, f_ncm.c, f_subset.c, f_rndis.c need to be
converted into modules and must not be #include'd. Consequently,
the u_ether.c needs to be a module too, in a manner similar
to u_serial.c. The resulting module should not take any parameters,
so they are pushed to the current users of it, that is ether.c,
g_ffs.c, multi.c, ncm.c, nokia.c.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2013-05-23 15:22:03 +08:00
|
|
|
const char *dev_addr, const char *host_addr,
|
|
|
|
u8 ethaddr[ETH_ALEN], unsigned qmult)
|
2012-05-10 16:08:02 +08:00
|
|
|
{
|
usb: gadget: u_ether: convert into module
u_ether.c has been #include'd by all gadgets which implement
USB Ethernet functions. In order to add configfs support,
the f_ecm.c, f_eem.c, f_ncm.c, f_subset.c, f_rndis.c need to be
converted into modules and must not be #include'd. Consequently,
the u_ether.c needs to be a module too, in a manner similar
to u_serial.c. The resulting module should not take any parameters,
so they are pushed to the current users of it, that is ether.c,
g_ffs.c, multi.c, ncm.c, nokia.c.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2013-05-23 15:22:03 +08:00
|
|
|
return gether_setup_name(g, dev_addr, host_addr, ethaddr, qmult, "usb");
|
2012-05-10 16:08:02 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 15:22:05 +08:00
|
|
|
/*
|
|
|
|
* variant of gether_setup_default that allows customizing
|
|
|
|
* network device name
|
|
|
|
*/
|
|
|
|
struct net_device *gether_setup_name_default(const char *netname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gether_register_netdev - register the net device
|
|
|
|
* @net: net device to register
|
|
|
|
*
|
|
|
|
* Registers the net device associated with this ethernet-over-usb link
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int gether_register_netdev(struct net_device *net);
|
|
|
|
|
|
|
|
/* gether_setup_default - initialize one ethernet-over-usb link
|
|
|
|
* Context: may sleep
|
|
|
|
*
|
|
|
|
* This sets up the single network link that may be exported by a
|
|
|
|
* gadget driver using this framework. The link layer addresses
|
|
|
|
* are set to random values.
|
|
|
|
*
|
|
|
|
* Returns negative errno, or zero on success
|
|
|
|
*/
|
|
|
|
static inline struct net_device *gether_setup_default(void)
|
|
|
|
{
|
|
|
|
return gether_setup_name_default("usb");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_set_gadget - initialize one ethernet-over-usb link with a gadget
|
|
|
|
* @net: device representing this link
|
|
|
|
* @g: the gadget to initialize with
|
|
|
|
*
|
|
|
|
* This associates one ethernet-over-usb link with a gadget.
|
|
|
|
*/
|
|
|
|
void gether_set_gadget(struct net_device *net, struct usb_gadget *g);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_set_dev_addr - initialize an ethernet-over-usb link with eth address
|
|
|
|
* @net: device representing this link
|
|
|
|
* @dev_addr: eth address of this device
|
|
|
|
*
|
|
|
|
* This sets the device-side Ethernet address of this ethernet-over-usb link
|
|
|
|
* if dev_addr is correct.
|
|
|
|
* Returns negative errno if the new address is incorrect.
|
|
|
|
*/
|
|
|
|
int gether_set_dev_addr(struct net_device *net, const char *dev_addr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_get_dev_addr - get an ethernet-over-usb link eth address
|
|
|
|
* @net: device representing this link
|
|
|
|
* @dev_addr: place to store device's eth address
|
|
|
|
* @len: length of the @dev_addr buffer
|
|
|
|
*
|
|
|
|
* This gets the device-side Ethernet address of this ethernet-over-usb link.
|
|
|
|
* Returns zero on success, else negative errno.
|
|
|
|
*/
|
|
|
|
int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_set_host_addr - initialize an ethernet-over-usb link with host address
|
|
|
|
* @net: device representing this link
|
|
|
|
* @host_addr: eth address of the host
|
|
|
|
*
|
|
|
|
* This sets the host-side Ethernet address of this ethernet-over-usb link
|
|
|
|
* if host_addr is correct.
|
|
|
|
* Returns negative errno if the new address is incorrect.
|
|
|
|
*/
|
|
|
|
int gether_set_host_addr(struct net_device *net, const char *host_addr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_get_host_addr - get an ethernet-over-usb link host address
|
|
|
|
* @net: device representing this link
|
|
|
|
* @host_addr: place to store eth address of the host
|
|
|
|
* @len: length of the @host_addr buffer
|
|
|
|
*
|
|
|
|
* This gets the host-side Ethernet address of this ethernet-over-usb link.
|
|
|
|
* Returns zero on success, else negative errno.
|
|
|
|
*/
|
|
|
|
int gether_get_host_addr(struct net_device *net, char *host_addr, int len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_get_host_addr_cdc - get an ethernet-over-usb link host address
|
|
|
|
* @net: device representing this link
|
|
|
|
* @host_addr: place to store eth address of the host
|
|
|
|
* @len: length of the @host_addr buffer
|
|
|
|
*
|
|
|
|
* This gets the CDC formatted host-side Ethernet address of this
|
|
|
|
* ethernet-over-usb link.
|
|
|
|
* Returns zero on success, else negative errno.
|
|
|
|
*/
|
|
|
|
int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len);
|
|
|
|
|
2013-05-28 15:15:45 +08:00
|
|
|
/**
|
|
|
|
* gether_get_host_addr_u8 - get an ethernet-over-usb link host address
|
|
|
|
* @net: device representing this link
|
|
|
|
* @host_mac: place to store the eth address of the host
|
|
|
|
*
|
|
|
|
* This gets the binary formatted host-side Ethernet address of this
|
|
|
|
* ethernet-over-usb link.
|
|
|
|
*/
|
|
|
|
void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]);
|
|
|
|
|
2013-05-23 15:22:05 +08:00
|
|
|
/**
|
|
|
|
* gether_set_qmult - initialize an ethernet-over-usb link with a multiplier
|
|
|
|
* @net: device representing this link
|
|
|
|
* @qmult: queue multiplier
|
|
|
|
*
|
|
|
|
* This sets the queue length multiplier of this ethernet-over-usb link.
|
|
|
|
* For higher speeds use longer queues.
|
|
|
|
*/
|
|
|
|
void gether_set_qmult(struct net_device *net, unsigned qmult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_get_qmult - get an ethernet-over-usb link multiplier
|
|
|
|
* @net: device representing this link
|
|
|
|
*
|
|
|
|
* This gets the queue length multiplier of this ethernet-over-usb link.
|
|
|
|
*/
|
|
|
|
unsigned gether_get_qmult(struct net_device *net);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gether_get_ifname - get an ethernet-over-usb link interface name
|
|
|
|
* @net: device representing this link
|
|
|
|
* @name: place to store the interface name
|
|
|
|
* @len: length of the @name buffer
|
|
|
|
*
|
|
|
|
* This gets the interface name of this ethernet-over-usb link.
|
|
|
|
* Returns zero on success, else negative errno.
|
|
|
|
*/
|
|
|
|
int gether_get_ifname(struct net_device *net, char *name, int len);
|
|
|
|
|
usb: gadget: u_ether: support configuring interface names.
This patch allows the administrator to configure the interface
name of a function using u_ether (e.g., eem, ncm, rndis).
Currently, all such interfaces, regardless of function type, are
always called usb0, usb1, etc. This makes it very cumbersome to
use more than one such type at a time, because userspace cannnot
easily tell the interfaces apart and apply the right
configuration to each one. Interface renaming in userspace based
on driver doesn't help, because the interfaces all have the same
driver. Without this patch, doing this require hacks/workarounds
such as setting fixed MAC addresses on the functions, and then
renaming by MAC address, or scraping configfs after each
interface is created to find out what it is.
Setting the interface name is done by writing to the same
"ifname" configfs attribute that reports the interface name after
the function is bound. The write must contain an interface
pattern such as "usb%d" (which will cause the net core to pick
the next available interface name starting with "usb").
This patch does not allow writing an exact interface name (as
opposed to a pattern) because if the interface already exists at
bind time, the bind will fail and the whole gadget will fail to
activate. This could be allowed in a future patch.
For compatibility with current userspace, when reading an ifname
that has not currently been set, the result is still "(unnamed
net_device)". Once a write to ifname happens, then reading ifname
will return whatever was last written.
Tested by configuring an rndis function and an ncm function on
the same gadget, and writing "rndis%d" to ifname on the rndis
function and "ncm%d" to ifname on the ncm function. When the
gadget was bound, the rndis interface was rndis0 and the ncm
interface was ncm0.
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
Link: https://lore.kernel.org/r/20210113234222.3272933-1-lorenzo@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-01-14 07:42:22 +08:00
|
|
|
/**
|
|
|
|
* gether_set_ifname - set an ethernet-over-usb link interface name
|
|
|
|
* @net: device representing this link
|
|
|
|
* @name: new interface name
|
|
|
|
* @len: length of @name
|
|
|
|
*
|
|
|
|
* This sets the interface name of this ethernet-over-usb link.
|
|
|
|
* A single terminating newline, if any, is ignored.
|
|
|
|
* Returns zero on success, else negative errno.
|
|
|
|
*/
|
|
|
|
int gether_set_ifname(struct net_device *net, const char *name, int len);
|
|
|
|
|
2012-12-24 04:10:12 +08:00
|
|
|
void gether_cleanup(struct eth_dev *dev);
|
2008-06-20 09:19:28 +08:00
|
|
|
|
|
|
|
/* connect/disconnect is handled by individual functions */
|
|
|
|
struct net_device *gether_connect(struct gether *);
|
|
|
|
void gether_disconnect(struct gether *);
|
|
|
|
|
2008-06-20 09:19:46 +08:00
|
|
|
/* Some controllers can't support CDC Ethernet (ECM) ... */
|
|
|
|
static inline bool can_support_ecm(struct usb_gadget *gadget)
|
|
|
|
{
|
2015-07-28 13:20:03 +08:00
|
|
|
if (!gadget_is_altset_supported(gadget))
|
2008-06-20 09:19:46 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Everything else is *presumably* fine ... but this is a bit
|
|
|
|
* chancy, so be **CERTAIN** there are no hardware issues with
|
|
|
|
* your controller. Add it above if it can't handle CDC.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-20 09:19:28 +08:00
|
|
|
#endif /* __U_ETHER_H */
|