On Thu, Apr 11 2013, Andrzej Pietrasiewicz wrote: > When configfs support is added it will be possible to add an unconfigured > interface to the system. This patch adds an interface to u_ether which > makes it possible to create a struct eth_dev filled with default values, > an interface which makes it possible to fill the struct with useful values, > and an interface which makes it possible to read the values set. > > Signed-off-by: Andrzej Pietrasiewicz <[email protected]> > Signed-off-by: Kyungmin Park <[email protected]> > --- > drivers/usb/gadget/u_ether.c | 173 > ++++++++++++++++++++++++++++++++++++++++++ > drivers/usb/gadget/u_ether.h | 101 ++++++++++++++++++++++++ > 2 files changed, 274 insertions(+), 0 deletions(-) > > diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c > index de9d84f..f9b17c8 100644 > --- a/drivers/usb/gadget/u_ether.c > +++ b/drivers/usb/gadget/u_ether.c > @@ -719,6 +719,24 @@ static int get_ether_addr(const char *str, u8 *dev_addr) > return 1; > } > > +static int get_ether_addr_str(u8 dev_addr[ETH_ALEN], char *str, int len) > +{ > + char *s; > + > + if (len < 16)
Shouldn't that be 18?
> + return -EINVAL;
> +
> + hex_dump_to_buffer(dev_addr, ETH_ALEN, 16, 1, str, 20, false);
Ditto.
> + s = str;
> + while (*s) {
> + if (*s == ' ')
> + *s = ':';
> + s++;
> + }
> +
> + return strlen(str);
> +}
static int get_ether_addr_str(u8 dev_addr[ETH_ALEN], char *str, int len)
{
if (len < 18)
return -EINVAL;
sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
dev_addr[0], dev_addr[1], dev_addr[2]
dev_addr[3], dev_addr[4], dev_addr[5]);
return 18;
}
Much shorter.
> @@ -812,6 +830,161 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g,
> }
> EXPORT_SYMBOL(gether_setup_name);
>
> +struct net_device *gether_setup_name_default(const char *netname,
> + u8 ethaddr[ETH_ALEN])
> +{
> + struct net_device *net;
> + struct eth_dev *dev;
> + int status;
> +
> + net = alloc_etherdev(sizeof(*dev));
> + if (!net)
> + return ERR_PTR(-ENOMEM);
> +
> + dev = netdev_priv(net);
> + spin_lock_init(&dev->lock);
> + spin_lock_init(&dev->req_lock);
> + INIT_WORK(&dev->work, eth_work);
> + INIT_LIST_HEAD(&dev->tx_reqs);
> + INIT_LIST_HEAD(&dev->rx_reqs);
> +
> + skb_queue_head_init(&dev->rx_frames);
> +
> + /* network device setup */
> + dev->net = net;
> + dev->qmult = QMULT_DEFAULT;
> + snprintf(net->name, sizeof(net->name), "%s%%d", netname);
> + dev->parent_dev = gadget_sysfs_root;
> +
> + eth_random_addr(net->dev_addr);
> + dev_warn(dev->parent_dev, "using random %s ethernet address\n", "self");
> + eth_random_addr(dev->host_mac);
> + dev_warn(dev->parent_dev, "using random %s ethernet address\n", "host");
> +
> + if (ethaddr)
> + memcpy(ethaddr, dev->host_mac, ETH_ALEN);
> +
> + net->netdev_ops = ð_netdev_ops;
> +
> + SET_ETHTOOL_OPS(net, &ops);
> +
> + SET_NETDEV_DEV(net, dev->parent_dev);
> + SET_NETDEV_DEVTYPE(net, &gadget_type);
> +
> + status = register_netdev(net);
> + if (status < 0) {
> + dev_dbg(dev->parent_dev, "register_netdev failed, %d\n",
> + status);
> + free_netdev(net);
> + dev = ERR_PTR(status);
> + } else {
> + INFO(dev, "MAC %pM\n", net->dev_addr);
> + INFO(dev, "HOST MAC %pM\n", dev->host_mac);
> +
> + /* two kinds of host-initiated state changes:
> + * - iff DATA transfer is active, carrier is "on"
> + * - tx queueing enabled if open *and* carrier is "on"
> + */
Nitpick, but the comment should be:
+ /*
+ * Two kinds of host-initiated state changes:
+ * - iff DATA transfer is active, carrier is "on"
+ * - tx queueing enabled if open *and* carrier is "on"
+ */
> + netif_carrier_off(net);
> + }
> +
> + return net;
> +}
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo--
pgpRT2F7AxHaK.pgp
Description: PGP signature
