Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
phy.h
Go to the documentation of this file.
1
6
7/*
8 * Copyright (c) 2021 IP-Logix Inc.
9 * Copyright 2022 NXP
10 * Copyright (c) 2025 Aerlync Labs Inc.
11 *
12 * SPDX-License-Identifier: Apache-2.0
13 */
14#ifndef ZEPHYR_INCLUDE_DRIVERS_PHY_H_
15#define ZEPHYR_INCLUDE_DRIVERS_PHY_H_
16
25#include <zephyr/types.h>
26#include <zephyr/device.h>
28#include <errno.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
53
61#define PHY_LINK_IS_FULL_DUPLEX(x) \
62 (x & (LINK_FULL_10BASE | LINK_FULL_100BASE | LINK_FULL_1000BASE | LINK_FULL_2500BASE | \
63 LINK_FULL_5000BASE))
64
72#define PHY_LINK_IS_SPEED_1000M(x) (x & (LINK_HALF_1000BASE | LINK_FULL_1000BASE))
73
81#define PHY_LINK_IS_SPEED_100M(x) (x & (LINK_HALF_100BASE | LINK_FULL_100BASE))
82
90#define PHY_LINK_IS_SPEED_10M(x) (x & (LINK_HALF_10BASE | LINK_FULL_10BASE))
91
99
105
123
133typedef void (*phy_callback_t)(const struct device *dev, struct phy_link_state *state,
134 void *user_data);
135
141
145__subsystem struct ethphy_driver_api {
147 int (*get_link)(const struct device *dev, struct phy_link_state *state);
148
150 int (*cfg_link)(const struct device *dev, enum phy_link_speed adv_speeds,
152
158 int (*link_cb_set)(const struct device *dev, phy_callback_t cb, void *user_data);
159
161 int (*read)(const struct device *dev, uint16_t reg_addr, uint32_t *data);
162
164 int (*write)(const struct device *dev, uint16_t reg_addr, uint32_t data);
165
167 int (*read_c45)(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t *data);
168
170 int (*write_c45)(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t data);
171
172#if defined(CONFIG_ETH_PHY_API_PLCA) || defined(__DOXYGEN__)
177 int (*set_plca_cfg)(const struct device *dev, struct phy_plca_cfg *plca_cfg);
178
183 int (*get_plca_cfg)(const struct device *dev, struct phy_plca_cfg *plca_cfg);
184
189 int (*get_plca_sts)(const struct device *dev, bool *plca_sts);
190#endif /* CONFIG_ETH_PHY_API_PLCA */
191};
192
194
209static inline int phy_configure_link(const struct device *dev, enum phy_link_speed speeds,
211{
212 if (DEVICE_API_GET(ethphy, dev)->cfg_link == NULL) {
213 return -ENOSYS;
214 }
215
216 /* Check if only one speed is set, when auto-negotiation is disabled */
218 return -EINVAL;
219 }
220
221 return DEVICE_API_GET(ethphy, dev)->cfg_link(dev, speeds, flags);
222}
223
237static inline int phy_get_link_state(const struct device *dev, struct phy_link_state *state)
238{
239 if (DEVICE_API_GET(ethphy, dev)->get_link == NULL) {
240 return -ENOSYS;
241 }
242
243 return DEVICE_API_GET(ethphy, dev)->get_link(dev, state);
244}
245
264static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback,
265 void *user_data)
266{
267 if (DEVICE_API_GET(ethphy, dev)->link_cb_set == NULL) {
268 return -ENOSYS;
269 }
270
271 return DEVICE_API_GET(ethphy, dev)->link_cb_set(dev, callback, user_data);
272}
273
286static inline int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value)
287{
288 if (DEVICE_API_GET(ethphy, dev)->read == NULL) {
289 return -ENOSYS;
290 }
291
292 return DEVICE_API_GET(ethphy, dev)->read(dev, reg_addr, value);
293}
294
307static inline int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value)
308{
309 if (DEVICE_API_GET(ethphy, dev)->write == NULL) {
310 return -ENOSYS;
311 }
312
313 return DEVICE_API_GET(ethphy, dev)->write(dev, reg_addr, value);
314}
315
329static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t regad,
330 uint16_t *data)
331{
332 if (DEVICE_API_GET(ethphy, dev)->read_c45 == NULL) {
333 return -ENOSYS;
334 }
335
336 return DEVICE_API_GET(ethphy, dev)->read_c45(dev, devad, regad, data);
337}
338
352static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_t regad,
354{
355 if (DEVICE_API_GET(ethphy, dev)->write_c45 == NULL) {
356 return -ENOSYS;
357 }
358
359 return DEVICE_API_GET(ethphy, dev)->write_c45(dev, devad, regad, data);
360}
361
375static inline int phy_set_plca_cfg(__maybe_unused const struct device *dev,
376 __maybe_unused struct phy_plca_cfg *plca_cfg)
377{
378#if defined(CONFIG_ETH_PHY_API_PLCA)
379 if (DEVICE_API_GET(ethphy, dev)->set_plca_cfg == NULL) {
380 return -ENOSYS;
381 }
382
383 return DEVICE_API_GET(ethphy, dev)->set_plca_cfg(dev, plca_cfg);
384#else
385 return -ENOSYS;
386#endif /* CONFIG_ETH_PHY_API_PLCA */
387}
388
402static inline int phy_get_plca_cfg(__maybe_unused const struct device *dev,
403 __maybe_unused struct phy_plca_cfg *plca_cfg)
404{
405#if defined(CONFIG_ETH_PHY_API_PLCA)
406 if (DEVICE_API_GET(ethphy, dev)->get_plca_cfg == NULL) {
407 return -ENOSYS;
408 }
409
410 return DEVICE_API_GET(ethphy, dev)->get_plca_cfg(dev, plca_cfg);
411#else
412 return -ENOSYS;
413#endif /* CONFIG_ETH_PHY_API_PLCA */
414}
415
429static inline int phy_get_plca_sts(__maybe_unused const struct device *dev,
430 __maybe_unused bool *plca_status)
431{
432#if defined(CONFIG_ETH_PHY_API_PLCA)
433 if (DEVICE_API_GET(ethphy, dev)->get_plca_sts == NULL) {
434 return -ENOSYS;
435 }
436
437 return DEVICE_API_GET(ethphy, dev)->get_plca_sts(dev, plca_status);
438#else
439 return -ENOSYS;
440#endif /* CONFIG_ETH_PHY_API_PLCA */
441}
442
443#ifdef __cplusplus
444}
445#endif
446
450
451#endif /* ZEPHYR_INCLUDE_DRIVERS_PHY_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
System error numbers.
static int phy_link_callback_set(const struct device *dev, phy_callback_t callback, void *user_data)
Set link state change callback.
Definition phy.h:264
static int phy_set_plca_cfg(__maybe_unused const struct device *dev, __maybe_unused struct phy_plca_cfg *plca_cfg)
Write PHY PLCA configuration.
Definition phy.h:375
void(* phy_callback_t)(const struct device *dev, struct phy_link_state *state, void *user_data)
Define the callback function signature for phy_link_callback_set() function.
Definition phy.h:133
static int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value)
Read PHY registers.
Definition phy.h:286
static int phy_write_c45(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t data)
Write PHY C45 register.
Definition phy.h:352
static int phy_get_link_state(const struct device *dev, struct phy_link_state *state)
Get PHY link state.
Definition phy.h:237
static int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t *data)
Read PHY C45 register.
Definition phy.h:329
static int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value)
Write PHY register.
Definition phy.h:307
phy_cfg_link_flag
Ethernet configure link flags.
Definition phy.h:101
phy_link_speed
Ethernet link speeds.
Definition phy.h:35
static int phy_get_plca_sts(__maybe_unused const struct device *dev, __maybe_unused bool *plca_status)
Read PHY PLCA status.
Definition phy.h:429
static int phy_get_plca_cfg(__maybe_unused const struct device *dev, __maybe_unused struct phy_plca_cfg *plca_cfg)
Read PHY PLCA configuration.
Definition phy.h:402
static int phy_configure_link(const struct device *dev, enum phy_link_speed speeds, enum phy_cfg_link_flag flags)
Configure PHY link.
Definition phy.h:209
@ PHY_FLAG_AUTO_NEGOTIATION_DISABLED
Auto-negotiation disable.
Definition phy.h:103
@ LINK_HALF_10BASE
10Base Half-Duplex
Definition phy.h:37
@ LINK_FULL_2500BASE
2.5GBase Full-Duplex
Definition phy.h:49
@ LINK_FULL_10BASE
10Base Full-Duplex
Definition phy.h:39
@ LINK_HALF_100BASE
100Base Half-Duplex
Definition phy.h:41
@ LINK_FULL_1000BASE
1000Base Full-Duplex
Definition phy.h:47
@ LINK_HALF_1000BASE
1000Base Half-Duplex
Definition phy.h:45
@ LINK_FULL_5000BASE
5GBase Full-Duplex
Definition phy.h:51
@ LINK_FULL_100BASE
100Base Full-Duplex
Definition phy.h:43
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define IS_POWER_OF_TWO(x)
Check if a x is a power of two.
Definition util_macro.h:83
#define EINVAL
Invalid argument.
Definition errno.h:60
#define ENOSYS
Function not implemented.
Definition errno.h:82
flags
Definition parser.h:97
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
<span class="mlabel">Driver Operations</span> Ethernet PHY driver operations
Definition phy.h:145
int(* set_plca_cfg)(const struct device *dev, struct phy_plca_cfg *plca_cfg)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:177
int(* write_c45)(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t data)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:170
int(* cfg_link)(const struct device *dev, enum phy_link_speed adv_speeds, enum phy_cfg_link_flag flags)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:150
int(* read_c45)(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t *data)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:167
int(* write)(const struct device *dev, uint16_t reg_addr, uint32_t data)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:164
int(* get_plca_sts)(const struct device *dev, bool *plca_sts)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:189
int(* get_plca_cfg)(const struct device *dev, struct phy_plca_cfg *plca_cfg)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:183
int(* get_link)(const struct device *dev, struct phy_link_state *state)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:147
int(* read)(const struct device *dev, uint16_t reg_addr, uint32_t *data)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:161
int(* link_cb_set)(const struct device *dev, phy_callback_t cb, void *user_data)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition phy.h:158
PLCA (Physical Layer Collision Avoidance) Reconciliation Sublayer configurations.
Definition phy.h:107
uint8_t to_timer
PLCA to_timer in bit-times, which determines the PLCA transmit opportunity.
Definition phy.h:121
uint8_t node_count
PLCA node count.
Definition phy.h:115
uint8_t version
PLCA register map version.
Definition phy.h:109
bool enable
PLCA configured mode (enable/disable).
Definition phy.h:111
uint8_t node_id
PLCA local node identifier.
Definition phy.h:113
uint8_t burst_count
Additional frames a node is allowed to send in single transmit opportunity (TO).
Definition phy.h:117
uint8_t burst_timer
Wait time for the MAC to send a new frame before interrupting the burst.
Definition phy.h:119
Macro utilities.