drivers/net: make sure that net driver d_buf is 16-bit aligned

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2022-08-04 19:47:53 +02:00 committed by Xiang Xiao
parent 93584f8668
commit b3cd9090d1
17 changed files with 237 additions and 223 deletions

View file

@ -284,7 +284,8 @@
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[CONFIG_C5471_NET_NINTERFACES]
[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* The c5471_driver_s encapsulates all state information for a single c5471
* hardware interface
@ -2389,7 +2390,7 @@ void arm_netinitialize(void)
memset(g_c5471, 0,
CONFIG_C5471_NET_NINTERFACES * sizeof(struct c5471_driver_s));
g_c5471[0].c_dev.d_buf = g_pktbuf; /* Single packet buffer */
g_c5471[0].c_dev.d_buf = g_pktbuf[0]; /* Single packet buffer */
g_c5471[0].c_dev.d_ifup = c5471_ifup; /* I/F down callback */
g_c5471[0].c_dev.d_ifdown = c5471_ifdown; /* I/F up (new IP address) callback */
g_c5471[0].c_dev.d_txavail = c5471_txavail; /* New TX data callback */

View file

@ -308,7 +308,7 @@ struct lpc17_40_driver_s
/* A single packet buffer per interface is used */
static uint8_t g_pktbuf[PKTBUF_SIZE * CONFIG_LPC17_40_NINTERFACES];
static uint8_t g_pktbuf[CONFIG_LPC17_40_NINTERFACES][PKTBUF_SIZE];
/* Array of ethernet driver status structures */
@ -3149,7 +3149,6 @@ static inline int lpc17_40_ethinitialize(int intf)
#endif
{
struct lpc17_40_driver_s *priv;
uint8_t *pktbuf;
uint32_t regval;
int ret;
int i;
@ -3172,14 +3171,10 @@ static inline int lpc17_40_ethinitialize(int intf)
lpc17_40_showpins();
/* Select the packet buffer */
pktbuf = &g_pktbuf[PKTBUF_SIZE * intf];
/* Initialize the driver structure */
memset(priv, 0, sizeof(struct lpc17_40_driver_s));
priv->lp_dev.d_buf = pktbuf; /* Single packet buffer */
priv->lp_dev.d_buf = g_pktbuf[intf]; /* Single packet buffer */
priv->lp_dev.d_ifup = lpc17_40_ifup; /* I/F down callback */
priv->lp_dev.d_ifdown = lpc17_40_ifdown; /* I/F up (new IP address) callback */
priv->lp_dev.d_txavail = lpc17_40_txavail; /* New TX data callback */

View file

@ -199,7 +199,8 @@ struct tiva_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[TIVA_NETHCONTROLLERS]
[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Ethernet peripheral state */
@ -1605,20 +1606,20 @@ static inline int tiva_ethinitialize(int intf)
/* Initialize the driver structure */
memset(priv, 0, sizeof(struct tiva_driver_s));
priv->ld_dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->ld_dev.d_ifup = tiva_ifup; /* I/F down callback */
priv->ld_dev.d_ifdown = tiva_ifdown; /* I/F up (new IP address) callback */
priv->ld_dev.d_txavail = tiva_txavail; /* New TX data callback */
priv->ld_dev.d_buf = g_pktbuf[intf]; /* Single packet buffer */
priv->ld_dev.d_ifup = tiva_ifup; /* I/F down callback */
priv->ld_dev.d_ifdown = tiva_ifdown; /* I/F up (new IP address) callback */
priv->ld_dev.d_txavail = tiva_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
priv->ld_dev.d_addmac = tiva_addmac; /* Add multicast MAC address */
priv->ld_dev.d_rmmac = tiva_rmmac; /* Remove multicast MAC address */
priv->ld_dev.d_addmac = tiva_addmac; /* Add multicast MAC address */
priv->ld_dev.d_rmmac = tiva_rmmac; /* Remove multicast MAC address */
#endif
priv->ld_dev.d_private = priv; /* Used to recover private state from dev */
priv->ld_dev.d_private = priv; /* Used to recover private state from dev */
#if TIVA_NETHCONTROLLERS > 1
# error "A mechanism to associate base address an IRQ with an interface is needed"
priv->ld_base = ??; /* Ethernet controller base address */
priv->ld_irq = ??; /* Ethernet controller IRQ number */
priv->ld_base = ??; /* Ethernet controller base address */
priv->ld_irq = ??; /* Ethernet controller IRQ number */
#endif
#ifdef CONFIG_TIVA_BOARDMAC

View file

@ -89,7 +89,8 @@ struct emac_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[CONFIG_HCS12_NINTERFACES]
[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Driver state structure */
@ -693,7 +694,7 @@ int emac_initialize(int intf)
/* Get the interface structure associated with this interface number. */
DEBUGASSERT(inf < CONFIG_HCS12_NINTERFACES);
DEBUGASSERT(inf < CONFIG_HCS12_NINTERFACES);
priv = &g_emac[intf];
/* Check if a Ethernet chip is recognized at its I/O base */
@ -710,7 +711,7 @@ int emac_initialize(int intf)
/* Initialize the driver structure */
memset(priv, 0, sizeof(struct emac_driver_s));
priv->d_dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->d_dev.d_buf = g_pktbuf[inf]; /* Single packet buffer */
priv->d_dev.d_ifup = emac_ifup; /* I/F down callback */
priv->d_dev.d_ifdown = emac_ifdown; /* I/F up (new IP address) callback */
priv->d_dev.d_txavail = emac_txavail; /* New TX data callback */

View file

@ -116,7 +116,8 @@ struct misoc_net_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[CONFIG_MISOC_NET_NINTERFACES]
[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Driver state structure */
@ -1092,7 +1093,7 @@ int misoc_net_initialize(int intf)
priv->tx_buf = priv->tx0_buf;
priv->tx_slot = 0;
priv->misoc_net_dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->misoc_net_dev.d_buf = g_pktbuf[intf]; /* Single packet buffer */
priv->misoc_net_dev.d_ifup = misoc_net_ifup; /* I/F up (new IP address) callback */
priv->misoc_net_dev.d_ifdown = misoc_net_ifdown; /* I/F down callback */
priv->misoc_net_dev.d_txavail = misoc_net_txavail; /* New TX data callback */

View file

@ -210,7 +210,8 @@ struct gmac_txdesc_s
#endif
};
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[MPFS_NETHERNET]
[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
#if defined(CONFIG_MPFS_GMAC_PREALLOCATE)
static uint8_t g_txbuffer[CONFIG_MPFS_ETHMAC_NTXBUFFERS * GMAC_TX_UNITSIZE]
@ -3554,7 +3555,7 @@ int mpfs_ethinitialize(int intf)
/* Initialize the driver structure */
memset(priv, 0, sizeof(struct mpfs_ethmac_s));
priv->dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->dev.d_buf = g_pktbuf[intf]; /* Single packet buffer */
priv->dev.d_ifup = mpfs_ifup; /* I/F up (new IP address) callback */
priv->dev.d_ifdown = mpfs_ifdown; /* I/F down callback */
priv->dev.d_txavail = mpfs_txavail; /* New TX data callback */

View file

@ -378,17 +378,17 @@ static int ez80emac_miiconfigure(FAR struct ez80emac_driver_s *priv);
/* Multi-cast filtering */
#ifdef CONFIG_EZ80_MCFILTER
static void ez80emac_machash(FAR uint8_t *mac, int *ndx, int *bitno)
static void ez80emac_machash(FAR uint8_t *mac, FAR int *ndx, FAR int *bitno);
#endif
/* TX/RX logic */
static int ez80emac_transmit(struct ez80emac_driver_s *priv);
static int ez80emac_txpoll(struct net_driver_s *dev);
static int ez80emac_transmit(FAR struct ez80emac_driver_s *priv);
static int ez80emac_txpoll(FAR struct net_driver_s *dev);
static inline FAR struct ez80emac_desc_s *ez80emac_rwp(void);
static inline FAR struct ez80emac_desc_s *ez80emac_rrp(void);
static int ez80emac_receive(struct ez80emac_driver_s *priv);
static int ez80emac_receive(FAR struct ez80emac_driver_s *priv);
/* Interrupt handling */
@ -411,16 +411,16 @@ static void ez80emac_txtimeout_expiry(wdparm_t arg);
/* NuttX callback functions */
static int ez80emac_ifup(struct net_driver_s *dev);
static int ez80emac_ifdown(struct net_driver_s *dev);
static int ez80emac_ifup(FAR struct net_driver_s *dev);
static int ez80emac_ifdown(FAR struct net_driver_s *dev);
static void ez80emac_txavail_work(FAR void *arg);
static int ez80emac_txavail(struct net_driver_s *dev);
static int ez80emac_txavail(FAR struct net_driver_s *dev);
#ifdef CONFIG_NET_MCASTGROUP
static int ez80emac_addmac(struct net_driver_s *dev,
static int ez80emac_addmac(FAR struct net_driver_s *dev,
FAR const uint8_t *mac);
static int ez80emac_rmmac(struct net_driver_s *dev,
static int ez80emac_rmmac(FAR struct net_driver_s *dev,
FAR const uint8_t *mac);
#endif
@ -944,7 +944,7 @@ static int ez80emac_miiconfigure(FAR struct ez80emac_driver_s *priv)
****************************************************************************/
#ifdef CONFIG_EZ80_MCFILTER
static void ez80emac_machash(FAR uint8_t *mac, int *ndx, int *bitno)
static void ez80emac_machash(FAR uint8_t *mac, FAR int *ndx, FAR int *bitno)
{
uint32_t hash;
uint32_t crc32;
@ -1021,14 +1021,14 @@ static void ez80emac_machash(FAR uint8_t *mac, int *ndx, int *bitno)
*
****************************************************************************/
static int ez80emac_transmit(struct ez80emac_driver_s *priv)
static int ez80emac_transmit(FAR struct ez80emac_driver_s *priv)
{
FAR struct ez80emac_desc_s *txdesc;
FAR struct ez80emac_desc_s *txnext;
uint8_t *psrc;
uint8_t *pdest;
uint24_t len;
irqstate_t flags;
FAR uint8_t *psrc;
FAR uint8_t *pdest;
uint24_t len;
irqstate_t flags;
/* Careful: This function can be called from outside of the interrupt
* handler and, therefore, may be suspended when debug output is generated!
@ -1057,11 +1057,11 @@ static int ez80emac_transmit(struct ez80emac_driver_s *priv)
txdesc = priv->txnext;
len = EMAC_PKTBUF_ALIGN(priv->dev.d_len + SIZEOF_EMACSDESC);
txnext = (FAR struct ez80emac_desc_s *)((uint8_t *)txdesc + len);
txnext = (FAR struct ez80emac_desc_s *)((FAR uint8_t *)txdesc + len);
/* Handle wraparound to the beginning of the TX region */
if ((uint8_t *)txnext + SIZEOF_EMACSDESC >= (uint8_t *)priv->rxstart)
if ((uint8_t *)txnext + SIZEOF_EMACSDESC >= (FAR uint8_t *)priv->rxstart)
{
txnext = (FAR struct ez80emac_desc_s *)
((FAR uint8_t *)priv->txstart +
@ -1078,8 +1078,8 @@ static int ez80emac_transmit(struct ez80emac_driver_s *priv)
*/
psrc = priv->dev.d_buf;
pdest = (uint8_t *)txdesc + SIZEOF_EMACSDESC;
len = (uint8_t *)priv->rxstart - pdest;
pdest = (FAR uint8_t *)txdesc + SIZEOF_EMACSDESC;
len = (FAR uint8_t *)priv->rxstart - pdest;
if (len >= priv->dev.d_len)
{
/* The entire packet will fit into the EMAC SRAM without wrapping */
@ -1264,15 +1264,15 @@ static inline FAR struct ez80emac_desc_s *ez80emac_rrp(void)
*
****************************************************************************/
static int ez80emac_receive(struct ez80emac_driver_s *priv)
static int ez80emac_receive(FAR struct ez80emac_driver_s *priv)
{
FAR struct ez80emac_desc_s *rxdesc = priv->rxnext;
FAR struct ez80emac_desc_s *rwp;
uint8_t *psrc;
uint8_t *pdest;
int pktlen;
int npackets;
uint8_t pktgood;
FAR uint8_t *psrc;
FAR uint8_t *pdest;
int pktlen;
int npackets;
uint8_t pktgood;
/* The RRP register points to where the next Receive packet is read from.
* The read-only EMAC Receive Write Pointer (RWP) register reports the
@ -2080,7 +2080,7 @@ static int ez80emac_ifup(FAR struct net_driver_s *dev)
*
****************************************************************************/
static int ez80emac_ifdown(struct net_driver_s *dev)
static int ez80emac_ifdown(FAR struct net_driver_s *dev)
{
FAR struct ez80emac_driver_s *priv =
(FAR struct ez80emac_driver_s *)dev->d_private;
@ -2205,7 +2205,8 @@ static int ez80emac_txavail(FAR struct net_driver_s *dev)
****************************************************************************/
#ifdef CONFIG_NET_MCASTGROUP
static int ez80emac_addmac(struct net_driver_s *dev, FAR const uint8_t *mac)
static int ez80emac_addmac(FAR struct net_driver_s *dev,
FAR const uint8_t *mac)
{
FAR struct ez80emac_driver_s *priv =
(FAR struct ez80emac_driver_s *)dev->d_private;
@ -2237,7 +2238,8 @@ static int ez80emac_addmac(struct net_driver_s *dev, FAR const uint8_t *mac)
****************************************************************************/
#ifdef CONFIG_NET_MCASTGROUP
static int ez80emac_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac)
static int ez80emac_rmmac(FAR struct net_driver_s *dev,
FAR const uint8_t *mac)
{
FAR struct ez80emac_driver_s *priv =
(FAR struct ez80emac_driver_s *)dev->d_private;
@ -2266,7 +2268,7 @@ static int ez80emac_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac)
static int ez80_emacinitialize(void)
{
struct ez80emac_driver_s *priv = &g_emac;
FAR struct ez80emac_driver_s *priv = &g_emac;
uint24_t addr;
uint8_t regval;
int ret;
@ -2494,7 +2496,7 @@ errout:
int up_netinitialize(void)
{
struct ez80emac_driver_s *priv = &g_emac;
FAR struct ez80emac_driver_s *priv = &g_emac;
int ret;
/* Disable all interrupts */

View file

@ -260,7 +260,7 @@ menuconfig ENCX24J600
if ENCX24J600
config ENC28J60_NINTERFACES
config ENCX24J600_NINTERFACES
int "Number of physical ENCX24J600"
default 1
range 1 1

View file

@ -273,6 +273,10 @@
#define DM6X_TXTIMEOUT (60*CLK_TCK)
/* Packet buffer size */
#define PKTBUF_SIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE)
/* This is a helper pointer for accessing the contents of Ethernet header */
#define BUF ((FAR struct eth_hdr_s *)priv->dm_dev.d_buf)
@ -323,7 +327,7 @@ struct dm9x_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint16_t g_pktbuf[CONFIG_DM9X_NINTERFACES][(PKTBUF_SIZE + 1) / 2];
/* At present, only a single DM90x0 device is supported. */
@ -1866,15 +1870,15 @@ int dm9x_initialize(void)
/* Initialize the driver structure */
memset(g_dm9x, 0, CONFIG_DM9X_NINTERFACES*sizeof(struct dm9x_driver_s));
g_dm9x[0].dm_dev.d_buf = g_pktbuf; /* Single packet buffer */
g_dm9x[0].dm_dev.d_ifup = dm9x_ifup; /* I/F down callback */
g_dm9x[0].dm_dev.d_ifdown = dm9x_ifdown; /* I/F up (new IP address) callback */
g_dm9x[0].dm_dev.d_txavail = dm9x_txavail; /* New TX data callback */
g_dm9x[0].dm_dev.d_buf = (FAR uint8_t *)g_pktbuf[0]; /* Single packet buffer */
g_dm9x[0].dm_dev.d_ifup = dm9x_ifup; /* I/F down callback */
g_dm9x[0].dm_dev.d_ifdown = dm9x_ifdown; /* I/F up (new IP address) callback */
g_dm9x[0].dm_dev.d_txavail = dm9x_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
g_dm9x[0].dm_dev.d_addmac = dm9x_addmac; /* Add multicast MAC address */
g_dm9x[0].dm_dev.d_rmmac = dm9x_rmmac; /* Remove multicast MAC address */
g_dm9x[0].dm_dev.d_addmac = dm9x_addmac; /* Add multicast MAC address */
g_dm9x[0].dm_dev.d_rmmac = dm9x_rmmac; /* Remove multicast MAC address */
#endif
g_dm9x[0].dm_dev.d_private = g_dm9x; /* Used to recover private state from dev */
g_dm9x[0].dm_dev.d_private = g_dm9x; /* Used to recover private state from dev */
/* Read the MAC address */

View file

@ -175,6 +175,10 @@
#define enc_bfsgreg(priv,ctrlreg,setbits) \
enc_wrgreg2(priv, ENC_BFS | GETADDR(ctrlreg), setbits)
/* Packet buffer size */
#define PKTBUF_SIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE)
/* This is a helper pointer for accessing the contents of Ethernet header */
#define BUF ((FAR struct eth_hdr_s *)priv->dev.d_buf)
@ -250,7 +254,7 @@ struct enc_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint16_t g_pktbuf[CONFIG_ENC28J60_NINTERFACES][(PKTBUF_SIZE + 1) / 2];
/* Driver status structure */
@ -2528,17 +2532,17 @@ int enc_initialize(FAR struct spi_dev_s *spi,
memset(g_enc28j60, 0,
CONFIG_ENC28J60_NINTERFACES * sizeof(struct enc_driver_s));
priv->dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->dev.d_ifup = enc_ifup; /* I/F down callback */
priv->dev.d_ifdown = enc_ifdown; /* I/F up (new IP address) callback */
priv->dev.d_txavail = enc_txavail; /* New TX data callback */
priv->dev.d_buf = (FAR uint8_t *)g_pktbuf[devno]; /* Single packet buffer */
priv->dev.d_ifup = enc_ifup; /* I/F down callback */
priv->dev.d_ifdown = enc_ifdown; /* I/F up (new IP address) callback */
priv->dev.d_txavail = enc_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
priv->dev.d_addmac = enc_addmac; /* Add multicast MAC address */
priv->dev.d_rmmac = enc_rmmac; /* Remove multicast MAC address */
priv->dev.d_addmac = enc_addmac; /* Add multicast MAC address */
priv->dev.d_rmmac = enc_rmmac; /* Remove multicast MAC address */
#endif
priv->dev.d_private = priv; /* Used to recover private state from dev */
priv->spi = spi; /* Save the SPI instance */
priv->lower = lower; /* Save the low-level MCU interface */
priv->dev.d_private = priv; /* Used to recover private state from dev */
priv->spi = spi; /* Save the SPI instance */
priv->lower = lower; /* Save the low-level MCU interface */
/* The interface should be in the down state. However, this function is
* called too early in initialization to perform the ENC28J60 reset in

View file

@ -158,6 +158,10 @@
#define ENC_NTXDESCR ((PKTMEM_RX_START - PKTMEM_START) / PKTMEM_ALIGNED_BUFSIZE)
/* Packet buffer size */
#define PKTBUF_SIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE)
/* This is a helper pointer for accessing the contents of Ethernet header */
#define BUF ((FAR struct eth_hdr_s *)priv->dev.d_buf)
@ -253,7 +257,8 @@ struct enc_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint16_t g_pktbuf[CONFIG_ENCX24J600_NINTERFACES]
[(PKTBUF_SIZE + 1) / 2];
/* Driver status structure */
@ -2711,17 +2716,17 @@ int enc_initialize(FAR struct spi_dev_s *spi,
memset(g_encx24j600, 0,
CONFIG_ENCX24J600_NINTERFACES * sizeof(struct enc_driver_s));
priv->dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->dev.d_ifup = enc_ifup; /* I/F up (new IP address) callback */
priv->dev.d_ifdown = enc_ifdown; /* I/F down callback */
priv->dev.d_txavail = enc_txavail; /* New TX data callback */
priv->dev.d_buf = (FAR uint8_t *)g_pktbuf[devno]; /* Single packet buffer */
priv->dev.d_ifup = enc_ifup; /* I/F up (new IP address) callback */
priv->dev.d_ifdown = enc_ifdown; /* I/F down callback */
priv->dev.d_txavail = enc_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
priv->dev.d_addmac = enc_addmac; /* Add multicast MAC address */
priv->dev.d_rmmac = enc_rmmac; /* Remove multicast MAC address */
priv->dev.d_addmac = enc_addmac; /* Add multicast MAC address */
priv->dev.d_rmmac = enc_rmmac; /* Remove multicast MAC address */
#endif
priv->dev.d_private = priv; /* Used to recover private state from dev */
priv->spi = spi; /* Save the SPI instance */
priv->lower = lower; /* Save the low-level MCU interface */
priv->dev.d_private = priv; /* Used to recover private state from dev */
priv->spi = spi; /* Save the SPI instance */
priv->lower = lower; /* Save the low-level MCU interface */
/* The interface should be in the down state. However, this function is
* called too early in initialization to perform the ENCX24J600 reset in

View file

@ -85,6 +85,10 @@
#define FTMAC100_TXTIMEOUT (60*CLK_TCK)
/* Packet buffer size */
#define PKTBUF_SIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE)
/* This is a helper pointer for accessing the contents of the Ethernet
* header.
*/
@ -171,7 +175,8 @@ struct ftmac100_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint16_t g_pktbuf[CONFIG_FTMAC100_NINTERFACES]
[(PKTBUF_SIZE + 1) / 2];
/* Driver state structure. */
@ -1488,15 +1493,15 @@ int ftmac100_initialize(int intf)
/* Initialize the driver structure */
memset(priv, 0, sizeof(struct ftmac100_driver_s));
priv->ft_dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->ft_dev.d_ifup = ftmac100_ifup; /* I/F up (new IP address) callback */
priv->ft_dev.d_ifdown = ftmac100_ifdown; /* I/F down callback */
priv->ft_dev.d_txavail = ftmac100_txavail; /* New TX data callback */
priv->ft_dev.d_buf = (FAR uint8_t *)g_pktbuf[intf]; /* Single packet buffer */
priv->ft_dev.d_ifup = ftmac100_ifup; /* I/F up (new IP address) callback */
priv->ft_dev.d_ifdown = ftmac100_ifdown; /* I/F down callback */
priv->ft_dev.d_txavail = ftmac100_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
priv->ft_dev.d_addmac = ftmac100_addmac; /* Add multicast MAC address */
priv->ft_dev.d_rmmac = ftmac100_rmmac; /* Remove multicast MAC address */
priv->ft_dev.d_addmac = ftmac100_addmac; /* Add multicast MAC address */
priv->ft_dev.d_rmmac = ftmac100_rmmac; /* Remove multicast MAC address */
#endif
priv->ft_dev.d_private = g_ftmac100; /* Used to recover private state from dev */
priv->ft_dev.d_private = g_ftmac100; /* Used to recover private state from dev */
priv->iobase = CONFIG_FTMAC100_BASE;
/* Put the interface in the down state. This usually amounts to resetting

View file

@ -81,12 +81,12 @@
struct lan91c111_driver_s
{
uintptr_t base; /* Base address */
int irq; /* IRQ number */
uint16_t bank; /* Current bank */
struct work_s irqwork; /* For deferring interrupt work to the work queue */
struct work_s pollwork; /* For deferring poll work to the work queue */
uint8_t pktbuf[MAX_NETDEV_PKTSIZE + 4]; /* +4 due to getregs32/putregs32 */
uintptr_t base; /* Base address */
int irq; /* IRQ number */
struct work_s irqwork; /* For deferring interrupt work to the work queue */
struct work_s pollwork; /* For deferring poll work to the work queue */
uint16_t bank; /* Current bank */
uint16_t pktbuf[(MAX_NETDEV_PKTSIZE + 4 + 1) / 2]; /* +4 due to getregs32/putregs32 */
/* This holds the information visible to the NuttX network */
@ -1493,18 +1493,18 @@ int lan91c111_initialize(uintptr_t base, int irq)
/* Initialize the driver structure */
dev->d_buf = priv->pktbuf; /* Single packet buffer */
dev->d_ifup = lan91c111_ifup; /* I/F up (new IP address) callback */
dev->d_ifdown = lan91c111_ifdown; /* I/F down callback */
dev->d_txavail = lan91c111_txavail; /* New TX data callback */
dev->d_buf = (FAR uint8_t *)priv->pktbuf; /* Single packet buffer */
dev->d_ifup = lan91c111_ifup; /* I/F up (new IP address) callback */
dev->d_ifdown = lan91c111_ifdown; /* I/F down callback */
dev->d_txavail = lan91c111_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
dev->d_addmac = lan91c111_addmac; /* Add multicast MAC address */
dev->d_rmmac = lan91c111_rmmac; /* Remove multicast MAC address */
dev->d_addmac = lan91c111_addmac; /* Add multicast MAC address */
dev->d_rmmac = lan91c111_rmmac; /* Remove multicast MAC address */
#endif
#ifdef CONFIG_NETDEV_IOCTL
dev->d_ioctl = lan91c111_ioctl; /* Handle network IOCTL commands */
dev->d_ioctl = lan91c111_ioctl; /* Handle network IOCTL commands */
#endif
dev->d_private = priv; /* Used to recover private state from dev */
dev->d_private = priv; /* Used to recover private state from dev */
/* Put the interface in the down state. This usually amounts to resetting
* the device and/or calling lan91c111_ifdown().

View file

@ -80,6 +80,10 @@
#define SKELETON_TXTIMEOUT (60*CLK_TCK)
/* Packet buffer size */
#define PKTBUF_SIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE)
/* This is a helper pointer for accessing the contents of Ethernet header */
#define BUF ((FAR struct eth_hdr_s *)priv->sk_dev.d_buf)
@ -124,7 +128,7 @@ struct skel_driver_s
* allocated dynamically in cases where more than one are needed.
*/
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint16_t g_pktbuf[CONFIG_SKELETON_NINTERFACES][(PKTBUF_SIZE + 1) / 2];
/* Driver state structure */
@ -1070,18 +1074,18 @@ int skel_initialize(int intf)
/* Initialize the driver structure */
memset(priv, 0, sizeof(struct skel_driver_s));
priv->sk_dev.d_buf = g_pktbuf; /* Single packet buffer */
priv->sk_dev.d_ifup = skel_ifup; /* I/F up (new IP address) callback */
priv->sk_dev.d_ifdown = skel_ifdown; /* I/F down callback */
priv->sk_dev.d_txavail = skel_txavail; /* New TX data callback */
priv->sk_dev.d_buf = (FAR uint8_t *)g_pktbuf[intf]; /* Single packet buffer */
priv->sk_dev.d_ifup = skel_ifup; /* I/F up (new IP address) callback */
priv->sk_dev.d_ifdown = skel_ifdown; /* I/F down callback */
priv->sk_dev.d_txavail = skel_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
priv->sk_dev.d_addmac = skel_addmac; /* Add multicast MAC address */
priv->sk_dev.d_rmmac = skel_rmmac; /* Remove multicast MAC address */
priv->sk_dev.d_addmac = skel_addmac; /* Add multicast MAC address */
priv->sk_dev.d_rmmac = skel_rmmac; /* Remove multicast MAC address */
#endif
#ifdef CONFIG_NETDEV_IOCTL
priv->sk_dev.d_ioctl = skel_ioctl; /* Handle network IOCTL commands */
priv->sk_dev.d_ioctl = skel_ioctl; /* Handle network IOCTL commands */
#endif
priv->sk_dev.d_private = g_skel; /* Used to recover private state from dev */
priv->sk_dev.d_private = g_skel; /* Used to recover private state from dev */
/* Put the interface in the down state. This usually amounts to resetting
* the device and/or calling skel_ifdown().

View file

@ -80,7 +80,7 @@
*/
#ifndef CONFIG_NET_W5500_NINTERFACES
# define CONFIG_NET_W5500_NINTERFACES 1
# define CONFIG_NET_W5500_NINTERFACES 1
#endif
/* TX timeout = 1 minute
@ -89,9 +89,13 @@
#define W5500_TXTIMEOUT (60 * CLK_TCK)
/* Packet buffer size */
#define PKTBUF_SIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE)
/* This is a helper pointer for accessing the contents of Ethernet header */
#define ETH_HDR ((FAR struct eth_hdr_s *)self->sk_dev.d_buf)
#define BUF ((FAR struct eth_hdr_s *)self->w_dev.d_buf)
/* Number of Ethernet frame transmission buffers maintained in W5500's 16 KiB
* Tx RAM. A maximum size is conservatively assumed per Ethernet frame in
@ -357,10 +361,10 @@
struct w5500_driver_s
{
bool sk_bifup; /* true:ifup false:ifdown */
struct wdog_s sk_txtimeout; /* TX timeout timer */
struct work_s sk_irqwork; /* For deferring interrupt work to the work queue */
struct work_s sk_pollwork; /* For deferring poll work to the work queue */
bool w_bifup; /* true:ifup false:ifdown */
struct wdog_s w_txtimeout; /* TX timeout timer */
struct work_s w_irqwork; /* For deferring interrupt work to the work queue */
struct work_s w_pollwork; /* For deferring poll work to the work queue */
/* Ethernet frame transmission buffer management */
@ -375,30 +379,17 @@ struct w5500_driver_s
/* This holds the information visible to the NuttX network */
struct net_driver_s sk_dev; /* Interface understood by the network */
struct net_driver_s w_dev; /* Interface understood by the network */
};
/****************************************************************************
* Private Data
****************************************************************************/
/* These statically allocated structures would mean that only a single
* instance of the device could be supported. In order to support multiple
* devices instances, this data would have to be allocated dynamically.
*/
/* A single packet buffer is used */
/* A single packet buffer per device is used in this example. There might
* be multiple packet buffers in a more complex, pipelined design. Many
* contemporary Ethernet interfaces, for example, use multiple, linked DMA
* descriptors in rings to implement such a pipeline. This example assumes
* much simpler hardware that simply handles one packet at a time.
*
* NOTE that if CONFIG_NET_W5500_NINTERFACES were greater than 1, you would
* need a minimum on one packet buffer per instance. Much better to be
* allocated dynamically in cases where more than one are needed.
*/
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
static uint16_t g_pktbuf[CONFIG_NET_W5500_NINTERFACES]
[(PKTBUF_SIZE + 1) / 2];
/* Driver state structure */
@ -415,7 +406,7 @@ static int w5500_txpoll(FAR struct net_driver_s *dev);
/* Interrupt handling */
static void w5500_reply(struct w5500_driver_s *priv);
static void w5500_reply(FAR struct w5500_driver_s *priv);
static void w5500_receive(FAR struct w5500_driver_s *priv);
static void w5500_txdone(FAR struct w5500_driver_s *priv);
@ -554,7 +545,7 @@ static void w5500_unlock(FAR struct w5500_driver_s *self)
static void w5500_read(FAR struct w5500_driver_s *self,
uint8_t block_select_bits,
uint16_t offset,
void *buffer,
FAR void *buffer,
uint16_t len)
{
uint8_t addr_cntl[3];
@ -588,7 +579,7 @@ static void w5500_read(FAR struct w5500_driver_s *self,
static void w5500_write(FAR struct w5500_driver_s *self,
uint8_t block_select_bits,
off_t offset,
const void *data,
FAR const void *data,
size_t len)
{
uint8_t addr_cntl[3];
@ -862,11 +853,11 @@ static uint16_t w5500_txbuf_copy(FAR struct w5500_driver_s *self)
w5500_write(self,
W5500_BSB_SOCKET_TX_BUFFER(0),
offset,
self->sk_dev.d_buf,
self->sk_dev.d_len);
self->w_dev.d_buf,
self->w_dev.d_len);
self->txbuf_wrptr = (self->txbuf_wrptr + 1) % (NUM_TXBUFS + 1);
self->txbuf_offset[self->txbuf_wrptr] = offset + self->sk_dev.d_len;
self->txbuf_offset[self->txbuf_wrptr] = offset + self->w_dev.d_len;
return self->txbuf_offset[self->txbuf_wrptr];
}
@ -920,7 +911,7 @@ static bool w5500_txbuf_next(FAR struct w5500_driver_s *self)
/* (Re-)start the TX timeout watchdog timer */
wd_start(&self->sk_txtimeout,
wd_start(&self->w_txtimeout,
W5500_TXTIMEOUT,
w5500_txtimeout_expiry,
(wdparm_t)self);
@ -943,7 +934,7 @@ static void w5500_fence(FAR struct w5500_driver_s *self)
{
self->lower->enable(self->lower, false);
w5500_reset(self, true); /* Reset and keep reset asserted */
self->sk_bifup = false;
self->w_bifup = false;
}
/****************************************************************************
@ -976,8 +967,8 @@ static int w5500_unfence(FAR struct w5500_driver_s *self)
w5500_write(self,
W5500_BSB_COMMON_REGS,
W5500_SHAR0, /* Source Hardware Address Register */
self->sk_dev.d_mac.ether.ether_addr_octet,
sizeof(self->sk_dev.d_mac.ether.ether_addr_octet));
self->w_dev.d_mac.ether.ether_addr_octet,
sizeof(self->w_dev.d_mac.ether.ether_addr_octet));
/* Configure socket 0 for raw MAC access with MAC filtering enabled. */
@ -1116,13 +1107,13 @@ static void w5500_transmit(FAR struct w5500_driver_s *self)
if (!w5500_txbuf_numfree(self))
{
ninfo("Dropping Tx packet due to no buffer available.\n");
NETDEV_TXERRORS(self->sk_dev);
NETDEV_TXERRORS(self->w_dev);
return;
}
/* Increment statistics */
NETDEV_TXPACKETS(self->sk_dev);
NETDEV_TXPACKETS(self->w_dev);
/* Copy packet data to TX buffer */
@ -1158,12 +1149,12 @@ static void w5500_transmit(FAR struct w5500_driver_s *self)
/* Setup the TX timeout watchdog (perhaps restarting the timer) */
wd_start(&self->sk_txtimeout, W5500_TXTIMEOUT,
wd_start(&self->w_txtimeout, W5500_TXTIMEOUT,
w5500_txtimeout_expiry, (wdparm_t)self);
}
#ifdef CONFIG_DEBUG_NET_INFO
ninfodumpbuffer("Transmitted:", self->sk_dev.d_buf, self->sk_dev.d_len);
ninfodumpbuffer("Transmitted:", self->w_dev.d_buf, self->w_dev.d_len);
#endif
}
@ -1199,23 +1190,23 @@ static int w5500_txpoll(FAR struct net_driver_s *dev)
* the field d_len is set to a value > 0.
*/
if (self->sk_dev.d_len > 0)
if (self->w_dev.d_len > 0)
{
/* Look up the destination MAC address and add it to the Ethernet
* header.
*/
#ifdef CONFIG_NET_IPv4
if (IFF_IS_IPv4(self->sk_dev.d_flags))
if (IFF_IS_IPv4(self->w_dev.d_flags))
{
arp_out(&self->sk_dev);
arp_out(&self->w_dev);
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
if (IFF_IS_IPv6(self->sk_dev.d_flags))
if (IFF_IS_IPv6(self->w_dev.d_flags))
{
neighbor_out(&self->sk_dev);
neighbor_out(&self->w_dev);
}
#endif /* CONFIG_NET_IPv6 */
@ -1224,7 +1215,7 @@ static int w5500_txpoll(FAR struct net_driver_s *dev)
* don't attempt to put it on the wire.
*/
if (!devif_loopback(&self->sk_dev))
if (!devif_loopback(&self->w_dev))
{
/* Send the packet */
@ -1267,27 +1258,27 @@ static int w5500_txpoll(FAR struct net_driver_s *dev)
*
****************************************************************************/
static void w5500_reply(struct w5500_driver_s *self)
static void w5500_reply(FAR struct w5500_driver_s *self)
{
/* If the packet dispatch resulted in data that should be sent out on the
* network, the field d_len will set to a value > 0.
*/
if (self->sk_dev.d_len > 0)
if (self->w_dev.d_len > 0)
{
/* Update the Ethernet header with the correct MAC address */
#ifdef CONFIG_NET_IPv4
if (IFF_IS_IPv4(self->sk_dev.d_flags))
if (IFF_IS_IPv4(self->w_dev.d_flags))
{
arp_out(&self->sk_dev);
arp_out(&self->w_dev);
}
#endif
#ifdef CONFIG_NET_IPv6
if (IFF_IS_IPv6(self->sk_dev.d_flags))
if (IFF_IS_IPv6(self->w_dev.d_flags))
{
neighbor_out(&self->sk_dev);
neighbor_out(&self->w_dev);
}
#endif
@ -1382,19 +1373,19 @@ static void w5500_receive(FAR struct w5500_driver_s *self)
s0_rx_rsr);
}
self->sk_dev.d_len = pktlen - sizeof(pktlen);
self->w_dev.d_len = pktlen - sizeof(pktlen);
/* Copy the data data from the hardware to priv->sk_dev.d_buf. Set
* amount of data in priv->sk_dev.d_len
/* Copy the data data from the hardware to priv->w_dev.d_buf. Set
* amount of data in priv->w_dev.d_len
*/
if (self->sk_dev.d_len <= CONFIG_NET_ETH_PKTSIZE)
if (self->w_dev.d_len <= CONFIG_NET_ETH_PKTSIZE)
{
w5500_read(self,
W5500_BSB_SOCKET_RX_BUFFER(0),
s0_rx_rd + sizeof(pktlen),
self->sk_dev.d_buf,
self->sk_dev.d_len);
self->w_dev.d_buf,
self->w_dev.d_len);
}
/* Acknowledge data reception to W5500 */
@ -1411,41 +1402,41 @@ static void w5500_receive(FAR struct w5500_driver_s *self)
/* Check for errors and update statistics */
if (self->sk_dev.d_len > CONFIG_NET_ETH_PKTSIZE ||
self->sk_dev.d_len < ETH_HDRLEN)
if (self->w_dev.d_len > CONFIG_NET_ETH_PKTSIZE ||
self->w_dev.d_len < ETH_HDRLEN)
{
nerr("Bad packet size dropped (%"PRIu16")\n", self->sk_dev.d_len);
self->sk_dev.d_len = 0;
nerr("Bad packet size dropped (%"PRIu16")\n", self->w_dev.d_len);
self->w_dev.d_len = 0;
NETDEV_RXERRORS(&priv->dev);
continue;
}
#ifdef CONFIG_DEBUG_NET_INFO
ninfodumpbuffer("Received Packet:",
self->sk_dev.d_buf,
self->sk_dev.d_len);
self->w_dev.d_buf,
self->w_dev.d_len);
#endif
#ifdef CONFIG_NET_PKT
/* When packet sockets are enabled, feed the frame into the tap */
pkt_input(&self->sk_dev);
pkt_input(&self->w_dev);
#endif
#ifdef CONFIG_NET_IPv4
/* Check for an IPv4 packet */
if (ETH_HDR->type == HTONS(ETHTYPE_IP))
if (BUF->type == HTONS(ETHTYPE_IP))
{
ninfo("IPv4 frame\n");
NETDEV_RXIPV4(&self->sk_dev);
NETDEV_RXIPV4(&self->w_dev);
/* Handle ARP on input, then dispatch IPv4 packet to the network
* layer.
*/
arp_ipin(&self->sk_dev);
ipv4_input(&self->sk_dev);
arp_ipin(&self->w_dev);
ipv4_input(&self->w_dev);
/* Check for a reply to the IPv4 packet */
@ -1456,14 +1447,14 @@ static void w5500_receive(FAR struct w5500_driver_s *self)
#ifdef CONFIG_NET_IPv6
/* Check for an IPv6 packet */
if (ETH_HDR->type == HTONS(ETHTYPE_IP6))
if (BUF->type == HTONS(ETHTYPE_IP6))
{
ninfo("IPv6 frame\n");
NETDEV_RXIPV6(&self->sk_dev);
NETDEV_RXIPV6(&self->w_dev);
/* Dispatch IPv6 packet to the network layer */
ipv6_input(&self->sk_dev);
ipv6_input(&self->w_dev);
/* Check for a reply to the IPv6 packet */
@ -1474,21 +1465,21 @@ static void w5500_receive(FAR struct w5500_driver_s *self)
#ifdef CONFIG_NET_ARP
/* Check for an ARP packet */
if (ETH_HDR->type == HTONS(ETHTYPE_ARP))
if (BUF->type == HTONS(ETHTYPE_ARP))
{
ninfo("ARP frame\n");
/* Dispatch ARP packet to the network layer */
arp_arpin(&self->sk_dev);
NETDEV_RXARP(&self->sk_dev);
arp_arpin(&self->w_dev);
NETDEV_RXARP(&self->w_dev);
/* If the above function invocation resulted in data that should be
* sent out on the network, the field d_len will set to a value
* > 0.
*/
if (self->sk_dev.d_len > 0)
if (self->w_dev.d_len > 0)
{
w5500_transmit(self);
}
@ -1498,7 +1489,7 @@ static void w5500_receive(FAR struct w5500_driver_s *self)
{
ninfo("Dropped frame\n");
NETDEV_RXDROPPED(&self->sk_dev);
NETDEV_RXDROPPED(&self->w_dev);
}
}
while (true); /* While there are more packets to be processed */
@ -1530,7 +1521,7 @@ static void w5500_txdone(FAR struct w5500_driver_s *self)
{
/* Check for errors and update statistics */
NETDEV_TXDONE(self->sk_dev);
NETDEV_TXDONE(self->w_dev);
/* Check if there are pending transmissions. */
@ -1542,7 +1533,7 @@ static void w5500_txdone(FAR struct w5500_driver_s *self)
* and disable further Tx interrupts.
*/
wd_cancel(&self->sk_txtimeout);
wd_cancel(&self->w_txtimeout);
/* And disable further TX interrupts. */
@ -1553,7 +1544,7 @@ static void w5500_txdone(FAR struct w5500_driver_s *self)
/* In any event, poll the network for new TX data */
devif_poll(&self->sk_dev, w5500_txpoll);
devif_poll(&self->w_dev, w5500_txpoll);
}
/****************************************************************************
@ -1710,7 +1701,7 @@ static int w5500_interrupt(int irq, FAR void *context, FAR void *arg)
/* Schedule to perform the interrupt processing on the worker thread. */
work_queue(ETHWORK, &self->sk_irqwork, w5500_interrupt_work, self, 0);
work_queue(ETHWORK, &self->w_irqwork, w5500_interrupt_work, self, 0);
return OK;
}
@ -1742,7 +1733,7 @@ static void w5500_txtimeout_work(FAR void *arg)
/* Increment statistics and dump debug info */
NETDEV_TXTIMEOUTS(self->sk_dev);
NETDEV_TXTIMEOUTS(self->w_dev);
/* Then reset the hardware */
@ -1752,7 +1743,7 @@ static void w5500_txtimeout_work(FAR void *arg)
/* Then poll the network for new XMIT data */
devif_poll(&self->sk_dev, w5500_txpoll);
devif_poll(&self->w_dev, w5500_txpoll);
}
net_unlock();
@ -1790,7 +1781,7 @@ static void w5500_txtimeout_expiry(wdparm_t arg)
/* Schedule to perform the TX timeout processing on the worker thread. */
work_queue(ETHWORK, &self->sk_irqwork, w5500_txtimeout_work, self, 0);
work_queue(ETHWORK, &self->w_irqwork, w5500_txtimeout_work, self, 0);
}
/****************************************************************************
@ -1848,7 +1839,7 @@ static int w5500_ifup(FAR struct net_driver_s *dev)
/* Enable the Ethernet interrupt */
self->sk_bifup = true;
self->w_bifup = true;
self->lower->enable(self->lower, true);
return OK;
@ -1884,7 +1875,7 @@ static int w5500_ifdown(FAR struct net_driver_s *dev)
/* Cancel the TX timeout timer */
wd_cancel(&self->sk_txtimeout);
wd_cancel(&self->w_txtimeout);
/* Put the EMAC in its reset, non-operational state. This should be
* a known configuration that will guarantee the w5500_ifup() always
@ -1895,7 +1886,7 @@ static int w5500_ifdown(FAR struct net_driver_s *dev)
/* Mark the device "down" */
self->sk_bifup = false;
self->w_bifup = false;
leave_critical_section(flags);
return OK;
}
@ -1931,13 +1922,13 @@ static void w5500_txavail_work(FAR void *arg)
/* Ignore the notification if the interface is not yet up */
if (priv->sk_bifup)
if (priv->w_bifup)
{
/* Check if there is room in the hardware to hold another packet. */
/* If so, then poll the network for new XMIT data */
devif_poll(&priv->sk_dev, w5500_txpoll);
devif_poll(&priv->w_dev, w5500_txpoll);
}
net_unlock();
@ -1972,11 +1963,11 @@ static int w5500_txavail(FAR struct net_driver_s *dev)
* availability action.
*/
if (work_available(&priv->sk_pollwork))
if (work_available(&priv->w_pollwork))
{
/* Schedule to serialize the poll on the worker thread. */
work_queue(ETHWORK, &priv->sk_pollwork, w5500_txavail_work, priv, 0);
work_queue(ETHWORK, &priv->w_pollwork, w5500_txavail_work, priv, 0);
}
return OK;
@ -2131,11 +2122,10 @@ static void w5500_ipv6multicast(FAR struct w5500_driver_s *priv)
#ifdef CONFIG_NETDEV_IOCTL
static int w5500_ioctl(FAR struct net_driver_s *dev, int cmd,
unsigned long arg)
unsigned long arg)
{
FAR struct w5500_driver_s *priv =
(FAR struct w5500_driver_s *)dev->d_private;
int ret;
/* Decode and dispatch the driver-specific IOCTL command */
@ -2200,30 +2190,30 @@ int w5500_initialize(FAR struct spi_dev_s *spi_dev,
/* Initialize the driver structure */
memset(self, 0, sizeof(struct w5500_driver_s));
self->sk_dev.d_buf = g_pktbuf; /* Single packet buffer */
self->sk_dev.d_ifup = w5500_ifup; /* I/F up (new IP address) callback */
self->sk_dev.d_ifdown = w5500_ifdown; /* I/F down callback */
self->sk_dev.d_txavail = w5500_txavail; /* New TX data callback */
self->w_dev.d_buf = (FAR uint8_t *)g_pktbuf[devno]; /* Single packet buffer */
self->w_dev.d_ifup = w5500_ifup; /* I/F up (new IP address) callback */
self->w_dev.d_ifdown = w5500_ifdown; /* I/F down callback */
self->w_dev.d_txavail = w5500_txavail; /* New TX data callback */
#ifdef CONFIG_NET_MCASTGROUP
self->sk_dev.d_addmac = w5500_addmac; /* Add multicast MAC address */
self->sk_dev.d_rmmac = w5500_rmmac; /* Remove multicast MAC address */
self->w_dev.d_addmac = w5500_addmac; /* Add multicast MAC address */
self->w_dev.d_rmmac = w5500_rmmac; /* Remove multicast MAC address */
#endif
#ifdef CONFIG_NETDEV_IOCTL
self->sk_dev.d_ioctl = w5500_ioctl; /* Handle network IOCTL commands */
self->w_dev.d_ioctl = w5500_ioctl; /* Handle network IOCTL commands */
#endif
self->sk_dev.d_private = g_w5500; /* Used to recover private state from dev */
self->spi_dev = spi_dev; /* SPI hardware interconnect */
self->lower = lower; /* Low-level MCU specific support */
self->w_dev.d_private = g_w5500; /* Used to recover private state from dev */
self->spi_dev = spi_dev; /* SPI hardware interconnect */
self->lower = lower; /* Low-level MCU specific support */
/* Put the interface in the down state. This usually amounts to resetting
* the device and/or calling w5500_ifdown().
*/
w5500_ifdown(&self->sk_dev);
w5500_ifdown(&self->w_dev);
/* Register the device with the OS so that socket IOCTLs can be performed */
netdev_register(&self->sk_dev, NET_LL_ETHERNET);
netdev_register(&self->w_dev, NET_LL_ETHERNET);
return OK;
}

View file

@ -229,7 +229,7 @@ struct usbhost_cdcmbim_s
bool bifup; /* true:ifup false:ifdown */
struct net_driver_s netdev; /* Interface understood by the network */
uint8_t txpktbuf[MAX_NETDEV_PKTSIZE];
uint16_t txpktbuf[(MAX_NETDEV_PKTSIZE + 1) / 2];
};
/****************************************************************************
@ -2331,7 +2331,7 @@ static int cdcmbim_txpoll(struct net_driver_s *dev)
* the field d_len is set to a value > 0.
*/
DEBUGASSERT(priv->netdev.d_buf == priv->txpktbuf);
DEBUGASSERT(priv->netdev.d_buf == (FAR uint8_t *)priv->txpktbuf);
usbhost_takesem(&priv->exclsem);
@ -2460,7 +2460,7 @@ static void cdcmbim_txavail_work(void *arg)
net_lock();
priv->netdev.d_buf = priv->txpktbuf;
priv->netdev.d_buf = (FAR uint8_t *)priv->txpktbuf;
if (priv->bifup)
{

View file

@ -39,7 +39,7 @@
* Pre-processor Definitions
****************************************************************************/
#define PKTBUF ((FAR struct eth_hdr_s *)&dev->d_buf)
#define PKTBUF ((FAR struct eth_hdr_s *)dev->d_buf)
/****************************************************************************
* Public Functions
@ -68,7 +68,7 @@
int pkt_input(struct net_driver_s *dev)
{
FAR struct pkt_conn_s *conn;
FAR struct eth_hdr_s *pbuf = (FAR struct eth_hdr_s *)dev->d_buf;
FAR struct eth_hdr_s *pbuf = PKTBUF;
int ret = OK;
conn = pkt_active(pbuf);