blob: ba8b95d016b0593a85b511b6d7a888e811838c00 [file] [log] [blame]
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +00001/* bnx2x_vfpf.c: 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
20#include "bnx2x.h"
21#include "bnx2x_sriov.h"
Ariel Eliorb93288d2013-01-01 05:22:35 +000022#include <linux/crc32.h>
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +000023
24/* place a given tlv on the tlv buffer at a given offset */
25void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
26 u16 length)
27{
28 struct channel_tlv *tl =
29 (struct channel_tlv *)(tlvs_list + offset);
30
31 tl->type = type;
32 tl->length = length;
33}
34
35/* Clear the mailbox and init the header of the first tlv */
36void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
37 u16 type, u16 length)
38{
39 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
40 type);
41
42 /* Clear mailbox */
43 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
44
45 /* init type and length */
46 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
47
48 /* init first tlv header */
49 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
50}
51
52/* list the types and lengths of the tlvs on the buffer */
53void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
54{
55 int i = 1;
56 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
57
58 while (tlv->type != CHANNEL_TLV_LIST_END) {
59 /* output tlv */
60 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
61 tlv->type, tlv->length);
62
63 /* advance to next tlv */
64 tlvs_list += tlv->length;
65
66 /* cast general tlv list pointer to channel tlv header*/
67 tlv = (struct channel_tlv *)tlvs_list;
68
69 i++;
70
71 /* break condition for this loop */
72 if (i > MAX_TLVS_IN_LIST) {
73 WARN(true, "corrupt tlvs");
74 return;
75 }
76 }
77
78 /* output last tlv */
79 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
80 tlv->type, tlv->length);
81}
Ariel Eliorb56e9672013-01-01 05:22:32 +000082
Ariel Eliorfd1fc792013-01-01 05:22:33 +000083/* test whether we support a tlv type */
84bool bnx2x_tlv_supported(u16 tlvtype)
85{
86 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
87}
88
89static inline int bnx2x_pfvf_status_codes(int rc)
90{
91 switch (rc) {
92 case 0:
93 return PFVF_STATUS_SUCCESS;
94 case -ENOMEM:
95 return PFVF_STATUS_NO_RESOURCE;
96 default:
97 return PFVF_STATUS_FAILURE;
98 }
99}
100
Ariel Eliorb56e9672013-01-01 05:22:32 +0000101/* General service functions */
102static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
103{
104 u32 addr = BAR_CSTRORM_INTMEM +
105 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
106
107 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
108}
109
110static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
111{
112 u32 addr = BAR_CSTRORM_INTMEM +
113 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
114
115 REG_WR8(bp, addr, 1);
116}
117
118static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
119{
120 int i;
121
122 for_each_vf(bp, i)
123 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
124}
125
126/* enable vf_pf mailbox (aka vf-pf-chanell) */
127void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
128{
129 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
130
131 /* enable the mailbox in the FW */
132 storm_memset_vf_mbx_ack(bp, abs_vfid);
133 storm_memset_vf_mbx_valid(bp, abs_vfid);
134
135 /* enable the VF access to the mailbox */
136 bnx2x_vf_enable_access(bp, abs_vfid);
137}
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000138
139/* this works only on !E1h */
140static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
141 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
142 u32 vf_addr_lo, u32 len32)
143{
144 struct dmae_command dmae;
145
146 if (CHIP_IS_E1x(bp)) {
147 BNX2X_ERR("Chip revision does not support VFs\n");
148 return DMAE_NOT_RDY;
149 }
150
151 if (!bp->dmae_ready) {
152 BNX2X_ERR("DMAE is not ready, can not copy\n");
153 return DMAE_NOT_RDY;
154 }
155
156 /* set opcode and fixed command fields */
157 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
158
159 if (from_vf) {
160 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
161 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
162 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
163
164 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
165
166 dmae.src_addr_lo = vf_addr_lo;
167 dmae.src_addr_hi = vf_addr_hi;
168 dmae.dst_addr_lo = U64_LO(pf_addr);
169 dmae.dst_addr_hi = U64_HI(pf_addr);
170 } else {
171 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
172 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
173 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
174
175 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
176
177 dmae.src_addr_lo = U64_LO(pf_addr);
178 dmae.src_addr_hi = U64_HI(pf_addr);
179 dmae.dst_addr_lo = vf_addr_lo;
180 dmae.dst_addr_hi = vf_addr_hi;
181 }
182 dmae.len = len32;
183 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
184
185 /* issue the command and wait for completion */
186 return bnx2x_issue_dmae_with_comp(bp, &dmae);
187}
188
Ariel Elior8ca5e172013-01-01 05:22:34 +0000189static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
190{
191 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
192 u64 vf_addr;
193 dma_addr_t pf_addr;
194 u16 length, type;
195 int rc;
196 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
197
198 /* prepare response */
199 type = mbx->first_tlv.tl.type;
200 length = type == CHANNEL_TLV_ACQUIRE ?
201 sizeof(struct pfvf_acquire_resp_tlv) :
202 sizeof(struct pfvf_general_resp_tlv);
203 bnx2x_add_tlv(bp, resp, 0, type, length);
204 resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
205 bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
206 sizeof(struct channel_list_end_tlv));
207 bnx2x_dp_tlv_list(bp, resp);
208 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
209 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
210
211 /* send response */
212 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
213 mbx->first_tlv.resp_msg_offset;
214 pf_addr = mbx->msg_mapping +
215 offsetof(struct bnx2x_vf_mbx_msg, resp);
216
217 /* copy the response body, if there is one, before the header, as the vf
218 * is sensitive to the header being written
219 */
220 if (resp->hdr.tl.length > sizeof(u64)) {
221 length = resp->hdr.tl.length - sizeof(u64);
222 vf_addr += sizeof(u64);
223 pf_addr += sizeof(u64);
224 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
225 U64_HI(vf_addr),
226 U64_LO(vf_addr),
227 length/4);
228 if (rc) {
229 BNX2X_ERR("Failed to copy response body to VF %d\n",
230 vf->abs_vfid);
Ariel Eliorf1929b02013-01-01 05:22:41 +0000231 goto mbx_error;
Ariel Elior8ca5e172013-01-01 05:22:34 +0000232 }
233 vf_addr -= sizeof(u64);
234 pf_addr -= sizeof(u64);
235 }
236
237 /* ack the FW */
238 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
239 mmiowb();
240
241 /* initiate dmae to send the response */
242 mbx->flags &= ~VF_MSG_INPROCESS;
243
244 /* copy the response header including status-done field,
245 * must be last dmae, must be after FW is acked
246 */
247 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
248 U64_HI(vf_addr),
249 U64_LO(vf_addr),
250 sizeof(u64)/4);
251
252 /* unlock channel mutex */
253 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
254
255 if (rc) {
256 BNX2X_ERR("Failed to copy response status to VF %d\n",
257 vf->abs_vfid);
Ariel Eliorf1929b02013-01-01 05:22:41 +0000258 goto mbx_error;
Ariel Elior8ca5e172013-01-01 05:22:34 +0000259 }
260 return;
Ariel Eliorf1929b02013-01-01 05:22:41 +0000261
262mbx_error:
263 bnx2x_vf_release(bp, vf, false); /* non blocking */
Ariel Elior8ca5e172013-01-01 05:22:34 +0000264}
265
266static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
267 struct bnx2x_vf_mbx *mbx, int vfop_status)
268{
269 int i;
270 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
271 struct pf_vf_resc *resc = &resp->resc;
272 u8 status = bnx2x_pfvf_status_codes(vfop_status);
273
274 memset(resp, 0, sizeof(*resp));
275
276 /* fill in pfdev info */
277 resp->pfdev_info.chip_num = bp->common.chip_id;
278 resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
279 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
280 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
281 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
282 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
283 sizeof(resp->pfdev_info.fw_ver));
284
285 if (status == PFVF_STATUS_NO_RESOURCE ||
286 status == PFVF_STATUS_SUCCESS) {
287 /* set resources numbers, if status equals NO_RESOURCE these
288 * are max possible numbers
289 */
290 resc->num_rxqs = vf_rxq_count(vf) ? :
291 bnx2x_vf_max_queue_cnt(bp, vf);
292 resc->num_txqs = vf_txq_count(vf) ? :
293 bnx2x_vf_max_queue_cnt(bp, vf);
294 resc->num_sbs = vf_sb_count(vf);
295 resc->num_mac_filters = vf_mac_rules_cnt(vf);
296 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
297 resc->num_mc_filters = 0;
298
299 if (status == PFVF_STATUS_SUCCESS) {
300 for_each_vfq(vf, i)
301 resc->hw_qid[i] =
302 vfq_qzone_id(vf, vfq_get(vf, i));
303
304 for_each_vf_sb(vf, i) {
305 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
306 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
307 }
308 }
309 }
310
311 DP(BNX2X_MSG_IOV, "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%x\n"
312 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
313 vf->abs_vfid,
314 resp->pfdev_info.chip_num,
315 resp->pfdev_info.db_size,
316 resp->pfdev_info.indices_per_sb,
317 resp->pfdev_info.pf_cap,
318 resc->num_rxqs,
319 resc->num_txqs,
320 resc->num_sbs,
321 resc->num_mac_filters,
322 resc->num_vlan_filters,
323 resc->num_mc_filters,
324 resp->pfdev_info.fw_ver);
325
326 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
327 for (i = 0; i < vf_rxq_count(vf); i++)
328 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
329 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
330 for (i = 0; i < vf_sb_count(vf); i++)
331 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
332 resc->hw_sbs[i].hw_sb_id,
333 resc->hw_sbs[i].sb_qid);
334 DP_CONT(BNX2X_MSG_IOV, "]\n");
335
336 /* send the response */
337 vf->op_rc = vfop_status;
338 bnx2x_vf_mbx_resp(bp, vf);
339}
340
341static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
342 struct bnx2x_vf_mbx *mbx)
343{
344 int rc;
345 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
346
347 /* log vfdef info */
348 DP(BNX2X_MSG_IOV,
349 "VF[%d] ACQUIRE: vfdev_info- vf_id %d, vf_os %d resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d\n",
350 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
351 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
352 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
353 acquire->resc_request.num_vlan_filters,
354 acquire->resc_request.num_mc_filters);
355
356 /* acquire the resources */
357 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
358
359 /* response */
360 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
361}
362
Ariel Eliorb93288d2013-01-01 05:22:35 +0000363static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
364 struct bnx2x_vf_mbx *mbx)
365{
366 struct vfpf_init_tlv *init = &mbx->msg->req.init;
367
368 /* record ghost addresses from vf message */
369 vf->spq_map = init->spq_addr;
370 vf->fw_stat_map = init->stats_addr;
371 vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
372
373 /* response */
374 bnx2x_vf_mbx_resp(bp, vf);
375}
376
Ariel Elior8db573b2013-01-01 05:22:37 +0000377/* convert MBX queue-flags to standard SP queue-flags */
378static void bnx2x_vf_mbx_set_q_flags(u32 mbx_q_flags,
379 unsigned long *sp_q_flags)
380{
381 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
382 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
383 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
384 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
385 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
386 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
387 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
388 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
389 if (mbx_q_flags & VFPF_QUEUE_FLG_OV)
390 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
391 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
392 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
393 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
394 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
395 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
396 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
397 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
398 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
399}
400
401static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
402 struct bnx2x_vf_mbx *mbx)
403{
404 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
405 struct bnx2x_vfop_cmd cmd = {
406 .done = bnx2x_vf_mbx_resp,
407 .block = false,
408 };
409
410 /* verify vf_qid */
411 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
412 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
413 setup_q->vf_qid, vf_rxq_count(vf));
414 vf->op_rc = -EINVAL;
415 goto response;
416 }
417
418 /* tx queues must be setup alongside rx queues thus if the rx queue
419 * is not marked as valid there's nothing to do.
420 */
421 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
422 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
423 unsigned long q_type = 0;
424
425 struct bnx2x_queue_init_params *init_p;
426 struct bnx2x_queue_setup_params *setup_p;
427
428 /* reinit the VF operation context */
429 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
430 setup_p = &vf->op_params.qctor.prep_qsetup;
431 init_p = &vf->op_params.qctor.qstate.params.init;
432
433 /* activate immediately */
434 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
435
436 if (setup_q->param_valid & VFPF_TXQ_VALID) {
437 struct bnx2x_txq_setup_params *txq_params =
438 &setup_p->txq_params;
439
440 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
441
442 /* save sb resource index */
443 q->sb_idx = setup_q->txq.vf_sb;
444
445 /* tx init */
446 init_p->tx.hc_rate = setup_q->txq.hc_rate;
447 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
448
449 bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
450 &init_p->tx.flags);
451
452 /* tx setup - flags */
453 bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
454 &setup_p->flags);
455
456 /* tx setup - general, nothing */
457
458 /* tx setup - tx */
459 txq_params->dscr_map = setup_q->txq.txq_addr;
460 txq_params->sb_cq_index = setup_q->txq.sb_index;
461 txq_params->traffic_type = setup_q->txq.traffic_type;
462
463 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
464 q->index, q->sb_idx);
465 }
466
467 if (setup_q->param_valid & VFPF_RXQ_VALID) {
468 struct bnx2x_rxq_setup_params *rxq_params =
469 &setup_p->rxq_params;
470
471 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
472
473 /* Note: there is no support for different SBs
474 * for TX and RX
475 */
476 q->sb_idx = setup_q->rxq.vf_sb;
477
478 /* rx init */
479 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
480 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
481 bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
482 &init_p->rx.flags);
483
484 /* rx setup - flags */
485 bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
486 &setup_p->flags);
487
488 /* rx setup - general */
489 setup_p->gen_params.mtu = setup_q->rxq.mtu;
490
491 /* rx setup - rx */
492 rxq_params->drop_flags = setup_q->rxq.drop_flags;
493 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
494 rxq_params->sge_map = setup_q->rxq.sge_addr;
495 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
496 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
497 rxq_params->buf_sz = setup_q->rxq.buf_sz;
498 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
499 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
500 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
501 rxq_params->cache_line_log =
502 setup_q->rxq.cache_line_log;
503 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
504
505 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
506 q->index, q->sb_idx);
507 }
508 /* complete the preparations */
509 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
510
511 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
512 if (vf->op_rc)
513 goto response;
514 return;
515 }
516response:
517 bnx2x_vf_mbx_resp(bp, vf);
518}
519
Ariel Elior954ea742013-01-01 05:22:38 +0000520enum bnx2x_vfop_filters_state {
521 BNX2X_VFOP_MBX_Q_FILTERS_MACS,
522 BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
523 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
524 BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
525 BNX2X_VFOP_MBX_Q_FILTERS_DONE
526};
527
528static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
529 struct bnx2x_virtf *vf,
530 struct vfpf_set_q_filters_tlv *tlv,
531 struct bnx2x_vfop_filters **pfl,
532 u32 type_flag)
533{
534 int i, j;
535 struct bnx2x_vfop_filters *fl = NULL;
536 size_t fsz;
537
538 fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
539 sizeof(struct bnx2x_vfop_filters);
540
541 fl = kzalloc(fsz, GFP_KERNEL);
542 if (!fl)
543 return -ENOMEM;
544
545 INIT_LIST_HEAD(&fl->head);
546
547 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
548 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
549
550 if ((msg_filter->flags & type_flag) != type_flag)
551 continue;
552 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
553 fl->filters[j].mac = msg_filter->mac;
554 fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
555 } else {
556 fl->filters[j].vid = msg_filter->vlan_tag;
557 fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
558 }
559 fl->filters[j].add =
560 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
561 true : false;
562 list_add_tail(&fl->filters[j++].link, &fl->head);
563 }
564 if (list_empty(&fl->head))
565 kfree(fl);
566 else
567 *pfl = fl;
568
569 return 0;
570}
571
572static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
573 struct vfpf_q_mac_vlan_filter *filter)
574{
575 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
576 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
577 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
578 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
579 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
580 DP_CONT(msglvl, "\n");
581}
582
583static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
584 struct vfpf_set_q_filters_tlv *filters)
585{
586 int i;
587
588 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
589 for (i = 0; i < filters->n_mac_vlan_filters; i++)
590 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
591 &filters->filters[i]);
592
593 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
594 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
595
596 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
597 for (i = 0; i < filters->n_multicast; i++)
598 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
599}
600
601#define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
602#define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
603
604static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
605{
606 int rc;
607
608 struct vfpf_set_q_filters_tlv *msg =
609 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
610
611 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
612 enum bnx2x_vfop_filters_state state = vfop->state;
613
614 struct bnx2x_vfop_cmd cmd = {
615 .done = bnx2x_vfop_mbx_qfilters,
616 .block = false,
617 };
618
619 DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
620
621 if (vfop->rc < 0)
622 goto op_err;
623
624 switch (state) {
625 case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
626 /* next state */
627 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
628
629 /* check for any vlan/mac changes */
630 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
631 /* build mac list */
632 struct bnx2x_vfop_filters *fl = NULL;
633
634 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
635 VFPF_MAC_FILTER);
636 if (vfop->rc)
637 goto op_err;
638
639 if (fl) {
640 /* set mac list */
641 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
642 msg->vf_qid,
643 false);
644 if (rc) {
645 vfop->rc = rc;
646 goto op_err;
647 }
648 return;
649 }
650 }
651 /* fall through */
652
653 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
654 /* next state */
655 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
656
657 /* check for any vlan/mac changes */
658 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
659 /* build vlan list */
660 struct bnx2x_vfop_filters *fl = NULL;
661
662 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
663 VFPF_VLAN_FILTER);
664 if (vfop->rc)
665 goto op_err;
666
667 if (fl) {
668 /* set vlan list */
669 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
670 msg->vf_qid,
671 false);
672 if (rc) {
673 vfop->rc = rc;
674 goto op_err;
675 }
676 return;
677 }
678 }
679 /* fall through */
680
681 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
682 /* next state */
683 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
684
685 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
686 unsigned long accept = 0;
687
688 /* covert VF-PF if mask to bnx2x accept flags */
689 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
690 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
691
692 if (msg->rx_mask &
693 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
694 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
695
696 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
697 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
698
699 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
700 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
701
702 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
703 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
704
705 /* A packet arriving the vf's mac should be accepted
706 * with any vlan
707 */
708 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
709
710 /* set rx-mode */
711 rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
712 msg->vf_qid, accept);
713 if (rc) {
714 vfop->rc = rc;
715 goto op_err;
716 }
717 return;
718 }
719 /* fall through */
720
721 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
722 /* next state */
723 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
724
725 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
726 /* set mcasts */
727 rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
728 msg->n_multicast, false);
729 if (rc) {
730 vfop->rc = rc;
731 goto op_err;
732 }
733 return;
734 }
735 /* fall through */
736op_done:
737 case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
738 bnx2x_vfop_end(bp, vf, vfop);
739 return;
740op_err:
741 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
742 vf->abs_vfid, msg->vf_qid, vfop->rc);
743 goto op_done;
744
745 default:
746 bnx2x_vfop_default(state);
747 }
748}
749
750static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
751 struct bnx2x_virtf *vf,
752 struct bnx2x_vfop_cmd *cmd)
753{
754 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
755 if (vfop) {
756 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
757 bnx2x_vfop_mbx_qfilters, cmd->done);
758 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
759 cmd->block);
760 }
761 return -ENOMEM;
762}
763
764static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
765 struct bnx2x_virtf *vf,
766 struct bnx2x_vf_mbx *mbx)
767{
768 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
769 struct bnx2x_vfop_cmd cmd = {
770 .done = bnx2x_vf_mbx_resp,
771 .block = false,
772 };
773
774 /* verify vf_qid */
775 if (filters->vf_qid > vf_rxq_count(vf))
776 goto response;
777
778 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
779 vf->abs_vfid,
780 filters->vf_qid);
781
782 /* print q_filter message */
783 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
784
785 vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
786 if (vf->op_rc)
787 goto response;
788 return;
789
790response:
791 bnx2x_vf_mbx_resp(bp, vf);
792}
793
Ariel Elior463a68a2013-01-01 05:22:39 +0000794static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
795 struct bnx2x_vf_mbx *mbx)
796{
797 int qid = mbx->msg->req.q_op.vf_qid;
798 struct bnx2x_vfop_cmd cmd = {
799 .done = bnx2x_vf_mbx_resp,
800 .block = false,
801 };
802
803 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
804 vf->abs_vfid, qid);
805
806 vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
807 if (vf->op_rc)
808 bnx2x_vf_mbx_resp(bp, vf);
809}
810
Ariel Elior99e9d212013-01-01 05:22:40 +0000811static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
812 struct bnx2x_vf_mbx *mbx)
813{
814 struct bnx2x_vfop_cmd cmd = {
815 .done = bnx2x_vf_mbx_resp,
816 .block = false,
817 };
818
819 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
820
821 vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
822 if (vf->op_rc)
823 bnx2x_vf_mbx_resp(bp, vf);
824}
825
Ariel Eliorf1929b02013-01-01 05:22:41 +0000826static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
827 struct bnx2x_vf_mbx *mbx)
828{
829 struct bnx2x_vfop_cmd cmd = {
830 .done = bnx2x_vf_mbx_resp,
831 .block = false,
832 };
833
834 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
835
836 vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
837 if (vf->op_rc)
838 bnx2x_vf_mbx_resp(bp, vf);
839}
840
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000841/* dispatch request */
842static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
843 struct bnx2x_vf_mbx *mbx)
844{
845 int i;
846
847 /* check if tlv type is known */
848 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
Ariel Elior8ca5e172013-01-01 05:22:34 +0000849 /* Lock the per vf op mutex and note the locker's identity.
850 * The unlock will take place in mbx response.
851 */
852 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
853
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000854 /* switch on the opcode */
855 switch (mbx->first_tlv.tl.type) {
Ariel Elior8ca5e172013-01-01 05:22:34 +0000856 case CHANNEL_TLV_ACQUIRE:
857 bnx2x_vf_mbx_acquire(bp, vf, mbx);
858 break;
Ariel Eliorb93288d2013-01-01 05:22:35 +0000859 case CHANNEL_TLV_INIT:
860 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
861 break;
Ariel Elior8db573b2013-01-01 05:22:37 +0000862 case CHANNEL_TLV_SETUP_Q:
863 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
864 break;
Ariel Elior954ea742013-01-01 05:22:38 +0000865 case CHANNEL_TLV_SET_Q_FILTERS:
866 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
867 break;
Ariel Elior463a68a2013-01-01 05:22:39 +0000868 case CHANNEL_TLV_TEARDOWN_Q:
869 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
870 break;
Ariel Elior99e9d212013-01-01 05:22:40 +0000871 case CHANNEL_TLV_CLOSE:
872 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
873 break;
Ariel Eliorf1929b02013-01-01 05:22:41 +0000874 case CHANNEL_TLV_RELEASE:
875 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
876 break;
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000877 }
Ariel Elior463a68a2013-01-01 05:22:39 +0000878
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000879 } else {
880 /* unknown TLV - this may belong to a VF driver from the future
881 * - a version written after this PF driver was written, which
882 * supports features unknown as of yet. Too bad since we don't
883 * support them. Or this may be because someone wrote a crappy
884 * VF driver and is sending garbage over the channel.
885 */
886 BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
887 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
888 for (i = 0; i < 20; i++)
889 DP_CONT(BNX2X_MSG_IOV, "%x ",
890 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
Ariel Elior8ca5e172013-01-01 05:22:34 +0000891
892 /* test whether we can respond to the VF (do we have an address
893 * for it?)
894 */
895 if (vf->state == VF_ACQUIRED) {
896 /* mbx_resp uses the op_rc of the VF */
897 vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
898
899 /* notify the VF that we do not support this request */
900 bnx2x_vf_mbx_resp(bp, vf);
901 } else {
902 /* can't send a response since this VF is unknown to us
903 * just unlock the channel and be done with.
904 */
905 bnx2x_unlock_vf_pf_channel(bp, vf,
906 mbx->first_tlv.tl.type);
907 }
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000908 }
909}
910
911/* handle new vf-pf message */
912void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
913{
914 struct bnx2x_virtf *vf;
915 struct bnx2x_vf_mbx *mbx;
916 u8 vf_idx;
917 int rc;
918
919 DP(BNX2X_MSG_IOV,
920 "vf pf event received: vfid %d, address_hi %x, address lo %x",
921 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
922 /* Sanity checks consider removing later */
923
924 /* check if the vf_id is valid */
925 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
926 BNX2X_NR_VIRTFN(bp)) {
927 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
928 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
929 goto mbx_done;
930 }
931 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
932 mbx = BP_VF_MBX(bp, vf_idx);
933
934 /* verify an event is not currently being processed -
935 * debug failsafe only
936 */
937 if (mbx->flags & VF_MSG_INPROCESS) {
938 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
939 vfpf_event->vf_id);
940 goto mbx_done;
941 }
942 vf = BP_VF(bp, vf_idx);
943
944 /* save the VF message address */
945 mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
946 mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
947 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
948 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
949
950 /* dmae to get the VF request */
951 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
952 mbx->vf_addr_hi, mbx->vf_addr_lo,
953 sizeof(union vfpf_tlvs)/4);
954 if (rc) {
955 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
956 goto mbx_error;
957 }
958
959 /* process the VF message header */
960 mbx->first_tlv = mbx->msg->req.first_tlv;
961
962 /* dispatch the request (will prepare the response) */
963 bnx2x_vf_mbx_request(bp, vf, mbx);
964 goto mbx_done;
965
966mbx_error:
Ariel Eliorf1929b02013-01-01 05:22:41 +0000967 bnx2x_vf_release(bp, vf, false); /* non blocking */
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000968mbx_done:
969 return;
970}