net/vmxnet3: prepare for version 3 changes
authorShrikrishna Khare <skhare@vmware.com>
Mon, 6 Mar 2017 22:55:01 +0000 (14:55 -0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 4 Apr 2017 13:52:51 +0000 (15:52 +0200)
Cleanup some code in preparation of vmxnet3 version 3 changes.

Signed-off-by: Shrikrishna Khare <skhare@vmware.com>
Acked-by: Yong Wang <yongwang@vmware.com>
Acked-by: Jin Heo <heoj@vmware.com>
drivers/net/vmxnet3/vmxnet3_ethdev.c
drivers/net/vmxnet3/vmxnet3_ethdev.h

index b7b5377..09f2085 100644 (file)
@@ -265,13 +265,22 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
        /* Check h/w version compatibility with driver. */
        ver = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_VRRS);
        PMD_INIT_LOG(DEBUG, "Hardware version : %d", ver);
-       if (ver & 0x1)
-               VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS, 1);
-       else {
-               PMD_INIT_LOG(ERR, "Incompatible h/w version, should be 0x1");
+
+       if (ver & (1 << VMXNET3_REV_2)) {
+               VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
+                                      1 << VMXNET3_REV_2);
+               hw->version = VMXNET3_REV_2 + 1;
+       } else if (ver & (1 << VMXNET3_REV_1)) {
+               VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
+                                      1 << VMXNET3_REV_1);
+               hw->version = VMXNET3_REV_1 + 1;
+       } else {
+               PMD_INIT_LOG(ERR, "Incompatible hardware version: %d", ver);
                return -EIO;
        }
 
+       PMD_INIT_LOG(DEBUG, "Using device version %d\n", hw->version);
+
        /* Check UPT version compatibility with driver. */
        ver = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_UVRS);
        PMD_INIT_LOG(DEBUG, "UPT hardware version : %d", ver);
index 348c840..3cc8979 100644 (file)
@@ -101,6 +101,8 @@ struct vmxnet3_hw {
        uint8_t num_rx_queues;
        uint8_t bufs_per_pkt;
 
+       uint8_t version;
+
        Vmxnet3_TxQueueDesc   *tqd_start;       /* start address of all tx queue desc */
        Vmxnet3_RxQueueDesc   *rqd_start;       /* start address of all rx queue desc */
 
@@ -117,6 +119,13 @@ struct vmxnet3_hw {
 #define VMXNET3_VFT_TABLE_SIZE     (VMXNET3_VFT_SIZE * sizeof(uint32_t))
 };
 
+#define VMXNET3_REV_3          2               /* Vmxnet3 Rev. 3 */
+#define VMXNET3_REV_2          1               /* Vmxnet3 Rev. 2 */
+#define VMXNET3_REV_1          0               /* Vmxnet3 Rev. 1 */
+
+#define VMXNET3_VERSION_GE_3(hw) ((hw)->version >= VMXNET3_REV_3 + 1)
+#define VMXNET3_VERSION_GE_2(hw) ((hw)->version >= VMXNET3_REV_2 + 1)
+
 #define VMXNET3_GET_ADDR_LO(reg)   ((uint32_t)(reg))
 #define VMXNET3_GET_ADDR_HI(reg)   ((uint32_t)(((uint64_t)(reg)) >> 32))