Skip to content

Commit 0182d07

Browse files
Subbaraya Sundeepdavem330
authored andcommitted
octeontx2-pf: Simplify the receive buffer size calculation
This patch separates the logic of configuring hardware maximum transmit frame size and receive frame size. This simplifies the logic to calculate receive buffer size and using cqe descriptor of different size. Also additional size of skb_shared_info structure is allocated for each receive buffer pointer given to hardware which is not necessary. Hence change the size calculation to remove the size of skb_shared_info. Add a check for array out of bounds while adding fragments to the network stack. Signed-off-by: Subbaraya Sundeep <sbhatta@marvell.com> Signed-off-by: Hariprasad Kelam <hkelam@marvell.com> Signed-off-by: Sunil Goutham <sgoutham@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b9c56cc commit 0182d07

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

drivers/net/ethernet/marvell/octeontx2/nic/cn10k.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int cn10k_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura)
8888
aq->sq.ena = 1;
8989
/* Only one SMQ is allocated, map all SQ's to that SMQ */
9090
aq->sq.smq = pfvf->hw.txschq_list[NIX_TXSCH_LVL_SMQ][0];
91-
aq->sq.smq_rr_weight = mtu_to_dwrr_weight(pfvf, pfvf->max_frs);
91+
aq->sq.smq_rr_weight = mtu_to_dwrr_weight(pfvf, pfvf->tx_max_pktlen);
9292
aq->sq.default_chan = pfvf->hw.tx_chan_base;
9393
aq->sq.sqe_stype = NIX_STYPE_STF; /* Cache SQB */
9494
aq->sq.sqb_aura = sqb_aura;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu)
231231
return -ENOMEM;
232232
}
233233

234-
req->maxlen = pfvf->max_frs;
234+
req->maxlen = pfvf->netdev->mtu + OTX2_ETH_HLEN + OTX2_HW_TIMESTAMP_LEN;
235235

236236
err = otx2_sync_mbox_msg(&pfvf->mbox);
237237
mutex_unlock(&pfvf->mbox.lock);
@@ -590,7 +590,7 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl)
590590
u64 schq, parent;
591591
u64 dwrr_val;
592592

593-
dwrr_val = mtu_to_dwrr_weight(pfvf, pfvf->max_frs);
593+
dwrr_val = mtu_to_dwrr_weight(pfvf, pfvf->tx_max_pktlen);
594594

595595
req = otx2_mbox_alloc_msg_nix_txschq_cfg(&pfvf->mbox);
596596
if (!req)
@@ -603,9 +603,7 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl)
603603
/* Set topology e.t.c configuration */
604604
if (lvl == NIX_TXSCH_LVL_SMQ) {
605605
req->reg[0] = NIX_AF_SMQX_CFG(schq);
606-
req->regval[0] = ((pfvf->netdev->max_mtu + OTX2_ETH_HLEN) << 8)
607-
| OTX2_MIN_MTU;
608-
606+
req->regval[0] = ((u64)pfvf->tx_max_pktlen << 8) | OTX2_MIN_MTU;
609607
req->regval[0] |= (0x20ULL << 51) | (0x80ULL << 39) |
610608
(0x2ULL << 36);
611609
req->num_regs++;
@@ -800,7 +798,7 @@ int otx2_sq_aq_init(void *dev, u16 qidx, u16 sqb_aura)
800798
aq->sq.ena = 1;
801799
/* Only one SMQ is allocated, map all SQ's to that SMQ */
802800
aq->sq.smq = pfvf->hw.txschq_list[NIX_TXSCH_LVL_SMQ][0];
803-
aq->sq.smq_rr_quantum = mtu_to_dwrr_weight(pfvf, pfvf->max_frs);
801+
aq->sq.smq_rr_quantum = mtu_to_dwrr_weight(pfvf, pfvf->tx_max_pktlen);
804802
aq->sq.default_chan = pfvf->hw.tx_chan_base;
805803
aq->sq.sqe_stype = NIX_STYPE_STF; /* Cache SQB */
806804
aq->sq.sqb_aura = sqb_aura;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ struct otx2_nic {
326326
struct net_device *netdev;
327327
struct dev_hw_ops *hw_ops;
328328
void *iommu_domain;
329-
u16 max_frs;
329+
u16 tx_max_pktlen;
330330
u16 rbsize; /* Receive buffer size */
331331

332332
#define OTX2_FLAG_RX_TSTAMP_ENABLED BIT_ULL(0)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,16 +1312,14 @@ static int otx2_get_rbuf_size(struct otx2_nic *pf, int mtu)
13121312
* NIX transfers entire data using 6 segments/buffers and writes
13131313
* a CQE_RX descriptor with those segment addresses. First segment
13141314
* has additional data prepended to packet. Also software omits a
1315-
* headroom of 128 bytes and sizeof(struct skb_shared_info) in
1316-
* each segment. Hence the total size of memory needed
1317-
* to receive a packet with 'mtu' is:
1315+
* headroom of 128 bytes in each segment. Hence the total size of
1316+
* memory needed to receive a packet with 'mtu' is:
13181317
* frame size = mtu + additional data;
1319-
* memory = frame_size + (headroom + struct skb_shared_info size) * 6;
1318+
* memory = frame_size + headroom * 6;
13201319
* each receive buffer size = memory / 6;
13211320
*/
13221321
frame_size = mtu + OTX2_ETH_HLEN + OTX2_HW_TIMESTAMP_LEN;
1323-
total_size = frame_size + (OTX2_HEAD_ROOM +
1324-
OTX2_DATA_ALIGN(sizeof(struct skb_shared_info))) * 6;
1322+
total_size = frame_size + OTX2_HEAD_ROOM * 6;
13251323
rbuf_size = total_size / 6;
13261324

13271325
return ALIGN(rbuf_size, 2048);
@@ -1343,7 +1341,8 @@ static int otx2_init_hw_resources(struct otx2_nic *pf)
13431341
hw->sqpool_cnt = hw->tot_tx_queues;
13441342
hw->pool_cnt = hw->rqpool_cnt + hw->sqpool_cnt;
13451343

1346-
pf->max_frs = pf->netdev->mtu + OTX2_ETH_HLEN + OTX2_HW_TIMESTAMP_LEN;
1344+
/* Maximum hardware supported transmit length */
1345+
pf->tx_max_pktlen = pf->netdev->max_mtu + OTX2_ETH_HLEN;
13471346

13481347
pf->rbsize = otx2_get_rbuf_size(pf, pf->netdev->mtu);
13491348

@@ -1807,7 +1806,7 @@ static netdev_tx_t otx2_xmit(struct sk_buff *skb, struct net_device *netdev)
18071806

18081807
/* Check for minimum and maximum packet length */
18091808
if (skb->len <= ETH_HLEN ||
1810-
(!skb_shinfo(skb)->gso_size && skb->len > pf->max_frs)) {
1809+
(!skb_shinfo(skb)->gso_size && skb->len > pf->tx_max_pktlen)) {
18111810
dev_kfree_skb(skb);
18121811
return NETDEV_TX_OK;
18131812
}

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ static void otx2_set_rxtstamp(struct otx2_nic *pfvf,
181181
skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(tsns);
182182
}
183183

184-
static void otx2_skb_add_frag(struct otx2_nic *pfvf, struct sk_buff *skb,
185-
u64 iova, int len, struct nix_rx_parse_s *parse)
184+
static bool otx2_skb_add_frag(struct otx2_nic *pfvf, struct sk_buff *skb,
185+
u64 iova, int len, struct nix_rx_parse_s *parse,
186+
int qidx)
186187
{
187188
struct page *page;
188189
int off = 0;
@@ -203,11 +204,22 @@ static void otx2_skb_add_frag(struct otx2_nic *pfvf, struct sk_buff *skb,
203204
}
204205

205206
page = virt_to_page(va);
206-
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
207-
va - page_address(page) + off, len - off, pfvf->rbsize);
207+
if (likely(skb_shinfo(skb)->nr_frags < MAX_SKB_FRAGS)) {
208+
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
209+
va - page_address(page) + off,
210+
len - off, pfvf->rbsize);
211+
212+
otx2_dma_unmap_page(pfvf, iova - OTX2_HEAD_ROOM,
213+
pfvf->rbsize, DMA_FROM_DEVICE);
214+
return true;
215+
}
208216

209-
otx2_dma_unmap_page(pfvf, iova - OTX2_HEAD_ROOM,
210-
pfvf->rbsize, DMA_FROM_DEVICE);
217+
/* If more than MAX_SKB_FRAGS fragments are received then
218+
* give back those buffer pointers to hardware for reuse.
219+
*/
220+
pfvf->hw_ops->aura_freeptr(pfvf, qidx, iova & ~0x07ULL);
221+
222+
return false;
211223
}
212224

213225
static void otx2_set_rxhash(struct otx2_nic *pfvf,
@@ -349,9 +361,9 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
349361
seg_addr = &sg->seg_addr;
350362
seg_size = (void *)sg;
351363
for (seg = 0; seg < sg->segs; seg++, seg_addr++) {
352-
otx2_skb_add_frag(pfvf, skb, *seg_addr, seg_size[seg],
353-
parse);
354-
cq->pool_ptrs++;
364+
if (otx2_skb_add_frag(pfvf, skb, *seg_addr,
365+
seg_size[seg], parse, cq->cq_idx))
366+
cq->pool_ptrs++;
355367
}
356368
start += sizeof(*sg);
357369
}

drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
#define RCV_FRAG_LEN(x) \
4040
((RCV_FRAG_LEN1(x) < 2048) ? 2048 : RCV_FRAG_LEN1(x))
4141

42-
#define DMA_BUFFER_LEN(x) \
43-
((x) - OTX2_HEAD_ROOM - \
44-
OTX2_DATA_ALIGN(sizeof(struct skb_shared_info)))
42+
#define DMA_BUFFER_LEN(x) ((x) - OTX2_HEAD_ROOM)
4543

4644
/* IRQ triggered when NIX_LF_CINTX_CNT[ECOUNT]
4745
* is equal to this value.

0 commit comments

Comments
 (0)