2 * Copyright 2017 Broadcom. All Rights Reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
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.
10 * Contact Information:
11 * linux-drivers@broadcom.com
18 #include <linux/pci.h>
19 #include <linux/if_vlan.h>
20 #include <linux/irq_poll.h>
23 #define MCC_CQ_LEN 256
24 #define MAX_MCC_CMD 16
25 /* BladeEngine Generation numbers */
35 struct be_queue_info
{
36 struct be_dma_mem dma_mem
;
38 u16 entry_size
; /* Size of an element in the queue */
42 u16 used
; /* Number of valid elements in the queue */
45 static inline u32
MODULO(u16 val
, u16 limit
)
47 WARN_ON(limit
& (limit
- 1));
48 return val
& (limit
- 1);
51 static inline void index_inc(u16
*index
, u16 limit
)
53 *index
= MODULO((*index
+ 1), limit
);
56 static inline void *queue_head_node(struct be_queue_info
*q
)
58 return q
->dma_mem
.va
+ q
->head
* q
->entry_size
;
61 static inline void *queue_get_wrb(struct be_queue_info
*q
, unsigned int wrb_num
)
63 return q
->dma_mem
.va
+ wrb_num
* q
->entry_size
;
66 static inline void *queue_tail_node(struct be_queue_info
*q
)
68 return q
->dma_mem
.va
+ q
->tail
* q
->entry_size
;
71 static inline void queue_head_inc(struct be_queue_info
*q
)
73 index_inc(&q
->head
, q
->len
);
76 static inline void queue_tail_inc(struct be_queue_info
*q
)
78 index_inc(&q
->tail
, q
->len
);
83 struct be_aic_obj
{ /* Adaptive interrupt coalescing (AIC) info */
84 unsigned long jiffies
;
85 u32 eq_prev
; /* Used to calculate eqe */
87 #define BEISCSI_EQ_DELAY_MIN 0
88 #define BEISCSI_EQ_DELAY_DEF 32
89 #define BEISCSI_EQ_DELAY_MAX 128
94 struct be_queue_info q
;
95 struct beiscsi_hba
*phba
;
96 struct be_queue_info
*cq
;
97 struct work_struct mcc_work
; /* Work Item */
98 struct irq_poll iopoll
;
102 struct be_queue_info q
;
103 struct be_queue_info cq
;
106 struct beiscsi_mcc_tag_state
{
107 unsigned long tag_state
;
108 #define MCC_TAG_STATE_RUNNING 0
109 #define MCC_TAG_STATE_TIMEOUT 1
110 #define MCC_TAG_STATE_ASYNC 2
111 #define MCC_TAG_STATE_IGNORE 3
112 void (*cbfn
)(struct beiscsi_hba
*, unsigned int);
113 struct be_dma_mem tag_mem_state
;
116 struct be_ctrl_info
{
118 u8 __iomem
*db
; /* Door Bell */
119 u8 __iomem
*pcicfg
; /* PCI config space */
120 struct pci_dev
*pdev
;
122 /* Mbox used for cmd request/response */
123 struct mutex mbox_lock
; /* For serializing mbox cmds to BE card */
124 struct be_dma_mem mbox_mem
;
125 /* Mbox mem is adjusted to align to 16 bytes. The allocated addr
126 * is stored for freeing purpose */
127 struct be_dma_mem mbox_mem_alloced
;
130 struct be_mcc_obj mcc_obj
;
131 spinlock_t mcc_lock
; /* For serializing mcc cmds to BE card */
133 wait_queue_head_t mcc_wait
[MAX_MCC_CMD
+ 1];
134 unsigned int mcc_tag
[MAX_MCC_CMD
];
135 unsigned int mcc_tag_status
[MAX_MCC_CMD
+ 1];
136 unsigned short mcc_alloc_index
;
137 unsigned short mcc_free_index
;
138 unsigned int mcc_tag_available
;
140 struct beiscsi_mcc_tag_state ptag_state
[MAX_MCC_CMD
+ 1];
145 /* WRB index mask for MCC_Q_LEN queue entries */
146 #define MCC_Q_WRB_IDX_MASK CQE_STATUS_WRB_MASK
147 #define MCC_Q_WRB_IDX_SHIFT CQE_STATUS_WRB_SHIFT
148 /* TAG is from 1...MAX_MCC_CMD, MASK includes MAX_MCC_CMD */
149 #define MCC_Q_CMD_TAG_MASK ((MAX_MCC_CMD << 1) - 1)
151 #define PAGE_SHIFT_4K 12
152 #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
154 /* Returns number of pages spanned by the data starting at the given addr */
155 #define PAGES_4K_SPANNED(_address, size) \
156 ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \
157 (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K))
159 /* Returns bit offset within a DWORD of a bitfield */
160 #define AMAP_BIT_OFFSET(_struct, field) \
161 (((size_t)&(((_struct *)0)->field))%32)
163 /* Returns the bit mask of the field that is NOT shifted into location. */
164 static inline u32
amap_mask(u32 bitsize
)
166 return (bitsize
== 32 ? 0xFFFFFFFF : (1 << bitsize
) - 1);
169 static inline void amap_set(void *ptr
, u32 dw_offset
, u32 mask
,
170 u32 offset
, u32 value
)
172 u32
*dw
= (u32
*) ptr
+ dw_offset
;
173 *dw
&= ~(mask
<< offset
);
174 *dw
|= (mask
& value
) << offset
;
177 #define AMAP_SET_BITS(_struct, field, ptr, val) \
179 offsetof(_struct, field)/32, \
180 amap_mask(sizeof(((_struct *)0)->field)), \
181 AMAP_BIT_OFFSET(_struct, field), \
184 static inline u32
amap_get(void *ptr
, u32 dw_offset
, u32 mask
, u32 offset
)
187 return mask
& (*(dw
+ dw_offset
) >> offset
);
190 #define AMAP_GET_BITS(_struct, field, ptr) \
192 offsetof(_struct, field)/32, \
193 amap_mask(sizeof(((_struct *)0)->field)), \
194 AMAP_BIT_OFFSET(_struct, field))
196 #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
197 #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len)
198 static inline void swap_dws(void *wrb
, int len
)
204 *dw
= cpu_to_le32(*dw
);
208 #endif /* __BIG_ENDIAN */
210 #endif /* BEISCSI_H */