Replace nxsem API when used as a lock with nxmutex API

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
anjiahao
2022-09-06 14:18:45 +08:00
committed by Masayuki Ishikawa
parent 0dfd1f004d
commit d1d46335df
710 changed files with 7503 additions and 14852 deletions
-7
View File
@@ -91,13 +91,6 @@ config MAC802154_SFEVENT_VERBOSE
---help---
Enable verbose logging of superframe events Default: false
config MAC802154_LOCK_VERBOSE
bool "Verbose logging related to MAC lock management"
default n
depends on DEBUG_WIRELESS_INFO
---help---
Enable verbose logging of MAC lock management. Default: false
config IEEE802154_MACDEV
bool "Character driver for IEEE 802.15.4 MAC layer"
default n
+44 -45
View File
@@ -140,8 +140,7 @@ static void mac802154_resetqueues(FAR struct ieee802154_privmac_s *priv)
****************************************************************************/
int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_txdesc_s **txdesc,
bool allow_interrupt)
FAR struct ieee802154_txdesc_s **txdesc)
{
int ret;
FAR struct ieee802154_primitive_s *primitive;
@@ -162,19 +161,19 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
{
/* Unlock MAC so that other work can be done to free a notification */
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
/* Take a count from the tx desc semaphore, waiting if necessary. We
* only return from here with an error if we are allowing interruptions
* and we received a signal.
*/
ret = mac802154_takesem(&priv->txdesc_sem, allow_interrupt);
ret = nxsem_wait_uninterruptible(&priv->txdesc_sem);
if (ret < 0)
{
/* MAC is already released */
wlwarn("WARNING: mac802154_takesem failed: %d\n", ret);
wlwarn("WARNING: nxsem_wait_uninterruptible failed: %d\n", ret);
return ret;
}
@@ -183,12 +182,12 @@ int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
* re-lock the MAC in order to ensure this happens correctly.
*/
ret = mac802154_lock(priv, allow_interrupt);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
wlwarn("WARNING: mac802154_lock failed: %d\n", ret);
wlwarn("WARNING: nxmutex_lock failed: %d\n", ret);
mac802154_givesem(&priv->txdesc_sem);
nxsem_post(&priv->txdesc_sem);
return ret;
}
@@ -377,10 +376,10 @@ static void mac802154_notify_worker(FAR void *arg)
FAR struct ieee802154_primitive_s *primitive;
int ret;
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
primitive =
(FAR struct ieee802154_primitive_s *)sq_remfirst(&priv->primitive_queue);
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
while (primitive != NULL)
{
@@ -450,10 +449,10 @@ static void mac802154_notify_worker(FAR void *arg)
/* Get the next primitive then loop */
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
primitive = (FAR struct ieee802154_primitive_s *)
sq_remfirst(&priv->primitive_queue);
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
}
}
@@ -722,7 +721,7 @@ static void mac802154_purge_worker(FAR void *arg)
* signals so don't allow interruptions
*/
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
while (1)
{
@@ -768,7 +767,7 @@ static void mac802154_purge_worker(FAR void *arg)
}
}
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -796,7 +795,7 @@ static int
/* Get exclusive access to the driver structure. Ignore EINTR signals */
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
if (gts)
{
@@ -813,7 +812,7 @@ static int
sq_remfirst(&priv->csma_queue);
}
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
if (*txdesc != NULL)
{
@@ -851,11 +850,11 @@ static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb,
* signals so don't allow interruptions
*/
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
sq_addlast((FAR sq_entry_t *)txdesc, &priv->txdone_queue);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
/* Schedule work with the work queue to process the completion further */
@@ -887,7 +886,7 @@ static void mac802154_txdone_worker(FAR void *arg)
* signals so don't allow interruptions
*/
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
while (1)
{
@@ -995,7 +994,7 @@ static void mac802154_txdone_worker(FAR void *arg)
mac802154_txdesc_free(priv, txdesc);
}
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -1026,7 +1025,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_lock(priv, false);
nxmutex_lock(&priv->lock);
/* Push the iob onto the tail of the frame list for processing */
@@ -1034,7 +1033,7 @@ static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb,
wlinfo("Frame received\n");
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
/* Schedule work with the work queue to process the completion further */
@@ -1073,7 +1072,7 @@ static void mac802154_rxframe_worker(FAR void *arg)
* again.
*/
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* Pop the data indication from the head of the frame list for
* processing. Note: dataind_queue contains ieee802154_primitive_s
@@ -1085,7 +1084,7 @@ static void mac802154_rxframe_worker(FAR void *arg)
/* Once we pop off the indication, we needn't to keep the mac locked */
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
if (ind == NULL)
{
@@ -1284,7 +1283,7 @@ static void mac802154_rxdataframe(FAR struct ieee802154_privmac_s *priv,
/* Get exclusive access to the MAC */
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* If we are currently performing a POLL operation and we've
* received a data response, use the addressing information
@@ -1408,7 +1407,7 @@ static void mac802154_rxdataframe(FAR struct ieee802154_privmac_s *priv,
priv->curr_op = MAC802154_OP_NONE;
priv->cmd_desc = NULL;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
/* Release the MAC and notify the next highest layer */
@@ -1431,7 +1430,7 @@ static void mac802154_rxdataframe(FAR struct ieee802154_privmac_s *priv,
mac802154_notify(priv, (FAR struct ieee802154_primitive_s *)ind);
}
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -1452,7 +1451,7 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv,
/* Get exclusive access to the MAC */
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* Search the list of indirect transactions to see if there are any waiting
* for the requesting device.
@@ -1492,7 +1491,7 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv,
priv->radio->txdelayed(priv->radio, txdesc, 0);
priv->beaconupdate = true;
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return;
}
}
@@ -1509,7 +1508,7 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv,
priv->radio->txdelayed(priv->radio, txdesc, 0);
priv->beaconupdate = true;
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return;
}
}
@@ -1614,13 +1613,13 @@ static void mac802154_rxdatareq(FAR struct ieee802154_privmac_s *priv,
/* Allocate the txdesc, waiting if necessary, allow interruptions */
mac802154_txdesc_alloc(priv, &txdesc, false);
mac802154_txdesc_alloc(priv, &txdesc);
txdesc->frame = iob;
txdesc->frametype = IEEE802154_FRAME_DATA;
txdesc->ackreq = false;
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
priv->radio->txdelayed(priv->radio, txdesc, 0);
}
@@ -1651,7 +1650,7 @@ mac802154_edresult(FAR const struct ieee802154_radiocb_s *radiocb,
* signals so if we see one, just go back to trying to get access again.
*/
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* If we are actively performing a scan operation, notify the handler */
@@ -1662,7 +1661,7 @@ mac802154_edresult(FAR const struct ieee802154_radiocb_s *radiocb,
/* Relinquish control of the private structure */
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
}
static void mac802154_sfevent(FAR const struct ieee802154_radiocb_s *radiocb,
@@ -1679,7 +1678,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_lock(priv, false);
nxmutex_lock(&priv->lock);
switch (sfevent)
{
@@ -1705,7 +1704,7 @@ static void mac802154_sfevent(FAR const struct ieee802154_radiocb_s *radiocb,
break;
}
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -1902,7 +1901,7 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv,
/* At this point, all relevant info is extracted from the incoming frame */
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
if (priv->curr_op == MAC802154_OP_SCAN)
{
@@ -1925,7 +1924,7 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv,
/* The beacon is the same as another, so discard it */
ieee802154_primitive_free(primitive);
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
return;
}
@@ -1980,7 +1979,7 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv,
if (priv->curr_op == MAC802154_OP_ASSOC && pending_eaddr)
{
priv->curr_cmd = IEEE802154_CMD_DATA_REQ;
mac802154_txdesc_alloc(priv, &respdesc, false);
mac802154_txdesc_alloc(priv, &respdesc);
mac802154_createdatareq(priv, &priv->pandesc.coordaddr,
IEEE802154_ADDRMODE_EXTENDED, respdesc);
@@ -2015,7 +2014,7 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv,
if (pending_saddr | pending_eaddr)
{
mac802154_txdesc_alloc(priv, &respdesc, false);
mac802154_txdesc_alloc(priv, &respdesc);
if (priv->curr_op == MAC802154_OP_POLL)
{
@@ -2028,7 +2027,7 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv,
else if (priv->curr_op == MAC802154_OP_NONE)
{
DEBUGASSERT(priv->opsem.semcount == 1);
mac802154_takesem(&priv->opsem, false);
nxsem_wait_uninterruptible(&priv->opsem);
priv->curr_op = MAC802154_OP_AUTOEXTRACT;
priv->curr_cmd = IEEE802154_CMD_DATA_REQ;
}
@@ -2061,7 +2060,7 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv,
if (beacon->payloadlength > 0)
{
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
return;
}
}
@@ -2074,13 +2073,13 @@ static void mac802154_rxbeaconframe(FAR struct ieee802154_privmac_s *priv,
*/
mac802154_notify(priv, primitive);
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
return; /* Return so that we don't free the primitive */
}
}
}
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
ieee802154_primitive_free(primitive);
return;
@@ -2136,7 +2135,7 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev)
/* Allow exclusive access to the privmac struct */
nxsem_init(&mac->exclsem, 0, 1);
nxmutex_init(&mac->lock);
/* Allow exclusive access to the dedicated command transaction */
+1 -1
View File
@@ -138,7 +138,7 @@ int mac802154_get_mhrlen(MACHANDLE mac,
int mac802154_req_data(MACHANDLE mac,
FAR const struct ieee802154_frame_meta_s *meta,
FAR struct iob_s *frame, bool allowinterrupt);
FAR struct iob_s *frame);
/****************************************************************************
* Name: mac802154_req_purge
+24 -26
View File
@@ -86,7 +86,7 @@ int mac802154_req_associate(MACHANDLE mac,
* cmdtrans but needs access to the MAC in order to unlock it.
*/
ret = mac802154_takesem(&priv->opsem, true);
ret = nxsem_wait_uninterruptible(&priv->opsem);
if (ret < 0)
{
return ret;
@@ -97,10 +97,10 @@ int mac802154_req_associate(MACHANDLE mac,
/* Get exclusive access to the MAC */
ret = mac802154_lock(priv, true);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
return ret;
}
@@ -142,12 +142,12 @@ int mac802154_req_associate(MACHANDLE mac,
/* Allocate the txdesc, waiting if necessary */
ret = mac802154_txdesc_alloc(priv, &txdesc, true);
ret = mac802154_txdesc_alloc(priv, &txdesc);
if (ret < 0)
{
iob_free(iob);
mac802154_unlock(priv)
mac802154_givesem(&priv->opsem);
nxmutex_unlock(&priv->lock);
nxsem_post(&priv->opsem);
return ret;
}
@@ -300,8 +300,7 @@ int mac802154_req_associate(MACHANDLE mac,
/* We no longer need to have the MAC layer locked. */
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -398,7 +397,7 @@ int mac802154_resp_associate(MACHANDLE mac,
/* Get exclusive access to the MAC */
ret = mac802154_lock(priv, true);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
iob_free(iob);
@@ -407,11 +406,11 @@ int mac802154_resp_associate(MACHANDLE mac,
/* Allocate the txdesc, waiting if necessary */
ret = mac802154_txdesc_alloc(priv, &txdesc, true);
ret = mac802154_txdesc_alloc(priv, &txdesc);
if (ret < 0)
{
iob_free(iob);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -425,8 +424,7 @@ int mac802154_resp_associate(MACHANDLE mac,
mac802154_setupindirect(priv, txdesc);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -484,7 +482,7 @@ void mac802154_txdone_assocreq(FAR struct ieee802154_privmac_s *priv,
priv->curr_op = MAC802154_OP_NONE;
priv->cmd_desc = NULL;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
/* Release the MAC, call the callback, get exclusive access again */
@@ -623,7 +621,7 @@ void mac802154_txdone_datareq_assoc(FAR struct ieee802154_privmac_s *priv,
priv->curr_op = MAC802154_OP_NONE;
priv->cmd_desc = NULL;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
mac802154_notify(priv, primitive);
}
@@ -719,12 +717,12 @@ void mac802154_rx_assocreq(FAR struct ieee802154_privmac_s *priv,
/* Get exclusive access to the MAC */
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* Notify the next highest layer of the association status */
mac802154_notify(priv, primitive);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -775,7 +773,7 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
/* Get exclusive access to the MAC */
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* Parse the short address from the response */
@@ -818,13 +816,13 @@ void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
priv->curr_op = MAC802154_OP_NONE;
priv->cmd_desc = NULL;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
mac802154_rxdisable(priv);
/* Notify the next highest layer of the association status */
mac802154_notify(priv, primitive);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -882,12 +880,12 @@ static void mac802154_assoctimeout(FAR void *arg)
priv->curr_op = MAC802154_OP_NONE;
priv->cmd_desc = NULL;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
mac802154_rxdisable(priv);
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
mac802154_notify(priv, primitive);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -908,14 +906,14 @@ static void mac802154_extract_assocresp(FAR void *arg)
(FAR struct ieee802154_privmac_s *)arg;
FAR struct ieee802154_txdesc_s *respdesc;
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
mac802154_txdesc_alloc(priv, &respdesc, false);
mac802154_txdesc_alloc(priv, &respdesc);
mac802154_createdatareq(priv, &priv->pandesc.coordaddr,
IEEE802154_ADDRMODE_EXTENDED, respdesc);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
priv->curr_cmd = IEEE802154_CMD_DATA_REQ;
+11 -11
View File
@@ -55,7 +55,7 @@
int mac802154_req_data(MACHANDLE mac,
FAR const struct ieee802154_frame_meta_s *meta,
FAR struct iob_s *frame, bool allowinterrupt)
FAR struct iob_s *frame)
{
FAR struct ieee802154_privmac_s *priv =
(FAR struct ieee802154_privmac_s *)mac;
@@ -141,12 +141,12 @@ int mac802154_req_data(MACHANDLE mac,
/* From this point on, we need exclusive access to the privmac struct */
ret = mac802154_lock(priv, allowinterrupt);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
/* Should only fail if interrupted by a signal */
wlwarn("WARNING: mac802154_takesem failed: %d\n", ret);
wlwarn("WARNING: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -212,7 +212,7 @@ int mac802154_req_data(MACHANDLE mac,
if (priv->devmode != IEEE802154_DEVMODE_PANCOORD)
{
ret = -EINVAL;
goto errout_with_sem;
goto errout_with_lock;
}
}
@@ -238,15 +238,15 @@ int mac802154_req_data(MACHANDLE mac,
/* Allocate the txdesc, waiting if necessary, allow interruptions */
ret = mac802154_txdesc_alloc(priv, &txdesc, true);
ret = mac802154_txdesc_alloc(priv, &txdesc);
if (ret < 0)
{
/* Should only fail if interrupted by a signal while re-acquiring
* exclsem. So the lock is not held if a failure is returned.
* lock. So the lock is not held if a failure is returned.
*/
wlwarn("WARNING: mac802154_txdesc_alloc failed: %d\n", ret);
return ret;
goto errout_with_lock;
}
/* Set the offset to 0 to include the header ( we do not want to
@@ -320,7 +320,7 @@ int mac802154_req_data(MACHANDLE mac,
memcpy(&txdesc->destaddr, &meta->destaddr,
sizeof(struct ieee802154_addr_s));
mac802154_setupindirect(priv, txdesc);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
else
{
@@ -336,7 +336,7 @@ int mac802154_req_data(MACHANDLE mac,
/* We no longer need to have the MAC layer locked. */
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
/* Notify the radio driver that there is data available */
@@ -353,8 +353,8 @@ errout_with_txdesc:
txdesc->frame = NULL;
mac802154_txdesc_free(priv, txdesc);
errout_with_sem:
mac802154_unlock(priv)
errout_with_lock:
nxmutex_unlock(&priv->lock);
return ret;
}
+28 -46
View File
@@ -84,7 +84,7 @@ struct mac802154_chardevice_s
{
MACHANDLE md_mac; /* Saved binding to the mac layer */
struct mac802154dev_callback_s md_cb; /* Callback information */
sem_t md_exclsem; /* Exclusive device access */
sem_t md_lock; /* Exclusive device access */
/* Hold a list of events */
@@ -117,11 +117,6 @@ struct mac802154_chardevice_s
* Private Function Prototypes
****************************************************************************/
/* Semaphore helpers */
static inline int mac802154dev_takesem(sem_t *sem);
#define mac802154dev_givesem(s) nxsem_post(s);
static int mac802154dev_notify(FAR struct mac802154_maccb_s *maccb,
FAR struct ieee802154_primitive_s *primitive);
static int mac802154dev_rxframe(FAR struct mac802154_chardevice_s *dev,
@@ -158,19 +153,6 @@ static const struct file_operations mac802154dev_fops =
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: mac802154dev_semtake
*
* Description:
* Acquire the semaphore used for access serialization.
*
****************************************************************************/
static inline int mac802154dev_takesem(sem_t *sem)
{
return nxsem_wait(sem);
}
/****************************************************************************
* Name: mac802154dev_open
*
@@ -194,10 +176,10 @@ static int mac802154dev_open(FAR struct file *filep)
/* Get exclusive access to the MAC driver data structure */
ret = mac802154dev_takesem(&dev->md_exclsem);
ret = nxmutex_lock(&dev->md_lock);
if (ret < 0)
{
wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret);
wlerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret;
}
@@ -210,7 +192,7 @@ static int mac802154dev_open(FAR struct file *filep)
{
wlerr("ERROR: Failed to allocate new open struct\n");
ret = -ENOMEM;
goto errout_with_sem;
goto errout_with_lock;
}
/* Attach the open struct to the device */
@@ -223,8 +205,8 @@ static int mac802154dev_open(FAR struct file *filep)
filep->f_priv = (FAR void *)opriv;
ret = OK;
errout_with_sem:
mac802154dev_givesem(&dev->md_exclsem);
errout_with_lock:
nxmutex_unlock(&dev->md_lock);
return ret;
}
@@ -277,10 +259,10 @@ static int mac802154dev_close(FAR struct file *filep)
/* Get exclusive access to the driver structure */
ret = mac802154dev_takesem(&dev->md_exclsem);
ret = nxmutex_lock(&dev->md_lock);
if (ret < 0)
{
wlerr("ERROR: mac802154_takesem failed: %d\n", ret);
wlerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret;
}
@@ -337,7 +319,7 @@ static int mac802154dev_close(FAR struct file *filep)
ret = OK;
errout_with_exclsem:
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
return ret;
}
@@ -380,10 +362,10 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer,
{
/* Get exclusive access to the driver structure */
ret = mac802154dev_takesem(&dev->md_exclsem);
ret = nxmutex_lock(&dev->md_lock);
if (ret < 0)
{
wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret);
wlerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret;
}
@@ -398,7 +380,7 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer,
if (ind != NULL)
{
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
break;
}
@@ -412,12 +394,12 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer,
if ((filep->f_oflags & O_NONBLOCK) || dev->readpending)
{
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
return -EAGAIN;
}
dev->readpending = true;
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
/* Wait to be signaled when a frame is added to the list */
@@ -551,7 +533,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
/* Pass the request to the MAC layer */
ret = mac802154_req_data(dev->md_mac, &tx->meta, iob, true);
ret = mac802154_req_data(dev->md_mac, &tx->meta, iob);
if (ret < 0)
{
iob_free(iob);
@@ -587,10 +569,10 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
/* Get exclusive access to the driver structure */
ret = mac802154dev_takesem(&dev->md_exclsem);
ret = nxmutex_lock(&dev->md_lock);
if (ret < 0)
{
wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret);
wlerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret;
}
@@ -660,7 +642,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
}
dev->geteventpending = true;
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
/* Wait to be signaled when an event is queued */
@@ -675,10 +657,10 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
* and pop an event off the queue
*/
ret = mac802154dev_takesem(&dev->md_exclsem);
ret = nxmutex_lock(&dev->md_lock);
if (ret < 0)
{
wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret);
wlerr("ERROR: nxsem_wait failed: %d\n", ret);
return ret;
}
}
@@ -701,7 +683,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
break;
}
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
return ret;
}
@@ -736,7 +718,7 @@ static int mac802154dev_notify(FAR struct mac802154_maccb_s *maccb,
* again
*/
while (mac802154dev_takesem(&dev->md_exclsem) != 0);
while (nxmutex_lock(&dev->md_lock) != 0);
sq_addlast((FAR sq_entry_t *)primitive, &dev->primitive_queue);
@@ -757,7 +739,7 @@ static int mac802154dev_notify(FAR struct mac802154_maccb_s *maccb,
SI_QUEUE, &dev->md_notify_work);
}
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
return OK;
}
@@ -787,7 +769,7 @@ static int mac802154dev_rxframe(FAR struct mac802154_chardevice_s *dev,
* signals so if we see one, just go back to trying to get access again
*/
while (mac802154dev_takesem(&dev->md_exclsem) != 0);
while (nxmutex_lock(&dev->md_lock) != 0);
/* Push the indication onto the list */
@@ -805,7 +787,7 @@ static int mac802154dev_rxframe(FAR struct mac802154_chardevice_s *dev,
/* Release the driver */
mac802154dev_givesem(&dev->md_exclsem);
nxmutex_unlock(&dev->md_lock);
return OK;
}
@@ -848,8 +830,8 @@ int mac802154dev_register(MACHANDLE mac, int minor)
/* Initialize the new mac driver instance */
dev->md_mac = mac;
nxsem_init(&dev->md_exclsem, 0, 1); /* Allow the device to be opened once
* before blocking */
nxmutex_init(&dev->md_lock); /* Allow the device to be opened once
* before blocking */
nxsem_init(&dev->readsem, 0, 0);
nxsem_set_protocol(&dev->readsem, SEM_PRIO_NONE);
@@ -904,7 +886,7 @@ int mac802154dev_register(MACHANDLE mac, int minor)
return OK;
errout_with_priv:
nxsem_destroy(&dev->md_exclsem);
nxmutex_destroy(&dev->md_lock);
kmm_free(dev);
return ret;
}
+5 -54
View File
@@ -35,6 +35,7 @@
#include <nuttx/wdog.h>
#include <nuttx/wqueue.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
@@ -104,8 +105,8 @@ struct ieee802154_privmac_s
FAR struct mac802154_maccb_s *cb; /* Head of a list of MAC callbacks */
FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */
sem_t exclsem; /* Support exclusive access */
uint8_t nclients; /* Number of notification clients */
mutex_t lock; /* Support exclusive access */
uint8_t nclients; /* Number of notification clients */
/* Only support a single command at any given time. As of now I see no
* condition where you need to have more than one command frame
@@ -305,7 +306,7 @@ struct ieee802154_privmac_s
****************************************************************************/
int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_txdesc_s **txdesc, bool allow_interrupt);
FAR struct ieee802154_txdesc_s **txdesc);
void mac802154_setupindirect(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_txdesc_s *txdesc);
@@ -510,62 +511,12 @@ void mac802154_notify(FAR struct ieee802154_privmac_s *priv,
/* General helpers **********************************************************/
#define mac802154_givesem(s) nxsem_post(s)
static inline int mac802154_takesem(sem_t *sem, bool allowinterrupt)
{
if (allowinterrupt)
{
return nxsem_wait(sem);
}
else
{
return nxsem_wait_uninterruptible(sem);
}
}
#ifdef CONFIG_MAC802154_LOCK_VERBOSE
#define mac802154_unlock(dev) \
mac802154_givesem(&dev->exclsem); \
wlinfo("MAC unlocked\n");
#else
#define mac802154_unlock(dev) \
mac802154_givesem(&dev->exclsem);
#endif
#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;
#ifdef CONFIG_MAC802154_LOCK_VERBOSE
wlinfo("Locking MAC: %s\n", funcname);
#endif
ret = mac802154_takesem(&dev->exclsem, allowinterrupt);
if (ret < 0)
{
wlwarn("Failed to lock MAC\n");
}
else
{
#ifdef CONFIG_MAC802154_LOCK_VERBOSE
wlinfo("MAC locked\n");
#endif
}
return ret;
}
static inline void
mac802154_txdesc_free(FAR struct ieee802154_privmac_s *priv,
FAR struct ieee802154_txdesc_s *txdesc)
{
sq_addlast((FAR sq_entry_t *)txdesc, &priv->txdesc_queue);
mac802154_givesem(&priv->txdesc_sem);
nxsem_post(&priv->txdesc_sem);
}
/****************************************************************************
+13 -12
View File
@@ -39,6 +39,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/signal.h>
#include <nuttx/wqueue.h>
#include <nuttx/mutex.h>
#include <nuttx/mm/iob.h>
#include <nuttx/net/arp.h>
#include <nuttx/net/netdev.h>
@@ -130,7 +131,7 @@ struct macnet_driver_s
/* For internal use by this driver */
sem_t md_exclsem; /* Exclusive access to struct */
mutex_t md_lock; /* Exclusive access to struct */
struct macnet_callback_s md_cb; /* Callback information */
MACHANDLE md_mac; /* Contained MAC interface */
bool md_bifup; /* true:ifup false:ifdown */
@@ -362,7 +363,7 @@ static int macnet_notify(FAR struct mac802154_maccb_s *maccb,
* back to trying to get access again
*/
while (nxsem_wait(&priv->md_exclsem) < 0);
while (nxmutex_lock(&priv->md_lock) < 0);
sq_addlast((FAR sq_entry_t *)primitive, &priv->primitive_queue);
@@ -383,7 +384,7 @@ static int macnet_notify(FAR struct mac802154_maccb_s *maccb,
SI_QUEUE, &priv->md_notify_work);
}
nxsem_post(&priv->md_exclsem);
nxmutex_unlock(&priv->md_lock);
return OK;
}
@@ -904,10 +905,10 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
dev->d_private;
int ret = -EINVAL;
ret = nxsem_wait(&priv->md_exclsem);
ret = nxmutex_lock(&priv->md_lock);
if (ret < 0)
{
wlerr("ERROR: nxsem_wait failed: %d\n", ret);
wlerr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -981,7 +982,7 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
}
priv->md_eventpending = true;
nxsem_post(&priv->md_exclsem);
nxmutex_unlock(&priv->md_lock);
/* Wait to be signaled when an event is queued */
@@ -996,10 +997,10 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
* and try and pop an event off the queue
*/
ret = nxsem_wait(&priv->md_exclsem);
ret = nxmutex_lock(&priv->md_lock);
if (ret < 0)
{
wlerr("ERROR: nxsem_wait failed: %d\n", ret);
wlerr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
}
@@ -1031,7 +1032,7 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
ret = mac802154_ioctl(priv->md_mac, cmd, arg);
}
nxsem_post(&priv->md_exclsem);
nxmutex_unlock(&priv->md_lock);
return ret;
}
#endif
@@ -1112,7 +1113,7 @@ static int macnet_req_data(FAR struct radio_driver_s *netdev,
/* Transfer the frame to the MAC. */
ret = mac802154_req_data(priv->md_mac, pktmeta, iob, false);
ret = mac802154_req_data(priv->md_mac, pktmeta, iob);
if (ret < 0)
{
wlerr("ERROR: mac802154_req_data failed: %d\n", ret);
@@ -1266,9 +1267,9 @@ int mac802154netdev_register(MACHANDLE mac)
dev->d_private = priv; /* Used to recover private state from dev */
priv->md_mac = mac; /* Save the MAC interface instance */
/* Setup a locking semaphore for exclusive device driver access */
/* Setup a locking mutex for exclusive device driver access */
nxsem_init(&priv->md_exclsem, 0, 1);
nxmutex_init(&priv->md_lock);
/* Set the network mask. */
+11 -11
View File
@@ -78,7 +78,7 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req)
* cmdtrans but needs access to the MAC in order to unlock it.
*/
ret = mac802154_takesem(&priv->opsem, true);
ret = nxsem_wait_uninterruptible(&priv->opsem);
if (ret < 0)
{
return ret;
@@ -86,10 +86,10 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req)
/* Get exclusive access to the MAC */
ret = mac802154_lock(priv, true);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
return ret;
}
@@ -98,11 +98,11 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req)
/* Allocate the txdesc, waiting if necessary */
ret = mac802154_txdesc_alloc(priv, &txdesc, true);
ret = mac802154_txdesc_alloc(priv, &txdesc);
if (ret < 0)
{
mac802154_unlock(priv)
mac802154_givesem(&priv->opsem);
nxmutex_unlock(&priv->lock);
nxsem_post(&priv->opsem);
return ret;
}
@@ -148,7 +148,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_unlock(priv)
nxmutex_unlock(&priv->lock);
/* Notify the radio driver that there is data available */
@@ -208,7 +208,7 @@ void mac802154_txdone_datareq_poll(FAR struct ieee802154_privmac_s *priv,
priv->curr_op = MAC802154_OP_NONE;
priv->cmd_desc = NULL;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
mac802154_notify(priv, primitive);
}
@@ -268,14 +268,14 @@ void mac802154_polltimeout(FAR void *arg)
primitive->type = IEEE802154_PRIMITIVE_CONF_POLL;
primitive->u.pollconf.status = IEEE802154_STATUS_NO_DATA;
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* We are no longer performing the association operation */
priv->curr_op = MAC802154_OP_NONE;
priv->cmd_desc = NULL;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
mac802154_notify(priv, primitive);
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
}
+16 -16
View File
@@ -60,20 +60,20 @@ static void mac802154_rxenabletimeout(FAR void *arg)
FAR struct ieee802154_privmac_s *priv =
(FAR struct ieee802154_privmac_s *)arg;
while (mac802154_lock(priv, true) != 0);
while (nxmutex_lock(&priv->lock) != 0);
if (priv->curr_op != MAC802154_OP_RXENABLE)
{
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
return;
}
mac802154_rxdisable(priv);
priv->curr_op = MAC802154_OP_NONE;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -103,7 +103,7 @@ int mac802154_req_rxenable(MACHANDLE mac,
if (priv->sfspec.sforder < 15)
{
return -EINVAL;
goto errout_with_sem;
goto errout_with_lock;
}
/* Non-beacon enabled network */
@@ -119,7 +119,7 @@ int mac802154_req_rxenable(MACHANDLE mac,
* MAC in order to unlock it.
*/
ret = mac802154_takesem(&priv->opsem, true);
ret = nxsem_wait_uninterruptible(&priv->opsem);
if (ret < 0)
{
return ret;
@@ -129,14 +129,14 @@ int mac802154_req_rxenable(MACHANDLE mac,
/* Get exclusive access to the MAC */
ret = mac802154_lock(priv, true);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
/* Should only fail if interrupted by a signal */
wlwarn("WARNING: mac802154_takesem failed: %d\n", ret);
wlwarn("WARNING: nxmutex_lock failed: %d\n", ret);
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
return ret;
}
@@ -150,33 +150,33 @@ int mac802154_req_rxenable(MACHANDLE mac,
}
else
{
ret = mac802154_lock(priv, true);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
/* Should only fail if interrupted by a signal */
wlwarn("WARNING: mac802154_takesem failed: %d\n", ret);
wlwarn("WARNING: nxmutex_lock failed: %d\n", ret);
return ret;
}
if (priv->curr_op != MAC802154_OP_RXENABLE)
{
ret = -EINVAL;
goto errout_with_sem;
goto errout_with_lock;
}
mac802154_timercancel(priv);
mac802154_rxdisable(priv);
priv->curr_op = MAC802154_OP_NONE;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
}
}
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return OK;
errout_with_sem:
mac802154_unlock(priv)
errout_with_lock:
nxmutex_unlock(&priv->lock);
return ret;
}
+13 -14
View File
@@ -79,7 +79,7 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req)
* This must be done before locking the MAC so that we don't hold the MAC
*/
ret = mac802154_takesem(&priv->opsem, true);
ret = nxsem_wait_uninterruptible(&priv->opsem);
if (ret < 0)
{
goto errout;
@@ -89,10 +89,10 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req)
/* Get exclusive access to the MAC */
ret = mac802154_lock(priv, true);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
goto errout;
}
@@ -144,7 +144,7 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req)
case IEEE802154_SCANTYPE_ACTIVE:
{
ret = -ENOTTY;
goto errout_with_sem;
goto errout_with_lock;
}
break;
case IEEE802154_SCANTYPE_ED:
@@ -163,24 +163,23 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req)
case IEEE802154_SCANTYPE_ORPHAN:
{
ret = -ENOTTY;
goto errout_with_sem;
goto errout_with_lock;
}
break;
default:
{
ret = -EINVAL;
goto errout_with_sem;
goto errout_with_lock;
}
break;
}
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return OK;
errout_with_sem:
mac802154_unlock(priv)
mac802154_givesem(&priv->opsem);
errout_with_lock:
nxmutex_unlock(&priv->lock);
nxsem_post(&priv->opsem);
errout:
return ret;
}
@@ -255,7 +254,7 @@ void mac802154_scanfinish(FAR struct ieee802154_privmac_s *priv,
scanconf->status = status;
priv->curr_op = MAC802154_OP_NONE;
mac802154_givesem(&priv->opsem);
nxsem_post(&priv->opsem);
mac802154_notify(priv, primitive);
}
@@ -326,7 +325,7 @@ static void mac802154_scantimeout(FAR void *arg)
(FAR struct ieee802154_privmac_s *)arg;
DEBUGASSERT(priv->curr_op == MAC802154_OP_SCAN);
mac802154_lock(priv, false);
nxmutex_lock(&priv->lock);
/* If we got here it means we are done scanning that channel */
@@ -359,5 +358,5 @@ static void mac802154_scantimeout(FAR void *arg)
mac802154_rxenable(priv);
mac802154_timerstart(priv, priv->scansymdur, mac802154_scantimeout);
mac802154_unlock(priv);
nxmutex_unlock(&priv->lock);
}
+3 -4
View File
@@ -58,7 +58,7 @@ int mac802154_req_start(MACHANDLE mac,
/* Get exclusive access to the MAC */
ret = mac802154_lock(priv, true);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -185,11 +185,10 @@ int mac802154_req_start(MACHANDLE mac,
}
}
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return OK;
errout:
mac802154_unlock(priv)
nxmutex_unlock(&priv->lock);
return ret;
}