blob: 3861cf44dc1586cd60b11fa54e88896597a4f325 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
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>
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053023#include <linux/blk-iopoll.h>
24#define FW_VER_LEN 32
25#define MCC_Q_LEN 128
26#define MCC_CQ_LEN 256
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +053027#define MAX_MCC_CMD 16
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053028
29struct be_dma_mem {
30 void *va;
31 dma_addr_t dma;
32 u32 size;
33};
34
35struct be_queue_info {
36 struct be_dma_mem dma_mem;
37 u16 len;
38 u16 entry_size; /* Size of an element in the queue */
39 u16 id;
40 u16 tail, head;
41 bool created;
42 atomic_t used; /* Number of valid elements in the queue */
43};
44
45static inline u32 MODULO(u16 val, u16 limit)
46{
47 WARN_ON(limit & (limit - 1));
48 return val & (limit - 1);
49}
50
51static inline void index_inc(u16 *index, u16 limit)
52{
53 *index = MODULO((*index + 1), limit);
54}
55
56static inline void *queue_head_node(struct be_queue_info *q)
57{
58 return q->dma_mem.va + q->head * q->entry_size;
59}
60
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +053061static inline void *queue_get_wrb(struct be_queue_info *q, unsigned int wrb_num)
62{
63 return q->dma_mem.va + wrb_num * q->entry_size;
64}
65
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053066static inline void *queue_tail_node(struct be_queue_info *q)
67{
68 return q->dma_mem.va + q->tail * q->entry_size;
69}
70
71static inline void queue_head_inc(struct be_queue_info *q)
72{
73 index_inc(&q->head, q->len);
74}
75
76static inline void queue_tail_inc(struct be_queue_info *q)
77{
78 index_inc(&q->tail, q->len);
79}
80
81/*ISCSI */
82
83struct be_eq_obj {
84 struct be_queue_info q;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053085 struct beiscsi_hba *phba;
86 struct be_queue_info *cq;
87 struct blk_iopoll iopoll;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053088};
89
90struct be_mcc_obj {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053091 struct be_queue_info q;
92 struct be_queue_info cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053093};
94
95struct be_ctrl_info {
96 u8 __iomem *csr;
97 u8 __iomem *db; /* Door Bell */
98 u8 __iomem *pcicfg; /* PCI config space */
99 struct pci_dev *pdev;
100
101 /* Mbox used for cmd request/response */
102 spinlock_t mbox_lock; /* For serializing mbox cmds to BE card */
103 struct be_dma_mem mbox_mem;
104 /* Mbox mem is adjusted to align to 16 bytes. The allocated addr
105 * is stored for freeing purpose */
106 struct be_dma_mem mbox_mem_alloced;
107
108 /* MCC Rings */
109 struct be_mcc_obj mcc_obj;
110 spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */
111 spinlock_t mcc_cq_lock;
112
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530113 wait_queue_head_t mcc_wait[MAX_MCC_CMD + 1];
114 unsigned int mcc_tag[MAX_MCC_CMD];
115 unsigned int mcc_numtag[MAX_MCC_CMD + 1];
116 unsigned short mcc_alloc_index;
117 unsigned short mcc_free_index;
118 unsigned int mcc_tag_available;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530119};
120
121#include "be_cmds.h"
122
123#define PAGE_SHIFT_4K 12
124#define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530125#define mcc_timeout 120000 /* 5s timeout */
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530126
127/* Returns number of pages spanned by the data starting at the given addr */
128#define PAGES_4K_SPANNED(_address, size) \
129 ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \
130 (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K))
131
132/* Byte offset into the page corresponding to given address */
133#define OFFSET_IN_PAGE(addr) \
134 ((size_t)(addr) & (PAGE_SIZE_4K-1))
135
136/* Returns bit offset within a DWORD of a bitfield */
137#define AMAP_BIT_OFFSET(_struct, field) \
138 (((size_t)&(((_struct *)0)->field))%32)
139
140/* Returns the bit mask of the field that is NOT shifted into location. */
141static inline u32 amap_mask(u32 bitsize)
142{
143 return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1);
144}
145
146static inline void amap_set(void *ptr, u32 dw_offset, u32 mask,
147 u32 offset, u32 value)
148{
149 u32 *dw = (u32 *) ptr + dw_offset;
150 *dw &= ~(mask << offset);
151 *dw |= (mask & value) << offset;
152}
153
154#define AMAP_SET_BITS(_struct, field, ptr, val) \
155 amap_set(ptr, \
156 offsetof(_struct, field)/32, \
157 amap_mask(sizeof(((_struct *)0)->field)), \
158 AMAP_BIT_OFFSET(_struct, field), \
159 val)
160
161static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
162{
163 u32 *dw = ptr;
164 return mask & (*(dw + dw_offset) >> offset);
165}
166
167#define AMAP_GET_BITS(_struct, field, ptr) \
168 amap_get(ptr, \
169 offsetof(_struct, field)/32, \
170 amap_mask(sizeof(((_struct *)0)->field)), \
171 AMAP_BIT_OFFSET(_struct, field))
172
173#define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
174#define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len)
175static inline void swap_dws(void *wrb, int len)
176{
177#ifdef __BIG_ENDIAN
178 u32 *dw = wrb;
179 WARN_ON(len % 4);
180 do {
181 *dw = cpu_to_le32(*dw);
182 dw++;
183 len -= 4;
184 } while (len);
185#endif /* __BIG_ENDIAN */
186}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530187#endif /* BEISCSI_H */