From d64e12548ca202bf5a32c2a40e2f105d3f8c4f5f Mon Sep 17 00:00:00 2001 From: brad Date: Mon, 26 Jan 2015 09:58:47 +0000 Subject: [PATCH] Set PCIe max read request size to 2K to help with TX performance. From FreeBSD Tested with 8168C, 8168D and 8168G. --- sys/dev/ic/rtl81x9reg.h | 3 ++- sys/dev/pci/if_re_pci.c | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sys/dev/ic/rtl81x9reg.h b/sys/dev/ic/rtl81x9reg.h index c9cc6cb099b..c5244baa07a 100644 --- a/sys/dev/ic/rtl81x9reg.h +++ b/sys/dev/ic/rtl81x9reg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rtl81x9reg.h,v 1.90 2015/01/20 04:33:06 brad Exp $ */ +/* $OpenBSD: rtl81x9reg.h,v 1.91 2015/01/26 09:58:47 brad Exp $ */ /* * Copyright (c) 1997, 1998 @@ -833,6 +833,7 @@ struct rl_softc { bus_space_handle_t rl_bhandle; /* bus space handle */ bus_space_tag_t rl_btag; /* bus space tag */ bus_dma_tag_t sc_dmat; + u_int32_t rl_expcap; bus_dma_segment_t sc_rx_seg; bus_dmamap_t sc_rx_dmamap; struct arpcom sc_arpcom; /* interface info */ diff --git a/sys/dev/pci/if_re_pci.c b/sys/dev/pci/if_re_pci.c index 3955436d5e0..8dd43c73a92 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.44 2014/12/22 02:28:52 tedu Exp $ */ +/* $OpenBSD: if_re_pci.c,v 1.45 2015/01/26 09:58:47 brad Exp $ */ /* * Copyright (c) 2005 Peter Valchev @@ -130,6 +130,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 rrs; pci_set_powerstate(pa->pa_pc, pa->pa_tag, PCI_PMCSR_STATE_D0); @@ -174,8 +176,26 @@ 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)) + &sc->rl_expcap, NULL)) { + if (!(PCI_VENDOR(pa->pa_id) == PCI_VENDOR_REALTEK && + PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_REALTEK_RT8101E)) { + /* Set PCIe maximum read request size to 2048. */ + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, + sc->rl_expcap + PCI_PCIE_DCSR); + reg = (reg & ~PCI_PCIE_DCSR_MPS); + reg >>= 12; + rrs = (1 << (reg + 7)); + if (rrs < 2048) { + reg = pci_conf_read(pa->pa_pc, pa->pa_tag, + sc->rl_expcap + PCI_PCIE_DCSR); + reg = (reg & ~PCI_PCIE_DCSR_MPS) | + (fls(2048) - 8) << 12; + pci_conf_write(pa->pa_pc, pa->pa_tag, + sc->rl_expcap + PCI_PCIE_DCSR, 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)) { -- 2.20.1