Commit 4da29df3 authored by Tjeerd Pinkert's avatar Tjeerd Pinkert Committed by Adam Wujek

userspace/tools: dynamically check maximum port number in wr_port_tx_control

Signed-off-by: Tjeerd Pinkert's avatarTjeerd Pinkert <t.j.pinkert@alumnus.utwente.nl>
parent 4244c894
......@@ -6,6 +6,7 @@
#include <regs/endpoint-regs.h>
#include <fpga_io.h>
#include <libwr/switch_hw.h>
#include <libwr/shmem.h>
static struct EP_WB _ep_wb;
......@@ -49,6 +50,66 @@ void pcs_write(int ep, uint32_t reg, uint32_t val)
;
}
int get_nports_from_hal(void)
{
struct hal_shmem_header *h;
struct wrs_shm_head *hal_head = NULL;
int hal_nports_local; /* local copy of number of ports */
int ii;
int n_wait = 0;
int ret;
/* wait for HAL */
while ((ret = wrs_shm_get_and_check(wrs_shm_hal, &hal_head)) != 0) {
n_wait++;
if (n_wait > 10) {
if (ret == 1) {
fprintf(stderr, "rtu_stat: Unable to open "
"HAL's shm !\n");
}
if (ret == 2) {
fprintf(stderr, "rtu_stat: Unable to read "
"HAL's version!\n");
}
exit(1);
}
sleep(1);
}
h = (void *)hal_head + hal_head->data_off;
n_wait = 0;
while (1) { /* wait for 10 sec for HAL to produce consistent nports */
n_wait++;
ii = wrs_shm_seqbegin(hal_head);
/* Assume number of ports does not change in runtime */
hal_nports_local = h->nports;
if (!wrs_shm_seqretry(hal_head, ii))
break;
fprintf(stderr, "rtu_stat: Wait for HAL.\n");
if (n_wait > 10) {
exit(1);
}
sleep(1);
}
/* check hal's shm version */
if (hal_head->version != HAL_SHMEM_VERSION) {
fprintf(stderr, "rtu_stat: unknown HAL's shm version %i "
"(known is %i)\n",
hal_head->version, HAL_SHMEM_VERSION);
exit(-1);
}
if (hal_nports_local > HAL_MAX_PORTS) {
fprintf(stderr, "rtu_stat: Too many ports reported by HAL. "
"%d vs %d supported\n",
hal_nports_local, HAL_MAX_PORTS);
exit(-1);
}
return hal_nports_local;
}
int main(int argc, char *argv[])
{
int opt;
......@@ -70,7 +131,7 @@ int main(int argc, char *argv[])
if (argc > 2) {
port_number = atoi(argv[1]);
if (port_number < 0 || port_number > 17) {
if (port_number < 0 || port_number > get_nports_from_hal()-1) {
printf("Port number out of range\n");
exit(1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment