diff options
Diffstat (limited to 'drivers/scsi/be2iscsi/be.h')
| -rw-r--r-- | drivers/scsi/be2iscsi/be.h | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/drivers/scsi/be2iscsi/be.h b/drivers/scsi/be2iscsi/be.h new file mode 100644 index 000000000000..b36020dcf012 --- /dev/null +++ b/drivers/scsi/be2iscsi/be.h | |||
| @@ -0,0 +1,183 @@ | |||
| 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 | |||
| 18 | #ifndef BEISCSI_H | ||
| 19 | #define BEISCSI_H | ||
| 20 | |||
| 21 | #include <linux/pci.h> | ||
| 22 | #include <linux/if_vlan.h> | ||
| 23 | |||
| 24 | #define FW_VER_LEN 32 | ||
| 25 | |||
| 26 | struct be_dma_mem { | ||
| 27 | void *va; | ||
| 28 | dma_addr_t dma; | ||
| 29 | u32 size; | ||
| 30 | }; | ||
| 31 | |||
| 32 | struct be_queue_info { | ||
| 33 | struct be_dma_mem dma_mem; | ||
| 34 | u16 len; | ||
| 35 | u16 entry_size; /* Size of an element in the queue */ | ||
| 36 | u16 id; | ||
| 37 | u16 tail, head; | ||
| 38 | bool created; | ||
| 39 | atomic_t used; /* Number of valid elements in the queue */ | ||
| 40 | }; | ||
| 41 | |||
| 42 | static inline u32 MODULO(u16 val, u16 limit) | ||
| 43 | { | ||
| 44 | WARN_ON(limit & (limit - 1)); | ||
| 45 | return val & (limit - 1); | ||
| 46 | } | ||
| 47 | |||
| 48 | static inline void index_inc(u16 *index, u16 limit) | ||
| 49 | { | ||
| 50 | *index = MODULO((*index + 1), limit); | ||
| 51 | } | ||
| 52 | |||
| 53 | static inline void *queue_head_node(struct be_queue_info *q) | ||
| 54 | { | ||
| 55 | return q->dma_mem.va + q->head * q->entry_size; | ||
| 56 | } | ||
| 57 | |||
| 58 | static inline void *queue_tail_node(struct be_queue_info *q) | ||
| 59 | { | ||
| 60 | return q->dma_mem.va + q->tail * q->entry_size; | ||
| 61 | } | ||
| 62 | |||
| 63 | static inline void queue_head_inc(struct be_queue_info *q) | ||
| 64 | { | ||
| 65 | index_inc(&q->head, q->len); | ||
| 66 | } | ||
| 67 | |||
| 68 | static inline void queue_tail_inc(struct be_queue_info *q) | ||
| 69 | { | ||
| 70 | index_inc(&q->tail, q->len); | ||
| 71 | } | ||
| 72 | |||
| 73 | /*ISCSI */ | ||
| 74 | |||
| 75 | struct be_eq_obj { | ||
| 76 | struct be_queue_info q; | ||
| 77 | char desc[32]; | ||
| 78 | |||
| 79 | /* Adaptive interrupt coalescing (AIC) info */ | ||
| 80 | bool enable_aic; | ||
| 81 | u16 min_eqd; /* in usecs */ | ||
| 82 | u16 max_eqd; /* in usecs */ | ||
| 83 | u16 cur_eqd; /* in usecs */ | ||
| 84 | }; | ||
| 85 | |||
| 86 | struct be_mcc_obj { | ||
| 87 | struct be_queue_info *q; | ||
| 88 | struct be_queue_info *cq; | ||
| 89 | }; | ||
| 90 | |||
| 91 | struct be_ctrl_info { | ||
| 92 | u8 __iomem *csr; | ||
| 93 | u8 __iomem *db; /* Door Bell */ | ||
| 94 | u8 __iomem *pcicfg; /* PCI config space */ | ||
| 95 | struct pci_dev *pdev; | ||
| 96 | |||
| 97 | /* Mbox used for cmd request/response */ | ||
| 98 | spinlock_t mbox_lock; /* For serializing mbox cmds to BE card */ | ||
| 99 | struct be_dma_mem mbox_mem; | ||
| 100 | /* Mbox mem is adjusted to align to 16 bytes. The allocated addr | ||
| 101 | * is stored for freeing purpose */ | ||
| 102 | struct be_dma_mem mbox_mem_alloced; | ||
| 103 | |||
| 104 | /* MCC Rings */ | ||
| 105 | struct be_mcc_obj mcc_obj; | ||
| 106 | spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */ | ||
| 107 | spinlock_t mcc_cq_lock; | ||
| 108 | |||
| 109 | /* MCC Async callback */ | ||
| 110 | void (*async_cb) (void *adapter, bool link_up); | ||
| 111 | void *adapter_ctxt; | ||
| 112 | }; | ||
| 113 | |||
| 114 | #include "be_cmds.h" | ||
| 115 | |||
| 116 | #define PAGE_SHIFT_4K 12 | ||
| 117 | #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K) | ||
| 118 | |||
| 119 | /* Returns number of pages spanned by the data starting at the given addr */ | ||
| 120 | #define PAGES_4K_SPANNED(_address, size) \ | ||
| 121 | ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \ | ||
| 122 | (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K)) | ||
| 123 | |||
| 124 | /* Byte offset into the page corresponding to given address */ | ||
| 125 | #define OFFSET_IN_PAGE(addr) \ | ||
| 126 | ((size_t)(addr) & (PAGE_SIZE_4K-1)) | ||
| 127 | |||
| 128 | /* Returns bit offset within a DWORD of a bitfield */ | ||
| 129 | #define AMAP_BIT_OFFSET(_struct, field) \ | ||
| 130 | (((size_t)&(((_struct *)0)->field))%32) | ||
| 131 | |||
| 132 | /* Returns the bit mask of the field that is NOT shifted into location. */ | ||
| 133 | static inline u32 amap_mask(u32 bitsize) | ||
| 134 | { | ||
| 135 | return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1); | ||
| 136 | } | ||
| 137 | |||
| 138 | static inline void amap_set(void *ptr, u32 dw_offset, u32 mask, | ||
| 139 | u32 offset, u32 value) | ||
| 140 | { | ||
| 141 | u32 *dw = (u32 *) ptr + dw_offset; | ||
| 142 | *dw &= ~(mask << offset); | ||
| 143 | *dw |= (mask & value) << offset; | ||
| 144 | } | ||
| 145 | |||
| 146 | #define AMAP_SET_BITS(_struct, field, ptr, val) \ | ||
| 147 | amap_set(ptr, \ | ||
| 148 | offsetof(_struct, field)/32, \ | ||
| 149 | amap_mask(sizeof(((_struct *)0)->field)), \ | ||
| 150 | AMAP_BIT_OFFSET(_struct, field), \ | ||
| 151 | val) | ||
| 152 | |||
| 153 | static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset) | ||
| 154 | { | ||
| 155 | u32 *dw = ptr; | ||
| 156 | return mask & (*(dw + dw_offset) >> offset); | ||
| 157 | } | ||
| 158 | |||
| 159 | #define AMAP_GET_BITS(_struct, field, ptr) \ | ||
| 160 | amap_get(ptr, \ | ||
| 161 | offsetof(_struct, field)/32, \ | ||
| 162 | amap_mask(sizeof(((_struct *)0)->field)), \ | ||
| 163 | AMAP_BIT_OFFSET(_struct, field)) | ||
| 164 | |||
| 165 | #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len) | ||
| 166 | #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len) | ||
| 167 | static inline void swap_dws(void *wrb, int len) | ||
| 168 | { | ||
| 169 | #ifdef __BIG_ENDIAN | ||
| 170 | u32 *dw = wrb; | ||
| 171 | WARN_ON(len % 4); | ||
| 172 | do { | ||
| 173 | *dw = cpu_to_le32(*dw); | ||
| 174 | dw++; | ||
| 175 | len -= 4; | ||
| 176 | } while (len); | ||
| 177 | #endif /* __BIG_ENDIAN */ | ||
| 178 | } | ||
| 179 | |||
| 180 | extern void beiscsi_cq_notify(struct be_ctrl_info *ctrl, u16 qid, bool arm, | ||
| 181 | u16 num_popped); | ||
| 182 | |||
| 183 | #endif /* BEISCSI_H */ | ||
