From 67bf693b69b8585a91dd886d98693567e868cc5f Mon Sep 17 00:00:00 2001 From: Martin Mueller Date: Tue, 3 Nov 2026 17:05:05 +0100 Subject: [PATCH] force writing of udp header aligned and in order for all detectors --- .../ctbDetectorServer/slsDetectorFunctionList.c | 14 ++++++++++++-- .../slsDetectorFunctionList.c | 16 +++++++++++++--- .../slsDetectorFunctionList.c | 15 +++++++++++++-- .../slsDetectorFunctionList.c | 15 +++++++++++++-- .../slsDetectorFunctionList.c | 17 ++++++++++++++--- 5 files changed, 65 insertions(+), 12 deletions(-) diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index eadf83efb..9fc774e00 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -2158,8 +2158,9 @@ int configureMAC() { // start addr uint32_t addr = RXR_ENDPOINT_START_REG; - // get struct memory - udp_header *udp = (udp_header *)(Blackfin_getBaseAddress() + addr / 2); + // build udp header + udp_header header; + udp_header *udp = &header; memset(udp, 0, sizeof(udp_header)); // mac addresses @@ -2191,6 +2192,15 @@ int configureMAC() { calcChecksum(udp); + // force FPGA writes to be aligned and in order + volatile uint32_t *dst = + (volatile uint32_t *)(Blackfin_getBaseAddress() + addr / 2); + uint32_t words[sizeof(udp_header) / sizeof(uint32_t)]; + memcpy(words, udp, sizeof(udp_header)); + for (size_t i = 0; i != sizeof(words) / sizeof(words[0]); ++i) { + dst[i] = words[i]; + } + cleanFifos(); // FIXME: resetPerpheral() for ctb? resetPeripheral(); LOG(logINFO, ("Waiting for %d s for mac to be up\n", diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 39761d91f..31790658a 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -2052,9 +2052,9 @@ void setupHeader(int iRxEntry, int vetoInterface, uint32_t destip, iRxEntry += RXR_ENDPOINTS_MAX; } addr += (iRxEntry * RXR_ENDPOINT_OFST); - // get struct memory - udp_header *udp = - (udp_header *)(Nios_getBaseAddress() + addr / (sizeof(u_int32_t))); + // build udp header + udp_header header; + udp_header *udp = &header; memset(udp, 0, sizeof(udp_header)); // mac addresses @@ -2085,6 +2085,16 @@ void setupHeader(int iRxEntry, int vetoInterface, uint32_t destip, // total length is redefined in firmware calcChecksum(udp); + + // force FPGA writes to be aligned and in order + volatile uint32_t *dst = (volatile uint32_t *)(Nios_getBaseAddress() + + addr / (sizeof(u_int32_t))); + uint32_t words[sizeof(udp_header) / sizeof(uint32_t)]; + memcpy(words, udp, sizeof(udp_header)); + for (size_t i = 0; i != sizeof(words) / sizeof(words[0]); ++i) { + dst[i] = words[i]; + } + if (iRxEntry < numUdpDestinations) { LOG(logINFO, ("\tIP checksum : 0x%lx\n\n", udp->ip_checksum)); } diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 72244a4eb..ecdd49042 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1870,8 +1870,9 @@ void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, : RXR_ENDPOINT_OUTER_START_REG); // calculate rxr endpoint offset addr += (iRxEntry * RXR_ENDPOINT_OFST); - // get struct memory - udp_header *udp = (udp_header *)(Blackfin_getBaseAddress() + addr / 2); + // build udp header + udp_header header; + udp_header *udp = &header; memset(udp, 0, sizeof(udp_header)); // mac addresses @@ -1902,6 +1903,16 @@ void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, // total length is redefined in firmware calcChecksum(udp); + + // force FPGA writes to be aligned and in order + volatile uint32_t *dst = + (volatile uint32_t *)(Blackfin_getBaseAddress() + addr / 2); + uint32_t words[sizeof(udp_header) / sizeof(uint32_t)]; + memcpy(words, udp, sizeof(udp_header)); + for (size_t i = 0; i != sizeof(words) / sizeof(words[0]); ++i) { + dst[i] = words[i]; + } + if (iRxEntry < numUdpDestinations) { LOG(logINFO, ("\tIP checksum : 0x%lx\n\n", udp->ip_checksum)); } diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index b3cb6fe69..8c17dd573 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -1203,8 +1203,9 @@ void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, : RXR_ENDPOINT_OUTER_START_REG); // calculate rxr endpoint offset addr += (iRxEntry * RXR_ENDPOINT_OFST); - // get struct memory - udp_header *udp = (udp_header *)(Blackfin_getBaseAddress() + addr / 2); + // build udp header + udp_header header; + udp_header *udp = &header; memset(udp, 0, sizeof(udp_header)); // mac addresses @@ -1235,6 +1236,16 @@ void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, // total length is redefined in firmware calcChecksum(udp); + + // force FPGA writes to be aligned and in order + volatile uint32_t *dst = + (volatile uint32_t *)(Blackfin_getBaseAddress() + addr / 2); + uint32_t words[sizeof(udp_header) / sizeof(uint32_t)]; + memcpy(words, udp, sizeof(udp_header)); + for (size_t i = 0; i != sizeof(words) / sizeof(words[0]); ++i) { + dst[i] = words[i]; + } + if (iRxEntry < numUdpDestinations) { LOG(logINFO, ("\tIP checksum : 0x%lx\n\n", udp->ip_checksum)); } diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 8c7f107aa..cfe99a8c0 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -2225,9 +2225,9 @@ int configureMAC() { uint32_t addr = BASE_UDP_RAM; // calculate rxr endpoint offset addr += (iRxEntry * RXR_ENDPOINT_OFST); // TODO: is there round robin - // get struct memory - udp_header *udp = - (udp_header *)(Nios_getBaseAddress() + addr / (sizeof(u_int32_t))); + // build udp header + udp_header header; + udp_header *udp = &header; memset(udp, 0, sizeof(udp_header)); // mac addresses @@ -2258,6 +2258,17 @@ int configureMAC() { // total length is redefined in firmware calcChecksum(udp); + + // force FPGA writes to be aligned and in order + volatile uint32_t *dst = (volatile uint32_t *)(Nios_getBaseAddress() + + addr / + (sizeof(u_int32_t))); + uint32_t words[sizeof(udp_header) / sizeof(uint32_t)]; + memcpy(words, udp, sizeof(udp_header)); + for (size_t i = 0; i != sizeof(words) / sizeof(words[0]); ++i) { + dst[i] = words[i]; + } + if (iRxEntry < numUdpDestinations) { LOG(logINFO, ("\tIP checksum : 0x%lx\n\n", udp->ip_checksum)); }