qed: Read device port count from the shmem
authorSudarsana Reddy Kalluru <skalluru@marvell.com>
Thu, 21 Feb 2019 14:03:31 +0000 (06:03 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 21 Feb 2019 18:51:08 +0000 (10:51 -0800)
Read port count from the shared memory instead of driver deriving this
value. This change simplifies the driver implementation and also avoids
any dependencies for finding the port-count.

Signed-off-by: Sudarsana Reddy Kalluru <skalluru@marvell.com>
Signed-off-by: Michal Kalderon <mkalderon@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qlogic/qed/qed.h
drivers/net/ethernet/qlogic/qed/qed_dev.c
drivers/net/ethernet/qlogic/qed/qed_l2.c
drivers/net/ethernet/qlogic/qed/qed_mcp.h
drivers/net/ethernet/qlogic/qed/qed_ptp.c

index 2d21c94f19c2c3fd2fc109ca3df53bf640e5d0ef..43a57ec296fd9c6e55ec667f34b6ddd98880e41f 100644 (file)
@@ -753,6 +753,7 @@ struct qed_dev {
 #define CHIP_BOND_ID_SHIFT              0
 
        u8                              num_engines;
+       u8                              num_ports;
        u8                              num_ports_in_engine;
        u8                              num_funcs_in_port;
 
@@ -892,7 +893,6 @@ void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
 
 void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
 int qed_device_num_engines(struct qed_dev *cdev);
-int qed_device_get_port_id(struct qed_dev *cdev);
 void qed_set_fw_mac_addr(__le16 *fw_msb,
                         __le16 *fw_mid, __le16 *fw_lsb, u8 *mac);
 
@@ -939,6 +939,10 @@ bool qed_edpm_enabled(struct qed_hwfn *p_hwfn);
        writel((u32)val, (void __iomem *)((u8 __iomem *)\
                                          (cdev->doorbells) + (db_addr)))
 
+#define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id %                          \
+                                 qed_device_num_ports((_p_hwfn)->cdev))
+int qed_device_num_ports(struct qed_dev *cdev);
+
 /* Prototypes */
 int qed_fill_dev_info(struct qed_dev *cdev,
                      struct qed_dev_info *dev_info);
index e2cbd77646a273287d4dfbe02cd8956782907b6e..9df8c4b3b54e3dc71fdca5a759a9d98b303d8ac7 100644 (file)
@@ -3269,55 +3269,43 @@ static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
                   p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
 }
 
-static void qed_hw_info_port_num_bb(struct qed_hwfn *p_hwfn,
-                                   struct qed_ptt *p_ptt)
-{
-       u32 port_mode;
-
-       port_mode = qed_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
-
-       if (port_mode < 3) {
-               p_hwfn->cdev->num_ports_in_engine = 1;
-       } else if (port_mode <= 5) {
-               p_hwfn->cdev->num_ports_in_engine = 2;
-       } else {
-               DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
-                         p_hwfn->cdev->num_ports_in_engine);
-
-               /* Default num_ports_in_engine to something */
-               p_hwfn->cdev->num_ports_in_engine = 1;
-       }
-}
-
-static void qed_hw_info_port_num_ah(struct qed_hwfn *p_hwfn,
-                                   struct qed_ptt *p_ptt)
+static void qed_hw_info_port_num(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
 {
-       u32 port;
-       int i;
-
-       p_hwfn->cdev->num_ports_in_engine = 0;
+       u32 addr, global_offsize, global_addr, port_mode;
+       struct qed_dev *cdev = p_hwfn->cdev;
 
-       for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
-               port = qed_rd(p_hwfn, p_ptt,
-                             CNIG_REG_NIG_PORT0_CONF_K2 + (i * 4));
-               if (port & 1)
-                       p_hwfn->cdev->num_ports_in_engine++;
+       /* In CMT there is always only one port */
+       if (cdev->num_hwfns > 1) {
+               cdev->num_ports_in_engine = 1;
+               cdev->num_ports = 1;
+               return;
        }
 
-       if (!p_hwfn->cdev->num_ports_in_engine) {
-               DP_NOTICE(p_hwfn, "All NIG ports are inactive\n");
-
-               /* Default num_ports_in_engine to something */
-               p_hwfn->cdev->num_ports_in_engine = 1;
+       /* Determine the number of ports per engine */
+       port_mode = qed_rd(p_hwfn, p_ptt, MISC_REG_PORT_MODE);
+       switch (port_mode) {
+       case 0x0:
+               cdev->num_ports_in_engine = 1;
+               break;
+       case 0x1:
+               cdev->num_ports_in_engine = 2;
+               break;
+       case 0x2:
+               cdev->num_ports_in_engine = 4;
+               break;
+       default:
+               DP_NOTICE(p_hwfn, "Unknown port mode 0x%08x\n", port_mode);
+               cdev->num_ports_in_engine = 1;  /* Default to something */
+               break;
        }
-}
 
-static void qed_hw_info_port_num(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
-{
-       if (QED_IS_BB(p_hwfn->cdev))
-               qed_hw_info_port_num_bb(p_hwfn, p_ptt);
-       else
-               qed_hw_info_port_num_ah(p_hwfn, p_ptt);
+       /* Get the total number of ports of the device */
+       addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
+                                   PUBLIC_GLOBAL);
+       global_offsize = qed_rd(p_hwfn, p_ptt, addr);
+       global_addr = SECTION_ADDR(global_offsize, 0);
+       addr = global_addr + offsetof(struct public_global, max_ports);
+       cdev->num_ports = (u8)qed_rd(p_hwfn, p_ptt, addr);
 }
 
 static void qed_get_eee_caps(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
@@ -3355,7 +3343,8 @@ qed_get_hw_info(struct qed_hwfn *p_hwfn,
                        return rc;
        }
 
-       qed_hw_info_port_num(p_hwfn, p_ptt);
+       if (IS_LEAD_HWFN(p_hwfn))
+               qed_hw_info_port_num(p_hwfn, p_ptt);
 
        qed_mcp_get_capabilities(p_hwfn, p_ptt);
 
@@ -4760,23 +4749,9 @@ void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
               sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
 }
 
-int qed_device_num_engines(struct qed_dev *cdev)
-{
-       return QED_IS_BB(cdev) ? 2 : 1;
-}
-
-static int qed_device_num_ports(struct qed_dev *cdev)
-{
-       /* in CMT always only one port */
-       if (cdev->num_hwfns > 1)
-               return 1;
-
-       return cdev->num_ports_in_engine * qed_device_num_engines(cdev);
-}
-
-int qed_device_get_port_id(struct qed_dev *cdev)
+int qed_device_num_ports(struct qed_dev *cdev)
 {
-       return (QED_LEADING_HWFN(cdev)->abs_pf_id) % qed_device_num_ports(cdev);
+       return cdev->num_ports;
 }
 
 void qed_set_fw_mac_addr(__le16 *fw_msb,
index 58be1c4c66684797b79e4bf5d1ca834fe2d61f9d..57641728df69e2aa70a755c3707ae1ca4b441a23 100644 (file)
@@ -1898,6 +1898,7 @@ static void _qed_get_vport_stats(struct qed_dev *cdev,
                struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
                struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
                                                    :  NULL;
+               bool b_get_port_stats;
 
                if (IS_PF(cdev)) {
                        /* The main vport index is relative first */
@@ -1912,8 +1913,9 @@ static void _qed_get_vport_stats(struct qed_dev *cdev,
                        continue;
                }
 
+               b_get_port_stats = IS_PF(cdev) && IS_LEAD_HWFN(p_hwfn);
                __qed_get_vport_stats(p_hwfn, p_ptt, stats, fw_vport,
-                                     IS_PF(cdev) ? true : false);
+                                     b_get_port_stats);
 
 out:
                if (IS_PF(cdev) && p_ptt)
index 2799e67417659f660f9f0ba6d9791494564e129a..261c1a392e2c7129c2b6531f09975f9d7ddb585a 100644 (file)
@@ -691,10 +691,6 @@ int qed_mfw_process_tlv_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
                                            rel_pfid)
 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
 
-#define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id %                          \
-                                ((_p_hwfn)->cdev->num_ports_in_engine * \
-                                 qed_device_num_engines((_p_hwfn)->cdev)))
-
 struct qed_mcp_info {
        /* List for mailbox commands which were sent and wait for a response */
        struct list_head                        cmd_list;
index 5a90d69dc2f8eb886c52d39be8981f62715cc5f9..1302b308bd87de6531d1adeb040cade0a19366f6 100644 (file)
@@ -47,7 +47,7 @@
 
 static enum qed_resc_lock qed_ptcdev_to_resc(struct qed_hwfn *p_hwfn)
 {
-       switch (qed_device_get_port_id(p_hwfn->cdev)) {
+       switch (MFW_PORT(p_hwfn)) {
        case 0:
                return QED_RESC_LOCK_PTP_PORT0;
        case 1: