Lines Matching full:bd

15 static u16 bnge_num_tx_to_cp(struct bnge_dev *bd, u16 tx)  in bnge_num_tx_to_cp()  argument
17 u16 tcs = bd->num_tc; in bnge_num_tx_to_cp()
25 static u16 bnge_get_max_func_irqs(struct bnge_dev *bd) in bnge_get_max_func_irqs() argument
27 struct bnge_hw_resc *hw_resc = &bd->hw_resc; in bnge_get_max_func_irqs()
32 static unsigned int bnge_get_max_func_stat_ctxs(struct bnge_dev *bd) in bnge_get_max_func_stat_ctxs() argument
34 return bd->hw_resc.max_stat_ctxs; in bnge_get_max_func_stat_ctxs()
37 bool bnge_aux_has_enough_resources(struct bnge_dev *bd) in bnge_aux_has_enough_resources() argument
41 max_stat_ctxs = bnge_get_max_func_stat_ctxs(bd); in bnge_aux_has_enough_resources()
43 bd->nq_nr_rings == max_stat_ctxs) in bnge_aux_has_enough_resources()
49 static unsigned int bnge_get_max_func_cp_rings(struct bnge_dev *bd) in bnge_get_max_func_cp_rings() argument
51 return bd->hw_resc.max_cp_rings; in bnge_get_max_func_cp_rings()
54 static int bnge_aux_get_dflt_msix(struct bnge_dev *bd) in bnge_aux_get_dflt_msix() argument
61 u16 bnge_aux_get_msix(struct bnge_dev *bd) in bnge_aux_get_msix() argument
63 if (bnge_is_roce_en(bd)) in bnge_aux_get_msix()
64 return bd->aux_num_msix; in bnge_aux_get_msix()
69 static void bnge_aux_set_msix_num(struct bnge_dev *bd, u16 num) in bnge_aux_set_msix_num() argument
71 if (bnge_is_roce_en(bd)) in bnge_aux_set_msix_num()
72 bd->aux_num_msix = num; in bnge_aux_set_msix_num()
75 static u16 bnge_aux_get_stat_ctxs(struct bnge_dev *bd) in bnge_aux_get_stat_ctxs() argument
77 if (bnge_is_roce_en(bd)) in bnge_aux_get_stat_ctxs()
78 return bd->aux_num_stat_ctxs; in bnge_aux_get_stat_ctxs()
83 static void bnge_aux_set_stat_ctxs(struct bnge_dev *bd, u16 num_aux_ctx) in bnge_aux_set_stat_ctxs() argument
85 if (bnge_is_roce_en(bd)) in bnge_aux_set_stat_ctxs()
86 bd->aux_num_stat_ctxs = num_aux_ctx; in bnge_aux_set_stat_ctxs()
89 static u16 bnge_func_stat_ctxs_demand(struct bnge_dev *bd) in bnge_func_stat_ctxs_demand() argument
91 return bd->nq_nr_rings + bnge_aux_get_stat_ctxs(bd); in bnge_func_stat_ctxs_demand()
94 static int bnge_get_dflt_aux_stat_ctxs(struct bnge_dev *bd) in bnge_get_dflt_aux_stat_ctxs() argument
98 if (bnge_is_roce_en(bd)) { in bnge_get_dflt_aux_stat_ctxs()
101 if (!bd->pf.port_id && bd->port_count > 1) in bnge_get_dflt_aux_stat_ctxs()
108 static u16 bnge_nqs_demand(struct bnge_dev *bd) in bnge_nqs_demand() argument
110 return bd->nq_nr_rings + bnge_aux_get_msix(bd); in bnge_nqs_demand()
113 static u16 bnge_cprs_demand(struct bnge_dev *bd) in bnge_cprs_demand() argument
115 return bd->tx_nr_rings + bd->rx_nr_rings; in bnge_cprs_demand()
118 static u16 bnge_get_avail_msix(struct bnge_dev *bd, int num) in bnge_get_avail_msix() argument
120 u16 max_irq = bnge_get_max_func_irqs(bd); in bnge_get_avail_msix()
121 u16 total_demand = bd->nq_nr_rings + num; in bnge_get_avail_msix()
124 num = max_irq - bd->nq_nr_rings; in bnge_get_avail_msix()
132 static u16 bnge_num_cp_to_tx(struct bnge_dev *bd, u16 tx_chunks) in bnge_num_cp_to_tx() argument
134 return tx_chunks * bd->num_tc; in bnge_num_cp_to_tx()
160 static int bnge_adjust_rings(struct bnge_dev *bd, u16 *rx, in bnge_adjust_rings() argument
163 u16 tx_chunks = bnge_num_tx_to_cp(bd, *tx); in bnge_adjust_rings()
172 *tx = bnge_num_cp_to_tx(bd, tx_chunks); in bnge_adjust_rings()
188 static u16 bnge_rss_ctxs_in_use(struct bnge_dev *bd, in bnge_rss_ctxs_in_use() argument
194 static u16 bnge_get_total_vnics(struct bnge_dev *bd, u16 rx_rings) in bnge_get_total_vnics() argument
199 u32 bnge_get_rxfh_indir_size(struct bnge_dev *bd) in bnge_get_rxfh_indir_size() argument
201 return bnge_cal_nr_rss_ctxs(bd->rx_nr_rings) * in bnge_get_rxfh_indir_size()
205 static void bnge_set_dflt_rss_indir_tbl(struct bnge_dev *bd) in bnge_set_dflt_rss_indir_tbl() argument
211 max_entries = bnge_get_rxfh_indir_size(bd); in bnge_set_dflt_rss_indir_tbl()
212 rss_indir_tbl = &bd->rss_indir_tbl[0]; in bnge_set_dflt_rss_indir_tbl()
216 bd->rx_nr_rings); in bnge_set_dflt_rss_indir_tbl()
218 pad = bd->rss_indir_tbl_entries - max_entries; in bnge_set_dflt_rss_indir_tbl()
223 static void bnge_copy_reserved_rings(struct bnge_dev *bd, in bnge_copy_reserved_rings() argument
226 struct bnge_hw_resc *hw_resc = &bd->hw_resc; in bnge_copy_reserved_rings()
244 static bool bnge_need_reserve_rings(struct bnge_dev *bd) in bnge_need_reserve_rings() argument
246 struct bnge_hw_resc *hw_resc = &bd->hw_resc; in bnge_need_reserve_rings()
247 u16 cprs = bnge_cprs_demand(bd); in bnge_need_reserve_rings()
248 u16 rx = bd->rx_nr_rings, stat; in bnge_need_reserve_rings()
249 u16 nqs = bnge_nqs_demand(bd); in bnge_need_reserve_rings()
252 if (hw_resc->resv_tx_rings != bd->tx_nr_rings) in bnge_need_reserve_rings()
255 vnic = bnge_get_total_vnics(bd, rx); in bnge_need_reserve_rings()
257 if (bnge_is_agg_reqd(bd)) in bnge_need_reserve_rings()
259 stat = bnge_func_stat_ctxs_demand(bd); in bnge_need_reserve_rings()
269 int bnge_reserve_rings(struct bnge_dev *bd) in bnge_reserve_rings() argument
271 u16 aux_dflt_msix = bnge_aux_get_dflt_msix(bd); in bnge_reserve_rings()
274 u16 nq = bd->nq_nr_rings; in bnge_reserve_rings()
280 if (!bnge_need_reserve_rings(bd)) in bnge_reserve_rings()
283 if (!bnge_aux_registered(bd)) { in bnge_reserve_rings()
284 aux_msix = bnge_get_avail_msix(bd, aux_dflt_msix); in bnge_reserve_rings()
286 bnge_aux_set_stat_ctxs(bd, 0); in bnge_reserve_rings()
292 hwr.nq = bnge_nqs_demand(bd); in bnge_reserve_rings()
295 hwr.tx = bd->tx_nr_rings; in bnge_reserve_rings()
296 hwr.rx = bd->rx_nr_rings; in bnge_reserve_rings()
297 if (bd->flags & BNGE_EN_SHARED_CHNL) in bnge_reserve_rings()
301 hwr.vnic = bnge_get_total_vnics(bd, hwr.rx); in bnge_reserve_rings()
303 if (bnge_is_agg_reqd(bd)) in bnge_reserve_rings()
305 hwr.grp = bd->rx_nr_rings; in bnge_reserve_rings()
306 hwr.rss_ctx = bnge_rss_ctxs_in_use(bd, &hwr); in bnge_reserve_rings()
307 hwr.stat = bnge_func_stat_ctxs_demand(bd); in bnge_reserve_rings()
308 old_rx_rings = bd->hw_resc.resv_rx_rings; in bnge_reserve_rings()
310 rc = bnge_hwrm_reserve_rings(bd, &hwr); in bnge_reserve_rings()
314 bnge_copy_reserved_rings(bd, &hwr); in bnge_reserve_rings()
317 if (bnge_is_agg_reqd(bd)) { in bnge_reserve_rings()
325 hwr.nq = min_t(u16, hwr.nq, bd->nq_nr_rings); in bnge_reserve_rings()
326 if (hwr.stat > bnge_aux_get_stat_ctxs(bd)) in bnge_reserve_rings()
327 hwr.stat -= bnge_aux_get_stat_ctxs(bd); in bnge_reserve_rings()
331 rc = bnge_adjust_rings(bd, &rx_rings, &hwr.tx, hwr.nq, sh); in bnge_reserve_rings()
332 if (bnge_is_agg_reqd(bd)) in bnge_reserve_rings()
336 bd->tx_nr_rings = hwr.tx; in bnge_reserve_rings()
338 if (rx_rings != bd->rx_nr_rings) in bnge_reserve_rings()
339 dev_warn(bd->dev, "RX rings resv reduced to %d than earlier %d requested\n", in bnge_reserve_rings()
340 rx_rings, bd->rx_nr_rings); in bnge_reserve_rings()
342 bd->rx_nr_rings = rx_rings; in bnge_reserve_rings()
343 bd->nq_nr_rings = hwr.nq; in bnge_reserve_rings()
348 if (old_rx_rings != bd->hw_resc.resv_rx_rings) in bnge_reserve_rings()
349 bnge_set_dflt_rss_indir_tbl(bd); in bnge_reserve_rings()
351 if (!bnge_aux_registered(bd)) { in bnge_reserve_rings()
355 hw_resc = &bd->hw_resc; in bnge_reserve_rings()
356 resv_msix = hw_resc->resv_irqs - bd->nq_nr_rings; in bnge_reserve_rings()
358 bnge_aux_set_msix_num(bd, aux_msix); in bnge_reserve_rings()
359 resv_ctx = hw_resc->resv_stat_ctxs - bd->nq_nr_rings; in bnge_reserve_rings()
360 aux_ctxs = min(resv_ctx, bnge_aux_get_stat_ctxs(bd)); in bnge_reserve_rings()
361 bnge_aux_set_stat_ctxs(bd, aux_ctxs); in bnge_reserve_rings()
367 int bnge_alloc_irqs(struct bnge_dev *bd) in bnge_alloc_irqs() argument
373 irqs_demand = bnge_nqs_demand(bd); in bnge_alloc_irqs()
374 max = bnge_get_max_func_irqs(bd); in bnge_alloc_irqs()
378 if (!(bd->flags & BNGE_EN_SHARED_CHNL)) in bnge_alloc_irqs()
381 irqs_demand = pci_alloc_irq_vectors(bd->pdev, min, irqs_demand, in bnge_alloc_irqs()
383 aux_msix = bnge_aux_get_msix(bd); in bnge_alloc_irqs()
390 if (pci_msix_can_alloc_dyn(bd->pdev)) in bnge_alloc_irqs()
392 bd->irq_tbl = kcalloc(num_entries, sizeof(*bd->irq_tbl), GFP_KERNEL); in bnge_alloc_irqs()
393 if (!bd->irq_tbl) { in bnge_alloc_irqs()
399 bd->irq_tbl[i].vector = pci_irq_vector(bd->pdev, i); in bnge_alloc_irqs()
401 bd->irqs_acquired = irqs_demand; in bnge_alloc_irqs()
406 rc = bnge_adjust_rings(bd, &bd->rx_nr_rings, in bnge_alloc_irqs()
407 &bd->tx_nr_rings, in bnge_alloc_irqs()
412 tx_cp = bnge_num_tx_to_cp(bd, bd->tx_nr_rings); in bnge_alloc_irqs()
413 bd->nq_nr_rings = (min == 1) ? in bnge_alloc_irqs()
414 max_t(u16, tx_cp, bd->rx_nr_rings) : in bnge_alloc_irqs()
415 tx_cp + bd->rx_nr_rings; in bnge_alloc_irqs()
418 if (!bd->num_tc) in bnge_alloc_irqs()
419 bd->tx_nr_rings_per_tc = bd->tx_nr_rings; in bnge_alloc_irqs()
424 dev_err(bd->dev, "Failed to allocate IRQs err = %d\n", rc); in bnge_alloc_irqs()
425 bnge_free_irqs(bd); in bnge_alloc_irqs()
429 void bnge_free_irqs(struct bnge_dev *bd) in bnge_free_irqs() argument
431 pci_free_irq_vectors(bd->pdev); in bnge_free_irqs()
432 kfree(bd->irq_tbl); in bnge_free_irqs()
433 bd->irq_tbl = NULL; in bnge_free_irqs()
436 static void _bnge_get_max_rings(struct bnge_dev *bd, u16 *max_rx, in _bnge_get_max_rings() argument
439 struct bnge_hw_resc *hw_resc = &bd->hw_resc; in _bnge_get_max_rings()
445 *max_nq = min_t(int, bnge_get_max_func_irqs(bd), in _bnge_get_max_rings()
448 if (bnge_is_agg_reqd(bd)) in _bnge_get_max_rings()
451 max_cp = bnge_get_max_func_cp_rings(bd); in _bnge_get_max_rings()
463 static int bnge_get_max_rings(struct bnge_dev *bd, u16 *max_rx, in bnge_get_max_rings() argument
468 _bnge_get_max_rings(bd, &rx, &tx, &nq); in bnge_get_max_rings()
477 static int bnge_get_dflt_rings(struct bnge_dev *bd, u16 *max_rx, u16 *max_tx, in bnge_get_dflt_rings() argument
482 rc = bnge_get_max_rings(bd, max_rx, max_tx, shared); in bnge_get_dflt_rings()
484 dev_info(bd->dev, "Not enough rings available\n"); in bnge_get_dflt_rings()
488 if (bnge_is_roce_en(bd)) { in bnge_get_dflt_rings()
492 max_cp = bnge_get_max_func_cp_rings(bd); in bnge_get_dflt_rings()
493 max_stat = bnge_get_max_func_stat_ctxs(bd); in bnge_get_dflt_rings()
494 max_irq = bnge_get_max_func_irqs(bd); in bnge_get_dflt_rings()
505 rc = bnge_adjust_rings(bd, max_rx, max_tx, max_cp, shared); in bnge_get_dflt_rings()
516 static void bnge_trim_dflt_sh_rings(struct bnge_dev *bd) in bnge_trim_dflt_sh_rings() argument
518 bd->nq_nr_rings = min_t(u16, bd->tx_nr_rings_per_tc, bd->rx_nr_rings); in bnge_trim_dflt_sh_rings()
519 bd->rx_nr_rings = bd->nq_nr_rings; in bnge_trim_dflt_sh_rings()
520 bd->tx_nr_rings_per_tc = bd->nq_nr_rings; in bnge_trim_dflt_sh_rings()
521 bd->tx_nr_rings = bd->tx_nr_rings_per_tc; in bnge_trim_dflt_sh_rings()
524 static int bnge_net_init_dflt_rings(struct bnge_dev *bd, bool sh) in bnge_net_init_dflt_rings() argument
530 bd->flags |= BNGE_EN_SHARED_CHNL; in bnge_net_init_dflt_rings()
534 rc = bnge_get_dflt_rings(bd, &max_rx_rings, &max_tx_rings, sh); in bnge_net_init_dflt_rings()
537 bd->rx_nr_rings = min_t(u16, dflt_rings, max_rx_rings); in bnge_net_init_dflt_rings()
538 bd->tx_nr_rings_per_tc = min_t(u16, dflt_rings, max_tx_rings); in bnge_net_init_dflt_rings()
540 bnge_trim_dflt_sh_rings(bd); in bnge_net_init_dflt_rings()
542 bd->nq_nr_rings = bd->tx_nr_rings_per_tc + bd->rx_nr_rings; in bnge_net_init_dflt_rings()
543 bd->tx_nr_rings = bd->tx_nr_rings_per_tc; in bnge_net_init_dflt_rings()
545 rc = bnge_reserve_rings(bd); in bnge_net_init_dflt_rings()
547 dev_warn(bd->dev, "Unable to reserve tx rings\n"); in bnge_net_init_dflt_rings()
548 bd->tx_nr_rings_per_tc = bd->tx_nr_rings; in bnge_net_init_dflt_rings()
550 bnge_trim_dflt_sh_rings(bd); in bnge_net_init_dflt_rings()
553 if (bnge_need_reserve_rings(bd)) { in bnge_net_init_dflt_rings()
554 rc = bnge_reserve_rings(bd); in bnge_net_init_dflt_rings()
556 dev_warn(bd->dev, "Fewer rings reservation failed\n"); in bnge_net_init_dflt_rings()
557 bd->tx_nr_rings_per_tc = bd->tx_nr_rings; in bnge_net_init_dflt_rings()
560 bd->tx_nr_rings = 0; in bnge_net_init_dflt_rings()
561 bd->rx_nr_rings = 0; in bnge_net_init_dflt_rings()
567 static int bnge_alloc_rss_indir_tbl(struct bnge_dev *bd) in bnge_alloc_rss_indir_tbl() argument
573 bd->rss_indir_tbl_entries = entries; in bnge_alloc_rss_indir_tbl()
574 bd->rss_indir_tbl = in bnge_alloc_rss_indir_tbl()
575 kmalloc_array(entries, sizeof(*bd->rss_indir_tbl), GFP_KERNEL); in bnge_alloc_rss_indir_tbl()
576 if (!bd->rss_indir_tbl) in bnge_alloc_rss_indir_tbl()
582 int bnge_net_init_dflt_config(struct bnge_dev *bd) in bnge_net_init_dflt_config() argument
587 rc = bnge_alloc_rss_indir_tbl(bd); in bnge_net_init_dflt_config()
591 rc = bnge_net_init_dflt_rings(bd, true); in bnge_net_init_dflt_config()
595 hw_resc = &bd->hw_resc; in bnge_net_init_dflt_config()
596 bd->max_fltr = hw_resc->max_rx_em_flows + hw_resc->max_rx_wm_flows + in bnge_net_init_dflt_config()
602 kfree(bd->rss_indir_tbl); in bnge_net_init_dflt_config()
603 bd->rss_indir_tbl = NULL; in bnge_net_init_dflt_config()
607 void bnge_net_uninit_dflt_config(struct bnge_dev *bd) in bnge_net_uninit_dflt_config() argument
609 kfree(bd->rss_indir_tbl); in bnge_net_uninit_dflt_config()
610 bd->rss_indir_tbl = NULL; in bnge_net_uninit_dflt_config()
613 void bnge_aux_init_dflt_config(struct bnge_dev *bd) in bnge_aux_init_dflt_config() argument
615 bd->aux_num_msix = bnge_aux_get_dflt_msix(bd); in bnge_aux_init_dflt_config()
616 bd->aux_num_stat_ctxs = bnge_get_dflt_aux_stat_ctxs(bd); in bnge_aux_init_dflt_config()