diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c index b2fb591778..db144235d2 100644 --- a/drivers/net/netdev_upperhalf.c +++ b/drivers/net/netdev_upperhalf.c @@ -106,23 +106,6 @@ static int quota_fetch_dec(FAR struct netdev_lowerhalf_s *lower, return ret; } -/**************************************************************************** - * Name: quota_load - * - * Description: - * Fetch the quota, works like atomic_load. - * - ****************************************************************************/ - -static int quota_load(FAR struct netdev_lowerhalf_s *lower, - enum netpkt_type_e type) -{ - irqstate_t flags = spin_lock_irqsave(NULL); - int ret = lower->quota[type]; - spin_unlock_irqrestore(NULL, flags); - return ret; -} - /**************************************************************************** * Name: netpkt_get * @@ -232,7 +215,7 @@ netdev_upper_alloc(FAR struct netdev_lowerhalf_s *dev) static inline bool netdev_upper_can_tx(FAR struct netdev_upperhalf_s *upper) { - return quota_load(upper->lower, NETPKT_TX) > 0; + return netdev_lower_quota_load(upper->lower, NETPKT_TX) > 0; } /**************************************************************************** @@ -840,6 +823,27 @@ void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev) netdev_upper_queue_work(&dev->netdev); } +/**************************************************************************** + * Name: netdev_lower_quota_load + * + * Description: + * Fetch the quota, works like atomic_load. + * + * Input Parameters: + * dev - The lower half device driver structure + * type - Whether get quota for TX or RX + * + ****************************************************************************/ + +int netdev_lower_quota_load(FAR struct netdev_lowerhalf_s *dev, + enum netpkt_type_e type) +{ + irqstate_t flags = spin_lock_irqsave(NULL); + int ret = dev->quota[type]; + spin_unlock_irqrestore(NULL, flags); + return ret; +} + /**************************************************************************** * Name: netpkt_alloc * diff --git a/include/nuttx/net/netdev_lowerhalf.h b/include/nuttx/net/netdev_lowerhalf.h index 6fdf35872d..958505801a 100644 --- a/include/nuttx/net/netdev_lowerhalf.h +++ b/include/nuttx/net/netdev_lowerhalf.h @@ -234,6 +234,21 @@ void netdev_lower_rxready(FAR struct netdev_lowerhalf_s *dev); void netdev_lower_txdone(FAR struct netdev_lowerhalf_s *dev); +/**************************************************************************** + * Name: netdev_lower_quota_load + * + * Description: + * Fetch the quota, use this interface when device is running. + * + * Input Parameters: + * dev - The lower half device driver structure + * type - Whether get quota for TX or RX + * + ****************************************************************************/ + +int netdev_lower_quota_load(FAR struct netdev_lowerhalf_s *dev, + enum netpkt_type_e type); + /**************************************************************************** * Name: netpkt_alloc *