xref: /linux-6.15/include/linux/pse-pd/pse.h (revision b58be8db)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 // Copyright (c) 2022 Pengutronix, Oleksij Rempel <[email protected]>
4  */
5 #ifndef _LINUX_PSE_CONTROLLER_H
6 #define _LINUX_PSE_CONTROLLER_H
7 
8 #include <linux/ethtool.h>
9 #include <linux/list.h>
10 #include <uapi/linux/ethtool.h>
11 
12 struct phy_device;
13 struct pse_controller_dev;
14 
15 /**
16  * struct pse_control_config - PSE control/channel configuration.
17  *
18  * @podl_admin_control: set PoDL PSE admin control as described in
19  *	IEEE 802.3-2018 30.15.1.2.1 acPoDLPSEAdminControl
20  * @c33_admin_control: set PSE admin control as described in
21  *	IEEE 802.3-2022 30.9.1.2.1 acPSEAdminControl
22  */
23 struct pse_control_config {
24 	enum ethtool_podl_pse_admin_state podl_admin_control;
25 	enum ethtool_c33_pse_admin_state c33_admin_control;
26 };
27 
28 /**
29  * struct pse_control_status - PSE control/channel status.
30  *
31  * @podl_admin_state: operational state of the PoDL PSE
32  *	functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState
33  * @podl_pw_status: power detection status of the PoDL PSE.
34  *	IEEE 802.3-2018 30.15.1.1.3 aPoDLPSEPowerDetectionStatus:
35  * @c33_admin_state: operational state of the PSE
36  *	functions. IEEE 802.3-2022 30.9.1.1.2 aPSEAdminState
37  * @c33_pw_status: power detection status of the PSE.
38  *	IEEE 802.3-2022 30.9.1.1.5 aPSEPowerDetectionStatus:
39  */
40 struct pse_control_status {
41 	enum ethtool_podl_pse_admin_state podl_admin_state;
42 	enum ethtool_podl_pse_pw_d_status podl_pw_status;
43 	enum ethtool_c33_pse_admin_state c33_admin_state;
44 	enum ethtool_c33_pse_pw_d_status c33_pw_status;
45 };
46 
47 /**
48  * struct pse_controller_ops - PSE controller driver callbacks
49  *
50  * @ethtool_get_status: get PSE control status for ethtool interface
51  * @ethtool_set_config: set PSE control configuration over ethtool interface
52  */
53 struct pse_controller_ops {
54 	int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
55 		unsigned long id, struct netlink_ext_ack *extack,
56 		struct pse_control_status *status);
57 	int (*ethtool_set_config)(struct pse_controller_dev *pcdev,
58 		unsigned long id, struct netlink_ext_ack *extack,
59 		const struct pse_control_config *config);
60 };
61 
62 struct module;
63 struct device_node;
64 struct of_phandle_args;
65 struct pse_control;
66 
67 /**
68  * struct pse_controller_dev - PSE controller entity that might
69  *                             provide multiple PSE controls
70  * @ops: a pointer to device specific struct pse_controller_ops
71  * @owner: kernel module of the PSE controller driver
72  * @list: internal list of PSE controller devices
73  * @pse_control_head: head of internal list of requested PSE controls
74  * @dev: corresponding driver model device struct
75  * @of_pse_n_cells: number of cells in PSE line specifiers
76  * @of_xlate: translation function to translate from specifier as found in the
77  *            device tree to id as given to the PSE control ops
78  * @nr_lines: number of PSE controls in this controller device
79  * @lock: Mutex for serialization access to the PSE controller
80  */
81 struct pse_controller_dev {
82 	const struct pse_controller_ops *ops;
83 	struct module *owner;
84 	struct list_head list;
85 	struct list_head pse_control_head;
86 	struct device *dev;
87 	int of_pse_n_cells;
88 	int (*of_xlate)(struct pse_controller_dev *pcdev,
89 			const struct of_phandle_args *pse_spec);
90 	unsigned int nr_lines;
91 	struct mutex lock;
92 };
93 
94 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
95 int pse_controller_register(struct pse_controller_dev *pcdev);
96 void pse_controller_unregister(struct pse_controller_dev *pcdev);
97 struct device;
98 int devm_pse_controller_register(struct device *dev,
99 				 struct pse_controller_dev *pcdev);
100 
101 struct pse_control *of_pse_control_get(struct device_node *node);
102 void pse_control_put(struct pse_control *psec);
103 
104 int pse_ethtool_get_status(struct pse_control *psec,
105 			   struct netlink_ext_ack *extack,
106 			   struct pse_control_status *status);
107 int pse_ethtool_set_config(struct pse_control *psec,
108 			   struct netlink_ext_ack *extack,
109 			   const struct pse_control_config *config);
110 
111 #else
112 
113 static inline struct pse_control *of_pse_control_get(struct device_node *node)
114 {
115 	return ERR_PTR(-ENOENT);
116 }
117 
118 static inline void pse_control_put(struct pse_control *psec)
119 {
120 }
121 
122 static inline int pse_ethtool_get_status(struct pse_control *psec,
123 					 struct netlink_ext_ack *extack,
124 					 struct pse_control_status *status)
125 {
126 	return -ENOTSUPP;
127 }
128 
129 static inline int pse_ethtool_set_config(struct pse_control *psec,
130 					 struct netlink_ext_ack *extack,
131 					 const struct pse_control_config *config)
132 {
133 	return -ENOTSUPP;
134 }
135 
136 #endif
137 
138 #endif
139