1/* bnx2x_vfpf.c: Broadcom Everest network driver. 2 * 3 * Copyright 2009-2013 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: Ariel Elior <ariel.elior@qlogic.com> 16 * Written by: Shmulik Ravid 17 * Ariel Elior <ariel.elior@qlogic.com> 18 */ 19 20#include "bnx2x.h" 21#include "bnx2x_cmn.h" 22#include <linux/crc32.h> 23 24static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx); 25 26/* place a given tlv on the tlv buffer at a given offset */ 27static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, 28 u16 offset, u16 type, u16 length) 29{ 30 struct channel_tlv *tl = 31 (struct channel_tlv *)(tlvs_list + offset); 32 33 tl->type = type; 34 tl->length = length; 35} 36 37/* Clear the mailbox and init the header of the first tlv */ 38static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv, 39 u16 type, u16 length) 40{ 41 mutex_lock(&bp->vf2pf_mutex); 42 43 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n", 44 type); 45 46 /* Clear mailbox */ 47 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg)); 48 49 /* init type and length */ 50 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length); 51 52 /* init first tlv header */ 53 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req); 54} 55 56/* releases the mailbox */ 57static void bnx2x_vfpf_finalize(struct bnx2x *bp, 58 struct vfpf_first_tlv *first_tlv) 59{ 60 DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n", 61 first_tlv->tl.type); 62 63 mutex_unlock(&bp->vf2pf_mutex); 64} 65 66/* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */ 67static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list, 68 enum channel_tlvs req_tlv) 69{ 70 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list; 71 72 do { 73 if (tlv->type == req_tlv) 74 return tlv; 75 76 if (!tlv->length) { 77 BNX2X_ERR("Found TLV with length 0\n"); 78 return NULL; 79 } 80 81 tlvs_list += tlv->length; 82 tlv = (struct channel_tlv *)tlvs_list; 83 } while (tlv->type != CHANNEL_TLV_LIST_END); 84 85 DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv); 86 87 return NULL; 88} 89 90/* list the types and lengths of the tlvs on the buffer */ 91static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list) 92{ 93 int i = 1; 94 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list; 95 96 while (tlv->type != CHANNEL_TLV_LIST_END) { 97 /* output tlv */ 98 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i, 99 tlv->type, tlv->length); 100 101 /* advance to next tlv */ 102 tlvs_list += tlv->length; 103 104 /* cast general tlv list pointer to channel tlv header*/ 105 tlv = (struct channel_tlv *)tlvs_list; 106 107 i++; 108 109 /* break condition for this loop */ 110 if (i > MAX_TLVS_IN_LIST) { 111 WARN(true, "corrupt tlvs"); 112 return; 113 } 114 } 115 116 /* output last tlv */ 117 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i, 118 tlv->type, tlv->length); 119} 120 121/* test whether we support a tlv type */ 122bool bnx2x_tlv_supported(u16 tlvtype) 123{ 124 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX; 125} 126 127static inline int bnx2x_pfvf_status_codes(int rc) 128{ 129 switch (rc) { 130 case 0: 131 return PFVF_STATUS_SUCCESS; 132 case -ENOMEM: 133 return PFVF_STATUS_NO_RESOURCE; 134 default: 135 return PFVF_STATUS_FAILURE; 136 } 137} 138 139static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping) 140{ 141 struct cstorm_vf_zone_data __iomem *zone_data = 142 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START); 143 int tout = 100, interval = 100; /* wait for 10 seconds */ 144 145 if (*done) { 146 BNX2X_ERR("done was non zero before message to pf was sent\n"); 147 WARN_ON(true); 148 return -EINVAL; 149 } 150 151 /* if PF indicated channel is down avoid sending message. Return success 152 * so calling flow can continue 153 */ 154 bnx2x_sample_bulletin(bp); 155 if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) { 156 DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n"); 157 *done = PFVF_STATUS_SUCCESS; 158 return -EINVAL; 159 } 160 161 /* Write message address */ 162 writel(U64_LO(msg_mapping), 163 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo); 164 writel(U64_HI(msg_mapping), 165 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi); 166 167 /* make sure the address is written before FW accesses it */ 168 wmb(); 169 170 /* Trigger the PF FW */ 171 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid); 172 173 /* Wait for PF to complete */ 174 while ((tout >= 0) && (!*done)) { 175 msleep(interval); 176 tout -= 1; 177 178 /* progress indicator - HV can take its own sweet time in 179 * answering VFs... 180 */ 181 DP_CONT(BNX2X_MSG_IOV, "."); 182 } 183 184 if (!*done) { 185 BNX2X_ERR("PF response has timed out\n"); 186 return -EAGAIN; 187 } 188 DP(BNX2X_MSG_SP, "Got a response from PF\n"); 189 return 0; 190} 191 192static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id) 193{ 194 u32 me_reg; 195 int tout = 10, interval = 100; /* Wait for 1 sec */ 196 197 do { 198 /* pxp traps vf read of doorbells and returns me reg value */ 199 me_reg = readl(bp->doorbells); 200 if (GOOD_ME_REG(me_reg)) 201 break; 202 203 msleep(interval); 204 205 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?", 206 me_reg); 207 } while (tout-- > 0); 208 209 if (!GOOD_ME_REG(me_reg)) { 210 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg); 211 return -EINVAL; 212 } 213 214 DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg); 215 216 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT; 217 218 return 0; 219} 220 221int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count) 222{ 223 int rc = 0, attempts = 0; 224 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire; 225 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp; 226 struct vfpf_port_phys_id_resp_tlv *phys_port_resp; 227 u32 vf_id; 228 bool resources_acquired = false; 229 230 /* clear mailbox and prep first tlv */ 231 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req)); 232 233 if (bnx2x_get_vf_id(bp, &vf_id)) { 234 rc = -EAGAIN; 235 goto out; 236 } 237 238 req->vfdev_info.vf_id = vf_id; 239 req->vfdev_info.vf_os = 0; 240 241 req->resc_request.num_rxqs = rx_count; 242 req->resc_request.num_txqs = tx_count; 243 req->resc_request.num_sbs = bp->igu_sb_cnt; 244 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS; 245 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS; 246 247 /* pf 2 vf bulletin board address */ 248 req->bulletin_addr = bp->pf2vf_bulletin_mapping; 249 250 /* Request physical port identifier */ 251 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, 252 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv)); 253 254 /* Bulletin support for bulletin board with length > legacy length */ 255 req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN; 256 257 /* add list termination tlv */ 258 bnx2x_add_tlv(bp, req, 259 req->first_tlv.tl.length + sizeof(struct channel_tlv), 260 CHANNEL_TLV_LIST_END, 261 sizeof(struct channel_list_end_tlv)); 262 263 /* output tlvs list */ 264 bnx2x_dp_tlv_list(bp, req); 265 266 while (!resources_acquired) { 267 DP(BNX2X_MSG_SP, "attempting to acquire resources\n"); 268 269 /* send acquire request */ 270 rc = bnx2x_send_msg2pf(bp, 271 &resp->hdr.status, 272 bp->vf2pf_mbox_mapping); 273 274 /* PF timeout */ 275 if (rc) 276 goto out; 277 278 /* copy acquire response from buffer to bp */ 279 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp)); 280 281 attempts++; 282 283 /* test whether the PF accepted our request. If not, humble 284 * the request and try again. 285 */ 286 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) { 287 DP(BNX2X_MSG_SP, "resources acquired\n"); 288 resources_acquired = true; 289 } else if (bp->acquire_resp.hdr.status == 290 PFVF_STATUS_NO_RESOURCE && 291 attempts < VF_ACQUIRE_THRESH) { 292 DP(BNX2X_MSG_SP, 293 "PF unwilling to fulfill resource request. Try PF recommended amount\n"); 294 295 /* humble our request */ 296 req->resc_request.num_txqs = 297 min(req->resc_request.num_txqs, 298 bp->acquire_resp.resc.num_txqs); 299 req->resc_request.num_rxqs = 300 min(req->resc_request.num_rxqs, 301 bp->acquire_resp.resc.num_rxqs); 302 req->resc_request.num_sbs = 303 min(req->resc_request.num_sbs, 304 bp->acquire_resp.resc.num_sbs); 305 req->resc_request.num_mac_filters = 306 min(req->resc_request.num_mac_filters, 307 bp->acquire_resp.resc.num_mac_filters); 308 req->resc_request.num_vlan_filters = 309 min(req->resc_request.num_vlan_filters, 310 bp->acquire_resp.resc.num_vlan_filters); 311 req->resc_request.num_mc_filters = 312 min(req->resc_request.num_mc_filters, 313 bp->acquire_resp.resc.num_mc_filters); 314 315 /* Clear response buffer */ 316 memset(&bp->vf2pf_mbox->resp, 0, 317 sizeof(union pfvf_tlvs)); 318 } else { 319 /* PF reports error */ 320 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n", 321 bp->acquire_resp.hdr.status); 322 rc = -EAGAIN; 323 goto out; 324 } 325 } 326 327 /* Retrieve physical port id (if possible) */ 328 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *) 329 bnx2x_search_tlv_list(bp, resp, 330 CHANNEL_TLV_PHYS_PORT_ID); 331 if (phys_port_resp) { 332 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN); 333 bp->flags |= HAS_PHYS_PORT_ID; 334 } 335 336 /* get HW info */ 337 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff); 338 bp->link_params.chip_id = bp->common.chip_id; 339 bp->db_size = bp->acquire_resp.pfdev_info.db_size; 340 bp->common.int_block = INT_BLOCK_IGU; 341 bp->common.chip_port_mode = CHIP_2_PORT_MODE; 342 bp->igu_dsb_id = -1; 343 bp->mf_ov = 0; 344 bp->mf_mode = 0; 345 bp->common.flash_size = 0; 346 bp->flags |= 347 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG; 348 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs; 349 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id; 350 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver, 351 sizeof(bp->fw_ver)); 352 353 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr)) 354 memcpy(bp->dev->dev_addr, 355 bp->acquire_resp.resc.current_mac_addr, 356 ETH_ALEN); 357 358out: 359 bnx2x_vfpf_finalize(bp, &req->first_tlv); 360 return rc; 361} 362 363int bnx2x_vfpf_release(struct bnx2x *bp) 364{ 365 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release; 366 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 367 u32 rc, vf_id; 368 369 /* clear mailbox and prep first tlv */ 370 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req)); 371 372 if (bnx2x_get_vf_id(bp, &vf_id)) { 373 rc = -EAGAIN; 374 goto out; 375 } 376 377 req->vf_id = vf_id; 378 379 /* add list termination tlv */ 380 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 381 sizeof(struct channel_list_end_tlv)); 382 383 /* output tlvs list */ 384 bnx2x_dp_tlv_list(bp, req); 385 386 /* send release request */ 387 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 388 389 if (rc) 390 /* PF timeout */ 391 goto out; 392 393 if (resp->hdr.status == PFVF_STATUS_SUCCESS) { 394 /* PF released us */ 395 DP(BNX2X_MSG_SP, "vf released\n"); 396 } else { 397 /* PF reports error */ 398 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n", 399 resp->hdr.status); 400 rc = -EAGAIN; 401 goto out; 402 } 403out: 404 bnx2x_vfpf_finalize(bp, &req->first_tlv); 405 406 return rc; 407} 408 409/* Tell PF about SB addresses */ 410int bnx2x_vfpf_init(struct bnx2x *bp) 411{ 412 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init; 413 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 414 int rc, i; 415 416 /* clear mailbox and prep first tlv */ 417 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req)); 418 419 /* status blocks */ 420 for_each_eth_queue(bp, i) 421 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i, 422 status_blk_mapping); 423 424 /* statistics - requests only supports single queue for now */ 425 req->stats_addr = bp->fw_stats_data_mapping + 426 offsetof(struct bnx2x_fw_stats_data, queue_stats); 427 428 req->stats_stride = sizeof(struct per_queue_stats); 429 430 /* add list termination tlv */ 431 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 432 sizeof(struct channel_list_end_tlv)); 433 434 /* output tlvs list */ 435 bnx2x_dp_tlv_list(bp, req); 436 437 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 438 if (rc) 439 goto out; 440 441 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 442 BNX2X_ERR("INIT VF failed: %d. Breaking...\n", 443 resp->hdr.status); 444 rc = -EAGAIN; 445 goto out; 446 } 447 448 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n"); 449out: 450 bnx2x_vfpf_finalize(bp, &req->first_tlv); 451 452 return rc; 453} 454 455/* CLOSE VF - opposite to INIT_VF */ 456void bnx2x_vfpf_close_vf(struct bnx2x *bp) 457{ 458 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close; 459 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 460 int i, rc; 461 u32 vf_id; 462 463 /* If we haven't got a valid VF id, there is no sense to 464 * continue with sending messages 465 */ 466 if (bnx2x_get_vf_id(bp, &vf_id)) 467 goto free_irq; 468 469 /* Close the queues */ 470 for_each_queue(bp, i) 471 bnx2x_vfpf_teardown_queue(bp, i); 472 473 /* remove mac */ 474 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false); 475 476 /* clear mailbox and prep first tlv */ 477 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req)); 478 479 req->vf_id = vf_id; 480 481 /* add list termination tlv */ 482 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 483 sizeof(struct channel_list_end_tlv)); 484 485 /* output tlvs list */ 486 bnx2x_dp_tlv_list(bp, req); 487 488 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 489 490 if (rc) 491 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc); 492 493 else if (resp->hdr.status != PFVF_STATUS_SUCCESS) 494 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n", 495 resp->hdr.status); 496 497 bnx2x_vfpf_finalize(bp, &req->first_tlv); 498 499free_irq: 500 /* Disable HW interrupts, NAPI */ 501 bnx2x_netif_stop(bp, 0); 502 /* Delete all NAPI objects */ 503 bnx2x_del_all_napi(bp); 504 505 /* Release IRQs */ 506 bnx2x_free_irq(bp); 507} 508 509static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf, 510 struct bnx2x_vf_queue *q) 511{ 512 u8 cl_id = vfq_cl_id(vf, q); 513 u8 func_id = FW_VF_HANDLE(vf->abs_vfid); 514 515 /* mac */ 516 bnx2x_init_mac_obj(bp, &q->mac_obj, 517 cl_id, q->cid, func_id, 518 bnx2x_vf_sp(bp, vf, mac_rdata), 519 bnx2x_vf_sp_map(bp, vf, mac_rdata), 520 BNX2X_FILTER_MAC_PENDING, 521 &vf->filter_state, 522 BNX2X_OBJ_TYPE_RX_TX, 523 &bp->macs_pool); 524 /* vlan */ 525 bnx2x_init_vlan_obj(bp, &q->vlan_obj, 526 cl_id, q->cid, func_id, 527 bnx2x_vf_sp(bp, vf, vlan_rdata), 528 bnx2x_vf_sp_map(bp, vf, vlan_rdata), 529 BNX2X_FILTER_VLAN_PENDING, 530 &vf->filter_state, 531 BNX2X_OBJ_TYPE_RX_TX, 532 &bp->vlans_pool); 533 534 /* mcast */ 535 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id, 536 q->cid, func_id, func_id, 537 bnx2x_vf_sp(bp, vf, mcast_rdata), 538 bnx2x_vf_sp_map(bp, vf, mcast_rdata), 539 BNX2X_FILTER_MCAST_PENDING, 540 &vf->filter_state, 541 BNX2X_OBJ_TYPE_RX_TX); 542 543 /* rss */ 544 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid, 545 func_id, func_id, 546 bnx2x_vf_sp(bp, vf, rss_rdata), 547 bnx2x_vf_sp_map(bp, vf, rss_rdata), 548 BNX2X_FILTER_RSS_CONF_PENDING, 549 &vf->filter_state, 550 BNX2X_OBJ_TYPE_RX_TX); 551 552 vf->leading_rss = cl_id; 553 q->is_leading = true; 554 q->sp_initialized = true; 555} 556 557/* ask the pf to open a queue for the vf */ 558int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp, 559 bool is_leading) 560{ 561 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q; 562 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 563 u8 fp_idx = fp->index; 564 u16 tpa_agg_size = 0, flags = 0; 565 int rc; 566 567 /* clear mailbox and prep first tlv */ 568 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req)); 569 570 /* select tpa mode to request */ 571 if (!fp->disable_tpa) { 572 flags |= VFPF_QUEUE_FLG_TPA; 573 flags |= VFPF_QUEUE_FLG_TPA_IPV6; 574 if (fp->mode == TPA_MODE_GRO) 575 flags |= VFPF_QUEUE_FLG_TPA_GRO; 576 tpa_agg_size = TPA_AGG_SIZE; 577 } 578 579 if (is_leading) 580 flags |= VFPF_QUEUE_FLG_LEADING_RSS; 581 582 /* calculate queue flags */ 583 flags |= VFPF_QUEUE_FLG_STATS; 584 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN; 585 flags |= VFPF_QUEUE_FLG_VLAN; 586 587 /* Common */ 588 req->vf_qid = fp_idx; 589 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID; 590 591 /* Rx */ 592 req->rxq.rcq_addr = fp->rx_comp_mapping; 593 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE; 594 req->rxq.rxq_addr = fp->rx_desc_mapping; 595 req->rxq.sge_addr = fp->rx_sge_mapping; 596 req->rxq.vf_sb = fp_idx; 597 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS; 598 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0; 599 req->rxq.mtu = bp->dev->mtu; 600 req->rxq.buf_sz = fp->rx_buf_size; 601 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE; 602 req->rxq.tpa_agg_sz = tpa_agg_size; 603 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT; 604 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) & 605 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT; 606 req->rxq.flags = flags; 607 req->rxq.drop_flags = 0; 608 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT; 609 req->rxq.stat_id = -1; /* No stats at the moment */ 610 611 /* Tx */ 612 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping; 613 req->txq.vf_sb = fp_idx; 614 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0; 615 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0; 616 req->txq.flags = flags; 617 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW; 618 619 /* add list termination tlv */ 620 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 621 sizeof(struct channel_list_end_tlv)); 622 623 /* output tlvs list */ 624 bnx2x_dp_tlv_list(bp, req); 625 626 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 627 if (rc) 628 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n", 629 fp_idx); 630 631 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 632 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n", 633 fp_idx, resp->hdr.status); 634 rc = -EINVAL; 635 } 636 637 bnx2x_vfpf_finalize(bp, &req->first_tlv); 638 639 return rc; 640} 641 642static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx) 643{ 644 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op; 645 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 646 int rc; 647 648 /* clear mailbox and prep first tlv */ 649 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q, 650 sizeof(*req)); 651 652 req->vf_qid = qidx; 653 654 /* add list termination tlv */ 655 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 656 sizeof(struct channel_list_end_tlv)); 657 658 /* output tlvs list */ 659 bnx2x_dp_tlv_list(bp, req); 660 661 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 662 663 if (rc) { 664 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx, 665 rc); 666 goto out; 667 } 668 669 /* PF failed the transaction */ 670 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 671 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx, 672 resp->hdr.status); 673 rc = -EINVAL; 674 } 675 676out: 677 bnx2x_vfpf_finalize(bp, &req->first_tlv); 678 679 return rc; 680} 681 682/* request pf to add a mac for the vf */ 683int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set) 684{ 685 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters; 686 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 687 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content; 688 int rc = 0; 689 690 /* clear mailbox and prep first tlv */ 691 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS, 692 sizeof(*req)); 693 694 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED; 695 req->vf_qid = vf_qid; 696 req->n_mac_vlan_filters = 1; 697 698 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID; 699 if (set) 700 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC; 701 702 /* sample bulletin board for new mac */ 703 bnx2x_sample_bulletin(bp); 704 705 /* copy mac from device to request */ 706 memcpy(req->filters[0].mac, addr, ETH_ALEN); 707 708 /* add list termination tlv */ 709 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 710 sizeof(struct channel_list_end_tlv)); 711 712 /* output tlvs list */ 713 bnx2x_dp_tlv_list(bp, req); 714 715 /* send message to pf */ 716 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 717 if (rc) { 718 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc); 719 goto out; 720 } 721 722 /* failure may mean PF was configured with a new mac for us */ 723 while (resp->hdr.status == PFVF_STATUS_FAILURE) { 724 DP(BNX2X_MSG_IOV, 725 "vfpf SET MAC failed. Check bulletin board for new posts\n"); 726 727 /* copy mac from bulletin to device */ 728 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN); 729 730 /* check if bulletin board was updated */ 731 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) { 732 /* copy mac from device to request */ 733 memcpy(req->filters[0].mac, bp->dev->dev_addr, 734 ETH_ALEN); 735 736 /* send message to pf */ 737 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, 738 bp->vf2pf_mbox_mapping); 739 } else { 740 /* no new info in bulletin */ 741 break; 742 } 743 } 744 745 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 746 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status); 747 rc = -EINVAL; 748 } 749out: 750 bnx2x_vfpf_finalize(bp, &req->first_tlv); 751 752 return rc; 753} 754 755/* request pf to config rss table for vf queues*/ 756int bnx2x_vfpf_config_rss(struct bnx2x *bp, 757 struct bnx2x_config_rss_params *params) 758{ 759 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 760 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss; 761 int rc = 0; 762 763 /* clear mailbox and prep first tlv */ 764 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS, 765 sizeof(*req)); 766 767 /* add list termination tlv */ 768 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 769 sizeof(struct channel_list_end_tlv)); 770 771 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE); 772 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key)); 773 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE; 774 req->rss_key_size = T_ETH_RSS_KEY; 775 req->rss_result_mask = params->rss_result_mask; 776 777 /* flags handled individually for backward/forward compatability */ 778 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED)) 779 req->rss_flags |= VFPF_RSS_MODE_DISABLED; 780 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR)) 781 req->rss_flags |= VFPF_RSS_MODE_REGULAR; 782 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH)) 783 req->rss_flags |= VFPF_RSS_SET_SRCH; 784 if (params->rss_flags & (1 << BNX2X_RSS_IPV4)) 785 req->rss_flags |= VFPF_RSS_IPV4; 786 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP)) 787 req->rss_flags |= VFPF_RSS_IPV4_TCP; 788 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP)) 789 req->rss_flags |= VFPF_RSS_IPV4_UDP; 790 if (params->rss_flags & (1 << BNX2X_RSS_IPV6)) 791 req->rss_flags |= VFPF_RSS_IPV6; 792 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP)) 793 req->rss_flags |= VFPF_RSS_IPV6_TCP; 794 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP)) 795 req->rss_flags |= VFPF_RSS_IPV6_UDP; 796 797 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags); 798 799 /* output tlvs list */ 800 bnx2x_dp_tlv_list(bp, req); 801 802 /* send message to pf */ 803 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 804 if (rc) { 805 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc); 806 goto out; 807 } 808 809 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 810 /* Since older drivers don't support this feature (and VF has 811 * no way of knowing other than failing this), don't propagate 812 * an error in this case. 813 */ 814 DP(BNX2X_MSG_IOV, 815 "Failed to send rss message to PF over VF-PF channel [%d]\n", 816 resp->hdr.status); 817 } 818out: 819 bnx2x_vfpf_finalize(bp, &req->first_tlv); 820 821 return rc; 822} 823 824int bnx2x_vfpf_set_mcast(struct net_device *dev) 825{ 826 struct bnx2x *bp = netdev_priv(dev); 827 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters; 828 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 829 int rc, i = 0; 830 struct netdev_hw_addr *ha; 831 832 if (bp->state != BNX2X_STATE_OPEN) { 833 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); 834 return -EINVAL; 835 } 836 837 /* clear mailbox and prep first tlv */ 838 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS, 839 sizeof(*req)); 840 841 /* Get Rx mode requested */ 842 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags); 843 844 netdev_for_each_mc_addr(ha, dev) { 845 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n", 846 bnx2x_mc_addr(ha)); 847 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN); 848 i++; 849 } 850 851 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast 852 * addresses tops 853 */ 854 if (i >= PFVF_MAX_MULTICAST_PER_VF) { 855 DP(NETIF_MSG_IFUP, 856 "VF supports not more than %d multicast MAC addresses\n", 857 PFVF_MAX_MULTICAST_PER_VF); 858 return -EINVAL; 859 } 860 861 req->n_multicast = i; 862 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED; 863 req->vf_qid = 0; 864 865 /* add list termination tlv */ 866 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 867 sizeof(struct channel_list_end_tlv)); 868 869 /* output tlvs list */ 870 bnx2x_dp_tlv_list(bp, req); 871 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 872 if (rc) { 873 BNX2X_ERR("Sending a message failed: %d\n", rc); 874 goto out; 875 } 876 877 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 878 BNX2X_ERR("Set Rx mode/multicast failed: %d\n", 879 resp->hdr.status); 880 rc = -EINVAL; 881 } 882out: 883 bnx2x_vfpf_finalize(bp, &req->first_tlv); 884 885 return 0; 886} 887 888int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp) 889{ 890 int mode = bp->rx_mode; 891 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters; 892 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp; 893 int rc; 894 895 /* clear mailbox and prep first tlv */ 896 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS, 897 sizeof(*req)); 898 899 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode); 900 901 /* Ignore everything accept MODE_NONE */ 902 if (mode == BNX2X_RX_MODE_NONE) { 903 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE; 904 } else { 905 /* Current PF driver will not look at the specific flags, 906 * but they are required when working with older drivers on hv. 907 */ 908 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST; 909 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST; 910 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST; 911 } 912 913 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED; 914 req->vf_qid = 0; 915 916 /* add list termination tlv */ 917 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END, 918 sizeof(struct channel_list_end_tlv)); 919 920 /* output tlvs list */ 921 bnx2x_dp_tlv_list(bp, req); 922 923 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping); 924 if (rc) 925 BNX2X_ERR("Sending a message failed: %d\n", rc); 926 927 if (resp->hdr.status != PFVF_STATUS_SUCCESS) { 928 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status); 929 rc = -EINVAL; 930 } 931 932 bnx2x_vfpf_finalize(bp, &req->first_tlv); 933 934 return rc; 935} 936 937/* General service functions */ 938static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid) 939{ 940 u32 addr = BAR_CSTRORM_INTMEM + 941 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid); 942 943 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY); 944} 945 946static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid) 947{ 948 u32 addr = BAR_CSTRORM_INTMEM + 949 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid); 950 951 REG_WR8(bp, addr, 1); 952} 953 954/* enable vf_pf mailbox (aka vf-pf-channel) */ 955void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid) 956{ 957 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid); 958 959 /* enable the mailbox in the FW */ 960 storm_memset_vf_mbx_ack(bp, abs_vfid); 961 storm_memset_vf_mbx_valid(bp, abs_vfid); 962 963 /* enable the VF access to the mailbox */ 964 bnx2x_vf_enable_access(bp, abs_vfid); 965} 966 967/* this works only on !E1h */ 968static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf, 969 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi, 970 u32 vf_addr_lo, u32 len32) 971{ 972 struct dmae_command dmae; 973 974 if (CHIP_IS_E1x(bp)) { 975 BNX2X_ERR("Chip revision does not support VFs\n"); 976 return DMAE_NOT_RDY; 977 } 978 979 if (!bp->dmae_ready) { 980 BNX2X_ERR("DMAE is not ready, can not copy\n"); 981 return DMAE_NOT_RDY; 982 } 983 984 /* set opcode and fixed command fields */ 985 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI); 986 987 if (from_vf) { 988 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) | 989 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) | 990 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT); 991 992 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT); 993 994 dmae.src_addr_lo = vf_addr_lo; 995 dmae.src_addr_hi = vf_addr_hi; 996 dmae.dst_addr_lo = U64_LO(pf_addr); 997 dmae.dst_addr_hi = U64_HI(pf_addr); 998 } else { 999 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) | 1000 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) | 1001 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT); 1002 1003 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT); 1004 1005 dmae.src_addr_lo = U64_LO(pf_addr); 1006 dmae.src_addr_hi = U64_HI(pf_addr); 1007 dmae.dst_addr_lo = vf_addr_lo; 1008 dmae.dst_addr_hi = vf_addr_hi; 1009 } 1010 dmae.len = len32; 1011 1012 /* issue the command and wait for completion */ 1013 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp)); 1014} 1015 1016static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp, 1017 struct bnx2x_virtf *vf) 1018{ 1019 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index); 1020 u16 length, type; 1021 1022 /* prepare response */ 1023 type = mbx->first_tlv.tl.type; 1024 length = type == CHANNEL_TLV_ACQUIRE ? 1025 sizeof(struct pfvf_acquire_resp_tlv) : 1026 sizeof(struct pfvf_general_resp_tlv); 1027 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length); 1028 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END, 1029 sizeof(struct channel_list_end_tlv)); 1030} 1031 1032static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp, 1033 struct bnx2x_virtf *vf, 1034 int vf_rc) 1035{ 1036 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index); 1037 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp; 1038 dma_addr_t pf_addr; 1039 u64 vf_addr; 1040 int rc; 1041 1042 bnx2x_dp_tlv_list(bp, resp); 1043 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n", 1044 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset); 1045 1046 resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc); 1047 1048 /* send response */ 1049 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) + 1050 mbx->first_tlv.resp_msg_offset; 1051 pf_addr = mbx->msg_mapping + 1052 offsetof(struct bnx2x_vf_mbx_msg, resp); 1053 1054 /* Copy the response buffer. The first u64 is written afterwards, as 1055 * the vf is sensitive to the header being written 1056 */ 1057 vf_addr += sizeof(u64); 1058 pf_addr += sizeof(u64); 1059 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid, 1060 U64_HI(vf_addr), 1061 U64_LO(vf_addr), 1062 (sizeof(union pfvf_tlvs) - sizeof(u64))/4); 1063 if (rc) { 1064 BNX2X_ERR("Failed to copy response body to VF %d\n", 1065 vf->abs_vfid); 1066 goto mbx_error; 1067 } 1068 vf_addr -= sizeof(u64); 1069 pf_addr -= sizeof(u64); 1070 1071 /* ack the FW */ 1072 storm_memset_vf_mbx_ack(bp, vf->abs_vfid); 1073 mmiowb(); 1074 1075 /* copy the response header including status-done field, 1076 * must be last dmae, must be after FW is acked 1077 */ 1078 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid, 1079 U64_HI(vf_addr), 1080 U64_LO(vf_addr), 1081 sizeof(u64)/4); 1082 1083 /* unlock channel mutex */ 1084 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); 1085 1086 if (rc) { 1087 BNX2X_ERR("Failed to copy response status to VF %d\n", 1088 vf->abs_vfid); 1089 goto mbx_error; 1090 } 1091 return; 1092 1093mbx_error: 1094 bnx2x_vf_release(bp, vf); 1095} 1096 1097static void bnx2x_vf_mbx_resp(struct bnx2x *bp, 1098 struct bnx2x_virtf *vf, 1099 int rc) 1100{ 1101 bnx2x_vf_mbx_resp_single_tlv(bp, vf); 1102 bnx2x_vf_mbx_resp_send_msg(bp, vf, rc); 1103} 1104 1105static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp, 1106 struct bnx2x_virtf *vf, 1107 void *buffer, 1108 u16 *offset) 1109{ 1110 struct vfpf_port_phys_id_resp_tlv *port_id; 1111 1112 if (!(bp->flags & HAS_PHYS_PORT_ID)) 1113 return; 1114 1115 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID, 1116 sizeof(struct vfpf_port_phys_id_resp_tlv)); 1117 1118 port_id = (struct vfpf_port_phys_id_resp_tlv *) 1119 (((u8 *)buffer) + *offset); 1120 memcpy(port_id->id, bp->phys_port_id, ETH_ALEN); 1121 1122 /* Offset should continue representing the offset to the tail 1123 * of TLV data (outside this function scope) 1124 */ 1125 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv); 1126} 1127 1128static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf, 1129 struct bnx2x_vf_mbx *mbx, int vfop_status) 1130{ 1131 int i; 1132 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp; 1133 struct pf_vf_resc *resc = &resp->resc; 1134 u8 status = bnx2x_pfvf_status_codes(vfop_status); 1135 u16 length; 1136 1137 memset(resp, 0, sizeof(*resp)); 1138 1139 /* fill in pfdev info */ 1140 resp->pfdev_info.chip_num = bp->common.chip_id; 1141 resp->pfdev_info.db_size = bp->db_size; 1142 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2; 1143 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS | 1144 PFVF_CAP_TPA | 1145 PFVF_CAP_TPA_UPDATE); 1146 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver, 1147 sizeof(resp->pfdev_info.fw_ver)); 1148 1149 if (status == PFVF_STATUS_NO_RESOURCE || 1150 status == PFVF_STATUS_SUCCESS) { 1151 /* set resources numbers, if status equals NO_RESOURCE these 1152 * are max possible numbers 1153 */ 1154 resc->num_rxqs = vf_rxq_count(vf) ? : 1155 bnx2x_vf_max_queue_cnt(bp, vf); 1156 resc->num_txqs = vf_txq_count(vf) ? : 1157 bnx2x_vf_max_queue_cnt(bp, vf); 1158 resc->num_sbs = vf_sb_count(vf); 1159 resc->num_mac_filters = vf_mac_rules_cnt(vf); 1160 resc->num_vlan_filters = vf_vlan_rules_visible_cnt(vf); 1161 resc->num_mc_filters = 0; 1162 1163 if (status == PFVF_STATUS_SUCCESS) { 1164 /* fill in the allocated resources */ 1165 struct pf_vf_bulletin_content *bulletin = 1166 BP_VF_BULLETIN(bp, vf->index); 1167 1168 for_each_vfq(vf, i) 1169 resc->hw_qid[i] = 1170 vfq_qzone_id(vf, vfq_get(vf, i)); 1171 1172 for_each_vf_sb(vf, i) { 1173 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i); 1174 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i); 1175 } 1176 1177 /* if a mac has been set for this vf, supply it */ 1178 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) { 1179 memcpy(resc->current_mac_addr, bulletin->mac, 1180 ETH_ALEN); 1181 } 1182 } 1183 } 1184 1185 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" 1186 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n", 1187 vf->abs_vfid, 1188 resp->pfdev_info.chip_num, 1189 resp->pfdev_info.db_size, 1190 resp->pfdev_info.indices_per_sb, 1191 resp->pfdev_info.pf_cap, 1192 resc->num_rxqs, 1193 resc->num_txqs, 1194 resc->num_sbs, 1195 resc->num_mac_filters, 1196 resc->num_vlan_filters, 1197 resc->num_mc_filters, 1198 resp->pfdev_info.fw_ver); 1199 1200 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ "); 1201 for (i = 0; i < vf_rxq_count(vf); i++) 1202 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]); 1203 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ "); 1204 for (i = 0; i < vf_sb_count(vf); i++) 1205 DP_CONT(BNX2X_MSG_IOV, "%d:%d ", 1206 resc->hw_sbs[i].hw_sb_id, 1207 resc->hw_sbs[i].sb_qid); 1208 DP_CONT(BNX2X_MSG_IOV, "]\n"); 1209 1210 /* prepare response */ 1211 length = sizeof(struct pfvf_acquire_resp_tlv); 1212 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length); 1213 1214 /* Handle possible VF requests for physical port identifiers. 1215 * 'length' should continue to indicate the offset of the first empty 1216 * place in the buffer (i.e., where next TLV should be inserted) 1217 */ 1218 if (bnx2x_search_tlv_list(bp, &mbx->msg->req, 1219 CHANNEL_TLV_PHYS_PORT_ID)) 1220 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length); 1221 1222 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END, 1223 sizeof(struct channel_list_end_tlv)); 1224 1225 /* send the response */ 1226 bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status); 1227} 1228 1229static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp, 1230 struct vfpf_acquire_tlv *acquire) 1231{ 1232 /* Windows driver does one of three things: 1233 * 1. Old driver doesn't have bulletin board address set. 1234 * 2. 'Middle' driver sends mc_num == 32. 1235 * 3. New driver sets the OS field. 1236 */ 1237 if (!acquire->bulletin_addr || 1238 acquire->resc_request.num_mc_filters == 32 || 1239 ((acquire->vfdev_info.vf_os & VF_OS_MASK) == 1240 VF_OS_WINDOWS)) 1241 return true; 1242 1243 return false; 1244} 1245 1246static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp, 1247 struct bnx2x_virtf *vf, 1248 struct bnx2x_vf_mbx *mbx) 1249{ 1250 /* Linux drivers which correctly set the doorbell size also 1251 * send a physical port request 1252 */ 1253 if (bnx2x_search_tlv_list(bp, &mbx->msg->req, 1254 CHANNEL_TLV_PHYS_PORT_ID)) 1255 return 0; 1256 1257 /* Issue does not exist in windows VMs */ 1258 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire)) 1259 return 0; 1260 1261 return -EOPNOTSUPP; 1262} 1263 1264static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf, 1265 struct bnx2x_vf_mbx *mbx) 1266{ 1267 int rc; 1268 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire; 1269 1270 /* log vfdef info */ 1271 DP(BNX2X_MSG_IOV, 1272 "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", 1273 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os, 1274 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs, 1275 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters, 1276 acquire->resc_request.num_vlan_filters, 1277 acquire->resc_request.num_mc_filters); 1278 1279 /* Prevent VFs with old drivers from loading, since they calculate 1280 * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover 1281 * while being upgraded. 1282 */ 1283 rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx); 1284 if (rc) { 1285 DP(BNX2X_MSG_IOV, 1286 "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n", 1287 vf->abs_vfid); 1288 goto out; 1289 } 1290 1291 /* acquire the resources */ 1292 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request); 1293 1294 /* store address of vf's bulletin board */ 1295 vf->bulletin_map = acquire->bulletin_addr; 1296 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) { 1297 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n", 1298 vf->abs_vfid); 1299 vf->cfg_flags |= VF_CFG_EXT_BULLETIN; 1300 } else { 1301 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN; 1302 } 1303 1304out: 1305 /* response */ 1306 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc); 1307} 1308 1309static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, 1310 struct bnx2x_vf_mbx *mbx) 1311{ 1312 struct vfpf_init_tlv *init = &mbx->msg->req.init; 1313 int rc; 1314 1315 /* record ghost addresses from vf message */ 1316 vf->spq_map = init->spq_addr; 1317 vf->fw_stat_map = init->stats_addr; 1318 vf->stats_stride = init->stats_stride; 1319 rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr); 1320 1321 /* set VF multiqueue statistics collection mode */ 1322 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE) 1323 vf->cfg_flags |= VF_CFG_STATS_COALESCE; 1324 1325 /* Update VF's view of link state */ 1326 if (vf->cfg_flags & VF_CFG_EXT_BULLETIN) 1327 bnx2x_iov_link_update_vf(bp, vf->index); 1328 1329 /* response */ 1330 bnx2x_vf_mbx_resp(bp, vf, rc); 1331} 1332 1333/* convert MBX queue-flags to standard SP queue-flags */ 1334static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags, 1335 unsigned long *sp_q_flags) 1336{ 1337 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA) 1338 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags); 1339 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6) 1340 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags); 1341 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO) 1342 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags); 1343 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS) 1344 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags); 1345 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN) 1346 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags); 1347 if (mbx_q_flags & VFPF_QUEUE_FLG_COS) 1348 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags); 1349 if (mbx_q_flags & VFPF_QUEUE_FLG_HC) 1350 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags); 1351 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC) 1352 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags); 1353 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS) 1354 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags); 1355 1356 /* outer vlan removal is set according to PF's multi function mode */ 1357 if (IS_MF_SD(bp)) 1358 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags); 1359} 1360 1361static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf, 1362 struct bnx2x_vf_mbx *mbx) 1363{ 1364 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q; 1365 struct bnx2x_vf_queue_construct_params qctor; 1366 int rc = 0; 1367 1368 /* verify vf_qid */ 1369 if (setup_q->vf_qid >= vf_rxq_count(vf)) { 1370 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n", 1371 setup_q->vf_qid, vf_rxq_count(vf)); 1372 rc = -EINVAL; 1373 goto response; 1374 } 1375 1376 /* tx queues must be setup alongside rx queues thus if the rx queue 1377 * is not marked as valid there's nothing to do. 1378 */ 1379 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) { 1380 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid); 1381 unsigned long q_type = 0; 1382 1383 struct bnx2x_queue_init_params *init_p; 1384 struct bnx2x_queue_setup_params *setup_p; 1385 1386 if (bnx2x_vfq_is_leading(q)) 1387 bnx2x_leading_vfq_init(bp, vf, q); 1388 1389 /* re-init the VF operation context */ 1390 memset(&qctor, 0 , 1391 sizeof(struct bnx2x_vf_queue_construct_params)); 1392 setup_p = &qctor.prep_qsetup; 1393 init_p = &qctor.qstate.params.init; 1394 1395 /* activate immediately */ 1396 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags); 1397 1398 if (setup_q->param_valid & VFPF_TXQ_VALID) { 1399 struct bnx2x_txq_setup_params *txq_params = 1400 &setup_p->txq_params; 1401 1402 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); 1403 1404 /* save sb resource index */ 1405 q->sb_idx = setup_q->txq.vf_sb; 1406 1407 /* tx init */ 1408 init_p->tx.hc_rate = setup_q->txq.hc_rate; 1409 init_p->tx.sb_cq_index = setup_q->txq.sb_index; 1410 1411 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags, 1412 &init_p->tx.flags); 1413 1414 /* tx setup - flags */ 1415 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags, 1416 &setup_p->flags); 1417 1418 /* tx setup - general, nothing */ 1419 1420 /* tx setup - tx */ 1421 txq_params->dscr_map = setup_q->txq.txq_addr; 1422 txq_params->sb_cq_index = setup_q->txq.sb_index; 1423 txq_params->traffic_type = setup_q->txq.traffic_type; 1424 1425 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p, 1426 q->index, q->sb_idx); 1427 } 1428 1429 if (setup_q->param_valid & VFPF_RXQ_VALID) { 1430 struct bnx2x_rxq_setup_params *rxq_params = 1431 &setup_p->rxq_params; 1432 1433 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); 1434 1435 /* Note: there is no support for different SBs 1436 * for TX and RX 1437 */ 1438 q->sb_idx = setup_q->rxq.vf_sb; 1439 1440 /* rx init */ 1441 init_p->rx.hc_rate = setup_q->rxq.hc_rate; 1442 init_p->rx.sb_cq_index = setup_q->rxq.sb_index; 1443 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags, 1444 &init_p->rx.flags); 1445 1446 /* rx setup - flags */ 1447 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags, 1448 &setup_p->flags); 1449 1450 /* rx setup - general */ 1451 setup_p->gen_params.mtu = setup_q->rxq.mtu; 1452 1453 /* rx setup - rx */ 1454 rxq_params->drop_flags = setup_q->rxq.drop_flags; 1455 rxq_params->dscr_map = setup_q->rxq.rxq_addr; 1456 rxq_params->sge_map = setup_q->rxq.sge_addr; 1457 rxq_params->rcq_map = setup_q->rxq.rcq_addr; 1458 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr; 1459 rxq_params->buf_sz = setup_q->rxq.buf_sz; 1460 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz; 1461 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt; 1462 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz; 1463 rxq_params->cache_line_log = 1464 setup_q->rxq.cache_line_log; 1465 rxq_params->sb_cq_index = setup_q->rxq.sb_index; 1466 1467 /* rx setup - multicast engine */ 1468 if (bnx2x_vfq_is_leading(q)) { 1469 u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid); 1470 1471 rxq_params->mcast_engine_id = mcast_id; 1472 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags); 1473 } 1474 1475 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p, 1476 q->index, q->sb_idx); 1477 } 1478 /* complete the preparations */ 1479 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type); 1480 1481 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor); 1482 if (rc) 1483 goto response; 1484 } 1485response: 1486 bnx2x_vf_mbx_resp(bp, vf, rc); 1487} 1488 1489static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp, 1490 struct bnx2x_virtf *vf, 1491 struct vfpf_set_q_filters_tlv *tlv, 1492 struct bnx2x_vf_mac_vlan_filters **pfl, 1493 u32 type_flag) 1494{ 1495 int i, j; 1496 struct bnx2x_vf_mac_vlan_filters *fl = NULL; 1497 size_t fsz; 1498 1499 fsz = tlv->n_mac_vlan_filters * 1500 sizeof(struct bnx2x_vf_mac_vlan_filter) + 1501 sizeof(struct bnx2x_vf_mac_vlan_filters); 1502 1503 fl = kzalloc(fsz, GFP_KERNEL); 1504 if (!fl) 1505 return -ENOMEM; 1506 1507 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) { 1508 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i]; 1509 1510 if ((msg_filter->flags & type_flag) != type_flag) 1511 continue; 1512 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) { 1513 fl->filters[j].mac = msg_filter->mac; 1514 fl->filters[j].type = BNX2X_VF_FILTER_MAC; 1515 } else { 1516 fl->filters[j].vid = msg_filter->vlan_tag; 1517 fl->filters[j].type = BNX2X_VF_FILTER_VLAN; 1518 } 1519 fl->filters[j].add = 1520 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ? 1521 true : false; 1522 fl->count++; 1523 } 1524 if (!fl->count) 1525 kfree(fl); 1526 else 1527 *pfl = fl; 1528 1529 return 0; 1530} 1531 1532static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx, 1533 struct vfpf_q_mac_vlan_filter *filter) 1534{ 1535 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags); 1536 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID) 1537 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag); 1538 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID) 1539 DP_CONT(msglvl, ", MAC=%pM", filter->mac); 1540 DP_CONT(msglvl, "\n"); 1541} 1542 1543static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl, 1544 struct vfpf_set_q_filters_tlv *filters) 1545{ 1546 int i; 1547 1548 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) 1549 for (i = 0; i < filters->n_mac_vlan_filters; i++) 1550 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i, 1551 &filters->filters[i]); 1552 1553 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) 1554 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask); 1555 1556 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) 1557 for (i = 0; i < filters->n_multicast; i++) 1558 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]); 1559} 1560 1561#define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID 1562#define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID 1563 1564static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf) 1565{ 1566 int rc = 0; 1567 1568 struct vfpf_set_q_filters_tlv *msg = 1569 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters; 1570 1571 /* check for any mac/vlan changes */ 1572 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) { 1573 /* build mac list */ 1574 struct bnx2x_vf_mac_vlan_filters *fl = NULL; 1575 1576 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl, 1577 VFPF_MAC_FILTER); 1578 if (rc) 1579 goto op_err; 1580 1581 if (fl) { 1582 1583 /* set mac list */ 1584 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl, 1585 msg->vf_qid, 1586 false); 1587 if (rc) 1588 goto op_err; 1589 } 1590 1591 /* build vlan list */ 1592 fl = NULL; 1593 1594 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl, 1595 VFPF_VLAN_FILTER); 1596 if (rc) 1597 goto op_err; 1598 1599 if (fl) { 1600 /* set vlan list */ 1601 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl, 1602 msg->vf_qid, 1603 false); 1604 if (rc) 1605 goto op_err; 1606 } 1607 } 1608 1609 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) { 1610 unsigned long accept = 0; 1611 struct pf_vf_bulletin_content *bulletin = 1612 BP_VF_BULLETIN(bp, vf->index); 1613 1614 /* Ignore VF requested mode; instead set a regular mode */ 1615 if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) { 1616 __set_bit(BNX2X_ACCEPT_UNICAST, &accept); 1617 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept); 1618 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept); 1619 } 1620 1621 /* A packet arriving the vf's mac should be accepted 1622 * with any vlan, unless a vlan has already been 1623 * configured. 1624 */ 1625 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID))) 1626 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept); 1627 1628 /* set rx-mode */ 1629 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept); 1630 if (rc) 1631 goto op_err; 1632 } 1633 1634 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) { 1635 /* set mcasts */ 1636 rc = bnx2x_vf_mcast(bp, vf, msg->multicast, 1637 msg->n_multicast, false); 1638 if (rc) 1639 goto op_err; 1640 } 1641op_err: 1642 if (rc) 1643 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n", 1644 vf->abs_vfid, msg->vf_qid, rc); 1645 return rc; 1646} 1647 1648static int bnx2x_filters_validate_mac(struct bnx2x *bp, 1649 struct bnx2x_virtf *vf, 1650 struct vfpf_set_q_filters_tlv *filters) 1651{ 1652 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index); 1653 int rc = 0; 1654 1655 /* if a mac was already set for this VF via the set vf mac ndo, we only 1656 * accept mac configurations of that mac. Why accept them at all? 1657 * because PF may have been unable to configure the mac at the time 1658 * since queue was not set up. 1659 */ 1660 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) { 1661 /* once a mac was set by ndo can only accept a single mac... */ 1662 if (filters->n_mac_vlan_filters > 1) { 1663 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n", 1664 vf->abs_vfid); 1665 rc = -EPERM; 1666 goto response; 1667 } 1668 1669 /* ...and only the mac set by the ndo */ 1670 if (filters->n_mac_vlan_filters == 1 && 1671 !ether_addr_equal(filters->filters->mac, bulletin->mac)) { 1672 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n", 1673 vf->abs_vfid); 1674 1675 rc = -EPERM; 1676 goto response; 1677 } 1678 } 1679 1680response: 1681 return rc; 1682} 1683 1684static int bnx2x_filters_validate_vlan(struct bnx2x *bp, 1685 struct bnx2x_virtf *vf, 1686 struct vfpf_set_q_filters_tlv *filters) 1687{ 1688 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index); 1689 int rc = 0; 1690 1691 /* if vlan was set by hypervisor we don't allow guest to config vlan */ 1692 if (bulletin->valid_bitmap & 1 << VLAN_VALID) { 1693 int i; 1694 1695 /* search for vlan filters */ 1696 for (i = 0; i < filters->n_mac_vlan_filters; i++) { 1697 if (filters->filters[i].flags & 1698 VFPF_Q_FILTER_VLAN_TAG_VALID) { 1699 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n", 1700 vf->abs_vfid); 1701 rc = -EPERM; 1702 goto response; 1703 } 1704 } 1705 } 1706 1707 /* verify vf_qid */ 1708 if (filters->vf_qid > vf_rxq_count(vf)) { 1709 rc = -EPERM; 1710 goto response; 1711 } 1712 1713response: 1714 return rc; 1715} 1716 1717static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp, 1718 struct bnx2x_virtf *vf, 1719 struct bnx2x_vf_mbx *mbx) 1720{ 1721 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters; 1722 int rc; 1723 1724 rc = bnx2x_filters_validate_mac(bp, vf, filters); 1725 if (rc) 1726 goto response; 1727 1728 rc = bnx2x_filters_validate_vlan(bp, vf, filters); 1729 if (rc) 1730 goto response; 1731 1732 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n", 1733 vf->abs_vfid, 1734 filters->vf_qid); 1735 1736 /* print q_filter message */ 1737 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters); 1738 1739 rc = bnx2x_vf_mbx_qfilters(bp, vf); 1740response: 1741 bnx2x_vf_mbx_resp(bp, vf, rc); 1742} 1743 1744static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf, 1745 struct bnx2x_vf_mbx *mbx) 1746{ 1747 int qid = mbx->msg->req.q_op.vf_qid; 1748 int rc; 1749 1750 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n", 1751 vf->abs_vfid, qid); 1752 1753 rc = bnx2x_vf_queue_teardown(bp, vf, qid); 1754 bnx2x_vf_mbx_resp(bp, vf, rc); 1755} 1756 1757static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, 1758 struct bnx2x_vf_mbx *mbx) 1759{ 1760 int rc; 1761 1762 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid); 1763 1764 rc = bnx2x_vf_close(bp, vf); 1765 bnx2x_vf_mbx_resp(bp, vf, rc); 1766} 1767 1768static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, 1769 struct bnx2x_vf_mbx *mbx) 1770{ 1771 int rc; 1772 1773 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid); 1774 1775 rc = bnx2x_vf_free(bp, vf); 1776 bnx2x_vf_mbx_resp(bp, vf, rc); 1777} 1778 1779static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf, 1780 struct bnx2x_vf_mbx *mbx) 1781{ 1782 struct bnx2x_config_rss_params rss; 1783 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss; 1784 int rc = 0; 1785 1786 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE || 1787 rss_tlv->rss_key_size != T_ETH_RSS_KEY) { 1788 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n", 1789 vf->index); 1790 rc = -EINVAL; 1791 goto mbx_resp; 1792 } 1793 1794 memset(&rss, 0, sizeof(struct bnx2x_config_rss_params)); 1795 1796 /* set vfop params according to rss tlv */ 1797 memcpy(rss.ind_table, rss_tlv->ind_table, 1798 T_ETH_INDIRECTION_TABLE_SIZE); 1799 memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key)); 1800 rss.rss_obj = &vf->rss_conf_obj; 1801 rss.rss_result_mask = rss_tlv->rss_result_mask; 1802 1803 /* flags handled individually for backward/forward compatability */ 1804 rss.rss_flags = 0; 1805 rss.ramrod_flags = 0; 1806 1807 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED) 1808 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags); 1809 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR) 1810 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags); 1811 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH) 1812 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags); 1813 if (rss_tlv->rss_flags & VFPF_RSS_IPV4) 1814 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags); 1815 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) 1816 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags); 1817 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) 1818 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags); 1819 if (rss_tlv->rss_flags & VFPF_RSS_IPV6) 1820 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags); 1821 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) 1822 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags); 1823 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP) 1824 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags); 1825 1826 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) && 1827 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) || 1828 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) && 1829 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) { 1830 BNX2X_ERR("about to hit a FW assert. aborting...\n"); 1831 rc = -EINVAL; 1832 goto mbx_resp; 1833 } 1834 1835 rc = bnx2x_vf_rss_update(bp, vf, &rss); 1836mbx_resp: 1837 bnx2x_vf_mbx_resp(bp, vf, rc); 1838} 1839 1840static int bnx2x_validate_tpa_params(struct bnx2x *bp, 1841 struct vfpf_tpa_tlv *tpa_tlv) 1842{ 1843 int rc = 0; 1844 1845 if (tpa_tlv->tpa_client_info.max_sges_for_packet > 1846 U_ETH_MAX_SGES_FOR_PACKET) { 1847 rc = -EINVAL; 1848 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n", 1849 tpa_tlv->tpa_client_info.max_sges_for_packet, 1850 U_ETH_MAX_SGES_FOR_PACKET); 1851 } 1852 1853 if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) { 1854 rc = -EINVAL; 1855 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n", 1856 tpa_tlv->tpa_client_info.max_tpa_queues, 1857 MAX_AGG_QS(bp)); 1858 } 1859 1860 return rc; 1861} 1862 1863static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf, 1864 struct bnx2x_vf_mbx *mbx) 1865{ 1866 struct bnx2x_queue_update_tpa_params vf_op_params; 1867 struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa; 1868 int rc = 0; 1869 1870 memset(&vf_op_params, 0, sizeof(vf_op_params)); 1871 1872 if (bnx2x_validate_tpa_params(bp, tpa_tlv)) 1873 goto mbx_resp; 1874 1875 vf_op_params.complete_on_both_clients = 1876 tpa_tlv->tpa_client_info.complete_on_both_clients; 1877 vf_op_params.dont_verify_thr = 1878 tpa_tlv->tpa_client_info.dont_verify_thr; 1879 vf_op_params.max_agg_sz = 1880 tpa_tlv->tpa_client_info.max_agg_size; 1881 vf_op_params.max_sges_pkt = 1882 tpa_tlv->tpa_client_info.max_sges_for_packet; 1883 vf_op_params.max_tpa_queues = 1884 tpa_tlv->tpa_client_info.max_tpa_queues; 1885 vf_op_params.sge_buff_sz = 1886 tpa_tlv->tpa_client_info.sge_buff_size; 1887 vf_op_params.sge_pause_thr_high = 1888 tpa_tlv->tpa_client_info.sge_pause_thr_high; 1889 vf_op_params.sge_pause_thr_low = 1890 tpa_tlv->tpa_client_info.sge_pause_thr_low; 1891 vf_op_params.tpa_mode = 1892 tpa_tlv->tpa_client_info.tpa_mode; 1893 vf_op_params.update_ipv4 = 1894 tpa_tlv->tpa_client_info.update_ipv4; 1895 vf_op_params.update_ipv6 = 1896 tpa_tlv->tpa_client_info.update_ipv6; 1897 1898 rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params); 1899 1900mbx_resp: 1901 bnx2x_vf_mbx_resp(bp, vf, rc); 1902} 1903 1904/* dispatch request */ 1905static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf, 1906 struct bnx2x_vf_mbx *mbx) 1907{ 1908 int i; 1909 1910 /* check if tlv type is known */ 1911 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) { 1912 /* Lock the per vf op mutex and note the locker's identity. 1913 * The unlock will take place in mbx response. 1914 */ 1915 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); 1916 1917 /* switch on the opcode */ 1918 switch (mbx->first_tlv.tl.type) { 1919 case CHANNEL_TLV_ACQUIRE: 1920 bnx2x_vf_mbx_acquire(bp, vf, mbx); 1921 return; 1922 case CHANNEL_TLV_INIT: 1923 bnx2x_vf_mbx_init_vf(bp, vf, mbx); 1924 return; 1925 case CHANNEL_TLV_SETUP_Q: 1926 bnx2x_vf_mbx_setup_q(bp, vf, mbx); 1927 return; 1928 case CHANNEL_TLV_SET_Q_FILTERS: 1929 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx); 1930 return; 1931 case CHANNEL_TLV_TEARDOWN_Q: 1932 bnx2x_vf_mbx_teardown_q(bp, vf, mbx); 1933 return; 1934 case CHANNEL_TLV_CLOSE: 1935 bnx2x_vf_mbx_close_vf(bp, vf, mbx); 1936 return; 1937 case CHANNEL_TLV_RELEASE: 1938 bnx2x_vf_mbx_release_vf(bp, vf, mbx); 1939 return; 1940 case CHANNEL_TLV_UPDATE_RSS: 1941 bnx2x_vf_mbx_update_rss(bp, vf, mbx); 1942 return; 1943 case CHANNEL_TLV_UPDATE_TPA: 1944 bnx2x_vf_mbx_update_tpa(bp, vf, mbx); 1945 return; 1946 } 1947 1948 } else { 1949 /* unknown TLV - this may belong to a VF driver from the future 1950 * - a version written after this PF driver was written, which 1951 * supports features unknown as of yet. Too bad since we don't 1952 * support them. Or this may be because someone wrote a crappy 1953 * VF driver and is sending garbage over the channel. 1954 */ 1955 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n", 1956 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length, 1957 vf->state); 1958 for (i = 0; i < 20; i++) 1959 DP_CONT(BNX2X_MSG_IOV, "%x ", 1960 mbx->msg->req.tlv_buf_size.tlv_buffer[i]); 1961 } 1962 1963 /* can we respond to VF (do we have an address for it?) */ 1964 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) { 1965 /* notify the VF that we do not support this request */ 1966 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED); 1967 } else { 1968 /* can't send a response since this VF is unknown to us 1969 * just ack the FW to release the mailbox and unlock 1970 * the channel. 1971 */ 1972 storm_memset_vf_mbx_ack(bp, vf->abs_vfid); 1973 /* Firmware ack should be written before unlocking channel */ 1974 mmiowb(); 1975 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); 1976 } 1977} 1978 1979void bnx2x_vf_mbx_schedule(struct bnx2x *bp, 1980 struct vf_pf_event_data *vfpf_event) 1981{ 1982 u8 vf_idx; 1983 1984 DP(BNX2X_MSG_IOV, 1985 "vf pf event received: vfid %d, address_hi %x, address lo %x", 1986 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo); 1987 /* Sanity checks consider removing later */ 1988 1989 /* check if the vf_id is valid */ 1990 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf > 1991 BNX2X_NR_VIRTFN(bp)) { 1992 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n", 1993 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp)); 1994 return; 1995 } 1996 1997 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id); 1998 1999 /* Update VFDB with current message and schedule its handling */ 2000 mutex_lock(&BP_VFDB(bp)->event_mutex); 2001 BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi; 2002 BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo; 2003 BP_VFDB(bp)->event_occur |= (1ULL << vf_idx); 2004 mutex_unlock(&BP_VFDB(bp)->event_mutex); 2005 2006 bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG); 2007} 2008 2009/* handle new vf-pf messages */ 2010void bnx2x_vf_mbx(struct bnx2x *bp) 2011{ 2012 struct bnx2x_vfdb *vfdb = BP_VFDB(bp); 2013 u64 events; 2014 u8 vf_idx; 2015 int rc; 2016 2017 if (!vfdb) 2018 return; 2019 2020 mutex_lock(&vfdb->event_mutex); 2021 events = vfdb->event_occur; 2022 vfdb->event_occur = 0; 2023 mutex_unlock(&vfdb->event_mutex); 2024 2025 for_each_vf(bp, vf_idx) { 2026 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx); 2027 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx); 2028 2029 /* Handle VFs which have pending events */ 2030 if (!(events & (1ULL << vf_idx))) 2031 continue; 2032 2033 DP(BNX2X_MSG_IOV, 2034 "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n", 2035 vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo, 2036 mbx->first_tlv.resp_msg_offset); 2037 2038 /* dmae to get the VF request */ 2039 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, 2040 vf->abs_vfid, mbx->vf_addr_hi, 2041 mbx->vf_addr_lo, 2042 sizeof(union vfpf_tlvs)/4); 2043 if (rc) { 2044 BNX2X_ERR("Failed to copy request VF %d\n", 2045 vf->abs_vfid); 2046 bnx2x_vf_release(bp, vf); 2047 return; 2048 } 2049 2050 /* process the VF message header */ 2051 mbx->first_tlv = mbx->msg->req.first_tlv; 2052 2053 /* Clean response buffer to refrain from falsely 2054 * seeing chains. 2055 */ 2056 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs)); 2057 2058 /* dispatch the request (will prepare the response) */ 2059 bnx2x_vf_mbx_request(bp, vf, mbx); 2060 } 2061} 2062 2063void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin, 2064 bool support_long) 2065{ 2066 /* Older VFs contain a bug where they can't check CRC for bulletin 2067 * boards of length greater than legacy size. 2068 */ 2069 bulletin->length = support_long ? BULLETIN_CONTENT_SIZE : 2070 BULLETIN_CONTENT_LEGACY_SIZE; 2071 bulletin->crc = bnx2x_crc_vf_bulletin(bulletin); 2072} 2073 2074/* propagate local bulletin board to vf */ 2075int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf) 2076{ 2077 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf); 2078 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping + 2079 vf * BULLETIN_CONTENT_SIZE; 2080 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map); 2081 int rc; 2082 2083 /* can only update vf after init took place */ 2084 if (bnx2x_vf(bp, vf, state) != VF_ENABLED && 2085 bnx2x_vf(bp, vf, state) != VF_ACQUIRED) 2086 return 0; 2087 2088 /* increment bulletin board version and compute crc */ 2089 bulletin->version++; 2090 bnx2x_vf_bulletin_finalize(bulletin, 2091 (bnx2x_vf(bp, vf, cfg_flags) & 2092 VF_CFG_EXT_BULLETIN) ? true : false); 2093 2094 /* propagate bulletin board via dmae to vm memory */ 2095 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, 2096 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr), 2097 U64_LO(vf_addr), bulletin->length / 4); 2098 return rc; 2099} 2100