Lines Matching refs:bp

22 static int bnxt_vf_ndo_prep(struct bnxt *bp, int vf_id)  in bnxt_vf_ndo_prep()  argument
24 if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { in bnxt_vf_ndo_prep()
25 netdev_err(bp->dev, "vf ndo called though PF is down\n"); in bnxt_vf_ndo_prep()
28 if (!bp->pf.active_vfs) { in bnxt_vf_ndo_prep()
29 netdev_err(bp->dev, "vf ndo called though sriov is disabled\n"); in bnxt_vf_ndo_prep()
32 if (vf_id >= bp->pf.max_vfs) { in bnxt_vf_ndo_prep()
33 netdev_err(bp->dev, "Invalid VF id %d\n", vf_id); in bnxt_vf_ndo_prep()
42 struct bnxt *bp = netdev_priv(dev); in bnxt_set_vf_spoofchk() local
48 rc = bnxt_vf_ndo_prep(bp, vf_id); in bnxt_set_vf_spoofchk()
52 vf = &bp->pf.vf[vf_id]; in bnxt_set_vf_spoofchk()
66 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); in bnxt_set_vf_spoofchk()
69 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_set_vf_spoofchk()
83 struct bnxt *bp = netdev_priv(dev); in bnxt_get_vf_config() local
87 rc = bnxt_vf_ndo_prep(bp, vf_id); in bnxt_get_vf_config()
92 vf = &bp->pf.vf[vf_id]; in bnxt_get_vf_config()
113 struct bnxt *bp = netdev_priv(dev); in bnxt_set_vf_mac() local
117 rc = bnxt_vf_ndo_prep(bp, vf_id); in bnxt_set_vf_mac()
127 vf = &bp->pf.vf[vf_id]; in bnxt_set_vf_mac()
130 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); in bnxt_set_vf_mac()
135 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_set_vf_mac()
141 struct bnxt *bp = netdev_priv(dev); in bnxt_set_vf_vlan() local
146 rc = bnxt_vf_ndo_prep(bp, vf_id); in bnxt_set_vf_vlan()
156 vf = &bp->pf.vf[vf_id]; in bnxt_set_vf_vlan()
161 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); in bnxt_set_vf_vlan()
166 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_set_vf_vlan()
176 struct bnxt *bp = netdev_priv(dev); in bnxt_set_vf_bw() local
181 rc = bnxt_vf_ndo_prep(bp, vf_id); in bnxt_set_vf_bw()
185 vf = &bp->pf.vf[vf_id]; in bnxt_set_vf_bw()
186 pf_link_speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed); in bnxt_set_vf_bw()
188 netdev_info(bp->dev, "max tx rate %d exceed PF link speed for VF %d\n", in bnxt_set_vf_bw()
194 netdev_info(bp->dev, "min tx rate %d is invalid for VF %d\n", in bnxt_set_vf_bw()
200 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); in bnxt_set_vf_bw()
207 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_set_vf_bw()
217 struct bnxt *bp = netdev_priv(dev); in bnxt_set_vf_link_state() local
221 rc = bnxt_vf_ndo_prep(bp, vf_id); in bnxt_set_vf_link_state()
225 vf = &bp->pf.vf[vf_id]; in bnxt_set_vf_link_state()
239 netdev_err(bp->dev, "Invalid link option\n"); in bnxt_set_vf_link_state()
248 static int bnxt_set_vf_attr(struct bnxt *bp, int num_vfs) in bnxt_set_vf_attr() argument
254 vf = &bp->pf.vf[i]; in bnxt_set_vf_attr()
261 static int bnxt_hwrm_func_vf_resource_free(struct bnxt *bp, int num_vfs) in bnxt_hwrm_func_vf_resource_free() argument
264 struct bnxt_pf_info *pf = &bp->pf; in bnxt_hwrm_func_vf_resource_free()
267 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_RESC_FREE, -1, -1); in bnxt_hwrm_func_vf_resource_free()
269 mutex_lock(&bp->hwrm_cmd_lock); in bnxt_hwrm_func_vf_resource_free()
272 rc = _hwrm_send_message(bp, &req, sizeof(req), in bnxt_hwrm_func_vf_resource_free()
277 mutex_unlock(&bp->hwrm_cmd_lock); in bnxt_hwrm_func_vf_resource_free()
281 static void bnxt_free_vf_resources(struct bnxt *bp) in bnxt_free_vf_resources() argument
283 struct pci_dev *pdev = bp->pdev; in bnxt_free_vf_resources()
286 kfree(bp->pf.vf_event_bmap); in bnxt_free_vf_resources()
287 bp->pf.vf_event_bmap = NULL; in bnxt_free_vf_resources()
290 if (bp->pf.hwrm_cmd_req_addr[i]) { in bnxt_free_vf_resources()
292 bp->pf.hwrm_cmd_req_addr[i], in bnxt_free_vf_resources()
293 bp->pf.hwrm_cmd_req_dma_addr[i]); in bnxt_free_vf_resources()
294 bp->pf.hwrm_cmd_req_addr[i] = NULL; in bnxt_free_vf_resources()
298 kfree(bp->pf.vf); in bnxt_free_vf_resources()
299 bp->pf.vf = NULL; in bnxt_free_vf_resources()
302 static int bnxt_alloc_vf_resources(struct bnxt *bp, int num_vfs) in bnxt_alloc_vf_resources() argument
304 struct pci_dev *pdev = bp->pdev; in bnxt_alloc_vf_resources()
307 bp->pf.vf = kcalloc(num_vfs, sizeof(struct bnxt_vf_info), GFP_KERNEL); in bnxt_alloc_vf_resources()
308 if (!bp->pf.vf) in bnxt_alloc_vf_resources()
311 bnxt_set_vf_attr(bp, num_vfs); in bnxt_alloc_vf_resources()
319 bp->pf.hwrm_cmd_req_addr[i] = in bnxt_alloc_vf_resources()
321 &bp->pf.hwrm_cmd_req_dma_addr[i], in bnxt_alloc_vf_resources()
324 if (!bp->pf.hwrm_cmd_req_addr[i]) in bnxt_alloc_vf_resources()
328 struct bnxt_vf_info *vf = &bp->pf.vf[k]; in bnxt_alloc_vf_resources()
330 vf->hwrm_cmd_req_addr = bp->pf.hwrm_cmd_req_addr[i] + in bnxt_alloc_vf_resources()
333 bp->pf.hwrm_cmd_req_dma_addr[i] + j * in bnxt_alloc_vf_resources()
340 bp->pf.vf_event_bmap = kzalloc(16, GFP_KERNEL); in bnxt_alloc_vf_resources()
341 if (!bp->pf.vf_event_bmap) in bnxt_alloc_vf_resources()
344 bp->pf.hwrm_cmd_req_pages = nr_pages; in bnxt_alloc_vf_resources()
348 static int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp) in bnxt_hwrm_func_buf_rgtr() argument
352 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_BUF_RGTR, -1, -1); in bnxt_hwrm_func_buf_rgtr()
354 req.req_buf_num_pages = cpu_to_le16(bp->pf.hwrm_cmd_req_pages); in bnxt_hwrm_func_buf_rgtr()
357 req.req_buf_page_addr0 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[0]); in bnxt_hwrm_func_buf_rgtr()
358 req.req_buf_page_addr1 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[1]); in bnxt_hwrm_func_buf_rgtr()
359 req.req_buf_page_addr2 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[2]); in bnxt_hwrm_func_buf_rgtr()
360 req.req_buf_page_addr3 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[3]); in bnxt_hwrm_func_buf_rgtr()
362 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_hwrm_func_buf_rgtr()
366 static int bnxt_hwrm_func_cfg(struct bnxt *bp, int *num_vfs) in bnxt_hwrm_func_cfg() argument
371 struct bnxt_pf_info *pf = &bp->pf; in bnxt_hwrm_func_cfg()
373 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); in bnxt_hwrm_func_cfg()
381 vf_cp_rings = min_t(u16, bp->pf.max_cp_rings, bp->pf.max_stat_ctxs); in bnxt_hwrm_func_cfg()
382 vf_cp_rings = (vf_cp_rings - bp->cp_nr_rings) / *num_vfs; in bnxt_hwrm_func_cfg()
385 vf_stat_ctx = (bp->pf.max_stat_ctxs - bp->num_stat_ctxs) / *num_vfs; in bnxt_hwrm_func_cfg()
386 if (bp->flags & BNXT_FLAG_AGG_RINGS) in bnxt_hwrm_func_cfg()
387 vf_rx_rings = (bp->pf.max_rx_rings - bp->rx_nr_rings * 2) / in bnxt_hwrm_func_cfg()
390 vf_rx_rings = (bp->pf.max_rx_rings - bp->rx_nr_rings) / in bnxt_hwrm_func_cfg()
392 vf_tx_rings = (bp->pf.max_tx_rings - bp->tx_nr_rings) / *num_vfs; in bnxt_hwrm_func_cfg()
404 mtu = bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; in bnxt_hwrm_func_cfg()
419 mutex_lock(&bp->hwrm_cmd_lock); in bnxt_hwrm_func_cfg()
422 rc = _hwrm_send_message(bp, &req, sizeof(req), in bnxt_hwrm_func_cfg()
426 bp->pf.active_vfs = i + 1; in bnxt_hwrm_func_cfg()
427 bp->pf.vf[i].fw_fid = le16_to_cpu(req.vf_id); in bnxt_hwrm_func_cfg()
429 mutex_unlock(&bp->hwrm_cmd_lock); in bnxt_hwrm_func_cfg()
431 bp->pf.max_pf_tx_rings = bp->tx_nr_rings; in bnxt_hwrm_func_cfg()
432 if (bp->flags & BNXT_FLAG_AGG_RINGS) in bnxt_hwrm_func_cfg()
433 bp->pf.max_pf_rx_rings = bp->rx_nr_rings * 2; in bnxt_hwrm_func_cfg()
435 bp->pf.max_pf_rx_rings = bp->rx_nr_rings; in bnxt_hwrm_func_cfg()
440 static int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs) in bnxt_sriov_enable() argument
457 if (bp->flags & BNXT_FLAG_AGG_RINGS) { in bnxt_sriov_enable()
458 if (bp->pf.max_rx_rings - bp->rx_nr_rings * 2 >= in bnxt_sriov_enable()
462 if (bp->pf.max_rx_rings - bp->rx_nr_rings >= in bnxt_sriov_enable()
467 if (bp->pf.max_tx_rings - bp->tx_nr_rings >= min_tx_rings) in bnxt_sriov_enable()
470 if (bp->pf.max_rsscos_ctxs - bp->rsscos_nr_ctxs >= min_rss_ctxs) in bnxt_sriov_enable()
480 netdev_err(bp->dev, "Cannot enable VF's as all resources are used by PF\n"); in bnxt_sriov_enable()
485 netdev_info(bp->dev, "Requested VFs %d, can enable %d\n", in bnxt_sriov_enable()
490 rc = bnxt_alloc_vf_resources(bp, *num_vfs); in bnxt_sriov_enable()
495 rc = bnxt_hwrm_func_cfg(bp, num_vfs); in bnxt_sriov_enable()
500 rc = bnxt_hwrm_func_buf_rgtr(bp); in bnxt_sriov_enable()
504 rc = pci_enable_sriov(bp->pdev, *num_vfs); in bnxt_sriov_enable()
512 bnxt_hwrm_func_vf_resource_free(bp, *num_vfs); in bnxt_sriov_enable()
515 bnxt_free_vf_resources(bp); in bnxt_sriov_enable()
520 void bnxt_sriov_disable(struct bnxt *bp) in bnxt_sriov_disable() argument
522 u16 num_vfs = pci_num_vf(bp->pdev); in bnxt_sriov_disable()
527 if (pci_vfs_assigned(bp->pdev)) { in bnxt_sriov_disable()
528 netdev_warn(bp->dev, "Unable to free %d VFs because some are assigned to VMs.\n", in bnxt_sriov_disable()
531 pci_disable_sriov(bp->pdev); in bnxt_sriov_disable()
533 bnxt_hwrm_func_vf_resource_free(bp, num_vfs); in bnxt_sriov_disable()
536 bnxt_free_vf_resources(bp); in bnxt_sriov_disable()
538 bp->pf.active_vfs = 0; in bnxt_sriov_disable()
539 bp->pf.max_pf_rx_rings = bp->pf.max_rx_rings; in bnxt_sriov_disable()
540 bp->pf.max_pf_tx_rings = bp->pf.max_tx_rings; in bnxt_sriov_disable()
546 struct bnxt *bp = netdev_priv(dev); in bnxt_sriov_configure() local
548 if (!(bp->flags & BNXT_FLAG_USING_MSIX)) { in bnxt_sriov_configure()
559 bp->sriov_cfg = true; in bnxt_sriov_configure()
562 if (pci_vfs_assigned(bp->pdev)) { in bnxt_sriov_configure()
569 if (num_vfs && num_vfs == bp->pf.active_vfs) in bnxt_sriov_configure()
573 bnxt_sriov_disable(bp); in bnxt_sriov_configure()
577 bnxt_sriov_enable(bp, &num_vfs); in bnxt_sriov_configure()
580 bp->sriov_cfg = false; in bnxt_sriov_configure()
581 wake_up(&bp->sriov_cfg_wait); in bnxt_sriov_configure()
586 static int bnxt_hwrm_fwd_resp(struct bnxt *bp, struct bnxt_vf_info *vf, in bnxt_hwrm_fwd_resp() argument
592 struct hwrm_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr; in bnxt_hwrm_fwd_resp()
594 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FWD_RESP, -1, -1); in bnxt_hwrm_fwd_resp()
603 mutex_lock(&bp->hwrm_cmd_lock); in bnxt_hwrm_fwd_resp()
604 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_hwrm_fwd_resp()
607 netdev_err(bp->dev, "hwrm_fwd_resp failed. rc:%d\n", rc); in bnxt_hwrm_fwd_resp()
612 netdev_err(bp->dev, "hwrm_fwd_resp error %d\n", in bnxt_hwrm_fwd_resp()
618 mutex_unlock(&bp->hwrm_cmd_lock); in bnxt_hwrm_fwd_resp()
622 static int bnxt_hwrm_fwd_err_resp(struct bnxt *bp, struct bnxt_vf_info *vf, in bnxt_hwrm_fwd_err_resp() argument
627 struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr; in bnxt_hwrm_fwd_err_resp()
629 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_REJECT_FWD_RESP, -1, -1); in bnxt_hwrm_fwd_err_resp()
634 mutex_lock(&bp->hwrm_cmd_lock); in bnxt_hwrm_fwd_err_resp()
635 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_hwrm_fwd_err_resp()
638 netdev_err(bp->dev, "hwrm_fwd_err_resp failed. rc:%d\n", rc); in bnxt_hwrm_fwd_err_resp()
643 netdev_err(bp->dev, "hwrm_fwd_err_resp error %d\n", in bnxt_hwrm_fwd_err_resp()
649 mutex_unlock(&bp->hwrm_cmd_lock); in bnxt_hwrm_fwd_err_resp()
653 static int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, struct bnxt_vf_info *vf, in bnxt_hwrm_exec_fwd_resp() argument
658 struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr; in bnxt_hwrm_exec_fwd_resp()
660 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_EXEC_FWD_RESP, -1, -1); in bnxt_hwrm_exec_fwd_resp()
665 mutex_lock(&bp->hwrm_cmd_lock); in bnxt_hwrm_exec_fwd_resp()
666 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); in bnxt_hwrm_exec_fwd_resp()
669 netdev_err(bp->dev, "hwrm_exec_fw_resp failed. rc:%d\n", rc); in bnxt_hwrm_exec_fwd_resp()
674 netdev_err(bp->dev, "hwrm_exec_fw_resp error %d\n", in bnxt_hwrm_exec_fwd_resp()
680 mutex_unlock(&bp->hwrm_cmd_lock); in bnxt_hwrm_exec_fwd_resp()
684 static int bnxt_vf_validate_set_mac(struct bnxt *bp, struct bnxt_vf_info *vf) in bnxt_vf_validate_set_mac() argument
692 return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size); in bnxt_vf_validate_set_mac()
694 return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size); in bnxt_vf_validate_set_mac()
697 static int bnxt_vf_set_link(struct bnxt *bp, struct bnxt_vf_info *vf) in bnxt_vf_set_link() argument
704 bp, vf, sizeof(struct hwrm_port_phy_qcfg_input)); in bnxt_vf_set_link()
711 mutex_lock(&bp->hwrm_cmd_lock); in bnxt_vf_set_link()
712 memcpy(&phy_qcfg_resp, &bp->link_info.phy_qcfg_resp, in bnxt_vf_set_link()
714 mutex_unlock(&bp->hwrm_cmd_lock); in bnxt_vf_set_link()
742 rc = bnxt_hwrm_fwd_resp(bp, vf, &phy_qcfg_resp, in bnxt_vf_set_link()
750 static int bnxt_vf_req_validate_snd(struct bnxt *bp, struct bnxt_vf_info *vf) in bnxt_vf_req_validate_snd() argument
758 rc = bnxt_vf_validate_set_mac(bp, vf); in bnxt_vf_req_validate_snd()
765 bp, vf, sizeof(struct hwrm_func_cfg_input)); in bnxt_vf_req_validate_snd()
768 rc = bnxt_vf_set_link(bp, vf); in bnxt_vf_req_validate_snd()
776 void bnxt_hwrm_exec_fwd_req(struct bnxt *bp) in bnxt_hwrm_exec_fwd_req() argument
778 u32 i = 0, active_vfs = bp->pf.active_vfs, vf_id; in bnxt_hwrm_exec_fwd_req()
782 vf_id = find_next_bit(bp->pf.vf_event_bmap, active_vfs, i); in bnxt_hwrm_exec_fwd_req()
786 clear_bit(vf_id, bp->pf.vf_event_bmap); in bnxt_hwrm_exec_fwd_req()
787 bnxt_vf_req_validate_snd(bp, &bp->pf.vf[vf_id]); in bnxt_hwrm_exec_fwd_req()
792 void bnxt_update_vf_mac(struct bnxt *bp) in bnxt_update_vf_mac() argument
795 struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr; in bnxt_update_vf_mac()
797 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1); in bnxt_update_vf_mac()
800 mutex_lock(&bp->hwrm_cmd_lock); in bnxt_update_vf_mac()
801 if (_hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT)) in bnxt_update_vf_mac()
807 if (!ether_addr_equal(resp->perm_mac_address, bp->vf.mac_addr)) in bnxt_update_vf_mac()
808 memcpy(bp->vf.mac_addr, resp->perm_mac_address, ETH_ALEN); in bnxt_update_vf_mac()
810 memcpy(bp->dev->dev_addr, bp->vf.mac_addr, ETH_ALEN); in bnxt_update_vf_mac()
812 mutex_unlock(&bp->hwrm_cmd_lock); in bnxt_update_vf_mac()
817 void bnxt_sriov_disable(struct bnxt *bp) in bnxt_sriov_disable() argument
821 void bnxt_hwrm_exec_fwd_req(struct bnxt *bp) in bnxt_hwrm_exec_fwd_req() argument
823 netdev_err(bp->dev, "Invalid VF message received when SRIOV is not enable\n"); in bnxt_hwrm_exec_fwd_req()
826 void bnxt_update_vf_mac(struct bnxt *bp) in bnxt_update_vf_mac() argument