From d105dc9b5e82a3b8710b44a81f05660410e1f22d Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 27 Jan 2019 08:57:23 -0600 Subject: [PATCH] drivers/net/phy_notify.c and all network drivers that support PHY notifications: Support the signal notification through SIGEV_THREAD --- arch/arm/src/imxrt/imxrt_enet.c | 2 +- arch/arm/src/lpc43xx/lpc43_ethernet.c | 2 +- arch/arm/src/sam34/sam_emac.c | 2 +- arch/arm/src/sama5/sam_emaca.c | 2 +- arch/arm/src/sama5/sam_emacb.c | 2 +- arch/arm/src/sama5/sam_gmac.c | 2 +- arch/arm/src/samv7/sam_emac.c | 2 +- arch/arm/src/stm32/stm32_eth.c | 2 +- arch/arm/src/stm32f7/stm32_ethernet.c | 2 +- arch/arm/src/tiva/tm4c/tm4c_ethernet.c | 2 +- drivers/net/phy_notify.c | 38 +++++++------------------- include/net/if.h | 6 ++-- include/nuttx/net/phy.h | 8 +++--- 13 files changed, 27 insertions(+), 45 deletions(-) diff --git a/arch/arm/src/imxrt/imxrt_enet.c b/arch/arm/src/imxrt/imxrt_enet.c index 3e37e965d0..e40a29ab18 100644 --- a/arch/arm/src/imxrt/imxrt_enet.c +++ b/arch/arm/src/imxrt/imxrt_enet.c @@ -1752,7 +1752,7 @@ static int imxrt_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/lpc43xx/lpc43_ethernet.c b/arch/arm/src/lpc43xx/lpc43_ethernet.c index 5d72a0be4a..b6ff901d46 100644 --- a/arch/arm/src/lpc43xx/lpc43_ethernet.c +++ b/arch/arm/src/lpc43xx/lpc43_ethernet.c @@ -2763,7 +2763,7 @@ static int lpc43_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/sam34/sam_emac.c b/arch/arm/src/sam34/sam_emac.c index 19b25c32d0..5eaa9c8d69 100644 --- a/arch/arm/src/sam34/sam_emac.c +++ b/arch/arm/src/sam34/sam_emac.c @@ -2328,7 +2328,7 @@ static int sam_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/sama5/sam_emaca.c b/arch/arm/src/sama5/sam_emaca.c index 9d940a7a98..7eef64f42e 100644 --- a/arch/arm/src/sama5/sam_emaca.c +++ b/arch/arm/src/sama5/sam_emaca.c @@ -2364,7 +2364,7 @@ static int sam_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/sama5/sam_emacb.c b/arch/arm/src/sama5/sam_emacb.c index d382186388..174da786d3 100644 --- a/arch/arm/src/sama5/sam_emacb.c +++ b/arch/arm/src/sama5/sam_emacb.c @@ -2731,7 +2731,7 @@ static int sam_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/sama5/sam_gmac.c b/arch/arm/src/sama5/sam_gmac.c index ac409c53f4..98872e5d45 100644 --- a/arch/arm/src/sama5/sam_gmac.c +++ b/arch/arm/src/sama5/sam_gmac.c @@ -2319,7 +2319,7 @@ static int sam_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/samv7/sam_emac.c b/arch/arm/src/samv7/sam_emac.c index 68e37840e1..b67a9d7b0f 100644 --- a/arch/arm/src/samv7/sam_emac.c +++ b/arch/arm/src/samv7/sam_emac.c @@ -3215,7 +3215,7 @@ static int sam_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/stm32/stm32_eth.c b/arch/arm/src/stm32/stm32_eth.c index 8b8a1565c4..3e3aa6390a 100644 --- a/arch/arm/src/stm32/stm32_eth.c +++ b/arch/arm/src/stm32/stm32_eth.c @@ -2875,7 +2875,7 @@ static int stm32_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/stm32f7/stm32_ethernet.c b/arch/arm/src/stm32f7/stm32_ethernet.c index 1997ab29d2..403772ba40 100644 --- a/arch/arm/src/stm32f7/stm32_ethernet.c +++ b/arch/arm/src/stm32f7/stm32_ethernet.c @@ -2977,7 +2977,7 @@ static int stm32_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/arch/arm/src/tiva/tm4c/tm4c_ethernet.c b/arch/arm/src/tiva/tm4c/tm4c_ethernet.c index 928f43deeb..9033f9b110 100644 --- a/arch/arm/src/tiva/tm4c/tm4c_ethernet.c +++ b/arch/arm/src/tiva/tm4c/tm4c_ethernet.c @@ -2876,7 +2876,7 @@ static int tiva_ioctl(struct net_driver_s *dev, int cmd, unsigned long arg) { struct mii_iotcl_notify_s *req = (struct mii_iotcl_notify_s *)((uintptr_t)arg); - ret = phy_notify_subscribe(dev->d_ifname, req->pid, req->signo, req->arg); + ret = phy_notify_subscribe(dev->d_ifname, req->pid, &req->event); if (ret == OK) { /* Enable PHY link up/down interrupts */ diff --git a/drivers/net/phy_notify.c b/drivers/net/phy_notify.c index c36bb8ed04..19ece2e7db 100644 --- a/drivers/net/phy_notify.c +++ b/drivers/net/phy_notify.c @@ -52,7 +52,6 @@ #include #include #include -#include #include #include @@ -102,10 +101,9 @@ struct phy_notify_s { bool assigned; - uint8_t signo; char intf[CONFIG_PHY_NOTIFICATION_MAXINTFLEN+1]; pid_t pid; - FAR void *arg; + struct sigevent event; phy_enable_t enable; }; @@ -177,10 +175,8 @@ static FAR struct phy_notify_s *phy_find_unassigned(void) /* Assign and re-initialized the entry */ client->assigned = true; - client->signo = 0; client->intf[0] = '\0'; client->pid = -1; - client->arg = NULL; client->enable = NULL; /* Return the client entry assigned to the caller */ @@ -236,13 +232,10 @@ static FAR struct phy_notify_s *phy_find_assigned(FAR const char *intf, static int phy_handler(int irq, FAR void *context, FAR void *arg) { FAR struct phy_notify_s *client = (FAR struct phy_notify_s *)arg; -#ifdef CONFIG_CAN_PASS_STRUCTS - union sigval value; -#endif int ret; DEBUGASSERT(client != NULL && client->assigned && client->enable); - phyinfo("Signalling PID=%d with signal %d\n", client->pid, client->signo); + phyinfo("Signaling PID=%d with event %p\n", client->pid, &client->event); /* Disable further interrupts */ @@ -250,16 +243,10 @@ static int phy_handler(int irq, FAR void *context, FAR void *arg) /* Signal the client that the PHY has something interesting to say to us */ -#ifdef CONFIG_CAN_PASS_STRUCTS - value.sival_ptr = client->arg; - ret = nxsig_queue(client->pid, client->signo, value); -#else - ret = nxsig_queue(client->pid, client->signo, client->arg); -#endif - + ret = nxsig_notification(client->pid, &client->event, SI_QUEUE); if (ret < 0) { - phyerr("ERROR: nxsig_queue failed: %d\n", ret); + phyerr("ERROR: nxsig_notification failed: %d\n", ret); } return OK; @@ -287,23 +274,22 @@ static int phy_handler(int irq, FAR void *context, FAR void *arg) * terminator). Configurable with CONFIG_PHY_NOTIFICATION_MAXINTFLEN. * pid - Identifies the task to receive the signal. The special value * of zero means to use the pid of the current task. - * signo - This is the signal number to use when notifying the task. - * arg - An argument that will accompany the notification signal. + * event - Describes the way a task is to be notified * * Returned Value: * OK on success; Negated errno on failure. * ****************************************************************************/ -int phy_notify_subscribe(FAR const char *intf, pid_t pid, int signo, - FAR void *arg) +int phy_notify_subscribe(FAR const char *intf, pid_t pid, + FAR struct sigevent *event) { FAR struct phy_notify_s *client; int ret = OK; DEBUGASSERT(intf); - phyinfo("%s: PID=%d signo=%d arg=%p\n", intf, pid, signo, arg); + phyinfo("%s: PID=%d event=%p\n", intf, pid, event); /* The special value pid == 0 means to use the pid of the current task. */ @@ -320,8 +306,7 @@ int phy_notify_subscribe(FAR const char *intf, pid_t pid, int signo, { /* Yes.. update the signal number and argument */ - client->signo = signo; - client->arg = arg; + client->event = *event; } else { @@ -336,9 +321,8 @@ int phy_notify_subscribe(FAR const char *intf, pid_t pid, int signo, /* Initialize the new client entry */ - client->signo = signo; client->pid = pid; - client->arg = arg; + client->event = *event; snprintf(client->intf, CONFIG_PHY_NOTIFICATION_MAXINTFLEN+1, intf); client->intf[CONFIG_PHY_NOTIFICATION_MAXINTFLEN] = '\0'; @@ -399,10 +383,8 @@ int phy_notify_unsubscribe(FAR const char *intf, pid_t pid) /* Un-initialize the client entry */ client->assigned = false; - client->signo = 0; client->intf[0] = '\0'; client->pid = -1; - client->arg = NULL; phy_semgive(); return OK; diff --git a/include/net/if.h b/include/net/if.h index 93d03b1274..4be72038ca 100644 --- a/include/net/if.h +++ b/include/net/if.h @@ -40,6 +40,7 @@ * Included Files *******************************************************************************************/ +#include #include /******************************************************************************************* @@ -119,9 +120,8 @@ struct mii_iotcl_notify_s { - pid_t pid; /* PID of the task to receive the signal. Zero means "this task" */ - uint8_t signo; /* Signal number to use when signalling */ - FAR void *arg; /* An argument that will accompany the signal callback */ + pid_t pid; /* PID of the task to receive the signal. Zero means "this task" */ + struct sigevent event; /* Describe the way a task is to be notified */ }; /* Structure passed to read from or write to the MII/PHY management interface via the diff --git a/include/nuttx/net/phy.h b/include/nuttx/net/phy.h index 811415e0a7..1b62b0adf1 100644 --- a/include/nuttx/net/phy.h +++ b/include/nuttx/net/phy.h @@ -45,6 +45,7 @@ #include +#include #include /**************************************************************************** @@ -103,8 +104,7 @@ extern "C" * terminator). Configurable with CONFIG_PHY_NOTIFICATION_MAXINTFLEN. * pid - Identifies the task to receive the signal. The special value * of zero means to use the pid of the current task. - * signo - This is the signal number to use when notifying the task. - * arg - An argument that will accompany the notification signal. + * event - Describe the way a task is to be notified * * Returned Value: * OK on success; Negated errno on failure. @@ -112,8 +112,8 @@ extern "C" ****************************************************************************/ #ifdef CONFIG_ARCH_PHY_INTERRUPT -int phy_notify_subscribe(FAR const char *intf, pid_t pid, int signo, - FAR void *arg); +int phy_notify_subscribe(FAR const char *intf, pid_t pid, + FAR struct sigevent *event); #endif /****************************************************************************