Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 Intel Corporation. |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
| 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include "ixgbe.h" |
| 30 | #include <linux/dcbnl.h> |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 31 | #include "ixgbe_dcb_82598.h" |
| 32 | #include "ixgbe_dcb_82599.h" |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 33 | |
| 34 | /* Callbacks for DCB netlink in the kernel */ |
| 35 | #define BIT_DCB_MODE 0x01 |
| 36 | #define BIT_PFC 0x02 |
| 37 | #define BIT_PG_RX 0x04 |
| 38 | #define BIT_PG_TX 0x08 |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 39 | #define BIT_APP_UPCHG 0x10 |
PJ Waskiewicz | 235ea82 | 2009-02-27 15:44:48 +0000 | [diff] [blame] | 40 | #define BIT_LINKSPEED 0x80 |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 41 | |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 42 | /* Responses for the DCB_C_SET_ALL command */ |
| 43 | #define DCB_HW_CHG_RST 0 /* DCB configuration changed with reset */ |
| 44 | #define DCB_NO_HW_CHG 1 /* DCB configuration did not change */ |
| 45 | #define DCB_HW_CHG 2 /* DCB configuration changed, no reset */ |
| 46 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 47 | int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg, |
| 48 | struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max) |
| 49 | { |
| 50 | struct tc_configuration *src_tc_cfg = NULL; |
| 51 | struct tc_configuration *dst_tc_cfg = NULL; |
| 52 | int i; |
| 53 | |
| 54 | if (!src_dcb_cfg || !dst_dcb_cfg) |
| 55 | return -EINVAL; |
| 56 | |
| 57 | for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) { |
| 58 | src_tc_cfg = &src_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0]; |
| 59 | dst_tc_cfg = &dst_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0]; |
| 60 | |
| 61 | dst_tc_cfg->path[DCB_TX_CONFIG].prio_type = |
| 62 | src_tc_cfg->path[DCB_TX_CONFIG].prio_type; |
| 63 | |
| 64 | dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id = |
| 65 | src_tc_cfg->path[DCB_TX_CONFIG].bwg_id; |
| 66 | |
| 67 | dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent = |
| 68 | src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent; |
| 69 | |
| 70 | dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap = |
| 71 | src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap; |
| 72 | |
| 73 | dst_tc_cfg->path[DCB_RX_CONFIG].prio_type = |
| 74 | src_tc_cfg->path[DCB_RX_CONFIG].prio_type; |
| 75 | |
| 76 | dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id = |
| 77 | src_tc_cfg->path[DCB_RX_CONFIG].bwg_id; |
| 78 | |
| 79 | dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent = |
| 80 | src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent; |
| 81 | |
| 82 | dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap = |
| 83 | src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap; |
| 84 | } |
| 85 | |
| 86 | for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) { |
| 87 | dst_dcb_cfg->bw_percentage[DCB_TX_CONFIG] |
| 88 | [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage |
| 89 | [DCB_TX_CONFIG][i-DCB_PG_ATTR_BW_ID_0]; |
| 90 | dst_dcb_cfg->bw_percentage[DCB_RX_CONFIG] |
| 91 | [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage |
| 92 | [DCB_RX_CONFIG][i-DCB_PG_ATTR_BW_ID_0]; |
| 93 | } |
| 94 | |
| 95 | for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) { |
| 96 | dst_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc = |
| 97 | src_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc; |
| 98 | } |
| 99 | |
PJ Waskiewicz | ea4af4f | 2009-03-31 21:33:25 +0000 | [diff] [blame] | 100 | dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable; |
| 101 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static u8 ixgbe_dcbnl_get_state(struct net_device *netdev) |
| 106 | { |
| 107 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 108 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 109 | return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED); |
| 110 | } |
| 111 | |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 112 | static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 113 | { |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 114 | u8 err = 0; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 115 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 116 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 117 | if (state > 0) { |
| 118 | /* Turn on DCB */ |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 119 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 120 | goto out; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 121 | |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 122 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 123 | e_err(drv, "Enable failed, needs MSI-X\n"); |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 124 | err = 1; |
| 125 | goto out; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 126 | } |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 127 | |
| 128 | if (netif_running(netdev)) |
| 129 | netdev->netdev_ops->ndo_stop(netdev); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 130 | ixgbe_clear_interrupt_scheme(adapter); |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 131 | |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 132 | switch (adapter->hw.mac.type) { |
| 133 | case ixgbe_mac_82598EB: |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 134 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 135 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 136 | break; |
| 137 | case ixgbe_mac_82599EB: |
| 138 | case ixgbe_mac_X540: |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 139 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 140 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 141 | break; |
| 142 | default: |
| 143 | break; |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 144 | } |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 145 | |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 146 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 147 | if (!netdev_get_num_tc(netdev)) |
| 148 | ixgbe_setup_tc(netdev, MAX_TRAFFIC_CLASS); |
| 149 | |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 150 | ixgbe_init_interrupt_scheme(adapter); |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 151 | if (netif_running(netdev)) |
| 152 | netdev->netdev_ops->ndo_open(netdev); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 153 | } else { |
| 154 | /* Turn off DCB */ |
| 155 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 156 | if (netif_running(netdev)) |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 157 | netdev->netdev_ops->ndo_stop(netdev); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 158 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 159 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 160 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 161 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 162 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 163 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 164 | switch (adapter->hw.mac.type) { |
| 165 | case ixgbe_mac_82599EB: |
| 166 | case ixgbe_mac_X540: |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 167 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 168 | break; |
| 169 | default: |
| 170 | break; |
| 171 | } |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 172 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 173 | ixgbe_setup_tc(netdev, 0); |
| 174 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 175 | ixgbe_init_interrupt_scheme(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 176 | if (netif_running(netdev)) |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 177 | netdev->netdev_ops->ndo_open(netdev); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 178 | } |
| 179 | } |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 180 | out: |
| 181 | return err; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev, |
| 185 | u8 *perm_addr) |
| 186 | { |
| 187 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 188 | int i, j; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 189 | |
Lucy Liu | 86e713a | 2009-07-16 13:43:10 +0000 | [diff] [blame] | 190 | memset(perm_addr, 0xff, MAX_ADDR_LEN); |
| 191 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 192 | for (i = 0; i < netdev->addr_len; i++) |
| 193 | perm_addr[i] = adapter->hw.mac.perm_addr[i]; |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 194 | |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 195 | switch (adapter->hw.mac.type) { |
| 196 | case ixgbe_mac_82599EB: |
| 197 | case ixgbe_mac_X540: |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 198 | for (j = 0; j < netdev->addr_len; j++, i++) |
| 199 | perm_addr[i] = adapter->hw.mac.san_addr[j]; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 200 | break; |
| 201 | default: |
| 202 | break; |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 203 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc, |
| 207 | u8 prio, u8 bwg_id, u8 bw_pct, |
| 208 | u8 up_map) |
| 209 | { |
| 210 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 211 | |
| 212 | if (prio != DCB_ATTR_VALUE_UNDEFINED) |
| 213 | adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio; |
| 214 | if (bwg_id != DCB_ATTR_VALUE_UNDEFINED) |
| 215 | adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id; |
| 216 | if (bw_pct != DCB_ATTR_VALUE_UNDEFINED) |
| 217 | adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent = |
| 218 | bw_pct; |
| 219 | if (up_map != DCB_ATTR_VALUE_UNDEFINED) |
| 220 | adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap = |
| 221 | up_map; |
| 222 | |
| 223 | if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type != |
| 224 | adapter->dcb_cfg.tc_config[tc].path[0].prio_type) || |
| 225 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id != |
| 226 | adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) || |
| 227 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent != |
| 228 | adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) || |
| 229 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap != |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 230 | adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap)) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 231 | adapter->dcb_set_bitmap |= BIT_PG_TX; |
| 232 | } |
| 233 | |
| 234 | static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id, |
| 235 | u8 bw_pct) |
| 236 | { |
| 237 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 238 | |
| 239 | adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct; |
| 240 | |
| 241 | if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] != |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 242 | adapter->dcb_cfg.bw_percentage[0][bwg_id]) |
John Fastabend | ebe1b30 | 2010-01-27 16:37:44 +0000 | [diff] [blame] | 243 | adapter->dcb_set_bitmap |= BIT_PG_TX; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc, |
| 247 | u8 prio, u8 bwg_id, u8 bw_pct, |
| 248 | u8 up_map) |
| 249 | { |
| 250 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 251 | |
| 252 | if (prio != DCB_ATTR_VALUE_UNDEFINED) |
| 253 | adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio; |
| 254 | if (bwg_id != DCB_ATTR_VALUE_UNDEFINED) |
| 255 | adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id; |
| 256 | if (bw_pct != DCB_ATTR_VALUE_UNDEFINED) |
| 257 | adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent = |
| 258 | bw_pct; |
| 259 | if (up_map != DCB_ATTR_VALUE_UNDEFINED) |
| 260 | adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap = |
| 261 | up_map; |
| 262 | |
| 263 | if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type != |
| 264 | adapter->dcb_cfg.tc_config[tc].path[1].prio_type) || |
| 265 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id != |
| 266 | adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) || |
| 267 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent != |
| 268 | adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) || |
| 269 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap != |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 270 | adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap)) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 271 | adapter->dcb_set_bitmap |= BIT_PG_RX; |
| 272 | } |
| 273 | |
| 274 | static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id, |
| 275 | u8 bw_pct) |
| 276 | { |
| 277 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 278 | |
| 279 | adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct; |
| 280 | |
| 281 | if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] != |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 282 | adapter->dcb_cfg.bw_percentage[1][bwg_id]) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 283 | adapter->dcb_set_bitmap |= BIT_PG_RX; |
| 284 | } |
| 285 | |
| 286 | static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, |
| 287 | u8 *prio, u8 *bwg_id, u8 *bw_pct, |
| 288 | u8 *up_map) |
| 289 | { |
| 290 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 291 | |
| 292 | *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type; |
| 293 | *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id; |
| 294 | *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent; |
| 295 | *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap; |
| 296 | } |
| 297 | |
| 298 | static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id, |
| 299 | u8 *bw_pct) |
| 300 | { |
| 301 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 302 | |
| 303 | *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id]; |
| 304 | } |
| 305 | |
| 306 | static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc, |
| 307 | u8 *prio, u8 *bwg_id, u8 *bw_pct, |
| 308 | u8 *up_map) |
| 309 | { |
| 310 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 311 | |
| 312 | *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type; |
| 313 | *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id; |
| 314 | *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent; |
| 315 | *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap; |
| 316 | } |
| 317 | |
| 318 | static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id, |
| 319 | u8 *bw_pct) |
| 320 | { |
| 321 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 322 | |
| 323 | *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id]; |
| 324 | } |
| 325 | |
| 326 | static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority, |
| 327 | u8 setting) |
| 328 | { |
| 329 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 330 | |
| 331 | adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting; |
| 332 | if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc != |
PJ Waskiewicz | ea4af4f | 2009-03-31 21:33:25 +0000 | [diff] [blame] | 333 | adapter->dcb_cfg.tc_config[priority].dcb_pfc) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 334 | adapter->dcb_set_bitmap |= BIT_PFC; |
PJ Waskiewicz | ea4af4f | 2009-03-31 21:33:25 +0000 | [diff] [blame] | 335 | adapter->temp_dcb_cfg.pfc_mode_enable = true; |
| 336 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority, |
| 340 | u8 *setting) |
| 341 | { |
| 342 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 343 | |
| 344 | *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc; |
| 345 | } |
| 346 | |
| 347 | static u8 ixgbe_dcbnl_set_all(struct net_device *netdev) |
| 348 | { |
| 349 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
John Fastabend | c8ca76e | 2011-03-12 03:50:53 +0000 | [diff] [blame] | 350 | struct dcb_app app = { |
| 351 | .selector = DCB_APP_IDTYPE_ETHTYPE, |
| 352 | .protocol = ETH_P_FCOE, |
| 353 | }; |
| 354 | u8 up = dcb_getapp(netdev, &app); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 355 | int ret; |
| 356 | |
John Fastabend | 3ce1cc5 | 2010-01-27 16:38:06 +0000 | [diff] [blame] | 357 | ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 358 | MAX_TRAFFIC_CLASS); |
John Fastabend | 3ce1cc5 | 2010-01-27 16:38:06 +0000 | [diff] [blame] | 359 | if (ret) |
| 360 | return DCB_NO_HW_CHG; |
| 361 | |
John Fastabend | c8ca76e | 2011-03-12 03:50:53 +0000 | [diff] [blame] | 362 | /* In IEEE mode app data must be parsed into DCBX format for |
| 363 | * hardware routines. |
| 364 | */ |
| 365 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 366 | up = (1 << up); |
| 367 | |
| 368 | #ifdef IXGBE_FCOE |
| 369 | if (up && (up != (1 << adapter->fcoe.up))) |
| 370 | adapter->dcb_set_bitmap |= BIT_APP_UPCHG; |
| 371 | |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 372 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 373 | * Only take down the adapter if an app change occurred. FCoE |
John Fastabend | d37e1d0 | 2011-01-07 15:30:46 +0000 | [diff] [blame] | 374 | * may shuffle tx rings in this case and this can not be done |
| 375 | * without a reset currently. |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 376 | */ |
John Fastabend | d37e1d0 | 2011-01-07 15:30:46 +0000 | [diff] [blame] | 377 | if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) { |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 378 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 379 | usleep_range(1000, 2000); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 380 | |
John Fastabend | c8ca76e | 2011-03-12 03:50:53 +0000 | [diff] [blame] | 381 | ixgbe_fcoe_setapp(adapter, up); |
| 382 | |
John Fastabend | d37e1d0 | 2011-01-07 15:30:46 +0000 | [diff] [blame] | 383 | if (netif_running(netdev)) |
| 384 | netdev->netdev_ops->ndo_stop(netdev); |
| 385 | ixgbe_clear_interrupt_scheme(adapter); |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 386 | } |
John Fastabend | c8ca76e | 2011-03-12 03:50:53 +0000 | [diff] [blame] | 387 | #endif |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 388 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 389 | if (adapter->dcb_cfg.pfc_mode_enable) { |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 390 | switch (adapter->hw.mac.type) { |
| 391 | case ixgbe_mac_82599EB: |
| 392 | case ixgbe_mac_X540: |
| 393 | if (adapter->hw.fc.current_mode != ixgbe_fc_pfc) |
| 394 | adapter->last_lfc_mode = |
| 395 | adapter->hw.fc.current_mode; |
| 396 | break; |
| 397 | default: |
| 398 | break; |
| 399 | } |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 400 | adapter->hw.fc.requested_mode = ixgbe_fc_pfc; |
| 401 | } else { |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 402 | switch (adapter->hw.mac.type) { |
| 403 | case ixgbe_mac_82598EB: |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 404 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 405 | break; |
| 406 | case ixgbe_mac_82599EB: |
| 407 | case ixgbe_mac_X540: |
| 408 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 409 | break; |
| 410 | default: |
| 411 | break; |
| 412 | } |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 413 | } |
| 414 | |
John Fastabend | c8ca76e | 2011-03-12 03:50:53 +0000 | [diff] [blame] | 415 | #ifdef IXGBE_FCOE |
John Fastabend | d37e1d0 | 2011-01-07 15:30:46 +0000 | [diff] [blame] | 416 | if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) { |
| 417 | ixgbe_init_interrupt_scheme(adapter); |
| 418 | if (netif_running(netdev)) |
| 419 | netdev->netdev_ops->ndo_open(netdev); |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 420 | ret = DCB_HW_CHG_RST; |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 421 | } |
John Fastabend | c8ca76e | 2011-03-12 03:50:53 +0000 | [diff] [blame] | 422 | #endif |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 423 | |
| 424 | if (adapter->dcb_set_bitmap & BIT_PFC) { |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame] | 425 | u8 pfc_en; |
| 426 | ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en); |
John Fastabend | 5977dea | 2011-01-05 04:48:45 +0000 | [diff] [blame] | 427 | ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en); |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 428 | ret = DCB_HW_CHG; |
| 429 | } |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 430 | |
| 431 | if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) { |
| 432 | u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS]; |
| 433 | u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS]; |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 434 | /* Priority to TC mapping in CEE case default to 1:1 */ |
| 435 | u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7}; |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 436 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 437 | |
| 438 | #ifdef CONFIG_FCOE |
| 439 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 440 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 441 | #endif |
| 442 | |
| 443 | ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg, |
| 444 | max_frame, DCB_TX_CONFIG); |
| 445 | ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg, |
| 446 | max_frame, DCB_RX_CONFIG); |
| 447 | |
| 448 | ixgbe_dcb_unpack_refill(&adapter->dcb_cfg, |
| 449 | DCB_TX_CONFIG, refill); |
| 450 | ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max); |
| 451 | ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg, |
| 452 | DCB_TX_CONFIG, bwg_id); |
| 453 | ixgbe_dcb_unpack_prio(&adapter->dcb_cfg, |
| 454 | DCB_TX_CONFIG, prio_type); |
| 455 | |
| 456 | ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max, |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 457 | bwg_id, prio_type, prio_tc); |
John Fastabend | d43f5c2 | 2011-01-22 06:07:05 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 460 | if (adapter->dcb_cfg.pfc_mode_enable) |
| 461 | adapter->hw.fc.current_mode = ixgbe_fc_pfc; |
| 462 | |
John Fastabend | d37e1d0 | 2011-01-07 15:30:46 +0000 | [diff] [blame] | 463 | if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 464 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 465 | adapter->dcb_set_bitmap = 0x00; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 466 | return ret; |
| 467 | } |
| 468 | |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 469 | static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap) |
| 470 | { |
| 471 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 472 | |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 473 | switch (capid) { |
| 474 | case DCB_CAP_ATTR_PG: |
| 475 | *cap = true; |
| 476 | break; |
| 477 | case DCB_CAP_ATTR_PFC: |
| 478 | *cap = true; |
| 479 | break; |
| 480 | case DCB_CAP_ATTR_UP2TC: |
| 481 | *cap = false; |
| 482 | break; |
| 483 | case DCB_CAP_ATTR_PG_TCS: |
| 484 | *cap = 0x80; |
| 485 | break; |
| 486 | case DCB_CAP_ATTR_PFC_TCS: |
| 487 | *cap = 0x80; |
| 488 | break; |
| 489 | case DCB_CAP_ATTR_GSP: |
| 490 | *cap = true; |
| 491 | break; |
| 492 | case DCB_CAP_ATTR_BCN: |
| 493 | *cap = false; |
| 494 | break; |
| 495 | case DCB_CAP_ATTR_DCBX: |
| 496 | *cap = adapter->dcbx_cap; |
| 497 | break; |
| 498 | default: |
| 499 | *cap = false; |
| 500 | break; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 501 | } |
| 502 | |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 503 | return 0; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 506 | static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num) |
| 507 | { |
| 508 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 509 | u8 rval = 0; |
| 510 | |
| 511 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 512 | switch (tcid) { |
| 513 | case DCB_NUMTCS_ATTR_PG: |
| 514 | *num = MAX_TRAFFIC_CLASS; |
| 515 | break; |
| 516 | case DCB_NUMTCS_ATTR_PFC: |
| 517 | *num = MAX_TRAFFIC_CLASS; |
| 518 | break; |
| 519 | default: |
| 520 | rval = -EINVAL; |
| 521 | break; |
| 522 | } |
| 523 | } else { |
| 524 | rval = -EINVAL; |
| 525 | } |
| 526 | |
| 527 | return rval; |
| 528 | } |
| 529 | |
| 530 | static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num) |
| 531 | { |
| 532 | return -EINVAL; |
| 533 | } |
| 534 | |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 535 | static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev) |
| 536 | { |
| 537 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 538 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 539 | return adapter->dcb_cfg.pfc_mode_enable; |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state) |
| 543 | { |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 544 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 545 | |
| 546 | adapter->temp_dcb_cfg.pfc_mode_enable = state; |
| 547 | if (adapter->temp_dcb_cfg.pfc_mode_enable != |
| 548 | adapter->dcb_cfg.pfc_mode_enable) |
| 549 | adapter->dcb_set_bitmap |= BIT_PFC; |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 552 | /** |
| 553 | * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority |
| 554 | * @netdev : the corresponding netdev |
| 555 | * @idtype : identifies the id as ether type or TCP/UDP port number |
| 556 | * @id: id is either ether type or TCP/UDP port number |
| 557 | * |
| 558 | * Returns : on success, returns a non-zero 802.1p user priority bitmap |
| 559 | * otherwise returns 0 as the invalid user priority bitmap to indicate an |
| 560 | * error. |
| 561 | */ |
| 562 | static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id) |
| 563 | { |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 564 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
John Fastabend | dc166e2 | 2011-02-23 05:57:52 +0000 | [diff] [blame] | 565 | struct dcb_app app = { |
| 566 | .selector = idtype, |
| 567 | .protocol = id, |
| 568 | }; |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 569 | |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 570 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)) |
John Fastabend | dc166e2 | 2011-02-23 05:57:52 +0000 | [diff] [blame] | 571 | return 0; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 572 | |
John Fastabend | dc166e2 | 2011-02-23 05:57:52 +0000 | [diff] [blame] | 573 | return dcb_getapp(netdev, &app); |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 574 | } |
| 575 | |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 576 | static int ixgbe_dcbnl_ieee_getets(struct net_device *dev, |
| 577 | struct ieee_ets *ets) |
| 578 | { |
| 579 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 580 | struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets; |
| 581 | |
| 582 | /* No IEEE PFC settings available */ |
| 583 | if (!my_ets) |
| 584 | return -EINVAL; |
| 585 | |
| 586 | ets->ets_cap = MAX_TRAFFIC_CLASS; |
| 587 | ets->cbs = my_ets->cbs; |
| 588 | memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw)); |
| 589 | memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw)); |
| 590 | memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa)); |
| 591 | memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc)); |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | static int ixgbe_dcbnl_ieee_setets(struct net_device *dev, |
| 596 | struct ieee_ets *ets) |
| 597 | { |
| 598 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 599 | __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS]; |
John Fastabend | 3b97fd6 | 2011-02-23 05:58:14 +0000 | [diff] [blame] | 600 | __u8 prio_type[IEEE_8021QAZ_MAX_TCS]; |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 601 | int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
John Fastabend | 3b97fd6 | 2011-02-23 05:58:14 +0000 | [diff] [blame] | 602 | int i, err; |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 603 | __u64 *p = (__u64 *) ets->prio_tc; |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 604 | /* naively give each TC a bwg to map onto CEE hardware */ |
| 605 | __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7}; |
| 606 | |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 607 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)) |
| 608 | return -EINVAL; |
| 609 | |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 610 | if (!adapter->ixgbe_ieee_ets) { |
| 611 | adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets), |
| 612 | GFP_KERNEL); |
| 613 | if (!adapter->ixgbe_ieee_ets) |
| 614 | return -ENOMEM; |
| 615 | } |
| 616 | |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 617 | memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets)); |
| 618 | |
John Fastabend | 3b97fd6 | 2011-02-23 05:58:14 +0000 | [diff] [blame] | 619 | /* Map TSA onto CEE prio type */ |
| 620 | for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) { |
| 621 | switch (ets->tc_tsa[i]) { |
| 622 | case IEEE_8021QAZ_TSA_STRICT: |
| 623 | prio_type[i] = 2; |
| 624 | break; |
| 625 | case IEEE_8021QAZ_TSA_ETS: |
| 626 | prio_type[i] = 0; |
| 627 | break; |
| 628 | default: |
| 629 | /* Hardware only supports priority strict or |
| 630 | * ETS transmission selection algorithms if |
| 631 | * we receive some other value from dcbnl |
| 632 | * throw an error |
| 633 | */ |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | } |
| 637 | |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 638 | if (*p) |
| 639 | ixgbe_dcbnl_set_state(dev, 1); |
| 640 | else |
| 641 | ixgbe_dcbnl_set_state(dev, 0); |
| 642 | |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 643 | ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame); |
| 644 | err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max, |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 645 | bwg_id, prio_type, ets->prio_tc); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 646 | return err; |
| 647 | } |
| 648 | |
| 649 | static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev, |
| 650 | struct ieee_pfc *pfc) |
| 651 | { |
| 652 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 653 | struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc; |
| 654 | int i; |
| 655 | |
| 656 | /* No IEEE PFC settings available */ |
| 657 | if (!my_pfc) |
| 658 | return -EINVAL; |
| 659 | |
| 660 | pfc->pfc_cap = MAX_TRAFFIC_CLASS; |
| 661 | pfc->pfc_en = my_pfc->pfc_en; |
| 662 | pfc->mbc = my_pfc->mbc; |
| 663 | pfc->delay = my_pfc->delay; |
| 664 | |
| 665 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 666 | pfc->requests[i] = adapter->stats.pxoffrxc[i]; |
| 667 | pfc->indications[i] = adapter->stats.pxofftxc[i]; |
| 668 | } |
| 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev, |
| 674 | struct ieee_pfc *pfc) |
| 675 | { |
| 676 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 677 | int err; |
| 678 | |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 679 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)) |
| 680 | return -EINVAL; |
| 681 | |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 682 | if (!adapter->ixgbe_ieee_pfc) { |
| 683 | adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc), |
| 684 | GFP_KERNEL); |
| 685 | if (!adapter->ixgbe_ieee_pfc) |
| 686 | return -ENOMEM; |
| 687 | } |
| 688 | |
| 689 | memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc)); |
| 690 | err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en); |
| 691 | return err; |
| 692 | } |
| 693 | |
John Fastabend | f8628d4 | 2011-02-23 05:57:47 +0000 | [diff] [blame] | 694 | static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev, |
| 695 | struct dcb_app *app) |
| 696 | { |
| 697 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 698 | |
| 699 | if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)) |
| 700 | return -EINVAL; |
John Fastabend | f8628d4 | 2011-02-23 05:57:47 +0000 | [diff] [blame] | 701 | |
John Fastabend | f8628d4 | 2011-02-23 05:57:47 +0000 | [diff] [blame] | 702 | dcb_setapp(dev, app); |
John Fastabend | c8ca76e | 2011-03-12 03:50:53 +0000 | [diff] [blame] | 703 | |
| 704 | #ifdef IXGBE_FCOE |
| 705 | if (app->selector == 1 && app->protocol == ETH_P_FCOE && |
| 706 | adapter->fcoe.tc == app->priority) |
| 707 | ixgbe_dcbnl_set_all(dev); |
| 708 | #endif |
John Fastabend | f8628d4 | 2011-02-23 05:57:47 +0000 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 712 | static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev) |
| 713 | { |
| 714 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 715 | return adapter->dcbx_cap; |
| 716 | } |
| 717 | |
| 718 | static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode) |
| 719 | { |
| 720 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 721 | struct ieee_ets ets = {0}; |
| 722 | struct ieee_pfc pfc = {0}; |
| 723 | |
| 724 | /* no support for LLD_MANAGED modes or CEE+IEEE */ |
| 725 | if ((mode & DCB_CAP_DCBX_LLD_MANAGED) || |
| 726 | ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) || |
| 727 | !(mode & DCB_CAP_DCBX_HOST)) |
| 728 | return 1; |
| 729 | |
| 730 | if (mode == adapter->dcbx_cap) |
| 731 | return 0; |
| 732 | |
| 733 | adapter->dcbx_cap = mode; |
| 734 | |
| 735 | /* ETS and PFC defaults */ |
| 736 | ets.ets_cap = 8; |
| 737 | pfc.pfc_cap = 8; |
| 738 | |
| 739 | if (mode & DCB_CAP_DCBX_VER_IEEE) { |
| 740 | ixgbe_dcbnl_ieee_setets(dev, &ets); |
| 741 | ixgbe_dcbnl_ieee_setpfc(dev, &pfc); |
| 742 | } else if (mode & DCB_CAP_DCBX_VER_CEE) { |
| 743 | adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX); |
| 744 | ixgbe_dcbnl_set_all(dev); |
| 745 | } else { |
| 746 | /* Drop into single TC mode strict priority as this |
| 747 | * indicates CEE and IEEE versions are disabled |
| 748 | */ |
| 749 | ixgbe_dcbnl_ieee_setets(dev, &ets); |
| 750 | ixgbe_dcbnl_ieee_setpfc(dev, &pfc); |
| 751 | ixgbe_dcbnl_set_state(dev, 0); |
| 752 | } |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
Stephen Hemminger | 3295354 | 2009-10-05 06:01:03 +0000 | [diff] [blame] | 757 | const struct dcbnl_rtnl_ops dcbnl_ops = { |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 758 | .ieee_getets = ixgbe_dcbnl_ieee_getets, |
| 759 | .ieee_setets = ixgbe_dcbnl_ieee_setets, |
| 760 | .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc, |
| 761 | .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc, |
John Fastabend | f8628d4 | 2011-02-23 05:57:47 +0000 | [diff] [blame] | 762 | .ieee_setapp = ixgbe_dcbnl_ieee_setapp, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 763 | .getstate = ixgbe_dcbnl_get_state, |
| 764 | .setstate = ixgbe_dcbnl_set_state, |
| 765 | .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr, |
| 766 | .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx, |
| 767 | .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx, |
| 768 | .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx, |
| 769 | .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx, |
| 770 | .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx, |
| 771 | .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx, |
| 772 | .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx, |
| 773 | .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx, |
| 774 | .setpfccfg = ixgbe_dcbnl_set_pfc_cfg, |
| 775 | .getpfccfg = ixgbe_dcbnl_get_pfc_cfg, |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 776 | .setall = ixgbe_dcbnl_set_all, |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 777 | .getcap = ixgbe_dcbnl_getcap, |
| 778 | .getnumtcs = ixgbe_dcbnl_getnumtcs, |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 779 | .setnumtcs = ixgbe_dcbnl_setnumtcs, |
| 780 | .getpfcstate = ixgbe_dcbnl_getpfcstate, |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 781 | .setpfcstate = ixgbe_dcbnl_setpfcstate, |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 782 | .getapp = ixgbe_dcbnl_getapp, |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 783 | .getdcbx = ixgbe_dcbnl_getdcbx, |
| 784 | .setdcbx = ixgbe_dcbnl_setdcbx, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 785 | }; |