Commit e972a128 authored by Alessandro Rubini's avatar Alessandro Rubini

general: split ptp_offset into tx and rx offset

This step is in preparation for vlan support, where the tx and rx
headers have a different length.

This commit doesn't build for arch-wrpc, fixed in the next commit
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent b7cd7e37
......@@ -92,7 +92,7 @@ void sim_main_loop(struct pp_globals *ppg)
sim_set_global_DS(ppi);
tmp_ns = 1000LL * 1000LL * pp_state_machine(ppi,
ppi->rx_ptp, i - ppi->ptp_offset);
ppi->rx_ptp, i - ppi->rx_offset);
if (tmp_ns < delay_ns)
delay_ns = tmp_ns;
......
......@@ -49,13 +49,6 @@ void unix_main_loop(struct pp_globals *ppg)
ppi = INST(ppg, j);
/*
* If we are sending or receiving raw ethernet frames,
* the ptp payload is one-eth-header bytes into the frame
*/
if (ppi->proto == PPSI_PROTO_RAW)
ppi->ptp_offset = ETH_HLEN;
/*
* The main loop here is based on select. While we are not
* doing anything else but the protocol, this allows extra stuff
......@@ -131,7 +124,7 @@ void unix_main_loop(struct pp_globals *ppg)
}
tmp_d = pp_state_machine(ppi, ppi->rx_ptp,
i - ppi->ptp_offset);
i - ppi->rx_offset);
if ((delay_ms == -1) || (tmp_d < delay_ms))
delay_ms = tmp_d;
......
......@@ -88,13 +88,6 @@ void wrs_main_loop(struct pp_globals *ppg)
ppi = INST(ppg, j);
/*
* If we are sending or receiving raw ethernet frames,
* the ptp payload is one-eth-header bytes into the frame
*/
if (ppi->proto == PPSI_PROTO_RAW)
ppi->ptp_offset = ETH_HLEN;
/*
* The main loop here is based on select. While we are not
* doing anything else but the protocol, this allows extra stuff
......@@ -172,7 +165,7 @@ void wrs_main_loop(struct pp_globals *ppg)
}
tmp_d = pp_state_machine(ppi, ppi->rx_ptp,
i - ppi->ptp_offset);
i - ppi->rx_offset);
if ((delay_ms == -1) || (tmp_d < delay_ms))
delay_ms = tmp_d;
......
......@@ -148,8 +148,8 @@ struct pp_instance {
/* The net_path used to be allocated separately, but there's no need */
struct pp_channel ch[__NR_PP_NP]; /* general and event ch */
Integer32 mcast_addr; /* FIXME: only ipv4/udp */
int ptp_offset;
Integer32 mcast_addr; /* only ipv4/udp */
int tx_offset, rx_offset; /* ptp payload vs send/recv */
/* Times, for the various offset computations */
TimeInternal t1, t2, t3, t4; /* *the* stamps */
......
......@@ -102,21 +102,8 @@ static inline struct pp_servo *SRV(struct pp_instance *ppi)
return GLBS(ppi)->servo;
}
/* Sometimes (e.g., raw ethernet frames), we need to consider an offset */
static inline void *pp_get_header(struct pp_instance *ppi, void *ptp_payload)
{
return ptp_payload - ppi->ptp_offset;
}
static inline void *pp_get_payload(struct pp_instance *ppi, void *frame_ptr)
{
return frame_ptr + ppi->ptp_offset;
}
extern void pp_prepare_pointers(struct pp_instance *ppi);
/*
* Each extension should fill this structure that is used to augment
* the standard states and avoid code duplications. Please remember
......
......@@ -24,8 +24,6 @@ void bare_main_loop(struct pp_instance *ppi)
{
int delay_ms;
ppi->ptp_offset = 14;
/*
* The main loop here is based on select. While we are not
* doing anything else but the protocol, this allows extra stuff
......@@ -77,6 +75,6 @@ void bare_main_loop(struct pp_instance *ppi)
goto again;
delay_ms = pp_state_machine(ppi, ppi->rx_ptp,
i - ppi->ptp_offset);
i - ppi->rx_offset);
}
}
......@@ -12,7 +12,7 @@
#include <ppsi/lib.h>
#include "wr-constants.h"
#define WRS_PPSI_SHMEM_VERSION 8 /* removed netpath in ppsi */
#define WRS_PPSI_SHMEM_VERSION 9 /* tx and rx offsets are split */
/*
* This structure is used as extension-specific data in the DSPort
......
......@@ -5,6 +5,7 @@
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <linux/if_ether.h>
#include <ppsi/ppsi.h>
#include "common-fun.h"
......@@ -25,12 +26,30 @@ static void *__align_pointer(void *p)
void pp_prepare_pointers(struct pp_instance *ppi)
{
ppi->tx_ptp = __align_pointer(pp_get_payload(ppi, ppi->__tx_buffer));
ppi->rx_ptp = __align_pointer(pp_get_payload(ppi, ppi->__rx_buffer));
/*
* Horrible thing: when we receive vlan, we get standard eth header,
* but when we send we must fill the complete vlan header.
* So we reserve a different number of bytes.
*/
switch(ppi->proto) {
case PPSI_PROTO_RAW:
ppi->tx_offset = ETH_HLEN; /* 14, I know! */
ppi->rx_offset = ETH_HLEN;
break;
case PPSI_PROTO_UDP:
ppi->tx_offset = 0; /* 14, I know! */
ppi->rx_offset = 0;
break;
case PPSI_PROTO_VLAN:
/* FIXME */
break;
}
ppi->tx_ptp = __align_pointer(ppi->__tx_buffer + ppi->tx_offset);
ppi->rx_ptp = __align_pointer(ppi->__rx_buffer + ppi->rx_offset);
/* Now that ptp payload is aligned, get back the header */
ppi->tx_frame = pp_get_header(ppi, ppi->tx_ptp);
ppi->rx_frame = pp_get_header(ppi, ppi->rx_ptp);
ppi->tx_frame = ppi->tx_ptp - ppi->tx_offset;
ppi->rx_frame = ppi->rx_ptp - ppi->rx_offset;
if (0) { /* enable to verify... it works for me though */
pp_printf("%p -> %p %p\n",
......
......@@ -38,7 +38,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
static inline int __send_and_log(struct pp_instance *ppi, int msglen,
int msgtype, int chtype)
{
if (ppi->n_ops->send(ppi, ppi->tx_frame, msglen + ppi->ptp_offset,
if (ppi->n_ops->send(ppi, ppi->tx_frame, msglen + ppi->tx_offset,
&ppi->last_snt_time, chtype, 0) < msglen) {
pp_diag(ppi, frames, 1, "%s(%d) Message can't be sent\n",
pp_msg_names[msgtype], msgtype);
......
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