qede: Simplify the usage of qede-flags.
authorSudarsana Reddy Kalluru <sudarsana.kalluru@cavium.com>
Mon, 26 Nov 2018 10:26:58 +0000 (02:26 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 28 Nov 2018 00:17:19 +0000 (16:17 -0800)
The values represented by qede->flags is being used in mixed ways:
  1. As 'value' at some places e.g., QEDE_FLAGS_IS_VF usage
  2. As bit-mask(value) at some places e.g., QEDE_FLAGS_PTP_TX_IN_PRORGESS
     usage.
This implementation pose problems in future when we want to add more flag
values e.g., overlap of the values, overflow of 64-bit storage.

Updated the implementation to go with approach (2) for qede->flags.

Signed-off-by: Sudarsana Reddy Kalluru <Sudarsana.Kalluru@cavium.com>
Signed-off-by: Ariel Elior <Ariel.Elior@cavium.com>
Signed-off-by: Michal Kalderon <Michal.Kalderon@cavium.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qlogic/qede/qede.h
drivers/net/ethernet/qlogic/qede/qede_main.c
drivers/net/ethernet/qlogic/qede/qede_ptp.c

index de98a974673b3e542a9af878cede821c7a04cf5b..f8ced12bfc1ac4587e4a5f614b9d394d69de8578 100644 (file)
@@ -168,6 +168,12 @@ struct qede_ptp;
 
 #define QEDE_RFS_MAX_FLTR      256
 
+enum qede_flags_bit {
+       QEDE_FLAGS_IS_VF = 0,
+       QEDE_FLAGS_PTP_TX_IN_PRORGESS,
+       QEDE_FLAGS_TX_TIMESTAMPING_EN
+};
+
 struct qede_dev {
        struct qed_dev                  *cdev;
        struct net_device               *ndev;
@@ -177,10 +183,7 @@ struct qede_dev {
        u8                              dp_level;
 
        unsigned long flags;
-#define QEDE_FLAG_IS_VF                        BIT(0)
-#define IS_VF(edev)    (!!((edev)->flags & QEDE_FLAG_IS_VF))
-#define QEDE_TX_TIMESTAMPING_EN                BIT(1)
-#define QEDE_FLAGS_PTP_TX_IN_PRORGESS  BIT(2)
+#define IS_VF(edev)    (test_bit(QEDE_FLAGS_IS_VF, &(edev)->flags))
 
        const struct qed_eth_ops        *ops;
        struct qede_ptp                 *ptp;
index 46d0f2eaa0c094c19ae47161f84320caeba2c567..0f1c480759e0074e9afbd471f46a70d18179bbd3 100644 (file)
@@ -1086,7 +1086,7 @@ static int __qede_probe(struct pci_dev *pdev, u32 dp_module, u8 dp_level,
        }
 
        if (is_vf)
-               edev->flags |= QEDE_FLAG_IS_VF;
+               set_bit(QEDE_FLAGS_IS_VF, &edev->flags);
 
        qede_init_ndev(edev);
 
index 013ff567283c738f342ca5d6f5358e30ca6daa72..5f3f42a25361679220fcc55224fcb2aa46adec03 100644 (file)
@@ -223,12 +223,12 @@ static int qede_ptp_cfg_filters(struct qede_dev *edev)
 
        switch (ptp->tx_type) {
        case HWTSTAMP_TX_ON:
-               edev->flags |= QEDE_TX_TIMESTAMPING_EN;
+               set_bit(QEDE_FLAGS_TX_TIMESTAMPING_EN, &edev->flags);
                tx_type = QED_PTP_HWTSTAMP_TX_ON;
                break;
 
        case HWTSTAMP_TX_OFF:
-               edev->flags &= ~QEDE_TX_TIMESTAMPING_EN;
+               clear_bit(QEDE_FLAGS_TX_TIMESTAMPING_EN, &edev->flags);
                tx_type = QED_PTP_HWTSTAMP_TX_OFF;
                break;
 
@@ -518,7 +518,7 @@ void qede_ptp_tx_ts(struct qede_dev *edev, struct sk_buff *skb)
        if (test_and_set_bit_lock(QEDE_FLAGS_PTP_TX_IN_PRORGESS, &edev->flags))
                return;
 
-       if (unlikely(!(edev->flags & QEDE_TX_TIMESTAMPING_EN))) {
+       if (unlikely(!test_bit(QEDE_FLAGS_TX_TIMESTAMPING_EN, &edev->flags))) {
                DP_NOTICE(edev,
                          "Tx timestamping was not enabled, this packet will not be timestamped\n");
        } else if (unlikely(ptp->tx_skb)) {