[PATCH v2 07/15] ice: Add support for VSI allocation and deallocation

2018-03-15 Thread Anirudh Venkataramanan
This patch introduces data structures and functions to alloc/free
VSIs. The driver represents a VSI using the ice_vsi structure.

Some noteworthy points about VSI allocation:

1) A VSI is allocated in the firmware using the "add VSI" admin queue
   command (implemented as ice_aq_add_vsi). The firmware returns an
   identifier for the allocated VSI. The VSI context is used to program
   certain aspects (loopback, queue map, etc.) of the VSI's configuration.

2) A VSI is deleted using the "free VSI" admin queue command (implemented
   as ice_aq_free_vsi).

3) The driver represents a VSI using struct ice_vsi. This is allocated
   and initialized as part of the ice_vsi_alloc flow, and deallocated
   as part of the ice_vsi_delete flow.

4) Once the VSI is created, a netdev is allocated and associated with it.
   The VSI's ring and vector related data structures are also allocated
   and initialized.

5) A VSI's queues can either be contiguous or scattered. To do this, the
   driver maintains a bitmap (vsi->avail_txqs) which is kept in sync with
   the firmware's VSI queue allocation imap. If the VSI can't get a
   contiguous queue allocation, it will fallback to scatter. This is
   implemented in ice_vsi_get_qs which is called as part of the VSI setup
   flow. In the release flow, the VSI's queues are released and the bitmap
   is updated to reflect this by ice_vsi_put_qs.

CC: Shannon Nelson <shannon.nel...@oracle.com>
Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
v2: Addressed Shannon Nelson's comments by
   1) using a new define ICE_NO_VSI instead of the magic number 0x.
   2) adding missing curly braces and break statements.

Also, ice_set_def_vsi_ctx was changed to ice_set_dflt_vsi_ctx for clarity.
---
 drivers/net/ethernet/intel/ice/ice.h|   72 ++
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  199 
 drivers/net/ethernet/intel/ice/ice_main.c   |  +++
 drivers/net/ethernet/intel/ice/ice_switch.c |  115 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |   21 +
 drivers/net/ethernet/intel/ice/ice_txrx.h   |   26 +
 drivers/net/ethernet/intel/ice/ice_type.h   |4 +
 7 files changed, 1548 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index c8079c852a48..c9f59374daad 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -25,6 +25,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -32,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
@@ -41,17 +44,43 @@
 #include "ice_sched.h"
 
 #define ICE_BAR0   0
+#define ICE_DFLT_NUM_DESC  128
+#define ICE_REQ_DESC_MULTIPLE  32
 #define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
 #define ICE_AQ_LEN 64
 #define ICE_MIN_MSIX   2
+#define ICE_NO_VSI 0x
 #define ICE_MAX_VSI_ALLOC  130
 #define ICE_MAX_TXQS   2048
 #define ICE_MAX_RXQS   2048
+#define ICE_VSI_MAP_CONTIG 0
+#define ICE_VSI_MAP_SCATTER1
+#define ICE_MAX_SCATTER_TXQS   16
+#define ICE_MAX_SCATTER_RXQS   16
 #define ICE_RES_VALID_BIT  0x8000
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
+#define ICE_INVAL_Q_INDEX  0x
 
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+#define ICE_MAX_MTU(ICE_AQ_SET_MAC_FRAME_SIZE_MAX - \
+ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN)
+
+#define ICE_UP_TABLE_TRANSLATE(val, i) \
+   (((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
+ ICE_AQ_VSI_UP_TABLE_UP##i##_M)
+
+struct ice_tc_info {
+   u16 qoffset;
+   u16 qcount;
+};
+
+struct ice_tc_cfg {
+   u8 numtc; /* Total number of enabled TCs */
+   u8 ena_tc; /* TX map */
+   struct ice_tc_info tc_info[ICE_MAX_TRAFFIC_CLASS];
+};
+
 struct ice_res_tracker {
u16 num_entries;
u16 search_hint;
@@ -75,8 +104,47 @@ enum ice_state {
 /* struct that defines a VSI, associated with a dev */
 struct ice_vsi {
struct net_device *netdev;
+   struct ice_sw *vsw;  /* switch this VSI is on */
+   struct ice_pf *back; /* back pointer to PF */
struct ice_port_info *port_info; /* back pointer to port_info */
+   struct ice_ring **rx_rings;  /* rx ring array */
+   struct ice_ring **tx_rings;  /* tx ring array */
+   struct ice_q_vector **q_vectors; /* q_vector array */
+   DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   int num_q_vectors;
+   int base_vector;
+   enum ice_vsi_type type;
u16 vsi_num; /* HW (absolute) index of this VSI */
+   u16 idx; /* software index in pf->vsi[] */
+
+   /* Interrupt thresholds */
+   

[PATCH v2 06/15] ice: Initialize PF and setup miscellaneous interrupt

2018-03-15 Thread Anirudh Venkataramanan
This patch continues the initialization flow as follows:

1) Allocate and initialize necessary fields (like vsi, num_alloc_vsi,
   irq_tracker, etc) in the ice_pf instance.

2) Setup the miscellaneous interrupt handler. This also known as the
   "other interrupt causes" (OIC) handler and is used to handle non
   hotpath interrupts (like control queue events, link events,
   exceptions, etc.

3) Implement a background task to process admin queue receive (ARQ)
   events received by the driver.

CC: Shannon Nelson <shannon.nel...@oracle.com>
Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
v2: Removed reference to "lump" as suggested by Shannon Nelson.
---
 drivers/net/ethernet/intel/ice/ice.h|  84 +++
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |   2 +
 drivers/net/ethernet/intel/ice/ice_common.c |   6 +
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_controlq.c   | 101 
 drivers/net/ethernet/intel/ice/ice_controlq.h   |   8 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  63 +++
 drivers/net/ethernet/intel/ice/ice_main.c   | 719 +++-
 drivers/net/ethernet/intel/ice/ice_txrx.h   |  43 ++
 drivers/net/ethernet/intel/ice/ice_type.h   |  11 +
 10 files changed, 1039 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.h

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 9681e971bcab..c8079c852a48 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -26,29 +26,113 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
+#include 
 #include "ice_devids.h"
 #include "ice_type.h"
+#include "ice_txrx.h"
 #include "ice_switch.h"
 #include "ice_common.h"
 #include "ice_sched.h"
 
 #define ICE_BAR0   0
+#define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
 #define ICE_AQ_LEN 64
+#define ICE_MIN_MSIX   2
+#define ICE_MAX_VSI_ALLOC  130
+#define ICE_MAX_TXQS   2048
+#define ICE_MAX_RXQS   2048
+#define ICE_RES_VALID_BIT  0x8000
+#define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+struct ice_res_tracker {
+   u16 num_entries;
+   u16 search_hint;
+   u16 list[1];
+};
+
+struct ice_sw {
+   struct ice_pf *pf;
+   u16 sw_id;  /* switch ID for this switch */
+   u16 bridge_mode;/* VEB/VEPA/Port Virtualizer */
+};
+
 enum ice_state {
__ICE_DOWN,
+   __ICE_PFR_REQ,  /* set by driver and peers */
+   __ICE_ADMINQ_EVENT_PENDING,
+   __ICE_SERVICE_SCHED,
__ICE_STATE_NBITS   /* must be last */
 };
 
+/* struct that defines a VSI, associated with a dev */
+struct ice_vsi {
+   struct net_device *netdev;
+   struct ice_port_info *port_info; /* back pointer to port_info */
+   u16 vsi_num; /* HW (absolute) index of this VSI */
+} cacheline_internodealigned_in_smp;
+
+enum ice_pf_flags {
+   ICE_FLAG_MSIX_ENA,
+   ICE_FLAG_FLTR_SYNC,
+   ICE_FLAG_RSS_ENA,
+   ICE_PF_FLAGS_NBITS  /* must be last */
+};
+
 struct ice_pf {
struct pci_dev *pdev;
+   struct msix_entry *msix_entries;
+   struct ice_res_tracker *irq_tracker;
+   struct ice_vsi **vsi;   /* VSIs created by the driver */
+   struct ice_sw *first_sw;/* first switch created by firmware */
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   DECLARE_BITMAP(avail_txqs, ICE_MAX_TXQS);
+   DECLARE_BITMAP(avail_rxqs, ICE_MAX_RXQS);
+   DECLARE_BITMAP(flags, ICE_PF_FLAGS_NBITS);
+   unsigned long serv_tmr_period;
+   unsigned long serv_tmr_prev;
+   struct timer_list serv_tmr;
+   struct work_struct serv_task;
+   struct mutex avail_q_mutex; /* protects access to avail_[rx|tx]qs */
+   struct mutex sw_mutex;  /* lock for protecting VSI alloc flow */
u32 msg_enable;
+   u32 oicr_idx;   /* Other interrupt cause vector index */
+   u32 num_lan_msix;   /* Total MSIX vectors for base driver */
+   u32 num_avail_msix; /* remaining MSIX vectors left unclaimed */
+   u16 num_lan_tx; /* num lan tx queues setup */
+   u16 num_lan_rx; /* num lan rx queues setup */
+   u16 q_left_tx;  /* remaining num tx queues left unclaimed */
+   u16 q_left_rx;  /* remaining num rx queues left unclaimed */
+   u16 next_vsi;   /* Next free slot in pf->vsi[] - 0-based! */
+   u16 num_alloc_vsi;
+
struct ice_hw hw;
+   char int_name[ICE_INT_NAME_STR_LEN];
 };
+
+/**
+ * ice_irq_dynamic_ena - Enable default interrupt generation se

[PATCH v2 09/15] ice: Configure VSIs for Tx/Rx

2018-03-15 Thread Anirudh Venkataramanan
This patch configures the VSIs to be able to send and receive
packets by doing the following:

1) Initialize flexible parser to extract and include certain
   fields in the Rx descriptor.

2) Add Tx queues by programming the Tx queue context (implemented in
   ice_vsi_cfg_txqs). Note that adding the queues also enables (starts)
   the queues.

3) Add Rx queues by programming Rx queue context (implemented in
   ice_vsi_cfg_rxqs). Note that this only adds queues but doesn't start
   them. The rings will be started by calling ice_vsi_start_rx_rings on
   interface up.

4) Configure interrupts for VSI queues.

5) Implement ice_open and ice_stop.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/Makefile |3 +-
 drivers/net/ethernet/intel/ice/ice.h|   36 +-
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |   86 ++
 drivers/net/ethernet/intel/ice/ice_common.c |  602 
 drivers/net/ethernet/intel/ice/ice_common.h |   13 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |   59 ++
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  |  260 ++
 drivers/net/ethernet/intel/ice/ice_main.c   | 1140 ++-
 drivers/net/ethernet/intel/ice/ice_sched.c  |  105 +++
 drivers/net/ethernet/intel/ice/ice_sched.h  |5 +
 drivers/net/ethernet/intel/ice/ice_status.h |2 +
 drivers/net/ethernet/intel/ice/ice_txrx.c   |  375 
 drivers/net/ethernet/intel/ice/ice_txrx.h   |   75 ++
 drivers/net/ethernet/intel/ice/ice_type.h   |2 +
 14 files changed, 2757 insertions(+), 6 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.c

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 809d85c04398..0abeb20c006d 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -29,4 +29,5 @@ ice-y := ice_main.o   \
 ice_common.o   \
 ice_nvm.o  \
 ice_switch.o   \
-ice_sched.o
+ice_sched.o\
+ice_txrx.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index c9f59374daad..e3ec19099e37 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -25,8 +25,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -57,6 +59,8 @@
 #define ICE_VSI_MAP_SCATTER1
 #define ICE_MAX_SCATTER_TXQS   16
 #define ICE_MAX_SCATTER_RXQS   16
+#define ICE_Q_WAIT_RETRY_LIMIT 10
+#define ICE_Q_WAIT_MAX_RETRY   (5 * ICE_Q_WAIT_RETRY_LIMIT)
 #define ICE_RES_VALID_BIT  0x8000
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 #define ICE_INVAL_Q_INDEX  0x
@@ -70,6 +74,14 @@
(((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
  ICE_AQ_VSI_UP_TABLE_UP##i##_M)
 
+#define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
+
+#define ice_for_each_txq(vsi, i) \
+   for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
+
+#define ice_for_each_rxq(vsi, i) \
+   for ((i) = 0; (i) < (vsi)->num_rxq; (i)++)
+
 struct ice_tc_info {
u16 qoffset;
u16 qcount;
@@ -110,6 +122,9 @@ struct ice_vsi {
struct ice_ring **rx_rings;  /* rx ring array */
struct ice_ring **tx_rings;  /* tx ring array */
struct ice_q_vector **q_vectors; /* q_vector array */
+
+   irqreturn_t (*irq_handler)(int irq, void *data);
+
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
int num_q_vectors;
int base_vector;
@@ -120,8 +135,14 @@ struct ice_vsi {
/* Interrupt thresholds */
u16 work_lmt;
 
+   u16 max_frame;
+   u16 rx_buf_len;
+
struct ice_aqc_vsi_props info;   /* VSI properties */
 
+   bool irqs_ready;
+   bool current_isup;   /* Sync 'link up' logging */
+
/* queue information */
u8 tx_mapping_mode;  /* ICE_MAP_MODE_[CONTIG|SCATTER] */
u8 rx_mapping_mode;  /* ICE_MAP_MODE_[CONTIG|SCATTER] */
@@ -142,9 +163,11 @@ struct ice_q_vector {
struct napi_struct napi;
struct ice_ring_container rx;
struct ice_ring_container tx;
+   struct irq_affinity_notify affinity_notify;
u16 v_idx;  /* index in the vsi->q_vector array. */
u8 num_ring_tx; /* total number of tx rings in vector */
u8 num_ring_rx; /* total number of rx rings in vector */
+   char name[ICE_INT_NAME_STR_LEN];
 } cacheline_internodealigned_in_smp;
 
 enum ice_pf_flags {
@@ -192,10 +215,14 @@ struct ice_netdev_priv {
 /**
  * ice_irq_dynamic_ena - Enable default interrupt generation settings
  * @hw: pointer to hw struct
+ * @vsi: pointer to vsi stru

[PATCH v2 05/15] ice: Get MAC/PHY/link info and scheduler topology

2018-03-15 Thread Anirudh Venkataramanan
This patch adds code to continue the initialization flow as follows:

1) Get PHY/link information and store it
2) Get default scheduler tree topology and store it
3) Get the MAC address associated with the port and store it

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|   1 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 261 +++
 drivers/net/ethernet/intel/ice/ice_common.c | 264 +++
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_sched.c  | 328 
 drivers/net/ethernet/intel/ice/ice_sched.h  |   6 +
 drivers/net/ethernet/intel/ice/ice_status.h |   1 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  65 +
 8 files changed, 929 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index f6e3339591bb..9681e971bcab 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 66a3f41df673..13e3b7f3e24d 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -118,6 +118,35 @@ struct ice_aqc_list_caps_elem {
__le64 rsvd2;
 };
 
+/* Manage MAC address, read command - indirect (0x0107)
+ * This struct is also used for the response
+ */
+struct ice_aqc_manage_mac_read {
+   __le16 flags; /* Zeroed by device driver */
+#define ICE_AQC_MAN_MAC_LAN_ADDR_VALID BIT(4)
+#define ICE_AQC_MAN_MAC_SAN_ADDR_VALID BIT(5)
+#define ICE_AQC_MAN_MAC_PORT_ADDR_VALIDBIT(6)
+#define ICE_AQC_MAN_MAC_WOL_ADDR_VALID BIT(7)
+#define ICE_AQC_MAN_MAC_READ_S 4
+#define ICE_AQC_MAN_MAC_READ_M (0xF << ICE_AQC_MAN_MAC_READ_S)
+   u8 lport_num;
+   u8 lport_num_valid;
+#define ICE_AQC_MAN_MAC_PORT_NUM_IS_VALID  BIT(0)
+   u8 num_addr; /* Used in response */
+   u8 reserved[3];
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Response buffer format for manage MAC read command */
+struct ice_aqc_manage_mac_read_resp {
+   u8 lport_num;
+   u8 addr_type;
+#define ICE_AQC_MAN_MAC_ADDR_TYPE_LAN  0
+#define ICE_AQC_MAN_MAC_ADDR_TYPE_WOL  1
+   u8 mac_addr[ETH_ALEN];
+};
+
 /* Clear PXE Command and response (direct 0x0110) */
 struct ice_aqc_clear_pxe {
u8 rx_cnt;
@@ -175,6 +204,16 @@ struct ice_aqc_get_sw_cfg_resp {
struct ice_aqc_get_sw_cfg_resp_elem elements[1];
 };
 
+/* Get Default Topology (indirect 0x0400) */
+struct ice_aqc_get_topo {
+   u8 port_num;
+   u8 num_branches;
+   __le16 reserved1;
+   __le32 reserved2;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
 /* Add TSE (indirect 0x0401)
  * Delete TSE (indirect 0x040F)
  * Move TSE (indirect 0x0408)
@@ -235,6 +274,12 @@ struct ice_aqc_txsched_topo_grp_info_hdr {
__le16 reserved2;
 };
 
+struct ice_aqc_get_topo_elem {
+   struct ice_aqc_txsched_topo_grp_info_hdr hdr;
+   struct ice_aqc_txsched_elem_data
+   generic[ICE_AQC_TOPO_MAX_LEVEL_NUM];
+};
+
 struct ice_aqc_delete_elem {
struct ice_aqc_txsched_topo_grp_info_hdr hdr;
__le32 teid[1];
@@ -280,6 +325,210 @@ struct ice_aqc_query_txsched_res_resp {
struct ice_aqc_layer_props layer_props[ICE_AQC_TOPO_MAX_LEVEL_NUM];
 };
 
+/* Get PHY capabilities (indirect 0x0600) */
+struct ice_aqc_get_phy_caps {
+   u8 lport_num;
+   u8 reserved;
+   __le16 param0;
+   /* 18.0 - Report qualified modules */
+#define ICE_AQC_GET_PHY_RQMBIT(0)
+   /* 18.1 - 18.2 : Report mode
+* 00b - Report NVM capabilities
+* 01b - Report topology capabilities
+* 10b - Report SW configured
+*/
+#define ICE_AQC_REPORT_MODE_S  1
+#define ICE_AQC_REPORT_MODE_M  (3 << ICE_AQC_REPORT_MODE_S)
+#define ICE_AQC_REPORT_NVM_CAP 0
+#define ICE_AQC_REPORT_TOPO_CAPBIT(1)
+#define ICE_AQC_REPORT_SW_CFG  BIT(2)
+   __le32 reserved1;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* This is #define of PHY type (Extended):
+ * The first set of defines is for phy_type_low.
+ */
+#define ICE_PHY_TYPE_LOW_100BASE_TXBIT_ULL(0)
+#define ICE_PHY_TYPE_LOW_100M_SGMIIBIT_ULL(1)
+#define ICE_PHY_TYPE_LOW_1000BASE_TBIT_ULL(2)
+#define ICE_PHY_TYPE_LOW_1000BASE_SX   BIT_ULL(3)
+#define ICE_PHY_TYPE_LOW_1000BASE_LX   BIT_ULL(4)
+#define ICE_PHY_TYPE_LOW_1000BASE_KX   BIT_ULL(5)
+#define ICE_PHY_TYPE_LOW_1G_SGMII  BIT_ULL(6)
+#define ICE_PHY_TYPE_LOW_2500BASE_TB

[PATCH v2 08/15] ice: Add support for switch filter programming

2018-03-15 Thread Anirudh Venkataramanan
A VSI needs traffic directed towards it. This is done by programming
filter rules on the switch (embedded vSwitch) element in the hardware,
which connects the VSI to the ingress/egress port.

This patch introduces data structures and functions necessary to add
remove or update switch rules on the switch element. This is a pretty low
level function that is generic enough to add a whole range of filters.

This patch also introduces two top level functions ice_add_mac and
ice_remove mac which through a series of intermediate helper functions
eventually call ice_aq_sw_rules to add/delete simple MAC based filters.
It's worth noting that one invocation of ice_add_mac/ice_remove_mac
is capable of adding/deleting multiple MAC filters.

Also worth noting is the fact that the driver maintains a list of currently
active filters, so every filter addition/removal causes an update to this
list. This is done for a couple of reasons:

1) If two VSIs try to add the same filters, we need to detect it and do
   things a little differently (i.e. use VSI lists, described below) as
   the same filter can't be added more than once.

2) In the event of a hardware reset we can simply walk through this list
   and restore the filters.

VSI Lists:
In a multi-VSI situation, it's possible that multiple VSIs want to add the
same filter rule. For example, two VSIs that want to receive broadcast
traffic would both add a filter for destination MAC ff:ff:ff:ff:ff:ff.
This can become cumbersome to maintain and so this is handled using a
VSI list.

A VSI list is resource that can be allocated in the hardware using the
ice_aq_alloc_free_res admin queue command. Simply put, a VSI list can
be thought of as a subscription list containing a set of VSIs to which
the packet should be forwarded, should the filter match.

For example, if VSI-0 has already added a broadcast filter, and VSI-1
wants to do the same thing, the filter creation flow will detect this,
allocate a VSI list and update the switch rule so that broadcast traffic
will now be forwarded to the VSI list which contains VSI-0 and VSI-1.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  249 
 drivers/net/ethernet/intel/ice/ice_common.c |   74 +-
 drivers/net/ethernet/intel/ice/ice_main.c   |   92 ++
 drivers/net/ethernet/intel/ice/ice_status.h |3 +
 drivers/net/ethernet/intel/ice/ice_switch.c | 1378 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |  120 ++
 drivers/net/ethernet/intel/ice/ice_type.h   |   21 +
 7 files changed, 1935 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 570169c99786..c834ed38602b 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -22,6 +22,7 @@
  * descriptor format.  It is shared between Firmware and Software.
  */
 
+#define ICE_MAX_VSI768
 #define ICE_AQC_TOPO_MAX_LEVEL_NUM 0x9
 #define ICE_AQ_SET_MAC_FRAME_SIZE_MAX  9728
 
@@ -205,6 +206,46 @@ struct ice_aqc_get_sw_cfg_resp {
struct ice_aqc_get_sw_cfg_resp_elem elements[1];
 };
 
+/* These resource type defines are used for all switch resource
+ * commands where a resource type is required, such as:
+ * Get Resource Allocation command (indirect 0x0204)
+ * Allocate Resources command (indirect 0x0208)
+ * Free Resources command (indirect 0x0209)
+ * Get Allocated Resource Descriptors Command (indirect 0x020A)
+ */
+#define ICE_AQC_RES_TYPE_VSI_LIST_REP  0x03
+#define ICE_AQC_RES_TYPE_VSI_LIST_PRUNE0x04
+
+/* Allocate Resources command (indirect 0x0208)
+ * Free Resources command (indirect 0x0209)
+ */
+struct ice_aqc_alloc_free_res_cmd {
+   __le16 num_entries; /* Number of Resource entries */
+   u8 reserved[6];
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Resource descriptor */
+struct ice_aqc_res_elem {
+   union {
+   __le16 sw_resp;
+   __le16 flu_resp;
+   } e;
+};
+
+/* Buffer for Allocate/Free Resources commands */
+struct ice_aqc_alloc_free_res_elem {
+   __le16 res_type; /* Types defined above cmd 0x0204 */
+#define ICE_AQC_RES_TYPE_SHARED_S  7
+#define ICE_AQC_RES_TYPE_SHARED_M  (0x1 << ICE_AQC_RES_TYPE_SHARED_S)
+#define ICE_AQC_RES_TYPE_VSI_PRUNE_LIST_S  8
+#define ICE_AQC_RES_TYPE_VSI_PRUNE_LIST_M  \
+   (0xF << ICE_AQC_RES_TYPE_VSI_PRUNE_LIST_S)
+   __le16 num_elems;
+   struct ice_aqc_res_elem elem[1];
+};
+
 /* Add VSI (indirect 0x0210)
  * Update VSI (indirect 0x0211)
  * Get VSI (indirect 0x0212)
@@ -398,6 +439,202 @@ struct ice_aqc_vsi_props {
u8 reserved[24];
 };
 
+/* Add/Update/Remove/Get switch rules (indirect 0x02A0, 0x02A1, 0x02A2, 0x02A3)
+ */
+struct ice_aqc_sw_rules {
+   

[PATCH v2 02/15] ice: Add support for control queues

2018-03-15 Thread Anirudh Venkataramanan
A control queue is a hardware interface which is used by the driver
to interact with other subsystems (like firmware, PHY, etc.). It is
implemented as a producer-consumer ring. More specifically, an
"admin queue" is a type of control queue used to interact with the
firmware.

This patch introduces data structures and functions to initialize
and teardown control/admin queues. Once the admin queue is initialized,
the driver uses it to get the firmware version.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/Makefile |   4 +-
 drivers/net/ethernet/intel/ice/ice.h|   1 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 108 +++
 drivers/net/ethernet/intel/ice/ice_common.c | 144 
 drivers/net/ethernet/intel/ice/ice_common.h |  39 +
 drivers/net/ethernet/intel/ice/ice_controlq.c   | 979 
 drivers/net/ethernet/intel/ice/ice_controlq.h   |  97 +++
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  46 ++
 drivers/net/ethernet/intel/ice/ice_main.c   |  11 +-
 drivers/net/ethernet/intel/ice/ice_osdep.h  |  86 +++
 drivers/net/ethernet/intel/ice/ice_status.h |  35 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  22 +
 12 files changed, 1570 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_hw_autogen.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_osdep.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_status.h

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 2a177ea21b74..eebf619e84a8 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -24,4 +24,6 @@
 
 obj-$(CONFIG_ICE) += ice.o
 
-ice-y := ice_main.o
+ice-y := ice_main.o\
+ice_controlq.o \
+ice_common.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index d781027330cc..ea2fb63bb095 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
new file mode 100644
index ..885fa3c6fec4
--- /dev/null
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Intel(R) Ethernet Connection E800 Series Linux Driver
+ * Copyright (c) 2018, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ */
+
+#ifndef _ICE_ADMINQ_CMD_H_
+#define _ICE_ADMINQ_CMD_H_
+
+/* This header file defines the Admin Queue commands, error codes and
+ * descriptor format.  It is shared between Firmware and Software.
+ */
+
+struct ice_aqc_generic {
+   __le32 param0;
+   __le32 param1;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Get version (direct 0x0001) */
+struct ice_aqc_get_ver {
+   __le32 rom_ver;
+   __le32 fw_build;
+   u8 fw_branch;
+   u8 fw_major;
+   u8 fw_minor;
+   u8 fw_patch;
+   u8 api_branch;
+   u8 api_major;
+   u8 api_minor;
+   u8 api_patch;
+};
+
+/* Queue Shutdown (direct 0x0003) */
+struct ice_aqc_q_shutdown {
+#define ICE_AQC_DRIVER_UNLOADING   BIT(0)
+   __le32 driver_unloading;
+   u8 reserved[12];
+};
+
+/**
+ * struct ice_aq_desc - Admin Queue (AQ) descriptor
+ * @flags: ICE_AQ_FLAG_* flags
+ * @opcode: AQ command opcode
+ * @datalen: length in bytes of indirect/external data buffer
+ * @retval: return value from firmware
+ * @cookie_h: opaque data high-half
+ * @cookie_l: opaque data low-half
+ * @params: command-specific parameters
+ *
+ * Descriptor format for commands the driver posts on the Admin Transmit Queue
+ * (ATQ).  The firmware writes back onto the command descriptor and returns
+ * the result of the command.  Asynchronous events that are not an immediate
+ * result of the command are written to th

[PATCH v2 13/15] ice: Update Tx scheduler tree for VSI multi-Tx queue support

2018-03-15 Thread Anirudh Venkataramanan
This patch adds the ability for a VSI to use multiple Tx queues. More
specifically, the patch
1) Provides the ability to update the Tx scheduler tree in the
   firmware. The driver can configure the Tx scheduler tree by
   adding/removing multiple Tx queues per TC per VSI.

2) Allows a VSI to reconfigure its Tx queues during runtime.

3) Synchronizes the Tx scheduler update operations using locks.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|   7 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  28 +
 drivers/net/ethernet/intel/ice/ice_common.c |  54 ++
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_main.c   |  20 +-
 drivers/net/ethernet/intel/ice/ice_sched.c  | 886 
 drivers/net/ethernet/intel/ice/ice_sched.h  |   4 +
 drivers/net/ethernet/intel/ice/ice_type.h   |   7 +
 8 files changed, 1006 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 6014ef9c36e1..cb1e8a127af1 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -56,6 +56,7 @@ extern const char ice_drv_ver[];
 #define ICE_MIN_NUM_DESC   8
 #define ICE_MAX_NUM_DESC   8160
 #define ICE_REQ_DESC_MULTIPLE  32
+#define ICE_DFLT_TRAFFIC_CLASS BIT(0)
 #define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
 #define ICE_ETHTOOL_FWVER_LEN  32
 #define ICE_AQ_LEN 64
@@ -275,6 +276,12 @@ static inline void ice_irq_dynamic_ena(struct ice_hw *hw, 
struct ice_vsi *vsi,
wr32(hw, GLINT_DYN_CTL(vector), val);
 }
 
+static inline void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
+{
+   vsi->tc_cfg.ena_tc =  ICE_DFLT_TRAFFIC_CLASS;
+   vsi->tc_cfg.numtc = 1;
+}
+
 void ice_set_ethtool_ops(struct net_device *netdev);
 int ice_up(struct ice_vsi *vsi);
 int ice_down(struct ice_vsi *vsi);
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 2c8d8533f87d..62509635fc5e 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -645,6 +645,25 @@ struct ice_aqc_get_topo {
__le32 addr_low;
 };
 
+/* Update TSE (indirect 0x0403)
+ * Get TSE (indirect 0x0404)
+ */
+struct ice_aqc_get_cfg_elem {
+   __le16 num_elem_req;/* Used by commands */
+   __le16 num_elem_resp;   /* Used by responses */
+   __le32 reserved;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* This is the buffer for:
+ * Suspend Nodes (indirect 0x0409)
+ * Resume Nodes (indirect 0x040A)
+ */
+struct ice_aqc_suspend_resume_elem {
+   __le32 teid[1];
+};
+
 /* Add TSE (indirect 0x0401)
  * Delete TSE (indirect 0x040F)
  * Move TSE (indirect 0x0408)
@@ -705,6 +724,11 @@ struct ice_aqc_txsched_topo_grp_info_hdr {
__le16 reserved2;
 };
 
+struct ice_aqc_add_elem {
+   struct ice_aqc_txsched_topo_grp_info_hdr hdr;
+   struct ice_aqc_txsched_elem_data generic[1];
+};
+
 struct ice_aqc_get_topo_elem {
struct ice_aqc_txsched_topo_grp_info_hdr hdr;
struct ice_aqc_txsched_elem_data
@@ -1195,6 +1219,7 @@ struct ice_aq_desc {
struct ice_aqc_get_sw_cfg get_sw_conf;
struct ice_aqc_sw_rules sw_rules;
struct ice_aqc_get_topo get_topo;
+   struct ice_aqc_get_cfg_elem get_update_elem;
struct ice_aqc_query_txsched_res query_sched_res;
struct ice_aqc_add_move_delete_elem add_move_delete_elem;
struct ice_aqc_nvm nvm;
@@ -1272,6 +1297,9 @@ enum ice_adminq_opc {
 
/* transmit scheduler commands */
ice_aqc_opc_get_dflt_topo   = 0x0400,
+   ice_aqc_opc_add_sched_elems = 0x0401,
+   ice_aqc_opc_suspend_sched_elems = 0x0409,
+   ice_aqc_opc_resume_sched_elems  = 0x040A,
ice_aqc_opc_delete_sched_elems  = 0x040F,
ice_aqc_opc_query_sched_res = 0x0412,
 
diff --git a/drivers/net/ethernet/intel/ice/ice_common.c 
b/drivers/net/ethernet/intel/ice/ice_common.c
index 43cca9370444..958161a21115 100644
--- a/drivers/net/ethernet/intel/ice/ice_common.c
+++ b/drivers/net/ethernet/intel/ice/ice_common.c
@@ -2103,3 +2103,57 @@ ice_dis_vsi_txq(struct ice_port_info *pi, u8 num_queues, 
u16 *q_ids,
mutex_unlock(>sched_lock);
return status;
 }
+
+/**
+ * ice_cfg_vsi_qs - configure the new/exisiting VSI queues
+ * @pi: port information structure
+ * @vsi_id: VSI Id
+ * @tc_bitmap: TC bitmap
+ * @maxqs: max queues array per TC
+ * @owner: lan or rdma
+ *
+ * This function adds/updates the VSI queues per TC.
+ */
+static enum ice_status
+ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_id, u8 tc_bitmap,
+  u16 *maxqs, u8 owner)

[PATCH v2 04/15] ice: Get switch config, scheduler config and device capabilities

2018-03-15 Thread Anirudh Venkataramanan
This patch adds to the initialization flow by getting switch
configuration, scheduler configuration and device capabilities.

Switch configuration:
On boot, an L2 switch element is created in the firmware per physical
function. Each physical function is also mapped to a port, to which its
switch element is connected. In other words, this switch can be visualized
as an embedded vSwitch that can connect a physical functions's virtual
station interfaces (VSIs) to the egress/ingress port. Egress/ingress
filters will be eventually created and applied on this switch element.
As part of the initialization flow, the driver gets configuration data
from this switch element and stores it.

Scheduler configuration:
The Tx scheduler is a subsystem responsible for setting and enforcing QoS.
As part of the initialization flow, the driver queries and stores the
default scheduler configuration for the given physical function.

Device capabilities:
As part of initialization, the driver has to determine what the device is
capable of (ex. max queues, VSIs, etc). This information is obtained from
the firmware and stored by the driver.

CC: Shannon Nelson <shannon.nel...@oracle.com>
Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
v2: Addressed Shannon Nelson's review comment by changing retry count value
to 2.
---
 drivers/net/ethernet/intel/ice/Makefile |   4 +-
 drivers/net/ethernet/intel/ice/ice.h|   2 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 209 ++
 drivers/net/ethernet/intel/ice/ice_common.c | 231 
 drivers/net/ethernet/intel/ice/ice_common.h |   2 +
 drivers/net/ethernet/intel/ice/ice_sched.c  | 354 
 drivers/net/ethernet/intel/ice/ice_sched.h  |  42 +++
 drivers/net/ethernet/intel/ice/ice_switch.c | 158 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |  28 ++
 drivers/net/ethernet/intel/ice/ice_type.h   | 109 
 10 files changed, 1138 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.h

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 373d481dbb25..809d85c04398 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -27,4 +27,6 @@ obj-$(CONFIG_ICE) += ice.o
 ice-y := ice_main.o\
 ice_controlq.o \
 ice_common.o   \
-ice_nvm.o
+ice_nvm.o  \
+ice_switch.o   \
+ice_sched.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index ab2800c31906..f6e3339591bb 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -30,7 +30,9 @@
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
+#include "ice_switch.h"
 #include "ice_common.h"
+#include "ice_sched.h"
 
 #define ICE_BAR0   0
 #define ICE_AQ_LEN 64
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 05b22a1ffd70..66a3f41df673 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -22,6 +22,8 @@
  * descriptor format.  It is shared between Firmware and Software.
  */
 
+#define ICE_AQC_TOPO_MAX_LEVEL_NUM 0x9
+
 struct ice_aqc_generic {
__le32 param0;
__le32 param1;
@@ -82,6 +84,40 @@ struct ice_aqc_req_res {
u8 reserved[2];
 };
 
+/* Get function capabilities (indirect 0x000A)
+ * Get device capabilities (indirect 0x000B)
+ */
+struct ice_aqc_list_caps {
+   u8 cmd_flags;
+   u8 pf_index;
+   u8 reserved[2];
+   __le32 count;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Device/Function buffer entry, repeated per reported capability */
+struct ice_aqc_list_caps_elem {
+   __le16 cap;
+#define ICE_AQC_CAPS_VSI   0x0017
+#define ICE_AQC_CAPS_RSS   0x0040
+#define ICE_AQC_CAPS_RXQS  0x0041
+#define ICE_AQC_CAPS_TXQS  0x0042
+#define ICE_AQC_CAPS_MSIX  0x0043
+#define ICE_AQC_CAPS_MAX_MTU   0x0047
+
+   u8 major_ver;
+   u8 minor_ver;
+   /* Number of resources described by this capability */
+   __le32 number;
+   /* Only meaningful for some types of resources */
+   __le32 logical_id;
+   /* Only meaningful for some types of resources */
+   __le32 phys_id;
+   __le64 rsvd1;
+   __le64 rsvd2;
+};
+
 /* Clear PXE Command and response (direct 0x0110) */
 struct ice_aqc_clear_pxe {
  

[PATCH v2 12/15] ice: Add stats and ethtool support

2018-03-15 Thread Anirudh Venkataramanan
This patch implements a watchdog task to get packet statistics from
the device.

This patch also adds support for the following ethtool operations:

ethtool devname
ethtool -s devname [msglvl N] [msglevel type on|off]
ethtool -g|--show-ring devname
ethtool -G|--set-ring devname [rx N] [tx N]
ethtool -i|--driver devname
ethtool -d|--register-dump devname [raw on|off] [hex on|off] [file name]
ethtool -k|--show-features|--show-offload devname
ethtool -K|--features|--offload devname feature on|off
ethtool -P|--show-permaddr devname
ethtool -S|--statistics devname
ethtool -a|--show-pause devname
ethtool -A|--pause devname [autoneg on|off] [rx on|off] [tx on|off]
ethtool -r|--negotiate devname

CC: Andrew Lunn <and...@lunn.ch>
CC: Jakub Kicinski <kubak...@wp.pl>
CC: Stephen Hemminger <step...@networkplumber.org>
Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
v2: Addressed multiple review comments. Specifically,
1) Andrew Lunn's comment on PHY statistics.
2) Jakub Kicinski's comment on netdev stats.
3) Stephen Hemminger's comment on the net_stats_prev field.

Additionally, the code around stats collection was reworked a bit:
1) A new function ice_update_vsi_ring_stats was added to update ring
   stats. ice_get_stats64 which also reports ring stats was re-written
   to use this function.
2) Calls to ice_update_vsi_stats and ice_update_pf_stats in
   ice_get_ethtool_stats were removed, as this is done by the
   watchdog task anyway.
---
 drivers/net/ethernet/intel/ice/Makefile |   3 +-
 drivers/net/ethernet/intel/ice/ice.h|  28 +-
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  43 ++
 drivers/net/ethernet/intel/ice/ice_common.c | 195 +
 drivers/net/ethernet/intel/ice/ice_common.h |   5 +
 drivers/net/ethernet/intel/ice/ice_ethtool.c| 954 
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  80 ++
 drivers/net/ethernet/intel/ice/ice_main.c   | 469 +++-
 drivers/net/ethernet/intel/ice/ice_type.h   |  70 ++
 9 files changed, 1842 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_ethtool.c

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 0abeb20c006d..643d63016624 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -30,4 +30,5 @@ ice-y := ice_main.o   \
 ice_nvm.o  \
 ice_switch.o   \
 ice_sched.o\
-ice_txrx.o
+ice_txrx.o \
+ice_ethtool.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index f10ae53cc4ac..6014ef9c36e1 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -27,12 +27,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,10 +50,14 @@
 #include "ice_common.h"
 #include "ice_sched.h"
 
+extern const char ice_drv_ver[];
 #define ICE_BAR0   0
 #define ICE_DFLT_NUM_DESC  128
+#define ICE_MIN_NUM_DESC   8
+#define ICE_MAX_NUM_DESC   8160
 #define ICE_REQ_DESC_MULTIPLE  32
 #define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
+#define ICE_ETHTOOL_FWVER_LEN  32
 #define ICE_AQ_LEN 64
 #define ICE_MIN_MSIX   2
 #define ICE_NO_VSI 0x
@@ -70,6 +76,8 @@
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 #define ICE_INVAL_Q_INDEX  0x
 
+#define ICE_VSIQF_HKEY_ARRAY_SIZE  ((VSIQF_HKEY_MAX_INDEX + 1) *   4)
+
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
 #define ICE_MAX_MTU(ICE_AQ_SET_MAC_FRAME_SIZE_MAX - \
@@ -116,6 +124,7 @@ enum ice_state {
__ICE_DOWN,
__ICE_PFR_REQ,  /* set by driver and peers */
__ICE_ADMINQ_EVENT_PENDING,
+   __ICE_CFG_BUSY,
__ICE_SERVICE_SCHED,
__ICE_STATE_NBITS   /* must be last */
 };
@@ -132,8 +141,13 @@ struct ice_vsi {
 
irqreturn_t (*irq_handler)(int irq, void *data);
 
+   u64 tx_linearize;
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
+   u32 tx_restart;
+   u32 tx_busy;
+   u32 rx_buf_failed;
+   u32 rx_page_failed;
int num_q_vectors;
int base_vector;
enum ice_vsi_type type;
@@ -155,8 +169,14 @@ struct ice_vsi {
 
struct ice_aqc_vsi_props info;   /* VSI properties */
 
+   /* VSI stats */
+   struct rtnl_link_stats64 net_stats;
+   struct ice_eth_stats eth_stats;
+   struct ice_eth_stats eth_stats_prev;
+
bool irqs_ready;
bool current_isup;   /* Sync 'link up' logging */
+   bool stat_offsets_loaded;
 
/* queue information */
u8 tx_mapping_mode; 

[PATCH v2 03/15] ice: Start hardware initialization

2018-03-15 Thread Anirudh Venkataramanan
This patch implements multiple pieces of the initialization flow
as follows:

1) A reset is issued to ensure a clean device state, followed
   by initialization of admin queue interface.

2) Once the admin queue interface is up, clear the PF config
   and transition the device to non-PXE mode.

3) Get the NVM configuration stored in the device's non-volatile
   memory (NVM) using ice_init_nvm.

CC: Shannon Nelson <shannon.nel...@oracle.com>
Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
v2: Addressed Shannon Nelson's review comments by
1) removing an unnecessary register write in ice_aq_clear_pxe_mode.
2) adding a comment explaining the need to convert word sized values
   to byte sized values.
---
 drivers/net/ethernet/intel/ice/Makefile |   3 +-
 drivers/net/ethernet/intel/ice/ice.h|   2 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  79 +
 drivers/net/ethernet/intel/ice/ice_common.c | 405 
 drivers/net/ethernet/intel/ice/ice_common.h |  11 +
 drivers/net/ethernet/intel/ice/ice_controlq.h   |   3 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  30 ++
 drivers/net/ethernet/intel/ice/ice_main.c   |  31 ++
 drivers/net/ethernet/intel/ice/ice_nvm.c| 250 +++
 drivers/net/ethernet/intel/ice/ice_osdep.h  |   1 +
 drivers/net/ethernet/intel/ice/ice_status.h |   5 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  49 +++
 12 files changed, 868 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_nvm.c

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index eebf619e84a8..373d481dbb25 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -26,4 +26,5 @@ obj-$(CONFIG_ICE) += ice.o
 
 ice-y := ice_main.o\
 ice_controlq.o \
-ice_common.o
+ice_common.o   \
+ice_nvm.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index ea2fb63bb095..ab2800c31906 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -30,8 +30,10 @@
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
+#include "ice_common.h"
 
 #define ICE_BAR0   0
+#define ICE_AQ_LEN 64
 
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 885fa3c6fec4..05b22a1ffd70 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -50,6 +50,67 @@ struct ice_aqc_q_shutdown {
u8 reserved[12];
 };
 
+/* Request resource ownership (direct 0x0008)
+ * Release resource ownership (direct 0x0009)
+ */
+struct ice_aqc_req_res {
+   __le16 res_id;
+#define ICE_AQC_RES_ID_NVM 1
+#define ICE_AQC_RES_ID_SDP 2
+#define ICE_AQC_RES_ID_CHNG_LOCK   3
+#define ICE_AQC_RES_ID_GLBL_LOCK   4
+   __le16 access_type;
+#define ICE_AQC_RES_ACCESS_READ1
+#define ICE_AQC_RES_ACCESS_WRITE   2
+
+   /* Upon successful completion, FW writes this value and driver is
+* expected to release resource before timeout. This value is provided
+* in milliseconds.
+*/
+   __le32 timeout;
+#define ICE_AQ_RES_NVM_READ_DFLT_TIMEOUT_MS3000
+#define ICE_AQ_RES_NVM_WRITE_DFLT_TIMEOUT_MS   18
+#define ICE_AQ_RES_CHNG_LOCK_DFLT_TIMEOUT_MS   1000
+#define ICE_AQ_RES_GLBL_LOCK_DFLT_TIMEOUT_MS   3000
+   /* For SDP: pin id of the SDP */
+   __le32 res_number;
+   /* Status is only used for ICE_AQC_RES_ID_GLBL_LOCK */
+   __le16 status;
+#define ICE_AQ_RES_GLBL_SUCCESS0
+#define ICE_AQ_RES_GLBL_IN_PROG1
+#define ICE_AQ_RES_GLBL_DONE   2
+   u8 reserved[2];
+};
+
+/* Clear PXE Command and response (direct 0x0110) */
+struct ice_aqc_clear_pxe {
+   u8 rx_cnt;
+#define ICE_AQC_CLEAR_PXE_RX_CNT   0x2
+   u8 reserved[15];
+};
+
+/* NVM Read command (indirect 0x0701)
+ * NVM Erase commands (direct 0x0702)
+ * NVM Update commands (indirect 0x0703)
+ */
+struct ice_aqc_nvm {
+   u8  cmd_flags;
+#define ICE_AQC_NVM_LAST_CMD   BIT(0)
+#define ICE_AQC_NVM_PCIR_REQ   BIT(0)  /* Used by NVM Update reply */
+#define ICE_AQC_NVM_PRESERVATION_S 1
+#define ICE_AQC_NVM_PRESERVATION_M (3 << CSR_AQ_NVM_PRESERVATION_S)
+#define ICE_AQC_NVM_NO_PRESERVATION(0 << CSR_AQ_NVM_PRESERVATION_S)
+#define ICE_AQC_NVM_PRESERVE_ALL   BIT(1)
+#define ICE_AQC_NVM_PRESERVE_SELECTED  (3 << CSR_AQ_NVM_PRESERVATION_S)
+#define ICE_AQC_NVM_FLASH_ONLY BIT(7)
+   u8  module_typeid;
+   __le16  length;
+#define ICE_AQC_NVM_ERASE_LEN  0x
+

[PATCH v2 14/15] ice: Support link events, reset and rebuild

2018-03-15 Thread Anirudh Venkataramanan
Link events are posted to a PF's admin receive queue (ARQ). This patch
adds the ability to detect and process link events.

This patch also adds the ability to process resets.

The driver can process the following resets:
1) EMP Reset (EMPR)
2) Global Reset (GLOBR)
3) Core Reset (CORER)
4) Physical Function Reset (PFR)

EMPR is the largest level of reset that the driver can handle. An EMPR
resets the manageability block and also the data path, including PHY and
link for all the PFs. The affected PFs are notified of this event through
a miscellaneous interrupt.

GLOBR is a subset of EMPR. It does everything EMPR does except that it
doesn't reset the manageability block.

CORER is a subset of GLOBR. It does everything GLOBR does but doesn't
reset PHY and link.

PFR is a subset of CORER and affects only the given physical function.
In other words, PFR can be thought of as a CORER for a single PF. Since
only the issuing PF is affected, a PFR doesn't result in the miscellaneousi
interrupt being triggered.

All the resets have the following in common:
1) Tx/Rx is halted and all queues are stopped.
2) All the VSIs and filters programmed for the PF are lost and have to be
   reprogrammed.
3) Control queue interfaces are reset and have to be reprogrammed.

In the rebuild flow, control queues are reinitialized, VSIs are reallocated
and filters are restored.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|  19 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  19 +
 drivers/net/ethernet/intel/ice/ice_common.c |  60 +++
 drivers/net/ethernet/intel/ice/ice_common.h |   5 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |   2 +
 drivers/net/ethernet/intel/ice/ice_main.c   | 581 +++-
 drivers/net/ethernet/intel/ice/ice_type.h   |   1 +
 7 files changed, 681 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index cb1e8a127af1..6d7d03b80dbf 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -92,6 +92,11 @@ extern const char ice_drv_ver[];
 #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
 #define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
 
+/* Macro for each VSI in a PF */
+#define ice_for_each_vsi(pf, i) \
+   for ((i) = 0; (i) < (pf)->num_alloc_vsi; (i)++)
+
+/* Macros for each tx/rx ring in a VSI */
 #define ice_for_each_txq(vsi, i) \
for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
 
@@ -123,7 +128,16 @@ struct ice_sw {
 
 enum ice_state {
__ICE_DOWN,
+   __ICE_NEEDS_RESTART,
+   __ICE_RESET_RECOVERY_PENDING,   /* set by driver when reset starts */
__ICE_PFR_REQ,  /* set by driver and peers */
+   __ICE_CORER_REQ,/* set by driver and peers */
+   __ICE_GLOBR_REQ,/* set by driver and peers */
+   __ICE_CORER_RECV,   /* set by OICR handler */
+   __ICE_GLOBR_RECV,   /* set by OICR handler */
+   __ICE_EMPR_RECV,/* set by OICR handler */
+   __ICE_SUSPENDED,/* set on module remove path */
+   __ICE_RESET_FAILED, /* set by reset/rebuild */
__ICE_ADMINQ_EVENT_PENDING,
__ICE_CFG_BUSY,
__ICE_SERVICE_SCHED,
@@ -240,6 +254,11 @@ struct ice_pf {
u16 q_left_rx;  /* remaining num rx queues left unclaimed */
u16 next_vsi;   /* Next free slot in pf->vsi[] - 0-based! */
u16 num_alloc_vsi;
+   u16 corer_count;/* Core reset count */
+   u16 globr_count;/* Global reset count */
+   u16 empr_count; /* EMP reset count */
+   u16 pfr_count;  /* PF reset count */
+
struct ice_hw_port_stats stats;
struct ice_hw_port_stats stats_prev;
struct ice_hw hw;
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 62509635fc5e..8cade22c1cf6 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -1023,6 +1023,23 @@ struct ice_aqc_get_link_status_data {
__le64 reserved4;
 };
 
+/* Set event mask command (direct 0x0613) */
+struct ice_aqc_set_event_mask {
+   u8  lport_num;
+   u8  reserved[7];
+   __le16  event_mask;
+#define ICE_AQ_LINK_EVENT_UPDOWN   BIT(1)
+#define ICE_AQ_LINK_EVENT_MEDIA_NA BIT(2)
+#define ICE_AQ_LINK_EVENT_LINK_FAULT   BIT(3)
+#define ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM   BIT(4)
+#define ICE_AQ_LINK_EVENT_EXCESSIVE_ERRORS BIT(5)
+#define ICE_AQ_LINK_EVENT_SIGNAL_DETECTBIT(6)
+#define ICE_AQ_LINK_EVENT_AN_COMPLETED BIT(7)
+#define ICE_AQ_LINK_EVENT_M

[PATCH v2 11/15] ice: Add support for VLANs and offloads

2018-03-15 Thread Anirudh Venkataramanan
This patch adds support for VLANs. When a VLAN is created a switch filter
is added to direct the VLAN traffic to the corresponding VSI. When a VLAN
is deleted, the filter is deleted as well.

This patch also adds support for the following hardware offloads.
1) VLAN tag insertion/stripping
2) Receive Side Scaling (RSS)
3) Tx checksum and TCP segmentation
4) Rx checksum

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|  19 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  62 +++
 drivers/net/ethernet/intel/ice/ice_common.c | 188 
 drivers/net/ethernet/intel/ice/ice_common.h |  13 +
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  | 169 +++
 drivers/net/ethernet/intel/ice/ice_main.c   | 601 +++-
 drivers/net/ethernet/intel/ice/ice_switch.c | 169 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |   4 +
 drivers/net/ethernet/intel/ice/ice_txrx.c   | 405 +++-
 drivers/net/ethernet/intel/ice/ice_txrx.h   |  17 +
 10 files changed, 1631 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 7998e57994bf..f10ae53cc4ac 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -37,7 +37,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
 #include "ice_devids.h"
 #include "ice_type.h"
 #include "ice_txrx.h"
@@ -61,6 +64,8 @@
 #define ICE_MAX_SCATTER_RXQS   16
 #define ICE_Q_WAIT_RETRY_LIMIT 10
 #define ICE_Q_WAIT_MAX_RETRY   (5 * ICE_Q_WAIT_RETRY_LIMIT)
+#define ICE_MAX_LG_RSS_QS  256
+#define ICE_MAX_SMALL_RSS_QS   8
 #define ICE_RES_VALID_BIT  0x8000
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 #define ICE_INVAL_Q_INDEX  0x
@@ -76,6 +81,7 @@
 
 #define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
 #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
+#define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
 
 #define ice_for_each_txq(vsi, i) \
for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
@@ -127,6 +133,7 @@ struct ice_vsi {
irqreturn_t (*irq_handler)(int irq, void *data);
 
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
int num_q_vectors;
int base_vector;
enum ice_vsi_type type;
@@ -136,6 +143,13 @@ struct ice_vsi {
/* Interrupt thresholds */
u16 work_lmt;
 
+   /* RSS config */
+   u16 rss_table_size; /* HW RSS table size */
+   u16 rss_size;   /* Allocated RSS queues */
+   u8 *rss_hkey_user;  /* User configured hash keys */
+   u8 *rss_lut_user;   /* User configured lookup table entries */
+   u8 rss_lut_type;/* used to configure Get/Set RSS LUT AQ call */
+
u16 max_frame;
u16 rx_buf_len;
 
@@ -195,6 +209,7 @@ struct ice_pf {
struct mutex avail_q_mutex; /* protects access to avail_[rx|tx]qs */
struct mutex sw_mutex;  /* lock for protecting VSI alloc flow */
u32 msg_enable;
+   u32 hw_csum_rx_error;
u32 oicr_idx;   /* Other interrupt cause vector index */
u32 num_lan_msix;   /* Total MSIX vectors for base driver */
u32 num_avail_msix; /* remaining MSIX vectors left unclaimed */
@@ -238,4 +253,8 @@ static inline void ice_irq_dynamic_ena(struct ice_hw *hw, 
struct ice_vsi *vsi,
wr32(hw, GLINT_DYN_CTL(vector), val);
 }
 
+int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
+int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
+void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
+
 #endif /* _ICE_H_ */
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 358a482630db..49102817f0a9 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -982,6 +982,60 @@ struct ice_aqc_nvm {
__le32  addr_low;
 };
 
+/* Get/Set RSS key (indirect 0x0B04/0x0B02) */
+struct ice_aqc_get_set_rss_key {
+#define ICE_AQC_GSET_RSS_KEY_VSI_VALID BIT(15)
+#define ICE_AQC_GSET_RSS_KEY_VSI_ID_S  0
+#define ICE_AQC_GSET_RSS_KEY_VSI_ID_M  (0x3FF << ICE_AQC_GSET_RSS_KEY_VSI_ID_S)
+   __le16 vsi_id;
+   u8 reserved[6];
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+#define ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE  0x28
+#define ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE 0xC
+
+struct ice_aqc_get_set_rss_keys {
+   u8 standard_rss_key[ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE];
+   u8 extended_hash_key[ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE];
+};
+
+/* Get/Set RSS LUT (i

[PATCH v2 15/15] ice: Implement filter sync, NDO operations and bump version

2018-03-15 Thread Anirudh Venkataramanan
This patch implements multiple pieces of functionality:

1. Added ice_vsi_sync_filters, which is called through the service task
   to push filter updates to the hardware.

2. Add support to enable/disable promiscuous mode on an interface.
   Enabling/disabling promiscuous mode on an interface results in
   addition/removal of a promisc filter rule through ice_vsi_sync_filters.

3. Implement handlers for ndo_set_mac_address, ndo_change_mtu,
   ndo_poll_controller and ndo_set_rx_mode.

This patch also marks the end of the driver addition by bumping up the
driver version.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|  14 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  21 +
 drivers/net/ethernet/intel/ice/ice_common.c |  28 ++
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  |  12 +
 drivers/net/ethernet/intel/ice/ice_main.c   | 567 +++-
 drivers/net/ethernet/intel/ice/ice_switch.c |  77 
 drivers/net/ethernet/intel/ice/ice_switch.h |   2 +
 drivers/net/ethernet/intel/ice/ice_type.h   |   5 +
 9 files changed, 728 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 6d7d03b80dbf..9bb8a99b929e 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -139,11 +139,20 @@ enum ice_state {
__ICE_SUSPENDED,/* set on module remove path */
__ICE_RESET_FAILED, /* set by reset/rebuild */
__ICE_ADMINQ_EVENT_PENDING,
+   __ICE_FLTR_OVERFLOW_PROMISC,
__ICE_CFG_BUSY,
__ICE_SERVICE_SCHED,
__ICE_STATE_NBITS   /* must be last */
 };
 
+enum ice_vsi_flags {
+   ICE_VSI_FLAG_UMAC_FLTR_CHANGED,
+   ICE_VSI_FLAG_MMAC_FLTR_CHANGED,
+   ICE_VSI_FLAG_VLAN_FLTR_CHANGED,
+   ICE_VSI_FLAG_PROMISC_CHANGED,
+   ICE_VSI_FLAG_NBITS  /* must be last */
+};
+
 /* struct that defines a VSI, associated with a dev */
 struct ice_vsi {
struct net_device *netdev;
@@ -158,7 +167,9 @@ struct ice_vsi {
 
u64 tx_linearize;
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   DECLARE_BITMAP(flags, ICE_VSI_FLAG_NBITS);
unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
+   unsigned int current_netdev_flags;
u32 tx_restart;
u32 tx_busy;
u32 rx_buf_failed;
@@ -189,6 +200,9 @@ struct ice_vsi {
struct ice_eth_stats eth_stats;
struct ice_eth_stats eth_stats_prev;
 
+   struct list_head tmp_sync_list; /* MAC filters to be synced */
+   struct list_head tmp_unsync_list;   /* MAC filters to be unsynced */
+
bool irqs_ready;
bool current_isup;   /* Sync 'link up' logging */
bool stat_offsets_loaded;
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 8cade22c1cf6..fc19c287ebc5 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -149,6 +149,24 @@ struct ice_aqc_manage_mac_read_resp {
u8 mac_addr[ETH_ALEN];
 };
 
+/* Manage MAC address, write command - direct (0x0108) */
+struct ice_aqc_manage_mac_write {
+   u8 port_num;
+   u8 flags;
+#define ICE_AQC_MAN_MAC_WR_MC_MAG_EN   BIT(0)
+#define ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEPBIT(1)
+#define ICE_AQC_MAN_MAC_WR_S   6
+#define ICE_AQC_MAN_MAC_WR_M   (3 << ICE_AQC_MAN_MAC_WR_S)
+#define ICE_AQC_MAN_MAC_UPDATE_LAA 0
+#define ICE_AQC_MAN_MAC_UPDATE_LAA_WOL (BIT(0) << ICE_AQC_MAN_MAC_WR_S)
+   /* High 16 bits of MAC address in big endian order */
+   __be16 sah;
+   /* Low 32 bits of MAC address in big endian order */
+   __be32 sal;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
 /* Clear PXE Command and response (direct 0x0110) */
 struct ice_aqc_clear_pxe {
u8 rx_cnt;
@@ -1228,6 +1246,7 @@ struct ice_aq_desc {
struct ice_aqc_q_shutdown q_shutdown;
struct ice_aqc_req_res res_owner;
struct ice_aqc_manage_mac_read mac_read;
+   struct ice_aqc_manage_mac_write mac_write;
struct ice_aqc_clear_pxe clear_pxe;
struct ice_aqc_list_caps get_cap;
struct ice_aqc_get_phy_caps get_phy;
@@ -1272,6 +1291,7 @@ enum ice_aq_err {
ICE_AQ_RC_ENOMEM= 9,  /* Out of memory */
ICE_AQ_RC_EBUSY = 12, /* Device or resource busy */
ICE_AQ_RC_EEXIST= 13, /* object already exists */
+   ICE_AQ_RC_ENOSPC= 16, /* No space left or allocation failure */
 };
 
 /* Admin Queue command opcodes */
@@ -1290,6 +1310,7 @@ enum ice_adminq_opc {
 
/* manage MAC address */
ice_aqc_o

[PATCH v2 01/15] ice: Add basic driver framework for Intel(R) E800 Series

2018-03-15 Thread Anirudh Venkataramanan
This patch adds a basic driver framework for the Intel(R) E800 Ethernet
Series of network devices. There is no functionality right now other than
the ability to load.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 Documentation/networking/ice.txt|  39 +++
 MAINTAINERS |   1 +
 drivers/net/ethernet/intel/Kconfig  |  14 +++
 drivers/net/ethernet/intel/Makefile |   1 +
 drivers/net/ethernet/intel/ice/Makefile |  27 +
 drivers/net/ethernet/intel/ice/ice.h|  48 
 drivers/net/ethernet/intel/ice/ice_devids.h |  33 ++
 drivers/net/ethernet/intel/ice/ice_main.c   | 172 
 drivers/net/ethernet/intel/ice/ice_type.h   |  42 +++
 9 files changed, 377 insertions(+)
 create mode 100644 Documentation/networking/ice.txt
 create mode 100644 drivers/net/ethernet/intel/ice/Makefile
 create mode 100644 drivers/net/ethernet/intel/ice/ice.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_devids.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_main.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_type.h

diff --git a/Documentation/networking/ice.txt b/Documentation/networking/ice.txt
new file mode 100644
index ..6261c46378e1
--- /dev/null
+++ b/Documentation/networking/ice.txt
@@ -0,0 +1,39 @@
+Intel(R) Ethernet Connection E800 Series Linux Driver
+===
+
+Intel ice Linux driver.
+Copyright(c) 2018 Intel Corporation.
+
+Contents
+
+- Enabling the driver
+- Support
+
+The driver in this release supports Intel's E800 Series of products. For
+more information, visit Intel's support page at http://support.intel.com.
+
+Enabling the driver
+===
+
+The driver is enabled via the standard kernel configuration system,
+using the make command:
+
+ Make oldconfig/silentoldconfig/menuconfig/etc.
+
+The driver is located in the menu structure at:
+
+   -> Device Drivers
+ -> Network device support (NETDEVICES [=y])
+   -> Ethernet driver support
+ -> Intel devices
+   -> Intel(R) Ethernet Connection E800 Series Support
+
+Support
+===
+
+For general information, go to the Intel support website at:
+
+http://support.intel.com
+
+If an issue is identified with the released source code, please email
+the maintainer listed in the MAINTAINERS file.
diff --git a/MAINTAINERS b/MAINTAINERS
index 079af8b7ae8e..f1fe3bbec595 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7019,6 +7019,7 @@ F:Documentation/networking/ixgbe.txt
 F: Documentation/networking/ixgbevf.txt
 F: Documentation/networking/i40e.txt
 F: Documentation/networking/i40evf.txt
+F: Documentation/networking/ice.txt
 F: drivers/net/ethernet/intel/
 F: drivers/net/ethernet/intel/*/
 F: include/linux/avf/virtchnl.h
diff --git a/drivers/net/ethernet/intel/Kconfig 
b/drivers/net/ethernet/intel/Kconfig
index 1feb54b6d92e..14d287bed33c 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -251,6 +251,20 @@ config I40EVF
  will be called i40evf.  MSI-X interrupt support is required
  for this driver to work correctly.
 
+config ICE
+   tristate "Intel(R) Ethernet Connection E800 Series Support"
+   default n
+   depends on PCI_MSI
+   ---help---
+ This driver supports Intel(R) Ethernet Connection E800 Series of
+ devices.  For more information on how to identify your adapter, go
+ to the Adapter & Driver ID Guide that can be located at:
+
+ <http://support.intel.com>
+
+ To compile this driver as a module, choose M here. The module
+ will be called ice.
+
 config FM10K
tristate "Intel(R) FM1 Ethernet Switch Host Interface Support"
default n
diff --git a/drivers/net/ethernet/intel/Makefile 
b/drivers/net/ethernet/intel/Makefile
index 90af7757a885..807a4f8c7e4e 100644
--- a/drivers/net/ethernet/intel/Makefile
+++ b/drivers/net/ethernet/intel/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_I40E) += i40e/
 obj-$(CONFIG_IXGB) += ixgb/
 obj-$(CONFIG_I40EVF) += i40evf/
 obj-$(CONFIG_FM10K) += fm10k/
+obj-$(CONFIG_ICE) += ice/
diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
new file mode 100644
index ..2a177ea21b74
--- /dev/null
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+#
+# Intel(R) Ethernet Connection E800 Series Linux Driver
+# Copyright (c) 2018, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Sof

[PATCH v2 10/15] ice: Implement transmit and NAPI support

2018-03-15 Thread Anirudh Venkataramanan
This patch implements ice_start_xmit (the handler for ndo_start_xmit) and
related functions. ice_start_xmit ultimately calls ice_tx_map, where the
Tx descriptor is built and posted to the hardware by bumping the ring tail.

This patch also implements ice_napi_poll, which is invoked when there's an
interrupt on the VSI's queues. The interrupt can be due to either a
completed Tx or an Rx event. In case of a completed Tx/Rx event, resources
are reclaimed. Additionally, in case of an Rx event, the skb is fetched
and passed up to the network stack.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h   |1 +
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h |   46 ++
 drivers/net/ethernet/intel/ice/ice_main.c  |   55 ++
 drivers/net/ethernet/intel/ice/ice_txrx.c  | 1026 +++-
 drivers/net/ethernet/intel/ice/ice_txrx.h  |   45 ++
 5 files changed, 1171 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index e3ec19099e37..7998e57994bf 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -74,6 +74,7 @@
(((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
  ICE_AQ_VSI_UP_TABLE_UP##i##_M)
 
+#define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
 #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
 
 #define ice_for_each_txq(vsi, i) \
diff --git a/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h 
b/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
index 0cdf1ae480cf..c930f3e06ecc 100644
--- a/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
+++ b/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
@@ -145,6 +145,33 @@ enum ice_rx_flg64_bits {
ICE_RXFLG_RSVD  = 63
 };
 
+/* for ice_32byte_rx_flex_desc.ptype_flexi_flags0 member */
+#define ICE_RX_FLEX_DESC_PTYPE_M   (0x3FF) /* 10-bits */
+
+/* for ice_32byte_rx_flex_desc.pkt_length member */
+#define ICE_RX_FLX_DESC_PKT_LEN_M  (0x3FFF) /* 14-bits */
+
+enum ice_rx_flex_desc_status_error_0_bits {
+   /* Note: These are predefined bit offsets */
+   ICE_RX_FLEX_DESC_STATUS0_DD_S = 0,
+   ICE_RX_FLEX_DESC_STATUS0_EOF_S,
+   ICE_RX_FLEX_DESC_STATUS0_HBO_S,
+   ICE_RX_FLEX_DESC_STATUS0_L3L4P_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_L4E_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_EUDPE_S,
+   ICE_RX_FLEX_DESC_STATUS0_LPBK_S,
+   ICE_RX_FLEX_DESC_STATUS0_IPV6EXADD_S,
+   ICE_RX_FLEX_DESC_STATUS0_RXE_S,
+   ICE_RX_FLEX_DESC_STATUS0_CRCP_S,
+   ICE_RX_FLEX_DESC_STATUS0_RSS_VALID_S,
+   ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S,
+   ICE_RX_FLEX_DESC_STATUS0_XTRMD0_VALID_S,
+   ICE_RX_FLEX_DESC_STATUS0_XTRMD1_VALID_S,
+   ICE_RX_FLEX_DESC_STATUS0_LAST /* this entry must be last!!! */
+};
+
 #define ICE_RXQ_CTX_SIZE_DWORDS8
 #define ICE_RXQ_CTX_SZ (ICE_RXQ_CTX_SIZE_DWORDS * sizeof(u32))
 
@@ -215,6 +242,25 @@ struct ice_tx_desc {
__le64 cmd_type_offset_bsz;
 };
 
+enum ice_tx_desc_dtype_value {
+   ICE_TX_DESC_DTYPE_DATA  = 0x0,
+   ICE_TX_DESC_DTYPE_CTX   = 0x1,
+   /* DESC_DONE - HW has completed write-back of descriptor */
+   ICE_TX_DESC_DTYPE_DESC_DONE = 0xF,
+};
+
+#define ICE_TXD_QW1_CMD_S  4
+#define ICE_TXD_QW1_CMD_M  (0xFFFUL << ICE_TXD_QW1_CMD_S)
+
+enum ice_tx_desc_cmd_bits {
+   ICE_TX_DESC_CMD_EOP = 0x0001,
+   ICE_TX_DESC_CMD_RS  = 0x0002,
+};
+
+#define ICE_TXD_QW1_OFFSET_S   16
+#define ICE_TXD_QW1_TX_BUF_SZ_S34
+#define ICE_TXD_QW1_L2TAG1_S   48
+
 #define ICE_LAN_TXQ_MAX_QGRPS  127
 #define ICE_LAN_TXQ_MAX_QDIS   1023
 
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c 
b/drivers/net/ethernet/intel/ice/ice_main.c
index afb400a1f1d2..b802cac8376c 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -1272,6 +1272,23 @@ static int ice_vsi_alloc_arrays(struct ice_vsi *vsi, 
bool alloc_qvectors)
return -ENOMEM;
 }
 
+/**
+ * ice_msix_clean_rings - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ */
+static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
+{
+   struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
+
+   if (!q_vector->tx.ring && !q_vector->rx.ring)
+   return IRQ_HANDLED;
+
+   napi_schedule(_vector->napi);
+
+   return IRQ_HANDLED;
+}
+
 /**
  * ice_vsi_alloc - Allocates the next available struct vsi in the PF
  * @pf: board private structure
@@ -1312,6 +1329,8 @@ static struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf, 
enum ice_vsi_type type)
if (ice_vsi_

[PATCH v2 00/15] Add ice driver

2018-03-15 Thread Anirudh Venkataramanan
This patch series adds the ice driver, which will support the Intel(R)
E800 Series of network devices.

This is the first phase in the release of this driver where we implement
basic transmit and receive. The idea behind the multi-phase release is to
aid in code review as well as testing. Subsequent phases will implement
advanced features (like SR-IOV, tunnelling, flow director, QoS, etc.) that
build upon the previous phase(s). Each phase will be submitted as a patch
series.

I cc'd netdev for review since this is a new driver, even though this is
targeted to go through Jeff Kirsher's Intel Wired LAN git tree(s).

v2: Addressed community feedback
  patch #3 : Removed register write based on Shannon's comments
  patch #4 : Change retries value based on Shannon's comments
  patch #6 : Remove reference to "lump" as Shannon suggested
  patch #7 : Add define for magic number as Shannon suggested
  patch #12: Reworked based on multiple comments (Jakub, Stephen, et al.)

Anirudh Venkataramanan (15):
  ice: Add basic driver framework for Intel(R) E800 Series
  ice: Add support for control queues
  ice: Start hardware initialization
  ice: Get switch config, scheduler config and device capabilities
  ice: Get MAC/PHY/link info and scheduler topology
  ice: Initialize PF and setup miscellaneous interrupt
  ice: Add support for VSI allocation and deallocation
  ice: Add support for switch filter programming
  ice: Configure VSIs for Tx/Rx
  ice: Implement transmit and NAPI support
  ice: Add support for VLANs and offloads
  ice: Add stats and ethtool support
  ice: Update Tx scheduler tree for VSI multi-Tx queue support
  ice: Support link events, reset and rebuild
  ice: Implement filter sync, NDO operations and bump version

 Documentation/networking/ice.txt|   39 +
 MAINTAINERS |1 +
 drivers/net/ethernet/intel/Kconfig  |   14 +
 drivers/net/ethernet/intel/Makefile |1 +
 drivers/net/ethernet/intel/ice/Makefile |   34 +
 drivers/net/ethernet/intel/ice/ice.h|  326 ++
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 1366 ++
 drivers/net/ethernet/intel/ice/ice_common.c | 2247 +
 drivers/net/ethernet/intel/ice/ice_common.h |  100 +
 drivers/net/ethernet/intel/ice/ice_controlq.c   | 1080 +
 drivers/net/ethernet/intel/ice/ice_controlq.h   |  108 +
 drivers/net/ethernet/intel/ice/ice_devids.h |   33 +
 drivers/net/ethernet/intel/ice/ice_ethtool.c|  954 
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  280 ++
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  |  487 ++
 drivers/net/ethernet/intel/ice/ice_main.c   | 5509 +++
 drivers/net/ethernet/intel/ice/ice_nvm.c|  250 +
 drivers/net/ethernet/intel/ice/ice_osdep.h  |   87 +
 drivers/net/ethernet/intel/ice/ice_sched.c  | 1673 +++
 drivers/net/ethernet/intel/ice/ice_sched.h  |   57 +
 drivers/net/ethernet/intel/ice/ice_status.h |   46 +
 drivers/net/ethernet/intel/ice/ice_switch.c | 1897 
 drivers/net/ethernet/intel/ice/ice_switch.h |  175 +
 drivers/net/ethernet/intel/ice/ice_txrx.c   | 1796 
 drivers/net/ethernet/intel/ice/ice_txrx.h   |  206 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  408 ++
 26 files changed, 19174 insertions(+)
 create mode 100644 Documentation/networking/ice.txt
 create mode 100644 drivers/net/ethernet/intel/ice/Makefile
 create mode 100644 drivers/net/ethernet/intel/ice/ice.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_devids.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_ethtool.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_hw_autogen.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_main.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_nvm.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_osdep.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_status.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_type.h

-- 
2.14.3



[PATCH 08/15] ice: Add support for switch filter programming

2018-03-09 Thread Anirudh Venkataramanan
A VSI needs traffic directed towards it. This is done by programming
filter rules on the switch (embedded vSwitch) element in the hardware,
which connects the VSI to the ingress/egress port.

This patch introduces data structures and functions necessary to add
remove or update switch rules on the switch element. This is a pretty low
level function that is generic enough to add a whole range of filters.

This patch also introduces two top level functions ice_add_mac and
ice_remove mac which through a series of intermediate helper functions
eventually call ice_aq_sw_rules to add/delete simple MAC based filters.
It's worth noting that one invocation of ice_add_mac/ice_remove_mac
is capable of adding/deleting multiple MAC filters.

Also worth noting is the fact that the driver maintains a list of currently
active filters, so every filter addition/removal causes an update to this
list. This is done for a couple of reasons:

1) If two VSIs try to add the same filters, we need to detect it and do
   things a little differently (i.e. use VSI lists, described below) as
   the same filter can't be added more than once.

2) In the event of a hardware reset we can simply walk through this list
   and restore the filters.

VSI Lists:
In a multi-VSI situation, it's possible that multiple VSIs want to add the
same filter rule. For example, two VSIs that want to receive broadcast
traffic would both add a filter for destination MAC ff:ff:ff:ff:ff:ff.
This can become cumbersome to maintain and so this is handled using a
VSI list.

A VSI list is resource that can be allocated in the hardware using the
ice_aq_alloc_free_res admin queue command. Simply put, a VSI list can
be thought of as a subscription list containing a set of VSIs to which
the packet should be forwarded, should the filter match.

For example, if VSI-0 has already added a broadcast filter, and VSI-1
wants to do the same thing, the filter creation flow will detect this,
allocate a VSI list and update the switch rule so that broadcast traffic
will now be forwarded to the VSI list which contains VSI-0 and VSI-1.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  249 
 drivers/net/ethernet/intel/ice/ice_common.c |   74 +-
 drivers/net/ethernet/intel/ice/ice_main.c   |   92 ++
 drivers/net/ethernet/intel/ice/ice_status.h |3 +
 drivers/net/ethernet/intel/ice/ice_switch.c | 1378 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |  120 ++
 drivers/net/ethernet/intel/ice/ice_type.h   |   21 +
 7 files changed, 1935 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 570169c99786..c834ed38602b 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -22,6 +22,7 @@
  * descriptor format.  It is shared between Firmware and Software.
  */
 
+#define ICE_MAX_VSI768
 #define ICE_AQC_TOPO_MAX_LEVEL_NUM 0x9
 #define ICE_AQ_SET_MAC_FRAME_SIZE_MAX  9728
 
@@ -205,6 +206,46 @@ struct ice_aqc_get_sw_cfg_resp {
struct ice_aqc_get_sw_cfg_resp_elem elements[1];
 };
 
+/* These resource type defines are used for all switch resource
+ * commands where a resource type is required, such as:
+ * Get Resource Allocation command (indirect 0x0204)
+ * Allocate Resources command (indirect 0x0208)
+ * Free Resources command (indirect 0x0209)
+ * Get Allocated Resource Descriptors Command (indirect 0x020A)
+ */
+#define ICE_AQC_RES_TYPE_VSI_LIST_REP  0x03
+#define ICE_AQC_RES_TYPE_VSI_LIST_PRUNE0x04
+
+/* Allocate Resources command (indirect 0x0208)
+ * Free Resources command (indirect 0x0209)
+ */
+struct ice_aqc_alloc_free_res_cmd {
+   __le16 num_entries; /* Number of Resource entries */
+   u8 reserved[6];
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Resource descriptor */
+struct ice_aqc_res_elem {
+   union {
+   __le16 sw_resp;
+   __le16 flu_resp;
+   } e;
+};
+
+/* Buffer for Allocate/Free Resources commands */
+struct ice_aqc_alloc_free_res_elem {
+   __le16 res_type; /* Types defined above cmd 0x0204 */
+#define ICE_AQC_RES_TYPE_SHARED_S  7
+#define ICE_AQC_RES_TYPE_SHARED_M  (0x1 << ICE_AQC_RES_TYPE_SHARED_S)
+#define ICE_AQC_RES_TYPE_VSI_PRUNE_LIST_S  8
+#define ICE_AQC_RES_TYPE_VSI_PRUNE_LIST_M  \
+   (0xF << ICE_AQC_RES_TYPE_VSI_PRUNE_LIST_S)
+   __le16 num_elems;
+   struct ice_aqc_res_elem elem[1];
+};
+
 /* Add VSI (indirect 0x0210)
  * Update VSI (indirect 0x0211)
  * Get VSI (indirect 0x0212)
@@ -398,6 +439,202 @@ struct ice_aqc_vsi_props {
u8 reserved[24];
 };
 
+/* Add/Update/Remove/Get switch rules (indirect 0x02A0, 0x02A1, 0x02A2, 0x02A3)
+ */
+struct ice_aqc_sw_rules {
+   

[PATCH 07/15] ice: Add support for VSI allocation and deallocation

2018-03-09 Thread Anirudh Venkataramanan
This patch introduces data structures and functions to alloc/free
VSIs. The driver represents a VSI using the ice_vsi structure.

Some noteworthy points about VSI allocation:

1) A VSI is allocated in the firmware using the "add VSI" admin queue
   command (implemented as ice_aq_add_vsi). The firmware returns an
   identifier for the allocated VSI. The VSI context is used to program
   certain aspects (loopback, queue map, etc.) of the VSI's configuration.

2) A VSI is deleted using the "free VSI" admin queue command (implemented
   as ice_aq_free_vsi).

3) The driver represents a VSI using struct ice_vsi. This is allocated
   and initialized as part of the ice_vsi_alloc flow, and deallocated
   as part of the ice_vsi_delete flow.

4) Once the VSI is created, a netdev is allocated and associated with it.
   The VSI's ring and vector related data structures are also allocated
   and initialized.

5) A VSI's queues can either be contiguous or scattered. To do this, the
   driver maintains a bitmap (vsi->avail_txqs) which is kept in sync with
   the firmware's VSI queue allocation imap. If the VSI can't get a
   contiguous queue allocation, it will fallback to scatter. This is
   implemented in ice_vsi_get_qs which is called as part of the VSI setup
   flow. In the release flow, the VSI's queues are released and the bitmap
   is updated to reflect this by ice_vsi_put_qs.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|   71 ++
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  199 
 drivers/net/ethernet/intel/ice/ice_main.c   | 1108 +++
 drivers/net/ethernet/intel/ice/ice_switch.c |  115 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |   21 +
 drivers/net/ethernet/intel/ice/ice_txrx.h   |   26 +
 drivers/net/ethernet/intel/ice/ice_type.h   |4 +
 7 files changed, 1544 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index c8079c852a48..b169f3751cc9 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -25,6 +25,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -32,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
@@ -41,17 +44,42 @@
 #include "ice_sched.h"
 
 #define ICE_BAR0   0
+#define ICE_DFLT_NUM_DESC  128
+#define ICE_REQ_DESC_MULTIPLE  32
 #define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
 #define ICE_AQ_LEN 64
 #define ICE_MIN_MSIX   2
 #define ICE_MAX_VSI_ALLOC  130
 #define ICE_MAX_TXQS   2048
 #define ICE_MAX_RXQS   2048
+#define ICE_VSI_MAP_CONTIG 0
+#define ICE_VSI_MAP_SCATTER1
+#define ICE_MAX_SCATTER_TXQS   16
+#define ICE_MAX_SCATTER_RXQS   16
 #define ICE_RES_VALID_BIT  0x8000
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
+#define ICE_INVAL_Q_INDEX  0x
 
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+#define ICE_MAX_MTU(ICE_AQ_SET_MAC_FRAME_SIZE_MAX - \
+ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN)
+
+#define ICE_UP_TABLE_TRANSLATE(val, i) \
+   (((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
+ ICE_AQ_VSI_UP_TABLE_UP##i##_M)
+
+struct ice_tc_info {
+   u16 qoffset;
+   u16 qcount;
+};
+
+struct ice_tc_cfg {
+   u8 numtc; /* Total number of enabled TCs */
+   u8 ena_tc; /* TX map */
+   struct ice_tc_info tc_info[ICE_MAX_TRAFFIC_CLASS];
+};
+
 struct ice_res_tracker {
u16 num_entries;
u16 search_hint;
@@ -75,8 +103,47 @@ enum ice_state {
 /* struct that defines a VSI, associated with a dev */
 struct ice_vsi {
struct net_device *netdev;
+   struct ice_sw *vsw;  /* switch this VSI is on */
+   struct ice_pf *back; /* back pointer to PF */
struct ice_port_info *port_info; /* back pointer to port_info */
+   struct ice_ring **rx_rings;  /* rx ring array */
+   struct ice_ring **tx_rings;  /* tx ring array */
+   struct ice_q_vector **q_vectors; /* q_vector array */
+   DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   int num_q_vectors;
+   int base_vector;
+   enum ice_vsi_type type;
u16 vsi_num; /* HW (absolute) index of this VSI */
+   u16 idx; /* software index in pf->vsi[] */
+
+   /* Interrupt thresholds */
+   u16 work_lmt;
+
+   struct ice_aqc_vsi_props info;   /* VSI properties */
+
+   /* queue information */
+   u8 tx_mapping_mode;  /* ICE_MAP_MODE_[CONTIG|SCATTER] */
+   u8 rx_mapping_mode;  /* ICE_MAP_MODE_[CONTIG|SCATTER] */
+   u16 txq_map[ICE_MAX_TXQS];   /* index in pf->avail_txqs */
+  

[PATCH 06/15] ice: Initialize PF and setup miscellaneous interrupt

2018-03-09 Thread Anirudh Venkataramanan
This patch continues the initialization flow as follows:

1) Allocate and initialize necessary fields (like vsi, num_alloc_vsi,
   irq_tracker, etc) in the ice_pf instance.

2) Setup the miscellaneous interrupt handler. This also known as the
   "other interrupt causes" (OIC) handler and is used to handle non
   hotpath interrupts (like control queue events, link events,
   exceptions, etc.

3) Implement a background task to process admin queue receive (ARQ)
   events received by the driver.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|  84 +++
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |   2 +
 drivers/net/ethernet/intel/ice/ice_common.c |   6 +
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_controlq.c   | 101 
 drivers/net/ethernet/intel/ice/ice_controlq.h   |   8 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  63 +++
 drivers/net/ethernet/intel/ice/ice_main.c   | 719 +++-
 drivers/net/ethernet/intel/ice/ice_txrx.h   |  43 ++
 drivers/net/ethernet/intel/ice/ice_type.h   |  11 +
 10 files changed, 1039 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.h

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 9681e971bcab..c8079c852a48 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -26,29 +26,113 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
+#include 
 #include "ice_devids.h"
 #include "ice_type.h"
+#include "ice_txrx.h"
 #include "ice_switch.h"
 #include "ice_common.h"
 #include "ice_sched.h"
 
 #define ICE_BAR0   0
+#define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
 #define ICE_AQ_LEN 64
+#define ICE_MIN_MSIX   2
+#define ICE_MAX_VSI_ALLOC  130
+#define ICE_MAX_TXQS   2048
+#define ICE_MAX_RXQS   2048
+#define ICE_RES_VALID_BIT  0x8000
+#define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
+struct ice_res_tracker {
+   u16 num_entries;
+   u16 search_hint;
+   u16 list[1];
+};
+
+struct ice_sw {
+   struct ice_pf *pf;
+   u16 sw_id;  /* switch ID for this switch */
+   u16 bridge_mode;/* VEB/VEPA/Port Virtualizer */
+};
+
 enum ice_state {
__ICE_DOWN,
+   __ICE_PFR_REQ,  /* set by driver and peers */
+   __ICE_ADMINQ_EVENT_PENDING,
+   __ICE_SERVICE_SCHED,
__ICE_STATE_NBITS   /* must be last */
 };
 
+/* struct that defines a VSI, associated with a dev */
+struct ice_vsi {
+   struct net_device *netdev;
+   struct ice_port_info *port_info; /* back pointer to port_info */
+   u16 vsi_num; /* HW (absolute) index of this VSI */
+} cacheline_internodealigned_in_smp;
+
+enum ice_pf_flags {
+   ICE_FLAG_MSIX_ENA,
+   ICE_FLAG_FLTR_SYNC,
+   ICE_FLAG_RSS_ENA,
+   ICE_PF_FLAGS_NBITS  /* must be last */
+};
+
 struct ice_pf {
struct pci_dev *pdev;
+   struct msix_entry *msix_entries;
+   struct ice_res_tracker *irq_tracker;
+   struct ice_vsi **vsi;   /* VSIs created by the driver */
+   struct ice_sw *first_sw;/* first switch created by firmware */
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   DECLARE_BITMAP(avail_txqs, ICE_MAX_TXQS);
+   DECLARE_BITMAP(avail_rxqs, ICE_MAX_RXQS);
+   DECLARE_BITMAP(flags, ICE_PF_FLAGS_NBITS);
+   unsigned long serv_tmr_period;
+   unsigned long serv_tmr_prev;
+   struct timer_list serv_tmr;
+   struct work_struct serv_task;
+   struct mutex avail_q_mutex; /* protects access to avail_[rx|tx]qs */
+   struct mutex sw_mutex;  /* lock for protecting VSI alloc flow */
u32 msg_enable;
+   u32 oicr_idx;   /* Other interrupt cause vector index */
+   u32 num_lan_msix;   /* Total MSIX vectors for base driver */
+   u32 num_avail_msix; /* remaining MSIX vectors left unclaimed */
+   u16 num_lan_tx; /* num lan tx queues setup */
+   u16 num_lan_rx; /* num lan rx queues setup */
+   u16 q_left_tx;  /* remaining num tx queues left unclaimed */
+   u16 q_left_rx;  /* remaining num rx queues left unclaimed */
+   u16 next_vsi;   /* Next free slot in pf->vsi[] - 0-based! */
+   u16 num_alloc_vsi;
+
struct ice_hw hw;
+   char int_name[ICE_INT_NAME_STR_LEN];
 };
+
+/**
+ * ice_irq_dynamic_ena - Enable default interrupt generation settings
+ * @hw: pointer to hw struct
+ */
+static inline void ice_irq_dynamic_ena(struct ice_hw *hw)
+{
+   u32 vector = ((s

[PATCH 02/15] ice: Add support for control queues

2018-03-09 Thread Anirudh Venkataramanan
A control queue is a hardware interface which is used by the driver
to interact with other subsystems (like firmware, PHY, etc.). It is
implemented as a producer-consumer ring. More specifically, an
"admin queue" is a type of control queue used to interact with the
firmware.

This patch introduces data structures and functions to initialize
and teardown control/admin queues. Once the admin queue is initialized,
the driver uses it to get the firmware version.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/Makefile |   4 +-
 drivers/net/ethernet/intel/ice/ice.h|   1 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 108 +++
 drivers/net/ethernet/intel/ice/ice_common.c | 144 
 drivers/net/ethernet/intel/ice/ice_common.h |  39 +
 drivers/net/ethernet/intel/ice/ice_controlq.c   | 979 
 drivers/net/ethernet/intel/ice/ice_controlq.h   |  97 +++
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  46 ++
 drivers/net/ethernet/intel/ice/ice_main.c   |  11 +-
 drivers/net/ethernet/intel/ice/ice_osdep.h  |  86 +++
 drivers/net/ethernet/intel/ice/ice_status.h |  35 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  22 +
 12 files changed, 1570 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_hw_autogen.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_osdep.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_status.h

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 2a177ea21b74..eebf619e84a8 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -24,4 +24,6 @@
 
 obj-$(CONFIG_ICE) += ice.o
 
-ice-y := ice_main.o
+ice-y := ice_main.o\
+ice_controlq.o \
+ice_common.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index d781027330cc..ea2fb63bb095 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
new file mode 100644
index ..885fa3c6fec4
--- /dev/null
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Intel(R) Ethernet Connection E800 Series Linux Driver
+ * Copyright (c) 2018, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called "COPYING".
+ */
+
+#ifndef _ICE_ADMINQ_CMD_H_
+#define _ICE_ADMINQ_CMD_H_
+
+/* This header file defines the Admin Queue commands, error codes and
+ * descriptor format.  It is shared between Firmware and Software.
+ */
+
+struct ice_aqc_generic {
+   __le32 param0;
+   __le32 param1;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Get version (direct 0x0001) */
+struct ice_aqc_get_ver {
+   __le32 rom_ver;
+   __le32 fw_build;
+   u8 fw_branch;
+   u8 fw_major;
+   u8 fw_minor;
+   u8 fw_patch;
+   u8 api_branch;
+   u8 api_major;
+   u8 api_minor;
+   u8 api_patch;
+};
+
+/* Queue Shutdown (direct 0x0003) */
+struct ice_aqc_q_shutdown {
+#define ICE_AQC_DRIVER_UNLOADING   BIT(0)
+   __le32 driver_unloading;
+   u8 reserved[12];
+};
+
+/**
+ * struct ice_aq_desc - Admin Queue (AQ) descriptor
+ * @flags: ICE_AQ_FLAG_* flags
+ * @opcode: AQ command opcode
+ * @datalen: length in bytes of indirect/external data buffer
+ * @retval: return value from firmware
+ * @cookie_h: opaque data high-half
+ * @cookie_l: opaque data low-half
+ * @params: command-specific parameters
+ *
+ * Descriptor format for commands the driver posts on the Admin Transmit Queue
+ * (ATQ).  The firmware writes back onto the command descriptor and returns
+ * the result of the command.  Asynchronous events that are not an immediate
+ * result of the command are written to th

[PATCH 03/15] ice: Start hardware initialization

2018-03-09 Thread Anirudh Venkataramanan
This patch implements multiple pieces of the initialization flow
as follows:

1) A reset is issued to ensure a clean device state, followed
   by initialization of admin queue interface.

2) Once the admin queue interface is up, clear the PF config
   and transition the device to non-PXE mode.

3) Get the NVM configuration stored in the device's non-volatile
   memory (NVM) using ice_init_nvm.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/Makefile |   3 +-
 drivers/net/ethernet/intel/ice/ice.h|   2 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  79 +
 drivers/net/ethernet/intel/ice/ice_common.c | 410 
 drivers/net/ethernet/intel/ice/ice_common.h |  11 +
 drivers/net/ethernet/intel/ice/ice_controlq.h   |   3 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  30 ++
 drivers/net/ethernet/intel/ice/ice_main.c   |  31 ++
 drivers/net/ethernet/intel/ice/ice_nvm.c| 245 ++
 drivers/net/ethernet/intel/ice/ice_osdep.h  |   1 +
 drivers/net/ethernet/intel/ice/ice_status.h |   5 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  49 +++
 12 files changed, 868 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_nvm.c

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index eebf619e84a8..373d481dbb25 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -26,4 +26,5 @@ obj-$(CONFIG_ICE) += ice.o
 
 ice-y := ice_main.o\
 ice_controlq.o \
-ice_common.o
+ice_common.o   \
+ice_nvm.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index ea2fb63bb095..ab2800c31906 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -30,8 +30,10 @@
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
+#include "ice_common.h"
 
 #define ICE_BAR0   0
+#define ICE_AQ_LEN 64
 
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 885fa3c6fec4..05b22a1ffd70 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -50,6 +50,67 @@ struct ice_aqc_q_shutdown {
u8 reserved[12];
 };
 
+/* Request resource ownership (direct 0x0008)
+ * Release resource ownership (direct 0x0009)
+ */
+struct ice_aqc_req_res {
+   __le16 res_id;
+#define ICE_AQC_RES_ID_NVM 1
+#define ICE_AQC_RES_ID_SDP 2
+#define ICE_AQC_RES_ID_CHNG_LOCK   3
+#define ICE_AQC_RES_ID_GLBL_LOCK   4
+   __le16 access_type;
+#define ICE_AQC_RES_ACCESS_READ1
+#define ICE_AQC_RES_ACCESS_WRITE   2
+
+   /* Upon successful completion, FW writes this value and driver is
+* expected to release resource before timeout. This value is provided
+* in milliseconds.
+*/
+   __le32 timeout;
+#define ICE_AQ_RES_NVM_READ_DFLT_TIMEOUT_MS3000
+#define ICE_AQ_RES_NVM_WRITE_DFLT_TIMEOUT_MS   18
+#define ICE_AQ_RES_CHNG_LOCK_DFLT_TIMEOUT_MS   1000
+#define ICE_AQ_RES_GLBL_LOCK_DFLT_TIMEOUT_MS   3000
+   /* For SDP: pin id of the SDP */
+   __le32 res_number;
+   /* Status is only used for ICE_AQC_RES_ID_GLBL_LOCK */
+   __le16 status;
+#define ICE_AQ_RES_GLBL_SUCCESS0
+#define ICE_AQ_RES_GLBL_IN_PROG1
+#define ICE_AQ_RES_GLBL_DONE   2
+   u8 reserved[2];
+};
+
+/* Clear PXE Command and response (direct 0x0110) */
+struct ice_aqc_clear_pxe {
+   u8 rx_cnt;
+#define ICE_AQC_CLEAR_PXE_RX_CNT   0x2
+   u8 reserved[15];
+};
+
+/* NVM Read command (indirect 0x0701)
+ * NVM Erase commands (direct 0x0702)
+ * NVM Update commands (indirect 0x0703)
+ */
+struct ice_aqc_nvm {
+   u8  cmd_flags;
+#define ICE_AQC_NVM_LAST_CMD   BIT(0)
+#define ICE_AQC_NVM_PCIR_REQ   BIT(0)  /* Used by NVM Update reply */
+#define ICE_AQC_NVM_PRESERVATION_S 1
+#define ICE_AQC_NVM_PRESERVATION_M (3 << CSR_AQ_NVM_PRESERVATION_S)
+#define ICE_AQC_NVM_NO_PRESERVATION(0 << CSR_AQ_NVM_PRESERVATION_S)
+#define ICE_AQC_NVM_PRESERVE_ALL   BIT(1)
+#define ICE_AQC_NVM_PRESERVE_SELECTED  (3 << CSR_AQ_NVM_PRESERVATION_S)
+#define ICE_AQC_NVM_FLASH_ONLY BIT(7)
+   u8  module_typeid;
+   __le16  length;
+#define ICE_AQC_NVM_ERASE_LEN  0x
+   __le32  offset;
+   __le32  addr_high;
+   __le32  addr_low;
+};
+
 /**
  * struct ice_aq_desc - Admin Queue (AQ) descriptor
  * @flags: ICE_AQ_FLAG_* flags
@@ -79,6 +140,9 @@ struct ice_aq_desc {
struct ice_aqc_generic generic;

[PATCH 14/15] ice: Support link events, reset and rebuild

2018-03-09 Thread Anirudh Venkataramanan
Link events are posted to a PF's admin receive queue (ARQ). This patch
adds the ability to detect and process link events.

This patch also adds the ability to process resets.

The driver can process the following resets:
1) EMP Reset (EMPR)
2) Global Reset (GLOBR)
3) Core Reset (CORER)
4) Physical Function Reset (PFR)

EMPR is the largest level of reset that the driver can handle. An EMPR
resets the manageability block and also the data path, including PHY and
link for all the PFs. The affected PFs are notified of this event through
a miscellaneous interrupt.

GLOBR is a subset of EMPR. It does everything EMPR does except that it
doesn't reset the manageability block.

CORER is a subset of GLOBR. It does everything GLOBR does but doesn't
reset PHY and link.

PFR is a subset of CORER and affects only the given physical function.
In other words, PFR can be thought of as a CORER for a single PF. Since
only the issuing PF is affected, a PFR doesn't result in the miscellaneousi
interrupt being triggered.

All the resets have the following in common:
1) Tx/Rx is halted and all queues are stopped.
2) All the VSIs and filters programmed for the PF are lost and have to be
   reprogrammed.
3) Control queue interfaces are reset and have to be reprogrammed.

In the rebuild flow, control queues are reinitialized, VSIs are reallocated
and filters are restored.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|  19 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  19 +
 drivers/net/ethernet/intel/ice/ice_common.c |  60 +++
 drivers/net/ethernet/intel/ice/ice_common.h |   5 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |   2 +
 drivers/net/ethernet/intel/ice/ice_main.c   | 581 +++-
 drivers/net/ethernet/intel/ice/ice_type.h   |   1 +
 7 files changed, 681 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index c32dc36a9801..e2d4b4de1f1d 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -91,6 +91,11 @@ extern const char ice_drv_ver[];
 #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
 #define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
 
+/* Macro for each VSI in a PF */
+#define ice_for_each_vsi(pf, i) \
+   for ((i) = 0; (i) < (pf)->num_alloc_vsi; (i)++)
+
+/* Macros for each tx/rx ring in a VSI */
 #define ice_for_each_txq(vsi, i) \
for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
 
@@ -122,7 +127,16 @@ struct ice_sw {
 
 enum ice_state {
__ICE_DOWN,
+   __ICE_NEEDS_RESTART,
+   __ICE_RESET_RECOVERY_PENDING,   /* set by driver when reset starts */
__ICE_PFR_REQ,  /* set by driver and peers */
+   __ICE_CORER_REQ,/* set by driver and peers */
+   __ICE_GLOBR_REQ,/* set by driver and peers */
+   __ICE_CORER_RECV,   /* set by OICR handler */
+   __ICE_GLOBR_RECV,   /* set by OICR handler */
+   __ICE_EMPR_RECV,/* set by OICR handler */
+   __ICE_SUSPENDED,/* set on module remove path */
+   __ICE_RESET_FAILED, /* set by reset/rebuild */
__ICE_ADMINQ_EVENT_PENDING,
__ICE_CFG_BUSY,
__ICE_SERVICE_SCHED,
@@ -240,6 +254,11 @@ struct ice_pf {
u16 q_left_rx;  /* remaining num rx queues left unclaimed */
u16 next_vsi;   /* Next free slot in pf->vsi[] - 0-based! */
u16 num_alloc_vsi;
+   u16 corer_count;/* Core reset count */
+   u16 globr_count;/* Global reset count */
+   u16 empr_count; /* EMP reset count */
+   u16 pfr_count;  /* PF reset count */
+
struct ice_hw_port_stats stats;
struct ice_hw_port_stats stats_prev;
struct ice_hw hw;
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 62509635fc5e..8cade22c1cf6 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -1023,6 +1023,23 @@ struct ice_aqc_get_link_status_data {
__le64 reserved4;
 };
 
+/* Set event mask command (direct 0x0613) */
+struct ice_aqc_set_event_mask {
+   u8  lport_num;
+   u8  reserved[7];
+   __le16  event_mask;
+#define ICE_AQ_LINK_EVENT_UPDOWN   BIT(1)
+#define ICE_AQ_LINK_EVENT_MEDIA_NA BIT(2)
+#define ICE_AQ_LINK_EVENT_LINK_FAULT   BIT(3)
+#define ICE_AQ_LINK_EVENT_PHY_TEMP_ALARM   BIT(4)
+#define ICE_AQ_LINK_EVENT_EXCESSIVE_ERRORS BIT(5)
+#define ICE_AQ_LINK_EVENT_SIGNAL_DETECTBIT(6)
+#define ICE_AQ_LINK_EVENT_AN_COMPLETED BIT(7)
+#define ICE_AQ_LINK_EVENT_M

[PATCH 11/15] ice: Add support for VLANs and offloads

2018-03-09 Thread Anirudh Venkataramanan
This patch adds support for VLANs. When a VLAN is created a switch filter
is added to direct the VLAN traffic to the corresponding VSI. When a VLAN
is deleted, the filter is deleted as well.

This patch also adds support for the following hardware offloads.
1) VLAN tag insertion/stripping
2) Receive Side Scaling (RSS)
3) Tx checksum and TCP segmentation
4) Rx checksum

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|  19 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  62 +++
 drivers/net/ethernet/intel/ice/ice_common.c | 188 
 drivers/net/ethernet/intel/ice/ice_common.h |  13 +
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  | 169 +++
 drivers/net/ethernet/intel/ice/ice_main.c   | 601 +++-
 drivers/net/ethernet/intel/ice/ice_switch.c | 169 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |   4 +
 drivers/net/ethernet/intel/ice/ice_txrx.c   | 405 +++-
 drivers/net/ethernet/intel/ice/ice_txrx.h   |  17 +
 10 files changed, 1631 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 03bcc5c371ac..96964d99032d 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -37,7 +37,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
 #include "ice_devids.h"
 #include "ice_type.h"
 #include "ice_txrx.h"
@@ -60,6 +63,8 @@
 #define ICE_MAX_SCATTER_RXQS   16
 #define ICE_Q_WAIT_RETRY_LIMIT 10
 #define ICE_Q_WAIT_MAX_RETRY   (5 * ICE_Q_WAIT_RETRY_LIMIT)
+#define ICE_MAX_LG_RSS_QS  256
+#define ICE_MAX_SMALL_RSS_QS   8
 #define ICE_RES_VALID_BIT  0x8000
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 #define ICE_INVAL_Q_INDEX  0x
@@ -75,6 +80,7 @@
 
 #define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
 #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
+#define ICE_TX_CTX_DESC(R, i) (&(((struct ice_tx_ctx_desc *)((R)->desc))[i]))
 
 #define ice_for_each_txq(vsi, i) \
for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
@@ -126,6 +132,7 @@ struct ice_vsi {
irqreturn_t (*irq_handler)(int irq, void *data);
 
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
int num_q_vectors;
int base_vector;
enum ice_vsi_type type;
@@ -135,6 +142,13 @@ struct ice_vsi {
/* Interrupt thresholds */
u16 work_lmt;
 
+   /* RSS config */
+   u16 rss_table_size; /* HW RSS table size */
+   u16 rss_size;   /* Allocated RSS queues */
+   u8 *rss_hkey_user;  /* User configured hash keys */
+   u8 *rss_lut_user;   /* User configured lookup table entries */
+   u8 rss_lut_type;/* used to configure Get/Set RSS LUT AQ call */
+
u16 max_frame;
u16 rx_buf_len;
 
@@ -194,6 +208,7 @@ struct ice_pf {
struct mutex avail_q_mutex; /* protects access to avail_[rx|tx]qs */
struct mutex sw_mutex;  /* lock for protecting VSI alloc flow */
u32 msg_enable;
+   u32 hw_csum_rx_error;
u32 oicr_idx;   /* Other interrupt cause vector index */
u32 num_lan_msix;   /* Total MSIX vectors for base driver */
u32 num_avail_msix; /* remaining MSIX vectors left unclaimed */
@@ -237,4 +252,8 @@ static inline void ice_irq_dynamic_ena(struct ice_hw *hw, 
struct ice_vsi *vsi,
wr32(hw, GLINT_DYN_CTL(vector), val);
 }
 
+int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
+int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
+void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
+
 #endif /* _ICE_H_ */
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 358a482630db..49102817f0a9 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -982,6 +982,60 @@ struct ice_aqc_nvm {
__le32  addr_low;
 };
 
+/* Get/Set RSS key (indirect 0x0B04/0x0B02) */
+struct ice_aqc_get_set_rss_key {
+#define ICE_AQC_GSET_RSS_KEY_VSI_VALID BIT(15)
+#define ICE_AQC_GSET_RSS_KEY_VSI_ID_S  0
+#define ICE_AQC_GSET_RSS_KEY_VSI_ID_M  (0x3FF << ICE_AQC_GSET_RSS_KEY_VSI_ID_S)
+   __le16 vsi_id;
+   u8 reserved[6];
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+#define ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE  0x28
+#define ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE 0xC
+
+struct ice_aqc_get_set_rss_keys {
+   u8 standard_rss_key[ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE];
+   u8 extended_hash_key[ICE_AQC_GET_SET_RSS_KEY_DATA_HASH_KEY_SIZE];
+};
+
+/* Get/Set RSS LUT (i

[PATCH 13/15] ice: Update Tx scheduler tree for VSI multi-Tx queue support

2018-03-09 Thread Anirudh Venkataramanan
This patch adds the ability for a VSI to use multiple Tx queues. More
specifically, the patch
1) Provides the ability to update the Tx scheduler tree in the
   firmware. The driver can configure the Tx scheduler tree by
   adding/removing multiple Tx queues per TC per VSI.

2) Allows a VSI to reconfigure its Tx queues during runtime.

3) Synchronizes the Tx scheduler update operations using locks.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|   7 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  28 +
 drivers/net/ethernet/intel/ice/ice_common.c |  54 ++
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_main.c   |  20 +-
 drivers/net/ethernet/intel/ice/ice_sched.c  | 886 
 drivers/net/ethernet/intel/ice/ice_sched.h  |   4 +
 drivers/net/ethernet/intel/ice/ice_type.h   |   7 +
 8 files changed, 1006 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index c09921d43f7a..c32dc36a9801 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -56,6 +56,7 @@ extern const char ice_drv_ver[];
 #define ICE_MIN_NUM_DESC   8
 #define ICE_MAX_NUM_DESC   8160
 #define ICE_REQ_DESC_MULTIPLE  32
+#define ICE_DFLT_TRAFFIC_CLASS BIT(0)
 #define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
 #define ICE_ETHTOOL_FWVER_LEN  32
 #define ICE_AQ_LEN 64
@@ -275,6 +276,12 @@ static inline void ice_irq_dynamic_ena(struct ice_hw *hw, 
struct ice_vsi *vsi,
wr32(hw, GLINT_DYN_CTL(vector), val);
 }
 
+static inline void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
+{
+   vsi->tc_cfg.ena_tc =  ICE_DFLT_TRAFFIC_CLASS;
+   vsi->tc_cfg.numtc = 1;
+}
+
 void ice_set_ethtool_ops(struct net_device *netdev);
 void ice_update_pf_stats(struct ice_pf *pf);
 void ice_update_vsi_stats(struct ice_vsi *vsi);
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 2c8d8533f87d..62509635fc5e 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -645,6 +645,25 @@ struct ice_aqc_get_topo {
__le32 addr_low;
 };
 
+/* Update TSE (indirect 0x0403)
+ * Get TSE (indirect 0x0404)
+ */
+struct ice_aqc_get_cfg_elem {
+   __le16 num_elem_req;/* Used by commands */
+   __le16 num_elem_resp;   /* Used by responses */
+   __le32 reserved;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* This is the buffer for:
+ * Suspend Nodes (indirect 0x0409)
+ * Resume Nodes (indirect 0x040A)
+ */
+struct ice_aqc_suspend_resume_elem {
+   __le32 teid[1];
+};
+
 /* Add TSE (indirect 0x0401)
  * Delete TSE (indirect 0x040F)
  * Move TSE (indirect 0x0408)
@@ -705,6 +724,11 @@ struct ice_aqc_txsched_topo_grp_info_hdr {
__le16 reserved2;
 };
 
+struct ice_aqc_add_elem {
+   struct ice_aqc_txsched_topo_grp_info_hdr hdr;
+   struct ice_aqc_txsched_elem_data generic[1];
+};
+
 struct ice_aqc_get_topo_elem {
struct ice_aqc_txsched_topo_grp_info_hdr hdr;
struct ice_aqc_txsched_elem_data
@@ -1195,6 +1219,7 @@ struct ice_aq_desc {
struct ice_aqc_get_sw_cfg get_sw_conf;
struct ice_aqc_sw_rules sw_rules;
struct ice_aqc_get_topo get_topo;
+   struct ice_aqc_get_cfg_elem get_update_elem;
struct ice_aqc_query_txsched_res query_sched_res;
struct ice_aqc_add_move_delete_elem add_move_delete_elem;
struct ice_aqc_nvm nvm;
@@ -1272,6 +1297,9 @@ enum ice_adminq_opc {
 
/* transmit scheduler commands */
ice_aqc_opc_get_dflt_topo   = 0x0400,
+   ice_aqc_opc_add_sched_elems = 0x0401,
+   ice_aqc_opc_suspend_sched_elems = 0x0409,
+   ice_aqc_opc_resume_sched_elems  = 0x040A,
ice_aqc_opc_delete_sched_elems  = 0x040F,
ice_aqc_opc_query_sched_res = 0x0412,
 
diff --git a/drivers/net/ethernet/intel/ice/ice_common.c 
b/drivers/net/ethernet/intel/ice/ice_common.c
index b97c0e27196b..311e7b2a4fb7 100644
--- a/drivers/net/ethernet/intel/ice/ice_common.c
+++ b/drivers/net/ethernet/intel/ice/ice_common.c
@@ -2100,3 +2100,57 @@ ice_dis_vsi_txq(struct ice_port_info *pi, u8 num_queues, 
u16 *q_ids,
mutex_unlock(>sched_lock);
return status;
 }
+
+/**
+ * ice_cfg_vsi_qs - configure the new/exisiting VSI queues
+ * @pi: port information structure
+ * @vsi_id: VSI Id
+ * @tc_bitmap: TC bitmap
+ * @maxqs: max queues array per TC
+ * @owner: lan or rdma
+ *
+ * This function adds/updates the VSI queues per TC.
+ */
+static enum ice_status
+ice_cfg_vsi_qs(struct ice_port_info *pi, u16 vsi_id, u8 tc_bitmap,
+ 

[PATCH 10/15] ice: Implement transmit and NAPI support

2018-03-09 Thread Anirudh Venkataramanan
This patch implements ice_start_xmit (the handler for ndo_start_xmit) and
related functions. ice_start_xmit ultimately calls ice_tx_map, where the
Tx descriptor is built and posted to the hardware by bumping the ring tail.

This patch also implements ice_napi_poll, which is invoked when there's an
interrupt on the VSI's queues. The interrupt can be due to either a
completed Tx or an Rx event. In case of a completed Tx/Rx event, resources
are reclaimed. Additionally, in case of an Rx event, the skb is fetched
and passed up to the network stack.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h   |1 +
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h |   46 ++
 drivers/net/ethernet/intel/ice/ice_main.c  |   55 ++
 drivers/net/ethernet/intel/ice/ice_txrx.c  | 1026 +++-
 drivers/net/ethernet/intel/ice/ice_txrx.h  |   45 ++
 5 files changed, 1171 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 4945cba60764..03bcc5c371ac 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -73,6 +73,7 @@
(((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
  ICE_AQ_VSI_UP_TABLE_UP##i##_M)
 
+#define ICE_TX_DESC(R, i) (&(((struct ice_tx_desc *)((R)->desc))[i]))
 #define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
 
 #define ice_for_each_txq(vsi, i) \
diff --git a/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h 
b/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
index 0cdf1ae480cf..c930f3e06ecc 100644
--- a/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
+++ b/drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
@@ -145,6 +145,33 @@ enum ice_rx_flg64_bits {
ICE_RXFLG_RSVD  = 63
 };
 
+/* for ice_32byte_rx_flex_desc.ptype_flexi_flags0 member */
+#define ICE_RX_FLEX_DESC_PTYPE_M   (0x3FF) /* 10-bits */
+
+/* for ice_32byte_rx_flex_desc.pkt_length member */
+#define ICE_RX_FLX_DESC_PKT_LEN_M  (0x3FFF) /* 14-bits */
+
+enum ice_rx_flex_desc_status_error_0_bits {
+   /* Note: These are predefined bit offsets */
+   ICE_RX_FLEX_DESC_STATUS0_DD_S = 0,
+   ICE_RX_FLEX_DESC_STATUS0_EOF_S,
+   ICE_RX_FLEX_DESC_STATUS0_HBO_S,
+   ICE_RX_FLEX_DESC_STATUS0_L3L4P_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_L4E_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S,
+   ICE_RX_FLEX_DESC_STATUS0_XSUM_EUDPE_S,
+   ICE_RX_FLEX_DESC_STATUS0_LPBK_S,
+   ICE_RX_FLEX_DESC_STATUS0_IPV6EXADD_S,
+   ICE_RX_FLEX_DESC_STATUS0_RXE_S,
+   ICE_RX_FLEX_DESC_STATUS0_CRCP_S,
+   ICE_RX_FLEX_DESC_STATUS0_RSS_VALID_S,
+   ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S,
+   ICE_RX_FLEX_DESC_STATUS0_XTRMD0_VALID_S,
+   ICE_RX_FLEX_DESC_STATUS0_XTRMD1_VALID_S,
+   ICE_RX_FLEX_DESC_STATUS0_LAST /* this entry must be last!!! */
+};
+
 #define ICE_RXQ_CTX_SIZE_DWORDS8
 #define ICE_RXQ_CTX_SZ (ICE_RXQ_CTX_SIZE_DWORDS * sizeof(u32))
 
@@ -215,6 +242,25 @@ struct ice_tx_desc {
__le64 cmd_type_offset_bsz;
 };
 
+enum ice_tx_desc_dtype_value {
+   ICE_TX_DESC_DTYPE_DATA  = 0x0,
+   ICE_TX_DESC_DTYPE_CTX   = 0x1,
+   /* DESC_DONE - HW has completed write-back of descriptor */
+   ICE_TX_DESC_DTYPE_DESC_DONE = 0xF,
+};
+
+#define ICE_TXD_QW1_CMD_S  4
+#define ICE_TXD_QW1_CMD_M  (0xFFFUL << ICE_TXD_QW1_CMD_S)
+
+enum ice_tx_desc_cmd_bits {
+   ICE_TX_DESC_CMD_EOP = 0x0001,
+   ICE_TX_DESC_CMD_RS  = 0x0002,
+};
+
+#define ICE_TXD_QW1_OFFSET_S   16
+#define ICE_TXD_QW1_TX_BUF_SZ_S34
+#define ICE_TXD_QW1_L2TAG1_S   48
+
 #define ICE_LAN_TXQ_MAX_QGRPS  127
 #define ICE_LAN_TXQ_MAX_QDIS   1023
 
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c 
b/drivers/net/ethernet/intel/ice/ice_main.c
index fca87bdaace9..d4c435f58f82 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -1271,6 +1271,23 @@ static int ice_vsi_alloc_arrays(struct ice_vsi *vsi, 
bool alloc_qvectors)
return -ENOMEM;
 }
 
+/**
+ * ice_msix_clean_rings - MSIX mode Interrupt Handler
+ * @irq: interrupt number
+ * @data: pointer to a q_vector
+ */
+static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
+{
+   struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
+
+   if (!q_vector->tx.ring && !q_vector->rx.ring)
+   return IRQ_HANDLED;
+
+   napi_schedule(_vector->napi);
+
+   return IRQ_HANDLED;
+}
+
 /**
  * ice_vsi_alloc - Allocates the next available struct vsi in the PF
  * @pf: board private structure
@@ -1311,6 +1328,8 @@ static struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf, 
enum ice_vsi_type type)
if (ice_vsi_

[PATCH 09/15] ice: Configure VSIs for Tx/Rx

2018-03-09 Thread Anirudh Venkataramanan
This patch configures the VSIs to be able to send and receive
packets by doing the following:

1) Initialize flexible parser to extract and include certain
   fields in the Rx descriptor.

2) Add Tx queues by programming the Tx queue context (implemented in
   ice_vsi_cfg_txqs). Note that adding the queues also enables (starts)
   the queues.

3) Add Rx queues by programming Rx queue context (implemented in
   ice_vsi_cfg_rxqs). Note that this only adds queues but doesn't start
   them. The rings will be started by calling ice_vsi_start_rx_rings on
   interface up.

4) Configure interrupts for VSI queues.

5) Implement ice_open and ice_stop.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/Makefile |3 +-
 drivers/net/ethernet/intel/ice/ice.h|   36 +-
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |   86 ++
 drivers/net/ethernet/intel/ice/ice_common.c |  602 
 drivers/net/ethernet/intel/ice/ice_common.h |   13 +
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |   59 ++
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  |  260 +
 drivers/net/ethernet/intel/ice/ice_main.c   | 1186 ++-
 drivers/net/ethernet/intel/ice/ice_sched.c  |  105 ++
 drivers/net/ethernet/intel/ice/ice_sched.h  |5 +
 drivers/net/ethernet/intel/ice/ice_status.h |2 +
 drivers/net/ethernet/intel/ice/ice_txrx.c   |  375 +++
 drivers/net/ethernet/intel/ice/ice_txrx.h   |   75 ++
 drivers/net/ethernet/intel/ice/ice_type.h   |2 +
 14 files changed, 2780 insertions(+), 29 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.c

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 809d85c04398..0abeb20c006d 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -29,4 +29,5 @@ ice-y := ice_main.o   \
 ice_common.o   \
 ice_nvm.o  \
 ice_switch.o   \
-ice_sched.o
+ice_sched.o\
+ice_txrx.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index b169f3751cc9..4945cba60764 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -25,8 +25,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -56,6 +58,8 @@
 #define ICE_VSI_MAP_SCATTER1
 #define ICE_MAX_SCATTER_TXQS   16
 #define ICE_MAX_SCATTER_RXQS   16
+#define ICE_Q_WAIT_RETRY_LIMIT 10
+#define ICE_Q_WAIT_MAX_RETRY   (5 * ICE_Q_WAIT_RETRY_LIMIT)
 #define ICE_RES_VALID_BIT  0x8000
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 #define ICE_INVAL_Q_INDEX  0x
@@ -69,6 +73,14 @@
(((val) << ICE_AQ_VSI_UP_TABLE_UP##i##_S) & \
  ICE_AQ_VSI_UP_TABLE_UP##i##_M)
 
+#define ICE_RX_DESC(R, i) (&(((union ice_32b_rx_flex_desc *)((R)->desc))[i]))
+
+#define ice_for_each_txq(vsi, i) \
+   for ((i) = 0; (i) < (vsi)->num_txq; (i)++)
+
+#define ice_for_each_rxq(vsi, i) \
+   for ((i) = 0; (i) < (vsi)->num_rxq; (i)++)
+
 struct ice_tc_info {
u16 qoffset;
u16 qcount;
@@ -109,6 +121,9 @@ struct ice_vsi {
struct ice_ring **rx_rings;  /* rx ring array */
struct ice_ring **tx_rings;  /* tx ring array */
struct ice_q_vector **q_vectors; /* q_vector array */
+
+   irqreturn_t (*irq_handler)(int irq, void *data);
+
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
int num_q_vectors;
int base_vector;
@@ -119,8 +134,14 @@ struct ice_vsi {
/* Interrupt thresholds */
u16 work_lmt;
 
+   u16 max_frame;
+   u16 rx_buf_len;
+
struct ice_aqc_vsi_props info;   /* VSI properties */
 
+   bool irqs_ready;
+   bool current_isup;   /* Sync 'link up' logging */
+
/* queue information */
u8 tx_mapping_mode;  /* ICE_MAP_MODE_[CONTIG|SCATTER] */
u8 rx_mapping_mode;  /* ICE_MAP_MODE_[CONTIG|SCATTER] */
@@ -141,9 +162,11 @@ struct ice_q_vector {
struct napi_struct napi;
struct ice_ring_container rx;
struct ice_ring_container tx;
+   struct irq_affinity_notify affinity_notify;
u16 v_idx;  /* index in the vsi->q_vector array. */
u8 num_ring_tx; /* total number of tx rings in vector */
u8 num_ring_rx; /* total number of rx rings in vector */
+   char name[ICE_INT_NAME_STR_LEN];
 } cacheline_internodealigned_in_smp;
 
 enum ice_pf_flags {
@@ -191,10 +214,14 @@ struct ice_netdev_priv {
 /**
  * ice_irq_dynamic_ena - Enable default interrupt generation settings
  * @hw: pointer to hw struct
+ * @vsi: pointer to vsi stru

[PATCH 15/15] ice: Implement filter sync, NDO operations and bump version

2018-03-09 Thread Anirudh Venkataramanan
This patch implements multiple pieces of functionality:

1. Added ice_vsi_sync_filters, which is called through the service task
   to push filter updates to the hardware.

2. Add support to enable/disable promiscuous mode on an interface.
   Enabling/disabling promiscuous mode on an interface results in
   addition/removal of a promisc filter rule through ice_vsi_sync_filters.

3. Implement handlers for ndo_set_mac_address, ndo_change_mtu,
   ndo_poll_controller and ndo_set_rx_mode.

This patch also marks the end of the driver addition by bumping up the
driver version.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|  14 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  21 +
 drivers/net/ethernet/intel/ice/ice_common.c |  28 ++
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  |  12 +
 drivers/net/ethernet/intel/ice/ice_main.c   | 567 +++-
 drivers/net/ethernet/intel/ice/ice_switch.c |  77 
 drivers/net/ethernet/intel/ice/ice_switch.h |   2 +
 drivers/net/ethernet/intel/ice/ice_type.h   |   5 +
 9 files changed, 728 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index e2d4b4de1f1d..55dbe9ffee56 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -138,11 +138,20 @@ enum ice_state {
__ICE_SUSPENDED,/* set on module remove path */
__ICE_RESET_FAILED, /* set by reset/rebuild */
__ICE_ADMINQ_EVENT_PENDING,
+   __ICE_FLTR_OVERFLOW_PROMISC,
__ICE_CFG_BUSY,
__ICE_SERVICE_SCHED,
__ICE_STATE_NBITS   /* must be last */
 };
 
+enum ice_vsi_flags {
+   ICE_VSI_FLAG_UMAC_FLTR_CHANGED,
+   ICE_VSI_FLAG_MMAC_FLTR_CHANGED,
+   ICE_VSI_FLAG_VLAN_FLTR_CHANGED,
+   ICE_VSI_FLAG_PROMISC_CHANGED,
+   ICE_VSI_FLAG_NBITS  /* must be last */
+};
+
 /* struct that defines a VSI, associated with a dev */
 struct ice_vsi {
struct net_device *netdev;
@@ -157,7 +166,9 @@ struct ice_vsi {
 
u64 tx_linearize;
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
+   DECLARE_BITMAP(flags, ICE_VSI_FLAG_NBITS);
unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
+   unsigned int current_netdev_flags;
u32 tx_restart;
u32 tx_busy;
u32 rx_buf_failed;
@@ -189,6 +200,9 @@ struct ice_vsi {
struct ice_eth_stats eth_stats;
struct ice_eth_stats eth_stats_prev;
 
+   struct list_head tmp_sync_list; /* MAC filters to be synced */
+   struct list_head tmp_unsync_list;   /* MAC filters to be unsynced */
+
bool irqs_ready;
bool current_isup;   /* Sync 'link up' logging */
bool stat_offsets_loaded;
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 8cade22c1cf6..fc19c287ebc5 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -149,6 +149,24 @@ struct ice_aqc_manage_mac_read_resp {
u8 mac_addr[ETH_ALEN];
 };
 
+/* Manage MAC address, write command - direct (0x0108) */
+struct ice_aqc_manage_mac_write {
+   u8 port_num;
+   u8 flags;
+#define ICE_AQC_MAN_MAC_WR_MC_MAG_EN   BIT(0)
+#define ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEPBIT(1)
+#define ICE_AQC_MAN_MAC_WR_S   6
+#define ICE_AQC_MAN_MAC_WR_M   (3 << ICE_AQC_MAN_MAC_WR_S)
+#define ICE_AQC_MAN_MAC_UPDATE_LAA 0
+#define ICE_AQC_MAN_MAC_UPDATE_LAA_WOL (BIT(0) << ICE_AQC_MAN_MAC_WR_S)
+   /* High 16 bits of MAC address in big endian order */
+   __be16 sah;
+   /* Low 32 bits of MAC address in big endian order */
+   __be32 sal;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
 /* Clear PXE Command and response (direct 0x0110) */
 struct ice_aqc_clear_pxe {
u8 rx_cnt;
@@ -1228,6 +1246,7 @@ struct ice_aq_desc {
struct ice_aqc_q_shutdown q_shutdown;
struct ice_aqc_req_res res_owner;
struct ice_aqc_manage_mac_read mac_read;
+   struct ice_aqc_manage_mac_write mac_write;
struct ice_aqc_clear_pxe clear_pxe;
struct ice_aqc_list_caps get_cap;
struct ice_aqc_get_phy_caps get_phy;
@@ -1272,6 +1291,7 @@ enum ice_aq_err {
ICE_AQ_RC_ENOMEM= 9,  /* Out of memory */
ICE_AQ_RC_EBUSY = 12, /* Device or resource busy */
ICE_AQ_RC_EEXIST= 13, /* object already exists */
+   ICE_AQ_RC_ENOSPC= 16, /* No space left or allocation failure */
 };
 
 /* Admin Queue command opcodes */
@@ -1290,6 +1310,7 @@ enum ice_adminq_opc {
 
/* manage MAC address */
ice_aqc_o

[PATCH 12/15] ice: Add stats and ethtool support

2018-03-09 Thread Anirudh Venkataramanan
This patch implements a watchdog task to get packet statistics from
the device.

This patch also adds support for the following ethtool operations:

ethtool devname
ethtool -s devname [msglvl N] [msglevel type on|off]
ethtool -g|--show-ring devname
ethtool -G|--set-ring devname [rx N] [tx N]
ethtool -i|--driver devname
ethtool -d|--register-dump devname [raw on|off] [hex on|off] [file name]
ethtool -k|--show-features|--show-offload devname
ethtool -K|--features|--offload devname feature on|off
ethtool -P|--show-permaddr devname
ethtool -S|--statistics devname
ethtool -a|--show-pause devname
ethtool -A|--pause devname [autoneg on|off] [rx on|off] [tx on|off]
ethtool -r|--negotiate devname
ethtool --phy-statistics devname

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/Makefile |   3 +-
 drivers/net/ethernet/intel/ice/ice.h|  31 +-
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h |  43 ++
 drivers/net/ethernet/intel/ice/ice_common.c | 195 +
 drivers/net/ethernet/intel/ice/ice_common.h |   5 +
 drivers/net/ethernet/intel/ice/ice_ethtool.c| 972 
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  80 ++
 drivers/net/ethernet/intel/ice/ice_main.c   | 470 +++-
 drivers/net/ethernet/intel/ice/ice_type.h   |  69 ++
 9 files changed, 1863 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_ethtool.c

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 0abeb20c006d..643d63016624 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -30,4 +30,5 @@ ice-y := ice_main.o   \
 ice_nvm.o  \
 ice_switch.o   \
 ice_sched.o\
-ice_txrx.o
+ice_txrx.o \
+ice_ethtool.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index 96964d99032d..c09921d43f7a 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -27,12 +27,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,10 +50,14 @@
 #include "ice_common.h"
 #include "ice_sched.h"
 
+extern const char ice_drv_ver[];
 #define ICE_BAR0   0
 #define ICE_DFLT_NUM_DESC  128
+#define ICE_MIN_NUM_DESC   8
+#define ICE_MAX_NUM_DESC   8160
 #define ICE_REQ_DESC_MULTIPLE  32
 #define ICE_INT_NAME_STR_LEN   (IFNAMSIZ + 16)
+#define ICE_ETHTOOL_FWVER_LEN  32
 #define ICE_AQ_LEN 64
 #define ICE_MIN_MSIX   2
 #define ICE_MAX_VSI_ALLOC  130
@@ -69,6 +75,8 @@
 #define ICE_RES_MISC_VEC_ID(ICE_RES_VALID_BIT - 1)
 #define ICE_INVAL_Q_INDEX  0x
 
+#define ICE_VSIQF_HKEY_ARRAY_SIZE  ((VSIQF_HKEY_MAX_INDEX + 1) *   4)
+
 #define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
 #define ICE_MAX_MTU(ICE_AQ_SET_MAC_FRAME_SIZE_MAX - \
@@ -115,6 +123,7 @@ enum ice_state {
__ICE_DOWN,
__ICE_PFR_REQ,  /* set by driver and peers */
__ICE_ADMINQ_EVENT_PENDING,
+   __ICE_CFG_BUSY,
__ICE_SERVICE_SCHED,
__ICE_STATE_NBITS   /* must be last */
 };
@@ -131,8 +140,13 @@ struct ice_vsi {
 
irqreturn_t (*irq_handler)(int irq, void *data);
 
+   u64 tx_linearize;
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
+   u32 tx_restart;
+   u32 tx_busy;
+   u32 rx_buf_failed;
+   u32 rx_page_failed;
int num_q_vectors;
int base_vector;
enum ice_vsi_type type;
@@ -154,8 +168,15 @@ struct ice_vsi {
 
struct ice_aqc_vsi_props info;   /* VSI properties */
 
+   /* VSI stats */
+   struct rtnl_link_stats64 net_stats;
+   struct rtnl_link_stats64 net_stats_prev;
+   struct ice_eth_stats eth_stats;
+   struct ice_eth_stats eth_stats_prev;
+
bool irqs_ready;
bool current_isup;   /* Sync 'link up' logging */
+   bool stat_offsets_loaded;
 
/* queue information */
u8 tx_mapping_mode;  /* ICE_MAP_MODE_[CONTIG|SCATTER] */
@@ -218,8 +239,10 @@ struct ice_pf {
u16 q_left_rx;  /* remaining num rx queues left unclaimed */
u16 next_vsi;   /* Next free slot in pf->vsi[] - 0-based! */
u16 num_alloc_vsi;
-
+   struct ice_hw_port_stats stats;
+   struct ice_hw_port_stats stats_prev;
struct ice_hw hw;
+   bool stat_prev_loaded;  /* has previous stats been loaded */
char int_name[ICE_INT_NAME_STR_LEN];
 };
 
@@ -252,8 +275,14 @@ static inline void ice_irq_dynamic_ena(struct ice_hw *hw, 
struct ice_vsi *vsi,
wr32(hw, GLINT_DYN_CTL(vector), val);
 }
 
+void ice_set_ethtool_

[PATCH 04/15] ice: Get switch config, scheduler config and device capabilities

2018-03-09 Thread Anirudh Venkataramanan
This patch adds to the initialization flow by getting switch
configuration, scheduler configuration and device capabilities.

Switch configuration:
On boot, an L2 switch element is created in the firmware per physical
function. Each physical function is also mapped to a port, to which its
switch element is connected. In other words, this switch can be visualized
as an embedded vSwitch that can connect a physical functions's virtual
station interfaces (VSIs) to the egress/ingress port. Egress/ingress
filters will be eventually created and applied on this switch element.
As part of the initialization flow, the driver gets configuration data
from this switch element and stores it.

Scheduler configuration:
The Tx scheduler is a subsystem responsible for setting and enforcing QoS.
As part of the initialization flow, the driver queries and stores the
default scheduler configuration for the given physical function.

Device capabilities:
As part of initialization, the driver has to determine what the device is
capable of (ex. max queues, VSIs, etc). This information is obtained from
the firmware and stored by the driver.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/Makefile |   4 +-
 drivers/net/ethernet/intel/ice/ice.h|   2 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 209 ++
 drivers/net/ethernet/intel/ice/ice_common.c | 223 +++
 drivers/net/ethernet/intel/ice/ice_common.h |   2 +
 drivers/net/ethernet/intel/ice/ice_sched.c  | 354 
 drivers/net/ethernet/intel/ice/ice_sched.h  |  42 +++
 drivers/net/ethernet/intel/ice/ice_switch.c | 158 +++
 drivers/net/ethernet/intel/ice/ice_switch.h |  28 ++
 drivers/net/ethernet/intel/ice/ice_type.h   | 109 
 10 files changed, 1130 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.h

diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
index 373d481dbb25..809d85c04398 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -27,4 +27,6 @@ obj-$(CONFIG_ICE) += ice.o
 ice-y := ice_main.o\
 ice_controlq.o \
 ice_common.o   \
-ice_nvm.o
+ice_nvm.o  \
+ice_switch.o   \
+ice_sched.o
diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index ab2800c31906..f6e3339591bb 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -30,7 +30,9 @@
 #include 
 #include "ice_devids.h"
 #include "ice_type.h"
+#include "ice_switch.h"
 #include "ice_common.h"
+#include "ice_sched.h"
 
 #define ICE_BAR0   0
 #define ICE_AQ_LEN 64
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 05b22a1ffd70..66a3f41df673 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -22,6 +22,8 @@
  * descriptor format.  It is shared between Firmware and Software.
  */
 
+#define ICE_AQC_TOPO_MAX_LEVEL_NUM 0x9
+
 struct ice_aqc_generic {
__le32 param0;
__le32 param1;
@@ -82,6 +84,40 @@ struct ice_aqc_req_res {
u8 reserved[2];
 };
 
+/* Get function capabilities (indirect 0x000A)
+ * Get device capabilities (indirect 0x000B)
+ */
+struct ice_aqc_list_caps {
+   u8 cmd_flags;
+   u8 pf_index;
+   u8 reserved[2];
+   __le32 count;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Device/Function buffer entry, repeated per reported capability */
+struct ice_aqc_list_caps_elem {
+   __le16 cap;
+#define ICE_AQC_CAPS_VSI   0x0017
+#define ICE_AQC_CAPS_RSS   0x0040
+#define ICE_AQC_CAPS_RXQS  0x0041
+#define ICE_AQC_CAPS_TXQS  0x0042
+#define ICE_AQC_CAPS_MSIX  0x0043
+#define ICE_AQC_CAPS_MAX_MTU   0x0047
+
+   u8 major_ver;
+   u8 minor_ver;
+   /* Number of resources described by this capability */
+   __le32 number;
+   /* Only meaningful for some types of resources */
+   __le32 logical_id;
+   /* Only meaningful for some types of resources */
+   __le32 phys_id;
+   __le64 rsvd1;
+   __le64 rsvd2;
+};
+
 /* Clear PXE Command and response (direct 0x0110) */
 struct ice_aqc_clear_pxe {
u8 rx_cnt;
@@ -89,6 +125,161 @@ struct ice_aqc_clear_pxe {
u8 reserved[15];
 };
 
+/* Get switch configuration (0x0200) */
+struct ice_a

[PATCH 05/15] ice: Get MAC/PHY/link info and scheduler topology

2018-03-09 Thread Anirudh Venkataramanan
This patch adds code to continue the initialization flow as follows:

1) Get PHY/link information and store it
2) Get default scheduler tree topology and store it
3) Get the MAC address associated with the port and store it

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 drivers/net/ethernet/intel/ice/ice.h|   1 +
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 261 +++
 drivers/net/ethernet/intel/ice/ice_common.c | 264 +++
 drivers/net/ethernet/intel/ice/ice_common.h |   3 +
 drivers/net/ethernet/intel/ice/ice_sched.c  | 328 
 drivers/net/ethernet/intel/ice/ice_sched.h  |   6 +
 drivers/net/ethernet/intel/ice/ice_status.h |   1 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  65 +
 8 files changed, 929 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/ice.h 
b/drivers/net/ethernet/intel/ice/ice.h
index f6e3339591bb..9681e971bcab 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h 
b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
index 66a3f41df673..13e3b7f3e24d 100644
--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
@@ -118,6 +118,35 @@ struct ice_aqc_list_caps_elem {
__le64 rsvd2;
 };
 
+/* Manage MAC address, read command - indirect (0x0107)
+ * This struct is also used for the response
+ */
+struct ice_aqc_manage_mac_read {
+   __le16 flags; /* Zeroed by device driver */
+#define ICE_AQC_MAN_MAC_LAN_ADDR_VALID BIT(4)
+#define ICE_AQC_MAN_MAC_SAN_ADDR_VALID BIT(5)
+#define ICE_AQC_MAN_MAC_PORT_ADDR_VALIDBIT(6)
+#define ICE_AQC_MAN_MAC_WOL_ADDR_VALID BIT(7)
+#define ICE_AQC_MAN_MAC_READ_S 4
+#define ICE_AQC_MAN_MAC_READ_M (0xF << ICE_AQC_MAN_MAC_READ_S)
+   u8 lport_num;
+   u8 lport_num_valid;
+#define ICE_AQC_MAN_MAC_PORT_NUM_IS_VALID  BIT(0)
+   u8 num_addr; /* Used in response */
+   u8 reserved[3];
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* Response buffer format for manage MAC read command */
+struct ice_aqc_manage_mac_read_resp {
+   u8 lport_num;
+   u8 addr_type;
+#define ICE_AQC_MAN_MAC_ADDR_TYPE_LAN  0
+#define ICE_AQC_MAN_MAC_ADDR_TYPE_WOL  1
+   u8 mac_addr[ETH_ALEN];
+};
+
 /* Clear PXE Command and response (direct 0x0110) */
 struct ice_aqc_clear_pxe {
u8 rx_cnt;
@@ -175,6 +204,16 @@ struct ice_aqc_get_sw_cfg_resp {
struct ice_aqc_get_sw_cfg_resp_elem elements[1];
 };
 
+/* Get Default Topology (indirect 0x0400) */
+struct ice_aqc_get_topo {
+   u8 port_num;
+   u8 num_branches;
+   __le16 reserved1;
+   __le32 reserved2;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
 /* Add TSE (indirect 0x0401)
  * Delete TSE (indirect 0x040F)
  * Move TSE (indirect 0x0408)
@@ -235,6 +274,12 @@ struct ice_aqc_txsched_topo_grp_info_hdr {
__le16 reserved2;
 };
 
+struct ice_aqc_get_topo_elem {
+   struct ice_aqc_txsched_topo_grp_info_hdr hdr;
+   struct ice_aqc_txsched_elem_data
+   generic[ICE_AQC_TOPO_MAX_LEVEL_NUM];
+};
+
 struct ice_aqc_delete_elem {
struct ice_aqc_txsched_topo_grp_info_hdr hdr;
__le32 teid[1];
@@ -280,6 +325,210 @@ struct ice_aqc_query_txsched_res_resp {
struct ice_aqc_layer_props layer_props[ICE_AQC_TOPO_MAX_LEVEL_NUM];
 };
 
+/* Get PHY capabilities (indirect 0x0600) */
+struct ice_aqc_get_phy_caps {
+   u8 lport_num;
+   u8 reserved;
+   __le16 param0;
+   /* 18.0 - Report qualified modules */
+#define ICE_AQC_GET_PHY_RQMBIT(0)
+   /* 18.1 - 18.2 : Report mode
+* 00b - Report NVM capabilities
+* 01b - Report topology capabilities
+* 10b - Report SW configured
+*/
+#define ICE_AQC_REPORT_MODE_S  1
+#define ICE_AQC_REPORT_MODE_M  (3 << ICE_AQC_REPORT_MODE_S)
+#define ICE_AQC_REPORT_NVM_CAP 0
+#define ICE_AQC_REPORT_TOPO_CAPBIT(1)
+#define ICE_AQC_REPORT_SW_CFG  BIT(2)
+   __le32 reserved1;
+   __le32 addr_high;
+   __le32 addr_low;
+};
+
+/* This is #define of PHY type (Extended):
+ * The first set of defines is for phy_type_low.
+ */
+#define ICE_PHY_TYPE_LOW_100BASE_TXBIT_ULL(0)
+#define ICE_PHY_TYPE_LOW_100M_SGMIIBIT_ULL(1)
+#define ICE_PHY_TYPE_LOW_1000BASE_TBIT_ULL(2)
+#define ICE_PHY_TYPE_LOW_1000BASE_SX   BIT_ULL(3)
+#define ICE_PHY_TYPE_LOW_1000BASE_LX   BIT_ULL(4)
+#define ICE_PHY_TYPE_LOW_1000BASE_KX   BIT_ULL(5)
+#define ICE_PHY_TYPE_LOW_1G_SGMII  BIT_ULL(6)
+#define ICE_PHY_TYPE_LOW_2500BASE_TB

[PATCH 00/15] Add ice driver

2018-03-09 Thread Anirudh Venkataramanan
This patch series adds the ice driver, which will support the Intel(R)
E800 Series of network devices.

This is the first phase in the release of this driver where we implement
basic transmit and receive. The idea behind the multi-phase release is to
aid in code review as well as testing. Subsequent phases will implement
advanced features (like SR-IOV, tunnelling, flow director, QoS, etc.) that
build upon the previous phase(s). Each phase will be submitted as a patch
series.

I cc'd netdev for review since this is a new driver, even though this is
targetted to go through Jeff Kirsher's Intel Wired LAN git tree(s).

Anirudh Venkataramanan (15):
  ice: Add basic driver framework for Intel(R) E800 Series
  ice: Add support for control queues
  ice: Start hardware initialization
  ice: Get switch config, scheduler config and device capabilities
  ice: Get MAC/PHY/link info and scheduler topology
  ice: Initialize PF and setup miscellaneous interrupt
  ice: Add support for VSI allocation and deallocation
  ice: Add support for switch filter programming
  ice: Configure VSIs for Tx/Rx
  ice: Implement transmit and NAPI support
  ice: Add support for VLANs and offloads
  ice: Add stats and ethtool support
  ice: Update Tx scheduler tree for VSI multi-Tx queue support
  ice: Support link events, reset and rebuild
  ice: Implement filter sync, NDO operations and bump version

 Documentation/networking/ice.txt|   39 +
 MAINTAINERS |1 +
 drivers/net/ethernet/intel/Kconfig  |   14 +
 drivers/net/ethernet/intel/Makefile |1 +
 drivers/net/ethernet/intel/ice/Makefile |   34 +
 drivers/net/ethernet/intel/ice/ice.h|  328 ++
 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h | 1366 ++
 drivers/net/ethernet/intel/ice/ice_common.c | 2244 +
 drivers/net/ethernet/intel/ice/ice_common.h |  100 +
 drivers/net/ethernet/intel/ice/ice_controlq.c   | 1080 +
 drivers/net/ethernet/intel/ice/ice_controlq.h   |  108 +
 drivers/net/ethernet/intel/ice/ice_devids.h |   33 +
 drivers/net/ethernet/intel/ice/ice_ethtool.c|  972 
 drivers/net/ethernet/intel/ice/ice_hw_autogen.h |  280 ++
 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h  |  487 ++
 drivers/net/ethernet/intel/ice/ice_main.c   | 5507 +++
 drivers/net/ethernet/intel/ice/ice_nvm.c|  245 +
 drivers/net/ethernet/intel/ice/ice_osdep.h  |   87 +
 drivers/net/ethernet/intel/ice/ice_sched.c  | 1673 +++
 drivers/net/ethernet/intel/ice/ice_sched.h  |   57 +
 drivers/net/ethernet/intel/ice/ice_status.h |   46 +
 drivers/net/ethernet/intel/ice/ice_switch.c | 1897 
 drivers/net/ethernet/intel/ice/ice_switch.h |  175 +
 drivers/net/ethernet/intel/ice/ice_txrx.c   | 1796 
 drivers/net/ethernet/intel/ice/ice_txrx.h   |  206 +
 drivers/net/ethernet/intel/ice/ice_type.h   |  407 ++
 26 files changed, 19183 insertions(+)
 create mode 100644 Documentation/networking/ice.txt
 create mode 100644 drivers/net/ethernet/intel/ice/Makefile
 create mode 100644 drivers/net/ethernet/intel/ice/ice.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_adminq_cmd.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_common.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_controlq.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_devids.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_ethtool.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_hw_autogen.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_main.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_nvm.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_osdep.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_sched.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_status.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_switch.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_txrx.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_type.h

-- 
2.14.3



[PATCH 01/15] ice: Add basic driver framework for Intel(R) E800 Series

2018-03-09 Thread Anirudh Venkataramanan
This patch adds a basic driver framework for the Intel(R) E800 Ethernet
Series of network devices. There is no functionality right now other than
the ability to load.

Signed-off-by: Anirudh Venkataramanan <anirudh.venkatarama...@intel.com>
---
 Documentation/networking/ice.txt|  39 +++
 MAINTAINERS |   1 +
 drivers/net/ethernet/intel/Kconfig  |  14 +++
 drivers/net/ethernet/intel/Makefile |   1 +
 drivers/net/ethernet/intel/ice/Makefile |  27 +
 drivers/net/ethernet/intel/ice/ice.h|  48 
 drivers/net/ethernet/intel/ice/ice_devids.h |  33 ++
 drivers/net/ethernet/intel/ice/ice_main.c   | 172 
 drivers/net/ethernet/intel/ice/ice_type.h   |  42 +++
 9 files changed, 377 insertions(+)
 create mode 100644 Documentation/networking/ice.txt
 create mode 100644 drivers/net/ethernet/intel/ice/Makefile
 create mode 100644 drivers/net/ethernet/intel/ice/ice.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_devids.h
 create mode 100644 drivers/net/ethernet/intel/ice/ice_main.c
 create mode 100644 drivers/net/ethernet/intel/ice/ice_type.h

diff --git a/Documentation/networking/ice.txt b/Documentation/networking/ice.txt
new file mode 100644
index ..6261c46378e1
--- /dev/null
+++ b/Documentation/networking/ice.txt
@@ -0,0 +1,39 @@
+Intel(R) Ethernet Connection E800 Series Linux Driver
+===
+
+Intel ice Linux driver.
+Copyright(c) 2018 Intel Corporation.
+
+Contents
+
+- Enabling the driver
+- Support
+
+The driver in this release supports Intel's E800 Series of products. For
+more information, visit Intel's support page at http://support.intel.com.
+
+Enabling the driver
+===
+
+The driver is enabled via the standard kernel configuration system,
+using the make command:
+
+ Make oldconfig/silentoldconfig/menuconfig/etc.
+
+The driver is located in the menu structure at:
+
+   -> Device Drivers
+ -> Network device support (NETDEVICES [=y])
+   -> Ethernet driver support
+ -> Intel devices
+   -> Intel(R) Ethernet Connection E800 Series Support
+
+Support
+===
+
+For general information, go to the Intel support website at:
+
+http://support.intel.com
+
+If an issue is identified with the released source code, please email
+the maintainer listed in the MAINTAINERS file.
diff --git a/MAINTAINERS b/MAINTAINERS
index 079af8b7ae8e..f1fe3bbec595 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7019,6 +7019,7 @@ F:Documentation/networking/ixgbe.txt
 F: Documentation/networking/ixgbevf.txt
 F: Documentation/networking/i40e.txt
 F: Documentation/networking/i40evf.txt
+F: Documentation/networking/ice.txt
 F: drivers/net/ethernet/intel/
 F: drivers/net/ethernet/intel/*/
 F: include/linux/avf/virtchnl.h
diff --git a/drivers/net/ethernet/intel/Kconfig 
b/drivers/net/ethernet/intel/Kconfig
index 1feb54b6d92e..14d287bed33c 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -251,6 +251,20 @@ config I40EVF
  will be called i40evf.  MSI-X interrupt support is required
  for this driver to work correctly.
 
+config ICE
+   tristate "Intel(R) Ethernet Connection E800 Series Support"
+   default n
+   depends on PCI_MSI
+   ---help---
+ This driver supports Intel(R) Ethernet Connection E800 Series of
+ devices.  For more information on how to identify your adapter, go
+ to the Adapter & Driver ID Guide that can be located at:
+
+ <http://support.intel.com>
+
+ To compile this driver as a module, choose M here. The module
+ will be called ice.
+
 config FM10K
tristate "Intel(R) FM1 Ethernet Switch Host Interface Support"
default n
diff --git a/drivers/net/ethernet/intel/Makefile 
b/drivers/net/ethernet/intel/Makefile
index 90af7757a885..807a4f8c7e4e 100644
--- a/drivers/net/ethernet/intel/Makefile
+++ b/drivers/net/ethernet/intel/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_I40E) += i40e/
 obj-$(CONFIG_IXGB) += ixgb/
 obj-$(CONFIG_I40EVF) += i40evf/
 obj-$(CONFIG_FM10K) += fm10k/
+obj-$(CONFIG_ICE) += ice/
diff --git a/drivers/net/ethernet/intel/ice/Makefile 
b/drivers/net/ethernet/intel/ice/Makefile
new file mode 100644
index ..2a177ea21b74
--- /dev/null
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+#
+# Intel(R) Ethernet Connection E800 Series Linux Driver
+# Copyright (c) 2018, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Sof