Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/infra/api/affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static struct api_out affinity_set(const void *request, struct api_ctx *) {
if (CPU_COUNT(&req->datapath_cpus) > 0) {
struct iface *iface = NULL;
while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL)
gr_vec_add(ports, (struct iface_info_port *)iface->info);
gr_vec_add(ports, iface_info_port(iface));

ret = worker_queue_distribute(&req->datapath_cpus, ports);
if (ret < 0)
Expand Down Expand Up @@ -86,7 +86,7 @@ static struct api_out rxq_set(const void *request, struct api_ctx *) {
if (iface == NULL)
return api_out(errno, 0, NULL);

port = (struct iface_info_port *)iface->info;
port = iface_info_port(iface);
if (worker_rxq_assign(port->port_id, req->rxq_id, req->cpu_id) < 0)
return api_out(errno, 0, NULL);

Expand Down
9 changes: 4 additions & 5 deletions modules/infra/api/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static struct api_out stats_get(const void *request, struct api_ctx *) {
unsigned num;

while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) {
struct iface_info_port *port = (struct iface_info_port *)iface->info;
struct iface_info_port *port = iface_info_port(iface);

// call first with NULL/0 to get the exact count
if ((ret = rte_eth_xstats_get(port->port_id, NULL, 0)) < 0)
Expand Down Expand Up @@ -240,7 +240,7 @@ static struct api_out stats_reset(const void * /*request*/, struct api_ctx *) {
memset(iface_stats, 0, sizeof(iface_stats));

while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) {
struct iface_info_port *port = (struct iface_info_port *)iface->info;
struct iface_info_port *port = iface_info_port(iface);
if ((ret = rte_eth_stats_reset(port->port_id)) < 0)
return api_out(-ret, 0, NULL);
if ((ret = rte_eth_xstats_reset(port->port_id)) < 0)
Expand Down Expand Up @@ -278,7 +278,7 @@ static struct api_out iface_stats_get(const void * /*request*/, struct api_ctx *

if (iface->type == GR_IFACE_TYPE_PORT) {
// If possible, use the hardware statistics from the driver
struct iface_info_port *port = (struct iface_info_port *)iface->info;
struct iface_info_port *port = iface_info_port(iface);
struct rte_eth_stats stats = {0};
if (rte_eth_stats_get(port->port_id, &stats) == 0) {
s.rx_drops = stats.imissed;
Expand Down Expand Up @@ -400,8 +400,7 @@ telemetry_ifaces_info_get(const char * /*cmd*/, const char * /*params*/, struct

// Get hardware stats for physical ports.
if (iface->type == GR_IFACE_TYPE_PORT) {
struct iface_info_port *port = (struct
iface_info_port *)iface->info;
struct iface_info_port *port = iface_info_port(iface);

struct rte_eth_stats eth_stats;
if (rte_eth_stats_get(port->port_id, &eth_stats) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions modules/infra/cli/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ port_list_info(struct gr_api_client *c, const struct gr_iface *iface, char *buf,
SAFE_BUF(snprintf, len, "devargs=%s mac=" ETH_F, port->devargs, &port->mac);
if (iface->mode == GR_IFACE_MODE_L1_XC) {
if ((peer = iface_from_id(c, iface->domain_id)) != NULL)
SAFE_BUF(snprintf, len - n, " xc_peer=%s", peer->name);
SAFE_BUF(snprintf, len, " xc_peer=%s", peer->name);
else
SAFE_BUF(snprintf, len - n, " xc_peer=%u", iface->domain_id);
SAFE_BUF(snprintf, len, " xc_peer=%u", iface->domain_id);
}
err:
free(peer);
Expand Down
60 changes: 37 additions & 23 deletions modules/infra/control/gr_iface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,49 @@
struct __rte_cache_aligned iface {
BASE(__gr_iface_base);

gr_vec const struct iface **subinterfaces;
gr_vec struct iface **subinterfaces;
char *name;
alignas(alignof(void *)) uint8_t info[/* size depends on type */];
};

#define IFACE_SET_ALL UINT64_C(0xffffffffffffffff)
#define GR_IFACE_INFO(type_id, type_name, fields) \
struct type_name fields __attribute__((__may_alias__, aligned(alignof(void *)))); \
static inline struct type_name *type_name(const struct iface *iface) { \
assert(iface->type == type_id); \
return (struct type_name *)iface->info; \
}

typedef int (*iface_init_t)(struct iface *, const void *api_info);
typedef int (*iface_reconfig_t)(
struct iface *,
uint64_t set_attrs,
const struct gr_iface *,
const void *api_info
);
typedef int (*iface_fini_t)(struct iface *);
typedef int (*iface_eth_addr_get_t)(const struct iface *, struct rte_ether_addr *);
typedef int (*iface_eth_addr_filter_t)(struct iface *, const struct rte_ether_addr *);
typedef void (*iface_to_api_t)(void *api_info, const struct iface *);
#define IFACE_SET_ALL UINT64_C(0xffffffffffffffff)

struct iface_type {
uint16_t id;
size_t pub_size;
size_t priv_size;
iface_init_t init;
iface_reconfig_t reconfig;
iface_fini_t fini;
iface_eth_addr_get_t get_eth_addr;
iface_eth_addr_filter_t add_eth_addr;
iface_eth_addr_filter_t del_eth_addr;
iface_to_api_t to_api;
int (*init)(struct iface *, const void *api_info);
int (*reconfig)(
struct iface *,
uint64_t set_attrs,
const struct gr_iface *,
const void *api_info
);
int (*fini)(struct iface *);
int (*get_eth_addr)(const struct iface *, struct rte_ether_addr *);
int (*set_eth_addr)(struct iface *, const struct rte_ether_addr *);
int (*add_eth_addr)(struct iface *, const struct rte_ether_addr *);
int (*del_eth_addr)(struct iface *, const struct rte_ether_addr *);
int (*set_up_down)(struct iface *, bool up);
int (*set_mtu)(struct iface *, uint16_t mtu);
int (*set_promisc)(struct iface *, bool enabled);
int (*set_allmulti)(struct iface *, bool enabled);
int (*add_vlan)(struct iface *, uint16_t vlan_id);
int (*del_vlan)(struct iface *, uint16_t vlan_id);
void (*to_api)(void *api_info, const struct iface *);
const char *name;
STAILQ_ENTRY(iface_type) next;
};

void iface_type_register(struct iface_type *);
struct iface_type *iface_type_get(gr_iface_type_t type_id);
const struct iface_type *iface_type_get(gr_iface_type_t type_id);
struct iface *iface_create(const struct gr_iface *conf, const void *api_info);
int iface_reconfig(
uint16_t ifid,
Expand All @@ -61,11 +68,18 @@ int iface_reconfig(
);
int iface_destroy(uint16_t ifid);
struct iface *iface_from_id(uint16_t ifid);
void iface_add_subinterface(struct iface *parent, const struct iface *sub);
void iface_del_subinterface(struct iface *parent, const struct iface *sub);
void iface_add_subinterface(struct iface *parent, struct iface *sub);
void iface_del_subinterface(struct iface *parent, struct iface *sub);
int iface_get_eth_addr(uint16_t ifid, struct rte_ether_addr *);
int iface_set_eth_addr(uint16_t ifid, const struct rte_ether_addr *);
int iface_add_eth_addr(uint16_t ifid, const struct rte_ether_addr *);
int iface_del_eth_addr(uint16_t ifid, const struct rte_ether_addr *);
int iface_set_mtu(uint16_t ifid, uint16_t mtu);
int iface_set_up_down(uint16_t ifid, bool up);
int iface_set_promisc(uint16_t ifid, bool enabled);
int iface_set_allmulti(uint16_t ifid, bool enabled);
int iface_add_vlan(uint16_t ifid, uint16_t vlan_id);
int iface_del_vlan(uint16_t ifid, uint16_t vlan_id);
uint16_t ifaces_count(gr_iface_type_t type_id);
struct iface *iface_next(gr_iface_type_t type_id, const struct iface *prev);

Expand Down
4 changes: 2 additions & 2 deletions modules/infra/control/gr_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct mac_filter {
struct rte_ether_addr mac[RTE_ETH_NUM_RECEIVE_MAC_ADDR];
};

struct __rte_aligned(alignof(void *)) iface_info_port {
GR_IFACE_INFO(GR_IFACE_TYPE_PORT, iface_info_port, {
BASE(__gr_iface_info_port_base);

uint16_t port_id;
Expand All @@ -37,7 +37,7 @@ struct __rte_aligned(alignof(void *)) iface_info_port {
uint32_t pool_size;
struct mac_filter ucast_filter;
struct mac_filter mcast_filter;
};
});

uint32_t port_get_rxq_buffer_us(uint16_t port_id, uint16_t rxq_id);
const struct iface *port_get_iface(uint16_t port_id);
4 changes: 1 addition & 3 deletions modules/infra/control/gr_vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <stdint.h>
#include <sys/queue.h>

struct __rte_aligned(alignof(void *)) iface_info_vlan {
BASE(gr_iface_info_vlan);
};
GR_IFACE_INFO(GR_IFACE_TYPE_VLAN, iface_info_vlan, { BASE(gr_iface_info_vlan); });

struct iface *vlan_get_iface(uint16_t port_id, uint16_t vlan_id);
Loading