Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: pse-pd: Add support for PSE PIs

The Power Sourcing Equipment Power Interface (PSE PI) plays a pivotal role
in the architecture of Power over Ethernet (PoE) systems. It is essentially
a blueprint that outlines how one or multiple power sources are connected
to the eight-pin modular jack, commonly known as the Ethernet RJ45 port.
This connection scheme is crucial for enabling the delivery of power
alongside data over Ethernet cables.

This patch adds support for getting the PSE controller node through PSE PI
device subnode.

This supports adds a way to get the PSE PI id from the pse_pi devicetree
subnode of a PSE controller node simply by reading the reg property.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
Link: https://lore.kernel.org/r/20240417-feature_poe-v9-7-242293fd1900@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kory Maincent (Dent Project) and committed by
Jakub Kicinski
9be9567a edd79f08

+568 -40
+1
Documentation/networking/pse-pd/index.rst
··· 7 7 :maxdepth: 2 8 8 9 9 introduction 10 + pse-pi
+301
Documentation/networking/pse-pd/pse-pi.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + PSE Power Interface (PSE PI) Documentation 4 + ========================================== 5 + 6 + The Power Sourcing Equipment Power Interface (PSE PI) plays a pivotal role in 7 + the architecture of Power over Ethernet (PoE) systems. It is essentially a 8 + blueprint that outlines how one or multiple power sources are connected to the 9 + eight-pin modular jack, commonly known as the Ethernet RJ45 port. This 10 + connection scheme is crucial for enabling the delivery of power alongside data 11 + over Ethernet cables. 12 + 13 + Documentation and Standards 14 + --------------------------- 15 + 16 + The IEEE 802.3 standard provides detailed documentation on the PSE PI. 17 + Specifically: 18 + 19 + - Section "33.2.3 PI pin assignments" covers the pin assignments for PoE 20 + systems that utilize two pairs for power delivery. 21 + - Section "145.2.4 PSE PI" addresses the configuration for PoE systems that 22 + deliver power over all four pairs of an Ethernet cable. 23 + 24 + PSE PI and Single Pair Ethernet 25 + ------------------------------- 26 + 27 + Single Pair Ethernet (SPE) represents a different approach to Ethernet 28 + connectivity, utilizing just one pair of conductors for both data and power 29 + transmission. Unlike the configurations detailed in the PSE PI for standard 30 + Ethernet, which can involve multiple power sourcing arrangements across four or 31 + two pairs of wires, SPE operates on a simpler model due to its single-pair 32 + design. As a result, the complexities of choosing between alternative pin 33 + assignments for power delivery, as described in the PSE PI for multi-pair 34 + Ethernet, are not applicable to SPE. 35 + 36 + Understanding PSE PI 37 + -------------------- 38 + 39 + The Power Sourcing Equipment Power Interface (PSE PI) is a framework defining 40 + how Power Sourcing Equipment (PSE) delivers power to Powered Devices (PDs) over 41 + Ethernet cables. It details two main configurations for power delivery, known 42 + as Alternative A and Alternative B, which are distinguished not only by their 43 + method of power transmission but also by the implications for polarity and data 44 + transmission direction. 45 + 46 + Alternative A and B Overview 47 + ---------------------------- 48 + 49 + - **Alternative A:** Utilizes RJ45 conductors 1, 2, 3 and 6. In either case of 50 + networks 10/100BaseT or 1G/2G/5G/10GBaseT, the pairs used are carrying data. 51 + The power delivery's polarity in this alternative can vary based on the MDI 52 + (Medium Dependent Interface) or MDI-X (Medium Dependent Interface Crossover) 53 + configuration. 54 + 55 + - **Alternative B:** Utilizes RJ45 conductors 4, 5, 7 and 8. In case of 56 + 10/100BaseT network the pairs used are spare pairs without data and are less 57 + influenced by data transmission direction. This is not the case for 58 + 1G/2G/5G/10GBaseT network. Alternative B includes two configurations with 59 + different polarities, known as variant X and variant S, to accommodate 60 + different network requirements and device specifications. 61 + 62 + Table 145-3 PSE Pinout Alternatives 63 + ----------------------------------- 64 + 65 + The following table outlines the pin configurations for both Alternative A and 66 + Alternative B. 67 + 68 + +------------+-------------------+-----------------+-----------------+-----------------+ 69 + | Conductor | Alternative A | Alternative A | Alternative B | Alternative B | 70 + | | (MDI-X) | (MDI) | (X) | (S) | 71 + +============+===================+=================+=================+=================+ 72 + | 1 | Negative V | Positive V | - | - | 73 + +------------+-------------------+-----------------+-----------------+-----------------+ 74 + | 2 | Negative V | Positive V | - | - | 75 + +------------+-------------------+-----------------+-----------------+-----------------+ 76 + | 3 | Positive V | Negative V | - | - | 77 + +------------+-------------------+-----------------+-----------------+-----------------+ 78 + | 4 | - | - | Negative V | Positive V | 79 + +------------+-------------------+-----------------+-----------------+-----------------+ 80 + | 5 | - | - | Negative V | Positive V | 81 + +------------+-------------------+-----------------+-----------------+-----------------+ 82 + | 6 | Positive V | Negative V | - | - | 83 + +------------+-------------------+-----------------+-----------------+-----------------+ 84 + | 7 | - | - | Positive V | Negative V | 85 + +------------+-------------------+-----------------+-----------------+-----------------+ 86 + | 8 | - | - | Positive V | Negative V | 87 + +------------+-------------------+-----------------+-----------------+-----------------+ 88 + 89 + .. note:: 90 + - "Positive V" and "Negative V" indicate the voltage polarity for each pin. 91 + - "-" indicates that the pin is not used for power delivery in that 92 + specific configuration. 93 + 94 + PSE PI compatibilities 95 + ---------------------- 96 + 97 + The following table outlines the compatibility between the pinout alternative 98 + and the 1000/2.5G/5G/10GBaseT in the PSE 2 pairs connection. 99 + 100 + +---------+---------------+---------------------+-----------------------+ 101 + | Variant | Alternative | Power Feeding Type | Compatibility with | 102 + | | (A/B) | (Direct/Phantom) | 1000/2.5G/5G/10GBaseT | 103 + +=========+===============+=====================+=======================+ 104 + | 1 | A | Phantom | Yes | 105 + +---------+---------------+---------------------+-----------------------+ 106 + | 2 | B | Phantom | Yes | 107 + +---------+---------------+---------------------+-----------------------+ 108 + | 3 | B | Direct | No | 109 + +---------+---------------+---------------------+-----------------------+ 110 + 111 + .. note:: 112 + - "Direct" indicate a variant where the power is injected directly to pairs 113 + without using magnetics in case of spare pairs. 114 + - "Phantom" indicate power path over coils/magnetics as it is done for 115 + Alternative A variant. 116 + 117 + In case of PSE 4 pairs, a PSE supporting only 10/100BaseT (which mean Direct 118 + Power on pinout Alternative B) is not compatible with a 4 pairs 119 + 1000/2.5G/5G/10GBaseT. 120 + 121 + PSE Power Interface (PSE PI) Connection Diagram 122 + ----------------------------------------------- 123 + 124 + The diagram below illustrates the connection architecture between the RJ45 125 + port, the Ethernet PHY (Physical Layer), and the PSE PI (Power Sourcing 126 + Equipment Power Interface), demonstrating how power and data are delivered 127 + simultaneously through an Ethernet cable. The RJ45 port serves as the physical 128 + interface for these connections, with each of its eight pins connected to both 129 + the Ethernet PHY for data transmission and the PSE PI for power delivery. 130 + 131 + .. code-block:: 132 + 133 + +--------------------------+ 134 + | | 135 + | RJ45 Port | 136 + | | 137 + +--+--+--+--+--+--+--+--+--+ +-------------+ 138 + 1| 2| 3| 4| 5| 6| 7| 8| | | 139 + | | | | | | | o-------------------+ | 140 + | | | | | | o--|-------------------+ +<--- PSE 1 141 + | | | | | o--|--|-------------------+ | 142 + | | | | o--|--|--|-------------------+ | 143 + | | | o--|--|--|--|-------------------+ PSE PI | 144 + | | o--|--|--|--|--|-------------------+ | 145 + | o--|--|--|--|--|--|-------------------+ +<--- PSE 2 (optional) 146 + o--|--|--|--|--|--|--|-------------------+ | 147 + | | | | | | | | | | 148 + +--+--+--+--+--+--+--+--+--+ +-------------+ 149 + | | 150 + | Ethernet PHY | 151 + | | 152 + +--------------------------+ 153 + 154 + Simple PSE PI Configuration for Alternative A 155 + --------------------------------------------- 156 + 157 + The diagram below illustrates a straightforward PSE PI (Power Sourcing 158 + Equipment Power Interface) configuration designed to support the Alternative A 159 + setup for Power over Ethernet (PoE). This implementation is tailored to provide 160 + power delivery through the data-carrying pairs of an Ethernet cable, suitable 161 + for either MDI or MDI-X configurations, albeit supporting one variation at a 162 + time. 163 + 164 + .. code-block:: 165 + 166 + +-------------+ 167 + | PSE PI | 168 + 8 -----+ +-------------+ 169 + 7 -----+ Rail 1 | 170 + 6 -----+------+----------------------+ 171 + 5 -----+ | | 172 + 4 -----+ | Rail 2 | PSE 1 173 + 3 -----+------/ +------------+ 174 + 2 -----+--+-------------/ | 175 + 1 -----+--/ +-------------+ 176 + | 177 + +-------------+ 178 + 179 + In this configuration: 180 + 181 + - Pins 1 and 2, as well as pins 3 and 6, are utilized for power delivery in 182 + addition to data transmission. This aligns with the standard wiring for 183 + 10/100BaseT Ethernet networks where these pairs are used for data. 184 + - Rail 1 and Rail 2 represent the positive and negative voltage rails, with 185 + Rail 1 connected to pins 1 and 2, and Rail 2 connected to pins 3 and 6. 186 + More advanced PSE PI configurations may include integrated or external 187 + switches to change the polarity of the voltage rails, allowing for 188 + compatibility with both MDI and MDI-X configurations. 189 + 190 + More complex PSE PI configurations may include additional components, to support 191 + Alternative B, or to provide additional features such as power management, or 192 + additional power delivery capabilities such as 2-pair or 4-pair power delivery. 193 + 194 + .. code-block:: 195 + 196 + +-------------+ 197 + | PSE PI | 198 + | +---+ 199 + 8 -----+--------+ | +-------------+ 200 + 7 -----+--------+ | Rail 1 | 201 + 6 -----+--------+ +-----------------+ 202 + 5 -----+--------+ | | 203 + 4 -----+--------+ | Rail 2 | PSE 1 204 + 3 -----+--------+ +----------------+ 205 + 2 -----+--------+ | | 206 + 1 -----+--------+ | +-------------+ 207 + | +---+ 208 + +-------------+ 209 + 210 + Device Tree Configuration: Describing PSE PI Configurations 211 + ----------------------------------------------------------- 212 + 213 + The necessity for a separate PSE PI node in the device tree is influenced by 214 + the intricacy of the Power over Ethernet (PoE) system's setup. Here are 215 + descriptions of both simple and complex PSE PI configurations to illustrate 216 + this decision-making process: 217 + 218 + **Simple PSE PI Configuration:** 219 + In a straightforward scenario, the PSE PI setup involves a direct, one-to-one 220 + connection between a single PSE controller and an Ethernet port. This setup 221 + typically supports basic PoE functionality without the need for dynamic 222 + configuration or management of multiple power delivery modes. For such simple 223 + configurations, detailing the PSE PI within the existing PSE controller's node 224 + may suffice, as the system does not encompass additional complexity that 225 + warrants a separate node. The primary focus here is on the clear and direct 226 + association of power delivery to a specific Ethernet port. 227 + 228 + **Complex PSE PI Configuration:** 229 + Contrastingly, a complex PSE PI setup may encompass multiple PSE controllers or 230 + auxiliary circuits that collectively manage power delivery to one Ethernet 231 + port. Such configurations might support a range of PoE standards and require 232 + the capability to dynamically configure power delivery based on the operational 233 + mode (e.g., PoE2 versus PoE4) or specific requirements of connected devices. In 234 + these instances, a dedicated PSE PI node becomes essential for accurately 235 + documenting the system architecture. This node would serve to detail the 236 + interactions between different PSE controllers, the support for various PoE 237 + modes, and any additional logic required to coordinate power delivery across 238 + the network infrastructure. 239 + 240 + **Guidance:** 241 + 242 + For simple PSE setups, including PSE PI information in the PSE controller node 243 + might suffice due to the straightforward nature of these systems. However, 244 + complex configurations, involving multiple components or advanced PoE features, 245 + benefit from a dedicated PSE PI node. This method adheres to IEEE 802.3 246 + specifications, improving documentation clarity and ensuring accurate 247 + representation of the PoE system's complexity. 248 + 249 + PSE PI Node: Essential Information 250 + ---------------------------------- 251 + 252 + The PSE PI (Power Sourcing Equipment Power Interface) node in a device tree can 253 + include several key pieces of information critical for defining the power 254 + delivery capabilities and configurations of a PoE (Power over Ethernet) system. 255 + Below is a list of such information, along with explanations for their 256 + necessity and reasons why they might not be found within a PSE controller node: 257 + 258 + 1. **Powered Pairs Configuration** 259 + 260 + - *Description:* Identifies the pairs used for power delivery in the 261 + Ethernet cable. 262 + - *Necessity:* Essential to ensure the correct pairs are powered according 263 + to the board's design. 264 + - *PSE Controller Node:* Typically lacks details on physical pair usage, 265 + focusing on power regulation. 266 + 267 + 2. **Polarity of Powered Pairs** 268 + 269 + - *Description:* Specifies the polarity (positive or negative) for each 270 + powered pair. 271 + - *Necessity:* Critical for safe and effective power transmission to PDs. 272 + - *PSE Controller Node:* Polarity management may exceed the standard 273 + functionalities of PSE controllers. 274 + 275 + 3. **PSE Cells Association** 276 + 277 + - *Description:* Details the association of PSE cells with Ethernet ports or 278 + pairs in multi-cell configurations. 279 + - *Necessity:* Allows for optimized power resource allocation in complex 280 + systems. 281 + - *PSE Controller Node:* Controllers may not manage cell associations 282 + directly, focusing instead on power flow regulation. 283 + 284 + 4. **Support for PoE Standards** 285 + 286 + - *Description:* Lists the PoE standards and configurations supported by the 287 + system. 288 + - *Necessity:* Ensures system compatibility with various PDs and adherence 289 + to industry standards. 290 + - *PSE Controller Node:* Specific capabilities may depend on the overall PSE 291 + PI design rather than the controller alone. Multiple PSE cells per PI 292 + do not necessarily imply support for multiple PoE standards. 293 + 294 + 5. **Protection Mechanisms** 295 + 296 + - *Description:* Outlines additional protection mechanisms, such as 297 + overcurrent protection and thermal management. 298 + - *Necessity:* Provides extra safety and stability, complementing PSE 299 + controller protections. 300 + - *PSE Controller Node:* Some protections may be implemented via 301 + board-specific hardware or algorithms external to the controller.
+232 -36
drivers/net/pse-pd/pse_core.c
··· 27 27 struct kref refcnt; 28 28 }; 29 29 30 - /** 31 - * of_pse_zero_xlate - dummy function for controllers with one only control 32 - * @pcdev: a pointer to the PSE controller device 33 - * @pse_spec: PSE line specifier as found in the device tree 34 - * 35 - * This static translation function is used by default if of_xlate in 36 - * :c:type:`pse_controller_dev` is not set. It is useful for all PSE 37 - * controllers with #pse-cells = <0>. 38 - */ 39 - static int of_pse_zero_xlate(struct pse_controller_dev *pcdev, 40 - const struct of_phandle_args *pse_spec) 30 + static int of_load_single_pse_pi_pairset(struct device_node *node, 31 + struct pse_pi *pi, 32 + int pairset_num) 41 33 { 34 + struct device_node *pairset_np; 35 + const char *name; 36 + int ret; 37 + 38 + ret = of_property_read_string_index(node, "pairset-names", 39 + pairset_num, &name); 40 + if (ret) 41 + return ret; 42 + 43 + if (!strcmp(name, "alternative-a")) { 44 + pi->pairset[pairset_num].pinout = ALTERNATIVE_A; 45 + } else if (!strcmp(name, "alternative-b")) { 46 + pi->pairset[pairset_num].pinout = ALTERNATIVE_B; 47 + } else { 48 + pr_err("pse: wrong pairset-names value %s (%pOF)\n", 49 + name, node); 50 + return -EINVAL; 51 + } 52 + 53 + pairset_np = of_parse_phandle(node, "pairsets", pairset_num); 54 + if (!pairset_np) 55 + return -ENODEV; 56 + 57 + pi->pairset[pairset_num].np = pairset_np; 58 + 42 59 return 0; 43 60 } 44 61 45 62 /** 46 - * of_pse_simple_xlate - translate pse_spec to the PSE line number 47 - * @pcdev: a pointer to the PSE controller device 48 - * @pse_spec: PSE line specifier as found in the device tree 63 + * of_load_pse_pi_pairsets - load PSE PI pairsets pinout and polarity 64 + * @node: a pointer of the device node 65 + * @pi: a pointer of the PSE PI to fill 66 + * @npairsets: the number of pairsets (1 or 2) used by the PI 49 67 * 50 - * This static translation function is used by default if of_xlate in 51 - * :c:type:`pse_controller_dev` is not set. It is useful for all PSE 52 - * controllers with 1:1 mapping, where PSE lines can be indexed by number 53 - * without gaps. 68 + * Return: 0 on success and failure value on error 54 69 */ 55 - static int of_pse_simple_xlate(struct pse_controller_dev *pcdev, 56 - const struct of_phandle_args *pse_spec) 70 + static int of_load_pse_pi_pairsets(struct device_node *node, 71 + struct pse_pi *pi, 72 + int npairsets) 57 73 { 58 - if (pse_spec->args[0] >= pcdev->nr_lines) 59 - return -EINVAL; 74 + int i, ret; 60 75 61 - return pse_spec->args[0]; 76 + ret = of_property_count_strings(node, "pairset-names"); 77 + if (ret != npairsets) { 78 + pr_err("pse: amount of pairsets and pairset-names is not equal %d != %d (%pOF)\n", 79 + npairsets, ret, node); 80 + return -EINVAL; 81 + } 82 + 83 + for (i = 0; i < npairsets; i++) { 84 + ret = of_load_single_pse_pi_pairset(node, pi, i); 85 + if (ret) 86 + goto out; 87 + } 88 + 89 + if (npairsets == 2 && 90 + pi->pairset[0].pinout == pi->pairset[1].pinout) { 91 + pr_err("pse: two PI pairsets can not have identical pinout (%pOF)", 92 + node); 93 + ret = -EINVAL; 94 + } 95 + 96 + out: 97 + /* If an error appears, release all the pairset device node kref */ 98 + if (ret) { 99 + of_node_put(pi->pairset[0].np); 100 + pi->pairset[0].np = NULL; 101 + of_node_put(pi->pairset[1].np); 102 + pi->pairset[1].np = NULL; 103 + } 104 + 105 + return ret; 106 + } 107 + 108 + static void pse_release_pis(struct pse_controller_dev *pcdev) 109 + { 110 + int i; 111 + 112 + for (i = 0; i <= pcdev->nr_lines; i++) { 113 + of_node_put(pcdev->pi[i].pairset[0].np); 114 + of_node_put(pcdev->pi[i].pairset[1].np); 115 + of_node_put(pcdev->pi[i].np); 116 + } 117 + kfree(pcdev->pi); 118 + } 119 + 120 + /** 121 + * of_load_pse_pis - load all the PSE PIs 122 + * @pcdev: a pointer to the PSE controller device 123 + * 124 + * Return: 0 on success and failure value on error 125 + */ 126 + static int of_load_pse_pis(struct pse_controller_dev *pcdev) 127 + { 128 + struct device_node *np = pcdev->dev->of_node; 129 + struct device_node *node, *pis; 130 + int ret; 131 + 132 + if (!np) 133 + return -ENODEV; 134 + 135 + pis = of_get_child_by_name(np, "pse-pis"); 136 + if (!pis) { 137 + /* no description of PSE PIs */ 138 + pcdev->no_of_pse_pi = true; 139 + return 0; 140 + } 141 + 142 + pcdev->pi = kcalloc(pcdev->nr_lines, sizeof(*pcdev->pi), GFP_KERNEL); 143 + if (!pcdev->pi) { 144 + of_node_put(pis); 145 + return -ENOMEM; 146 + } 147 + 148 + for_each_child_of_node(pis, node) { 149 + struct pse_pi pi = {0}; 150 + u32 id; 151 + 152 + if (!of_node_name_eq(node, "pse-pi")) 153 + continue; 154 + 155 + ret = of_property_read_u32(node, "reg", &id); 156 + if (ret) { 157 + dev_err(pcdev->dev, 158 + "can't get reg property for node '%pOF'", 159 + node); 160 + goto out; 161 + } 162 + 163 + if (id >= pcdev->nr_lines) { 164 + dev_err(pcdev->dev, 165 + "reg value (%u) is out of range (%u) (%pOF)\n", 166 + id, pcdev->nr_lines, node); 167 + ret = -EINVAL; 168 + goto out; 169 + } 170 + 171 + if (pcdev->pi[id].np) { 172 + dev_err(pcdev->dev, 173 + "other node with same reg value was already registered. %pOF : %pOF\n", 174 + pcdev->pi[id].np, node); 175 + ret = -EINVAL; 176 + goto out; 177 + } 178 + 179 + ret = of_count_phandle_with_args(node, "pairsets", NULL); 180 + /* npairsets is limited to value one or two */ 181 + if (ret == 1 || ret == 2) { 182 + ret = of_load_pse_pi_pairsets(node, &pi, ret); 183 + if (ret) 184 + goto out; 185 + } else if (ret != ENOENT) { 186 + dev_err(pcdev->dev, 187 + "error: wrong number of pairsets. Should be 1 or 2, got %d (%pOF)\n", 188 + ret, node); 189 + ret = -EINVAL; 190 + goto out; 191 + } 192 + 193 + of_node_get(node); 194 + pi.np = node; 195 + memcpy(&pcdev->pi[id], &pi, sizeof(pi)); 196 + } 197 + 198 + of_node_put(pis); 199 + return 0; 200 + 201 + out: 202 + pse_release_pis(pcdev); 203 + of_node_put(node); 204 + of_node_put(pis); 205 + return ret; 62 206 } 63 207 64 208 /** ··· 211 67 */ 212 68 int pse_controller_register(struct pse_controller_dev *pcdev) 213 69 { 214 - if (!pcdev->of_xlate) { 215 - if (pcdev->of_pse_n_cells == 0) 216 - pcdev->of_xlate = of_pse_zero_xlate; 217 - else if (pcdev->of_pse_n_cells == 1) 218 - pcdev->of_xlate = of_pse_simple_xlate; 219 - } 70 + int ret; 220 71 221 72 mutex_init(&pcdev->lock); 222 73 INIT_LIST_HEAD(&pcdev->pse_control_head); 74 + 75 + if (!pcdev->nr_lines) 76 + pcdev->nr_lines = 1; 77 + 78 + ret = of_load_pse_pis(pcdev); 79 + if (ret) 80 + return ret; 223 81 224 82 mutex_lock(&pse_list_mutex); 225 83 list_add(&pcdev->list, &pse_controller_list); ··· 237 91 */ 238 92 void pse_controller_unregister(struct pse_controller_dev *pcdev) 239 93 { 94 + pse_release_pis(pcdev); 240 95 mutex_lock(&pse_list_mutex); 241 96 list_del(&pcdev->list); 242 97 mutex_unlock(&pse_list_mutex); ··· 350 203 return psec; 351 204 } 352 205 353 - struct pse_control * 354 - of_pse_control_get(struct device_node *node) 206 + /** 207 + * of_pse_match_pi - Find the PSE PI id matching the device node phandle 208 + * @pcdev: a pointer to the PSE controller device 209 + * @np: a pointer to the device node 210 + * 211 + * Return: id of the PSE PI, -EINVAL if not found 212 + */ 213 + static int of_pse_match_pi(struct pse_controller_dev *pcdev, 214 + struct device_node *np) 215 + { 216 + int i; 217 + 218 + for (i = 0; i <= pcdev->nr_lines; i++) { 219 + if (pcdev->pi[i].np == np) 220 + return i; 221 + } 222 + 223 + return -EINVAL; 224 + } 225 + 226 + /** 227 + * psec_id_xlate - translate pse_spec to the PSE line number according 228 + * to the number of pse-cells in case of no pse_pi node 229 + * @pcdev: a pointer to the PSE controller device 230 + * @pse_spec: PSE line specifier as found in the device tree 231 + * 232 + * Return: 0 if #pse-cells = <0>. Return PSE line number otherwise. 233 + */ 234 + static int psec_id_xlate(struct pse_controller_dev *pcdev, 235 + const struct of_phandle_args *pse_spec) 236 + { 237 + if (!pcdev->of_pse_n_cells) 238 + return 0; 239 + 240 + if (pcdev->of_pse_n_cells > 1 || 241 + pse_spec->args[0] >= pcdev->nr_lines) 242 + return -EINVAL; 243 + 244 + return pse_spec->args[0]; 245 + } 246 + 247 + struct pse_control *of_pse_control_get(struct device_node *node) 355 248 { 356 249 struct pse_controller_dev *r, *pcdev; 357 250 struct of_phandle_args args; ··· 409 222 mutex_lock(&pse_list_mutex); 410 223 pcdev = NULL; 411 224 list_for_each_entry(r, &pse_controller_list, list) { 412 - if (args.np == r->dev->of_node) { 225 + if (!r->no_of_pse_pi) { 226 + ret = of_pse_match_pi(r, args.np); 227 + if (ret >= 0) { 228 + pcdev = r; 229 + psec_id = ret; 230 + break; 231 + } 232 + } else if (args.np == r->dev->of_node) { 413 233 pcdev = r; 414 234 break; 415 235 } ··· 432 238 goto out; 433 239 } 434 240 435 - psec_id = pcdev->of_xlate(pcdev, &args); 436 - if (psec_id < 0) { 437 - psec = ERR_PTR(psec_id); 438 - goto out; 241 + if (pcdev->no_of_pse_pi) { 242 + psec_id = psec_id_xlate(pcdev, &args); 243 + if (psec_id < 0) { 244 + psec = ERR_PTR(psec_id); 245 + goto out; 246 + } 439 247 } 440 248 441 249 /* pse_list_mutex also protects the pcdev's pse_control list */
+34 -4
include/linux/pse-pd/pse.h
··· 64 64 struct of_phandle_args; 65 65 struct pse_control; 66 66 67 + /* PSE PI pairset pinout can either be Alternative A or Alternative B */ 68 + enum pse_pi_pairset_pinout { 69 + ALTERNATIVE_A, 70 + ALTERNATIVE_B, 71 + }; 72 + 73 + /** 74 + * struct pse_pi_pairset - PSE PI pairset entity describing the pinout 75 + * alternative ant its phandle 76 + * 77 + * @pinout: description of the pinout alternative 78 + * @np: device node pointer describing the pairset phandle 79 + */ 80 + struct pse_pi_pairset { 81 + enum pse_pi_pairset_pinout pinout; 82 + struct device_node *np; 83 + }; 84 + 85 + /** 86 + * struct pse_pi - PSE PI (Power Interface) entity as described in 87 + * IEEE 802.3-2022 145.2.4 88 + * 89 + * @pairset: table of the PSE PI pinout alternative for the two pairset 90 + * @np: device node pointer of the PSE PI node 91 + */ 92 + struct pse_pi { 93 + struct pse_pi_pairset pairset[2]; 94 + struct device_node *np; 95 + }; 96 + 67 97 /** 68 98 * struct pse_controller_dev - PSE controller entity that might 69 99 * provide multiple PSE controls ··· 103 73 * @pse_control_head: head of internal list of requested PSE controls 104 74 * @dev: corresponding driver model device struct 105 75 * @of_pse_n_cells: number of cells in PSE line specifiers 106 - * @of_xlate: translation function to translate from specifier as found in the 107 - * device tree to id as given to the PSE control ops 108 76 * @nr_lines: number of PSE controls in this controller device 109 77 * @lock: Mutex for serialization access to the PSE controller 110 78 * @types: types of the PSE controller 79 + * @pi: table of PSE PIs described in this controller device 80 + * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used 111 81 */ 112 82 struct pse_controller_dev { 113 83 const struct pse_controller_ops *ops; ··· 116 86 struct list_head pse_control_head; 117 87 struct device *dev; 118 88 int of_pse_n_cells; 119 - int (*of_xlate)(struct pse_controller_dev *pcdev, 120 - const struct of_phandle_args *pse_spec); 121 89 unsigned int nr_lines; 122 90 struct mutex lock; 123 91 enum ethtool_pse_types types; 92 + struct pse_pi *pi; 93 + bool no_of_pse_pi; 124 94 }; 125 95 126 96 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)