pci
This commit is contained in:
parent
a7ee7b6617
commit
6e78474998
|
@ -0,0 +1,10 @@
|
||||||
|
from building import *
|
||||||
|
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
src = Glob('*.c')
|
||||||
|
|
||||||
|
CPPPATH = [cwd]
|
||||||
|
|
||||||
|
group = DefineGroup('ofw', src, depend = ['RT_USING_OFW'], CPPPATH = CPPPATH)
|
||||||
|
|
||||||
|
Return('group')
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2024-09-25 zhujiale the first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include "ofw.h"
|
||||||
|
|
||||||
|
static const char* const rt_phy_modes[] =
|
||||||
|
{
|
||||||
|
[RT_PHY_INTERFACE_MODE_NA] = "",
|
||||||
|
[RT_PHY_INTERFACE_MODE_INTERNAL] = "internal",
|
||||||
|
[RT_PHY_INTERFACE_MODE_MII] = "mii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_GMII] = "gmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_SGMII] = "sgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_TBI] = "tbi",
|
||||||
|
[RT_PHY_INTERFACE_MODE_REVMII] = "rev-mii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_RMII] = "rmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_REVRMII] = "rev-rmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_RGMII] = "rgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_RGMII_ID] = "rgmii-id",
|
||||||
|
[RT_PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
|
||||||
|
[RT_PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
|
||||||
|
[RT_PHY_INTERFACE_MODE_RTBI] = "rtbi",
|
||||||
|
[RT_PHY_INTERFACE_MODE_SMII] = "smii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_XGMII] = "xgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_XLGMII] = "xlgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_MOCA] = "moca",
|
||||||
|
[RT_PHY_INTERFACE_MODE_PSGMII] = "psgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_QSGMII] = "qsgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_TRGMII] = "trgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_1000BASEX] = "1000base-x",
|
||||||
|
[RT_PHY_INTERFACE_MODE_1000BASEKX] = "1000base-kx",
|
||||||
|
[RT_PHY_INTERFACE_MODE_2500BASEX] = "2500base-x",
|
||||||
|
[RT_PHY_INTERFACE_MODE_5GBASER] = "5gbase-r",
|
||||||
|
[RT_PHY_INTERFACE_MODE_RXAUI] = "rxaui",
|
||||||
|
[RT_PHY_INTERFACE_MODE_XAUI] = "xaui",
|
||||||
|
[RT_PHY_INTERFACE_MODE_10GBASER] = "10gbase-r",
|
||||||
|
[RT_PHY_INTERFACE_MODE_25GBASER] = "25gbase-r",
|
||||||
|
[RT_PHY_INTERFACE_MODE_USXGMII] = "usxgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_10GKR] = "10gbase-kr",
|
||||||
|
[RT_PHY_INTERFACE_MODE_100BASEX] = "100base-x",
|
||||||
|
[RT_PHY_INTERFACE_MODE_QUSGMII] = "qusgmii",
|
||||||
|
[RT_PHY_INTERFACE_MODE_MAX] = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
static rt_err_t _get_interface_by_name(const char *name, rt_phy_interface *interface)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < RT_PHY_INTERFACE_MODE_MAX; i++)
|
||||||
|
{
|
||||||
|
if (!strcmp(name, rt_phy_modes[i]))
|
||||||
|
{
|
||||||
|
*interface = i;
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_err_t rt_ofw_get_interface(struct rt_ofw_node *np, rt_phy_interface *interface)
|
||||||
|
{
|
||||||
|
const char *phy_mode = RT_NULL;
|
||||||
|
|
||||||
|
if (rt_ofw_prop_read_string(np, "phy-mode", &phy_mode))
|
||||||
|
rt_ofw_prop_read_string(np, "phy-connection-type", &phy_mode);
|
||||||
|
if (!phy_mode)
|
||||||
|
return -RT_ERROR;
|
||||||
|
|
||||||
|
return _get_interface_by_name(phy_mode, interface);
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_err_t rt_ofw_get_mac_addr_by_name(struct rt_ofw_node *np, const char *name, rt_uint8_t *addr)
|
||||||
|
{
|
||||||
|
rt_ssize_t len;
|
||||||
|
const void *p;
|
||||||
|
p = rt_ofw_prop_read_raw(np, name, &len);
|
||||||
|
if (p)
|
||||||
|
{
|
||||||
|
rt_memcpy(addr, p, len);
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_err_t rt_ofw_get_mac_addr(struct rt_ofw_node *np, rt_uint8_t *addr)
|
||||||
|
{
|
||||||
|
if (!rt_ofw_get_mac_addr_by_name(np, "mac-address", addr))
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
if (!rt_ofw_get_mac_addr_by_name(np, "local-mac-address", addr))
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
if (!rt_ofw_get_mac_addr_by_name(np, "address", addr))
|
||||||
|
return RT_EOK;
|
||||||
|
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
#ifndef __NET_OFW_H__
|
||||||
|
#define __NET_OFW_H__
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <drivers/ofw.h>
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
RT_PHY_INTERFACE_MODE_NA,
|
||||||
|
RT_PHY_INTERFACE_MODE_INTERNAL,
|
||||||
|
RT_PHY_INTERFACE_MODE_MII,
|
||||||
|
RT_PHY_INTERFACE_MODE_GMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_SGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_TBI,
|
||||||
|
RT_PHY_INTERFACE_MODE_REVMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_RMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_REVRMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_RGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_RGMII_ID,
|
||||||
|
RT_PHY_INTERFACE_MODE_RGMII_RXID,
|
||||||
|
RT_PHY_INTERFACE_MODE_RGMII_TXID,
|
||||||
|
RT_PHY_INTERFACE_MODE_RTBI,
|
||||||
|
RT_PHY_INTERFACE_MODE_SMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_XGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_XLGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_MOCA,
|
||||||
|
RT_PHY_INTERFACE_MODE_PSGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_QSGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_TRGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_100BASEX,
|
||||||
|
RT_PHY_INTERFACE_MODE_1000BASEX,
|
||||||
|
RT_PHY_INTERFACE_MODE_2500BASEX,
|
||||||
|
RT_PHY_INTERFACE_MODE_5GBASER,
|
||||||
|
RT_PHY_INTERFACE_MODE_RXAUI,
|
||||||
|
RT_PHY_INTERFACE_MODE_XAUI,
|
||||||
|
/* 10GBASE-R, XFI, SFI - single lane 10G Serdes */
|
||||||
|
RT_PHY_INTERFACE_MODE_10GBASER,
|
||||||
|
RT_PHY_INTERFACE_MODE_25GBASER,
|
||||||
|
RT_PHY_INTERFACE_MODE_USXGMII,
|
||||||
|
/* 10GBASE-KR - with Clause 73 AN */
|
||||||
|
RT_PHY_INTERFACE_MODE_10GKR,
|
||||||
|
RT_PHY_INTERFACE_MODE_QUSGMII,
|
||||||
|
RT_PHY_INTERFACE_MODE_1000BASEKX,
|
||||||
|
RT_PHY_INTERFACE_MODE_MAX,
|
||||||
|
} rt_phy_interface;
|
||||||
|
|
||||||
|
rt_err_t rt_ofw_get_mac_addr(struct rt_ofw_node *np, rt_uint8_t *addr);
|
||||||
|
rt_err_t rt_ofw_get_mac_addr_by_name(struct rt_ofw_node *np, const char *name, rt_uint8_t *addr);
|
||||||
|
rt_err_t rt_ofw_get_interface(struct rt_ofw_node *np, rt_phy_interface *interface);
|
||||||
|
#endif
|
Loading…
Reference in New Issue