summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/class/net/ncm.h50
-rw-r--r--src/class/net/ncm_device.c6
2 files changed, 31 insertions, 25 deletions
diff --git a/src/class/net/ncm.h b/src/class/net/ncm.h
index c768192a5..cf4daf96c 100644
--- a/src/class/net/ncm.h
+++ b/src/class/net/ncm.h
@@ -2,6 +2,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2021, Ha Thach (tinyusb.org)
+ * Copyright (c) 2024, Hardy Griech
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,42 +30,47 @@
#define _TUSB_NCM_H_
#include "common/tusb_common.h"
-
+#include "lwipopts.h"
#ifndef CFG_TUD_NCM_IN_NTB_MAX_SIZE
- /// must be >> MTU
- #define CFG_TUD_NCM_IN_NTB_MAX_SIZE 3200
+ #define CFG_TUD_NCM_IN_NTB_MAX_SIZE (2 * TCP_MSS + 100)
#endif
#ifndef CFG_TUD_NCM_OUT_NTB_MAX_SIZE
- /// must be >> MTU
- #define CFG_TUD_NCM_OUT_NTB_MAX_SIZE 3200
+ #define CFG_TUD_NCM_OUT_NTB_MAX_SIZE (2 * TCP_MSS + 100)
#endif
#ifndef CFG_TUD_NCM_OUT_NTB_N
- /// number of ntb buffers for reception side
- /// 1 - good performance
- /// 2 - up to 30% more performance with iperf with small packets
- /// >2 - no performance gain
- #define CFG_TUD_NCM_OUT_NTB_N 2
+ /// number of NTB buffers for reception side
+ /// 1 - good performance
+ /// 2 - up to 30% more performance with iperf with small packets
+ /// >2 - no performance gain
+ /// -> for performance optimizations this parameter could be increased with the cost of additional RAM requirements
+ #define CFG_TUD_NCM_OUT_NTB_N 1
#endif
#ifndef CFG_TUD_NCM_IN_NTB_N
- /// number of ntb buffers for transmission side
- /// 1 - good performance but SystemView shows lost events (on load test)
- /// 2 - up to 50% more performance with iperf with small packets, "tud_network_can_xmit: request blocked"
- /// happens from time to time with SystemView
- /// 3 - "tud_network_can_xmit: request blocked" never happens
- /// >2 - no performance gain
- #define CFG_TUD_NCM_IN_NTB_N 3
+ /// number of NTB buffers for transmission side
+ /// 1 - good performance but SystemView shows lost events (on load test)
+ /// 2 - up to 50% more performance with iperf with small packets, "tud_network_can_xmit: request blocked"
+ /// happens from time to time with SystemView
+ /// 3 - "tud_network_can_xmit: request blocked" never happens
+ /// >2 - no performance gain
+ /// -> for performance optimizations this parameter could be increased with the cost of additional RAM requirements
+ #define CFG_TUD_NCM_IN_NTB_N 1
+#endif
+
+#ifndef CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB
+ /// this is for the transmission side for allocation of \a ndp16_datagram_t
+ #define CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB 8
#endif
-#ifndef CFG_TUD_NCM_MAX_DATAGRAMS_PER_NTB
- /// this is for the transmission size for allocation of \a ndp16_datagram_t
- #define CFG_TUD_NCM_MAX_DATAGRAMS_PER_NTB 8
+#ifndef CFG_TUD_NCM_OUT_MAX_DATAGRAMS_PER_NTB
+ /// this tells the host how many datagrams it is allowed to put into an NTB
+ #define CFG_TUD_NCM_OUT_MAX_DATAGRAMS_PER_NTB 6
#endif
#ifndef CFG_TUD_NCM_ALIGNMENT
- #define CFG_TUD_NCM_ALIGNMENT 4
+ #define CFG_TUD_NCM_ALIGNMENT 4
#endif
#if (CFG_TUD_NCM_ALIGNMENT != 4)
#error "CFG_TUD_NCM_ALIGNMENT must be 4, otherwise the headers and start of datagrams have to be aligned (which they are currently not)"
@@ -136,7 +142,7 @@ typedef union TU_ATTR_PACKED {
struct {
nth16_t nth;
ndp16_t ndp;
- ndp16_datagram_t ndp_datagram[CFG_TUD_NCM_MAX_DATAGRAMS_PER_NTB + 1];
+ ndp16_datagram_t ndp_datagram[CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB + 1];
};
uint8_t data[CFG_TUD_NCM_IN_NTB_MAX_SIZE];
} xmit_ntb_t;
diff --git a/src/class/net/ncm_device.c b/src/class/net/ncm_device.c
index 829161865..40f70dc3f 100644
--- a/src/class/net/ncm_device.c
+++ b/src/class/net/ncm_device.c
@@ -1,8 +1,8 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2023 Hardy Griech
* Copyright (c) 2019 Ha Thach (tinyusb.org)
+ * Copyright (c) 2024 Hardy Griech
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -126,7 +126,7 @@ CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN tu_static const ntb_parameters_t ntb_par
.wNdbOutDivisor = 4,
.wNdbOutPayloadRemainder = 0,
.wNdbOutAlignment = CFG_TUD_NCM_ALIGNMENT,
- .wNtbOutMaxDatagrams = 6 // 0=no limit
+ .wNtbOutMaxDatagrams = CFG_TUD_NCM_OUT_MAX_DATAGRAMS_PER_NTB,
};
//-----------------------------------------------------------------------------
@@ -371,7 +371,7 @@ static bool xmit_requested_datagram_fits_into_current_ntb(uint16_t datagram_size
if (ncm_interface.xmit_glue_ntb == NULL) {
return false;
}
- if (ncm_interface.xmit_glue_ntb_datagram_ndx >= CFG_TUD_NCM_MAX_DATAGRAMS_PER_NTB) {
+ if (ncm_interface.xmit_glue_ntb_datagram_ndx >= CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB) {
return false;
}
if (ncm_interface.xmit_glue_ntb->nth.wBlockLength + datagram_size + XMIT_ALIGN_OFFSET(datagram_size) > CFG_TUD_NCM_OUT_NTB_MAX_SIZE) {