Skip to content

Commit 490e145

Browse files
bmarreddykuba-moo
authored andcommitted
bng_en: Introduce VNIC
Add the VNIC-specific structures and DMA memory necessary to support UC/MC and RSS functionality. Signed-off-by: Bhargava Marreddy <[email protected]> Reviewed-by: Vikas Gupta <[email protected]> Reviewed-by: Rajashekar Hudumula <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bd06d72 commit 490e145

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

drivers/net/ethernet/broadcom/bnge/bnge_netdev.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,122 @@ static int bnge_alloc_tx_rings(struct bnge_net *bn)
439439
return rc;
440440
}
441441

442+
static void bnge_free_vnic_attributes(struct bnge_net *bn)
443+
{
444+
struct pci_dev *pdev = bn->bd->pdev;
445+
struct bnge_vnic_info *vnic;
446+
int i;
447+
448+
if (!bn->vnic_info)
449+
return;
450+
451+
for (i = 0; i < bn->nr_vnics; i++) {
452+
vnic = &bn->vnic_info[i];
453+
454+
kfree(vnic->uc_list);
455+
vnic->uc_list = NULL;
456+
457+
if (vnic->mc_list) {
458+
dma_free_coherent(&pdev->dev, vnic->mc_list_size,
459+
vnic->mc_list, vnic->mc_list_mapping);
460+
vnic->mc_list = NULL;
461+
}
462+
463+
if (vnic->rss_table) {
464+
dma_free_coherent(&pdev->dev, vnic->rss_table_size,
465+
vnic->rss_table,
466+
vnic->rss_table_dma_addr);
467+
vnic->rss_table = NULL;
468+
}
469+
470+
vnic->rss_hash_key = NULL;
471+
vnic->flags = 0;
472+
}
473+
}
474+
475+
static int bnge_alloc_vnic_attributes(struct bnge_net *bn)
476+
{
477+
struct bnge_dev *bd = bn->bd;
478+
struct bnge_vnic_info *vnic;
479+
int i, size;
480+
481+
for (i = 0; i < bn->nr_vnics; i++) {
482+
vnic = &bn->vnic_info[i];
483+
484+
if (vnic->flags & BNGE_VNIC_UCAST_FLAG) {
485+
int mem_size = (BNGE_MAX_UC_ADDRS - 1) * ETH_ALEN;
486+
487+
vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
488+
if (!vnic->uc_list)
489+
goto err_free_vnic_attributes;
490+
}
491+
492+
if (vnic->flags & BNGE_VNIC_MCAST_FLAG) {
493+
vnic->mc_list_size = BNGE_MAX_MC_ADDRS * ETH_ALEN;
494+
vnic->mc_list =
495+
dma_alloc_coherent(bd->dev,
496+
vnic->mc_list_size,
497+
&vnic->mc_list_mapping,
498+
GFP_KERNEL);
499+
if (!vnic->mc_list)
500+
goto err_free_vnic_attributes;
501+
}
502+
503+
/* Allocate rss table and hash key */
504+
size = L1_CACHE_ALIGN(BNGE_MAX_RSS_TABLE_SIZE);
505+
506+
vnic->rss_table_size = size + HW_HASH_KEY_SIZE;
507+
vnic->rss_table = dma_alloc_coherent(bd->dev,
508+
vnic->rss_table_size,
509+
&vnic->rss_table_dma_addr,
510+
GFP_KERNEL);
511+
if (!vnic->rss_table)
512+
goto err_free_vnic_attributes;
513+
514+
vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
515+
vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
516+
}
517+
return 0;
518+
519+
err_free_vnic_attributes:
520+
bnge_free_vnic_attributes(bn);
521+
return -ENOMEM;
522+
}
523+
524+
static int bnge_alloc_vnics(struct bnge_net *bn)
525+
{
526+
int num_vnics;
527+
528+
/* Allocate only 1 VNIC for now
529+
* Additional VNICs will be added based on RFS/NTUPLE in future patches
530+
*/
531+
num_vnics = 1;
532+
533+
bn->vnic_info = kcalloc(num_vnics, sizeof(struct bnge_vnic_info),
534+
GFP_KERNEL);
535+
if (!bn->vnic_info)
536+
return -ENOMEM;
537+
538+
bn->nr_vnics = num_vnics;
539+
540+
return 0;
541+
}
542+
543+
static void bnge_free_vnics(struct bnge_net *bn)
544+
{
545+
kfree(bn->vnic_info);
546+
bn->vnic_info = NULL;
547+
bn->nr_vnics = 0;
548+
}
549+
442550
static void bnge_free_core(struct bnge_net *bn)
443551
{
552+
bnge_free_vnic_attributes(bn);
444553
bnge_free_tx_rings(bn);
445554
bnge_free_rx_rings(bn);
446555
bnge_free_nq_tree(bn);
447556
bnge_free_nq_arrays(bn);
557+
bnge_free_vnics(bn);
448558
kfree(bn->tx_ring_map);
449559
bn->tx_ring_map = NULL;
450560
kfree(bn->tx_ring);
@@ -531,6 +641,10 @@ static int bnge_alloc_core(struct bnge_net *bn)
531641
txr->bnapi = bnapi2;
532642
}
533643

644+
rc = bnge_alloc_vnics(bn);
645+
if (rc)
646+
goto err_free_core;
647+
534648
rc = bnge_alloc_nq_arrays(bn);
535649
if (rc)
536650
goto err_free_core;
@@ -546,6 +660,13 @@ static int bnge_alloc_core(struct bnge_net *bn)
546660
goto err_free_core;
547661

548662
rc = bnge_alloc_nq_tree(bn);
663+
if (rc)
664+
goto err_free_core;
665+
666+
bn->vnic_info[BNGE_VNIC_DEFAULT].flags |= BNGE_VNIC_RSS_FLAG |
667+
BNGE_VNIC_MCAST_FLAG |
668+
BNGE_VNIC_UCAST_FLAG;
669+
rc = bnge_alloc_vnic_attributes(bn);
549670
if (rc)
550671
goto err_free_core;
551672
return 0;

drivers/net/ethernet/broadcom/bnge/bnge_netdev.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ struct bnge_net {
176176
u16 *tx_ring_map;
177177
enum dma_data_direction rx_dir;
178178

179+
struct bnge_vnic_info *vnic_info;
180+
int nr_vnics;
179181
int total_irqs;
180182
};
181183

@@ -300,4 +302,32 @@ struct bnge_napi {
300302
struct bnge_tx_ring_info *tx_ring[BNGE_MAX_TXR_PER_NAPI];
301303
};
302304

305+
#define INVALID_STATS_CTX_ID -1
306+
#define BNGE_VNIC_DEFAULT 0
307+
#define BNGE_MAX_UC_ADDRS 4
308+
309+
struct bnge_vnic_info {
310+
u8 *uc_list;
311+
dma_addr_t rss_table_dma_addr;
312+
__le16 *rss_table;
313+
dma_addr_t rss_hash_key_dma_addr;
314+
u64 *rss_hash_key;
315+
int rss_table_size;
316+
#define BNGE_RSS_TABLE_ENTRIES 64
317+
#define BNGE_RSS_TABLE_SIZE (BNGE_RSS_TABLE_ENTRIES * 4)
318+
#define BNGE_RSS_TABLE_MAX_TBL 8
319+
#define BNGE_MAX_RSS_TABLE_SIZE \
320+
(BNGE_RSS_TABLE_SIZE * BNGE_RSS_TABLE_MAX_TBL)
321+
322+
u8 *mc_list;
323+
int mc_list_size;
324+
int mc_list_count;
325+
dma_addr_t mc_list_mapping;
326+
#define BNGE_MAX_MC_ADDRS 16
327+
328+
u32 flags;
329+
#define BNGE_VNIC_RSS_FLAG 1
330+
#define BNGE_VNIC_MCAST_FLAG 4
331+
#define BNGE_VNIC_UCAST_FLAG 8
332+
};
303333
#endif /* _BNGE_NETDEV_H_ */

0 commit comments

Comments
 (0)