xref: /linux-6.15/include/linux/pse-pd/pse.h (revision 47e0dd53)
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  * @types: types of the PSE controller
81  */
82 struct pse_controller_dev {
83 	const struct pse_controller_ops *ops;
84 	struct module *owner;
85 	struct list_head list;
86 	struct list_head pse_control_head;
87 	struct device *dev;
88 	int of_pse_n_cells;
89 	int (*of_xlate)(struct pse_controller_dev *pcdev,
90 			const struct of_phandle_args *pse_spec);
91 	unsigned int nr_lines;
92 	struct mutex lock;
93 	enum ethtool_pse_types types;
94 };
95 
96 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
97 int pse_controller_register(struct pse_controller_dev *pcdev);
98 void pse_controller_unregister(struct pse_controller_dev *pcdev);
99 struct device;
100 int devm_pse_controller_register(struct device *dev,
101 				 struct pse_controller_dev *pcdev);
102 
103 struct pse_control *of_pse_control_get(struct device_node *node);
104 void pse_control_put(struct pse_control *psec);
105 
106 int pse_ethtool_get_status(struct pse_control *psec,
107 			   struct netlink_ext_ack *extack,
108 			   struct pse_control_status *status);
109 int pse_ethtool_set_config(struct pse_control *psec,
110 			   struct netlink_ext_ack *extack,
111 			   const struct pse_control_config *config);
112 
113 bool pse_has_podl(struct pse_control *psec);
114 bool pse_has_c33(struct pse_control *psec);
115 
116 #else
117 
118 static inline struct pse_control *of_pse_control_get(struct device_node *node)
119 {
120 	return ERR_PTR(-ENOENT);
121 }
122 
123 static inline void pse_control_put(struct pse_control *psec)
124 {
125 }
126 
127 static inline int pse_ethtool_get_status(struct pse_control *psec,
128 					 struct netlink_ext_ack *extack,
129 					 struct pse_control_status *status)
130 {
131 	return -ENOTSUPP;
132 }
133 
134 static inline int pse_ethtool_set_config(struct pse_control *psec,
135 					 struct netlink_ext_ack *extack,
136 					 const struct pse_control_config *config)
137 {
138 	return -ENOTSUPP;
139 }
140 
141 static inline bool pse_has_podl(struct pse_control *psec)
142 {
143 	return false;
144 }
145 
146 static inline bool pse_has_c33(struct pse_control *psec)
147 {
148 	return false;
149 }
150 
151 #endif
152 
153 #endif
154