You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/03/15 10:01:10 UTC

[incubator-nuttx-apps] 01/04: feature: pointer of netdev ioctl support cross-core access via clean dcache

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 6c2a487f85df3b58119867096a829bd3416f9923
Author: zhanghongyu <zh...@xiaomi.com>
AuthorDate: Tue Dec 14 17:31:53 2021 +0800

    feature: pointer of netdev ioctl support cross-core access via clean dcache
    
    Signed-off-by: zhanghongyu <zh...@xiaomi.com>
---
 netutils/usrsock_rpmsg/usrsock_rpmsg.h        | 15 +++++++++
 netutils/usrsock_rpmsg/usrsock_rpmsg_client.c | 45 +++++++++++++++++++++++++++
 netutils/usrsock_rpmsg/usrsock_rpmsg_server.c | 17 ++++++++++
 3 files changed, 77 insertions(+)

diff --git a/netutils/usrsock_rpmsg/usrsock_rpmsg.h b/netutils/usrsock_rpmsg/usrsock_rpmsg.h
index 4c0b1bd..3ca4493 100644
--- a/netutils/usrsock_rpmsg/usrsock_rpmsg.h
+++ b/netutils/usrsock_rpmsg/usrsock_rpmsg.h
@@ -27,6 +27,11 @@
 
 #include <nuttx/net/usrsock.h>
 
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+#  include <nuttx/wireless/wireless.h>
+#  include <metal/cache.h>
+#endif
+
 /****************************************************************************
  * Pre-processor definitions
  ****************************************************************************/
@@ -35,6 +40,16 @@
 
 #define USRSOCK_RPMSG_DNS_EVENT      127
 
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+#  define WL_IS80211POINTERCMD(cmd)  ((cmd) == SIOCGIWSCAN || \
+                                      (cmd) == SIOCSIWCOUNTRY || \
+                                      (cmd) == SIOCGIWRANGE || \
+                                      (cmd) == SIOCSIWENCODEEXT || \
+                                      (cmd) == SIOCGIWENCODEEXT || \
+                                      (cmd) == SIOCGIWESSID || \
+                                      (cmd) == SIOCSIWESSID)
+#endif
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
diff --git a/netutils/usrsock_rpmsg/usrsock_rpmsg_client.c b/netutils/usrsock_rpmsg/usrsock_rpmsg_client.c
index a33fff8..2d608e6 100644
--- a/netutils/usrsock_rpmsg/usrsock_rpmsg_client.c
+++ b/netutils/usrsock_rpmsg/usrsock_rpmsg_client.c
@@ -49,6 +49,12 @@ struct usrsock_rpmsg_s
   struct file           file;
 };
 
+enum usrsock_cache_action_e
+{
+  USRSOCK_COHERENT_BEFORE,
+  USRSOCK_COHERENT_AFTER,
+};
+
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
@@ -155,6 +161,41 @@ static int usrsock_rpmsg_ept_cb(struct rpmsg_endpoint *ept, void *data,
   return ret;
 }
 
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+
+static void usersock_coherent_cache(FAR void *buf,
+                                    enum usrsock_cache_action_e action)
+{
+  FAR struct usrsock_request_ioctl_s *req = buf;
+  FAR struct iwreq *wlreq;
+
+  if (req->head.reqid == USRSOCK_REQUEST_IOCTL)
+    {
+      if (WL_IS80211POINTERCMD(req->cmd))
+        {
+          wlreq = (FAR struct iwreq *)(req + 1);
+          if (action == USRSOCK_COHERENT_BEFORE)
+            {
+              metal_cache_flush(wlreq->u.data.pointer,
+                                wlreq->u.data.length);
+            }
+
+          if (action == USRSOCK_COHERENT_AFTER)
+            {
+              metal_cache_invalidate(wlreq->u.data.pointer,
+                                    wlreq->u.data.length);
+            }
+        }
+    }
+}
+
+#else
+static void usersock_coherent_cache(FAR void *buf,
+                                    enum usrsock_cache_action_e action)
+{
+}
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -251,6 +292,8 @@ int main(int argc, char *argv[])
               break;
             }
 
+          usersock_coherent_cache(buf, USRSOCK_COHERENT_BEFORE);
+
           /* Send the packet to remote */
 
           ret = rpmsg_send_nocopy(&priv.ept, buf, ret);
@@ -258,6 +301,8 @@ int main(int argc, char *argv[])
             {
               break;
             }
+
+          usersock_coherent_cache(buf, USRSOCK_COHERENT_AFTER);
         }
 
       /* Reclaim the resource */
diff --git a/netutils/usrsock_rpmsg/usrsock_rpmsg_server.c b/netutils/usrsock_rpmsg/usrsock_rpmsg_server.c
index fb4625a..e8daddd 100644
--- a/netutils/usrsock_rpmsg/usrsock_rpmsg_server.c
+++ b/netutils/usrsock_rpmsg/usrsock_rpmsg_server.c
@@ -716,9 +716,26 @@ static int usrsock_rpmsg_ioctl_handler(struct rpmsg_endpoint *ept,
   if (req->usockid >= 0 &&
       req->usockid < CONFIG_NETUTILS_USRSOCK_NSOCK_DESCRIPTORS)
     {
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+      FAR struct iwreq *wlreq = (FAR struct iwreq *)(req + 1);
+      if (WL_IS80211POINTERCMD(req->cmd))
+        {
+          metal_cache_invalidate(wlreq->u.data.pointer,
+                                 wlreq->u.data.length);
+        }
+#endif
+
       memcpy(ack + 1, req + 1, req->arglen);
       ret = psock_ioctl(&priv->socks[req->usockid],
               req->cmd, (unsigned long)(ack + 1));
+
+#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
+      if (WL_IS80211POINTERCMD(req->cmd))
+        {
+          metal_cache_flush(wlreq->u.data.pointer,
+                            wlreq->u.data.length);
+        }
+#endif
     }
 
   return usrsock_rpmsg_send_data_ack(ept,