From 82243b86fc673981d332881bbc98a871b2231329 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Sun, 21 Feb 2016 23:55:32 +0100 Subject: [PATCH 1/6] drivers: netdev2: remove extra event_callback argument --- drivers/include/net/netdev2.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/include/net/netdev2.h b/drivers/include/net/netdev2.h index dce2bc92a262..bede2b6d59ba 100644 --- a/drivers/include/net/netdev2.h +++ b/drivers/include/net/netdev2.h @@ -93,9 +93,8 @@ typedef struct netdev2 netdev2_t; * @brief Event callback for signaling event to upper layers * * @param[in] type type of the event - * @param[in] arg event argument */ -typedef void (*netdev2_event_cb_t)(netdev2_t *dev, netdev2_event_t event, void *arg); +typedef void (*netdev2_event_cb_t)(netdev2_t *dev, netdev2_event_t event); /** * @brief Structure to hold driver state From d7b17684e4dcc8da579d29c545ab5338efb4136a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Sun, 21 Feb 2016 23:56:19 +0100 Subject: [PATCH 2/6] drivers: net: adapt to removed event_callback argument --- cpu/native/netdev2_tap/netdev2_tap.c | 6 +++--- drivers/at86rf2xx/at86rf2xx.c | 2 +- drivers/at86rf2xx/at86rf2xx_netdev.c | 12 ++++++------ drivers/cc110x/cc110x-netdev2.c | 4 ++-- drivers/enc28j60/enc28j60.c | 10 +++++----- drivers/encx24j600/encx24j600.c | 8 +++----- drivers/ethos/ethos.c | 4 ++-- sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c | 4 +--- tests/driver_at86rf2xx/main.c | 4 +--- tests/netdev2_test/main.c | 5 ++--- 10 files changed, 26 insertions(+), 33 deletions(-) diff --git a/cpu/native/netdev2_tap/netdev2_tap.c b/cpu/native/netdev2_tap/netdev2_tap.c index 43d24399ff81..b59f8f21b2d2 100644 --- a/cpu/native/netdev2_tap/netdev2_tap.c +++ b/cpu/native/netdev2_tap/netdev2_tap.c @@ -98,7 +98,7 @@ static inline int _set_promiscous(netdev2_t *netdev, int value) static inline void _isr(netdev2_t *netdev) { if (netdev->event_callback) { - netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE); } #if DEVELHELP else { @@ -297,7 +297,7 @@ static int _send(netdev2_t *netdev, const struct iovec *vector, int n) netdev->stats.tx_bytes += bytes; #endif if (netdev->event_callback) { - netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE); } return res; } @@ -313,7 +313,7 @@ static void _tap_isr(int fd) { netdev2_t *netdev = (netdev2_t *)&netdev2_tap; if (netdev->event_callback) { - netdev->event_callback(netdev, NETDEV2_EVENT_ISR, netdev->isr_arg); + netdev->event_callback(netdev, NETDEV2_EVENT_ISR); } else { puts("netdev2_tap: _isr: no event callback."); diff --git a/drivers/at86rf2xx/at86rf2xx.c b/drivers/at86rf2xx/at86rf2xx.c index 075ecb735f0d..19c41bd13492 100644 --- a/drivers/at86rf2xx/at86rf2xx.c +++ b/drivers/at86rf2xx/at86rf2xx.c @@ -218,6 +218,6 @@ void at86rf2xx_tx_exec(at86rf2xx_t *dev) AT86RF2XX_TRX_STATE__TX_START); if (netdev->event_callback && (dev->netdev.flags & AT86RF2XX_OPT_TELL_TX_START)) { - netdev->event_callback(netdev, NETDEV2_EVENT_TX_STARTED, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_TX_STARTED); } } diff --git a/drivers/at86rf2xx/at86rf2xx_netdev.c b/drivers/at86rf2xx/at86rf2xx_netdev.c index 49b9499484d2..55cedce15280 100644 --- a/drivers/at86rf2xx/at86rf2xx_netdev.c +++ b/drivers/at86rf2xx/at86rf2xx_netdev.c @@ -61,7 +61,7 @@ static void _irq_handler(void *arg) netdev2_t *dev = (netdev2_t *) arg; if (dev->event_callback) { - dev->event_callback(dev, NETDEV2_EVENT_ISR, NULL); + dev->event_callback(dev, NETDEV2_EVENT_ISR); } } @@ -606,7 +606,7 @@ static void _isr(netdev2_t *netdev) AT86RF2XX_TRX_STATE_MASK__TRAC; if (irq_mask & AT86RF2XX_IRQ_STATUS_MASK__RX_START) { - netdev->event_callback(netdev, NETDEV2_EVENT_RX_STARTED, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_RX_STARTED); DEBUG("[at86rf2xx] EVT - RX_START\n"); } @@ -617,7 +617,7 @@ static void _isr(netdev2_t *netdev) if (!(dev->netdev.flags & AT86RF2XX_OPT_TELL_RX_END)) { return; } - netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE); } else if (state == AT86RF2XX_STATE_TX_ARET_ON || state == AT86RF2XX_STATE_BUSY_TX_ARET) { @@ -635,15 +635,15 @@ static void _isr(netdev2_t *netdev) switch (trac_status) { case AT86RF2XX_TRX_STATE__TRAC_SUCCESS: case AT86RF2XX_TRX_STATE__TRAC_SUCCESS_DATA_PENDING: - netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE); DEBUG("[at86rf2xx] TX SUCCESS\n"); break; case AT86RF2XX_TRX_STATE__TRAC_NO_ACK: - netdev->event_callback(netdev, NETDEV2_EVENT_TX_NOACK, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_TX_NOACK); DEBUG("[at86rf2xx] TX NO_ACK\n"); break; case AT86RF2XX_TRX_STATE__TRAC_CHANNEL_ACCESS_FAILURE: - netdev->event_callback(netdev, NETDEV2_EVENT_TX_MEDIUM_BUSY, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_TX_MEDIUM_BUSY); DEBUG("[at86rf2xx] TX_CHANNEL_ACCESS_FAILURE\n"); break; default: diff --git a/drivers/cc110x/cc110x-netdev2.c b/drivers/cc110x/cc110x-netdev2.c index 96e3b079aee7..f3a69abf72af 100644 --- a/drivers/cc110x/cc110x-netdev2.c +++ b/drivers/cc110x/cc110x-netdev2.c @@ -164,7 +164,7 @@ static int _set(netdev2_t *dev, netopt_t opt, void *value, size_t value_len) static void _netdev2_cc110x_isr(void *arg) { netdev2_t *netdev2 = (netdev2_t*) arg; - netdev2->event_callback(netdev2, NETDEV2_EVENT_ISR, netdev2->isr_arg); + netdev2->event_callback(netdev2, NETDEV2_EVENT_ISR); } static void _netdev2_cc110x_rx_callback(void *arg) @@ -172,7 +172,7 @@ static void _netdev2_cc110x_rx_callback(void *arg) netdev2_t *netdev2 = (netdev2_t*) arg; cc110x_t *cc110x = &((netdev2_cc110x_t*) arg)->cc110x; gpio_irq_disable(cc110x->params.gdo2); - netdev2->event_callback(netdev2, NETDEV2_EVENT_RX_COMPLETE, NULL); + netdev2->event_callback(netdev2, NETDEV2_EVENT_RX_COMPLETE); } static void _isr(netdev2_t *dev) diff --git a/drivers/enc28j60/enc28j60.c b/drivers/enc28j60/enc28j60.c index 384aba522829..386e0796f022 100644 --- a/drivers/enc28j60/enc28j60.c +++ b/drivers/enc28j60/enc28j60.c @@ -216,7 +216,7 @@ static void mac_set(enc28j60_t *dev, uint8_t *mac) static void on_int(void *arg) { netdev2_t *netdev = (netdev2_t *)arg; - netdev->event_callback(arg, NETDEV2_EVENT_ISR, netdev->isr_arg); + netdev->event_callback(arg, NETDEV2_EVENT_ISR); } static int nd_send(netdev2_t *netdev, const struct iovec *data, int count) @@ -400,17 +400,17 @@ static void nd_isr(netdev2_t *netdev) /* go and tell the new link layer state to upper layers */ if (cmd_r_phy(dev, REG_PHY_PHSTAT2) & PHSTAT2_LSTAT) { DEBUG("[enc28j60] isr: link up!\n"); - netdev->event_callback(netdev, NETDEV2_EVENT_LINK_UP, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_LINK_UP); } else { DEBUG("[enc28j60] isr: link down!\n"); - netdev->event_callback(netdev, NETDEV2_EVENT_LINK_DOWN, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_LINK_DOWN); } } if (eir & EIR_PKTIF) { do { DEBUG("[enc28j60] isr: packet received\n"); - netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE); } while (cmd_rcr(dev, REG_B1_EPKTCNT, 1) > 0); } if (eir & EIR_RXERIF) { @@ -419,7 +419,7 @@ static void nd_isr(netdev2_t *netdev) } if (eir & EIR_TXIF) { DEBUG("[enc28j60] isr: packet transmitted\n"); - netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE, NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE); cmd_bfc(dev, REG_EIR, -1, EIR_TXIF); } if (eir & EIR_TXERIF) { diff --git a/drivers/encx24j600/encx24j600.c b/drivers/encx24j600/encx24j600.c index 13504110ec40..ddb5d6713ad6 100644 --- a/drivers/encx24j600/encx24j600.c +++ b/drivers/encx24j600/encx24j600.c @@ -96,13 +96,12 @@ void encx24j600_setup(encx24j600_t *dev, const encx24j600_params_t *params) static void encx24j600_isr(void *arg) { encx24j600_t *dev = (encx24j600_t *) arg; - netdev2_t *netdev = (netdev2_t *) arg; /* disable interrupt line */ gpio_irq_disable(dev->int_pin); /* call netdev2 hook */ - dev->netdev.event_callback((netdev2_t*) dev, NETDEV2_EVENT_ISR, netdev->isr_arg); + dev->netdev.event_callback((netdev2_t*) dev, NETDEV2_EVENT_ISR); } static void _isr(netdev2_t *netdev) @@ -124,15 +123,14 @@ static void _isr(netdev2_t *netdev) NETDEV2_EVENT_LINK_DOWN : NETDEV2_EVENT_LINK_UP; - netdev->event_callback(netdev, event, NULL); + netdev->event_callback(netdev, event); } /* check & handle available packets */ if (eir & ENC_PKTIF) { while (_packets_available(dev)) { unlock(dev); - netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE, - NULL); + netdev->event_callback(netdev, NETDEV2_EVENT_RX_COMPLETE); lock(dev); } } diff --git a/drivers/ethos/ethos.c b/drivers/ethos/ethos.c index 28bcd1beedf2..267f4813673d 100644 --- a/drivers/ethos/ethos.c +++ b/drivers/ethos/ethos.c @@ -111,7 +111,7 @@ static void _end_of_frame(ethos_t *dev) case ETHOS_FRAME_TYPE_DATA: if (dev->framesize) { dev->last_framesize = dev->framesize; - dev->netdev.event_callback((netdev2_t*) dev, NETDEV2_EVENT_ISR, dev->netdev.isr_arg); + dev->netdev.event_callback((netdev2_t*) dev, NETDEV2_EVENT_ISR); } break; case ETHOS_FRAME_TYPE_HELLO: @@ -177,7 +177,7 @@ static void ethos_isr(void *arg, uint8_t c) static void _isr(netdev2_t *netdev) { ethos_t *dev = (ethos_t *) netdev; - dev->netdev.event_callback((netdev2_t*) dev, NETDEV2_EVENT_RX_COMPLETE, NULL); + dev->netdev.event_callback((netdev2_t*) dev, NETDEV2_EVENT_RX_COMPLETE); } static int _init(netdev2_t *encdev) diff --git a/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c b/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c index d8a223534b1a..adcc23ad5576 100644 --- a/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c +++ b/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c @@ -45,11 +45,9 @@ static void _pass_on_packet(gnrc_pktsnip_t *pkt); * @brief Function called by the device driver on device events * * @param[in] event type of event - * @param[in] data optional parameter */ -static void _event_cb(netdev2_t *dev, netdev2_event_t event, void *data) +static void _event_cb(netdev2_t *dev, netdev2_event_t event) { - (void) data; gnrc_netdev2_t *gnrc_netdev2 = (gnrc_netdev2_t*) dev->isr_arg; if (event == NETDEV2_EVENT_ISR) { diff --git a/tests/driver_at86rf2xx/main.c b/tests/driver_at86rf2xx/main.c index 59416db3684b..c2c98cb87beb 100644 --- a/tests/driver_at86rf2xx/main.c +++ b/tests/driver_at86rf2xx/main.c @@ -42,10 +42,8 @@ static const shell_command_t shell_commands[] = { { NULL, NULL, NULL } }; -static void _event_cb(netdev2_t *dev, netdev2_event_t event, void *data) +static void _event_cb(netdev2_t *dev, netdev2_event_t event) { - (void) data; - if (event == NETDEV2_EVENT_ISR) { msg_t msg; diff --git a/tests/netdev2_test/main.c b/tests/netdev2_test/main.c index f5a4408a507c..13f7411100cc 100644 --- a/tests/netdev2_test/main.c +++ b/tests/netdev2_test/main.c @@ -153,8 +153,7 @@ static int test_receive(void) /* register for GNRC_NETTYPE_UNDEF */ gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &me); /* fire ISR event */ - _dev.netdev.event_callback((netdev2_t *)&_dev.netdev, NETDEV2_EVENT_ISR, - &_dev.netdev.isr_arg); + _dev.netdev.event_callback((netdev2_t *)&_dev.netdev, NETDEV2_EVENT_ISR); /* wait for packet from MAC layer*/ msg_receive(&msg); /* check message */ @@ -289,7 +288,7 @@ static void _dev_isr(netdev2_t *dev) { (void)dev; if (dev->event_callback) { - dev->event_callback(dev, NETDEV2_EVENT_RX_COMPLETE, dev->isr_arg); + dev->event_callback(dev, NETDEV2_EVENT_RX_COMPLETE); } } From 3ad195963d999f1d380f1745a7dd1d3f9a0e6267 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 22 Feb 2016 00:02:45 +0100 Subject: [PATCH 3/6] drivers: netdev2: rename isr_arg --- drivers/include/net/netdev2.h | 5 ++++- sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/include/net/netdev2.h b/drivers/include/net/netdev2.h index bede2b6d59ba..37bf8dcd7a34 100644 --- a/drivers/include/net/netdev2.h +++ b/drivers/include/net/netdev2.h @@ -101,11 +101,14 @@ typedef void (*netdev2_event_cb_t)(netdev2_t *dev, netdev2_event_t event); * * Supposed to be extended by driver implementations. * The extended structure should contain all variable driver state. + * + * Contains a field @p context which is not used by the drivers, but supposed to + * be used by upper layers to store reference information. */ struct netdev2 { const struct netdev2_driver *driver; /**< ptr to that driver's interface. */ netdev2_event_cb_t event_callback; /**< callback for device events */ - void *isr_arg; /**< argument to pass on isr event */ + void* context; /**< ptr to network stack context */ #ifdef MODULE_NETSTATS_L2 netstats_t stats; /**< transceiver's statistics */ #endif diff --git a/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c b/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c index adcc23ad5576..b28d6e772ed9 100644 --- a/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c +++ b/sys/net/gnrc/link_layer/netdev2/gnrc_netdev2.c @@ -48,7 +48,7 @@ static void _pass_on_packet(gnrc_pktsnip_t *pkt); */ static void _event_cb(netdev2_t *dev, netdev2_event_t event) { - gnrc_netdev2_t *gnrc_netdev2 = (gnrc_netdev2_t*) dev->isr_arg; + gnrc_netdev2_t *gnrc_netdev2 = (gnrc_netdev2_t*) dev->context; if (event == NETDEV2_EVENT_ISR) { msg_t msg; @@ -122,7 +122,7 @@ static void *_gnrc_netdev2_thread(void *args) /* register the event callback with the device driver */ dev->event_callback = _event_cb; - dev->isr_arg = (void*) gnrc_netdev2; + dev->context = (void*) gnrc_netdev2; /* register the device to the network stack*/ gnrc_netif_add(thread_getpid()); From af5914bafa63156081fae416e87773a431c67407 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 31 May 2016 22:10:21 +0200 Subject: [PATCH 4/6] pkg: lwip: adapt t renamed netdev2->isr_arg --- pkg/lwip/contrib/netdev2/lwip_netdev2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/lwip/contrib/netdev2/lwip_netdev2.c b/pkg/lwip/contrib/netdev2/lwip_netdev2.c index d80cf8716c7f..fdcc31498388 100644 --- a/pkg/lwip/contrib/netdev2/lwip_netdev2.c +++ b/pkg/lwip/contrib/netdev2/lwip_netdev2.c @@ -148,7 +148,7 @@ err_t lwip_netdev2_init(struct netif *netif) netif->flags |= NETIF_FLAG_LINK_UP; netif->flags |= NETIF_FLAG_IGMP; netif->flags |= NETIF_FLAG_MLD6; - netdev->isr_arg = netif; + netdev->context = netif; netdev->event_callback = _event_cb; #if LWIP_IPV6_AUTOCONFIG netif->ip6_autoconfig_enabled = 1; @@ -224,7 +224,7 @@ static void _event_cb(netdev2_t *dev, netdev2_event_t event, void *arg) } } else { - struct netif *netif = dev->isr_arg; + struct netif *netif = dev->context; switch (event) { case NETDEV2_EVENT_RX_COMPLETE: { struct pbuf *p = _get_recv_pkt(dev); From 575ee23679bb53bd586eebde461b986c5f0707be Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 31 May 2016 22:16:28 +0200 Subject: [PATCH 5/6] pkg: emb6: adapt to removed netdev2 callback_event arg --- pkg/emb6/contrib/netdev2/emb6_netdev2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/emb6/contrib/netdev2/emb6_netdev2.c b/pkg/emb6/contrib/netdev2/emb6_netdev2.c index 039db6f7627b..e2905c292cd5 100644 --- a/pkg/emb6/contrib/netdev2/emb6_netdev2.c +++ b/pkg/emb6/contrib/netdev2/emb6_netdev2.c @@ -80,9 +80,8 @@ static void _get_recv_pkt(void) } } -static void _event_cb(netdev2_t *dev, netdev2_event_t event, void *arg) +static void _event_cb(netdev2_t *dev, netdev2_event_t event) { - (void)arg; if (event == NETDEV2_EVENT_ISR) { /* EVENT_TYPE_PCK_LL is supposed to be used by drivers, so use it * (though NETDEV2_EVENT_ISR technically doesn't only signify From 15d9ce496300683714c68dbdb1d8653ffdd3ff6b Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 31 May 2016 22:18:54 +0200 Subject: [PATCH 6/6] pkg: lwip: adapt to changed netdev2->event_callback signature --- pkg/lwip/contrib/netdev2/lwip_netdev2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/lwip/contrib/netdev2/lwip_netdev2.c b/pkg/lwip/contrib/netdev2/lwip_netdev2.c index fdcc31498388..991aad3f8977 100644 --- a/pkg/lwip/contrib/netdev2/lwip_netdev2.c +++ b/pkg/lwip/contrib/netdev2/lwip_netdev2.c @@ -57,7 +57,7 @@ static err_t _eth_link_output(struct netif *netif, struct pbuf *p); #ifdef MODULE_LWIP_SIXLOWPAN static err_t _ieee802154_link_output(struct netif *netif, struct pbuf *p); #endif -static void _event_cb(netdev2_t *dev, netdev2_event_t event, void *arg); +static void _event_cb(netdev2_t *dev, netdev2_event_t event); static void *_event_loop(void *arg); err_t lwip_netdev2_init(struct netif *netif) @@ -209,9 +209,8 @@ static struct pbuf *_get_recv_pkt(netdev2_t *dev) return p; } -static void _event_cb(netdev2_t *dev, netdev2_event_t event, void *arg) +static void _event_cb(netdev2_t *dev, netdev2_event_t event) { - (void)arg; if (event == NETDEV2_EVENT_ISR) { assert(_pid != KERNEL_PID_UNDEF); msg_t msg;