netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Lobakin <alobakin@marvell.com>
To: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: Alexander Lobakin <alobakin@marvell.com>,
	Igor Russkikh <irusskikh@marvell.com>,
	Michal Kalderon <michal.kalderon@marvell.com>,
	"Ariel Elior" <aelior@marvell.com>,
	Denis Bolotin <denis.bolotin@marvell.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	<GR-everest-linux-l2@marvell.com>,
	<QLogic-Storage-Upstream@marvell.com>, <netdev@vger.kernel.org>,
	<linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 net-next 13/14] qed: populate supported link modes maps on module init
Date: Sun, 19 Jul 2020 23:14:52 +0300	[thread overview]
Message-ID: <20200719201453.3648-14-alobakin@marvell.com> (raw)
In-Reply-To: <20200719201453.3648-1-alobakin@marvell.com>

Simplify and lighten qed_set_link() by declaring static link modes maps
and populating them on module init. This way we save plenty of text size
at the low expense of __ro_after_init and __initconst data (the latter
will be purged after module init is done).

Misc: sanitize exit callback.

Signed-off-by: Alexander Lobakin <alobakin@marvell.com>
Signed-off-by: Igor Russkikh <irusskikh@marvell.com>
---
 drivers/net/ethernet/qlogic/qed/qed_main.c | 194 +++++++++++++--------
 1 file changed, 123 insertions(+), 71 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_main.c b/drivers/net/ethernet/qlogic/qed/qed_main.c
index ff8e41694f65..28f13cd7bd9b 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_main.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_main.c
@@ -64,20 +64,122 @@ MODULE_VERSION(DRV_MODULE_VERSION);
 
 MODULE_FIRMWARE(QED_FW_FILE_NAME);
 
+/* MFW speed capabilities maps */
+
+struct qed_mfw_speed_map {
+	u32		mfw_val;
+
+	QED_LM_DECLARE(caps);
+
+	const u32	*cap_arr;
+	u32		arr_size;
+};
+
+#define QED_MFW_SPEED_MAP(type, arr)		\
+{						\
+	.mfw_val	= (type),		\
+	.cap_arr	= (arr),		\
+	.arr_size	= ARRAY_SIZE(arr),	\
+}
+
+static const u32 qed_mfw_legacy_1g[] __initconst = {
+	QED_LM_1000baseT_Full,
+	QED_LM_1000baseKX_Full,
+	QED_LM_1000baseX_Full,
+};
+
+static const u32 qed_mfw_legacy_10g[] __initconst = {
+	QED_LM_10000baseT_Full,
+	QED_LM_10000baseKR_Full,
+	QED_LM_10000baseKX4_Full,
+	QED_LM_10000baseR_FEC,
+	QED_LM_10000baseCR_Full,
+	QED_LM_10000baseSR_Full,
+	QED_LM_10000baseLR_Full,
+	QED_LM_10000baseLRM_Full,
+};
+
+static const u32 qed_mfw_legacy_20g[] __initconst = {
+	QED_LM_20000baseKR2_Full,
+};
+
+static const u32 qed_mfw_legacy_25g[] __initconst = {
+	QED_LM_25000baseKR_Full,
+	QED_LM_25000baseCR_Full,
+	QED_LM_25000baseSR_Full,
+};
+
+static const u32 qed_mfw_legacy_40g[] __initconst = {
+	QED_LM_40000baseLR4_Full,
+	QED_LM_40000baseKR4_Full,
+	QED_LM_40000baseCR4_Full,
+	QED_LM_40000baseSR4_Full,
+};
+
+static const u32 qed_mfw_legacy_50g[] __initconst = {
+	QED_LM_50000baseKR2_Full,
+	QED_LM_50000baseCR2_Full,
+	QED_LM_50000baseSR2_Full,
+};
+
+static const u32 qed_mfw_legacy_bb_100g[] __initconst = {
+	QED_LM_100000baseKR4_Full,
+	QED_LM_100000baseSR4_Full,
+	QED_LM_100000baseCR4_Full,
+	QED_LM_100000baseLR4_ER4_Full,
+};
+
+static struct qed_mfw_speed_map qed_mfw_legacy_maps[] __ro_after_init = {
+	QED_MFW_SPEED_MAP(NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G,
+			  qed_mfw_legacy_1g),
+	QED_MFW_SPEED_MAP(NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G,
+			  qed_mfw_legacy_10g),
+	QED_MFW_SPEED_MAP(NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_20G,
+			  qed_mfw_legacy_20g),
+	QED_MFW_SPEED_MAP(NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G,
+			  qed_mfw_legacy_25g),
+	QED_MFW_SPEED_MAP(NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G,
+			  qed_mfw_legacy_40g),
+	QED_MFW_SPEED_MAP(NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G,
+			  qed_mfw_legacy_50g),
+	QED_MFW_SPEED_MAP(NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G,
+			  qed_mfw_legacy_bb_100g),
+};
+
+static void __init qed_mfw_speed_map_populate(struct qed_mfw_speed_map *map)
+{
+	u32 i;
+
+	for (i = 0; i < map->arr_size; i++)
+		__set_bit(map->cap_arr[i], map->caps);
+
+	map->cap_arr = NULL;
+	map->arr_size = 0;
+}
+
+static void __init qed_mfw_speed_maps_init(void)
+{
+	u32 i;
+
+	for (i = 0; i < ARRAY_SIZE(qed_mfw_legacy_maps); i++)
+		qed_mfw_speed_map_populate(qed_mfw_legacy_maps + i);
+}
+
 static int __init qed_init(void)
 {
 	pr_info("%s", version);
 
+	qed_mfw_speed_maps_init();
+
 	return 0;
 }
+module_init(qed_init);
 
-static void __exit qed_cleanup(void)
+static void __exit qed_exit(void)
 {
-	pr_notice("qed_cleanup called\n");
+	/* To prevent marking this module as "permanent" */
 }
-
-module_init(qed_init);
-module_exit(qed_cleanup);
+module_exit(qed_exit);
 
 /* Check if the DMA controller on the machine can properly handle the DMA
  * addressing required by the device.
@@ -1457,11 +1559,12 @@ static bool qed_can_link_change(struct qed_dev *cdev)
 static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
 {
 	struct qed_mcp_link_params *link_params;
-	QED_LM_DECLARE(sup_caps);
+	struct qed_mcp_link_speed_params *speed;
+	const struct qed_mfw_speed_map *map;
 	struct qed_hwfn *hwfn;
 	struct qed_ptt *ptt;
-	u32 as;
 	int rc;
+	u32 i;
 
 	if (!cdev)
 		return -ENODEV;
@@ -1486,78 +1589,26 @@ static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
 	if (!link_params)
 		return -ENODATA;
 
+	speed = &link_params->speed;
+
 	if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
-		link_params->speed.autoneg = params->autoneg;
+		speed->autoneg = !!params->autoneg;
 
 	if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
-		as = 0;
-
-		qed_link_mode_zero(sup_caps);
-		__set_bit(QED_LM_1000baseT_Full, sup_caps);
-		__set_bit(QED_LM_1000baseKX_Full, sup_caps);
-		__set_bit(QED_LM_1000baseX_Full, sup_caps);
-
-		if (qed_link_mode_intersects(params->adv_speeds, sup_caps))
-			as |= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
-
-		qed_link_mode_zero(sup_caps);
-		__set_bit(QED_LM_10000baseT_Full, sup_caps);
-		__set_bit(QED_LM_10000baseKR_Full, sup_caps);
-		__set_bit(QED_LM_10000baseKX4_Full, sup_caps);
-		__set_bit(QED_LM_10000baseR_FEC, sup_caps);
-		__set_bit(QED_LM_10000baseCR_Full, sup_caps);
-		__set_bit(QED_LM_10000baseSR_Full, sup_caps);
-		__set_bit(QED_LM_10000baseLR_Full, sup_caps);
-		__set_bit(QED_LM_10000baseLRM_Full, sup_caps);
+		speed->advertised_speeds = 0;
 
-		if (qed_link_mode_intersects(params->adv_speeds, sup_caps))
-			as |= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
+		for (i = 0; i < ARRAY_SIZE(qed_mfw_legacy_maps); i++) {
+			map = qed_mfw_legacy_maps + i;
 
-		qed_link_mode_zero(sup_caps);
-		__set_bit(QED_LM_20000baseKR2_Full, sup_caps);
-
-		if (qed_link_mode_intersects(params->adv_speeds, sup_caps))
-			as |= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_20G;
-
-		qed_link_mode_zero(sup_caps);
-		__set_bit(QED_LM_25000baseKR_Full, sup_caps);
-		__set_bit(QED_LM_25000baseCR_Full, sup_caps);
-		__set_bit(QED_LM_25000baseSR_Full, sup_caps);
-
-		if (qed_link_mode_intersects(params->adv_speeds, sup_caps))
-			as |= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
-
-		qed_link_mode_zero(sup_caps);
-		__set_bit(QED_LM_40000baseLR4_Full, sup_caps);
-		__set_bit(QED_LM_40000baseKR4_Full, sup_caps);
-		__set_bit(QED_LM_40000baseCR4_Full, sup_caps);
-		__set_bit(QED_LM_40000baseSR4_Full, sup_caps);
-
-		if (qed_link_mode_intersects(params->adv_speeds, sup_caps))
-			as |= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
-
-		qed_link_mode_zero(sup_caps);
-		__set_bit(QED_LM_50000baseKR2_Full, sup_caps);
-		__set_bit(QED_LM_50000baseCR2_Full, sup_caps);
-		__set_bit(QED_LM_50000baseSR2_Full, sup_caps);
-
-		if (qed_link_mode_intersects(params->adv_speeds, sup_caps))
-			as |= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
-
-		qed_link_mode_zero(sup_caps);
-		__set_bit(QED_LM_100000baseKR4_Full, sup_caps);
-		__set_bit(QED_LM_100000baseSR4_Full, sup_caps);
-		__set_bit(QED_LM_100000baseCR4_Full, sup_caps);
-		__set_bit(QED_LM_100000baseLR4_ER4_Full, sup_caps);
-
-		if (qed_link_mode_intersects(params->adv_speeds, sup_caps))
-			as |= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
-
-		link_params->speed.advertised_speeds = as;
+			if (qed_link_mode_intersects(params->adv_speeds,
+						     map->caps))
+				speed->advertised_speeds |= map->mfw_val;
+		}
 	}
 
 	if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
-		link_params->speed.forced_speed = params->forced_speed;
+		speed->forced_speed = params->forced_speed;
+
 	if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
 		if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
 			link_params->pause.autoneg = true;
@@ -1572,6 +1623,7 @@ static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
 		else
 			link_params->pause.forced_tx = false;
 	}
+
 	if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
 		switch (params->loopback_mode) {
 		case QED_LINK_LOOPBACK_INT_PHY:
-- 
2.25.1


  parent reply	other threads:[~2020-07-19 20:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-19 20:14 [PATCH v2 net-next 00/14] qed/qede: add support for new operating modes Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 01/14] qed: convert link mode from u32 to bitmap Alexander Lobakin
2020-07-19 21:21   ` Andrew Lunn
2020-07-20  9:23     ` Alexander Lobakin
2020-07-20 15:19       ` Joe Perches
2020-07-20 15:29         ` Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 02/14] qed: reformat public_port::transceiver_data a bit Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 03/14] qed: add support for multi-rate transceivers Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 04/14] qed: use transceiver data to fill link partner's advertising speeds Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 05/14] qed: reformat several structures a bit Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 06/14] qed: add support for Forward Error Correction Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 07/14] qede: format qede{,_vf}_ethtool_ops Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 08/14] qede: introduce support for FEC control Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 09/14] qed: reformat several structures a bit Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 10/14] qed: remove unused qed_hw_info::port_mode and QED_PORT_MODE Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 11/14] qed: add support for new port modes Alexander Lobakin
2020-07-19 20:14 ` [PATCH v2 net-next 12/14] qed: add missing loopback modes Alexander Lobakin
2020-07-19 20:14 ` Alexander Lobakin [this message]
2020-07-19 20:14 ` [PATCH v2 net-next 14/14] qed/qede: add support for the extended speed and FEC modes Alexander Lobakin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200719201453.3648-14-alobakin@marvell.com \
    --to=alobakin@marvell.com \
    --cc=GR-everest-linux-l2@marvell.com \
    --cc=QLogic-Storage-Upstream@marvell.com \
    --cc=aelior@marvell.com \
    --cc=davem@davemloft.net \
    --cc=denis.bolotin@marvell.com \
    --cc=irusskikh@marvell.com \
    --cc=jejb@linux.ibm.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michal.kalderon@marvell.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).