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