xref: /linux-6.15/include/linux/pse-pd/pse.h (revision 9be9567a)
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 /* PSE PI pairset pinout can either be Alternative A or Alternative B */
68 enum pse_pi_pairset_pinout {
69 	ALTERNATIVE_A,
70 	ALTERNATIVE_B,
71 };
72 
73 /**
74  * struct pse_pi_pairset - PSE PI pairset entity describing the pinout
75  *			   alternative ant its phandle
76  *
77  * @pinout: description of the pinout alternative
78  * @np: device node pointer describing the pairset phandle
79  */
80 struct pse_pi_pairset {
81 	enum pse_pi_pairset_pinout pinout;
82 	struct device_node *np;
83 };
84 
85 /**
86  * struct pse_pi - PSE PI (Power Interface) entity as described in
87  *		   IEEE 802.3-2022 145.2.4
88  *
89  * @pairset: table of the PSE PI pinout alternative for the two pairset
90  * @np: device node pointer of the PSE PI node
91  */
92 struct pse_pi {
93 	struct pse_pi_pairset pairset[2];
94 	struct device_node *np;
95 };
96 
97 /**
98  * struct pse_controller_dev - PSE controller entity that might
99  *                             provide multiple PSE controls
100  * @ops: a pointer to device specific struct pse_controller_ops
101  * @owner: kernel module of the PSE controller driver
102  * @list: internal list of PSE controller devices
103  * @pse_control_head: head of internal list of requested PSE controls
104  * @dev: corresponding driver model device struct
105  * @of_pse_n_cells: number of cells in PSE line specifiers
106  * @nr_lines: number of PSE controls in this controller device
107  * @lock: Mutex for serialization access to the PSE controller
108  * @types: types of the PSE controller
109  * @pi: table of PSE PIs described in this controller device
110  * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used
111  */
112 struct pse_controller_dev {
113 	const struct pse_controller_ops *ops;
114 	struct module *owner;
115 	struct list_head list;
116 	struct list_head pse_control_head;
117 	struct device *dev;
118 	int of_pse_n_cells;
119 	unsigned int nr_lines;
120 	struct mutex lock;
121 	enum ethtool_pse_types types;
122 	struct pse_pi *pi;
123 	bool no_of_pse_pi;
124 };
125 
126 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
127 int pse_controller_register(struct pse_controller_dev *pcdev);
128 void pse_controller_unregister(struct pse_controller_dev *pcdev);
129 struct device;
130 int devm_pse_controller_register(struct device *dev,
131 				 struct pse_controller_dev *pcdev);
132 
133 struct pse_control *of_pse_control_get(struct device_node *node);
134 void pse_control_put(struct pse_control *psec);
135 
136 int pse_ethtool_get_status(struct pse_control *psec,
137 			   struct netlink_ext_ack *extack,
138 			   struct pse_control_status *status);
139 int pse_ethtool_set_config(struct pse_control *psec,
140 			   struct netlink_ext_ack *extack,
141 			   const struct pse_control_config *config);
142 
143 bool pse_has_podl(struct pse_control *psec);
144 bool pse_has_c33(struct pse_control *psec);
145 
146 #else
147 
148 static inline struct pse_control *of_pse_control_get(struct device_node *node)
149 {
150 	return ERR_PTR(-ENOENT);
151 }
152 
153 static inline void pse_control_put(struct pse_control *psec)
154 {
155 }
156 
157 static inline int pse_ethtool_get_status(struct pse_control *psec,
158 					 struct netlink_ext_ack *extack,
159 					 struct pse_control_status *status)
160 {
161 	return -ENOTSUPP;
162 }
163 
164 static inline int pse_ethtool_set_config(struct pse_control *psec,
165 					 struct netlink_ext_ack *extack,
166 					 const struct pse_control_config *config)
167 {
168 	return -ENOTSUPP;
169 }
170 
171 static inline bool pse_has_podl(struct pse_control *psec)
172 {
173 	return false;
174 }
175 
176 static inline bool pse_has_c33(struct pse_control *psec)
177 {
178 	return false;
179 }
180 
181 #endif
182 
183 #endif
184