layerscape: add patches-5.4
[openwrt/staging/jow.git] / target / linux / layerscape / patches-5.4 / 701-net-0296-staging-fsl_ppfe-eth-support-for-userspace-networkin.patch
1 From 25d189ea016270d1d7ab67eafc57bc8989b5381c Mon Sep 17 00:00:00 2001
2 From: Akhil Goyal <akhil.goyal@nxp.com>
3 Date: Fri, 13 Apr 2018 15:41:28 +0530
4 Subject: [PATCH] staging: fsl_ppfe/eth: support for userspace networking
5
6 This patch adds the userspace mode support to fsl_ppfe network driver.
7 In the new mode, basic hardware initialization is performed in kernel, while
8 the datapath and HIF handling is the responsibility of the userspace.
9
10 The new command line parameter is added to initialize the ppfe module
11 in userspace mode. By default the module remains in kernelspace networking
12 mode.
13 To enable userspace mode, use "insmod pfe.ko us=1"
14
15 Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
16 Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
17 ---
18 drivers/staging/fsl_ppfe/pfe_eth.c | 21 +++++++++++++++++++--
19 drivers/staging/fsl_ppfe/pfe_mod.c | 15 +++++++++++++++
20 drivers/staging/fsl_ppfe/pfe_mod.h | 2 ++
21 3 files changed, 36 insertions(+), 2 deletions(-)
22
23 --- a/drivers/staging/fsl_ppfe/pfe_eth.c
24 +++ b/drivers/staging/fsl_ppfe/pfe_eth.c
25 @@ -2296,6 +2296,8 @@ static int pfe_eth_init_one(struct pfe *
26 goto err0;
27 }
28
29 + if (us)
30 + emac_txq_cnt = EMAC_TXQ_CNT;
31 /* Create an ethernet device instance */
32 ndev = alloc_etherdev_mq(sizeof(*priv), emac_txq_cnt);
33
34 @@ -2342,6 +2344,9 @@ static int pfe_eth_init_one(struct pfe *
35 }
36 }
37
38 + if (us)
39 + goto phy_init;
40 +
41 ndev->mtu = 1500;
42
43 /* Set MTU limits */
44 @@ -2381,6 +2386,8 @@ static int pfe_eth_init_one(struct pfe *
45 netdev_err(ndev, "register_netdev() failed\n");
46 goto err3;
47 }
48 +
49 +phy_init:
50 device_init_wakeup(&ndev->dev, WAKE_MAGIC);
51
52 if (!(priv->einfo->phy_flags & GEMAC_NO_PHY)) {
53 @@ -2392,6 +2399,12 @@ static int pfe_eth_init_one(struct pfe *
54 }
55 }
56
57 + if (us) {
58 + if (priv->phydev)
59 + phy_start(priv->phydev);
60 + return 0;
61 + }
62 +
63 netif_carrier_on(ndev);
64
65 /* Create all the sysfs files */
66 @@ -2403,6 +2416,8 @@ static int pfe_eth_init_one(struct pfe *
67
68 return 0;
69 err4:
70 + if (us)
71 + goto err3;
72 unregister_netdev(ndev);
73 err3:
74 pfe_eth_mdio_exit(priv->mii_bus);
75 @@ -2449,9 +2464,11 @@ static void pfe_eth_exit_one(struct pfe_
76 {
77 netif_info(priv, probe, priv->ndev, "%s\n", __func__);
78
79 - pfe_eth_sysfs_exit(priv->ndev);
80 + if (!us) {
81 + pfe_eth_sysfs_exit(priv->ndev);
82
83 - unregister_netdev(priv->ndev);
84 + unregister_netdev(priv->ndev);
85 + }
86
87 if (!(priv->einfo->phy_flags & GEMAC_NO_PHY))
88 pfe_phy_exit(priv->ndev);
89 --- a/drivers/staging/fsl_ppfe/pfe_mod.c
90 +++ b/drivers/staging/fsl_ppfe/pfe_mod.c
91 @@ -19,6 +19,10 @@
92 #include <linux/dma-mapping.h>
93 #include "pfe_mod.h"
94
95 +unsigned int us;
96 +module_param(us, uint, 0444);
97 +MODULE_PARM_DESC(us, "0: module enabled for kernel networking (DEFAULT)\n"
98 + "1: module enabled for userspace networking\n");
99 struct pfe *pfe;
100
101 /*
102 @@ -56,6 +60,9 @@ int pfe_probe(struct pfe *pfe)
103 if (rc < 0)
104 goto err_hw;
105
106 + if (us)
107 + goto firmware_init;
108 +
109 rc = pfe_hif_lib_init(pfe);
110 if (rc < 0)
111 goto err_hif_lib;
112 @@ -64,6 +71,7 @@ int pfe_probe(struct pfe *pfe)
113 if (rc < 0)
114 goto err_hif;
115
116 +firmware_init:
117 rc = pfe_firmware_init(pfe);
118 if (rc < 0)
119 goto err_firmware;
120 @@ -99,6 +107,9 @@ err_ctrl:
121 pfe_firmware_exit(pfe);
122
123 err_firmware:
124 + if (us)
125 + goto err_hif_lib;
126 +
127 pfe_hif_exit(pfe);
128
129 err_hif:
130 @@ -131,10 +142,14 @@ int pfe_remove(struct pfe *pfe)
131 #endif
132 pfe_firmware_exit(pfe);
133
134 + if (us)
135 + goto hw_exit;
136 +
137 pfe_hif_exit(pfe);
138
139 pfe_hif_lib_exit(pfe);
140
141 +hw_exit:
142 pfe_hw_exit(pfe);
143
144 return 0;
145 --- a/drivers/staging/fsl_ppfe/pfe_mod.h
146 +++ b/drivers/staging/fsl_ppfe/pfe_mod.h
147 @@ -22,6 +22,8 @@
148 #include <linux/device.h>
149 #include <linux/elf.h>
150
151 +extern unsigned int us;
152 +
153 struct pfe;
154
155 #include "pfe_hw.h"