1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
From 136d46d2fa27815cc4cc3a57d5e3d54523028768 Mon Sep 17 00:00:00 2001
From: Sachin Saxena <sachin.saxena@nxp.com>
Date: Thu, 19 Dec 2019 12:57:35 +0530
Subject: [PATCH] fsl_qbman: Framework for enabling Link status notification
- This will enable link update event notification for
user space USDPAA application.
Signed-off-by: Sachin Saxena <sachin.saxena@nxp.com>
DPDK-2128
(cherry picked from commit fb53c813a779cc3fc28c8ed3fc8bc0dde24db0ea)
---
drivers/staging/fsl_qbman/Makefile | 4 +
drivers/staging/fsl_qbman/fsl_usdpaa.c | 278 ++++++++++++++++++++++++++++++++-
include/linux/fsl_usdpaa.h | 32 ++++
3 files changed, 313 insertions(+), 1 deletion(-)
--- a/drivers/staging/fsl_qbman/Makefile
+++ b/drivers/staging/fsl_qbman/Makefile
@@ -1,5 +1,9 @@
subdir-ccflags-y := -Werror
+# Include netcomm SW specific definitions
+include $(srctree)/drivers/net/ethernet/freescale/sdk_fman/ncsw_config.mk
+ccflags-y += -I$(NET_DPA)
+
# Common
obj-$(CONFIG_FSL_SDK_DPA) += dpa_alloc.o
obj-$(CONFIG_FSL_SDK_DPA) += qbman_driver.o
--- a/drivers/staging/fsl_qbman/fsl_usdpaa.c
+++ b/drivers/staging/fsl_qbman/fsl_usdpaa.c
@@ -18,6 +18,8 @@
#include <linux/slab.h>
#include <linux/mman.h>
#include <linux/of_reserved_mem.h>
+#include <linux/eventfd.h>
+#include <linux/fdtable.h>
#if !(defined(CONFIG_ARM) || defined(CONFIG_ARM64))
#include <mm/mmu_decl.h>
@@ -27,6 +29,26 @@
#include <linux/fsl_usdpaa.h>
#include "bman_low.h"
#include "qman_low.h"
+/* Headers requires for
+ * Link status support
+ */
+#include <linux/device.h>
+#include <linux/of_mdio.h>
+#include "mac.h"
+#include "dpaa_eth_common.h"
+
+/* Private data for Proxy Interface */
+struct dpa_proxy_priv_s {
+ struct mac_device *mac_dev;
+ struct eventfd_ctx *efd_ctx;
+};
+/* Interface Helpers */
+static inline struct device *get_dev_ptr(char *if_name);
+static void phy_link_updates(struct net_device *net_dev);
+/* IOCTL handlers */
+static inline int ioctl_usdpaa_get_link_status(char *if_name);
+static int ioctl_en_if_link_status(struct usdpaa_ioctl_link_status *args);
+static int ioctl_disable_if_link_status(char *if_name);
/* Physical address range of the memory reservation, exported for mm/mem.c */
static u64 phys_start;
@@ -556,7 +578,6 @@ static bool check_portal_channel(void *c
-
static int usdpaa_release(struct inode *inode, struct file *filp)
{
int err = 0;
@@ -1656,6 +1677,220 @@ found:
return 0;
}
+
+static inline struct device *get_dev_ptr(char *if_name)
+{
+ struct device *dev;
+ char node[NODE_NAME_LEN];
+
+ sprintf(node, "soc:fsl,dpaa:%s",if_name);
+ dev = bus_find_device_by_name(&platform_bus_type, NULL, node);
+ if (dev == NULL) {
+ pr_err(KBUILD_MODNAME "IF %s not found\n", if_name);
+ return NULL;
+ }
+ pr_debug("%s: found dev 0x%lX for If %s ,dev->platform_data %p\n",
+ __func__, (unsigned long)dev,
+ if_name, dev->platform_data);
+
+ return dev;
+}
+
+/* This function will return Current link status of the device
+ * '1' if Link is UP, '0' otherwise.
+ *
+ * Input parameter:
+ * if_name: Interface node name
+ *
+ */
+static inline int ioctl_usdpaa_get_link_status(char *if_name)
+{
+ struct net_device *net_dev = NULL;
+ struct device *dev;
+
+ dev = get_dev_ptr(if_name);
+ if (dev == NULL)
+ return -ENODEV;
+ net_dev = dev->platform_data;
+ if (net_dev == NULL)
+ return -ENODEV;
+
+ if (test_bit(__LINK_STATE_NOCARRIER, &net_dev->state))
+ return 0; /* Link is DOWN */
+ else
+ return 1; /* Link is UP */
+}
+
+
+/* Link Status Callback Function
+ * This function will be resgitered to PHY framework to get
+ * Link update notifications and should be responsible for waking up
+ * user space task when there is a link update notification.
+ */
+static void phy_link_updates(struct net_device *net_dev)
+{
+ struct dpa_proxy_priv_s *priv = NULL;
+
+ pr_debug("%s: Link '%s': Speed '%d-Mbps': Autoneg '%d': Duplex '%d'\n",
+ net_dev->name,
+ ioctl_usdpaa_get_link_status(net_dev->name)?"UP":"DOWN",
+ net_dev->phydev->speed,
+ net_dev->phydev->autoneg,
+ net_dev->phydev->duplex);
+
+ /* Wake up the user space context to notify PHY update */
+ priv = netdev_priv(net_dev);
+ eventfd_signal(priv->efd_ctx, 1);
+}
+
+
+/* IOCTL handler for enabling Link status request for a given interface
+ * Input parameters:
+ * args->if_name: This the network interface node name as defind in
+ * device tree file. Currently, it has format of
+ * "ethernet@x" type for each interface.
+ * args->efd: The eventfd value which should be waked up when
+ * there is any link update received.
+ */
+static int ioctl_en_if_link_status(struct usdpaa_ioctl_link_status *args)
+{
+ struct net_device *net_dev = NULL;
+ struct dpa_proxy_priv_s *priv = NULL;
+ struct device *dev;
+ struct mac_device *mac_dev;
+ struct proxy_device *proxy_dev;
+ struct task_struct *userspace_task = NULL;
+ struct file *efd_file = NULL;
+
+ dev = get_dev_ptr(args->if_name);
+ if (dev == NULL)
+ return -ENODEV;
+ /* Utilize dev->platform_data to save netdevice
+ pointer as it will not be registered */
+ if (dev->platform_data) {
+ pr_debug("%s: IF %s already initialized\n",
+ __func__, args->if_name);
+ /* This will happen when application is not able to initiate
+ * cleanup in last run. We still need to save the new
+ * eventfd context.
+ */
+ net_dev = dev->platform_data;
+ priv = netdev_priv(net_dev);
+
+ /* Get current task context from which IOCTL was called */
+ userspace_task = current;
+
+ rcu_read_lock();
+ efd_file = fcheck_files(userspace_task->files, args->efd);
+ rcu_read_unlock();
+
+ priv->efd_ctx = eventfd_ctx_fileget(efd_file);
+ if (!priv->efd_ctx) {
+ pr_err(KBUILD_MODNAME "get eventfd context failed\n");
+ /* Free the allocated memory for net device */
+ dev->platform_data = NULL;
+ free_netdev(net_dev);
+ return -EINVAL;
+ }
+ /* Since there will be NO PHY update as link is already setup,
+ * wake user context once so that current PHY status can
+ * be fetched.
+ */
+ phy_link_updates(net_dev);
+ return 0;
+ }
+
+ proxy_dev = dev_get_drvdata(dev);
+ mac_dev = proxy_dev->mac_dev;
+ /* Allocate an dummy net device for proxy interface */
+ net_dev = alloc_etherdev(sizeof(*priv));
+ if (!net_dev) {
+ pr_err(KBUILD_MODNAME "alloc_etherdev failed\n");
+ return -ENOMEM;
+ } else {
+ SET_NETDEV_DEV(net_dev, dev);
+ priv = netdev_priv(net_dev);
+ priv->mac_dev = mac_dev;
+ /* Get current task context from which IOCTL was called */
+ userspace_task = current;
+
+ rcu_read_lock();
+ efd_file = fcheck_files(userspace_task->files, args->efd);
+ rcu_read_unlock();
+
+ priv->efd_ctx = eventfd_ctx_fileget(efd_file);
+
+ if (!priv->efd_ctx) {
+ pr_err(KBUILD_MODNAME "get eventfd context failed\n");
+ /* Free the allocated memory for net device */
+ free_netdev(net_dev);
+ return -EINVAL;
+ }
+ strncpy(net_dev->name, args->if_name, IF_NAME_MAX_LEN);
+ dev->platform_data = net_dev;
+ }
+
+ pr_debug("%s: mac_dev %p cell_index %d\n",
+ __func__, mac_dev, mac_dev->cell_index);
+ mac_dev->phy_dev = of_phy_connect(net_dev, mac_dev->phy_node,
+ phy_link_updates, 0, mac_dev->phy_if);
+ if (unlikely(mac_dev->phy_dev == NULL) || IS_ERR(mac_dev->phy_dev)) {
+ pr_err("%s: --------Error in PHY Connect\n", __func__);
+ /* Free the allocated memory for net device */
+ free_netdev(net_dev);
+ return -ENODEV;
+ }
+ net_dev->phydev = mac_dev->phy_dev;
+ mac_dev->start(mac_dev);
+ pr_debug("%s: --- PHY connected for %s\n", __func__, args->if_name);
+
+ return 0;
+}
+
+/* IOCTL handler for disabling Link status for a given interface
+ * Input parameters:
+ * if_name: This the network interface node name as defind in
+ * device tree file. Currently, it has format of
+ * "ethernet@x" type for each interface.
+ */
+static int ioctl_disable_if_link_status(char *if_name)
+{
+ struct net_device *net_dev = NULL;
+ struct device *dev;
+ struct mac_device *mac_dev;
+ struct proxy_device *proxy_dev;
+ struct dpa_proxy_priv_s *priv = NULL;
+
+ dev = get_dev_ptr(if_name);
+ if (dev == NULL)
+ return -ENODEV;
+ /* Utilize dev->platform_data to save netdevice
+ pointer as it will not be registered */
+ if (!dev->platform_data) {
+ pr_debug("%s: IF %s already Disabled for Link status\n",
+ __func__, if_name);
+ return 0;
+ }
+
+ net_dev = dev->platform_data;
+ proxy_dev = dev_get_drvdata(dev);
+ mac_dev = proxy_dev->mac_dev;
+ mac_dev->stop(mac_dev);
+
+ priv = netdev_priv(net_dev);
+ eventfd_ctx_put(priv->efd_ctx);
+
+ /* This will also deregister the call back */
+ phy_disconnect(mac_dev->phy_dev);
+ phy_resume(mac_dev->phy_dev);
+
+ free_netdev(net_dev);
+ dev->platform_data = NULL;
+
+ pr_debug("%s: Link status Disabled for %s\n", __func__, if_name);
+ return 0;
+}
+
static long usdpaa_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
{
struct ctx *ctx = fp->private_data;
@@ -1722,6 +1957,47 @@ static long usdpaa_ioctl(struct file *fp
return -EFAULT;
return ioctl_free_raw_portal(fp, ctx, &input);
}
+ case USDPAA_IOCTL_ENABLE_LINK_STATUS_INTERRUPT:
+ {
+ struct usdpaa_ioctl_link_status input;
+ int ret;
+
+ if (copy_from_user(&input, a, sizeof(input)))
+ return -EFAULT;
+ ret = ioctl_en_if_link_status(&input);
+ if (ret)
+ pr_err("Error(%d) enable link interrupt:IF: %s\n",
+ ret, input.if_name);
+ return ret;
+ }
+ case USDPAA_IOCTL_DISABLE_LINK_STATUS_INTERRUPT:
+ {
+ char *input;
+ int ret;
+
+ if (copy_from_user(&input, a, sizeof(input)))
+ return -EFAULT;
+ ret = ioctl_disable_if_link_status(input);
+ if (ret)
+ pr_err("Error(%d) Disabling link interrupt:IF: %s\n",
+ ret, input);
+ return ret;
+ }
+ case USDPAA_IOCTL_GET_LINK_STATUS:
+ {
+ struct usdpaa_ioctl_link_status_args input;
+
+ if (copy_from_user(&input, a, sizeof(input)))
+ return -EFAULT;
+
+ input.link_status = ioctl_usdpaa_get_link_status(input.if_name);
+ if (input.link_status < 0)
+ return input.link_status;
+ if (copy_to_user(a, &input, sizeof(input)))
+ return -EFAULT;
+
+ return 0;
+ }
}
return -EINVAL;
}
--- a/include/linux/fsl_usdpaa.h
+++ b/include/linux/fsl_usdpaa.h
@@ -365,6 +365,38 @@ int dpa_alloc_pop(struct dpa_alloc *allo
int dpa_alloc_check(struct dpa_alloc *list, u32 id);
#endif /* __KERNEL__ */
+
+/************************************
+ * Link Status support for user space
+ * interface
+ ************************************/
+#define IF_NAME_MAX_LEN 16
+#define NODE_NAME_LEN 32
+
+struct usdpaa_ioctl_link_status {
+ /* network device node name */
+ char if_name[IF_NAME_MAX_LEN];
+ /* Eventfd value */
+ uint32_t efd;
+};
+
+#define USDPAA_IOCTL_ENABLE_LINK_STATUS_INTERRUPT \
+ _IOW(USDPAA_IOCTL_MAGIC, 0x0E, struct usdpaa_ioctl_link_status)
+
+#define USDPAA_IOCTL_DISABLE_LINK_STATUS_INTERRUPT \
+ _IOW(USDPAA_IOCTL_MAGIC, 0x0F, char *)
+
+struct usdpaa_ioctl_link_status_args {
+ /* network device node name */
+ char if_name[IF_NAME_MAX_LEN];
+ /* link status(UP/DOWN) */
+ int link_status;
+};
+
+#define USDPAA_IOCTL_GET_LINK_STATUS \
+ _IOWR(USDPAA_IOCTL_MAGIC, 0x10, struct usdpaa_ioctl_link_status_args)
+
+
#ifdef __cplusplus
}
#endif
|