| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Linux network driver for Brocade Converged Network Adapter. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify it | 
					
						
							|  |  |  |  * under the terms of the GNU General Public License (GPL) Version 2 as | 
					
						
							|  |  |  |  * published by the Free Software Foundation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, but | 
					
						
							|  |  |  |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * General Public License for more details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  |  * Copyright (c) 2005-2011 Brocade Communications Systems, Inc. | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  |  * All rights reserved | 
					
						
							|  |  |  |  * www.brocade.com | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* BFA common services */ | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | #ifndef __BFA_CS_H__
 | 
					
						
							|  |  |  | #define __BFA_CS_H__
 | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "cna.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* BFA state machine interfaces */ | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | typedef void (*bfa_sm_t)(void *sm, int event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* oc - object class eg. bfa_ioc
 | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  |  * st - state, eg. reset | 
					
						
							|  |  |  |  * otype - object type, eg. struct bfa_ioc | 
					
						
							|  |  |  |  * etype - object type, eg. enum ioc_event | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | #define bfa_sm_state_decl(oc, st, otype, etype)			\
 | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | 	static void oc ## _sm_ ## st(otype * fsm, etype event) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define bfa_sm_set_state(_sm, _state)	((_sm)->sm = (bfa_sm_t)(_state))
 | 
					
						
							|  |  |  | #define bfa_sm_send_event(_sm, _event)	((_sm)->sm((_sm), (_event)))
 | 
					
						
							|  |  |  | #define bfa_sm_get_state(_sm)		((_sm)->sm)
 | 
					
						
							|  |  |  | #define bfa_sm_cmp_state(_sm, _state)	((_sm)->sm == (bfa_sm_t)(_state))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* For converting from state machine function to state encoding. */ | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | struct bfa_sm_table { | 
					
						
							|  |  |  | 	bfa_sm_t	sm;	/*!< state machine function	*/ | 
					
						
							|  |  |  | 	int		state;	/*!< state machine encoding	*/ | 
					
						
							|  |  |  | 	char		*name;	/*!< state name for display	*/ | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | #define BFA_SM(_sm)		((bfa_sm_t)(_sm))
 | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* State machine with entry actions. */ | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | typedef void (*bfa_fsm_t)(void *fsm, int event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* oc - object class eg. bfa_ioc
 | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  |  * st - state, eg. reset | 
					
						
							|  |  |  |  * otype - object type, eg. struct bfa_ioc | 
					
						
							|  |  |  |  * etype - object type, eg. enum ioc_event | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | #define bfa_fsm_state_decl(oc, st, otype, etype)			\
 | 
					
						
							|  |  |  | 	static void oc ## _sm_ ## st(otype * fsm, etype event);		\ | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | 	static void oc ## _sm_ ## st ## _entry(otype * fsm) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | #define bfa_fsm_set_state(_fsm, _state) do {				\
 | 
					
						
							|  |  |  | 	(_fsm)->fsm = (bfa_fsm_t)(_state);				\ | 
					
						
							|  |  |  | 	_state ## _entry(_fsm);						\ | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define bfa_fsm_send_event(_fsm, _event)	((_fsm)->fsm((_fsm), (_event)))
 | 
					
						
							|  |  |  | #define bfa_fsm_get_state(_fsm)			((_fsm)->fsm)
 | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | #define bfa_fsm_cmp_state(_fsm, _state)					\
 | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | 	((_fsm)->fsm == (bfa_fsm_t)(_state)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline int | 
					
						
							| 
									
										
										
										
											2010-10-05 15:46:05 +00:00
										 |  |  | bfa_sm_to_state(const struct bfa_sm_table *smt, bfa_sm_t sm) | 
					
						
							| 
									
										
										
										
											2010-08-23 20:24:12 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int	i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (smt[i].sm && smt[i].sm != sm) | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 	return smt[i].state; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* Generic wait counter. */ | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef void (*bfa_wc_resume_t) (void *cbarg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct bfa_wc { | 
					
						
							|  |  |  | 	bfa_wc_resume_t wc_resume; | 
					
						
							|  |  |  | 	void		*wc_cbarg; | 
					
						
							|  |  |  | 	int		wc_count; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void | 
					
						
							|  |  |  | bfa_wc_up(struct bfa_wc *wc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	wc->wc_count++; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void | 
					
						
							|  |  |  | bfa_wc_down(struct bfa_wc *wc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	wc->wc_count--; | 
					
						
							|  |  |  | 	if (wc->wc_count == 0) | 
					
						
							|  |  |  | 		wc->wc_resume(wc->wc_cbarg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* Initialize a waiting counter. */ | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | static inline void | 
					
						
							|  |  |  | bfa_wc_init(struct bfa_wc *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	wc->wc_resume = wc_resume; | 
					
						
							|  |  |  | 	wc->wc_cbarg = wc_cbarg; | 
					
						
							|  |  |  | 	wc->wc_count = 0; | 
					
						
							|  |  |  | 	bfa_wc_up(wc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 10:56:59 +00:00
										 |  |  | /* Wait for counter to reach zero */ | 
					
						
							| 
									
										
										
										
											2011-07-22 08:07:49 +00:00
										 |  |  | static inline void | 
					
						
							|  |  |  | bfa_wc_wait(struct bfa_wc *wc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bfa_wc_down(wc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* __BFA_CS_H__ */
 |