Skip to content

Commit 73a6e37

Browse files
Andre Guedesanguy11
authored andcommitted
igc: Refactor __igc_xdp_run_prog()
Refactor __igc_xdp_run_prog() helper from igc_xdp_run_prog(), preparing the code for AF_XDP zero-copy support which is added by upcoming patches. The existing igc_xdp_run_prog() caters to regular XDP rx path which has to verify if bpf_prog is not NULL. Zero-copy path assumes that bpf_prog is not NULL and hence this check is not required. Therefore it makes sense to refactor the common code into a helper function, to avoid code duplication. Signed-off-by: Andre Guedes <[email protected]> Signed-off-by: Vedang Patel <[email protected]> Signed-off-by: Jithu Joseph <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Tested-by: Dvora Fuxbrumer <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 0c20f2d commit 73a6e37

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

drivers/net/ethernet/intel/igc/igc_main.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,48 +2020,48 @@ static int igc_xdp_xmit_back(struct igc_adapter *adapter, struct xdp_buff *xdp)
20202020
return res;
20212021
}
20222022

2023-
static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter,
2024-
struct xdp_buff *xdp)
2023+
/* This function assumes rcu_read_lock() is held by the caller. */
2024+
static int __igc_xdp_run_prog(struct igc_adapter *adapter,
2025+
struct bpf_prog *prog,
2026+
struct xdp_buff *xdp)
20252027
{
2026-
struct bpf_prog *prog;
2027-
int res;
2028-
u32 act;
2029-
2030-
rcu_read_lock();
2031-
2032-
prog = READ_ONCE(adapter->xdp_prog);
2033-
if (!prog) {
2034-
res = IGC_XDP_PASS;
2035-
goto unlock;
2036-
}
2028+
u32 act = bpf_prog_run_xdp(prog, xdp);
20372029

2038-
act = bpf_prog_run_xdp(prog, xdp);
20392030
switch (act) {
20402031
case XDP_PASS:
2041-
res = IGC_XDP_PASS;
2042-
break;
2032+
return IGC_XDP_PASS;
20432033
case XDP_TX:
2044-
if (igc_xdp_xmit_back(adapter, xdp) < 0)
2045-
res = IGC_XDP_CONSUMED;
2046-
else
2047-
res = IGC_XDP_TX;
2048-
break;
2034+
return igc_xdp_xmit_back(adapter, xdp) < 0 ?
2035+
IGC_XDP_CONSUMED : IGC_XDP_TX;
20492036
case XDP_REDIRECT:
2050-
if (xdp_do_redirect(adapter->netdev, xdp, prog) < 0)
2051-
res = IGC_XDP_CONSUMED;
2052-
else
2053-
res = IGC_XDP_REDIRECT;
2054-
break;
2037+
return xdp_do_redirect(adapter->netdev, xdp, prog) < 0 ?
2038+
IGC_XDP_CONSUMED : IGC_XDP_REDIRECT;
20552039
default:
20562040
bpf_warn_invalid_xdp_action(act);
20572041
fallthrough;
20582042
case XDP_ABORTED:
20592043
trace_xdp_exception(adapter->netdev, prog, act);
20602044
fallthrough;
20612045
case XDP_DROP:
2062-
res = IGC_XDP_CONSUMED;
2063-
break;
2046+
return IGC_XDP_CONSUMED;
20642047
}
2048+
}
2049+
2050+
static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter,
2051+
struct xdp_buff *xdp)
2052+
{
2053+
struct bpf_prog *prog;
2054+
int res;
2055+
2056+
rcu_read_lock();
2057+
2058+
prog = READ_ONCE(adapter->xdp_prog);
2059+
if (!prog) {
2060+
res = IGC_XDP_PASS;
2061+
goto unlock;
2062+
}
2063+
2064+
res = __igc_xdp_run_prog(adapter, prog, xdp);
20652065

20662066
unlock:
20672067
rcu_read_unlock();

0 commit comments

Comments
 (0)