brintos

brintos / linux-shallow public Read only

0
0
Text · 3.6 KiB · e50e93e Raw
136 lines · c
1/*2 * This file is part of the Chelsio FCoE driver for Linux.3 *4 * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses.  You may choose to be licensed under the terms of the GNU8 * General Public License (GPL) Version 2, available from the file9 * COPYING in the main directory of this source tree, or the10 * OpenIB.org BSD license below:11 *12 *     Redistribution and use in source and binary forms, with or13 *     without modification, are permitted provided that the following14 *     conditions are met:15 *16 *      - Redistributions of source code must retain the above17 *        copyright notice, this list of conditions and the following18 *        disclaimer.19 *20 *      - Redistributions in binary form must reproduce the above21 *        copyright notice, this list of conditions and the following22 *        disclaimer in the documentation and/or other materials23 *        provided with the distribution.24 *25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE32 * SOFTWARE.33 */34 35#ifndef __CSIO_DEFS_H__36#define __CSIO_DEFS_H__37 38#include <linux/kernel.h>39#include <linux/stddef.h>40#include <linux/timer.h>41#include <linux/list.h>42#include <linux/bug.h>43#include <linux/pci.h>44#include <linux/jiffies.h>45 46#define CSIO_INVALID_IDX		0xFFFFFFFF47#define CSIO_INC_STATS(elem, val)	((elem)->stats.val++)48#define CSIO_DEC_STATS(elem, val)	((elem)->stats.val--)49#define CSIO_VALID_WWN(__n)		((*__n >> 4) == 0x5 ? true : false)50#define CSIO_DID_MASK			0xFFFFFF51#define CSIO_WORD_TO_BYTE		452 53#ifndef readq54static inline u64 readq(void __iomem *addr)55{56	return readl(addr) + ((u64)readl(addr + 4) << 32);57}58 59static inline void writeq(u64 val, void __iomem *addr)60{61	writel(val, addr);62	writel(val >> 32, addr + 4);63}64#endif65 66static inline int67csio_list_deleted(struct list_head *list)68{69	return ((list->next == list) && (list->prev == list));70}71 72#define csio_list_next(elem)	(((struct list_head *)(elem))->next)73#define csio_list_prev(elem)	(((struct list_head *)(elem))->prev)74 75/* State machine */76struct csio_lnode;77 78/* State machine evets */79enum csio_ln_ev {80	CSIO_LNE_NONE = (uint32_t)0,81	CSIO_LNE_LINKUP,82	CSIO_LNE_FAB_INIT_DONE,83	CSIO_LNE_LINK_DOWN,84	CSIO_LNE_DOWN_LINK,85	CSIO_LNE_LOGO,86	CSIO_LNE_CLOSE,87	CSIO_LNE_MAX_EVENT,88};89 90typedef void (*csio_sm_state_t)(struct csio_lnode *ln, enum csio_ln_ev evt);91 92struct csio_sm {93	struct list_head	sm_list;94	csio_sm_state_t		sm_state;95};96 97static inline void98csio_set_state(void *smp, void *state)99{100	((struct csio_sm *)smp)->sm_state = state;101}102 103static inline void104csio_init_state(struct csio_sm *smp, void *state)105{106	csio_set_state(smp, state);107}108 109static inline void110csio_post_event(void *smp, uint32_t evt)111{112	((struct csio_sm *)smp)->sm_state(smp, evt);113}114 115static inline csio_sm_state_t116csio_get_state(void *smp)117{118	return ((struct csio_sm *)smp)->sm_state;119}120 121static inline bool122csio_match_state(void *smp, void *state)123{124	return (csio_get_state(smp) == (csio_sm_state_t)state);125}126 127#define	CSIO_ASSERT(cond)		BUG_ON(!(cond))128 129#ifdef __CSIO_DEBUG__130#define CSIO_DB_ASSERT(__c)		CSIO_ASSERT((__c))131#else132#define CSIO_DB_ASSERT(__c)133#endif134 135#endif /* ifndef __CSIO_DEFS_H__ */136