2023-12-01 17:12:11

by Kory Maincent

[permalink] [raw]
Subject: [PATCH net-next v2 3/8] net: pse-pd: Introduce PSE types enumeration

Introduce an enumeration to define PSE types (C33 or PoDL),
utilizing a bitfield for potential future support of both types.
Include 'pse_get_types' helper for external access to PSE type info.

Sponsored-by: Dent Project <[email protected]>
Signed-off-by: Kory Maincent <[email protected]>
---

Changes in v2:
- Rename PSE_POE to PSE_C33 to have naming consistency.
- Use "static inline" instead of simple static in the header
---
drivers/net/pse-pd/pse_core.c | 9 +++++++++
drivers/net/pse-pd/pse_regulator.c | 1 +
include/linux/pse-pd/pse.h | 22 ++++++++++++++++++++++
3 files changed, 32 insertions(+)

diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
index 146b81f08a89..2959c94f7798 100644
--- a/drivers/net/pse-pd/pse_core.c
+++ b/drivers/net/pse-pd/pse_core.c
@@ -312,3 +312,12 @@ int pse_ethtool_set_config(struct pse_control *psec,
return err;
}
EXPORT_SYMBOL_GPL(pse_ethtool_set_config);
+
+u32 pse_get_types(struct pse_control *psec)
+{
+ if (!psec->pcdev)
+ return PSE_UNKNOWN;
+ else
+ return psec->pcdev->types;
+}
+EXPORT_SYMBOL_GPL(pse_get_types);
diff --git a/drivers/net/pse-pd/pse_regulator.c b/drivers/net/pse-pd/pse_regulator.c
index 1dedf4de296e..e34ab8526067 100644
--- a/drivers/net/pse-pd/pse_regulator.c
+++ b/drivers/net/pse-pd/pse_regulator.c
@@ -116,6 +116,7 @@ pse_reg_probe(struct platform_device *pdev)
priv->pcdev.owner = THIS_MODULE;
priv->pcdev.ops = &pse_reg_ops;
priv->pcdev.dev = dev;
+ priv->pcdev.types = PSE_PODL;
ret = devm_pse_controller_register(dev, &priv->pcdev);
if (ret) {
dev_err(dev, "failed to register PSE controller (%pe)\n",
diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h
index be4e5754eb24..4a0ae3097bb2 100644
--- a/include/linux/pse-pd/pse.h
+++ b/include/linux/pse-pd/pse.h
@@ -44,6 +44,19 @@ struct pse_control_status {
enum ethtool_c33_pse_pw_d_status c33_pw_status;
};

+/**
+ * enum - Types of PSE controller.
+ *
+ * @PSE_UNKNOWN: Type of PSE controller is unknown
+ * @PSE_PODL: PSE controller which support PoDL
+ * @PSE_C33: PSE controller which support Clause 33 (PoE)
+ */
+enum {
+ PSE_UNKNOWN = BIT(0),
+ PSE_PODL = BIT(1),
+ PSE_C33 = BIT(2),
+};
+
/**
* struct pse_controller_ops - PSE controller driver callbacks
*
@@ -77,6 +90,7 @@ struct pse_control;
* device tree to id as given to the PSE control ops
* @nr_lines: number of PSE controls in this controller device
* @lock: Mutex for serialization access to the PSE controller
+ * @types: types of the PSE controller
*/
struct pse_controller_dev {
const struct pse_controller_ops *ops;
@@ -89,6 +103,7 @@ struct pse_controller_dev {
const struct of_phandle_args *pse_spec);
unsigned int nr_lines;
struct mutex lock;
+ u32 types;
};

#if IS_ENABLED(CONFIG_PSE_CONTROLLER)
@@ -108,6 +123,8 @@ int pse_ethtool_set_config(struct pse_control *psec,
struct netlink_ext_ack *extack,
const struct pse_control_config *config);

+u32 pse_get_types(struct pse_control *psec);
+
#else

static inline struct pse_control *of_pse_control_get(struct device_node *node)
@@ -133,6 +150,11 @@ static inline int pse_ethtool_set_config(struct pse_control *psec,
return -ENOTSUPP;
}

+static inline u32 pse_get_types(struct pse_control *psec)
+{
+ return PSE_UNKNOWN;
+}
+
#endif

#endif

--
2.25.1


2023-12-03 18:31:29

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/8] net: pse-pd: Introduce PSE types enumeration

> +u32 pse_get_types(struct pse_control *psec)
> +{
> + if (!psec->pcdev)

Is that possible?

Andrew

2023-12-03 18:38:25

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/8] net: pse-pd: Introduce PSE types enumeration

> +/**
> + * enum - Types of PSE controller.
> + *
> + * @PSE_UNKNOWN: Type of PSE controller is unknown
> + * @PSE_PODL: PSE controller which support PoDL
> + * @PSE_C33: PSE controller which support Clause 33 (PoE)
> + */
> +enum {
> + PSE_UNKNOWN = BIT(0),
> + PSE_PODL = BIT(1),
> + PSE_C33 = BIT(2),
> +};

Maybe this should be in the netlink API?

I think you can imply it by looking at what properties are in the
netlink reply, but having it explicitly is probably better.
ethtool(1) can default to PSE_PODL if the property is missing for an
older kernel.

Andrew

2023-12-04 12:44:25

by Oleksij Rempel

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/8] net: pse-pd: Introduce PSE types enumeration

On Sun, Dec 03, 2023 at 07:31:01PM +0100, Andrew Lunn wrote:
> > +u32 pse_get_types(struct pse_control *psec)
> > +{
> > + if (!psec->pcdev)
>
> Is that possible?

pcdev is automatically linked within pse_control_get_internal()

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2023-12-04 12:52:07

by Oleksij Rempel

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/8] net: pse-pd: Introduce PSE types enumeration

On Fri, Dec 01, 2023 at 06:10:25PM +0100, Kory Maincent wrote:
> +u32 pse_get_types(struct pse_control *psec);

I would add here some helper function. Something like:
pse_has_podl() or pse_has_c33()

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2023-12-04 14:01:02

by Kory Maincent

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/8] net: pse-pd: Introduce PSE types enumeration

Thanks for your review:

On Sun, 3 Dec 2023 19:38:04 +0100
Andrew Lunn <[email protected]> wrote:

> > +/**
> > + * enum - Types of PSE controller.
> > + *
> > + * @PSE_UNKNOWN: Type of PSE controller is unknown
> > + * @PSE_PODL: PSE controller which support PoDL
> > + * @PSE_C33: PSE controller which support Clause 33 (PoE)
> > + */
> > +enum {
> > + PSE_UNKNOWN = BIT(0),
> > + PSE_PODL = BIT(1),
> > + PSE_C33 = BIT(2),
> > +};
>
> Maybe this should be in the netlink API?
>
> I think you can imply it by looking at what properties are in the
> netlink reply, but having it explicitly is probably better.
> ethtool(1) can default to PSE_PODL if the property is missing for an
> older kernel.

Ok, I will add it to netlink API in v3 then.

Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

2023-12-04 14:57:10

by Kory Maincent

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/8] net: pse-pd: Introduce PSE types enumeration


Thanks for your review!

On Mon, 4 Dec 2023 13:51:31 +0100
Oleksij Rempel <[email protected]> wrote:

> On Fri, Dec 01, 2023 at 06:10:25PM +0100, Kory Maincent wrote:
> > +u32 pse_get_types(struct pse_control *psec);
>
> I would add here some helper function. Something like:
> pse_has_podl() or pse_has_c33()

Instead of pse_get_types function? It is indeed maybe cleaner to use such
helper functions instead.

Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com