be.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * Copyright (C) 2005 - 2009 ServerEngines
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@serverengines.com
  12. *
  13. * ServerEngines
  14. * 209 N. Fair Oaks Ave
  15. * Sunnyvale, CA 94085
  16. */
  17. #ifndef BEISCSI_H
  18. #define BEISCSI_H
  19. #include <linux/pci.h>
  20. #include <linux/if_vlan.h>
  21. #include <linux/blk-iopoll.h>
  22. #define FW_VER_LEN 32
  23. #define MCC_Q_LEN 128
  24. #define MCC_CQ_LEN 256
  25. struct be_dma_mem {
  26. void *va;
  27. dma_addr_t dma;
  28. u32 size;
  29. };
  30. struct be_queue_info {
  31. struct be_dma_mem dma_mem;
  32. u16 len;
  33. u16 entry_size; /* Size of an element in the queue */
  34. u16 id;
  35. u16 tail, head;
  36. bool created;
  37. atomic_t used; /* Number of valid elements in the queue */
  38. };
  39. static inline u32 MODULO(u16 val, u16 limit)
  40. {
  41. WARN_ON(limit & (limit - 1));
  42. return val & (limit - 1);
  43. }
  44. static inline void index_inc(u16 *index, u16 limit)
  45. {
  46. *index = MODULO((*index + 1), limit);
  47. }
  48. static inline void *queue_head_node(struct be_queue_info *q)
  49. {
  50. return q->dma_mem.va + q->head * q->entry_size;
  51. }
  52. static inline void *queue_tail_node(struct be_queue_info *q)
  53. {
  54. return q->dma_mem.va + q->tail * q->entry_size;
  55. }
  56. static inline void queue_head_inc(struct be_queue_info *q)
  57. {
  58. index_inc(&q->head, q->len);
  59. }
  60. static inline void queue_tail_inc(struct be_queue_info *q)
  61. {
  62. index_inc(&q->tail, q->len);
  63. }
  64. /*ISCSI */
  65. struct be_eq_obj {
  66. struct be_queue_info q;
  67. struct beiscsi_hba *phba;
  68. struct be_queue_info *cq;
  69. struct blk_iopoll iopoll;
  70. };
  71. struct be_mcc_obj {
  72. struct be_queue_info q;
  73. struct be_queue_info cq;
  74. };
  75. struct be_ctrl_info {
  76. u8 __iomem *csr;
  77. u8 __iomem *db; /* Door Bell */
  78. u8 __iomem *pcicfg; /* PCI config space */
  79. struct pci_dev *pdev;
  80. /* Mbox used for cmd request/response */
  81. spinlock_t mbox_lock; /* For serializing mbox cmds to BE card */
  82. struct be_dma_mem mbox_mem;
  83. /* Mbox mem is adjusted to align to 16 bytes. The allocated addr
  84. * is stored for freeing purpose */
  85. struct be_dma_mem mbox_mem_alloced;
  86. /* MCC Rings */
  87. struct be_mcc_obj mcc_obj;
  88. spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */
  89. spinlock_t mcc_cq_lock;
  90. /* MCC Async callback */
  91. void (*async_cb) (void *adapter, bool link_up);
  92. void *adapter_ctxt;
  93. };
  94. #include "be_cmds.h"
  95. #define PAGE_SHIFT_4K 12
  96. #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
  97. /* Returns number of pages spanned by the data starting at the given addr */
  98. #define PAGES_4K_SPANNED(_address, size) \
  99. ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \
  100. (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K))
  101. /* Byte offset into the page corresponding to given address */
  102. #define OFFSET_IN_PAGE(addr) \
  103. ((size_t)(addr) & (PAGE_SIZE_4K-1))
  104. /* Returns bit offset within a DWORD of a bitfield */
  105. #define AMAP_BIT_OFFSET(_struct, field) \
  106. (((size_t)&(((_struct *)0)->field))%32)
  107. /* Returns the bit mask of the field that is NOT shifted into location. */
  108. static inline u32 amap_mask(u32 bitsize)
  109. {
  110. return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1);
  111. }
  112. static inline void amap_set(void *ptr, u32 dw_offset, u32 mask,
  113. u32 offset, u32 value)
  114. {
  115. u32 *dw = (u32 *) ptr + dw_offset;
  116. *dw &= ~(mask << offset);
  117. *dw |= (mask & value) << offset;
  118. }
  119. #define AMAP_SET_BITS(_struct, field, ptr, val) \
  120. amap_set(ptr, \
  121. offsetof(_struct, field)/32, \
  122. amap_mask(sizeof(((_struct *)0)->field)), \
  123. AMAP_BIT_OFFSET(_struct, field), \
  124. val)
  125. static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
  126. {
  127. u32 *dw = ptr;
  128. return mask & (*(dw + dw_offset) >> offset);
  129. }
  130. #define AMAP_GET_BITS(_struct, field, ptr) \
  131. amap_get(ptr, \
  132. offsetof(_struct, field)/32, \
  133. amap_mask(sizeof(((_struct *)0)->field)), \
  134. AMAP_BIT_OFFSET(_struct, field))
  135. #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
  136. #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len)
  137. static inline void swap_dws(void *wrb, int len)
  138. {
  139. #ifdef __BIG_ENDIAN
  140. u32 *dw = wrb;
  141. WARN_ON(len % 4);
  142. do {
  143. *dw = cpu_to_le32(*dw);
  144. dw++;
  145. len -= 4;
  146. } while (len);
  147. #endif /* __BIG_ENDIAN */
  148. }
  149. #endif /* BEISCSI_H */