Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2009 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 |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 39 | #define BIT_RESETLINK 0x40 |
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 | |
| 109 | DPRINTK(DRV, INFO, "Get DCB Admin Mode.\n"); |
| 110 | |
| 111 | return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED); |
| 112 | } |
| 113 | |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 114 | static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 115 | { |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 116 | u8 err = 0; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 117 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 118 | |
| 119 | DPRINTK(DRV, INFO, "Set DCB Admin Mode.\n"); |
| 120 | |
| 121 | if (state > 0) { |
| 122 | /* Turn on DCB */ |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 123 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 124 | goto out; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 125 | |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 126 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 127 | DPRINTK(DRV, ERR, "Enable failed, needs MSI-X\n"); |
| 128 | err = 1; |
| 129 | goto out; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 130 | } |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 131 | |
| 132 | if (netif_running(netdev)) |
| 133 | netdev->netdev_ops->ndo_stop(netdev); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 134 | ixgbe_clear_interrupt_scheme(adapter); |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 135 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 136 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 137 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 138 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
| 139 | } |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 140 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 141 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 142 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 143 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 144 | } |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 145 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
| 146 | ixgbe_init_interrupt_scheme(adapter); |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 147 | if (netif_running(netdev)) |
| 148 | netdev->netdev_ops->ndo_open(netdev); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 149 | } else { |
| 150 | /* Turn off DCB */ |
| 151 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 152 | if (netif_running(netdev)) |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 153 | netdev->netdev_ops->ndo_stop(netdev); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 154 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 155 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 156 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 157 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 158 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 159 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 160 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 161 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 162 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 163 | ixgbe_init_interrupt_scheme(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 164 | if (netif_running(netdev)) |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 165 | netdev->netdev_ops->ndo_open(netdev); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 166 | } |
| 167 | } |
Don Skidmore | 1486a61 | 2008-12-21 20:09:50 -0800 | [diff] [blame] | 168 | out: |
| 169 | return err; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev, |
| 173 | u8 *perm_addr) |
| 174 | { |
| 175 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 176 | int i, j; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 177 | |
Lucy Liu | 86e713a | 2009-07-16 13:43:10 +0000 | [diff] [blame^] | 178 | memset(perm_addr, 0xff, MAX_ADDR_LEN); |
| 179 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 180 | for (i = 0; i < netdev->addr_len; i++) |
| 181 | perm_addr[i] = adapter->hw.mac.perm_addr[i]; |
Waskiewicz Jr, Peter P | aca6bee | 2009-05-17 12:32:48 +0000 | [diff] [blame] | 182 | |
| 183 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 184 | for (j = 0; j < netdev->addr_len; j++, i++) |
| 185 | perm_addr[i] = adapter->hw.mac.san_addr[j]; |
| 186 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc, |
| 190 | u8 prio, u8 bwg_id, u8 bw_pct, |
| 191 | u8 up_map) |
| 192 | { |
| 193 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 194 | |
| 195 | if (prio != DCB_ATTR_VALUE_UNDEFINED) |
| 196 | adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio; |
| 197 | if (bwg_id != DCB_ATTR_VALUE_UNDEFINED) |
| 198 | adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id; |
| 199 | if (bw_pct != DCB_ATTR_VALUE_UNDEFINED) |
| 200 | adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent = |
| 201 | bw_pct; |
| 202 | if (up_map != DCB_ATTR_VALUE_UNDEFINED) |
| 203 | adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap = |
| 204 | up_map; |
| 205 | |
| 206 | if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type != |
| 207 | adapter->dcb_cfg.tc_config[tc].path[0].prio_type) || |
| 208 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id != |
| 209 | adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) || |
| 210 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent != |
| 211 | adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) || |
| 212 | (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap != |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 213 | adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap)) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 214 | adapter->dcb_set_bitmap |= BIT_PG_TX; |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 215 | adapter->dcb_set_bitmap |= BIT_RESETLINK; |
| 216 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id, |
| 220 | u8 bw_pct) |
| 221 | { |
| 222 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 223 | |
| 224 | adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct; |
| 225 | |
| 226 | if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] != |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 227 | adapter->dcb_cfg.bw_percentage[0][bwg_id]) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 228 | adapter->dcb_set_bitmap |= BIT_PG_RX; |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 229 | adapter->dcb_set_bitmap |= BIT_RESETLINK; |
| 230 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc, |
| 234 | u8 prio, u8 bwg_id, u8 bw_pct, |
| 235 | u8 up_map) |
| 236 | { |
| 237 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 238 | |
| 239 | if (prio != DCB_ATTR_VALUE_UNDEFINED) |
| 240 | adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio; |
| 241 | if (bwg_id != DCB_ATTR_VALUE_UNDEFINED) |
| 242 | adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id; |
| 243 | if (bw_pct != DCB_ATTR_VALUE_UNDEFINED) |
| 244 | adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent = |
| 245 | bw_pct; |
| 246 | if (up_map != DCB_ATTR_VALUE_UNDEFINED) |
| 247 | adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap = |
| 248 | up_map; |
| 249 | |
| 250 | if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type != |
| 251 | adapter->dcb_cfg.tc_config[tc].path[1].prio_type) || |
| 252 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id != |
| 253 | adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) || |
| 254 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent != |
| 255 | adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) || |
| 256 | (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap != |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 257 | adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap)) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 258 | adapter->dcb_set_bitmap |= BIT_PG_RX; |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 259 | adapter->dcb_set_bitmap |= BIT_RESETLINK; |
| 260 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id, |
| 264 | u8 bw_pct) |
| 265 | { |
| 266 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 267 | |
| 268 | adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct; |
| 269 | |
| 270 | if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] != |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 271 | adapter->dcb_cfg.bw_percentage[1][bwg_id]) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 272 | adapter->dcb_set_bitmap |= BIT_PG_RX; |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 273 | adapter->dcb_set_bitmap |= BIT_RESETLINK; |
| 274 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, |
| 278 | u8 *prio, u8 *bwg_id, u8 *bw_pct, |
| 279 | u8 *up_map) |
| 280 | { |
| 281 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 282 | |
| 283 | *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type; |
| 284 | *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id; |
| 285 | *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent; |
| 286 | *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap; |
| 287 | } |
| 288 | |
| 289 | static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id, |
| 290 | u8 *bw_pct) |
| 291 | { |
| 292 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 293 | |
| 294 | *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id]; |
| 295 | } |
| 296 | |
| 297 | static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc, |
| 298 | u8 *prio, u8 *bwg_id, u8 *bw_pct, |
| 299 | u8 *up_map) |
| 300 | { |
| 301 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 302 | |
| 303 | *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type; |
| 304 | *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id; |
| 305 | *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent; |
| 306 | *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap; |
| 307 | } |
| 308 | |
| 309 | static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id, |
| 310 | u8 *bw_pct) |
| 311 | { |
| 312 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 313 | |
| 314 | *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id]; |
| 315 | } |
| 316 | |
| 317 | static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority, |
| 318 | u8 setting) |
| 319 | { |
| 320 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 321 | |
| 322 | adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting; |
| 323 | if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc != |
PJ Waskiewicz | ea4af4f | 2009-03-31 21:33:25 +0000 | [diff] [blame] | 324 | adapter->dcb_cfg.tc_config[priority].dcb_pfc) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 325 | adapter->dcb_set_bitmap |= BIT_PFC; |
PJ Waskiewicz | ea4af4f | 2009-03-31 21:33:25 +0000 | [diff] [blame] | 326 | adapter->temp_dcb_cfg.pfc_mode_enable = true; |
| 327 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority, |
| 331 | u8 *setting) |
| 332 | { |
| 333 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 334 | |
| 335 | *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc; |
| 336 | } |
| 337 | |
| 338 | static u8 ixgbe_dcbnl_set_all(struct net_device *netdev) |
| 339 | { |
| 340 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 341 | int ret; |
| 342 | |
| 343 | if (!adapter->dcb_set_bitmap) |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 344 | return DCB_NO_HW_CHG; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 345 | |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 346 | /* |
| 347 | * Only take down the adapter if the configuration change |
| 348 | * requires a reset. |
| 349 | */ |
| 350 | if (adapter->dcb_set_bitmap & BIT_RESETLINK) { |
| 351 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 352 | msleep(1); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 353 | |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 354 | if (netif_running(netdev)) |
| 355 | ixgbe_down(adapter); |
| 356 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 357 | |
| 358 | ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 359 | adapter->ring_feature[RING_F_DCB].indices); |
| 360 | if (ret) { |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 361 | if (adapter->dcb_set_bitmap & BIT_RESETLINK) |
| 362 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 363 | return DCB_NO_HW_CHG; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 366 | if (adapter->dcb_cfg.pfc_mode_enable) { |
| 367 | if ((adapter->hw.mac.type != ixgbe_mac_82598EB) && |
| 368 | (adapter->hw.fc.current_mode != ixgbe_fc_pfc)) |
| 369 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 370 | adapter->hw.fc.requested_mode = ixgbe_fc_pfc; |
| 371 | } else { |
| 372 | if (adapter->hw.mac.type != ixgbe_mac_82598EB) |
| 373 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 374 | else |
| 375 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
| 376 | } |
| 377 | |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 378 | if (adapter->dcb_set_bitmap & BIT_RESETLINK) { |
| 379 | if (netif_running(netdev)) |
| 380 | ixgbe_up(adapter); |
| 381 | ret = DCB_HW_CHG_RST; |
| 382 | } else if (adapter->dcb_set_bitmap & BIT_PFC) { |
| 383 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 384 | ixgbe_dcb_config_pfc_82598(&adapter->hw, |
| 385 | &adapter->dcb_cfg); |
| 386 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 387 | ixgbe_dcb_config_pfc_82599(&adapter->hw, |
| 388 | &adapter->dcb_cfg); |
| 389 | ret = DCB_HW_CHG; |
| 390 | } |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 391 | if (adapter->dcb_cfg.pfc_mode_enable) |
| 392 | adapter->hw.fc.current_mode = ixgbe_fc_pfc; |
| 393 | |
Peter P Waskiewicz Jr | 62551d3 | 2009-05-17 12:35:57 +0000 | [diff] [blame] | 394 | if (adapter->dcb_set_bitmap & BIT_RESETLINK) |
| 395 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 396 | adapter->dcb_set_bitmap = 0x00; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 397 | return ret; |
| 398 | } |
| 399 | |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 400 | static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap) |
| 401 | { |
| 402 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 403 | u8 rval = 0; |
| 404 | |
| 405 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 406 | switch (capid) { |
| 407 | case DCB_CAP_ATTR_PG: |
| 408 | *cap = true; |
| 409 | break; |
| 410 | case DCB_CAP_ATTR_PFC: |
| 411 | *cap = true; |
| 412 | break; |
| 413 | case DCB_CAP_ATTR_UP2TC: |
| 414 | *cap = false; |
| 415 | break; |
| 416 | case DCB_CAP_ATTR_PG_TCS: |
| 417 | *cap = 0x80; |
| 418 | break; |
| 419 | case DCB_CAP_ATTR_PFC_TCS: |
| 420 | *cap = 0x80; |
| 421 | break; |
| 422 | case DCB_CAP_ATTR_GSP: |
| 423 | *cap = true; |
| 424 | break; |
| 425 | case DCB_CAP_ATTR_BCN: |
| 426 | *cap = false; |
| 427 | break; |
| 428 | default: |
| 429 | rval = -EINVAL; |
| 430 | break; |
| 431 | } |
| 432 | } else { |
| 433 | rval = -EINVAL; |
| 434 | } |
| 435 | |
| 436 | return rval; |
| 437 | } |
| 438 | |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 439 | static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num) |
| 440 | { |
| 441 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 442 | u8 rval = 0; |
| 443 | |
| 444 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 445 | switch (tcid) { |
| 446 | case DCB_NUMTCS_ATTR_PG: |
| 447 | *num = MAX_TRAFFIC_CLASS; |
| 448 | break; |
| 449 | case DCB_NUMTCS_ATTR_PFC: |
| 450 | *num = MAX_TRAFFIC_CLASS; |
| 451 | break; |
| 452 | default: |
| 453 | rval = -EINVAL; |
| 454 | break; |
| 455 | } |
| 456 | } else { |
| 457 | rval = -EINVAL; |
| 458 | } |
| 459 | |
| 460 | return rval; |
| 461 | } |
| 462 | |
| 463 | static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num) |
| 464 | { |
| 465 | return -EINVAL; |
| 466 | } |
| 467 | |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 468 | static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev) |
| 469 | { |
| 470 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 471 | |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 472 | return adapter->dcb_cfg.pfc_mode_enable; |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state) |
| 476 | { |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 477 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 478 | |
| 479 | adapter->temp_dcb_cfg.pfc_mode_enable = state; |
| 480 | if (adapter->temp_dcb_cfg.pfc_mode_enable != |
| 481 | adapter->dcb_cfg.pfc_mode_enable) |
| 482 | adapter->dcb_set_bitmap |= BIT_PFC; |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 483 | return; |
| 484 | } |
| 485 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 486 | struct dcbnl_rtnl_ops dcbnl_ops = { |
| 487 | .getstate = ixgbe_dcbnl_get_state, |
| 488 | .setstate = ixgbe_dcbnl_set_state, |
| 489 | .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr, |
| 490 | .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx, |
| 491 | .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx, |
| 492 | .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx, |
| 493 | .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx, |
| 494 | .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx, |
| 495 | .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx, |
| 496 | .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx, |
| 497 | .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx, |
| 498 | .setpfccfg = ixgbe_dcbnl_set_pfc_cfg, |
| 499 | .getpfccfg = ixgbe_dcbnl_get_pfc_cfg, |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 500 | .setall = ixgbe_dcbnl_set_all, |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 501 | .getcap = ixgbe_dcbnl_getcap, |
| 502 | .getnumtcs = ixgbe_dcbnl_getnumtcs, |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 503 | .setnumtcs = ixgbe_dcbnl_setnumtcs, |
| 504 | .getpfcstate = ixgbe_dcbnl_getpfcstate, |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 505 | .setpfcstate = ixgbe_dcbnl_setpfcstate, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 506 | }; |
| 507 | |