Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is part of the Chelsio FCoE driver for Linux.
0003  *
0004  * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
0005  *
0006  * This software is available to you under a choice of one of two
0007  * licenses.  You may choose to be licensed under the terms of the GNU
0008  * General Public License (GPL) Version 2, available from the file
0009  * COPYING in the main directory of this source tree, or the
0010  * OpenIB.org BSD license below:
0011  *
0012  *     Redistribution and use in source and binary forms, with or
0013  *     without modification, are permitted provided that the following
0014  *     conditions are met:
0015  *
0016  *      - Redistributions of source code must retain the above
0017  *        copyright notice, this list of conditions and the following
0018  *        disclaimer.
0019  *
0020  *      - Redistributions in binary form must reproduce the above
0021  *        copyright notice, this list of conditions and the following
0022  *        disclaimer in the documentation and/or other materials
0023  *        provided with the distribution.
0024  *
0025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0026  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0027  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0028  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0029  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0030  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0031  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0032  * SOFTWARE.
0033  */
0034 
0035 #ifndef __CSIO_DEFS_H__
0036 #define __CSIO_DEFS_H__
0037 
0038 #include <linux/kernel.h>
0039 #include <linux/stddef.h>
0040 #include <linux/timer.h>
0041 #include <linux/list.h>
0042 #include <linux/bug.h>
0043 #include <linux/pci.h>
0044 #include <linux/jiffies.h>
0045 
0046 #define CSIO_INVALID_IDX        0xFFFFFFFF
0047 #define CSIO_INC_STATS(elem, val)   ((elem)->stats.val++)
0048 #define CSIO_DEC_STATS(elem, val)   ((elem)->stats.val--)
0049 #define CSIO_VALID_WWN(__n)     ((*__n >> 4) == 0x5 ? true : false)
0050 #define CSIO_DID_MASK           0xFFFFFF
0051 #define CSIO_WORD_TO_BYTE       4
0052 
0053 #ifndef readq
0054 static inline u64 readq(void __iomem *addr)
0055 {
0056     return readl(addr) + ((u64)readl(addr + 4) << 32);
0057 }
0058 
0059 static inline void writeq(u64 val, void __iomem *addr)
0060 {
0061     writel(val, addr);
0062     writel(val >> 32, addr + 4);
0063 }
0064 #endif
0065 
0066 static inline int
0067 csio_list_deleted(struct list_head *list)
0068 {
0069     return ((list->next == list) && (list->prev == list));
0070 }
0071 
0072 #define csio_list_next(elem)    (((struct list_head *)(elem))->next)
0073 #define csio_list_prev(elem)    (((struct list_head *)(elem))->prev)
0074 
0075 /* State machine */
0076 typedef void (*csio_sm_state_t)(void *, uint32_t);
0077 
0078 struct csio_sm {
0079     struct list_head    sm_list;
0080     csio_sm_state_t     sm_state;
0081 };
0082 
0083 static inline void
0084 csio_set_state(void *smp, void *state)
0085 {
0086     ((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state;
0087 }
0088 
0089 static inline void
0090 csio_init_state(struct csio_sm *smp, void *state)
0091 {
0092     csio_set_state(smp, state);
0093 }
0094 
0095 static inline void
0096 csio_post_event(void *smp, uint32_t evt)
0097 {
0098     ((struct csio_sm *)smp)->sm_state(smp, evt);
0099 }
0100 
0101 static inline csio_sm_state_t
0102 csio_get_state(void *smp)
0103 {
0104     return ((struct csio_sm *)smp)->sm_state;
0105 }
0106 
0107 static inline bool
0108 csio_match_state(void *smp, void *state)
0109 {
0110     return (csio_get_state(smp) == (csio_sm_state_t)state);
0111 }
0112 
0113 #define CSIO_ASSERT(cond)       BUG_ON(!(cond))
0114 
0115 #ifdef __CSIO_DEBUG__
0116 #define CSIO_DB_ASSERT(__c)     CSIO_ASSERT((__c))
0117 #else
0118 #define CSIO_DB_ASSERT(__c)
0119 #endif
0120 
0121 #endif /* ifndef __CSIO_DEFS_H__ */