nfp: prepare print macros for use without netdev
authorJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 6 Jun 2017 00:01:46 +0000 (17:01 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 7 Jun 2017 16:51:38 +0000 (12:51 -0400)
To be able to reuse print macros easily with control vNICs make the
macros check if netdev pointer is populated and use dev_* print
functions otherwise.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfp_net.h

index 2e526338f6780cad897f7b53d338c686dad197a8..b14aa31d494a38b7390406c191833d99d9b2ec65 100644 (file)
 
 #include "nfp_net_ctrl.h"
 
-#define nn_err(nn, fmt, args...)  netdev_err((nn)->dp.netdev, fmt, ## args)
-#define nn_warn(nn, fmt, args...) netdev_warn((nn)->dp.netdev, fmt, ## args)
-#define nn_info(nn, fmt, args...) netdev_info((nn)->dp.netdev, fmt, ## args)
-#define nn_dbg(nn, fmt, args...)  netdev_dbg((nn)->dp.netdev, fmt, ## args)
+#define nn_pr(nn, lvl, fmt, args...)                                   \
+       ({                                                              \
+               struct nfp_net *__nn = (nn);                            \
+                                                                       \
+               if (__nn->dp.netdev)                                    \
+                       netdev_printk(lvl, __nn->dp.netdev, fmt, ## args); \
+               else                                                    \
+                       dev_printk(lvl, __nn->dp.dev, "ctrl: " fmt, ## args); \
+       })
+
+#define nn_err(nn, fmt, args...)       nn_pr(nn, KERN_ERR, fmt, ## args)
+#define nn_warn(nn, fmt, args...)      nn_pr(nn, KERN_WARNING, fmt, ## args)
+#define nn_info(nn, fmt, args...)      nn_pr(nn, KERN_INFO, fmt, ## args)
+#define nn_dbg(nn, fmt, args...)       nn_pr(nn, KERN_DEBUG, fmt, ## args)
+
 #define nn_dp_warn(dp, fmt, args...)                                   \
-       do {                                                            \
-               if (unlikely(net_ratelimit()))                          \
-                       netdev_warn((dp)->netdev, fmt, ## args);        \
-       } while (0)
+       ({                                                              \
+               struct nfp_net_dp *__dp = (dp);                         \
+                                                                       \
+               if (unlikely(net_ratelimit())) {                        \
+                       if (__dp->netdev)                               \
+                               netdev_warn(__dp->netdev, fmt, ## args); \
+                       else                                            \
+                               dev_warn(__dp->dev, fmt, ## args);      \
+               }                                                       \
+       })
 
 /* Max time to wait for NFP to respond on updates (in seconds) */
 #define NFP_NET_POLL_TIMEOUT   5