From: Shannon Nelson <snelson@pensando.io>
To: snelson@pensando.io, netdev@vger.kernel.org
Subject: [PATCH v2 net-next 12/19] ionic: Add async link status check and basic stats
Date: Fri, 28 Jun 2019 14:39:27 -0700 [thread overview]
Message-ID: <20190628213934.8810-13-snelson@pensando.io> (raw)
In-Reply-To: <20190628213934.8810-1-snelson@pensando.io>
Add code to handle the link status event, and wire up the
basic netdev hardware stats.
Signed-off-by: Shannon Nelson <snelson@pensando.io>
---
.../net/ethernet/pensando/ionic/ionic_lif.c | 116 ++++++++++++++++++
.../net/ethernet/pensando/ionic/ionic_lif.h | 1 +
2 files changed, 117 insertions(+)
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index dbe35249ab76..be7ee002b11d 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -15,6 +15,7 @@
static void ionic_lif_rx_mode(struct lif *lif, unsigned int rx_mode);
static int ionic_lif_addr_add(struct lif *lif, const u8 *addr);
static int ionic_lif_addr_del(struct lif *lif, const u8 *addr);
+static void ionic_link_status_check(struct lif *lif);
static int ionic_set_nic_features(struct lif *lif, netdev_features_t features);
static int ionic_notifyq_clean(struct lif *lif, int budget);
@@ -44,6 +45,9 @@ static void ionic_lif_deferred_work(struct work_struct *work)
case DW_TYPE_RX_ADDR_DEL:
ionic_lif_addr_del(lif, w->addr);
break;
+ case DW_TYPE_LINK_STATUS:
+ ionic_link_status_check(lif);
+ break;
default:
break;
}
@@ -69,6 +73,7 @@ int ionic_open(struct net_device *netdev)
set_bit(LIF_UP, lif->state);
+ ionic_link_status_check(lif);
if (netif_carrier_ok(netdev))
netif_tx_wake_all_queues(netdev);
@@ -151,6 +156,39 @@ static int ionic_adminq_napi(struct napi_struct *napi, int budget)
return max(n_work, a_work);
}
+static void ionic_link_status_check(struct lif *lif)
+{
+ struct net_device *netdev = lif->netdev;
+ u16 link_status;
+ bool link_up;
+
+ clear_bit(LIF_LINK_CHECK_NEEDED, lif->state);
+
+ link_status = le16_to_cpu(lif->info->status.link_status);
+ link_up = link_status == PORT_OPER_STATUS_UP;
+
+ /* filter out the no-change cases */
+ if (link_up == netif_carrier_ok(netdev))
+ return;
+
+ if (link_up) {
+ netdev_info(netdev, "Link up - %d Gbps\n",
+ le32_to_cpu(lif->info->status.link_speed) / 1000);
+
+ if (test_bit(LIF_UP, lif->state)) {
+ netif_tx_wake_all_queues(lif->netdev);
+ netif_carrier_on(netdev);
+ }
+ } else {
+ netdev_info(netdev, "Link down\n");
+
+ /* carrier off first to avoid watchdog timeout */
+ netif_carrier_off(netdev);
+ if (test_bit(LIF_UP, lif->state))
+ netif_tx_stop_all_queues(netdev);
+ }
+}
+
static bool ionic_notifyq_service(struct cq *cq, struct cq_info *cq_info)
{
union notifyq_comp *comp = cq_info->cq_desc;
@@ -182,6 +220,9 @@ static bool ionic_notifyq_service(struct cq *cq, struct cq_info *cq_info)
" link_status=%d link_speed=%d\n",
le16_to_cpu(comp->link_change.link_status),
le32_to_cpu(comp->link_change.link_speed));
+
+ set_bit(LIF_LINK_CHECK_NEEDED, lif->state);
+
break;
case EVENT_OPCODE_RESET:
netdev_info(netdev, "Notifyq EVENT_OPCODE_RESET eid=%lld\n",
@@ -222,10 +263,81 @@ static int ionic_notifyq_clean(struct lif *lif, int budget)
if (work_done == budget)
goto return_to_napi;
+ /* After outstanding events are processed we can check on
+ * the link status and any outstanding interrupt credits.
+ *
+ * We wait until here to check on the link status in case
+ * there was a long list of link events from a flap episode.
+ */
+ if (test_bit(LIF_LINK_CHECK_NEEDED, lif->state)) {
+ struct ionic_deferred_work *work;
+
+ work = kzalloc(sizeof(*work), GFP_ATOMIC);
+ if (!work) {
+ netdev_err(lif->netdev, "%s OOM\n", __func__);
+ } else {
+ work->type = DW_TYPE_LINK_STATUS;
+ ionic_lif_deferred_enqueue(&lif->deferred, work);
+ }
+ }
+
return_to_napi:
return work_done;
}
+static void ionic_get_stats64(struct net_device *netdev,
+ struct rtnl_link_stats64 *ns)
+{
+ struct lif *lif = netdev_priv(netdev);
+ struct lif_stats *ls;
+
+ memset(ns, 0, sizeof(*ns));
+ ls = &lif->info->stats;
+
+ ns->rx_packets = le64_to_cpu(ls->rx_ucast_packets) +
+ le64_to_cpu(ls->rx_mcast_packets) +
+ le64_to_cpu(ls->rx_bcast_packets);
+
+ ns->tx_packets = le64_to_cpu(ls->tx_ucast_packets) +
+ le64_to_cpu(ls->tx_mcast_packets) +
+ le64_to_cpu(ls->tx_bcast_packets);
+
+ ns->rx_bytes = le64_to_cpu(ls->rx_ucast_bytes) +
+ le64_to_cpu(ls->rx_mcast_bytes) +
+ le64_to_cpu(ls->rx_bcast_bytes);
+
+ ns->tx_bytes = le64_to_cpu(ls->tx_ucast_bytes) +
+ le64_to_cpu(ls->tx_mcast_bytes) +
+ le64_to_cpu(ls->tx_bcast_bytes);
+
+ ns->rx_dropped = le64_to_cpu(ls->rx_ucast_drop_packets) +
+ le64_to_cpu(ls->rx_mcast_drop_packets) +
+ le64_to_cpu(ls->rx_bcast_drop_packets);
+
+ ns->tx_dropped = le64_to_cpu(ls->tx_ucast_drop_packets) +
+ le64_to_cpu(ls->tx_mcast_drop_packets) +
+ le64_to_cpu(ls->tx_bcast_drop_packets);
+
+ ns->multicast = le64_to_cpu(ls->rx_mcast_packets);
+
+ ns->rx_over_errors = le64_to_cpu(ls->rx_queue_empty);
+
+ ns->rx_missed_errors = le64_to_cpu(ls->rx_dma_error) +
+ le64_to_cpu(ls->rx_queue_disabled) +
+ le64_to_cpu(ls->rx_desc_fetch_error) +
+ le64_to_cpu(ls->rx_desc_data_error);
+
+ ns->tx_aborted_errors = le64_to_cpu(ls->tx_dma_error) +
+ le64_to_cpu(ls->tx_queue_disabled) +
+ le64_to_cpu(ls->tx_desc_fetch_error) +
+ le64_to_cpu(ls->tx_desc_data_error);
+
+ ns->rx_errors = ns->rx_over_errors +
+ ns->rx_missed_errors;
+
+ ns->tx_errors = ns->tx_aborted_errors;
+}
+
static int ionic_lif_addr_add(struct lif *lif, const u8 *addr)
{
struct ionic_admin_ctx ctx = {
@@ -581,6 +693,7 @@ static int ionic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
static const struct net_device_ops ionic_netdev_ops = {
.ndo_open = ionic_open,
.ndo_stop = ionic_stop,
+ .ndo_get_stats64 = ionic_get_stats64,
.ndo_set_rx_mode = ionic_set_rx_mode,
.ndo_set_features = ionic_set_features,
.ndo_set_mac_address = ionic_set_mac_address,
@@ -1420,6 +1533,8 @@ static int ionic_lif_init(struct lif *lif)
set_bit(LIF_INITED, lif->state);
+ ionic_link_status_check(lif);
+
return 0;
err_out_notifyq_deinit:
@@ -1463,6 +1578,7 @@ int ionic_lifs_register(struct ionic *ionic)
return err;
}
+ ionic_link_status_check(ionic->master_lif);
ionic->master_lif->registered = true;
return 0;
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.h b/drivers/net/ethernet/pensando/ionic/ionic_lif.h
index 20b4fa573f77..9930b9390c8a 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.h
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.h
@@ -86,6 +86,7 @@ struct ionic_deferred {
enum lif_state_flags {
LIF_INITED,
LIF_UP,
+ LIF_LINK_CHECK_NEEDED,
LIF_QUEUE_RESET,
/* leave this as last */
--
2.17.1
next prev parent reply other threads:[~2019-06-28 21:39 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 21:39 [PATCH v2 net-next 00/19] Add ionic driver Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 01/19] ionic: Add basic framework for IONIC Network device driver Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 02/19] ionic: Add hardware init and device commands Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 03/19] ionic: Add port management commands Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 04/19] ionic: Add basic lif support Shannon Nelson
2019-06-29 18:45 ` Jakub Kicinski
2019-07-01 18:00 ` Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 05/19] ionic: Add interrupts and doorbells Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 06/19] ionic: Add basic adminq support Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 07/19] ionic: Add adminq action Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 08/19] ionic: Add notifyq support Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 09/19] ionic: Add the basic NDO callbacks for netdev support Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 10/19] ionic: Add management of rx filters Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 11/19] ionic: Add Rx filter and rx_mode ndo support Shannon Nelson
2019-06-28 21:39 ` Shannon Nelson [this message]
2019-06-28 21:39 ` [PATCH v2 net-next 13/19] ionic: Add initial ethtool support Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 14/19] ionic: Add Tx and Rx handling Shannon Nelson
2019-06-29 18:57 ` Jakub Kicinski
2019-07-01 18:17 ` Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 15/19] ionic: Add netdev-event handling Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 16/19] ionic: Add driver stats Shannon Nelson
2019-06-29 18:53 ` Jakub Kicinski
2019-07-01 18:06 ` Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 17/19] ionic: Add RSS support Shannon Nelson
2019-06-29 18:48 ` Jakub Kicinski
2019-07-01 18:03 ` Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 18/19] ionic: Add coalesce and other features Shannon Nelson
2019-06-28 21:39 ` [PATCH v2 net-next 19/19] ionic: Add basic devlink interface Shannon Nelson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190628213934.8810-13-snelson@pensando.io \
--to=snelson@pensando.io \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox