From 4cf2d0a6a8eea2cf5318fa271aab7e18be0208fe Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 7 Jul 2017 23:31:13 -0400 Subject: [PATCH] ieee802154: Changes mac locking/unlocking to aid in debugging --- wireless/ieee802154/mac802154.c | 56 ++++++++++++------------ wireless/ieee802154/mac802154_assoc.c | 34 +++++++------- wireless/ieee802154/mac802154_data.c | 8 ++-- wireless/ieee802154/mac802154_internal.h | 32 ++++++++++++-- wireless/ieee802154/mac802154_notif.c | 8 ++-- wireless/ieee802154/mac802154_poll.c | 14 +++--- wireless/ieee802154/mac802154_scan.c | 10 ++--- wireless/ieee802154/mac802154_start.c | 6 +-- 8 files changed, 96 insertions(+), 72 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 09a3ab0274..8b401d9ae0 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -184,7 +184,7 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv, { /* Unlock MAC so that other work can be done to free a notification */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Take a count from the tx desc semaphore, waiting if necessary. We * only return from here with an error if we are allowing interruptions @@ -204,7 +204,7 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv, * MAC in order to ensure this happens correctly. */ - ret = mac802154_takesem(&priv->exclsem, allow_interrupt); + ret = mac802154_lock(priv, allow_interrupt); if (ret < 0) { wlwarn("WARNING: mac802154_takesem failed: %d\n", ret); @@ -609,7 +609,7 @@ static void mac802154_purge_worker(FAR void *arg) * signals so don't allow interruptions */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); while (1) { @@ -679,7 +679,7 @@ static int mac802154_radiopoll(FAR const struct ieee802154_radiocb_s *radiocb, /* Get exclusive access to the driver structure. Ignore any EINTR signals */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); if (gts) { @@ -694,7 +694,7 @@ static int mac802154_radiopoll(FAR const struct ieee802154_radiocb_s *radiocb, *txdesc = (FAR struct ieee802154_txdesc_s *)sq_remfirst(&priv->csma_queue); } - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) if (*txdesc != NULL) { @@ -731,11 +731,11 @@ static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, * signals so don't allow interruptions */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); sq_addlast((FAR sq_entry_t *)txdesc, &priv->txdone_queue); - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Schedule work with the work queue to process the completion further */ @@ -767,7 +767,7 @@ static void mac802154_txdone_worker(FAR void *arg) * signals so don't allow interruptions */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); while (1) { @@ -794,9 +794,9 @@ static void mac802154_txdone_worker(FAR void *arg) /* Release the MAC, call the callback, get exclusive access again */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); } break; @@ -878,7 +878,7 @@ static void mac802154_txdone_worker(FAR void *arg) mac802154_txdesc_free(priv, txdesc); } - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) } /**************************************************************************** @@ -909,7 +909,7 @@ static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, * signals so if we see one, just go back to trying to get access again. */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); /* Push the iob onto the tail of the frame list for processing */ @@ -917,7 +917,7 @@ static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, wlinfo("Frame received\n"); - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Schedule work with the work queue to process the completion further */ @@ -955,7 +955,7 @@ static void mac802154_rxframe_worker(FAR void *arg) * signals so if we see one, just go back to trying to get access again. */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); /* Pop the iob from the head of the frame list for processing */ @@ -963,7 +963,7 @@ static void mac802154_rxframe_worker(FAR void *arg) /* Once we pop off the indication, we don't need to keep the mac locked */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) if (ind == NULL) { @@ -1147,7 +1147,7 @@ static void mac802154_rxdataframe(FAR struct ieee802154_privmac_s *priv, /* Get exclusive access to the MAC */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); /* If we are currently performing a POLL operation and we've * received a data response, use the addressing information @@ -1266,7 +1266,7 @@ static void mac802154_rxdataframe(FAR struct ieee802154_privmac_s *priv, /* Release the MAC */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); /* If there was data, pass it along */ @@ -1282,7 +1282,7 @@ static void mac802154_rxdataframe(FAR struct ieee802154_privmac_s *priv, notify_with_lock: - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) notify_without_lock: @@ -1341,7 +1341,7 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv, /* Get exclusive access to the MAC */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); /* Search the list of indirect transactions to see if there are any waiting * for the requesting device. @@ -1371,7 +1371,7 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv, priv->radio->txdelayed(priv->radio, txdesc, 0); priv->beaconupdate = true; - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return; } } @@ -1388,7 +1388,7 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv, priv->radio->txdelayed(priv->radio, txdesc, 0); priv->beaconupdate = true; - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return; } } @@ -1494,7 +1494,7 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv, txdesc->frame = iob; txdesc->frametype = IEEE802154_FRAME_DATA; - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) priv->radio->txdelayed(priv->radio, txdesc, 0); } @@ -1513,7 +1513,7 @@ static void mac802154_sfevent(FAR const struct ieee802154_radiocb_s *radiocb, * signals so if we see one, just go back to trying to get access again. */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); switch (sfevent) { @@ -1536,7 +1536,7 @@ static void mac802154_sfevent(FAR const struct ieee802154_radiocb_s *radiocb, } - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) } /**************************************************************************** @@ -1823,9 +1823,9 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv, { /* Unlock the MAC, notify, then lock again */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); } /* If we have data pending for us, attempt to extract it. If for some @@ -1887,9 +1887,9 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv, /* Unlock the MAC, notify, then lock again */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); return; /* Return so that we don't free the notificaiton */ } } diff --git a/wireless/ieee802154/mac802154_assoc.c b/wireless/ieee802154/mac802154_assoc.c index 6f413eafe6..beaf1c34f6 100644 --- a/wireless/ieee802154/mac802154_assoc.c +++ b/wireless/ieee802154/mac802154_assoc.c @@ -111,7 +111,7 @@ int mac802154_req_associate(MACHANDLE mac, /* Get exclusive access to the MAC */ - ret = mac802154_takesem(&priv->exclsem, true); + ret = mac802154_lock(priv, true); if (ret < 0) { mac802154_givesem(&priv->opsem); @@ -154,7 +154,7 @@ int mac802154_req_associate(MACHANDLE mac, if (ret < 0) { iob_free(iob); - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_givesem(&priv->opsem); return ret; } @@ -299,7 +299,7 @@ int mac802154_req_associate(MACHANDLE mac, /* We no longer need to have the MAC layer locked. */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return OK; } @@ -394,7 +394,7 @@ int mac802154_resp_associate(MACHANDLE mac, /* Get exclusive access to the MAC */ - ret = mac802154_takesem(&priv->exclsem, true); + ret = mac802154_lock(priv, true); if (ret < 0) { iob_free(iob); @@ -407,7 +407,7 @@ int mac802154_resp_associate(MACHANDLE mac, if (ret < 0) { iob_free(iob); - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return ret; } @@ -420,7 +420,7 @@ int mac802154_resp_associate(MACHANDLE mac, mac802154_setupindirect(priv, txdesc); - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return OK; } @@ -484,9 +484,9 @@ void mac802154_txdone_assocreq(FAR struct ieee802154_privmac_s *priv, /* Release the MAC, call the callback, get exclusive access again */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); } else { @@ -627,9 +627,9 @@ void mac802154_txdone_datareq_assoc(FAR struct ieee802154_privmac_s *priv, /* Release the MAC, call the callback, get exclusive access again */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); } else { @@ -689,7 +689,7 @@ void mac802154_rx_assocreq(FAR struct ieee802154_privmac_s *priv, /* Get exclusive access to the MAC */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); /* Allocate a notification to pass to the next highest layer */ @@ -730,7 +730,7 @@ void mac802154_rx_assocreq(FAR struct ieee802154_privmac_s *priv, /* Unlock the MAC */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Notify the next highest layer of the association status */ @@ -738,7 +738,7 @@ void mac802154_rx_assocreq(FAR struct ieee802154_privmac_s *priv, return; errout_with_sem: - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return; } @@ -785,7 +785,7 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv, /* Get exclusive access to the MAC */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); /* Allocate a notification to pass to the next highest layer */ @@ -838,7 +838,7 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv, /* Unlock the MAC */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Notify the next highest layer of the association status */ @@ -875,7 +875,7 @@ static void mac802154_assoctimeout(FAR struct ieee802154_privmac_s *priv) * Don't allow EINTR to interrupt. */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); mac802154_notif_alloc(priv, ¬if, false); /* We are no longer performing the association operation */ @@ -887,7 +887,7 @@ static void mac802154_assoctimeout(FAR struct ieee802154_privmac_s *priv) /* Release the MAC */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) notif->notiftype = IEEE802154_NOTIFY_CONF_ASSOC; notif->u.assocconf.status = IEEE802154_STATUS_NO_DATA; diff --git a/wireless/ieee802154/mac802154_data.c b/wireless/ieee802154/mac802154_data.c index 171751169b..066c4815b8 100644 --- a/wireless/ieee802154/mac802154_data.c +++ b/wireless/ieee802154/mac802154_data.c @@ -147,7 +147,7 @@ int mac802154_req_data(MACHANDLE mac, /* From this point on, we need exclusive access to the privmac struct */ - ret = mac802154_takesem(&priv->exclsem, true); + ret = mac802154_lock(priv, true); if (ret < 0) { /* Should only fail if interrupted by a signal */ @@ -313,7 +313,7 @@ int mac802154_req_data(MACHANDLE mac, memcpy(&txdesc->destaddr, &meta->destaddr, sizeof(struct ieee802154_addr_s)); mac802154_setupindirect(priv, txdesc); - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) } else { @@ -329,7 +329,7 @@ int mac802154_req_data(MACHANDLE mac, /* We no longer need to have the MAC layer locked. */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Notify the radio driver that there is data available */ @@ -346,7 +346,7 @@ errout_with_txdesc: mac802154_txdesc_free(priv, txdesc); errout_with_sem: - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return ret; } diff --git a/wireless/ieee802154/mac802154_internal.h b/wireless/ieee802154/mac802154_internal.h index d3f86be9dd..b31c0f2931 100644 --- a/wireless/ieee802154/mac802154_internal.h +++ b/wireless/ieee802154/mac802154_internal.h @@ -388,8 +388,6 @@ void mac802154_createdatareq(FAR struct ieee802154_privmac_s *priv, void mac802154_updatebeacon(FAR struct ieee802154_privmac_s *priv); - - /**************************************************************************** * Helper Macros/Inline Functions ****************************************************************************/ @@ -564,9 +562,9 @@ void mac802154_updatebeacon(FAR struct ieee802154_privmac_s *priv); ((GETHOST16(ptr, index) & IEEE802154_PENDADDR_NEADDR) >> \ IEEE802154_PENDADDR_SHIFT_NEADDR) -/* General helper macros ****************************************************/ +/* General helpers ****************************************************/ -#define mac802154_givesem(s) sem_post(s); +#define mac802154_givesem(s) sem_post(s) static inline int mac802154_takesem(sem_t *sem, bool allowinterrupt) { @@ -593,6 +591,32 @@ static inline int mac802154_takesem(sem_t *sem, bool allowinterrupt) return OK; } +#define mac802154_unlock(dev) \ + mac802154_givesem(&dev->exclsem); \ + wlinfo("MAC unlocked\n"); + +#define mac802154_lock(dev, allowinterrupt) \ + mac802154_lockpriv(dev, allowinterrupt, __FUNCTION__) + +static inline int mac802154_lockpriv(FAR struct ieee802154_privmac_s *dev, + bool allowinterrupt, FAR const char *funcname) +{ + int ret; + + wlinfo("Locking MAC: %s\n", funcname); + ret = mac802154_takesem(&dev->exclsem, allowinterrupt); + if (ret < 0) + { + wlinfo("Failed to lock MAC\n"); + } + else + { + wlinfo("MAC locked\n"); + } + + return ret; +} + static inline void mac802154_txdesc_free(FAR struct ieee802154_privmac_s *priv, FAR struct ieee802154_txdesc_s *txdesc) { diff --git a/wireless/ieee802154/mac802154_notif.c b/wireless/ieee802154/mac802154_notif.c index 059d95624c..0d2727c0e1 100644 --- a/wireless/ieee802154/mac802154_notif.c +++ b/wireless/ieee802154/mac802154_notif.c @@ -76,7 +76,7 @@ void mac802154_notif_free(MACHANDLE mac, FAR struct ieee802154_notif_s *notif) /* Lock the MAC */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); /* Call the internal helper function to free the notification */ @@ -84,7 +84,7 @@ void mac802154_notif_free(MACHANDLE mac, FAR struct ieee802154_notif_s *notif) /* Unlock the MAC */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) } /**************************************************************************** @@ -170,7 +170,7 @@ int mac802154_notif_alloc(FAR struct ieee802154_privmac_s *priv, { /* Unlock MAC so that other work can be done to free a notification */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Take a count from the notification semaphore, waiting if necessary. We * only return from here with an error if we are allowing interruptions @@ -189,7 +189,7 @@ int mac802154_notif_alloc(FAR struct ieee802154_privmac_s *priv, * MAC in order to ensure this happens correctly. */ - ret = mac802154_takesem(&priv->exclsem, allow_interrupt); + ret = mac802154_lock(priv, allow_interrupt); if (ret < 0) { mac802154_givesem(&priv->notif_sem); diff --git a/wireless/ieee802154/mac802154_poll.c b/wireless/ieee802154/mac802154_poll.c index 368f8baac2..715518e916 100644 --- a/wireless/ieee802154/mac802154_poll.c +++ b/wireless/ieee802154/mac802154_poll.c @@ -106,7 +106,7 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) /* Get exclusive access to the MAC */ - ret = mac802154_takesem(&priv->exclsem, true); + ret = mac802154_lock(priv, true); if (ret < 0) { mac802154_givesem(&priv->opsem); @@ -121,7 +121,7 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) ret = mac802154_txdesc_alloc(priv, &txdesc, true); if (ret < 0) { - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_givesem(&priv->opsem); return ret; } @@ -158,7 +158,7 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) /* We no longer need to have the MAC layer locked. */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) /* Notify the radio driver that there is data available */ @@ -222,9 +222,9 @@ void mac802154_txdone_datareq_poll(FAR struct ieee802154_privmac_s *priv, /* Release the MAC, call the callback, get exclusive access again */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); } else { @@ -269,7 +269,7 @@ void mac802154_polltimeout(FAR struct ieee802154_privmac_s *priv) * Don't allow EINTR to interrupt. */ - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); mac802154_notif_alloc(priv, ¬if, false); /* We are no longer performing the association operation */ @@ -279,7 +279,7 @@ void mac802154_polltimeout(FAR struct ieee802154_privmac_s *priv) /* Release the MAC */ - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) notif->notiftype = IEEE802154_NOTIFY_CONF_POLL; notif->u.pollconf.status = IEEE802154_STATUS_NO_DATA; diff --git a/wireless/ieee802154/mac802154_scan.c b/wireless/ieee802154/mac802154_scan.c index 819ac141f8..c24ae0b5f1 100644 --- a/wireless/ieee802154/mac802154_scan.c +++ b/wireless/ieee802154/mac802154_scan.c @@ -110,7 +110,7 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) /* Get exclusive access to the MAC */ - ret = mac802154_takesem(&priv->exclsem, true); + ret = mac802154_lock(priv, true); if (ret < 0) { mac802154_givesem(&priv->opsem); @@ -186,11 +186,11 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) break; } - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return OK; errout_with_sem: - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_givesem(&priv->opsem); errout: return ret; @@ -205,7 +205,7 @@ void mac802154_scanfinish(FAR struct ieee802154_privmac_s *priv, { FAR struct ieee802154_notif_s * notif; - mac802154_takesem(&priv->exclsem, false); + mac802154_lock(priv, false); mac802154_notif_alloc(priv, ¬if, false); priv->curr_op = MAC802154_OP_NONE; @@ -233,7 +233,7 @@ void mac802154_scanfinish(FAR struct ieee802154_privmac_s *priv, mac802154_setpanid(priv, priv->panidbeforescan); - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) mac802154_notify(priv, notif); } diff --git a/wireless/ieee802154/mac802154_start.c b/wireless/ieee802154/mac802154_start.c index 5a9c4379ea..2bab5afd15 100644 --- a/wireless/ieee802154/mac802154_start.c +++ b/wireless/ieee802154/mac802154_start.c @@ -72,7 +72,7 @@ int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req) /* Get exclusive access to the MAC */ - ret = mac802154_takesem(&priv->exclsem, true); + ret = mac802154_lock(priv, true); if (ret < 0) { return ret; @@ -194,11 +194,11 @@ int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req) } } - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return OK; errout: - mac802154_givesem(&priv->exclsem); + mac802154_unlock(priv) return ret; } \ No newline at end of file