From 56bdc47de41e961714659642a1c48a02af45759b Mon Sep 17 00:00:00 2001 From: kevlo Date: Mon, 12 Jun 2017 03:00:26 +0000 Subject: [PATCH] From FreeBSD (r227593, r307982): More and more RealTek controllers started to implement EEE feature. Vendor driver seems to load a kind of firmware for EEE with additional PHY fixups. It is known that the EEE feature may need ASPM support. Unfortunately there is no documentation for EEE of the controller so enabling ASPM may cause more problems. The Realtek vendor drivers for FreeBSD and Linux also disable ASPM and clock request. While here, add a define for the ECPM (Enable Clock Power Management) bit. Tested by stsp@ and myself. ok stsp@ --- sys/dev/pci/if_re_pci.c | 12 ++++++++++-- sys/dev/pci/pcireg.h | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/dev/pci/if_re_pci.c b/sys/dev/pci/if_re_pci.c index 8a29f45cc93..84d1f3f2b04 100644 --- a/sys/dev/pci/if_re_pci.c +++ b/sys/dev/pci/if_re_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_re_pci.c,v 1.50 2015/12/28 05:49:15 jmatthew Exp $ */ +/* $OpenBSD: if_re_pci.c,v 1.51 2017/06/12 03:00:26 kevlo Exp $ */ /* * Copyright (c) 2005 Peter Valchev @@ -128,6 +128,8 @@ re_pci_attach(struct device *parent, struct device *self, void *aux) pci_chipset_tag_t pc = pa->pa_pc; pci_intr_handle_t ih; const char *intrstr = NULL; + pcireg_t reg; + int offset; pci_set_powerstate(pa->pa_pc, pa->pa_tag, PCI_PMCSR_STATE_D0); @@ -172,8 +174,14 @@ re_pci_attach(struct device *parent, struct device *self, void *aux) * PCI Express check. */ if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PCIEXPRESS, - NULL, NULL)) + &offset, NULL)) { + /* Disable PCIe ASPM and ECPM. */ + reg = pci_conf_read(pc, pa->pa_tag, offset + PCI_PCIE_LCSR); + reg &= ~(PCI_PCIE_LCSR_ASPM_L0S | PCI_PCIE_LCSR_ASPM_L1 | + PCI_PCIE_LCSR_ECPM); + pci_conf_write(pc, pa->pa_tag, offset + PCI_PCIE_LCSR, reg); sc->rl_flags |= RL_FLAG_PCIE; + } if (!(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_REALTEK && PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_REALTEK_RT8139)) { diff --git a/sys/dev/pci/pcireg.h b/sys/dev/pci/pcireg.h index ab53be0dce2..71fe94c9cf4 100644 --- a/sys/dev/pci/pcireg.h +++ b/sys/dev/pci/pcireg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcireg.h,v 1.53 2017/03/25 07:33:46 mlarkin Exp $ */ +/* $OpenBSD: pcireg.h,v 1.54 2017/06/12 03:00:26 kevlo Exp $ */ /* $NetBSD: pcireg.h,v 1.26 2000/05/10 16:58:42 thorpej Exp $ */ /* @@ -574,6 +574,7 @@ typedef u_int8_t pci_revision_t; #define PCI_PCIE_LCSR_ASPM_L0S 0x00000001 #define PCI_PCIE_LCSR_ASPM_L1 0x00000002 #define PCI_PCIE_LCSR_ES 0x00000080 +#define PCI_PCIE_LCSR_ECPM 0x00000100 #define PCI_PCIE_SLCAP 0x14 #define PCI_PCIE_SLCAP_ABP 0x00000001 #define PCI_PCIE_SLCAP_PCP 0x00000002 -- 2.20.1