Set PCIe max read request size to 2K to help with TX performance.
authorbrad <brad@openbsd.org>
Mon, 26 Jan 2015 09:58:47 +0000 (09:58 +0000)
committerbrad <brad@openbsd.org>
Mon, 26 Jan 2015 09:58:47 +0000 (09:58 +0000)
From FreeBSD

Tested with 8168C, 8168D and 8168G.

sys/dev/ic/rtl81x9reg.h
sys/dev/pci/if_re_pci.c

index c9cc6cb..c5244ba 100644 (file)
@@ -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 */
index 3955436..8dd43c7 100644 (file)
@@ -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 <pvalchev@openbsd.org>
@@ -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)) {