FreeBSD/sys/dev/mps/mps.c
/* 
 * The terms diag reset and hard reset are used interchangeably in the MPI
 * docs to mean resetting the controller chip.  In this code diag reset
 * cleans everything up, and the hard reset function just sends the reset
 * sequence to the chip.  This should probably be refactored so that every
 * subsystem gets a reset notification of some sort, and can clean up
 * appropriately.
 */
The terms diag reset and hard reset are used interchangeably in the MPI
docs to mean resetting the controller chip.  In this code diag reset
cleans everything up, and the hard reset function just sends the reset
sequence to the chip.  This should probably be refactored so that every
subsystem gets a reset notification of some sort, and can clean up
appropriately.
The terms diag reset and hard reset are used interchangeably in the MPI docs to mean resetting the controller chip . In this code diag reset cleans everything up and the hard reset function just sends the reset sequence to the chip . This should probably be refactored so that every subsystem gets a reset notification of some sort and can clean up appropriately .
int
mps_reinit(struct mps_softc *sc)
{
	int error;
	struct mpssas_softc *sassc;
	sassc = sc->sassc;
	MPS_FUNCTRACE(sc);
	mtx_assert(&sc->mps_mtx, MA_OWNED);
	if (sc->mps_flags & MPS_FLAGS_DIAGRESET) {
		mps_dprint(sc, MPS_INIT, "%s reset already in progress\n",
			   __func__);
		return 0;
	}
	mps_dprint(sc, MPS_INFO, "Reinitializing controller,\n");
	sc->mps_flags |= MPS_FLAGS_DIAGRESET;
	mps_dprint(sc, MPS_INIT, "%s mask interrupts\n", __func__);
	mps_mask_intr(sc);
	error = mps_diag_reset(sc, CAN_SLEEP);
	if (error != 0) {
		panic("%s hard reset failed with error %d\n",
		    __func__, error);
	}
	mps_pci_restore(sc);
	mpssas_handle_reinit(sc);
	if ((error = mps_iocfacts_allocate(sc, FALSE)) != 0) {
		panic("%s IOC Facts based allocation failed with error %d\n",
		    __func__, error);
	}
	mps_mapping_exit(sc);
	mps_unmask_intr(sc);
	sc->mps_flags &= ~MPS_FLAGS_DIAGRESET;
	mps_base_static_config_pages(sc);
	mps_mapping_initialize(sc);
	mps_reregister_events(sc);
	mps_dprint(sc, MPS_INFO, "%s finished sc %p post %u free %u\n", 
	    __func__, sc, sc->replypostindex, sc->replyfreeindex);
	mpssas_release_simq_reinit(sassc);
	return 0;
}
int mps_reinit ( struct mps_softc * sc ) { int error ; struct mpssas_softc * sassc ; sassc = sc -> sassc ; MPS_FUNCTRACE ( sc ) ; mtx_assert ( & sc -> mps_mtx , MA_OWNED ) ; if ( sc -> mps_flags & MPS_FLAGS_DIAGRESET ) { mps_dprint ( sc , MPS_INIT , " \n " , __func__ ) ; return 0 ; } mps_dprint ( sc , MPS_INFO , " \n " ) ; sc -> mps_flags |= MPS_FLAGS_DIAGRESET ; mps_dprint ( sc , MPS_INIT , " \n " , __func__ ) ; mps_mask_intr ( sc ) ; error = mps_diag_reset ( sc , CAN_SLEEP ) ; if ( error != 0 ) { panic ( " \n " , __func__ , error ) ; } mps_pci_restore ( sc ) ; mpssas_handle_reinit ( sc ) ; if ( ( error = mps_iocfacts_allocate ( sc , FALSE ) ) != 0 ) { panic ( " \n " , __func__ , error ) ; } mps_mapping_exit ( sc ) ; mps_unmask_intr ( sc ) ; sc -> mps_flags &= ~ MPS_FLAGS_DIAGRESET ; mps_base_static_config_pages ( sc ) ; mps_mapping_initialize ( sc ) ; mps_reregister_events ( sc ) ; mps_dprint ( sc , MPS_INFO , " \n " , __func__ , sc , sc -> replypostindex , sc -> replyfreeindex ) ; mpssas_release_simq_reinit ( sassc ) ; return 0 ; }
The terms diag reset and hard reset are used interchangeably in the MPI
 docs to mean resetting the controller chip.
The terms diag reset and hard reset are used interchangeably in the MPI docs to mean resetting the controller chip .
/* make sure the completion callbacks can recognize they're getting
	 * a NULL cm_reply due to a reset.
	 */ /*
	 * Mask interrupts here.
	 */ /* XXXSL No need to panic here */ /* Restore the PCI state, including the MSI-X registers */ /* Give the I/O subsystem special priority to get itself prepared */ /*
	 * Get IOC Facts and allocate all structures based on this information.
	 * The attach function will also call mps_iocfacts_allocate at startup.
	 * If relevant values have changed in IOC Facts, this function will free
	 * all of the memory based on IOC Facts and reallocate that memory.
	 */ /*
	 * Mapping structures will be re-allocated after getting IOC Page8, so
	 * free these structures here.
	 */ /*
	 * The static page function currently read is IOC Page8.  Others can be
	 * added in future.  It's possible that the values in IOC Page8 have
	 * changed after a Diag Reset due to user modification, so always read
	 * these.  Interrupts are masked, so unmask them before getting config
	 * pages.
	 */ /*
	 * Some mapping info is based in IOC Page8 data, so re-initialize the
	 * mapping tables.
	 */ /*
	 * Restart will reload the event masks clobbered by the reset, and
	 * then enable the port.
	 */ /* the end of discovery will release the simq, so we're done. */