Commit b6a228b8 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: move defines of rtu entry type to libwr

Use define instead of magic numbers
Add enumeration of the "dynamic" field to the wrs_dump_shmem
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 82f50a10
......@@ -21,6 +21,10 @@ struct rtu_addr {
int bucket;
};
/* Filtering entries may be static (permanent) or dynamic (learned) */
#define RTU_ENTRY_TYPE_DYNAMIC 1
#define RTU_ENTRY_TYPE_STATIC 0
/**
* \brief RTU Filtering Database Entry Object
*/
......
......@@ -115,15 +115,15 @@ char *decode_ports(int dpm, int nports)
void show_help(char *prgname)
{
fprintf(stderr, "usage: %s <command> <values>\n", prgname);
fprintf(stderr,""
" help: Show this message\n"
" list: List the routing table (same as empty command)\n"
" remove <ifnum>: Remove all dynamic entries for one interface\n"
" add <mac (XX:XX:XX:XX:XX)> <ifnum> [<mode>]: Add entry for a specific \n"
" MAC address (mode={1=dynamic,0=static}\n"
" vlan <vid> <fid> <hex mask> [<drop>, <prio>, <has_prio>, <prio_override>]: \n"
" Add VLAN entry with vid, fid, mask and drop flag (Write mask=0x0 \n"
" and drop=1 to remove the VLAN)\n");
fprintf(stderr, " help: Show this message\n");
fprintf(stderr, " list: List the routing table (same as empty command)\n");
fprintf(stderr, " remove <ifnum>: Remove all dynamic entries for one interface\n");
fprintf(stderr, " add <mac (XX:XX:XX:XX:XX)> <ifnum> [<mode>]: Add entry for a specific \n");
fprintf(stderr, " MAC address (mode={%d=dynamic, %d=static})\n",
RTU_ENTRY_TYPE_DYNAMIC, RTU_ENTRY_TYPE_STATIC);
fprintf(stderr, " vlan <vid> <fid> <hex mask> [<drop>, <prio>, <has_prio>, <prio_override>]: \n");
fprintf(stderr, " Add VLAN entry with vid, fid, mask and drop flag (Write mask=0x0 \n");
fprintf(stderr, " and drop=1 to remove the VLAN)\n");
exit(1);
}
......@@ -400,10 +400,11 @@ int main(int argc, char **argv)
mac_to_buffer(rtu_htab_local[i].mac, mac_buf),
decode_ports(rtu_htab_local[i].port_mask_dst, nports),
rtu_htab_local[i].fid,
rtu_htab_local[i].dynamic ? "DYNAMIC" : "STATIC ",
rtu_htab_local[i].dynamic == RTU_ENTRY_TYPE_DYNAMIC ?
"DYNAMIC" : "STATIC ",
rtu_htab_local[i].addr.hash,
rtu_htab_local[i].addr.bucket);
if (rtu_htab_local[i].dynamic)
if (rtu_htab_local[i].dynamic == RTU_ENTRY_TYPE_DYNAMIC)
printf("%d\n", rtu_htab_local[i].age);
else
printf("-\n");
......
......@@ -122,6 +122,8 @@ enum dump_type {
dump_type_spll_mode,
dump_type_spll_seq_state,
dump_type_spll_align_state,
/* rtu_filtering_entry enumerations */
dump_type_rtu_filtering_entry_dynamic,
};
static int dump_all_rtu_entries = 0; /* rtu exports 4096 vlans and 2048 htab
......@@ -323,6 +325,19 @@ void dump_one_field(void *addr, struct dump_info *info)
printf("Unknown(%d)\n", i);
}
break;
case dump_type_rtu_filtering_entry_dynamic:
i = *(uint32_t *)p;
switch (i) {
case RTU_ENTRY_TYPE_STATIC:
printf("static");
break;
case RTU_ENTRY_TYPE_DYNAMIC:
printf("dynamic");
break;
default:
printf("Unknown(%d)\n", i);
}
break;
}
}
void dump_many_fields(void *addr, struct dump_info *info, int ninfo)
......@@ -463,7 +478,7 @@ struct dump_info htab_info[] = {
DUMP_FIELD(UInteger8, prio_dst),
DUMP_FIELD(int, has_prio_dst),
DUMP_FIELD(int, prio_override_dst),
DUMP_FIELD(int, dynamic),
DUMP_FIELD(rtu_filtering_entry_dynamic, dynamic),
DUMP_FIELD(int, age),
};
......
......@@ -528,7 +528,8 @@ static void rtu_fd_age_update(void)
hash = bit_cnt >> 2; // 4 buckets per hash
bucket = bit_cnt & 0x03; // last 2 bits
if (!rtu_htab[hash][bucket].dynamic)
if (rtu_htab[hash][bucket].dynamic
== RTU_ENTRY_TYPE_STATIC)
continue;
if (0)
......@@ -561,7 +562,8 @@ void rtu_fd_clear_entries_for_port(int dest_port)
for (i = HTAB_ENTRIES; i-- > 0;) {
for (j = RTU_BUCKETS; j-- > 0;) {
ent = &rtu_htab[i][j];
if (ent->valid && ent->dynamic) {
if (ent->valid
&& (ent->dynamic == RTU_ENTRY_TYPE_DYNAMIC)) {
if (ent->port_mask_dst == (1 << dest_port)) {
/* entry is _only_ for this port */
hw_request(HW_REMOVE_REQ, ent->addr,
......@@ -602,7 +604,7 @@ static void rtu_fd_age_out(void)
for (i = HTAB_ENTRIES; i-- > 0;) {
for (j = RTU_BUCKETS; j-- > 0;) {
ent = &rtu_htab[i][j];
if (ent->valid && ent->dynamic
if (ent->valid && ent->dynamic == RTU_ENTRY_TYPE_DYNAMIC
&& (time_after(t, ent->last_access_t)
|| ent->force_remove)) {
pr_debug("Deleting htab entry: mac = %s, hash ="
......
......@@ -35,9 +35,6 @@
#include "rtu.h"
// Filtering entries may be static (permanent) or dynamic (learned)
#define STATIC 0
#define DYNAMIC 1
// Tells the rtu_fd_create_entry() function what to do if MAC entry is added
// and the same MAC is already known to be at some port (coud be the same or different).
// Most of the time we would like to override the entry because the device simply moved
......
......@@ -108,7 +108,8 @@ static int rtu_create_static_entries(void)
slow_proto_mac[5] = i;
err =
rtu_fd_create_entry(slow_proto_mac, 0,
(1 << hal_nports_local), STATIC,
(1 << hal_nports_local),
RTU_ENTRY_TYPE_STATIC,
OVERRIDE_EXISTING);
if (err)
return err;
......@@ -124,7 +125,7 @@ static int rtu_create_static_entries(void)
pr_info("Adding entry for PTP over UDP\n");
err =
rtu_fd_create_entry(udp_ptp_mac, 0, (1 << hal_nports_local),
STATIC, OVERRIDE_EXISTING);
RTU_ENTRY_TYPE_STATIC, OVERRIDE_EXISTING);
if (err)
return err;
......@@ -133,13 +134,13 @@ static int rtu_create_static_entries(void)
err =
rtu_fd_create_entry(bcast_mac, 0,
enabled_port_mask | (1 << hal_nports_local),
STATIC, OVERRIDE_EXISTING);
RTU_ENTRY_TYPE_STATIC, OVERRIDE_EXISTING);
if (err)
return err;
err =
rtu_fd_create_entry(ptp_mcast_mac, 0,
(1 << hal_nports_local), STATIC,
(1 << hal_nports_local), RTU_ENTRY_TYPE_STATIC,
OVERRIDE_EXISTING);
if (err)
return err;
......@@ -246,7 +247,8 @@ static int rtu_daemon_learning_process(void)
port_map = (1 << req.port_id);
// create or update entry at filtering database
err =
rtu_fd_create_entry(req.src, vid, port_map, DYNAMIC,
rtu_fd_create_entry(req.src, vid, port_map,
RTU_ENTRY_TYPE_DYNAMIC,
OVERRIDE_EXISTING);
err = 0;
if (err == -ENOMEM) {
......
......@@ -83,7 +83,7 @@ int rtudexp_add_entry(const struct minipc_pd *pd, uint32_t * args, void *ret)
pr_info("Create entry for (MAC=%s) port %x (wri%d), mode:%s\n",
mac_to_string(mac_tmp), 1 << port, port + 1,
(mode) ? "DYNAMIC" : "STATIC");
mode == RTU_ENTRY_TYPE_DYNAMIC ? "DYNAMIC" : "STATIC");
*p_ret =
rtu_fd_create_entry(mac_tmp, 0, 1 << port, mode, OVERRIDE_EXISTING);
return *p_ret;
......
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