1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020, Intel Corporation. */
3 
4 #include "igc.h"
5 #include "igc_xdp.h"
6 
7 int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
8 		     struct netlink_ext_ack *extack)
9 {
10 	struct net_device *dev = adapter->netdev;
11 	bool if_running = netif_running(dev);
12 	struct bpf_prog *old_prog;
13 
14 	if (dev->mtu > ETH_DATA_LEN) {
15 		/* For now, the driver doesn't support XDP functionality with
16 		 * jumbo frames so we return error.
17 		 */
18 		NL_SET_ERR_MSG_MOD(extack, "Jumbo frames not supported");
19 		return -EOPNOTSUPP;
20 	}
21 
22 	if (if_running)
23 		igc_close(dev);
24 
25 	old_prog = xchg(&adapter->xdp_prog, prog);
26 	if (old_prog)
27 		bpf_prog_put(old_prog);
28 
29 	if (if_running)
30 		igc_open(dev);
31 
32 	return 0;
33 }
34 
35 int igc_xdp_register_rxq_info(struct igc_ring *ring)
36 {
37 	struct net_device *dev = ring->netdev;
38 	int err;
39 
40 	err = xdp_rxq_info_reg(&ring->xdp_rxq, dev, ring->queue_index, 0);
41 	if (err) {
42 		netdev_err(dev, "Failed to register xdp rxq info\n");
43 		return err;
44 	}
45 
46 	err = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq, MEM_TYPE_PAGE_SHARED,
47 					 NULL);
48 	if (err) {
49 		netdev_err(dev, "Failed to register xdp rxq mem model\n");
50 		xdp_rxq_info_unreg(&ring->xdp_rxq);
51 		return err;
52 	}
53 
54 	return 0;
55 }
56 
57 void igc_xdp_unregister_rxq_info(struct igc_ring *ring)
58 {
59 	xdp_rxq_info_unreg(&ring->xdp_rxq);
60 }
61