xref: /openbmc/linux/include/linux/pse-pd/pse.h (revision b0c95cef)
13114b075SOleksij Rempel // SPDX-License-Identifier: GPL-2.0-only
23114b075SOleksij Rempel /*
33114b075SOleksij Rempel // Copyright (c) 2022 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
43114b075SOleksij Rempel  */
53114b075SOleksij Rempel #ifndef _LINUX_PSE_CONTROLLER_H
63114b075SOleksij Rempel #define _LINUX_PSE_CONTROLLER_H
73114b075SOleksij Rempel 
83114b075SOleksij Rempel #include <linux/ethtool.h>
93114b075SOleksij Rempel #include <linux/list.h>
103114b075SOleksij Rempel #include <uapi/linux/ethtool.h>
113114b075SOleksij Rempel 
1218ff0bcdSOleksij Rempel struct phy_device;
1318ff0bcdSOleksij Rempel struct pse_controller_dev;
1418ff0bcdSOleksij Rempel 
1518ff0bcdSOleksij Rempel /**
1618ff0bcdSOleksij Rempel  * struct pse_control_config - PSE control/channel configuration.
1718ff0bcdSOleksij Rempel  *
1818ff0bcdSOleksij Rempel  * @admin_cotrol: set PoDL PSE admin control as described in
1918ff0bcdSOleksij Rempel  *	IEEE 802.3-2018 30.15.1.2.1 acPoDLPSEAdminControl
2018ff0bcdSOleksij Rempel  */
2118ff0bcdSOleksij Rempel struct pse_control_config {
2218ff0bcdSOleksij Rempel 	enum ethtool_podl_pse_admin_state admin_cotrol;
2318ff0bcdSOleksij Rempel };
2418ff0bcdSOleksij Rempel 
2518ff0bcdSOleksij Rempel /**
2618ff0bcdSOleksij Rempel  * struct pse_control_status - PSE control/channel status.
2718ff0bcdSOleksij Rempel  *
2818ff0bcdSOleksij Rempel  * @podl_admin_state: operational state of the PoDL PSE
2918ff0bcdSOleksij Rempel  *	functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState
3018ff0bcdSOleksij Rempel  * @podl_pw_status: power detection status of the PoDL PSE.
3118ff0bcdSOleksij Rempel  *	IEEE 802.3-2018 30.15.1.1.3 aPoDLPSEPowerDetectionStatus:
3218ff0bcdSOleksij Rempel  */
3318ff0bcdSOleksij Rempel struct pse_control_status {
3418ff0bcdSOleksij Rempel 	enum ethtool_podl_pse_admin_state podl_admin_state;
3518ff0bcdSOleksij Rempel 	enum ethtool_podl_pse_pw_d_status podl_pw_status;
3618ff0bcdSOleksij Rempel };
3718ff0bcdSOleksij Rempel 
3818ff0bcdSOleksij Rempel /**
3918ff0bcdSOleksij Rempel  * struct pse_controller_ops - PSE controller driver callbacks
4018ff0bcdSOleksij Rempel  *
4118ff0bcdSOleksij Rempel  * @ethtool_get_status: get PSE control status for ethtool interface
4218ff0bcdSOleksij Rempel  * @ethtool_set_config: set PSE control configuration over ethtool interface
4318ff0bcdSOleksij Rempel  */
4418ff0bcdSOleksij Rempel struct pse_controller_ops {
4518ff0bcdSOleksij Rempel 	int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
4618ff0bcdSOleksij Rempel 		unsigned long id, struct netlink_ext_ack *extack,
4718ff0bcdSOleksij Rempel 		struct pse_control_status *status);
4818ff0bcdSOleksij Rempel 	int (*ethtool_set_config)(struct pse_controller_dev *pcdev,
4918ff0bcdSOleksij Rempel 		unsigned long id, struct netlink_ext_ack *extack,
5018ff0bcdSOleksij Rempel 		const struct pse_control_config *config);
5118ff0bcdSOleksij Rempel };
5218ff0bcdSOleksij Rempel 
533114b075SOleksij Rempel struct module;
543114b075SOleksij Rempel struct device_node;
553114b075SOleksij Rempel struct of_phandle_args;
563114b075SOleksij Rempel struct pse_control;
573114b075SOleksij Rempel 
583114b075SOleksij Rempel /**
593114b075SOleksij Rempel  * struct pse_controller_dev - PSE controller entity that might
603114b075SOleksij Rempel  *                             provide multiple PSE controls
613114b075SOleksij Rempel  * @ops: a pointer to device specific struct pse_controller_ops
623114b075SOleksij Rempel  * @owner: kernel module of the PSE controller driver
633114b075SOleksij Rempel  * @list: internal list of PSE controller devices
643114b075SOleksij Rempel  * @pse_control_head: head of internal list of requested PSE controls
653114b075SOleksij Rempel  * @dev: corresponding driver model device struct
663114b075SOleksij Rempel  * @of_pse_n_cells: number of cells in PSE line specifiers
673114b075SOleksij Rempel  * @of_xlate: translation function to translate from specifier as found in the
683114b075SOleksij Rempel  *            device tree to id as given to the PSE control ops
693114b075SOleksij Rempel  * @nr_lines: number of PSE controls in this controller device
703114b075SOleksij Rempel  * @lock: Mutex for serialization access to the PSE controller
713114b075SOleksij Rempel  */
723114b075SOleksij Rempel struct pse_controller_dev {
733114b075SOleksij Rempel 	const struct pse_controller_ops *ops;
743114b075SOleksij Rempel 	struct module *owner;
753114b075SOleksij Rempel 	struct list_head list;
763114b075SOleksij Rempel 	struct list_head pse_control_head;
773114b075SOleksij Rempel 	struct device *dev;
783114b075SOleksij Rempel 	int of_pse_n_cells;
793114b075SOleksij Rempel 	int (*of_xlate)(struct pse_controller_dev *pcdev,
803114b075SOleksij Rempel 			const struct of_phandle_args *pse_spec);
813114b075SOleksij Rempel 	unsigned int nr_lines;
823114b075SOleksij Rempel 	struct mutex lock;
833114b075SOleksij Rempel };
843114b075SOleksij Rempel 
853114b075SOleksij Rempel #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
863114b075SOleksij Rempel int pse_controller_register(struct pse_controller_dev *pcdev);
873114b075SOleksij Rempel void pse_controller_unregister(struct pse_controller_dev *pcdev);
883114b075SOleksij Rempel struct device;
893114b075SOleksij Rempel int devm_pse_controller_register(struct device *dev,
903114b075SOleksij Rempel 				 struct pse_controller_dev *pcdev);
913114b075SOleksij Rempel 
923114b075SOleksij Rempel struct pse_control *of_pse_control_get(struct device_node *node);
933114b075SOleksij Rempel void pse_control_put(struct pse_control *psec);
943114b075SOleksij Rempel 
9518ff0bcdSOleksij Rempel int pse_ethtool_get_status(struct pse_control *psec,
9618ff0bcdSOleksij Rempel 			   struct netlink_ext_ack *extack,
9718ff0bcdSOleksij Rempel 			   struct pse_control_status *status);
9818ff0bcdSOleksij Rempel int pse_ethtool_set_config(struct pse_control *psec,
9918ff0bcdSOleksij Rempel 			   struct netlink_ext_ack *extack,
10018ff0bcdSOleksij Rempel 			   const struct pse_control_config *config);
10118ff0bcdSOleksij Rempel 
1023114b075SOleksij Rempel #else
1033114b075SOleksij Rempel 
of_pse_control_get(struct device_node * node)1043114b075SOleksij Rempel static inline struct pse_control *of_pse_control_get(struct device_node *node)
1053114b075SOleksij Rempel {
1063114b075SOleksij Rempel 	return ERR_PTR(-ENOENT);
1073114b075SOleksij Rempel }
1083114b075SOleksij Rempel 
pse_control_put(struct pse_control * psec)1093114b075SOleksij Rempel static inline void pse_control_put(struct pse_control *psec)
1103114b075SOleksij Rempel {
1113114b075SOleksij Rempel }
1123114b075SOleksij Rempel 
pse_ethtool_get_status(struct pse_control * psec,struct netlink_ext_ack * extack,struct pse_control_status * status)113681bf011SJakub Kicinski static inline int pse_ethtool_get_status(struct pse_control *psec,
11418ff0bcdSOleksij Rempel 					 struct netlink_ext_ack *extack,
11518ff0bcdSOleksij Rempel 					 struct pse_control_status *status)
11618ff0bcdSOleksij Rempel {
117b0c95cefSKory Maincent 	return -EOPNOTSUPP;
11818ff0bcdSOleksij Rempel }
11918ff0bcdSOleksij Rempel 
pse_ethtool_set_config(struct pse_control * psec,struct netlink_ext_ack * extack,const struct pse_control_config * config)120681bf011SJakub Kicinski static inline int pse_ethtool_set_config(struct pse_control *psec,
12118ff0bcdSOleksij Rempel 					 struct netlink_ext_ack *extack,
12218ff0bcdSOleksij Rempel 					 const struct pse_control_config *config)
12318ff0bcdSOleksij Rempel {
124b0c95cefSKory Maincent 	return -EOPNOTSUPP;
12518ff0bcdSOleksij Rempel }
12618ff0bcdSOleksij Rempel 
1273114b075SOleksij Rempel #endif
1283114b075SOleksij Rempel 
1293114b075SOleksij Rempel #endif
130