/*-1* CAM IO Scheduler Interface2*3* SPDX-License-Identifier: BSD-2-Clause4*5* Copyright (c) 2015 Netflix, Inc.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _CAM_CAM_IOSCHED_H30#define _CAM_CAM_IOSCHED_H3132/* No user-serviceable parts in here. */33#ifdef _KERNEL3435/* Forward declare all structs to keep interface thin */36struct cam_iosched_softc;37struct sysctl_ctx_list;38struct sysctl_oid;39union ccb;40struct bio;4142/*43* For 64-bit platforms, we know that uintptr_t is the same size as sbintime_t44* so we can store values in it. For 32-bit systems, however, uintptr_t is only45* 32-bits, so it won't fit. For those systems, store 24 bits of fraction and 846* bits of seconds. This allows us to measure an interval of up to ~256s, which47* is ~200x what our current uses require. Provide some convenience functions to48* get the time, subtract two times and convert back to sbintime_t in a safe way49* that can be centralized.50*/51#ifdef __LP64__52#define CAM_IOSCHED_TIME_SHIFT 053#else54#define CAM_IOSCHED_TIME_SHIFT 855#endif56static inline uintptr_t57cam_iosched_now(void)58{5960/* Cast here is to avoid right shifting a signed value */61return (uintptr_t)((uint64_t)sbinuptime() >> CAM_IOSCHED_TIME_SHIFT);62}6364static inline uintptr_t65cam_iosched_delta_t(uintptr_t then)66{6768/* Since the types are identical, wrapping works correctly */69return (cam_iosched_now() - then);70}7172static inline sbintime_t73cam_iosched_sbintime_t(uintptr_t delta)74{7576/* Cast here is to widen the type so the left shift doesn't lose precision */77return (sbintime_t)((uint64_t)delta << CAM_IOSCHED_TIME_SHIFT);78}7980typedef void (*cam_iosched_latfcn_t)(void *, sbintime_t, struct bio *);81typedef void (*cam_iosched_schedule_t)(struct cam_periph *periph);8283int cam_iosched_init(struct cam_iosched_softc **, struct cam_periph *periph,84const struct disk *dp, cam_iosched_schedule_t schedfnp);85void cam_iosched_fini(struct cam_iosched_softc *);86void cam_iosched_sysctl_init(struct cam_iosched_softc *, struct sysctl_ctx_list *, struct sysctl_oid *);87struct bio *cam_iosched_next_trim(struct cam_iosched_softc *isc);88struct bio *cam_iosched_get_trim(struct cam_iosched_softc *isc);89struct bio *cam_iosched_next_bio(struct cam_iosched_softc *isc);90void cam_iosched_queue_work(struct cam_iosched_softc *isc, struct bio *bp);91void cam_iosched_flush(struct cam_iosched_softc *isc, struct devstat *stp, int err);92void cam_iosched_schedule(struct cam_iosched_softc *isc, struct cam_periph *periph);93void cam_iosched_finish_trim(struct cam_iosched_softc *isc);94void cam_iosched_submit_trim(struct cam_iosched_softc *isc);95void cam_iosched_put_back_trim(struct cam_iosched_softc *isc, struct bio *bp);96void cam_iosched_set_sort_queue(struct cam_iosched_softc *isc, int val);97int cam_iosched_has_work_flags(struct cam_iosched_softc *isc, uint32_t flags);98void cam_iosched_set_work_flags(struct cam_iosched_softc *isc, uint32_t flags);99void cam_iosched_clr_work_flags(struct cam_iosched_softc *isc, uint32_t flags);100void cam_iosched_trim_done(struct cam_iosched_softc *isc);101int cam_iosched_bio_complete(struct cam_iosched_softc *isc, struct bio *bp, union ccb *done_ccb);102void cam_iosched_set_latfcn(struct cam_iosched_softc *isc, cam_iosched_latfcn_t, void *);103void cam_iosched_set_trim_goal(struct cam_iosched_softc *isc, int goal);104void cam_iosched_set_trim_ticks(struct cam_iosched_softc *isc, int ticks);105#endif106#endif107108109