Skip to content

Commit 094f57a

Browse files
Elad Kanfidavem330
authored andcommitted
net: nps_enet: code reuse
Add inline function that checks if there is a pending tx packet. Signed-off-by: Elad Kanfi <eladkan@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ddbff3e commit 094f57a

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

‎drivers/net/ethernet/ezchip/nps_enet.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424

2525
#define DRV_NAME "nps_mgt_enet"
2626

27+
static inline bool nps_enet_is_tx_pending(struct nps_enet_priv *priv)
28+
{
29+
u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL);
30+
u32 tx_ctrl_ct = (tx_ctrl_value & TX_CTL_CT_MASK) >> TX_CTL_CT_SHIFT;
31+
32+
return (!tx_ctrl_ct && priv->tx_skb);
33+
}
34+
2735
static void nps_enet_clean_rx_fifo(struct net_device *ndev, u32 frame_len)
2836
{
2937
struct nps_enet_priv *priv = netdev_priv(ndev);
@@ -141,12 +149,11 @@ static void nps_enet_tx_handler(struct net_device *ndev)
141149
{
142150
struct nps_enet_priv *priv = netdev_priv(ndev);
143151
u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL);
144-
u32 tx_ctrl_ct = (tx_ctrl_value & TX_CTL_CT_MASK) >> TX_CTL_CT_SHIFT;
145152
u32 tx_ctrl_et = (tx_ctrl_value & TX_CTL_ET_MASK) >> TX_CTL_ET_SHIFT;
146153
u32 tx_ctrl_nt = (tx_ctrl_value & TX_CTL_NT_MASK) >> TX_CTL_NT_SHIFT;
147154

148155
/* Check if we got TX */
149-
if (!priv->tx_skb || tx_ctrl_ct)
156+
if (!nps_enet_is_tx_pending(priv))
150157
return;
151158

152159
/* Ack Tx ctrl register */
@@ -184,9 +191,6 @@ static int nps_enet_poll(struct napi_struct *napi, int budget)
184191
work_done = nps_enet_rx_handler(ndev);
185192
if (work_done < budget) {
186193
u32 buf_int_enable_value = 0;
187-
u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL);
188-
u32 tx_ctrl_ct =
189-
(tx_ctrl_value & TX_CTL_CT_MASK) >> TX_CTL_CT_SHIFT;
190194

191195
napi_complete(napi);
192196

@@ -205,8 +209,7 @@ static int nps_enet_poll(struct napi_struct *napi, int budget)
205209
* the two code lines below will solve this situation by
206210
* re-adding ourselves to the poll list.
207211
*/
208-
209-
if (priv->tx_skb && !tx_ctrl_ct) {
212+
if (nps_enet_is_tx_pending(priv)) {
210213
nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0);
211214
napi_reschedule(napi);
212215
}
@@ -231,11 +234,9 @@ static irqreturn_t nps_enet_irq_handler(s32 irq, void *dev_instance)
231234
struct net_device *ndev = dev_instance;
232235
struct nps_enet_priv *priv = netdev_priv(ndev);
233236
u32 rx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_RX_CTL);
234-
u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL);
235-
u32 tx_ctrl_ct = (tx_ctrl_value & TX_CTL_CT_MASK) >> TX_CTL_CT_SHIFT;
236237
u32 rx_ctrl_cr = (rx_ctrl_value & RX_CTL_CR_MASK) >> RX_CTL_CR_SHIFT;
237238

238-
if ((!tx_ctrl_ct && priv->tx_skb) || rx_ctrl_cr)
239+
if (nps_enet_is_tx_pending(priv) || rx_ctrl_cr)
239240
if (likely(napi_schedule_prep(&priv->napi))) {
240241
nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0);
241242
__napi_schedule(&priv->napi);

0 commit comments

Comments
 (0)