pse.h 3.9 KB

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