xref: /freebsd-src/sys/dev/smartpqi/smartpqi_helper.h (revision 2f06449d64298fe508e3c585b45effd69a72d696)
17ea28254SJohn Hall /*-
27ea28254SJohn Hall  * Copyright 2016-2023 Microchip Technology, Inc. and/or its subsidiaries.
37ea28254SJohn Hall  *
47ea28254SJohn Hall  * Redistribution and use in source and binary forms, with or without
57ea28254SJohn Hall  * modification, are permitted provided that the following conditions
67ea28254SJohn Hall  * are met:
77ea28254SJohn Hall  * 1. Redistributions of source code must retain the above copyright
87ea28254SJohn Hall  *    notice, this list of conditions and the following disclaimer.
97ea28254SJohn Hall  * 2. Redistributions in binary form must reproduce the above copyright
107ea28254SJohn Hall  *    notice, this list of conditions and the following disclaimer in the
117ea28254SJohn Hall  *    documentation and/or other materials provided with the distribution.
127ea28254SJohn Hall  *
137ea28254SJohn Hall  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
147ea28254SJohn Hall  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
157ea28254SJohn Hall  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
167ea28254SJohn Hall  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
177ea28254SJohn Hall  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
187ea28254SJohn Hall  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
197ea28254SJohn Hall  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
207ea28254SJohn Hall  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
217ea28254SJohn Hall  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
227ea28254SJohn Hall  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
237ea28254SJohn Hall  * SUCH DAMAGE.
247ea28254SJohn Hall  */
257ea28254SJohn Hall 
267ea28254SJohn Hall 
277ea28254SJohn Hall #ifndef _PQI_HELPER_H
287ea28254SJohn Hall #define _PQI_HELPER_H
297ea28254SJohn Hall 
307ea28254SJohn Hall 
31*2f06449dSWarner Losh static inline uint64_t
pqisrc_increment_device_active_io(pqisrc_softstate_t * softs,pqi_scsi_dev_t * device)327ea28254SJohn Hall pqisrc_increment_device_active_io(pqisrc_softstate_t *softs, pqi_scsi_dev_t *device)
337ea28254SJohn Hall {
347ea28254SJohn Hall #if PQISRC_DEVICE_IO_COUNTER
357ea28254SJohn Hall 	/*Increment device active io count by one*/
367ea28254SJohn Hall 	return OS_ATOMIC64_INC(&device->active_requests);
377ea28254SJohn Hall #endif
387ea28254SJohn Hall }
397ea28254SJohn Hall 
40*2f06449dSWarner Losh static inline uint64_t
pqisrc_decrement_device_active_io(pqisrc_softstate_t * softs,pqi_scsi_dev_t * device)417ea28254SJohn Hall pqisrc_decrement_device_active_io(pqisrc_softstate_t *softs,  pqi_scsi_dev_t *device)
427ea28254SJohn Hall {
437ea28254SJohn Hall #if PQISRC_DEVICE_IO_COUNTER
447ea28254SJohn Hall 	/*Decrement device active io count by one*/
457ea28254SJohn Hall 	return OS_ATOMIC64_DEC(&device->active_requests);
467ea28254SJohn Hall #endif
477ea28254SJohn Hall }
487ea28254SJohn Hall 
49*2f06449dSWarner Losh static inline void
pqisrc_init_device_active_io(pqisrc_softstate_t * softs,pqi_scsi_dev_t * device)507ea28254SJohn Hall pqisrc_init_device_active_io(pqisrc_softstate_t *softs, pqi_scsi_dev_t *device)
517ea28254SJohn Hall {
527ea28254SJohn Hall #if PQISRC_DEVICE_IO_COUNTER
537ea28254SJohn Hall 	/* Reset device count to Zero */
547ea28254SJohn Hall 	OS_ATOMIC64_INIT(&device->active_requests, 0);
557ea28254SJohn Hall #endif
567ea28254SJohn Hall }
577ea28254SJohn Hall 
58*2f06449dSWarner Losh static inline uint64_t
pqisrc_read_device_active_io(pqisrc_softstate_t * softs,pqi_scsi_dev_t * device)597ea28254SJohn Hall pqisrc_read_device_active_io(pqisrc_softstate_t *softs, pqi_scsi_dev_t *device)
607ea28254SJohn Hall {
617ea28254SJohn Hall #if PQISRC_DEVICE_IO_COUNTER
627ea28254SJohn Hall 	/* read device active count*/
637ea28254SJohn Hall 	return OS_ATOMIC64_READ(&device->active_requests);
647ea28254SJohn Hall #endif
657ea28254SJohn Hall }
667ea28254SJohn Hall #endif  /* _PQI_HELPER_H */
67