netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vinicius Costa Gomes <vinicius.gomes@intel.com>
To: Piotr Kwapulinski <piotr.kwapulinski@intel.com>,
	intel-wired-lan@lists.osuosl.org
Cc: Piotr Kwapulinski <piotr.kwapulinski@intel.com>,
	netdev@vger.kernel.org,
	Jedrzej Jagielski <jedrzej.jagielski@intel.com>,
	Jan Glaza <jan.glaza@intel.com>,
	Stefan Wegrzyn <stefan.wegrzyn@intel.com>
Subject: Re: [Intel-wired-lan] [PATCH iwl-next v1 3/5] ixgbe: Add link management support for E610 device
Date: Thu, 04 Apr 2024 17:14:57 -0700	[thread overview]
Message-ID: <87r0fkbr7i.fsf@intel.com> (raw)
In-Reply-To: <20240327155422.25424-4-piotr.kwapulinski@intel.com>

Piotr Kwapulinski <piotr.kwapulinski@intel.com> writes:

> Add low level link management support for E610 device. Link management
> operations are handled via the Admin Command Interface. Add the following
> link management operations:
> - get link capabilities
> - set up link
> - get media type
> - get link status, link status events
> - link power management
>
> Co-developed-by: Stefan Wegrzyn <stefan.wegrzyn@intel.com>
> Signed-off-by: Stefan Wegrzyn <stefan.wegrzyn@intel.com>
> Co-developed-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
> Signed-off-by: Jedrzej Jagielski <jedrzej.jagielski@intel.com>
> Reviewed-by: Jan Glaza <jan.glaza@intel.com>
> Signed-off-by: Piotr Kwapulinski <piotr.kwapulinski@intel.com>
> ---

[...]

> +/**
> + * ixgbe_update_link_info - update status of the HW network link
> + * @hw: pointer to the HW struct
> + *
> + * Update the status of the HW network link.
> + *
> + * Return: the exit code of the operation.
> + */
> +int ixgbe_update_link_info(struct ixgbe_hw *hw)
> +{
> +	struct ixgbe_link_status *li;
> +	int err;
> +
> +	if (!hw)
> +		return -EINVAL;
> +
> +	li = &hw->link.link_info;
> +
> +	err = ixgbe_aci_get_link_info(hw, true, NULL);
> +	if (err)
> +		return err;
> +
> +	if (li->link_info & IXGBE_ACI_MEDIA_AVAILABLE) {
> +		struct ixgbe_aci_cmd_get_phy_caps_data __free(kfree) *pcaps;
> +
> +		pcaps =	kzalloc(sizeof(*pcaps), GFP_KERNEL);
> +		if (!pcaps)
> +			return -ENOMEM;
> +

Seems that 'pcaps' is leaking here.

> +		err = ixgbe_aci_get_phy_caps(hw, false,
> +					     IXGBE_ACI_REPORT_TOPO_CAP_MEDIA,
> +					     pcaps);
> +
> +		if (!err)
> +			memcpy(li->module_type, &pcaps->module_type,
> +			       sizeof(li->module_type));
> +	}
> +
> +	return err;
> +}
> +
[...]

> +/**
> + * ixgbe_get_media_type_e610 - Gets media type
> + * @hw: pointer to the HW struct
> + *
> + * In order to get the media type, the function gets PHY
> + * capabilities and later on use them to identify the PHY type
> + * checking phy_type_high and phy_type_low.
> + *
> + * Return: the type of media in form of ixgbe_media_type enum
> + * or ixgbe_media_type_unknown in case of an error.
> + */
> +enum ixgbe_media_type ixgbe_get_media_type_e610(struct ixgbe_hw *hw)
> +{
> +	struct ixgbe_aci_cmd_get_phy_caps_data pcaps;
> +	int rc;
> +
> +	rc = ixgbe_update_link_info(hw);
> +	if (rc)
> +		return ixgbe_media_type_unknown;
> +
> +	/* If there is no link but PHY (dongle) is available SW should use
> +	 * Get PHY Caps admin command instead of Get Link Status, find most
> +	 * significant bit that is set in PHY types reported by the command
> +	 * and use it to discover media type.
> +	 */
> +	if (!(hw->link.link_info.link_info & IXGBE_ACI_LINK_UP) &&
> +	    (hw->link.link_info.link_info & IXGBE_ACI_MEDIA_AVAILABLE)) {
> +		u64 phy_mask;
> +		u8 i;
> +
> +		/* Get PHY Capabilities */
> +		rc = ixgbe_aci_get_phy_caps(hw, false,
> +					    IXGBE_ACI_REPORT_TOPO_CAP_MEDIA,
> +					    &pcaps);
> +		if (rc)
> +			return ixgbe_media_type_unknown;
> +
> +		/* Check if there is some bit set in phy_type_high */
> +		for (i = 64; i > 0; i--) {
> +			phy_mask = (u64)((u64)1 << (i - 1));
> +			if ((pcaps.phy_type_high & phy_mask) != 0) {
> +				/* If any bit is set treat it as PHY type */
> +				hw->link.link_info.phy_type_high = phy_mask;
> +				hw->link.link_info.phy_type_low = 0;
> +				break;
> +			}
> +			phy_mask = 0;
> +		}
> +
> +		/* If nothing found in phy_type_high search in phy_type_low */
> +		if (phy_mask == 0) {
> +			for (i = 64; i > 0; i--) {
> +				phy_mask = (u64)((u64)1 << (i - 1));
> +				if ((pcaps.phy_type_low & phy_mask) != 0) {
> +					/* Treat as PHY type is any bit set */
> +					hw->link.link_info.phy_type_high = 0;
> +					hw->link.link_info.phy_type_low = phy_mask;
> +					break;
> +				}
> +			}
> +		}

These two look like they are doing something very similar to fls64().
Could that work?

> +
> +		/* Based on search above try to discover media type */
> +		hw->phy.media_type = ixgbe_get_media_type_from_phy_type(hw);
> +	}
> +
> +	return hw->phy.media_type;
> +}
> +


-- 
Vinicius

  reply	other threads:[~2024-04-05  0:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 15:54 [PATCH iwl-next v1 0/5] ixgbe: Add support for Intel(R) E610 device Piotr Kwapulinski
2024-03-27 15:54 ` [PATCH iwl-next v1 1/5] ixgbe: Add support for E610 FW Admin Command Interface Piotr Kwapulinski
2024-03-29 18:28   ` Simon Horman
2024-04-03  7:27     ` Kwapulinski, Piotr
2024-04-05  0:03   ` [Intel-wired-lan] " Vinicius Costa Gomes
2024-04-05 14:35     ` Kwapulinski, Piotr
2024-04-05 16:40       ` Vinicius Costa Gomes
2024-03-27 15:54 ` [PATCH iwl-next v1 2/5] ixgbe: Add support for E610 device capabilities detection Piotr Kwapulinski
2024-03-27 15:54 ` [PATCH iwl-next v1 3/5] ixgbe: Add link management support for E610 device Piotr Kwapulinski
2024-04-05  0:14   ` Vinicius Costa Gomes [this message]
2024-04-05 15:10     ` [Intel-wired-lan] " Kwapulinski, Piotr
2024-03-27 15:54 ` [PATCH iwl-next v1 4/5] ixgbe: Add support for NVM handling in " Piotr Kwapulinski
2024-03-27 15:54 ` [PATCH iwl-next v1 5/5] ixgbe: Enable link management " Piotr Kwapulinski
2024-03-27 22:12   ` [Intel-wired-lan] " kernel test robot
2024-03-28  0:58   ` kernel test robot

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=87r0fkbr7i.fsf@intel.com \
    --to=vinicius.gomes@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jan.glaza@intel.com \
    --cc=jedrzej.jagielski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=piotr.kwapulinski@intel.com \
    --cc=stefan.wegrzyn@intel.com \
    /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).