Lines Matching full:nic
14 #include "nic.h"
73 MODULE_DESCRIPTION("Cavium Thunder NIC Physical Function Driver");
88 static void nic_reg_write(struct nicpf *nic, u64 offset, u64 val) in nic_reg_write() argument
90 writeq_relaxed(val, nic->reg_base + offset); in nic_reg_write()
93 static u64 nic_reg_read(struct nicpf *nic, u64 offset) in nic_reg_read() argument
95 return readq_relaxed(nic->reg_base + offset); in nic_reg_read()
99 static void nic_enable_mbx_intr(struct nicpf *nic) in nic_enable_mbx_intr() argument
101 int vf_cnt = pci_sriov_get_totalvfs(nic->pdev); in nic_enable_mbx_intr()
106 nic_reg_write(nic, NIC_PF_MAILBOX_INT, INTR_MASK(vf_cnt)); in nic_enable_mbx_intr()
109 nic_reg_write(nic, NIC_PF_MAILBOX_ENA_W1S, INTR_MASK(vf_cnt)); in nic_enable_mbx_intr()
112 nic_reg_write(nic, NIC_PF_MAILBOX_INT + sizeof(u64), in nic_enable_mbx_intr()
114 nic_reg_write(nic, NIC_PF_MAILBOX_ENA_W1S + sizeof(u64), in nic_enable_mbx_intr()
119 static void nic_clear_mbx_intr(struct nicpf *nic, int vf, int mbx_reg) in nic_clear_mbx_intr() argument
121 nic_reg_write(nic, NIC_PF_MAILBOX_INT + (mbx_reg << 3), BIT_ULL(vf)); in nic_clear_mbx_intr()
133 static void nic_send_msg_to_vf(struct nicpf *nic, int vf, union nic_mbx *mbx) in nic_send_msg_to_vf() argument
135 void __iomem *mbx_addr = nic->reg_base + nic_get_mbx_addr(vf); in nic_send_msg_to_vf()
142 if (pass1_silicon(nic->pdev)) { in nic_send_msg_to_vf()
158 static void nic_mbx_send_ready(struct nicpf *nic, int vf) in nic_mbx_send_ready() argument
169 if (vf < nic->num_vf_en) { in nic_mbx_send_ready()
170 bgx_idx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_mbx_send_ready()
171 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_mbx_send_ready()
173 mac = bgx_get_lmac_mac(nic->node, bgx_idx, lmac); in nic_mbx_send_ready()
177 mbx.nic_cfg.sqs_mode = (vf >= nic->num_vf_en) ? true : false; in nic_mbx_send_ready()
178 mbx.nic_cfg.node_id = nic->node; in nic_mbx_send_ready()
180 mbx.nic_cfg.loopback_supported = vf < nic->num_vf_en; in nic_mbx_send_ready()
182 nic_send_msg_to_vf(nic, vf, &mbx); in nic_mbx_send_ready()
188 static void nic_mbx_send_ack(struct nicpf *nic, int vf) in nic_mbx_send_ack() argument
193 nic_send_msg_to_vf(nic, vf, &mbx); in nic_mbx_send_ack()
200 static void nic_mbx_send_nack(struct nicpf *nic, int vf) in nic_mbx_send_nack() argument
205 nic_send_msg_to_vf(nic, vf, &mbx); in nic_mbx_send_nack()
211 static int nic_rcv_queue_sw_sync(struct nicpf *nic) in nic_rcv_queue_sw_sync() argument
215 nic_reg_write(nic, NIC_PF_SW_SYNC_RX, 0x01); in nic_rcv_queue_sw_sync()
218 if (nic_reg_read(nic, NIC_PF_SW_SYNC_RX_DONE) & 0x1) in nic_rcv_queue_sw_sync()
222 nic_reg_write(nic, NIC_PF_SW_SYNC_RX, 0x00); in nic_rcv_queue_sw_sync()
224 dev_err(&nic->pdev->dev, "Receive queue software sync failed"); in nic_rcv_queue_sw_sync()
231 static void nic_get_bgx_stats(struct nicpf *nic, struct bgx_stats_msg *bgx) in nic_get_bgx_stats() argument
236 bgx_idx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[bgx->vf_id]); in nic_get_bgx_stats()
237 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[bgx->vf_id]); in nic_get_bgx_stats()
244 mbx.bgx_stats.stats = bgx_get_rx_stats(nic->node, bgx_idx, in nic_get_bgx_stats()
247 mbx.bgx_stats.stats = bgx_get_tx_stats(nic->node, bgx_idx, in nic_get_bgx_stats()
249 nic_send_msg_to_vf(nic, bgx->vf_id, &mbx); in nic_get_bgx_stats()
253 static int nic_update_hw_frs(struct nicpf *nic, int new_frs, int vf) in nic_update_hw_frs() argument
261 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_update_hw_frs()
262 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_update_hw_frs()
268 lmac_cnt = bgx_get_lmac_count(nic->node, bgx); in nic_update_hw_frs()
269 lmac_credits = nic_reg_read(nic, NIC_PF_LMAC_0_7_CREDIT + (lmac * 8)); in nic_update_hw_frs()
272 nic_reg_write(nic, NIC_PF_LMAC_0_7_CREDIT + (lmac * 8), lmac_credits); in nic_update_hw_frs()
277 if (!pass1_silicon(nic->pdev)) in nic_update_hw_frs()
278 nic_reg_write(nic, in nic_update_hw_frs()
284 static void nic_set_tx_pkt_pad(struct nicpf *nic, int size) in nic_set_tx_pkt_pad() argument
292 * NIC will zero PAD packet and also updates IP total length. in nic_set_tx_pkt_pad()
299 pci_read_config_word(nic->pdev, PCI_SUBSYSTEM_ID, &sdevid); in nic_set_tx_pkt_pad()
302 max_lmac = ((nic->hw->bgx_cnt - 1) * MAX_LMAC_PER_BGX) + 1; in nic_set_tx_pkt_pad()
304 max_lmac = nic->hw->bgx_cnt * MAX_LMAC_PER_BGX; in nic_set_tx_pkt_pad()
307 lmac_cfg = nic_reg_read(nic, NIC_PF_LMAC_0_7_CFG | (lmac << 3)); in nic_set_tx_pkt_pad()
310 nic_reg_write(nic, NIC_PF_LMAC_0_7_CFG | (lmac << 3), lmac_cfg); in nic_set_tx_pkt_pad()
317 static void nic_set_lmac_vf_mapping(struct nicpf *nic) in nic_set_lmac_vf_mapping() argument
319 unsigned bgx_map = bgx_get_map(nic->node); in nic_set_lmac_vf_mapping()
324 nic->num_vf_en = 0; in nic_set_lmac_vf_mapping()
326 for (bgx = 0; bgx < nic->hw->bgx_cnt; bgx++) { in nic_set_lmac_vf_mapping()
329 lmac_cnt = bgx_get_lmac_count(nic->node, bgx); in nic_set_lmac_vf_mapping()
331 nic->vf_lmac_map[next_bgx_lmac++] = in nic_set_lmac_vf_mapping()
333 nic->num_vf_en += lmac_cnt; in nic_set_lmac_vf_mapping()
343 nic_reg_write(nic, in nic_set_lmac_vf_mapping()
350 if (nic->num_vf_en >= pci_sriov_get_totalvfs(nic->pdev)) { in nic_set_lmac_vf_mapping()
351 nic->num_vf_en = pci_sriov_get_totalvfs(nic->pdev); in nic_set_lmac_vf_mapping()
357 static void nic_get_hw_info(struct nicpf *nic) in nic_get_hw_info() argument
360 struct hw_info *hw = nic->hw; in nic_get_hw_info()
362 pci_read_config_word(nic->pdev, PCI_SUBSYSTEM_ID, &sdevid); in nic_get_hw_info()
405 hw->tl4_cnt = MAX_QUEUES_PER_QSET * pci_sriov_get_totalvfs(nic->pdev); in nic_get_hw_info()
411 static void nic_init_hw(struct nicpf *nic) in nic_init_hw() argument
416 /* Enable NIC HW block */ in nic_init_hw()
417 nic_reg_write(nic, NIC_PF_CFG, 0x3); in nic_init_hw()
420 nic_reg_write(nic, NIC_PF_BP_CFG, (1ULL << 6) | 0x03); in nic_init_hw()
425 if (nic->pdev->subsystem_device == PCI_SUBSYS_DEVID_88XX_NIC_PF) { in nic_init_hw()
427 nic_reg_write(nic, NIC_PF_INTF_0_1_SEND_CFG, in nic_init_hw()
430 nic_reg_write(nic, NIC_PF_INTF_0_1_SEND_CFG | (1 << 8), in nic_init_hw()
435 for (i = 0; i < nic->hw->bgx_cnt; i++) in nic_init_hw()
436 nic_reg_write(nic, NIC_PF_INTFX_SEND_CFG | (i << 3), in nic_init_hw()
440 nic_reg_write(nic, NIC_PF_INTF_0_1_BP_CFG, in nic_init_hw()
442 nic_reg_write(nic, NIC_PF_INTF_0_1_BP_CFG + (1 << 8), in nic_init_hw()
446 nic->pkind.minlen = 0; in nic_init_hw()
447 nic->pkind.maxlen = NIC_HW_MAX_FRS + VLAN_ETH_HLEN + ETH_FCS_LEN + 4; in nic_init_hw()
448 nic->pkind.lenerr_en = 1; in nic_init_hw()
449 nic->pkind.rx_hdr = 0; in nic_init_hw()
450 nic->pkind.hdr_sl = 0; in nic_init_hw()
453 nic_reg_write(nic, NIC_PF_PKIND_0_15_CFG | (i << 3), in nic_init_hw()
454 *(u64 *)&nic->pkind); in nic_init_hw()
456 nic_set_tx_pkt_pad(nic, NIC_HW_MIN_FRS); in nic_init_hw()
459 nic_reg_write(nic, NIC_PF_INTR_TIMER_CFG, NICPF_CLK_PER_INT_TICK); in nic_init_hw()
462 nic_reg_write(nic, NIC_PF_RX_ETYPE_0_7, in nic_init_hw()
466 cqm_cfg = nic_reg_read(nic, NIC_PF_CQM_CFG); in nic_init_hw()
468 nic_reg_write(nic, NIC_PF_CQM_CFG, NICPF_CQM_MIN_DROP_LEVEL); in nic_init_hw()
472 static void nic_config_cpi(struct nicpf *nic, struct cpi_cfg_msg *cfg) in nic_config_cpi() argument
474 struct hw_info *hw = nic->hw; in nic_config_cpi()
481 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vnic]); in nic_config_cpi()
482 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vnic]); in nic_config_cpi()
489 nic_reg_write(nic, NIC_PF_CHAN_0_255_RX_BP_CFG | (chan << 3), in nic_config_cpi()
491 nic_reg_write(nic, NIC_PF_CHAN_0_255_RX_CFG | (chan << 3), in nic_config_cpi()
507 nic_reg_write(nic, NIC_PF_RSSI_0_4097_RQ | (rssi << 3), in nic_config_cpi()
522 if (pass1_silicon(nic->pdev)) { in nic_config_cpi()
523 nic_reg_write(nic, NIC_PF_CPI_0_2047_CFG | (cpi << 3), in nic_config_cpi()
528 nic_reg_write(nic, NIC_PF_CPI_0_2047_CFG | (cpi << 3), in nic_config_cpi()
531 nic_reg_write(nic, NIC_PF_MPI_0_2047_CFG | (cpi << 3), in nic_config_cpi()
545 nic->cpi_base[cfg->vf_id] = cpi_base; in nic_config_cpi()
546 nic->rssi_base[cfg->vf_id] = rssi_base; in nic_config_cpi()
550 static void nic_send_rss_size(struct nicpf *nic, int vf) in nic_send_rss_size() argument
555 mbx.rss_size.ind_tbl_size = nic->hw->rss_ind_tbl_size; in nic_send_rss_size()
556 nic_send_msg_to_vf(nic, vf, &mbx); in nic_send_rss_size()
565 static void nic_config_rss(struct nicpf *nic, struct rss_cfg_msg *cfg) in nic_config_rss() argument
571 rssi_base = nic->rssi_base[cfg->vf_id] + cfg->tbl_offset; in nic_config_rss()
579 qset = nic->vf_sqs[cfg->vf_id][svf - 1]; in nic_config_rss()
582 nic_reg_write(nic, NIC_PF_RSSI_0_4097_RQ | (rssi << 3), in nic_config_rss()
587 cpi_base = nic->cpi_base[cfg->vf_id]; in nic_config_rss()
588 if (pass1_silicon(nic->pdev)) in nic_config_rss()
592 cpi_cfg = nic_reg_read(nic, idx_addr | (cpi_base << 3)); in nic_config_rss()
595 nic_reg_write(nic, idx_addr | (cpi_base << 3), cpi_cfg); in nic_config_rss()
611 static void nic_tx_channel_cfg(struct nicpf *nic, u8 vnic, in nic_tx_channel_cfg() argument
614 struct hw_info *hw = nic->hw; in nic_tx_channel_cfg()
623 pqs_vnic = nic->pqs_vf[vnic]; in nic_tx_channel_cfg()
627 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[pqs_vnic]); in nic_tx_channel_cfg()
628 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[pqs_vnic]); in nic_tx_channel_cfg()
642 if (nic->vf_sqs[pqs_vnic][svf] == vnic) in nic_tx_channel_cfg()
655 nic_reg_write(nic, NIC_PF_QSET_0_127_SQ_0_7_CFG2 | in nic_tx_channel_cfg()
658 nic_reg_write(nic, NIC_PF_TL4_0_1023_CFG | (tl4 << 3), in nic_tx_channel_cfg()
661 nic_reg_write(nic, NIC_PF_TL3_0_255_CFG | (tl3 << 3), rr_quantum); in nic_tx_channel_cfg()
671 nic_reg_write(nic, NIC_PF_TL3_0_255_CHAN | (tl3 << 3), chan); in nic_tx_channel_cfg()
673 nic_reg_write(nic, NIC_PF_TL3_0_255_CHAN | (tl3 << 3), 0); in nic_tx_channel_cfg()
676 nic_reg_write(nic, NIC_PF_CHAN_0_255_TX_CFG | (chan << 3), 1); in nic_tx_channel_cfg()
679 nic_reg_write(nic, NIC_PF_TL3A_0_63_CFG | (tl2 << 3), tl2); in nic_tx_channel_cfg()
680 nic_reg_write(nic, NIC_PF_TL2_0_63_CFG | (tl2 << 3), rr_quantum); in nic_tx_channel_cfg()
682 nic_reg_write(nic, NIC_PF_TL2_0_63_PRI | (tl2 << 3), 0x00); in nic_tx_channel_cfg()
691 nic_reg_write(nic, NIC_PF_TL2_LMAC | (tl2 << 3), in nic_tx_channel_cfg()
696 static void nic_send_pnicvf(struct nicpf *nic, int sqs) in nic_send_pnicvf() argument
701 mbx.nicvf.nicvf = nic->nicvf[nic->pqs_vf[sqs]]; in nic_send_pnicvf()
702 nic_send_msg_to_vf(nic, sqs, &mbx); in nic_send_pnicvf()
706 static void nic_send_snicvf(struct nicpf *nic, struct nicvf_ptr *nicvf) in nic_send_snicvf() argument
709 int sqs_id = nic->vf_sqs[nicvf->vf_id][nicvf->sqs_id]; in nic_send_snicvf()
713 mbx.nicvf.nicvf = nic->nicvf[sqs_id]; in nic_send_snicvf()
714 nic_send_msg_to_vf(nic, nicvf->vf_id, &mbx); in nic_send_snicvf()
720 static int nic_nxt_avail_sqs(struct nicpf *nic) in nic_nxt_avail_sqs() argument
724 for (sqs = 0; sqs < nic->num_sqs_en; sqs++) { in nic_nxt_avail_sqs()
725 if (!nic->sqs_used[sqs]) in nic_nxt_avail_sqs()
726 nic->sqs_used[sqs] = true; in nic_nxt_avail_sqs()
729 return sqs + nic->num_vf_en; in nic_nxt_avail_sqs()
735 static void nic_alloc_sqs(struct nicpf *nic, struct sqs_alloc *sqs) in nic_alloc_sqs() argument
741 if (!nic->num_sqs_en) in nic_alloc_sqs()
745 sqs_id = nic_nxt_avail_sqs(nic); in nic_alloc_sqs()
748 nic->vf_sqs[sqs->vf_id][idx] = sqs_id; in nic_alloc_sqs()
749 nic->pqs_vf[sqs_id] = sqs->vf_id; in nic_alloc_sqs()
757 nic_send_msg_to_vf(nic, sqs->vf_id, &mbx); in nic_alloc_sqs()
760 static int nic_config_loopback(struct nicpf *nic, struct set_loopback *lbk) in nic_config_loopback() argument
764 if (lbk->vf_id >= nic->num_vf_en) in nic_config_loopback()
767 bgx_idx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[lbk->vf_id]); in nic_config_loopback()
768 lmac_idx = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[lbk->vf_id]); in nic_config_loopback()
770 bgx_lmac_internal_loopback(nic->node, bgx_idx, lmac_idx, lbk->enable); in nic_config_loopback()
776 nic_reg_write(nic, NIC_PF_CQ_AVG_CFG, in nic_config_loopback()
778 nic_reg_write(nic, NIC_PF_RRM_AVG_CFG, in nic_config_loopback()
785 static int nic_reset_stat_counters(struct nicpf *nic, in nic_reset_stat_counters() argument
796 nic_reg_write(nic, reg_addr, 0); in nic_reset_stat_counters()
805 nic_reg_write(nic, reg_addr, 0); in nic_reset_stat_counters()
816 nic_reg_write(nic, reg_addr, 0); in nic_reset_stat_counters()
820 nic_reg_write(nic, reg_addr, 0); in nic_reset_stat_counters()
827 static void nic_enable_tunnel_parsing(struct nicpf *nic, int vf) in nic_enable_tunnel_parsing() argument
834 nic_reg_write(nic, NIC_PF_RX_GENEVE_DEF, in nic_enable_tunnel_parsing()
836 nic_reg_write(nic, NIC_PF_RX_GENEVE_PROT_DEF, in nic_enable_tunnel_parsing()
838 nic_reg_write(nic, NIC_PF_RX_NVGRE_PROT_DEF, in nic_enable_tunnel_parsing()
840 nic_reg_write(nic, NIC_PF_RX_VXLAN_DEF_0_1, in nic_enable_tunnel_parsing()
842 nic_reg_write(nic, NIC_PF_RX_VXLAN_PROT_DEF, in nic_enable_tunnel_parsing()
846 static void nic_enable_vf(struct nicpf *nic, int vf, bool enable) in nic_enable_vf() argument
850 nic->vf_enabled[vf] = enable; in nic_enable_vf()
852 if (vf >= nic->num_vf_en) in nic_enable_vf()
855 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_enable_vf()
856 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_enable_vf()
858 bgx_lmac_rx_tx_enable(nic->node, bgx, lmac, enable); in nic_enable_vf()
861 static void nic_pause_frame(struct nicpf *nic, int vf, struct pfc *cfg) in nic_pause_frame() argument
867 if (vf >= nic->num_vf_en) in nic_pause_frame()
869 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_pause_frame()
870 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_pause_frame()
873 bgx_lmac_get_pfc(nic->node, bgx, lmac, &pfc); in nic_pause_frame()
878 nic_send_msg_to_vf(nic, vf, &mbx); in nic_pause_frame()
880 bgx_lmac_set_pfc(nic->node, bgx, lmac, cfg); in nic_pause_frame()
881 nic_mbx_send_ack(nic, vf); in nic_pause_frame()
886 static void nic_config_timestamp(struct nicpf *nic, int vf, struct set_ptp *ptp) in nic_config_timestamp() argument
892 if (vf >= nic->num_vf_en) in nic_config_timestamp()
895 bgx_idx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_config_timestamp()
896 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_config_timestamp()
899 pkind_val = nic_reg_read(nic, NIC_PF_PKIND_0_15_CFG | (pkind_idx << 3)); in nic_config_timestamp()
909 bgx_config_timestamping(nic->node, bgx_idx, lmac, true); in nic_config_timestamp()
910 nic_reg_write(nic, NIC_PF_RX_ETYPE_0_7 | (1 << 3), in nic_config_timestamp()
915 bgx_config_timestamping(nic->node, bgx_idx, lmac, false); in nic_config_timestamp()
916 nic_reg_write(nic, NIC_PF_RX_ETYPE_0_7 | (1 << 3), in nic_config_timestamp()
920 nic_reg_write(nic, NIC_PF_PKIND_0_15_CFG | (pkind_idx << 3), pkind_val); in nic_config_timestamp()
927 static void nic_link_status_get(struct nicpf *nic, u8 vf) in nic_link_status_get() argument
936 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_link_status_get()
937 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_link_status_get()
940 bgx_get_lmac_link_state(nic->node, bgx, lmac, &link); in nic_link_status_get()
949 nic_send_msg_to_vf(nic, vf, &mbx); in nic_link_status_get()
953 static void nic_handle_mbx_intr(struct nicpf *nic, int vf) in nic_handle_mbx_intr() argument
968 *mbx_data = nic_reg_read(nic, mbx_addr); in nic_handle_mbx_intr()
973 dev_dbg(&nic->pdev->dev, "%s: Mailbox msg 0x%02x from VF%d\n", in nic_handle_mbx_intr()
977 nic_mbx_send_ready(nic, vf); in nic_handle_mbx_intr()
984 if (vf >= nic->num_vf_en) { in nic_handle_mbx_intr()
987 cfg |= nic->pqs_vf[vf]; in nic_handle_mbx_intr()
989 nic_reg_write(nic, reg_addr, cfg); in nic_handle_mbx_intr()
995 nic_reg_write(nic, reg_addr, mbx.rq.cfg); in nic_handle_mbx_intr()
1001 if (pass2_silicon(nic->pdev)) in nic_handle_mbx_intr()
1002 nic_reg_write(nic, NIC_PF_RX_CFG, 0x01); in nic_handle_mbx_intr()
1003 if (!pass1_silicon(nic->pdev)) in nic_handle_mbx_intr()
1004 nic_enable_tunnel_parsing(nic, vf); in nic_handle_mbx_intr()
1010 nic_reg_write(nic, reg_addr, mbx.rq.cfg); in nic_handle_mbx_intr()
1013 ret = nic_rcv_queue_sw_sync(nic); in nic_handle_mbx_intr()
1019 nic_reg_write(nic, reg_addr, mbx.rq.cfg); in nic_handle_mbx_intr()
1025 nic_reg_write(nic, reg_addr, mbx.sq.cfg); in nic_handle_mbx_intr()
1026 nic_tx_channel_cfg(nic, mbx.qs.num, &mbx.sq); in nic_handle_mbx_intr()
1029 if (vf >= nic->num_vf_en) { in nic_handle_mbx_intr()
1034 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[lmac]); in nic_handle_mbx_intr()
1035 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[lmac]); in nic_handle_mbx_intr()
1036 bgx_set_lmac_mac(nic->node, bgx, lmac, mbx.mac.mac_addr); in nic_handle_mbx_intr()
1039 ret = nic_update_hw_frs(nic, mbx.frs.max_frs, in nic_handle_mbx_intr()
1043 nic_config_cpi(nic, &mbx.cpi_cfg); in nic_handle_mbx_intr()
1046 nic_send_rss_size(nic, vf); in nic_handle_mbx_intr()
1050 nic_config_rss(nic, &mbx.rss_cfg); in nic_handle_mbx_intr()
1054 nic_enable_vf(nic, vf, true); in nic_handle_mbx_intr()
1058 if (vf >= nic->num_vf_en) in nic_handle_mbx_intr()
1059 nic->sqs_used[vf - nic->num_vf_en] = false; in nic_handle_mbx_intr()
1060 nic->pqs_vf[vf] = 0; in nic_handle_mbx_intr()
1061 nic_enable_vf(nic, vf, false); in nic_handle_mbx_intr()
1064 nic_alloc_sqs(nic, &mbx.sqs_alloc); in nic_handle_mbx_intr()
1067 nic->nicvf[vf] = mbx.nicvf.nicvf; in nic_handle_mbx_intr()
1070 nic_send_pnicvf(nic, vf); in nic_handle_mbx_intr()
1073 nic_send_snicvf(nic, &mbx.nicvf); in nic_handle_mbx_intr()
1076 nic_get_bgx_stats(nic, &mbx.bgx_stats); in nic_handle_mbx_intr()
1079 ret = nic_config_loopback(nic, &mbx.lbk); in nic_handle_mbx_intr()
1082 ret = nic_reset_stat_counters(nic, vf, &mbx.reset_stat); in nic_handle_mbx_intr()
1085 nic_pause_frame(nic, vf, &mbx.pfc); in nic_handle_mbx_intr()
1088 nic_config_timestamp(nic, vf, &mbx.ptp); in nic_handle_mbx_intr()
1091 if (vf >= nic->num_vf_en) { in nic_handle_mbx_intr()
1095 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_handle_mbx_intr()
1096 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_handle_mbx_intr()
1097 bgx_reset_xcast_mode(nic->node, bgx, lmac, in nic_handle_mbx_intr()
1103 if (vf >= nic->num_vf_en) { in nic_handle_mbx_intr()
1107 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_handle_mbx_intr()
1108 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_handle_mbx_intr()
1109 bgx_set_dmac_cam_filter(nic->node, bgx, lmac, in nic_handle_mbx_intr()
1116 if (vf >= nic->num_vf_en) { in nic_handle_mbx_intr()
1120 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_handle_mbx_intr()
1121 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]); in nic_handle_mbx_intr()
1122 bgx_set_xcast_mode(nic->node, bgx, lmac, mbx.xcast.mode); in nic_handle_mbx_intr()
1125 if (vf >= nic->num_vf_en) { in nic_handle_mbx_intr()
1129 nic_link_status_get(nic, vf); in nic_handle_mbx_intr()
1132 dev_err(&nic->pdev->dev, in nic_handle_mbx_intr()
1138 nic_mbx_send_ack(nic, vf); in nic_handle_mbx_intr()
1140 dev_err(&nic->pdev->dev, "NACK for MBOX 0x%02x from VF %d\n", in nic_handle_mbx_intr()
1142 nic_mbx_send_nack(nic, vf); in nic_handle_mbx_intr()
1148 struct nicpf *nic = (struct nicpf *)nic_irq; in nic_mbx_intr_handler() local
1153 if (irq == nic->irq_allocated[NIC_PF_INTR_ID_MBOX0]) in nic_mbx_intr_handler()
1158 intr = nic_reg_read(nic, NIC_PF_MAILBOX_INT + (mbx << 3)); in nic_mbx_intr_handler()
1159 dev_dbg(&nic->pdev->dev, "PF interrupt Mbox%d 0x%llx\n", mbx, intr); in nic_mbx_intr_handler()
1162 dev_dbg(&nic->pdev->dev, "Intr from VF %d\n", in nic_mbx_intr_handler()
1165 nic_handle_mbx_intr(nic, vf + in nic_mbx_intr_handler()
1167 nic_clear_mbx_intr(nic, vf, mbx); in nic_mbx_intr_handler()
1173 static void nic_free_all_interrupts(struct nicpf *nic) in nic_free_all_interrupts() argument
1177 for (irq = 0; irq < nic->num_vec; irq++) { in nic_free_all_interrupts()
1178 if (nic->irq_allocated[irq]) in nic_free_all_interrupts()
1179 free_irq(nic->irq_allocated[irq], nic); in nic_free_all_interrupts()
1180 nic->irq_allocated[irq] = 0; in nic_free_all_interrupts()
1184 static int nic_register_interrupts(struct nicpf *nic) in nic_register_interrupts() argument
1187 nic->num_vec = pci_msix_vec_count(nic->pdev); in nic_register_interrupts()
1190 ret = pci_alloc_irq_vectors(nic->pdev, nic->num_vec, nic->num_vec, in nic_register_interrupts()
1193 dev_err(&nic->pdev->dev, in nic_register_interrupts()
1195 nic->num_vec, ret); in nic_register_interrupts()
1200 for (i = NIC_PF_INTR_ID_MBOX0; i < nic->num_vec; i++) { in nic_register_interrupts()
1201 sprintf(nic->irq_name[i], in nic_register_interrupts()
1204 irq = pci_irq_vector(nic->pdev, i); in nic_register_interrupts()
1206 nic->irq_name[i], nic); in nic_register_interrupts()
1210 nic->irq_allocated[i] = irq; in nic_register_interrupts()
1214 nic_enable_mbx_intr(nic); in nic_register_interrupts()
1218 dev_err(&nic->pdev->dev, "Request irq failed\n"); in nic_register_interrupts()
1219 nic_free_all_interrupts(nic); in nic_register_interrupts()
1220 pci_free_irq_vectors(nic->pdev); in nic_register_interrupts()
1221 nic->num_vec = 0; in nic_register_interrupts()
1225 static void nic_unregister_interrupts(struct nicpf *nic) in nic_unregister_interrupts() argument
1227 nic_free_all_interrupts(nic); in nic_unregister_interrupts()
1228 pci_free_irq_vectors(nic->pdev); in nic_unregister_interrupts()
1229 nic->num_vec = 0; in nic_unregister_interrupts()
1232 static int nic_num_sqs_en(struct nicpf *nic, int vf_en) in nic_num_sqs_en() argument
1247 pos = pci_find_ext_capability(nic->pdev, PCI_EXT_CAP_ID_SRIOV); in nic_num_sqs_en()
1248 pci_read_config_word(nic->pdev, (pos + PCI_SRIOV_TOTAL_VF), &total_vf); in nic_num_sqs_en()
1252 static int nic_sriov_init(struct pci_dev *pdev, struct nicpf *nic) in nic_sriov_init() argument
1266 if (total_vf_cnt < nic->num_vf_en) in nic_sriov_init()
1267 nic->num_vf_en = total_vf_cnt; in nic_sriov_init()
1272 vf_en = nic->num_vf_en; in nic_sriov_init()
1273 nic->num_sqs_en = nic_num_sqs_en(nic, nic->num_vf_en); in nic_sriov_init()
1274 vf_en += nic->num_sqs_en; in nic_sriov_init()
1280 nic->num_vf_en = 0; in nic_sriov_init()
1287 nic->flags |= NIC_SRIOV_ENABLED; in nic_sriov_init()
1294 struct nicpf *nic; in nic_probe() local
1300 nic = devm_kzalloc(dev, sizeof(*nic), GFP_KERNEL); in nic_probe()
1301 if (!nic) in nic_probe()
1304 nic->hw = devm_kzalloc(dev, sizeof(struct hw_info), GFP_KERNEL); in nic_probe()
1305 if (!nic->hw) in nic_probe()
1308 pci_set_drvdata(pdev, nic); in nic_probe()
1310 nic->pdev = pdev; in nic_probe()
1331 nic->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0); in nic_probe()
1332 if (!nic->reg_base) { in nic_probe()
1338 nic->node = nic_get_node_id(pdev); in nic_probe()
1341 nic_get_hw_info(nic); in nic_probe()
1345 max_lmac = nic->hw->bgx_cnt * MAX_LMAC_PER_BGX; in nic_probe()
1347 nic->vf_lmac_map = devm_kmalloc_array(dev, max_lmac, sizeof(u8), in nic_probe()
1349 if (!nic->vf_lmac_map) in nic_probe()
1353 nic_init_hw(nic); in nic_probe()
1355 nic_set_lmac_vf_mapping(nic); in nic_probe()
1358 err = nic_register_interrupts(nic); in nic_probe()
1363 err = nic_sriov_init(pdev, nic); in nic_probe()
1370 nic_unregister_interrupts(nic); in nic_probe()
1381 struct nicpf *nic = pci_get_drvdata(pdev); in nic_remove() local
1383 if (!nic) in nic_remove()
1386 if (nic->flags & NIC_SRIOV_ENABLED) in nic_remove()
1389 nic_unregister_interrupts(nic); in nic_remove()