Skip to content

Commit d85b5a2

Browse files
bmarreddykuba-moo
authored andcommitted
bng_en: Initialise core resources
Add initial settings to all core resources, such as the RX, AGG, TX, CQ, and NQ rings, as well as the VNIC. This will help enable these resources in future patches. 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 490e145 commit d85b5a2

File tree

3 files changed

+261
-0
lines changed

3 files changed

+261
-0
lines changed

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

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,41 @@ static void bnge_free_vnics(struct bnge_net *bn)
547547
bn->nr_vnics = 0;
548548
}
549549

550+
static void bnge_free_ring_grps(struct bnge_net *bn)
551+
{
552+
kfree(bn->grp_info);
553+
bn->grp_info = NULL;
554+
}
555+
556+
static int bnge_init_ring_grps(struct bnge_net *bn)
557+
{
558+
struct bnge_dev *bd = bn->bd;
559+
int i;
560+
561+
bn->grp_info = kcalloc(bd->nq_nr_rings,
562+
sizeof(struct bnge_ring_grp_info),
563+
GFP_KERNEL);
564+
if (!bn->grp_info)
565+
return -ENOMEM;
566+
for (i = 0; i < bd->nq_nr_rings; i++) {
567+
bn->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
568+
bn->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
569+
bn->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
570+
bn->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
571+
bn->grp_info[i].nq_fw_ring_id = INVALID_HW_RING_ID;
572+
}
573+
574+
return 0;
575+
}
576+
550577
static void bnge_free_core(struct bnge_net *bn)
551578
{
552579
bnge_free_vnic_attributes(bn);
553580
bnge_free_tx_rings(bn);
554581
bnge_free_rx_rings(bn);
555582
bnge_free_nq_tree(bn);
556583
bnge_free_nq_arrays(bn);
584+
bnge_free_ring_grps(bn);
557585
bnge_free_vnics(bn);
558586
kfree(bn->tx_ring_map);
559587
bn->tx_ring_map = NULL;
@@ -692,6 +720,167 @@ static irqreturn_t bnge_msix(int irq, void *dev_instance)
692720
return IRQ_HANDLED;
693721
}
694722

723+
static void bnge_init_nq_tree(struct bnge_net *bn)
724+
{
725+
struct bnge_dev *bd = bn->bd;
726+
int i, j;
727+
728+
for (i = 0; i < bd->nq_nr_rings; i++) {
729+
struct bnge_nq_ring_info *nqr = &bn->bnapi[i]->nq_ring;
730+
struct bnge_ring_struct *ring = &nqr->ring_struct;
731+
732+
ring->fw_ring_id = INVALID_HW_RING_ID;
733+
for (j = 0; j < nqr->cp_ring_count; j++) {
734+
struct bnge_cp_ring_info *cpr = &nqr->cp_ring_arr[j];
735+
736+
ring = &cpr->ring_struct;
737+
ring->fw_ring_id = INVALID_HW_RING_ID;
738+
}
739+
}
740+
}
741+
742+
static void bnge_init_rxbd_pages(struct bnge_ring_struct *ring, u32 type)
743+
{
744+
struct rx_bd **rx_desc_ring;
745+
u32 prod;
746+
int i;
747+
748+
rx_desc_ring = (struct rx_bd **)ring->ring_mem.pg_arr;
749+
for (i = 0, prod = 0; i < ring->ring_mem.nr_pages; i++) {
750+
struct rx_bd *rxbd = rx_desc_ring[i];
751+
int j;
752+
753+
for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
754+
rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
755+
rxbd->rx_bd_opaque = prod;
756+
}
757+
}
758+
}
759+
760+
static void bnge_init_one_rx_ring_rxbd(struct bnge_net *bn,
761+
struct bnge_rx_ring_info *rxr)
762+
{
763+
struct bnge_ring_struct *ring;
764+
u32 type;
765+
766+
type = (bn->rx_buf_use_size << RX_BD_LEN_SHIFT) |
767+
RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
768+
769+
if (NET_IP_ALIGN == 2)
770+
type |= RX_BD_FLAGS_SOP;
771+
772+
ring = &rxr->rx_ring_struct;
773+
bnge_init_rxbd_pages(ring, type);
774+
ring->fw_ring_id = INVALID_HW_RING_ID;
775+
}
776+
777+
static void bnge_init_one_agg_ring_rxbd(struct bnge_net *bn,
778+
struct bnge_rx_ring_info *rxr)
779+
{
780+
struct bnge_ring_struct *ring;
781+
u32 type;
782+
783+
ring = &rxr->rx_agg_ring_struct;
784+
ring->fw_ring_id = INVALID_HW_RING_ID;
785+
if (bnge_is_agg_reqd(bn->bd)) {
786+
type = ((u32)BNGE_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
787+
RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
788+
789+
bnge_init_rxbd_pages(ring, type);
790+
}
791+
}
792+
793+
static void bnge_init_one_rx_ring_pair(struct bnge_net *bn, int ring_nr)
794+
{
795+
struct bnge_rx_ring_info *rxr;
796+
797+
rxr = &bn->rx_ring[ring_nr];
798+
bnge_init_one_rx_ring_rxbd(bn, rxr);
799+
800+
netif_queue_set_napi(bn->netdev, ring_nr, NETDEV_QUEUE_TYPE_RX,
801+
&rxr->bnapi->napi);
802+
803+
bnge_init_one_agg_ring_rxbd(bn, rxr);
804+
}
805+
806+
static void bnge_init_rx_rings(struct bnge_net *bn)
807+
{
808+
int i;
809+
810+
#define BNGE_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
811+
#define BNGE_RX_DMA_OFFSET NET_SKB_PAD
812+
bn->rx_offset = BNGE_RX_OFFSET;
813+
bn->rx_dma_offset = BNGE_RX_DMA_OFFSET;
814+
815+
for (i = 0; i < bn->bd->rx_nr_rings; i++)
816+
bnge_init_one_rx_ring_pair(bn, i);
817+
}
818+
819+
static void bnge_init_tx_rings(struct bnge_net *bn)
820+
{
821+
int i;
822+
823+
bn->tx_wake_thresh = max(bn->tx_ring_size / 2, BNGE_MIN_TX_DESC_CNT);
824+
825+
for (i = 0; i < bn->bd->tx_nr_rings; i++) {
826+
struct bnge_tx_ring_info *txr = &bn->tx_ring[i];
827+
struct bnge_ring_struct *ring = &txr->tx_ring_struct;
828+
829+
ring->fw_ring_id = INVALID_HW_RING_ID;
830+
831+
netif_queue_set_napi(bn->netdev, i, NETDEV_QUEUE_TYPE_TX,
832+
&txr->bnapi->napi);
833+
}
834+
}
835+
836+
static void bnge_init_vnics(struct bnge_net *bn)
837+
{
838+
struct bnge_vnic_info *vnic0 = &bn->vnic_info[BNGE_VNIC_DEFAULT];
839+
int i;
840+
841+
for (i = 0; i < bn->nr_vnics; i++) {
842+
struct bnge_vnic_info *vnic = &bn->vnic_info[i];
843+
int j;
844+
845+
vnic->fw_vnic_id = INVALID_HW_RING_ID;
846+
vnic->vnic_id = i;
847+
for (j = 0; j < BNGE_MAX_CTX_PER_VNIC; j++)
848+
vnic->fw_rss_cos_lb_ctx[j] = INVALID_HW_RING_ID;
849+
850+
if (bn->vnic_info[i].rss_hash_key) {
851+
if (i == BNGE_VNIC_DEFAULT) {
852+
u8 *key = (void *)vnic->rss_hash_key;
853+
int k;
854+
855+
if (!bn->rss_hash_key_valid &&
856+
!bn->rss_hash_key_updated) {
857+
get_random_bytes(bn->rss_hash_key,
858+
HW_HASH_KEY_SIZE);
859+
bn->rss_hash_key_updated = true;
860+
}
861+
862+
memcpy(vnic->rss_hash_key, bn->rss_hash_key,
863+
HW_HASH_KEY_SIZE);
864+
865+
if (!bn->rss_hash_key_updated)
866+
continue;
867+
868+
bn->rss_hash_key_updated = false;
869+
bn->rss_hash_key_valid = true;
870+
871+
bn->toeplitz_prefix = 0;
872+
for (k = 0; k < 8; k++) {
873+
bn->toeplitz_prefix <<= 8;
874+
bn->toeplitz_prefix |= key[k];
875+
}
876+
} else {
877+
memcpy(vnic->rss_hash_key, vnic0->rss_hash_key,
878+
HW_HASH_KEY_SIZE);
879+
}
880+
}
881+
}
882+
}
883+
695884
static void bnge_setup_msix(struct bnge_net *bn)
696885
{
697886
struct net_device *dev = bn->netdev;
@@ -836,6 +1025,20 @@ static void bnge_del_napi(struct bnge_net *bn)
8361025
synchronize_net();
8371026
}
8381027

1028+
static int bnge_init_nic(struct bnge_net *bn)
1029+
{
1030+
int rc;
1031+
1032+
bnge_init_nq_tree(bn);
1033+
bnge_init_rx_rings(bn);
1034+
bnge_init_tx_rings(bn);
1035+
rc = bnge_init_ring_grps(bn);
1036+
if (rc)
1037+
return rc;
1038+
bnge_init_vnics(bn);
1039+
return rc;
1040+
}
1041+
8391042
static int bnge_open_core(struct bnge_net *bn)
8401043
{
8411044
struct bnge_dev *bd = bn->bd;
@@ -862,9 +1065,16 @@ static int bnge_open_core(struct bnge_net *bn)
8621065
goto err_del_napi;
8631066
}
8641067

1068+
rc = bnge_init_nic(bn);
1069+
if (rc) {
1070+
netdev_err(bn->netdev, "bnge_init_nic err: %d\n", rc);
1071+
goto err_free_irq;
1072+
}
8651073
set_bit(BNGE_STATE_OPEN, &bd->state);
8661074
return 0;
8671075

1076+
err_free_irq:
1077+
bnge_free_irq(bn);
8681078
err_del_napi:
8691079
bnge_del_napi(bn);
8701080
bnge_free_core(bn);

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ struct bnge_sw_rx_agg_bd {
118118
dma_addr_t mapping;
119119
};
120120

121+
#define HWRM_RING_ALLOC_TX 0x1
122+
#define HWRM_RING_ALLOC_RX 0x2
123+
#define HWRM_RING_ALLOC_AGG 0x4
124+
#define HWRM_RING_ALLOC_CMPL 0x8
125+
#define HWRM_RING_ALLOC_NQ 0x10
126+
127+
struct bnge_ring_grp_info {
128+
u16 fw_stats_ctx;
129+
u16 fw_grp_id;
130+
u16 rx_fw_ring_id;
131+
u16 agg_fw_ring_id;
132+
u16 nq_fw_ring_id;
133+
};
134+
121135
#define BNGE_RX_COPY_THRESH 256
122136

123137
#define BNGE_HW_FEATURE_VLAN_ALL_RX \
@@ -133,6 +147,28 @@ enum {
133147

134148
#define BNGE_NET_EN_TPA (BNGE_NET_EN_GRO | BNGE_NET_EN_LRO)
135149

150+
/* Minimum TX BDs for a TX packet with MAX_SKB_FRAGS + 1. We need one extra
151+
* BD because the first TX BD is always a long BD.
152+
*/
153+
#define BNGE_MIN_TX_DESC_CNT (MAX_SKB_FRAGS + 2)
154+
155+
#define RX_RING(bn, x) (((x) & (bn)->rx_ring_mask) >> (BNGE_PAGE_SHIFT - 4))
156+
#define RX_AGG_RING(bn, x) (((x) & (bn)->rx_agg_ring_mask) >> \
157+
(BNGE_PAGE_SHIFT - 4))
158+
#define RX_IDX(x) ((x) & (RX_DESC_CNT - 1))
159+
160+
#define TX_RING(bn, x) (((x) & (bn)->tx_ring_mask) >> (BNGE_PAGE_SHIFT - 4))
161+
#define TX_IDX(x) ((x) & (TX_DESC_CNT - 1))
162+
163+
#define CP_RING(x) (((x) & ~(CP_DESC_CNT - 1)) >> (BNGE_PAGE_SHIFT - 4))
164+
#define CP_IDX(x) ((x) & (CP_DESC_CNT - 1))
165+
166+
#define RING_RX(bn, idx) ((idx) & (bn)->rx_ring_mask)
167+
#define NEXT_RX(idx) ((idx) + 1)
168+
169+
#define RING_RX_AGG(bn, idx) ((idx) & (bn)->rx_agg_ring_mask)
170+
#define NEXT_RX_AGG(idx) ((idx) + 1)
171+
136172
#define BNGE_NQ_HDL_TYPE_RX 0x00
137173
#define BNGE_NQ_HDL_TYPE_TX 0x01
138174

@@ -176,9 +212,19 @@ struct bnge_net {
176212
u16 *tx_ring_map;
177213
enum dma_data_direction rx_dir;
178214

215+
/* grp_info indexed by napi/nq index */
216+
struct bnge_ring_grp_info *grp_info;
179217
struct bnge_vnic_info *vnic_info;
180218
int nr_vnics;
181219
int total_irqs;
220+
221+
u32 tx_wake_thresh;
222+
u16 rx_offset;
223+
u16 rx_dma_offset;
224+
225+
u8 rss_hash_key[HW_HASH_KEY_SIZE];
226+
u8 rss_hash_key_valid:1;
227+
u8 rss_hash_key_updated:1;
182228
};
183229

184230
#define BNGE_DEFAULT_RX_RING_SIZE 511
@@ -307,6 +353,9 @@ struct bnge_napi {
307353
#define BNGE_MAX_UC_ADDRS 4
308354

309355
struct bnge_vnic_info {
356+
u16 fw_vnic_id;
357+
#define BNGE_MAX_CTX_PER_VNIC 8
358+
u16 fw_rss_cos_lb_ctx[BNGE_MAX_CTX_PER_VNIC];
310359
u8 *uc_list;
311360
dma_addr_t rss_table_dma_addr;
312361
__le16 *rss_table;
@@ -329,5 +378,6 @@ struct bnge_vnic_info {
329378
#define BNGE_VNIC_RSS_FLAG 1
330379
#define BNGE_VNIC_MCAST_FLAG 4
331380
#define BNGE_VNIC_UCAST_FLAG 8
381+
u32 vnic_id;
332382
};
333383
#endif /* _BNGE_NETDEV_H_ */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct bnge_ctx_mem_info {
184184
struct bnge_ring_struct {
185185
struct bnge_ring_mem_info ring_mem;
186186

187+
u16 fw_ring_id;
187188
union {
188189
u16 grp_idx;
189190
u16 map_idx; /* Used by NQs */

0 commit comments

Comments
 (0)