Skip to content

Commit 7737d32

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Refactor bnxt_init_one_rx_ring().
bnxt_init_one_rx_ring() includes logic to initialize the BDs for one RX ring and to allocate the buffers. Separate the allocation logic into a new bnxt_alloc_one_rx_ring() function. The allocation function will be used later to allocate new buffers for one specified RX ring when we reset that RX ring. Reviewed-by: Pavan Chebbi <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 975bc99 commit 7737d32

File tree

1 file changed

+50
-46
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+50
-46
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,54 +3163,30 @@ static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
31633163
}
31643164
}
31653165

3166-
static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
3166+
static int bnxt_alloc_one_rx_ring(struct bnxt *bp, int ring_nr)
31673167
{
3168+
struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
31683169
struct net_device *dev = bp->dev;
3169-
struct bnxt_rx_ring_info *rxr;
3170-
struct bnxt_ring_struct *ring;
3171-
u32 prod, type;
3170+
u32 prod;
31723171
int i;
31733172

3174-
type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
3175-
RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
3176-
3177-
if (NET_IP_ALIGN == 2)
3178-
type |= RX_BD_FLAGS_SOP;
3179-
3180-
rxr = &bp->rx_ring[ring_nr];
3181-
ring = &rxr->rx_ring_struct;
3182-
bnxt_init_rxbd_pages(ring, type);
3183-
3184-
if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
3185-
bpf_prog_add(bp->xdp_prog, 1);
3186-
rxr->xdp_prog = bp->xdp_prog;
3187-
}
31883173
prod = rxr->rx_prod;
31893174
for (i = 0; i < bp->rx_ring_size; i++) {
3190-
if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
3175+
if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL)) {
31913176
netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
31923177
ring_nr, i, bp->rx_ring_size);
31933178
break;
31943179
}
31953180
prod = NEXT_RX(prod);
31963181
}
31973182
rxr->rx_prod = prod;
3198-
ring->fw_ring_id = INVALID_HW_RING_ID;
3199-
3200-
ring = &rxr->rx_agg_ring_struct;
3201-
ring->fw_ring_id = INVALID_HW_RING_ID;
32023183

32033184
if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
32043185
return 0;
32053186

3206-
type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
3207-
RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
3208-
3209-
bnxt_init_rxbd_pages(ring, type);
3210-
32113187
prod = rxr->rx_agg_prod;
32123188
for (i = 0; i < bp->rx_agg_ring_size; i++) {
3213-
if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
3189+
if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL)) {
32143190
netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
32153191
ring_nr, i, bp->rx_ring_size);
32163192
break;
@@ -3219,30 +3195,58 @@ static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
32193195
}
32203196
rxr->rx_agg_prod = prod;
32213197

3222-
if (bp->flags & BNXT_FLAG_TPA) {
3223-
if (rxr->rx_tpa) {
3224-
u8 *data;
3225-
dma_addr_t mapping;
3198+
if (rxr->rx_tpa) {
3199+
dma_addr_t mapping;
3200+
u8 *data;
32263201

3227-
for (i = 0; i < bp->max_tpa; i++) {
3228-
data = __bnxt_alloc_rx_data(bp, &mapping,
3229-
GFP_KERNEL);
3230-
if (!data)
3231-
return -ENOMEM;
3202+
for (i = 0; i < bp->max_tpa; i++) {
3203+
data = __bnxt_alloc_rx_data(bp, &mapping, GFP_KERNEL);
3204+
if (!data)
3205+
return -ENOMEM;
32323206

3233-
rxr->rx_tpa[i].data = data;
3234-
rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
3235-
rxr->rx_tpa[i].mapping = mapping;
3236-
}
3237-
} else {
3238-
netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
3239-
return -ENOMEM;
3207+
rxr->rx_tpa[i].data = data;
3208+
rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
3209+
rxr->rx_tpa[i].mapping = mapping;
32403210
}
32413211
}
3242-
32433212
return 0;
32443213
}
32453214

3215+
static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
3216+
{
3217+
struct bnxt_rx_ring_info *rxr;
3218+
struct bnxt_ring_struct *ring;
3219+
u32 type;
3220+
3221+
type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
3222+
RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
3223+
3224+
if (NET_IP_ALIGN == 2)
3225+
type |= RX_BD_FLAGS_SOP;
3226+
3227+
rxr = &bp->rx_ring[ring_nr];
3228+
ring = &rxr->rx_ring_struct;
3229+
bnxt_init_rxbd_pages(ring, type);
3230+
3231+
if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
3232+
bpf_prog_add(bp->xdp_prog, 1);
3233+
rxr->xdp_prog = bp->xdp_prog;
3234+
}
3235+
ring->fw_ring_id = INVALID_HW_RING_ID;
3236+
3237+
ring = &rxr->rx_agg_ring_struct;
3238+
ring->fw_ring_id = INVALID_HW_RING_ID;
3239+
3240+
if ((bp->flags & BNXT_FLAG_AGG_RINGS)) {
3241+
type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
3242+
RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
3243+
3244+
bnxt_init_rxbd_pages(ring, type);
3245+
}
3246+
3247+
return bnxt_alloc_one_rx_ring(bp, ring_nr);
3248+
}
3249+
32463250
static void bnxt_init_cp_rings(struct bnxt *bp)
32473251
{
32483252
int i, j;

0 commit comments

Comments
 (0)