Commit 9b8b187f authored by Federico Vaga's avatar Federico Vaga

sw:fw:ep: improve code

Readability, and API
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 748944e5
...@@ -89,23 +89,24 @@ static inline uint32_t ep_eth_build_mac_lo(struct trtl_ep_eth_address* addr) ...@@ -89,23 +89,24 @@ static inline uint32_t ep_eth_build_mac_lo(struct trtl_ep_eth_address* addr)
static inline void rmq_ep_out_writel(int slot, uint32_t data, uint32_t addr) static inline void rmq_ep_out_writel(int slot, uint32_t data, uint32_t addr)
{ {
mq_writel( TRTL_RMQ, data, addr + TRTL_MQ_SLOT_ENDPOINT_CONFIG_START + TRTL_MQ_SLOT_OUT (slot) ); addr += TRTL_MQ_SLOT_ENDPOINT_CONFIG_START + TRTL_MQ_SLOT_OUT(slot);
mq_writel(TRTL_RMQ, data, addr);
} }
static inline void rmq_ep_in_writel(int slot, uint32_t data, uint32_t addr) static inline void rmq_ep_in_writel(int slot, uint32_t data, uint32_t addr)
{ {
mq_writel( TRTL_RMQ, data, addr + TRTL_MQ_SLOT_ENDPOINT_CONFIG_START + TRTL_MQ_SLOT_IN (slot) ); addr += TRTL_MQ_SLOT_ENDPOINT_CONFIG_START + TRTL_MQ_SLOT_IN(slot);
mq_writel(TRTL_RMQ, data, addr);
} }
static void rmq_ep_bind_in(int slot, struct trtl_ep_eth_address* addr) static int rmq_ep_eth_bind_in(unsigned int slot, void *arg)
{ {
struct trtl_ep_eth_address *addr = arg;
uint32_t cfg = 0, tmp; uint32_t cfg = 0, tmp;
switch(addr->type) switch(addr->type)
{ {
case TRTL_EP_FRAME_UDP: case TRTL_EP_FRAME_UDP:
cfg |= TRTL_EP_FILTER_UDP;
break;
case TRTL_EP_FRAME_TLV: case TRTL_EP_FRAME_TLV:
cfg |= TRTL_EP_FILTER_UDP; cfg |= TRTL_EP_FILTER_UDP;
break; break;
...@@ -123,37 +124,63 @@ static void rmq_ep_bind_in(int slot, struct trtl_ep_eth_address* addr) ...@@ -123,37 +124,63 @@ static void rmq_ep_bind_in(int slot, struct trtl_ep_eth_address* addr)
rmq_ep_in_writel( slot, addr->ethertype, TRTL_EP_IN_ETHERTYPE ); rmq_ep_in_writel( slot, addr->ethertype, TRTL_EP_IN_ETHERTYPE );
rmq_ep_in_writel( slot, addr->dst_ip, TRTL_EP_IN_DST_IP ); rmq_ep_in_writel( slot, addr->dst_ip, TRTL_EP_IN_DST_IP );
rmq_ep_in_writel( slot, addr->dst_port, TRTL_EP_IN_DST_PORT ); rmq_ep_in_writel( slot, addr->dst_port, TRTL_EP_IN_DST_PORT );
return 0;
} }
static void rmq_ep_bind_out(int slot, static int rmq_ep_eth_bind_out(unsigned int slot, void *arg)
struct trtl_ep_eth_address* addr)
{ {
struct trtl_ep_eth_address *addr = arg;
uint32_t tmp; uint32_t tmp;
rmq_ep_out_writel( slot, addr->type == TRTL_EP_FRAME_UDP ? 1 : 0, TRTL_EP_OUT_CONFIG ); tmp = addr->type == TRTL_EP_FRAME_UDP ? 1 : 0;
rmq_ep_out_writel(slot, tmp, TRTL_EP_OUT_CONFIG);
tmp = ep_eth_build_mac_hi(addr); tmp = ep_eth_build_mac_hi(addr);
rmq_ep_out_writel( slot, tmp, TRTL_EP_OUT_MAC_HI ); rmq_ep_out_writel(slot, tmp, TRTL_EP_OUT_MAC_HI);
tmp = ep_eth_build_mac_lo(addr); tmp = ep_eth_build_mac_lo(addr);
rmq_ep_out_writel( slot, tmp, TRTL_EP_OUT_MAC_LO ); rmq_ep_out_writel(slot, tmp, TRTL_EP_OUT_MAC_LO);
rmq_ep_out_writel( slot, addr->ethertype, TRTL_EP_OUT_ETHERTYPE ); rmq_ep_out_writel(slot, addr->ethertype, TRTL_EP_OUT_ETHERTYPE);
rmq_ep_out_writel( slot, addr->src_ip, TRTL_EP_OUT_SRC_IP ); rmq_ep_out_writel(slot, addr->src_ip, TRTL_EP_OUT_SRC_IP);
rmq_ep_out_writel( slot, addr->dst_ip, TRTL_EP_OUT_DST_IP ); rmq_ep_out_writel(slot, addr->dst_ip, TRTL_EP_OUT_DST_IP);
rmq_ep_out_writel( slot, addr->src_port, TRTL_EP_OUT_SRC_PORT ); rmq_ep_out_writel(slot, addr->src_port, TRTL_EP_OUT_SRC_PORT);
rmq_ep_out_writel( slot, addr->dst_port, TRTL_EP_OUT_DST_PORT ); rmq_ep_out_writel(slot, addr->dst_port, TRTL_EP_OUT_DST_PORT);
return 0;
} }
void mq_bind(enum trtl_mq_type type, int slot, int is_out,
struct trtl_ep_eth_address* addr) typedef int (trtl_fw_rmq_bind_t) (unsigned int slot, void *arg);
/*
* It's true that this is slower to execute, but on the other hand
* we do not expect to use this on cricital paths. This should be
* used during the initialization phase. The advantage is that, when
* we will add more end-point, here we will have a nice summary and
* we will not need any switch case to execute our functions.
*/
#define __TRTL_EP_IN 0
#define __TRTL_EP_OUT 1
static trtl_fw_rmq_bind_t *rmq_ep_bind[__TRTL_EP_MAX][2] = {
[TRTL_EP_ETH] = {
[__TRTL_EP_IN] = rmq_ep_eth_bind_in,
[__TRTL_EP_OUT] = rmq_ep_eth_bind_out,
},
};
int rmq_bind_in(unsigned int slot, enum trtl_ep_type type, void *addr)
{ {
if( type != TRTL_RMQ ) if (type >= __TRTL_EP_MAX)
{ return -EINVAL;
pr_error("mq_bind() not supported on HMQ slots\n\r");
return; return rmq_ep_bind[type][__TRTL_EP_IN](slot, addr);
} }
int rmq_bind_out(unsigned int slot, enum trtl_ep_type type, void *addr)
{
if (type >= __TRTL_EP_MAX)
return -EINVAL;
if(is_out) return rmq_ep_bind[type][__TRTL_EP_OUT](slot, addr);
rmq_ep_bind_out( slot, addr );
else
rmq_ep_bind_in( slot, addr );
} }
...@@ -489,15 +489,22 @@ static inline void mq_send(enum trtl_mq_type type, int slot) ...@@ -489,15 +489,22 @@ static inline void mq_send(enum trtl_mq_type type, int slot)
} }
/** /**
* Binds an RMQ slot to a particular IP configuration. Used when the Ethernet/UDP * Binds an RMQ slot (input) to a particular IP configuration. Used when
* endpoint is enabled. * the Ethernet/UDP endpoint is enabled.
* @param[in] type MQ type to use * @param[in] slot slot number
* @param[in] type EP type to use
* @param[in] addr bind address
*/
extern int rmq_bind_in(unsigned int slot, enum trtl_ep_type type, void *addr);
/**
* Binds an RMQ slot (output) to a particular IP configuration. Used when
* the Ethernet/UDP endpoint is enabled.
* @param[in] slot slot number * @param[in] slot slot number
* @param[in] is_out non-zero if we're configuring an output slot * @param[in] type EP type to use
* @param[in] addr bind address * @param[in] addr bind address
*/ */
void mq_bind(enum trtl_mq_type type, int slot, int is_out, extern int rmq_bind_out(unsigned int slot, enum trtl_ep_type type, void *addr);
struct trtl_ep_eth_address* addr);
/** /**
......
/* /*
* This work is part of the White Rabbit Node Core project. * Copyright (C) 2018 CERN (www.cern.ch)
*
* Copyright (C) 2013-2014 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* Released according to the GNU GPL, version 2 or any later version. * SPDX-License-Identifier: LGPL-3.0-or-later
*/ */
/*.
* White Rabbit Node Core
*
* rt-mqueue.h: Message Queues definitions and functions
*/
#ifndef __TRTL_ENDPOINT_H #ifndef __TRTL_ENDPOINT_H
#define __TRTL_ENDPOINT_H #define __TRTL_ENDPOINT_H
enum trtl_ep_type {
TRTL_EP_ETH = 0,
__TRTL_EP_MAX,
};
#define TRTL_EP_OUT_CONFIG 0 #define TRTL_EP_OUT_CONFIG 0
#define TRTL_EP_OUT_MAC_HI 4 #define TRTL_EP_OUT_MAC_HI 4
#define TRTL_EP_OUT_MAC_LO 8 #define TRTL_EP_OUT_MAC_LO 8
......
...@@ -78,9 +78,9 @@ int main() ...@@ -78,9 +78,9 @@ int main()
bind_addr.filter |= TRTL_EP_FILTER_ENABLE; bind_addr.filter |= TRTL_EP_FILTER_ENABLE;
// configure outgoing channel // configure outgoing channel
mq_bind(TRTL_RMQ, rmq, 1, &bind_addr); rmq_bind_out(rmq, TRTL_EP_ETH, &bind_addr);
// configure incoming channel // configure incoming channel
mq_bind(TRTL_RMQ, rmq, 0, &bind_addr); rmq_bind_in(rmq, TRTL_EP_ETH, &bind_addr);
send_pkt(0, 0x123); send_pkt(0, 0x123);
v = handle_rx(0); v = handle_rx(0);
......
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