From b7f77127028e1aed1f911a3f750cb8613e76d3d3 Mon Sep 17 00:00:00 2001 From: Scott Long Date: Tue, 1 Jul 2014 04:33:36 +0000 Subject: [PATCH] Refactor some code in mps.c to reduce header pollution. Reviewed by: gibbs Obtained from: Netflix, Inc. MFC after: 2 days --- sys/dev/mps/mps.c | 27 ++------------------------- sys/dev/mps/mps_sas.c | 30 ++++++++++++++++++++++++++++++ sys/dev/mps/mps_sas.h | 2 -- sys/dev/mps/mps_user.c | 1 - sys/dev/mps/mpsvar.h | 3 +++ 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/sys/dev/mps/mps.c b/sys/dev/mps/mps.c index a73b3919340..c1c1f6c9992 100644 --- a/sys/dev/mps/mps.c +++ b/sys/dev/mps/mps.c @@ -75,7 +75,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include static int mps_diag_reset(struct mps_softc *sc, int sleep_flag); static int mps_init_queues(struct mps_softc *sc); @@ -328,11 +327,9 @@ mps_transition_operational(struct mps_softc *sc) static int mps_iocfacts_allocate(struct mps_softc *sc, uint8_t attaching) { - int error, i; + int error; Mpi2IOCFactsReply_t saved_facts; uint8_t saved_mode, reallocating; - struct mpssas_lun *lun, *lun_tmp; - struct mpssas_target *targ; mps_dprint(sc, MPS_TRACE, "%s\n", __func__); @@ -489,27 +486,7 @@ mps_iocfacts_allocate(struct mps_softc *sc, uint8_t attaching) */ if (reallocating) { mps_iocfacts_free(sc); - - /* - * The number of targets is based on IOC Facts, so free all of - * the allocated LUNs for each target and then the target buffer - * itself. - */ - for (i=0; i< saved_facts.MaxTargets; i++) { - targ = &sc->sassc->targets[i]; - SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link, - lun_tmp) { - free(lun, M_MPT2); - } - } - free(sc->sassc->targets, M_MPT2); - - sc->sassc->targets = malloc(sizeof(struct mpssas_target) * - sc->facts->MaxTargets, M_MPT2, M_WAITOK|M_ZERO); - if (!sc->sassc->targets) { - panic("%s failed to alloc targets with error %d\n", - __func__, ENOMEM); - } + mpssas_realloc_targets(sc, saved_facts.MaxTargets); } /* diff --git a/sys/dev/mps/mps_sas.c b/sys/dev/mps/mps_sas.c index 06f0e696ea4..b30e83d1993 100644 --- a/sys/dev/mps/mps_sas.c +++ b/sys/dev/mps/mps_sas.c @@ -3591,3 +3591,33 @@ mpssas_check_id(struct mpssas_softc *sassc, int id) return (0); } + +void +mpssas_realloc_targets(struct mps_softc *sc, int maxtargets) +{ + struct mpssas_softc *sassc; + struct mpssas_lun *lun, *lun_tmp; + struct mpssas_target *targ; + int i; + + sassc = sc->sassc; + /* + * The number of targets is based on IOC Facts, so free all of + * the allocated LUNs for each target and then the target buffer + * itself. + */ + for (i=0; i< maxtargets; i++) { + targ = &sassc->targets[i]; + SLIST_FOREACH_SAFE(lun, &targ->luns, lun_link, lun_tmp) { + free(lun, M_MPT2); + } + } + free(sassc->targets, M_MPT2); + + sassc->targets = malloc(sizeof(struct mpssas_target) * maxtargets, + M_MPT2, M_WAITOK|M_ZERO); + if (!sassc->targets) { + panic("%s failed to alloc targets with error %d\n", + __func__, ENOMEM); + } +} diff --git a/sys/dev/mps/mps_sas.h b/sys/dev/mps/mps_sas.h index 0c3bb08980a..05db3b37863 100644 --- a/sys/dev/mps/mps_sas.h +++ b/sys/dev/mps/mps_sas.h @@ -156,7 +156,5 @@ void mpssas_discovery_end(struct mpssas_softc *sassc); void mpssas_startup_increment(struct mpssas_softc *sassc); void mpssas_startup_decrement(struct mpssas_softc *sassc); -struct mps_command * mpssas_alloc_tm(struct mps_softc *sc); -void mpssas_free_tm(struct mps_softc *sc, struct mps_command *tm); void mpssas_firmware_event_work(void *arg, int pending); int mpssas_check_id(struct mpssas_softc *sassc, int id); diff --git a/sys/dev/mps/mps_user.c b/sys/dev/mps/mps_user.c index 9212f77f9c2..16ec4e4e623 100644 --- a/sys/dev/mps/mps_user.c +++ b/sys/dev/mps/mps_user.c @@ -101,7 +101,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include diff --git a/sys/dev/mps/mpsvar.h b/sys/dev/mps/mpsvar.h index 14015fa0d6d..50e93f00ae6 100644 --- a/sys/dev/mps/mpsvar.h +++ b/sys/dev/mps/mpsvar.h @@ -756,6 +756,9 @@ void mpssas_prepare_remove(struct mpssas_softc *sassc, uint16_t handle); void mpssas_prepare_volume_remove(struct mpssas_softc *sassc, uint16_t handle); int mpssas_startup(struct mps_softc *sc); struct mpssas_target * mpssas_find_target_by_handle(struct mpssas_softc *, int, uint16_t); +void mpssas_realloc_targets(struct mps_softc *sc, int maxtargets); +struct mps_command * mpssas_alloc_tm(struct mps_softc *sc); +void mpssas_free_tm(struct mps_softc *sc, struct mps_command *tm); SYSCTL_DECL(_hw_mps);