driver: Add network support for Xilinx boards#3059
driver: Add network support for Xilinx boards#3059DeaconescuDaniel wants to merge 6 commits intomainfrom
Conversation
| #define XGEM_PHY_LINK_TIMEOUT_MS 5000 | ||
|
|
||
| /* Uncached memory region for DMA buffer descriptors */ | ||
| static uint8_t bd_space[0x100000] __attribute__((aligned(0x100000))); |
There was a problem hiding this comment.
Do we require 1 MB of DMA buffer memory to reach the full bandwidth of the MAC? There may be cases in which we can poll and receive data more often, so then we can decrease the size of this buffer. I think we can define a macro like this, that also allows the user to configure the buffer size at compile time.
#ifndef XEMACPS_BD_SPACE_SIZE
#define XEMACPS_BD_SPACE_SIZE 0x100000
#endif
static uint8_t bd_space[XEMACPS_BD_SPACE_SIZE] ...
There was a problem hiding this comment.
The cortex-a9 limits the Xil_SetTlbAttributes function to only work with 1MB sections, it would be a good idea for portability, if the bsp supports higher granularity, but we are forced to use 1MB for this processor.
Source: Cortex A9 BSP
/************************** Constant Definitions *****************************/
#define ARM_AR_MEM_TTB_SECT_SIZE 1024*1024
#define ARM_AR_MEM_TTB_SECT_SIZE_MASK (~(ARM_AR_MEM_TTB_SECT_SIZE-1UL))
/************************** Variable Definitions *****************************/
extern u32 MMUTable;
/************************** Function Prototypes ******************************/
/*****************************************************************************/
/**
* @brief This function sets the memory attributes for a section covering 1MB
* of memory in the translation table.
*
* @param Addr: 32-bit address for which memory attributes need to be set.
* @param attrib: Attribute for the given memory region. xil_mmu.h contains
* definitions of commonly used memory attributes which can be
* utilized for this function.
*
*
* @return None.
*
* @note The MMU or D-cache does not need to be disabled before changing a
* translation table entry.
*
******************************************************************************/
void Xil_SetTlbAttributes(INTPTR Addr, u32 attrib)
{
u32 *ptr;
u32 section;
section = Addr / 0x100000U;| #define XGEM_BUFF_SIZE (((XEMACPS_MAX_FRAME_SIZE) + XGEM_CACHE_LINE_SIZE - 1u) \ | ||
| & ~(XGEM_CACHE_LINE_SIZE - 1u)) |
There was a problem hiding this comment.
You can use the no_os_round_up() macro instead of manually aligning: https://github.com/analogdevicesinc/no-OS/blob/main/include/no_os_util.h#L78
There was a problem hiding this comment.
Fixed, i changed it to no_os_align, it was the same macro
| /** XEmacPs device ID from xparameters.h (e.g. XPAR_XEMACPS_0_DEVICE_ID) */ | ||
| uint16_t device_id; | ||
| /** MDIO address of the on-board PHY */ | ||
| uint32_t phy_addr; |
There was a problem hiding this comment.
Nitpick, but the type can be uint8_t, since you can only have 32 PHYs on an MDIO bus.
| XEmacPs_PhyRead(emac, phy_addr, PHY_REG_BMSR, &bmsr); | ||
| ret = XEmacPs_PhyRead(emac, phy_addr, PHY_REG_BMSR, &bmsr); |
There was a problem hiding this comment.
Do you need to read the status register twice?
There was a problem hiding this comment.
Usually the bmsr is a latch low register, which means we need to read twice to get the updated value, but in a loop it doesn't matter since we read again on the next iteration anyway(this section was removed in the latest commit)
| XEmacPs_SetMacAddress(&d->emac, param->hwaddr, 1); | ||
| XEmacPs_SetMdioDivisor(&d->emac, MDC_DIV_224); | ||
|
|
||
| speed = xgem_phy_setup(&d->emac, param->phy_addr); |
There was a problem hiding this comment.
This driver will fail if the link is not up during the xemacps_init() call, right? Having the PHY link up should't be a requirement for a MAC driver to register properly. What can be done instead is to periodically verify the status of the link (e.g Linux does this once per second) and store it somewhere in struct xemacps_desc. Since there is a poll function, I think we can verify the PHY link there. Then, frame RX/TX operation should only be done if the link state is up.
There was a problem hiding this comment.
You're right, i moved the phy polling to the poll function, this way it supports connects and disconnects and we don't busy wait for the connection
0aac9c9 to
5b1d62e
Compare
|
I think this pull request looks good. One thing we can maybe change is to convert the sample project from being specific to the Cora Z7 to an example of using the Ethernet driver for the Xilinx platform. This way, we can add support for other Xilinx boards as well. |
5b1d62e to
141a22d
Compare
|
You're right, i moved the projects to the xilinx_lwip folder, and added support for defining the mdio address, so that for a different board we can just change the address and have it work. (I have not yet tested on other boards, but i think that's all we have to do for compatibility). |
c2cbebf to
bf1daa2
Compare
Add a standalone bare-metal MAC driver for the Zynq-7000 and ZynqMP PS Gigabit Ethernet MAC (XEmacPs / GEM). The driver provides a simple init/remove/send/recv/poll interface with no dependency on any network stack. Signed-off-by: DeaconescuDaniel <Nicolae-daniel.Deaconescu@analog.com>
Add a thin lwIP integration layer for the XEmacPs MAC driver, following the same two-layer pattern as lwip_adin1110. Signed-off-by: DeaconescuDaniel <Nicolae-daniel.Deaconescu@analog.com>
Removed dependency on adin1110 driver, updated heap allocations and removed unused variable Signed-off-by: DeaconescuDaniel <Nicolae-daniel.Deaconescu@analog.com>
Signed-off-by: DeaconescuDaniel <Nicolae-daniel.Deaconescu@analog.com>
Signed-off-by: DeaconescuDaniel <Nicolae-daniel.Deaconescu@analog.com>
Signed-off-by: DeaconescuDaniel <Nicolae-daniel.Deaconescu@analog.com>
bf1daa2 to
6bffe6b
Compare
Pull Request Description
Added ethernet support for xilinx boards using the XEMacPs driver, following the AMD Programming Guide.
Components:
PR Type
PR Checklist