Deleted Added
full compact
mps_pci.c (281564) mps_pci.c (322661)
1/*-
2 * Copyright (c) 2009 Yahoo! Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009 Yahoo! Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/10/sys/dev/mps/mps_pci.c 281564 2015-04-15 21:47:15Z slm $");
28__FBSDID("$FreeBSD: stable/10/sys/dev/mps/mps_pci.c 322661 2017-08-18 15:38:08Z ken $");
29
30/* PCI/PCI-X/PCIe bus interface for the Avago Tech (LSI) MPT2 controllers */
31
32/* TODO Move headers to mpsvar */
33#include <sys/types.h>
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>

--- 26 unchanged lines hidden (view full) ---

63static int mps_pci_probe(device_t);
64static int mps_pci_attach(device_t);
65static int mps_pci_detach(device_t);
66static int mps_pci_suspend(device_t);
67static int mps_pci_resume(device_t);
68static void mps_pci_free(struct mps_softc *);
69static int mps_alloc_msix(struct mps_softc *sc, int msgs);
70static int mps_alloc_msi(struct mps_softc *sc, int msgs);
29
30/* PCI/PCI-X/PCIe bus interface for the Avago Tech (LSI) MPT2 controllers */
31
32/* TODO Move headers to mpsvar */
33#include <sys/types.h>
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>

--- 26 unchanged lines hidden (view full) ---

63static int mps_pci_probe(device_t);
64static int mps_pci_attach(device_t);
65static int mps_pci_detach(device_t);
66static int mps_pci_suspend(device_t);
67static int mps_pci_resume(device_t);
68static void mps_pci_free(struct mps_softc *);
69static int mps_alloc_msix(struct mps_softc *sc, int msgs);
70static int mps_alloc_msi(struct mps_softc *sc, int msgs);
71static int mps_pci_alloc_interrupts(struct mps_softc *sc);
71
72static device_method_t mps_methods[] = {
73 DEVMETHOD(device_probe, mps_pci_probe),
74 DEVMETHOD(device_attach, mps_pci_attach),
75 DEVMETHOD(device_detach, mps_pci_detach),
76 DEVMETHOD(device_suspend, mps_pci_suspend),
77 DEVMETHOD(device_resume, mps_pci_resume),
78

--- 107 unchanged lines hidden (view full) ---

186 int error;
187
188 sc = device_get_softc(dev);
189 bzero(sc, sizeof(*sc));
190 sc->mps_dev = dev;
191 m = mps_find_ident(dev);
192 sc->mps_flags = m->flags;
193
72
73static device_method_t mps_methods[] = {
74 DEVMETHOD(device_probe, mps_pci_probe),
75 DEVMETHOD(device_attach, mps_pci_attach),
76 DEVMETHOD(device_detach, mps_pci_detach),
77 DEVMETHOD(device_suspend, mps_pci_suspend),
78 DEVMETHOD(device_resume, mps_pci_resume),
79

--- 107 unchanged lines hidden (view full) ---

187 int error;
188
189 sc = device_get_softc(dev);
190 bzero(sc, sizeof(*sc));
191 sc->mps_dev = dev;
192 m = mps_find_ident(dev);
193 sc->mps_flags = m->flags;
194
195 mps_get_tunables(sc);
196
194 /* Twiddle basic PCI config bits for a sanity check */
195 pci_enable_busmaster(dev);
196
197 /* Allocate the System Interface Register Set */
198 sc->mps_regs_rid = PCIR_BAR(1);
199 if ((sc->mps_regs_resource = bus_alloc_resource_any(dev,
200 SYS_RES_MEMORY, &sc->mps_regs_rid, RF_ACTIVE)) == NULL) {
201 mps_printf(sc, "Cannot allocate PCI registers\n");

--- 14 unchanged lines hidden (view full) ---

216 0, /* flags */
217 NULL, NULL, /* lockfunc, lockarg */
218 &sc->mps_parent_dmat)) {
219 mps_printf(sc, "Cannot allocate parent DMA tag\n");
220 mps_pci_free(sc);
221 return (ENOMEM);
222 }
223
197 /* Twiddle basic PCI config bits for a sanity check */
198 pci_enable_busmaster(dev);
199
200 /* Allocate the System Interface Register Set */
201 sc->mps_regs_rid = PCIR_BAR(1);
202 if ((sc->mps_regs_resource = bus_alloc_resource_any(dev,
203 SYS_RES_MEMORY, &sc->mps_regs_rid, RF_ACTIVE)) == NULL) {
204 mps_printf(sc, "Cannot allocate PCI registers\n");

--- 14 unchanged lines hidden (view full) ---

219 0, /* flags */
220 NULL, NULL, /* lockfunc, lockarg */
221 &sc->mps_parent_dmat)) {
222 mps_printf(sc, "Cannot allocate parent DMA tag\n");
223 mps_pci_free(sc);
224 return (ENOMEM);
225 }
226
224 if ((error = mps_attach(sc)) != 0)
227 if (((error = mps_pci_alloc_interrupts(sc)) != 0) ||
228 ((error = mps_attach(sc)) != 0))
225 mps_pci_free(sc);
226
227 return (error);
228}
229
229 mps_pci_free(sc);
230
231 return (error);
232}
233
230int
231mps_pci_setup_interrupts(struct mps_softc *sc)
234/*
235 * Allocate, but don't assign interrupts early. Doing it before requesting
236 * the IOCFacts message informs the firmware that we want to do MSI-X
237 * multiqueue. We might not use all of the available messages, but there's
238 * no reason to re-alloc if we don't.
239 */
240static int
241mps_pci_alloc_interrupts(struct mps_softc *sc)
232{
233 device_t dev;
242{
243 device_t dev;
234 int i, error, msgs;
244 int error, msgs;
235
236 dev = sc->mps_dev;
245
246 dev = sc->mps_dev;
237 error = ENXIO;
247 error = 0;
248 msgs = 0;
249
238 if ((sc->disable_msix == 0) &&
239 ((msgs = pci_msix_count(dev)) >= MPS_MSI_COUNT))
240 error = mps_alloc_msix(sc, MPS_MSI_COUNT);
241 if ((error != 0) && (sc->disable_msi == 0) &&
242 ((msgs = pci_msi_count(dev)) >= MPS_MSI_COUNT))
243 error = mps_alloc_msi(sc, MPS_MSI_COUNT);
250 if ((sc->disable_msix == 0) &&
251 ((msgs = pci_msix_count(dev)) >= MPS_MSI_COUNT))
252 error = mps_alloc_msix(sc, MPS_MSI_COUNT);
253 if ((error != 0) && (sc->disable_msi == 0) &&
254 ((msgs = pci_msi_count(dev)) >= MPS_MSI_COUNT))
255 error = mps_alloc_msi(sc, MPS_MSI_COUNT);
256 if (error != 0)
257 msgs = 0;
244
258
245 if (error != 0) {
259 sc->msi_msgs = msgs;
260 return (error);
261}
262
263int
264mps_pci_setup_interrupts(struct mps_softc *sc)
265{
266 device_t dev;
267 int i, error;
268
269 dev = sc->mps_dev;
270 error = ENXIO;
271
272 if (sc->msi_msgs == 0) {
246 sc->mps_flags |= MPS_FLAGS_INTX;
247 sc->mps_irq_rid[0] = 0;
248 sc->mps_irq[0] = bus_alloc_resource_any(dev, SYS_RES_IRQ,
249 &sc->mps_irq_rid[0], RF_SHAREABLE | RF_ACTIVE);
250 if (sc->mps_irq[0] == NULL) {
251 mps_printf(sc, "Cannot allocate INTx interrupt\n");
252 return (ENXIO);
253 }

--- 128 unchanged lines hidden ---
273 sc->mps_flags |= MPS_FLAGS_INTX;
274 sc->mps_irq_rid[0] = 0;
275 sc->mps_irq[0] = bus_alloc_resource_any(dev, SYS_RES_IRQ,
276 &sc->mps_irq_rid[0], RF_SHAREABLE | RF_ACTIVE);
277 if (sc->mps_irq[0] == NULL) {
278 mps_printf(sc, "Cannot allocate INTx interrupt\n");
279 return (ENXIO);
280 }

--- 128 unchanged lines hidden ---