以太网控制器(XMAC)的主要功能是在兼容 IEEE802.3 standard 标准的以太网中发送和接收数据,当前支持 SGMII/RGMII 的 PHY 接口
XMAC 接口特点包括
XMAC 驱动提供了以太网控制器的初始化,DMA 环形队列使用函数,外部PHY 接口相关的配置功能
XMAC 驱动程序的源文件包括,
.
├── fxmac_bd.h
├── fxmac_bdring.c
├── fxmac_bdring.h
├── fxmac.c
├── fxmac_g.c
├── fxmac.h
├── fxmac_hw.h
├── fxmac_intr.c
├── fxmac_options.c
├── fxmac_phy.c
├── fxmac_phy.h
├── fxmac_sinit.c
├── Kconfig
└── phy
├── eth_ieee_reg.h
└── yt
├── phy_yt.c
└── phy_yt.h
中断相关接口
其中fxmac_bdring.h/fxmac_bdring.c 为开发者提供了以下功能:
创建dma 环形队列
环形队列数据拷贝
环形队列描述符分配
环形队列描述符释放
FXMAC 驱动配置数据
typedef struct
{
u32 instance_id; /* Id of device*/
volatile uintptr_t base_address;
volatile uintptr_t extral_mode_base;
volatile uintptr_t extral_loopback_base;
FXmacPhyInterface interface; /* 接口类型,提供SGMII/RGMII 选择 */
u32 speed; /* FXMAC_SPEED_XXX */
u32 duplex; /* 1 is full-duplex , 0 is half-duplex */
u32 auto_neg; /* Enable auto-negotiation - when set active high, autonegotiation operation is enabled. */
u32 pclk_hz;
u32 max_queue_num; /* Number of Xmac Controller Queues */
u32 tx_queue_id; /* 0 ~ FT_XMAC_QUEUE_MAX_NUM ,Index queue number */
u32 rx_queue_id; /* 0 ~ FT_XMAC_QUEUE_MAX_NUM ,Index queue number */
u32 hotplug_irq_num;
u32 dma_brust_length; /* burst length */
u32 network_default_config; /* mac 控制器默认配置 */
u32 queue_irq_num[FT_XMAC_QUEUE_MAX_NUM]; /* mac0 8个 ,其他的 4个 */
} FXmacConfig;
FGMAC 驱动控制数据
typedef struct
{
FXmacConfig config;
u32 is_ready; /* Device is ininitialized and ready*/
u32 is_started;
u32 link_status; /* indicates link status ,FXMAC_LINKUP is link up ,FXMAC_LINKDOWN is link down,FXMAC_NEGOTIATING is need to negotiating*/
u32 options;
FXmacQueue tx_bd_queue; /* Transmit Queue */
FXmacQueue rx_bd_queue; /* Receive Queue */
FXmacIrqHandler send_irq_handler;
void *send_args;
FXmacIrqHandler recv_irq_handler;
void *recv_args;
FXmacErrorIrqHandler error_irq_handler;
void *error_args;
FXmacIrqHandler link_change_handler;
void *link_change_args;
FXmacIrqHandler restart_handler;
void *restart_args;
u32 moudle_id; /* Module identification number */
u32 max_mtu_size;
u32 max_frame_size;
u32 phy_address; /* phy address */
u32 rxbuf_mask; /* Filter length */ /* 1000,100,10 */
} FXmac;
FGMAC DMA描述符
typedef struct
{
uintptr phys_base_addr; /* Physical address of 1st BD in list */
uintptr base_bd_addr; /* Virtual address of 1st BD in list */
uintptr high_bd_addr; /* Virtual address of last BD in the list */
u32 length; /* Total size of ring in bytes */
u32 run_state; /* Flag to indicate DMA is started */
u32 separation; /* Number of bytes between the starting address
of adjacent BDs */
FXmacBd *free_head;
/* First BD in the free group */
FXmacBd *pre_head; /* First BD in the pre-work group */
FXmacBd *hw_head; /* First BD in the work group */
FXmacBd *hw_tail; /* Last BD in the work group */
FXmacBd *post_head;
/* First BD in the post-work group */
FXmacBd *bda_restart;
/* BDA to load when channel is started */
volatile u32 hw_cnt; /* Number of BDs in work group */
u32 pre_cnt; /* Number of BDs in pre-work group */
u32 free_cnt; /* Number of allocatable BDs in the free group */
u32 post_cnt; /* Number of BDs in post-work group */
u32 all_cnt; /* Total Number of BDs for channel */
} FXmacBdRing;
FGMAC DMA描述符表(链式)相关数据
typedef struct
{
u32 desc_idx; /* For Current Desc position */
u32 desc_buf_idx; /* For Current Desc buffer buf position */
u32 desc_max_num; /* Max Number for Desc and Desc buffer */
u8 *desc_buf_base; /* Desc buffer Base */
} FGmacRingDescData;
获取FXMAC驱动的默认配置参数
const FXmacConfig *FXmacLookupConfig(u32 instance_id);
Note:
Input:
Return:
{const FXmacConfig *}, 驱动默认配置
完成FGMAC驱动实例的初始化,使之可以使用
FError FXmacCfgInitialize(FXmac *instance_p, const FXmacConfig *config_p)
Note:
Input:
{FXmac} *instance_p MAC 控制器实例指针
{FXmacConfig} *cofig_p 控制器驱动配置数据
Return:
根据phy 接口类型 ,初始化mac 控制器配置
void FXmacInitInterface(FXmac *instance_p)
Note:
Input:
根据index 获取mac 地址
void FXmacGetMacAddress(FXmac *instance_p, u8 *address_ptr, u8 index)
Input :
Output :
根据index 写入mac 地址
FError FXmacSetMacAddress(FXmac *instance_p, u8 *address_ptr, u8 index);
Input :
Output :
设置FXmac 中的相关配置信息
FError FXmacSetOptions(FXmac *instance_p, u32 options, u32 queue_num)
Note:
Input:
Return:
清除FXmac 中的相关配置信息
FError FXmacClearOptions(FXmac *instance_p, u32 options, u32 queue_num)
Note:
Input:
Return:
启动以太网控制器
void FXmacStart(FXmac *instance_p)
note:
Input:
关闭以太网控制器
void FXmacStop(FXmac *instance_p)
note:
Input:
设置mac 控制器中接收/发送缓冲区 的描述符环形队列的首地址
void FXmacSetQueuePtr(FXmac *instance_p, uintptr queue_p, u8 queue_num,
u32 direction)
Note:
Input:
将数据写入指定的PHY寄存器。
FError FXmacPhyWrite(FXmac *instance_p, u32 phy_address,
u32 register_num, u16 phy_data)
Note:
Input:
Return:
指定PHY 芯片中对应的寄存器号,读出其中对应的参数
FError FXmacPhyRead(FXmac *instance_p, u32 phy_address,
u32 register_num, u16 *phydat_aptr)
Note:
Input:
Output:
Return:
初始化PHY 芯片 ,首先检查出当前已连接的PHY 芯片地址,然后根据协商方式,确定
FError FXmacPhyInit(FXmac *instance_p, u32 speed,u32 duplex_mode, u32 autonegotiation_en);
Input:
Return:
根据MAC 与 PHY 芯片连接的情况,设置相关时钟参数
void FXmacSelectClk(FXmac *instance_p )
Input:
设置中断回调函数
FError FXmacSetHandler(FXmac *instance_p, u32 handler_type, void *func_pointer, void *call_back_ref)
Input: