csio_defs.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * 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 OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CSIO_DEFS_H__
  35. #define __CSIO_DEFS_H__
  36. #include <linux/kernel.h>
  37. #include <linux/stddef.h>
  38. #include <linux/timer.h>
  39. #include <linux/list.h>
  40. #include <linux/bug.h>
  41. #include <linux/pci.h>
  42. #include <linux/jiffies.h>
  43. #define CSIO_INVALID_IDX 0xFFFFFFFF
  44. #define CSIO_INC_STATS(elem, val) ((elem)->stats.val++)
  45. #define CSIO_DEC_STATS(elem, val) ((elem)->stats.val--)
  46. #define CSIO_VALID_WWN(__n) ((*__n >> 4) == 0x5 ? true : false)
  47. #define CSIO_DID_MASK 0xFFFFFF
  48. #define CSIO_WORD_TO_BYTE 4
  49. #ifndef readq
  50. static inline u64 readq(void __iomem *addr)
  51. {
  52. return readl(addr) + ((u64)readl(addr + 4) << 32);
  53. }
  54. static inline void writeq(u64 val, void __iomem *addr)
  55. {
  56. writel(val, addr);
  57. writel(val >> 32, addr + 4);
  58. }
  59. #endif
  60. static inline int
  61. csio_list_deleted(struct list_head *list)
  62. {
  63. return ((list->next == list) && (list->prev == list));
  64. }
  65. #define csio_list_next(elem) (((struct list_head *)(elem))->next)
  66. #define csio_list_prev(elem) (((struct list_head *)(elem))->prev)
  67. /* State machine */
  68. typedef void (*csio_sm_state_t)(void *, uint32_t);
  69. struct csio_sm {
  70. struct list_head sm_list;
  71. csio_sm_state_t sm_state;
  72. };
  73. static inline void
  74. csio_set_state(void *smp, void *state)
  75. {
  76. ((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state;
  77. }
  78. static inline void
  79. csio_init_state(struct csio_sm *smp, void *state)
  80. {
  81. csio_set_state(smp, state);
  82. }
  83. static inline void
  84. csio_post_event(void *smp, uint32_t evt)
  85. {
  86. ((struct csio_sm *)smp)->sm_state(smp, evt);
  87. }
  88. static inline csio_sm_state_t
  89. csio_get_state(void *smp)
  90. {
  91. return ((struct csio_sm *)smp)->sm_state;
  92. }
  93. static inline bool
  94. csio_match_state(void *smp, void *state)
  95. {
  96. return (csio_get_state(smp) == (csio_sm_state_t)state);
  97. }
  98. #define CSIO_ASSERT(cond) BUG_ON(!(cond))
  99. #ifdef __CSIO_DEBUG__
  100. #define CSIO_DB_ASSERT(__c) CSIO_ASSERT((__c))
  101. #else
  102. #define CSIO_DB_ASSERT(__c)
  103. #endif
  104. #endif /* ifndef __CSIO_DEFS_H__ */