bnx2x: Prepare device and initialize VF database
[pandora-kernel.git] / drivers / net / ethernet / broadcom / bnx2x / bnx2x_sriov.h
1 /* bnx2x_sriov.h: Broadcom Everest network driver.
2  *
3  * Copyright 2009-2012 Broadcom Corporation
4  *
5  * Unless you and Broadcom execute a separate written software license
6  * agreement governing use of this software, this software is licensed to you
7  * under the terms of the GNU General Public License version 2, available
8  * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
9  *
10  * Notwithstanding the above, under no circumstances may you combine this
11  * software in any way with any other Broadcom software provided under a
12  * license other than the GPL, without Broadcom's express prior written
13  * consent.
14  *
15  * Maintained by: Eilon Greenstein <eilong@broadcom.com>
16  * Written by: Shmulik Ravid <shmulikr@broadcom.com>
17  *             Ariel Elior <ariele@broadcom.com>
18  */
19 #ifndef BNX2X_SRIOV_H
20 #define BNX2X_SRIOV_H
21
22 /* The bnx2x device structure holds vfdb structure described below.
23  * The VF array is indexed by the relative vfid.
24  */
25 struct bnx2x_sriov {
26         u32 first_vf_in_pf;
27
28         /* standard SRIOV capability fields, mostly for debugging */
29         int pos;                /* capability position */
30         int nres;               /* number of resources */
31         u32 cap;                /* SR-IOV Capabilities */
32         u16 ctrl;               /* SR-IOV Control */
33         u16 total;              /* total VFs associated with the PF */
34         u16 initial;            /* initial VFs associated with the PF */
35         u16 nr_virtfn;          /* number of VFs available */
36         u16 offset;             /* first VF Routing ID offset */
37         u16 stride;             /* following VF stride */
38         u32 pgsz;               /* page size for BAR alignment */
39         u8 link;                /* Function Dependency Link */
40 };
41
42 /* bars */
43 struct bnx2x_vf_bar {
44         u64 bar;
45         u32 size;
46 };
47
48 /* vf queue (used both for rx or tx) */
49 struct bnx2x_vf_queue {
50         struct eth_context              *cxt;
51
52         /* MACs object */
53         struct bnx2x_vlan_mac_obj       mac_obj;
54
55         /* VLANs object */
56         struct bnx2x_vlan_mac_obj       vlan_obj;
57         atomic_t vlan_count;            /* 0 means vlan-0 is set  ~ untagged */
58
59         /* Queue Slow-path State object */
60         struct bnx2x_queue_sp_obj       sp_obj;
61
62         u32 cid;
63         u16 index;
64         u16 sb_idx;
65 };
66
67 /* struct bnx2x_vfop_qctor_params - prepare queue construction parameters:
68  * q-init, q-setup and SB index
69  */
70 struct bnx2x_vfop_qctor_params {
71         struct bnx2x_queue_state_params         qstate;
72         struct bnx2x_queue_setup_params         prep_qsetup;
73 };
74
75 /* VFOP parameters (one copy per VF) */
76 union bnx2x_vfop_params {
77         struct bnx2x_vlan_mac_ramrod_params     vlan_mac;
78         struct bnx2x_rx_mode_ramrod_params      rx_mode;
79         struct bnx2x_mcast_ramrod_params        mcast;
80         struct bnx2x_config_rss_params          rss;
81         struct bnx2x_vfop_qctor_params          qctor;
82 };
83
84 /* forward */
85 struct bnx2x_virtf;
86 /* vf context */
87 struct bnx2x_virtf {
88         u16 cfg_flags;
89 #define VF_CFG_STATS            0x0001
90 #define VF_CFG_FW_FC            0x0002
91 #define VF_CFG_TPA              0x0004
92 #define VF_CFG_INT_SIMD         0x0008
93 #define VF_CACHE_LINE           0x0010
94
95         u8 state;
96 #define VF_FREE         0       /* VF ready to be acquired holds no resc */
97 #define VF_ACQUIRED     1       /* VF aquired, but not initalized */
98 #define VF_ENABLED      2       /* VF Enabled */
99 #define VF_RESET        3       /* VF FLR'd, pending cleanup */
100
101         /* non 0 during flr cleanup */
102         u8 flr_clnup_stage;
103 #define VF_FLR_CLN      1       /* reclaim resources and do 'final cleanup'
104                                  * sans the end-wait
105                                  */
106 #define VF_FLR_ACK      2       /* ACK flr notification */
107 #define VF_FLR_EPILOG   3       /* wait for VF remnants to dissipate in the HW
108                                  * ~ final cleanup' end wait
109                                  */
110
111         /* dma */
112         dma_addr_t fw_stat_map;         /* valid iff VF_CFG_STATS */
113         dma_addr_t spq_map;
114         dma_addr_t bulletin_map;
115
116         /* Allocated resources counters. Before the VF is acquired, the
117          * counters hold the following values:
118          *
119          * - xxq_count = 0 as the queues memory is not allocated yet.
120          *
121          * - sb_count  = The number of status blocks configured for this VF in
122          *               the IGU CAM. Initially read during probe.
123          *
124          * - xx_rules_count = The number of rules statically and equally
125          *                    allocated for each VF, during PF load.
126          */
127         struct vf_pf_resc_request       alloc_resc;
128 #define vf_rxq_count(vf)                ((vf)->alloc_resc.num_rxqs)
129 #define vf_txq_count(vf)                ((vf)->alloc_resc.num_txqs)
130 #define vf_sb_count(vf)                 ((vf)->alloc_resc.num_sbs)
131 #define vf_mac_rules_cnt(vf)            ((vf)->alloc_resc.num_mac_filters)
132 #define vf_vlan_rules_cnt(vf)           ((vf)->alloc_resc.num_vlan_filters)
133 #define vf_mc_rules_cnt(vf)             ((vf)->alloc_resc.num_mc_filters)
134
135         u8 sb_count;    /* actual number of SBs */
136         u8 igu_base_id; /* base igu status block id */
137
138         struct bnx2x_vf_queue   *vfqs;
139 #define bnx2x_vfq(vf, nr, var)  ((vf)->vfqs[(nr)].var)
140
141         u8 index;       /* index in the vf array */
142         u8 abs_vfid;
143         u8 sp_cl_id;
144         u32 error;      /* 0 means all's-well */
145
146         /* BDF */
147         unsigned int bus;
148         unsigned int devfn;
149
150         /* bars */
151         struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
152
153         /* set-mac ramrod state 1-pending, 0-done */
154         unsigned long   filter_state;
155
156         /* leading rss client id ~~ the client id of the first rxq, must be
157          * set for each txq.
158          */
159         int leading_rss;
160
161         /* MCAST object */
162         struct bnx2x_mcast_obj          mcast_obj;
163
164         /* RSS configuration object */
165         struct bnx2x_rss_config_obj     rss_conf_obj;
166
167         /* slow-path operations */
168         atomic_t                        op_in_progress;
169         int                             op_rc;
170         bool                            op_wait_blocking;
171         struct list_head                op_list_head;
172         union bnx2x_vfop_params         op_params;
173         struct mutex                    op_mutex; /* one vfop at a time mutex */
174         enum channel_tlvs               op_current;
175 };
176
177 #define BNX2X_NR_VIRTFN(bp)     ((bp)->vfdb->sriov.nr_virtfn)
178
179 #define for_each_vf(bp, var) \
180                 for ((var) = 0; (var) < BNX2X_NR_VIRTFN(bp); (var)++)
181
182 #define HW_VF_HANDLE(bp, abs_vfid) \
183         (u16)(BP_ABS_FUNC((bp)) | (1<<3) |  ((u16)(abs_vfid) << 4))
184
185 #define FW_PF_MAX_HANDLE        8
186
187 #define FW_VF_HANDLE(abs_vfid)  \
188         (abs_vfid + FW_PF_MAX_HANDLE)
189
190 /* VF mail box (aka vf-pf channel) */
191
192 /* a container for the bi-directional vf<-->pf messages.
193  *  The actual response will be placed according to the offset parameter
194  *  provided in the request
195  */
196
197 #define MBX_MSG_ALIGN   8
198 #define MBX_MSG_ALIGNED_SIZE    (roundup(sizeof(struct bnx2x_vf_mbx_msg), \
199                                 MBX_MSG_ALIGN))
200
201 struct bnx2x_vf_mbx_msg {
202         union vfpf_tlvs req;
203         union pfvf_tlvs resp;
204 };
205
206 struct bnx2x_vf_mbx {
207         struct bnx2x_vf_mbx_msg *msg;
208         dma_addr_t msg_mapping;
209
210         /* VF GPA address */
211         u32 vf_addr_lo;
212         u32 vf_addr_hi;
213
214         struct vfpf_first_tlv first_tlv;        /* saved VF request header */
215
216         u8 flags;
217 #define VF_MSG_INPROCESS        0x1     /* failsafe - the FW should prevent
218                                          * more then one pending msg
219                                          */
220 };
221
222 struct bnx2x_vf_sp {
223         union {
224                 struct eth_classify_rules_ramrod_data   e2;
225         } mac_rdata;
226
227         union {
228                 struct eth_classify_rules_ramrod_data   e2;
229         } vlan_rdata;
230
231         union {
232                 struct eth_filter_rules_ramrod_data     e2;
233         } rx_mode_rdata;
234
235         union {
236                 struct eth_multicast_rules_ramrod_data  e2;
237         } mcast_rdata;
238
239         union {
240                 struct client_init_ramrod_data  init_data;
241                 struct client_update_ramrod_data update_data;
242         } q_data;
243 };
244
245 struct hw_dma {
246         void *addr;
247         dma_addr_t mapping;
248         size_t size;
249 };
250
251 struct bnx2x_vfdb {
252 #define BP_VFDB(bp)             ((bp)->vfdb)
253         /* vf array */
254         struct bnx2x_virtf      *vfs;
255 #define BP_VF(bp, idx)          (&((bp)->vfdb->vfs[(idx)]))
256 #define bnx2x_vf(bp, idx, var)  ((bp)->vfdb->vfs[(idx)].var)
257
258         /* queue array - for all vfs */
259         struct bnx2x_vf_queue *vfqs;
260
261         /* vf HW contexts */
262         struct hw_dma           context[BNX2X_VF_CIDS/ILT_PAGE_CIDS];
263 #define BP_VF_CXT_PAGE(bp, i)   (&(bp)->vfdb->context[(i)])
264
265         /* SR-IOV information */
266         struct bnx2x_sriov      sriov;
267         struct hw_dma           mbx_dma;
268 #define BP_VF_MBX_DMA(bp)       (&((bp)->vfdb->mbx_dma))
269         struct bnx2x_vf_mbx     mbxs[BNX2X_MAX_NUM_OF_VFS];
270 #define BP_VF_MBX(bp, vfid)     (&((bp)->vfdb->mbxs[(vfid)]))
271
272         struct hw_dma           sp_dma;
273 #define bnx2x_vf_sp(bp, vf, field) ((bp)->vfdb->sp_dma.addr +           \
274                 (vf)->index * sizeof(struct bnx2x_vf_sp) +              \
275                 offsetof(struct bnx2x_vf_sp, field))
276 #define bnx2x_vf_sp_map(bp, vf, field) ((bp)->vfdb->sp_dma.mapping +    \
277                 (vf)->index * sizeof(struct bnx2x_vf_sp) +              \
278                 offsetof(struct bnx2x_vf_sp, field))
279
280 #define FLRD_VFS_DWORDS (BNX2X_MAX_NUM_OF_VFS / 32)
281         u32 flrd_vfs[FLRD_VFS_DWORDS];
282 };
283
284 static inline u8 vf_igu_sb(struct bnx2x_virtf *vf, u16 sb_idx)
285 {
286         return vf->igu_base_id + sb_idx;
287 }
288
289 /* global iov routines */
290 int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line);
291 int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, int num_vfs_param);
292 void bnx2x_iov_remove_one(struct bnx2x *bp);
293 void bnx2x_iov_free_mem(struct bnx2x *bp);
294 int bnx2x_iov_alloc_mem(struct bnx2x *bp);
295 int bnx2x_iov_nic_init(struct bnx2x *bp);
296 void bnx2x_iov_init_dq(struct bnx2x *bp);
297 void bnx2x_iov_init_dmae(struct bnx2x *bp);
298 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid);
299 int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid);
300 /* VF FLR helpers */
301 int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid);
302 void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid);
303 void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
304                    u16 length);
305 void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
306                      u16 type, u16 length);
307 void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list);
308 #endif /* bnx2x_sriov.h */