[Midnightbsd-cvs] src [10109] trunk/sys/dev: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun May 27 19:54:23 EDT 2018


Revision: 10109
          http://svnweb.midnightbsd.org/src/?rev=10109
Author:   laffer1
Date:     2018-05-27 19:54:22 -0400 (Sun, 27 May 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/sys/dev/e1000/e1000_80003es2lan.c
    trunk/sys/dev/e1000/e1000_80003es2lan.h
    trunk/sys/dev/e1000/e1000_82540.c
    trunk/sys/dev/e1000/e1000_82541.c
    trunk/sys/dev/e1000/e1000_82541.h
    trunk/sys/dev/e1000/e1000_82542.c
    trunk/sys/dev/e1000/e1000_82543.c
    trunk/sys/dev/e1000/e1000_82543.h
    trunk/sys/dev/e1000/e1000_82571.c
    trunk/sys/dev/e1000/e1000_82571.h
    trunk/sys/dev/e1000/e1000_82575.c
    trunk/sys/dev/e1000/e1000_82575.h
    trunk/sys/dev/e1000/e1000_api.c
    trunk/sys/dev/e1000/e1000_api.h
    trunk/sys/dev/e1000/e1000_defines.h
    trunk/sys/dev/e1000/e1000_hw.h
    trunk/sys/dev/e1000/e1000_i210.c
    trunk/sys/dev/e1000/e1000_i210.h
    trunk/sys/dev/e1000/e1000_ich8lan.c
    trunk/sys/dev/e1000/e1000_ich8lan.h
    trunk/sys/dev/e1000/e1000_mac.c
    trunk/sys/dev/e1000/e1000_mac.h
    trunk/sys/dev/e1000/e1000_manage.c
    trunk/sys/dev/e1000/e1000_manage.h
    trunk/sys/dev/e1000/e1000_mbx.c
    trunk/sys/dev/e1000/e1000_mbx.h
    trunk/sys/dev/e1000/e1000_nvm.c
    trunk/sys/dev/e1000/e1000_nvm.h
    trunk/sys/dev/e1000/e1000_osdep.c
    trunk/sys/dev/e1000/e1000_osdep.h
    trunk/sys/dev/e1000/e1000_phy.c
    trunk/sys/dev/e1000/e1000_phy.h
    trunk/sys/dev/e1000/e1000_regs.h
    trunk/sys/dev/e1000/e1000_vf.c
    trunk/sys/dev/e1000/e1000_vf.h
    trunk/sys/dev/e1000/if_em.c
    trunk/sys/dev/e1000/if_em.h
    trunk/sys/dev/e1000/if_igb.c
    trunk/sys/dev/e1000/if_igb.h
    trunk/sys/dev/e1000/if_lem.c
    trunk/sys/dev/e1000/if_lem.h
    trunk/sys/dev/ex/if_ex.c
    trunk/sys/dev/ex/if_ex_isa.c
    trunk/sys/dev/ex/if_ex_pccard.c
    trunk/sys/dev/ex/if_exreg.h
    trunk/sys/dev/ex/if_exvar.h
    trunk/sys/dev/glxiic/glxiic.c

Added Paths:
-----------
    trunk/sys/dev/ffec/
    trunk/sys/dev/ffec/if_ffec.c
    trunk/sys/dev/ffec/if_ffecreg.h

Modified: trunk/sys/dev/e1000/e1000_80003es2lan.c
===================================================================
--- trunk/sys/dev/e1000/e1000_80003es2lan.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_80003es2lan.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_80003es2lan.h
===================================================================
--- trunk/sys/dev/e1000/e1000_80003es2lan.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_80003es2lan.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82540.c
===================================================================
--- trunk/sys/dev/e1000/e1000_82540.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82540.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82541.c
===================================================================
--- trunk/sys/dev/e1000/e1000_82541.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82541.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82541.h
===================================================================
--- trunk/sys/dev/e1000/e1000_82541.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82541.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82542.c
===================================================================
--- trunk/sys/dev/e1000/e1000_82542.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82542.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82543.c
===================================================================
--- trunk/sys/dev/e1000/e1000_82543.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82543.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82543.h
===================================================================
--- trunk/sys/dev/e1000/e1000_82543.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82543.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82571.c
===================================================================
--- trunk/sys/dev/e1000/e1000_82571.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82571.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82571.h
===================================================================
--- trunk/sys/dev/e1000/e1000_82571.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82571.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_82575.c
===================================================================
--- trunk/sys/dev/e1000/e1000_82575.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82575.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_82575.c 296055 2016-02-25 19:15:06Z erj $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_82575.c 333216 2018-05-03 15:47:49Z marius $*/
 
 /*
  * 82575EB Gigabit Network Connection
@@ -101,7 +102,6 @@
 						   u16 offset);
 static s32 e1000_validate_nvm_checksum_i350(struct e1000_hw *hw);
 static s32 e1000_update_nvm_checksum_i350(struct e1000_hw *hw);
-static void e1000_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value);
 static void e1000_clear_vfta_i350(struct e1000_hw *hw);
 
 static void e1000_i2c_start(struct e1000_hw *hw);
@@ -1679,7 +1679,7 @@
 	case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
 		/* disable PCS autoneg and support parallel detect only */
 		pcs_autoneg = FALSE;
-		/* fall through to default case */
+		/* FALLTHROUGH */
 	default:
 		if (hw->mac.type == e1000_82575 ||
 		    hw->mac.type == e1000_82576) {
@@ -1806,6 +1806,7 @@
 			break;
 		}
 		/* fall through for I2C based SGMII */
+		/* FALLTHROUGH */
 	case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
 		/* read media type from SFP EEPROM */
 		ret_val = e1000_set_sfp_media_type_82575(hw);

Modified: trunk/sys/dev/e1000/e1000_82575.h
===================================================================
--- trunk/sys/dev/e1000/e1000_82575.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_82575.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_82575.h 296055 2016-02-25 19:15:06Z erj $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_82575.h 333214 2018-05-03 15:41:04Z marius $*/
 
 #ifndef _E1000_82575_H_
 #define _E1000_82575_H_
@@ -384,7 +385,7 @@
 #define E1000_ETQF_FILTER_ENABLE	(1 << 26)
 #define E1000_ETQF_IMM_INT		(1 << 29)
 #define E1000_ETQF_1588			(1 << 30)
-#define E1000_ETQF_QUEUE_ENABLE		(1 << 31)
+#define E1000_ETQF_QUEUE_ENABLE		(1U << 31)
 /*
  * ETQF filter list: one static filter per filter consumer. This is
  *                   to avoid filter collisions later. Add new filters
@@ -411,7 +412,7 @@
 #define E1000_DTXSWC_LLE_MASK		0x00FF0000 /* Per VF Local LB enables */
 #define E1000_DTXSWC_VLAN_SPOOF_SHIFT	8
 #define E1000_DTXSWC_LLE_SHIFT		16
-#define E1000_DTXSWC_VMDQ_LOOPBACK_EN	(1 << 31)  /* global VF LB enable */
+#define E1000_DTXSWC_VMDQ_LOOPBACK_EN	(1U << 31)  /* global VF LB enable */
 
 /* Easy defines for setting default pool, would normally be left a zero */
 #define E1000_VT_CTL_DEFAULT_POOL_SHIFT	7
@@ -493,6 +494,7 @@
 void e1000_vfta_set_vf(struct e1000_hw *, u16, bool);
 void e1000_rlpml_set_vf(struct e1000_hw *, u16);
 s32 e1000_promisc_set_vf(struct e1000_hw *, enum e1000_promisc_type type);
+void e1000_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value);
 u16 e1000_rxpbs_adjust_82580(u32 data);
 s32 e1000_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data);
 s32 e1000_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M);

Modified: trunk/sys/dev/e1000/e1000_api.c
===================================================================
--- trunk/sys/dev/e1000/e1000_api.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_api.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_api.c 304338 2016-08-18 07:32:02Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_api.c 333214 2018-05-03 15:41:04Z marius $*/
 
 #include "e1000_api.h"
 
@@ -310,6 +311,16 @@
 	case E1000_DEV_ID_PCH_SPT_I219_V5:
 		mac->type = e1000_pch_spt;
 		break;
+	case E1000_DEV_ID_PCH_CNP_I219_LM6:
+	case E1000_DEV_ID_PCH_CNP_I219_V6:
+	case E1000_DEV_ID_PCH_CNP_I219_LM7:
+	case E1000_DEV_ID_PCH_CNP_I219_V7:
+	case E1000_DEV_ID_PCH_ICP_I219_LM8:
+	case E1000_DEV_ID_PCH_ICP_I219_V8:
+	case E1000_DEV_ID_PCH_ICP_I219_LM9:
+	case E1000_DEV_ID_PCH_ICP_I219_V9:
+		mac->type = e1000_pch_cnp;
+		break;
 	case E1000_DEV_ID_82575EB_COPPER:
 	case E1000_DEV_ID_82575EB_FIBER_SERDES:
 	case E1000_DEV_ID_82575GB_QUAD_COPPER:
@@ -461,6 +472,7 @@
 	case e1000_pch2lan:
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		e1000_init_function_pointers_ich8lan(hw);
 		break;
 	case e1000_82575:

Modified: trunk/sys/dev/e1000/e1000_api.h
===================================================================
--- trunk/sys/dev/e1000/e1000_api.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_api.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_defines.h
===================================================================
--- trunk/sys/dev/e1000/e1000_defines.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_defines.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_defines.h 296055 2016-02-25 19:15:06Z erj $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_defines.h 323080 2017-08-31 23:59:46Z marius $*/
 
 #ifndef _E1000_DEFINES_H_
 #define _E1000_DEFINES_H_
@@ -469,6 +470,8 @@
 
 #define ETHERNET_FCS_SIZE		4
 #define MAX_JUMBO_FRAME_SIZE		0x3F00
+/* The datasheet maximum supported RX size is 9.5KB (9728 bytes) */
+#define MAX_RX_JUMBO_FRAME_SIZE		0x2600
 #define E1000_TX_PTR_GAP		0x1F
 
 /* Extended Configuration Control and Size */

Modified: trunk/sys/dev/e1000/e1000_hw.h
===================================================================
--- trunk/sys/dev/e1000/e1000_hw.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_hw.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_hw.h 304338 2016-08-18 07:32:02Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_hw.h 333214 2018-05-03 15:41:04Z marius $*/
 
 #ifndef _E1000_HW_H_
 #define _E1000_HW_H_
@@ -146,6 +147,14 @@
 #define E1000_DEV_ID_PCH_SPT_I219_V4		0x15D8
 #define E1000_DEV_ID_PCH_SPT_I219_LM5		0x15E3
 #define E1000_DEV_ID_PCH_SPT_I219_V5		0x15D6
+#define E1000_DEV_ID_PCH_CNP_I219_LM6		0x15BD
+#define E1000_DEV_ID_PCH_CNP_I219_V6		0x15BE
+#define E1000_DEV_ID_PCH_CNP_I219_LM7		0x15BB
+#define E1000_DEV_ID_PCH_CNP_I219_V7		0x15BC
+#define E1000_DEV_ID_PCH_ICP_I219_LM8		0x15DF
+#define E1000_DEV_ID_PCH_ICP_I219_V8		0x15E0
+#define E1000_DEV_ID_PCH_ICP_I219_LM9		0x15E1
+#define E1000_DEV_ID_PCH_ICP_I219_V9		0x15E2
 #define E1000_DEV_ID_82576			0x10C9
 #define E1000_DEV_ID_82576_FIBER		0x10E6
 #define E1000_DEV_ID_82576_SERDES		0x10E7
@@ -232,6 +241,7 @@
 	e1000_pch2lan,
 	e1000_pch_lpt,
 	e1000_pch_spt,
+	e1000_pch_cnp,
 	e1000_82575,
 	e1000_82576,
 	e1000_82580,

Modified: trunk/sys/dev/e1000/e1000_i210.c
===================================================================
--- trunk/sys/dev/e1000/e1000_i210.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_i210.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_i210.h
===================================================================
--- trunk/sys/dev/e1000/e1000_i210.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_i210.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_ich8lan.c
===================================================================
--- trunk/sys/dev/e1000/e1000_ich8lan.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_ich8lan.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_ich8lan.c 304338 2016-08-18 07:32:02Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_ich8lan.c 333214 2018-05-03 15:41:04Z marius $*/
 
 /* 82562G 10/100 Network Connection
  * 82562G-2 10/100 Network Connection
@@ -243,8 +244,7 @@
 	if (ret_val)
 		return FALSE;
 out:
-	if ((hw->mac.type == e1000_pch_lpt) ||
-	    (hw->mac.type == e1000_pch_spt)) {
+	if (hw->mac.type >= e1000_pch_lpt) {
 		/* Only unforce SMBus if ME is not active */
 		if (!(E1000_READ_REG(hw, E1000_FWSM) &
 		    E1000_ICH_FWSM_FW_VALID)) {
@@ -345,6 +345,7 @@
 	switch (hw->mac.type) {
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		if (e1000_phy_is_accessible_pchlan(hw))
 			break;
 
@@ -493,6 +494,7 @@
 		case e1000_pch2lan:
 		case e1000_pch_lpt:
 		case e1000_pch_spt:
+		case e1000_pch_cnp:
 			/* In case the PHY needs to be in mdio slow mode,
 			 * set slow mode and try to get the PHY id again.
 			 */
@@ -641,7 +643,7 @@
 
 	nvm->type = e1000_nvm_flash_sw;
 
-	if (hw->mac.type == e1000_pch_spt) {
+	if (hw->mac.type >= e1000_pch_spt) {
 		/* in SPT, gfpreg doesn't exist. NVM size is taken from the
 		 * STRAP register. This is because in SPT the GbE Flash region
 		 * is no longer accessed through the flash registers. Instead,
@@ -701,7 +703,7 @@
 	/* Function Pointers */
 	nvm->ops.acquire	= e1000_acquire_nvm_ich8lan;
 	nvm->ops.release	= e1000_release_nvm_ich8lan;
-	if (hw->mac.type == e1000_pch_spt) {
+	if (hw->mac.type >= e1000_pch_spt) {
 		nvm->ops.read	= e1000_read_nvm_spt;
 		nvm->ops.update	= e1000_update_nvm_checksum_spt;
 	} else {
@@ -794,6 +796,7 @@
 		/* fall-through */
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		/* multicast address update for pch2 */
 		mac->ops.update_mc_addr_list =
 			e1000_update_mc_addr_list_pch2lan;
@@ -815,8 +818,7 @@
 		break;
 	}
 
-	if ((mac->type == e1000_pch_lpt) ||
-	    (mac->type == e1000_pch_spt)) {
+	if (mac->type >= e1000_pch_lpt) {
 		mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
 		mac->ops.rar_set = e1000_rar_set_pch_lpt;
 		mac->ops.setup_physical_interface = e1000_setup_copper_link_pch_lpt;
@@ -1576,9 +1578,7 @@
 	 * aggressive resulting in many collisions. To avoid this, increase
 	 * the IPG and reduce Rx latency in the PHY.
 	 */
-	if (((hw->mac.type == e1000_pch2lan) ||
-	     (hw->mac.type == e1000_pch_lpt) ||
-	     (hw->mac.type == e1000_pch_spt)) && link) {
+	if ((hw->mac.type >= e1000_pch2lan) && link) {
 		u16 speed, duplex;
 
 		e1000_get_speed_and_duplex_copper_generic(hw, &speed, &duplex);
@@ -1589,7 +1589,7 @@
 			tipg_reg |= 0xFF;
 			/* Reduce Rx latency in analog PHY */
 			emi_val = 0;
-		} else if (hw->mac.type == e1000_pch_spt &&
+		} else if (hw->mac.type >= e1000_pch_spt &&
 			   duplex == FULL_DUPLEX && speed != SPEED_1000) {
 			tipg_reg |= 0xC;
 			emi_val = 1;
@@ -1611,8 +1611,8 @@
 			emi_addr = I217_RX_CONFIG;
 		ret_val = e1000_write_emi_reg_locked(hw, emi_addr, emi_val);
 
-		if (hw->mac.type == e1000_pch_lpt ||
-		    hw->mac.type == e1000_pch_spt) {
+
+		if (hw->mac.type >= e1000_pch_lpt) {
 			u16 phy_reg;
 
 			hw->phy.ops.read_reg_locked(hw, I217_PLL_CLOCK_GATE_REG,
@@ -1641,7 +1641,7 @@
 		if (ret_val)
 			return ret_val;
 
-		if (hw->mac.type == e1000_pch_spt) {
+		if (hw->mac.type >= e1000_pch_spt) {
 			u16 data;
 			u16 ptr_gap;
 
@@ -1690,8 +1690,7 @@
 	 * on power up.
 	 * Set the Beacon Duration for I217 to 8 usec
 	 */
-	if ((hw->mac.type == e1000_pch_lpt) ||
-	    (hw->mac.type == e1000_pch_spt)) {
+	if (hw->mac.type >= e1000_pch_lpt) {
 		u32 mac_reg;
 
 		mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM4);
@@ -1709,8 +1708,7 @@
 		if (ret_val)
 			return ret_val;
 	}
-	if ((hw->mac.type == e1000_pch_lpt) ||
-	    (hw->mac.type == e1000_pch_spt)) {
+	if (hw->mac.type >= e1000_pch_lpt) {
 		/* Set platform power management values for
 		 * Latency Tolerance Reporting (LTR)
 		 * Optimized Buffer Flush/Fill (OBFF)
@@ -1723,15 +1721,20 @@
 	/* Clear link partner's EEE ability */
 	hw->dev_spec.ich8lan.eee_lp_ability = 0;
 
-	/* FEXTNVM6 K1-off workaround */
-	if (hw->mac.type == e1000_pch_spt) {
-		u32 pcieanacfg = E1000_READ_REG(hw, E1000_PCIEANACFG);
+	if (hw->mac.type >= e1000_pch_lpt) {
 		u32 fextnvm6 = E1000_READ_REG(hw, E1000_FEXTNVM6);
 
-		if ((pcieanacfg & E1000_FEXTNVM6_K1_OFF_ENABLE) &&
-			(hw->dev_spec.ich8lan.disable_k1_off == FALSE))
-			fextnvm6 |= E1000_FEXTNVM6_K1_OFF_ENABLE;
-		else
+		if (hw->mac.type == e1000_pch_spt) {
+			/* FEXTNVM6 K1-off workaround - for SPT only */
+			u32 pcieanacfg = E1000_READ_REG(hw, E1000_PCIEANACFG);
+
+			if (pcieanacfg & E1000_FEXTNVM6_K1_OFF_ENABLE)
+				fextnvm6 |= E1000_FEXTNVM6_K1_OFF_ENABLE;
+			else
+				fextnvm6 &= ~E1000_FEXTNVM6_K1_OFF_ENABLE;
+		}
+
+		if (hw->dev_spec.ich8lan.disable_k1_off == TRUE)
 			fextnvm6 &= ~E1000_FEXTNVM6_K1_OFF_ENABLE;
 
 		E1000_WRITE_REG(hw, E1000_FEXTNVM6, fextnvm6);
@@ -1831,6 +1834,7 @@
 	case e1000_pch2lan:
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		hw->phy.ops.init_params = e1000_init_phy_params_pchlan;
 		break;
 	default:
@@ -2295,6 +2299,7 @@
 	case e1000_pch2lan:
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
 		break;
 	default:
@@ -2655,6 +2660,8 @@
 			e1000_phy_sw_reset_generic(hw);
 			ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL,
 							0x3140);
+			if (ret_val)
+				return ret_val;
 		}
 	}
 
@@ -3412,6 +3419,7 @@
 
 	switch (hw->mac.type) {
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		bank1_offset = nvm->flash_bank_size;
 		act_offset = E1000_ICH_NVM_SIG_WORD;
 
@@ -3671,7 +3679,7 @@
 	/* Clear FCERR and DAEL in hw status by writing 1 */
 	hsfsts.hsf_status.flcerr = 1;
 	hsfsts.hsf_status.dael = 1;
-	if (hw->mac.type == e1000_pch_spt)
+	if (hw->mac.type >= e1000_pch_spt)
 		E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
 				      hsfsts.regval & 0xFFFF);
 	else
@@ -3691,7 +3699,7 @@
 		 * Begin by setting Flash Cycle Done.
 		 */
 		hsfsts.hsf_status.flcdone = 1;
-		if (hw->mac.type == e1000_pch_spt)
+		if (hw->mac.type >= e1000_pch_spt)
 			E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
 					      hsfsts.regval & 0xFFFF);
 		else
@@ -3718,7 +3726,7 @@
 			 * now set the Flash Cycle Done.
 			 */
 			hsfsts.hsf_status.flcdone = 1;
-			if (hw->mac.type == e1000_pch_spt)
+			if (hw->mac.type >= e1000_pch_spt)
 				E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
 						      hsfsts.regval & 0xFFFF);
 			else
@@ -3748,13 +3756,13 @@
 	DEBUGFUNC("e1000_flash_cycle_ich8lan");
 
 	/* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
-	if (hw->mac.type == e1000_pch_spt)
+	if (hw->mac.type >= e1000_pch_spt)
 		hsflctl.regval = E1000_READ_FLASH_REG(hw, ICH_FLASH_HSFSTS)>>16;
 	else
 		hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
 	hsflctl.hsf_ctrl.flcgo = 1;
 
-	if (hw->mac.type == e1000_pch_spt)
+	if (hw->mac.type >= e1000_pch_spt)
 		E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
 				      hsflctl.regval << 16);
 	else
@@ -3837,7 +3845,7 @@
 	/* In SPT, only 32 bits access is supported,
 	 * so this function should not be called.
 	 */
-	if (hw->mac.type == e1000_pch_spt)
+	if (hw->mac.type >= e1000_pch_spt)
 		return -E1000_ERR_NVM;
 	else
 		ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
@@ -3946,7 +3954,7 @@
 	DEBUGFUNC("e1000_read_flash_data_ich8lan");
 
 		if (offset > ICH_FLASH_LINEAR_ADDR_MASK ||
-		    hw->mac.type != e1000_pch_spt)
+		    hw->mac.type < e1000_pch_spt)
 			return -E1000_ERR_NVM;
 	flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
 			     hw->nvm.flash_base_addr);
@@ -4387,6 +4395,7 @@
 	switch (hw->mac.type) {
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		word = NVM_COMPAT;
 		valid_csum_mask = NVM_COMPAT_VALID_CSUM;
 		break;
@@ -4434,7 +4443,7 @@
 
 	DEBUGFUNC("e1000_write_ich8_data");
 
-	if (hw->mac.type == e1000_pch_spt) {
+	if (hw->mac.type >= e1000_pch_spt) {
 		if (size != 4 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
 			return -E1000_ERR_NVM;
 	} else {
@@ -4454,7 +4463,7 @@
 		/* In SPT, This register is in Lan memory space, not
 		 * flash.  Therefore, only 32 bit access is supported
 		 */
-		if (hw->mac.type == e1000_pch_spt)
+		if (hw->mac.type >= e1000_pch_spt)
 			hsflctl.regval =
 			    E1000_READ_FLASH_REG(hw, ICH_FLASH_HSFSTS)>>16;
 		else
@@ -4468,7 +4477,7 @@
 		 * not flash.  Therefore, only 32 bit access is
 		 * supported
 		 */
-		if (hw->mac.type == e1000_pch_spt)
+		if (hw->mac.type >= e1000_pch_spt)
 			E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
 					      hsflctl.regval << 16);
 		else
@@ -4530,7 +4539,7 @@
 
 	DEBUGFUNC("e1000_write_flash_data32_ich8lan");
 
-	if (hw->mac.type == e1000_pch_spt) {
+	if (hw->mac.type >= e1000_pch_spt) {
 		if (offset > ICH_FLASH_LINEAR_ADDR_MASK)
 			return -E1000_ERR_NVM;
 	}
@@ -4546,7 +4555,7 @@
 		/* In SPT, This register is in Lan memory space, not
 		 * flash.  Therefore, only 32 bit access is supported
 		 */
-		if (hw->mac.type == e1000_pch_spt)
+		if (hw->mac.type >= e1000_pch_spt)
 			hsflctl.regval = E1000_READ_FLASH_REG(hw,
 							      ICH_FLASH_HSFSTS)
 					 >> 16;
@@ -4561,7 +4570,7 @@
 		 * not flash.  Therefore, only 32 bit access is
 		 * supported
 		 */
-		if (hw->mac.type == e1000_pch_spt)
+		if (hw->mac.type >= e1000_pch_spt)
 			E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
 					      hsflctl.regval << 16);
 		else
@@ -4763,7 +4772,7 @@
 			/* Write a value 11 (block Erase) in Flash
 			 * Cycle field in hw flash control
 			 */
-			if (hw->mac.type == e1000_pch_spt)
+			if (hw->mac.type >= e1000_pch_spt)
 				hsflctl.regval =
 				    E1000_READ_FLASH_REG(hw,
 							 ICH_FLASH_HSFSTS)>>16;
@@ -4773,7 +4782,7 @@
 							   ICH_FLASH_HSFCTL);
 
 			hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
-			if (hw->mac.type == e1000_pch_spt)
+			if (hw->mac.type >= e1000_pch_spt)
 				E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
 						      hsflctl.regval << 16);
 			else
@@ -5193,7 +5202,7 @@
 	/* Device Status */
 	if (hw->mac.type == e1000_ich8lan) {
 		reg = E1000_READ_REG(hw, E1000_STATUS);
-		reg &= ~(1 << 31);
+		reg &= ~(1U << 31);
 		E1000_WRITE_REG(hw, E1000_STATUS, reg);
 	}
 
@@ -5211,8 +5220,7 @@
 	E1000_WRITE_REG(hw, E1000_RFCTL, reg);
 
 	/* Enable ECC on Lynxpoint */
-	if ((hw->mac.type == e1000_pch_lpt) ||
-	    (hw->mac.type == e1000_pch_spt)) {
+	if (hw->mac.type >= e1000_pch_lpt) {
 		reg = E1000_READ_REG(hw, E1000_PBECCSTS);
 		reg |= E1000_PBECCSTS_ECC_ENABLE;
 		E1000_WRITE_REG(hw, E1000_PBECCSTS, reg);
@@ -5645,7 +5653,7 @@
 		    (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
 		    (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
 		    (device_id == E1000_DEV_ID_PCH_I218_V3) ||
-		    (hw->mac.type == e1000_pch_spt)) {
+		    (hw->mac.type >= e1000_pch_spt)) {
 			u32 fextnvm6 = E1000_READ_REG(hw, E1000_FEXTNVM6);
 
 			E1000_WRITE_REG(hw, E1000_FEXTNVM6,

Modified: trunk/sys/dev/e1000/e1000_ich8lan.h
===================================================================
--- trunk/sys/dev/e1000/e1000_ich8lan.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_ich8lan.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_ich8lan.h 304338 2016-08-18 07:32:02Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_ich8lan.h 333214 2018-05-03 15:41:04Z marius $*/
 
 #ifndef _E1000_ICH8LAN_H_
 #define _E1000_ICH8LAN_H_
@@ -123,7 +124,8 @@
 #define NVM_SIZE_MULTIPLIER 4096  /*multiplier for NVMS field*/
 #define E1000_FLASH_BASE_ADDR 0xE000 /*offset of NVM access regs*/
 #define E1000_CTRL_EXT_NVMVS 0x3 /*NVM valid sector */
-#define E1000_TARC0_CB_MULTIQ_3_REQ	(1 << 28 | 1 << 29)
+#define E1000_TARC0_CB_MULTIQ_3_REQ	0x30000000
+#define E1000_TARC0_CB_MULTIQ_2_REQ	0x20000000
 #define PCIE_ICH8_SNOOP_ALL	PCIE_NO_SNOOP_ALL
 
 #define E1000_ICH_RAR_ENTRIES	7

Modified: trunk/sys/dev/e1000/e1000_mac.c
===================================================================
--- trunk/sys/dev/e1000/e1000_mac.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_mac.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_mac.h
===================================================================
--- trunk/sys/dev/e1000/e1000_mac.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_mac.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_manage.c
===================================================================
--- trunk/sys/dev/e1000/e1000_manage.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_manage.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_manage.h
===================================================================
--- trunk/sys/dev/e1000/e1000_manage.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_manage.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_mbx.c
===================================================================
--- trunk/sys/dev/e1000/e1000_mbx.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_mbx.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_mbx.c 296055 2016-02-25 19:15:06Z erj $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_mbx.c 333216 2018-05-03 15:47:49Z marius $*/
 
 #include "e1000_mbx.h"
 
@@ -778,6 +779,7 @@
 		mbx->stats.reqs = 0;
 		mbx->stats.acks = 0;
 		mbx->stats.rsts = 0;
+		/* FALLTHROUGH */
 	default:
 		return E1000_SUCCESS;
 	}

Modified: trunk/sys/dev/e1000/e1000_mbx.h
===================================================================
--- trunk/sys/dev/e1000/e1000_mbx.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_mbx.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_nvm.c
===================================================================
--- trunk/sys/dev/e1000/e1000_nvm.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_nvm.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_nvm.h
===================================================================
--- trunk/sys/dev/e1000/e1000_nvm.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_nvm.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_osdep.c
===================================================================
--- trunk/sys/dev/e1000/e1000_osdep.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_osdep.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_osdep.h
===================================================================
--- trunk/sys/dev/e1000/e1000_osdep.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_osdep.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_phy.c
===================================================================
--- trunk/sys/dev/e1000/e1000_phy.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_phy.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_phy.c 304338 2016-08-18 07:32:02Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_phy.c 333216 2018-05-03 15:47:49Z marius $*/
 
 #include "e1000_api.h"
 
@@ -1297,6 +1298,7 @@
 			phy_data |= M88E1000_PSCR_AUTO_X_1000T;
 			break;
 		}
+		/* FALLTHROUGH */
 	case 0:
 	default:
 		phy_data |= M88E1000_PSCR_AUTO_X_MODE;

Modified: trunk/sys/dev/e1000/e1000_phy.h
===================================================================
--- trunk/sys/dev/e1000/e1000_phy.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_phy.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/e1000_regs.h
===================================================================
--- trunk/sys/dev/e1000/e1000_regs.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_regs.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_regs.h 296055 2016-02-25 19:15:06Z erj $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_regs.h 333214 2018-05-03 15:41:04Z marius $*/
 
 #ifndef _E1000_REGS_H_
 #define _E1000_REGS_H_
@@ -214,7 +215,7 @@
 /* QAV Tx mode control register bitfields masks */
 #define E1000_TQAVCC_IDLE_SLOPE		0xFFFF /* Idle slope */
 #define E1000_TQAVCC_KEEP_CREDITS	(1 << 30) /* Keep credits opt enable */
-#define E1000_TQAVCC_QUEUE_MODE		(1 << 31) /* SP vs. SR Tx mode */
+#define E1000_TQAVCC_QUEUE_MODE		(1U << 31) /* SP vs. SR Tx mode */
 
 /* Good transmitted packets counter registers */
 #define E1000_PQGPTC(_n)		(0x010014 + (0x100 * (_n)))

Modified: trunk/sys/dev/e1000/e1000_vf.c
===================================================================
--- trunk/sys/dev/e1000/e1000_vf.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_vf.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/e1000_vf.c 294958 2016-01-27 22:31:08Z marius $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/e1000_vf.c 333216 2018-05-03 15:47:49Z marius $*/
 
 
 #include "e1000_api.h"
@@ -487,8 +488,10 @@
 		break;
 	case e1000_promisc_enabled:
 		msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
+		/* FALLTHROUGH */
 	case e1000_promisc_unicast:
 		msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
+		/* FALLTHROUGH */
 	case e1000_promisc_disabled:
 		break;
 	default:

Modified: trunk/sys/dev/e1000/e1000_vf.h
===================================================================
--- trunk/sys/dev/e1000/e1000_vf.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/e1000_vf.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/if_em.c
===================================================================
--- trunk/sys/dev/e1000/if_em.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/if_em.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,8 +31,9 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/if_em.c 320117 2017-06-19 15:56:03Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/if_em.c 333214 2018-05-03 15:41:04Z marius $*/
 
+#include "opt_em.h"
 #include "opt_ddb.h"
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -197,6 +199,24 @@
 	{ 0x8086, E1000_DEV_ID_PCH_SPT_I219_LM5,
 						PCI_ANY_ID, PCI_ANY_ID, 0},
 	{ 0x8086, E1000_DEV_ID_PCH_SPT_I219_V5, PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_SPT_I219_LM4,
+						PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_SPT_I219_V4, PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_SPT_I219_LM5,
+						PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_SPT_I219_V5, PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_CNP_I219_LM6,
+						PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_CNP_I219_V6, PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_CNP_I219_LM7,
+						PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_CNP_I219_V7, PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_ICP_I219_LM8,
+						PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_ICP_I219_V8, PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_ICP_I219_LM9,
+						PCI_ANY_ID, PCI_ANY_ID, 0},
+	{ 0x8086, E1000_DEV_ID_PCH_ICP_I219_V9, PCI_ANY_ID, PCI_ANY_ID, 0},
 	/* required last entry */
 	{ 0, 0, 0, 0, 0}
 };
@@ -364,11 +384,6 @@
 #define MAX_INTS_PER_SEC	8000
 #define DEFAULT_ITR		(1000000000/(MAX_INTS_PER_SEC * 256))
 
-/* Allow common code without TSO */
-#ifndef CSUM_TSO
-#define CSUM_TSO	0
-#endif
-
 #define TSO_WORKAROUND	4
 
 static SYSCTL_NODE(_hw, OID_AUTO, em, CTLFLAG_RD, 0, "EM driver parameters");
@@ -598,7 +613,7 @@
 	** so use the same tag and an offset handle for the
 	** FLASH read/write macros in the shared code.
 	*/
-	else if (hw->mac.type == e1000_pch_spt) {
+	else if (hw->mac.type >= e1000_pch_spt) {
 		adapter->osdep.flash_bus_space_tag =
 		    adapter->osdep.mem_bus_space_tag;
 		adapter->osdep.flash_bus_space_handle =
@@ -1200,6 +1215,7 @@
 		case e1000_pch2lan:
 		case e1000_pch_lpt:
 		case e1000_pch_spt:
+		case e1000_pch_cnp:
 		case e1000_82574:
 		case e1000_82583:
 		case e1000_80003es2lan:	/* 9K Jumbo Frame size */
@@ -1399,18 +1415,10 @@
 	E1000_WRITE_REG(&adapter->hw, E1000_VET, ETHERTYPE_VLAN);
 
 	/* Set hardware offload abilities */
-	ifp->if_hwassist = 0;
 	if (ifp->if_capenable & IFCAP_TXCSUM)
 		ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
-	/* 
-	** There have proven to be problems with TSO when not
-	** at full gigabit speed, so disable the assist automatically
-	** when at lower speeds.  -jfv
-	*/
-	if (ifp->if_capenable & IFCAP_TSO4) {
-		if (adapter->link_speed == SPEED_1000)
-			ifp->if_hwassist |= CSUM_TSO;
-	}
+	else
+		ifp->if_hwassist &= ~(CSUM_TCP | CSUM_UDP);
 
 	/* Configure for OS presence */
 	em_init_manageability(adapter);
@@ -1926,7 +1934,7 @@
 	bool			do_tso, tso_desc, remap = TRUE;
 
 	m_head = *m_headp;
-	do_tso = (m_head->m_pkthdr.csum_flags & CSUM_TSO);
+	do_tso = m_head->m_pkthdr.csum_flags & CSUM_IP_TSO;
 	tso_desc = FALSE;
 	ip_off = poff = 0;
 
@@ -2113,7 +2121,7 @@
 	m_head = *m_headp;
 
 	/* Do hardware assists */
-	if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
+	if (m_head->m_pkthdr.csum_flags & CSUM_IP_TSO) {
 		em_tso_setup(txr, m_head, ip_off, ip, tp,
 		    &txd_upper, &txd_lower);
 		/* we need to make a final sentinel transmit desc */
@@ -2458,6 +2466,19 @@
 	if (link_check && (adapter->link_active == 0)) {
 		e1000_get_speed_and_duplex(hw, &adapter->link_speed,
 		    &adapter->link_duplex);
+
+		/*
+		** There have proven to be problems with TSO when not at full
+		** gigabit speed, so disable the assist automatically when at
+		** lower speeds.  -jfv
+		*/
+		if (ifp->if_capenable & IFCAP_TSO4) {
+			if (adapter->link_speed == SPEED_1000)
+				ifp->if_hwassist |= CSUM_IP_TSO;
+			else
+				ifp->if_hwassist &= ~CSUM_IP_TSO;
+		}
+
 		/* Check if we must disable SPEED_MODE bit on PCI-E */
 		if ((adapter->link_speed != SPEED_1000) &&
 		    ((hw->mac.type == e1000_82571) ||
@@ -2594,7 +2615,7 @@
  *  Setup the Legacy or MSI Interrupt handler
  *
  **********************************************************************/
-int
+static int
 em_allocate_legacy(struct adapter *adapter)
 {
 	device_t dev = adapter->dev;
@@ -2651,7 +2672,7 @@
  *   for TX, RX, and Link.
  *
  **********************************************************************/
-int
+static int
 em_allocate_msix(struct adapter *adapter)
 {
 	device_t	dev = adapter->dev;
@@ -3118,6 +3139,7 @@
 	case e1000_pch2lan:
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		pba = E1000_PBA_26K;
 		break;
 	default:
@@ -3177,6 +3199,7 @@
 	case e1000_pch2lan:
 	case e1000_pch_lpt:
 	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		hw->fc.high_water = 0x5C20;
 		hw->fc.low_water = 0x5048;
 		hw->fc.pause_time = 0x0650;
@@ -3247,8 +3270,8 @@
 	/* TSO parameters */
 	ifp->if_hw_tsomax = IP_MAXPACKET;
 	/* Take m_pullup(9)'s in em_xmit() w/ TSO into acount. */
-	//ifp->if_hw_tsomaxsegcount = EM_MAX_SCATTER - 5;
-	//ifp->if_hw_tsomaxsegsize = EM_TSO_SEG_SIZE;
+	ifp->if_hw_tsomaxsegcount = EM_MAX_SCATTER - 5;
+	ifp->if_hw_tsomaxsegsize = EM_TSO_SEG_SIZE;
 
 #ifdef EM_MULTIQUEUE
 	/* Multiqueue stack interface */
@@ -3263,11 +3286,9 @@
 
 	ether_ifattach(ifp, adapter->hw.mac.addr);
 
-	ifp->if_capabilities = ifp->if_capenable = 0;
+	ifp->if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM;
+	ifp->if_capenable = ifp->if_capabilities;
 
-
-	ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_VLAN_HWCSUM;
-	ifp->if_capabilities |= IFCAP_TSO4;
 	/*
 	 * Tell the upper layer(s) we
 	 * support full VLAN capability
@@ -3276,9 +3297,28 @@
 	ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING
 			     |  IFCAP_VLAN_HWTSO
 			     |  IFCAP_VLAN_MTU;
-	ifp->if_capenable = ifp->if_capabilities;
+	ifp->if_capenable |= IFCAP_VLAN_HWTAGGING
+			  |  IFCAP_VLAN_MTU;
 
 	/*
+	 * We don't enable IFCAP_{TSO4,VLAN_HWTSO} by default because:
+	 * - Although the silicon bug of TSO only working at gigabit speed is
+	 *   worked around in em_update_link_status() by selectively setting
+	 *   CSUM_IP_TSO, we cannot atomically flush already queued TSO-using
+	 *   descriptors.  Thus, such descriptors may still cause the MAC to
+	 *   hang and, consequently, TSO is only safe to be used in setups
+	 *   where the link isn't expected to switch from gigabit to lower
+	 *   speeds.
+	 * - Similarly, there's currently no way to trigger a reconfiguration
+	 *   of vlan(4) when the state of IFCAP_VLAN_HWTSO support changes at
+	 *   runtime.  Therefore, IFCAP_VLAN_HWTSO also only is safe to use
+	 *   when link speed changes are not to be expected.
+	 * - Despite all the workarounds for TSO-related silicon bugs, at
+	 *   least 82579 still may hang at gigabit speed with IFCAP_TSO4.
+	 */
+	ifp->if_capabilities |= IFCAP_TSO4 | IFCAP_VLAN_HWTSO;
+
+	/*
 	** Don't turn this on by default, if vlans are
 	** created on another pseudo device (eg. lagg)
 	** then vlan events are not passed thru, breaking
@@ -3802,13 +3842,16 @@
 	/* This write will effectively turn on the transmit unit. */
 	E1000_WRITE_REG(&adapter->hw, E1000_TCTL, tctl);
 
+	/* SPT and KBL errata workarounds */
 	if (hw->mac.type == e1000_pch_spt) {
 		u32 reg;
 		reg = E1000_READ_REG(hw, E1000_IOSFPC);
 		reg |= E1000_RCTL_RDMTS_HEX;
 		E1000_WRITE_REG(hw, E1000_IOSFPC, reg);
+		/* i218-i219 Specification Update 1.5.4.5 */
 		reg = E1000_READ_REG(hw, E1000_TARC(0));
-		reg |= E1000_TARC0_CB_MULTIQ_3_REQ;
+		reg &= ~E1000_TARC0_CB_MULTIQ_3_REQ;
+		reg |= E1000_TARC0_CB_MULTIQ_2_REQ;
 		E1000_WRITE_REG(hw, E1000_TARC(0), reg);
 	}
 }
@@ -5316,6 +5359,9 @@
 	case e1000_ich10lan:
 	case e1000_pchlan:
 	case e1000_pch2lan:
+	case e1000_pch_lpt:
+	case e1000_pch_spt:
+	case e1000_pch_cnp:
 		apme_mask = E1000_WUC_APME;
 		adapter->has_amt = TRUE;
 		eeprom_data = E1000_READ_REG(&adapter->hw, E1000_WUC);
@@ -5364,32 +5410,13 @@
 {
 	struct adapter	*adapter = device_get_softc(dev);
 	struct ifnet	*ifp = adapter->ifp;
+	int		error = 0;
 	u32		pmc, ctrl, ctrl_ext, rctl;
 	u16     	status;
 
-	if ((pci_find_cap(dev, PCIY_PMG, &pmc) != 0))
+	if (pci_find_cap(dev, PCIY_PMG, &pmc) != 0)
 		return;
 
-	/* Advertise the wakeup capability */
-	ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL);
-	ctrl |= (E1000_CTRL_SWDPIN2 | E1000_CTRL_SWDPIN3);
-	E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl);
-	E1000_WRITE_REG(&adapter->hw, E1000_WUC, E1000_WUC_PME_EN);
-
-	if ((adapter->hw.mac.type == e1000_ich8lan) ||
-	    (adapter->hw.mac.type == e1000_pchlan) ||
-	    (adapter->hw.mac.type == e1000_ich9lan) ||
-	    (adapter->hw.mac.type == e1000_ich10lan))
-		e1000_suspend_workarounds_ich8lan(&adapter->hw);
-
-	/* Keep the laser running on Fiber adapters */
-	if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
-	    adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
-		ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT);
-		ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
-		E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, ctrl_ext);
-	}
-
 	/*
 	** Determine type of Wakeup: note that wol
 	** is set with all bits on by default.
@@ -5405,11 +5432,37 @@
 		E1000_WRITE_REG(&adapter->hw, E1000_RCTL, rctl);
 	}
 
-	if ((adapter->hw.mac.type == e1000_pchlan) ||
-	    (adapter->hw.mac.type == e1000_pch2lan)) {
-		if (em_enable_phy_wakeup(adapter))
-			return;
+	if (!(adapter->wol & (E1000_WUFC_EX | E1000_WUFC_MAG | E1000_WUFC_MC)))
+		goto pme;
+
+	/* Advertise the wakeup capability */
+	ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL);
+	ctrl |= (E1000_CTRL_SWDPIN2 | E1000_CTRL_SWDPIN3);
+	E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl);
+
+	/* Keep the laser running on Fiber adapters */
+	if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
+	    adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
+		ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT);
+		ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
+		E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, ctrl_ext);
+	}
+
+	if ((adapter->hw.mac.type == e1000_ich8lan) ||
+	    (adapter->hw.mac.type == e1000_pchlan) ||
+	    (adapter->hw.mac.type == e1000_ich9lan) ||
+	    (adapter->hw.mac.type == e1000_ich10lan))
+		e1000_suspend_workarounds_ich8lan(&adapter->hw);
+
+	if ((adapter->hw.mac.type == e1000_pchlan)  ||
+	    (adapter->hw.mac.type == e1000_pch2lan) ||
+	    (adapter->hw.mac.type == e1000_pch_lpt) ||
+	    (adapter->hw.mac.type == e1000_pch_spt)) {
+		error = em_enable_phy_wakeup(adapter);
+		if (error)
+			goto pme;
 	} else {
+		/* Enable wakeup by the MAC */
 		E1000_WRITE_REG(&adapter->hw, E1000_WUC, E1000_WUC_PME_EN);
 		E1000_WRITE_REG(&adapter->hw, E1000_WUFC, adapter->wol);
 	}
@@ -5417,10 +5470,10 @@
 	if (adapter->hw.phy.type == e1000_phy_igp_3)
 		e1000_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
 
-        /* Request PME */
+pme:
         status = pci_read_config(dev, pmc + PCIR_POWER_STATUS, 2);
 	status &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE);
-	if (ifp->if_capenable & IFCAP_WOL)
+	if (!error && (ifp->if_capenable & IFCAP_WOL))
 		status |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE;
         pci_write_config(dev, pmc + PCIR_POWER_STATUS, status, 2);
 

Modified: trunk/sys/dev/e1000/if_em.h
===================================================================
--- trunk/sys/dev/e1000/if_em.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/if_em.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/if_igb.c
===================================================================
--- trunk/sys/dev/e1000/if_igb.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/if_igb.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/if_igb.c 316588 2017-04-06 19:13:40Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/if_igb.c 323293 2017-09-08 00:11:35Z marius $*/
 
 
 #include "opt_inet.h"
@@ -724,12 +725,6 @@
 	igb_release_manageability(adapter);
 	igb_release_hw_control(adapter);
 
-	if (adapter->wol) {
-		E1000_WRITE_REG(&adapter->hw, E1000_WUC, E1000_WUC_PME_EN);
-		E1000_WRITE_REG(&adapter->hw, E1000_WUFC, adapter->wol);
-		igb_enable_wakeup(dev);
-	}
-
 	/* Unregister VLAN events */
 	if (adapter->vlan_attach != NULL)
 		EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
@@ -781,13 +776,8 @@
 
         igb_release_manageability(adapter);
 	igb_release_hw_control(adapter);
+	igb_enable_wakeup(dev);
 
-        if (adapter->wol) {
-                E1000_WRITE_REG(&adapter->hw, E1000_WUC, E1000_WUC_PME_EN);
-                E1000_WRITE_REG(&adapter->hw, E1000_WUFC, adapter->wol);
-                igb_enable_wakeup(dev);
-        }
-
 	IGB_CORE_UNLOCK(adapter);
 
 	return bus_generic_suspend(dev);
@@ -1216,6 +1206,14 @@
 			ifp->if_capenable ^= IFCAP_LRO;
 			reinit = 1;
 		}
+		if (mask & IFCAP_WOL) {
+			if (mask & IFCAP_WOL_MAGIC)
+				ifp->if_capenable ^= IFCAP_WOL_MAGIC;
+			if (mask & IFCAP_WOL_MCAST)
+				ifp->if_capenable ^= IFCAP_WOL_MCAST;
+			if (mask & IFCAP_WOL_UCAST)
+				ifp->if_capenable ^= IFCAP_WOL_UCAST;
+		}
 		if (reinit && (ifp->if_drv_flags & IFF_DRV_RUNNING))
 			igb_init(adapter);
 		VLAN_CAPABILITIES(ifp);
@@ -2275,7 +2273,7 @@
 	}
 
 	e1000_reset_hw(&adapter->hw);
-	E1000_WRITE_REG(&adapter->hw, E1000_WUC, 0);
+	E1000_WRITE_REG(&adapter->hw, E1000_WUFC, 0);
 
 	e1000_led_off(&adapter->hw);
 	e1000_cleanup_led(&adapter->hw);
@@ -3031,7 +3029,7 @@
 
 	/* Issue a global reset */
 	e1000_reset_hw(hw);
-	E1000_WRITE_REG(hw, E1000_WUC, 0);
+	E1000_WRITE_REG(hw, E1000_WUFC, 0);
 
 	/* Reset for AutoMediaDetect */
 	if (adapter->flags & IGB_MEDIA_RESET) {
@@ -3077,8 +3075,8 @@
 
 	/* TSO parameters */
 	ifp->if_hw_tsomax = IP_MAXPACKET;
-	//ifp->if_hw_tsomaxsegcount = IGB_MAX_SCATTER;
-	//ifp->if_hw_tsomaxsegsize = IGB_TSO_SEG_SIZE;
+	ifp->if_hw_tsomaxsegcount = IGB_MAX_SCATTER;
+	ifp->if_hw_tsomaxsegsize = IGB_TSO_SEG_SIZE;
 
 #ifndef IGB_LEGACY_TX
 	ifp->if_transmit = igb_mq_start;
@@ -3122,6 +3120,13 @@
 			  |  IFCAP_VLAN_MTU;
 
 	/*
+	 * Enable only WOL MAGIC by default if WOL is enabled in EEPROM.
+	 */
+	ifp->if_capabilities |= IFCAP_WOL;
+	if (adapter->wol)
+		ifp->if_capenable |= IFCAP_WOL_MAGIC;
+
+	/*
 	** Don't turn this on by default, if vlans are
 	** created on another pseudo device (eg. lagg)
 	** then vlan events are not passed thru, breaking
@@ -3733,9 +3738,10 @@
 		break;
 #endif
 	default:
-		panic("%s: CSUM_TSO but no supported IP version (0x%04x)",
-		    __func__, ntohs(eh_type));
-		break;
+		device_printf(adapter->dev,
+		    "CSUM_TSO but no supported IP version (0x%04x)",
+		    ntohs(eh_type));
+		return (ENXIO);
 	}
 
 	ctxd = txr->next_avail_desc;
@@ -5311,22 +5317,61 @@
 static void
 igb_enable_wakeup(device_t dev)
 {
-	u16     cap, status;
-	u8      id;
+	struct adapter	*adapter = device_get_softc(dev);
+	struct ifnet	*ifp = adapter->ifp;
+	u32		pmc, ctrl, ctrl_ext, rctl, wuc;
+	u16		status;
 
-	/* First find the capabilities pointer*/
-	cap = pci_read_config(dev, PCIR_CAP_PTR, 2);
-	/* Read the PM Capabilities */
-	id = pci_read_config(dev, cap, 1);
-	if (id != PCIY_PMG)     /* Something wrong */
+	if (pci_find_cap(dev, PCIY_PMG, &pmc) != 0)
 		return;
-	/* OK, we have the power capabilities, so
-	   now get the status register */
-	cap += PCIR_POWER_STATUS;
-	status = pci_read_config(dev, cap, 2);
-	status |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE;
-	pci_write_config(dev, cap, status, 2);
-	return;
+
+	adapter->wol = E1000_READ_REG(&adapter->hw, E1000_WUFC);
+	if (ifp->if_capenable & IFCAP_WOL_MAGIC)
+		adapter->wol |=  E1000_WUFC_MAG;
+	else
+		adapter->wol &= ~E1000_WUFC_MAG;
+
+	if (ifp->if_capenable & IFCAP_WOL_MCAST) {
+		adapter->wol |=  E1000_WUFC_MC;
+		rctl = E1000_READ_REG(&adapter->hw, E1000_RCTL);
+		rctl |= E1000_RCTL_MPE;
+		E1000_WRITE_REG(&adapter->hw, E1000_RCTL, rctl);
+	} else
+		adapter->wol &= ~E1000_WUFC_MC;
+
+	if (ifp->if_capenable & IFCAP_WOL_UCAST)
+		adapter->wol |=  E1000_WUFC_EX;
+	else
+		adapter->wol &= ~E1000_WUFC_EX;
+
+	if (!(adapter->wol & (E1000_WUFC_EX | E1000_WUFC_MAG | E1000_WUFC_MC)))
+		goto pme;
+
+	/* Advertise the wakeup capability */
+	ctrl = E1000_READ_REG(&adapter->hw, E1000_CTRL);
+	ctrl |= (E1000_CTRL_SWDPIN2 | E1000_CTRL_SWDPIN3);
+	E1000_WRITE_REG(&adapter->hw, E1000_CTRL, ctrl);
+
+	/* Keep the laser running on Fiber adapters */
+	if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
+	    adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
+		ctrl_ext = E1000_READ_REG(&adapter->hw, E1000_CTRL_EXT);
+		ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
+		E1000_WRITE_REG(&adapter->hw, E1000_CTRL_EXT, ctrl_ext);
+	}
+
+	/* Enable wakeup by the MAC */
+	wuc = E1000_READ_REG(&adapter->hw, E1000_WUC);
+	wuc |= E1000_WUC_PME_EN | E1000_WUC_APME;
+	E1000_WRITE_REG(&adapter->hw, E1000_WUC, wuc);
+	E1000_WRITE_REG(&adapter->hw, E1000_WUFC, adapter->wol);
+
+pme:
+	status = pci_read_config(dev, pmc + PCIR_POWER_STATUS, 2);
+	status &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE);
+	if (ifp->if_capenable & IFCAP_WOL)
+		status |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE;
+	pci_write_config(dev, pmc + PCIR_POWER_STATUS, status, 2);
 }
 
 static void

Modified: trunk/sys/dev/e1000/if_igb.h
===================================================================
--- trunk/sys/dev/e1000/if_igb.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/if_igb.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/e1000/if_lem.c
===================================================================
--- trunk/sys/dev/e1000/if_lem.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/if_lem.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 
@@ -30,7 +31,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: stable/10/sys/dev/e1000/if_lem.c 303117 2016-07-20 22:32:19Z sbruno $*/
+/*$FreeBSD: stable/10/sys/dev/e1000/if_lem.c 323293 2017-09-08 00:11:35Z marius $*/
 
 /*
  * Uncomment the following extensions for better performance in a VM,
@@ -2336,7 +2337,7 @@
  *  Setup the Legacy or MSI Interrupt handler
  *
  **********************************************************************/
-int
+static int
 lem_allocate_irq(struct adapter *adapter)
 {
 	device_t dev = adapter->dev;

Modified: trunk/sys/dev/e1000/if_lem.h
===================================================================
--- trunk/sys/dev/e1000/if_lem.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/e1000/if_lem.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
 
   Copyright (c) 2001-2015, Intel Corporation 

Modified: trunk/sys/dev/ex/if_ex.c
===================================================================
--- trunk/sys/dev/ex/if_ex.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/ex/if_ex.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1996, Javier Mart\xEDn Rueda (jmrueda at diatel.upm.es)
+ * Copyright (c) 1996, Javier Martín Rueda (jmrueda at diatel.upm.es)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ex/if_ex.c 243857 2012-12-04 09:32:43Z glebius $");
 
 /*
  * Intel EtherExpress Pro/10, Pro/10+ Ethernet driver
@@ -232,7 +233,6 @@
 	 */
 	ifp->if_softc = sc;
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
-	ifp->if_mtu = ETHERMTU;
 	ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST;
 	ifp->if_start = ex_start;
 	ifp->if_ioctl = ex_ioctl;

Modified: trunk/sys/dev/ex/if_ex_isa.c
===================================================================
--- trunk/sys/dev/ex/if_ex_isa.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/ex/if_ex_isa.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000 Matthew N. Dodd
  * All rights reserved.
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ex/if_ex_isa.c 182088 2008-08-24 00:22:42Z imp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/ex/if_ex_pccard.c
===================================================================
--- trunk/sys/dev/ex/if_ex_pccard.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/ex/if_ex_pccard.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000 Mitsuru IWASAKI
  * All rights reserved.
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/ex/if_ex_pccard.c 182227 2008-08-27 04:11:03Z imp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/ex/if_exreg.h
===================================================================
--- trunk/sys/dev/ex/if_exreg.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/ex/if_exreg.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1996, Javier Mart\xEDn Rueda (jmrueda at diatel.upm.es)
+ * Copyright (c) 1996, Javier Martín Rueda (jmrueda at diatel.upm.es)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/ex/if_exreg.h 230132 2012-01-15 13:23:18Z uqs $
  */
 
 /*

Modified: trunk/sys/dev/ex/if_exvar.h
===================================================================
--- trunk/sys/dev/ex/if_exvar.h	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/ex/if_exvar.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1996, Javier Mart^mn Rueda (jmrueda at diatel.upm.es)
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$MidnightBSD$
+ *	$FreeBSD: stable/10/sys/dev/ex/if_exvar.h 182088 2008-08-24 00:22:42Z imp $
  */
 
 struct ex_softc {

Added: trunk/sys/dev/ffec/if_ffec.c
===================================================================
--- trunk/sys/dev/ffec/if_ffec.c	                        (rev 0)
+++ trunk/sys/dev/ffec/if_ffec.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -0,0 +1,1773 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Ian Lepore <ian at freebsd.org>
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/ffec/if_ffec.c 276285 2014-12-27 04:35:18Z ian $");
+
+/*
+ * Driver for Freescale Fast Ethernet Controller, found on imx-series SoCs among
+ * others.  Also works for the ENET Gigibit controller found on imx6 and imx28,
+ * but the driver doesn't currently use any of the ENET advanced features other
+ * than enabling gigabit.
+ *
+ * The interface name 'fec' is already taken by netgraph's Fast Etherchannel
+ * (netgraph/ng_fec.c), so we use 'ffec'.
+ *
+ * Requires an FDT entry with at least these properties:
+ *   fec: ethernet at 02188000 {
+ *      compatible = "fsl,imxNN-fec";
+ *      reg = <0x02188000 0x4000>;
+ *      interrupts = <150 151>;
+ *      phy-mode = "rgmii";
+ *      phy-disable-preamble; // optional
+ *   };
+ * The second interrupt number is for IEEE-1588, and is not currently used; it
+ * need not be present.  phy-mode must be one of: "mii", "rmii", "rgmii".
+ * There is also an optional property, phy-disable-preamble, which if present
+ * will disable the preamble bits, cutting the size of each mdio transaction
+ * (and thus the busy-wait time) in half.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/endian.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/rman.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/sysctl.h>
+
+#include <machine/bus.h>
+
+#include <net/bpf.h>
+#include <net/if.h>
+#include <net/ethernet.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+#include <net/if_var.h>
+#include <net/if_vlan_var.h>
+
+#include <dev/ffec/if_ffecreg.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include "miibus_if.h"
+
+/*
+ * There are small differences in the hardware on various SoCs.  Not every SoC
+ * we support has its own FECTYPE; most work as GENERIC and only the ones that
+ * need different handling get their own entry.  In addition to the types in
+ * this list, there are some flags below that can be ORed into the upper bits.
+ */
+enum {
+	FECTYPE_NONE,
+	FECTYPE_GENERIC,
+	FECTYPE_IMX53,
+	FECTYPE_IMX6,
+};
+
+/*
+ * Flags that describe general differences between the FEC hardware in various
+ * SoCs.  These are ORed into the FECTYPE enum values.
+ */
+#define	FECTYPE_MASK		0x0000ffff
+#define	FECFLAG_GBE		(0x0001 << 16)
+
+/*
+ * Table of supported FDT compat strings and their associated FECTYPE values.
+ */
+static struct ofw_compat_data compat_data[] = {
+	{"fsl,imx51-fec",	FECTYPE_GENERIC},
+	{"fsl,imx53-fec",	FECTYPE_IMX53},
+	{"fsl,imx6q-fec",	FECTYPE_IMX6 | FECFLAG_GBE},
+	{"fsl,mvf600-fec",	FECTYPE_GENERIC},
+	{"fsl,vf-fec",		FECTYPE_GENERIC},
+	{NULL,		 	FECTYPE_NONE},
+};
+
+/*
+ * Driver data and defines.
+ */
+#define	RX_DESC_COUNT	64
+#define	RX_DESC_SIZE	(sizeof(struct ffec_hwdesc) * RX_DESC_COUNT)
+#define	TX_DESC_COUNT	64
+#define	TX_DESC_SIZE	(sizeof(struct ffec_hwdesc) * TX_DESC_COUNT)
+
+#define	WATCHDOG_TIMEOUT_SECS	5
+#define	STATS_HARVEST_INTERVAL	3
+
+struct ffec_bufmap {
+	struct mbuf	*mbuf;
+	bus_dmamap_t	map;
+};
+
+enum {
+	PHY_CONN_UNKNOWN,
+	PHY_CONN_MII,
+	PHY_CONN_RMII,
+	PHY_CONN_RGMII
+};
+
+struct ffec_softc {
+	device_t		dev;
+	device_t		miibus;
+	struct mii_data *	mii_softc;
+	struct ifnet		*ifp;
+	int			if_flags;
+	struct mtx		mtx;
+	struct resource		*irq_res;
+	struct resource		*mem_res;
+	void *			intr_cookie;
+	struct callout		ffec_callout;
+	uint8_t			phy_conn_type;
+	uint8_t			fectype;
+	boolean_t		link_is_up;
+	boolean_t		is_attached;
+	boolean_t		is_detaching;
+	int			tx_watchdog_count;
+	int			stats_harvest_count;
+
+	bus_dma_tag_t		rxdesc_tag;
+	bus_dmamap_t		rxdesc_map;
+	struct ffec_hwdesc	*rxdesc_ring;
+	bus_addr_t		rxdesc_ring_paddr;
+	bus_dma_tag_t		rxbuf_tag;
+	struct ffec_bufmap	rxbuf_map[RX_DESC_COUNT];
+	uint32_t		rx_idx;
+
+	bus_dma_tag_t		txdesc_tag;
+	bus_dmamap_t		txdesc_map;
+	struct ffec_hwdesc	*txdesc_ring;
+	bus_addr_t		txdesc_ring_paddr;
+	bus_dma_tag_t		txbuf_tag;
+	struct ffec_bufmap	txbuf_map[RX_DESC_COUNT];
+	uint32_t		tx_idx_head;
+	uint32_t		tx_idx_tail;
+	int			txcount;
+};
+
+#define	FFEC_LOCK(sc)			mtx_lock(&(sc)->mtx)
+#define	FFEC_UNLOCK(sc)			mtx_unlock(&(sc)->mtx)
+#define	FFEC_LOCK_INIT(sc)		mtx_init(&(sc)->mtx, \
+	    device_get_nameunit((sc)->dev), MTX_NETWORK_LOCK, MTX_DEF)
+#define	FFEC_LOCK_DESTROY(sc)		mtx_destroy(&(sc)->mtx);
+#define	FFEC_ASSERT_LOCKED(sc)		mtx_assert(&(sc)->mtx, MA_OWNED);
+#define	FFEC_ASSERT_UNLOCKED(sc)	mtx_assert(&(sc)->mtx, MA_NOTOWNED);
+
+static void ffec_init_locked(struct ffec_softc *sc);
+static void ffec_stop_locked(struct ffec_softc *sc);
+static void ffec_txstart_locked(struct ffec_softc *sc);
+static void ffec_txfinish_locked(struct ffec_softc *sc);
+
+static inline uint16_t
+RD2(struct ffec_softc *sc, bus_size_t off)
+{
+
+	return (bus_read_2(sc->mem_res, off));
+}
+
+static inline void
+WR2(struct ffec_softc *sc, bus_size_t off, uint16_t val)
+{
+
+	bus_write_2(sc->mem_res, off, val);
+}
+
+static inline uint32_t
+RD4(struct ffec_softc *sc, bus_size_t off)
+{
+
+	return (bus_read_4(sc->mem_res, off));
+}
+
+static inline void
+WR4(struct ffec_softc *sc, bus_size_t off, uint32_t val)
+{
+
+	bus_write_4(sc->mem_res, off, val);
+}
+
+static inline uint32_t
+next_rxidx(struct ffec_softc *sc, uint32_t curidx)
+{
+
+	return ((curidx == RX_DESC_COUNT - 1) ? 0 : curidx + 1);
+}
+
+static inline uint32_t
+next_txidx(struct ffec_softc *sc, uint32_t curidx)
+{
+
+	return ((curidx == TX_DESC_COUNT - 1) ? 0 : curidx + 1);
+}
+
+static void
+ffec_get1paddr(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
+{
+
+	if (error != 0)
+		return;
+	*(bus_addr_t *)arg = segs[0].ds_addr;
+}
+
+static void
+ffec_miigasket_setup(struct ffec_softc *sc)
+{
+	uint32_t ifmode;
+
+	/*
+	 * We only need the gasket for MII and RMII connections on certain SoCs.
+	 */
+
+	switch (sc->fectype & FECTYPE_MASK)
+	{
+	case FECTYPE_IMX53:
+		break;
+	default:
+		return;
+	}
+
+	switch (sc->phy_conn_type)
+	{
+	case PHY_CONN_MII:
+		ifmode = 0;
+		break;
+	case PHY_CONN_RMII:
+		ifmode = FEC_MIIGSK_CFGR_IF_MODE_RMII;
+		break;
+	default:
+		return;
+	}
+
+	/*
+	 * Disable the gasket, configure for either MII or RMII, then enable.
+	 */
+
+	WR2(sc, FEC_MIIGSK_ENR, 0);
+	while (RD2(sc, FEC_MIIGSK_ENR) & FEC_MIIGSK_ENR_READY)
+		continue;
+
+	WR2(sc, FEC_MIIGSK_CFGR, ifmode);
+
+	WR2(sc, FEC_MIIGSK_ENR, FEC_MIIGSK_ENR_EN);
+	while (!(RD2(sc, FEC_MIIGSK_ENR) & FEC_MIIGSK_ENR_READY))
+		continue;
+}
+
+static boolean_t
+ffec_miibus_iowait(struct ffec_softc *sc)
+{
+	uint32_t timeout;
+
+	for (timeout = 10000; timeout != 0; --timeout)
+		if (RD4(sc, FEC_IER_REG) & FEC_IER_MII)
+			return (true);
+
+	return (false);
+}
+
+static int
+ffec_miibus_readreg(device_t dev, int phy, int reg)
+{
+	struct ffec_softc *sc;
+	int val;
+
+	sc = device_get_softc(dev);
+
+	WR4(sc, FEC_IER_REG, FEC_IER_MII);
+
+	WR4(sc, FEC_MMFR_REG, FEC_MMFR_OP_READ |
+	    FEC_MMFR_ST_VALUE | FEC_MMFR_TA_VALUE |
+	    ((phy << FEC_MMFR_PA_SHIFT) & FEC_MMFR_PA_MASK) |
+	    ((reg << FEC_MMFR_RA_SHIFT) & FEC_MMFR_RA_MASK));
+
+	if (!ffec_miibus_iowait(sc)) {
+		device_printf(dev, "timeout waiting for mii read\n");
+		return (-1); /* All-ones is a symptom of bad mdio. */
+	}
+
+	val = RD4(sc, FEC_MMFR_REG) & FEC_MMFR_DATA_MASK;
+
+	return (val);
+}
+
+static int
+ffec_miibus_writereg(device_t dev, int phy, int reg, int val)
+{
+	struct ffec_softc *sc;
+
+	sc = device_get_softc(dev);
+
+	WR4(sc, FEC_IER_REG, FEC_IER_MII);
+
+	WR4(sc, FEC_MMFR_REG, FEC_MMFR_OP_WRITE |
+	    FEC_MMFR_ST_VALUE | FEC_MMFR_TA_VALUE |
+	    ((phy << FEC_MMFR_PA_SHIFT) & FEC_MMFR_PA_MASK) |
+	    ((reg << FEC_MMFR_RA_SHIFT) & FEC_MMFR_RA_MASK) |
+	    (val & FEC_MMFR_DATA_MASK));
+
+	if (!ffec_miibus_iowait(sc)) {
+		device_printf(dev, "timeout waiting for mii write\n");
+		return (-1);
+	}
+
+	return (0);
+}
+
+static void
+ffec_miibus_statchg(device_t dev)
+{
+	struct ffec_softc *sc;
+	struct mii_data *mii;
+	uint32_t ecr, rcr, tcr;
+
+	/*
+	 * Called by the MII bus driver when the PHY establishes link to set the
+	 * MAC interface registers.
+	 */
+
+	sc = device_get_softc(dev);
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	mii = sc->mii_softc;
+
+	if (mii->mii_media_status & IFM_ACTIVE)
+		sc->link_is_up = true;
+	else
+		sc->link_is_up = false;
+
+	ecr = RD4(sc, FEC_ECR_REG) & ~FEC_ECR_SPEED;
+	rcr = RD4(sc, FEC_RCR_REG) & ~(FEC_RCR_RMII_10T | FEC_RCR_RMII_MODE |
+	    FEC_RCR_RGMII_EN | FEC_RCR_DRT | FEC_RCR_FCE);
+	tcr = RD4(sc, FEC_TCR_REG) & ~FEC_TCR_FDEN;
+
+	rcr |= FEC_RCR_MII_MODE; /* Must always be on even for R[G]MII. */
+	switch (sc->phy_conn_type) {
+	case PHY_CONN_MII:
+		break;
+	case PHY_CONN_RMII:
+		rcr |= FEC_RCR_RMII_MODE;
+		break;
+	case PHY_CONN_RGMII:
+		rcr |= FEC_RCR_RGMII_EN;
+		break;
+	}
+
+	switch (IFM_SUBTYPE(mii->mii_media_active)) {
+	case IFM_1000_T:
+	case IFM_1000_SX:
+		ecr |= FEC_ECR_SPEED;
+		break;
+	case IFM_100_TX:
+		/* Not-FEC_ECR_SPEED + not-FEC_RCR_RMII_10T means 100TX */
+		break;
+	case IFM_10_T:
+		rcr |= FEC_RCR_RMII_10T;
+		break;
+	case IFM_NONE:
+		sc->link_is_up = false;
+		return;
+	default:
+		sc->link_is_up = false;
+		device_printf(dev, "Unsupported media %u\n",
+		    IFM_SUBTYPE(mii->mii_media_active));
+		return;
+	}
+
+	if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0)
+		tcr |= FEC_TCR_FDEN;
+	else
+		rcr |= FEC_RCR_DRT;
+
+	if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FLOW) != 0)
+		rcr |= FEC_RCR_FCE;
+
+	WR4(sc, FEC_RCR_REG, rcr);
+	WR4(sc, FEC_TCR_REG, tcr);
+	WR4(sc, FEC_ECR_REG, ecr);
+}
+
+static void
+ffec_media_status(struct ifnet * ifp, struct ifmediareq *ifmr)
+{
+	struct ffec_softc *sc;
+	struct mii_data *mii;
+
+
+	sc = ifp->if_softc;
+	mii = sc->mii_softc;
+	FFEC_LOCK(sc);
+	mii_pollstat(mii);
+	ifmr->ifm_active = mii->mii_media_active;
+	ifmr->ifm_status = mii->mii_media_status;
+	FFEC_UNLOCK(sc);
+}
+
+static int
+ffec_media_change_locked(struct ffec_softc *sc)
+{
+
+	return (mii_mediachg(sc->mii_softc));
+}
+
+static int
+ffec_media_change(struct ifnet * ifp)
+{
+	struct ffec_softc *sc;
+	int error;
+
+	sc = ifp->if_softc;
+
+	FFEC_LOCK(sc);
+	error = ffec_media_change_locked(sc);
+	FFEC_UNLOCK(sc);
+	return (error);
+}
+
+static void ffec_clear_stats(struct ffec_softc *sc)
+{
+
+	WR4(sc, FEC_RMON_R_PACKETS, 0);
+	WR4(sc, FEC_RMON_R_MC_PKT, 0);
+	WR4(sc, FEC_RMON_R_CRC_ALIGN, 0);
+	WR4(sc, FEC_RMON_R_UNDERSIZE, 0);
+	WR4(sc, FEC_RMON_R_OVERSIZE, 0);
+	WR4(sc, FEC_RMON_R_FRAG, 0);
+	WR4(sc, FEC_RMON_R_JAB, 0);
+	WR4(sc, FEC_RMON_T_PACKETS, 0);
+	WR4(sc, FEC_RMON_T_MC_PKT, 0);
+	WR4(sc, FEC_RMON_T_CRC_ALIGN, 0);
+	WR4(sc, FEC_RMON_T_UNDERSIZE, 0);
+	WR4(sc, FEC_RMON_T_OVERSIZE , 0);
+	WR4(sc, FEC_RMON_T_FRAG, 0);
+	WR4(sc, FEC_RMON_T_JAB, 0);
+	WR4(sc, FEC_RMON_T_COL, 0);
+}
+
+static void
+ffec_harvest_stats(struct ffec_softc *sc)
+{
+	struct ifnet *ifp;
+
+	/* We don't need to harvest too often. */
+	if (++sc->stats_harvest_count < STATS_HARVEST_INTERVAL)
+		return;
+
+	/*
+	 * Try to avoid harvesting unless the IDLE flag is on, but if it has
+	 * been too long just go ahead and do it anyway, the worst that'll
+	 * happen is we'll lose a packet count or two as we clear at the end.
+	 */
+	if (sc->stats_harvest_count < (2 * STATS_HARVEST_INTERVAL) &&
+	    ((RD4(sc, FEC_MIBC_REG) & FEC_MIBC_IDLE) == 0))
+		return;
+
+	sc->stats_harvest_count = 0;
+	ifp = sc->ifp;
+
+	ifp->if_ipackets   += RD4(sc, FEC_RMON_R_PACKETS);
+	ifp->if_imcasts    += RD4(sc, FEC_RMON_R_MC_PKT);
+	ifp->if_ierrors    += RD4(sc, FEC_RMON_R_CRC_ALIGN);
+	ifp->if_ierrors    += RD4(sc, FEC_RMON_R_UNDERSIZE);
+	ifp->if_ierrors    += RD4(sc, FEC_RMON_R_OVERSIZE);
+	ifp->if_ierrors    += RD4(sc, FEC_RMON_R_FRAG);
+	ifp->if_ierrors    += RD4(sc, FEC_RMON_R_JAB);
+
+	ifp->if_opackets   += RD4(sc, FEC_RMON_T_PACKETS);
+	ifp->if_omcasts    += RD4(sc, FEC_RMON_T_MC_PKT);
+	ifp->if_oerrors    += RD4(sc, FEC_RMON_T_CRC_ALIGN);
+	ifp->if_oerrors    += RD4(sc, FEC_RMON_T_UNDERSIZE);
+	ifp->if_oerrors    += RD4(sc, FEC_RMON_T_OVERSIZE );
+	ifp->if_oerrors    += RD4(sc, FEC_RMON_T_FRAG);
+	ifp->if_oerrors    += RD4(sc, FEC_RMON_T_JAB);
+
+	ifp->if_collisions += RD4(sc, FEC_RMON_T_COL);
+
+	ffec_clear_stats(sc);
+}
+
+static void
+ffec_tick(void *arg)
+{
+	struct ffec_softc *sc;
+	struct ifnet *ifp;
+	int link_was_up;
+
+	sc = arg;
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	ifp = sc->ifp;
+
+	if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
+	    return;
+
+	/*
+	 * Typical tx watchdog.  If this fires it indicates that we enqueued
+	 * packets for output and never got a txdone interrupt for them.  Maybe
+	 * it's a missed interrupt somehow, just pretend we got one.
+	 */
+	if (sc->tx_watchdog_count > 0) {
+		if (--sc->tx_watchdog_count == 0) {
+			ffec_txfinish_locked(sc);
+		}
+	}
+
+	/* Gather stats from hardware counters. */
+	ffec_harvest_stats(sc);
+
+	/* Check the media status. */
+	link_was_up = sc->link_is_up;
+	mii_tick(sc->mii_softc);
+	if (sc->link_is_up && !link_was_up)
+		ffec_txstart_locked(sc);
+
+	/* Schedule another check one second from now. */
+	callout_reset(&sc->ffec_callout, hz, ffec_tick, sc);
+}
+
+inline static uint32_t
+ffec_setup_txdesc(struct ffec_softc *sc, int idx, bus_addr_t paddr, 
+    uint32_t len)
+{
+	uint32_t nidx;
+	uint32_t flags;
+
+	nidx = next_txidx(sc, idx);
+
+	/* Addr/len 0 means we're clearing the descriptor after xmit done. */
+	if (paddr == 0 || len == 0) {
+		flags = 0;
+		--sc->txcount;
+	} else {
+		flags = FEC_TXDESC_READY | FEC_TXDESC_L | FEC_TXDESC_TC;
+		++sc->txcount;
+	}
+	if (nidx == 0)
+		flags |= FEC_TXDESC_WRAP;
+
+	/*
+	 * The hardware requires 32-bit physical addresses.  We set up the dma
+	 * tag to indicate that, so the cast to uint32_t should never lose
+	 * significant bits.
+	 */
+	sc->txdesc_ring[idx].buf_paddr = (uint32_t)paddr;
+	sc->txdesc_ring[idx].flags_len = flags | len; /* Must be set last! */
+
+	return (nidx);
+}
+
+static int
+ffec_setup_txbuf(struct ffec_softc *sc, int idx, struct mbuf **mp)
+{
+	struct mbuf * m;
+	int error, nsegs;
+	struct bus_dma_segment seg;
+
+	if ((m = m_defrag(*mp, M_NOWAIT)) == NULL)
+		return (ENOMEM);
+	*mp = m;
+
+	error = bus_dmamap_load_mbuf_sg(sc->txbuf_tag, sc->txbuf_map[idx].map,
+	    m, &seg, &nsegs, 0);
+	if (error != 0) {
+		return (ENOMEM);
+	}
+	bus_dmamap_sync(sc->txbuf_tag, sc->txbuf_map[idx].map, 
+	    BUS_DMASYNC_PREWRITE);
+
+	sc->txbuf_map[idx].mbuf = m;
+	ffec_setup_txdesc(sc, idx, seg.ds_addr, seg.ds_len);
+
+	return (0);
+
+}
+
+static void
+ffec_txstart_locked(struct ffec_softc *sc)
+{
+	struct ifnet *ifp;
+	struct mbuf *m;
+	int enqueued;
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	if (!sc->link_is_up)
+		return;
+
+	ifp = sc->ifp;
+
+	if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
+		return;
+
+	enqueued = 0;
+
+	for (;;) {
+		if (sc->txcount == (TX_DESC_COUNT-1)) {
+			ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+			break;
+		}
+		IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
+		if (m == NULL)
+			break;
+		if (ffec_setup_txbuf(sc, sc->tx_idx_head, &m) != 0) {
+			IFQ_DRV_PREPEND(&ifp->if_snd, m);
+			break;
+		}
+		BPF_MTAP(ifp, m);
+		sc->tx_idx_head = next_txidx(sc, sc->tx_idx_head);
+		++enqueued;
+	}
+
+	if (enqueued != 0) {
+		bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_PREWRITE);
+		WR4(sc, FEC_TDAR_REG, FEC_TDAR_TDAR);
+		bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_POSTWRITE);
+		sc->tx_watchdog_count = WATCHDOG_TIMEOUT_SECS;
+	}
+}
+
+static void
+ffec_txstart(struct ifnet *ifp)
+{
+	struct ffec_softc *sc = ifp->if_softc;
+
+	FFEC_LOCK(sc);
+	ffec_txstart_locked(sc);
+	FFEC_UNLOCK(sc);
+}
+
+static void
+ffec_txfinish_locked(struct ffec_softc *sc)
+{
+	struct ifnet *ifp;
+	struct ffec_hwdesc *desc;
+	struct ffec_bufmap *bmap;
+	boolean_t retired_buffer;
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	/* XXX Can't set PRE|POST right now, but we need both. */
+	bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_PREREAD);
+	bus_dmamap_sync(sc->txdesc_tag, sc->txdesc_map, BUS_DMASYNC_POSTREAD);
+	ifp = sc->ifp;
+	retired_buffer = false;
+	while (sc->tx_idx_tail != sc->tx_idx_head) {
+		desc = &sc->txdesc_ring[sc->tx_idx_tail];
+		if (desc->flags_len & FEC_TXDESC_READY)
+			break;
+		retired_buffer = true;
+		bmap = &sc->txbuf_map[sc->tx_idx_tail];
+		bus_dmamap_sync(sc->txbuf_tag, bmap->map, 
+		    BUS_DMASYNC_POSTWRITE);
+		bus_dmamap_unload(sc->txbuf_tag, bmap->map);
+		m_freem(bmap->mbuf);
+		bmap->mbuf = NULL;
+		ffec_setup_txdesc(sc, sc->tx_idx_tail, 0, 0);
+		sc->tx_idx_tail = next_txidx(sc, sc->tx_idx_tail);
+	}
+
+	/*
+	 * If we retired any buffers, there will be open tx slots available in
+	 * the descriptor ring, go try to start some new output.
+	 */
+	if (retired_buffer) {
+		ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
+		ffec_txstart_locked(sc);
+	}
+
+	/* If there are no buffers outstanding, muzzle the watchdog. */
+	if (sc->tx_idx_tail == sc->tx_idx_head) {
+		sc->tx_watchdog_count = 0;
+	}
+}
+
+inline static uint32_t
+ffec_setup_rxdesc(struct ffec_softc *sc, int idx, bus_addr_t paddr)
+{
+	uint32_t nidx;
+
+	/*
+	 * The hardware requires 32-bit physical addresses.  We set up the dma
+	 * tag to indicate that, so the cast to uint32_t should never lose
+	 * significant bits.
+	 */
+	nidx = next_rxidx(sc, idx);
+	sc->rxdesc_ring[idx].buf_paddr = (uint32_t)paddr;
+	sc->rxdesc_ring[idx].flags_len = FEC_RXDESC_EMPTY | 
+		((nidx == 0) ? FEC_RXDESC_WRAP : 0);
+
+	return (nidx);
+}
+
+static int
+ffec_setup_rxbuf(struct ffec_softc *sc, int idx, struct mbuf * m)
+{
+	int error, nsegs;
+	struct bus_dma_segment seg;
+
+	/*
+	 * We need to leave at least ETHER_ALIGN bytes free at the beginning of
+	 * the buffer to allow the data to be re-aligned after receiving it (by
+	 * copying it backwards ETHER_ALIGN bytes in the same buffer).  We also
+	 * have to ensure that the beginning of the buffer is aligned to the
+	 * hardware's requirements.
+	 */
+	m_adj(m, roundup(ETHER_ALIGN, FEC_RXBUF_ALIGN));
+
+	error = bus_dmamap_load_mbuf_sg(sc->rxbuf_tag, sc->rxbuf_map[idx].map,
+	    m, &seg, &nsegs, 0);
+	if (error != 0) {
+		return (error);
+	}
+
+	bus_dmamap_sync(sc->rxbuf_tag, sc->rxbuf_map[idx].map, 
+	    BUS_DMASYNC_PREREAD);
+
+	sc->rxbuf_map[idx].mbuf = m;
+	ffec_setup_rxdesc(sc, idx, seg.ds_addr);
+	
+	return (0);
+}
+
+static struct mbuf *
+ffec_alloc_mbufcl(struct ffec_softc *sc)
+{
+	struct mbuf *m;
+
+	m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
+	m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
+
+	return (m);
+}
+
+static void
+ffec_rxfinish_onebuf(struct ffec_softc *sc, int len)
+{
+	struct mbuf *m, *newmbuf;
+	struct ffec_bufmap *bmap;
+	uint8_t *dst, *src;
+	int error;
+
+	/*
+	 *  First try to get a new mbuf to plug into this slot in the rx ring.
+	 *  If that fails, drop the current packet and recycle the current
+	 *  mbuf, which is still mapped and loaded.
+	 */
+	if ((newmbuf = ffec_alloc_mbufcl(sc)) == NULL) {
+		++sc->ifp->if_iqdrops;
+		ffec_setup_rxdesc(sc, sc->rx_idx, 
+		    sc->rxdesc_ring[sc->rx_idx].buf_paddr);
+		return;
+	}
+
+	/*
+	 *  Unfortunately, the protocol headers need to be aligned on a 32-bit
+	 *  boundary for the upper layers.  The hardware requires receive
+	 *  buffers to be 16-byte aligned.  The ethernet header is 14 bytes,
+	 *  leaving the protocol header unaligned.  We used m_adj() after
+	 *  allocating the buffer to leave empty space at the start of the
+	 *  buffer, now we'll use the alignment agnostic bcopy() routine to
+	 *  shuffle all the data backwards 2 bytes and adjust m_data.
+	 *
+	 *  XXX imx6 hardware is able to do this 2-byte alignment by setting the
+	 *  SHIFT16 bit in the RACC register.  Older hardware doesn't have that
+	 *  feature, but for them could we speed this up by copying just the
+	 *  protocol headers into their own small mbuf then chaining the cluster
+	 *  to it?  That way we'd only need to copy like 64 bytes or whatever
+	 *  the biggest header is, instead of the whole 1530ish-byte frame.
+	 */
+
+	FFEC_UNLOCK(sc);
+
+	bmap = &sc->rxbuf_map[sc->rx_idx];
+	len -= ETHER_CRC_LEN;
+	bus_dmamap_sync(sc->rxbuf_tag, bmap->map, BUS_DMASYNC_POSTREAD);
+	bus_dmamap_unload(sc->rxbuf_tag, bmap->map);
+	m = bmap->mbuf;
+	bmap->mbuf = NULL;
+	m->m_len = len;
+	m->m_pkthdr.len = len;
+	m->m_pkthdr.rcvif = sc->ifp;
+
+	src = mtod(m, uint8_t*);
+	dst = src - ETHER_ALIGN;
+	bcopy(src, dst, len);
+	m->m_data = dst;
+	sc->ifp->if_input(sc->ifp, m);
+
+	FFEC_LOCK(sc);
+
+	if ((error = ffec_setup_rxbuf(sc, sc->rx_idx, newmbuf)) != 0) {
+		device_printf(sc->dev, "ffec_setup_rxbuf error %d\n", error);
+		/* XXX Now what?  We've got a hole in the rx ring. */
+	}
+
+}
+
+static void
+ffec_rxfinish_locked(struct ffec_softc *sc)
+{
+	struct ffec_hwdesc *desc;
+	int len;
+	boolean_t produced_empty_buffer;
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	/* XXX Can't set PRE|POST right now, but we need both. */
+	bus_dmamap_sync(sc->rxdesc_tag, sc->rxdesc_map, BUS_DMASYNC_PREREAD);
+	bus_dmamap_sync(sc->rxdesc_tag, sc->rxdesc_map, BUS_DMASYNC_POSTREAD);
+	produced_empty_buffer = false;
+	for (;;) {
+		desc = &sc->rxdesc_ring[sc->rx_idx];
+		if (desc->flags_len & FEC_RXDESC_EMPTY)
+			break;
+		produced_empty_buffer = true;
+		len = (desc->flags_len & FEC_RXDESC_LEN_MASK);
+		if (len < 64) {
+			/*
+			 * Just recycle the descriptor and continue.           .
+			 */
+			ffec_setup_rxdesc(sc, sc->rx_idx,
+			    sc->rxdesc_ring[sc->rx_idx].buf_paddr);
+		} else if ((desc->flags_len & FEC_RXDESC_L) == 0) {
+			/*
+			 * The entire frame is not in this buffer.  Impossible.
+			 * Recycle the descriptor and continue.
+			 *
+			 * XXX what's the right way to handle this? Probably we
+			 * should stop/init the hardware because this should
+			 * just really never happen when we have buffers bigger
+			 * than the maximum frame size.
+			 */
+			device_printf(sc->dev, 
+			    "fec_rxfinish: received frame without LAST bit set");
+			ffec_setup_rxdesc(sc, sc->rx_idx, 
+			    sc->rxdesc_ring[sc->rx_idx].buf_paddr);
+		} else if (desc->flags_len & FEC_RXDESC_ERROR_BITS) {
+			/*
+			 *  Something went wrong with receiving the frame, we
+			 *  don't care what (the hardware has counted the error
+			 *  in the stats registers already), we just reuse the
+			 *  same mbuf, which is still dma-mapped, by resetting
+			 *  the rx descriptor.
+			 */
+			ffec_setup_rxdesc(sc, sc->rx_idx, 
+			    sc->rxdesc_ring[sc->rx_idx].buf_paddr);
+		} else {
+			/*
+			 *  Normal case: a good frame all in one buffer.
+			 */
+			ffec_rxfinish_onebuf(sc, len);
+		}
+		sc->rx_idx = next_rxidx(sc, sc->rx_idx);
+	}
+
+	if (produced_empty_buffer) {
+		bus_dmamap_sync(sc->rxdesc_tag, sc->txdesc_map, BUS_DMASYNC_PREWRITE);
+		WR4(sc, FEC_RDAR_REG, FEC_RDAR_RDAR);
+		bus_dmamap_sync(sc->rxdesc_tag, sc->txdesc_map, BUS_DMASYNC_POSTWRITE);
+	}
+}
+
+static void
+ffec_get_hwaddr(struct ffec_softc *sc, uint8_t *hwaddr)
+{
+	uint32_t palr, paur, rnd;
+
+	/*
+	 * Try to recover a MAC address from the running hardware. If there's
+	 * something non-zero there, assume the bootloader did the right thing
+	 * and just use it.
+	 *
+	 * Otherwise, set the address to a convenient locally assigned address,
+	 * 'bsd' + random 24 low-order bits.  'b' is 0x62, which has the locally
+	 * assigned bit set, and the broadcast/multicast bit clear.
+	 */
+	palr = RD4(sc, FEC_PALR_REG);
+	paur = RD4(sc, FEC_PAUR_REG) & FEC_PAUR_PADDR2_MASK;
+	if ((palr | paur) != 0) {
+		hwaddr[0] = palr >> 24;
+		hwaddr[1] = palr >> 16;
+		hwaddr[2] = palr >>  8;
+		hwaddr[3] = palr >>  0;
+		hwaddr[4] = paur >> 24;
+		hwaddr[5] = paur >> 16;
+	} else {
+		rnd = arc4random() & 0x00ffffff;
+		hwaddr[0] = 'b';
+		hwaddr[1] = 's';
+		hwaddr[2] = 'd';
+		hwaddr[3] = rnd >> 16;
+		hwaddr[4] = rnd >>  8;
+		hwaddr[5] = rnd >>  0;
+	}
+
+	if (bootverbose) {
+		device_printf(sc->dev,
+		    "MAC address %02x:%02x:%02x:%02x:%02x:%02x:\n",
+		    hwaddr[0], hwaddr[1], hwaddr[2], 
+		    hwaddr[3], hwaddr[4], hwaddr[5]);
+	}
+}
+
+static void
+ffec_setup_rxfilter(struct ffec_softc *sc)
+{
+	struct ifnet *ifp;
+	struct ifmultiaddr *ifma;
+	uint8_t *eaddr;
+	uint32_t crc;
+	uint64_t ghash, ihash;
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	ifp = sc->ifp;
+
+	/*
+	 * Set the multicast (group) filter hash.
+	 */
+	if ((ifp->if_flags & IFF_ALLMULTI))
+		ghash = 0xffffffffffffffffLLU;
+	else {
+		ghash = 0;
+		if_maddr_rlock(ifp);
+		TAILQ_FOREACH(ifma, &sc->ifp->if_multiaddrs, ifma_link) {
+			if (ifma->ifma_addr->sa_family != AF_LINK)
+				continue;
+			/* 6 bits from MSB in LE CRC32 are used for hash. */
+			crc = ether_crc32_le(LLADDR((struct sockaddr_dl *)
+			    ifma->ifma_addr), ETHER_ADDR_LEN);
+			ghash |= 1LLU << (((uint8_t *)&crc)[3] >> 2);
+		}
+		if_maddr_runlock(ifp);
+	}
+	WR4(sc, FEC_GAUR_REG, (uint32_t)(ghash >> 32));
+	WR4(sc, FEC_GALR_REG, (uint32_t)ghash);
+
+	/*
+	 * Set the individual address filter hash.
+	 *
+	 * XXX Is 0 the right value when promiscuous is off?  This hw feature
+	 * seems to support the concept of MAC address aliases, does such a
+	 * thing even exist?
+	 */
+	if ((ifp->if_flags & IFF_PROMISC))
+		ihash = 0xffffffffffffffffLLU;
+	else {
+		ihash = 0;
+	}
+	WR4(sc, FEC_IAUR_REG, (uint32_t)(ihash >> 32));
+	WR4(sc, FEC_IALR_REG, (uint32_t)ihash);
+
+	/*
+	 * Set the primary address.
+	 */
+	eaddr = IF_LLADDR(ifp);
+	WR4(sc, FEC_PALR_REG, (eaddr[0] << 24) | (eaddr[1] << 16) |
+	    (eaddr[2] <<  8) | eaddr[3]);
+	WR4(sc, FEC_PAUR_REG, (eaddr[4] << 24) | (eaddr[5] << 16));
+}
+
+static void
+ffec_stop_locked(struct ffec_softc *sc)
+{
+	struct ifnet *ifp;
+	struct ffec_hwdesc *desc;
+	struct ffec_bufmap *bmap;
+	int idx;
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	ifp = sc->ifp;
+	ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
+	sc->tx_watchdog_count = 0;
+	sc->stats_harvest_count = 0;
+
+	/* 
+	 * Stop the hardware, mask all interrupts, and clear all current
+	 * interrupt status bits.
+	 */
+	WR4(sc, FEC_ECR_REG, RD4(sc, FEC_ECR_REG) & ~FEC_ECR_ETHEREN);
+	WR4(sc, FEC_IEM_REG, 0x00000000);
+	WR4(sc, FEC_IER_REG, 0xffffffff);
+
+	/*
+	 * Stop the media-check callout.  Do not use callout_drain() because
+	 * we're holding a mutex the callout acquires, and if it's currently
+	 * waiting to acquire it, we'd deadlock.  If it is waiting now, the
+	 * ffec_tick() routine will return without doing anything when it sees
+	 * that IFF_DRV_RUNNING is not set, so avoiding callout_drain() is safe.
+	 */
+	callout_stop(&sc->ffec_callout);
+
+	/*
+	 * Discard all untransmitted buffers.  Each buffer is simply freed;
+	 * it's as if the bits were transmitted and then lost on the wire.
+	 *
+	 * XXX Is this right?  Or should we use IFQ_DRV_PREPEND() to put them
+	 * back on the queue for when we get restarted later?
+	 */
+	idx = sc->tx_idx_tail;
+	while (idx != sc->tx_idx_head) {
+		desc = &sc->txdesc_ring[idx];
+		bmap = &sc->txbuf_map[idx];
+		if (desc->buf_paddr != 0) {
+			bus_dmamap_unload(sc->txbuf_tag, bmap->map);
+			m_freem(bmap->mbuf);
+			bmap->mbuf = NULL;
+			ffec_setup_txdesc(sc, idx, 0, 0);
+		}
+		idx = next_txidx(sc, idx);
+	}
+
+	/*
+	 * Discard all unprocessed receive buffers.  This amounts to just
+	 * pretending that nothing ever got received into them.  We reuse the
+	 * mbuf already mapped for each desc, simply turning the EMPTY flags
+	 * back on so they'll get reused when we start up again.
+	 */
+	for (idx = 0; idx < RX_DESC_COUNT; ++idx) {
+		desc = &sc->rxdesc_ring[idx];
+		ffec_setup_rxdesc(sc, idx, desc->buf_paddr);
+	}
+}
+
+static void
+ffec_init_locked(struct ffec_softc *sc)
+{
+	struct ifnet *ifp = sc->ifp;
+	uint32_t maxbuf, maxfl, regval;
+
+	FFEC_ASSERT_LOCKED(sc);
+
+	/*
+	 * The hardware has a limit of 0x7ff as the max frame length (see
+	 * comments for MRBR below), and we use mbuf clusters as receive
+	 * buffers, and we currently are designed to receive an entire frame
+	 * into a single buffer.
+	 *
+	 * We start with a MCLBYTES-sized cluster, but we have to offset into
+	 * the buffer by ETHER_ALIGN to make room for post-receive re-alignment,
+	 * and then that value has to be rounded up to the hardware's DMA
+	 * alignment requirements, so all in all our buffer is that much smaller
+	 * than MCLBYTES.
+	 *
+	 * The resulting value is used as the frame truncation length and the
+	 * max buffer receive buffer size for now.  It'll become more complex
+	 * when we support jumbo frames and receiving fragments of them into
+	 * separate buffers.
+	 */
+	maxbuf = MCLBYTES - roundup(ETHER_ALIGN, FEC_RXBUF_ALIGN);
+	maxfl = min(maxbuf, 0x7ff);
+
+	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
+		return;
+
+	/* Mask all interrupts and clear all current interrupt status bits. */
+	WR4(sc, FEC_IEM_REG, 0x00000000);
+	WR4(sc, FEC_IER_REG, 0xffffffff);
+
+	/*
+	 * Go set up palr/puar, galr/gaur, ialr/iaur.
+	 */
+	ffec_setup_rxfilter(sc);
+
+	/*
+	 * TFWR - Transmit FIFO watermark register.
+	 *
+	 * Set the transmit fifo watermark register to "store and forward" mode
+	 * and also set a threshold of 128 bytes in the fifo before transmission
+	 * of a frame begins (to avoid dma underruns).  Recent FEC hardware
+	 * supports STRFWD and when that bit is set, the watermark level in the
+	 * low bits is ignored.  Older hardware doesn't have STRFWD, but writing
+	 * to that bit is innocuous, and the TWFR bits get used instead.
+	 */
+	WR4(sc, FEC_TFWR_REG, FEC_TFWR_STRFWD | FEC_TFWR_TWFR_128BYTE);
+
+	/* RCR - Receive control register.
+	 *
+	 * Set max frame length + clean out anything left from u-boot.
+	 */
+	WR4(sc, FEC_RCR_REG, (maxfl << FEC_RCR_MAX_FL_SHIFT));
+
+	/*
+	 * TCR - Transmit control register.
+	 *
+	 * Clean out anything left from u-boot.  Any necessary values are set in
+	 * ffec_miibus_statchg() based on the media type.
+	 */
+	WR4(sc, FEC_TCR_REG, 0);
+        
+	/*
+	 * OPD - Opcode/pause duration.
+	 *
+	 * XXX These magic numbers come from u-boot.
+	 */
+	WR4(sc, FEC_OPD_REG, 0x00010020);
+
+	/*
+	 * FRSR - Fifo receive start register.
+	 *
+	 * This register does not exist on imx6, it is present on earlier
+	 * hardware. The u-boot code sets this to a non-default value that's 32
+	 * bytes larger than the default, with no clue as to why.  The default
+	 * value should work fine, so there's no code to init it here.
+	 */
+
+	/*
+	 *  MRBR - Max RX buffer size.
+	 *
+	 *  Note: For hardware prior to imx6 this value cannot exceed 0x07ff,
+	 *  but the datasheet says no such thing for imx6.  On the imx6, setting
+	 *  this to 2K without setting EN1588 resulted in a crazy runaway
+	 *  receive loop in the hardware, where every rx descriptor in the ring
+	 *  had its EMPTY flag cleared, no completion or error flags set, and a
+	 *  length of zero.  I think maybe you can only exceed it when EN1588 is
+	 *  set, like maybe that's what enables jumbo frames, because in general
+	 *  the EN1588 flag seems to be the "enable new stuff" vs. "be legacy-
+	 *  compatible" flag.
+	 */
+	WR4(sc, FEC_MRBR_REG, maxfl << FEC_MRBR_R_BUF_SIZE_SHIFT);
+
+	/*
+	 * FTRL - Frame truncation length.
+	 *
+	 * Must be greater than or equal to the value set in FEC_RCR_MAXFL.
+	 */
+	WR4(sc, FEC_FTRL_REG, maxfl);
+
+	/*
+	 * RDSR / TDSR descriptor ring pointers.
+	 *
+	 * When we turn on ECR_ETHEREN at the end, the hardware zeroes its
+	 * internal current descriptor index values for both rings, so we zero
+	 * our index values as well.
+	 */
+	sc->rx_idx = 0;
+	sc->tx_idx_head = sc->tx_idx_tail = 0;
+	sc->txcount = 0;
+	WR4(sc, FEC_RDSR_REG, sc->rxdesc_ring_paddr);
+	WR4(sc, FEC_TDSR_REG, sc->txdesc_ring_paddr);
+
+	/*
+	 * EIM - interrupt mask register.
+	 *
+	 * We always enable the same set of interrupts while running; unlike
+	 * some drivers there's no need to change the mask on the fly depending
+	 * on what operations are in progress.
+	 */
+	WR4(sc, FEC_IEM_REG, FEC_IER_TXF | FEC_IER_RXF | FEC_IER_EBERR);
+
+	/*
+	 * MIBC - MIB control (hardware stats).
+	 */
+	regval = RD4(sc, FEC_MIBC_REG);
+	WR4(sc, FEC_MIBC_REG, regval | FEC_MIBC_DIS);
+	ffec_clear_stats(sc);
+	WR4(sc, FEC_MIBC_REG, regval & ~FEC_MIBC_DIS);
+
+	/*
+	 * ECR - Ethernet control register.
+	 *
+	 * This must happen after all the other config registers are set.  If
+	 * we're running on little-endian hardware, also set the flag for byte-
+	 * swapping descriptor ring entries.  This flag doesn't exist on older
+	 * hardware, but it can be safely set -- the bit position it occupies
+	 * was unused.
+	 */
+	regval = RD4(sc, FEC_ECR_REG);
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+	regval |= FEC_ECR_DBSWP;
+#endif
+	regval |= FEC_ECR_ETHEREN;
+	WR4(sc, FEC_ECR_REG, regval);
+
+	ifp->if_drv_flags |= IFF_DRV_RUNNING;
+
+       /*
+	* Call mii_mediachg() which will call back into ffec_miibus_statchg() to
+	* set up the remaining config registers based on the current media.
+	*/
+	mii_mediachg(sc->mii_softc);
+	callout_reset(&sc->ffec_callout, hz, ffec_tick, sc);
+
+	/*
+	 * Tell the hardware that receive buffers are available.  They were made
+	 * available in ffec_attach() or ffec_stop().
+	 */
+	WR4(sc, FEC_RDAR_REG, FEC_RDAR_RDAR);
+}
+
+static void
+ffec_init(void *if_softc)
+{
+	struct ffec_softc *sc = if_softc;
+
+	FFEC_LOCK(sc);
+	ffec_init_locked(sc);
+	FFEC_UNLOCK(sc);
+}
+
+static void
+ffec_intr(void *arg)
+{
+	struct ffec_softc *sc;
+	uint32_t ier;
+
+	sc = arg;
+
+	FFEC_LOCK(sc);
+
+	ier = RD4(sc, FEC_IER_REG);
+
+	if (ier & FEC_IER_TXF) {
+		WR4(sc, FEC_IER_REG, FEC_IER_TXF);
+		ffec_txfinish_locked(sc);
+	}
+
+	if (ier & FEC_IER_RXF) {
+		WR4(sc, FEC_IER_REG, FEC_IER_RXF);
+		ffec_rxfinish_locked(sc);
+	}
+
+	/*
+	 * We actually don't care about most errors, because the hardware copes
+	 * with them just fine, discarding the incoming bad frame, or forcing a
+	 * bad CRC onto an outgoing bad frame, and counting the errors in the
+	 * stats registers.  The one that really matters is EBERR (DMA bus
+	 * error) because the hardware automatically clears ECR[ETHEREN] and we
+	 * have to restart it here.  It should never happen.
+	 */
+	if (ier & FEC_IER_EBERR) {
+		WR4(sc, FEC_IER_REG, FEC_IER_EBERR);
+		device_printf(sc->dev, 
+		    "Ethernet DMA error, restarting controller.\n");
+		ffec_stop_locked(sc);
+		ffec_init_locked(sc);
+	}
+
+	FFEC_UNLOCK(sc);
+
+}
+
+static int
+ffec_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+{
+	struct ffec_softc *sc;
+	struct mii_data *mii;
+	struct ifreq *ifr;
+	int mask, error;
+
+	sc = ifp->if_softc;
+	ifr = (struct ifreq *)data;
+
+	error = 0;
+	switch (cmd) {
+	case SIOCSIFFLAGS:
+		FFEC_LOCK(sc);
+		if (ifp->if_flags & IFF_UP) {
+			if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+				if ((ifp->if_flags ^ sc->if_flags) &
+				    (IFF_PROMISC | IFF_ALLMULTI))
+					ffec_setup_rxfilter(sc);
+			} else {
+				if (!sc->is_detaching)
+					ffec_init_locked(sc);
+			}
+		} else {
+			if (ifp->if_drv_flags & IFF_DRV_RUNNING)
+				ffec_stop_locked(sc);
+		}
+		sc->if_flags = ifp->if_flags;
+		FFEC_UNLOCK(sc);
+		break;
+
+	case SIOCADDMULTI:
+	case SIOCDELMULTI:
+		if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+			FFEC_LOCK(sc);
+			ffec_setup_rxfilter(sc);
+			FFEC_UNLOCK(sc);
+		}
+		break;
+
+	case SIOCSIFMEDIA:
+	case SIOCGIFMEDIA:
+		mii = sc->mii_softc;
+		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, cmd);
+		break;
+
+	case SIOCSIFCAP:
+		mask = ifp->if_capenable ^ ifr->ifr_reqcap;
+		if (mask & IFCAP_VLAN_MTU) {
+			/* No work to do except acknowledge the change took. */
+			ifp->if_capenable ^= IFCAP_VLAN_MTU;
+		}
+		break;
+
+	default:
+		error = ether_ioctl(ifp, cmd, data);
+		break;
+	}       
+
+	return (error);
+}
+
+static int
+ffec_detach(device_t dev)
+{
+	struct ffec_softc *sc;
+	bus_dmamap_t map;
+	int idx;
+
+	/*
+	 * NB: This function can be called internally to unwind a failure to
+	 * attach. Make sure a resource got allocated/created before destroying.
+	 */
+
+	sc = device_get_softc(dev);
+
+	if (sc->is_attached) {
+		FFEC_LOCK(sc);
+		sc->is_detaching = true;
+		ffec_stop_locked(sc);
+		FFEC_UNLOCK(sc);
+		callout_drain(&sc->ffec_callout);
+		ether_ifdetach(sc->ifp);
+	}
+
+	/* XXX no miibus detach? */
+
+	/* Clean up RX DMA resources and free mbufs. */
+	for (idx = 0; idx < RX_DESC_COUNT; ++idx) {
+		if ((map = sc->rxbuf_map[idx].map) != NULL) {
+			bus_dmamap_unload(sc->rxbuf_tag, map);
+			bus_dmamap_destroy(sc->rxbuf_tag, map);
+			m_freem(sc->rxbuf_map[idx].mbuf);
+		}
+	}
+	if (sc->rxbuf_tag != NULL)
+		bus_dma_tag_destroy(sc->rxbuf_tag);
+	if (sc->rxdesc_map != NULL) {
+		bus_dmamap_unload(sc->rxdesc_tag, sc->rxdesc_map);
+		bus_dmamap_destroy(sc->rxdesc_tag, sc->rxdesc_map);
+	}
+	if (sc->rxdesc_tag != NULL)
+	bus_dma_tag_destroy(sc->rxdesc_tag);
+
+	/* Clean up TX DMA resources. */
+	for (idx = 0; idx < TX_DESC_COUNT; ++idx) {
+		if ((map = sc->txbuf_map[idx].map) != NULL) {
+			/* TX maps are already unloaded. */
+			bus_dmamap_destroy(sc->txbuf_tag, map);
+		}
+	}
+	if (sc->txbuf_tag != NULL)
+		bus_dma_tag_destroy(sc->txbuf_tag);
+	if (sc->txdesc_map != NULL) {
+		bus_dmamap_unload(sc->txdesc_tag, sc->txdesc_map);
+		bus_dmamap_destroy(sc->txdesc_tag, sc->txdesc_map);
+	}
+	if (sc->txdesc_tag != NULL)
+	bus_dma_tag_destroy(sc->txdesc_tag);
+
+	/* Release bus resources. */
+	if (sc->intr_cookie)
+		bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie);
+
+	if (sc->irq_res != NULL)
+		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
+
+	if (sc->mem_res != NULL)
+		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);
+
+	FFEC_LOCK_DESTROY(sc);
+	return (0);
+}
+
+static int
+ffec_attach(device_t dev)
+{
+	struct ffec_softc *sc;
+	struct ifnet *ifp = NULL;
+	struct mbuf *m;
+	phandle_t ofw_node;
+	int error, rid;
+	uint8_t eaddr[ETHER_ADDR_LEN];
+	char phy_conn_name[32];
+	uint32_t idx, mscr;
+
+	sc = device_get_softc(dev);
+	sc->dev = dev;
+
+	FFEC_LOCK_INIT(sc);
+
+	/*
+	 * There are differences in the implementation and features of the FEC
+	 * hardware on different SoCs, so figure out what type we are.
+	 */
+	sc->fectype = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
+
+	/*
+	 * We have to be told what kind of electrical connection exists between
+	 * the MAC and PHY or we can't operate correctly.
+	 */
+	if ((ofw_node = ofw_bus_get_node(dev)) == -1) {
+		device_printf(dev, "Impossible: Can't find ofw bus node\n");
+		error = ENXIO;
+		goto out;
+	}
+	if (OF_searchprop(ofw_node, "phy-mode", 
+	    phy_conn_name, sizeof(phy_conn_name)) != -1) {
+		if (strcasecmp(phy_conn_name, "mii") == 0)
+			sc->phy_conn_type = PHY_CONN_MII;
+		else if (strcasecmp(phy_conn_name, "rmii") == 0)
+			sc->phy_conn_type = PHY_CONN_RMII;
+		else if (strcasecmp(phy_conn_name, "rgmii") == 0)
+			sc->phy_conn_type = PHY_CONN_RGMII;
+	}
+	if (sc->phy_conn_type == PHY_CONN_UNKNOWN) {
+		device_printf(sc->dev, "No valid 'phy-mode' "
+		    "property found in FDT data for device.\n");
+		error = ENOATTR;
+		goto out;
+	}
+
+	callout_init_mtx(&sc->ffec_callout, &sc->mtx, 0);
+
+	/* Allocate bus resources for accessing the hardware. */
+	rid = 0;
+	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 
+	    RF_ACTIVE);
+	if (sc->mem_res == NULL) {
+		device_printf(dev, "could not allocate memory resources.\n");
+		error = ENOMEM;
+		goto out;
+	}
+	rid = 0;
+	sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
+	    RF_ACTIVE);
+	if (sc->irq_res == NULL) {
+		device_printf(dev, "could not allocate interrupt resources.\n");
+		error = ENOMEM;
+		goto out;
+	}
+
+	/*
+	 * Set up TX descriptor ring, descriptors, and dma maps.
+	 */
+	error = bus_dma_tag_create(
+	    bus_get_dma_tag(dev),	/* Parent tag. */
+	    FEC_DESC_RING_ALIGN, 0,	/* alignment, boundary */
+	    BUS_SPACE_MAXADDR_32BIT,	/* lowaddr */
+	    BUS_SPACE_MAXADDR,		/* highaddr */
+	    NULL, NULL,			/* filter, filterarg */
+	    TX_DESC_SIZE, 1, 		/* maxsize, nsegments */
+	    TX_DESC_SIZE,		/* maxsegsize */
+	    0,				/* flags */
+	    NULL, NULL,			/* lockfunc, lockarg */
+	    &sc->txdesc_tag);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not create TX ring DMA tag.\n");
+		goto out;
+	}
+
+	error = bus_dmamem_alloc(sc->txdesc_tag, (void**)&sc->txdesc_ring,
+	    BUS_DMA_COHERENT | BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->txdesc_map);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not allocate TX descriptor ring.\n");
+		goto out;
+	}
+
+	error = bus_dmamap_load(sc->txdesc_tag, sc->txdesc_map, sc->txdesc_ring,
+	    TX_DESC_SIZE, ffec_get1paddr, &sc->txdesc_ring_paddr, 0);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not load TX descriptor ring map.\n");
+		goto out;
+	}
+
+	error = bus_dma_tag_create(
+	    bus_get_dma_tag(dev),	/* Parent tag. */
+	    FEC_TXBUF_ALIGN, 0,		/* alignment, boundary */
+	    BUS_SPACE_MAXADDR_32BIT,	/* lowaddr */
+	    BUS_SPACE_MAXADDR,		/* highaddr */
+	    NULL, NULL,			/* filter, filterarg */
+	    MCLBYTES, 1, 		/* maxsize, nsegments */
+	    MCLBYTES,			/* maxsegsize */
+	    0,				/* flags */
+	    NULL, NULL,			/* lockfunc, lockarg */
+	    &sc->txbuf_tag);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not create TX ring DMA tag.\n");
+		goto out;
+	}
+
+	for (idx = 0; idx < TX_DESC_COUNT; ++idx) {
+		error = bus_dmamap_create(sc->txbuf_tag, 0, 
+		    &sc->txbuf_map[idx].map);
+		if (error != 0) {
+			device_printf(sc->dev,
+			    "could not create TX buffer DMA map.\n");
+			goto out;
+		}
+		ffec_setup_txdesc(sc, idx, 0, 0);
+	}
+
+	/*
+	 * Set up RX descriptor ring, descriptors, dma maps, and mbufs.
+	 */
+	error = bus_dma_tag_create(
+	    bus_get_dma_tag(dev),	/* Parent tag. */
+	    FEC_DESC_RING_ALIGN, 0,	/* alignment, boundary */
+	    BUS_SPACE_MAXADDR_32BIT,	/* lowaddr */
+	    BUS_SPACE_MAXADDR,		/* highaddr */
+	    NULL, NULL,			/* filter, filterarg */
+	    RX_DESC_SIZE, 1, 		/* maxsize, nsegments */
+	    RX_DESC_SIZE,		/* maxsegsize */
+	    0,				/* flags */
+	    NULL, NULL,			/* lockfunc, lockarg */
+	    &sc->rxdesc_tag);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not create RX ring DMA tag.\n");
+		goto out;
+	}
+
+	error = bus_dmamem_alloc(sc->rxdesc_tag, (void **)&sc->rxdesc_ring, 
+	    BUS_DMA_COHERENT | BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->rxdesc_map);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not allocate RX descriptor ring.\n");
+		goto out;
+	}
+
+	error = bus_dmamap_load(sc->rxdesc_tag, sc->rxdesc_map, sc->rxdesc_ring,
+	    RX_DESC_SIZE, ffec_get1paddr, &sc->rxdesc_ring_paddr, 0);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not load RX descriptor ring map.\n");
+		goto out;
+	}
+
+	error = bus_dma_tag_create(
+	    bus_get_dma_tag(dev),	/* Parent tag. */
+	    1, 0,			/* alignment, boundary */
+	    BUS_SPACE_MAXADDR_32BIT,	/* lowaddr */
+	    BUS_SPACE_MAXADDR,		/* highaddr */
+	    NULL, NULL,			/* filter, filterarg */
+	    MCLBYTES, 1, 		/* maxsize, nsegments */
+	    MCLBYTES,			/* maxsegsize */
+	    0,				/* flags */
+	    NULL, NULL,			/* lockfunc, lockarg */
+	    &sc->rxbuf_tag);
+	if (error != 0) {
+		device_printf(sc->dev,
+		    "could not create RX buf DMA tag.\n");
+		goto out;
+	}
+
+	for (idx = 0; idx < RX_DESC_COUNT; ++idx) {
+		error = bus_dmamap_create(sc->rxbuf_tag, 0, 
+		    &sc->rxbuf_map[idx].map);
+		if (error != 0) {
+			device_printf(sc->dev,
+			    "could not create RX buffer DMA map.\n");
+			goto out;
+		}
+		if ((m = ffec_alloc_mbufcl(sc)) == NULL) {
+			device_printf(dev, "Could not alloc mbuf\n");
+			error = ENOMEM;
+			goto out;
+		}
+		if ((error = ffec_setup_rxbuf(sc, idx, m)) != 0) {
+			device_printf(sc->dev,
+			    "could not create new RX buffer.\n");
+			goto out;
+		}
+	}
+
+	/* Try to get the MAC address from the hardware before resetting it. */
+	ffec_get_hwaddr(sc, eaddr);
+
+	/* Reset the hardware.  Disables all interrupts. */
+	WR4(sc, FEC_ECR_REG, FEC_ECR_RESET);
+
+	/* Setup interrupt handler. */
+	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
+	    NULL, ffec_intr, sc, &sc->intr_cookie);
+	if (error != 0) {
+		device_printf(dev, "could not setup interrupt handler.\n");
+		goto out;
+	}
+
+	/*
+	 * Set up the PHY control register.
+	 *
+	 * Speed formula for ENET is md_clock = mac_clock / ((N + 1) * 2).
+	 * Speed formula for FEC is  md_clock = mac_clock / (N * 2)
+	 *
+	 * XXX - Revisit this...
+	 *
+	 * For a Wandboard imx6 (ENET) I was originally using 4, but the uboot
+	 * code uses 10.  Both values seem to work, but I suspect many modern
+	 * PHY parts can do mdio at speeds far above the standard 2.5 MHz.
+	 *
+	 * Different imx manuals use confusingly different terminology (things
+	 * like "system clock" and "internal module clock") with examples that
+	 * use frequencies that have nothing to do with ethernet, giving the
+	 * vague impression that maybe the clock in question is the periphclock
+	 * or something.  In fact, on an imx53 development board (FEC),
+	 * measuring the mdio clock at the pin on the PHY and playing with
+	 * various divisors showed that the root speed was 66 MHz (clk_ipg_root
+	 * aka periphclock) and 13 was the right divisor.
+	 *
+	 * All in all, it seems likely that 13 is a safe divisor for now,
+	 * because if we really do need to base it on the peripheral clock
+	 * speed, then we need a platform-independant get-clock-freq API.
+	 */
+	mscr = 13 << FEC_MSCR_MII_SPEED_SHIFT;
+	if (OF_hasprop(ofw_node, "phy-disable-preamble")) {
+		mscr |= FEC_MSCR_DIS_PRE;
+		if (bootverbose)
+			device_printf(dev, "PHY preamble disabled\n");
+	}
+	WR4(sc, FEC_MSCR_REG, mscr);
+
+	/* Set up the ethernet interface. */
+	sc->ifp = ifp = if_alloc(IFT_ETHER);
+
+	ifp->if_softc = sc;
+	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
+	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+	ifp->if_capabilities = IFCAP_VLAN_MTU;
+	ifp->if_capenable = ifp->if_capabilities;
+	ifp->if_start = ffec_txstart;
+	ifp->if_ioctl = ffec_ioctl;
+	ifp->if_init = ffec_init;
+	IFQ_SET_MAXLEN(&ifp->if_snd, TX_DESC_COUNT - 1);
+	ifp->if_snd.ifq_drv_maxlen = TX_DESC_COUNT - 1;
+	IFQ_SET_READY(&ifp->if_snd);
+	ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
+
+#if 0 /* XXX The hardware keeps stats we could use for these. */
+	ifp->if_linkmib = &sc->mibdata;
+	ifp->if_linkmiblen = sizeof(sc->mibdata);
+#endif
+
+	/* Set up the miigasket hardware (if any). */
+	ffec_miigasket_setup(sc);
+
+	/* Attach the mii driver. */
+	error = mii_attach(dev, &sc->miibus, ifp, ffec_media_change,
+	    ffec_media_status, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
+	if (error != 0) {
+		device_printf(dev, "PHY attach failed\n");
+		goto out;
+	}
+	sc->mii_softc = device_get_softc(sc->miibus);
+
+	/* All ready to run, attach the ethernet interface. */
+	ether_ifattach(ifp, eaddr);
+	sc->is_attached = true;
+
+	error = 0;
+out:
+
+	if (error != 0)
+		ffec_detach(dev);
+
+	return (error);
+}
+
+static int
+ffec_probe(device_t dev)
+{
+	uintptr_t fectype;
+
+	if (!ofw_bus_status_okay(dev))
+		return (ENXIO);
+
+	fectype = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
+	if (fectype == FECTYPE_NONE)
+		return (ENXIO);
+
+	device_set_desc(dev, (fectype & FECFLAG_GBE) ?
+	    "Freescale Gigabit Ethernet Controller" :
+	    "Freescale Fast Ethernet Controller");
+
+	return (BUS_PROBE_DEFAULT);
+}
+
+
+static device_method_t ffec_methods[] = {
+	/* Device interface. */
+	DEVMETHOD(device_probe,		ffec_probe),
+	DEVMETHOD(device_attach,	ffec_attach),
+	DEVMETHOD(device_detach,	ffec_detach),
+
+/*
+	DEVMETHOD(device_shutdown,	ffec_shutdown),
+	DEVMETHOD(device_suspend,	ffec_suspend),
+	DEVMETHOD(device_resume,	ffec_resume),
+*/
+
+	/* MII interface. */
+	DEVMETHOD(miibus_readreg,	ffec_miibus_readreg),
+	DEVMETHOD(miibus_writereg,	ffec_miibus_writereg),
+	DEVMETHOD(miibus_statchg,	ffec_miibus_statchg),
+
+	DEVMETHOD_END
+};
+
+static driver_t ffec_driver = {
+	"ffec",
+	ffec_methods,
+	sizeof(struct ffec_softc)
+};
+
+static devclass_t ffec_devclass;
+
+DRIVER_MODULE(ffec, simplebus, ffec_driver, ffec_devclass, 0, 0);
+DRIVER_MODULE(miibus, ffec, miibus_driver, miibus_devclass, 0, 0);
+
+MODULE_DEPEND(ffec, ether, 1, 1, 1);
+MODULE_DEPEND(ffec, miibus, 1, 1, 1);


Property changes on: trunk/sys/dev/ffec/if_ffec.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/ffec/if_ffecreg.h
===================================================================
--- trunk/sys/dev/ffec/if_ffecreg.h	                        (rev 0)
+++ trunk/sys/dev/ffec/if_ffecreg.h	2018-05-27 23:54:22 UTC (rev 10109)
@@ -0,0 +1,304 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Ian Lepore <ian at freebsd.org>
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ */
+
+#ifndef IF_FFECREG_H
+#define IF_FFECREG_H
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/ffec/if_ffecreg.h 261455 2014-02-04 03:36:42Z eadler $");
+
+/*
+ * Hardware defines for Freescale Fast Ethernet Controller.
+ */
+
+/*
+ * MAC registers.
+ */
+#define	FEC_IER_REG			0x0004
+#define	FEC_IEM_REG			0x0008
+#define	  FEC_IER_HBERR			  (1U << 31)
+#define	  FEC_IER_BABR			  (1 << 30)
+#define	  FEC_IER_BABT			  (1 << 29)
+#define	  FEC_IER_GRA			  (1 << 28)
+#define	  FEC_IER_TXF			  (1 << 27)
+#define	  FEC_IER_TXB			  (1 << 26)
+#define	  FEC_IER_RXF			  (1 << 25)
+#define	  FEC_IER_RXB			  (1 << 24)
+#define	  FEC_IER_MII			  (1 << 23)
+#define	  FEC_IER_EBERR			  (1 << 22)
+#define	  FEC_IER_LC			  (1 << 21)
+#define	  FEC_IER_RL			  (1 << 20)
+#define	  FEC_IER_UN			  (1 << 19)
+#define	  FEC_IER_PLR			  (1 << 18)
+#define	  FEC_IER_WAKEUP		  (1 << 17)
+#define	  FEC_IER_AVAIL			  (1 << 16)
+#define	  FEC_IER_TIMER			  (1 << 15)
+
+#define	FEC_RDAR_REG			0x0010
+#define	  FEC_RDAR_RDAR			  (1 << 24)
+
+#define	FEC_TDAR_REG			0x0014
+#define	  FEC_TDAR_TDAR			  (1 << 24)
+
+#define	FEC_ECR_REG			0x0024
+#define	  FEC_ECR_DBSWP			  (1 <<  8)
+#define	  FEC_ECR_STOPEN		  (1 <<  7)
+#define	  FEC_ECR_DBGEN			  (1 <<  6)
+#define	  FEC_ECR_SPEED			  (1 <<  5)
+#define	  FEC_ECR_EN1588		  (1 <<  4)
+#define	  FEC_ECR_SLEEP			  (1 <<  3)
+#define	  FEC_ECR_MAGICEN		  (1 <<  2)
+#define	  FEC_ECR_ETHEREN		  (1 <<  1)
+#define	  FEC_ECR_RESET			  (1 <<  0)
+
+#define	FEC_MMFR_REG			0x0040
+#define	  FEC_MMFR_ST_SHIFT		  30
+#define	  FEC_MMFR_ST_VALUE		  (0x01 << FEC_MMFR_ST_SHIFT)
+#define	  FEC_MMFR_OP_SHIFT		  28
+#define	  FEC_MMFR_OP_WRITE		  (0x01 << FEC_MMFR_OP_SHIFT)
+#define	  FEC_MMFR_OP_READ		  (0x02 << FEC_MMFR_OP_SHIFT)
+#define	  FEC_MMFR_PA_SHIFT		  23
+#define	  FEC_MMFR_PA_MASK		  (0x1f << FEC_MMFR_PA_SHIFT)
+#define	  FEC_MMFR_RA_SHIFT		  18
+#define	  FEC_MMFR_RA_MASK		  (0x1f << FEC_MMFR_RA_SHIFT)
+#define	  FEC_MMFR_TA_SHIFT		  16
+#define	  FEC_MMFR_TA_VALUE		  (0x02 << FEC_MMFR_TA_SHIFT)
+#define	  FEC_MMFR_DATA_SHIFT		  0
+#define	  FEC_MMFR_DATA_MASK		  (0xffff << FEC_MMFR_DATA_SHIFT)
+
+#define	FEC_MSCR_REG			0x0044
+#define	  FEC_MSCR_HOLDTIME_SHIFT	  8
+#define	  FEC_MSCR_HOLDTIME_MASK	  (0x07 << FEC_MSCR_HOLDTIME_SHIFT)
+#define	  FEC_MSCR_DIS_PRE      	  (1 <<  7)
+#define	  FEC_MSCR_MII_SPEED_SHIFT	  1
+#define	  FEC_MSCR_MII_SPEED_MASk	  (0x3f << FEC_MSCR_MII_SPEED_SHIFT)
+
+#define	FEC_MIBC_REG			0x0064
+#define	  FEC_MIBC_DIS			  (1U << 31)
+#define	  FEC_MIBC_IDLE			  (1 << 30)
+#define	  FEC_MIBC_CLEAR		  (1 << 29) /* imx6 only */
+
+#define	FEC_RCR_REG			0x0084
+#define	  FEC_RCR_GRS			  (1U << 31)
+#define	  FEC_RCR_NLC			  (1 << 30)
+#define	  FEC_RCR_MAX_FL_SHIFT		  16
+#define	  FEC_RCR_MAX_FL_MASK		  (0x3fff << FEC_RCR_MAX_FL_SHIFT)
+#define	  FEC_RCR_CFEN			  (1 << 15)
+#define	  FEC_RCR_CRCFWD		  (1 << 14)
+#define	  FEC_RCR_PAUFWD		  (1 << 13)
+#define	  FEC_RCR_PADEN			  (1 << 12)
+#define	  FEC_RCR_RMII_10T		  (1 <<  9)
+#define	  FEC_RCR_RMII_MODE		  (1 <<  8)
+#define	  FEC_RCR_RGMII_EN		  (1 <<  6)
+#define	  FEC_RCR_FCE			  (1 <<  5)
+#define	  FEC_RCR_BC_REJ		  (1 <<  4)
+#define	  FEC_RCR_PROM			  (1 <<  3)
+#define	  FEC_RCR_MII_MODE		  (1 <<  2)
+#define	  FEC_RCR_DRT			  (1 <<  1)
+#define	  FEC_RCR_LOOP			  (1 <<  0)
+
+#define	FEC_TCR_REG			0x00c4
+#define	  FEC_TCR_ADDINS		  (1 <<  9)
+#define	  FEC_TCR_ADDSEL_SHIFT		  5
+#define	  FEC_TCR_ADDSEL_MASK		  (0x07 << FEC_TCR_ADDSEL_SHIFT)
+#define	  FEC_TCR_RFC_PAUSE		  (1 <<  4)
+#define	  FEC_TCR_TFC_PAUSE		  (1 <<  3)
+#define	  FEC_TCR_FDEN			  (1 <<  2)
+#define	  FEC_TCR_GTS			  (1 <<  0)
+
+#define	FEC_PALR_REG			0x00e4
+#define	  FEC_PALR_PADDR1_SHIFT		  0
+#define	  FEC_PALR_PADDR1_MASK		  (0xffffffff << FEC_PALR_PADDR1_SHIFT)
+
+#define	FEC_PAUR_REG			0x00e8
+#define	  FEC_PAUR_PADDR2_SHIFT		  16
+#define	  FEC_PAUR_PADDR2_MASK		  (0xffff << FEC_PAUR_PADDR2_SHIFT)
+#define	  FEC_PAUR_TYPE_VALUE		  (0x8808)
+
+#define	FEC_OPD_REG			0x00ec
+#define	  FEC_OPD_PAUSE_DUR_SHIFT	  0
+#define	  FEC_OPD_PAUSE_DUR_MASK	  (0xffff << FEC_OPD_PAUSE_DUR_SHIFT)
+
+#define	FEC_IAUR_REG			0x0118
+#define	FEC_IALR_REG			0x011c
+
+#define	FEC_GAUR_REG			0x0120
+#define	FEC_GALR_REG			0x0124
+
+#define	FEC_TFWR_REG			0x0144
+#define	  FEC_TFWR_STRFWD		  (1 <<  8)
+#define	  FEC_TFWR_TWFR_SHIFT		  0
+#define	  FEC_TFWR_TWFR_MASK		  (0x3f << FEC_TFWR_TWFR_SHIFT)
+#define	  FEC_TFWR_TWFR_128BYTE		  (0x02 << FEC_TFWR_TWFR_SHIFT)
+
+#define	FEC_RDSR_REG			0x0180
+
+#define	FEC_TDSR_REG			0x0184
+
+#define	FEC_MRBR_REG			0x0188
+#define	  FEC_MRBR_R_BUF_SIZE_SHIFT	  0
+#define	  FEC_MRBR_R_BUF_SIZE_MASK	  (0x3fff << FEC_MRBR_R_BUF_SIZE_SHIFT)
+
+#define	FEC_RSFL_REG			0x0190
+#define	FEC_RSEM_REG			0x0194
+#define	FEC_RAEM_REG			0x0198
+#define	FEC_RAFL_REG			0x019c
+#define	FEC_TSEM_REG			0x01a0
+#define	FEC_TAEM_REG			0x01a4
+#define	FEC_TAFL_REG			0x01a8
+#define	FEC_TIPG_REG			0x01ac
+#define	FEC_FTRL_REG			0x01b0
+
+#define	FEC_TACC_REG			0x01c0
+#define	  FEC_TACC_PROCHK		  (1 <<  4)
+#define	  FEC_TACC_IPCHK		  (1 <<  3)
+#define	  FEC_TACC_SHIFT16		  (1 <<  0)
+
+#define	FEC_RACC_REG			0x01c4
+#define	  FEC_RACC_SHIFT16		  (1 <<  7)
+#define	  FEC_RACC_LINEDIS		  (1 <<  6)
+#define	  FEC_RACC_PRODIS		  (1 <<  2)
+#define	  FEC_RACC_IPDIS		  (1 <<  1)
+#define	  FEC_RACC_PADREM		  (1 <<  0)
+
+/*
+ * Statistics registers
+ */
+#define	FEC_RMON_T_DROP			0x200
+#define	FEC_RMON_T_PACKETS		0x204
+#define	FEC_RMON_T_BC_PKT		0x208
+#define	FEC_RMON_T_MC_PKT		0x20C
+#define	FEC_RMON_T_CRC_ALIGN		0x210
+#define	FEC_RMON_T_UNDERSIZE		0x214
+#define	FEC_RMON_T_OVERSIZE		0x218
+#define	FEC_RMON_T_FRAG			0x21C
+#define	FEC_RMON_T_JAB			0x220
+#define	FEC_RMON_T_COL			0x224
+#define	FEC_RMON_T_P64			0x228
+#define	FEC_RMON_T_P65TO127		0x22C
+#define	FEC_RMON_T_P128TO255		0x230
+#define	FEC_RMON_T_P256TO511		0x234
+#define	FEC_RMON_T_P512TO1023		0x238
+#define	FEC_RMON_T_P1024TO2047		0x23C
+#define	FEC_RMON_T_P_GTE2048		0x240
+#define	FEC_RMON_T_OCTECTS		0x240
+#define	FEC_IEEE_T_DROP			0x248
+#define	FEC_IEEE_T_FRAME_OK		0x24C
+#define	FEC_IEEE_T_1COL			0x250
+#define	FEC_IEEE_T_MCOL			0x254
+#define	FEC_IEEE_T_DEF			0x258
+#define	FEC_IEEE_T_LCOL			0x25C
+#define	FEC_IEEE_T_EXCOL		0x260
+#define	FEC_IEEE_T_MACERR		0x264
+#define	FEC_IEEE_T_CSERR		0x268
+#define	FEC_IEEE_T_SQE			0x26C
+#define	FEC_IEEE_T_FDXFC		0x270
+#define	FEC_IEEE_T_OCTETS_OK		0x274
+#define	FEC_RMON_R_PACKETS		0x284
+#define	FEC_RMON_R_BC_PKT		0x288
+#define	FEC_RMON_R_MC_PKT		0x28C
+#define	FEC_RMON_R_CRC_ALIGN		0x290
+#define	FEC_RMON_R_UNDERSIZE		0x294
+#define	FEC_RMON_R_OVERSIZE		0x298
+#define	FEC_RMON_R_FRAG			0x29C
+#define	FEC_RMON_R_JAB			0x2A0
+#define	FEC_RMON_R_RESVD_0		0x2A4
+#define	FEC_RMON_R_P64			0x2A8
+#define	FEC_RMON_R_P65TO127		0x2AC
+#define	FEC_RMON_R_P128TO255		0x2B0
+#define	FEC_RMON_R_P256TO511		0x2B4
+#define	FEC_RMON_R_P512TO1023		0x2B8
+#define	FEC_RMON_R_P1024TO2047		0x2BC
+#define	FEC_RMON_R_P_GTE2048		0x2C0
+#define	FEC_RMON_R_OCTETS		0x2C4
+#define	FEC_IEEE_R_DROP			0x2C8
+#define	FEC_IEEE_R_FRAME_OK		0x2CC
+#define	FEC_IEEE_R_CRC			0x2D0
+#define	FEC_IEEE_R_ALIGN		0x2D4
+#define	FEC_IEEE_R_MACERR		0x2D8
+#define	FEC_IEEE_R_FDXFC		0x2DC
+#define	FEC_IEEE_R_OCTETS_OK		0x2E0
+
+#define	FEC_MIIGSK_CFGR			0x300
+#define	FEC_MIIGSK_CFGR_FRCONT		(1 << 6)   /* Freq: 0=50MHz, 1=5MHz */
+#define	FEC_MIIGSK_CFGR_LBMODE		(1 << 4)   /* loopback mode */
+#define	FEC_MIIGSK_CFGR_EMODE		(1 << 3)   /* echo mode */
+#define	FEC_MIIGSK_CFGR_IF_MODE_MASK	(0x3 << 0)
+#define	FEC_MIIGSK_CFGR_IF_MODE_MII	  (0 << 0)
+#define	FEC_MIIGSK_CFGR_IF_MODE_RMII	  (1 << 0)
+
+#define	FEC_MIIGSK_ENR			0x308
+#define	FEC_MIIGSK_ENR_READY		(1 << 2)
+#define	FEC_MIIGSK_ENR_EN		(1 << 1)
+
+/*
+ * A hardware buffer descriptor.  Rx and Tx buffers have the same descriptor
+ * layout, but the bits in the flags field have different meanings.
+ */
+struct ffec_hwdesc
+{
+	uint32_t	flags_len;
+	uint32_t	buf_paddr;
+};
+
+#define	FEC_TXDESC_READY		(1U << 31)
+#define	FEC_TXDESC_T01			(1 << 30)
+#define	FEC_TXDESC_WRAP			(1 << 29)
+#define	FEC_TXDESC_T02			(1 << 28)
+#define	FEC_TXDESC_L			(1 << 27)
+#define	FEC_TXDESC_TC			(1 << 26)
+#define	FEC_TXDESC_ABC			(1 << 25)
+#define	FEC_TXDESC_LEN_MASK		(0xffff)
+
+#define	FEC_RXDESC_EMPTY		(1U << 31)
+#define	FEC_RXDESC_R01			(1 << 30)
+#define	FEC_RXDESC_WRAP			(1 << 29)
+#define	FEC_RXDESC_R02			(1 << 28)
+#define	FEC_RXDESC_L			(1 << 27)
+#define	FEC_RXDESC_M			(1 << 24)
+#define	FEC_RXDESC_BC			(1 << 23)
+#define	FEC_RXDESC_MC			(1 << 22)
+#define	FEC_RXDESC_LG			(1 << 21)
+#define	FEC_RXDESC_NO			(1 << 20)
+#define	FEC_RXDESC_CR			(1 << 18)
+#define	FEC_RXDESC_OV			(1 << 17)
+#define	FEC_RXDESC_TR			(1 << 16)
+#define	FEC_RXDESC_LEN_MASK		(0xffff)
+
+#define	FEC_RXDESC_ERROR_BITS	(FEC_RXDESC_LG | FEC_RXDESC_NO | \
+    FEC_RXDESC_OV | FEC_RXDESC_TR)
+
+/*
+ * The hardware imposes alignment restrictions on various objects involved in
+ * DMA transfers.  These values are expressed in bytes (not bits).
+ */
+#define	FEC_DESC_RING_ALIGN		16
+#define	FEC_RXBUF_ALIGN			16
+#define	FEC_TXBUF_ALIGN			16
+
+#endif	/* IF_FFECREG_H */


Property changes on: trunk/sys/dev/ffec/if_ffecreg.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/dev/glxiic/glxiic.c
===================================================================
--- trunk/sys/dev/glxiic/glxiic.c	2018-05-27 23:51:40 UTC (rev 10108)
+++ trunk/sys/dev/glxiic/glxiic.c	2018-05-27 23:54:22 UTC (rev 10109)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2011 Henrik Brix Andersen <brix at FreeBSD.org>
  * All rights reserved.
@@ -24,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/glxiic/glxiic.c 275982 2014-12-21 03:06:11Z smh $");
 /*
  * AMD Geode LX CS5536 System Management Bus controller.
  *
@@ -562,8 +563,8 @@
 
 	GLXIIC_ASSERT_LOCKED(sc);
 
-	callout_reset(&sc->callout, sc->timeout * 1000 / hz, glxiic_timeout,
-	    sc);
+	callout_reset_sbt(&sc->callout, SBT_1MS * sc->timeout, 0,
+	    glxiic_timeout, sc, 0);
 }
 
 static void
@@ -711,6 +712,7 @@
 glxiic_state_master_addr_callback(struct glxiic_softc *sc, uint8_t status)
 {
 	uint8_t slave;
+	uint8_t ctrl1;
 
 	GLXIIC_ASSERT_LOCKED(sc);
 
@@ -746,6 +748,13 @@
 
 	bus_write_1(sc->smb_res, GLXIIC_SMB_SDA, slave);
 
+	if ((sc->msg->flags & IIC_M_RD) != 0 && sc->ndata == 1) {
+		/* Last byte from slave, set NACK. */
+		ctrl1 = bus_read_1(sc->smb_res, GLXIIC_SMB_CTRL1);
+		bus_write_1(sc->smb_res, GLXIIC_SMB_CTRL1,
+		    ctrl1 | GLXIIC_SMB_CTRL1_ACK_BIT);
+	}
+
 	return (IIC_NOERR);
 }
 
@@ -811,13 +820,6 @@
 		return (IIC_ENOACK);
 	}
 
-	if (sc->ndata == 1) {
-		/* Last byte from slave, set NACK. */
-		ctrl1 = bus_read_1(sc->smb_res, GLXIIC_SMB_CTRL1);
-		bus_write_1(sc->smb_res, GLXIIC_SMB_CTRL1,
-		    ctrl1 | GLXIIC_SMB_CTRL1_ACK_BIT);
-	}
-
 	if ((status & GLXIIC_SMB_STS_STASTR_BIT) != 0) {
 		/* Bus is stalled, clear and wait for data. */
 		bus_write_1(sc->smb_res, GLXIIC_SMB_STS,
@@ -837,6 +839,13 @@
 		return (glxiic_state_table[sc->state].callback(sc, status));
 	}
 
+	if (sc->ndata == 1) {
+		/* Last byte from slave, set NACK. */
+		ctrl1 = bus_read_1(sc->smb_res, GLXIIC_SMB_CTRL1);
+		bus_write_1(sc->smb_res, GLXIIC_SMB_CTRL1,
+		    ctrl1 | GLXIIC_SMB_CTRL1_ACK_BIT);
+	}
+
 	glxiic_start_timeout_locked(sc);
 
 	return (IIC_NOERR);



More information about the Midnightbsd-cvs mailing list