Zephyr Project API 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
phy.h
Go to the documentation of this file.
1
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>
27#include <errno.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
52
60#define PHY_LINK_IS_FULL_DUPLEX(x) \
61 (x & (LINK_FULL_10BASE | LINK_FULL_100BASE | LINK_FULL_1000BASE | LINK_FULL_2500BASE | \
62 LINK_FULL_5000BASE))
63
71#define PHY_LINK_IS_SPEED_1000M(x) (x & (LINK_HALF_1000BASE | LINK_FULL_1000BASE))
72
80#define PHY_LINK_IS_SPEED_100M(x) (x & (LINK_HALF_100BASE | LINK_FULL_100BASE))
81
89#define PHY_LINK_IS_SPEED_10M(x) (x & (LINK_HALF_10BASE | LINK_FULL_10BASE))
90
98
116
128int genphy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg);
129
141int genphy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg);
142
154int genphy_get_plca_sts(const struct device *dev, bool *plca_status);
155
165typedef void (*phy_callback_t)(const struct device *dev, struct phy_link_state *state,
166 void *user_data);
167
174__subsystem struct ethphy_driver_api {
176 int (*get_link)(const struct device *dev, struct phy_link_state *state);
177
179 int (*cfg_link)(const struct device *dev, enum phy_link_speed adv_speeds);
180
184 int (*link_cb_set)(const struct device *dev, phy_callback_t cb, void *user_data);
185
187 int (*read)(const struct device *dev, uint16_t reg_addr, uint32_t *data);
188
190 int (*write)(const struct device *dev, uint16_t reg_addr, uint32_t data);
191
193 int (*read_c45)(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t *data);
194
196 int (*write_c45)(const struct device *dev, uint8_t devad, uint16_t regad, uint16_t data);
197
198 /* Set PLCA settings */
199 int (*set_plca_cfg)(const struct device *dev, struct phy_plca_cfg *plca_cfg);
200
201 /* Get PLCA settings */
202 int (*get_plca_cfg)(const struct device *dev, struct phy_plca_cfg *plca_cfg);
203
204 /* Get PLCA status */
205 int (*get_plca_sts)(const struct device *dev, bool *plca_sts);
206};
223static inline int phy_configure_link(const struct device *dev, enum phy_link_speed speeds)
224{
225 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
226
227 if (api->cfg_link == NULL) {
228 return -ENOSYS;
229 }
230
231 return api->cfg_link(dev, speeds);
232}
233
247static inline int phy_get_link_state(const struct device *dev, struct phy_link_state *state)
248{
249 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
250
251 if (api->get_link == NULL) {
252 return -ENOSYS;
253 }
254
255 return api->get_link(dev, state);
256}
257
276static inline int phy_link_callback_set(const struct device *dev, phy_callback_t callback,
277 void *user_data)
278{
279 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
280
281 if (api->link_cb_set == NULL) {
282 return -ENOSYS;
283 }
284
285 return api->link_cb_set(dev, callback, user_data);
286}
287
300static inline int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value)
301{
302 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
303
304 if (api->read == NULL) {
305 return -ENOSYS;
306 }
307
308 return api->read(dev, reg_addr, value);
309}
310
323static inline int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value)
324{
325 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
326
327 if (api->write == NULL) {
328 return -ENOSYS;
329 }
330
331 return api->write(dev, reg_addr, value);
332}
333
347static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t regad,
348 uint16_t *data)
349{
350 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
351
352 if (api->read_c45 == NULL) {
353 return -ENOSYS;
354 }
355
356 return api->read_c45(dev, devad, regad, data);
357}
358
372static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_t regad,
373 uint16_t data)
374{
375 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
376
377 if (api->write_c45 == NULL) {
378 return -ENOSYS;
379 }
380
381 return api->write_c45(dev, devad, regad, data);
382}
383
395static inline int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
396{
397 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
398
399 if (api->set_plca_cfg == NULL) {
400 return -ENOSYS;
401 }
402
403 return api->set_plca_cfg(dev, plca_cfg);
404}
405
417static inline int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
418{
419 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
420
421 if (api->get_plca_cfg == NULL) {
422 return -ENOSYS;
423 }
424
425 return api->get_plca_cfg(dev, plca_cfg);
426}
427
439static inline int phy_get_plca_sts(const struct device *dev, bool *plca_status)
440{
441 const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
442
443 if (api->get_plca_sts == NULL) {
444 return -ENOSYS;
445 }
446
447 return api->get_plca_sts(dev, plca_status);
448}
449
450#ifdef __cplusplus
451}
452#endif
453
458#endif /* ZEPHYR_INCLUDE_DRIVERS_PHY_H_ */
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:276
int genphy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
Write PHY PLCA configuration.
static int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
Write PHY PLCA configuration.
Definition phy.h:395
static int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value)
Read PHY registers.
Definition phy.h:300
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:372
static int phy_get_link_state(const struct device *dev, struct phy_link_state *state)
Get PHY link state.
Definition phy.h:247
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:347
static int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value)
Write PHY register.
Definition phy.h:323
static int phy_get_plca_sts(const struct device *dev, bool *plca_status)
Read PHY PLCA status.
Definition phy.h:439
int genphy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
Read PHY PLCA configuration.
static int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg *plca_cfg)
Read PHY PLCA configuration.
Definition phy.h:417
phy_link_speed
Ethernet link speeds.
Definition phy.h:34
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:165
static int phy_configure_link(const struct device *dev, enum phy_link_speed speeds)
Configure PHY link.
Definition phy.h:223
int genphy_get_plca_sts(const struct device *dev, bool *plca_status)
Read PHY PLCA status.
@ LINK_HALF_10BASE
10Base Half-Duplex
Definition phy.h:36
@ LINK_FULL_2500BASE
2.5GBase Full-Duplex
Definition phy.h:48
@ LINK_FULL_10BASE
10Base Full-Duplex
Definition phy.h:38
@ LINK_HALF_100BASE
100Base Half-Duplex
Definition phy.h:40
@ LINK_FULL_1000BASE
1000Base Full-Duplex
Definition phy.h:46
@ LINK_HALF_1000BASE
1000Base Half-Duplex
Definition phy.h:44
@ LINK_FULL_5000BASE
5GBase Full-Duplex
Definition phy.h:50
@ LINK_FULL_100BASE
100Base Full-Duplex
Definition phy.h:42
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
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:504
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:510
PLCA (Physical Layer Collision Avoidance) Reconciliation Sublayer configurations.
Definition phy.h:100
uint8_t to_timer
PLCA to_timer in bit-times, which determines the PLCA transmit opportunity.
Definition phy.h:114
uint8_t node_count
PLCA node count.
Definition phy.h:108
uint8_t version
PLCA register map version.
Definition phy.h:102
bool enable
PLCA configured mode (enable/disable)
Definition phy.h:104
uint8_t node_id
PLCA local node identifier.
Definition phy.h:106
uint8_t burst_count
Additional frames a node is allowed to send in single transmit opportunity (TO)
Definition phy.h:110
uint8_t burst_timer
Wait time for the MAC to send a new frame before interrupting the burst.
Definition phy.h:112