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