1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright (c) 2022 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
5 #ifndef _LINUX_PSE_CONTROLLER_H
6 #define _LINUX_PSE_CONTROLLER_H
8 #include <linux/ethtool.h>
9 #include <linux/list.h>
10 #include <uapi/linux/ethtool.h>
13 struct pse_controller_dev;
16 * struct pse_control_config - PSE control/channel configuration.
18 * @admin_cotrol: set PoDL PSE admin control as described in
19 * IEEE 802.3-2018 30.15.1.2.1 acPoDLPSEAdminControl
21 struct pse_control_config {
22 enum ethtool_podl_pse_admin_state admin_cotrol;
26 * struct pse_control_status - PSE control/channel status.
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:
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;
39 * struct pse_controller_ops - PSE controller driver callbacks
41 * @ethtool_get_status: get PSE control status for ethtool interface
42 * @ethtool_set_config: set PSE control configuration over ethtool interface
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);
55 struct of_phandle_args;
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
72 struct pse_controller_dev {
73 const struct pse_controller_ops *ops;
75 struct list_head list;
76 struct list_head pse_control_head;
79 int (*of_xlate)(struct pse_controller_dev *pcdev,
80 const struct of_phandle_args *pse_spec);
81 unsigned int nr_lines;
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);
89 int devm_pse_controller_register(struct device *dev,
90 struct pse_controller_dev *pcdev);
92 struct pse_control *of_pse_control_get(struct device_node *node);
93 void pse_control_put(struct pse_control *psec);
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);
104 static inline struct pse_control *of_pse_control_get(struct device_node *node)
106 return ERR_PTR(-ENOENT);
109 static inline void pse_control_put(struct pse_control *psec)
113 int pse_ethtool_get_status(struct pse_control *psec,
114 struct netlink_ext_ack *extack,
115 struct pse_control_status *status)
120 int pse_ethtool_set_config(struct pse_control *psec,
121 struct netlink_ext_ack *extack,
122 const struct pse_control_config *config)