2007-11-02 21:10:33 +01:00
|
|
|
/****************************************************************************
|
2016-12-03 18:42:15 +01:00
|
|
|
* drivers/net/dm90x0.c
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
2018-11-21 14:57:26 +01:00
|
|
|
* Copyright (C) 2007-2010, 2014-2016, 2018 Gregory Nutt. All rights
|
|
|
|
* reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* References: Davicom data sheets (DM9000-DS-F03-041906.pdf,
|
|
|
|
* DM9010-DS-F01-103006.pdf) and looking at lots of other DM90x0
|
|
|
|
* drivers.
|
|
|
|
*
|
|
|
|
* 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_NET_DM90x0)
|
|
|
|
|
2007-11-06 00:04:16 +01:00
|
|
|
/* Only one hardware interface supported at present (although there are
|
2007-11-03 00:05:53 +01:00
|
|
|
* hooks throughout the design to that extending the support to multiple
|
|
|
|
* interfaces should not be that difficult)
|
|
|
|
*/
|
2007-11-02 21:33:42 +01:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
#undef CONFIG_DM9X_NINTERFACES
|
|
|
|
#define CONFIG_DM9X_NINTERFACES 1
|
|
|
|
|
2009-12-15 15:25:14 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2007-11-02 21:10:33 +01:00
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
#include <nuttx/arch.h>
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/wdog.h>
|
2016-12-03 23:28:19 +01:00
|
|
|
#include <nuttx/wqueue.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>
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2015-01-20 22:14:29 +01:00
|
|
|
#ifdef CONFIG_NET_PKT
|
|
|
|
# include <nuttx/net/pkt.h>
|
|
|
|
#endif
|
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
/****************************************************************************
|
2015-04-08 15:15:32 +02:00
|
|
|
* Pre-processor Definitions
|
2007-11-02 21:10:33 +01:00
|
|
|
****************************************************************************/
|
2019-12-05 21:54:50 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
/* If processing is not done at the interrupt level, then work queue support
|
|
|
|
* is required.
|
|
|
|
*/
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
#if !defined(CONFIG_SCHED_WORKQUEUE)
|
2016-12-03 18:42:15 +01:00
|
|
|
# error Work queue support is required in this configuration (CONFIG_SCHED_WORKQUEUE)
|
2018-11-21 14:57:26 +01:00
|
|
|
#endif
|
2016-12-03 18:42:15 +01:00
|
|
|
|
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!
|
|
|
|
*/
|
2016-12-03 18:42:15 +01:00
|
|
|
|
2018-11-21 14:57:26 +01:00
|
|
|
#define ETHWORK LPWORK
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2018-11-21 14:57:26 +01:00
|
|
|
/* DM90000 and DM9010 register offsets */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
#define DM9X_NETC 0x00 /* Network control register */
|
|
|
|
#define DM9X_NETS 0x01 /* Network Status register */
|
|
|
|
#define DM9X_TXC 0x02 /* TX control register */
|
|
|
|
#define DM9X_TXS1 0x03 /* TX status register 1 */
|
|
|
|
#define DM9X_TXS2 0x03 /* TX status register 2 */
|
|
|
|
#define DM9X_RXC 0x05 /* RX control register */
|
|
|
|
#define DM9X_RXS 0x06 /* RX status register */
|
|
|
|
#define DM9X_RXOVF 0x07 /* Receive overflow counter register */
|
|
|
|
#define DM9X_BPTHRES 0x08 /* Back pressure threshold register */
|
|
|
|
#define DM9X_FCTHRES 0x09 /* Flow control threshold register */
|
|
|
|
#define DM9X_FC 0x0a /* RX/TX flow control register */
|
|
|
|
#define DM9X_EEPHYC 0x0b /* EEPROM & PHY control register */
|
|
|
|
#define DM9X_EEPHYA 0x0c /* EEPROM & PHY address register */
|
|
|
|
#define DM9X_EEPHYDL 0x0d /* EEPROM & PHY data register (lo) */
|
|
|
|
#define DM9X_EEPHYDH 0x0e /* EEPROM & PHY data register (hi) */
|
|
|
|
#define DM9X_WAKEUP 0x0f /* Wake-up control register */
|
|
|
|
#define DM9X_PAB0 0x10 /* Physical address register (byte 0) */
|
|
|
|
#define DM9X_PAB1 0x11 /* Physical address register (byte 1) */
|
|
|
|
#define DM9X_PAB2 0x12 /* Physical address register (byte 2) */
|
|
|
|
#define DM9X_PAB3 0x13 /* Physical address register (byte 3) */
|
|
|
|
#define DM9X_PAB4 0x14 /* Physical address register (byte 4) */
|
|
|
|
#define DM9X_PAB5 0x15 /* Physical address register (byte 5) */
|
|
|
|
#define DM9X_MAB0 0x16 /* Multicast address register (byte 0) */
|
|
|
|
#define DM9X_MAB1 0x17 /* Multicast address register (byte 1) */
|
|
|
|
#define DM9X_MAB2 0x18 /* Multicast address register (byte 2) */
|
|
|
|
#define DM9X_MAB3 0x19 /* Multicast address register (byte 3) */
|
|
|
|
#define DM9X_MAB4 0x1a /* Multicast address register (byte 4) */
|
|
|
|
#define DM9X_MAB5 0x1b /* Multicast address register (byte 5) */
|
|
|
|
#define DM9X_MAB6 0x1c /* Multicast address register (byte 6) */
|
|
|
|
#define DM9X_MAB7 0x1d /* Multicast address register (byte 7) */
|
|
|
|
#define DM9X_GPC 0x1e /* General purpose control register */
|
|
|
|
#define DM9X_GPD 0x1f /* General purpose register */
|
|
|
|
|
|
|
|
#define DM9X_TRPAL 0x22 /* TX read pointer address (lo) */
|
|
|
|
#define DM9X_TRPAH 0x23 /* TX read pointer address (hi) */
|
|
|
|
#define DM9X_RWPAL 0x24 /* RX write pointer address (lo) */
|
|
|
|
#define DM9X_RWPAH 0x25 /* RX write pointer address (hi) */
|
|
|
|
|
|
|
|
#define DM9X_VIDL 0x28 /* Vendor ID (lo) */
|
|
|
|
#define DM9X_VIDH 0x29 /* Vendor ID (hi) */
|
|
|
|
#define DM9X_PIDL 0x2a /* Product ID (lo) */
|
|
|
|
#define DM9X_PIDH 0x2b /* Product ID (hi) */
|
|
|
|
#define DM9X_CHIPR 0x2c /* Product ID (lo) */
|
|
|
|
#define DM9X_TXC2 0x2d /* Transmit control register 2 (dm9010) */
|
|
|
|
#define DM9X_OTC 0x2e /* Operation test control register (dm9010) */
|
|
|
|
#define DM9X_SMODEC 0x2f /* Special mode control register */
|
|
|
|
#define DM9X_ETXCSR 0x30 /* Early transmit control/status register (dm9010) */
|
|
|
|
#define DM9X_TCCR 0x31 /* Transmit checksum control register (dm9010) */
|
|
|
|
#define DM9X_RCSR 0x32 /* Receive checksum control/status register (dm9010) */
|
|
|
|
#define DM9X_EPHYA 0x33 /* External PHY address register (dm9010) */
|
|
|
|
#define DM9X_GPC2 0x34 /* General purpose control register 2 (dm9010) */
|
|
|
|
#define DM9X_GPD2 0x35 /* General purpose register 2 */
|
|
|
|
#define DM9X_GPC3 0x36 /* General purpose control register 3 (dm9010) */
|
|
|
|
#define DM9X_GPD3 0x37 /* General purpose register 3 */
|
|
|
|
#define DM9X_PBUSC 0x38 /* Processor bus control register (dm9010) */
|
|
|
|
#define DM9X_IPINC 0x39 /* INT pin control register (dm9010) */
|
|
|
|
|
|
|
|
#define DM9X_MON1 0x40 /* Monitor register 1 (dm9010) */
|
|
|
|
#define DM9X_MON2 0x41 /* Monitor register 2 (dm9010) */
|
|
|
|
|
|
|
|
#define DM9X_SCLKC 0x50 /* System clock turn ON control register (dm9010) */
|
|
|
|
#define DM9X_SCLKR 0x51 /* Resume system clock control register (dm9010) */
|
|
|
|
|
|
|
|
#define DM9X_MRCMDX 0xf0 /* Memory data pre-fetch read command without address increment */
|
|
|
|
#define DM9X_MRCMDX1 0xf1 /* memory data read command without address increment (dm9010) */
|
|
|
|
#define DM9X_MRCMD 0xf2 /* Memory data read command with address increment */
|
|
|
|
#define DM9X_MDRAL 0xf4 /* Memory data read address register (lo) */
|
|
|
|
#define DM9X_MDRAH 0xf5 /* Memory data read address register (hi) */
|
|
|
|
#define DM9X_MWCMDX 0xf6 /* Memory data write command without address increment */
|
|
|
|
#define DM9X_MWCMD 0xf8 /* Memory data write command with address increment */
|
|
|
|
#define DM9X_MDWAL 0xfa /* Memory data write address register (lo) */
|
|
|
|
#define DM9X_MDWAH 0xfb /* Memory data write address register (lo) */
|
|
|
|
#define DM9X_TXPLL 0xfc /* Memory data write address register (lo) */
|
|
|
|
#define DM9X_TXPLH 0xfd /* Memory data write address register (hi) */
|
|
|
|
#define DM9X_ISR 0xfe /* Interrupt status register */
|
|
|
|
#define DM9X_IMR 0xff /* Interrupt mask register */
|
|
|
|
|
|
|
|
/* Network control register bit definitions */
|
|
|
|
|
|
|
|
#define DM9X_NETC_RST (1 << 0) /* Software reset */
|
|
|
|
#define DM9X_NETC_LBKM (3 << 1) /* Loopback mode mask */
|
|
|
|
#define DM9X_NETC_LBK0 (0 << 1) /* 0: Normal */
|
|
|
|
#define DM9X_NETC_LBK1 (1 << 1) /* 1: MAC internal loopback */
|
|
|
|
#define DM9X_NETC_LBK2 (2 << 1) /* 2: Internal PHY 100M mode loopback */
|
|
|
|
#define DM9X_NETC_FDX (1 << 3) /* Full dupliex mode */
|
|
|
|
#define DM9X_NETC_FCOL (1 << 4) /* Force collision mode */
|
|
|
|
#define DM9X_NETC_WAKEEN (1 << 6) /* Wakeup event enable */
|
|
|
|
#define DM9X_NETC_EXTPHY (1 << 7) /* Select external PHY */
|
|
|
|
|
|
|
|
/* Network status bit definitions */
|
|
|
|
|
|
|
|
#define DM9X_NETS_RXOV (1 << 1) /* RX Fifo overflow */
|
|
|
|
#define DM9X_NETS_TX1END (1 << 2) /* TX packet 1 complete status */
|
|
|
|
#define DM9X_NETS_TX2END (1 << 3) /* TX packet 2 complete status */
|
|
|
|
#define DM9X_NETS_WAKEST (1 << 5) /* Wakeup event status */
|
|
|
|
#define DM9X_NETS_LINKST (1 << 6) /* Link status */
|
|
|
|
#define DM9X_NETS_SPEED (1 << 7) /* Media speed */
|
|
|
|
|
|
|
|
/* IMR/ISR bit definitions */
|
|
|
|
|
|
|
|
#define DM9X_INT_PR (1 << 0) /* Packet received interrupt */
|
|
|
|
#define DM9X_INT_PT (1 << 1) /* Packet transmitted interrupt */
|
|
|
|
#define DM9X_INT_RO (1 << 2) /* Receive overflow interrupt */
|
|
|
|
#define DM9X_INT_ROO (1 << 3) /* Receive overflow counter overflow int */
|
|
|
|
#define DM9X_INT_UDRUN (1 << 4) /* Transmit underrun interrupt */
|
|
|
|
#define DM9X_INT_LNKCHG (1 << 5) /* Link status change interrupt */
|
|
|
|
#define DM9X_INT_ALL (0x3f)
|
|
|
|
|
|
|
|
#define DM9X_IMR_UNUSED (1 << 6) /* (not used) */
|
|
|
|
#define DM9X_IMR_PAR (1 << 7) /* Enable auto R/W pointer reset */
|
|
|
|
|
|
|
|
#define DM9X_ISR_IOMODEM (3 << 6) /* IO mode mask */
|
|
|
|
#define DM9X_ISR_IOMODE8 (2 << 6) /* IO mode = 8 bit */
|
|
|
|
#define DM9X_ISR_IOMODE16 (0 << 6) /* IO mode = 16 bit */
|
|
|
|
#define DM9X_ISR_IOMODE32 (1 << 6) /* IO mode = 32 bit */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
#define DM9X_IMRENABLE (DM9X_INT_PR | DM9X_INT_PT | DM9X_INT_LNKCHG | DM9X_IMR_PAR)
|
|
|
|
#define DM9X_IMRRXDISABLE (DM9X_INT_PT | DM9X_INT_LNKCHG | DM9X_IMR_PAR)
|
2007-11-02 21:10:33 +01:00
|
|
|
#define DM9X_IMRDISABLE (DM9X_IMR_PAR)
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* EEPROM/PHY control register bits */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
#define DM9X_EEPHYC_ERRE (1 << 0) /* EEPROM (vs PHY) access status */
|
|
|
|
#define DM9X_EEPHYC_ERPRW (1 << 1) /* EEPROM/PHY write access */
|
|
|
|
#define DM9X_EEPHYC_ERPRR (1 << 2) /* EEPROM/PHY read access */
|
|
|
|
#define DM9X_EEPHYC_EPOS (1 << 3) /* EEPROM/PHY operation select */
|
|
|
|
#define DM9X_EEPHYC_WEP (1 << 4) /* Write EEPROM enable */
|
|
|
|
#define DM9X_EEPHYC_REEP (1 << 5) /* Reload EEPROM */
|
|
|
|
|
|
|
|
/* Supported values from the vendor and product ID register */
|
|
|
|
|
|
|
|
#define DM9X_DAVICOMVID 0x0a46
|
|
|
|
#define DM9X_DM9000PID 0x9000
|
|
|
|
#define DM9X_DM9010PID 0x9010
|
|
|
|
|
|
|
|
/* RX control register bit settings */
|
|
|
|
|
|
|
|
#define DM9X_RXC_RXEN (1 << 0) /* RX enable */
|
|
|
|
#define DM9X_RXC_PRMSC (1 << 1) /* Promiscuous mode */
|
|
|
|
#define DM9X_RXC_RUNT (1 << 2) /* Pass runt packet */
|
|
|
|
#define DM9X_RXC_ALL (1 << 3) /* Pass all multicast */
|
|
|
|
#define DM9X_RXC_DISCRC (1 << 4) /* Discard CRC error packets */
|
|
|
|
#define DM9X_RXC_DISLONG (1 << 5) /* Discard long packets */
|
|
|
|
#define DM9X_RXC_WTDIS (1 << 6) /* Disable watchdog timer */
|
|
|
|
#define DM9X_RXC_HASHALL (1 << 7) /* Filter all addresses in hash table */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
#define DM9X_RXCSETUP (DM9X_RXC_DISCRC | DM9X_RXC_DISLONG)
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* EEPHY bit settings */
|
|
|
|
|
|
|
|
#define DM9X_EEPHYA_EROA 0x40 /* PHY register address 0x01 */
|
|
|
|
|
|
|
|
#define DM9X_PKTRDY 0x01 /* Packet ready to receive */
|
|
|
|
|
|
|
|
/* The RX interrupt will be disabled if more than the following RX
|
|
|
|
* interrupts are received back-to-back.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DM9X_CRXTHRES 10
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* All access is via an index register and a data register. Select accecss
|
2007-11-02 21:10:33 +01:00
|
|
|
* according to user supplied base address and bus width.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(CONFIG_DM9X_BUSWIDTH8)
|
2009-12-15 15:25:14 +01:00
|
|
|
# define DM9X_INDEX *(volatile uint8_t*)(CONFIG_DM9X_BASE)
|
|
|
|
# define DM9X_DATA *(volatile uint8_t*)(CONFIG_DM9X_BASE + 2)
|
2007-11-02 21:10:33 +01:00
|
|
|
#elif defined(CONFIG_DM9X_BUSWIDTH16)
|
2009-12-15 15:25:14 +01:00
|
|
|
# define DM9X_INDEX *(volatile uint16_t*)(CONFIG_DM9X_BASE)
|
|
|
|
# define DM9X_DATA *(volatile uint16_t*)(CONFIG_DM9X_BASE + 2)
|
2007-11-02 21:10:33 +01:00
|
|
|
#elif defined(CONFIG_DM9X_BUSWIDTH32)
|
2009-12-15 15:25:14 +01:00
|
|
|
# define DM9X_INDEX *(volatile uint32_t*)(CONFIG_DM9X_BASE)
|
|
|
|
# define DM9X_DATA *(volatile uint32_t*)(CONFIG_DM9X_BASE + 2)
|
2007-11-02 21:10:33 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Phy operating mode. Default is AUTO, but this setting can be overridden
|
|
|
|
* in the NuttX configuration file.
|
|
|
|
*/
|
|
|
|
|
2014-03-05 19:16:02 +01:00
|
|
|
#if !defined(CONFIG_DM9X_MODE_AUTO) && !defined(CONFIG_DM9X_MODE_10MHD) && \
|
|
|
|
!defined(CONFIG_DM9X_MODE_100MHD) && !defined(CONFIG_DM9X_MODE_10MFD) && \
|
|
|
|
!defined(CONFIG_DM9X_MODE_100MFD)
|
|
|
|
# define CONFIG_DM9X_MODE_AUTO 1
|
2007-11-02 21:10:33 +01:00
|
|
|
#endif
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* TX poll deley = 1 seconds.
|
|
|
|
* CLK_TCK is the number of clock ticks per second
|
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
#define DM9X_WDDELAY (1*CLK_TCK)
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-03 00:22:48 +01:00
|
|
|
/* TX timeout = 1 minute */
|
|
|
|
|
|
|
|
#define DM6X_TXTIMEOUT (60*CLK_TCK)
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* This is a helper pointer for accessing the contents of Ethernet header */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
#define BUF ((struct eth_hdr_s *)priv->dm_dev.d_buf)
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
union rx_desc_u
|
|
|
|
{
|
2009-12-16 21:59:06 +01:00
|
|
|
uint8_t rx_buf[4];
|
2007-11-02 21:10:33 +01:00
|
|
|
struct
|
|
|
|
{
|
2009-12-16 21:59:06 +01:00
|
|
|
uint8_t rx_byte;
|
|
|
|
uint8_t rx_status;
|
2009-12-15 15:25:14 +01:00
|
|
|
uint16_t rx_len;
|
2007-11-02 21:10:33 +01:00
|
|
|
} desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The dm9x_driver_s encapsulates all DM90x0 state information for a single
|
|
|
|
* DM90x0 hardware interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct dm9x_driver_s
|
|
|
|
{
|
2009-12-15 15:25:14 +01:00
|
|
|
bool dm_bifup; /* true:ifup false:ifdown */
|
2019-12-05 21:54:50 +01:00
|
|
|
bool dm_b100m; /* true:speed == 100M; false:speed == 10M */
|
2009-12-15 15:25:14 +01:00
|
|
|
uint8_t dm_ntxpending; /* Count of packets pending transmission */
|
|
|
|
uint8_t ncrxpackets; /* Number of continuous rx packets */
|
2020-08-04 12:31:31 +02:00
|
|
|
struct wdog_s dm_txpoll; /* TX poll timer */
|
|
|
|
struct wdog_s dm_txtimeout; /* TX timeout timer */
|
2017-03-03 21:45:09 +01:00
|
|
|
struct work_s dm_irqwork; /* For deferring interrupt work to the work queue */
|
|
|
|
struct work_s dm_pollwork; /* For deferring poll work to the work queue */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Mode-dependent function to move data in 8/16/32 I/O modes */
|
|
|
|
|
2009-12-16 21:59:06 +01:00
|
|
|
void (*dm_read)(uint8_t *ptr, int len);
|
|
|
|
void (*dm_write)(const uint8_t *ptr, int len);
|
2007-11-06 17:17:50 +01:00
|
|
|
void (*dm_discard)(int len);
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* This holds the information visible to the NuttX network */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
struct net_driver_s dm_dev;
|
2007-11-02 21:10:33 +01: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
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
/* At present, only a single DM90x0 device is supported. */
|
|
|
|
|
|
|
|
static struct dm9x_driver_s g_dm9x[CONFIG_DM9X_NINTERFACES];
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Utility functions */
|
|
|
|
|
2009-12-16 21:59:06 +01:00
|
|
|
static uint8_t getreg(int reg);
|
|
|
|
static void putreg(int reg, uint8_t value);
|
|
|
|
static void read8(uint8_t *ptr, int len);
|
|
|
|
static void read16(uint8_t *ptr, int len);
|
|
|
|
static void read32(uint8_t *ptr, int len);
|
2007-11-02 21:10:33 +01:00
|
|
|
static void discard8(int len);
|
|
|
|
static void discard16(int len);
|
|
|
|
static void discard32(int len);
|
2009-12-16 21:59:06 +01:00
|
|
|
static void write8(const uint8_t *ptr, int len);
|
|
|
|
static void write16(const uint8_t *ptr, int len);
|
|
|
|
static void write32(const uint8_t *ptr, int len);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
#if 0 /* Not used */
|
|
|
|
static uint16_t dm9x_readsrom(FAR struct dm9x_driver_s *priv, int offset);
|
|
|
|
#endif
|
|
|
|
static uint16_t dm9x_phyread(FAR struct dm9x_driver_s *priv, int reg);
|
|
|
|
static void dm9x_phywrite(FAR struct dm9x_driver_s *priv, int reg,
|
|
|
|
uint16_t value);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
#if defined(CONFIG_DM9X_CHECKSUM)
|
2009-12-15 15:25:14 +01:00
|
|
|
static bool dm9x_rxchecksumready(uint8_t);
|
2007-11-02 21:10:33 +01:00
|
|
|
#else
|
|
|
|
# define dm9x_rxchecksumready(a) ((a) == 0x01)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Common TX logic */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_transmit(FAR struct dm9x_driver_s *priv);
|
|
|
|
static int dm9x_txpoll(FAR struct net_driver_s *dev);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Interrupt handling */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static void dm9x_receive(FAR struct dm9x_driver_s *priv);
|
|
|
|
static void dm9x_txdone(FAR struct dm9x_driver_s *priv);
|
2016-12-03 18:42:15 +01:00
|
|
|
|
|
|
|
static void dm9x_interrupt_work(FAR void *arg);
|
2017-02-27 13:27:56 +01:00
|
|
|
static int dm9x_interrupt(int irq, FAR void *context, FAR void *arg);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Watchdog timer expirations */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
static void dm9x_txtimeout_work(FAR void *arg);
|
2020-08-09 20:29:35 +02:00
|
|
|
static void dm9x_txtimeout_expiry(wdparm_t arg);
|
2016-12-03 18:42:15 +01:00
|
|
|
|
|
|
|
static void dm9x_poll_work(FAR void *arg);
|
2020-08-09 20:29:35 +02:00
|
|
|
static void dm9x_poll_expiry(wdparm_t arg);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* NuttX callback functions */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_ifup(FAR struct net_driver_s *dev);
|
|
|
|
static int dm9x_ifdown(FAR struct net_driver_s *dev);
|
2016-12-03 18:42:15 +01:00
|
|
|
|
|
|
|
static void dm9x_txavail_work(FAR void *arg);
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_txavail(FAR struct net_driver_s *dev);
|
2016-12-03 18:42:15 +01:00
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac);
|
|
|
|
static int dm9x_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac);
|
2010-07-11 17:17:11 +02:00
|
|
|
#endif
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Initialization functions */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static void dm9x_bringup(FAR struct dm9x_driver_s *priv);
|
|
|
|
static void dm9x_reset(FAR struct dm9x_driver_s *priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: getreg and setreg
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Access to memory-mapped DM90x0 8-bit registers
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* reg - Register number
|
|
|
|
* value - Value to write to the register (setreg only)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Value read from the register (getreg only)
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-12-16 21:59:06 +01:00
|
|
|
static uint8_t getreg(int reg)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
DM9X_INDEX = reg;
|
|
|
|
return DM9X_DATA & 0xff;
|
|
|
|
}
|
|
|
|
|
2009-12-16 21:59:06 +01:00
|
|
|
static void putreg(int reg, uint8_t value)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2007-11-04 17:31:24 +01:00
|
|
|
DM9X_INDEX = reg;
|
|
|
|
DM9X_DATA = value & 0xff;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: read8, read16, read32
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read packet data from the DM90x0 SRAM based on its current I/O mode
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* ptr - Location to write the packet data
|
|
|
|
* len - The number of bytes to read
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
static void read8(FAR uint8_t *ptr, int len)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Read %d bytes (8-bit mode)\n", len);
|
2007-11-02 21:10:33 +01:00
|
|
|
for (; len > 0; len--)
|
|
|
|
{
|
|
|
|
*ptr++ = DM9X_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
static void read16(FAR uint8_t *ptr, int len)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR uint16_t *ptr16 = (FAR uint16_t *)ptr;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Read %d bytes (16-bit mode)\n", len);
|
2009-12-15 15:25:14 +01:00
|
|
|
for (; len > 0; len -= sizeof(uint16_t))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
*ptr16++ = DM9X_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-10 20:24:31 +02:00
|
|
|
static void read32(FAR uint8_t *ptr, int len)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR uint32_t *ptr32 = (FAR uint32_t *)ptr;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Read %d bytes (32-bit mode)\n", len);
|
2009-12-15 15:25:14 +01:00
|
|
|
for (; len > 0; len -= sizeof(uint32_t))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
*ptr32++ = DM9X_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: discard8, discard16, discard32
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read and discard packet data in the DM90x0 SRAM based on its current
|
|
|
|
* I/O mode
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* len - The number of bytes to discard
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void discard8(int len)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Discard %d bytes (8-bit mode)\n", len);
|
2007-11-02 21:10:33 +01:00
|
|
|
for (; len > 0; len--)
|
|
|
|
{
|
|
|
|
DM9X_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void discard16(int len)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Discard %d bytes (16-bit mode)\n", len);
|
2009-12-15 15:25:14 +01:00
|
|
|
for (; len > 0; len -= sizeof(uint16_t))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
DM9X_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void discard32(int len)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Discard %d bytes (32-bit mode)\n", len);
|
2009-12-15 15:25:14 +01:00
|
|
|
for (; len > 0; len -= sizeof(uint32_t))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
DM9X_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: write8, write16, write32
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write packet data into the DM90x0 SRAM based on its current I/O mode
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* ptr - Location to write the packet data
|
|
|
|
* len - The number of bytes to read
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
static void write8(FAR const uint8_t *ptr, int len)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Write %d bytes (8-bit mode)\n", len);
|
2015-10-10 18:41:00 +02:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
for (; len > 0; len--)
|
|
|
|
{
|
2007-11-04 23:59:30 +01:00
|
|
|
DM9X_DATA = (*ptr++ & 0xff);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-16 21:59:06 +01:00
|
|
|
static void write16(const uint8_t *ptr, int len)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR uint16_t *ptr16 = (FAR uint16_t *)ptr;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Write %d bytes (16-bit mode)\n", len);
|
2007-11-04 23:59:30 +01:00
|
|
|
|
2009-12-15 15:25:14 +01:00
|
|
|
for (; len > 0; len -= sizeof(uint16_t))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
DM9X_DATA = *ptr16++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
static void write32(FAR const uint8_t *ptr, int len)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR uint32_t *ptr32 = (FAR uint32_t *)ptr;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Write %d bytes (32-bit mode)\n", len);
|
2015-10-10 18:41:00 +02:00
|
|
|
|
2009-12-15 15:25:14 +01:00
|
|
|
for (; len > 0; len -= sizeof(uint32_t))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
DM9X_DATA = *ptr32++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_readsrom
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read a word from SROM
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
* offset - SROM offset to read from
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* SROM content at that offset
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if 0 /* Not used */
|
2019-02-24 18:51:25 +01:00
|
|
|
static uint16_t dm9x_readsrom(FAR struct dm9x_driver_s *priv, int offset)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
putreg(DM9X_EEPHYA, offset);
|
|
|
|
putreg(DM9X_EEPHYC, DM9X_EEPHYC_ERPRR);
|
|
|
|
up_udelay(200);
|
|
|
|
putreg(DM9X_EEPHYC, 0x00);
|
2015-10-10 18:41:00 +02:00
|
|
|
return (getreg(DM9X_EEPHYDL) + (getreg(DM9X_EEPHYDH) << 8));
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_phyread and dm9x_phywrite
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read/write data from/to the PHY
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
* reg - PHY register offset
|
|
|
|
* value - The value to write to the PHY register (dm9x_write only)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The value read from the PHY (dm9x_read only)
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static uint16_t dm9x_phyread(FAR struct dm9x_driver_s *priv, int reg)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
/* Setup DM9X_EEPHYA, the EEPROM/PHY address register */
|
|
|
|
|
|
|
|
putreg(DM9X_EEPHYA, DM9X_EEPHYA_EROA | reg);
|
|
|
|
|
|
|
|
/* Issue PHY read command pulse in the EEPROM/PHY control register */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
putreg(DM9X_EEPHYC, (DM9X_EEPHYC_ERPRR | DM9X_EEPHYC_EPOS));
|
2007-11-02 21:10:33 +01:00
|
|
|
up_udelay(100);
|
|
|
|
putreg(DM9X_EEPHYC, 0x00);
|
|
|
|
|
|
|
|
/* Return the data from the EEPROM/PHY data register pair */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
return (((uint16_t)getreg(DM9X_EEPHYDH)) << 8) |
|
|
|
|
(uint16_t)getreg(DM9X_EEPHYDL);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static void dm9x_phywrite(FAR struct dm9x_driver_s *priv, int reg,
|
|
|
|
uint16_t value)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
/* Setup DM9X_EEPHYA, the EEPROM/PHY address register */
|
|
|
|
|
|
|
|
putreg(DM9X_EEPHYA, DM9X_EEPHYA_EROA | reg);
|
|
|
|
|
|
|
|
/* Put the data to write in the EEPROM/PHY data register pair */
|
|
|
|
|
|
|
|
putreg(DM9X_EEPHYDL, (value & 0xff));
|
|
|
|
putreg(DM9X_EEPHYDH, ((value >> 8) & 0xff));
|
|
|
|
|
|
|
|
/* Issue PHY write command pulse in the EEPROM/PHY control register */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
putreg(DM9X_EEPHYC, (DM9X_EEPHYC_ERPRW | DM9X_EEPHYC_EPOS));
|
2007-11-02 21:10:33 +01:00
|
|
|
up_udelay(500);
|
|
|
|
putreg(DM9X_EEPHYC, 0x0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_rxchecksumready
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2009-12-15 15:25:14 +01:00
|
|
|
* Return true if the RX checksum is available
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* rxbyte
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2009-12-15 15:25:14 +01:00
|
|
|
* true: checksum is ready
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_DM9X_CHECKSUM)
|
2009-12-16 21:59:06 +01:00
|
|
|
static inline bool dm9x_rxchecksumready(uint8_t rxbyte)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
if ((rxbyte & 0x01) == 0)
|
|
|
|
{
|
2009-12-15 15:25:14 +01:00
|
|
|
return false;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ((rxbyte >> 4) | 0x01) != 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_transmit
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start hardware transmission. Called either from the txdone interrupt
|
|
|
|
* handling or from watchdog based polling.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_transmit(FAR struct dm9x_driver_s *priv)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2019-02-24 18:51:25 +01:00
|
|
|
/* Check if there is room in the DM90x0 to hold another packet. In 100M
|
|
|
|
* mode, that can be 2 packets, otherwise it is a single packet.
|
2007-11-17 15:28:10 +01:00
|
|
|
*/
|
|
|
|
|
2019-12-05 21:54:50 +01:00
|
|
|
if (priv->dm_ntxpending < 1 || (priv->dm_b100m && priv->dm_ntxpending < 2))
|
2007-11-17 15:28:10 +01:00
|
|
|
{
|
|
|
|
/* Increment count of packets transmitted */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_ntxpending++;
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_TXPACKETS(&dm9x0->dm_dev);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
/* Disable all DM90x0 interrupts */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
putreg(DM9X_IMR, DM9X_IMRDISABLE);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
/* Set the TX length */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
putreg(DM9X_TXPLL, (priv->dm_dev.d_len & 0xff));
|
|
|
|
putreg(DM9X_TXPLH, (priv->dm_dev.d_len >> 8) & 0xff);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
/* Move the data to be sent into TX SRAM */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
DM9X_INDEX = DM9X_MWCMD;
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_write(priv->dm_dev.d_buf, priv->dm_dev.d_len);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
#if !defined(CONFIG_DM9X_ETRANS)
|
2007-11-17 15:28:10 +01:00
|
|
|
/* Issue TX polling command */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
putreg(DM9X_TXC, 0x1); /* Cleared after TX complete */
|
2007-11-02 21:10:33 +01:00
|
|
|
#endif
|
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
/* Clear count of back-to-back RX packet transfers */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->ncrxpackets = 0;
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
/* Re-enable DM90x0 interrupts */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
putreg(DM9X_IMR, DM9X_IMRENABLE);
|
2007-11-03 00:22:48 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
/* Setup the TX timeout watchdog (perhaps restarting the timer) */
|
2007-11-03 00:22:48 +01:00
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_start(&priv->dm_txtimeout, DM6X_TXTIMEOUT,
|
2020-08-09 20:29:35 +02:00
|
|
|
dm9x_txtimeout_expiry, (wdparm_t)priv);
|
2007-11-17 15:28:10 +01:00
|
|
|
return OK;
|
|
|
|
}
|
2019-02-24 18:51:25 +01:00
|
|
|
|
2007-11-17 15:28:10 +01:00
|
|
|
return -EBUSY;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_txpoll
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2019-02-24 18:51:25 +01:00
|
|
|
* The transmitter is available, check if the network has any outgoing
|
|
|
|
* packets ready to send. This is a callback from devif_poll().
|
|
|
|
* devif_poll() may be called:
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* 1. When the preceding TX packet send is complete,
|
|
|
|
* 2. When the preceding TX packet send timesout and the DM90x0 is reset
|
|
|
|
* 3. During normal TX polling
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-22 15:42:52 +01:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_txpoll(FAR struct net_driver_s *dev)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct dm9x_driver_s *priv =
|
|
|
|
(FAR struct dm9x_driver_s *)dev->d_private;
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-06 00:04:16 +01: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.
|
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_dev.d_len > 0)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
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
|
2016-12-03 18:42:15 +01:00
|
|
|
if (IFF_IS_IPv4(priv->dm_dev.d_flags))
|
2015-01-21 18:36:33 +01:00
|
|
|
#endif
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
arp_out(&priv->dm_dev);
|
2015-01-21 18:36:33 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
neighbor_out(&priv->dm_dev);
|
2015-01-21 18:36:33 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
|
|
|
|
2018-08-25 16:33:21 +02:00
|
|
|
if (!devif_loopback(&priv->dm_dev))
|
2018-08-24 17:21:33 +02:00
|
|
|
{
|
|
|
|
/* Send the packet */
|
2015-01-21 18:36:33 +01:00
|
|
|
|
2018-08-24 17:21:33 +02:00
|
|
|
dm9x_transmit(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* Check if there is room in the DM90x0 to hold another packet.
|
|
|
|
* In 100M mode, that can be 2 packets, otherwise it is a single
|
|
|
|
* packet.
|
2018-08-24 17:21:33 +02:00
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2019-12-05 21:54:50 +01:00
|
|
|
if (priv->dm_ntxpending > 1 || !priv->dm_b100m)
|
2018-08-24 17:21:33 +02:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Returning a non-zero value terminate the poll operation */
|
2007-11-03 00:05:53 +01:00
|
|
|
|
2018-08-24 17:21:33 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* If zero is returned, the polling will continue until all connections
|
|
|
|
* have been examined.
|
2007-11-06 00:04:16 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_receive
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating the availability of a new RX packet
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
static void dm9x_receive(FAR struct dm9x_driver_s *priv)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
union rx_desc_u rx;
|
2009-12-15 15:25:14 +01:00
|
|
|
bool bchecksumready;
|
|
|
|
uint8_t rxbyte;
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Packet received\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Store the value of memory data read address register */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
getreg(DM9X_MDRAH);
|
|
|
|
getreg(DM9X_MDRAL);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2014-02-11 01:08:49 +01:00
|
|
|
getreg(DM9X_MRCMDX); /* Dummy read */
|
2009-12-15 15:25:14 +01:00
|
|
|
rxbyte = (uint8_t)DM9X_DATA; /* Get the most up-to-date data */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Packet ready for receive check */
|
|
|
|
|
|
|
|
bchecksumready = dm9x_rxchecksumready(rxbyte);
|
|
|
|
if (!bchecksumready)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A packet is ready now. Get status/length */
|
|
|
|
|
|
|
|
DM9X_INDEX = DM9X_MRCMD; /* set read ptr ++ */
|
|
|
|
|
|
|
|
/* Read packet status & length */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_read((FAR uint8_t *)&rx, 4);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Check if any errors were reported by the hardware */
|
|
|
|
|
2007-11-06 17:17:50 +01:00
|
|
|
if (rx.desc.rx_status & 0xbf)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
/* Bad RX packet... update statistics */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
nerr("ERROR: Received packet with errors: %02x\n",
|
|
|
|
rx.desc.rx_status);
|
2016-12-03 18:42:15 +01:00
|
|
|
NETDEV_RXERRORS(&priv->dm_dev);
|
2015-11-26 19:08:09 +01:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
/* Drop this packet and continue to check the next packet */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_discard(rx.desc.rx_len);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Also check if the packet is a valid size for the configuration */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
else if (rx.desc.rx_len < ETH_HDRLEN ||
|
|
|
|
rx.desc.rx_len > (CONFIG_NET_ETH_PKTSIZE + 2))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-06-12 16:31:22 +02:00
|
|
|
nerr("ERROR: RX length error\n");
|
2016-12-03 18:42:15 +01:00
|
|
|
NETDEV_RXERRORS(&priv->dm_dev);
|
2015-11-26 19:08:09 +01:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
/* Drop this packet and continue to check the next packet */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_discard(rx.desc.rx_len);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Good packet...
|
|
|
|
* Copy the packet data out of SRAM and pass it one to the network
|
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_dev.d_len = rx.desc.rx_len;
|
|
|
|
priv->dm_read(priv->dm_dev.d_buf, rx.desc.rx_len);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2015-01-20 22:14:29 +01:00
|
|
|
#ifdef CONFIG_NET_PKT
|
2020-08-06 19:41:45 +02:00
|
|
|
/* When packet sockets are enabled, feed the frame into the tap */
|
2015-01-20 22:14:29 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
pkt_input(&priv->dm_dev);
|
2015-01-20 22:14:29 +01:00
|
|
|
#endif
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* We accept IP packets of the configured type and ARP packets */
|
2007-11-02 21:10:33 +01: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))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("IPv4 frame\n");
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXIPV4(&priv->dm_dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* Handle ARP on input then give the IPv4 packet to the network
|
|
|
|
* layer
|
|
|
|
*/
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
arp_ipin(&priv->dm_dev);
|
|
|
|
ipv4_input(&priv->dm_dev);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* If the above function invocation resulted in data that
|
|
|
|
* should be sent out on the network, the field d_len will
|
|
|
|
* set to a value > 0.
|
2015-10-10 18:41:00 +02:00
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_dev.d_len > 0)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Update Ethernet header with the correct MAC address */
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2016-12-03 18:42:15 +01:00
|
|
|
if (IFF_IS_IPv4(priv->dm_dev.d_flags))
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
arp_out(&priv->dm_dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
}
|
2015-01-20 22:52:25 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
else
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
neighbor_out(&priv->dm_dev);
|
2015-01-20 22:52:25 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_transmit(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
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->dm_dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
|
|
|
|
/* Give the IPv6 packet to the network layer */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
ipv6_input(&priv->dm_dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* If the above function invocation resulted in data that
|
|
|
|
* should be sent out on the network, the field d_len will
|
|
|
|
* set to a value > 0.
|
2015-10-10 18:41:00 +02:00
|
|
|
*/
|
2015-01-15 17:25:53 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_dev.d_len > 0)
|
2019-12-05 21:54:50 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Update Ethernet header with the correct MAC address */
|
2015-01-15 17:25:53 +01:00
|
|
|
|
2015-01-20 22:52:25 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2016-12-03 18:42:15 +01:00
|
|
|
if (IFF_IS_IPv4(priv->dm_dev.d_flags))
|
2015-01-15 17:25:53 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
arp_out(&priv->dm_dev);
|
2015-01-15 17:25:53 +01:00
|
|
|
}
|
2015-01-20 22:52:25 +01:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
neighbor_out(&priv->dm_dev);
|
2015-01-20 22:52:25 +01:00
|
|
|
}
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_transmit(priv);
|
2015-01-15 17:25:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
if (BUF->type == htons(ETHTYPE_ARP))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
arp_arpin(&priv->dm_dev);
|
2015-11-26 19:08:09 +01:00
|
|
|
NETDEV_RXARP(&priv->dm_dev);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* If the above function invocation resulted in data that
|
|
|
|
* should be sent out on the network, the field d_len will set
|
|
|
|
* to a value > 0.
|
2015-10-10 18:41:00 +02:00
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_dev.d_len > 0)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_transmit(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-15 17:25:53 +01:00
|
|
|
#endif
|
2015-11-26 19:08:09 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NETDEV_RXDROPPED(&priv->dm_dev);
|
|
|
|
}
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
NETDEV_RXPACKETS(&priv->dm_dev);
|
|
|
|
priv->ncrxpackets++;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
2020-08-06 19:41:45 +02:00
|
|
|
while ((rxbyte & 0x01) == DM9X_PKTRDY &&
|
|
|
|
priv->ncrxpackets < DM9X_CRXTHRES);
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("All RX packets processed\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_txdone
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating that the last TX packet(s) is done
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static void dm9x_txdone(FAR struct dm9x_driver_s *priv)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
int nsr;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("TX done\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Another packet has completed transmission. Decrement the count of
|
|
|
|
* of pending TX transmissions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsr = getreg(DM9X_NETS);
|
|
|
|
if (nsr & DM9X_NETS_TX1END)
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_ntxpending)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_ntxpending--;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-12 16:31:22 +02:00
|
|
|
nerr("ERROR: Bad TX count (TX1END)\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsr & DM9X_NETS_TX2END)
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_ntxpending)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_ntxpending--;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-12 16:31:22 +02:00
|
|
|
nerr("ERROR: Bad TX count (TX2END)\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-03 00:22:48 +01:00
|
|
|
/* Cancel the TX timeout */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_ntxpending == 0)
|
2007-11-03 00:22:48 +01:00
|
|
|
{
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_cancel(&priv->dm_txtimeout);
|
2007-11-03 00:22:48 +01:00
|
|
|
}
|
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Then poll the network for new XMIT data */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_poll(&priv->dm_dev, dm9x_txpoll);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_interrupt_work
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-12-03 23:28:19 +01:00
|
|
|
* Perform interrupt related work from the worker thread
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 23:28:19 +01:00
|
|
|
* arg - The argument passed when work_queue() was called.
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2016-12-03 23:28:19 +01:00
|
|
|
* OK on success
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-12-03 18:42:15 +01:00
|
|
|
* The network is locked.
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
static void dm9x_interrupt_work(FAR void *arg)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 23:28:19 +01:00
|
|
|
FAR struct dm9x_driver_s *priv = (FAR struct dm9x_driver_s *)arg;
|
2009-12-16 21:59:06 +01:00
|
|
|
uint8_t isr;
|
|
|
|
uint8_t save;
|
2007-11-02 21:10:33 +01:00
|
|
|
int i;
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
/* Process pending Ethernet interrupts */
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
/* Save previous register address */
|
|
|
|
|
2009-12-15 15:25:14 +01:00
|
|
|
save = (uint8_t)DM9X_INDEX;
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Disable all DM90x0 interrupts */
|
|
|
|
|
2014-04-13 22:32:20 +02:00
|
|
|
putreg(DM9X_IMR, DM9X_IMRDISABLE);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Get and clear the DM90x0 interrupt status bits */
|
|
|
|
|
|
|
|
isr = getreg(DM9X_ISR);
|
|
|
|
putreg(DM9X_ISR, isr);
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Interrupt status: %02x\n", isr);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Check for link status change */
|
|
|
|
|
|
|
|
if (isr & DM9X_INT_LNKCHG)
|
|
|
|
{
|
|
|
|
/* Wait up to 0.5s for link OK */
|
|
|
|
|
|
|
|
for (i = 0; i < 500; i++)
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_phyread(priv, 0x1);
|
|
|
|
if (dm9x_phyread(priv, 0x1) & 0x4) /* Link OK */
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
/* Wait to get detected speed */
|
|
|
|
|
|
|
|
for (i = 0; i < 200; i++)
|
|
|
|
{
|
2007-11-03 00:05:53 +01:00
|
|
|
up_mdelay(1);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the new network speed */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (dm9x_phyread(priv, 0) & 0x2000)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2019-12-05 21:54:50 +01:00
|
|
|
priv->dm_b100m = true;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-05 21:54:50 +01:00
|
|
|
priv->dm_b100m = false;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-12-05 21:54:50 +01:00
|
|
|
|
2007-11-03 00:05:53 +01:00
|
|
|
up_mdelay(1);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
2016-06-12 16:31:22 +02:00
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
nerr("ERROR: delay: %dmS speed: %s\n",
|
2019-12-05 21:54:50 +01:00
|
|
|
i, priv->dm_b100m ? "100M" : "10M");
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
2015-10-04 23:04:00 +02:00
|
|
|
/* Check if we received an incoming packet */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2015-10-04 23:04:00 +02:00
|
|
|
if (isr & DM9X_INT_PR)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_receive(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
2015-10-04 23:04:00 +02:00
|
|
|
/* Check if we are able to transmit a packet */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2015-10-04 23:04:00 +02:00
|
|
|
if (isr & DM9X_INT_PT)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_txdone(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
2014-04-13 22:32:20 +02:00
|
|
|
/* If the number of consecutive receive packets exceeds a threshold,
|
2007-11-02 21:10:33 +01:00
|
|
|
* then disable the RX interrupt.
|
|
|
|
*/
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->ncrxpackets >= DM9X_CRXTHRES)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2020-02-23 09:50:23 +01:00
|
|
|
/* Enable all DM90x0 interrupts EXCEPT for RX */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
putreg(DM9X_IMR, DM9X_IMRRXDISABLE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Enable all DM90x0 interrupts */
|
|
|
|
|
|
|
|
putreg(DM9X_IMR, DM9X_IMRENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore previous register address */
|
|
|
|
|
|
|
|
DM9X_INDEX = save;
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2016-12-03 18:42:15 +01:00
|
|
|
|
|
|
|
/* Re-enable Ethernet interrupts */
|
|
|
|
|
|
|
|
up_enable_irq(CONFIG_DM9X_IRQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_interrupt
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Hardware interrupt handler
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* irq - Number of the IRQ that generated the interrupt
|
|
|
|
* context - Interrupt register state save info (architecture-specific)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-27 13:27:56 +01:00
|
|
|
static int dm9x_interrupt(int irq, FAR void *context, FAR void *arg)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
#if CONFIG_DM9X_NINTERFACES == 1
|
|
|
|
FAR struct dm9x_driver_s *priv = &g_dm9x[0];
|
|
|
|
#else
|
|
|
|
# error "Additional logic needed to support multiple interfaces"
|
|
|
|
#endif
|
|
|
|
uint8_t isr;
|
|
|
|
|
|
|
|
/* Disable further Ethernet interrupts. Because Ethernet interrupts are
|
|
|
|
* also disabled if the TX timeout event occurs, there can be no race
|
|
|
|
* condition here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_disable_irq(CONFIG_DM9X_IRQ);
|
|
|
|
|
|
|
|
/* Determine if a TX transfer just completed */
|
|
|
|
|
|
|
|
isr = getreg(DM9X_ISR);
|
|
|
|
if ((isr & DM9X_INT_PT) != 0)
|
|
|
|
{
|
|
|
|
/* If a TX transfer just completed, then cancel the TX timeout so
|
|
|
|
* there will be no race condition between any subsequent timeout
|
|
|
|
* expiration and the deferred interrupt processing.
|
|
|
|
*/
|
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_cancel(&priv->dm_txtimeout);
|
2016-12-03 18:42:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Schedule to perform the interrupt processing on the worker thread. */
|
|
|
|
|
2017-03-03 21:45:09 +01:00
|
|
|
work_queue(ETHWORK, &priv->dm_irqwork, dm9x_interrupt_work, priv, 0);
|
2016-12-03 18:42:15 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_txtimeout_work
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-12-03 23:28:19 +01:00
|
|
|
* Perform TX timeout related work from the worker thread
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 23:28:19 +01:00
|
|
|
* arg - The argument passed when work_queue() as called.
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2016-12-03 23:28:19 +01:00
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
static void dm9x_txtimeout_work(FAR void *arg)
|
2016-12-03 18:42:15 +01:00
|
|
|
{
|
2016-12-03 23:28:19 +01:00
|
|
|
FAR struct dm9x_driver_s *priv = (FAR struct dm9x_driver_s *)arg;
|
|
|
|
|
2016-06-12 16:31:22 +02:00
|
|
|
nerr("ERROR: TX timeout\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Increment statistics and dump debug info */
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2016-12-03 18:42:15 +01:00
|
|
|
NETDEV_TXTIMEOUTS(priv->dm_dev);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
ninfo(" TX packet count: %d\n", priv->dm_ntxpending);
|
2016-06-12 16:31:22 +02:00
|
|
|
ninfo(" TX read pointer address: 0x%02x:%02x\n",
|
|
|
|
getreg(DM9X_TRPAH), getreg(DM9X_TRPAL));
|
|
|
|
ninfo(" Memory data write address: 0x%02x:%02x (DM9010)\n",
|
|
|
|
getreg(DM9X_MDWAH), getreg(DM9X_MDWAL));
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Then reset the DM90x0 */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_reset(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-05-30 17:37:34 +02:00
|
|
|
/* Then poll the network for new XMIT data */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_poll(&priv->dm_dev, dm9x_txpoll);
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_txtimeout_expiry
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Our TX watchdog timed out. Called from the timer interrupt handler.
|
|
|
|
* The last TX never completed. Reset the hardware and start again.
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2020-08-09 20:29:35 +02:00
|
|
|
* arg - The argument
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-12-03 18:42:15 +01:00
|
|
|
* Global interrupts are disabled by the watchdog logic.
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-08-09 20:29:35 +02:00
|
|
|
static void dm9x_txtimeout_expiry(wdparm_t arg)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
FAR struct dm9x_driver_s *priv = (FAR struct dm9x_driver_s *)arg;
|
|
|
|
|
|
|
|
/* Disable further Ethernet interrupts. This will prevent some race
|
|
|
|
* conditions with interrupt work. There is still a potential race
|
|
|
|
* condition with interrupt work that is already queued and in progress.
|
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
up_disable_irq(CONFIG_DM9X_IRQ);
|
|
|
|
|
|
|
|
/* Schedule to perform the TX timeout processing on the worker thread. */
|
|
|
|
|
2017-03-03 21:45:09 +01:00
|
|
|
work_queue(ETHWORK, &priv->dm_irqwork, dm9x_txtimeout_work, priv, 0);
|
2016-12-03 18:42:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_poll_work
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-12-03 23:28:19 +01:00
|
|
|
* Perform periodic polling from the worker thread
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 23:28:19 +01:00
|
|
|
* arg - The argument passed when work_queue() as called.
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2016-12-03 23:28:19 +01:00
|
|
|
* OK on success
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-12-03 23:28:19 +01:00
|
|
|
* The network is locked.
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
static void dm9x_poll_work(FAR void *arg)
|
2016-12-03 18:42:15 +01:00
|
|
|
{
|
2016-12-03 23:28:19 +01:00
|
|
|
FAR struct dm9x_driver_s *priv = (FAR struct dm9x_driver_s *)arg;
|
|
|
|
|
|
|
|
/* Perform the poll */
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* If the number of contiguous RX packets exceeds a threshold, reset the
|
|
|
|
* counter and re-enable RX interrupts
|
2007-11-02 21:10:33 +01:00
|
|
|
*/
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->ncrxpackets >= DM9X_CRXTHRES)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->ncrxpackets = 0;
|
2007-11-02 21:10:33 +01:00
|
|
|
putreg(DM9X_IMR, DM9X_IMRENABLE);
|
|
|
|
}
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
/* Check if there is room in the DM90x0 to hold another packet. In 100M
|
|
|
|
* mode, that can be 2 packets, otherwise it is a single packet.
|
2007-11-03 00:05:53 +01:00
|
|
|
*/
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2019-12-05 21:54:50 +01:00
|
|
|
if (priv->dm_ntxpending < 1 || (priv->dm_b100m && priv->dm_ntxpending < 2))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Update TCP timing states and poll the network for new XMIT data */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_timer(&priv->dm_dev, DM9X_WDDELAY, dm9x_txpoll);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the watchdog poll timer again */
|
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_start(&priv->dm_txpoll, DM9X_WDDELAY,
|
2020-08-09 20:29:35 +02:00
|
|
|
dm9x_poll_expiry, (wdparm_t)priv);
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2016-12-03 18:42:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_poll_expiry
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Periodic timer handler. Called from the timer interrupt handler.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2020-08-09 20:29:35 +02:00
|
|
|
* arg - The argument
|
2016-12-03 18:42:15 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Global interrupts are disabled by the watchdog logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-08-09 20:29:35 +02:00
|
|
|
static void dm9x_poll_expiry(wdparm_t arg)
|
2016-12-03 18:42:15 +01:00
|
|
|
{
|
|
|
|
FAR struct dm9x_driver_s *priv = (FAR struct dm9x_driver_s *)arg;
|
|
|
|
|
2017-03-03 21:45:09 +01:00
|
|
|
/* Schedule to perform the interrupt processing on the worker thread. */
|
2016-12-03 18:42:15 +01:00
|
|
|
|
2017-03-03 21:45:09 +01:00
|
|
|
work_queue(ETHWORK, &priv->dm_pollwork, dm9x_poll_work, priv, 0);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_phymode
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the PHY operating mode
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static inline void dm9x_phymode(FAR struct dm9x_driver_s *priv)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2009-12-15 15:25:14 +01:00
|
|
|
uint16_t phyreg0;
|
|
|
|
uint16_t phyreg4;
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2015-09-01 15:04:09 +02:00
|
|
|
#ifdef CONFIG_DM9X_MODE_AUTO
|
2007-11-02 21:10:33 +01:00
|
|
|
phyreg0 = 0x1200; /* Auto-negotiation & Restart Auto-negotiation */
|
2015-10-10 18:41:00 +02:00
|
|
|
phyreg4 = 0x01e1; /* Default flow control disable */
|
2015-09-01 15:04:09 +02:00
|
|
|
#elif defined(CONFIG_DM9X_MODE_10MHD)
|
2014-04-13 22:32:20 +02:00
|
|
|
phyreg4 = 0x21;
|
2007-11-02 21:10:33 +01:00
|
|
|
phyreg0 = 0x1000;
|
2015-09-01 15:04:09 +02:00
|
|
|
#elif defined(CONFIG_DM9X_MODE_10MFD)
|
2014-04-13 22:32:20 +02:00
|
|
|
phyreg4 = 0x41;
|
2007-11-02 21:10:33 +01:00
|
|
|
phyreg0 = 0x1100;
|
2015-09-01 15:04:09 +02:00
|
|
|
#elif defined(CONFIG_DM9X_MODE_100MHD)
|
2014-04-13 22:32:20 +02:00
|
|
|
phyreg4 = 0x81;
|
2007-11-02 21:10:33 +01:00
|
|
|
phyreg0 = 0x3000;
|
2015-09-01 15:04:09 +02:00
|
|
|
#elif defined(CONFIG_DM9X_MODE_100MFD)
|
2014-04-13 22:32:20 +02:00
|
|
|
phyreg4 = 0x101;
|
2007-11-02 21:10:33 +01:00
|
|
|
phyreg0 = 0x3100;
|
|
|
|
#else
|
|
|
|
# error "Recognized PHY mode"
|
|
|
|
#endif
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_phywrite(priv, 0, phyreg0);
|
|
|
|
dm9x_phywrite(priv, 4, phyreg4);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_ifup
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Bring up the DM90x0 interface when an IP address is
|
2014-04-13 22:32:20 +02:00
|
|
|
* provided
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_ifup(FAR struct net_driver_s *dev)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct dm9x_driver_s *priv =
|
|
|
|
(FAR struct dm9x_driver_s *)dev->d_private;
|
2009-12-16 21:59:06 +01:00
|
|
|
uint8_t netstatus;
|
2007-11-02 21:10:33 +01:00
|
|
|
int i;
|
|
|
|
|
2016-06-12 16:31:22 +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);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2020-02-22 19:31:14 +01:00
|
|
|
/* Initialize DM90x0 chip */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_bringup(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Check link state and media speed (waiting up to 3s for link OK) */
|
|
|
|
|
2019-12-05 21:54:50 +01:00
|
|
|
priv->dm_b100m = false;
|
2007-11-02 21:10:33 +01:00
|
|
|
for (i = 0; i < 3000; i++)
|
|
|
|
{
|
|
|
|
netstatus = getreg(DM9X_NETS);
|
|
|
|
if (netstatus & DM9X_NETS_LINKST)
|
|
|
|
{
|
|
|
|
/* Link OK... Wait a bit before getting the detected speed */
|
|
|
|
|
|
|
|
up_mdelay(200);
|
|
|
|
netstatus = getreg(DM9X_NETS);
|
|
|
|
if ((netstatus & DM9X_NETS_SPEED) == 0)
|
|
|
|
{
|
2019-12-05 21:54:50 +01:00
|
|
|
priv->dm_b100m = true;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
2019-12-05 21:54:50 +01:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-12-05 21:54:50 +01:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
i++;
|
|
|
|
up_mdelay(1);
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:54:50 +01:00
|
|
|
ninfo("delay: %dmS speed: %s\n", i, priv->dm_b100m ? "100M" : "10M");
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Set and activate a timer process */
|
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_start(&priv->dm_txpoll, DM9X_WDDELAY,
|
2020-08-09 20:29:35 +02:00
|
|
|
dm9x_poll_expiry, (wdparm_t)priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Enable the DM9X interrupt */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_bifup = true;
|
2007-11-02 21:10:33 +01:00
|
|
|
up_enable_irq(CONFIG_DM9X_IRQ);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_ifdown
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Stop the interface.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_ifdown(FAR struct net_driver_s *dev)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct dm9x_driver_s *priv =
|
|
|
|
(FAR struct dm9x_driver_s *)dev->d_private;
|
2007-11-02 21:10:33 +01:00
|
|
|
irqstate_t flags;
|
|
|
|
|
2016-06-12 16:31:22 +02:00
|
|
|
ninfo("Stopping\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Disable the DM9X interrupt */
|
|
|
|
|
2016-02-14 14:32:58 +01:00
|
|
|
flags = enter_critical_section();
|
2007-11-02 21:10:33 +01:00
|
|
|
up_disable_irq(CONFIG_DM9X_IRQ);
|
|
|
|
|
|
|
|
/* Cancel the TX poll timer and TX timeout timers */
|
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_cancel(&priv->dm_txpoll);
|
|
|
|
wd_cancel(&priv->dm_txtimeout);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Reset the device */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_phywrite(priv, 0x00, 0x8000); /* PHY reset */
|
2007-11-02 21:10:33 +01:00
|
|
|
putreg(DM9X_GPD, 0x01); /* Power-down PHY (GEPIO0=1) */
|
|
|
|
putreg(DM9X_IMR, DM9X_IMRDISABLE); /* Disable all interrupts */
|
|
|
|
putreg(DM9X_RXC, 0x00); /* Disable RX */
|
|
|
|
putreg(DM9X_ISR, DM9X_INT_ALL); /* Clear interrupt status */
|
2007-11-30 21:46:29 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_bifup = false;
|
2016-02-14 14:32:58 +01:00
|
|
|
leave_critical_section(flags);
|
2007-11-02 21:10:33 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2007-11-22 15:42:52 +01:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_txavail_work
|
2007-11-22 15:42:52 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-12-03 23:28:19 +01:00
|
|
|
* Perform an out-of-cycle poll on the worker thread.
|
2007-11-22 15:42:52 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 23:28:19 +01:00
|
|
|
* arg - Reference to the NuttX driver state structure (cast to void*)
|
2007-11-22 15:42:52 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2016-12-03 23:28:19 +01:00
|
|
|
* Called on the higher priority worker thread.
|
2007-11-22 15:42:52 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
static void dm9x_txavail_work(FAR void *arg)
|
2007-11-22 15:42:52 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct dm9x_driver_s *priv =
|
|
|
|
(FAR struct dm9x_driver_s *)arg;
|
2016-12-03 23:28:19 +01:00
|
|
|
|
2016-06-12 16:31:22 +02:00
|
|
|
ninfo("Polling\n");
|
2007-11-22 15:42:52 +01:00
|
|
|
|
2007-11-30 21:46:29 +01:00
|
|
|
/* Ignore the notification if the interface is not yet up */
|
2007-11-22 15:42:52 +01:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2016-12-03 18:42:15 +01:00
|
|
|
if (priv->dm_bifup)
|
2007-11-22 15:42:52 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Check if there is room in the DM90x0 to hold another packet. In 100M
|
2007-11-30 21:46:29 +01:00
|
|
|
* mode, that can be 2 packets, otherwise it is a single packet.
|
|
|
|
*/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
if (priv->dm_ntxpending < 1 ||
|
2019-12-05 21:54:50 +01:00
|
|
|
(priv->dm_b100m && priv->dm_ntxpending < 2))
|
2007-11-30 21:46:29 +01:00
|
|
|
{
|
2016-05-30 17:37:34 +02:00
|
|
|
/* If so, then poll the network for new XMIT data */
|
2007-11-30 21:46:29 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_poll(&priv->dm_dev, dm9x_txpoll);
|
2007-11-30 21:46:29 +01:00
|
|
|
}
|
2007-11-22 15:42:52 +01:00
|
|
|
}
|
2016-12-03 18:42:15 +01:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2016-12-03 18:42:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_txavail
|
2016-12-03 18:42:15 +01: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:
|
2016-12-03 18:42:15 +01:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called in normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int dm9x_txavail(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct dm9x_driver_s *priv =
|
|
|
|
(FAR struct dm9x_driver_s *)dev->d_private;
|
2016-12-03 18:42:15 +01:00
|
|
|
|
|
|
|
/* Is our single work structure available? It may not be if there are
|
|
|
|
* pending interrupt actions and we will have to ignore the Tx
|
|
|
|
* availability action.
|
|
|
|
*/
|
|
|
|
|
2017-03-03 21:45:09 +01:00
|
|
|
if (work_available(&priv->dm_pollwork))
|
2016-12-03 18:42:15 +01:00
|
|
|
{
|
|
|
|
/* Schedule to serialize the poll on the worker thread. */
|
|
|
|
|
2017-03-03 21:45:09 +01:00
|
|
|
work_queue(ETHWORK, &priv->dm_pollwork, dm9x_txavail_work, priv, 0);
|
2016-12-03 18:42:15 +01:00
|
|
|
}
|
|
|
|
|
2007-11-23 23:32:52 +01:00
|
|
|
return OK;
|
2007-11-22 15:42:52 +01:00
|
|
|
}
|
|
|
|
|
2010-07-11 17:17:11 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_addmac
|
2010-07-11 17:17:11 +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:
|
2010-07-11 17:17:11 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
2014-04-13 22:32:20 +02:00
|
|
|
* mac - The MAC address to be added
|
2010-07-11 17:17:11 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
2010-07-11 17:17:11 +02:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct dm9x_driver_s *priv =
|
|
|
|
(FAR struct dm9x_driver_s *)dev->d_private;
|
2010-07-11 17:17:11 +02:00
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
#warning "Multicast MAC support not implemented"
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_rmmac
|
2010-07-11 17:17:11 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2019-02-24 18:51:25 +01:00
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware
|
|
|
|
* multicast address filtering
|
2010-07-11 17:17:11 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2010-07-11 17:17:11 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
2014-04-13 22:32:20 +02:00
|
|
|
* mac - The MAC address to be removed
|
2010-07-11 17:17:11 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2019-02-24 18:51:25 +01:00
|
|
|
static int dm9x_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
2010-07-11 17:17:11 +02:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
FAR struct dm9x_driver_s *priv =
|
|
|
|
(FAR struct dm9x_driver_s *)dev->d_private;
|
2010-07-11 17:17:11 +02:00
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
#warning "Multicast MAC support not implemented"
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_bringup
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the dm90x0 chip
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static void dm9x_bringup(FAR struct dm9x_driver_s *priv)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2016-06-12 16:31:22 +02:00
|
|
|
ninfo("Initializing\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Set the internal PHY power-on, GPIOs normal, and wait 2ms */
|
|
|
|
|
|
|
|
putreg(DM9X_GPD, 0x01); /* Power-down the PHY (GEPIO0=1) */
|
|
|
|
up_udelay(500);
|
|
|
|
putreg(DM9X_GPD, 0x00); /* Preactivate PHY (GPIO0=0 */
|
2007-11-06 17:17:50 +01:00
|
|
|
up_udelay(20); /* Wait 20us for PHY power-on ready */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Do a software reset and wait 20us (twice). The reset autoclears
|
|
|
|
* in 10us; 20us guarantees completion of the reset
|
|
|
|
*/
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
putreg(DM9X_NETC, (DM9X_NETC_RST | DM9X_NETC_LBK1));
|
2007-11-02 21:10:33 +01:00
|
|
|
up_udelay(20);
|
2015-10-10 18:41:00 +02:00
|
|
|
putreg(DM9X_NETC, (DM9X_NETC_RST | DM9X_NETC_LBK1));
|
2007-11-02 21:10:33 +01:00
|
|
|
up_udelay(20);
|
|
|
|
|
|
|
|
/* Configure I/O mode */
|
|
|
|
|
|
|
|
switch (getreg(DM9X_ISR) & DM9X_ISR_IOMODEM)
|
|
|
|
{
|
|
|
|
case DM9X_ISR_IOMODE8:
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_read = read8;
|
|
|
|
priv->dm_write = write8;
|
|
|
|
priv->dm_discard = discard8;
|
2007-11-02 21:10:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DM9X_ISR_IOMODE16:
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_read = read16;
|
|
|
|
priv->dm_write = write16;
|
|
|
|
priv->dm_discard = discard16;
|
2007-11-02 21:10:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DM9X_ISR_IOMODE32:
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->dm_read = read32;
|
|
|
|
priv->dm_write = write32;
|
|
|
|
priv->dm_discard = discard32;
|
2007-11-02 21:10:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-06 17:17:50 +01:00
|
|
|
/* Program PHY operating mode */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_phymode(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-06 17:17:50 +01:00
|
|
|
/* Program operating mode */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-06 17:17:50 +01:00
|
|
|
putreg(DM9X_NETC, 0x00); /* Network control */
|
|
|
|
putreg(DM9X_TXC, 0x00); /* Clear TX Polling */
|
|
|
|
putreg(DM9X_BPTHRES, 0x3f); /* Less 3kb, 600us */
|
|
|
|
putreg(DM9X_SMODEC, 0x00); /* Special mode */
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Clear TX status */
|
|
|
|
putreg(DM9X_NETS, DM9X_NETS_WAKEST | DM9X_NETS_TX1END | DM9X_NETS_TX2END);
|
2007-11-02 21:10:33 +01:00
|
|
|
putreg(DM9X_ISR, DM9X_INT_ALL); /* Clear interrupt status */
|
|
|
|
|
|
|
|
#if defined(CONFIG_DM9X_CHECKSUM)
|
2007-11-06 17:17:50 +01:00
|
|
|
putreg(DM9X_TCCR, 0x07); /* TX UDP/TCP/IP checksum enable */
|
|
|
|
putreg(DM9X_RCSR, 0x02); /* Receive checksum enable */
|
2007-11-02 21:10:33 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_DM9X_ETRANS)
|
|
|
|
putreg(DM9X_ETXCSR, 0x83);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize statistics */
|
|
|
|
|
2016-12-03 18:42:15 +01:00
|
|
|
priv->ncrxpackets = 0; /* Number of continuous RX packets */
|
|
|
|
priv->dm_ntxpending = 0; /* Number of pending TX packets */
|
|
|
|
NETDEV_RESET_STATISTICS(&priv->dm_dev);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Activate DM9000A/DM9010 */
|
|
|
|
|
|
|
|
putreg(DM9X_RXC, DM9X_RXCSETUP | 1); /* RX enable */
|
|
|
|
putreg(DM9X_IMR, DM9X_IMRENABLE); /* Enable TX/RX interrupts */
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_reset
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2007-11-03 00:22:48 +01:00
|
|
|
* Stop, reset, re-initialize, and restart the DM90x0 chip and driver. At
|
|
|
|
* present, the chip is only reset after a TX timeout.
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-12-03 18:42:15 +01:00
|
|
|
* priv - Reference to the driver state structure
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
static void dm9x_reset(FAR struct dm9x_driver_s *priv)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2009-12-16 21:59:06 +01:00
|
|
|
uint8_t save;
|
2007-11-02 21:10:33 +01:00
|
|
|
int i;
|
|
|
|
|
2007-11-03 00:22:48 +01:00
|
|
|
/* Cancel the TX poll timer and TX timeout timers */
|
|
|
|
|
2020-08-04 12:31:31 +02:00
|
|
|
wd_cancel(&priv->dm_txpoll);
|
|
|
|
wd_cancel(&priv->dm_txtimeout);
|
2007-11-03 00:22:48 +01:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
/* Save previous register address */
|
|
|
|
|
2009-12-15 15:25:14 +01:00
|
|
|
save = (uint8_t)DM9X_INDEX;
|
2016-12-03 18:42:15 +01:00
|
|
|
dm9x_bringup(priv);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Wait up to 1 second for the link to be OK */
|
|
|
|
|
2019-12-05 21:54:50 +01:00
|
|
|
priv->dm_b100m = false;
|
2007-11-02 21:10:33 +01:00
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
{
|
2016-12-03 18:42:15 +01:00
|
|
|
if (dm9x_phyread(priv, 0x1) & 0x4)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2019-12-05 21:54:50 +01:00
|
|
|
if (dm9x_phyread(priv, 0) & 0x2000)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2019-12-05 21:54:50 +01:00
|
|
|
priv->dm_b100m = true;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
2019-12-05 21:54:50 +01:00
|
|
|
|
2007-11-02 21:10:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-12-05 21:54:50 +01:00
|
|
|
|
2007-11-03 00:05:53 +01:00
|
|
|
up_mdelay(1);
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore previous register address */
|
|
|
|
|
|
|
|
DM9X_INDEX = save;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: dm9x_initialize
|
2007-11-02 21:10:33 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the DM90x0 driver
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-11-02 21:10:33 +01:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; Negated errno on failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Initialize the DM90x0 chip and driver */
|
|
|
|
|
|
|
|
int dm9x_initialize(void)
|
|
|
|
{
|
2009-12-16 21:59:06 +01:00
|
|
|
uint8_t *mptr;
|
2009-12-15 15:25:14 +01:00
|
|
|
uint16_t vid;
|
|
|
|
uint16_t pid;
|
2007-11-02 21:10:33 +01:00
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
/* Get the chip vendor ID and product ID */
|
|
|
|
|
2009-12-15 15:25:14 +01:00
|
|
|
vid = (((uint16_t)getreg(DM9X_VIDH)) << 8) | (uint16_t)getreg(DM9X_VIDL);
|
|
|
|
pid = (((uint16_t)getreg(DM9X_PIDH)) << 8) | (uint16_t)getreg(DM9X_PIDL);
|
2019-02-24 18:51:25 +01:00
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("I/O base: %08x VID: %04x PID: %04x\n", CONFIG_DM9X_BASE, vid, pid);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Check if a DM90x0 chip is recognized at this I/O base */
|
|
|
|
|
2019-02-24 18:51:25 +01:00
|
|
|
if (vid != DM9X_DAVICOMVID ||
|
|
|
|
(pid != DM9X_DM9000PID && pid != DM9X_DM9010PID))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
2020-08-06 19:41:45 +02:00
|
|
|
nerr("ERROR: vendor/product ID not found at this base address\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach the IRQ to the driver */
|
|
|
|
|
2017-02-27 13:27:56 +01:00
|
|
|
if (irq_attach(CONFIG_DM9X_IRQ, dm9x_interrupt, NULL))
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
/* We could not attach the ISR to the ISR */
|
2007-11-06 17:17:50 +01:00
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: irq_attach() failed\n");
|
2007-11-02 21:10:33 +01:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the driver structure */
|
|
|
|
|
|
|
|
memset(g_dm9x, 0, CONFIG_DM9X_NINTERFACES*sizeof(struct dm9x_driver_s));
|
2016-11-29 23:44:23 +01:00
|
|
|
g_dm9x[0].dm_dev.d_buf = g_pktbuf; /* Single packet buffer */
|
2007-11-06 17:17:50 +01:00
|
|
|
g_dm9x[0].dm_dev.d_ifup = dm9x_ifup; /* I/F down callback */
|
|
|
|
g_dm9x[0].dm_dev.d_ifdown = dm9x_ifdown; /* I/F up (new IP address) callback */
|
2007-11-22 15:42:52 +01:00
|
|
|
g_dm9x[0].dm_dev.d_txavail = dm9x_txavail; /* New TX data callback */
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2010-07-11 17:17:11 +02:00
|
|
|
g_dm9x[0].dm_dev.d_addmac = dm9x_addmac; /* Add multicast MAC address */
|
|
|
|
g_dm9x[0].dm_dev.d_rmmac = dm9x_rmmac; /* Remove multicast MAC address */
|
|
|
|
#endif
|
2020-08-04 12:31:31 +02:00
|
|
|
g_dm9x[0].dm_dev.d_private = g_dm9x; /* Used to recover private state from dev */
|
2007-11-02 21:10:33 +01:00
|
|
|
|
|
|
|
/* Read the MAC address */
|
|
|
|
|
2017-04-22 19:10:30 +02:00
|
|
|
mptr = g_dm9x[0].dm_dev.d_mac.ether.ether_addr_octet;
|
2007-12-11 15:28:16 +01:00
|
|
|
for (i = 0, j = DM9X_PAB0; i < ETHER_ADDR_LEN; i++, j++)
|
2007-11-02 21:10:33 +01:00
|
|
|
{
|
|
|
|
mptr[i] = getreg(j);
|
|
|
|
}
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("MAC: %0x:%0x:%0x:%0x:%0x:%0x\n",
|
|
|
|
mptr[0], mptr[1], mptr[2], mptr[3], mptr[4], mptr[5]);
|
2007-11-02 21:10:33 +01:00
|
|
|
|
2007-11-04 17:31:24 +01:00
|
|
|
/* Register the device with the OS so that socket IOCTLs can be performed */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
netdev_register(&g_dm9x[0].dm_dev, NET_LL_ETHERNET);
|
2007-11-04 17:31:24 +01:00
|
|
|
return OK;
|
2007-11-02 21:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_DM90x0 */
|