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 79 DEVMETHOD_END 80}; 81 82static driver_t mps_pci_driver = { 83 "mps", 84 mps_methods, 85 sizeof(struct mps_softc) 86}; 87 88static devclass_t mps_devclass; 89DRIVER_MODULE(mps, pci, mps_pci_driver, mps_devclass, 0, 0); 90MODULE_DEPEND(mps, cam, 1, 1, 1); 91 92struct mps_ident { 93 uint16_t vendor; 94 uint16_t device; 95 uint16_t subvendor; 96 uint16_t subdevice; 97 u_int flags; 98 const char *desc; 99} mps_identifiers[] = { 100 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, 101 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2004" }, 102 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, 103 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2008" }, 104 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, 105 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" }, 106 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, 107 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" }, 108 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, 109 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" }, 110 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, 111 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2116" }, 112 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, 113 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2116" }, 114 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, 115 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 116 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, 117 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 118 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, 119 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 120 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, 121 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 122 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, 123 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 124 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, 125 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 126 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, 127 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" }, 128 // Add Customer specific vender/subdevice id before generic 129 // (0xffff) vender/subdevice id. 130 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 131 0x8086, 0x3516, 0, "Intel(R) Integrated RAID Module RMS25JB080" }, 132 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 133 0x8086, 0x3517, 0, "Intel(R) Integrated RAID Module RMS25JB040" }, 134 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 135 0x8086, 0x3518, 0, "Intel(R) Integrated RAID Module RMS25KB080" }, 136 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 137 0x8086, 0x3519, 0, "Intel(R) Integrated RAID Module RMS25KB040" }, 138 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 139 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" }, 140 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, 141 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" }, 142 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, 143 0xffff, 0xffff, 0, "Avago Technologies (LSI) SSS6200" }, 144 { 0, 0, 0, 0, 0, NULL } 145}; 146 147static struct mps_ident * 148mps_find_ident(device_t dev) 149{ 150 struct mps_ident *m; 151 152 for (m = mps_identifiers; m->vendor != 0; m++) { 153 if (m->vendor != pci_get_vendor(dev)) 154 continue; 155 if (m->device != pci_get_device(dev)) 156 continue; 157 if ((m->subvendor != 0xffff) && 158 (m->subvendor != pci_get_subvendor(dev))) 159 continue; 160 if ((m->subdevice != 0xffff) && 161 (m->subdevice != pci_get_subdevice(dev))) 162 continue; 163 return (m); 164 } 165 166 return (NULL); 167} 168 169static int 170mps_pci_probe(device_t dev) 171{ 172 struct mps_ident *id; 173 174 if ((id = mps_find_ident(dev)) != NULL) { 175 device_set_desc(dev, id->desc); 176 return (BUS_PROBE_DEFAULT); 177 } 178 return (ENXIO); 179} 180 181static int 182mps_pci_attach(device_t dev) 183{ 184 struct mps_softc *sc; 185 struct mps_ident *m; 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 80 DEVMETHOD_END 81}; 82 83static driver_t mps_pci_driver = { 84 "mps", 85 mps_methods, 86 sizeof(struct mps_softc) 87}; 88 89static devclass_t mps_devclass; 90DRIVER_MODULE(mps, pci, mps_pci_driver, mps_devclass, 0, 0); 91MODULE_DEPEND(mps, cam, 1, 1, 1); 92 93struct mps_ident { 94 uint16_t vendor; 95 uint16_t device; 96 uint16_t subvendor; 97 uint16_t subdevice; 98 u_int flags; 99 const char *desc; 100} mps_identifiers[] = { 101 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004, 102 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2004" }, 103 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008, 104 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2008" }, 105 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1, 106 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" }, 107 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2, 108 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" }, 109 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3, 110 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2108" }, 111 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1, 112 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2116" }, 113 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2, 114 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2116" }, 115 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1, 116 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 117 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2, 118 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 119 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3, 120 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 121 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4, 122 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 123 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5, 124 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 125 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6, 126 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2208" }, 127 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1, 128 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" }, 129 // Add Customer specific vender/subdevice id before generic 130 // (0xffff) vender/subdevice id. 131 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 132 0x8086, 0x3516, 0, "Intel(R) Integrated RAID Module RMS25JB080" }, 133 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 134 0x8086, 0x3517, 0, "Intel(R) Integrated RAID Module RMS25JB040" }, 135 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 136 0x8086, 0x3518, 0, "Intel(R) Integrated RAID Module RMS25KB080" }, 137 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 138 0x8086, 0x3519, 0, "Intel(R) Integrated RAID Module RMS25KB040" }, 139 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2, 140 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" }, 141 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3, 142 0xffff, 0xffff, 0, "Avago Technologies (LSI) SAS2308" }, 143 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200, 144 0xffff, 0xffff, 0, "Avago Technologies (LSI) SSS6200" }, 145 { 0, 0, 0, 0, 0, NULL } 146}; 147 148static struct mps_ident * 149mps_find_ident(device_t dev) 150{ 151 struct mps_ident *m; 152 153 for (m = mps_identifiers; m->vendor != 0; m++) { 154 if (m->vendor != pci_get_vendor(dev)) 155 continue; 156 if (m->device != pci_get_device(dev)) 157 continue; 158 if ((m->subvendor != 0xffff) && 159 (m->subvendor != pci_get_subvendor(dev))) 160 continue; 161 if ((m->subdevice != 0xffff) && 162 (m->subdevice != pci_get_subdevice(dev))) 163 continue; 164 return (m); 165 } 166 167 return (NULL); 168} 169 170static int 171mps_pci_probe(device_t dev) 172{ 173 struct mps_ident *id; 174 175 if ((id = mps_find_ident(dev)) != NULL) { 176 device_set_desc(dev, id->desc); 177 return (BUS_PROBE_DEFAULT); 178 } 179 return (ENXIO); 180} 181 182static int 183mps_pci_attach(device_t dev) 184{ 185 struct mps_softc *sc; 186 struct mps_ident *m; 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
|
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 } 254 error = bus_setup_intr(dev, sc->mps_irq[0], 255 INTR_TYPE_BIO | INTR_MPSAFE, NULL, mps_intr, sc, 256 &sc->mps_intrhand[0]); 257 if (error) 258 mps_printf(sc, "Cannot setup INTx interrupt\n"); 259 } else { 260 sc->mps_flags |= MPS_FLAGS_MSI; 261 for (i = 0; i < MPS_MSI_COUNT; i++) { 262 sc->mps_irq_rid[i] = i + 1; 263 sc->mps_irq[i] = bus_alloc_resource_any(dev, 264 SYS_RES_IRQ, &sc->mps_irq_rid[i], RF_ACTIVE); 265 if (sc->mps_irq[i] == NULL) { 266 mps_printf(sc, 267 "Cannot allocate MSI interrupt\n"); 268 return (ENXIO); 269 } 270 error = bus_setup_intr(dev, sc->mps_irq[i], 271 INTR_TYPE_BIO | INTR_MPSAFE, NULL, mps_intr_msi, 272 sc, &sc->mps_intrhand[i]); 273 if (error) { 274 mps_printf(sc, 275 "Cannot setup MSI interrupt %d\n", i); 276 break; 277 } 278 } 279 } 280 281 return (error); 282} 283 284static int 285mps_pci_detach(device_t dev) 286{ 287 struct mps_softc *sc; 288 int error; 289 290 sc = device_get_softc(dev); 291 292 if ((error = mps_free(sc)) != 0) 293 return (error); 294 295 mps_pci_free(sc); 296 return (0); 297} 298 299static void 300mps_pci_free(struct mps_softc *sc) 301{ 302 int i; 303 304 if (sc->mps_parent_dmat != NULL) { 305 bus_dma_tag_destroy(sc->mps_parent_dmat); 306 } 307 308 if (sc->mps_flags & MPS_FLAGS_MSI) { 309 for (i = 0; i < MPS_MSI_COUNT; i++) { 310 if (sc->mps_irq[i] != NULL) { 311 bus_teardown_intr(sc->mps_dev, sc->mps_irq[i], 312 sc->mps_intrhand[i]); 313 bus_release_resource(sc->mps_dev, SYS_RES_IRQ, 314 sc->mps_irq_rid[i], sc->mps_irq[i]); 315 } 316 } 317 pci_release_msi(sc->mps_dev); 318 } 319 320 if (sc->mps_flags & MPS_FLAGS_INTX) { 321 bus_teardown_intr(sc->mps_dev, sc->mps_irq[0], 322 sc->mps_intrhand[0]); 323 bus_release_resource(sc->mps_dev, SYS_RES_IRQ, 324 sc->mps_irq_rid[0], sc->mps_irq[0]); 325 } 326 327 if (sc->mps_regs_resource != NULL) { 328 bus_release_resource(sc->mps_dev, SYS_RES_MEMORY, 329 sc->mps_regs_rid, sc->mps_regs_resource); 330 } 331 332 return; 333} 334 335static int 336mps_pci_suspend(device_t dev) 337{ 338 return (EINVAL); 339} 340 341static int 342mps_pci_resume(device_t dev) 343{ 344 return (EINVAL); 345} 346 347static int 348mps_alloc_msix(struct mps_softc *sc, int msgs) 349{ 350 int error; 351 352 error = pci_alloc_msix(sc->mps_dev, &msgs); 353 return (error); 354} 355 356static int 357mps_alloc_msi(struct mps_softc *sc, int msgs) 358{ 359 int error; 360 361 error = pci_alloc_msi(sc->mps_dev, &msgs); 362 return (error); 363} 364 365int 366mps_pci_restore(struct mps_softc *sc) 367{ 368 struct pci_devinfo *dinfo; 369 370 mps_dprint(sc, MPS_TRACE, "%s\n", __func__); 371 372 dinfo = device_get_ivars(sc->mps_dev); 373 if (dinfo == NULL) { 374 mps_dprint(sc, MPS_FAULT, "%s: NULL dinfo\n", __func__); 375 return (EINVAL); 376 } 377 378 pci_cfg_restore(sc->mps_dev, dinfo); 379 return (0); 380} 381
| 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 } 281 error = bus_setup_intr(dev, sc->mps_irq[0], 282 INTR_TYPE_BIO | INTR_MPSAFE, NULL, mps_intr, sc, 283 &sc->mps_intrhand[0]); 284 if (error) 285 mps_printf(sc, "Cannot setup INTx interrupt\n"); 286 } else { 287 sc->mps_flags |= MPS_FLAGS_MSI; 288 for (i = 0; i < MPS_MSI_COUNT; i++) { 289 sc->mps_irq_rid[i] = i + 1; 290 sc->mps_irq[i] = bus_alloc_resource_any(dev, 291 SYS_RES_IRQ, &sc->mps_irq_rid[i], RF_ACTIVE); 292 if (sc->mps_irq[i] == NULL) { 293 mps_printf(sc, 294 "Cannot allocate MSI interrupt\n"); 295 return (ENXIO); 296 } 297 error = bus_setup_intr(dev, sc->mps_irq[i], 298 INTR_TYPE_BIO | INTR_MPSAFE, NULL, mps_intr_msi, 299 sc, &sc->mps_intrhand[i]); 300 if (error) { 301 mps_printf(sc, 302 "Cannot setup MSI interrupt %d\n", i); 303 break; 304 } 305 } 306 } 307 308 return (error); 309} 310 311static int 312mps_pci_detach(device_t dev) 313{ 314 struct mps_softc *sc; 315 int error; 316 317 sc = device_get_softc(dev); 318 319 if ((error = mps_free(sc)) != 0) 320 return (error); 321 322 mps_pci_free(sc); 323 return (0); 324} 325 326static void 327mps_pci_free(struct mps_softc *sc) 328{ 329 int i; 330 331 if (sc->mps_parent_dmat != NULL) { 332 bus_dma_tag_destroy(sc->mps_parent_dmat); 333 } 334 335 if (sc->mps_flags & MPS_FLAGS_MSI) { 336 for (i = 0; i < MPS_MSI_COUNT; i++) { 337 if (sc->mps_irq[i] != NULL) { 338 bus_teardown_intr(sc->mps_dev, sc->mps_irq[i], 339 sc->mps_intrhand[i]); 340 bus_release_resource(sc->mps_dev, SYS_RES_IRQ, 341 sc->mps_irq_rid[i], sc->mps_irq[i]); 342 } 343 } 344 pci_release_msi(sc->mps_dev); 345 } 346 347 if (sc->mps_flags & MPS_FLAGS_INTX) { 348 bus_teardown_intr(sc->mps_dev, sc->mps_irq[0], 349 sc->mps_intrhand[0]); 350 bus_release_resource(sc->mps_dev, SYS_RES_IRQ, 351 sc->mps_irq_rid[0], sc->mps_irq[0]); 352 } 353 354 if (sc->mps_regs_resource != NULL) { 355 bus_release_resource(sc->mps_dev, SYS_RES_MEMORY, 356 sc->mps_regs_rid, sc->mps_regs_resource); 357 } 358 359 return; 360} 361 362static int 363mps_pci_suspend(device_t dev) 364{ 365 return (EINVAL); 366} 367 368static int 369mps_pci_resume(device_t dev) 370{ 371 return (EINVAL); 372} 373 374static int 375mps_alloc_msix(struct mps_softc *sc, int msgs) 376{ 377 int error; 378 379 error = pci_alloc_msix(sc->mps_dev, &msgs); 380 return (error); 381} 382 383static int 384mps_alloc_msi(struct mps_softc *sc, int msgs) 385{ 386 int error; 387 388 error = pci_alloc_msi(sc->mps_dev, &msgs); 389 return (error); 390} 391 392int 393mps_pci_restore(struct mps_softc *sc) 394{ 395 struct pci_devinfo *dinfo; 396 397 mps_dprint(sc, MPS_TRACE, "%s\n", __func__); 398 399 dinfo = device_get_ivars(sc->mps_dev); 400 if (dinfo == NULL) { 401 mps_dprint(sc, MPS_FAULT, "%s: NULL dinfo\n", __func__); 402 return (EINVAL); 403 } 404 405 pci_cfg_restore(sc->mps_dev, dinfo); 406 return (0); 407} 408
|