Skip to content

Commit

Permalink
Add support for ethernet in imxrt1064-evk
Browse files Browse the repository at this point in the history
JIRA: RTOS-507
  • Loading branch information
Julian Uziemblo committed Aug 26, 2024
1 parent b1ab9f6 commit a582983
Show file tree
Hide file tree
Showing 16 changed files with 2,864 additions and 1,740 deletions.
2 changes: 1 addition & 1 deletion _targets/Makefile.armv7a7-imx6ull
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
NET_DRIVERS_SUPPORTED := enet tuntap
NET_DRIVERS ?= $(NET_DRIVERS_SUPPORTED)

DRIVERS_SRCS_enet = imx6-enet.c ephy.c gpio.c imx6ull-gpio.c $(DRIVERS_SRCS_UTIL) hw-debug.c
DRIVERS_SRCS_enet = enet.c ephy.c imx6ull-gpio.c $(DRIVERS_SRCS_UTIL) hw-debug.c
4 changes: 3 additions & 1 deletion _targets/Makefile.armv7m7-imxrt106x
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Copyright 2021 Phoenix Systems
#

NET_DRIVERS_SUPPORTED := pppou pppos
NET_DRIVERS_SUPPORTED := pppou pppos enet
NET_DRIVERS ?= $(NET_DRIVERS_SUPPORTED)
PPPOS_MODEM := huawei

DRIVERS_SRCS_enet = enet.c ephy.c imxrt106x-gpio.c $(DRIVERS_SRCS_UTIL)
3 changes: 3 additions & 0 deletions drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ endif
ifeq ($(EPHY_KSZ8081),RND)
LOCAL_CFLAGS := -DEPHY_KSZ8081RND
endif
ifeq ($(EPHY_KSZ8081),RNB)
LOCAL_CFLAGS := -DEPHY_KSZ8081RNB
endif

# make possible to specify defalult APN name externally
ifneq ($(PPPOS_DEFAULT_APN),)
Expand Down
27 changes: 17 additions & 10 deletions drivers/bdring.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ static int is_power_of_2(size_t n)
return !(n & (n - 1));
}


int net_initRings(net_bufdesc_ring_t *rings, const size_t *sizes, size_t nrings, const net_bufdesc_ops_t *ops)
{
size_t i, nb, sz, psz, align;
Expand All @@ -72,7 +71,8 @@ int net_initRings(net_bufdesc_ring_t *rings, const size_t *sizes, size_t nrings,
return -EINVAL;
}

bufp = calloc(nb, sizeof(*bufp));
bufp = calloc(nb, sizeof(*bufp)); // NOLINT

if (!bufp)
return -ENOMEM;

Expand Down Expand Up @@ -117,7 +117,6 @@ int net_initRings(net_bufdesc_ring_t *rings, const size_t *sizes, size_t nrings,
return 0;
}


size_t net_receivePackets(net_bufdesc_ring_t *ring, struct netif *ni, unsigned ethpad)
{
struct pbuf *p, *pkt;
Expand All @@ -132,10 +131,13 @@ size_t net_receivePackets(net_bufdesc_ring_t *ring, struct netif *ni, unsigned e
if (i == ring->tail)
break;


sz = ring->ops->nextRxBufferSize(ring, i);

if (!sz)
break;


p = ring->bufp[i];
p->tot_len = p->len = sz;

Expand All @@ -144,11 +146,13 @@ size_t net_receivePackets(net_bufdesc_ring_t *ring, struct netif *ni, unsigned e
else
pbuf_cat(pkt, p);


if (ring->ops->pktRxFinished(ring, i)) {
pbuf_header_force(p, ETH_PAD_SIZE - ethpad);
#ifdef LWIP_HOOK_ETH_INPUT
if (LWIP_HOOK_ETH_INPUT(p, ni))
if (LWIP_HOOK_ETH_INPUT(p, ni)) {
pbuf_free(p);
}
else
#endif
{
Expand All @@ -157,7 +161,7 @@ size_t net_receivePackets(net_bufdesc_ring_t *ring, struct netif *ni, unsigned e
pkt = NULL;
}

i = (i + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
i = (i + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
++n;
}

Expand All @@ -176,7 +180,7 @@ size_t net_refillRx(net_bufdesc_ring_t *ring, size_t ethpad)

n = 0;
i = ring->tail;
nxt = (i + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
nxt = (i + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
sz = ring->ops->pkt_buf_sz;

while (nxt != ring->head) {
Expand All @@ -190,12 +194,13 @@ size_t net_refillRx(net_bufdesc_ring_t *ring, size_t ethpad)
ring->ops->fillRxDesc(ring, i, pa, sz, 0);

i = nxt;
nxt = (nxt + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
nxt = (nxt + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
++n;
}

ring->tail = i;
mutexUnlock(ring->lock);

return n;
}

Expand All @@ -217,7 +222,7 @@ size_t net_reapTxFinished(net_bufdesc_ring_t *ring)
ring->bufp[i] = NULL;
}

i = (i + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
i = (i + 1) & ring->last; // NOTE: 2^n ring size verified in net_initRings
++n;
}

Expand Down Expand Up @@ -276,7 +281,7 @@ size_t net_transmitPacket(net_bufdesc_ring_t *ring, struct pbuf *p)

mutexLock(ring->lock);
// NOTE: 2^n ring size verified in net_initRings
n = atomic_load(&ring->tail); // access tail once - it may be advanced by tx_done thread
n = atomic_load(&ring->tail); // access tail once - it may be advanced by tx_done thread
i = ring->head;
n = (n - i - 1) & ring->last;
if (n > MAX_TX_FRAGMENTS)
Expand All @@ -286,12 +291,13 @@ size_t net_transmitPacket(net_bufdesc_ring_t *ring, struct pbuf *p)
if (!frags) {
pbuf_free(p);
mutexUnlock(ring->lock);
return 0; /* dropped: too many fragments or empty packet */
return 0; /* dropped: too many fragments or empty packet */
}

/* fill fragments from last to avoid race against HW */
i = ni = (i + n) & ring->last;
ring->bufp[i] = p;

last = BDRING_SEG_LAST;
while (n--) {
if (!n)
Expand All @@ -303,5 +309,6 @@ size_t net_transmitPacket(net_bufdesc_ring_t *ring, struct pbuf *p)

atomic_store(&ring->head, ni);
mutexUnlock(ring->lock);

return frags;
}
8 changes: 3 additions & 5 deletions drivers/bdring.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ enum {
};


typedef struct net_bufdesc_ops_
{
typedef struct net_bufdesc_ops_ {
size_t (*nextRxBufferSize)(const net_bufdesc_ring_t *ring, size_t i);
int (*pktRxFinished)(const net_bufdesc_ring_t *ring, size_t i);
void (*fillRxDesc)(const net_bufdesc_ring_t *ring, size_t i, addr_t pa, size_t sz, unsigned seg /* = zero */);
Expand All @@ -42,11 +41,10 @@ typedef struct net_bufdesc_ops_
} net_bufdesc_ops_t;


struct net_bufdesc_ring_
{
struct net_bufdesc_ring_ {
volatile void *ring;
struct pbuf **bufp;
volatile unsigned head, tail;
_Atomic volatile unsigned head, tail;
unsigned last;
addr_t phys;
const net_bufdesc_ops_t *ops;
Expand Down
Loading

0 comments on commit a582983

Please sign in to comment.