2013-08-25 19:21:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/net/encx24j600.c
|
|
|
|
*
|
2018-11-21 14:57:26 +01:00
|
|
|
* Copyright (C) 2017-2018 Gregory Nutt. All rights reserved.
|
2014-08-21 19:16:55 +02:00
|
|
|
* Copyright (C) 2013-2014 UVC Ingenieure. All rights reserved.
|
2013-09-25 16:26:56 +02:00
|
|
|
* Author: Max Holtzberg <mh@uvc.de>
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* References:
|
|
|
|
* - ENC424J600/624J600 Data Sheet, Stand-Alone 10/100 Ethernet Controller
|
|
|
|
* with SPI or Parallel Interface, DS39935C, 2010 Microchip Technology Inc.
|
|
|
|
*
|
|
|
|
* Derived from enc28j60 driver written by:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2012 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_ENCX24J600)
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
2013-08-26 17:11:58 +02:00
|
|
|
#include <queue.h>
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
#include <nuttx/arch.h>
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/wdog.h>
|
2013-08-25 19:21:54 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
#include <nuttx/clock.h>
|
2014-07-05 00:38:51 +02:00
|
|
|
#include <nuttx/net/net.h>
|
2014-05-30 20:13:06 +02:00
|
|
|
#include <nuttx/net/arp.h>
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/encx24j600.h>
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2015-01-20 22:14:29 +01:00
|
|
|
#ifdef CONFIG_NET_PKT
|
|
|
|
# include <nuttx/net/pkt.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
#include "encx24j600.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-09-25 16:26:56 +02:00
|
|
|
* Pre-processor Definitions
|
2013-08-25 19:21:54 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
/* ENCX24J600 Configuration Settings:
|
|
|
|
*
|
|
|
|
* CONFIG_ENCX24J600 - Enabled ENCX24J600 support
|
|
|
|
* CONFIG_ENCX24J600_SPIMODE - Controls the SPI mode
|
|
|
|
* CONFIG_ENCX24J600_FREQUENCY - Define to use a different bus frequency
|
|
|
|
* CONFIG_ENCX24J600_NINTERFACES - Specifies the number of physical ENCX24J600
|
|
|
|
* devices that will be supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The ENCX24J600 spec says that it supports SPI mode 0,0 only: "The
|
|
|
|
* implementation used on this device supports SPI mode 0,0 only. In
|
|
|
|
* addition, the SPI port requires that SCK be at Idle in a low state;
|
|
|
|
* selectable clock polarity is not supported." However, sometimes you
|
|
|
|
* need to tinker with these things.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_ENCX24J600_SPIMODE
|
|
|
|
# define CONFIG_ENCX24J600_SPIMODE SPIDEV_MODE0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* CONFIG_ENCX24J600_NINTERFACES determines the number of physical interfaces
|
|
|
|
* that will be supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_ENCX24J600_NINTERFACES
|
|
|
|
# define CONFIG_ENCX24J600_NINTERFACES 1
|
|
|
|
#endif
|
|
|
|
|
2018-07-04 22:10:40 +02:00
|
|
|
/* CONFIG_NET_ETH_PKTSIZE must always be defined */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2018-07-04 22:10:40 +02:00
|
|
|
#if !defined(CONFIG_NET_ETH_PKTSIZE) && (CONFIG_NET_ETH_PKTSIZE <= MAX_FRAMELEN)
|
|
|
|
# error "CONFIG_NET_ETH_PKTSIZE is not valid for the ENCX24J600"
|
2013-08-25 19:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* We need to have the work queue to handle SPI interrupts */
|
|
|
|
|
2016-11-18 16:22:49 +01:00
|
|
|
#if !defined(CONFIG_SCHED_WORKQUEUE)
|
2013-08-25 19:21:54 +02:00
|
|
|
# error "Worker thread support is required (CONFIG_SCHED_WORKQUEUE)"
|
|
|
|
#endif
|
|
|
|
|
2018-11-21 14:57:26 +01:00
|
|
|
/* The low priority work queue is preferred. If it is not enabled, LPWORK
|
|
|
|
* will be the same as HPWORK.
|
|
|
|
*
|
|
|
|
* NOTE: However, the network should NEVER run on the high priority work
|
|
|
|
* queue! That queue is intended only to service short back end interrupt
|
|
|
|
* processing that never suspends. Suspending the high priority work queue
|
|
|
|
* may bring the system to its knees!
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ENCWORK LPWORK
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* CONFIG_ENCX24J600_DUMPPACKET will dump the contents of each packet to the console. */
|
|
|
|
|
|
|
|
#ifdef CONFIG_ENCX24J600_DUMPPACKET
|
|
|
|
# define enc_dumppacket(m,a,n) lib_dumpbuffer(m,a,n)
|
|
|
|
#else
|
|
|
|
# define enc_dumppacket(m,a,n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Low-level register debug */
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#if !defined(CONFIG_DEBUG_FEATURES) || !defined(CONFIG_DEBUG_NET)
|
2013-08-25 19:21:54 +02:00
|
|
|
# undef CONFIG_ENCX24J600_REGDEBUG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Timing *******************************************************************/
|
|
|
|
|
|
|
|
/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */
|
|
|
|
|
|
|
|
#define ENC_WDDELAY (1*CLK_TCK)
|
|
|
|
|
|
|
|
/* TX timeout = 1 minute */
|
|
|
|
|
|
|
|
#define ENC_TXTIMEOUT (60*CLK_TCK)
|
|
|
|
|
|
|
|
/* Poll timeout */
|
|
|
|
|
|
|
|
#define ENC_POLLTIMEOUT MSEC2TICK(50)
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Register poll timeout */
|
|
|
|
|
|
|
|
#define ENC_REGPOLLTIMEOUT MSEC2TICK(5000)
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* Packet Memory ************************************************************/
|
|
|
|
|
|
|
|
/* Packet memory layout */
|
|
|
|
|
2018-07-04 22:10:40 +02:00
|
|
|
#define PKTMEM_ALIGNED_BUFSIZE ((CONFIG_NET_ETH_PKTSIZE + 1) & ~1)
|
2013-08-26 17:11:58 +02:00
|
|
|
#define PKTMEM_RX_START (PKTMEM_START + PKTMEM_SIZE / 2) /* Followed by RX buffer */
|
2013-10-11 18:57:58 +02:00
|
|
|
#define PKTMEM_RX_SIZE (PKTMEM_SIZE - PKTMEM_RX_START)
|
|
|
|
#define PKTMEM_RX_END (PKTMEM_START + PKTMEM_SIZE) /* RX buffer goes to the end of SRAM */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-28 17:09:00 +02:00
|
|
|
/* We use preinitialized TX descriptors */
|
|
|
|
|
|
|
|
#define ENC_NTXDESCR ((PKTMEM_RX_START - PKTMEM_START) / PKTMEM_ALIGNED_BUFSIZE)
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* This is a helper pointer for accessing the contents of the Ethernet header */
|
|
|
|
|
2014-06-25 17:57:52 +02:00
|
|
|
#define BUF ((struct eth_hdr_s *)priv->dev.d_buf)
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Debug ********************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_ENCX24J600_REGDEBUG
|
2014-10-08 18:18:58 +02:00
|
|
|
# define enc_wrdump(a,v) \
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "ENCX24J600: %02x<-%04x\n", a, v);
|
2014-10-08 18:18:58 +02:00
|
|
|
# define enc_rddump(a,v) \
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "ENCX24J600: %02x->%04x\n", a, v);
|
2014-10-08 18:18:58 +02:00
|
|
|
# define enc_bfsdump(a,m) \
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "ENCX24J600: %02x|=%04x\n", a, m);
|
2014-10-08 18:18:58 +02:00
|
|
|
# define enc_bfcdump(a,m) \
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "ENCX24J600: %02x&=~%04x\n", a, m);
|
2014-10-08 18:18:58 +02:00
|
|
|
# define enc_cmddump(c) \
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "ENCX24J600: CMD: %02x\n", c);
|
2014-10-08 18:18:58 +02:00
|
|
|
# define enc_bmdump(c,b,s) \
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "ENCX24J600: CMD: %02x buffer: %p length: %d\n", c, b, s);
|
2013-08-25 19:21:54 +02:00
|
|
|
#else
|
|
|
|
# define enc_wrdump(a,v)
|
|
|
|
# define enc_rddump(a,v)
|
|
|
|
# define enc_bfsdump(a,m)
|
|
|
|
# define enc_bfcdump(a,m)
|
|
|
|
# define enc_cmddump(c)
|
|
|
|
# define enc_bmdump(c,b,s)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* The state of the interface */
|
|
|
|
|
|
|
|
enum enc_state_e
|
|
|
|
{
|
2013-08-26 17:11:58 +02:00
|
|
|
ENCSTATE_UNINIT = 0, /* The interface is in an uninitialized state */
|
|
|
|
ENCSTATE_DOWN, /* The interface is down */
|
2014-01-21 17:21:45 +01:00
|
|
|
ENCSTATE_UP, /* The interface is up */
|
|
|
|
ENCSTATE_RUNNING /* The interface is has a cable plugged in and is ready to use */
|
2013-08-26 17:11:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct enc_descr_s
|
|
|
|
{
|
|
|
|
struct enc_descr_next *flink;
|
|
|
|
uint16_t addr;
|
|
|
|
uint16_t len;
|
2013-08-25 19:21:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The enc_driver_s encapsulates all state information for a single hardware
|
|
|
|
* interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct enc_driver_s
|
|
|
|
{
|
|
|
|
/* Device control */
|
|
|
|
|
|
|
|
uint8_t ifstate; /* Interface state: See ENCSTATE_* */
|
|
|
|
uint8_t bank; /* Currently selected bank command */
|
|
|
|
uint16_t nextpkt; /* Next packet address */
|
|
|
|
FAR const struct enc_lower_s *lower; /* Low-level MCU-specific support */
|
|
|
|
|
|
|
|
/* Timing */
|
|
|
|
|
|
|
|
WDOG_ID txpoll; /* TX poll timer */
|
|
|
|
WDOG_ID txtimeout; /* TX timeout timer */
|
|
|
|
|
2016-01-24 15:21:55 +01:00
|
|
|
/* Avoid SPI accesses from the interrupt handler by using the work queue */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
struct work_s irqwork; /* Interrupt continuation work queue support */
|
|
|
|
struct work_s towork; /* Tx timeout work queue support */
|
|
|
|
struct work_s pollwork; /* Poll timeout work queue support */
|
|
|
|
|
2013-09-28 17:09:00 +02:00
|
|
|
struct enc_descr_s txdescralloc[ENC_NTXDESCR];
|
|
|
|
struct enc_descr_s rxdescralloc[CONFIG_ENCX24J600_NRXDESCR];
|
|
|
|
|
|
|
|
sq_queue_t txfreedescr; /* Free inititialized TX descriptors */
|
|
|
|
sq_queue_t rxfreedescr; /* Free RX descriptors */
|
2020-02-23 09:50:23 +01:00
|
|
|
sq_queue_t txqueue; /* Enqueued descriptors waiting for transmission */
|
2013-09-24 17:03:16 +02:00
|
|
|
sq_queue_t rxqueue; /* Unhandled incoming packets waiting for reception */
|
2013-08-26 17:11:58 +02:00
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* This is the contained SPI driver intstance */
|
|
|
|
|
|
|
|
FAR struct spi_dev_s *spi;
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* This holds the information visible to the NuttX network */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
struct net_driver_s dev; /* Interface understood by the network */
|
2013-08-25 19:21:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-11-29 23:44:23 +01:00
|
|
|
/* A single packet buffer is used */
|
|
|
|
|
2018-07-04 22:10:40 +02:00
|
|
|
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
|
2016-11-29 23:44:23 +01:00
|
|
|
|
|
|
|
/* Driver status structure */
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
static struct enc_driver_s g_encx24j600[CONFIG_ENCX24J600_NINTERFACES];
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Low-level SPI helpers */
|
|
|
|
|
|
|
|
static void enc_lock(FAR struct enc_driver_s *priv);
|
|
|
|
static inline void enc_unlock(FAR struct enc_driver_s *priv);
|
|
|
|
|
|
|
|
/* SPI control register access */
|
|
|
|
|
|
|
|
static inline void enc_setethrst(FAR struct enc_driver_s *priv);
|
|
|
|
static void enc_setbank(FAR struct enc_driver_s *priv, uint8_t bank);
|
|
|
|
static uint16_t enc_rdreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg);
|
|
|
|
static void enc_wrreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t wrdata);
|
|
|
|
static int enc_waitreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t bits, uint16_t value);
|
|
|
|
static void enc_bfs(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t bits);
|
|
|
|
static void enc_bfc(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t bits);
|
|
|
|
static void enc_cmd(FAR struct enc_driver_s *priv, uint8_t cmd, uint16_t arg);
|
|
|
|
|
|
|
|
#if 0 /* Sometimes useful */
|
|
|
|
static void enc_rxdump(FAR struct enc_driver_s *priv);
|
|
|
|
static void enc_txdump(FAR struct enc_driver_s *priv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* SPI buffer transfers */
|
|
|
|
|
|
|
|
static void enc_rdbuffer(FAR struct enc_driver_s *priv, FAR uint8_t *buffer,
|
|
|
|
size_t buflen);
|
|
|
|
static inline void enc_wrbuffer(FAR struct enc_driver_s *priv,
|
|
|
|
FAR const uint8_t *buffer, size_t buflen);
|
|
|
|
|
|
|
|
/* PHY register access */
|
|
|
|
|
|
|
|
static uint16_t enc_rdphy(FAR struct enc_driver_s *priv, uint8_t phyaddr);
|
|
|
|
static void enc_wrphy(FAR struct enc_driver_s *priv, uint8_t phyaddr,
|
|
|
|
uint16_t phydata);
|
|
|
|
|
|
|
|
/* Common TX logic */
|
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
static int enc_txenqueue(FAR struct enc_driver_s *priv);
|
2013-08-25 19:21:54 +02:00
|
|
|
static int enc_transmit(FAR struct enc_driver_s *priv);
|
2014-07-02 02:41:08 +02:00
|
|
|
static int enc_txpoll(struct net_driver_s *dev);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Common RX logic */
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
static struct enc_descr_s *enc_rxgetdescr(FAR struct enc_driver_s *priv);
|
2019-02-24 18:51:25 +01:00
|
|
|
static void enc_rxldpkt(FAR struct enc_driver_s *priv,
|
|
|
|
FAR struct enc_descr_s *descr);
|
|
|
|
static void enc_rxrmpkt(FAR struct enc_driver_s *priv,
|
|
|
|
FAR struct enc_descr_s *descr);
|
2013-09-24 17:03:16 +02:00
|
|
|
static void enc_rxdispatch(FAR struct enc_driver_s *priv);
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* Interrupt handling */
|
|
|
|
|
|
|
|
static void enc_linkstatus(FAR struct enc_driver_s *priv);
|
|
|
|
static void enc_txif(FAR struct enc_driver_s *priv);
|
|
|
|
static void enc_pktif(FAR struct enc_driver_s *priv);
|
2013-09-24 17:03:16 +02:00
|
|
|
static void enc_rxabtif(FAR struct enc_driver_s *priv);
|
2013-08-25 19:21:54 +02:00
|
|
|
static void enc_irqworker(FAR void *arg);
|
2017-08-22 00:23:22 +02:00
|
|
|
static int enc_interrupt(int irq, FAR void *context, FAR void *arg);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Watchdog timer expirations */
|
|
|
|
|
|
|
|
static void enc_toworker(FAR void *arg);
|
|
|
|
static void enc_txtimeout(int argc, uint32_t arg, ...);
|
|
|
|
static void enc_pollworker(FAR void *arg);
|
|
|
|
static void enc_polltimer(int argc, uint32_t arg, ...);
|
|
|
|
|
|
|
|
/* NuttX callback functions */
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int enc_ifup(struct net_driver_s *dev);
|
|
|
|
static int enc_ifdown(struct net_driver_s *dev);
|
|
|
|
static int enc_txavail(struct net_driver_s *dev);
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2014-06-28 00:48:12 +02:00
|
|
|
static int enc_addmac(struct net_driver_s *dev, FAR const uint8_t *mac);
|
|
|
|
static int enc_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac);
|
2013-08-25 19:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
static void enc_pwrsave(FAR struct enc_driver_s *priv);
|
|
|
|
static void enc_setmacaddr(FAR struct enc_driver_s *priv);
|
2013-10-11 18:57:58 +02:00
|
|
|
static void enc_resetbuffers(FAR struct enc_driver_s *priv);
|
2013-08-25 19:21:54 +02:00
|
|
|
static int enc_reset(FAR struct enc_driver_s *priv);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_lock
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Select the SPI, locking and re-configuring if necessary
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* spi - Reference to the SPI driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_lock(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
/* Lock the SPI bus in case there are multiple devices competing for the SPI
|
|
|
|
* bus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
SPI_LOCK(priv->spi, true);
|
|
|
|
|
|
|
|
/* Now make sure that the SPI bus is configured for the ENCX24J600 (it
|
|
|
|
* might have gotten configured for a different device while unlocked)
|
|
|
|
*/
|
|
|
|
|
|
|
|
SPI_SETMODE(priv->spi, CONFIG_ENCX24J600_SPIMODE);
|
|
|
|
SPI_SETBITS(priv->spi, 8);
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_HWFEATURES(priv->spi, 0);
|
|
|
|
SPI_SETFREQUENCY(priv->spi, CONFIG_ENCX24J600_FREQUENCY);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_unlock
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* De-select the SPI
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* spi - Reference to the SPI driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void enc_unlock(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
/* Relinquish the lock on the bus. */
|
|
|
|
|
|
|
|
SPI_LOCK(priv->spi, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_cmd
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Execute two byte command.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* cmd - ENCX24J600 two-byte command
|
|
|
|
* arg - Two byte argument to the command
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_cmd(FAR struct enc_driver_s *priv, uint8_t cmd, uint16_t arg)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
|
|
|
|
/* Select ENCX24J600 chip */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->spi, cmd); /* Clock out the command */
|
|
|
|
SPI_SEND(priv->spi, arg & 0xff); /* Clock out the low byte */
|
|
|
|
SPI_SEND(priv->spi, arg >> 8); /* Clock out the high byte */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* De-select ENCX24J600 chip. */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_wrdump(cmd, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_setethrst
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Issues System Reset by setting ETHRST (ECON2<4>)
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void enc_setethrst(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
|
2016-11-18 16:22:49 +01:00
|
|
|
/* Select ENCX24J600 chip */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Send the system reset command. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->spi, ENC_SETETHRST);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
up_udelay(25);
|
|
|
|
|
2016-11-18 16:22:49 +01:00
|
|
|
/* De-select ENCX24J600 chip. */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_cmddump(ENC_SETETHRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_setbank
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the bank for the next control register access.
|
|
|
|
*
|
|
|
|
* Assumption:
|
|
|
|
* The caller has exclusive access to the SPI bus
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* bank - SPI command to select the bank with
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The chip is selected and SPI is ready for communication.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_setbank(FAR struct enc_driver_s *priv, uint8_t bank)
|
|
|
|
{
|
|
|
|
/* Check if a bank has to be set and if the bank setting has changed.
|
2019-02-24 18:51:25 +01:00
|
|
|
* For registers that are available on all banks, the bank command is set
|
|
|
|
* to 0.
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (bank != 0 && bank != priv->bank)
|
|
|
|
{
|
|
|
|
/* Select bank with supplied command */
|
|
|
|
|
|
|
|
SPI_SEND(priv->spi, bank);
|
|
|
|
|
|
|
|
/* Then remember the bank setting */
|
|
|
|
|
|
|
|
priv->bank = bank;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rdreg
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read one word from a control register using the RCR command.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* ctrlreg - Bit encoded address of banked register to read
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The byte read from the banked register
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint16_t enc_rdreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg)
|
|
|
|
{
|
|
|
|
uint16_t rddata;
|
|
|
|
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
DEBUGASSERT((ctrlreg & 0xe0) == 0); /* banked regeitsers only */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
enc_setbank(priv, GETBANK(ctrlreg));
|
|
|
|
|
|
|
|
SPI_SEND(priv->spi, ENC_RCR | GETADDR(ctrlreg));
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
rddata = SPI_SEND(priv->spi, 0); /* Clock in the low byte */
|
|
|
|
rddata |= SPI_SEND(priv->spi, 0) << 8; /* Clock in the high byte */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_rddump(GETADDR(ctrlreg), rddata);
|
|
|
|
|
|
|
|
return rddata;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_wrreg
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write one word to a control register using the WCR command.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* ctrlreg - Bit encoded address of banked register to write
|
|
|
|
* wrdata - The data to send
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_wrreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t wrdata)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
DEBUGASSERT((ctrlreg & 0xe0) == 0); /* banked regeitsers only */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
enc_setbank(priv, GETBANK(ctrlreg));
|
|
|
|
|
|
|
|
SPI_SEND(priv->spi, ENC_WCR | GETADDR(ctrlreg));
|
2013-09-25 16:26:56 +02:00
|
|
|
SPI_SEND(priv->spi, wrdata & 0xff); /* Clock out the low byte */
|
|
|
|
SPI_SEND(priv->spi, wrdata >> 8); /* Clock out the high byte */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_wrdump(GETADDR(ctrlreg), wrdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_waitbreg
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Wait until banked register bit(s) take a specific value (or a timeout
|
|
|
|
* occurs).
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* ctrlreg - Bit encoded address of banked register to check
|
|
|
|
* bits - The bits to check (a mask)
|
|
|
|
* value - The value of the bits to return (value under mask)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success, negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int enc_waitreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t bits, uint16_t value)
|
|
|
|
{
|
2018-06-16 20:16:13 +02:00
|
|
|
clock_t start = clock_systimer();
|
|
|
|
clock_t elapsed;
|
2013-08-25 19:21:54 +02:00
|
|
|
uint16_t rddata;
|
|
|
|
|
|
|
|
/* Loop until the exit condition is met */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Read the byte from the requested banked register */
|
|
|
|
|
|
|
|
rddata = enc_rdreg(priv, ctrlreg);
|
|
|
|
elapsed = clock_systimer() - start;
|
|
|
|
}
|
2013-09-25 16:26:56 +02:00
|
|
|
while ((rddata & bits) != value && elapsed < ENC_REGPOLLTIMEOUT);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
return (rddata & bits) == value ? OK : -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_bfs
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Bit Field Set.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* ctrlreg - Bit encoded address of banked register to set bits in
|
|
|
|
* bits - The bits to set (a mask)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_bfs(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t bits)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
|
|
|
|
/* Select ENCX24J600 chip */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Set the bank */
|
|
|
|
|
|
|
|
enc_setbank(priv, GETBANK(ctrlreg));
|
|
|
|
|
|
|
|
/* Send the BFS command and data. The sequence requires 24-clocks:
|
|
|
|
* 8 to clock out the cmd + 16 to clock out the data.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->spi, ENC_BFS | GETADDR(ctrlreg)); /* Clock out the command */
|
|
|
|
SPI_SEND(priv->spi, bits & 0xff); /* Clock out the low byte */
|
|
|
|
SPI_SEND(priv->spi, bits >> 8); /* Clock out the high byte */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* De-select ENCX24J600 chip. */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_bfsdump(GETADDR(ctrlreg), bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_bfc
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Bit Field Clear.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* ctrlreg - Bit encoded address of banked register to clear bits in
|
|
|
|
* bits - The bits to clear (a mask)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_bfc(FAR struct enc_driver_s *priv, uint16_t ctrlreg,
|
|
|
|
uint16_t bits)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
|
|
|
|
/* Select ENCX24J600 chip */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Set the bank */
|
|
|
|
|
|
|
|
enc_setbank(priv, GETBANK(ctrlreg));
|
|
|
|
|
|
|
|
/* Send the BFC command and data. The sequence requires 24-clocks:
|
|
|
|
* 8 to clock out the cmd + 16 to clock out the data.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->spi, ENC_BFC | GETADDR(ctrlreg)); /* Clock out the command */
|
|
|
|
SPI_SEND(priv->spi, bits & 0xff); /* Clock out the low byte */
|
|
|
|
SPI_SEND(priv->spi, bits >> 8); /* Clock out the high byte */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* De-select ENCX24J600 chip. */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_bfcdump(GETADDR(ctrlreg), bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_txdump enc_rxdump
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump registers associated with receiving or sending packets.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if 0 /* Sometimes useful */
|
|
|
|
static void enc_rxdump(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "Rx Registers:\n");
|
|
|
|
syslog(LOG_DEBUG, " EIE: %02x EIR: %02x\n",
|
|
|
|
enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR));
|
|
|
|
syslog(LOG_DEBUG, " ESTAT: %02x ECON1: %02x ECON2: %02x\n",
|
|
|
|
enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1),
|
|
|
|
enc_rdgreg(priv, ENC_ECON2));
|
|
|
|
syslog(LOG_DEBUG, " ERXST: %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_ERXSTH), enc_rdbreg(priv, ENC_ERXSTL));
|
|
|
|
syslog(LOG_DEBUG, " ERXND: %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_ERXNDH), enc_rdbreg(priv, ENC_ERXNDL));
|
|
|
|
syslog(LOG_DEBUG, " ERXRDPT: %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_ERXRDPTH), enc_rdbreg(priv, ENC_ERXRDPTL));
|
|
|
|
syslog(LOG_DEBUG, " ERXFCON: %02x EPKTCNT: %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_ERXFCON), enc_rdbreg(priv, ENC_EPKTCNT));
|
|
|
|
syslog(LOG_DEBUG, " MACON1: %02x MACON3: %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3));
|
|
|
|
syslog(LOG_DEBUG, " MAMXFL: %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL));
|
|
|
|
syslog(LOG_DEBUG, " MAADR: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MAADR1), enc_rdbreg(priv, ENC_MAADR2),
|
|
|
|
enc_rdbreg(priv, ENC_MAADR3), enc_rdbreg(priv, ENC_MAADR4),
|
|
|
|
enc_rdbreg(priv, ENC_MAADR5), enc_rdbreg(priv, ENC_MAADR6));
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0 /* Sometimes useful */
|
|
|
|
static void enc_txdump(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_DEBUG, "Tx Registers:\n");
|
|
|
|
syslog(LOG_DEBUG, " EIE: %02x EIR: %02x\n",
|
|
|
|
enc_rdgreg(priv, ENC_EIE), enc_rdgreg(priv, ENC_EIR));
|
|
|
|
syslog(LOG_DEBUG, " ESTAT: %02x ECON1: %02x\n",
|
|
|
|
enc_rdgreg(priv, ENC_ESTAT), enc_rdgreg(priv, ENC_ECON1));
|
|
|
|
syslog(LOG_DEBUG, " ETXST: %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_ETXSTH), enc_rdbreg(priv, ENC_ETXSTL));
|
|
|
|
syslog(LOG_DEBUG, " ETXND: %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_ETXNDH), enc_rdbreg(priv, ENC_ETXNDL));
|
|
|
|
syslog(LOG_DEBUG, " MACON1: %02x MACON3: %02x MACON4: %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3),
|
|
|
|
enc_rdbreg(priv, ENC_MACON4));
|
|
|
|
syslog(LOG_DEBUG, " MACON1: %02x MACON3: %02x MACON4: %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MACON1), enc_rdbreg(priv, ENC_MACON3),
|
|
|
|
enc_rdbreg(priv, ENC_MACON4));
|
|
|
|
syslog(LOG_DEBUG, " MABBIPG: %02x MAIPG %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MABBIPG), enc_rdbreg(priv, ENC_MAIPGH),
|
|
|
|
enc_rdbreg(priv, ENC_MAIPGL));
|
|
|
|
syslog(LOG_DEBUG, " MACLCON1: %02x MACLCON2: %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MACLCON1), enc_rdbreg(priv, ENC_MACLCON2));
|
|
|
|
syslog(LOG_DEBUG, " MAMXFL: %02x %02x\n",
|
|
|
|
enc_rdbreg(priv, ENC_MAMXFLH), enc_rdbreg(priv, ENC_MAMXFLL));
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rdbuffer
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read a buffer of data from RX Data Buffer.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* buffer - A pointer to the buffer to read into
|
|
|
|
* buflen - The number of bytes to read
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* RX Data pointer is set to the correct address
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_rdbuffer(FAR struct enc_driver_s *priv, FAR uint8_t *buffer,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
|
|
|
|
/* Select ENCX24J600 chip */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Send the read buffer memory command (ignoring the response) */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->spi, ENC_RRXDATA);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Then read the buffer data */
|
|
|
|
|
|
|
|
SPI_RECVBLOCK(priv->spi, buffer, buflen);
|
|
|
|
|
|
|
|
/* De-select ENCX24J600 chip. */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_bmdump(ENC_RRXDATA, buffer, buflen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_wrbuffer
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write a buffer of data.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* buffer - A pointer to the buffer to write from
|
|
|
|
* buflen - The number of bytes to write
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* General Purpose Write pointer is set to the correct address
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void enc_wrbuffer(FAR struct enc_driver_s *priv,
|
|
|
|
FAR const uint8_t *buffer, size_t buflen)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(priv && priv->spi);
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), true);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
SPI_SEND(priv->spi, ENC_WGPDATA);
|
|
|
|
SPI_SNDBLOCK(priv->spi, buffer, buflen);
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->spi, SPIDEV_ETHERNET(0), false);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_bmdump(ENC_WGPDATA, buffer, buflen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rdphy
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read 16-bits of PHY data.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* phyaddr - The PHY register address
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 16-bit value read from the PHY
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint16_t enc_rdphy(FAR struct enc_driver_s *priv, uint8_t phyaddr)
|
|
|
|
{
|
|
|
|
uint16_t data = 0;
|
|
|
|
|
|
|
|
/* "To read from a PHY register:
|
|
|
|
* 1. Write the address of the PHY register to read from into the MIREGADR
|
2019-02-24 18:51:25 +01:00
|
|
|
* register (Register 3-1). Make sure to also set reserved bit 8 of
|
|
|
|
* this register.
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
enc_wrreg(priv, ENC_MIREGADR, phyaddr);
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* 2. Set the MIIRD bit (MICMD<0>, Register 3-2). The read operation
|
|
|
|
* begins and the BUSY bit (MISTAT<0>, Register 3-3) is automatically
|
|
|
|
* set by hardware.
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
enc_bfs(priv, ENC_MICMD, MICMD_MIIRD);
|
|
|
|
|
|
|
|
/* 3. Wait 25.6 μs. Poll the BUSY (MISTAT<0>) bit to be certain that the
|
|
|
|
* operation is complete. While busy, the host controller should not
|
|
|
|
* start any MIISCAN operations or write to the MIWR register. When the
|
|
|
|
* MAC has obtained the register contents, the BUSY bit will clear
|
|
|
|
* itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_udelay(26);
|
|
|
|
if (enc_waitreg(priv, ENC_MISTAT, MISTAT_BUSY, 0x00) == OK)
|
|
|
|
{
|
|
|
|
/* 4. Clear the MIIRD (MICMD<0>) bit. */
|
|
|
|
|
|
|
|
enc_bfc(priv, ENC_MICMD, MICMD_MIIRD);
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* 5. Read the desired data from the MIRD register. For 8-bit
|
|
|
|
* interfaces, the order that these bytes are read is unimportant."
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
data = enc_rdreg(priv, ENC_MIRD);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_wrphy
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* write 16-bits of PHY data.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* phyaddr - The PHY register address
|
|
|
|
* phydata - 16-bit data to write to the PHY
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_wrphy(FAR struct enc_driver_s *priv, uint8_t phyaddr,
|
|
|
|
uint16_t phydata)
|
|
|
|
{
|
|
|
|
/* "To write to a PHY register:
|
|
|
|
*
|
|
|
|
* 1. Write the address of the PHY register to write to into the MIREGADR
|
|
|
|
* register. Make sure to also set reserved bit 8 of this register.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enc_wrreg(priv, ENC_MIREGADR, 0x0100 | phyaddr);
|
|
|
|
|
|
|
|
/* 2. Write the 16 bits of data into the MIWR register. The low byte must
|
|
|
|
* be written first, followed by the high byte.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enc_wrreg(priv, ENC_MIWR, phydata);
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* 3. Writing to the high byte of MIWR begins the MIIM transaction and
|
|
|
|
* the BUSY (MISTAT<0>) bit is automatically set by hardware.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
2019-02-24 18:51:25 +01:00
|
|
|
* The PHY register is written after the MIIM operation completes, which
|
|
|
|
* takes 25.6 μs. When the write operation has completed, the BUSY bit
|
|
|
|
* clears itself. The host controller should not start any MIISCAN, MIWR
|
|
|
|
* or MIIRD operations while the BUSY bit is set.
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
up_udelay(26);
|
|
|
|
enc_waitreg(priv, ENC_MISTAT, MISTAT_BUSY, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_transmit
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start hardware transmission. Called either from:
|
|
|
|
*
|
|
|
|
* - pkif interrupt when an application responds to the receipt of data
|
|
|
|
* by trying to send something, or
|
|
|
|
* - From watchdog based polling.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int enc_transmit(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR struct enc_descr_s *descr;
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
/* dequeue next packet to transmit */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
descr = (FAR struct enc_descr_s *)sq_remfirst(&priv->txqueue);
|
2013-08-26 17:11:58 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(descr != NULL);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Verify that the hardware is ready to send another packet. The driver
|
|
|
|
* starts a transmission process by setting ECON1.TXRTS. When the packet is
|
|
|
|
* finished transmitting or is aborted due to an error/cancellation, the
|
|
|
|
* ECON1.TXRTS bit will be cleared.
|
|
|
|
*
|
|
|
|
* NOTE: If we got here, then we have committed to sending a packet.
|
|
|
|
* higher level logic must have assured that (1) there is no transmission
|
|
|
|
* in progress, and that (2) TX-related interrupts are disabled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT((enc_rdreg(priv, ENC_ECON1) & ECON1_TXRTS) == 0);
|
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
/* Set TXStart and TXLen registers. */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
enc_wrreg(priv, ENC_ETXST, descr->addr);
|
|
|
|
enc_wrreg(priv, ENC_ETXLEN, descr->len);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Set TXRTS to send the packet in the transmit buffer */
|
|
|
|
|
|
|
|
enc_bfs(priv, ENC_ECON1, ECON1_TXRTS);
|
|
|
|
|
|
|
|
/* Setup the TX timeout watchdog (perhaps restarting the timer). Note:
|
|
|
|
* Is there a race condition. Could the TXIF interrupt occur before
|
|
|
|
* the timer is started?
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
wd_start(priv->txtimeout, ENC_TXTIMEOUT, enc_txtimeout, 1,
|
|
|
|
(wdparm_t)priv);
|
2013-08-26 17:11:58 +02:00
|
|
|
|
|
|
|
/* free the descriptor */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)descr, &priv->txfreedescr);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_txenqueue
|
2013-08-26 17:11:58 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2019-02-24 18:51:25 +01:00
|
|
|
* Write packet from d_buf to the enc's SRAM if a free descriptor is
|
|
|
|
* available. The filled descriptor is enqueued for transmission.
|
2013-08-26 17:11:58 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-26 17:11:58 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* A packet is available in d_buf.
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-08-26 17:11:58 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int enc_txenqueue(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
int ret = OK;
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR struct enc_descr_s *descr;
|
2013-08-26 17:11:58 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(priv->dev.d_len > 0);
|
|
|
|
|
|
|
|
/* Increment statistics */
|
|
|
|
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_TXPACKETS(&priv->dev);
|
2013-08-26 17:11:58 +02:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
descr = (FAR struct enc_descr_s *)sq_remfirst(&priv->txfreedescr);
|
2013-08-26 17:11:58 +02:00
|
|
|
|
|
|
|
if (descr != NULL)
|
|
|
|
{
|
|
|
|
enc_dumppacket("Write packet to enc SRAM", priv->dev.d_buf,
|
|
|
|
priv->dev.d_len);
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Copy the packet into the transmit buffer described by the current
|
2013-08-26 17:11:58 +02:00
|
|
|
* tx descriptor
|
|
|
|
*/
|
|
|
|
|
|
|
|
enc_cmd(priv, ENC_WGPWRPT, descr->addr);
|
|
|
|
enc_wrbuffer(priv, priv->dev.d_buf, priv->dev.d_len);
|
|
|
|
|
|
|
|
/* store packet length */
|
|
|
|
|
|
|
|
descr->len = priv->dev.d_len;
|
|
|
|
|
|
|
|
/* enqueue packet */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)descr, &priv->txqueue);
|
2013-08-26 17:11:58 +02:00
|
|
|
|
|
|
|
/* if currently no transmission is active, trigger the transmission */
|
|
|
|
|
|
|
|
if ((enc_rdreg(priv, ENC_ECON1) & ECON1_TXRTS) == 0)
|
|
|
|
{
|
|
|
|
enc_transmit(priv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: no free descriptors\n");
|
2013-08-26 17:11:58 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_txpoll
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Enqueues network packets if available.
|
2014-07-01 02:40:41 +02:00
|
|
|
* This is a callback from devif_poll(). devif_poll() may be called:
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* 1. When the preceding TX packet send is complete,
|
|
|
|
* 2. When the preceding TX packet send timedout and the interface is reset
|
|
|
|
* 3. During normal TX polling
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-07-02 02:41:08 +02:00
|
|
|
static int enc_txpoll(struct net_driver_s *dev)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private;
|
2013-08-26 17:11:58 +02:00
|
|
|
int ret = OK;
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* If the polling resulted in data that should be sent out on the network,
|
|
|
|
* the field d_len is set to a value > 0.
|
|
|
|
*/
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Poll result: d_len=%d\n", priv->dev.d_len);
|
2013-08-26 17:11:58 +02:00
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
if (priv->dev.d_len > 0)
|
|
|
|
{
|
2015-01-21 18:36:33 +01:00
|
|
|
/* Look up the destination MAC address and add it to the Ethernet
|
|
|
|
* header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (IFF_IS_IPv4(priv->dev.d_flags))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
arp_out(&priv->dev);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
neighbor_out(&priv->dev);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
|
|
|
|
2018-08-25 16:33:21 +02:00
|
|
|
if (!devif_loopback(&priv->dev))
|
2018-08-24 17:21:33 +02:00
|
|
|
{
|
|
|
|
/* Send the packet */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2018-08-24 17:21:33 +02:00
|
|
|
ret = enc_txenqueue(priv);
|
|
|
|
}
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If zero is returned, the polling will continue until all connections have
|
|
|
|
* been examined.
|
|
|
|
*/
|
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
return ret;
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_linkstatus
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The current link status can be obtained from the PHSTAT1.LLSTAT or
|
|
|
|
* PHSTAT2.LSTAT.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_linkstatus(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
uint16_t regval;
|
|
|
|
|
|
|
|
/* Before transmitting the first packet after link establishment or
|
|
|
|
* auto-negotiation, the MAC duplex configuration must be manually set to
|
|
|
|
* match the duplex configuration of the PHY. To do this, configure
|
|
|
|
* FULDPX (MACON2<0>) to match PHYDPX (ESTAT<10>).
|
|
|
|
*/
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
regval = enc_rdreg(priv, ENC_ESTAT);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2014-01-21 17:21:45 +01:00
|
|
|
if (regval & ESTAT_PHYLNK)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
2014-01-21 17:21:45 +01:00
|
|
|
if (regval & ESTAT_PHYDPX)
|
|
|
|
{
|
|
|
|
/* Configure full-duplex */
|
|
|
|
|
|
|
|
enc_wrreg(priv, ENC_MABBIPG, 0x15);
|
|
|
|
enc_bfs(priv, ENC_MACON2, MACON2_FULDPX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Configure half-duplex */
|
|
|
|
|
|
|
|
enc_wrreg(priv, ENC_MABBIPG, 0x12);
|
|
|
|
enc_bfc(priv, ENC_MACON2, MACON2_FULDPX);
|
|
|
|
}
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2014-01-21 17:21:45 +01:00
|
|
|
netdev_carrier_on(&priv->dev);
|
|
|
|
priv->ifstate = ENCSTATE_RUNNING;
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-21 17:21:45 +01:00
|
|
|
netdev_carrier_off(&priv->dev);
|
|
|
|
priv->ifstate = ENCSTATE_UP;
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_txif
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An TXIF interrupt was received indicating that the last TX packet(s) is
|
|
|
|
* done
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_txif(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_TXDONE(&priv->dev);
|
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
if (sq_empty(&priv->txqueue))
|
|
|
|
{
|
|
|
|
/* If no further xmits are pending, then cancel the TX timeout */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-08-26 17:11:58 +02:00
|
|
|
wd_cancel(priv->txtimeout);
|
2013-09-28 17:09:00 +02:00
|
|
|
|
2014-07-03 01:23:25 +02:00
|
|
|
/* Poll for TX packets from the networking layer */
|
2013-09-28 17:09:00 +02:00
|
|
|
|
2014-07-02 02:41:08 +02:00
|
|
|
devif_poll(&priv->dev, enc_txpoll);
|
2013-08-26 17:11:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-26 19:08:09 +01:00
|
|
|
/* Process txqueue */
|
2013-08-26 17:11:58 +02:00
|
|
|
|
|
|
|
enc_transmit(priv);
|
|
|
|
}
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rxldpkt
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2014-07-03 01:23:25 +02:00
|
|
|
* Load packet from the enc's RX buffer to the driver d_buf.
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-09-24 17:03:16 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* descr - Reference to the descriptor that should be loaded
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_rxldpkt(FAR struct enc_driver_s *priv,
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR struct enc_descr_s *descr)
|
2013-09-24 17:03:16 +02:00
|
|
|
{
|
|
|
|
DEBUGASSERT(priv != NULL && descr != NULL);
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("load packet @%04x len: %d\n", descr->addr, descr->len);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
|
|
|
/* Set the rx data pointer to the start of the received packet (ERXRDPT) */
|
|
|
|
|
|
|
|
enc_cmd(priv, ENC_WRXRDPT, descr->addr);
|
|
|
|
|
|
|
|
/* Save the packet length (without the 4 byte CRC) in priv->dev.d_len */
|
|
|
|
|
|
|
|
priv->dev.d_len = descr->len - 4;
|
|
|
|
|
|
|
|
/* Copy the data data from the receive buffer to priv->dev.d_buf */
|
|
|
|
|
|
|
|
enc_rdbuffer(priv, priv->dev.d_buf, priv->dev.d_len);
|
|
|
|
|
|
|
|
enc_dumppacket("loaded RX packet", priv->dev.d_buf, priv->dev.d_len);
|
|
|
|
}
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rxgetdescr
|
2013-10-11 18:57:58 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check for a free descriptor in the free list. If no free descriptor is
|
|
|
|
* available a pending descriptor will be freed and returned
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-11 18:57:58 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A free rx descriptor
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-10-11 18:57:58 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static struct enc_descr_s *enc_rxgetdescr(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
if (sq_empty(&priv->rxfreedescr))
|
|
|
|
{
|
|
|
|
DEBUGASSERT(sq_peek(&priv->rxqueue) != NULL);
|
|
|
|
|
|
|
|
/* Packets are held in the enc's SRAM until the space is needed */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
enc_rxrmpkt(priv, (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue));
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
return (FAR struct enc_descr_s *)sq_remfirst(&priv->rxfreedescr);
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rxrmpkt
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Remove packet from the RX queue and free the block of memory in the enc's
|
|
|
|
* SRAM.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-09-24 17:03:16 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
* descr - Reference to the descriptor that should be freed
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static void enc_rxrmpkt(FAR struct enc_driver_s *priv,
|
|
|
|
FAR struct enc_descr_s *descr)
|
2013-09-24 17:03:16 +02:00
|
|
|
{
|
|
|
|
uint16_t addr;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("free descr: %p\n", descr);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
|
|
|
/* If it is the last descriptor in the queue, advance ERXTAIL.
|
2020-02-23 09:50:23 +01:00
|
|
|
* This way it is possible that gaps occur. Maybe pending packets
|
2013-09-24 17:03:16 +02:00
|
|
|
* can be reordered th enc's DMA to free RX space?
|
|
|
|
*/
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
if (descr != NULL)
|
2013-09-24 17:03:16 +02:00
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
if (descr == (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue))
|
2013-10-11 18:57:58 +02:00
|
|
|
{
|
|
|
|
/* Wrap address properly around */
|
2019-02-24 18:51:25 +01:00
|
|
|
|
|
|
|
addr = (descr->addr - PKTMEM_RX_START + descr->len - 2 +
|
|
|
|
PKTMEM_RX_SIZE)
|
|
|
|
% PKTMEM_RX_SIZE + PKTMEM_RX_START;
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
DEBUGASSERT(addr >= PKTMEM_RX_START && addr < PKTMEM_RX_END);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("ERXTAIL %04x\n", addr);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
enc_wrreg(priv, ENC_ERXTAIL, addr);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/* Remove packet from RX queue */
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
sq_remfirst(&priv->rxqueue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remove packet from RX queue */
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_rem((FAR sq_entry_t *)descr, &priv->rxqueue);
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)descr, &priv->rxfreedescr);
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
2013-09-24 17:03:16 +02:00
|
|
|
}
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rxdispatch
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Give the newly received packet to the network.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_rxdispatch(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR struct enc_descr_s *descr;
|
2013-09-24 17:03:16 +02:00
|
|
|
struct enc_descr_s *next;
|
|
|
|
|
|
|
|
/* Process the RX queue */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
descr = (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
|
|
|
while (descr != NULL)
|
|
|
|
{
|
|
|
|
/* Store the next pointer, because removing the item from list will set
|
|
|
|
* flink to NULL
|
|
|
|
*/
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
next = (FAR struct enc_descr_s *)sq_next(descr);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
|
|
|
/* Load the packet from the enc's SRAM */
|
|
|
|
|
|
|
|
enc_rxldpkt(priv, descr);
|
|
|
|
|
2015-01-20 22:14:29 +01:00
|
|
|
#ifdef CONFIG_NET_PKT
|
|
|
|
/* When packet sockets are enabled, feed the frame into the packet tap */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
pkt_input(&priv->dev);
|
2015-01-20 22:14:29 +01:00
|
|
|
#endif
|
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* We only accept IP packets of the configured type and ARP packets */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2015-01-15 17:25:53 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2014-07-04 23:40:49 +02:00
|
|
|
if (BUF->type == HTONS(ETHTYPE_IP))
|
2013-09-24 17:03:16 +02:00
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("IPv4 frame\n");
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXIPV4(&priv->dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* Handle ARP on input then give the IPv4 packet to the network
|
|
|
|
* layer
|
|
|
|
*/
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2014-05-30 20:13:06 +02:00
|
|
|
arp_ipin(&priv->dev);
|
2020-01-02 17:49:34 +01:00
|
|
|
ipv4_input(&priv->dev);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2017-08-21 14:27:29 +02:00
|
|
|
/* Free the packet */
|
2013-09-24 17:03:16 +02:00
|
|
|
|
2017-08-21 14:27:29 +02:00
|
|
|
enc_rxrmpkt(priv, descr);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
2019-02-24 18:51:25 +01:00
|
|
|
* sent out on the network, the field d_len will set to a value
|
|
|
|
* > 0.
|
2013-09-24 17:03:16 +02:00
|
|
|
*/
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
if (priv->dev.d_len > 0)
|
|
|
|
{
|
2015-01-15 17:25:53 +01:00
|
|
|
/* Update the Ethernet header with the correct MAC address */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-01-20 22:14:29 +01:00
|
|
|
if (IFF_IS_IPv4(priv->dev.d_flags))
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
arp_out(&priv->dev);
|
|
|
|
}
|
2015-01-20 22:52:25 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
else
|
|
|
|
{
|
|
|
|
neighbor_out(&priv->dev);
|
|
|
|
}
|
|
|
|
#endif
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
enc_txenqueue(priv);
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 17:25:53 +01:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (BUF->type == HTONS(ETHTYPE_IP6))
|
|
|
|
{
|
2020-03-03 16:11:57 +01:00
|
|
|
ninfo("IPv6 frame\n");
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXIPV6(&priv->dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* Give the IPv6 packet to the network layer */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
ipv6_input(&priv->dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
|
2017-08-21 14:27:29 +02:00
|
|
|
/* Free the packet */
|
2015-01-15 17:25:53 +01:00
|
|
|
|
2017-08-21 14:27:29 +02:00
|
|
|
enc_rxrmpkt(priv, descr);
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
2019-02-24 18:51:25 +01:00
|
|
|
* sent out on the network, the field d_len will set to a value
|
|
|
|
* > 0.
|
2015-01-15 17:25:53 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->dev.d_len > 0)
|
2019-12-05 21:54:50 +01:00
|
|
|
{
|
2015-01-15 17:25:53 +01:00
|
|
|
/* Update the Ethernet header with the correct MAC address */
|
|
|
|
|
2015-01-20 22:52:25 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2015-01-20 22:14:29 +01:00
|
|
|
if (IFF_IS_IPv4(priv->dev.d_flags))
|
2015-01-15 17:25:53 +01:00
|
|
|
{
|
|
|
|
arp_out(&priv->dev);
|
|
|
|
}
|
2015-01-20 22:52:25 +01:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
{
|
|
|
|
neighbor_out(&priv->dev);
|
|
|
|
}
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
|
|
|
enc_txenqueue(priv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
if (BUF->type == htons(ETHTYPE_ARP))
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("ARP packet received (%02x)\n", BUF->type);
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXARP(&priv->dev);
|
|
|
|
|
2014-05-30 20:13:06 +02:00
|
|
|
arp_arpin(&priv->dev);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
|
|
|
/* ARP packets are freed immediately */
|
|
|
|
|
|
|
|
enc_rxrmpkt(priv, descr);
|
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
2019-02-24 18:51:25 +01:00
|
|
|
* sent out on the network, the field d_len will set to a value
|
|
|
|
* > 0.
|
2013-09-24 17:03:16 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->dev.d_len > 0)
|
|
|
|
{
|
|
|
|
enc_txenqueue(priv);
|
|
|
|
}
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
2013-09-24 17:03:16 +02:00
|
|
|
else
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
2013-09-24 17:03:16 +02:00
|
|
|
{
|
|
|
|
/* free unsupported packet */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
enc_rxrmpkt(priv, descr);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
nerr("ERROR: Unsupported packet type dropped (%02x)\n",
|
|
|
|
htons(BUF->type));
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXDROPPED(&priv->dev);
|
2013-09-24 17:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
descr = next;
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_pktif
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating the availability of a new RX packet
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_pktif(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR struct enc_descr_s *descr;
|
2013-08-25 19:21:54 +02:00
|
|
|
uint8_t rsv[8];
|
|
|
|
uint16_t pktlen;
|
|
|
|
uint32_t rxstat;
|
2013-09-24 17:03:16 +02:00
|
|
|
uint16_t curpkt;
|
|
|
|
int pktcnt;
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
DEBUGASSERT(priv->nextpkt >= PKTMEM_RX_START &&
|
|
|
|
priv->nextpkt < PKTMEM_RX_END);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Enqueue all pending packets to the RX queue until PKTCNT == 0 or
|
|
|
|
* no more descriptors are available.
|
|
|
|
*/
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
pktcnt = (enc_rdreg(priv, ENC_ESTAT) & ESTAT_PKTCNT_MASK) >>
|
|
|
|
ESTAT_PKTCNT_SHIFT;
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
while (pktcnt > 0)
|
|
|
|
{
|
|
|
|
curpkt = priv->nextpkt;
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Set the rx data pointer to the start of the received packet (ERXRDPT) */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
enc_cmd(priv, ENC_WRXRDPT, curpkt);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Read the next packet pointer and the 6 byte read status vector (RSV)
|
2019-02-24 18:51:25 +01:00
|
|
|
* at the beginning of the received packet. (ERXRDPT should auto-
|
|
|
|
* increment and wrap to the beginning of the read buffer as necessary)
|
2013-09-24 17:03:16 +02:00
|
|
|
*/
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
enc_rdbuffer(priv, rsv, 8);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Decode the new next packet pointer, and the RSV. The
|
|
|
|
* RSV is encoded as:
|
|
|
|
*
|
2019-02-24 18:51:25 +01:00
|
|
|
* Bits 0-15: Indicates length of the received frame. This includes
|
|
|
|
* the destination address, source address, type/length,
|
|
|
|
* data, padding and CRC fields. This field is stored in
|
|
|
|
* little-endian format.
|
2013-09-24 17:03:16 +02:00
|
|
|
* Bits 16-47: Bit encoded RX status.
|
|
|
|
*/
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
priv->nextpkt = (uint16_t)rsv[1] << 8 | (uint16_t)rsv[0];
|
|
|
|
pktlen = (uint16_t)rsv[3] << 8 | (uint16_t)rsv[2];
|
|
|
|
rxstat = (uint32_t)rsv[7] << 24 | (uint32_t)rsv[6] << 16 |
|
|
|
|
(uint32_t)rsv[5] << 8 | (uint32_t)rsv[4];
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
ninfo("Receiving packet, nextpkt: %04x pktlen: %d rxstat: %08x "
|
|
|
|
"pktcnt: %d\n",
|
2016-06-20 19:59:15 +02:00
|
|
|
priv->nextpkt, pktlen, rxstat, pktcnt);
|
2013-10-11 18:57:58 +02:00
|
|
|
|
|
|
|
/* We enqueue the packet first and remove it later if its faulty.
|
|
|
|
* This way we avoid freeing packets that are not processed yet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
descr = enc_rxgetdescr(priv);
|
|
|
|
|
|
|
|
/* Store the start address of the frame without the enc's header */
|
|
|
|
|
|
|
|
descr->addr = curpkt + 8;
|
|
|
|
descr->len = pktlen;
|
2015-10-10 18:41:00 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)descr, &priv->rxqueue);
|
2013-09-24 17:03:16 +02:00
|
|
|
|
|
|
|
/* Check if the packet was received OK */
|
|
|
|
|
|
|
|
if ((rxstat & RXSTAT_OK) == 0)
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: RXSTAT: %08x\n", rxstat);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/* Discard packet */
|
|
|
|
|
|
|
|
enc_rxrmpkt(priv, descr);
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXERRORS(&priv->dev);
|
2013-09-24 17:03:16 +02:00
|
|
|
}
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Check for a usable packet length (4 added for the CRC) */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
else if (pktlen > (CONFIG_NET_ETH_PKTSIZE + 4) ||
|
|
|
|
pktlen <= (ETH_HDRLEN + 4))
|
2013-09-24 17:03:16 +02:00
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: Bad packet size dropped (%d)\n", pktlen);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/* Discard packet */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
enc_rxrmpkt(priv, descr);
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXERRORS(&priv->dev);
|
2013-09-24 17:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrement PKTCNT */
|
|
|
|
|
|
|
|
enc_bfs(priv, ENC_ECON1, ECON1_PKTDEC);
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/* Try to process the packet */
|
|
|
|
|
|
|
|
enc_rxdispatch(priv);
|
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Read out again, maybe there has another packet arrived */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
pktcnt = (enc_rdreg(priv, ENC_ESTAT) & ESTAT_PKTCNT_MASK) >>
|
|
|
|
ESTAT_PKTCNT_SHIFT;
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
2013-09-24 17:03:16 +02:00
|
|
|
}
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rxabtif
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating the abortion of an RX packet
|
|
|
|
*
|
2019-02-24 18:51:25 +01:00
|
|
|
* "The receive abort interrupt occurs when the reception of a frame has
|
|
|
|
* been aborted. A frame being received is aborted when the Head Pointer
|
|
|
|
* attempts to overrun the Tail Pointer, or when the packet counter has
|
|
|
|
* reached FFh. In either case, the receive buffer is full and cannot
|
|
|
|
* fit the incoming frame, so the packet has been dropped. This
|
|
|
|
* interrupt does not occur when packets are dropped due to the receive
|
|
|
|
* filters rejecting a packet. The interrupt should be cleared by
|
|
|
|
* software once it has been serviced."
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-09-24 17:03:16 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-05-30 17:37:34 +02:00
|
|
|
* Interrupts are enabled but the caller holds the network lock.
|
2013-09-24 17:03:16 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_rxabtif(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR struct enc_descr_s *descr;
|
2013-10-11 18:57:58 +02:00
|
|
|
|
|
|
|
#if 0
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Free the last received packet from the RX queue */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("rx abort\n");
|
|
|
|
ninfo("ESTAT: %04x\n", enc_rdreg(priv, ENC_ESTAT));
|
|
|
|
ninfo("EIR: %04x\n", enc_rdreg(priv, ENC_EIR));
|
|
|
|
ninfo("ERXTAIL: %04x\n", enc_rdreg(priv, ENC_ERXTAIL));
|
|
|
|
ninfo("ERXHAED: %04x\n", enc_rdreg(priv, ENC_ERXHEAD));
|
2013-10-11 18:57:58 +02:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
descr = (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
while (descr != NULL)
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("addr: %04x len: %d\n", descr->addr, descr->len);
|
2015-10-10 18:41:00 +02:00
|
|
|
descr = (FAR struct enc_descr_s *)sq_next(descr);
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGASSERT(false);
|
|
|
|
#endif
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
descr = (FAR struct enc_descr_s *)sq_peek(&priv->rxqueue);
|
2013-10-11 18:57:58 +02:00
|
|
|
|
|
|
|
if (descr != NULL)
|
|
|
|
{
|
|
|
|
enc_rxrmpkt(priv, descr);
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("pending packet freed\n");
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If no pending packet blocks the reception, reset all buffers */
|
|
|
|
|
|
|
|
enc_resetbuffers(priv);
|
|
|
|
}
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_irqworker
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform interrupt handling logic outside of the interrupt handler (on
|
|
|
|
* the work queue thread).
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* arg - The reference to the driver structure (case to void*)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_irqworker(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg;
|
|
|
|
uint16_t eir;
|
|
|
|
|
|
|
|
DEBUGASSERT(priv);
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Get exclusive access to both the network and the SPI bus. */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* A good practice is for the host controller to clear the Global Interrupt
|
|
|
|
* Enable bit, INTIE (EIE<15>), immediately after an interrupt event. This
|
|
|
|
* causes the interrupt pin to return to the non-asserted (high) state. Once
|
|
|
|
* the interrupt has been serviced, the INTIE bit is set again to re-enable
|
|
|
|
* interrupts. If a new interrupt occurs while servicing another, the act of
|
|
|
|
* resetting the global enable bit will cause a new falling edge to occur on
|
|
|
|
* the interrupt pin and ensure that the host does not miss any events
|
|
|
|
*/
|
|
|
|
|
|
|
|
enc_bfc(priv, ENC_EIE, EIE_INTIE);
|
|
|
|
|
|
|
|
/* Loop until all interrupts have been processed (EIR==0). Note that
|
2019-02-24 18:51:25 +01:00
|
|
|
* there is no infinite loop check... if there are always pending
|
|
|
|
* interrupts, we are just broken.
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
while ((eir = enc_rdreg(priv, ENC_EIR) & EIR_ALLINTS) != 0)
|
|
|
|
{
|
|
|
|
/* Handle interrupts according to interrupt register register bit
|
|
|
|
* settings.
|
|
|
|
*/
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("EIR: %04x\n", eir);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
if ((eir & EIR_DMAIF) != 0) /* DMA interrupt */
|
|
|
|
{
|
|
|
|
/* Not used by this driver. Just clear the interrupt request. */
|
|
|
|
|
|
|
|
enc_bfc(priv, ENC_EIR, EIR_DMAIF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LINKIF: The link change interrupt occurs when the PHY link status
|
|
|
|
* changes. This flag is set by hardware when a link has either been
|
2019-02-24 18:51:25 +01:00
|
|
|
* established or broken between the device and a remote Ethernet
|
|
|
|
* partner. The current link status can be read from PHYLNK
|
|
|
|
* (ESTAT<8>). The interrupt should be cleared by software once it
|
|
|
|
* has been serviced.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* To enable the link change interrupt, set LINKIE (EIE<11>).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((eir & EIR_LINKIF) != 0) /* PHY Link Status Change */
|
|
|
|
{
|
|
|
|
enc_linkstatus(priv); /* Get current link status */
|
|
|
|
enc_bfc(priv, ENC_EIR, EIR_LINKIF); /* Clear the LINKIF interrupt */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The transmit complete interrupt occurs when the transmission of a
|
|
|
|
* frame has ended (whether or not it was successful). This flag is set
|
|
|
|
* when TXRTS (ECON1<1>) is cleared. The interrupt should be cleared by
|
|
|
|
* software once it has been serviced.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((eir & EIR_TXIF) != 0) /* Transmit Done */
|
|
|
|
{
|
|
|
|
enc_txif(priv);
|
|
|
|
enc_bfc(priv, ENC_EIR, EIR_TXIF);
|
|
|
|
}
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/* The receive abort interrupt occurs when the reception of a frame has
|
|
|
|
* been aborted. A frame being received is aborted when the Head Pointer
|
|
|
|
* attempts to overrun the Tail Pointer, or when the packet counter has
|
2019-02-24 18:51:25 +01:00
|
|
|
* reached FFh. In either case, the receive buffer is full and cannot
|
|
|
|
* fit the incoming frame, so the packet has been dropped. This
|
|
|
|
* interrupt does not occur when packets are dropped due to the receive
|
|
|
|
* filters rejecting a packet. The interrupt should be cleared by
|
|
|
|
* software once it has been serviced.
|
2013-10-11 18:57:58 +02:00
|
|
|
*
|
|
|
|
* To enable the receive abort interrupt, set RXABTIE (EIE<1>).
|
|
|
|
* The corresponding interrupt flag is RXABTIF (EIR<1>).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((eir & EIR_RXABTIF) != 0) /* Receive Abort */
|
|
|
|
{
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXERRORS(&priv->dev);
|
2013-10-11 18:57:58 +02:00
|
|
|
enc_rxabtif(priv);
|
|
|
|
enc_bfc(priv, ENC_EIR, EIR_RXABTIF); /* Clear the RXABTIF interrupt */
|
|
|
|
}
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* The received packet pending interrupt occurs when one or more frames
|
2019-02-24 18:51:25 +01:00
|
|
|
* have been received and are ready for software processing. This flag
|
|
|
|
* is set when the PKTCNT<7:0> (ESTAT<7:0>) bits are non-zero. This
|
|
|
|
* interrupt flag is read-only and will automatically clear when the
|
|
|
|
* PKTCNT bits are decremented to zero. For more details about
|
|
|
|
* receiving and processing incoming frames, refer to Section 9.0
|
|
|
|
* "Transmitting and Receiving Packets".
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* To enable the received packet pending interrupt, set PKTIE (EIE<6>).
|
|
|
|
* The corresponding interrupt flag is PKTIF (EIR<6>).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((eir & EIR_PKTIF) != 0 /* RX Packet Pending */
|
|
|
|
&& (enc_rdreg(priv, ENC_ESTAT) & ESTAT_PKTCNT_MASK) != 0)
|
|
|
|
{
|
|
|
|
enc_pktif(priv); /* Handle packet receipt */
|
|
|
|
|
|
|
|
/* No clearing necessary, after PKTCNT == 0 the bit is automatically
|
|
|
|
* cleared. This means we will loop until all packets are processed.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2015-11-26 19:08:09 +01:00
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
2013-08-25 19:21:54 +02:00
|
|
|
/* The transmit abort interrupt occurs when the transmission of a frame
|
2019-02-24 18:51:25 +01:00
|
|
|
* has been aborted. An abort can occur for any of the following
|
|
|
|
* reasons:
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* * Excessive collisions occurred as defined by the Retransmission
|
|
|
|
* Maximum, MAXRET<3:0> bits (MACLCON<3:0>), setting. If this occurs,
|
2019-02-24 18:51:25 +01:00
|
|
|
* the COLCNT bits (ETXSTAT<3:0>) will indicate the number of
|
|
|
|
* collisions that occurred.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* * A late collision occurred after 63 bytes were transmitted. If this
|
|
|
|
* occurs, LATECOL (ETXSTAT<10>) will be set.
|
|
|
|
*
|
|
|
|
* * The medium was busy and the packet was deferred. If this occurs,
|
|
|
|
* EXDEFER (ETXSTAT<8>) will be set.
|
|
|
|
*
|
|
|
|
* * The application aborted the transmission by clearing TXRTS
|
|
|
|
* (ECON1<1>).
|
|
|
|
*
|
2019-02-24 18:51:25 +01:00
|
|
|
* The interrupt should be cleared by software once it has been
|
|
|
|
* serviced. To enable the transmit abort interrupt, set TXABTIE
|
|
|
|
* (EIE<2>).
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ((eir & EIR_TXABTIF) != 0) /* Transmit Abort */
|
|
|
|
{
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_TXERRORS(&priv->dev);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_bfc(priv, ENC_EIR, EIR_TXABTIF); /* Clear the TXABTIF interrupt */
|
|
|
|
}
|
2013-09-24 17:03:16 +02:00
|
|
|
#endif
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
2013-09-24 17:03:16 +02:00
|
|
|
/* Enable GPIO interrupts */
|
|
|
|
|
|
|
|
priv->lower->enable(priv->lower);
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* Enable Ethernet interrupts */
|
|
|
|
|
|
|
|
enc_bfs(priv, ENC_EIE, EIE_INTIE);
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Release lock on the SPI bus and the network */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
enc_unlock(priv);
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_interrupt
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Hardware interrupt handler
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* irq - Number of the IRQ that generated the interrupt
|
|
|
|
* context - Interrupt register state save info (architecture-specific)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-22 00:23:22 +02:00
|
|
|
static int enc_interrupt(int irq, FAR void *context, FAR void *arg)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
2017-08-22 00:49:43 +02:00
|
|
|
FAR struct enc_driver_s *priv;
|
2017-08-22 00:23:22 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(arg != NULL);
|
|
|
|
priv = (FAR struct enc_driver_s *)arg;
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* In complex environments, we cannot do SPI transfers from the interrupt
|
|
|
|
* handler because semaphores are probably used to lock the SPI bus. In
|
|
|
|
* this case, we will defer processing to the worker thread. This is also
|
|
|
|
* much kinder in the use of system resources and is, therefore, probably
|
|
|
|
* a good thing to do in any event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(work_available(&priv->irqwork));
|
|
|
|
|
|
|
|
/* Notice that further GPIO interrupts are disabled until the work is
|
|
|
|
* actually performed. This is to prevent overrun of the worker thread.
|
|
|
|
* Interrupts are re-enabled in enc_irqworker() when the work is completed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
priv->lower->disable(priv->lower);
|
2017-08-22 00:23:22 +02:00
|
|
|
return work_queue(ENCWORK, &priv->irqwork, enc_irqworker,
|
|
|
|
(FAR void *)priv, 0);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_toworker
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Our TX watchdog timed out. This is the worker thread continuation of
|
|
|
|
* the watchdog timer interrupt. Reset the hardware and start again.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* arg - The reference to the driver structure (case to void*)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_toworker(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: Tx timeout\n");
|
2013-08-25 19:21:54 +02:00
|
|
|
DEBUGASSERT(priv);
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Get exclusive access to the network. */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Increment statistics and dump debug info */
|
|
|
|
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_TXTIMEOUTS(&priv->dev);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Then reset the hardware: Take the interface down, then bring it
|
|
|
|
* back up
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = enc_ifdown(&priv->dev);
|
|
|
|
DEBUGASSERT(ret == OK);
|
|
|
|
ret = enc_ifup(&priv->dev);
|
|
|
|
DEBUGASSERT(ret == OK);
|
2020-01-02 17:49:34 +01:00
|
|
|
UNUSED(ret);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Then poll the network for new XMIT data */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_poll(&priv->dev, enc_txpoll);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Release the network */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_txtimeout
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Our TX watchdog timed out. Called from the timer interrupt handler.
|
|
|
|
* The last TX never completed. Perform work on the worker thread.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_txtimeout(int argc, uint32_t arg, ...)
|
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg;
|
|
|
|
int ret;
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* In complex environments, we cannot do SPI transfers from the timeout
|
2013-08-25 19:21:54 +02:00
|
|
|
* handler because semaphores are probably used to lock the SPI bus. In
|
|
|
|
* this case, we will defer processing to the worker thread. This is also
|
|
|
|
* much kinder in the use of system resources and is, therefore, probably
|
|
|
|
* a good thing to do in any event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(priv && work_available(&priv->towork));
|
|
|
|
|
|
|
|
/* Notice that Tx timeout watchdog is not active so further Tx timeouts
|
|
|
|
* can occur until we restart the Tx timeout watchdog.
|
|
|
|
*/
|
|
|
|
|
2016-11-18 16:22:49 +01:00
|
|
|
ret = work_queue(ENCWORK, &priv->towork, enc_toworker, (FAR void *)priv, 0);
|
2020-01-02 17:49:34 +01:00
|
|
|
UNUSED(ret);
|
2013-08-25 19:21:54 +02:00
|
|
|
DEBUGASSERT(ret == OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_pollworker
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Periodic timer handler continuation.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_pollworker(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg;
|
|
|
|
|
|
|
|
DEBUGASSERT(priv);
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Get exclusive access to both the network and the SPI bus. */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* Verify that the hardware is ready to send another packet. The driver
|
|
|
|
* start a transmission process by setting ECON1.TXRTS. When the packet is
|
|
|
|
* finished transmitting or is aborted due to an error/cancellation, the
|
|
|
|
* ECON1.TXRTS bit will be cleared.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((enc_rdreg(priv, ENC_ECON1) & ECON1_TXRTS) == 0)
|
|
|
|
{
|
2019-02-24 18:51:25 +01:00
|
|
|
/* Yes.. update TCP timing states and poll the network for new XMIT
|
|
|
|
* data. Hmmm.. looks like a bug here to me. Does this mean if there
|
|
|
|
* is a transmit in progress, we will missing TCP time state updates?
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_timer(&priv->dev, ENC_WDDELAY, enc_txpoll);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Release lock on the SPI bus and the network */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
enc_unlock(priv);
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Setup the watchdog poll timer again */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1, (wdparm_t)arg);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_polltimer
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Periodic timer handler. Called from the timer interrupt handler.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_polltimer(int argc, uint32_t arg, ...)
|
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)arg;
|
|
|
|
int ret;
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* In complex environments, we cannot do SPI transfers from the timeout
|
2013-08-25 19:21:54 +02:00
|
|
|
* handler because semaphores are probably used to lock the SPI bus. In
|
|
|
|
* this case, we will defer processing to the worker thread. This is also
|
|
|
|
* much kinder in the use of system resources and is, therefore, probably
|
|
|
|
* a good thing to do in any event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(priv && work_available(&priv->pollwork));
|
|
|
|
|
|
|
|
/* Notice that poll watchdog is not active so further poll timeouts can
|
|
|
|
* occur until we restart the poll timeout watchdog.
|
|
|
|
*/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
ret = work_queue(ENCWORK, &priv->pollwork, enc_pollworker,
|
|
|
|
(FAR void *)priv, 0);
|
2013-08-25 19:21:54 +02:00
|
|
|
DEBUGASSERT(ret == OK);
|
2019-02-24 18:51:25 +01:00
|
|
|
UNUSED(ret);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_ifup
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Bring up the Ethernet interface when an IP address is
|
|
|
|
* provided
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int enc_ifup(struct net_driver_s *dev)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Bringing up: %d.%d.%d.%d\n",
|
|
|
|
dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
|
|
|
|
(dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Lock the SPI bus so that we have exclusive access */
|
|
|
|
|
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* Initialize Ethernet interface, set the MAC address, and make sure that
|
|
|
|
* the ENC28J80 is not in power save mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = enc_reset(priv);
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
enc_setmacaddr(priv);
|
|
|
|
|
|
|
|
/* Enable interrupts at the ENCX24J600. Interrupts are still disabled
|
|
|
|
* at the interrupt controller.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enc_bfc(priv, ENC_EIR, EIR_ALLINTS);
|
|
|
|
enc_bfs(priv, ENC_EIE, EIE_INTIE | EIE_LINKIE |
|
|
|
|
EIE_PKTIE | EIE_RXABTIE |
|
2015-10-10 18:41:00 +02:00
|
|
|
EIE_TXIE);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2015-11-26 19:08:09 +01:00
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_bfs(priv, ENC_EIE, EIE_TXABTIE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Enable the receiver */
|
|
|
|
|
|
|
|
enc_bfs(priv, ENC_ECON1, ECON1_RXEN);
|
|
|
|
|
|
|
|
/* Set and activate a timer process */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
wd_start(priv->txpoll, ENC_WDDELAY, enc_polltimer, 1,
|
|
|
|
(wdparm_t)priv);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Mark the interface up and enable the Ethernet interrupt at the
|
|
|
|
* controller
|
|
|
|
*/
|
|
|
|
|
|
|
|
priv->ifstate = ENCSTATE_UP;
|
|
|
|
priv->lower->enable(priv->lower);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Un-lock the SPI bus */
|
|
|
|
|
|
|
|
enc_unlock(priv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_ifdown
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Stop the interface.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int enc_ifdown(struct net_driver_s *dev)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private;
|
|
|
|
irqstate_t flags;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Taking down: %d.%d.%d.%d\n",
|
|
|
|
dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
|
|
|
|
(dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Lock the SPI bus so that we have exclusive access */
|
|
|
|
|
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* Disable the Ethernet interrupt */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2013-08-25 19:21:54 +02:00
|
|
|
priv->lower->disable(priv->lower);
|
|
|
|
|
|
|
|
/* Cancel the TX poll timer and TX timeout timers */
|
|
|
|
|
|
|
|
wd_cancel(priv->txpoll);
|
|
|
|
wd_cancel(priv->txtimeout);
|
|
|
|
|
|
|
|
/* Reset the device and leave in the power save state */
|
|
|
|
|
|
|
|
ret = enc_reset(priv);
|
|
|
|
enc_pwrsave(priv);
|
|
|
|
|
|
|
|
priv->ifstate = ENCSTATE_DOWN;
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* Un-lock the SPI bus */
|
|
|
|
|
|
|
|
enc_unlock(priv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_txavail
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Driver callback invoked when new TX data is available. This is a
|
|
|
|
* stimulus perform an out-of-cycle poll and, thereby, reduce the TX
|
|
|
|
* latency.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called in normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static int enc_txavail(struct net_driver_s *dev)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Lock the SPI bus so that we have exclusive access */
|
|
|
|
|
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* Ignore the notification if the interface is not yet up */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2014-01-21 17:21:45 +01:00
|
|
|
if (priv->ifstate == ENCSTATE_RUNNING)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
/* Check if the hardware is ready to send another packet. The driver
|
2019-02-24 18:51:25 +01:00
|
|
|
* starts a transmission process by setting ECON1.TXRTS. When the
|
|
|
|
* packet is finished transmitting or is aborted due to an error/
|
|
|
|
* cancellation, the ECON1.TXRTS bit will be cleared.
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ((enc_rdreg(priv, ENC_ECON1) & ECON1_TXRTS) == 0)
|
|
|
|
{
|
2016-05-30 17:37:34 +02:00
|
|
|
/* The interface is up and TX is idle; poll the network for new XMIT data */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_poll(&priv->dev, enc_txpoll);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Un-lock the SPI bus */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_unlock(priv);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_addmac
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Add the specified MAC address to the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be added
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2014-06-28 00:48:12 +02:00
|
|
|
static int enc_addmac(struct net_driver_s *dev, FAR const uint8_t *mac)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private;
|
|
|
|
|
|
|
|
/* Lock the SPI bus so that we have exclusive access */
|
|
|
|
|
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
#warning "Multicast MAC support not implemented"
|
|
|
|
|
|
|
|
/* Un-lock the SPI bus */
|
|
|
|
|
|
|
|
enc_unlock(priv);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_rmmac
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2019-02-24 18:51:25 +01:00
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware
|
|
|
|
* multicast address filtering
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be removed
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2014-06-28 00:48:12 +02:00
|
|
|
static int enc_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv = (FAR struct enc_driver_s *)dev->d_private;
|
|
|
|
|
|
|
|
/* Lock the SPI bus so that we have exclusive access */
|
|
|
|
|
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
#warning "Multicast MAC support not implemented"
|
|
|
|
|
|
|
|
/* Un-lock the SPI bus */
|
|
|
|
|
|
|
|
enc_unlock(priv);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_pwrsave
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The ENCX24J600 may be placed in Power-Down mode through the command
|
2019-02-24 18:51:25 +01:00
|
|
|
* interface. In this mode, the device will no longer be able to transmit
|
|
|
|
* or receive any packets or perform DMA operations. However, most
|
|
|
|
* registers, and all buffer memories, retain their states and remain
|
|
|
|
* accessible by the host controller. The clock driver also remains
|
|
|
|
* operational, leaving the CLKOUT function unaffected. However, the
|
|
|
|
* MAC/MII and PHY registers all become inaccessible, and the PHY
|
|
|
|
* registers lose their current states.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* 1. Turn off the Modular Exponentiation and AES engines by clearing
|
|
|
|
* CRYPTEN (EIR<15>).
|
|
|
|
* 2. Turn off packet reception by clearing RXEN (ECON1<0>).
|
|
|
|
* 3. Wait for any in-progress receptions to complete by polling
|
|
|
|
* RXBUSY (ESTAT<13>) until it is clear.
|
|
|
|
* 4. Wait for any current transmission operation to complete by verifying
|
|
|
|
* that TXRTS (ECON1<1>) is clear.
|
|
|
|
* 5. Power-down the PHY by setting the PSLEEP bit (PHCON1<11>).
|
|
|
|
* 6. Power-down the Ethernet interface by clearing
|
2019-02-24 18:51:25 +01:00
|
|
|
* ETHEN and STRCH (ECON2<15,14>). Disabling the LED stretching behavior
|
|
|
|
* is necessary to ensure no LEDs get trapped in a perpetually
|
|
|
|
* illuminated state in the event they are being stretched on when ETHEN
|
|
|
|
* is cleared.
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* Instead of providing a powerup function, the job is done by enc_reset.
|
|
|
|
* enc_ifup calls it anyway.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_pwrsave(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
uint16_t regval;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Set PWRSV\n");
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
/* 1. Turn off AES */
|
|
|
|
|
|
|
|
enc_bfc(priv, ENC_EIR, EIR_CRYPTEN);
|
|
|
|
|
|
|
|
/* 2. Turn off packet reception */
|
|
|
|
|
|
|
|
enc_bfc(priv, ENC_ECON1, ECON1_RXEN);
|
|
|
|
|
|
|
|
/* 3. Wait for pending reception to complete */
|
|
|
|
|
|
|
|
enc_waitreg(priv, ENC_ESTAT, ESTAT_RXBUSY, 0);
|
|
|
|
|
|
|
|
/* 4. Wait for any current transmissions to complete */
|
|
|
|
|
|
|
|
enc_waitreg(priv, ENC_ECON1, ECON1_TXRTS, 0);
|
|
|
|
|
|
|
|
/* 5. Power down the PHY */
|
|
|
|
|
|
|
|
regval = enc_rdphy(priv, ENC_PHCON1);
|
|
|
|
regval |= PHCON1_PSLEEP;
|
|
|
|
enc_wrphy(priv, ENC_PHCON1, regval);
|
|
|
|
|
|
|
|
/* 6. Power down the Ethernet interface */
|
|
|
|
|
|
|
|
enc_bfc(priv, ENC_ECON2, ECON2_ETHEN | ECON2_STRCH);
|
|
|
|
}
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_ldmacaddr
|
2013-09-25 16:26:56 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Load the MAC address from the ENCX24j600 and write it to the device
|
|
|
|
* structure.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-09-25 16:26:56 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_ldmacaddr(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
uint16_t regval;
|
2017-04-22 19:10:30 +02:00
|
|
|
uint8_t *mac = priv->dev.d_mac.ether.ether_addr_octet;
|
2013-09-25 16:26:56 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Using ENCX24J600's built in MAC address\n");
|
2013-09-25 16:26:56 +02:00
|
|
|
|
|
|
|
regval = enc_rdreg(priv, ENC_MAADR1);
|
|
|
|
mac[0] = regval & 0xff;
|
|
|
|
mac[1] = regval >> 8;
|
|
|
|
|
|
|
|
regval = enc_rdreg(priv, ENC_MAADR2);
|
|
|
|
mac[2] = regval & 0xff;
|
|
|
|
mac[3] = regval >> 8;
|
|
|
|
|
|
|
|
regval = enc_rdreg(priv, ENC_MAADR3);
|
|
|
|
mac[4] = regval & 0xff;
|
|
|
|
mac[5] = regval >> 8;
|
|
|
|
}
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_setmacaddr
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the MAC address to the configured value. This is done after ifup
|
|
|
|
* or after a TX timeout. Note that this means that the interface must
|
|
|
|
* be down before configuring the MAC addr.
|
|
|
|
* If the MAC address is 0 in all digits, the ENCX24J600's MAC is read out.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_setmacaddr(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
2017-04-22 19:10:30 +02:00
|
|
|
uint8_t *mac = priv->dev.d_mac.ether.ether_addr_octet;
|
2013-08-25 19:21:54 +02:00
|
|
|
struct ether_addr zmac;
|
|
|
|
|
|
|
|
memset(&zmac, 0, sizeof(zmac));
|
|
|
|
|
2017-04-22 19:10:30 +02:00
|
|
|
if (memcmp(&priv->dev.d_mac.ether, &zmac, sizeof(zmac)) == 0)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
/* No user defined MAC address. Read it from the device. */
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
enc_ldmacaddr(priv);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* There is a user defined mac address. Write it to the ENCXJ600 */
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Using an user defined MAC address\n");
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
enc_wrreg(priv, ENC_MAADR1, (uint16_t)mac[1] << 8 | (uint16_t)mac[0]);
|
|
|
|
enc_wrreg(priv, ENC_MAADR2, (uint16_t)mac[3] << 8 | (uint16_t)mac[2]);
|
|
|
|
enc_wrreg(priv, ENC_MAADR3, (uint16_t)mac[5] << 8 | (uint16_t)mac[4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_resetbuffers
|
2013-10-11 18:57:58 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initializes the RX/TX queues and configures the enc's RX/TX buffers.
|
|
|
|
* Called on general reset and on rxabt interrupt.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-11 18:57:58 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void enc_resetbuffers(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
int i;
|
2019-02-24 18:51:25 +01:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/* Initialize receive and transmit buffers */
|
|
|
|
|
|
|
|
priv->nextpkt = PKTMEM_RX_START;
|
|
|
|
enc_wrreg(priv, ENC_ERXST, PKTMEM_RX_START);
|
|
|
|
|
|
|
|
/* Program the Tail Pointer, ERXTAIL, to the last even address of the buffer */
|
|
|
|
|
|
|
|
enc_wrreg(priv, ENC_ERXTAIL, PKTMEM_RX_END - 2);
|
|
|
|
|
|
|
|
sq_init(&priv->txfreedescr);
|
|
|
|
sq_init(&priv->rxfreedescr);
|
|
|
|
sq_init(&priv->txqueue);
|
|
|
|
sq_init(&priv->rxqueue);
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* For transmission we preinitialize the descriptors to aligned NET_BUFFSIZE */
|
2013-10-11 18:57:58 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ENC_NTXDESCR; i++)
|
|
|
|
{
|
2019-02-24 18:51:25 +01:00
|
|
|
priv->txdescralloc[i].addr = PKTMEM_START +
|
|
|
|
PKTMEM_ALIGNED_BUFSIZE * i;
|
|
|
|
sq_addlast((FAR sq_entry_t *)&priv->txdescralloc[i],
|
|
|
|
&priv->txfreedescr);
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Receive descriptors addresses are set on reception */
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_ENCX24J600_NRXDESCR; i++)
|
|
|
|
{
|
2019-02-24 18:51:25 +01:00
|
|
|
sq_addlast((FAR sq_entry_t *)&priv->rxdescralloc[i],
|
|
|
|
&priv->rxfreedescr);
|
2013-10-11 18:57:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_reset
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Stop, reset, re-initialize, and restart the ENCX24J600. This is done
|
|
|
|
* initially, on ifup, and after a TX timeout.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int enc_reset(FAR struct enc_driver_s *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
uint16_t regval;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Reset\n");
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
enc_wrreg(priv, ENC_EUDAST, 0x1234);
|
|
|
|
}
|
|
|
|
while (enc_rdreg(priv, ENC_EUDAST) != 0x1234);
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Wait for clock to become ready */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
ret = enc_waitreg(priv, ENC_ESTAT, ESTAT_CLKRDY, ESTAT_CLKRDY);
|
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: encx24j600 clock failed to become ready\n");
|
2013-08-25 19:21:54 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Reset the ENCX24J600 */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
enc_setethrst(priv);
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Check if EUDAST has been reset to 0 */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
regval = enc_rdreg(priv, ENC_EUDAST);
|
|
|
|
|
|
|
|
if (regval != 0x0000)
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: encx24j600 seems not to be reset properly\n");
|
2013-08-25 19:21:54 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:54:50 +01:00
|
|
|
/* Wait at least 256 μs for the PHY registers and PHY status bits to become
|
2013-08-25 19:21:54 +02:00
|
|
|
* available.
|
|
|
|
*/
|
2019-12-05 21:54:50 +01:00
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
up_udelay(256);
|
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
/* Initialize RX/TX buffers */
|
2013-09-28 17:09:00 +02:00
|
|
|
|
2013-10-11 18:57:58 +02:00
|
|
|
enc_resetbuffers(priv);
|
2013-09-28 17:09:00 +02:00
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
#if 0
|
|
|
|
/* When restarting auto-negotiation, the ESTAT_PHYLINK gets set but the link
|
|
|
|
* seems not to be ready. Because auto-negotiation is enabled by default
|
|
|
|
* (but with different PHANA_* settings) I did not investigate that further.
|
|
|
|
*/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* "Typically, when using auto-negotiation, users should write 0x05e1 to
|
|
|
|
* PHANA to advertise flow control capability."
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
enc_wrphy(priv, ENC_PHANA, PHANA_ADPAUS0 | PHANA_AD10FD | PHANA_AD10 |
|
|
|
|
PHANA_AD100FD | PHANA_AD100 | PHANA_ADIEEE0);
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Restart auto-negotiation */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
enc_wrphy(priv, ENC_PHCON1, PHCON1_RENEG);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
regval = enc_rdphy(priv, ENC_PHSTAT1);
|
|
|
|
}
|
|
|
|
while ((regval & PHSTAT1_ANDONE) != 0);
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
ninfo("Auto-negotiation completed\n");
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
#endif
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
enc_linkstatus(priv);
|
|
|
|
|
|
|
|
/* Set the maximum packet size which the controller will accept */
|
|
|
|
|
2018-07-04 22:10:40 +02:00
|
|
|
enc_wrreg(priv, ENC_MAMXFL, CONFIG_NET_ETH_PKTSIZE + 4);
|
2013-08-25 19:21:54 +02:00
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
ret = enc_waitreg(priv, ENC_ESTAT, ESTAT_PHYLNK, ESTAT_PHYLNK);
|
2014-01-21 17:21:45 +01:00
|
|
|
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
enc_linkstatus(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2013-09-25 16:26:56 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: encx24j600 failed to establish link\n");
|
2013-09-25 16:26:56 +02:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2014-01-21 17:21:45 +01:00
|
|
|
#endif
|
2013-09-25 16:26:56 +02:00
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: enc_initialize
|
2013-08-25 19:21:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the Ethernet driver. The ENCX24J600 device is assumed to be
|
|
|
|
* in the post-reset state upon entry to this function.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-08-25 19:21:54 +02:00
|
|
|
* spi - A reference to the platform's SPI driver for the ENCX24J600
|
|
|
|
* lower - The MCU-specific interrupt used to control low-level MCU
|
|
|
|
* functions (i.e., ENCX24J600 GPIO interrupts).
|
|
|
|
* devno - If more than one ENCX24J600 is supported, then this is the
|
|
|
|
* zero based number that identifies the ENCX24J600;
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; Negated errno on failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int enc_initialize(FAR struct spi_dev_s *spi,
|
|
|
|
FAR const struct enc_lower_s *lower,
|
|
|
|
unsigned int devno)
|
|
|
|
{
|
|
|
|
FAR struct enc_driver_s *priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(devno < CONFIG_ENCX24J600_NINTERFACES);
|
|
|
|
priv = &g_encx24j600[devno];
|
|
|
|
|
|
|
|
/* Initialize the driver structure */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
memset(g_encx24j600, 0,
|
|
|
|
CONFIG_ENCX24J600_NINTERFACES * sizeof(struct enc_driver_s));
|
|
|
|
|
2016-11-29 23:44:23 +01:00
|
|
|
priv->dev.d_buf = g_pktbuf; /* Single packet buffer */
|
2013-08-25 19:21:54 +02:00
|
|
|
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 */
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2013-08-25 19:21:54 +02:00
|
|
|
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 */
|
|
|
|
|
2018-01-22 15:17:31 +01:00
|
|
|
/* Create a watchdog for timing polling for and timing of transmissions */
|
2013-08-25 19:21:54 +02:00
|
|
|
|
|
|
|
priv->txpoll = wd_create(); /* Create periodic poll timer */
|
|
|
|
priv->txtimeout = wd_create(); /* Create TX timeout timer */
|
|
|
|
priv->spi = spi; /* Save the SPI instance */
|
|
|
|
priv->lower = lower; /* Save the low-level MCU interface */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* The interface should be in the down state. However, this function is
|
2019-08-21 17:32:59 +02:00
|
|
|
* called too early in initialization to perform the ENCX24J600 reset in
|
2019-02-24 18:51:25 +01:00
|
|
|
* enc_ifdown. We are depending upon the fact that the application level
|
|
|
|
* logic will call enc_ifdown later to reset the ENCX24J600.
|
2013-08-25 19:21:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
priv->ifstate = ENCSTATE_UNINIT;
|
|
|
|
|
|
|
|
/* Attach the interrupt to the driver (but don't enable it yet) */
|
|
|
|
|
2017-08-22 00:23:22 +02:00
|
|
|
if (lower->attach(lower, enc_interrupt, priv) < 0)
|
2013-08-25 19:21:54 +02:00
|
|
|
{
|
|
|
|
/* We could not attach the ISR to the interrupt */
|
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Lock the SPI bus so that we have exclusive access */
|
|
|
|
|
|
|
|
enc_lock(priv);
|
|
|
|
|
|
|
|
/* Load the MAC address */
|
|
|
|
|
|
|
|
enc_ldmacaddr(priv);
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* Power down the device */
|
|
|
|
|
|
|
|
enc_pwrsave(priv);
|
|
|
|
|
2013-09-25 16:26:56 +02:00
|
|
|
/* Unlock the SPI bus */
|
|
|
|
|
|
|
|
enc_unlock(priv);
|
|
|
|
|
2013-08-25 19:21:54 +02:00
|
|
|
/* Register the device with the OS so that socket IOCTLs can be performed */
|
|
|
|
|
2014-11-15 15:22:51 +01:00
|
|
|
return netdev_register(&priv->dev, NET_LL_ETHERNET);
|
2013-08-25 19:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_ENCX24J600_NET */
|