Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1 | /** |
Jayamohan Kallickal | 533c165 | 2013-04-05 20:38:34 -0700 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2013 Emulex |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 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: |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 12 | * |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #ifndef BEISCSI_H |
| 19 | #define BEISCSI_H |
| 20 | |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/if_vlan.h> |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 23 | #include <linux/blk-iopoll.h> |
| 24 | #define FW_VER_LEN 32 |
| 25 | #define MCC_Q_LEN 128 |
| 26 | #define MCC_CQ_LEN 256 |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 27 | #define MAX_MCC_CMD 16 |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 28 | /* BladeEngine Generation numbers */ |
| 29 | #define BE_GEN2 2 |
| 30 | #define BE_GEN3 3 |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 31 | #define BE_GEN4 4 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 32 | struct be_dma_mem { |
| 33 | void *va; |
| 34 | dma_addr_t dma; |
| 35 | u32 size; |
| 36 | }; |
| 37 | |
| 38 | struct be_queue_info { |
| 39 | struct be_dma_mem dma_mem; |
| 40 | u16 len; |
| 41 | u16 entry_size; /* Size of an element in the queue */ |
| 42 | u16 id; |
| 43 | u16 tail, head; |
| 44 | bool created; |
| 45 | atomic_t used; /* Number of valid elements in the queue */ |
| 46 | }; |
| 47 | |
| 48 | static inline u32 MODULO(u16 val, u16 limit) |
| 49 | { |
| 50 | WARN_ON(limit & (limit - 1)); |
| 51 | return val & (limit - 1); |
| 52 | } |
| 53 | |
| 54 | static inline void index_inc(u16 *index, u16 limit) |
| 55 | { |
| 56 | *index = MODULO((*index + 1), limit); |
| 57 | } |
| 58 | |
| 59 | static inline void *queue_head_node(struct be_queue_info *q) |
| 60 | { |
| 61 | return q->dma_mem.va + q->head * q->entry_size; |
| 62 | } |
| 63 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 64 | static inline void *queue_get_wrb(struct be_queue_info *q, unsigned int wrb_num) |
| 65 | { |
| 66 | return q->dma_mem.va + wrb_num * q->entry_size; |
| 67 | } |
| 68 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 69 | static inline void *queue_tail_node(struct be_queue_info *q) |
| 70 | { |
| 71 | return q->dma_mem.va + q->tail * q->entry_size; |
| 72 | } |
| 73 | |
| 74 | static inline void queue_head_inc(struct be_queue_info *q) |
| 75 | { |
| 76 | index_inc(&q->head, q->len); |
| 77 | } |
| 78 | |
| 79 | static inline void queue_tail_inc(struct be_queue_info *q) |
| 80 | { |
| 81 | index_inc(&q->tail, q->len); |
| 82 | } |
| 83 | |
| 84 | /*ISCSI */ |
| 85 | |
| 86 | struct be_eq_obj { |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 87 | bool todo_mcc_cq; |
| 88 | bool todo_cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 89 | struct be_queue_info q; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 90 | struct beiscsi_hba *phba; |
| 91 | struct be_queue_info *cq; |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 92 | struct work_struct work_cqs; /* Work Item */ |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 93 | struct blk_iopoll iopoll; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct be_mcc_obj { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 97 | struct be_queue_info q; |
| 98 | struct be_queue_info cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 99 | }; |
| 100 | |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 101 | struct beiscsi_mcc_tag_state { |
| 102 | #define MCC_TAG_STATE_COMPLETED 0x00 |
| 103 | #define MCC_TAG_STATE_RUNNING 0x01 |
| 104 | #define MCC_TAG_STATE_TIMEOUT 0x02 |
| 105 | uint8_t tag_state; |
| 106 | struct be_dma_mem tag_mem_state; |
| 107 | }; |
| 108 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 109 | struct be_ctrl_info { |
| 110 | u8 __iomem *csr; |
| 111 | u8 __iomem *db; /* Door Bell */ |
| 112 | u8 __iomem *pcicfg; /* PCI config space */ |
| 113 | struct pci_dev *pdev; |
| 114 | |
| 115 | /* Mbox used for cmd request/response */ |
| 116 | spinlock_t mbox_lock; /* For serializing mbox cmds to BE card */ |
| 117 | struct be_dma_mem mbox_mem; |
| 118 | /* Mbox mem is adjusted to align to 16 bytes. The allocated addr |
| 119 | * is stored for freeing purpose */ |
| 120 | struct be_dma_mem mbox_mem_alloced; |
| 121 | |
| 122 | /* MCC Rings */ |
| 123 | struct be_mcc_obj mcc_obj; |
| 124 | spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */ |
| 125 | spinlock_t mcc_cq_lock; |
| 126 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 127 | wait_queue_head_t mcc_wait[MAX_MCC_CMD + 1]; |
| 128 | unsigned int mcc_tag[MAX_MCC_CMD]; |
| 129 | unsigned int mcc_numtag[MAX_MCC_CMD + 1]; |
| 130 | unsigned short mcc_alloc_index; |
| 131 | unsigned short mcc_free_index; |
| 132 | unsigned int mcc_tag_available; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 133 | |
| 134 | struct beiscsi_mcc_tag_state ptag_state[MAX_MCC_CMD + 1]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | #include "be_cmds.h" |
| 138 | |
| 139 | #define PAGE_SHIFT_4K 12 |
| 140 | #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K) |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 141 | #define mcc_timeout 120000 /* 12s timeout */ |
Jayamohan Kallickal | 9343be7 | 2014-01-29 02:16:43 -0500 | [diff] [blame] | 142 | #define BEISCSI_LOGOUT_SYNC_DELAY 250 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 143 | |
| 144 | /* Returns number of pages spanned by the data starting at the given addr */ |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 145 | #define PAGES_4K_SPANNED(_address, size) \ |
| 146 | ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 147 | (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K)) |
| 148 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 149 | /* Returns bit offset within a DWORD of a bitfield */ |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 150 | #define AMAP_BIT_OFFSET(_struct, field) \ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 151 | (((size_t)&(((_struct *)0)->field))%32) |
| 152 | |
| 153 | /* Returns the bit mask of the field that is NOT shifted into location. */ |
| 154 | static inline u32 amap_mask(u32 bitsize) |
| 155 | { |
| 156 | return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1); |
| 157 | } |
| 158 | |
| 159 | static inline void amap_set(void *ptr, u32 dw_offset, u32 mask, |
| 160 | u32 offset, u32 value) |
| 161 | { |
| 162 | u32 *dw = (u32 *) ptr + dw_offset; |
| 163 | *dw &= ~(mask << offset); |
| 164 | *dw |= (mask & value) << offset; |
| 165 | } |
| 166 | |
| 167 | #define AMAP_SET_BITS(_struct, field, ptr, val) \ |
| 168 | amap_set(ptr, \ |
| 169 | offsetof(_struct, field)/32, \ |
| 170 | amap_mask(sizeof(((_struct *)0)->field)), \ |
| 171 | AMAP_BIT_OFFSET(_struct, field), \ |
| 172 | val) |
| 173 | |
| 174 | static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset) |
| 175 | { |
| 176 | u32 *dw = ptr; |
| 177 | return mask & (*(dw + dw_offset) >> offset); |
| 178 | } |
| 179 | |
| 180 | #define AMAP_GET_BITS(_struct, field, ptr) \ |
| 181 | amap_get(ptr, \ |
| 182 | offsetof(_struct, field)/32, \ |
| 183 | amap_mask(sizeof(((_struct *)0)->field)), \ |
| 184 | AMAP_BIT_OFFSET(_struct, field)) |
| 185 | |
| 186 | #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len) |
| 187 | #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len) |
| 188 | static inline void swap_dws(void *wrb, int len) |
| 189 | { |
| 190 | #ifdef __BIG_ENDIAN |
| 191 | u32 *dw = wrb; |
| 192 | WARN_ON(len % 4); |
| 193 | do { |
| 194 | *dw = cpu_to_le32(*dw); |
| 195 | dw++; |
| 196 | len -= 4; |
| 197 | } while (len); |
| 198 | #endif /* __BIG_ENDIAN */ |
| 199 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 200 | #endif /* BEISCSI_H */ |