Skip to content

Commit 656d203

Browse files
authored
Merge pull request #2449 from qgyhd1234/checksum
[components][lwip]添加 LWIP 硬件校验和选项,修改 STM32 系列和 rt1052 系列以太网驱动,支持硬件校验和
2 parents 38ffaf8 + bb97c76 commit 656d203

File tree

6 files changed

+50
-33
lines changed

6 files changed

+50
-33
lines changed

bsp/imxrt/Libraries/imxrt1050/drivers/drv_eth.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ static void _enet_config(void)
666666
//config.interrupt = 0xFFFFFFFF;
667667
config.miiSpeed = imxrt_eth_device.speed;
668668
config.miiDuplex = imxrt_eth_device.duplex;
669+
#ifdef RT_LWIP_USING_HW_CHECKSUM
670+
config.rxAccelerConfig = ENET_RACC_PRODIS_MASK | ENET_RACC_IPDIS_MASK;
671+
config.txAccelerConfig = ENET_TACC_IPCHK_MASK | ENET_TACC_PROCHK_MASK;
672+
#endif
669673

670674
/* Set SMI to get PHY link status. */
671675
sysClock = CLOCK_GetFreq(kCLOCK_AhbClk);

bsp/stm32/libraries/HAL_Drivers/drv_eth.c

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ struct rt_stm32_eth
4444

4545
static ETH_DMADescTypeDef *DMARxDscrTab, *DMATxDscrTab;
4646
static rt_uint8_t *Rx_Buff, *Tx_Buff;
47-
static rt_bool_t tx_is_waiting = RT_FALSE;
4847
static ETH_HandleTypeDef EthHandle;
4948
static struct rt_stm32_eth stm32_eth_device;
50-
static struct rt_semaphore tx_wait;
5149

5250
#if defined(ETH_RX_DUMP) || defined(ETH_TX_DUMP)
5351
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
@@ -91,8 +89,12 @@ static rt_err_t rt_stm32_eth_init(rt_device_t dev)
9189
EthHandle.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
9290
EthHandle.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
9391
EthHandle.Init.RxMode = ETH_RXINTERRUPT_MODE;
92+
#ifdef RT_LWIP_USING_HW_CHECKSUM
93+
EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
94+
#else
9495
EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_SOFTWARE;
95-
96+
#endif
97+
9698
HAL_ETH_DeInit(&EthHandle);
9799

98100
/* configure ethernet peripheral (GPIOs, clocks, MAC, DMA) */
@@ -190,29 +192,13 @@ rt_err_t rt_stm32_eth_tx(rt_device_t dev, struct pbuf *p)
190192
DmaTxDesc = EthHandle.TxDesc;
191193
bufferoffset = 0;
192194

193-
/* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
194-
while ((DmaTxDesc->Status & ETH_DMATXDESC_OWN) != (uint32_t)RESET)
195-
{
196-
rt_err_t result;
197-
rt_uint32_t level;
198-
199-
level = rt_hw_interrupt_disable();
200-
tx_is_waiting = RT_TRUE;
201-
rt_hw_interrupt_enable(level);
202-
203-
/* it's own bit set, wait it */
204-
result = rt_sem_take(&tx_wait, RT_WAITING_FOREVER);
205-
if (result == RT_EOK) break;
206-
if (result == -RT_ERROR) return -RT_ERROR;
207-
}
208-
209195
/* copy frame from pbufs to driver buffers */
210196
for (q = p; q != NULL; q = q->next)
211197
{
212198
/* Is this buffer available? If not, goto error */
213199
if ((DmaTxDesc->Status & ETH_DMATXDESC_OWN) != (uint32_t)RESET)
214200
{
215-
LOG_E("buffer not valid");
201+
LOG_D("buffer not valid");
216202
ret = ERR_USE;
217203
goto error;
218204
}
@@ -391,15 +377,6 @@ void ETH_IRQHandler(void)
391377
rt_interrupt_leave();
392378
}
393379

394-
void HAL_ETH_TxCpltCallback(ETH_HandleTypeDef *heth)
395-
{
396-
if (tx_is_waiting == RT_TRUE)
397-
{
398-
tx_is_waiting = RT_FALSE;
399-
rt_sem_release(&tx_wait);
400-
}
401-
}
402-
403380
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
404381
{
405382
rt_err_t result;
@@ -635,10 +612,6 @@ static int rt_hw_stm32_eth_init(void)
635612
stm32_eth_device.parent.eth_rx = rt_stm32_eth_rx;
636613
stm32_eth_device.parent.eth_tx = rt_stm32_eth_tx;
637614

638-
/* init tx semaphore */
639-
rt_sem_init(&tx_wait, "tx_wait", 0, RT_IPC_FLAG_FIFO);
640-
LOG_D("initialize tx wait semaphore");
641-
642615
/* register eth device */
643616
state = eth_device_init(&(stm32_eth_device.parent), "e0");
644617
if (RT_EOK == state)

components/net/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ config RT_USING_LWIP
261261
bool "Enable lwIP statistics"
262262
default n
263263

264+
config RT_LWIP_USING_HW_CHECKSUM
265+
bool "Enable hardware checksum"
266+
default n
267+
264268
menuconfig RT_LWIP_DEBUG
265269
bool "Enable lwIP Debugging Options"
266270
default n

components/net/lwip-1.4.1/src/lwipopts.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@
374374
#define ARP_TABLE_SIZE 10
375375
#define ARP_QUEUEING 1
376376

377+
/* ---------- Checksum options ---------- */
378+
#ifdef RT_LWIP_USING_HW_CHECKSUM
379+
#define CHECKSUM_GEN_IP 0
380+
#define CHECKSUM_GEN_UDP 0
381+
#define CHECKSUM_GEN_TCP 0
382+
#define CHECKSUM_GEN_ICMP 0
383+
#define CHECKSUM_CHECK_IP 0
384+
#define CHECKSUM_CHECK_UDP 0
385+
#define CHECKSUM_CHECK_TCP 0
386+
#define CHECKSUM_CHECK_ICMP 0
387+
#endif
388+
377389
/* ---------- IP options ---------- */
378390
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
379391
IP packets across network interfaces. If you are going to run lwIP

components/net/lwip-2.0.2/src/lwipopts.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,18 @@
383383
#define ARP_TABLE_SIZE 10
384384
#define ARP_QUEUEING 1
385385

386+
/* ---------- Checksum options ---------- */
387+
#ifdef RT_LWIP_USING_HW_CHECKSUM
388+
#define CHECKSUM_GEN_IP 0
389+
#define CHECKSUM_GEN_UDP 0
390+
#define CHECKSUM_GEN_TCP 0
391+
#define CHECKSUM_GEN_ICMP 0
392+
#define CHECKSUM_CHECK_IP 0
393+
#define CHECKSUM_CHECK_UDP 0
394+
#define CHECKSUM_CHECK_TCP 0
395+
#define CHECKSUM_CHECK_ICMP 0
396+
#endif
397+
386398
/* ---------- IP options ---------- */
387399
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
388400
IP packets across network interfaces. If you are going to run lwIP

components/net/lwip-2.1.0/src/lwipopts.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,18 @@
390390
#define ARP_TABLE_SIZE 10
391391
#define ARP_QUEUEING 1
392392

393+
/* ---------- Checksum options ---------- */
394+
#ifdef RT_LWIP_USING_HW_CHECKSUM
395+
#define CHECKSUM_GEN_IP 0
396+
#define CHECKSUM_GEN_UDP 0
397+
#define CHECKSUM_GEN_TCP 0
398+
#define CHECKSUM_GEN_ICMP 0
399+
#define CHECKSUM_CHECK_IP 0
400+
#define CHECKSUM_CHECK_UDP 0
401+
#define CHECKSUM_CHECK_TCP 0
402+
#define CHECKSUM_CHECK_ICMP 0
403+
#endif
404+
393405
/* ---------- IP options ---------- */
394406
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
395407
IP packets across network interfaces. If you are going to run lwIP

0 commit comments

Comments
 (0)