Subject: [RFC v2 1/6] bnxt: use extack for xdp error messages

From: Stephen Hemminger <[email-masked]>
Date: Thu, 28 Feb 2019 13:54:36 -0800

XDP has a netlink error message buffer available that should
be used for errors instead of console logging.

Signed-off-by: Stephen Hemminger <[email-masked]>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 26 +++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
index 0184ef6f05a7..a9f6a3a66b4c 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
@@ -150,19 +150,21 @@ bool bnxt_rx_xdp(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, u16 cons,
 }
 
 /* Under rtnl_lock */
-static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
+static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog,
+			struct netlink_ext_ack *extack)
 {
 	struct net_device *dev = bp->dev;
 	int tx_xdp = 0, rc, tc;
 	struct bpf_prog *old;
 
 	if (prog && bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU) {
-		netdev_warn(dev, "MTU %d larger than largest XDP supported MTU %d.\n",
-			    bp->dev->mtu, BNXT_MAX_PAGE_MODE_MTU);
+		NL_SET_ERR_MSG_MOD(extack,
+				   "MTU larger than largest XDP supported MTU");
 		return -EOPNOTSUPP;
 	}
 	if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) {
-		netdev_warn(dev, "ethtool rx/tx channels must be combined to support XDP.\n");
+		NL_SET_ERR_MSG_MOD(extack,
+				   "ethtool rx/tx channels must be combined to support XDP");
 		return -EOPNOTSUPP;
 	}
 	if (prog)
@@ -174,7 +176,8 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
 	rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
 			      true, tc, tx_xdp);
 	if (rc) {
-		netdev_warn(dev, "Unable to reserve enough TX rings to support XDP.\n");
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Unable to reserve enough TX rings to support XDP.\n");
 		return rc;
 	}
 	if (netif_running(dev))
@@ -211,19 +214,16 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
 int bnxt_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
 	struct bnxt *bp = netdev_priv(dev);
-	int rc;
 
 	switch (xdp->command) {
 	case XDP_SETUP_PROG:
-		rc = bnxt_xdp_set(bp, xdp->prog);
-		break;
+		return bnxt_xdp_set(bp, xdp->prog, xdp->extack);
+
 	case XDP_QUERY_PROG:
 		xdp->prog_id = bp->xdp_prog ? bp->xdp_prog->aux->id : 0;
-		rc = 0;
-		break;
+		return 0;
 	default:
-		rc = -EINVAL;
-		break;
+		NL_SET_ERR_MSG_MOD(xdp->extack, "Unsupported XDP command");
+		return -EINVAL;
 	}
-	return rc;
 }
-- 
2.17.1