1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-29 12:03:03 +00:00

- There's no need to keep track of resource IDs.

- Simplify MSI allocation and release. For a single one, we don't need to
  fiddle with the MSI count and pci_release_msi(9) is smart enough to just
  do nothing in case of INTx.
- Don't allocate MSI as RF_SHAREABLE.
- Use DEVMETHOD_END.
- Use NULL instead of 0 for pointers.

MFC after:	1 week
This commit is contained in:
Marius Strobl 2013-12-29 19:32:27 +00:00
parent 526b18aa8b
commit 7b23a8b2c0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=260053
2 changed files with 17 additions and 17 deletions

View File

@ -352,7 +352,8 @@ static device_method_t iwn_methods[] = {
DEVMETHOD(device_shutdown, iwn_shutdown), DEVMETHOD(device_shutdown, iwn_shutdown),
DEVMETHOD(device_suspend, iwn_suspend), DEVMETHOD(device_suspend, iwn_suspend),
DEVMETHOD(device_resume, iwn_resume), DEVMETHOD(device_resume, iwn_resume),
{ 0, 0 }
DEVMETHOD_END
}; };
static driver_t iwn_driver = { static driver_t iwn_driver = {
@ -362,7 +363,7 @@ static driver_t iwn_driver = {
}; };
static devclass_t iwn_devclass; static devclass_t iwn_devclass;
DRIVER_MODULE(iwn, pci, iwn_driver, iwn_devclass, 0, 0); DRIVER_MODULE(iwn, pci, iwn_driver, iwn_devclass, NULL, NULL);
MODULE_VERSION(iwn, 1); MODULE_VERSION(iwn, 1);
@ -392,7 +393,7 @@ iwn_attach(device_t dev)
struct ieee80211com *ic; struct ieee80211com *ic;
struct ifnet *ifp; struct ifnet *ifp;
uint32_t reg; uint32_t reg;
int i, error, result; int i, error, rid;
uint8_t macaddr[IEEE80211_ADDR_LEN]; uint8_t macaddr[IEEE80211_ADDR_LEN];
sc->sc_dev = dev; sc->sc_dev = dev;
@ -433,8 +434,8 @@ iwn_attach(device_t dev)
/* Enable bus-mastering. */ /* Enable bus-mastering. */
pci_enable_busmaster(dev); pci_enable_busmaster(dev);
sc->mem_rid = PCIR_BAR(0); rid = PCIR_BAR(0);
sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE); RF_ACTIVE);
if (sc->mem == NULL) { if (sc->mem == NULL) {
device_printf(dev, "can't map mem space\n"); device_printf(dev, "can't map mem space\n");
@ -444,13 +445,13 @@ iwn_attach(device_t dev)
sc->sc_st = rman_get_bustag(sc->mem); sc->sc_st = rman_get_bustag(sc->mem);
sc->sc_sh = rman_get_bushandle(sc->mem); sc->sc_sh = rman_get_bushandle(sc->mem);
sc->irq_rid = 0; i = 1;
if ((result = pci_msi_count(dev)) == 1 && rid = 0;
pci_alloc_msi(dev, &result) == 0) if (pci_alloc_msi(dev, &i) == 0)
sc->irq_rid = 1; rid = 1;
/* Install interrupt handler. */ /* Install interrupt handler. */
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE |
RF_ACTIVE | RF_SHAREABLE); (rid != 0 ? 0 : RF_SHAREABLE));
if (sc->irq == NULL) { if (sc->irq == NULL) {
device_printf(dev, "can't map interrupt\n"); device_printf(dev, "can't map interrupt\n");
error = ENOMEM; error = ENOMEM;
@ -1319,9 +1320,9 @@ iwn_detach(device_t dev)
/* Uninstall interrupt handler. */ /* Uninstall interrupt handler. */
if (sc->irq != NULL) { if (sc->irq != NULL) {
bus_teardown_intr(dev, sc->irq, sc->sc_ih); bus_teardown_intr(dev, sc->irq, sc->sc_ih);
bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq); bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq),
if (sc->irq_rid == 1) sc->irq);
pci_release_msi(dev); pci_release_msi(dev);
} }
/* Free DMA resources. */ /* Free DMA resources. */
@ -1335,7 +1336,8 @@ iwn_detach(device_t dev)
iwn_free_fwmem(sc); iwn_free_fwmem(sc);
if (sc->mem != NULL) if (sc->mem != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem); bus_release_resource(dev, SYS_RES_MEMORY,
rman_get_rid(sc->mem), sc->mem);
if (ifp != NULL) if (ifp != NULL)
if_free(ifp); if_free(ifp);

View File

@ -296,11 +296,9 @@ struct iwn_softc {
struct iwn_tx_ring txq[IWN5000_NTXQUEUES]; struct iwn_tx_ring txq[IWN5000_NTXQUEUES];
struct iwn_rx_ring rxq; struct iwn_rx_ring rxq;
int mem_rid;
struct resource *mem; struct resource *mem;
bus_space_tag_t sc_st; bus_space_tag_t sc_st;
bus_space_handle_t sc_sh; bus_space_handle_t sc_sh;
int irq_rid;
struct resource *irq; struct resource *irq;
void *sc_ih; void *sc_ih;
bus_size_t sc_sz; bus_size_t sc_sz;