18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is part of the Chelsio FCoE driver for Linux.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
78c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
138c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
148c2ecf20Sopenharmony_ci *     conditions are met:
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
178c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
188c2ecf20Sopenharmony_ci *        disclaimer.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
218c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
228c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
238c2ecf20Sopenharmony_ci *        provided with the distribution.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
328c2ecf20Sopenharmony_ci * SOFTWARE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef __CSIO_DEFS_H__
368c2ecf20Sopenharmony_ci#define __CSIO_DEFS_H__
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/kernel.h>
398c2ecf20Sopenharmony_ci#include <linux/stddef.h>
408c2ecf20Sopenharmony_ci#include <linux/timer.h>
418c2ecf20Sopenharmony_ci#include <linux/list.h>
428c2ecf20Sopenharmony_ci#include <linux/bug.h>
438c2ecf20Sopenharmony_ci#include <linux/pci.h>
448c2ecf20Sopenharmony_ci#include <linux/jiffies.h>
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define CSIO_INVALID_IDX		0xFFFFFFFF
478c2ecf20Sopenharmony_ci#define CSIO_INC_STATS(elem, val)	((elem)->stats.val++)
488c2ecf20Sopenharmony_ci#define CSIO_DEC_STATS(elem, val)	((elem)->stats.val--)
498c2ecf20Sopenharmony_ci#define CSIO_VALID_WWN(__n)		((*__n >> 4) == 0x5 ? true : false)
508c2ecf20Sopenharmony_ci#define CSIO_DID_MASK			0xFFFFFF
518c2ecf20Sopenharmony_ci#define CSIO_WORD_TO_BYTE		4
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#ifndef readq
548c2ecf20Sopenharmony_cistatic inline u64 readq(void __iomem *addr)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	return readl(addr) + ((u64)readl(addr + 4) << 32);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic inline void writeq(u64 val, void __iomem *addr)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	writel(val, addr);
628c2ecf20Sopenharmony_ci	writel(val >> 32, addr + 4);
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci#endif
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistatic inline int
678c2ecf20Sopenharmony_cicsio_list_deleted(struct list_head *list)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	return ((list->next == list) && (list->prev == list));
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define csio_list_next(elem)	(((struct list_head *)(elem))->next)
738c2ecf20Sopenharmony_ci#define csio_list_prev(elem)	(((struct list_head *)(elem))->prev)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* State machine */
768c2ecf20Sopenharmony_citypedef void (*csio_sm_state_t)(void *, uint32_t);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistruct csio_sm {
798c2ecf20Sopenharmony_ci	struct list_head	sm_list;
808c2ecf20Sopenharmony_ci	csio_sm_state_t		sm_state;
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic inline void
848c2ecf20Sopenharmony_cicsio_set_state(void *smp, void *state)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state;
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic inline void
908c2ecf20Sopenharmony_cicsio_init_state(struct csio_sm *smp, void *state)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	csio_set_state(smp, state);
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic inline void
968c2ecf20Sopenharmony_cicsio_post_event(void *smp, uint32_t evt)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	((struct csio_sm *)smp)->sm_state(smp, evt);
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistatic inline csio_sm_state_t
1028c2ecf20Sopenharmony_cicsio_get_state(void *smp)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	return ((struct csio_sm *)smp)->sm_state;
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistatic inline bool
1088c2ecf20Sopenharmony_cicsio_match_state(void *smp, void *state)
1098c2ecf20Sopenharmony_ci{
1108c2ecf20Sopenharmony_ci	return (csio_get_state(smp) == (csio_sm_state_t)state);
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci#define	CSIO_ASSERT(cond)		BUG_ON(!(cond))
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#ifdef __CSIO_DEBUG__
1168c2ecf20Sopenharmony_ci#define CSIO_DB_ASSERT(__c)		CSIO_ASSERT((__c))
1178c2ecf20Sopenharmony_ci#else
1188c2ecf20Sopenharmony_ci#define CSIO_DB_ASSERT(__c)
1198c2ecf20Sopenharmony_ci#endif
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#endif /* ifndef __CSIO_DEFS_H__ */
122