polarfire-soc / platform

Other
5 stars 11 forks source link

How to make MSS_MAC_receive_pkt() work ? #9

Open fcuzzocrea opened 2 years ago

fcuzzocrea commented 2 years ago

Ciao!

I am trying to setup a simple test of eth0 LOOPBACK (with null_phy configuration) using the baremetal driver provided in the bsp (I also sent some pull requests to fix compilation).

I am setting up mac0 in this way:

#include <stdint.h>

#include <drivers/mss/mss_ethernet_mac/mss_ethernet_registers.h>
#include <drivers/mss/mss_ethernet_mac/mss_ethernet_mac_sw_cfg.h>
#include <drivers/mss/mss_ethernet_mac/mss_ethernet_mac_regs.h>
#include <drivers/mss/mss_ethernet_mac/mss_ethernet_mac.h>
#include <drivers/mss/mss_ethernet_mac/phy.h>

mss_mac_cfg_t g_mac_config;

void init_ethernet()
{
    MSS_MAC_cfg_struct_def_init(&g_mac_config);

    /*
     * Set the MAC address, no need to change other things as the struct is
     * initialized defaulting to NULL_PHY mode.
     */
    g_mac_config.mac_addr[0] = 0xC0u;
    g_mac_config.mac_addr[1] = 0xB1u;
    g_mac_config.mac_addr[2] = 0x3Cu;
    g_mac_config.mac_addr[3] = 0x88u;
    g_mac_config.mac_addr[4] = 0x88u;
    g_mac_config.mac_addr[5] = 0x88u;

    g_mac_config.rx_flow_ctrl = MSS_MAC_RX_FLOW_CTRL_DISABLE;
    g_mac_config.tx_flow_ctrl = MSS_MAC_TX_FLOW_CTRL_DISABLE;
    g_mac_config.append_CRC = MSS_MAC_CRC_ENABLE;
    g_mac_config.queue_enable[0] = MSS_MAC_QUEUE_ENABLE;
    g_mac_config.queue_enable[1] = MSS_MAC_QUEUE_ENABLE;
    g_mac_config.queue_enable[2] = MSS_MAC_QUEUE_ENABLE;
    g_mac_config.queue_enable[3] = MSS_MAC_QUEUE_ENABLE;
    g_mac_config.loopback = MSS_MAC_LOOPBACK_ENABLE;
    g_mac_config.fullduplex = MSS_MAC_FULLDUPLEX_ENABLE;

    /*
     * Initialize MAC with specified configuration. The Ethernet MAC is
     * functional after this function returns but still requires transmit and
     * receive buffers to be allocated for communications to take place.
     */
    MSS_MAC_init(&g_mac0, &g_mac_config);
}

After this, according to the documentation, I created a TX and RX handler which are doing nothing but incrementing a counter (to keep is as simple as possible), and I register them.

After the registration of the handlers, I first call the MSS_MAC_receive_pkt() function, to enable the RX interrupt, and then I send a packet with the MSS_MAC_send_pkt() function.

However, the MSS_MAC_receive_pkt() function always fails to arm the rx. Looking trough the code of the function itself, it seems that status is initialized with MSS_MAC_FAILED

https://github.com/polarfire-soc/platform/blob/48c848c6ce788e517b67aab356c1a385799b63a8/drivers/mss/mss_ethernet_mac/mss_ethernet_mac.c#L1544

But then, trough the body of the function, seems that status never get updated. How can I check if the ARM phase is done correctly ?

Thank you!!

nitindeshpande commented 2 years ago

Hi, I Agree. The update needs to be added in the driver. We will take this up.

About the packet reception, you might have don't this but just to crosscheck, please make sure that in PLIC interrupts are enabled and you have registered the handlers using MSS_MAC_set_tx_callback() etc.

petermcs-01 commented 2 years ago

The important thing to remember about MSS_MAC_receive_pkt() is that when doing the initial setup, it needs to be called multiple times to allocate the complete set of buffers. Only when all MSS_MAC_RX_RING_SIZE buffers are allocated will rx be enabled. Have a look at the sample applications to see how this is done:

/*

fcuzzocrea commented 2 years ago

thanks @petermcs-01 in fact this is what fixed it yesterday in my tests :)

@nitindeshpande I sent some small fixes in a PR, would be nice to have them in the update as well :)

nitindeshpande commented 2 years ago

Sure, @fcuzzocrea :)