[U-Boot] [PATCH resend v3 0/6] DM conversion of usb ether gadget

The previous series didn't land on the mailing list properly, so resending the series as *v3 resend*, sorry for spamming.
This patch series adopts driver model for usb ether gadget driver. This series is tested with MUSB driver model conversion on AM335x GP evm and AM335x BBB (logs [1]).
Also pushed a branch for testing [2]
Changes from v2: * Moved USB ether address from driver hard code to Kconfig entry * Optimized if check in patch 5/6 as mentioned by Marek Vasut.
Changes from initial version: * Separated out the usb gadget driver patches from earlier musb series [3] for testing and submitting of dwc3 dm musb patches.
[1] - http://pastebin.ubuntu.com/23489333/ [2] - git://git.ti.com/~mugunthanvnm/ti-u-boot/mugunth-ti-u-boot.git dm-musb-v3 [3] - http://lists.denx.de/pipermail/u-boot/2016-February/246827.html
Note: ~~~~~ The following checkpatch warning can be ignored as this has to be fixed all over the file which should be a separate patch. CHECK: Avoid CamelCase: <configNr> #297: FILE: drivers/usb/gadget/rndis.c:1157: +int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
Mugunthan V N (6): drivers: usb: gadget: ether: adopt to usb driver model drivers: usb: gadget: ether: access network_started using local variable drivers: usb: gadget: ether: consolidate global devices to single struct drivers: usb: gadget: ether: use net device priv to pass usb ether priv drivers: usb: gadget: ether: prepare driver for driver model migration drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model
drivers/usb/gadget/Kconfig | 4 + drivers/usb/gadget/ether.c | 315 ++++++++++++++++++++++++++++++++++++--------- drivers/usb/gadget/rndis.c | 13 +- drivers/usb/gadget/rndis.h | 19 ++- include/net.h | 7 + 5 files changed, 293 insertions(+), 65 deletions(-)

Convert usb ether gadget to adopt usb driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org --- drivers/usb/gadget/ether.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 497b981129..9bc61186cf 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -24,6 +24,10 @@ #include "gadget_chips.h" #include "rndis.h"
+#include <dm.h> +#include <dm/uclass-internal.h> +#include <dm/device-internal.h> + #define USB_NET_NAME "usb_ether"
#define atomic_read @@ -101,6 +105,9 @@ struct eth_dev { struct usb_gadget *gadget; struct usb_request *req; /* for control responses */ struct usb_request *stat_req; /* for cdc & rndis status */ +#ifdef CONFIG_DM_USB + struct udevice *usb_udev; +#endif
u8 config; struct usb_ep *in_ep, *out_ep, *status_ep; @@ -2303,6 +2310,24 @@ fail:
/*-------------------------------------------------------------------------*/
+#ifdef CONFIG_DM_USB +int dm_usb_init(struct eth_dev *e_dev) +{ + struct udevice *dev = NULL; + int ret; + + ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev); + if (!dev || ret) { + error("No USB device found\n"); + return -ENODEV; + } + + e_dev->usb_udev = dev; + + return ret; +} +#endif + static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { struct eth_dev *dev = &l_ethdev; @@ -2315,7 +2340,14 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) goto fail; }
+#ifdef CONFIG_DM_USB + if (dm_usb_init(dev)) { + error("USB ether not found\n"); + return -ENODEV; + } +#else board_usb_init(0, USB_INIT_DEVICE); +#endif
/* Configure default mac-addresses for the USB ethernet device */ #ifdef CONFIG_USBNET_DEV_ADDR @@ -2497,7 +2529,11 @@ void usb_eth_halt(struct eth_device *netdev) }
usb_gadget_unregister_driver(ð_driver); +#ifdef CONFIG_DM_USB + device_remove(dev->usb_udev); +#else board_usb_cleanup(0, USB_INIT_DEVICE); +#endif }
static struct usb_gadget_driver eth_driver = {

On Thu, Nov 17, 2016 at 11:19 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Convert usb ether gadget to adopt usb driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Acked-by: Joe Hershberger joe.hershberger@ni.com

On 29 November 2016 at 16:55, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:19 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Convert usb ether gadget to adopt usb driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!

On 12/03/2016 05:26 AM, Simon Glass wrote:
On 29 November 2016 at 16:55, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:19 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Convert usb ether gadget to adopt usb driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!
Did you ever get an ACK on this from the USB gadget maintainer ?

On Sat, Dec 03, 2016 at 01:51:23PM +0100, Marek Vasut wrote:
On 12/03/2016 05:26 AM, Simon Glass wrote:
On 29 November 2016 at 16:55, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:19 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Convert usb ether gadget to adopt usb driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!
Did you ever get an ACK on this from the USB gadget maintainer ?
Well, v2 was posted back in May, so at some point this falls into the category of "has been reviewed by someone other than author, in public, move forward not stall time!".

On 12/03/2016 07:27 PM, Tom Rini wrote:
On Sat, Dec 03, 2016 at 01:51:23PM +0100, Marek Vasut wrote:
On 12/03/2016 05:26 AM, Simon Glass wrote:
On 29 November 2016 at 16:55, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:19 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Convert usb ether gadget to adopt usb driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!
Did you ever get an ACK on this from the USB gadget maintainer ?
Well, v2 was posted back in May, so at some point this falls into the category of "has been reviewed by someone other than author, in public, move forward not stall time!".
It might be a good start to CC the maintainer ;-) I poked him on jabber ...

network_started of struct eth_dev can be accessed using local variable dev and no reason to access it with the global struct.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org --- drivers/usb/gadget/ether.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 9bc61186cf..71d9252f74 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1142,7 +1142,7 @@ static void eth_status_complete(struct usb_ep *ep, struct usb_request *req) event->bNotificationType, value); if (event->bNotificationType == USB_CDC_NOTIFY_SPEED_CHANGE) { - l_ethdev.network_started = 1; + dev->network_started = 1; printf("USB network up!\n"); } } @@ -1330,7 +1330,7 @@ eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) * that network is working. So we signalize it * here. */ - l_ethdev.network_started = 1; + dev->network_started = 1; debug("USB network up!\n"); goto done_set_intf; } @@ -1830,10 +1830,10 @@ static void rndis_control_ack_complete(struct usb_ep *ep, debug("rndis control ack complete --> %d, %d/%d\n", req->status, req->actual, req->length);
- if (!l_ethdev.network_started) { + if (!dev->network_started) { if (rndis_get_state(dev->rndis_config) == RNDIS_DATA_INITIALIZED) { - l_ethdev.network_started = 1; + dev->network_started = 1; printf("USB RNDIS network up!\n"); } } @@ -2389,7 +2389,7 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) timeout = simple_strtoul(getenv("cdc_connect_timeout"), NULL, 10) * CONFIG_SYS_HZ; ts = get_timer(0); - while (!l_ethdev.network_started) { + while (!dev->network_started) { /* Handle control-c and timeouts */ if (ctrlc() || (get_timer(ts) > timeout)) { error("The remote end did not respond in time.");

On Thu, Nov 17, 2016 at 11:19 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
network_started of struct eth_dev can be accessed using local variable dev and no reason to access it with the global struct.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
Acked-by: Joe Hershberger joe.hershberger@ni.com

On 29 November 2016 at 16:20, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:19 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
network_started of struct eth_dev can be accessed using local variable dev and no reason to access it with the global struct.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!

Consolidate the net device, usb eth device and gadget device struct to single struct and a single global variable so that the same can be passed as priv of ethernet driver.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org --- drivers/usb/gadget/ether.c | 53 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 71d9252f74..16edeead65 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -141,9 +141,14 @@ struct eth_dev { */
/*-------------------------------------------------------------------------*/ -static struct eth_dev l_ethdev; -static struct eth_device l_netdev; -static struct usb_gadget_driver eth_driver; +struct ether_priv { + struct eth_dev ethdev; + struct eth_device netdev; + struct usb_gadget_driver eth_driver; +}; + +struct ether_priv eth_priv; +struct ether_priv *l_priv = ð_priv;
/*-------------------------------------------------------------------------*/
@@ -1848,7 +1853,7 @@ static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
static int rndis_control_ack(struct eth_device *net) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; int length; struct usb_request *resp = dev->stat_req;
@@ -1989,7 +1994,7 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
static int eth_bind(struct usb_gadget *gadget) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; u8 cdc = 1, zlp = 1, rndis = 1; struct usb_ep *in_ep, *out_ep, *status_ep = NULL; int status = -ENOMEM; @@ -2182,7 +2187,7 @@ autoconf_fail:
/* network device setup */ - dev->net = &l_netdev; + dev->net = &l_priv->netdev;
dev->cdc = cdc; dev->zlp = zlp; @@ -2330,7 +2335,7 @@ int dm_usb_init(struct eth_dev *e_dev)
static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; struct usb_gadget *gadget; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT; @@ -2374,7 +2379,15 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) goto fail; }
- if (usb_gadget_register_driver(ð_driver) < 0) + l_priv->eth_driver.speed = DEVSPEED; + l_priv->eth_driver.bind = eth_bind; + l_priv->eth_driver.unbind = eth_unbind; + l_priv->eth_driver.setup = eth_setup; + l_priv->eth_driver.reset = eth_disconnect; + l_priv->eth_driver.disconnect = eth_disconnect; + l_priv->eth_driver.suspend = eth_suspend; + l_priv->eth_driver.resume = eth_resume; + if (usb_gadget_register_driver(&l_priv->eth_driver) < 0) goto fail;
dev->network_started = 0; @@ -2409,7 +2422,7 @@ static int usb_eth_send(struct eth_device *netdev, void *packet, int length) { int retval; void *rndis_pkt = NULL; - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; struct usb_request *req = dev->tx_req; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT; @@ -2476,7 +2489,7 @@ drop:
static int usb_eth_recv(struct eth_device *netdev) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev;
usb_gadget_handle_interrupts(0);
@@ -2496,7 +2509,7 @@ static int usb_eth_recv(struct eth_device *netdev)
void usb_eth_halt(struct eth_device *netdev) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev;
if (!netdev) { error("received NULL ptr"); @@ -2528,7 +2541,7 @@ void usb_eth_halt(struct eth_device *netdev) dev->network_started = 0; }
- usb_gadget_unregister_driver(ð_driver); + usb_gadget_unregister_driver(&l_priv->eth_driver); #ifdef CONFIG_DM_USB device_remove(dev->usb_udev); #else @@ -2536,23 +2549,9 @@ void usb_eth_halt(struct eth_device *netdev) #endif }
-static struct usb_gadget_driver eth_driver = { - .speed = DEVSPEED, - - .bind = eth_bind, - .unbind = eth_unbind, - - .setup = eth_setup, - .reset = eth_disconnect, - .disconnect = eth_disconnect, - - .suspend = eth_suspend, - .resume = eth_resume, -}; - int usb_eth_initialize(bd_t *bi) { - struct eth_device *netdev = &l_netdev; + struct eth_device *netdev = &l_priv->netdev;
strlcpy(netdev->name, USB_NET_NAME, sizeof(netdev->name));

On Thu, Nov 17, 2016 at 11:36 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Consolidate the net device, usb eth device and gadget device struct to single struct and a single global variable so that the same can be passed as priv of ethernet driver.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
Acked-by: Joe Hershberger joe.hershberger@ni.com

On 29 November 2016 at 16:55, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:36 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Consolidate the net device, usb eth device and gadget device struct to single struct and a single global variable so that the same can be passed as priv of ethernet driver.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!

Use net device priv to pass usb ether priv and use it in net device ops callback.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org --- drivers/usb/gadget/ether.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 16edeead65..54b8b59b29 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1853,7 +1853,8 @@ static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
static int rndis_control_ack(struct eth_device *net) { - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)net->priv; + struct eth_dev *dev = &priv->ethdev; int length; struct usb_request *resp = dev->stat_req;
@@ -2335,16 +2336,12 @@ int dm_usb_init(struct eth_dev *e_dev)
static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev; struct usb_gadget *gadget; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT;
- if (!netdev) { - error("received NULL ptr"); - goto fail; - } - #ifdef CONFIG_DM_USB if (dm_usb_init(dev)) { error("USB ether not found\n"); @@ -2379,15 +2376,15 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) goto fail; }
- l_priv->eth_driver.speed = DEVSPEED; - l_priv->eth_driver.bind = eth_bind; - l_priv->eth_driver.unbind = eth_unbind; - l_priv->eth_driver.setup = eth_setup; - l_priv->eth_driver.reset = eth_disconnect; - l_priv->eth_driver.disconnect = eth_disconnect; - l_priv->eth_driver.suspend = eth_suspend; - l_priv->eth_driver.resume = eth_resume; - if (usb_gadget_register_driver(&l_priv->eth_driver) < 0) + priv->eth_driver.speed = DEVSPEED; + priv->eth_driver.bind = eth_bind; + priv->eth_driver.unbind = eth_unbind; + priv->eth_driver.setup = eth_setup; + priv->eth_driver.reset = eth_disconnect; + priv->eth_driver.disconnect = eth_disconnect; + priv->eth_driver.suspend = eth_suspend; + priv->eth_driver.resume = eth_resume; + if (usb_gadget_register_driver(&priv->eth_driver) < 0) goto fail;
dev->network_started = 0; @@ -2422,7 +2419,8 @@ static int usb_eth_send(struct eth_device *netdev, void *packet, int length) { int retval; void *rndis_pkt = NULL; - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev; struct usb_request *req = dev->tx_req; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT; @@ -2489,7 +2487,8 @@ drop:
static int usb_eth_recv(struct eth_device *netdev) { - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev;
usb_gadget_handle_interrupts(0);
@@ -2509,12 +2508,8 @@ static int usb_eth_recv(struct eth_device *netdev)
void usb_eth_halt(struct eth_device *netdev) { - struct eth_dev *dev = &l_priv->ethdev; - - if (!netdev) { - error("received NULL ptr"); - return; - } + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev;
/* If the gadget not registered, simple return */ if (!dev->gadget) @@ -2541,7 +2536,7 @@ void usb_eth_halt(struct eth_device *netdev) dev->network_started = 0; }
- usb_gadget_unregister_driver(&l_priv->eth_driver); + usb_gadget_unregister_driver(&priv->eth_driver); #ifdef CONFIG_DM_USB device_remove(dev->usb_udev); #else @@ -2559,6 +2554,7 @@ int usb_eth_initialize(bd_t *bi) netdev->send = usb_eth_send; netdev->recv = usb_eth_recv; netdev->halt = usb_eth_halt; + netdev->priv = l_priv;
#ifdef CONFIG_MCAST_TFTP #error not supported

On Thu, Nov 17, 2016 at 11:37 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Use net device priv to pass usb ether priv and use it in net device ops callback.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
Acked-by: Joe Hershberger joe.hershberger@ni.com

On 29 November 2016 at 16:55, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:37 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Use net device priv to pass usb ether priv and use it in net device ops callback.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!

prepare driver for driver model migration
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/ether.c | 73 +++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 54b8b59b29..046ad8ca2b 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -2334,9 +2334,8 @@ int dm_usb_init(struct eth_dev *e_dev) } #endif
-static int usb_eth_init(struct eth_device *netdev, bd_t *bd) +static int _usb_eth_init(struct ether_priv *priv) { - struct ether_priv *priv = (struct ether_priv *)netdev->priv; struct eth_dev *dev = &priv->ethdev; struct usb_gadget *gadget; unsigned long ts; @@ -2415,11 +2414,10 @@ fail: return -1; }
-static int usb_eth_send(struct eth_device *netdev, void *packet, int length) +static int _usb_eth_send(struct ether_priv *priv, void *packet, int length) { int retval; void *rndis_pkt = NULL; - struct ether_priv *priv = (struct ether_priv *)netdev->priv; struct eth_dev *dev = &priv->ethdev; struct usb_request *req = dev->tx_req; unsigned long ts; @@ -2485,30 +2483,15 @@ drop: return -ENOMEM; }
-static int usb_eth_recv(struct eth_device *netdev) +static int _usb_eth_recv(struct ether_priv *priv) { - struct ether_priv *priv = (struct ether_priv *)netdev->priv; - struct eth_dev *dev = &priv->ethdev; - usb_gadget_handle_interrupts(0);
- if (packet_received) { - debug("%s: packet received\n", __func__); - if (dev->rx_req) { - net_process_received_packet(net_rx_packets[0], - dev->rx_req->length); - packet_received = 0; - - rx_submit(dev, dev->rx_req, 0); - } else - error("dev->rx_req invalid"); - } return 0; }
-void usb_eth_halt(struct eth_device *netdev) +void _usb_eth_halt(struct ether_priv *priv) { - struct ether_priv *priv = (struct ether_priv *)netdev->priv; struct eth_dev *dev = &priv->ethdev;
/* If the gadget not registered, simple return */ @@ -2544,6 +2527,54 @@ void usb_eth_halt(struct eth_device *netdev) #endif }
+static int usb_eth_init(struct eth_device *netdev, bd_t *bd) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + + return _usb_eth_init(priv); +} + +static int usb_eth_send(struct eth_device *netdev, void *packet, int length) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + + return _usb_eth_send(priv, packet, length); +} + +static int usb_eth_recv(struct eth_device *netdev) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev; + int ret; + + ret = _usb_eth_recv(priv); + if (ret) { + error("error packet receive\n"); + return ret; + } + + if (!packet_received) + return 0; + + if (dev->rx_req) { + net_process_received_packet(net_rx_packets[0], + dev->rx_req->length); + } else { + error("dev->rx_req invalid"); + } + packet_received = 0; + rx_submit(dev, dev->rx_req, 0); + + return 0; +} + +void usb_eth_halt(struct eth_device *netdev) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + + _usb_eth_halt(priv); +} + int usb_eth_initialize(bd_t *bi) { struct eth_device *netdev = &l_priv->netdev;

On Thu, Nov 17, 2016 at 11:38 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
prepare driver for driver model migration
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Acked-by: Joe Hershberger joe.hershberger@ni.com

On 29 November 2016 at 16:55, Joe Hershberger joe.hershberger@gmail.com wrote:
On Thu, Nov 17, 2016 at 11:38 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
prepare driver for driver model migration
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Acked-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot-dm, thanks!

Adopt usb ether gadget and rndis driver to adopt driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/Kconfig | 4 ++ drivers/usb/gadget/ether.c | 153 ++++++++++++++++++++++++++++++++++++++++++--- drivers/usb/gadget/rndis.c | 13 +++- drivers/usb/gadget/rndis.h | 19 ++++-- include/net.h | 7 +++ 5 files changed, 181 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 40839d89e9..261ed128ac 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -112,6 +112,10 @@ config G_DNL_VENDOR_NUM config G_DNL_PRODUCT_NUM hex "Product ID of USB device"
+config USBNET_DEVADDR + string "USB Gadget Ethernet device mac address" + default "de:ad:be:ef:00:01" + endif # USB_GADGET_DOWNLOAD
endif # USB_GADGET diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 046ad8ca2b..8c3c3fd9ab 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -25,6 +25,7 @@ #include "rndis.h"
#include <dm.h> +#include <dm/lists.h> #include <dm/uclass-internal.h> #include <dm/device-internal.h>
@@ -116,7 +117,11 @@ struct eth_dev {
struct usb_request *tx_req, *rx_req;
+#ifndef CONFIG_DM_ETH struct eth_device *net; +#else + struct udevice *net; +#endif struct net_device_stats stats; unsigned int tx_qlen;
@@ -143,7 +148,11 @@ struct eth_dev { /*-------------------------------------------------------------------------*/ struct ether_priv { struct eth_dev ethdev; +#ifndef CONFIG_DM_ETH struct eth_device netdev; +#else + struct udevice *netdev; +#endif struct usb_gadget_driver eth_driver; };
@@ -1851,7 +1860,11 @@ static void rndis_control_ack_complete(struct usb_ep *ep,
static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
+#ifndef CONFIG_DM_ETH static int rndis_control_ack(struct eth_device *net) +#else +static int rndis_control_ack(struct udevice *net) +#endif { struct ether_priv *priv = (struct ether_priv *)net->priv; struct eth_dev *dev = &priv->ethdev; @@ -2001,6 +2014,9 @@ static int eth_bind(struct usb_gadget *gadget) int status = -ENOMEM; int gcnum; u8 tmp[7]; +#ifdef CONFIG_DM_ETH + struct eth_pdata *pdata = dev_get_platdata(l_priv->netdev); +#endif
/* these flags are only ever cleared; compiler take note */ #ifndef CONFIG_USB_ETH_CDC @@ -2188,7 +2204,11 @@ autoconf_fail:
/* network device setup */ +#ifndef CONFIG_DM_ETH dev->net = &l_priv->netdev; +#else + dev->net = l_priv->netdev; +#endif
dev->cdc = cdc; dev->zlp = zlp; @@ -2197,6 +2217,7 @@ autoconf_fail: dev->out_ep = out_ep; dev->status_ep = status_ep;
+ memset(tmp, 0, sizeof(tmp)); /* * Module params for these addresses should come from ID proms. * The host side address is used with CDC and RNDIS, and commonly @@ -2204,10 +2225,13 @@ autoconf_fail: * host side code for the SAFE thing cares -- its original BLAN * thing didn't, Sharp never assigned those addresses on Zaurii. */ +#ifndef CONFIG_DM_ETH get_ether_addr(dev_addr, dev->net->enetaddr); - - memset(tmp, 0, sizeof(tmp)); memcpy(tmp, dev->net->enetaddr, sizeof(dev->net->enetaddr)); +#else + get_ether_addr(dev_addr, pdata->enetaddr); + memcpy(tmp, pdata->enetaddr, sizeof(pdata->enetaddr)); +#endif
get_ether_addr(host_addr, dev->host_mac);
@@ -2268,10 +2292,11 @@ autoconf_fail: status_ep ? " STATUS " : "", status_ep ? status_ep->name : "" ); - printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\n", - dev->net->enetaddr[0], dev->net->enetaddr[1], - dev->net->enetaddr[2], dev->net->enetaddr[3], - dev->net->enetaddr[4], dev->net->enetaddr[5]); +#ifndef CONFIG_DM_ETH + printf("MAC %pM\n", dev->net->enetaddr); +#else + printf("MAC %pM\n", pdata->enetaddr); +#endif
if (cdc || rndis) printf("HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n", @@ -2520,13 +2545,12 @@ void _usb_eth_halt(struct ether_priv *priv) }
usb_gadget_unregister_driver(&priv->eth_driver); -#ifdef CONFIG_DM_USB - device_remove(dev->usb_udev); -#else +#ifndef CONFIG_DM_USB board_usb_cleanup(0, USB_INIT_DEVICE); #endif }
+#ifndef CONFIG_DM_ETH static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { struct ether_priv *priv = (struct ether_priv *)netdev->priv; @@ -2593,3 +2617,114 @@ int usb_eth_initialize(bd_t *bi) eth_register(netdev); return 0; } +#else +static int usb_eth_start(struct udevice *dev) +{ + struct ether_priv *priv = dev_get_priv(dev); + + return _usb_eth_init(priv); +} + +static int usb_eth_send(struct udevice *dev, void *packet, int length) +{ + struct ether_priv *priv = dev_get_priv(dev); + + return _usb_eth_send(priv, packet, length); +} + +static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp) +{ + struct ether_priv *priv = dev_get_priv(dev); + struct eth_dev *ethdev = &priv->ethdev; + int ret; + + ret = _usb_eth_recv(priv); + if (ret) { + error("error packet receive\n"); + return ret; + } + + if (packet_received) { + if (ethdev->rx_req) { + *packetp = (uchar *)net_rx_packets[0]; + return ethdev->rx_req->length; + } else { + error("dev->rx_req invalid"); + return -EFAULT; + } + } + + return -EAGAIN; +} + +static int usb_eth_free_pkt(struct udevice *dev, uchar *packet, + int length) +{ + struct ether_priv *priv = dev_get_priv(dev); + struct eth_dev *ethdev = &priv->ethdev; + + packet_received = 0; + + return rx_submit(ethdev, ethdev->rx_req, 0); +} + +static void usb_eth_stop(struct udevice *dev) +{ + struct ether_priv *priv = dev_get_priv(dev); + + _usb_eth_halt(priv); +} + +static int usb_eth_probe(struct udevice *dev) +{ + struct ether_priv *priv = dev_get_priv(dev); + struct eth_pdata *pdata = dev_get_platdata(dev); + + priv->netdev = dev; + l_priv = priv; + + get_ether_addr(CONFIG_USBNET_DEVADDR, pdata->enetaddr); + eth_setenv_enetaddr("usbnet_devaddr", pdata->enetaddr); + + return 0; +} + +static const struct eth_ops usb_eth_ops = { + .start = usb_eth_start, + .send = usb_eth_send, + .recv = usb_eth_recv, + .free_pkt = usb_eth_free_pkt, + .stop = usb_eth_stop, +}; + +int usb_ether_init(void) +{ + struct udevice *dev; + struct udevice *usb_dev; + int ret; + + ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &usb_dev); + if (!usb_dev || ret) { + error("No USB device found\n"); + return ret; + } + + ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", &dev); + if (!dev || ret) { + error("usb - not able to bind usb_ether device\n"); + return ret; + } + + return 0; +} + +U_BOOT_DRIVER(eth_usb) = { + .name = "usb_ether", + .id = UCLASS_ETH, + .probe = usb_eth_probe, + .ops = &usb_eth_ops, + .priv_auto_alloc_size = sizeof(struct ether_priv), + .platdata_auto_alloc_size = sizeof(struct eth_pdata), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +}; +#endif /* CONFIG_DM_ETH */ diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 844a0c7236..5ad481302b 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c @@ -1121,7 +1121,11 @@ int rndis_msg_parser(u8 configNr, u8 *buf) return -ENOTSUPP; }
+#ifndef CONFIG_DM_ETH int rndis_register(int (*rndis_control_ack)(struct eth_device *)) +#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)) +#endif { u8 i;
@@ -1149,8 +1153,13 @@ void rndis_deregister(int configNr) return; }
-int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, - struct net_device_stats *stats, u16 *cdc_filter) +#ifndef CONFIG_DM_ETH +int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, + struct net_device_stats *stats, u16 *cdc_filter) +#else +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu, + struct net_device_stats *stats, u16 *cdc_filter) +#endif { debug("%s: configNr = %d\n", __func__, configNr); if (!dev || !stats) diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index 7a389a580a..084af8541c 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h @@ -222,23 +222,34 @@ typedef struct rndis_params {
const u8 *host_mac; u16 *filter; - struct eth_device *dev; struct net_device_stats *stats; int mtu;
u32 vendorID; const char *vendorDescr; - int (*ack)(struct eth_device *); +#ifndef CONFIG_DM_ETH + struct eth_device *dev; + int (*ack)(struct eth_device *); +#else + struct udevice *dev; + int (*ack)(struct udevice *); +#endif struct list_head resp_queue; } rndis_params;
/* RNDIS Message parser and other useless functions */ int rndis_msg_parser(u8 configNr, u8 *buf); enum rndis_state rndis_get_state(int configNr); -int rndis_register(int (*rndis_control_ack)(struct eth_device *)); void rndis_deregister(int configNr); +#ifndef CONFIG_DM_ETH +int rndis_register(int (*rndis_control_ack)(struct eth_device *)); int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, - struct net_device_stats *stats, u16 *cdc_filter); + struct net_device_stats *stats, u16 *cdc_filter); +#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)); +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu, + struct net_device_stats *stats, u16 *cdc_filter); +#endif int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr); int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed); diff --git a/include/net.h b/include/net.h index 06320c6514..1f4d947350 100644 --- a/include/net.h +++ b/include/net.h @@ -255,6 +255,13 @@ int eth_setenv_enetaddr_by_index(const char *base_name, int index,
/* + * Initialize USB ethernet device with CONFIG_DM_ETH + * Returns: + * 0 is success, non-zero is error status. + */ +int usb_ether_init(void); + +/* * Get the hardware address for an ethernet interface . * Args: * base_name - base name for device (normally "eth")

On Thu, Nov 17, 2016 at 11:39 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Adopt usb ether gadget and rndis driver to adopt driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
drivers/usb/gadget/Kconfig | 4 ++ drivers/usb/gadget/ether.c | 153 ++++++++++++++++++++++++++++++++++++++++++--- drivers/usb/gadget/rndis.c | 13 +++- drivers/usb/gadget/rndis.h | 19 ++++-- include/net.h | 7 +++ 5 files changed, 181 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 40839d89e9..261ed128ac 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -112,6 +112,10 @@ config G_DNL_VENDOR_NUM config G_DNL_PRODUCT_NUM hex "Product ID of USB device"
+config USBNET_DEVADDR
string "USB Gadget Ethernet device mac address"
default "de:ad:be:ef:00:01"
Please don't do this. We don't have "default" MAC addresses. They are either from the env, from ROM, or randomly generated.
endif # USB_GADGET_DOWNLOAD
endif # USB_GADGET diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 046ad8ca2b..8c3c3fd9ab 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -25,6 +25,7 @@ #include "rndis.h"
#include <dm.h> +#include <dm/lists.h> #include <dm/uclass-internal.h> #include <dm/device-internal.h>
@@ -116,7 +117,11 @@ struct eth_dev {
struct usb_request *tx_req, *rx_req;
+#ifndef CONFIG_DM_ETH
Please use positive logic.
struct eth_device *net;
+#else
struct udevice *net;
+#endif struct net_device_stats stats; unsigned int tx_qlen;
@@ -143,7 +148,11 @@ struct eth_dev { /*-------------------------------------------------------------------------*/ struct ether_priv { struct eth_dev ethdev; +#ifndef CONFIG_DM_ETH
Please use positive logic
struct eth_device netdev;
+#else
struct udevice *netdev;
Did you really intend to have a pointer here when the other is an inline structure?
+#endif struct usb_gadget_driver eth_driver; };
@@ -1851,7 +1860,11 @@ static void rndis_control_ack_complete(struct usb_ep *ep,
static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
+#ifndef CONFIG_DM_ETH
Please use positive logic.
static int rndis_control_ack(struct eth_device *net) +#else +static int rndis_control_ack(struct udevice *net) +#endif { struct ether_priv *priv = (struct ether_priv *)net->priv; struct eth_dev *dev = &priv->ethdev; @@ -2001,6 +2014,9 @@ static int eth_bind(struct usb_gadget *gadget) int status = -ENOMEM; int gcnum; u8 tmp[7]; +#ifdef CONFIG_DM_ETH
struct eth_pdata *pdata = dev_get_platdata(l_priv->netdev);
+#endif
/* these flags are only ever cleared; compiler take note */
#ifndef CONFIG_USB_ETH_CDC @@ -2188,7 +2204,11 @@ autoconf_fail:
/* network device setup */
+#ifndef CONFIG_DM_ETH dev->net = &l_priv->netdev;
You wouldn't need this difference if the priv also used a ptr in the non-dm case.
Also, if you are opposed to cleaning this up (preferably by adding a preceding patch to make it a pointer), at least use positive logic (#ifdef CONFIG_DM_ETH). Same applies elsewhere.
+#else
dev->net = l_priv->netdev;
+#endif
dev->cdc = cdc; dev->zlp = zlp;
@@ -2197,6 +2217,7 @@ autoconf_fail: dev->out_ep = out_ep; dev->status_ep = status_ep;
memset(tmp, 0, sizeof(tmp)); /* * Module params for these addresses should come from ID proms. * The host side address is used with CDC and RNDIS, and commonly
@@ -2204,10 +2225,13 @@ autoconf_fail: * host side code for the SAFE thing cares -- its original BLAN * thing didn't, Sharp never assigned those addresses on Zaurii. */ +#ifndef CONFIG_DM_ETH get_ether_addr(dev_addr, dev->net->enetaddr);
memset(tmp, 0, sizeof(tmp)); memcpy(tmp, dev->net->enetaddr, sizeof(dev->net->enetaddr));
+#else
get_ether_addr(dev_addr, pdata->enetaddr);
memcpy(tmp, pdata->enetaddr, sizeof(pdata->enetaddr));
+#endif
get_ether_addr(host_addr, dev->host_mac);
@@ -2268,10 +2292,11 @@ autoconf_fail: status_ep ? " STATUS " : "", status_ep ? status_ep->name : "" );
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
dev->net->enetaddr[0], dev->net->enetaddr[1],
dev->net->enetaddr[2], dev->net->enetaddr[3],
dev->net->enetaddr[4], dev->net->enetaddr[5]);
+#ifndef CONFIG_DM_ETH
printf("MAC %pM\n", dev->net->enetaddr);
+#else
printf("MAC %pM\n", pdata->enetaddr);
+#endif
if (cdc || rndis) printf("HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
@@ -2520,13 +2545,12 @@ void _usb_eth_halt(struct ether_priv *priv) }
usb_gadget_unregister_driver(&priv->eth_driver);
-#ifdef CONFIG_DM_USB
device_remove(dev->usb_udev);
Why is this not needed anymore?
-#else +#ifndef CONFIG_DM_USB board_usb_cleanup(0, USB_INIT_DEVICE); #endif }
+#ifndef CONFIG_DM_ETH static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { struct ether_priv *priv = (struct ether_priv *)netdev->priv; @@ -2593,3 +2617,114 @@ int usb_eth_initialize(bd_t *bi) eth_register(netdev); return 0; } +#else +static int usb_eth_start(struct udevice *dev) +{
struct ether_priv *priv = dev_get_priv(dev);
return _usb_eth_init(priv);
+}
+static int usb_eth_send(struct udevice *dev, void *packet, int length) +{
struct ether_priv *priv = dev_get_priv(dev);
return _usb_eth_send(priv, packet, length);
+}
+static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp) +{
struct ether_priv *priv = dev_get_priv(dev);
struct eth_dev *ethdev = &priv->ethdev;
int ret;
ret = _usb_eth_recv(priv);
if (ret) {
error("error packet receive\n");
return ret;
}
if (packet_received) {
if (ethdev->rx_req) {
*packetp = (uchar *)net_rx_packets[0];
return ethdev->rx_req->length;
} else {
error("dev->rx_req invalid");
return -EFAULT;
}
}
return -EAGAIN;
+}
+static int usb_eth_free_pkt(struct udevice *dev, uchar *packet,
int length)
+{
struct ether_priv *priv = dev_get_priv(dev);
struct eth_dev *ethdev = &priv->ethdev;
packet_received = 0;
return rx_submit(ethdev, ethdev->rx_req, 0);
+}
+static void usb_eth_stop(struct udevice *dev) +{
struct ether_priv *priv = dev_get_priv(dev);
_usb_eth_halt(priv);
+}
+static int usb_eth_probe(struct udevice *dev) +{
struct ether_priv *priv = dev_get_priv(dev);
struct eth_pdata *pdata = dev_get_platdata(dev);
priv->netdev = dev;
l_priv = priv;
get_ether_addr(CONFIG_USBNET_DEVADDR, pdata->enetaddr);
This function it just a separately implemented copy of other functions the net stack already provides. Assuming you should be manipulating the MAC addresses from some string at all, at least it should be using eth_parse_enetaddr().
eth_setenv_enetaddr("usbnet_devaddr", pdata->enetaddr);
This means that it will always clobber user's env. That's no good. Also, UCLASS_ETH already deals with mac address names for USB NICs as just another ethaddr, not a special usbnet name. Why not let that work?
return 0;
+}
+static const struct eth_ops usb_eth_ops = {
.start = usb_eth_start,
.send = usb_eth_send,
.recv = usb_eth_recv,
.free_pkt = usb_eth_free_pkt,
.stop = usb_eth_stop,
+};
+int usb_ether_init(void) +{
struct udevice *dev;
struct udevice *usb_dev;
int ret;
ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &usb_dev);
if (!usb_dev || ret) {
error("No USB device found\n");
return ret;
}
ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", &dev);
if (!dev || ret) {
error("usb - not able to bind usb_ether device\n");
return ret;
}
return 0;
+}
+U_BOOT_DRIVER(eth_usb) = {
.name = "usb_ether",
.id = UCLASS_ETH,
.probe = usb_eth_probe,
.ops = &usb_eth_ops,
.priv_auto_alloc_size = sizeof(struct ether_priv),
.platdata_auto_alloc_size = sizeof(struct eth_pdata),
.flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif /* CONFIG_DM_ETH */
It seems that this driver now supports 3 configurations.
DM_ETH + DM_USB !DM_ETH + DM_USB !DM_ETH + !DM_USB
Since it doesn't support DM_ETH + !DM_USB, you should probably explicitly error in that case by checking at the top of the file.
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 844a0c7236..5ad481302b 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c @@ -1121,7 +1121,11 @@ int rndis_msg_parser(u8 configNr, u8 *buf) return -ENOTSUPP; }
+#ifndef CONFIG_DM_ETH int rndis_register(int (*rndis_control_ack)(struct eth_device *)) +#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)) +#endif { u8 i;
@@ -1149,8 +1153,13 @@ void rndis_deregister(int configNr) return; }
-int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter)
+#ifndef CONFIG_DM_ETH +int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter)
+#else +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter)
+#endif { debug("%s: configNr = %d\n", __func__, configNr); if (!dev || !stats) diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index 7a389a580a..084af8541c 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h @@ -222,23 +222,34 @@ typedef struct rndis_params {
const u8 *host_mac; u16 *filter;
struct eth_device *dev; struct net_device_stats *stats; int mtu; u32 vendorID; const char *vendorDescr;
int (*ack)(struct eth_device *);
+#ifndef CONFIG_DM_ETH
struct eth_device *dev;
int (*ack)(struct eth_device *);
+#else
struct udevice *dev;
int (*ack)(struct udevice *);
+#endif struct list_head resp_queue; } rndis_params;
/* RNDIS Message parser and other useless functions */ int rndis_msg_parser(u8 configNr, u8 *buf); enum rndis_state rndis_get_state(int configNr); -int rndis_register(int (*rndis_control_ack)(struct eth_device *)); void rndis_deregister(int configNr); +#ifndef CONFIG_DM_ETH +int rndis_register(int (*rndis_control_ack)(struct eth_device *)); int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter);
struct net_device_stats *stats, u16 *cdc_filter);
+#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)); +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter);
+#endif int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr); int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed); diff --git a/include/net.h b/include/net.h index 06320c6514..1f4d947350 100644 --- a/include/net.h +++ b/include/net.h @@ -255,6 +255,13 @@ int eth_setenv_enetaddr_by_index(const char *base_name, int index,
/*
- Initialize USB ethernet device with CONFIG_DM_ETH
- Returns:
0 is success, non-zero is error status.
- */
+int usb_ether_init(void);
+/*
- Get the hardware address for an ethernet interface .
- Args:
base_name - base name for device (normally "eth")
-- 2.11.0.rc2
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

On Wednesday 30 November 2016 05:24 AM, Joe Hershberger wrote:
On Thu, Nov 17, 2016 at 11:39 PM, Mugunthan V N mugunthanvnm@ti.com wrote:
Adopt usb ether gadget and rndis driver to adopt driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
drivers/usb/gadget/Kconfig | 4 ++ drivers/usb/gadget/ether.c | 153 ++++++++++++++++++++++++++++++++++++++++++--- drivers/usb/gadget/rndis.c | 13 +++- drivers/usb/gadget/rndis.h | 19 ++++-- include/net.h | 7 +++ 5 files changed, 181 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 40839d89e9..261ed128ac 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -112,6 +112,10 @@ config G_DNL_VENDOR_NUM config G_DNL_PRODUCT_NUM hex "Product ID of USB device"
+config USBNET_DEVADDR
string "USB Gadget Ethernet device mac address"
default "de:ad:be:ef:00:01"
Please don't do this. We don't have "default" MAC addresses. They are either from the env, from ROM, or randomly generated.
Okay will remove this and use either env MAC or random MAC.
endif # USB_GADGET_DOWNLOAD
endif # USB_GADGET diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 046ad8ca2b..8c3c3fd9ab 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -25,6 +25,7 @@ #include "rndis.h"
#include <dm.h> +#include <dm/lists.h> #include <dm/uclass-internal.h> #include <dm/device-internal.h>
@@ -116,7 +117,11 @@ struct eth_dev {
struct usb_request *tx_req, *rx_req;
+#ifndef CONFIG_DM_ETH
Please use positive logic.
Okay, will fix in next version.
struct eth_device *net;
+#else
struct udevice *net;
+#endif struct net_device_stats stats; unsigned int tx_qlen;
@@ -143,7 +148,11 @@ struct eth_dev { /*-------------------------------------------------------------------------*/ struct ether_priv { struct eth_dev ethdev; +#ifndef CONFIG_DM_ETH
Please use positive logic
struct eth_device netdev;
+#else
struct udevice *netdev;
Did you really intend to have a pointer here when the other is an inline structure?
Yes, udevice is the device allocated by probe and passed in probe, but in non-dm case netdev has to be allocated by driver, in this case it declared as inline structure.
+#endif struct usb_gadget_driver eth_driver; };
@@ -1851,7 +1860,11 @@ static void rndis_control_ack_complete(struct usb_ep *ep,
static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
+#ifndef CONFIG_DM_ETH
Please use positive logic.
static int rndis_control_ack(struct eth_device *net) +#else +static int rndis_control_ack(struct udevice *net) +#endif { struct ether_priv *priv = (struct ether_priv *)net->priv; struct eth_dev *dev = &priv->ethdev; @@ -2001,6 +2014,9 @@ static int eth_bind(struct usb_gadget *gadget) int status = -ENOMEM; int gcnum; u8 tmp[7]; +#ifdef CONFIG_DM_ETH
struct eth_pdata *pdata = dev_get_platdata(l_priv->netdev);
+#endif
/* these flags are only ever cleared; compiler take note */
#ifndef CONFIG_USB_ETH_CDC @@ -2188,7 +2204,11 @@ autoconf_fail:
/* network device setup */
+#ifndef CONFIG_DM_ETH dev->net = &l_priv->netdev;
You wouldn't need this difference if the priv also used a ptr in the non-dm case.
Also, if you are opposed to cleaning this up (preferably by adding a preceding patch to make it a pointer), at least use positive logic (#ifdef CONFIG_DM_ETH). Same applies elsewhere.
Okay, will add a patch to convert netdev to pointer
+#else
dev->net = l_priv->netdev;
+#endif
dev->cdc = cdc; dev->zlp = zlp;
@@ -2197,6 +2217,7 @@ autoconf_fail: dev->out_ep = out_ep; dev->status_ep = status_ep;
memset(tmp, 0, sizeof(tmp)); /* * Module params for these addresses should come from ID proms. * The host side address is used with CDC and RNDIS, and commonly
@@ -2204,10 +2225,13 @@ autoconf_fail: * host side code for the SAFE thing cares -- its original BLAN * thing didn't, Sharp never assigned those addresses on Zaurii. */ +#ifndef CONFIG_DM_ETH get_ether_addr(dev_addr, dev->net->enetaddr);
memset(tmp, 0, sizeof(tmp)); memcpy(tmp, dev->net->enetaddr, sizeof(dev->net->enetaddr));
+#else
get_ether_addr(dev_addr, pdata->enetaddr);
memcpy(tmp, pdata->enetaddr, sizeof(pdata->enetaddr));
+#endif
get_ether_addr(host_addr, dev->host_mac);
@@ -2268,10 +2292,11 @@ autoconf_fail: status_ep ? " STATUS " : "", status_ep ? status_ep->name : "" );
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
dev->net->enetaddr[0], dev->net->enetaddr[1],
dev->net->enetaddr[2], dev->net->enetaddr[3],
dev->net->enetaddr[4], dev->net->enetaddr[5]);
+#ifndef CONFIG_DM_ETH
printf("MAC %pM\n", dev->net->enetaddr);
+#else
printf("MAC %pM\n", pdata->enetaddr);
+#endif
if (cdc || rndis) printf("HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
@@ -2520,13 +2545,12 @@ void _usb_eth_halt(struct ether_priv *priv) }
usb_gadget_unregister_driver(&priv->eth_driver);
-#ifdef CONFIG_DM_USB
device_remove(dev->usb_udev);
Why is this not needed anymore?
Oops, thought of moveing device remove to .stop, but missed. Now realizing that this change is not needed as it will break !DM_ETH and DM_USB configuration.
-#else +#ifndef CONFIG_DM_USB board_usb_cleanup(0, USB_INIT_DEVICE); #endif }
+#ifndef CONFIG_DM_ETH static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { struct ether_priv *priv = (struct ether_priv *)netdev->priv; @@ -2593,3 +2617,114 @@ int usb_eth_initialize(bd_t *bi) eth_register(netdev); return 0; } +#else +static int usb_eth_start(struct udevice *dev) +{
struct ether_priv *priv = dev_get_priv(dev);
return _usb_eth_init(priv);
+}
+static int usb_eth_send(struct udevice *dev, void *packet, int length) +{
struct ether_priv *priv = dev_get_priv(dev);
return _usb_eth_send(priv, packet, length);
+}
+static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp) +{
struct ether_priv *priv = dev_get_priv(dev);
struct eth_dev *ethdev = &priv->ethdev;
int ret;
ret = _usb_eth_recv(priv);
if (ret) {
error("error packet receive\n");
return ret;
}
if (packet_received) {
if (ethdev->rx_req) {
*packetp = (uchar *)net_rx_packets[0];
return ethdev->rx_req->length;
} else {
error("dev->rx_req invalid");
return -EFAULT;
}
}
return -EAGAIN;
+}
+static int usb_eth_free_pkt(struct udevice *dev, uchar *packet,
int length)
+{
struct ether_priv *priv = dev_get_priv(dev);
struct eth_dev *ethdev = &priv->ethdev;
packet_received = 0;
return rx_submit(ethdev, ethdev->rx_req, 0);
+}
+static void usb_eth_stop(struct udevice *dev) +{
struct ether_priv *priv = dev_get_priv(dev);
_usb_eth_halt(priv);
+}
+static int usb_eth_probe(struct udevice *dev) +{
struct ether_priv *priv = dev_get_priv(dev);
struct eth_pdata *pdata = dev_get_platdata(dev);
priv->netdev = dev;
l_priv = priv;
get_ether_addr(CONFIG_USBNET_DEVADDR, pdata->enetaddr);
This function it just a separately implemented copy of other functions the net stack already provides. Assuming you should be manipulating the MAC addresses from some string at all, at least it should be using eth_parse_enetaddr().
eth_setenv_enetaddr("usbnet_devaddr", pdata->enetaddr);
This means that it will always clobber user's env. That's no good. Also, UCLASS_ETH already deals with mac address names for USB NICs as just another ethaddr, not a special usbnet name. Why not let that work?
Sure, will verify this and remove this section. Let network stack handle it.
return 0;
+}
+static const struct eth_ops usb_eth_ops = {
.start = usb_eth_start,
.send = usb_eth_send,
.recv = usb_eth_recv,
.free_pkt = usb_eth_free_pkt,
.stop = usb_eth_stop,
+};
+int usb_ether_init(void) +{
struct udevice *dev;
struct udevice *usb_dev;
int ret;
ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &usb_dev);
if (!usb_dev || ret) {
error("No USB device found\n");
return ret;
}
ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", &dev);
if (!dev || ret) {
error("usb - not able to bind usb_ether device\n");
return ret;
}
return 0;
+}
+U_BOOT_DRIVER(eth_usb) = {
.name = "usb_ether",
.id = UCLASS_ETH,
.probe = usb_eth_probe,
.ops = &usb_eth_ops,
.priv_auto_alloc_size = sizeof(struct ether_priv),
.platdata_auto_alloc_size = sizeof(struct eth_pdata),
.flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif /* CONFIG_DM_ETH */
It seems that this driver now supports 3 configurations.
DM_ETH + DM_USB !DM_ETH + DM_USB !DM_ETH + !DM_USB
Since it doesn't support DM_ETH + !DM_USB, you should probably explicitly error in that case by checking at the top of the file.
Will add an error at the top of the file.
Regards Mugunthan V N
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 844a0c7236..5ad481302b 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c @@ -1121,7 +1121,11 @@ int rndis_msg_parser(u8 configNr, u8 *buf) return -ENOTSUPP; }
+#ifndef CONFIG_DM_ETH int rndis_register(int (*rndis_control_ack)(struct eth_device *)) +#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)) +#endif { u8 i;
@@ -1149,8 +1153,13 @@ void rndis_deregister(int configNr) return; }
-int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter)
+#ifndef CONFIG_DM_ETH +int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter)
+#else +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter)
+#endif { debug("%s: configNr = %d\n", __func__, configNr); if (!dev || !stats) diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index 7a389a580a..084af8541c 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h @@ -222,23 +222,34 @@ typedef struct rndis_params {
const u8 *host_mac; u16 *filter;
struct eth_device *dev; struct net_device_stats *stats; int mtu; u32 vendorID; const char *vendorDescr;
int (*ack)(struct eth_device *);
+#ifndef CONFIG_DM_ETH
struct eth_device *dev;
int (*ack)(struct eth_device *);
+#else
struct udevice *dev;
int (*ack)(struct udevice *);
+#endif struct list_head resp_queue; } rndis_params;
/* RNDIS Message parser and other useless functions */ int rndis_msg_parser(u8 configNr, u8 *buf); enum rndis_state rndis_get_state(int configNr); -int rndis_register(int (*rndis_control_ack)(struct eth_device *)); void rndis_deregister(int configNr); +#ifndef CONFIG_DM_ETH +int rndis_register(int (*rndis_control_ack)(struct eth_device *)); int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter);
struct net_device_stats *stats, u16 *cdc_filter);
+#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)); +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu,
struct net_device_stats *stats, u16 *cdc_filter);
+#endif int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr); int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed); diff --git a/include/net.h b/include/net.h index 06320c6514..1f4d947350 100644 --- a/include/net.h +++ b/include/net.h @@ -255,6 +255,13 @@ int eth_setenv_enetaddr_by_index(const char *base_name, int index,
/*
- Initialize USB ethernet device with CONFIG_DM_ETH
- Returns:
0 is success, non-zero is error status.
- */
+int usb_ether_init(void);
+/*
- Get the hardware address for an ethernet interface .
- Args:
base_name - base name for device (normally "eth")
-- 2.11.0.rc2
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hi Lucasz,
On 17 November 2016 at 22:19, Mugunthan V N mugunthanvnm@ti.com wrote:
The previous series didn't land on the mailing list properly, so resending the series as *v3 resend*, sorry for spamming.
This patch series adopts driver model for usb ether gadget driver. This series is tested with MUSB driver model conversion on AM335x GP evm and AM335x BBB (logs [1]).
Also pushed a branch for testing [2]
Changes from v2:
- Moved USB ether address from driver hard code to Kconfig entry
- Optimized if check in patch 5/6 as mentioned by Marek Vasut.
Changes from initial version:
- Separated out the usb gadget driver patches from earlier musb series [3] for testing and submitting of dwc3 dm musb patches.
[1] - http://pastebin.ubuntu.com/23489333/ [2] - git://git.ti.com/~mugunthanvnm/ti-u-boot/mugunth-ti-u-boot.git dm-musb-v3 [3] - http://lists.denx.de/pipermail/u-boot/2016-February/246827.html
Note:
The following checkpatch warning can be ignored as this has to be fixed all over the file which should be a separate patch. CHECK: Avoid CamelCase: <configNr> #297: FILE: drivers/usb/gadget/rndis.c:1157: +int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, Mugunthan V N (6): drivers: usb: gadget: ether: adopt to usb driver model drivers: usb: gadget: ether: access network_started using local variable drivers: usb: gadget: ether: consolidate global devices to single struct drivers: usb: gadget: ether: use net device priv to pass usb ether priv drivers: usb: gadget: ether: prepare driver for driver model migration drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model drivers/usb/gadget/Kconfig | 4 + drivers/usb/gadget/ether.c | 315 ++++++++++++++++++++++++++++++++++++--------- drivers/usb/gadget/rndis.c | 13 +- drivers/usb/gadget/rndis.h | 19 ++- include/net.h | 7 + 5 files changed, 293 insertions(+), 65 deletions(-) -- 2.11.0.rc2
This series is assigned to me in patchwork. Are you OK with it? I plan to bring it in via DM.
Regards, Simon
participants (5)
-
Joe Hershberger
-
Marek Vasut
-
Mugunthan V N
-
Simon Glass
-
Tom Rini