From owner-svn-src-head@freebsd.org Tue May 17 19:48:29 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ADA77B3D5D9; Tue, 17 May 2016 19:48:29 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7048D1344; Tue, 17 May 2016 19:48:29 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4HJmSBR062767; Tue, 17 May 2016 19:48:28 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4HJmShN062765; Tue, 17 May 2016 19:48:28 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201605171948.u4HJmShN062765@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Tue, 17 May 2016 19:48:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300074 - head/sys/dev/pci X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2016 19:48:29 -0000 Author: jhb Date: Tue May 17 19:48:28 2016 New Revision: 300074 URL: https://svnweb.freebsd.org/changeset/base/300074 Log: Rework managing hotplug commands with command completions. Previously the command completion interrupt would post any pending command immediately before pcib_pcie_hotplug_update() had been run to inspect the current status. Now, the command completion interrupt merely clears the flag and stops the timer assuming that the caller is always going to call pcib_pcie_hotplug_update() to generate the next hotplug command if one is needed. While here, fix a bug for systems with command completion where the old (existing) value was written to the slot control register instead of the new value. This fixes the complaint about a missing hotplug interrupt on my T400. Differential Revision: https://reviews.freebsd.org/D6363 Modified: head/sys/dev/pci/pci_pci.c head/sys/dev/pci/pcib_private.h Modified: head/sys/dev/pci/pci_pci.c ============================================================================== --- head/sys/dev/pci/pci_pci.c Tue May 17 19:34:07 2016 (r300073) +++ head/sys/dev/pci/pci_pci.c Tue May 17 19:48:28 2016 (r300074) @@ -874,8 +874,11 @@ pcib_probe_hotplug(struct pcib_softc *sc /* * Send a HotPlug command to the slot control register. If this slot - * uses command completion interrupts, these updates will be buffered - * while a previous command is completing. + * uses command completion interrupts and a previous command is still + * in progress, then the command is dropped. Once the previous + * command completes or times out, pcib_pcie_hotplug_update() will be + * invoked to post a new command based on the slot's state at that + * time. */ static void pcib_pcie_hotplug_command(struct pcib_softc *sc, uint16_t val, uint16_t mask) @@ -884,28 +887,20 @@ pcib_pcie_hotplug_command(struct pcib_so uint16_t ctl, new; dev = sc->dev; - if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_NCCS) { - ctl = pcie_read_config(dev, PCIER_SLOT_CTL, 2); - new = (ctl & ~mask) | val; - if (new != ctl) - pcie_write_config(dev, PCIER_SLOT_CTL, new, 2); + + if (sc->flags & PCIB_HOTPLUG_CMD_PENDING) return; - } - if (sc->flags & PCIB_HOTPLUG_CMD_PENDING) { - sc->pcie_pending_link_ctl_val &= ~mask; - sc->pcie_pending_link_ctl_val |= val; - sc->pcie_pending_link_ctl_mask |= mask; - } else { - ctl = pcie_read_config(dev, PCIER_SLOT_CTL, 2); - new = (ctl & ~mask) | val; - if (new != ctl) { - pcie_write_config(dev, PCIER_SLOT_CTL, ctl, 2); - sc->flags |= PCIB_HOTPLUG_CMD_PENDING; - if (!cold) - callout_reset(&sc->pcie_cc_timer, hz, - pcib_pcie_cc_timeout, sc); - } + ctl = pcie_read_config(dev, PCIER_SLOT_CTL, 2); + new = (ctl & ~mask) | val; + if (new == ctl) + return; + pcie_write_config(dev, PCIER_SLOT_CTL, new, 2); + if (!(sc->pcie_slot_cap & PCIEM_SLOT_CAP_NCCS)) { + sc->flags |= PCIB_HOTPLUG_CMD_PENDING; + if (!cold) + callout_reset(&sc->pcie_cc_timer, hz, + pcib_pcie_cc_timeout, sc); } } @@ -913,7 +908,6 @@ static void pcib_pcie_hotplug_command_completed(struct pcib_softc *sc) { device_t dev; - uint16_t ctl, new; dev = sc->dev; @@ -921,23 +915,8 @@ pcib_pcie_hotplug_command_completed(stru device_printf(dev, "Command Completed\n"); if (!(sc->flags & PCIB_HOTPLUG_CMD_PENDING)) return; - if (sc->pcie_pending_link_ctl_mask != 0) { - ctl = pcie_read_config(dev, PCIER_SLOT_CTL, 2); - new = ctl & ~sc->pcie_pending_link_ctl_mask; - new |= sc->pcie_pending_link_ctl_val; - if (new != ctl) { - pcie_write_config(dev, PCIER_SLOT_CTL, ctl, 2); - if (!cold) - callout_reset(&sc->pcie_cc_timer, hz, - pcib_pcie_cc_timeout, sc); - } else - sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; - sc->pcie_pending_link_ctl_mask = 0; - sc->pcie_pending_link_ctl_val = 0; - } else { - callout_stop(&sc->pcie_cc_timer); - sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; - } + callout_stop(&sc->pcie_cc_timer); + sc->flags &= ~PCIB_HOTPLUG_CMD_PENDING; } /* @@ -1041,11 +1020,10 @@ pcib_pcie_hotplug_update(struct pcib_sof * Interlock. */ if (sc->pcie_slot_cap & PCIEM_SLOT_CAP_EIP) { + mask |= PCIEM_SLOT_CTL_EIC; if (card_inserted != - !(sc->pcie_slot_sta & PCIEM_SLOT_STA_EIS)) { - mask |= PCIEM_SLOT_CTL_EIC; + !(sc->pcie_slot_sta & PCIEM_SLOT_STA_EIS)) val |= PCIEM_SLOT_CTL_EIC; - } } /* Modified: head/sys/dev/pci/pcib_private.h ============================================================================== --- head/sys/dev/pci/pcib_private.h Tue May 17 19:34:07 2016 (r300073) +++ head/sys/dev/pci/pcib_private.h Tue May 17 19:48:28 2016 (r300074) @@ -134,8 +134,6 @@ struct pcib_softc uint16_t pcie_slot_sta; uint32_t pcie_link_cap; uint32_t pcie_slot_cap; - uint16_t pcie_pending_link_ctl_mask; - uint16_t pcie_pending_link_ctl_val; struct resource *pcie_irq; void *pcie_ihand; struct task pcie_hp_task;