ixgbe: IEEE 802.1Qaz, implement priority assignment table
[deliverable/linux.git] / drivers / net / ixgbe / ixgbe_dcb_nl.c
index a977df3fe81bfb42c890bd762a22b52f45b3ed80..fec4c724c37ad99775b26a9998495079672b2fb2 100644 (file)
@@ -1,7 +1,7 @@
 /*******************************************************************************
 
   Intel 10 Gigabit PCI Express Linux driver
-  Copyright(c) 1999 - 2010 Intel Corporation.
+  Copyright(c) 1999 - 2011 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,
@@ -129,7 +129,6 @@ static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
                        netdev->netdev_ops->ndo_stop(netdev);
                ixgbe_clear_interrupt_scheme(adapter);
 
-               adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
                switch (adapter->hw.mac.type) {
                case ixgbe_mac_82598EB:
                        adapter->last_lfc_mode = adapter->hw.fc.current_mode;
@@ -145,6 +144,9 @@ static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
                }
 
                adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
+               if (!netdev_get_num_tc(netdev))
+                       ixgbe_setup_tc(netdev, MAX_TRAFFIC_CLASS);
+
                ixgbe_init_interrupt_scheme(adapter);
                if (netif_running(netdev))
                        netdev->netdev_ops->ndo_open(netdev);
@@ -159,7 +161,6 @@ static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
                        adapter->temp_dcb_cfg.pfc_mode_enable = false;
                        adapter->dcb_cfg.pfc_mode_enable = false;
                        adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
-                       adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
                        switch (adapter->hw.mac.type) {
                        case ixgbe_mac_82599EB:
                        case ixgbe_mac_X540:
@@ -169,6 +170,8 @@ static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
                                break;
                        }
 
+                       ixgbe_setup_tc(netdev, 0);
+
                        ixgbe_init_interrupt_scheme(adapter);
                        if (netif_running(netdev))
                                netdev->netdev_ops->ndo_open(netdev);
@@ -346,11 +349,12 @@ static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
        int ret;
 
-       if (!adapter->dcb_set_bitmap)
+       if (!adapter->dcb_set_bitmap ||
+           !(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
                return DCB_NO_HW_CHG;
 
        ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
-                                adapter->ring_feature[RING_F_DCB].indices);
+                                MAX_TRAFFIC_CLASS);
 
        if (ret)
                return DCB_NO_HW_CHG;
@@ -412,6 +416,8 @@ static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
        if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
                u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
                u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
+               /* Priority to TC mapping in CEE case default to 1:1 */
+               u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7};
                int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
 
 #ifdef CONFIG_FCOE
@@ -433,7 +439,7 @@ static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
                                      DCB_TX_CONFIG, prio_type);
 
                ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
-                                       bwg_id, prio_type);
+                                       bwg_id, prio_type, prio_tc);
        }
 
        if (adapter->dcb_cfg.pfc_mode_enable)
@@ -448,40 +454,38 @@ static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
 static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
 {
        struct ixgbe_adapter *adapter = netdev_priv(netdev);
-       u8 rval = 0;
 
-       if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
-               switch (capid) {
-               case DCB_CAP_ATTR_PG:
-                       *cap = true;
-                       break;
-               case DCB_CAP_ATTR_PFC:
-                       *cap = true;
-                       break;
-               case DCB_CAP_ATTR_UP2TC:
-                       *cap = false;
-                       break;
-               case DCB_CAP_ATTR_PG_TCS:
-                       *cap = 0x80;
-                       break;
-               case DCB_CAP_ATTR_PFC_TCS:
-                       *cap = 0x80;
-                       break;
-               case DCB_CAP_ATTR_GSP:
-                       *cap = true;
-                       break;
-               case DCB_CAP_ATTR_BCN:
-                       *cap = false;
-                       break;
-               default:
-                       rval = -EINVAL;
-                       break;
-               }
-       } else {
-               rval = -EINVAL;
+       switch (capid) {
+       case DCB_CAP_ATTR_PG:
+               *cap = true;
+               break;
+       case DCB_CAP_ATTR_PFC:
+               *cap = true;
+               break;
+       case DCB_CAP_ATTR_UP2TC:
+               *cap = false;
+               break;
+       case DCB_CAP_ATTR_PG_TCS:
+               *cap = 0x80;
+               break;
+       case DCB_CAP_ATTR_PFC_TCS:
+               *cap = 0x80;
+               break;
+       case DCB_CAP_ATTR_GSP:
+               *cap = true;
+               break;
+       case DCB_CAP_ATTR_BCN:
+               *cap = false;
+               break;
+       case DCB_CAP_ATTR_DCBX:
+               *cap = adapter->dcbx_cap;
+               break;
+       default:
+               *cap = false;
+               break;
        }
 
-       return rval;
+       return 0;
 }
 
 static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
@@ -542,21 +546,16 @@ static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
  */
 static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
 {
-       u8 rval = 0;
+       struct ixgbe_adapter *adapter = netdev_priv(netdev);
+       struct dcb_app app = {
+                               .selector = idtype,
+                               .protocol = id,
+                            };
 
-       switch (idtype) {
-       case DCB_APP_IDTYPE_ETHTYPE:
-#ifdef IXGBE_FCOE
-               if (id == ETH_P_FCOE)
-                       rval = ixgbe_fcoe_getapp(netdev_priv(netdev));
-#endif
-               break;
-       case DCB_APP_IDTYPE_PORTNUM:
-               break;
-       default:
-               break;
-       }
-       return rval;
+       if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
+               return 0;
+
+       return dcb_getapp(netdev, &app);
 }
 
 /**
@@ -571,14 +570,24 @@ static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
 static u8 ixgbe_dcbnl_setapp(struct net_device *netdev,
                              u8 idtype, u16 id, u8 up)
 {
+       struct ixgbe_adapter *adapter = netdev_priv(netdev);
        u8 rval = 1;
+       struct dcb_app app = {
+                             .selector = idtype,
+                             .protocol = id,
+                             .priority = up
+                            };
+
+       if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
+               return rval;
+
+       rval = dcb_setapp(netdev, &app);
 
        switch (idtype) {
        case DCB_APP_IDTYPE_ETHTYPE:
 #ifdef IXGBE_FCOE
                if (id == ETH_P_FCOE) {
                        u8 old_tc;
-                       struct ixgbe_adapter *adapter = netdev_priv(netdev);
 
                        /* Get current programmed tc */
                        old_tc = adapter->fcoe.tc;
@@ -635,11 +644,16 @@ static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
 {
        struct ixgbe_adapter *adapter = netdev_priv(dev);
        __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
+       __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
        int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
-       int err;
+       int i, err;
+       __u64 *p = (__u64 *) ets->prio_tc;
        /* naively give each TC a bwg to map onto CEE hardware */
        __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
 
+       if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
+               return -EINVAL;
+
        if (!adapter->ixgbe_ieee_ets) {
                adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
                                                  GFP_KERNEL);
@@ -647,12 +661,35 @@ static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
                        return -ENOMEM;
        }
 
-
        memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
 
+       /* Map TSA onto CEE prio type */
+       for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
+               switch (ets->tc_tsa[i]) {
+               case IEEE_8021QAZ_TSA_STRICT:
+                       prio_type[i] = 2;
+                       break;
+               case IEEE_8021QAZ_TSA_ETS:
+                       prio_type[i] = 0;
+                       break;
+               default:
+                       /* Hardware only supports priority strict or
+                        * ETS transmission selection algorithms if
+                        * we receive some other value from dcbnl
+                        * throw an error
+                        */
+                       return -EINVAL;
+               }
+       }
+
+       if (*p)
+               ixgbe_dcbnl_set_state(dev, 1);
+       else
+               ixgbe_dcbnl_set_state(dev, 0);
+
        ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
        err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
-                                     bwg_id, ets->tc_tsa);
+                                     bwg_id, prio_type, ets->prio_tc);
        return err;
 }
 
@@ -686,6 +723,9 @@ static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
        struct ixgbe_adapter *adapter = netdev_priv(dev);
        int err;
 
+       if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
+               return -EINVAL;
+
        if (!adapter->ixgbe_ieee_pfc) {
                adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
                                                  GFP_KERNEL);
@@ -698,11 +738,86 @@ static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
        return err;
 }
 
+static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
+                                  struct dcb_app *app)
+{
+       struct ixgbe_adapter *adapter = netdev_priv(dev);
+
+       if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
+               return -EINVAL;
+#ifdef IXGBE_FCOE
+       if (app->selector == 1 && app->protocol == ETH_P_FCOE) {
+               if (adapter->fcoe.tc == app->priority)
+                       goto setapp;
+
+               /* In IEEE mode map up to tc 1:1 */
+               adapter->fcoe.tc = app->priority;
+               adapter->fcoe.up = app->priority;
+
+               /* Force hardware reset required to push FCoE
+                * setup on {tx|rx}_rings
+                */
+               adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
+               ixgbe_dcbnl_set_all(dev);
+       }
+
+setapp:
+#endif
+       dcb_setapp(dev, app);
+       return 0;
+}
+
+static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
+{
+       struct ixgbe_adapter *adapter = netdev_priv(dev);
+       return adapter->dcbx_cap;
+}
+
+static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
+{
+       struct ixgbe_adapter *adapter = netdev_priv(dev);
+       struct ieee_ets ets = {0};
+       struct ieee_pfc pfc = {0};
+
+       /* no support for LLD_MANAGED modes or CEE+IEEE */
+       if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
+           ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
+           !(mode & DCB_CAP_DCBX_HOST))
+               return 1;
+
+       if (mode == adapter->dcbx_cap)
+               return 0;
+
+       adapter->dcbx_cap = mode;
+
+       /* ETS and PFC defaults */
+       ets.ets_cap = 8;
+       pfc.pfc_cap = 8;
+
+       if (mode & DCB_CAP_DCBX_VER_IEEE) {
+               ixgbe_dcbnl_ieee_setets(dev, &ets);
+               ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
+       } else if (mode & DCB_CAP_DCBX_VER_CEE) {
+               adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX);
+               ixgbe_dcbnl_set_all(dev);
+       } else {
+               /* Drop into single TC mode strict priority as this
+                * indicates CEE and IEEE versions are disabled
+                */
+               ixgbe_dcbnl_ieee_setets(dev, &ets);
+               ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
+               ixgbe_dcbnl_set_state(dev, 0);
+       }
+
+       return 0;
+}
+
 const struct dcbnl_rtnl_ops dcbnl_ops = {
        .ieee_getets    = ixgbe_dcbnl_ieee_getets,
        .ieee_setets    = ixgbe_dcbnl_ieee_setets,
        .ieee_getpfc    = ixgbe_dcbnl_ieee_getpfc,
        .ieee_setpfc    = ixgbe_dcbnl_ieee_setpfc,
+       .ieee_setapp    = ixgbe_dcbnl_ieee_setapp,
        .getstate       = ixgbe_dcbnl_get_state,
        .setstate       = ixgbe_dcbnl_set_state,
        .getpermhwaddr  = ixgbe_dcbnl_get_perm_hw_addr,
@@ -724,5 +839,6 @@ const struct dcbnl_rtnl_ops dcbnl_ops = {
        .setpfcstate    = ixgbe_dcbnl_setpfcstate,
        .getapp         = ixgbe_dcbnl_getapp,
        .setapp         = ixgbe_dcbnl_setapp,
+       .getdcbx        = ixgbe_dcbnl_getdcbx,
+       .setdcbx        = ixgbe_dcbnl_setdcbx,
 };
-
This page took 0.028875 seconds and 5 git commands to generate.