[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] problem on ETH_PAD_SIZE!!!
From: |
davide1984 |
Subject: |
Re: [lwip-users] problem on ETH_PAD_SIZE!!! |
Date: |
Wed, 29 May 2013 00:47:35 -0700 (PDT) |
任强 wrote
> Hi,all!
> I can get packets in low_level_input. But after passed to
> ethernetif_input, they are discarded due to wrong ethhdr->type. I found
> out the wrong ethhdr->type is 2 bytes ahead of its proper position. I
> guess it's because of ETH_PAD_SIZE( in lwipopts.h: #define ETH_PAD_SIZE 2
> ). I change it into 0, and ethhdr->type is right. But the packets I send
> are wrong at this time.
> This problem sticked me for a few days, so please give me some advice!
> Thanks!!
Hi Guys,
this post is old but I have exactly the same issue now.
I'm trying to make working lwip on an embedded system based on lm32
processor.
The system is already working now, but I have to increase the speed using
the emebedded DMA to read/write from the tx/rx fifo of the ethernet
interface with the phy.
Since those fifo are 4 bytes width, the payload address of tx/rx pbuf must
be aligned by 4, otherwise doesn't work.
The problem that i observe is this:
If I define ETH_PAD_SIZE=0 (with NO_SYS=1 and MEM_ALIGNMENT=4), the rx pbuf
allocated in the low_level_input function has the payload 4-byte aligned
(example: 0x...8) (correct). However, all pbufs that are used for
transmission are 2-bytes aligned (example: 0x...2) (not correct).
If I define ETH_PAD_SIZE=2, I observe that the rx pbuf allocated in the
low_level_input function has the payload 2-bytes aligned. This cause an
issue in the function ethernetif_input, that cannot recognize the
eth_hdr->type.
I had this problem on lwip 1.2.0, so I decided to do an "upgrade" to v1.4.1,
but the issue is the same.
My low_level_input function is:
static struct pbuf *
low_level_input(struct netif *netif)
{
/*struct ethernetif *ethernetif = netif->state;*/
struct pbuf *p, *q;
u16_t len;
int i;
unsigned int bytesToRead;
/* Obtain the size of the packet and put it into the "len"
variable. */
bytesToRead = len = tsmac_rx_pkt_size(TS_MAC_CORE_BASE_ADDRESS);
/* don't process further if there is no data to read */
if(bytesToRead == 0)
return(NULL);
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; //allow room for Ethernet padding
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) {
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
/* We iterate over the pbuf chain until we have read the entire
* packet into the pbuf. */
for(q = p; q != NULL; q = q->next) {
int size;
/* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len
* variable.
read data into(q->payload, q->len);*/
size = (bytesToRead > q->len)?q->len:bytesToRead;
bytesToRead-=size;
//Read the data from ethernet interface
tsmac_read(TS_MAC_CORE_BASE_ADDRESS,q->payload, size);
}
#if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
} else {
tsmac_drop_rx_packet(TS_MAC_CORE_BASE_ADDRESS, bytesToRead);
}
Any idea?
Thanks
--
View this message in context:
http://lwip.100.n7.nabble.com/problem-on-ETH-PAD-SIZE-tp6119p21478.html
Sent from the lwip-users mailing list archive at Nabble.com.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [lwip-users] problem on ETH_PAD_SIZE!!!,
davide1984 <=