From: Wojciech Drewek <wojciech.drewek@intel.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, edumazet@google.com,
marcin.szycik@linux.intel.com, anthony.l.nguyen@intel.com,
idosch@nvidia.com, intel-wired-lan@lists.osuosl.org,
pabeni@redhat.com, przemyslaw.kitszel@intel.com
Subject: Re: [Intel-wired-lan] [PATCH net-next 2/3] ethtool: Introduce max power support
Date: Tue, 2 Apr 2024 13:25:07 +0200 [thread overview]
Message-ID: <f7c6264e-9a16-4232-aba2-fde91eb51fb7@intel.com> (raw)
In-Reply-To: <20240329152954.26a7ce75@kernel.org>
On 29.03.2024 23:29, Jakub Kicinski wrote:
> On Fri, 29 Mar 2024 10:23:20 +0100 Wojciech Drewek wrote:
>> Some modules use nonstandard power levels. Adjust ethtool
>> module implementation to support new attributes that will allow user
>> to change maximum power.
>>
>> Add three new get attributes:
>> ETHTOOL_A_MODULE_MAX_POWER_SET (used for set as well) - currently set
>> maximum power in the cage
>
> 1) I'd keep the ETHTOOL_A_MODULE_POWER_ prefix, consistently.
>
> 2) The _SET makes it sound like an action. Can we go with
> ETHTOOL_A_MODULE_POWER_MAX ? Or ETHTOOL_A_MODULE_POWER_LIMIT?
> Yes, ETHTOOL_A_MODULE_POWER_LIMIT
> ETHTOOL_A_MODULE_POWER_MAX
> ETHTOOL_A_MODULE_POWER_MIN
> would sound pretty good to me.
Makes sense, although ETHTOOL_A_MODULE_POWER_LIMIT does not say if
it's max or min limit. What about:
ETHTOOL_A_MODULE_POWER_MAX_LIMIT
ETHTOOL_A_MODULE_POWER_UPPER_LIMIT
>
>> ETHTOOL_A_MODULE_MIN_POWER_ALLOWED - minimum power allowed in the
>> cage reported by device
>> ETHTOOL_A_MODULE_MAX_POWER_ALLOWED - maximum power allowed in the
>> cage reported by device
>>
>> Add two new set attributes:
>> ETHTOOL_A_MODULE_MAX_POWER_SET (used for get as well) - change
>> maximum power in the cage to the given value (milliwatts)
>> ETHTOOL_A_MODULE_MAX_POWER_RESET - reset maximum power setting to the
>> default value
>>
>> Reviewed-by: Marcin Szycik <marcin.szycik@linux.intel.com>
>> Signed-off-by: Wojciech Drewek <wojciech.drewek@intel.com>
>> ---
>> include/linux/ethtool.h | 17 +++++--
>> include/uapi/linux/ethtool_netlink.h | 4 ++
>> net/ethtool/module.c | 74 ++++++++++++++++++++++++++--
>> net/ethtool/netlink.h | 2 +-
>> 4 files changed, 87 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
>> index f3af6b31c9f1..74ed8997443a 100644
>> --- a/include/linux/ethtool.h
>> +++ b/include/linux/ethtool.h
>> @@ -510,10 +510,18 @@ struct ethtool_module_eeprom {
>> * @policy: The power mode policy enforced by the host for the plug-in module.
>> * @mode: The operational power mode of the plug-in module. Should be filled by
>> * device drivers on get operations.
>> + * @min_pwr_allowed: minimum power allowed in the cage reported by device
>> + * @max_pwr_allowed: maximum power allowed in the cage reported by device
>> + * @max_pwr_set: maximum power currently set in the cage
>> + * @max_pwr_reset: restore default minimum power
>> */
>> struct ethtool_module_power_params {
>> enum ethtool_module_power_mode_policy policy;
>> enum ethtool_module_power_mode mode;
>> + u32 min_pwr_allowed;
>> + u32 max_pwr_allowed;
>> + u32 max_pwr_set;
>> + u8 max_pwr_reset;
>
> bool ?
Makes sense
>
>> diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h
>> index 3f89074aa06c..f7cd446b2a83 100644
>> --- a/include/uapi/linux/ethtool_netlink.h
>> +++ b/include/uapi/linux/ethtool_netlink.h
>> @@ -882,6 +882,10 @@ enum {
>> ETHTOOL_A_MODULE_HEADER, /* nest - _A_HEADER_* */
>> ETHTOOL_A_MODULE_POWER_MODE_POLICY, /* u8 */
>> ETHTOOL_A_MODULE_POWER_MODE, /* u8 */
>> + ETHTOOL_A_MODULE_MAX_POWER_SET, /* u32 */
>> + ETHTOOL_A_MODULE_MIN_POWER_ALLOWED, /* u32 */
>> + ETHTOOL_A_MODULE_MAX_POWER_ALLOWED, /* u32 */
>> + ETHTOOL_A_MODULE_MAX_POWER_RESET, /* u8 */
>
> flag ?
Agree
>
>> @@ -77,6 +86,7 @@ static int module_fill_reply(struct sk_buff *skb,
>> const struct ethnl_reply_data *reply_base)
>> {
>> const struct module_reply_data *data = MODULE_REPDATA(reply_base);
>> + u32 temp;
>
> tmp ? temp sounds too much like temperature in context of power
I'll change the name
>
>> static int
>> ethnl_set_module(struct ethnl_req_info *req_info, struct genl_info *info)
>> {
>> struct ethtool_module_power_params power = {};
>> struct ethtool_module_power_params power_new;
>> - const struct ethtool_ops *ops;
>> struct net_device *dev = req_info->dev;
>> struct nlattr **tb = info->attrs;
>> + const struct ethtool_ops *ops;
>> int ret;
>> + bool mod;
>>
>> ops = dev->ethtool_ops;
>>
>> - power_new.policy = nla_get_u8(tb[ETHTOOL_A_MODULE_POWER_MODE_POLICY]);
>> ret = ops->get_module_power_cfg(dev, &power, info->extack);
>> if (ret < 0)
>> return ret;
>>
>> - if (power_new.policy == power.policy)
>> + power_new.max_pwr_set = power.max_pwr_set;
>> + power_new.policy = power.policy;
>> +
>> + ethnl_update_u32(&power_new.max_pwr_set,
>> + tb[ETHTOOL_A_MODULE_MAX_POWER_SET], &mod);
>> + if (mod) {
>
> I think we can use if (tb[ETHTOOL_A_MODULE_MAX_POWER_SET]) here
> Less error prone for future additions.
Yep, makes sense
>
>> + if (power_new.max_pwr_set > power.max_pwr_allowed) {
>> + NL_SET_ERR_MSG(info->extack, "Provided value is higher than maximum allowed");
>
> NL_SET_ERR_MSG_ATTR() to point at the bad attribute.
Sure
>
>> + return -EINVAL;
>
> ERANGE?
Agree
>
>> + } else if (power_new.max_pwr_set < power.min_pwr_allowed) {
>> + NL_SET_ERR_MSG(info->extack, "Provided value is lower than minimum allowed");
>> + return -EINVAL;
>> + }
>> + }
>> +
>> + ethnl_update_policy(&power_new.policy,
>> + tb[ETHTOOL_A_MODULE_POWER_MODE_POLICY], &mod);
>> + ethnl_update_u8(&power_new.max_pwr_reset,
>> + tb[ETHTOOL_A_MODULE_MAX_POWER_RESET], &mod);
>
> I reckon reset should not be allowed if none of the max_pwr values
> are set (i.e. most likely driver doesn't support the config)?
Hmmm, I think we can allow to reset if the currently set limit is the default one.
Right now only the driver could catch such scenario because we don't have a parameter
that driver could use to inform the ethtool about the default value.
I hope that answers your question since I'm not 100% sure if that's what you asked about :)
>
>> + if (!mod)
>> return 0;
>>
>> + if (power_new.max_pwr_reset && power_new.max_pwr_set) {
>
> Mmm. How is that gonna work? The driver is going to set max_pwr_set
> to what's currently configured. So the user is expected to send
> ETHTOOL_A_MODULE_MAX_POWER_SET = 0
> ETHTOOL_A_MODULE_MAX_POWER_RESET = 1
> to reset?
Yes, that was my intention. Using both of those attributes at the same time is not allowed.
>
> Just:
>
> if (tb[ETHTOOL_A_MODULE_MAX_POWER_RESET] &&
> tb[ETHTOOL_A_MODULE_MAX_POWER_SET])
>
> And you can validate this before doing any real work.
Hmmm, makes sense
>
>> + NL_SET_ERR_MSG(info->extack, "Maximum power set and reset cannot be used at the same time");
>> + return 0;
>> + }
>> +
>> ret = ops->set_module_power_cfg(dev, &power_new, info->extack);
>> return ret < 0 ? ret : 1;
>> }
next prev parent reply other threads:[~2024-04-02 11:25 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 9:23 [Intel-wired-lan] [PATCH net-next 0/3] ethtool: Max power support Wojciech Drewek
2024-03-29 9:23 ` [Intel-wired-lan] [PATCH net-next 1/3] ethtool: Make module API more generic Wojciech Drewek
2024-03-29 9:23 ` [Intel-wired-lan] [PATCH net-next 2/3] ethtool: Introduce max power support Wojciech Drewek
2024-03-29 22:29 ` Jakub Kicinski
2024-03-29 22:29 ` Jakub Kicinski
2024-04-02 11:25 ` Wojciech Drewek [this message]
2024-04-02 14:34 ` Jakub Kicinski
2024-04-03 10:19 ` Wojciech Drewek
2024-04-04 0:18 ` Jakub Kicinski
2024-04-04 12:19 ` Wojciech Drewek
2024-03-30 22:14 ` Andrew Lunn
2024-03-30 22:14 ` Andrew Lunn
2024-04-03 9:50 ` Wojciech Drewek
2024-03-29 9:23 ` [Intel-wired-lan] [PATCH net-next 3/3] ice: Implement ethtool max power configuration Wojciech Drewek
2024-03-29 22:16 ` [Intel-wired-lan] [PATCH net-next 0/3] ethtool: Max power support Jakub Kicinski
2024-04-02 9:58 ` Wojciech Drewek
2024-03-30 21:57 ` Andrew Lunn
2024-03-30 21:57 ` Andrew Lunn
2024-04-02 11:38 ` Wojciech Drewek
2024-04-02 14:25 ` Jakub Kicinski
2024-04-02 14:53 ` Andrew Lunn
2024-04-02 14:46 ` Andrew Lunn
2024-04-02 14:57 ` Jakub Kicinski
2024-04-03 13:18 ` Wojciech Drewek
2024-04-03 13:40 ` Andrew Lunn
2024-04-04 12:21 ` Wojciech Drewek
2024-04-03 13:49 ` Andrew Lunn
2024-04-04 12:45 ` Wojciech Drewek
2024-04-04 13:53 ` Andrew Lunn
2024-04-09 12:20 ` Wojciech Drewek
2024-04-09 13:39 ` Andrew Lunn
2024-04-12 13:21 ` Wojciech Drewek
2024-04-15 22:03 ` Andrew Lunn
2024-04-18 11:48 ` Wojciech Drewek
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=f7c6264e-9a16-4232-aba2-fde91eb51fb7@intel.com \
--to=wojciech.drewek@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=edumazet@google.com \
--cc=idosch@nvidia.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuba@kernel.org \
--cc=marcin.szycik@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@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