Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2014- QLogic Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * All rights reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * www.qlogic.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  bfa_cs.h BFA common services
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #ifndef __BFA_CS_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define __BFA_CS_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "bfad_drv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * BFA TRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #ifndef BFA_TRC_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define BFA_TRC_MAX	(4 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define BFA_TRC_TS(_trcm)                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	({                                              \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		struct timespec64 ts;                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		ktime_get_ts64(&ts);                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		(ts.tv_sec*1000000+ts.tv_nsec / 1000);  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	})
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #ifndef BFA_TRC_TS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define BFA_TRC_TS(_trcm)	((_trcm)->ticks++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) struct bfa_trc_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	u16	fileno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	u16	line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	u16	line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u16	fileno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u32	timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			u32	rsvd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			u32	u32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		} u32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		u64	u64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	} data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct bfa_trc_mod_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u32	head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u32	tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u32	ntrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u32	stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u32	ticks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u32	rsvd[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct bfa_trc_s trc[BFA_TRC_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	BFA_TRC_HAL  = 1,	/*  BFA modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	BFA_TRC_FCS  = 2,	/*  BFA FCS modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	BFA_TRC_LDRV = 3,	/*  Linux driver modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	BFA_TRC_CNA  = 4,	/*  Common modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define BFA_TRC_MOD_SH	10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define BFA_TRC_MOD(__mod)	((BFA_TRC_ ## __mod) << BFA_TRC_MOD_SH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Define a new tracing file (module). Module should match one defined above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define BFA_TRC_FILE(__mod, __submod)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	static int __trc_fileno = ((BFA_TRC_ ## __mod ## _ ## __submod) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 						 BFA_TRC_MOD(__mod))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define bfa_trc32(_trcp, _data)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	__bfa_trc((_trcp)->trcmod, __trc_fileno, __LINE__, (u32)_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define bfa_trc(_trcp, _data)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	__bfa_trc((_trcp)->trcmod, __trc_fileno, __LINE__, (u64)_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) bfa_trc_init(struct bfa_trc_mod_s *trcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	trcm->head = trcm->tail = trcm->stopped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	trcm->ntrc = BFA_TRC_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) bfa_trc_stop(struct bfa_trc_mod_s *trcm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	trcm->stopped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) __bfa_trc(struct bfa_trc_mod_s *trcm, int fileno, int line, u64 data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) __bfa_trc32(struct bfa_trc_mod_s *trcm, int fileno, int line, u32 data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define bfa_sm_fault(__mod, __event)	do {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	bfa_trc(__mod, (((u32)0xDEAD << 16) | __event));		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	printk(KERN_ERR	"Assertion failure: %s:%d: %d",			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		__FILE__, __LINE__, (__event));				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* BFA queue definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define bfa_q_first(_q) ((void *)(((struct list_head *) (_q))->next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define bfa_q_next(_qe) (((struct list_head *) (_qe))->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define bfa_q_prev(_qe) (((struct list_head *) (_qe))->prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * bfa_q_qe_init - to initialize a queue element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define bfa_q_qe_init(_qe) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	bfa_q_next(_qe) = (struct list_head *) NULL;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	bfa_q_prev(_qe) = (struct list_head *) NULL;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * bfa_q_deq - dequeue an element from head of the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define bfa_q_deq(_q, _qe) do {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (!list_empty(_q)) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		(*((struct list_head **) (_qe))) = bfa_q_next(_q);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		bfa_q_prev(bfa_q_next(*((struct list_head **) _qe))) =	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 				(struct list_head *) (_q);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		bfa_q_next(_q) = bfa_q_next(*((struct list_head **) _qe));\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	} else {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		*((struct list_head **) (_qe)) = (struct list_head *) NULL;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * bfa_q_deq_tail - dequeue an element from tail of the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define bfa_q_deq_tail(_q, _qe) {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (!list_empty(_q)) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		*((struct list_head **) (_qe)) = bfa_q_prev(_q);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		bfa_q_next(bfa_q_prev(*((struct list_head **) _qe))) =	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			(struct list_head *) (_q);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		bfa_q_prev(_q) = bfa_q_prev(*(struct list_head **) _qe);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	} else {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		*((struct list_head **) (_qe)) = (struct list_head *) NULL;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) bfa_q_is_on_q_func(struct list_head *q, struct list_head *qe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct list_head        *tqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	tqe = bfa_q_next(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	while (tqe != q) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (tqe == qe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		tqe = bfa_q_next(tqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (tqe == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define bfa_q_is_on_q(_q, _qe)      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	bfa_q_is_on_q_func(_q, (struct list_head *)(_qe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * @ BFA state machine interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) typedef void (*bfa_sm_t)(void *sm, int event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * oc - object class eg. bfa_ioc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * st - state, eg. reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * otype - object type, eg. struct bfa_ioc_s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * etype - object type, eg. enum ioc_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define bfa_sm_state_decl(oc, st, otype, etype)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	static void oc ## _sm_ ## st(otype * fsm, etype event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define bfa_sm_set_state(_sm, _state)	((_sm)->sm = (bfa_sm_t)(_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #define bfa_sm_send_event(_sm, _event)	((_sm)->sm((_sm), (_event)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define bfa_sm_get_state(_sm)		((_sm)->sm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define bfa_sm_cmp_state(_sm, _state)	((_sm)->sm == (bfa_sm_t)(_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * For converting from state machine function to state encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct bfa_sm_table_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	bfa_sm_t	sm;	/*  state machine function	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	int		state;	/*  state machine encoding	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	char		*name;	/*  state name for display	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define BFA_SM(_sm)	((bfa_sm_t)(_sm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * State machine with entry actions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) typedef void (*bfa_fsm_t)(void *fsm, int event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * oc - object class eg. bfa_ioc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * st - state, eg. reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * otype - object type, eg. struct bfa_ioc_s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * etype - object type, eg. enum ioc_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define bfa_fsm_state_decl(oc, st, otype, etype)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	static void oc ## _sm_ ## st(otype * fsm, etype event);      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	static void oc ## _sm_ ## st ## _entry(otype * fsm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define bfa_fsm_set_state(_fsm, _state) do {	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	(_fsm)->fsm = (bfa_fsm_t)(_state);      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	_state ## _entry(_fsm);      \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define bfa_fsm_send_event(_fsm, _event)	((_fsm)->fsm((_fsm), (_event)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define bfa_fsm_get_state(_fsm)			((_fsm)->fsm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #define bfa_fsm_cmp_state(_fsm, _state)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	((_fsm)->fsm == (bfa_fsm_t)(_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) bfa_sm_to_state(struct bfa_sm_table_s *smt, bfa_sm_t sm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	int	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	while (smt[i].sm && smt[i].sm != sm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return smt[i].state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * @ Generic wait counter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) typedef void (*bfa_wc_resume_t) (void *cbarg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct bfa_wc_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	bfa_wc_resume_t wc_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	void		*wc_cbarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	int		wc_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) bfa_wc_up(struct bfa_wc_s *wc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	wc->wc_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) bfa_wc_down(struct bfa_wc_s *wc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	wc->wc_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (wc->wc_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		wc->wc_resume(wc->wc_cbarg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * Initialize a waiting counter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) bfa_wc_init(struct bfa_wc_s *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	wc->wc_resume = wc_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	wc->wc_cbarg = wc_cbarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	wc->wc_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	bfa_wc_up(wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * Wait for counter to reach zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) bfa_wc_wait(struct bfa_wc_s *wc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	bfa_wc_down(wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) wwn2str(char *wwn_str, u64 wwn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		u64 wwn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		u8 byte[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	} w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	w.wwn = wwn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		w.byte[6], w.byte[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) fcid2str(char *fcid_str, u32 fcid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		u32 fcid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		u8 byte[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	} f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	f.fcid = fcid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #define bfa_swap_3b(_x)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	((((_x) & 0xff) << 16) |		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	((_x) & 0x00ff00) |			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	(((_x) & 0xff0000) >> 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #ifndef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #define bfa_hton3b(_x)  bfa_swap_3b(_x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define bfa_hton3b(_x)  (_x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #define bfa_ntoh3b(_x)  bfa_hton3b(_x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #endif /* __BFA_CS_H__ */