Commit 44a51112aacd35bc1557d9567008e10ae8470c20

Authored by Mugunthan V N
Committed by Lokesh Vutla
1 parent a2997aca54

drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model

commit d4a3755368ca3d99f0a2b58ced8f8ddd42a80822 upstream.

Adopt usb ether gadget and rndis driver to adopt driver model

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Showing 5 changed files with 179 additions and 13 deletions Side-by-side Diff

drivers/usb/gadget/Kconfig
... ... @@ -112,6 +112,10 @@
112 112 config G_DNL_PRODUCT_NUM
113 113 hex "Product ID of USB device"
114 114  
  115 +config USBNET_DEVADDR
  116 + string "USB Gadget Ethernet device mac address"
  117 + default "de:ad:be:ef:00:01"
  118 +
115 119 endif # USB_GADGET_DOWNLOAD
116 120  
117 121 endif # USB_GADGET
drivers/usb/gadget/ether.c
... ... @@ -25,6 +25,7 @@
25 25 #include "rndis.h"
26 26  
27 27 #include <dm.h>
  28 +#include <dm/lists.h>
28 29 #include <dm/uclass-internal.h>
29 30 #include <dm/device-internal.h>
30 31  
31 32  
... ... @@ -115,7 +116,11 @@
115 116  
116 117 struct usb_request *tx_req, *rx_req;
117 118  
  119 +#ifndef CONFIG_DM_ETH
118 120 struct eth_device *net;
  121 +#else
  122 + struct udevice *net;
  123 +#endif
119 124 struct net_device_stats stats;
120 125 unsigned int tx_qlen;
121 126  
122 127  
... ... @@ -142,7 +147,11 @@
142 147 /*-------------------------------------------------------------------------*/
143 148 struct ether_priv {
144 149 struct eth_dev ethdev;
  150 +#ifndef CONFIG_DM_ETH
145 151 struct eth_device netdev;
  152 +#else
  153 + struct udevice *netdev;
  154 +#endif
146 155 struct usb_gadget_driver eth_driver;
147 156 };
148 157  
149 158  
... ... @@ -1852,7 +1861,11 @@
1852 1861  
1853 1862 static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
1854 1863  
  1864 +#ifndef CONFIG_DM_ETH
1855 1865 static int rndis_control_ack(struct eth_device *net)
  1866 +#else
  1867 +static int rndis_control_ack(struct udevice *net)
  1868 +#endif
1856 1869 {
1857 1870 struct ether_priv *priv = (struct ether_priv *)net->priv;
1858 1871 struct eth_dev *dev = &priv->ethdev;
... ... @@ -2001,6 +2014,9 @@
2001 2014 struct usb_ep *in_ep, *out_ep, *status_ep = NULL;
2002 2015 int status = -ENOMEM;
2003 2016 int gcnum;
  2017 +#ifdef CONFIG_DM_ETH
  2018 + struct eth_pdata *pdata = dev_get_platdata(l_priv->netdev);
  2019 +#endif
2004 2020  
2005 2021 /* these flags are only ever cleared; compiler take note */
2006 2022 #ifndef CONFIG_USB_ETH_CDC
2007 2023  
... ... @@ -2188,7 +2204,11 @@
2188 2204  
2189 2205  
2190 2206 /* network device setup */
  2207 +#ifndef CONFIG_DM_ETH
2191 2208 dev->net = &l_priv->netdev;
  2209 +#else
  2210 + dev->net = l_priv->netdev;
  2211 +#endif
2192 2212  
2193 2213 dev->cdc = cdc;
2194 2214 dev->zlp = zlp;
2195 2215  
... ... @@ -2204,7 +2224,11 @@
2204 2224 * host side code for the SAFE thing cares -- its original BLAN
2205 2225 * thing didn't, Sharp never assigned those addresses on Zaurii.
2206 2226 */
  2227 +#ifndef CONFIG_DM_ETH
2207 2228 get_ether_addr(dev_addr, dev->net->enetaddr);
  2229 +#else
  2230 + get_ether_addr(dev_addr, pdata->enetaddr);
  2231 +#endif
2208 2232  
2209 2233 get_ether_addr(host_addr, dev->host_mac);
2210 2234  
... ... @@ -2265,10 +2289,11 @@
2265 2289 status_ep ? " STATUS " : "",
2266 2290 status_ep ? status_ep->name : ""
2267 2291 );
2268   - printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2269   - dev->net->enetaddr[0], dev->net->enetaddr[1],
2270   - dev->net->enetaddr[2], dev->net->enetaddr[3],
2271   - dev->net->enetaddr[4], dev->net->enetaddr[5]);
  2292 +#ifndef CONFIG_DM_ETH
  2293 + printf("MAC %pM\n", dev->net->enetaddr);
  2294 +#else
  2295 + printf("MAC %pM\n", pdata->enetaddr);
  2296 +#endif
2272 2297  
2273 2298 if (cdc || rndis)
2274 2299 printf("HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
2275 2300  
... ... @@ -2517,13 +2542,12 @@
2517 2542 }
2518 2543  
2519 2544 usb_gadget_unregister_driver(&priv->eth_driver);
2520   -#ifdef CONFIG_DM_USB
2521   - device_remove(dev->usb_udev);
2522   -#else
  2545 +#ifndef CONFIG_DM_USB
2523 2546 board_usb_cleanup(0, USB_INIT_DEVICE);
2524 2547 #endif
2525 2548 }
2526 2549  
  2550 +#ifndef CONFIG_DM_ETH
2527 2551 static int usb_eth_init(struct eth_device *netdev, bd_t *bd)
2528 2552 {
2529 2553 struct ether_priv *priv = (struct ether_priv *)netdev->priv;
... ... @@ -2590,4 +2614,115 @@
2590 2614 eth_register(netdev);
2591 2615 return 0;
2592 2616 }
  2617 +#else
  2618 +static int usb_eth_start(struct udevice *dev)
  2619 +{
  2620 + struct ether_priv *priv = dev_get_priv(dev);
  2621 +
  2622 + return _usb_eth_init(priv);
  2623 +}
  2624 +
  2625 +static int usb_eth_send(struct udevice *dev, void *packet, int length)
  2626 +{
  2627 + struct ether_priv *priv = dev_get_priv(dev);
  2628 +
  2629 + return _usb_eth_send(priv, packet, length);
  2630 +}
  2631 +
  2632 +static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp)
  2633 +{
  2634 + struct ether_priv *priv = dev_get_priv(dev);
  2635 + struct eth_dev *ethdev = &priv->ethdev;
  2636 + int ret;
  2637 +
  2638 + ret = _usb_eth_recv(priv);
  2639 + if (ret) {
  2640 + error("error packet receive\n");
  2641 + return ret;
  2642 + }
  2643 +
  2644 + if (packet_received) {
  2645 + if (ethdev->rx_req) {
  2646 + *packetp = (uchar *)net_rx_packets[0];
  2647 + return ethdev->rx_req->length;
  2648 + } else {
  2649 + error("dev->rx_req invalid");
  2650 + return -EFAULT;
  2651 + }
  2652 + }
  2653 +
  2654 + return -EAGAIN;
  2655 +}
  2656 +
  2657 +static int usb_eth_free_pkt(struct udevice *dev, uchar *packet,
  2658 + int length)
  2659 +{
  2660 + struct ether_priv *priv = dev_get_priv(dev);
  2661 + struct eth_dev *ethdev = &priv->ethdev;
  2662 +
  2663 + packet_received = 0;
  2664 +
  2665 + return rx_submit(ethdev, ethdev->rx_req, 0);
  2666 +}
  2667 +
  2668 +static void usb_eth_stop(struct udevice *dev)
  2669 +{
  2670 + struct ether_priv *priv = dev_get_priv(dev);
  2671 +
  2672 + _usb_eth_halt(priv);
  2673 +}
  2674 +
  2675 +static int usb_eth_probe(struct udevice *dev)
  2676 +{
  2677 + struct ether_priv *priv = dev_get_priv(dev);
  2678 + struct eth_pdata *pdata = dev_get_platdata(dev);
  2679 +
  2680 + priv->netdev = dev;
  2681 + l_priv = priv;
  2682 +
  2683 + get_ether_addr(CONFIG_USBNET_DEVADDR, pdata->enetaddr);
  2684 + eth_setenv_enetaddr("usbnet_devaddr", pdata->enetaddr);
  2685 +
  2686 + return 0;
  2687 +}
  2688 +
  2689 +static const struct eth_ops usb_eth_ops = {
  2690 + .start = usb_eth_start,
  2691 + .send = usb_eth_send,
  2692 + .recv = usb_eth_recv,
  2693 + .free_pkt = usb_eth_free_pkt,
  2694 + .stop = usb_eth_stop,
  2695 +};
  2696 +
  2697 +int usb_ether_init(void)
  2698 +{
  2699 + struct udevice *dev;
  2700 + struct udevice *usb_dev;
  2701 + int ret;
  2702 +
  2703 + ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &usb_dev);
  2704 + if (!usb_dev || ret) {
  2705 + error("No USB device found\n");
  2706 + return ret;
  2707 + }
  2708 +
  2709 + ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", &dev);
  2710 + if (!dev || ret) {
  2711 + error("usb - not able to bind usb_ether device\n");
  2712 + return ret;
  2713 + }
  2714 +
  2715 + return 0;
  2716 +}
  2717 +
  2718 +U_BOOT_DRIVER(eth_usb) = {
  2719 + .name = "usb_ether",
  2720 + .id = UCLASS_ETH,
  2721 + .probe = usb_eth_probe,
  2722 + .ops = &usb_eth_ops,
  2723 + .priv_auto_alloc_size = sizeof(struct ether_priv),
  2724 + .platdata_auto_alloc_size = sizeof(struct eth_pdata),
  2725 + .flags = DM_FLAG_ALLOC_PRIV_DMA,
  2726 +};
  2727 +#endif /* CONFIG_DM_ETH */
drivers/usb/gadget/rndis.c
... ... @@ -1121,7 +1121,11 @@
1121 1121 return -ENOTSUPP;
1122 1122 }
1123 1123  
  1124 +#ifndef CONFIG_DM_ETH
1124 1125 int rndis_register(int (*rndis_control_ack)(struct eth_device *))
  1126 +#else
  1127 +int rndis_register(int (*rndis_control_ack)(struct udevice *))
  1128 +#endif
1125 1129 {
1126 1130 u8 i;
1127 1131  
... ... @@ -1149,8 +1153,13 @@
1149 1153 return;
1150 1154 }
1151 1155  
1152   -int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
1153   - struct net_device_stats *stats, u16 *cdc_filter)
  1156 +#ifndef CONFIG_DM_ETH
  1157 +int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
  1158 + struct net_device_stats *stats, u16 *cdc_filter)
  1159 +#else
  1160 +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu,
  1161 + struct net_device_stats *stats, u16 *cdc_filter)
  1162 +#endif
1154 1163 {
1155 1164 debug("%s: configNr = %d\n", __func__, configNr);
1156 1165 if (!dev || !stats)
drivers/usb/gadget/rndis.h
... ... @@ -222,23 +222,34 @@
222 222  
223 223 const u8 *host_mac;
224 224 u16 *filter;
225   - struct eth_device *dev;
226 225 struct net_device_stats *stats;
227 226 int mtu;
228 227  
229 228 u32 vendorID;
230 229 const char *vendorDescr;
231   - int (*ack)(struct eth_device *);
  230 +#ifndef CONFIG_DM_ETH
  231 + struct eth_device *dev;
  232 + int (*ack)(struct eth_device *);
  233 +#else
  234 + struct udevice *dev;
  235 + int (*ack)(struct udevice *);
  236 +#endif
232 237 struct list_head resp_queue;
233 238 } rndis_params;
234 239  
235 240 /* RNDIS Message parser and other useless functions */
236 241 int rndis_msg_parser(u8 configNr, u8 *buf);
237 242 enum rndis_state rndis_get_state(int configNr);
238   -int rndis_register(int (*rndis_control_ack)(struct eth_device *));
239 243 void rndis_deregister(int configNr);
  244 +#ifndef CONFIG_DM_ETH
  245 +int rndis_register(int (*rndis_control_ack)(struct eth_device *));
240 246 int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
241   - struct net_device_stats *stats, u16 *cdc_filter);
  247 + struct net_device_stats *stats, u16 *cdc_filter);
  248 +#else
  249 +int rndis_register(int (*rndis_control_ack)(struct udevice *));
  250 +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu,
  251 + struct net_device_stats *stats, u16 *cdc_filter);
  252 +#endif
242 253 int rndis_set_param_vendor(u8 configNr, u32 vendorID,
243 254 const char *vendorDescr);
244 255 int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed);
... ... @@ -255,6 +255,13 @@
255 255  
256 256  
257 257 /*
  258 + * Initialize USB ethernet device with CONFIG_DM_ETH
  259 + * Returns:
  260 + * 0 is success, non-zero is error status.
  261 + */
  262 +int usb_ether_init(void);
  263 +
  264 +/*
258 265 * Get the hardware address for an ethernet interface .
259 266 * Args:
260 267 * base_name - base name for device (normally "eth")