]> Pileus Git - ~andy/linux/blobdiff - drivers/net/ethernet/intel/ixgbevf/ixgbevf.h
ixgbe: cleanup IXGBE_DESC_UNUSED
[~andy/linux] / drivers / net / ethernet / intel / ixgbevf / ixgbevf.h
index d7837dcc98972235caf19ff691b48b1f2e276896..8971e2d0a984d74055b788742190f9654fb5ac13 100644 (file)
 
 #include "vf.h"
 
+#ifdef CONFIG_NET_RX_BUSY_POLL
+#include <net/busy_poll.h>
+#define BP_EXTENDED_STATS
+#endif
+
 /* wrapper around a pointer to a socket buffer,
  * so a DMA handle can be stored along with the buffer */
 struct ixgbevf_tx_buffer {
@@ -76,6 +81,11 @@ struct ixgbevf_ring {
        struct u64_stats_sync   syncp;
        u64 hw_csum_rx_error;
        u64 hw_csum_rx_good;
+#ifdef BP_EXTENDED_STATS
+       u64 bp_yields;
+       u64 bp_misses;
+       u64 bp_cleaned;
+#endif
 
        u16 head;
        u16 tail;
@@ -145,7 +155,118 @@ struct ixgbevf_q_vector {
        struct napi_struct napi;
        struct ixgbevf_ring_container rx, tx;
        char name[IFNAMSIZ + 9];
+#ifdef CONFIG_NET_RX_BUSY_POLL
+       unsigned int state;
+#define IXGBEVF_QV_STATE_IDLE          0
+#define IXGBEVF_QV_STATE_NAPI          1    /* NAPI owns this QV */
+#define IXGBEVF_QV_STATE_POLL          2    /* poll owns this QV */
+#define IXGBEVF_QV_STATE_DISABLED      4    /* QV is disabled */
+#define IXGBEVF_QV_OWNED (IXGBEVF_QV_STATE_NAPI | IXGBEVF_QV_STATE_POLL)
+#define IXGBEVF_QV_LOCKED (IXGBEVF_QV_OWNED | IXGBEVF_QV_STATE_DISABLED)
+#define IXGBEVF_QV_STATE_NAPI_YIELD    8    /* NAPI yielded this QV */
+#define IXGBEVF_QV_STATE_POLL_YIELD    16   /* poll yielded this QV */
+#define IXGBEVF_QV_YIELD (IXGBEVF_QV_STATE_NAPI_YIELD | IXGBEVF_QV_STATE_POLL_YIELD)
+#define IXGBEVF_QV_USER_PEND (IXGBEVF_QV_STATE_POLL | IXGBEVF_QV_STATE_POLL_YIELD)
+       spinlock_t lock;
+#endif /* CONFIG_NET_RX_BUSY_POLL */
 };
+#ifdef CONFIG_NET_RX_BUSY_POLL
+static inline void ixgbevf_qv_init_lock(struct ixgbevf_q_vector *q_vector)
+{
+
+       spin_lock_init(&q_vector->lock);
+       q_vector->state = IXGBEVF_QV_STATE_IDLE;
+}
+
+/* called from the device poll routine to get ownership of a q_vector */
+static inline bool ixgbevf_qv_lock_napi(struct ixgbevf_q_vector *q_vector)
+{
+       int rc = true;
+       spin_lock_bh(&q_vector->lock);
+       if (q_vector->state & IXGBEVF_QV_LOCKED) {
+               WARN_ON(q_vector->state & IXGBEVF_QV_STATE_NAPI);
+               q_vector->state |= IXGBEVF_QV_STATE_NAPI_YIELD;
+               rc = false;
+#ifdef BP_EXTENDED_STATS
+               q_vector->tx.ring->bp_yields++;
+#endif
+       } else {
+               /* we don't care if someone yielded */
+               q_vector->state = IXGBEVF_QV_STATE_NAPI;
+       }
+       spin_unlock_bh(&q_vector->lock);
+       return rc;
+}
+
+/* returns true is someone tried to get the qv while napi had it */
+static inline bool ixgbevf_qv_unlock_napi(struct ixgbevf_q_vector *q_vector)
+{
+       int rc = false;
+       spin_lock_bh(&q_vector->lock);
+       WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_POLL |
+                                  IXGBEVF_QV_STATE_NAPI_YIELD));
+
+       if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
+               rc = true;
+       /* reset state to idle, unless QV is disabled */
+       q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
+       spin_unlock_bh(&q_vector->lock);
+       return rc;
+}
+
+/* called from ixgbevf_low_latency_poll() */
+static inline bool ixgbevf_qv_lock_poll(struct ixgbevf_q_vector *q_vector)
+{
+       int rc = true;
+       spin_lock_bh(&q_vector->lock);
+       if ((q_vector->state & IXGBEVF_QV_LOCKED)) {
+               q_vector->state |= IXGBEVF_QV_STATE_POLL_YIELD;
+               rc = false;
+#ifdef BP_EXTENDED_STATS
+               q_vector->rx.ring->bp_yields++;
+#endif
+       } else {
+               /* preserve yield marks */
+               q_vector->state |= IXGBEVF_QV_STATE_POLL;
+       }
+       spin_unlock_bh(&q_vector->lock);
+       return rc;
+}
+
+/* returns true if someone tried to get the qv while it was locked */
+static inline bool ixgbevf_qv_unlock_poll(struct ixgbevf_q_vector *q_vector)
+{
+       int rc = false;
+       spin_lock_bh(&q_vector->lock);
+       WARN_ON(q_vector->state & (IXGBEVF_QV_STATE_NAPI));
+
+       if (q_vector->state & IXGBEVF_QV_STATE_POLL_YIELD)
+               rc = true;
+       /* reset state to idle, unless QV is disabled */
+       q_vector->state &= IXGBEVF_QV_STATE_DISABLED;
+       spin_unlock_bh(&q_vector->lock);
+       return rc;
+}
+
+/* true if a socket is polling, even if it did not get the lock */
+static inline bool ixgbevf_qv_busy_polling(struct ixgbevf_q_vector *q_vector)
+{
+       WARN_ON(!(q_vector->state & IXGBEVF_QV_OWNED));
+       return q_vector->state & IXGBEVF_QV_USER_PEND;
+}
+
+/* false if QV is currently owned */
+static inline bool ixgbevf_qv_disable(struct ixgbevf_q_vector *q_vector)
+{
+       int rc = true;
+       spin_lock_bh(&q_vector->lock);
+       if (q_vector->state & IXGBEVF_QV_OWNED)
+               rc = false;
+       spin_unlock_bh(&q_vector->lock);
+       return rc;
+}
+
+#endif /* CONFIG_NET_RX_BUSY_POLL */
 
 /*
  * microsecond values for various ITR rates shifted by 2 to fit itr register
@@ -165,9 +286,13 @@ struct ixgbevf_q_vector {
        ((_eitr) ? (1000000000 / ((_eitr) * 256)) : 8)
 #define EITR_REG_TO_INTS_PER_SEC EITR_INTS_PER_SEC_TO_REG
 
-#define IXGBE_DESC_UNUSED(R) \
-       ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
-       (R)->next_to_clean - (R)->next_to_use - 1)
+static inline u16 ixgbevf_desc_unused(struct ixgbevf_ring *ring)
+{
+       u16 ntc = ring->next_to_clean;
+       u16 ntu = ring->next_to_use;
+
+       return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
+}
 
 #define IXGBEVF_RX_DESC(R, i)      \
        (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i]))
@@ -240,7 +365,6 @@ struct ixgbevf_adapter {
        struct ixgbe_hw hw;
        u16 msg_enable;
        struct ixgbevf_hw_stats stats;
-       u64 zero_base;
        /* Interrupt Throttle Rate */
        u32 eitr_param;
 
@@ -249,6 +373,16 @@ struct ixgbevf_adapter {
        unsigned int tx_ring_count;
        unsigned int rx_ring_count;
 
+#ifdef BP_EXTENDED_STATS
+       u64 bp_rx_yields;
+       u64 bp_rx_cleaned;
+       u64 bp_rx_missed;
+
+       u64 bp_tx_yields;
+       u64 bp_tx_cleaned;
+       u64 bp_tx_missed;
+#endif
+
        u32 link_speed;
        bool link_up;